| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "reasonix/internal/event" |
| 11 | "reasonix/internal/provider" |
| 12 | ) |
| 13 | |
| 14 | func TestMaintenanceHistoryKeepsProgressPendingUntilRuntimeSync(t *testing.T) { |
| 15 | op := event.SessionOperationInfo{ |
| 16 | OperationID: "maintenance-history", OperationRevision: 3, RuntimeEpoch: "runtime-old", |
| 17 | Kind: "compact", Activity: "running", Status: "running", InputTokens: 1200, |
| 18 | } |
| 19 | payload, err := json.Marshal(op) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | rows := historyMessages([]provider.Message{{ |
| 24 | ID: "maintenance:maintenance-history", Role: provider.Role("compaction"), Content: string(payload), |
| 25 | }}, strings.TrimSpace) |
| 26 | assertPendingMaintenanceHistory(t, rows) |
| 27 | } |
| 28 | |
| 29 | func TestPreviewMaintenanceHistoryKeepsProgressPendingUntilRuntimeSync(t *testing.T) { |
| 30 | op := event.SessionOperationInfo{ |
| 31 | OperationID: "maintenance-history", OperationRevision: 3, RuntimeEpoch: "runtime-old", |
| 32 | Kind: "compact", Activity: "running", Status: "running", InputTokens: 1200, |
| 33 | } |
| 34 | record, err := json.Marshal(previewEventRecord{Kind: "session_operation", SessionOperation: &op}) |
| 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | path := filepath.Join(t.TempDir(), "events.jsonl") |
| 39 | if err := os.WriteFile(path, append(record, '\n'), 0o600); err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | rows, ok, err := previewEventSessionMessages(path) |
| 43 | if err != nil || !ok { |
| 44 | t.Fatalf("previewEventSessionMessages = ok %v, err %v", ok, err) |
| 45 | } |
| 46 | assertPendingMaintenanceHistory(t, rows) |
| 47 | } |
| 48 | |
| 49 | func assertPendingMaintenanceHistory(t *testing.T, rows []HistoryMessage) { |
| 50 | t.Helper() |
| 51 | if len(rows) != 1 { |
| 52 | t.Fatalf("history rows = %+v", rows) |
| 53 | } |
| 54 | row := rows[0] |
| 55 | if !row.Pending || row.OperationStatus != "running" || row.OperationID != "maintenance-history" || |
| 56 | row.OperationRevision != 3 || row.RuntimeEpoch != "runtime-old" || row.InputTokens != 1200 { |
| 57 | t.Fatalf("maintenance history row = %+v", row) |
| 58 | } |
| 59 | } |
| 60 |