Resolve linked prompts in their host context
This commit is contained in:
@@ -161,3 +161,40 @@ func TestEngineUsesRecordedContextWithWiderRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEngineResolvesLinkedPromptMessageBesideDefinition(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.Mkdir(filepath.Join(root, "defs"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, contents := range map[string]string{
|
||||
"config.yml": "version: 3\n",
|
||||
"defs/resources.yml": "prompts:\n - id: linked\n messages:\n - role: user\n content_file: message.txt\n output:\n format: text\n validation_mode: none\n",
|
||||
"defs/message.txt": "message beside definition",
|
||||
"message.txt": "message beside symlink",
|
||||
} {
|
||||
if err := os.WriteFile(filepath.Join(root, name), []byte(contents), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.Symlink("defs/resources.yml", filepath.Join(root, "prompts.yml")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := config.Load(ck.Input{Source: ck.File(filepath.Join(root, "config.yml"))}, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runtime, err := NewRuntime(context.Background(), loaded, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prompt, err := runtime.Engine.InspectPrompt(context.Background(), "linked")
|
||||
if err != nil || prompt.Messages[0].Content != "message beside definition" {
|
||||
t.Fatalf("linked prompt: %+v, %v", prompt, err)
|
||||
}
|
||||
for _, name := range []string{"defs/resources.yml", "defs/message.txt"} {
|
||||
if !slices.Contains(runtime.SourcePaths, filepath.Join(root, name)) {
|
||||
t.Errorf("missing consumed source %s in %v", name, runtime.SourcePaths)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user