Demonstrate independent collection discovery
This commit is contained in:
@@ -252,6 +252,8 @@ scaffolding, or conversation and coordination features.
|
|||||||
|
|
||||||
## Stage 6: Demonstrate discovery of independent collection checkouts
|
## Stage 6: Demonstrate discovery of independent collection checkouts
|
||||||
|
|
||||||
|
**Status: Complete.**
|
||||||
|
|
||||||
1. Add `examples/config.discovery.yml` selecting
|
1. Add `examples/config.discovery.yml` selecting
|
||||||
`./examples/discovery/framework.yml` as a file under
|
`./examples/discovery/framework.yml` as a file under
|
||||||
`promptkit_sources`. The framework file declares two **optional**
|
`promptkit_sources`. The framework file declares two **optional**
|
||||||
|
|||||||
2
examples/config.discovery.yml
Normal file
2
examples/config.discovery.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
promptkit_sources:
|
||||||
|
- file: ./examples/discovery/framework.yml
|
||||||
12
examples/discovery/collections/review-repo/collection.yaml
Normal file
12
examples/discovery/collections/review-repo/collection.yaml
Normal 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: {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
id: base
|
||||||
|
endpoint: https://example.invalid/v1
|
||||||
|
model: review-example
|
||||||
@@ -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
|
||||||
20
examples/discovery/collections/support-repo/collection.yml
Normal file
20
examples/discovery/collections/support-repo/collection.yml
Normal 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: {}
|
||||||
2
examples/discovery/collections/support-repo/other.yml
Normal file
2
examples/discovery/collections/support-repo/other.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
repository_metadata:
|
||||||
|
purpose: This file is not a PromptKit framework input.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
id: base
|
||||||
|
endpoint: https://example.invalid/v1
|
||||||
|
model: support-example
|
||||||
|
temperature: 0.2
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
id: fast
|
||||||
|
extends: {id: base}
|
||||||
|
max_tokens: 256
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Answer the support request using this transcript:
|
||||||
|
|
||||||
|
{{input "transcript"}}
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
4
examples/discovery/framework.yml
Normal file
4
examples/discovery/framework.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
config:
|
||||||
|
imports:
|
||||||
|
- glob: collections/*/collection.yml
|
||||||
|
- glob: collections/*/collection.yaml
|
||||||
82
internal/adapter/cli/discovery_test.go
Normal file
82
internal/adapter/cli/discovery_test.go
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user