Demonstrate independent collection discovery

This commit is contained in:
2026-11-18 19:20:55 +00:00
parent 27db6b6f47
commit a2205db152
14 changed files with 165 additions and 0 deletions

View File

@@ -252,6 +252,8 @@ scaffolding, or conversation and coordination features.
## Stage 6: Demonstrate discovery of independent collection checkouts
**Status: Complete.**
1. Add `examples/config.discovery.yml` selecting
`./examples/discovery/framework.yml` as a file under
`promptkit_sources`. The framework file declares two **optional**

View File

@@ -0,0 +1,2 @@
promptkit_sources:
- file: ./examples/discovery/framework.yml

View File

@@ -0,0 +1,12 @@
config:
imports:
- path: profiles/base.yaml
destination: [collections, review, profiles]
placement: sequence-item
required: true
- path: prompts/answer.yaml
destination: [collections, review, prompts]
placement: sequence-item
required: true
collections:
review: {}

View File

@@ -0,0 +1,3 @@
id: base
endpoint: https://example.invalid/v1
model: review-example

View File

@@ -0,0 +1,8 @@
id: answer
default_profile: review/base
messages:
- role: user
content: Review this material and report your findings.
output:
format: text
validation_mode: none

View File

@@ -0,0 +1,20 @@
config:
imports:
- path: profiles/base.yml
destination: [collections, support, profiles]
placement: sequence-item
required: true
- path: profiles/fast.yml
destination: [collections, support, profiles]
placement: sequence-item
required: true
- path: prompts/answer.yml
destination: [collections, support, prompts]
placement: sequence-item
required: true
- path: prompts/summarize.yml
destination: [collections, support, prompts]
placement: sequence-item
required: true
collections:
support: {}

View File

@@ -0,0 +1,2 @@
repository_metadata:
purpose: This file is not a PromptKit framework input.

View File

@@ -0,0 +1,4 @@
id: base
endpoint: https://example.invalid/v1
model: support-example
temperature: 0.2

View File

@@ -0,0 +1,3 @@
id: fast
extends: {id: base}
max_tokens: 256

View File

@@ -0,0 +1,3 @@
Answer the support request using this transcript:
{{input "transcript"}}

View File

@@ -0,0 +1,12 @@
id: answer
default_profile: support/fast
inputs:
- name: transcript
required: true
content_type: text/markdown
messages:
- role: user
content_file: ./answer.md
output:
format: text
validation_mode: none

View File

@@ -0,0 +1,8 @@
id: summarize
default_profile: support/fast
messages:
- role: user
content: Summarize the support request concisely.
output:
format: text
validation_mode: none

View File

@@ -0,0 +1,4 @@
config:
imports:
- glob: collections/*/collection.yml
- glob: collections/*/collection.yaml

View File

@@ -0,0 +1,82 @@
package cli
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
)
func TestCollectionCheckoutDiscoveryAcrossInvocations(t *testing.T) {
fixture, err := filepath.Abs(filepath.Join("..", "..", "..", "examples", "discovery"))
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
first string
second string
}{
{name: "yml then yaml", first: "support-repo", second: "review-repo"},
{name: "yaml then yml", first: "review-repo", second: "support-repo"},
} {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
framework, err := os.ReadFile(filepath.Join(fixture, "framework.yml"))
if err != nil {
t.Fatal(err)
}
frameworkPath := filepath.Join(root, "framework.yml")
if err := os.WriteFile(frameworkPath, framework, 0o644); err != nil {
t.Fatal(err)
}
collections := filepath.Join(root, "collections")
if err := os.MkdirAll(collections, 0o755); err != nil {
t.Fatal(err)
}
install := func(name string) {
t.Helper()
if err := os.CopyFS(filepath.Join(collections, name), os.DirFS(filepath.Join(fixture, "collections", name))); err != nil {
t.Fatal(err)
}
}
config := writeAppConfigFile(t, fmt.Sprintf("promptkit_sources:\n - file: %q\n", frameworkPath))
input := filepath.Join(root, "transcript.md")
if err := os.WriteFile(input, []byte("synthetic discovery transcript"), 0o644); err != nil {
t.Fatal(err)
}
args := func(name string) []string {
if name == "support-repo" {
return []string{"--config", config, "--prompt", "support/answer", "--profile", "support/fast", "--input", "transcript=" + input}
}
return []string{"--config", config, "--prompt", "review/answer", "--profile", "review/base"}
}
check := func(name string) {
t.Helper()
code, out, stderr := runCLICommand(t, renderCommand, args(name))
if code != ExitOK {
t.Fatalf("render %s: code=%d stderr=%s", name, code, stderr)
}
if name == "support-repo" {
for _, want := range []string{"prompt: support/answer", "selected_profile_id: support/fast", "model: support-example", "max_tokens: 256", "Answer the support request", "synthetic discovery transcript"} {
if !strings.Contains(out, want) {
t.Fatalf("missing %q: %s", want, out)
}
}
} else if !strings.Contains(out, "prompt: review/answer") || !strings.Contains(out, "model: review-example") || !strings.Contains(out, "Review this material") {
t.Fatalf("unexpected review render: %s", out)
}
}
install(tc.first)
check(tc.first)
code, _, _ := runCLICommand(t, renderCommand, args(tc.second))
if code != ExitRuntimeError {
t.Fatal("uninstalled collection unexpectedly selected")
}
install(tc.second)
check(tc.first)
check(tc.second)
})
}
}