| 1 | package completion |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/evidence" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestVerificationResultUsesExitCodeAndSourceCall(t *testing.T) { |
| 9 | code := 1 |
| 10 | ledger := evidence.NewLedger() |
| 11 | ledger.Record(evidence.Receipt{ToolName: "bash", ToolCallID: "check-1", Command: "go test ./...", Success: true, ExitCode: &code, Verification: evidence.VerificationFailed}) |
| 12 | report := Build(nil, ledger) |
| 13 | if len(report.Verifications) != 1 || report.Verifications[0].Passed || report.Verifications[0].ToolCallID != "check-1" || *report.Verifications[0].ExitCode != 1 { |
| 14 | t.Fatalf("result: %+v", report.Verifications) |
| 15 | } |
| 16 | zero := 0 |
| 17 | ledger.Record(evidence.Receipt{ToolName: "bash", ToolCallID: "check-2", Command: "go test ./...", Success: true, ExitCode: &zero, Verification: evidence.VerificationPassed}) |
| 18 | report = Build(nil, ledger) |
| 19 | if len(report.Verifications) != 1 || !report.Verifications[0].Passed || report.Verifications[0].ToolCallID != "check-2" { |
| 20 | t.Fatalf("latest result: %+v", report.Verifications) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestVerificationResultOmitsUnexecutedCallsAndPreservesInterruption(t *testing.T) { |
| 25 | for _, classification := range []string{evidence.VerificationNotRun, evidence.VerificationNotVerification} { |
| 26 | ledger := evidence.NewLedger() |
| 27 | ledger.Record(evidence.Receipt{ToolName: "bash", Command: "go test ./...", Verification: classification, Success: true}) |
| 28 | if got := Build(nil, ledger).Verifications; len(got) != 0 { |
| 29 | t.Fatalf("%s counted: %+v", classification, got) |
| 30 | } |
| 31 | } |
| 32 | ledger := evidence.NewLedger() |
| 33 | ledger.Record(evidence.Receipt{ToolName: "bash", Command: "go test ./...", Verification: evidence.VerificationFailed, Interrupted: true}) |
| 34 | if got := Build(nil, ledger).Verifications; len(got) != 1 || !got[0].Interrupted || got[0].Passed { |
| 35 | t.Fatalf("interruption: %+v", got) |
| 36 | } |
| 37 | } |
| 38 |