@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.0.0

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 (179) hide show
  1. package/NOTICE.md +13 -7
  2. package/README.en.md +20 -12
  3. package/README.md +20 -12
  4. package/compatibility.json +82 -46
  5. package/icon.png +0 -0
  6. package/lib/artifacts.js +148 -25
  7. package/lib/client/ActivityPanel.js +26 -5
  8. package/lib/client/WorkspaceActivity.js +6 -4
  9. package/lib/client/activity-monitor.js +113 -41
  10. package/lib/client/locales.js +14 -0
  11. package/lib/client.js +433 -199
  12. package/lib/client.js.map +1 -1
  13. package/lib/command.js +7 -4
  14. package/lib/git-artifact-stamp.json +2 -2
  15. package/lib/harness-compat.js +120 -62
  16. package/lib/index.js +7 -10
  17. package/lib/mailbox.js +15 -5
  18. package/lib/members.js +221 -154
  19. package/lib/snapshot.js +15 -10
  20. package/lib/state.js +41 -8
  21. package/lib/tools.js +123 -64
  22. package/lib/types/artifacts.d.ts +6 -3
  23. package/lib/types/client/activity-monitor.d.ts +13 -4
  24. package/lib/types/client/locales.d.ts +14 -0
  25. package/lib/types/harness-compat.d.ts +63 -16
  26. package/lib/types/mailbox.d.ts +2 -0
  27. package/lib/types/members.d.ts +5 -17
  28. package/lib/types/snapshot.d.ts +12 -7
  29. package/lib/types/state.d.ts +10 -3
  30. package/lib/types/types.d.ts +5 -0
  31. package/lib/types/web-routes.d.ts +2 -0
  32. package/lib/types/workspace-audit-service.d.ts +35 -0
  33. package/lib/types/workspace-audit-worker.d.ts +1 -0
  34. package/lib/web-routes.js +31 -0
  35. package/lib/workspace-audit-service.js +165 -0
  36. package/lib/workspace-audit-worker.js +11 -0
  37. package/lib/workspace-audit.js +6 -5
  38. package/locale/en.json +6 -0
  39. package/locale/zh.json +6 -0
  40. package/package.json +69 -64
  41. package/pnpm-workspace.yaml +306 -273
  42. package/release-notes/v0.1.25.md +16 -0
  43. package/release-notes/v0.1.26.md +19 -0
  44. package/release-notes/v0.1.27.md +42 -0
  45. package/release-notes/v0.1.28.md +45 -0
  46. package/release-notes/v0.1.29.md +23 -0
  47. package/release-notes/v1.1.0.md +42 -0
  48. package/release-notes/v2.0.0.md +17 -0
  49. package/scripts/artwork-role-match.test.mjs +517 -0
  50. package/scripts/capabilities.test.mjs +301 -0
  51. package/scripts/check-install-channel.mjs +55 -0
  52. package/scripts/check-install-channel.test.mjs +39 -0
  53. package/scripts/clean-build.mjs +14 -0
  54. package/scripts/client-harness-migration.test.mjs +46 -0
  55. package/scripts/compatibility.mjs +20 -0
  56. package/scripts/compatibility.test.mjs +187 -0
  57. package/scripts/corrupt-teamjson.test.mjs +180 -0
  58. package/scripts/custom-artwork.test.mjs +273 -0
  59. package/scripts/fallback-tdd.mjs +61 -0
  60. package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
  61. package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
  62. package/scripts/fixtures/harness-complex-case.mjs +201 -0
  63. package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
  64. package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
  65. package/scripts/fixtures/harness-issue-case.mjs +51 -0
  66. package/scripts/fixtures/harness-issue159-case.mjs +28 -0
  67. package/scripts/fixtures/harness-model-case.mjs +127 -0
  68. package/scripts/fixtures/harness-model-case.test.mjs +37 -0
  69. package/scripts/fixtures/harness-model-driver.mjs +100 -0
  70. package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
  71. package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
  72. package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
  73. package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
  74. package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
  75. package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
  76. package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
  77. package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
  78. package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
  79. package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
  80. package/scripts/git-artifacts.mjs +64 -0
  81. package/scripts/git-artifacts.test.mjs +32 -0
  82. package/scripts/harness-compat-tdd.mjs +492 -0
  83. package/scripts/harness-issue-verify.mjs +26 -0
  84. package/scripts/harness-model-benchmark.mjs +163 -0
  85. package/scripts/harness-runtime-platform.test.mjs +31 -0
  86. package/scripts/harness-runtime-scenarios.mjs +297 -0
  87. package/scripts/harness-runtime-verify.mjs +169 -0
  88. package/scripts/harness-source-verify.mjs +211 -0
  89. package/scripts/harness-source-verify.test.mjs +97 -0
  90. package/scripts/harness-validation.mjs +68 -0
  91. package/scripts/harness-validation.test.mjs +95 -0
  92. package/scripts/http-body.test.mjs +72 -0
  93. package/scripts/import-vendor-artwork.mjs +78 -0
  94. package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
  95. package/scripts/issue-159.test.mjs +78 -0
  96. package/scripts/issue-188.test.mjs +148 -0
  97. package/scripts/issue-189.test.mjs +100 -0
  98. package/scripts/issue-203-card.test.mjs +181 -0
  99. package/scripts/issue-205.test.mjs +163 -0
  100. package/scripts/issue-234.test.mjs +424 -0
  101. package/scripts/issue-236-stale-module.test.mjs +63 -0
  102. package/scripts/issue-236.test.mjs +59 -0
  103. package/scripts/issue-262.test.mjs +98 -0
  104. package/scripts/issue-336.test.mjs +404 -0
  105. package/scripts/legacy-session-source-repair.test.mjs +201 -0
  106. package/scripts/lifecycle-verify.mjs +1573 -0
  107. package/scripts/lineage-identity.test.mjs +77 -0
  108. package/scripts/member-failure-tdd.mjs +451 -0
  109. package/scripts/member-spawn-recovery.test.mjs +92 -0
  110. package/scripts/quality-gates-amend.test.mjs +161 -0
  111. package/scripts/quality-gates-content-bound.test.mjs +572 -0
  112. package/scripts/quality-gates-cross-binding.test.mjs +184 -0
  113. package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
  114. package/scripts/quality-gates-repair-scope.test.mjs +143 -0
  115. package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
  116. package/scripts/quality-gates-tdd.mjs +1238 -0
  117. package/scripts/quality-gates-work-order.test.mjs +494 -0
  118. package/scripts/readme-version.mjs +89 -0
  119. package/scripts/readme-version.test.mjs +77 -0
  120. package/scripts/release-metadata.mjs +45 -0
  121. package/scripts/release-metadata.test.mjs +66 -0
  122. package/scripts/scoped-release.test.mjs +52 -0
  123. package/scripts/stability-tdd.mjs +144 -0
  124. package/scripts/stress-verify.mjs +548 -0
  125. package/scripts/symlink-support.mjs +46 -0
  126. package/scripts/sync-skill.mjs +103 -0
  127. package/scripts/tool-policies.test.mjs +280 -0
  128. package/scripts/update-skills.mjs +105 -0
  129. package/scripts/update-skills.test.mjs +79 -0
  130. package/scripts/upgrade-status.mjs +66 -0
  131. package/scripts/upgrade-status.test.mjs +83 -0
  132. package/scripts/verify-package.mjs +73 -0
  133. package/scripts/verify.mjs +2199 -0
  134. package/scripts/web-routes-verify.mjs +142 -0
  135. package/scripts/workspace-activity.test.mjs +346 -0
  136. package/scripts/workspace-summary.test.mjs +49 -0
  137. package/src/artifacts.ts +487 -0
  138. package/src/artwork-source.ts +262 -0
  139. package/src/capabilities.ts +113 -0
  140. package/src/client/ActivityPanel.module.css +2390 -0
  141. package/src/client/ActivityPanel.tsx +1507 -0
  142. package/src/client/AgentTeamsCard.module.css +148 -0
  143. package/src/client/AgentTeamsCard.tsx +155 -0
  144. package/src/client/StagingPlanEditor.tsx +829 -0
  145. package/src/client/TeamChatEntry.tsx +27 -0
  146. package/src/client/WorkspaceActivity.module.css +41 -0
  147. package/src/client/WorkspaceActivity.tsx +137 -0
  148. package/src/client/activity-model.ts +372 -0
  149. package/src/client/activity-monitor.ts +440 -0
  150. package/src/client/agent-teams-card-definition.ts +250 -0
  151. package/src/client/artwork.ts +374 -0
  152. package/src/client/icons.tsx +17 -0
  153. package/src/client/index.tsx +140 -0
  154. package/src/client/locales.ts +481 -0
  155. package/src/client/panel-geometry.ts +194 -0
  156. package/src/client/session-navigation.ts +73 -0
  157. package/src/client/workspace-state.ts +52 -0
  158. package/src/command.ts +145 -0
  159. package/src/css-modules.d.ts +4 -0
  160. package/src/event-types.ts +177 -0
  161. package/src/events.ts +78 -0
  162. package/src/harness-compat.ts +570 -0
  163. package/src/index.ts +599 -0
  164. package/src/lineage.ts +248 -0
  165. package/src/mailbox.ts +185 -0
  166. package/src/members.ts +1230 -0
  167. package/src/profiles.ts +765 -0
  168. package/src/quality-gates.ts +2124 -0
  169. package/src/scheduler.ts +554 -0
  170. package/src/snapshot.ts +333 -0
  171. package/src/state.ts +1317 -0
  172. package/src/tool-names.ts +14 -0
  173. package/src/tool-policies.ts +219 -0
  174. package/src/tools.ts +2939 -0
  175. package/src/types.ts +414 -0
  176. package/src/web-routes.ts +128 -0
  177. package/src/workspace-audit-service.ts +182 -0
  178. package/src/workspace-audit-worker.ts +12 -0
  179. package/src/workspace-audit.ts +57 -0
@@ -0,0 +1,572 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regression tests for issue #161: a passing review is not bound to the
4
+ * revision it judged.
5
+ *
6
+ * Original case (reproduced through the API that already existed, with real
7
+ * bytes on a real disk):
8
+ * an implementation recorded `changedPaths`, a review closed with
9
+ * `verdict=pass` + `reviewedTaskId`, the workspace files were then really
10
+ * edited and really deleted, and `canDeclareDelivery(team)` still reported
11
+ * `ok: true` while `describeQualityLoop` still advertised `deliverable —
12
+ * All required quality gates passed`. A captain following that banner would
13
+ * report an unreviewed revision as verified; the only actor who could notice
14
+ * was a human re-hashing files by hand.
15
+ *
16
+ * The caller (which owns the workspace path, exactly like the status tool)
17
+ * reads the current bytes and passes them in; the rules stay pure. Nothing in
18
+ * this file is a fixture: every digest is read from a real temporary file with
19
+ * node:crypto, and the edits/deletions are real filesystem writes.
20
+ *
21
+ * Run: node --test scripts/quality-gates-content-bound.test.mjs
22
+ */
23
+ import test from 'node:test'
24
+ import assert from 'node:assert/strict'
25
+ import { createHash } from 'node:crypto'
26
+ import { mkdtempSync, mkdirSync, rmSync, statSync, readFileSync, writeFileSync, unlinkSync, utimesSync } from 'node:fs'
27
+ import { tmpdir } from 'node:os'
28
+ import { join } from 'node:path'
29
+ import { canDeclareDelivery, describeQualityLoop } from '../lib/quality-gates.js'
30
+
31
+ const STATS_V1 = [
32
+ 'export function median(values) {',
33
+ ' const sorted = [...values].sort((a, b) => a - b)',
34
+ ' const middle = Math.floor(sorted.length / 2)',
35
+ ' if (sorted.length % 2 === 0) {',
36
+ ' const lower = sorted[middle - 1]',
37
+ ' const upper = sorted[middle]',
38
+ ' return (lower + upper) / 2',
39
+ ' }',
40
+ ' return sorted[middle]',
41
+ '}',
42
+ '',
43
+ ].join('\n')
44
+ const STATS_V2 = STATS_V1.replace('lower', 'lo').replace('upper', 'hi')
45
+ const TEST_V1 = "import test from 'node:test'\nimport assert from 'node:assert/strict'\ntest('median', () => {})\n"
46
+ const TEST_V2 = `${TEST_V1}test('even list', () => {})\ntest('odd list', () => {})\n`
47
+ const PACKAGE_V1 = '{\n "name": "sample",\n "version": "0.0.0",\n "type": "module"\n}\n'
48
+
49
+ /** The caller's real byte reading: sha256 + size + mtime of the paths it owns. */
50
+ function readArtifacts(root, paths) {
51
+ return paths.map((path) => {
52
+ const absolute = join(root, path)
53
+ try {
54
+ const bytes = readFileSync(absolute)
55
+ return {
56
+ path,
57
+ present: true,
58
+ sha256: createHash('sha256').update(bytes).digest('hex'),
59
+ size: bytes.byteLength,
60
+ mtimeMs: statSync(absolute).mtimeMs,
61
+ }
62
+ } catch {
63
+ return { path, present: false }
64
+ }
65
+ })
66
+ }
67
+
68
+ function workspace() {
69
+ const root = mkdtempSync(join(tmpdir(), 'issue161-'))
70
+ mkdirSync(join(root, 'lib'), { recursive: true })
71
+ mkdirSync(join(root, 'test'), { recursive: true })
72
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V1)
73
+ writeFileSync(join(root, 'test', 'stats.test.js'), TEST_V1)
74
+ writeFileSync(join(root, 'package.json'), PACKAGE_V1)
75
+ // Windows filesystem time can lead Date.now() on a fresh write. Start with
76
+ // an unambiguously older revision so only the later edits invalidate review.
77
+ const beforeReview = new Date(Date.now() - 1000)
78
+ for (const path of ['lib/stats.js', 'test/stats.test.js', 'package.json']) {
79
+ utimesSync(join(root, path), beforeReview, beforeReview)
80
+ }
81
+ return root
82
+ }
83
+
84
+ function member(name, role) {
85
+ return { id: `member-${name}`, name, role, joinedAt: 0, status: 'idle' }
86
+ }
87
+
88
+ const REVIEWED_PATHS = ['lib/stats.js', 'test/stats.test.js', 'package.json']
89
+
90
+ /** Real wall-clock pause: an edit "after the pass" must be later than it. */
91
+ const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
92
+
93
+ /** The record the plugin writes: changedPaths on the implementation, a pass on the review. */
94
+ function team(extraReview = {}) {
95
+ return {
96
+ name: 'stats', id: 'stats', description: '', captainSessionId: 'captain',
97
+ createdAt: Date.now(), taskSeq: 2,
98
+ members: [member('engineer', 'engineer'), member('reviewer', 'reviewer')],
99
+ tasks: [
100
+ {
101
+ id: 't1', subject: 'implementation', status: 'completed', dependencies: [],
102
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'implementation',
103
+ assignee: 'engineer',
104
+ objective: 'Implement stats module', inScope: ['lib/', 'test/', 'package.json'],
105
+ acceptance: ['module works'], verify: ['node --test'],
106
+ changedPaths: REVIEWED_PATHS,
107
+ acceptanceResults: [{ criterion: 'module works', status: 'passed' }],
108
+ commandsRun: [{ command: 'node --test', status: 'passed', exitCode: 0 }],
109
+ },
110
+ {
111
+ id: 't5', subject: 'review-round-2', status: 'completed', dependencies: ['t1'],
112
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'review', round: 2,
113
+ assignee: 'reviewer', verdict: 'pass', reviewedTaskId: 't1',
114
+ objective: 'Review the implementation', acceptance: ['no blockers'],
115
+ ...extraReview,
116
+ },
117
+ ],
118
+ }
119
+ }
120
+
121
+ test('#161 (original case): editing and deleting reviewed bytes after the pass must stop the deliverable claim', async () => {
122
+ const root = workspace()
123
+ try {
124
+ const state = team()
125
+ const before = canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
126
+ assert.equal(before.ok, true, `precondition: the reviewed revision was deliverable: ${JSON.stringify(before)}`)
127
+
128
+ // The implementer's later turn, exactly as reported: rename two local
129
+ // variables, add two assertions, delete package.json.
130
+ await pause(10)
131
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
132
+ writeFileSync(join(root, 'test', 'stats.test.js'), TEST_V2)
133
+ unlinkSync(join(root, 'package.json'))
134
+
135
+ const after = canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
136
+ assert.equal(after.ok, false, `unreviewed revision still advertised as deliverable: ${JSON.stringify(after)}`)
137
+ assert.ok(
138
+ after.blockers.some((item) => item.includes('lib/stats.js')),
139
+ `no blocker for the edited reviewed file: ${JSON.stringify(after.blockers)}`,
140
+ )
141
+ assert.ok(
142
+ after.blockers.some((item) => item.includes('package.json')),
143
+ `no blocker for the deleted reviewed file: ${JSON.stringify(after.blockers)}`,
144
+ )
145
+ } finally {
146
+ rmSync(root, { recursive: true, force: true })
147
+ }
148
+ })
149
+
150
+ test('#161 (original case): the loop banner must not stay green over changed bytes', async () => {
151
+ const root = workspace()
152
+ try {
153
+ const state = team()
154
+ assert.equal(describeQualityLoop(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) }).deliverable, true)
155
+ await pause(10)
156
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
157
+ const loop = describeQualityLoop(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
158
+ assert.equal(loop.deliverable, false, `banner still reads deliverable: ${JSON.stringify(loop)}`)
159
+ assert.notEqual(loop.state, 'deliverable')
160
+ assert.match(loop.summary, /stats\.js/u)
161
+ } finally {
162
+ rmSync(root, { recursive: true, force: true })
163
+ }
164
+ })
165
+
166
+ test('#161 (recorded revision): a pass that recorded the bytes it judged is invalidated by any byte change', async () => {
167
+ const root = workspace()
168
+ try {
169
+ const recorded = readArtifacts(root, REVIEWED_PATHS)
170
+ const state = team({ reviewedAttempt: 1, reviewedArtifacts: recorded })
171
+ assert.equal(canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) }).ok, true)
172
+ await pause(10)
173
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
174
+ const after = canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
175
+ assert.equal(after.ok, false)
176
+ assert.ok(after.blockers.some((item) => item.includes('lib/stats.js')))
177
+ } finally {
178
+ rmSync(root, { recursive: true, force: true })
179
+ }
180
+ })
181
+
182
+ test('#161: an identical rewrite is not drift, a real deletion is', () => {
183
+ const root = workspace()
184
+ try {
185
+ const recorded = readArtifacts(root, REVIEWED_PATHS)
186
+ const state = team({ reviewedAttempt: 1, reviewedArtifacts: recorded })
187
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V1)
188
+ writeFileSync(join(root, 'test', 'stats.test.js'), TEST_V1)
189
+ assert.equal(canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) }).ok, true)
190
+ unlinkSync(join(root, 'package.json'))
191
+ const after = canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
192
+ assert.equal(after.ok, false)
193
+ assert.ok(
194
+ after.blockers.some((item) => item.includes('package.json') && /deleted|absent|missing|no longer/iu.test(item)),
195
+ `no deletion blocker: ${JSON.stringify(after.blockers)}`,
196
+ )
197
+ } finally {
198
+ rmSync(root, { recursive: true, force: true })
199
+ }
200
+ })
201
+
202
+ test('#161: re-attempting the reviewed task invalidates the pass without needing any hashing', () => {
203
+ const state = team({ reviewedAttempt: 1 })
204
+ state.tasks[0].attempt = 2
205
+ state.tasks[0].attemptId = 'attempt-2'
206
+ const delivery = canDeclareDelivery(state)
207
+ assert.equal(delivery.ok, false, `stale pass survived a re-attempt: ${JSON.stringify(delivery)}`)
208
+ assert.ok(
209
+ delivery.blockers.some((item) => item.includes('t5') && /attempt/u.test(item)),
210
+ `no attempt-drift blocker: ${JSON.stringify(delivery.blockers)}`,
211
+ )
212
+ })
213
+
214
+ test('#161: an intermediate verification that drifted is surfaced without false-blocking the newer review', async () => {
215
+ const root = workspace()
216
+ try {
217
+ const implementation = team().tasks[0]
218
+ const verification = {
219
+ id: 't3', subject: 'verification', status: 'completed', dependencies: ['t1'],
220
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'verification',
221
+ assignee: 'verifier', acceptance: ['commands pass'], verify: ['node --test'],
222
+ reviewedAttempt: 1, reviewedArtifacts: readArtifacts(root, ['lib/stats.js']),
223
+ acceptanceResults: [{ criterion: 'commands pass', status: 'passed' }],
224
+ commandsRun: [{ command: 'node --test', status: 'passed', exitCode: 0 }],
225
+ }
226
+ const repair = {
227
+ id: 't4', subject: 'repair-round-2', status: 'completed', dependencies: ['t3'],
228
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'repair', round: 2,
229
+ assignee: 'engineer', inScope: ['lib/'], acceptance: ['fix it'], verify: ['node --test'],
230
+ sourceTaskId: 't1', sourceFindingIds: ['F1'], changedPaths: ['lib/stats.js'],
231
+ acceptanceResults: [{ criterion: 'fix it', status: 'passed' }],
232
+ commandsRun: [{ command: 'node --test', status: 'passed', exitCode: 0 }],
233
+ }
234
+ await pause(10)
235
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
236
+ const review = {
237
+ ...team().tasks[1],
238
+ id: 't6', dependencies: ['t4'], round: 3, reviewedTaskId: 't4',
239
+ reviewedAttempt: 1, reviewedArtifacts: readArtifacts(root, ['lib/stats.js']),
240
+ }
241
+ const state = {
242
+ ...team(),
243
+ taskSeq: 6,
244
+ tasks: [implementation, verification, repair, review],
245
+ }
246
+ const loop = describeQualityLoop(state, { artifacts: readArtifacts(root, ['lib/stats.js']) })
247
+ assert.equal(loop.deliverable, true, `a superseded verification must not block the new review: ${JSON.stringify(loop)}`)
248
+ assert.ok(
249
+ (loop.warnings ?? []).some((item) => item.includes('t3') && /changed since|revision that no longer exists/u.test(item)),
250
+ `drifted verification not surfaced: ${JSON.stringify(loop)}`,
251
+ )
252
+ } finally {
253
+ rmSync(root, { recursive: true, force: true })
254
+ }
255
+ })
256
+
257
+ test('#161: a work-kind task without a review is still not deliverable', () => {
258
+ const state = team()
259
+ state.tasks[1].verdict = 'needs_revision'
260
+ assert.equal(canDeclareDelivery(state).ok, false)
261
+ })
262
+
263
+ /* ------------------------------------------------------------------------- *
264
+ * Boundaries the supervisor asked to be explicit about: a review that ran
265
+ * while the tree was moving, a legitimately superseded old pass, a new file
266
+ * appearing under a reviewed directory, and partial (capped) coverage. *
267
+ * ------------------------------------------------------------------------- */
268
+
269
+ const qualityGates = await import('../lib/quality-gates.js')
270
+
271
+ test('#161: a review that ran while its inputs were changing must not claim the current bytes', () => {
272
+ const root = workspace()
273
+ try {
274
+ const state = team({
275
+ reviewedAttempt: 1,
276
+ reviewedArtifacts: readArtifacts(root, REVIEWED_PATHS),
277
+ reviewedDuringDrift: ['lib/stats.js changed (sha256 062deee2 -> 91779f0e)'],
278
+ })
279
+ const delivery = canDeclareDelivery(state, { artifacts: readArtifacts(root, REVIEWED_PATHS) })
280
+ assert.equal(delivery.ok, false, `a verdict over a moving workspace was accepted: ${JSON.stringify(delivery)}`)
281
+ assert.ok(
282
+ delivery.blockers.some((item) => /while this verdict was being formed|stable revision/u.test(item)),
283
+ `no during-review drift blocker: ${JSON.stringify(delivery.blockers)}`,
284
+ )
285
+ } finally {
286
+ rmSync(root, { recursive: true, force: true })
287
+ }
288
+ })
289
+
290
+ test('#161: the claim-time snapshot and the close-time bytes decide what a verdict may bind', {
291
+ skip: typeof qualityGates.bindReviewToRevision === 'function' ? false : 'content binding not present in this build',
292
+ }, () => {
293
+ const root = workspace()
294
+ try {
295
+ const start = { at: Date.now(), artifacts: readArtifacts(root, REVIEWED_PATHS) }
296
+ // Someone else writes the file while the review is open.
297
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
298
+ const state = team()
299
+ const drifting = {
300
+ ...state.tasks[1],
301
+ verdictStartSnapshot: start,
302
+ }
303
+ const duringDrift = qualityGates.artifactDrift(start.artifacts, readArtifacts(root, REVIEWED_PATHS))
304
+ assert.equal(duringDrift.length, 1)
305
+ const bound = qualityGates.bindReviewToRevision({ ...state, tasks: [...state.tasks, drifting] }, drifting, {
306
+ artifacts: readArtifacts(root, REVIEWED_PATHS),
307
+ scope: REVIEWED_PATHS,
308
+ duringDrift,
309
+ })
310
+ assert.equal(bound.reviewedAttempt, 1)
311
+ assert.deepEqual(bound.reviewedDuringDrift, duringDrift)
312
+ assert.equal(bound.reviewedArtifacts.length, REVIEWED_PATHS.length)
313
+ const blocked = canDeclareDelivery({ ...state, tasks: [state.tasks[0], bound] }, {
314
+ artifacts: readArtifacts(root, REVIEWED_PATHS),
315
+ })
316
+ assert.equal(blocked.ok, false)
317
+ } finally {
318
+ rmSync(root, { recursive: true, force: true })
319
+ }
320
+ })
321
+
322
+ /**
323
+ * The delivery check compares two clocks: `updatedAt` comes from `Date.now()`
324
+ * (whole milliseconds) and `mtimeMs` from the filesystem, which records a
325
+ * sub-millisecond value that can sit *ahead* of the process clock. These cases
326
+ * pin that skew deterministically instead of hoping a real write lands in the
327
+ * wrong millisecond, so the tolerance is covered on every platform.
328
+ *
329
+ * Both use the legacy path on purpose: a verdict that recorded no digests is
330
+ * exactly where mtime is the only evidence, and where the skew was misread as a
331
+ * post-verdict edit.
332
+ */
333
+ test('#161: filesystem-clock skew smaller than the tolerance is not a post-verdict edit', () => {
334
+ const root = workspace()
335
+ try {
336
+ const recorded = readArtifacts(root, REVIEWED_PATHS)
337
+ const updatedAt = Date.now()
338
+ const state = team({ reviewedAttempt: 1 })
339
+ state.tasks[1].updatedAt = updatedAt
340
+ // Every reviewed file is stamped slightly *after* the verdict even though it
341
+ // was written before it. The skew is real (up to ~2.2ms on Windows) but far
342
+ // below the tolerance, so the verdict still binds this revision.
343
+ const skewed = recorded.map((artifact) => ({ ...artifact, mtimeMs: updatedAt + 2.2 }))
344
+ const delivery = canDeclareDelivery(state, { artifacts: skewed })
345
+ assert.equal(
346
+ delivery.ok,
347
+ true,
348
+ `a small clock skew read as a post-verdict edit: ${JSON.stringify(delivery.blockers)}`,
349
+ )
350
+ } finally {
351
+ rmSync(root, { recursive: true, force: true })
352
+ }
353
+ })
354
+
355
+ test('#161: a write clearly later than the tolerance is still a post-verdict edit', () => {
356
+ const root = workspace()
357
+ try {
358
+ const recorded = readArtifacts(root, REVIEWED_PATHS)
359
+ const updatedAt = Date.now()
360
+ const state = team({ reviewedAttempt: 1 })
361
+ state.tasks[1].updatedAt = updatedAt
362
+ // A real edit after the verdict moves the mtime well past the tolerance.
363
+ const later = recorded.map((artifact) => ({ ...artifact, mtimeMs: updatedAt + 500 }))
364
+ const delivery = canDeclareDelivery(state, { artifacts: later })
365
+ assert.equal(delivery.ok, false, 'a later write was silently accepted as the reviewed revision')
366
+ assert.ok(
367
+ delivery.blockers.some((item) => item.includes('lib/stats.js')),
368
+ `no blocker for the later write: ${JSON.stringify(delivery.blockers)}`,
369
+ )
370
+ } finally {
371
+ rmSync(root, { recursive: true, force: true })
372
+ }
373
+ })
374
+
375
+ test('#161: a legitimate later repair and new pass supersede the old pass instead of blocking forever', async () => {
376
+ const root = workspace()
377
+ try {
378
+ const implementation = { ...team().tasks[0], createdAt: 0 }
379
+ const firstPass = {
380
+ ...team().tasks[1],
381
+ id: 't2', round: 1, createdAt: 100, updatedAt: Date.now(),
382
+ reviewedAttempt: 1, reviewedArtifacts: readArtifacts(root, ['lib/stats.js']),
383
+ }
384
+ // A legitimate later round really changes the reviewed bytes.
385
+ await pause(10)
386
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
387
+ const repair = {
388
+ id: 't4', subject: 'repair-round-2', status: 'completed', dependencies: ['t2'],
389
+ createdAt: 200, updatedAt: Date.now(), attempt: 1, kind: 'repair', round: 2,
390
+ assignee: 'engineer', inScope: ['lib/'], acceptance: ['fix it'], verify: ['node --test'],
391
+ sourceTaskId: 't1', sourceFindingIds: ['F2'], changedPaths: ['lib/stats.js'],
392
+ acceptanceResults: [{ criterion: 'fix it', status: 'passed' }],
393
+ commandsRun: [{ command: 'node --test', status: 'passed', exitCode: 0 }],
394
+ }
395
+ const secondPass = {
396
+ ...team().tasks[1],
397
+ id: 't6', round: 3, createdAt: 300, updatedAt: Date.now(),
398
+ dependencies: ['t4'], reviewedTaskId: 't4', reviewedAttempt: 1,
399
+ reviewedArtifacts: readArtifacts(root, ['lib/stats.js']),
400
+ }
401
+ const state = { ...team(), taskSeq: 6, tasks: [implementation, firstPass, repair, secondPass] }
402
+ const loop = describeQualityLoop(state, { artifacts: readArtifacts(root, ['lib/stats.js']) })
403
+ assert.equal(loop.deliverable, true, `an old superseded pass blocked the new gate: ${JSON.stringify(loop)}`)
404
+ assert.ok(
405
+ (loop.warnings ?? []).some((item) => item.includes('t2') && /superseded/u.test(item)),
406
+ `the superseded pass was not reported: ${JSON.stringify(loop)}`,
407
+ )
408
+ } finally {
409
+ rmSync(root, { recursive: true, force: true })
410
+ }
411
+ })
412
+
413
+ test('#161: a new file under a reviewed directory scope was never reviewed', () => {
414
+ const root = workspace()
415
+ try {
416
+ const state = team({
417
+ reviewedAttempt: 1,
418
+ reviewedArtifacts: readArtifacts(root, ['lib/stats.js']),
419
+ reviewedScope: ['lib/'],
420
+ })
421
+ writeFileSync(join(root, 'lib', 'added.js'), 'export const added = true\n')
422
+ const delivery = canDeclareDelivery(state, {
423
+ artifacts: readArtifacts(root, ['lib/stats.js', 'lib/added.js']),
424
+ expandedScope: [
425
+ { path: 'lib/stats.js', present: true },
426
+ { path: 'lib/added.js', present: true },
427
+ ],
428
+ })
429
+ assert.equal(delivery.ok, false, `a broad scope silently absorbed an unreviewed file: ${JSON.stringify(delivery)}`)
430
+ assert.ok(
431
+ delivery.blockers.some((item) => item.includes('lib/added.js') && /never reviewed/u.test(item)),
432
+ `no unreviewed-file blocker: ${JSON.stringify(delivery.blockers)}`,
433
+ )
434
+ } finally {
435
+ rmSync(root, { recursive: true, force: true })
436
+ }
437
+ })
438
+
439
+ test('#161: an unreadable reviewed file cannot be claimed as unchanged', () => {
440
+ const root = workspace()
441
+ try {
442
+ const state = team({
443
+ reviewedAttempt: 1,
444
+ reviewedArtifacts: readArtifacts(root, REVIEWED_PATHS),
445
+ })
446
+ const delivery = canDeclareDelivery(state, {
447
+ artifacts: [
448
+ ...readArtifacts(root, ['test/stats.test.js', 'package.json']),
449
+ { path: 'lib/stats.js', present: false, unreadable: true, reason: 'lib/stats.js cannot be read (EACCES)' },
450
+ ],
451
+ })
452
+ assert.equal(delivery.ok, false)
453
+ assert.ok(
454
+ delivery.blockers.some((item) => item.includes('lib/stats.js') && /cannot be read|confirm/iu.test(item)),
455
+ `unreadable evidence was treated as a match: ${JSON.stringify(delivery.blockers)}`,
456
+ )
457
+ } finally {
458
+ rmSync(root, { recursive: true, force: true })
459
+ }
460
+ })
461
+
462
+ /* ------------------------------------------------------------------------- *
463
+ * Independent-review findings on the content binding itself. Each case uses a
464
+ * real temporary workspace with real bytes: A = lib/a.js, B = lib/b.js.
465
+ * ------------------------------------------------------------------------- */
466
+
467
+ function abWorkspace() {
468
+ const root = mkdtempSync(join(tmpdir(), 'issue161-ab-'))
469
+ mkdirSync(join(root, 'lib'), { recursive: true })
470
+ writeFileSync(join(root, 'lib', 'a.js'), 'export const a = 1\n')
471
+ writeFileSync(join(root, 'lib', 'b.js'), 'export const b = 1\n')
472
+ return root
473
+ }
474
+
475
+ /** Digest helper for an explicit root (the shared one is bound to REVIEWED_PATHS). */
476
+ function readArtifacts2(root, paths) {
477
+ return readArtifacts(root, paths)
478
+ }
479
+
480
+ function abTeam(reviewOverrides) {
481
+ const state = team()
482
+ state.tasks = [
483
+ {
484
+ ...state.tasks[0],
485
+ createdAt: 0, inScope: ['lib/'], changedPaths: ['lib/a.js', 'lib/b.js'],
486
+ },
487
+ {
488
+ ...state.tasks[1],
489
+ id: 't2', round: 1, createdAt: 100, dependencies: ['t1'],
490
+ reviewedTaskId: 't1', reviewedAttempt: 1,
491
+ ...reviewOverrides,
492
+ },
493
+ ]
494
+ return state
495
+ }
496
+
497
+ test('#161 review: an unbound legacy pass cannot supersede a real drift blocker', async () => {
498
+ const root = abWorkspace()
499
+ try {
500
+ const first = readArtifacts2(root, ['lib/a.js', 'lib/b.js'])
501
+ const state = abTeam({
502
+ reviewedAttempt: 1,
503
+ reviewedArtifacts: first,
504
+ reviewedScope: ['lib/a.js', 'lib/b.js'],
505
+ })
506
+ await pause(10)
507
+ writeFileSync(join(root, 'lib', 'b.js'), 'export const b = 2\n')
508
+ // A newer, completed pass in the same lineage that recorded NO artifact
509
+ // identity (the shape of every pre-fix record).
510
+ const legacy = {
511
+ ...state.tasks[1],
512
+ id: 't7', round: 5, createdAt: 900, updatedAt: Date.now(),
513
+ reviewedTaskId: 't1', reviewedAttempt: 1,
514
+ reviewedArtifacts: undefined, reviewedScope: undefined, reviewedGaps: undefined,
515
+ }
516
+ const withLegacy = { ...state, taskSeq: 7, tasks: [...state.tasks, legacy] }
517
+ const delivery = canDeclareDelivery(withLegacy, { artifacts: readArtifacts2(root, ['lib/a.js', 'lib/b.js']) })
518
+ assert.equal(delivery.ok, false, `an unbound pass cleared a real drift blocker: ${JSON.stringify(delivery)}`)
519
+ assert.ok(
520
+ delivery.blockers.some((item) => item.includes('lib/b.js')),
521
+ `the drifted path is not named: ${JSON.stringify(delivery.blockers)}`,
522
+ )
523
+ assert.ok(!delivery.warnings.some((item) => /superseded by t7/u.test(item)), 't7 was treated as superseding evidence')
524
+ } finally {
525
+ rmSync(root, { recursive: true, force: true })
526
+ }
527
+ })
528
+
529
+ test('#161 review: a narrower new pass cannot clear drift on a path it never reviewed', async () => {
530
+ const root = abWorkspace()
531
+ try {
532
+ const state = abTeam({
533
+ reviewedAttempt: 1,
534
+ reviewedArtifacts: readArtifacts2(root, ['lib/a.js', 'lib/b.js']),
535
+ reviewedScope: ['lib/a.js', 'lib/b.js'],
536
+ })
537
+ await pause(10)
538
+ writeFileSync(join(root, 'lib', 'b.js'), 'export const b = 2\n')
539
+ // A later sound pass that reviewed only A.
540
+ const narrower = {
541
+ ...state.tasks[1],
542
+ id: 't8', round: 4, createdAt: 800, updatedAt: Date.now(),
543
+ reviewedTaskId: 't1', reviewedAttempt: 1,
544
+ reviewedArtifacts: readArtifacts2(root, ['lib/a.js']),
545
+ reviewedScope: ['lib/a.js'],
546
+ }
547
+ const audit = { artifacts: readArtifacts2(root, ['lib/a.js', 'lib/b.js']) }
548
+ const narrowed = { ...state, taskSeq: 8, tasks: [...state.tasks, narrower] }
549
+ const blocked = canDeclareDelivery(narrowed, audit)
550
+ assert.equal(blocked.ok, false, `a narrower review cleared unreviewed drift: ${JSON.stringify(blocked)}`)
551
+ assert.ok(
552
+ blocked.blockers.some((item) => item.includes('lib/b.js')),
553
+ `the unreviewed drifted path is not named: ${JSON.stringify(blocked.blockers)}`,
554
+ )
555
+
556
+ // Positive control: a later pass that binds both paths does clear it.
557
+ const full = {
558
+ ...narrower,
559
+ id: 't9', round: 6, createdAt: 950,
560
+ reviewedArtifacts: readArtifacts2(root, ['lib/a.js', 'lib/b.js']),
561
+ reviewedScope: ['lib/a.js', 'lib/b.js'],
562
+ }
563
+ const cleared = canDeclareDelivery({ ...state, taskSeq: 9, tasks: [...state.tasks, full] }, audit)
564
+ assert.equal(cleared.ok, true, `a full re-review failed to clear the drift: ${JSON.stringify(cleared)}`)
565
+ assert.ok(
566
+ cleared.warnings.some((item) => item.includes('t2') && /superseded by t9/u.test(item)),
567
+ `the superseded pass was not reported: ${JSON.stringify(cleared.warnings)}`,
568
+ )
569
+ } finally {
570
+ rmSync(root, { recursive: true, force: true })
571
+ }
572
+ })