@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,494 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regression tests for issue #174: the auto-generated acceptance / inScope of
4
+ * a repair round is a snapshot taken at finding-generation time; every later
5
+ * repair invalidates it and nothing refreshes or flags it.
6
+ *
7
+ * Original case (reproduced through the API that already existed, with real
8
+ * files on a real disk):
9
+ * a review failed with a finding whose requiredFix cited `lib/stats.js:2`,
10
+ * `planQualityFollowUp` generated the repair round, the file was then really
11
+ * changed on disk, and nothing in the plugin said the work order no longer
12
+ * described the workspace — the member following it literally edits a line
13
+ * that may no longer exist. The generated acceptance also carried the line
14
+ * anchor verbatim, one of the six cases reported in the issue.
15
+ *
16
+ * Nothing here is a fixture: the workspace is a real temporary directory, the
17
+ * digests are real sha256 values, and every "later round" is a real write or
18
+ * unlink. The candidate-only rules (`contractStaleness`, `snapshotWorkspacePaths`,
19
+ * `workOrderWarnings`, `digestWorkspacePaths`) are loaded dynamically so this
20
+ * file also runs unchanged against the previous build and fails behaviourally.
21
+ *
22
+ * Run: node --test scripts/quality-gates-work-order.test.mjs
23
+ */
24
+ import test from 'node:test'
25
+ import assert from 'node:assert/strict'
26
+ import { createHash } from 'node:crypto'
27
+ import { chmodSync, closeSync, mkdtempSync, mkdirSync, openSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync, writeSync } from 'node:fs'
28
+ import { tmpdir } from 'node:os'
29
+ import { join } from 'node:path'
30
+ import { canDeclareDelivery, describeQualityLoop, planQualityFollowUp } from '../lib/quality-gates.js'
31
+ import { applyQualityFollowUp } from '../lib/tools.js'
32
+ import { noSymlinkSupport } from './symlink-support.mjs'
33
+
34
+ const qualityGates = await import('../lib/quality-gates.js')
35
+ const artifacts = await import('../lib/artifacts.js').catch(() => undefined)
36
+
37
+ /** Real wall-clock pause: a "later round" must be later than the verdict. */
38
+ const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
39
+
40
+ const STATS_V1 = 'export const median = (xs) => xs[0]\n'
41
+ const STATS_V2 = 'export const median = (xs) => (xs[0] + xs[1]) / 2\n'
42
+
43
+ function sha256(text) {
44
+ return createHash('sha256').update(text).digest('hex')
45
+ }
46
+
47
+ function workspace() {
48
+ const root = mkdtempSync(join(tmpdir(), 'issue174-'))
49
+ mkdirSync(join(root, 'lib'), { recursive: true })
50
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V1)
51
+ writeFileSync(join(root, 'lib', 'format.js'), 'export const fmt = (n) => String(n)\n')
52
+ return root
53
+ }
54
+
55
+ function member(name, role) {
56
+ return { id: `member-${name}`, name, role, joinedAt: 0, status: 'idle' }
57
+ }
58
+
59
+ const DRIFTED_FINDING = {
60
+ id: 'F1', severity: 'medium', file: 'lib/stats.js',
61
+ problem: 'median is wrong on an even-length list',
62
+ requiredFix: 'fix the even branch in lib/stats.js:2 so it averages the two middle values',
63
+ }
64
+
65
+ function teamWithReview(findings = [DRIFTED_FINDING]) {
66
+ const source = {
67
+ id: 't1', subject: 'impl', status: 'completed', dependencies: [],
68
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'implementation',
69
+ assignee: 'implementer', inScope: ['lib/'], acceptance: ['done'], verify: ['node --test'],
70
+ changedPaths: ['lib/stats.js'],
71
+ }
72
+ const review = {
73
+ id: 't2', subject: 'review-round-1', status: 'failed', dependencies: ['t1'],
74
+ createdAt: 0, updatedAt: Date.now(), attempt: 1, kind: 'review', round: 1,
75
+ assignee: 'reviewer', verdict: 'needs_revision', reviewedTaskId: 't1',
76
+ objective: 'Review', acceptance: ['no blockers'],
77
+ findings,
78
+ }
79
+ return {
80
+ name: 't', id: 't', description: '', captainSessionId: 'captain',
81
+ createdAt: 0, taskSeq: 2,
82
+ members: [member('implementer', 'implementer'), member('reviewer', 'reviewer')],
83
+ tasks: [source, review],
84
+ }
85
+ }
86
+
87
+ /** The caller's real byte reading, used on both sides of the comparison. */
88
+ function readArtifacts(root, paths) {
89
+ return paths.map((path) => {
90
+ try {
91
+ const bytes = readFileSync(join(root, path))
92
+ return { path, present: true, sha256: createHash('sha256').update(bytes).digest('hex'), size: bytes.byteLength }
93
+ } catch {
94
+ return { path, present: false }
95
+ }
96
+ })
97
+ }
98
+
99
+ test('#174 (original case): generated acceptance must not assert a line number that drifts', () => {
100
+ const team = teamWithReview()
101
+ const planned = planQualityFollowUp(team, team.tasks[1])
102
+ const repair = planned.created.find((item) => item.kind === 'repair')
103
+ assert.ok(repair, 'no repair round generated')
104
+ for (const item of repair.acceptance ?? []) {
105
+ assert.doesNotMatch(item, /:\d+/u, `acceptance asserts a drifting line anchor: ${item}`)
106
+ }
107
+ })
108
+
109
+ test('#174 (original case): the repair records the failed gate whose findings it fixes', () => {
110
+ const team = teamWithReview()
111
+ const planned = planQualityFollowUp(team, team.tasks[1])
112
+ const repair = planned.created.find((item) => item.kind === 'repair')
113
+ // A dedicated causal edge, not `dependencies`: a failed task never reaches
114
+ // `completed`, so a dependency on it would make the repair unclaimable.
115
+ assert.deepEqual(repair.findingSourceTaskIds, ['t2'])
116
+ assert.ok(repair.dependencies.includes('t1'), 'repair lost its upstream dependency')
117
+ })
118
+
119
+ test('#174 (original case): the work order must be flagged once a cited file changes underneath it', async () => {
120
+ const root = workspace()
121
+ try {
122
+ const team = teamWithReview()
123
+ const followUp = applyQualityFollowUp(team, team.tasks[1], (paths) => (
124
+ artifacts === undefined
125
+ ? { at: Date.now(), artifacts: [] }
126
+ : artifacts.snapshotWorkspacePaths(root, paths)
127
+ ))
128
+ const repair = followUp.created.find((item) => item.kind === 'repair')
129
+ assert.ok(repair, 'no repair task materialized')
130
+ // applyQualityFollowUp materializes the tasks onto the team record.
131
+ const staged = { ...team, taskSeq: 4, tasks: team.tasks }
132
+
133
+ // A later round really changes the file the work order was derived from.
134
+ await pause(10)
135
+ writeFileSync(join(root, 'lib', 'stats.js'), STATS_V2)
136
+ const audit = { artifacts: readArtifacts(root, ['lib/stats.js']) }
137
+ const loop = describeQualityLoop(staged, audit)
138
+ assert.ok(
139
+ (loop.warnings ?? []).some((warning) => warning.includes('lib/stats.js')),
140
+ `stale work order was not surfaced: ${JSON.stringify(loop)}`,
141
+ )
142
+ } finally {
143
+ rmSync(root, { recursive: true, force: true })
144
+ }
145
+ })
146
+
147
+ test('#174 (original case): the generated description states the plugin did not verify the finding', () => {
148
+ const team = teamWithReview()
149
+ const planned = planQualityFollowUp(team, team.tasks[1])
150
+ const repair = planned.created.find((item) => item.kind === 'repair')
151
+ assert.match(String(repair.description ?? ''), /line number/iu)
152
+ assert.match(String(repair.description ?? ''), /not verify|did not verify|unverified/iu)
153
+ })
154
+
155
+ test('#174: the generated work order records a real workspace snapshot', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
156
+ const root = workspace()
157
+ try {
158
+ const team = teamWithReview()
159
+ const followUp = applyQualityFollowUp(team, team.tasks[1], (paths) => artifacts.snapshotWorkspacePaths(root, paths))
160
+ const repair = followUp.created.find((item) => item.kind === 'repair')
161
+ assert.ok(repair.contractSnapshot, 'no contractSnapshot recorded')
162
+ assert.equal(typeof repair.contractSnapshot.at, 'number')
163
+ const snapshot = repair.contractSnapshot.artifacts.find((item) => item.path === 'lib/stats.js')
164
+ assert.equal(snapshot.sha256, sha256(STATS_V1))
165
+ assert.equal(snapshot.size, STATS_V1.length)
166
+ } finally {
167
+ rmSync(root, { recursive: true, force: true })
168
+ }
169
+ })
170
+
171
+ test('#174: digests are real bytes; a missing path is recorded as absent, not skipped', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
172
+ const root = workspace()
173
+ try {
174
+ const digests = artifacts.digestWorkspacePaths(root, ['lib/stats.js', 'lib/missing.js'])
175
+ const stats = digests.find((item) => item.path === 'lib/stats.js')
176
+ assert.equal(stats.sha256, sha256(STATS_V1))
177
+ const missing = digests.find((item) => item.path === 'lib/missing.js')
178
+ assert.equal(missing.present, false)
179
+ assert.equal(missing.sha256, undefined)
180
+ } finally {
181
+ rmSync(root, { recursive: true, force: true })
182
+ }
183
+ })
184
+
185
+ test('#174: a path absent at generation time becoming present is drift', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
186
+ const root = workspace()
187
+ try {
188
+ const snapshot = artifacts.snapshotWorkspacePaths(root, ['lib/new.js'])
189
+ assert.equal(snapshot.artifacts[0].present, false)
190
+ writeFileSync(join(root, 'lib', 'new.js'), 'export const added = true\n')
191
+ const task = { id: 't9', status: 'pending', contractSnapshot: snapshot }
192
+ const stale = qualityGates.contractStaleness(task, artifacts.digestWorkspacePaths(root, ['lib/new.js']))
193
+ assert.equal(stale.length, 1)
194
+ assert.match(stale[0], /lib\/new\.js/u)
195
+ assert.match(stale[0], /now exists|appeared/iu)
196
+ } finally {
197
+ rmSync(root, { recursive: true, force: true })
198
+ }
199
+ })
200
+
201
+ test('#174: a deleted cited file is reported and a completed order is not', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
202
+ const root = workspace()
203
+ try {
204
+ const team = teamWithReview()
205
+ const followUp = applyQualityFollowUp(team, team.tasks[1], (paths) => artifacts.snapshotWorkspacePaths(root, paths))
206
+ const repair = followUp.created.find((item) => item.kind === 'repair')
207
+ assert.deepEqual(qualityGates.contractStaleness(repair, artifacts.digestWorkspacePaths(root, ['lib/stats.js'])), [])
208
+ unlinkSync(join(root, 'lib', 'stats.js'))
209
+ const stale = qualityGates.contractStaleness(repair, artifacts.digestWorkspacePaths(root, ['lib/stats.js']))
210
+ assert.equal(stale.length, 1)
211
+ assert.match(stale[0], /deleted|absent|missing|no longer/iu)
212
+ const closed = {
213
+ ...team,
214
+ tasks: [...team.tasks.filter((item) => item.id !== repair.id), { ...repair, status: 'completed' }],
215
+ }
216
+ assert.deepEqual(qualityGates.workOrderWarnings(closed, artifacts.digestWorkspacePaths(root, ['lib/stats.js'])), [])
217
+ } finally {
218
+ rmSync(root, { recursive: true, force: true })
219
+ }
220
+ })
221
+
222
+ test('#174: a directory scope expands to the real files it covers', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
223
+ const root = workspace()
224
+ try {
225
+ assert.deepEqual(artifacts.expandScopePaths(root, ['lib/']), ['lib/format.js', 'lib/stats.js'])
226
+ } finally {
227
+ rmSync(root, { recursive: true, force: true })
228
+ }
229
+ })
230
+
231
+ test('#174: a broad scope must not absorb secrets, .env or plugin state', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
232
+ const root = workspace()
233
+ try {
234
+ mkdirSync(join(root, 'secrets'), { recursive: true })
235
+ mkdirSync(join(root, '.agent-teams', 'team'), { recursive: true })
236
+ mkdirSync(join(root, '.git'), { recursive: true })
237
+ writeFileSync(join(root, 'secrets', 'token.txt'), 'super-secret\n')
238
+ writeFileSync(join(root, '.env.example'), 'APP_SECRET=\n')
239
+ writeFileSync(join(root, '.agent-teams', 'team', 'team.json'), '{}\n')
240
+ writeFileSync(join(root, '.git', 'config'), '[core]\n')
241
+ const paths = artifacts.expandScopePaths(root, ['./'])
242
+ assert.ok(!paths.some((path) => path.includes('secrets')), `secrets leaked into scope: ${JSON.stringify(paths)}`)
243
+ assert.ok(!paths.some((path) => path.startsWith('.env')), `.env leaked into scope: ${JSON.stringify(paths)}`)
244
+ assert.ok(!paths.some((path) => path.startsWith('.agent-teams')), `plugin state leaked into scope: ${JSON.stringify(paths)}`)
245
+ assert.ok(!paths.some((path) => path.startsWith('.git')), `.git leaked into scope: ${JSON.stringify(paths)}`)
246
+ assert.ok(paths.includes('lib/stats.js'), `real source missing from scope: ${JSON.stringify(paths)}`)
247
+ } finally {
248
+ rmSync(root, { recursive: true, force: true })
249
+ }
250
+ })
251
+
252
+ test('#174: illegal scope patterns are rejected, never widened to the workspace root', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
253
+ const root = workspace()
254
+ try {
255
+ for (const pattern of ['../', '/etc/', '~/projects/', 'C:\\temp\\']) {
256
+ const read = artifacts.readArtifactScope(root, [pattern])
257
+ assert.deepEqual(read.artifacts, [], `${pattern} produced artifacts`)
258
+ assert.equal(read.gaps.length, 1, `${pattern} produced no gap: ${JSON.stringify(read.gaps)}`)
259
+ assert.match(read.gaps[0].reason, /workspace-relative|absolute/u)
260
+ }
261
+ const read = artifacts.readArtifactScope(root, ['', ' '])
262
+ assert.deepEqual(read.artifacts, [])
263
+ assert.equal(read.gaps.length, 1)
264
+ } finally {
265
+ rmSync(root, { recursive: true, force: true })
266
+ }
267
+ })
268
+
269
+ test('#174: traversal never follows a symlink out of the workspace or into a cycle', {
270
+ skip: artifacts === undefined
271
+ ? 'artifacts module missing in this build'
272
+ : noSymlinkSupport,
273
+ }, () => {
274
+ const root = workspace()
275
+ const outside = mkdtempSync(join(tmpdir(), 'issue174-outside-'))
276
+ try {
277
+ writeFileSync(join(outside, 'host-secret.txt'), 'not part of this project\n')
278
+ symlinkSync(outside, join(root, 'lib', 'escape'))
279
+ symlinkSync(join(root, 'lib'), join(root, 'lib', 'loop'))
280
+ const paths = artifacts.expandScopePaths(root, ['lib/'])
281
+ assert.ok(!paths.some((path) => path.includes('[host-secret]') || path.endsWith('host-secret.txt')), `escaped the workspace: ${JSON.stringify(paths)}`)
282
+ assert.ok(!paths.some((path) => path.includes('escape')), `followed a symlink out of the workspace: ${JSON.stringify(paths)}`)
283
+ assert.ok(!paths.some((path) => path.includes('loop')), `followed a symlink cycle: ${JSON.stringify(paths)}`)
284
+ // An explicitly named symlink is rejected with a reason instead of read.
285
+ const read = artifacts.readArtifactScope(root, ['lib/escape/host-secret.txt'])
286
+ assert.equal(read.artifacts[0].unreadable, true)
287
+ assert.match(String(read.artifacts[0].reason), /symlink|outside/iu)
288
+ } finally {
289
+ rmSync(root, { recursive: true, force: true })
290
+ rmSync(outside, { recursive: true, force: true })
291
+ }
292
+ })
293
+
294
+ test('#174: hitting the expansion cap is reported, not silently truncated', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
295
+ const root = workspace()
296
+ try {
297
+ mkdirSync(join(root, 'many'), { recursive: true })
298
+ for (let index = 0; index < artifacts.MAX_EXPANDED_ARTIFACTS + 25; index += 1) {
299
+ writeFileSync(join(root, 'many', `f${String(index).padStart(4, '0')}.js`), `export const n = ${index}\n`)
300
+ }
301
+ const read = artifacts.readArtifactScope(root, ['many/'])
302
+ assert.equal(read.artifacts.length, artifacts.MAX_EXPANDED_ARTIFACTS)
303
+ assert.equal(read.gaps.length, 1, `cap was silent: ${JSON.stringify(read.gaps)}`)
304
+ assert.match(read.gaps[0].reason, /cap|partial/iu)
305
+ } finally {
306
+ rmSync(root, { recursive: true, force: true })
307
+ }
308
+ })
309
+
310
+ test('#174: an unreadable path is reported as unreadable, never as unchanged or absent', {
311
+ skip: artifacts === undefined
312
+ ? 'artifacts module missing in this build'
313
+ : process.platform === 'win32' ? 'POSIX permission probe' : false,
314
+ }, () => {
315
+ const root = workspace()
316
+ try {
317
+ const target = join(root, 'lib', 'locked.js')
318
+ writeFileSync(target, 'export const locked = true\n')
319
+ chmodSync(target, 0o000)
320
+ const digest = artifacts.digestWorkspacePaths(root, ['lib/locked.js'])[0]
321
+ assert.equal(digest.unreadable, true, `expected an unreadable record, got ${JSON.stringify(digest)}`)
322
+ assert.notEqual(digest.present, true)
323
+ assert.match(String(digest.reason), /cannot be read|EACCES|EPERM/iu)
324
+ } finally {
325
+ chmodSync(join(root, 'lib', 'locked.js'), 0o600)
326
+ rmSync(root, { recursive: true, force: true })
327
+ }
328
+ })
329
+
330
+ test('#174: a capped scope is incomplete evidence and never passes as full coverage', { skip: artifacts === undefined && 'artifacts module missing in this build' }, () => {
331
+ const root = workspace()
332
+ try {
333
+ mkdirSync(join(root, 'many'), { recursive: true })
334
+ for (let index = 0; index < artifacts.MAX_EXPANDED_ARTIFACTS + 25; index += 1) {
335
+ writeFileSync(join(root, 'many', `f${String(index).padStart(4, '0')}.js`), `export const n = ${index}\n`)
336
+ }
337
+ const read = artifacts.readArtifactScope(root, ['many/'])
338
+ const state = teamWithReview([])
339
+ const review = {
340
+ ...state.tasks[1],
341
+ status: 'completed', verdict: 'pass', findings: [],
342
+ reviewedTaskId: 't1', reviewedAttempt: 1,
343
+ reviewedArtifacts: read.artifacts,
344
+ reviewedGaps: read.gaps,
345
+ reviewedScope: ['many/'],
346
+ }
347
+ const delivery = canDeclareDelivery({ ...state, tasks: [state.tasks[0], review] }, {
348
+ artifacts: read.artifacts,
349
+ expandedScope: read.artifacts.map((item) => ({ path: item.path, present: item.present })),
350
+ })
351
+ assert.equal(delivery.ok, false, `partial coverage passed as a full verdict: ${JSON.stringify(delivery)}`)
352
+ assert.ok(
353
+ delivery.blockers.some((item) => /partial|cap/iu.test(item)),
354
+ `no incomplete-coverage blocker: ${JSON.stringify(delivery.blockers)}`,
355
+ )
356
+ } finally {
357
+ rmSync(root, { recursive: true, force: true })
358
+ }
359
+ })
360
+
361
+ test('#174/#161: a large artifact is hashed in constant memory (no whole-file read)', {
362
+ skip: artifacts === undefined ? 'artifacts module missing in this build' : false,
363
+ }, () => {
364
+ const root = workspace()
365
+ try {
366
+ const big = join(root, 'lib', 'big.bin')
367
+ const chunk = Buffer.alloc(1024 * 1024, 7)
368
+ const megabytes = 48
369
+ const handle = openSync(big, 'w')
370
+ try {
371
+ for (let index = 0; index < megabytes; index += 1) writeSync(handle, chunk)
372
+ } finally {
373
+ closeSync(handle)
374
+ }
375
+ const expected = createHash('sha256')
376
+ for (let index = 0; index < megabytes; index += 1) expected.update(chunk)
377
+ const before = process.memoryUsage().heapUsed
378
+ const digest = artifacts.digestWorkspacePaths(root, ['lib/big.bin'])[0]
379
+ const grew = process.memoryUsage().heapUsed - before
380
+ assert.equal(digest.size, megabytes * chunk.byteLength)
381
+ assert.equal(digest.sha256, expected.digest('hex'))
382
+ assert.ok(
383
+ grew < 16 * 1024 * 1024,
384
+ `hashing a ${megabytes} MiB file grew the heap by ${Math.round(grew / 1024 / 1024)} MiB`,
385
+ )
386
+ } finally {
387
+ rmSync(root, { recursive: true, force: true })
388
+ }
389
+ })
390
+
391
+ test('#174/#161: the production audit carries current gaps, and an over-cap scope blocks delivery', {
392
+ skip: artifacts === undefined ? 'artifacts module missing in this build' : false,
393
+ }, async () => {
394
+ const root = workspace()
395
+ try {
396
+ // The reviewed scope held 199 of its 200-file cap when the verdict closed;
397
+ // later rounds grow it past the cap, with the new files sorting last.
398
+ mkdirSync(join(root, 'many'), { recursive: true })
399
+ for (let index = 0; index < 199; index += 1) {
400
+ writeFileSync(join(root, 'many', `f${String(index).padStart(4, '0')}.js`), `export const n = ${index}\n`)
401
+ }
402
+ const atReview = artifacts.readArtifactScope(root, ['many/'])
403
+ assert.deepEqual(atReview.gaps, [], 'the review-time read was already incomplete')
404
+ const state = teamWithReview([])
405
+ const review = {
406
+ ...state.tasks[1],
407
+ status: 'completed', verdict: 'pass', findings: [],
408
+ reviewedTaskId: 't1', reviewedAttempt: 1,
409
+ reviewedArtifacts: atReview.artifacts,
410
+ reviewedScope: ['many/'],
411
+ }
412
+ const reviewed = { ...state, taskSeq: 2, tasks: [state.tasks[0], review] }
413
+ for (let index = 199; index < 225; index += 1) {
414
+ writeFileSync(join(root, 'many', `f${String(index).padStart(4, '0')}.js`), `export const n = ${index}\n`)
415
+ }
416
+ const { auditTeamWorkspace } = await import('../lib/workspace-audit.js')
417
+ const audit = auditTeamWorkspace(root, reviewed)
418
+ assert.ok(audit.gaps !== undefined && audit.gaps.length > 0, `the production audit dropped the current gaps: ${JSON.stringify(audit.gaps)}`)
419
+ assert.ok(audit.gaps.some((gap) => /cap|partial/iu.test(gap.reason)))
420
+ const delivery = canDeclareDelivery(reviewed, audit)
421
+ assert.equal(delivery.ok, false, `an over-cap current audit still declared delivery: ${JSON.stringify(delivery)}`)
422
+ assert.ok(
423
+ delivery.blockers.some((item) => /audit is incomplete/iu.test(item)),
424
+ `no incomplete-audit blocker: ${JSON.stringify(delivery.blockers)}`,
425
+ )
426
+ } finally {
427
+ rmSync(root, { recursive: true, force: true })
428
+ }
429
+ })
430
+
431
+ test('#161: an unreadable current artifact makes the production audit incomplete and blocks delivery', {
432
+ skip: artifacts === undefined
433
+ ? 'artifacts module missing in this build'
434
+ : process.platform === 'win32' ? 'POSIX permission probe' : false,
435
+ }, async () => {
436
+ const root = workspace()
437
+ try {
438
+ const locked = join(root, 'lib', 'locked.js')
439
+ writeFileSync(locked, 'export const locked = true\n')
440
+ const atReview = artifacts.readArtifactScope(root, ['lib/locked.js'])
441
+ const state = teamWithReview([])
442
+ const review = {
443
+ ...state.tasks[1],
444
+ status: 'completed', verdict: 'pass', findings: [],
445
+ reviewedTaskId: 't1', reviewedAttempt: 1,
446
+ reviewedArtifacts: atReview.artifacts,
447
+ reviewedScope: ['lib/locked.js'],
448
+ }
449
+ const reviewed = { ...state, taskSeq: 2, tasks: [state.tasks[0], review] }
450
+ chmodSync(locked, 0o000)
451
+ const { auditTeamWorkspace } = await import('../lib/workspace-audit.js')
452
+ const audit = auditTeamWorkspace(root, reviewed)
453
+ assert.ok(audit.gaps !== undefined && audit.gaps.some((gap) => /locked\.js/u.test(gap.pattern)), `unreadable path not reported: ${JSON.stringify(audit.gaps)}`)
454
+ const delivery = canDeclareDelivery(reviewed, audit)
455
+ assert.equal(delivery.ok, false, `an unreadable current artifact still declared delivery: ${JSON.stringify(delivery)}`)
456
+ chmodSync(locked, 0o600)
457
+ } finally {
458
+ rmSync(root, { recursive: true, force: true })
459
+ }
460
+ })
461
+
462
+ test('#174/#161: a directory pattern that is a symlink out of the workspace is never enumerated', {
463
+ skip: artifacts === undefined
464
+ ? 'artifacts module missing in this build'
465
+ : noSymlinkSupport,
466
+ }, () => {
467
+ const root = workspace()
468
+ const outside = mkdtempSync(join(tmpdir(), 'issue174-outside-'))
469
+ try {
470
+ writeFileSync(join(outside, 'host-only-secret.js'), 'export const leaked = true\n')
471
+ mkdirSync(join(outside, 'nested'), { recursive: true })
472
+ writeFileSync(join(outside, 'nested', 'deeper.js'), 'export const deeper = true\n')
473
+ symlinkSync(outside, join(root, 'escape'))
474
+ // Trailing-slash directory patterns go straight to the walker, so the
475
+ // prefix itself must be verified before readdir.
476
+ const readSlash = artifacts.readArtifactScope(root, ['escape/'])
477
+ assert.deepEqual(readSlash.artifacts, [], `enumerated outside names: ${JSON.stringify(readSlash.artifacts)}`)
478
+ assert.equal(readSlash.gaps.length, 1, `no gap reported: ${JSON.stringify(readSlash.gaps)}`)
479
+ assert.match(readSlash.gaps[0].reason, /outside the workspace|resolves outside/iu)
480
+ const readPlain = artifacts.readArtifactScope(root, ['escape'])
481
+ assert.equal(readPlain.artifacts[0].unreadable, true)
482
+ // A nested pattern through the same symlink is refused too.
483
+ const readNested = artifacts.readArtifactScope(root, ['escape/nested/'])
484
+ assert.deepEqual(readNested.artifacts, [])
485
+ assert.ok(readNested.gaps.length > 0)
486
+ // And the same pattern used as a work-order scope records no external bytes.
487
+ const snapshot = artifacts.snapshotWorkspacePaths(root, ['escape/'])
488
+ assert.deepEqual(snapshot.artifacts, [])
489
+ assert.ok((snapshot.gaps ?? []).length > 0)
490
+ } finally {
491
+ rmSync(root, { recursive: true, force: true })
492
+ rmSync(outside, { recursive: true, force: true })
493
+ }
494
+ })
@@ -0,0 +1,89 @@
1
+ import { readFileSync, readdirSync } from 'node:fs'
2
+ import { fileURLToPath, pathToFileURL } from 'node:url'
3
+
4
+ // npm writes a package's README into the tarball at publish time and offers no way
5
+ // to update it afterwards, so a README that still names an older plugin version is
6
+ // only fixable by cutting another release. Catch it before the tag is pushed.
7
+
8
+ // Only this fork's README is checked: the upstream READMEs are kept verbatim for
9
+ // attribution and legitimately name their own historical versions. npm freezes a
10
+ // package's README at publish time, so ours must not name a stale version.
11
+ const README_FILES = ['README.md', 'README.en.md']
12
+
13
+ // This fork's README documents which upstream tag it is based on. That baseline is
14
+ // historic by design and will differ from this package's own version, so it is
15
+ // allowed to appear verbatim; every OTHER retired version must stay inside a
16
+ // release-notes link.
17
+ const UPSTREAM_BASELINE_VERSIONS = ['0.1.29']
18
+
19
+ // A README may name only the version being released. Older plugin versions stay
20
+ // reachable through their own release-notes links, which every check strips first.
21
+ function stripReleaseNoteLinks(markdown) {
22
+ return markdown.replace(/\[[^\]]*\]\([^)]*release-notes\/v[0-9A-Za-z.-]+\.md[^)]*\)/g, '')
23
+ }
24
+
25
+ function escapeForRegExp(value) {
26
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
27
+ }
28
+
29
+ export function publishedVersions(notesDirectory) {
30
+ return readdirSync(notesDirectory)
31
+ .map(name => /^v(.+)\.md$/.exec(name)?.[1])
32
+ .filter(Boolean)
33
+ .sort()
34
+ }
35
+
36
+ export function findStaleVersionReferences(markdown, version, known) {
37
+ const body = stripReleaseNoteLinks(markdown)
38
+ const stale = []
39
+ for (const candidate of known) {
40
+ if (candidate === version) continue
41
+ if (UPSTREAM_BASELINE_VERSIONS.includes(candidate)) continue
42
+ // Match whole versions only: `0.1.5` must not be found inside `0.1.5-rc.1`.
43
+ const pattern = new RegExp(`(?<![0-9A-Za-z.-])${escapeForRegExp(candidate)}(?![0-9A-Za-z.-])`, 'g')
44
+ for (const match of body.matchAll(pattern)) {
45
+ stale.push({ version: candidate, index: match.index })
46
+ }
47
+ }
48
+ return stale
49
+ }
50
+
51
+ export function findPinnedInstallVersions(markdown) {
52
+ return [...markdown.matchAll(/dsh-agent-teams-fish@([0-9A-Za-z.-]+)/g)].map(match => match[1])
53
+ }
54
+
55
+ export function checkReadmeVersions({ version, known, files }) {
56
+ const problems = []
57
+ for (const [name, markdown] of Object.entries(files)) {
58
+ for (const stale of findStaleVersionReferences(markdown, version, known)) {
59
+ problems.push(`${name} still names ${stale.version} outside a release-notes link`)
60
+ }
61
+ for (const pinned of findPinnedInstallVersions(markdown)) {
62
+ // The stable channel requests an update without pinning a numeric version.
63
+ if (pinned !== version && pinned !== 'latest') {
64
+ problems.push(`${name} pins dsh-agent-teams-fish@${pinned} but the package is ${version}`)
65
+ }
66
+ }
67
+ }
68
+ return problems
69
+ }
70
+
71
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
72
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
73
+ const notesDirectory = fileURLToPath(new URL('../release-notes', import.meta.url))
74
+ const files = Object.fromEntries(
75
+ README_FILES.map(name => [name, readFileSync(new URL(`../${name}`, import.meta.url), 'utf8')])
76
+ )
77
+ const problems = checkReadmeVersions({
78
+ version: pkg.version,
79
+ known: publishedVersions(notesDirectory),
80
+ files
81
+ })
82
+ if (problems.length > 0) {
83
+ console.error(`README version check failed for ${pkg.version}:`)
84
+ for (const problem of problems) console.error(` - ${problem}`)
85
+ console.error('Sync the README version references with package.json, or move old versions into release-notes links.')
86
+ process.exit(1)
87
+ }
88
+ console.log(`README version references match ${pkg.version}`)
89
+ }
@@ -0,0 +1,77 @@
1
+ import assert from 'node:assert/strict'
2
+ import { readFileSync } from 'node:fs'
3
+ import { fileURLToPath } from 'node:url'
4
+ import test from 'node:test'
5
+ import {
6
+ checkReadmeVersions,
7
+ findPinnedInstallVersions,
8
+ findStaleVersionReferences,
9
+ publishedVersions,
10
+ } from './readme-version.mjs'
11
+
12
+ const KNOWN = ['0.1.17', '0.1.19', '0.1.20']
13
+
14
+ test('a README that still names an older plugin version is rejected', () => {
15
+ const markdown = 'Install with `dsh plugin add dsh-agent-teams-fish@0.1.17`.'
16
+ const problems = checkReadmeVersions({ version: '0.1.20', known: KNOWN, files: { 'README.md': markdown } })
17
+ assert.ok(
18
+ problems.includes('README.md pins dsh-agent-teams-fish@0.1.17 but the package is 0.1.20'),
19
+ `expected a pinned-install problem, got ${JSON.stringify(problems)}`
20
+ )
21
+ })
22
+
23
+ test('an older version left in prose is rejected even without an install command', () => {
24
+ const markdown = 'The npm `latest` tag points to `0.1.17` on a fresh profile.'
25
+ assert.deepEqual(
26
+ findStaleVersionReferences(markdown, '0.1.20', KNOWN).map(stale => stale.version),
27
+ ['0.1.17']
28
+ )
29
+ })
30
+
31
+ test('older versions stay reachable through their release-notes links', () => {
32
+ const markdown = [
33
+ 'See [v0.1.19](./release-notes/v0.1.19.md) for the previous release.',
34
+ 'See [0.1.17](./release-notes/v0.1.17.md) for an older one.',
35
+ 'See [release verification](./docs/releases/v0.1.19/README.md) for the evidence.',
36
+ ].join('\n')
37
+ assert.deepEqual(findStaleVersionReferences(markdown, '0.1.20', KNOWN), [])
38
+ })
39
+
40
+ test('a shorter version does not match inside a longer prerelease', () => {
41
+ const markdown = 'Recommended host: DeepSeek Harness `0.1.5-rc.1`, plus `0.1.2-alpha.5` and `0.1.2-alpha.2`.'
42
+ assert.deepEqual(findStaleVersionReferences(markdown, '0.1.20', ['0.1.5', '0.1.2', ...KNOWN]), [])
43
+ })
44
+
45
+ test('the documented upstream baseline version may be named in prose', () => {
46
+ const markdown = 'Based on upstream `v0.1.22` (commit `9cba4fe`).'
47
+ assert.deepEqual(findStaleVersionReferences(markdown, '0.1.23', ['0.1.22', ...KNOWN]), [])
48
+ })
49
+
50
+ test('install commands are extracted regardless of version', () => {
51
+ const markdown = 'add --save-exact dsh-agent-teams-fish@0.1.16 and dsh-agent-teams-fish@0.1.20'
52
+ assert.deepEqual(findPinnedInstallVersions(markdown), ['0.1.16', '0.1.20'])
53
+ })
54
+
55
+ test('latest updates are allowed while stale pins and undeclared channels remain rejected', () => {
56
+ const check = spec => checkReadmeVersions({
57
+ version: '0.1.20', known: KNOWN,
58
+ files: { 'README.md': `dsh plugin add @fish-under-sea/dsh-agent-teams-fish@${spec}` },
59
+ })
60
+ assert.deepEqual(check('latest'), [])
61
+ assert.ok(check('0.1.19').length > 0)
62
+ assert.ok(check('next').length > 0)
63
+ })
64
+
65
+ test('published versions come from the release notes themselves', () => {
66
+ const known = publishedVersions(fileURLToPath(new URL('../release-notes', import.meta.url)))
67
+ assert.ok(known.includes('0.1.18') && known.includes('0.1.16-rc.2'), known.join(', '))
68
+ })
69
+
70
+ test('the checked-in READMEs match the package version', () => {
71
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
72
+ const files = Object.fromEntries(
73
+ ['README.md'].map(name => [name, readFileSync(new URL(`../${name}`, import.meta.url), 'utf8')])
74
+ )
75
+ const known = publishedVersions(fileURLToPath(new URL('../release-notes', import.meta.url)))
76
+ assert.deepEqual(checkReadmeVersions({ version: pkg.version, known, files }), [])
77
+ })