2026-11-10 17:25:08 +00:00
package glossary
import (
"encoding/json"
"strings"
"testing"
2026-11-17 19:57:22 +00:00
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
2026-11-10 17:25:08 +00:00
)
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" )
}
}