Migrate HTTP and report fixtures to PromptKit sources

This commit is contained in:
2026-10-04 12:20:43 +00:00
parent 5c302f18ac
commit 9ea9d0706d
3 changed files with 167 additions and 119 deletions

View File

@@ -3,8 +3,8 @@
## Status, Baseline, And Authority ## Status, Baseline, And Authority
Planned on 2026-10-04 against Scriptorium Planned on 2026-10-04 against Scriptorium
`82b0f231b6ba71328f65f9a501143b2eedbe5d9c`. Stages 1–6 are complete; stages `82b0f231b6ba71328f65f9a501143b2eedbe5d9c`. Stages 1–7 are complete; stages
7–13 are pending. 8–13 are pending.
This plan is for a Luna coding agent: implement the stages in sequential order, This plan is for a Luna coding agent: implement the stages in sequential order,
normally one stage per implementation prompt. The normally one stage per implementation prompt. The
[feature roadmap](promptkit.md) owns the target state, scope, and confirmed [feature roadmap](promptkit.md) owns the target state, scope, and confirmed
@@ -427,7 +427,13 @@ expectations, without legacy parsing or narrowed valid-definition support.
## Stage 7: Migrate HTTP And Report Fixtures Without Changing Their Contracts ## Stage 7: Migrate HTTP And Report Fixtures Without Changing Their Contracts
Status: Pending. Depends on Stage 6. Status: Complete. HTTP and report engine fixtures now use keyed prompt/profile
definitions and native ConfigKit underlays; backend tests use PromptKit's keyed
`BackendSource` while retaining explicit pointer-valued limits, including the
zero-capacity queue. Request/status and report assertions remain unchanged.
Focused HTTP/report tests, `go test ./...`, `go test -race ./...`, `go vet
./...`, the CLI build, `gofmt`, `git diff --check`, and a repository-wide search
for removed constructor APIs pass.
Files: `internal/adapter/http/handler_test.go`, Files: `internal/adapter/http/handler_test.go`,
`internal/report/report_test.go`; other test constructors found by removed-API `internal/report/report_test.go`; other test constructors found by removed-API

View File

@@ -15,6 +15,7 @@ import (
"testing" "testing"
"time" "time"
"gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/promptkit" "gitea.maximumdirect.net/eric/promptkit"
) )
@@ -597,8 +598,9 @@ func TestHandlerDelegatesDefinitionInputRequirements(t *testing.T) {
}{ }{
{ {
name: "no declared inputs", name: "no declared inputs",
definition: `id: p definition: `prompts:
version: "1" p:
"1":
default_profile: exec default_profile: exec
messages: messages:
- role: user - role: user
@@ -611,8 +613,9 @@ output:
}, },
{ {
name: "optional input omitted", name: "optional input omitted",
definition: `id: p definition: `prompts:
version: "1" p:
"1":
default_profile: exec default_profile: exec
inputs: inputs:
- name: note - name: note
@@ -628,8 +631,9 @@ output:
}, },
{ {
name: "required input omitted", name: "required input omitted",
definition: `id: p definition: `prompts:
version: "1" p:
"1":
default_profile: exec default_profile: exec
inputs: inputs:
- name: note - name: note
@@ -646,8 +650,9 @@ output:
}, },
{ {
name: "template input omitted", name: "template input omitted",
definition: `id: p definition: `prompts:
version: "1" p:
"1":
default_profile: exec default_profile: exec
messages: messages:
- role: user - role: user
@@ -988,7 +993,7 @@ func TestHandlerSessionIDUsesPromptkitResolution(t *testing.T) {
if tc.definitionSession != "" { if tc.definitionSession != "" {
sessionLine = " session_id: " + tc.definitionSession + "\n" sessionLine = " session_id: " + tc.definitionSession + "\n"
} }
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte("id: p\nversion: \"1\"\ndefault_profile: exec\n"+sessionLine+`messages: if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte("prompts:\n p:\n \"1\":\n default_profile: exec\n"+sessionLine+` messages:
- role: user - role: user
content: "hi" content: "hi"
output: output:
@@ -997,13 +1002,10 @@ output:
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatalf("write prompt fixture: %v", err) t.Fatalf("write prompt fixture: %v", err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("id: exec\nendpoint: http://127.0.0.1:1/v1\nmodel: test\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("profiles:\n exec:\n endpoint: http://127.0.0.1:1/v1\n model: test\n"), 0o644); err != nil {
t.Fatalf("write profile fixture: %v", err) t.Fatalf("write profile fixture: %v", err)
} }
engine, err := promptkit.NewEngine(promptkit.Config{PromptDir: promptDir, ProfileDir: profileDir}, promptkit.WithLLMClient(handlerLLMClient{})) engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, nil, promptkit.WithLLMClient(handlerLLMClient{}))
if err != nil {
t.Fatalf("new engine: %v", err)
}
body := `{"prompt_id":"p"}` body := `{"prompt_id":"p"}`
if tc.requestSession != "" { if tc.requestSession != "" {
@@ -1035,8 +1037,9 @@ output:
func TestHandlerSharesBackendCapacityAcrossConcurrentRequests(t *testing.T) { func TestHandlerSharesBackendCapacityAcrossConcurrentRequests(t *testing.T) {
promptDir := t.TempDir() promptDir := t.TempDir()
profileDir := t.TempDir() profileDir := t.TempDir()
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`id: p if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`prompts:
version: "1" p:
"1":
default_profile: limited default_profile: limited
messages: messages:
- role: user - role: user
@@ -1047,7 +1050,8 @@ output:
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatalf("write prompt fixture: %v", err) t.Fatalf("write prompt fixture: %v", err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`id: limited if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
limited:
backend: limited backend: limited
model: test model: test
`), 0o644); err != nil { `), 0o644); err != nil {
@@ -1055,19 +1059,8 @@ model: test
} }
queueCapacity := 0 queueCapacity := 0
client := &blockingLLMClient{started: make(chan struct{}, 1), release: make(chan struct{})} client := &blockingLLMClient{started: make(chan struct{}, 1), release: make(chan struct{})}
engine, err := promptkit.NewEngine( backend := promptkit.BackendConfig{Endpoint: stringPointer("http://127.0.0.1:1/v1"), ConcurrencyLimit: intPointer(1), QueueCapacity: &queueCapacity}
promptkit.Config{PromptDir: promptDir, ProfileDir: profileDir}, engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, &backend, promptkit.WithLLMClient(client))
promptkit.WithBackend(promptkit.Backend{
ID: "limited",
Endpoint: "http://127.0.0.1:1/v1",
ConcurrencyLimit: 1,
QueueCapacity: &queueCapacity,
}),
promptkit.WithLLMClient(client),
)
if err != nil {
t.Fatalf("new engine: %v", err)
}
h := NewHandler(engine) h := NewHandler(engine)
first := httptest.NewRecorder() first := httptest.NewRecorder()
firstDone := make(chan struct{}) firstDone := make(chan struct{})
@@ -1265,16 +1258,24 @@ func newRetryHandler(t *testing.T, endpoint string, retries *int, concurrency in
t.Helper() t.Helper()
promptDir := t.TempDir() promptDir := t.TempDir()
profileDir := t.TempDir() profileDir := t.TempDir()
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte("id: p\nversion: \"1\"\ndefault_profile: limited\nmessages:\n - role: user\n content: hi\noutput:\n format: text\n validation_mode: none\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`prompts:
p:
"1":
default_profile: limited
messages:
- role: user
content: hi
output:
format: text
validation_mode: none
`), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("id: limited\nbackend: limited\nmodel: test\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("profiles:\n limited:\n backend: limited\n model: test\n"), 0o644); err != nil {
t.Fatal(err)
}
engine, err := promptkit.NewEngine(promptkit.Config{PromptDir: promptDir, ProfileDir: profileDir, TransientRetries: retries}, promptkit.WithBackend(promptkit.Backend{ID: "limited", Endpoint: endpoint, ConcurrencyLimit: concurrency, QueueCapacity: queue}))
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
backend := promptkit.BackendConfig{Endpoint: &endpoint, ConcurrencyLimit: &concurrency, QueueCapacity: queue}
engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, retries, &backend)
return NewHandler(engine) return NewHandler(engine)
} }
@@ -1770,8 +1771,9 @@ func newHandlerEngineWithOptions(t *testing.T, options ...promptkit.Option) *pro
promptDir := t.TempDir() promptDir := t.TempDir()
profileDir := t.TempDir() profileDir := t.TempDir()
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`id: p if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`prompts:
version: "1" p:
"1":
default_profile: exec default_profile: exec
messages: messages:
- role: user - role: user
@@ -1783,21 +1785,15 @@ output:
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatalf("write prompt fixture: %v", err) t.Fatalf("write prompt fixture: %v", err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`id: exec if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
exec:
endpoint: http://example.invalid/v1 endpoint: http://example.invalid/v1
model: model model: model
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatalf("write profile fixture: %v", err) t.Fatalf("write profile fixture: %v", err)
} }
engine, err := promptkit.NewEngine(promptkit.Config{ return newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, nil, options...)
PromptDir: promptDir,
ProfileDir: profileDir,
}, options...)
if err != nil {
t.Fatalf("construct public engine: %v", err)
}
return engine
} }
func newDefinitionHandler(t *testing.T, definition string) *Handler { func newDefinitionHandler(t *testing.T, definition string) *Handler {
@@ -1808,21 +1804,46 @@ func newDefinitionHandler(t *testing.T, definition string) *Handler {
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(definition), 0o644); err != nil { if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(definition), 0o644); err != nil {
t.Fatalf("write prompt fixture: %v", err) t.Fatalf("write prompt fixture: %v", err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`id: exec if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
exec:
endpoint: http://example.invalid/v1 endpoint: http://example.invalid/v1
model: model model: model
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatalf("write profile fixture: %v", err) t.Fatalf("write profile fixture: %v", err)
} }
engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, nil, promptkit.WithLLMClient(handlerLLMClient{}))
return NewHandler(engine)
}
func newHandlerEngineFromDirectories(t *testing.T, promptDir, profileDir string, retries *int, backend *promptkit.BackendConfig, options ...promptkit.Option) *promptkit.Engine {
t.Helper()
promptInputs, err := promptkit.DirectoryInputs(promptDir)
if err != nil {
t.Fatalf("load prompt inputs: %v", err)
}
profileInputs, err := promptkit.DirectoryInputs(profileDir)
if err != nil {
t.Fatalf("load profile inputs: %v", err)
}
underlays := []configkit.Underlay{{Inputs: promptInputs}, {Inputs: profileInputs}}
if backend != nil {
underlays = append(underlays, configkit.Underlay{Inputs: []configkit.Input{{Source: promptkit.BackendSource("test backend", map[string]promptkit.BackendConfig{"limited": *backend})}}})
}
engine, err := promptkit.NewEngine(promptkit.Config{ engine, err := promptkit.NewEngine(promptkit.Config{
PromptDir: promptDir, Sources: promptkit.ConfigurationSources{Underlays: underlays},
ProfileDir: profileDir, TransientRetries: retries,
}, promptkit.WithLLMClient(handlerLLMClient{})) }, options...)
if err != nil { if err != nil {
t.Fatalf("construct public engine: %v", err) t.Fatalf("construct public engine: %v", err)
} }
return NewHandler(engine) return engine
}
func stringPointer(value string) *string {
return &value
} }
func assertHTTPErrorCode(t *testing.T, w *httptest.ResponseRecorder, status int, code string) { func assertHTTPErrorCode(t *testing.T, w *httptest.ResponseRecorder, status int, code string) {

View File

@@ -9,6 +9,7 @@ import (
"testing" "testing"
"time" "time"
"gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/promptkit" "gitea.maximumdirect.net/eric/promptkit"
) )
@@ -105,13 +106,33 @@ func (localClient) Generate(ctx context.Context, req promptkit.GenerateRequest)
func TestCollectorReceivesRealEngineTerminalEvent(t *testing.T) { func TestCollectorReceivesRealEngineTerminalEvent(t *testing.T) {
promptDir := t.TempDir() promptDir := t.TempDir()
profileDir := t.TempDir() profileDir := t.TempDir()
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte("id: p\nversion: \"1\"\ndefault_profile: local\nmessages:\n - role: user\n content: hi\noutput:\n format: text\n validation_mode: none\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`prompts:
p:
"1":
default_profile: local
messages:
- role: user
content: hi
output:
format: text
validation_mode: none
`), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("id: local\nendpoint: http://127.0.0.1:1/v1\nmodel: local-model\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("profiles:\n local:\n endpoint: http://127.0.0.1:1/v1\n model: local-model\n"), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
engine, err := promptkit.NewEngine(promptkit.Config{PromptDir: promptDir, ProfileDir: profileDir}, promptkit.WithLLMClient(localClient{})) promptInputs, err := promptkit.DirectoryInputs(promptDir)
if err != nil {
t.Fatal(err)
}
profileInputs, err := promptkit.DirectoryInputs(profileDir)
if err != nil {
t.Fatal(err)
}
engine, err := promptkit.NewEngine(promptkit.Config{
Sources: promptkit.ConfigurationSources{Underlays: []configkit.Underlay{{Inputs: promptInputs}, {Inputs: profileInputs}}},
}, promptkit.WithLLMClient(localClient{}))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }