@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,184 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regression tests for the #161 x #175 cross-group gap found during integration.
4
+ *
5
+ * Real trace it reproduces (this session's S-BC candidate artifact, deepseek-flash):
6
+ * t1 implementation.changedPaths = ['lib/format.js']
7
+ * t5 repair.changedPaths = ['lib/sum.js'] (automatic round)
8
+ * t6 verification.reviewedScope = ['lib/sum.js'] (automatic re-check)
9
+ * t4 review.dependencies = ['t6'] but reviewedTaskId = 't1'
10
+ * t4 review.reviewedScope = ['lib/format.js']
11
+ *
12
+ * The pre-planned review was rewired to the re-verification yet still bound only
13
+ * the original source file, and a drifted verification was demoted to a warning
14
+ * unconditionally. A later real edit of lib/sum.js therefore left the delivered
15
+ * bytes with no valid gate evidence while delivery still said ok.
16
+ *
17
+ * Both halves are covered here with real files on a real disk:
18
+ * · verdictScopePatterns must bind the whole judged lineage (source + repairs);
19
+ * · a drifted verification without a sound covering verdict must block.
20
+ *
21
+ * The candidate-only rules are loaded dynamically so the file also runs against
22
+ * a build that predates them (where the assertions fail behaviourally).
23
+ *
24
+ * Run: node --test scripts/quality-gates-cross-binding.test.mjs
25
+ */
26
+ import test from 'node:test'
27
+ import assert from 'node:assert/strict'
28
+ import { createHash } from 'node:crypto'
29
+ import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
30
+ import { tmpdir } from 'node:os'
31
+ import { join } from 'node:path'
32
+ import { canDeclareDelivery } from '../lib/quality-gates.js'
33
+
34
+ const qualityGates = await import('../lib/quality-gates.js')
35
+ const artifacts = await import('../lib/artifacts.js').catch(() => undefined)
36
+ const bindingReady = typeof qualityGates.verdictScopePatterns === 'function'
37
+ && typeof qualityGates.bindReviewToRevision === 'function'
38
+ && artifacts !== undefined
39
+ const skip = bindingReady ? false : 'content binding not present in this build'
40
+
41
+ /** Real workspace with the two files the S-BC trace touched. */
42
+ function workspace() {
43
+ const root = mkdtempSync(join(tmpdir(), 'issue161x175-'))
44
+ mkdirSync(join(root, 'lib'), { recursive: true })
45
+ writeFileSync(join(root, 'lib', 'format.js'), 'export const format = (n) => String(n)\n')
46
+ writeFileSync(join(root, 'lib', 'sum.js'), 'export const sum = (a, b) => a + b\n')
47
+ return root
48
+ }
49
+
50
+ const read = (root, paths) => artifacts.digestWorkspacePaths(root, paths)
51
+
52
+ /** The real S-BC graph: pre-planned review rewired to the automatic re-check. */
53
+ function sbcTeam(reviewExtra = {}) {
54
+ const base = { createdAt: 0, updatedAt: Date.now(), dependencies: [], attempt: 1, assignee: 'engineer' }
55
+ return {
56
+ name: 't', id: 't', description: '', captainSessionId: 'captain', createdAt: 0, taskSeq: 6,
57
+ members: [
58
+ { id: 'm1', name: 'engineer', role: 'engineer', joinedAt: 0, status: 'idle' },
59
+ { id: 'm2', name: 'verifier', role: 'verifier', joinedAt: 0, status: 'idle' },
60
+ ],
61
+ tasks: [
62
+ { ...base, id: 't1', subject: 'impl', kind: 'implementation', status: 'completed', inScope: ['lib/'], acceptance: ['x'], verify: ['node --test'], changedPaths: ['lib/format.js'] },
63
+ { ...base, id: 't5', subject: 'repair-round-2', kind: 'repair', status: 'completed', round: 2, dependencies: ['t1'], sourceTaskId: 't1', sourceFindingIds: ['F1'], findingSourceTaskIds: ['t3'], inScope: ['lib/', 'test/'], acceptance: ['y'], verify: ['node --test'], changedPaths: ['lib/sum.js'] },
64
+ { ...base, id: 't6', subject: 'verification-round-2', kind: 'verification', status: 'completed', round: 2, dependencies: ['t5'], acceptance: ['z'], verify: ['node --test'] },
65
+ {
66
+ ...base, id: 't4', subject: 'review-round-1', kind: 'review', status: 'completed', round: 2,
67
+ dependencies: ['t6'], reviewedTaskId: 't1', verdict: 'pass',
68
+ objective: 'Review the workspace implementation against the project contract',
69
+ acceptance: ['no blockers'],
70
+ ...reviewExtra,
71
+ },
72
+ ],
73
+ }
74
+ }
75
+
76
+ test('#161x#175: the rewired review binds the whole judged lineage, not only the original source', {
77
+ skip,
78
+ }, () => {
79
+ const root = workspace()
80
+ try {
81
+ const state = sbcTeam()
82
+ const scope = qualityGates.verdictScopePatterns(state, state.tasks[3])
83
+ assert.deepEqual(
84
+ [...scope].sort(),
85
+ ['lib/format.js', 'lib/sum.js'],
86
+ `the review scope lost a judged artifact: ${JSON.stringify(scope)}`,
87
+ )
88
+ } finally {
89
+ rmSync(root, { recursive: true, force: true })
90
+ }
91
+ })
92
+
93
+ test('#161x#175: after the loop closes, a later real edit of the repair target blocks delivery', {
94
+ skip,
95
+ }, () => {
96
+ const root = workspace()
97
+ try {
98
+ const state = sbcTeam()
99
+ const review = state.tasks[3]
100
+ // The production path: the bound bytes are exactly the derived scope.
101
+ const scope = qualityGates.verdictScopePatterns(state, review)
102
+ const bound = qualityGates.bindReviewToRevision(state, review, {
103
+ artifacts: read(root, scope),
104
+ scope,
105
+ })
106
+ const verification = { ...state.tasks[2], reviewedAttempt: 1, reviewedArtifacts: read(root, ['lib/sum.js']) }
107
+ const closed = { ...state, tasks: [state.tasks[0], state.tasks[1], verification, bound] }
108
+ assert.equal(
109
+ canDeclareDelivery(closed, { artifacts: read(root, ['lib/format.js', 'lib/sum.js']) }).ok,
110
+ true,
111
+ 'precondition: the closed loop was deliverable',
112
+ )
113
+
114
+ // A later turn really rewrites the repair's target.
115
+ writeFileSync(join(root, 'lib', 'sum.js'), 'export const sum = (a, b) => Number(a) + Number(b)\n')
116
+ const after = canDeclareDelivery(closed, { artifacts: read(root, ['lib/format.js', 'lib/sum.js']) })
117
+ assert.equal(after.ok, false, `a changed gate input was still delivered: ${JSON.stringify(after)}`)
118
+ assert.ok(
119
+ after.blockers.some((item) => item.includes('lib/sum.js')),
120
+ `no blocker names the changed artifact: ${JSON.stringify(after.blockers)}`,
121
+ )
122
+ } finally {
123
+ rmSync(root, { recursive: true, force: true })
124
+ }
125
+ })
126
+
127
+ test('#161x#175: the legacy shape (review bound only the old source) still blocks via the verification', {
128
+ skip,
129
+ }, () => {
130
+ const root = workspace()
131
+ try {
132
+ // The pre-fix binding: the review covers lib/format.js only, exactly like
133
+ // the recorded S-BC artifact.
134
+ const state = sbcTeam({
135
+ reviewedAttempt: 1,
136
+ reviewedArtifacts: read(root, ['lib/format.js']),
137
+ reviewedScope: ['lib/format.js'],
138
+ })
139
+ const verification = { ...state.tasks[2], reviewedAttempt: 1, reviewedArtifacts: read(root, ['lib/sum.js']) }
140
+ const closed = { ...state, tasks: [state.tasks[0], state.tasks[1], verification, state.tasks[3]] }
141
+ assert.equal(canDeclareDelivery(closed, { artifacts: read(root, ['lib/format.js', 'lib/sum.js']) }).ok, true)
142
+
143
+ writeFileSync(join(root, 'lib', 'sum.js'), 'export const sum = (a, b) => Number(a) + Number(b)\n')
144
+ const after = canDeclareDelivery(closed, { artifacts: read(root, ['lib/format.js', 'lib/sum.js']) })
145
+ assert.equal(after.ok, false, `a drifted verification was demoted to a warning: ${JSON.stringify(after)}`)
146
+ assert.ok(
147
+ after.blockers.some((item) => item.includes('t6') && item.includes('lib/sum.js')),
148
+ `the drifted verification is not a blocker: ${JSON.stringify(after.blockers)}`,
149
+ )
150
+ } finally {
151
+ rmSync(root, { recursive: true, force: true })
152
+ }
153
+ })
154
+
155
+ test('#161x#175: a later sound review that binds both artifacts restores delivery', {
156
+ skip,
157
+ }, () => {
158
+ const root = workspace()
159
+ try {
160
+ const state = sbcTeam({
161
+ reviewedAttempt: 1,
162
+ reviewedArtifacts: read(root, ['lib/format.js']),
163
+ reviewedScope: ['lib/format.js'],
164
+ })
165
+ const verification = { ...state.tasks[2], reviewedAttempt: 1, reviewedArtifacts: read(root, ['lib/sum.js']) }
166
+ writeFileSync(join(root, 'lib', 'sum.js'), 'export const sum = (a, b) => Number(a) + Number(b)\n')
167
+ const recheck = {
168
+ ...state.tasks[3],
169
+ id: 't9', subject: 'review-round-3', round: 3, createdAt: 900, updatedAt: Date.now(),
170
+ dependencies: ['t6'], reviewedTaskId: 't5', reviewedAttempt: 1,
171
+ reviewedArtifacts: read(root, ['lib/format.js', 'lib/sum.js']),
172
+ reviewedScope: ['lib/format.js', 'lib/sum.js'],
173
+ }
174
+ const closed = { ...state, taskSeq: 9, tasks: [state.tasks[0], state.tasks[1], verification, state.tasks[3], recheck] }
175
+ const delivery = canDeclareDelivery(closed, { artifacts: read(root, ['lib/format.js', 'lib/sum.js']) })
176
+ assert.equal(delivery.ok, true, `a full re-review did not restore delivery: ${JSON.stringify(delivery)}`)
177
+ assert.ok(
178
+ delivery.warnings.some((item) => item.includes('superseded by t9')),
179
+ `the superseded gates were not reported: ${JSON.stringify(delivery.warnings)}`,
180
+ )
181
+ } finally {
182
+ rmSync(root, { recursive: true, force: true })
183
+ }
184
+ })
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regression tests for issue #183: repair rounds derived from findings on
4
+ * default-excluded paths (`secrets/` segments, `.env*`, `.git`, `.dsh`,
5
+ * `id_rsa*`) are unsatisfiable.
6
+ *
7
+ * `repairScopeFromFindings()` used to collect `finding.file` and every path
8
+ * mentioned in `requiredFix` unconditionally, while the completion gate
9
+ * `classifyChangedPath()` checks `isDefaultExcluded()` BEFORE `inScope`. A
10
+ * derived contract could therefore demand an edit (`acceptance` ← requiredFix,
11
+ * `inScope` ← that path) that the gate rejects the moment the member honestly
12
+ * reports it in `changedPaths`: `repair cannot complete: <path> is
13
+ * out_of_scope`. No honest completion exists, so the round can only burn its
14
+ * attempts and escalate.
15
+ *
16
+ * Contract generation and the completion gate must agree: default-excluded
17
+ * paths are not eligible repair scope, and a finding whose only targets are
18
+ * default-excluded must not silently produce a repair round.
19
+ *
20
+ * Run: node --test scripts/quality-gates-excluded-scope.test.mjs
21
+ */
22
+ import test from 'node:test'
23
+ import assert from 'node:assert/strict'
24
+ import {
25
+ classifyChangedPath,
26
+ planQualityFollowUp,
27
+ repairScopeFromFindings,
28
+ } from '../lib/quality-gates.js'
29
+
30
+ function finding(extra = {}) {
31
+ return { id: 'F1', severity: 'medium', problem: 'problem', requiredFix: 'fix it', ...extra }
32
+ }
33
+
34
+ function member(name, role) {
35
+ return { id: `member-${name}`, name, role, joinedAt: 0, status: 'idle' }
36
+ }
37
+
38
+ function teamWithSource(extra = {}) {
39
+ return {
40
+ name: 't', id: 't', description: '', captainSessionId: 'captain',
41
+ createdAt: 0, taskSeq: 1,
42
+ members: [member('implementer', 'implementer'), member('reviewer', 'reviewer')],
43
+ tasks: [{
44
+ id: 't1', subject: 'impl', status: 'completed', dependencies: [],
45
+ createdAt: 0, updatedAt: 0, attempt: 1, kind: 'implementation',
46
+ assignee: 'implementer',
47
+ inScope: ['src/'], acceptance: ['done'], verify: ['pnpm test'],
48
+ ...extra,
49
+ }],
50
+ }
51
+ }
52
+
53
+ function failedReview(extra = {}) {
54
+ return {
55
+ id: 't2', subject: 'review', status: 'failed', dependencies: ['t1'],
56
+ createdAt: 0, updatedAt: 0, attempt: 1, kind: 'review', round: 1,
57
+ assignee: 'reviewer', verdict: 'needs_revision', reviewedTaskId: 't1',
58
+ objective: 'Review', acceptance: ['no blockers'],
59
+ findings: [finding()],
60
+ ...extra,
61
+ }
62
+ }
63
+
64
+ test('#183: derived repair scope drops paths the completion gate classifies out_of_scope', () => {
65
+ const scope = repairScopeFromFindings(
66
+ [finding({ file: 'src/secrets/redactor.ts', requiredFix: 'remove the leaking log line in src/secrets/redactor.ts' })],
67
+ ['src/app/'],
68
+ )
69
+ assert.deepEqual(scope, ['src/app/'], `default-excluded path leaked into scope: ${JSON.stringify(scope)}`)
70
+ })
71
+
72
+ test('#183: .env.example and secrets/ findings never produce an unsatisfiable inScope entry', () => {
73
+ const scope = repairScopeFromFindings(
74
+ [
75
+ finding({ id: 'F1', file: '.env.example', requiredFix: 'document APP_SECRET in .env.example' }),
76
+ finding({ id: 'F2', file: 'lib/secrets/parser.ts', requiredFix: 'harden lib/secrets/parser.ts' }),
77
+ finding({ id: 'F3', file: 'src/app/config.ts', requiredFix: 'read the value from src/app/config.ts' }),
78
+ ],
79
+ ['src/app/'],
80
+ )
81
+ assert.deepEqual(scope, ['src/app/config.ts'])
82
+ for (const entry of scope ?? []) {
83
+ assert.notEqual(
84
+ classifyChangedPath(entry, scope ?? [], []),
85
+ 'out_of_scope',
86
+ `derived scope entry ${entry} is rejected by the completion gate`,
87
+ )
88
+ }
89
+ })
90
+
91
+ test('#183: a repair round whose only cited targets are default-excluded escalates instead of dead-locking', () => {
92
+ const team = teamWithSource()
93
+ const review = failedReview({
94
+ findings: [finding({ file: 'src/secrets/redactor.ts', requiredFix: 'redact src/secrets/redactor.ts' })],
95
+ })
96
+ team.tasks.push(review)
97
+ const planned = planQualityFollowUp(team, review)
98
+ assert.equal(planned.created.length, 0, `unsatisfiable repair round was generated: ${JSON.stringify(planned.created)}`)
99
+ assert.equal(planned.escalated, true)
100
+ assert.match(String(planned.reason ?? ''), /excluded|secrets|\.env/iu)
101
+ })
102
+
103
+ test('#183: a mixed round keeps the legal target and records the excluded finding for the user', () => {
104
+ const team = teamWithSource()
105
+ const review = failedReview({
106
+ findings: [
107
+ finding({ id: 'F1', file: 'src/secrets/redactor.ts', requiredFix: 'redact src/secrets/redactor.ts' }),
108
+ finding({ id: 'F2', file: 'src/app/config.ts', requiredFix: 'read the value from src/app/config.ts' }),
109
+ ],
110
+ })
111
+ team.tasks.push(review)
112
+ const planned = planQualityFollowUp(team, review)
113
+ const repair = planned.created.find((item) => item.kind === 'repair')
114
+ assert.ok(repair, 'no repair round generated for the legal finding')
115
+ assert.deepEqual(repair.inScope, ['src/app/config.ts'])
116
+ assert.deepEqual(repair.acceptance, ['read the value from src/app/config.ts'])
117
+ assert.deepEqual(repair.sourceFindingIds, ['F2'])
118
+ assert.equal(planned.escalated, undefined)
119
+ assert.match(String(planned.excludedFindings ?? ''), /F1/u)
120
+ })
121
+
122
+ test('#183: the completion gate itself still refuses default-excluded paths (unchanged invariant)', () => {
123
+ assert.equal(classifyChangedPath('src/secrets/redactor.ts', ['src/secrets/'], []), 'out_of_scope')
124
+ assert.equal(classifyChangedPath('.env.example', ['.env.example'], []), 'out_of_scope')
125
+ assert.equal(classifyChangedPath('src/app/config.ts', ['src/app/'], []), 'in_scope')
126
+ })
127
+
128
+ test('#183: a prose path that is not a real file cannot rescue an excluded finding', () => {
129
+ // Real run (deepseek-flash, 2026-10-10): a blocker finding named
130
+ // src/secrets/redactor.js and its requiredFix said "never pass value to any
131
+ // console/stream write". `console/stream` is not a workspace path, but it
132
+ // made the finding look actionable, so the excluded finding produced a
133
+ // repair whose acceptance demanded an edit the gate forbids.
134
+ const team = teamWithSource()
135
+ const review = failedReview({
136
+ findings: [finding({
137
+ file: 'src/secrets/redactor.js',
138
+ requiredFix: "Remove the console.log from src/secrets/redactor.js and never pass `value` to any console/stream write.",
139
+ })],
140
+ })
141
+ team.tasks.push(review)
142
+ const planned = planQualityFollowUp(team, review, { pathExists: () => false })
143
+ assert.equal(planned.created.length, 0, `impossible repair was generated: ${JSON.stringify(planned.created)}`)
144
+ assert.equal(planned.escalated, true)
145
+ assert.match(String(planned.reason ?? ''), /excluded|secrets/iu)
146
+ assert.deepEqual(planned.excludedFindings, ['F1'])
147
+ })
148
+
149
+ test('#183: a real legal target keeps the finding actionable, and a missing own file is not discarded', () => {
150
+ const team = teamWithSource()
151
+ const review = failedReview({
152
+ findings: [
153
+ finding({ id: 'F1', file: 'src/app/config.js', requiredFix: 'route logging through src/app/config.js' }),
154
+ finding({ id: 'F2', file: 'src/app/new-logger.js', requiredFix: 'create src/app/new-logger.js' }),
155
+ ],
156
+ })
157
+ team.tasks.push(review)
158
+ const planned = planQualityFollowUp(team, review, { pathExists: (path) => path === 'src/app/config.js' })
159
+ const repair = planned.created.find((item) => item.kind === 'repair')
160
+ assert.ok(repair, 'a legal finding produced no repair round')
161
+ assert.deepEqual(repair.inScope, ['src/app/config.js', 'src/app/new-logger.js'])
162
+ assert.equal(planned.escalated, undefined)
163
+ })
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regression tests for auto-repair inScope derivation (planQualityFollowUp).
4
+ *
5
+ * Incident: a review finding observed the mismatch in `data/sample.txt` but
6
+ * its requiredFix said "edit README.md". The generated repair round declared
7
+ * inScope from `finding.file` alone, so its acceptance ("edit README.md")
8
+ * named a path the scope forbade — no honest completion existed and the
9
+ * repair dead-locked (worker blocked, downstream review permanently pending).
10
+ *
11
+ * Issue #173: derive every required path before dropping inherited exclusions
12
+ * that conflict with the generated repair scope. Handwritten contracts still
13
+ * enforce outOfScope first.
14
+ *
15
+ * Run: node --test scripts/quality-gates-repair-scope.test.mjs
16
+ */
17
+ import test from 'node:test'
18
+ import assert from 'node:assert/strict'
19
+ import { classifyChangedPath, evaluateQualityCompletion, planQualityFollowUp, repairScopeFromFindings } from '../lib/quality-gates.js'
20
+
21
+ function finding(extra = {}) {
22
+ return { id: 'F1', severity: 'medium', problem: 'problem', requiredFix: 'fix it', ...extra }
23
+ }
24
+
25
+ function member(name, role) {
26
+ return { id: `member-${name}`, name, role, joinedAt: 0, status: 'idle' }
27
+ }
28
+
29
+ function teamWithSource(extra = {}) {
30
+ return {
31
+ name: 't', id: 't', description: '', captainSessionId: 'captain',
32
+ createdAt: 0, taskSeq: 1,
33
+ members: [member('implementer', 'implementer'), member('reviewer', 'reviewer')],
34
+ tasks: [{
35
+ id: 't1', subject: 'impl', status: 'completed', dependencies: [],
36
+ createdAt: 0, updatedAt: 0, attempt: 1, kind: 'implementation',
37
+ assignee: 'implementer',
38
+ inScope: ['src/'], acceptance: ['done'], verify: ['pnpm test'],
39
+ ...extra,
40
+ }],
41
+ }
42
+ }
43
+
44
+ function failedReview(extra = {}) {
45
+ return {
46
+ id: 't2', subject: 'review', status: 'failed', dependencies: ['t1'],
47
+ createdAt: 0, updatedAt: 0, attempt: 1, kind: 'review', round: 1,
48
+ assignee: 'reviewer', verdict: 'needs_revision', reviewedTaskId: 't1',
49
+ objective: 'Review', acceptance: ['no blockers'],
50
+ findings: [finding()],
51
+ ...extra,
52
+ }
53
+ }
54
+
55
+ test('repair scope includes the fix target named in requiredFix, not just the observed file', () => {
56
+ const scope = repairScopeFromFindings(
57
+ [finding({ file: 'data/sample.txt', requiredFix: 'change README.md:5 to "2 lines / 5 words"' })],
58
+ ['data/sample.txt'],
59
+ )
60
+ assert.ok(scope.includes('README.md'), `README.md missing from ${JSON.stringify(scope)}`)
61
+ assert.ok(scope.includes('data/sample.txt'), `observed file missing from ${JSON.stringify(scope)}`)
62
+ })
63
+
64
+ test('repair scope drops absolute paths that can never match workspace-relative patterns', () => {
65
+ const scope = repairScopeFromFindings(
66
+ [finding({ file: 'F:\\team\\data\\sample.txt', requiredFix: 'update README.md sample reference to 5 words' })],
67
+ ['src/'],
68
+ )
69
+ assert.deepEqual(scope, ['README.md'])
70
+ })
71
+
72
+ test('repair scope falls back to the source inScope when findings name nothing legal', () => {
73
+ const scope = repairScopeFromFindings(
74
+ [finding({ requiredFix: 'reinstall the tool globally and retry' })],
75
+ ['src/'],
76
+ )
77
+ assert.deepEqual(scope, ['src/'])
78
+ })
79
+
80
+ test('line-number suffixes are stripped from derived paths', () => {
81
+ const scope = repairScopeFromFindings(
82
+ [finding({ requiredFix: 'rewrite docs/guide.md:42 to match the new flow' })],
83
+ undefined,
84
+ )
85
+ assert.deepEqual(scope, ['docs/guide.md'])
86
+ })
87
+
88
+ test('end-to-end: generated repair round is satisfiable for the incident shape', () => {
89
+ const closed = failedReview({
90
+ findings: [finding({
91
+ file: 'data/sample.txt',
92
+ requiredFix: 'A (recommended) change README.md to "2 lines / 5 words"; do not modify wc.js',
93
+ })],
94
+ })
95
+ const result = planQualityFollowUp(teamWithSource(), closed)
96
+ const repair = result.created.find((item) => item.kind === 'repair')
97
+ assert.ok(repair, 'repair round must be generated')
98
+ assert.ok(repair.inScope.includes('README.md'), `README.md missing from ${JSON.stringify(repair.inScope)}`)
99
+ assert.ok(
100
+ repair.acceptance.every((criterion) => criterion.length > 0),
101
+ 'acceptance must stay non-empty',
102
+ )
103
+ })
104
+
105
+ for (const [label, source, findings, expectedScope, expectedExclusions] of [
106
+ ['real F_DOC incident',
107
+ { inScope: ['data/sample.txt'], outOfScope: ['README.md', 'check-data.mjs', 'reports/'] },
108
+ [finding({ file: 'data/sample.txt', requiredFix: 'Edit README.md to contain exactly 2 words. Keep data/sample.txt unchanged.' })],
109
+ ['data/sample.txt', 'README.md'], ['check-data.mjs', 'reports/']],
110
+ ['directory exclusion covers observed and required paths',
111
+ { inScope: ['src/'], outOfScope: ['deploy/', 'go.mod'] },
112
+ [finding({ file: 'deploy/old.txt', requiredFix: 'edit deploy/new.txt and deploy/old.txt' }), finding({ file: 'deploy/old.txt' })],
113
+ ['deploy/old.txt', 'deploy/new.txt'], ['go.mod']],
114
+ ['fallback scope has duplicates and overlapping exclusions',
115
+ { inScope: ['src/', 'src/'], outOfScope: ['src/private.ts', 'docs/'] },
116
+ [finding()], ['src/'], ['docs/']],
117
+ ]) {
118
+ test(`generated repair is completable: ${label}`, () => {
119
+ const state = teamWithSource(source)
120
+ const original = structuredClone(state)
121
+ const closed = failedReview({ findings })
122
+ const result = planQualityFollowUp(state, closed)
123
+ const repair = result.created.find((item) => item.kind === 'repair')
124
+ assert.deepEqual(repair.inScope, expectedScope)
125
+ assert.deepEqual(repair.outOfScope, expectedExclusions)
126
+ assert.deepEqual(state, original, 'source contract must remain untouched')
127
+ assert.deepEqual(repair.acceptance, findings.map((item) => item.requiredFix))
128
+ for (const path of expectedScope) {
129
+ const concretePath = path.endsWith('/') ? `${path}fixed.ts` : path
130
+ assert.equal(classifyChangedPath(concretePath, repair.inScope, repair.outOfScope), 'in_scope')
131
+ const completion = evaluateQualityCompletion({ ...repair, status: 'in_progress' }, {
132
+ status: 'completed', changedPaths: [concretePath],
133
+ acceptanceResults: repair.acceptance.map((criterion) => ({ criterion, status: 'passed' })),
134
+ commandsRun: [{ command: 'pnpm test', status: 'passed', exitCode: 0 }],
135
+ })
136
+ assert.equal(completion.ok, true, completion.error)
137
+ }
138
+ assert.equal(result.created.find((item) => item.kind === 'review').reviewedTaskId, repair.id)
139
+ for (const path of expectedExclusions) {
140
+ assert.equal(classifyChangedPath(path, repair.inScope, repair.outOfScope), 'out_of_scope')
141
+ }
142
+ })
143
+ }