gsd-pi 2.44.0-dev.62b5d6c → 2.44.0-dev.a5271fc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +30 -12
  2. package/dist/resources/extensions/gsd/auto-start.js +10 -0
  3. package/dist/resources/extensions/gsd/bootstrap/system-context.js +46 -12
  4. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +5 -0
  5. package/dist/resources/extensions/gsd/preferences.js +9 -1
  6. package/dist/resources/extensions/gsd/state.js +19 -2
  7. package/dist/web/standalone/.next/BUILD_ID +1 -1
  8. package/dist/web/standalone/.next/app-path-routes-manifest.json +19 -19
  9. package/dist/web/standalone/.next/build-manifest.json +2 -2
  10. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  11. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  12. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  13. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  16. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  17. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  18. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  19. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  20. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/index.html +1 -1
  28. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app-paths-manifest.json +19 -19
  35. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  36. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  37. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  38. package/package.json +1 -1
  39. package/packages/pi-coding-agent/dist/core/auth-storage.test.js +6 -8
  40. package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
  41. package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +24 -26
  42. package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
  43. package/packages/pi-coding-agent/dist/core/fs-utils.test.js +29 -48
  44. package/packages/pi-coding-agent/dist/core/fs-utils.test.js.map +1 -1
  45. package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js +34 -44
  46. package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js.map +1 -1
  47. package/packages/pi-coding-agent/dist/core/session-manager.test.js +30 -34
  48. package/packages/pi-coding-agent/dist/core/session-manager.test.js.map +1 -1
  49. package/packages/pi-coding-agent/dist/core/tools/edit-diff.test.js +10 -12
  50. package/packages/pi-coding-agent/dist/core/tools/edit-diff.test.js.map +1 -1
  51. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.js +43 -47
  52. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.test.js.map +1 -1
  53. package/packages/pi-coding-agent/src/core/auth-storage.test.ts +7 -7
  54. package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +26 -26
  55. package/packages/pi-coding-agent/src/core/fs-utils.test.ts +31 -43
  56. package/packages/pi-coding-agent/src/core/resolve-config-value.test.ts +40 -45
  57. package/packages/pi-coding-agent/src/core/session-manager.test.ts +33 -33
  58. package/packages/pi-coding-agent/src/core/tools/edit-diff.test.ts +17 -17
  59. package/packages/pi-coding-agent/src/resources/extensions/memory/storage.test.ts +74 -74
  60. package/src/resources/extensions/gsd/auto-start.ts +14 -0
  61. package/src/resources/extensions/gsd/bootstrap/system-context.ts +48 -11
  62. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +8 -0
  63. package/src/resources/extensions/gsd/preferences.ts +11 -1
  64. package/src/resources/extensions/gsd/state.ts +19 -1
  65. package/src/resources/extensions/gsd/tests/all-milestones-complete-merge.test.ts +99 -99
  66. package/src/resources/extensions/gsd/tests/auto-lock-creation.test.ts +14 -16
  67. package/src/resources/extensions/gsd/tests/auto-paused-session-validation.test.ts +43 -57
  68. package/src/resources/extensions/gsd/tests/auto-preflight.test.ts +11 -13
  69. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +465 -523
  70. package/src/resources/extensions/gsd/tests/auto-secrets-gate.test.ts +73 -75
  71. package/src/resources/extensions/gsd/tests/auto-start-needs-discussion.test.ts +34 -56
  72. package/src/resources/extensions/gsd/tests/auto-worktree-milestone-merge.test.ts +533 -656
  73. package/src/resources/extensions/gsd/tests/auto-worktree.test.ts +165 -143
  74. package/src/resources/extensions/gsd/tests/cache-staleness-regression.test.ts +29 -52
  75. package/src/resources/extensions/gsd/tests/captures.test.ts +148 -176
  76. package/src/resources/extensions/gsd/tests/claude-import-tui.test.ts +32 -33
  77. package/src/resources/extensions/gsd/tests/collect-from-manifest.test.ts +141 -143
  78. package/src/resources/extensions/gsd/tests/commands-inspect-open-db.test.ts +25 -25
  79. package/src/resources/extensions/gsd/tests/commands-logs.test.ts +81 -81
  80. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +38 -59
  81. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +228 -263
  82. package/src/resources/extensions/gsd/tests/complete-task.test.ts +250 -302
  83. package/src/resources/extensions/gsd/tests/context-store.test.ts +354 -367
  84. package/src/resources/extensions/gsd/tests/continue-here.test.ts +68 -72
  85. package/src/resources/extensions/gsd/tests/cost-projection.test.ts +92 -106
  86. package/src/resources/extensions/gsd/tests/crash-recovery.test.ts +27 -35
  87. package/src/resources/extensions/gsd/tests/dashboard-budget.test.ts +220 -237
  88. package/src/resources/extensions/gsd/tests/db-writer.test.ts +390 -420
  89. package/src/resources/extensions/gsd/tests/definition-loader.test.ts +76 -92
  90. package/src/resources/extensions/gsd/tests/derive-state-crossval.test.ts +68 -83
  91. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +183 -181
  92. package/src/resources/extensions/gsd/tests/derive-state-deps.test.ts +78 -101
  93. package/src/resources/extensions/gsd/tests/derive-state.test.ts +192 -227
  94. package/src/resources/extensions/gsd/tests/detection.test.ts +232 -278
  95. package/src/resources/extensions/gsd/tests/dev-engine-wrapper.test.ts +30 -34
  96. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +164 -180
  97. package/src/resources/extensions/gsd/tests/dispatch-missing-task-plans.test.ts +43 -49
  98. package/src/resources/extensions/gsd/tests/dispatch-uat-last-completed.test.ts +28 -32
  99. package/src/resources/extensions/gsd/tests/doctor-completion-deferral.test.ts +27 -29
  100. package/src/resources/extensions/gsd/tests/doctor-delimiter-fix.test.ts +34 -38
  101. package/src/resources/extensions/gsd/tests/doctor-enhancements.test.ts +54 -75
  102. package/src/resources/extensions/gsd/tests/doctor-environment-worktree.test.ts +21 -32
  103. package/src/resources/extensions/gsd/tests/doctor-environment.test.ts +72 -97
  104. package/src/resources/extensions/gsd/tests/doctor-fixlevel.test.ts +38 -44
  105. package/src/resources/extensions/gsd/tests/doctor-git.test.ts +104 -145
  106. package/src/resources/extensions/gsd/tests/doctor-proactive.test.ts +84 -106
  107. package/src/resources/extensions/gsd/tests/doctor-roadmap-summary-atomicity.test.ts +54 -60
  108. package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +72 -93
  109. package/src/resources/extensions/gsd/tests/doctor.test.ts +104 -134
  110. package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +123 -131
  111. package/src/resources/extensions/gsd/tests/exit-command.test.ts +20 -24
  112. package/src/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +48 -57
  113. package/src/resources/extensions/gsd/tests/files-loadfile-eisdir.test.ts +5 -7
  114. package/src/resources/extensions/gsd/tests/flag-file-db.test.ts +30 -42
  115. package/src/resources/extensions/gsd/tests/freeform-decisions.test.ts +198 -206
  116. package/src/resources/extensions/gsd/tests/git-locale.test.ts +13 -27
  117. package/src/resources/extensions/gsd/tests/git-service.test.ts +285 -388
  118. package/src/resources/extensions/gsd/tests/gitignore-tracked-gsd.test.ts +31 -39
  119. package/src/resources/extensions/gsd/tests/graph-operations.test.ts +63 -69
  120. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +255 -264
  121. package/src/resources/extensions/gsd/tests/gsd-inspect.test.ts +108 -119
  122. package/src/resources/extensions/gsd/tests/gsd-recover.test.ts +81 -103
  123. package/src/resources/extensions/gsd/tests/gsd-tools.test.ts +229 -262
  124. package/src/resources/extensions/gsd/tests/headless-answers.test.ts +13 -13
  125. package/src/resources/extensions/gsd/tests/health-widget.test.ts +29 -37
  126. package/src/resources/extensions/gsd/tests/idle-recovery.test.ts +81 -102
  127. package/src/resources/extensions/gsd/tests/init-wizard.test.ts +16 -18
  128. package/src/resources/extensions/gsd/tests/integration-edge.test.ts +41 -46
  129. package/src/resources/extensions/gsd/tests/integration-lifecycle.test.ts +42 -53
  130. package/src/resources/extensions/gsd/tests/integration-mixed-milestones.test.ts +75 -91
  131. package/src/resources/extensions/gsd/tests/integration-proof.test.ts +18 -18
  132. package/src/resources/extensions/gsd/tests/knowledge.test.ts +89 -0
  133. package/src/resources/extensions/gsd/tests/markdown-renderer.test.ts +150 -194
  134. package/src/resources/extensions/gsd/tests/md-importer.test.ts +101 -125
  135. package/src/resources/extensions/gsd/tests/memory-extractor.test.ts +45 -54
  136. package/src/resources/extensions/gsd/tests/memory-store.test.ts +80 -93
  137. package/src/resources/extensions/gsd/tests/migrate-command.test.ts +57 -66
  138. package/src/resources/extensions/gsd/tests/migrate-hierarchy.test.ts +83 -93
  139. package/src/resources/extensions/gsd/tests/migrate-parser.test.ts +161 -170
  140. package/src/resources/extensions/gsd/tests/migrate-transformer.test.ts +125 -141
  141. package/src/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +107 -131
  142. package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +87 -96
  143. package/src/resources/extensions/gsd/tests/migrate-writer.test.ts +125 -164
  144. package/src/resources/extensions/gsd/tests/must-have-parser.test.ts +81 -94
  145. package/src/resources/extensions/gsd/tests/none-mode-gates.test.ts +35 -36
  146. package/src/resources/extensions/gsd/tests/overrides.test.ts +99 -106
  147. package/src/resources/extensions/gsd/tests/parallel-crash-recovery.test.ts +40 -47
  148. package/src/resources/extensions/gsd/tests/parallel-worker-monitoring.test.ts +25 -28
  149. package/src/resources/extensions/gsd/tests/parallel-workers-multi-milestone-e2e.test.ts +66 -83
  150. package/src/resources/extensions/gsd/tests/park-edge-cases.test.ts +54 -77
  151. package/src/resources/extensions/gsd/tests/park-milestone.test.ts +68 -115
  152. package/src/resources/extensions/gsd/tests/parsers.test.ts +546 -611
  153. package/src/resources/extensions/gsd/tests/paths.test.ts +72 -87
  154. package/src/resources/extensions/gsd/tests/post-unit-hooks.test.ts +77 -117
  155. package/src/resources/extensions/gsd/tests/preferences.test.ts +27 -0
  156. package/src/resources/extensions/gsd/tests/prompt-db.test.ts +56 -56
  157. package/src/resources/extensions/gsd/tests/queue-draft-detection.test.ts +93 -119
  158. package/src/resources/extensions/gsd/tests/queue-order.test.ts +70 -82
  159. package/src/resources/extensions/gsd/tests/queue-reorder-e2e.test.ts +42 -55
  160. package/src/resources/extensions/gsd/tests/quick-auto-guard.test.ts +100 -0
  161. package/src/resources/extensions/gsd/tests/quick-branch-lifecycle.test.ts +45 -73
  162. package/src/resources/extensions/gsd/tests/reassess-prompt.test.ts +28 -38
  163. package/src/resources/extensions/gsd/tests/replan-slice.test.ts +73 -80
  164. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +71 -74
  165. package/src/resources/extensions/gsd/tests/requirements.test.ts +70 -75
  166. package/src/resources/extensions/gsd/tests/retry-state-reset.test.ts +44 -66
  167. package/src/resources/extensions/gsd/tests/roadmap-parse-regression.test.ts +114 -181
  168. package/src/resources/extensions/gsd/tests/rule-registry.test.ts +63 -65
  169. package/src/resources/extensions/gsd/tests/run-uat.test.ts +66 -128
  170. package/src/resources/extensions/gsd/tests/session-lock-multipath.test.ts +18 -25
  171. package/src/resources/extensions/gsd/tests/session-lock-regression.test.ts +37 -44
  172. package/src/resources/extensions/gsd/tests/shared-wal.test.ts +19 -26
  173. package/src/resources/extensions/gsd/tests/sqlite-unavailable-gate.test.ts +63 -0
  174. package/src/resources/extensions/gsd/tests/stalled-tool-recovery.test.ts +6 -8
  175. package/src/resources/extensions/gsd/tests/symlink-numbered-variants.test.ts +22 -28
  176. package/src/resources/extensions/gsd/tests/token-savings.test.ts +54 -56
  177. package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +23 -25
  178. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +9 -11
  179. package/src/resources/extensions/gsd/tests/unique-milestone-ids.test.ts +66 -82
  180. package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +46 -47
  181. package/src/resources/extensions/gsd/tests/visualizer-critical-path.test.ts +20 -22
  182. package/src/resources/extensions/gsd/tests/visualizer-data.test.ts +84 -86
  183. package/src/resources/extensions/gsd/tests/visualizer-overlay.test.ts +41 -43
  184. package/src/resources/extensions/gsd/tests/visualizer-views.test.ts +94 -96
  185. package/src/resources/extensions/gsd/tests/windows-path-normalization.test.ts +11 -13
  186. package/src/resources/extensions/gsd/tests/worker-registry.test.ts +27 -29
  187. package/src/resources/extensions/gsd/tests/workflow-templates.test.ts +50 -52
  188. package/src/resources/extensions/gsd/tests/worktree-bugfix.test.ts +10 -13
  189. package/src/resources/extensions/gsd/tests/worktree-db-integration.test.ts +14 -18
  190. package/src/resources/extensions/gsd/tests/worktree-db.test.ts +38 -39
  191. package/src/resources/extensions/gsd/tests/worktree-e2e.test.ts +17 -21
  192. package/src/resources/extensions/gsd/tests/worktree-health.test.ts +25 -30
  193. package/src/resources/extensions/gsd/tests/worktree-integration.test.ts +30 -37
  194. package/src/resources/extensions/gsd/tests/worktree-symlink-removal.test.ts +15 -22
  195. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +59 -66
  196. package/src/resources/extensions/gsd/tests/worktree.test.ts +44 -50
  197. /package/dist/web/standalone/.next/static/{fOnWQBjWXMKUs4bqTg530 → JyimLR2pZuvKEzv26gI3w}/_buildManifest.js +0 -0
  198. /package/dist/web/standalone/.next/static/{fOnWQBjWXMKUs4bqTg530 → JyimLR2pZuvKEzv26gI3w}/_ssgManifest.js +0 -0
@@ -1,3 +1,5 @@
1
+ import { describe, test } from 'node:test';
2
+ import assert from 'node:assert/strict';
1
3
  /**
2
4
  * Tests for dashboard budget indicator rendering.
3
5
  *
@@ -18,10 +20,6 @@ import {
18
20
  getProjectTotals,
19
21
  formatTokenCount,
20
22
  } from "../metrics.js";
21
- import { createTestContext } from './test-helpers.ts';
22
-
23
- const { assertEq, assertTrue, assertMatch, assertNoMatch, report } = createTestContext();
24
-
25
23
  // ─── Test helpers ─────────────────────────────────────────────────────────────
26
24
 
27
25
  function makeUnit(overrides: Partial<UnitMetrics> = {}): UnitMetrics {
@@ -102,245 +100,230 @@ function renderModelContextWindow(units: UnitMetrics[], modelName: string): stri
102
100
 
103
101
  // ─── Completed section: budget indicators ─────────────────────────────────────
104
102
 
105
- console.log("\n=== Completed section: truncation + continue-here markers ===");
106
-
107
- {
108
- // Unit with truncation and continue-here — both markers appear
109
- const ledgerUnits = [
110
- makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 3, continueHereFired: true }),
111
- ];
112
- const markers = renderCompletedBudgetMarkers(
113
- { type: "execute-task", id: "M001/S01/T01" },
114
- ledgerUnits,
115
- );
116
- assertMatch(markers, /▼3/, "completed: shows ▼3 for 3 truncation sections");
117
- assertMatch(markers, /→ wrap-up/, "completed: shows → wrap-up when continueHereFired");
118
- }
119
-
120
- {
121
- // Unit with truncation only — no wrap-up marker
122
- const ledgerUnits = [
123
- makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 5, continueHereFired: false }),
124
- ];
125
- const markers = renderCompletedBudgetMarkers(
126
- { type: "execute-task", id: "M001/S01/T01" },
127
- ledgerUnits,
128
- );
129
- assertMatch(markers, /▼5/, "completed: shows ▼5 truncation only");
130
- assertNoMatch(markers, /wrap-up/, "completed: no wrap-up when continueHereFired=false");
131
- }
132
-
133
- {
134
- // Unit with continue-here only — no truncation marker
135
- const ledgerUnits = [
136
- makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 0, continueHereFired: true }),
137
- ];
138
- const markers = renderCompletedBudgetMarkers(
139
- { type: "execute-task", id: "M001/S01/T01" },
140
- ledgerUnits,
141
- );
142
- assertNoMatch(markers, /▼/, "completed: no ▼ when truncationSections=0");
143
- assertMatch(markers, /→ wrap-up/, "completed: shows → wrap-up");
144
- }
145
-
146
- // ─── Completed section: missing ledger match ──────────────────────────────────
147
-
148
- console.log("\n=== Completed section: missing ledger match ===");
149
-
150
- {
151
- // Completed unit with no matching ledger entry — no crash, no markers
152
- const ledgerUnits = [
153
- makeUnit({ type: "execute-task", id: "M001/S01/T99", truncationSections: 3 }),
154
- ];
155
- const markers = renderCompletedBudgetMarkers(
156
- { type: "execute-task", id: "M001/S01/T01" },
157
- ledgerUnits,
158
- );
159
- assertEq(markers, "", "missing match: empty markers when no ledger entry matches");
160
- }
161
-
162
- {
163
- // Empty ledger — no crash, no markers
164
- const markers = renderCompletedBudgetMarkers(
165
- { type: "execute-task", id: "M001/S01/T01" },
166
- [],
167
- );
168
- assertEq(markers, "", "empty ledger: empty markers");
169
- }
170
-
171
- // ─── Completed section: retry handling (last entry wins) ──────────────────────
172
-
173
- console.log("\n=== Completed section: retry handling ===");
174
-
175
- {
176
- // Two ledger entries for same unit (retry) — last entry wins
177
- const ledgerUnits = [
178
- makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 1 }),
179
- makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 7 }),
180
- ];
181
- const markers = renderCompletedBudgetMarkers(
182
- { type: "execute-task", id: "M001/S01/T01" },
183
- ledgerUnits,
184
- );
185
- assertMatch(markers, /▼7/, "retry: last entry's truncation count (7) wins over first (1)");
186
- assertNoMatch(markers, /▼1/, "retry: first entry's count (1) is not shown");
187
- }
188
-
189
- // ─── By Model section: context window display ─────────────────────────────────
190
-
191
- console.log("\n=== By Model section: context window ===");
192
-
193
- {
194
- // Model with context window — shows formatted token count
195
- const units = [
196
- makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000 }),
197
- ];
198
- const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
199
- assertEq(label, "[200.0k]", "by model: shows [200.0k] for 200000 context window");
200
- }
201
-
202
- {
203
- // Model without context window — no label
204
- const units = [
205
- makeUnit({ model: "claude-sonnet-4-20250514" }),
206
- ];
207
- const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
208
- assertEq(label, null, "by model: null when no contextWindowTokens");
209
- }
210
-
211
- {
212
- // Multiple models — each gets its own context window
213
- const units = [
214
- makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000, cost: 0.05 }),
215
- makeUnit({ model: "claude-opus-4-20250514", contextWindowTokens: 200000, cost: 0.30 }),
216
- ];
217
- const sonnetLabel = renderModelContextWindow(units, "claude-sonnet-4-20250514");
218
- const opusLabel = renderModelContextWindow(units, "claude-opus-4-20250514");
219
- assertEq(sonnetLabel, "[200.0k]", "by model multi: sonnet has context window");
220
- assertEq(opusLabel, "[200.0k]", "by model multi: opus has context window");
221
- }
222
-
223
- // ─── By Model section: single model visibility ───────────────────────────────
224
-
225
- console.log("\n=== By Model section: single model visibility ===");
226
-
227
- {
228
- // With guard changed to >= 1, single model aggregation should produce results
229
- const units = [
230
- makeUnit({ model: "claude-sonnet-4-20250514" }),
231
- ];
232
- const models = aggregateByModel(units);
233
- assertTrue(models.length >= 1, "single model: aggregateByModel returns >= 1 entry");
234
- assertEq(models.length, 1, "single model: exactly 1 model aggregate");
235
- assertEq(models[0].model, "claude-sonnet-4-20250514", "single model: correct model name");
236
- // The guard `models.length >= 1` (changed from > 1) means this section now renders
237
- assertTrue(models.length >= 1, "single model: passes >= 1 guard (section will render)");
238
- }
239
-
240
- // ─── Cost & Usage: aggregate budget line ──────────────────────────────────────
241
-
242
- console.log("\n=== Cost & Usage: aggregate budget line ===");
243
-
244
- {
245
- // Units with truncation and continue-here — both stats appear
246
- const units = [
247
- makeUnit({ truncationSections: 3, continueHereFired: true }),
248
- makeUnit({ truncationSections: 2, continueHereFired: false }),
249
- makeUnit({ truncationSections: 1, continueHereFired: true }),
250
- ];
251
- const line = renderCostBudgetLine(units);
252
- assertTrue(line !== null, "cost budget: line rendered when budget data exists");
253
- assertMatch(line!, /6 sections truncated/, "cost budget: shows total truncation count (3+2+1=6)");
254
- assertMatch(line!, /2 continue-here fired/, "cost budget: shows continue-here count");
255
- }
103
+ describe('dashboard-budget', () => {
104
+ test('Completed section: truncation + continue-here markers', () => {
105
+ // Unit with truncation and continue-here — both markers appear
106
+ const ledgerUnits = [
107
+ makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 3, continueHereFired: true }),
108
+ ];
109
+ const markers = renderCompletedBudgetMarkers(
110
+ { type: "execute-task", id: "M001/S01/T01" },
111
+ ledgerUnits,
112
+ );
113
+ assert.match(markers, /▼3/, "completed: shows ▼3 for 3 truncation sections");
114
+ assert.match(markers, /→ wrap-up/, "completed: shows wrap-up when continueHereFired");
115
+ });
116
+
117
+ {
118
+ // Unit with truncation only — no wrap-up marker
119
+ const ledgerUnits = [
120
+ makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 5, continueHereFired: false }),
121
+ ];
122
+ const markers = renderCompletedBudgetMarkers(
123
+ { type: "execute-task", id: "M001/S01/T01" },
124
+ ledgerUnits,
125
+ );
126
+ assert.match(markers, /▼5/, "completed: shows ▼5 truncation only");
127
+ assert.doesNotMatch(markers, /wrap-up/, "completed: no wrap-up when continueHereFired=false");
128
+ }
256
129
 
257
- {
258
- // Only truncation, no continue-here
259
- const units = [
260
- makeUnit({ truncationSections: 4, continueHereFired: false }),
261
- ];
262
- const line = renderCostBudgetLine(units);
263
- assertTrue(line !== null, "cost budget truncation-only: line rendered");
264
- assertMatch(line!, /4 sections truncated/, "cost budget truncation-only: shows count");
265
- assertNoMatch(line!, /continue-here/, "cost budget truncation-only: no continue-here text");
266
- }
130
+ {
131
+ // Unit with continue-here only — no truncation marker
132
+ const ledgerUnits = [
133
+ makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 0, continueHereFired: true }),
134
+ ];
135
+ const markers = renderCompletedBudgetMarkers(
136
+ { type: "execute-task", id: "M001/S01/T01" },
137
+ ledgerUnits,
138
+ );
139
+ assert.doesNotMatch(markers, /▼/, "completed: no ▼ when truncationSections=0");
140
+ assert.match(markers, /→ wrap-up/, "completed: shows → wrap-up");
141
+ }
267
142
 
268
- {
269
- // Only continue-here, no truncation
270
- const units = [
271
- makeUnit({ truncationSections: 0, continueHereFired: true }),
272
- ];
273
- const line = renderCostBudgetLine(units);
274
- assertTrue(line !== null, "cost budget continue-only: line rendered");
275
- assertNoMatch(line!, /truncated/, "cost budget continue-only: no truncation text");
276
- assertMatch(line!, /1 continue-here fired/, "cost budget continue-only: shows count");
277
- }
143
+ // ─── Completed section: missing ledger match ──────────────────────────────────
144
+
145
+ test('Completed section: missing ledger match', () => {
146
+ // Completed unit with no matching ledger entry — no crash, no markers
147
+ const ledgerUnits = [
148
+ makeUnit({ type: "execute-task", id: "M001/S01/T99", truncationSections: 3 }),
149
+ ];
150
+ const markers = renderCompletedBudgetMarkers(
151
+ { type: "execute-task", id: "M001/S01/T01" },
152
+ ledgerUnits,
153
+ );
154
+ assert.deepStrictEqual(markers, "", "missing match: empty markers when no ledger entry matches");
155
+ });
156
+
157
+ {
158
+ // Empty ledger — no crash, no markers
159
+ const markers = renderCompletedBudgetMarkers(
160
+ { type: "execute-task", id: "M001/S01/T01" },
161
+ [],
162
+ );
163
+ assert.deepStrictEqual(markers, "", "empty ledger: empty markers");
164
+ }
278
165
 
279
- // ─── Backward compat: no budget fields ────────────────────────────────────────
280
-
281
- console.log("\n=== Backward compat: no budget data ===");
282
-
283
- {
284
- // Old-format units without budget fields — no indicators anywhere
285
- const oldUnits = [
286
- makeUnit(), // no budget fields
287
- makeUnit({ id: "M001/S01/T02" }),
288
- ];
289
-
290
- // Completed section: no markers
291
- const markers = renderCompletedBudgetMarkers(
292
- { type: "execute-task", id: "M001/S01/T01" },
293
- oldUnits,
294
- );
295
- assertNoMatch(markers, /▼/, "backward compat completed: no truncation marker");
296
- assertNoMatch(markers, /wrap-up/, "backward compat completed: no wrap-up marker");
297
- assertEq(markers, "", "backward compat completed: empty markers string");
298
-
299
- // By Model section: no context window label
300
- const label = renderModelContextWindow(oldUnits, "claude-sonnet-4-20250514");
301
- assertEq(label, null, "backward compat by-model: no context window label");
302
-
303
- // Cost & Usage: no budget line
304
- const line = renderCostBudgetLine(oldUnits);
305
- assertEq(line, null, "backward compat cost: no budget summary line");
306
-
307
- // Aggregation still works
308
- const totals = getProjectTotals(oldUnits);
309
- assertEq(totals.totalTruncationSections, 0, "backward compat: truncation total = 0");
310
- assertEq(totals.continueHereFiredCount, 0, "backward compat: continueHere count = 0");
311
- assertEq(totals.units, 2, "backward compat: unit count correct");
312
- }
166
+ // ─── Completed section: retry handling (last entry wins) ──────────────────────
167
+
168
+ test('Completed section: retry handling', () => {
169
+ // Two ledger entries for same unit (retry) — last entry wins
170
+ const ledgerUnits = [
171
+ makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 1 }),
172
+ makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 7 }),
173
+ ];
174
+ const markers = renderCompletedBudgetMarkers(
175
+ { type: "execute-task", id: "M001/S01/T01" },
176
+ ledgerUnits,
177
+ );
178
+ assert.match(markers, /▼7/, "retry: last entry's truncation count (7) wins over first (1)");
179
+ assert.doesNotMatch(markers, /▼1/, "retry: first entry's count (1) is not shown");
180
+ });
181
+
182
+ // ─── By Model section: context window display ─────────────────────────────────
183
+
184
+ test('By Model section: context window', () => {
185
+ // Model with context window — shows formatted token count
186
+ const units = [
187
+ makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000 }),
188
+ ];
189
+ const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
190
+ assert.deepStrictEqual(label, "[200.0k]", "by model: shows [200.0k] for 200000 context window");
191
+ });
192
+
193
+ {
194
+ // Model without context window — no label
195
+ const units = [
196
+ makeUnit({ model: "claude-sonnet-4-20250514" }),
197
+ ];
198
+ const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
199
+ assert.deepStrictEqual(label, null, "by model: null when no contextWindowTokens");
200
+ }
313
201
 
314
- // ─── Edge cases ───────────────────────────────────────────────────────────────
202
+ {
203
+ // Multiple models — each gets its own context window
204
+ const units = [
205
+ makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000, cost: 0.05 }),
206
+ makeUnit({ model: "claude-opus-4-20250514", contextWindowTokens: 200000, cost: 0.30 }),
207
+ ];
208
+ const sonnetLabel = renderModelContextWindow(units, "claude-sonnet-4-20250514");
209
+ const opusLabel = renderModelContextWindow(units, "claude-opus-4-20250514");
210
+ assert.deepStrictEqual(sonnetLabel, "[200.0k]", "by model multi: sonnet has context window");
211
+ assert.deepStrictEqual(opusLabel, "[200.0k]", "by model multi: opus has context window");
212
+ }
315
213
 
316
- console.log("\n=== Edge cases ===");
214
+ // ─── By Model section: single model visibility ───────────────────────────────
215
+
216
+ test('By Model section: single model visibility', () => {
217
+ // With guard changed to >= 1, single model aggregation should produce results
218
+ const units = [
219
+ makeUnit({ model: "claude-sonnet-4-20250514" }),
220
+ ];
221
+ const models = aggregateByModel(units);
222
+ assert.ok(models.length >= 1, "single model: aggregateByModel returns >= 1 entry");
223
+ assert.deepStrictEqual(models.length, 1, "single model: exactly 1 model aggregate");
224
+ assert.deepStrictEqual(models[0].model, "claude-sonnet-4-20250514", "single model: correct model name");
225
+ // The guard `models.length >= 1` (changed from > 1) means this section now renders
226
+ assert.ok(models.length >= 1, "single model: passes >= 1 guard (section will render)");
227
+ });
228
+
229
+ // ─── Cost & Usage: aggregate budget line ──────────────────────────────────────
230
+
231
+ test('Cost & Usage: aggregate budget line', () => {
232
+ // Units with truncation and continue-here — both stats appear
233
+ const units = [
234
+ makeUnit({ truncationSections: 3, continueHereFired: true }),
235
+ makeUnit({ truncationSections: 2, continueHereFired: false }),
236
+ makeUnit({ truncationSections: 1, continueHereFired: true }),
237
+ ];
238
+ const line = renderCostBudgetLine(units);
239
+ assert.ok(line !== null, "cost budget: line rendered when budget data exists");
240
+ assert.match(line!, /6 sections truncated/, "cost budget: shows total truncation count (3+2+1=6)");
241
+ assert.match(line!, /2 continue-here fired/, "cost budget: shows continue-here count");
242
+ });
243
+
244
+ {
245
+ // Only truncation, no continue-here
246
+ const units = [
247
+ makeUnit({ truncationSections: 4, continueHereFired: false }),
248
+ ];
249
+ const line = renderCostBudgetLine(units);
250
+ assert.ok(line !== null, "cost budget truncation-only: line rendered");
251
+ assert.match(line!, /4 sections truncated/, "cost budget truncation-only: shows count");
252
+ assert.doesNotMatch(line!, /continue-here/, "cost budget truncation-only: no continue-here text");
253
+ }
317
254
 
318
- {
319
- // formatTokenCount for context window values
320
- assertEq(formatTokenCount(200000), "200.0k", "format: 200000 → 200.0k");
321
- assertEq(formatTokenCount(128000), "128.0k", "format: 128000 → 128.0k");
322
- assertEq(formatTokenCount(1000000), "1.00M", "format: 1000000 → 1.00M");
323
- assertEq(formatTokenCount(32000), "32.0k", "format: 32000 → 32.0k");
324
- }
255
+ {
256
+ // Only continue-here, no truncation
257
+ const units = [
258
+ makeUnit({ truncationSections: 0, continueHereFired: true }),
259
+ ];
260
+ const line = renderCostBudgetLine(units);
261
+ assert.ok(line !== null, "cost budget continue-only: line rendered");
262
+ assert.doesNotMatch(line!, /truncated/, "cost budget continue-only: no truncation text");
263
+ assert.match(line!, /1 continue-here fired/, "cost budget continue-only: shows count");
264
+ }
325
265
 
326
- {
327
- // Completed unit key includes type — different types don't collide
328
- const ledgerUnits = [
329
- makeUnit({ type: "research-slice", id: "M001/S01", truncationSections: 2 }),
330
- makeUnit({ type: "plan-slice", id: "M001/S01", truncationSections: 5 }),
331
- ];
332
- const researchMarkers = renderCompletedBudgetMarkers(
333
- { type: "research-slice", id: "M001/S01" },
334
- ledgerUnits,
335
- );
336
- const planMarkers = renderCompletedBudgetMarkers(
337
- { type: "plan-slice", id: "M001/S01" },
338
- ledgerUnits,
339
- );
340
- assertMatch(researchMarkers, /▼2/, "type-keying: research unit gets its own truncation count");
341
- assertMatch(planMarkers, /▼5/, "type-keying: plan unit gets its own truncation count");
342
- }
266
+ // ─── Backward compat: no budget fields ────────────────────────────────────────
267
+
268
+ test('Backward compat: no budget data', () => {
269
+ // Old-format units without budget fields — no indicators anywhere
270
+ const oldUnits = [
271
+ makeUnit(), // no budget fields
272
+ makeUnit({ id: "M001/S01/T02" }),
273
+ ];
274
+
275
+ // Completed section: no markers
276
+ const markers = renderCompletedBudgetMarkers(
277
+ { type: "execute-task", id: "M001/S01/T01" },
278
+ oldUnits,
279
+ );
280
+ assert.doesNotMatch(markers, /▼/, "backward compat completed: no truncation marker");
281
+ assert.doesNotMatch(markers, /wrap-up/, "backward compat completed: no wrap-up marker");
282
+ assert.deepStrictEqual(markers, "", "backward compat completed: empty markers string");
283
+
284
+ // By Model section: no context window label
285
+ const label = renderModelContextWindow(oldUnits, "claude-sonnet-4-20250514");
286
+ assert.deepStrictEqual(label, null, "backward compat by-model: no context window label");
287
+
288
+ // Cost & Usage: no budget line
289
+ const line = renderCostBudgetLine(oldUnits);
290
+ assert.deepStrictEqual(line, null, "backward compat cost: no budget summary line");
291
+
292
+ // Aggregation still works
293
+ const totals = getProjectTotals(oldUnits);
294
+ assert.deepStrictEqual(totals.totalTruncationSections, 0, "backward compat: truncation total = 0");
295
+ assert.deepStrictEqual(totals.continueHereFiredCount, 0, "backward compat: continueHere count = 0");
296
+ assert.deepStrictEqual(totals.units, 2, "backward compat: unit count correct");
297
+ });
298
+
299
+ // ─── Edge cases ───────────────────────────────────────────────────────────────
300
+
301
+ test('Edge cases', () => {
302
+ // formatTokenCount for context window values
303
+ assert.deepStrictEqual(formatTokenCount(200000), "200.0k", "format: 200000 → 200.0k");
304
+ assert.deepStrictEqual(formatTokenCount(128000), "128.0k", "format: 128000 → 128.0k");
305
+ assert.deepStrictEqual(formatTokenCount(1000000), "1.00M", "format: 1000000 → 1.00M");
306
+ assert.deepStrictEqual(formatTokenCount(32000), "32.0k", "format: 32000 → 32.0k");
307
+ });
308
+
309
+ {
310
+ // Completed unit key includes type — different types don't collide
311
+ const ledgerUnits = [
312
+ makeUnit({ type: "research-slice", id: "M001/S01", truncationSections: 2 }),
313
+ makeUnit({ type: "plan-slice", id: "M001/S01", truncationSections: 5 }),
314
+ ];
315
+ const researchMarkers = renderCompletedBudgetMarkers(
316
+ { type: "research-slice", id: "M001/S01" },
317
+ ledgerUnits,
318
+ );
319
+ const planMarkers = renderCompletedBudgetMarkers(
320
+ { type: "plan-slice", id: "M001/S01" },
321
+ ledgerUnits,
322
+ );
323
+ assert.match(researchMarkers, /▼2/, "type-keying: research unit gets its own truncation count");
324
+ assert.match(planMarkers, /▼5/, "type-keying: plan unit gets its own truncation count");
325
+ }
343
326
 
344
- // ─── Summary ──────────────────────────────────────────────────────────────────
327
+ // ─── Summary ──────────────────────────────────────────────────────────────────
345
328
 
346
- report();
329
+ });