43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
|
|
package promptfixture
|
||
|
|
|
||
|
|
import (
|
||
|
|
"go.yaml.in/yaml/v4"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestBudgetIgnoresLayoutAndPreservesContract(t *testing.T) {
|
||
|
|
for _, input := range []string{
|
||
|
|
`prompts: [{output: {format: json, repair_attempts: 9}, id: test, messages: [{role: user, content: hello}]}]`,
|
||
|
|
"collections:\n test:\n prompts:\n - output:\n format: json\n messages: [{role: user, content: hello}]\n id: test\n",
|
||
|
|
} {
|
||
|
|
result := WithRepairAttempts(t, []byte(input), 2)
|
||
|
|
var doc struct {
|
||
|
|
Prompts []struct {
|
||
|
|
Output struct {
|
||
|
|
Format string
|
||
|
|
RepairAttempts int `yaml:"repair_attempts"`
|
||
|
|
}
|
||
|
|
Messages []struct{ Content string }
|
||
|
|
}
|
||
|
|
Collections map[string]struct {
|
||
|
|
Prompts []struct {
|
||
|
|
Output struct {
|
||
|
|
RepairAttempts int `yaml:"repair_attempts"`
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if err := yaml.Unmarshal(result, &doc); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if len(doc.Prompts) > 0 {
|
||
|
|
p := doc.Prompts[0]
|
||
|
|
if p.Output.RepairAttempts != 2 || p.Output.Format != "json" || p.Messages[0].Content != "hello" {
|
||
|
|
t.Fatalf("lost contract: %s", result)
|
||
|
|
}
|
||
|
|
} else if doc.Collections["test"].Prompts[0].Output.RepairAttempts != 2 {
|
||
|
|
t.Fatalf("budget: %s", result)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|