| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "reasonix/internal/completion" |
| 6 | "reasonix/internal/evidence" |
| 7 | "reasonix/internal/plancontract" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func completeStepReceipt(t *testing.T, criterionID, kind, command string) evidence.Receipt { |
| 12 | t.Helper() |
| 13 | args, err := json.Marshal(map[string]any{ |
| 14 | "step": "do it", |
| 15 | "result": "done", |
| 16 | "evidence": []map[string]any{ |
| 17 | {"kind": kind, "summary": "proved it", "command": command, "criterion_id": criterionID}, |
| 18 | }, |
| 19 | }) |
| 20 | if err != nil { |
| 21 | t.Fatalf("marshal: %v", err) |
| 22 | } |
| 23 | return evidence.Receipt{ToolName: "complete_step", Success: true, Step: "do it", Args: args} |
| 24 | } |
| 25 | |
| 26 | func criterionPlan() plancontract.Plan { |
| 27 | return plancontract.Plan{ |
| 28 | Objective: "fix the retry race", |
| 29 | Steps: []plancontract.Step{{ |
| 30 | Title: "fix it", |
| 31 | Acceptance: []plancontract.Criterion{ |
| 32 | {Text: "retries no longer double-charge"}, |
| 33 | {Text: "existing payment tests keep passing", Regression: true}, |
| 34 | }, |
| 35 | }}, |
| 36 | }.Normalize() |
| 37 | } |
| 38 | |
| 39 | func TestCriterionClaimDoesNotCertifyFailedExecution(t *testing.T) { |
| 40 | ledger := evidence.NewLedger() |
| 41 | ledger.Record(evidence.Receipt{ToolName: "bash", Command: "go test ./...", Success: false}) |
| 42 | ledger.Record(completeStepReceipt(t, "c1", "verification", "go test ./...")) |
| 43 | report := completion.BuildFacts(ledger, "", nil) |
| 44 | if report.Verdict != completion.VerdictUnknown || len(report.Verifications) != 1 || report.Verifications[0].Passed { |
| 45 | t.Fatalf("claim altered facts: %+v", report) |
| 46 | } |
| 47 | } |
| 48 |