Preserve selected collections in materialized references

This commit is contained in:
2026-11-29 17:59:01 +00:00
parent 10221b0624
commit d406aa6cd2
33 changed files with 251 additions and 2 deletions

View File

@@ -123,6 +123,34 @@ func TestReferenceItemJSONOmitsContent(t *testing.T) {
}
}
func TestReferenceItemCollectionSelectionCopyAndJSON(t *testing.T) {
for _, selection := range [][]string{nil, {}, {"campaign"}} {
item := ReferenceItem{SlotName: "glossary", Collections: selection}
clone := CloneReferenceItem(item)
if (clone.Collections == nil) != (selection == nil) || len(clone.Collections) != len(selection) {
t.Fatalf("cloned selection = %#v, want %#v", clone.Collections, selection)
}
encoded, err := json.Marshal(item)
if err != nil {
t.Fatal(err)
}
var fields map[string]any
if err := json.Unmarshal(encoded, &fields); err != nil {
t.Fatal(err)
}
_, present := fields["collections"]
if present != (selection != nil) {
t.Fatalf("encoded selection = %s", encoded)
}
if len(selection) > 0 {
clone.Collections[0] = "changed"
if selection[0] != "campaign" {
t.Fatal("copy mutated original selection")
}
}
}
}
func TestLLMInputMaterialCopiesContentAndOmitsContentFromJSON(t *testing.T) {
content := []byte("raw source bytes")
material := NewLLMInputMaterial("transcript", "application/json", content, "sha256:source", "file:///tmp/source.json")