Keep prompt selection free of schema payloads

This commit is contained in:
2026-11-20 16:20:27 +00:00
parent 1bfb6eb301
commit 2c436d14d9
6 changed files with 30 additions and 6 deletions

View File

@@ -73,7 +73,7 @@ func TestPromptResolutionNormalizesOutputAndRejectsDuplicateNames(t *testing.T)
t.Fatal(err)
}
selected, inspection, err := state.prompt("example")
if err != nil || selected.Validation.SchemaPath != "schema.json" || inspection.OutputContract.SchemaPath != "schema.json" || selected.Inputs[0].Name != "document" {
if err != nil || selected.Validation.SchemaPath != "schema.json" || selected.Inputs[0].Name != "document" {
t.Fatalf("interpreted prompt = %+v, %+v, %v", selected, inspection, err)
}
composed := state.result.Config.Prompts[0]

View File

@@ -147,7 +147,6 @@ func (state *loaded) materializePrompt(id string, raw promptConfig, base configk
entry.inspection = domain.PromptInspection{
PromptID: id, PromptHash: hash,
DefaultProfileID: definition.DefaultProfile, Inputs: append([]domain.PromptInput(nil), definition.Inputs...),
OutputContract: contract,
}
return entry, nil
}
@@ -349,7 +348,6 @@ func ownPromptDefinition(definition domain.PromptDefinition) *domain.PromptDefin
}
func ownPromptInspection(inspection domain.PromptInspection) *domain.PromptInspection {
inspection.OutputContract = ownOutputContract(inspection.OutputContract)
inspection.Inputs = append([]domain.PromptInput(nil), inspection.Inputs...)
return &inspection
}

View File

@@ -14,6 +14,28 @@ func schemaPrompt(id string, output map[string]any) map[string]any {
return map[string]any{"id": id, "messages": []any{map[string]any{"role": "user", "content": "hello"}}, "output": output}
}
func TestLightweightPromptSelectionKeepsSchemaInResourceView(t *testing.T) {
schema := map[string]any{"type": "object", "examples": make([]any, 1024)}
definition := schemaPrompt("selected", map[string]any{"format": "json", "validation_mode": "json_schema", "schema": schema})
definition["default_profile"] = "partial"
state, err := load(mapping("selection", map[string]any{
"profiles": []any{map[string]any{"id": "partial"}},
"prompts": []any{definition},
}), nil)
if err != nil {
t.Fatal(err)
}
selection, err := state.GetPromptInspection(context.Background(), "selected")
if err != nil || selection.PromptID != "selected" || selection.DefaultProfileID != "partial" {
t.Fatalf("selection = %+v, %v", selection, err)
}
// The selection type has no output contract; the full resource view still does.
resource, err := state.InspectPrompt(context.Background(), "selected")
if err != nil || resource.Output.Schema.(map[string]any)["type"] != "object" {
t.Fatalf("resource schema = %+v, %v", resource, err)
}
}
func TestSchemaFileCaptureUsesEffectiveSource(t *testing.T) {
first := configkit.NewFilesystem("first", fstest.MapFS{"a/placeholder": {Data: []byte("x")}, "a/schema.json": {Data: []byte("first")}})
second := configkit.NewFilesystem("second", fstest.MapFS{"b/placeholder": {Data: []byte("x")}, "b/schema.json": {Data: []byte("second")}})