Add module correction repair prompts

This commit is contained in:
2026-11-11 04:13:55 +00:00
parent bb81354e21
commit eb45d0b623
17 changed files with 236 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ import (
"encoding/json"
"io"
"testing"
jsonschema "github.com/santhosh-tekuri/jsonschema/v6"
)
func TestPromptKitSchemaPathsUseCanonicalAssets(t *testing.T) {
@@ -132,3 +134,41 @@ func TestDiagnosticsMapIncludesStableSchemaMetadataShapeForAllSchemas(t *testing
}
}
}
func TestCorrectionRepairSchema(t *testing.T) {
var document any
if err := json.Unmarshal(MustLookup(CorrectionRepairKey).JSONSchema, &document); err != nil {
t.Fatal(err)
}
compiler := jsonschema.NewCompiler()
if err := compiler.AddResource("repair.json", document); err != nil {
t.Fatal(err)
}
schema, err := compiler.Compile("repair.json")
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name, content string
valid bool
}{
{"delete whitespace", `{"proposal_ref":1,"action":"revise","correction":{"id":1,"original_text":" ","corrected_text":"","confidence":0}}`, true},
{"withdraw", `{"proposal_ref":1,"action":"withdraw","correction":null}`, true},
{"missing correction", `{"proposal_ref":1,"action":"withdraw"}`, false},
{"extra field", `{"proposal_ref":1,"action":"withdraw","correction":null,"extra":1}`, false},
{"zero reference", `{"proposal_ref":0,"action":"withdraw","correction":null}`, false},
{"unknown action", `{"proposal_ref":1,"action":"other","correction":null}`, false},
{"empty original", `{"proposal_ref":1,"action":"revise","correction":{"id":1,"original_text":"","corrected_text":"x","confidence":1}}`, false},
{"confidence outside range", `{"proposal_ref":1,"action":"revise","correction":{"id":1,"original_text":"x","corrected_text":"y","confidence":2}}`, false},
} {
t.Run(tc.name, func(t *testing.T) {
var value any
if err := json.Unmarshal([]byte(tc.content), &value); err != nil {
t.Fatal(err)
}
if err := schema.Validate(value); (err == nil) != tc.valid {
t.Fatalf("validation = %v", err)
}
})
}
}