34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package glossary
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/config"
|
|
)
|
|
|
|
func TestSelectionRetainsDistinctIdentitiesAndDoesNotExposeExtensions(t *testing.T) {
|
|
plural := "Shields"
|
|
collections := map[string]config.GlossaryCollection{
|
|
"spells": {Entries: []config.GlossaryEntry{{ID: "shield", Name: "Shield", Category: "spell", Aliases: []string{"Ward"}, Plural: &plural, Extra: map[string]any{"private": "do not forward"}}}},
|
|
"items": {Entries: []config.GlossaryEntry{{ID: "shield", Name: "Shield", Category: "item"}}},
|
|
}
|
|
result := Select(collections, []string{"spells", "items", "spells"})
|
|
if len(result) != 2 || result[0].Collection != "spells" || result[1].Collection != "items" {
|
|
t.Fatalf("entries=%+v", result)
|
|
}
|
|
raw, err := json.Marshal(result)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(raw), "do not forward") {
|
|
t.Fatal("extension leaked into prompt projection")
|
|
}
|
|
result[0].Aliases[0] = "changed"
|
|
*result[0].Plural = "changed"
|
|
if collections["spells"].Entries[0].Aliases[0] != "Ward" || *collections["spells"].Entries[0].Plural != "Shields" {
|
|
t.Fatal("projection changed configuration")
|
|
}
|
|
}
|