Preserve selected collections in materialized references
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user