Migrate maintained PromptKit definitions and fixtures
This commit is contained in:
@@ -629,51 +629,48 @@ func TestHandlerDelegatesDefinitionInputRequirements(t *testing.T) {
|
||||
{
|
||||
name: "no declared inputs",
|
||||
definition: `prompts:
|
||||
p:
|
||||
"1":
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
- id: p
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`,
|
||||
wantStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "optional input omitted",
|
||||
definition: `prompts:
|
||||
p:
|
||||
"1":
|
||||
default_profile: exec
|
||||
inputs:
|
||||
- name: note
|
||||
required: false
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
- id: p
|
||||
default_profile: exec
|
||||
inputs:
|
||||
- name: note
|
||||
required: false
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`,
|
||||
wantStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "required input omitted",
|
||||
definition: `prompts:
|
||||
p:
|
||||
"1":
|
||||
default_profile: exec
|
||||
inputs:
|
||||
- name: note
|
||||
required: true
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
- id: p
|
||||
default_profile: exec
|
||||
inputs:
|
||||
- name: note
|
||||
required: true
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`,
|
||||
wantStatus: http.StatusBadRequest,
|
||||
wantCode: "prompt_render_failed",
|
||||
@@ -681,15 +678,14 @@ func TestHandlerDelegatesDefinitionInputRequirements(t *testing.T) {
|
||||
{
|
||||
name: "template input omitted",
|
||||
definition: `prompts:
|
||||
p:
|
||||
"1":
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: '{{input "note"}}'
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
- id: p
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: '{{input "note"}}'
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`,
|
||||
wantStatus: http.StatusBadRequest,
|
||||
wantCode: "prompt_render_failed",
|
||||
@@ -1020,18 +1016,18 @@ func TestHandlerSessionIDUsesPromptkitResolution(t *testing.T) {
|
||||
profileDir := t.TempDir()
|
||||
sessionLine := ""
|
||||
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("prompts:\n p:\n \"1\":\n default_profile: exec\n"+sessionLine+` messages:
|
||||
- role: user
|
||||
content: "hi"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte("prompts:\n - id: p\n default_profile: exec\n"+sessionLine+` messages:
|
||||
- role: user
|
||||
content: "hi"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`), 0o644); err != nil {
|
||||
t.Fatalf("write prompt fixture: %v", err)
|
||||
}
|
||||
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 {
|
||||
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte("profiles:\n - id: exec\n endpoint: http://127.0.0.1:1/v1\n model: test\n"), 0o644); err != nil {
|
||||
t.Fatalf("write profile fixture: %v", err)
|
||||
}
|
||||
engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, nil, promptkit.WithLLMClient(handlerLLMClient{}))
|
||||
@@ -1067,20 +1063,19 @@ func TestHandlerSharesBackendCapacityAcrossConcurrentRequests(t *testing.T) {
|
||||
promptDir := t.TempDir()
|
||||
profileDir := t.TempDir()
|
||||
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
|
||||
- id: p
|
||||
default_profile: limited
|
||||
messages:
|
||||
- role: user
|
||||
content: "hi"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`), 0o644); err != nil {
|
||||
t.Fatalf("write prompt fixture: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
|
||||
limited:
|
||||
- id: limited
|
||||
backend: limited
|
||||
model: test
|
||||
`), 0o644); err != nil {
|
||||
@@ -1088,7 +1083,7 @@ func TestHandlerSharesBackendCapacityAcrossConcurrentRequests(t *testing.T) {
|
||||
}
|
||||
queueCapacity := 0
|
||||
client := &blockingLLMClient{started: make(chan struct{}, 1), release: make(chan struct{})}
|
||||
backend := promptkit.BackendConfig{Endpoint: stringPointer("http://127.0.0.1:1/v1"), ConcurrencyLimit: intPointer(1), QueueCapacity: &queueCapacity}
|
||||
backend := promptkit.BackendConfig{ID: "limited", Endpoint: stringPointer("http://127.0.0.1:1/v1"), ConcurrencyLimit: intPointer(1), QueueCapacity: &queueCapacity}
|
||||
engine := newHandlerEngineFromDirectories(t, promptDir, profileDir, nil, &backend, promptkit.WithLLMClient(client))
|
||||
h := NewHandler(engine)
|
||||
first := httptest.NewRecorder()
|
||||
@@ -1822,21 +1817,20 @@ func newHandlerEngineWithOptions(t *testing.T, options ...promptkit.Option) *pro
|
||||
promptDir := t.TempDir()
|
||||
profileDir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(promptDir, "prompt.yaml"), []byte(`prompts:
|
||||
p:
|
||||
"1":
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: "hi"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
repair_attempts: 0
|
||||
- id: p
|
||||
default_profile: exec
|
||||
messages:
|
||||
- role: user
|
||||
content: "hi"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
repair_attempts: 0
|
||||
`), 0o644); err != nil {
|
||||
t.Fatalf("write prompt fixture: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
|
||||
exec:
|
||||
- id: exec
|
||||
endpoint: http://example.invalid/v1
|
||||
model: model
|
||||
`), 0o644); err != nil {
|
||||
@@ -1855,7 +1849,7 @@ func newDefinitionHandler(t *testing.T, definition string) *Handler {
|
||||
t.Fatalf("write prompt fixture: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(profileDir, "profile.yaml"), []byte(`profiles:
|
||||
exec:
|
||||
- id: exec
|
||||
endpoint: http://example.invalid/v1
|
||||
model: model
|
||||
`), 0o644); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user