| 1 | package evidence |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func readReceipt(path string) Receipt { |
| 9 | return ReceiptFromToolCall("read_file", json.RawMessage(`{"path":"`+path+`"}`), true, true) |
| 10 | } |
| 11 | |
| 12 | func bashReceipt(command string, success bool) Receipt { |
| 13 | args, _ := json.Marshal(map[string]string{"command": command}) |
| 14 | return ReceiptFromToolCall("bash", args, success, false) |
| 15 | } |
| 16 | |
| 17 | func TestProgressTrackerScoresNewVsRepeatedEvidence(t *testing.T) { |
| 18 | tr := NewProgressTracker() |
| 19 | |
| 20 | first := readReceipt("a.go") |
| 21 | first.OutputBytes = 10 |
| 22 | if got := tr.ScoreRound([]Receipt{first}); got != gainNewRead { |
| 23 | t.Fatalf("new read gain = %d, want %d", got, gainNewRead) |
| 24 | } |
| 25 | repeat := readReceipt("a.go") |
| 26 | repeat.OutputBytes = 10 |
| 27 | if got := tr.ScoreRound([]Receipt{repeat}); got != 0 { |
| 28 | t.Fatalf("repeated read gain = %d, want 0", got) |
| 29 | } |
| 30 | |
| 31 | if got := tr.ScoreRound([]Receipt{bashReceipt("go test ./x", false)}); got != gainNewFailure { |
| 32 | t.Fatalf("first failure gain = %d, want %d (a new error localizes)", got, gainNewFailure) |
| 33 | } |
| 34 | if got := tr.ScoreRound([]Receipt{bashReceipt("go test ./x", false)}); got != gainRepeatFailure { |
| 35 | t.Fatalf("same failure gain = %d, want %d", got, gainRepeatFailure) |
| 36 | } |
| 37 | if got := tr.ScoreRound([]Receipt{bashReceipt("go test ./x", true)}); got != gainStateChange { |
| 38 | t.Fatalf("failure→pass gain = %d, want %d", got, gainStateChange) |
| 39 | } |
| 40 | if got := tr.ScoreRound([]Receipt{bashReceipt("go test ./x", true)}); got != 0 { |
| 41 | t.Fatalf("repeated passing command gain = %d, want 0", got) |
| 42 | } |
| 43 | |
| 44 | write := ReceiptFromToolCall("write_file", json.RawMessage(`{"path":"b.go","content":"x"}`), true, false) |
| 45 | if got := tr.ScoreRound([]Receipt{write}); got != gainMutation { |
| 46 | t.Fatalf("mutation gain = %d, want %d", got, gainMutation) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestLedgerReceiptsSince(t *testing.T) { |
| 51 | l := &Ledger{} |
| 52 | l.Record(bashReceipt("one", true)) |
| 53 | l.Record(bashReceipt("two", true)) |
| 54 | if got := len(l.ReceiptsSince(1)); got != 1 { |
| 55 | t.Fatalf("receipts since 1 = %d, want 1", got) |
| 56 | } |
| 57 | if got := l.ReceiptsSince(5); got != nil { |
| 58 | t.Fatalf("out-of-range mark must yield nil, got %v", got) |
| 59 | } |
| 60 | var nilLedger *Ledger |
| 61 | if got := nilLedger.ReceiptsSince(0); got != nil { |
| 62 | t.Fatalf("nil ledger must yield nil") |
| 63 | } |
| 64 | } |
| 65 |