Verify native recovery, fallback reuse boundaries, and operator schemas

This commit is contained in:
2026-11-22 06:00:52 +00:00
parent 854d23b91e
commit 5b6854e975
3 changed files with 369 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package cli
import (
"context"
"errors"
"path/filepath"
"testing"
@@ -14,7 +15,7 @@ func TestNativeLoadPreparesOperatorSchemaSelections(t *testing.T) {
name, schema, root string
missing bool
}{
{"inline", "schema: {type: object}", "", false},
{"inline", `schema: {type: object, required: [operator_value], properties: {operator_value: {const: selected}}, additionalProperties: false}`, "", false},
{"source file", "schema_file: response.json", "", false},
{"external root", "schema_path: response.json", "schema_root: external-schemas", false},
{"replaced root missing embedded schema", "schema_path: dnd/scenes/schemas/dnd_scenes_llm.v1.json", "schema_root: external-schemas", true},
@@ -23,10 +24,18 @@ func TestNativeLoadPreparesOperatorSchemaSelections(t *testing.T) {
dir := t.TempDir()
main := filepath.Join(dir, "config.yml")
writeConfigKitFile(t, main, "version: 6\n")
writeConfigKitFile(t, filepath.Join(dir, "response.json"), `{"type":"object"}`)
writeConfigKitFile(t, filepath.Join(dir, "external-schemas", "response.json"), `{"type":"object"}`)
schema := `{"type":"object","required":["operator_value"],"properties":{"operator_value":{"const":"selected"}},"additionalProperties":false}`
writeConfigKitFile(t, filepath.Join(dir, "response.json"), schema)
writeConfigKitFile(t, filepath.Join(dir, "external-schemas", "response.json"), schema)
writeConfigKitFile(t, filepath.Join(dir, "prompts.yml"), "collections:\n notarius:\n "+test.root+"\n prompts:\n - id: dnd.scenes\n default_profile: notarius/dnd-extraction\n messages: [{role: user, content: operator-message}]\n output:\n format: json\n validation_mode: json_schema\n "+test.schema+"\n")
loaders := &nativeLoaders{}
calls := 0
loaders := &nativeLoaders{engineOptions: []promptkit.Option{promptkit.WithLLMClient(captureClient(func(_ context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
calls++
if !productionSchemaHasProperty(request, "operator_value") {
return nil, errors.New("operator schema did not reach provider preparation")
}
return &promptkit.GenerateResponse{Content: `{"operator_value":"selected"}`}, nil
}))}}
engine, err := loaders.engine(context.Background(), nativeSelection(main))
if err != nil {
t.Fatal(err)
@@ -48,6 +57,10 @@ func TestNativeLoadPreparesOperatorSchemaSelections(t *testing.T) {
if len(details.Messages) != 1 || details.Messages[0].Content != "operator-message" || details.StructuredOutput == nil {
t.Fatalf("replacement contract = %#v", details)
}
result, err := engine.RunPrepared(context.Background(), prepared)
if err != nil || result == nil || !result.Validation.IsValid || calls != 1 {
t.Fatalf("operator contract execution=%#v error=%v calls=%d", result, err, calls)
}
// Replacing one identified prompt must not discard unrelated embedded prompts.
if _, err := engine.InspectPrompt(context.Background(), "notarius/dnd.spells"); err != nil {
t.Fatal(err)