43 lines
955 B
Go
43 lines
955 B
Go
package sidekick
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestPromptsTemplating(t *testing.T) {
|
||
|
|
content := `
|
||
|
|
base_rules = "You are helpful."
|
||
|
|
coordinator = "{{template \"base_rules\"}} Route tasks."
|
||
|
|
`
|
||
|
|
tmpFile, err := os.CreateTemp("", "prompts-*.toml")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("failed to create temp file: %v", err)
|
||
|
|
}
|
||
|
|
defer os.Remove(tmpFile.Name())
|
||
|
|
|
||
|
|
if _, err := tmpFile.WriteString(content); err != nil {
|
||
|
|
t.Fatalf("failed to write temp file: %v", err)
|
||
|
|
}
|
||
|
|
tmpFile.Close()
|
||
|
|
|
||
|
|
tmpl, err := LoadPrompts(tmpFile.Name())
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("LoadPrompts failed: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
if tmpl.Lookup("coordinator") == nil {
|
||
|
|
t.Fatalf("template 'coordinator' not found")
|
||
|
|
}
|
||
|
|
|
||
|
|
rendered, err := RenderPrompt(tmpl, "coordinator")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("RenderPrompt failed: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
expected := "You are helpful. Route tasks."
|
||
|
|
if rendered != expected {
|
||
|
|
t.Errorf("expected %q, got %q", expected, rendered)
|
||
|
|
}
|
||
|
|
}
|