@aviaratech/ai-delivery 0.3.35 → 0.3.36

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 (297) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -554
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1651 -1590
  9. package/dist/boardReconcile.test.js.map +7 -1
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +402 -515
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -45
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +424 -369
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +288 -14
  22. package/dist/config/deliveryConfig.js +472 -390
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +773 -649
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -479
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.js +649 -0
  53. package/dist/deliveryBoard.test.js.map +7 -0
  54. package/dist/deliveryHealth.test.js +179 -155
  55. package/dist/deliveryHealth.test.js.map +7 -1
  56. package/dist/dependencyCompatibility.test.js +154 -140
  57. package/dist/dependencyCompatibility.test.js.map +7 -1
  58. package/dist/directoryIndependent.test.js +417 -383
  59. package/dist/directoryIndependent.test.js.map +7 -1
  60. package/dist/dispatch.d.ts +16 -11
  61. package/dist/dispatch.js +329 -353
  62. package/dist/dispatch.js.map +7 -1
  63. package/dist/errors.d.ts +3 -3
  64. package/dist/errors.js +103 -96
  65. package/dist/errors.js.map +7 -1
  66. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  67. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  68. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  69. package/dist/fixtures/discovery.d.ts +59 -19
  70. package/dist/fixtures/discovery.js +96 -90
  71. package/dist/fixtures/discovery.js.map +7 -1
  72. package/dist/fixtures/inertEntrypointChild.js +57 -56
  73. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  74. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  75. package/dist/fixtures/inertEntrypoints.js +321 -276
  76. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  77. package/dist/fixtures/inertTarget.d.ts +78 -7
  78. package/dist/fixtures/inertTarget.js +769 -691
  79. package/dist/fixtures/inertTarget.js.map +7 -1
  80. package/dist/fixtures/issue63.d.ts +4 -3
  81. package/dist/fixtures/issue63.js +260 -274
  82. package/dist/fixtures/issue63.js.map +7 -1
  83. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  84. package/dist/fixtures/issueProjectItems.js +15 -0
  85. package/dist/fixtures/issueProjectItems.js.map +7 -0
  86. package/dist/fixtures/readView.d.ts +120 -0
  87. package/dist/fixtures/readView.js +172 -0
  88. package/dist/fixtures/readView.js.map +7 -0
  89. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  90. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  91. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  92. package/dist/genericCompatibility.test.js +64 -55
  93. package/dist/genericCompatibility.test.js.map +7 -1
  94. package/dist/git.js +73 -67
  95. package/dist/git.js.map +7 -1
  96. package/dist/gitProcess.d.ts +1 -1
  97. package/dist/gitProcess.js +58 -53
  98. package/dist/gitProcess.js.map +7 -1
  99. package/dist/github/client.d.ts +2 -2
  100. package/dist/github/client.js +484 -379
  101. package/dist/github/client.js.map +7 -1
  102. package/dist/github/commandIdentityPolicy.js +44 -52
  103. package/dist/github/commandIdentityPolicy.js.map +7 -1
  104. package/dist/github/discovery.d.ts +1 -0
  105. package/dist/github/discovery.js +197 -215
  106. package/dist/github/discovery.js.map +7 -1
  107. package/dist/github/discovery.test.js +223 -177
  108. package/dist/github/discovery.test.js.map +7 -1
  109. package/dist/github/issueHistory.d.ts +2 -2
  110. package/dist/github/issueHistory.js +117 -125
  111. package/dist/github/issueHistory.js.map +7 -1
  112. package/dist/github/machineAuth.d.ts +1 -1
  113. package/dist/github/machineAuth.js +126 -117
  114. package/dist/github/machineAuth.js.map +7 -1
  115. package/dist/github/machineAuth.test.js +755 -639
  116. package/dist/github/machineAuth.test.js.map +7 -1
  117. package/dist/github/nativeIssueMetadata.js +286 -273
  118. package/dist/github/nativeIssueMetadata.js.map +7 -1
  119. package/dist/github/projectDelivery.d.ts +18 -2
  120. package/dist/github/projectDelivery.js +615 -557
  121. package/dist/github/projectDelivery.js.map +7 -1
  122. package/dist/github/relationships.js +433 -389
  123. package/dist/github/relationships.js.map +7 -1
  124. package/dist/github/repo.d.ts +1 -0
  125. package/dist/github/repo.js +123 -96
  126. package/dist/github/repo.js.map +7 -1
  127. package/dist/index.js +3 -3
  128. package/dist/index.js.map +7 -1
  129. package/dist/issue.d.ts +40 -9
  130. package/dist/issue.js +2102 -1742
  131. package/dist/issue.js.map +7 -1
  132. package/dist/issue63History.test.js +40 -42
  133. package/dist/issue63History.test.js.map +7 -1
  134. package/dist/issue63Routes.test.js +154 -143
  135. package/dist/issue63Routes.test.js.map +7 -1
  136. package/dist/issueBatchUpdate.test.js +989 -885
  137. package/dist/issueBatchUpdate.test.js.map +7 -1
  138. package/dist/issueBlockerGuard.test.js +262 -226
  139. package/dist/issueBlockerGuard.test.js.map +7 -1
  140. package/dist/issueContract.d.ts +23 -4
  141. package/dist/issueContract.js +416 -395
  142. package/dist/issueContract.js.map +7 -1
  143. package/dist/issueContract.test.d.ts +4 -3
  144. package/dist/issueContract.test.js +358 -321
  145. package/dist/issueContract.test.js.map +7 -1
  146. package/dist/issueDates.test.js +235 -233
  147. package/dist/issueDates.test.js.map +7 -1
  148. package/dist/issueInfoReadback.test.js +304 -190
  149. package/dist/issueInfoReadback.test.js.map +7 -1
  150. package/dist/issueIntake.test.js +1945 -1732
  151. package/dist/issueIntake.test.js.map +7 -1
  152. package/dist/issueJournal.d.ts +40 -19
  153. package/dist/issueJournal.js +229 -138
  154. package/dist/issueJournal.js.map +7 -1
  155. package/dist/issueJournal.test.js +605 -422
  156. package/dist/issueJournal.test.js.map +7 -1
  157. package/dist/issueRollup.test.d.ts +1 -0
  158. package/dist/issueRollup.test.js +476 -0
  159. package/dist/issueRollup.test.js.map +7 -0
  160. package/dist/issueTracking.test.js +1059 -989
  161. package/dist/issueTracking.test.js.map +7 -1
  162. package/dist/issueWriteRecovery.test.d.ts +1 -0
  163. package/dist/issueWriteRecovery.test.js +260 -0
  164. package/dist/issueWriteRecovery.test.js.map +7 -0
  165. package/dist/lifecycle.test.js +112 -441
  166. package/dist/lifecycle.test.js.map +7 -1
  167. package/dist/logger.js +80 -74
  168. package/dist/logger.js.map +7 -1
  169. package/dist/mcp/index.js +116 -94
  170. package/dist/mcp/index.js.map +7 -1
  171. package/dist/mcp/tools.d.ts +264 -286
  172. package/dist/mcp/tools.js +267 -340
  173. package/dist/mcp/tools.js.map +7 -1
  174. package/dist/pluginAuthProbe.js +63 -52
  175. package/dist/pluginAuthProbe.js.map +7 -1
  176. package/dist/pluginAuthProbe.test.js +85 -62
  177. package/dist/pluginAuthProbe.test.js.map +7 -1
  178. package/dist/pluginCredentials.test.js +282 -259
  179. package/dist/pluginCredentials.test.js.map +7 -1
  180. package/dist/pluginDoctor.test.js +653 -588
  181. package/dist/pluginDoctor.test.js.map +7 -1
  182. package/dist/pluginInstaller.d.ts +7 -5
  183. package/dist/pluginInstaller.js +1173 -1229
  184. package/dist/pluginInstaller.js.map +7 -1
  185. package/dist/pluginInstaller.test.js +1842 -1423
  186. package/dist/pluginInstaller.test.js.map +7 -1
  187. package/dist/pluginPackaging.test.js +460 -409
  188. package/dist/pluginPackaging.test.js.map +7 -1
  189. package/dist/pr.d.ts +132 -94
  190. package/dist/pr.js +1521 -1323
  191. package/dist/pr.js.map +7 -1
  192. package/dist/pr.test.js +1678 -632
  193. package/dist/pr.test.js.map +7 -1
  194. package/dist/prAssociation.test.js +2419 -1788
  195. package/dist/prAssociation.test.js.map +7 -1
  196. package/dist/prDispatch.test.js +150 -89
  197. package/dist/prDispatch.test.js.map +7 -1
  198. package/dist/readView.d.ts +183 -0
  199. package/dist/readView.js +217 -0
  200. package/dist/readView.js.map +7 -0
  201. package/dist/readView.test.d.ts +1 -0
  202. package/dist/readView.test.js +119 -0
  203. package/dist/readView.test.js.map +7 -0
  204. package/dist/releaseReconciliation.test.js +267 -288
  205. package/dist/releaseReconciliation.test.js.map +7 -1
  206. package/dist/releaseWorkflow.test.js +2493 -422
  207. package/dist/releaseWorkflow.test.js.map +7 -1
  208. package/dist/review.d.ts +738 -2
  209. package/dist/review.js +601 -348
  210. package/dist/review.js.map +7 -1
  211. package/dist/review.test.js +1218 -812
  212. package/dist/review.test.js.map +7 -1
  213. package/dist/reviewSubmit.test.d.ts +1 -0
  214. package/dist/reviewSubmit.test.js +747 -0
  215. package/dist/reviewSubmit.test.js.map +7 -0
  216. package/dist/services/agentReadinessService.js +42 -37
  217. package/dist/services/agentReadinessService.js.map +7 -1
  218. package/dist/services/blockerGuardService.js +188 -188
  219. package/dist/services/blockerGuardService.js.map +7 -1
  220. package/dist/services/boardReconcileService.d.ts +125 -125
  221. package/dist/services/boardReconcileService.js +1295 -1421
  222. package/dist/services/boardReconcileService.js.map +7 -1
  223. package/dist/services/deliveryAdmission.js +131 -154
  224. package/dist/services/deliveryAdmission.js.map +7 -1
  225. package/dist/services/deliveryHealthService.js +197 -199
  226. package/dist/services/deliveryHealthService.js.map +7 -1
  227. package/dist/services/legacyIssueMigration.js +263 -277
  228. package/dist/services/legacyIssueMigration.js.map +7 -1
  229. package/dist/services/worktreeRegistry.d.ts +27 -119
  230. package/dist/services/worktreeRegistry.js +765 -1182
  231. package/dist/services/worktreeRegistry.js.map +7 -1
  232. package/dist/stagedChecks.test.js +396 -194
  233. package/dist/stagedChecks.test.js.map +7 -1
  234. package/dist/start.test.js +99 -95
  235. package/dist/start.test.js.map +7 -1
  236. package/dist/stdoutRegression.test.js +353 -352
  237. package/dist/stdoutRegression.test.js.map +7 -1
  238. package/dist/targetPolicyDiscovery.test.js +141 -143
  239. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  240. package/dist/targetPolicyEntrypoints.test.js +308 -269
  241. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  242. package/dist/targetPolicyLocal.test.js +580 -1051
  243. package/dist/targetPolicyLocal.test.js.map +7 -1
  244. package/dist/targetPolicyRoutes.test.js +305 -281
  245. package/dist/targetPolicyRoutes.test.js.map +7 -1
  246. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  247. package/dist/targetRepositoryExecution.test.js +463 -0
  248. package/dist/targetRepositoryExecution.test.js.map +7 -0
  249. package/dist/terminalMessages.js +41 -35
  250. package/dist/terminalMessages.js.map +7 -1
  251. package/dist/toolOutput.d.ts +2 -0
  252. package/dist/toolOutput.js +36 -0
  253. package/dist/toolOutput.js.map +7 -0
  254. package/dist/toolOutput.test.d.ts +1 -0
  255. package/dist/toolOutput.test.js +240 -0
  256. package/dist/toolOutput.test.js.map +7 -0
  257. package/dist/utils/atomicJson.js +84 -76
  258. package/dist/utils/atomicJson.js.map +7 -1
  259. package/dist/utils/filesystem.js +15 -18
  260. package/dist/utils/filesystem.js.map +7 -1
  261. package/dist/utils/lockfile.js +68 -71
  262. package/dist/utils/lockfile.js.map +7 -1
  263. package/dist/verification.d.ts +1 -19
  264. package/dist/verification.js +1020 -1939
  265. package/dist/verification.js.map +7 -1
  266. package/dist/verificationGate.test.js +127 -117
  267. package/dist/verificationGate.test.js.map +7 -1
  268. package/dist/version.js +23 -24
  269. package/dist/version.js.map +7 -1
  270. package/dist/worktree.d.ts +3 -15
  271. package/dist/worktree.js +97 -177
  272. package/dist/worktree.js.map +7 -1
  273. package/package.json +9 -8
  274. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  275. package/plugins/ai-delivery/README.md +47 -156
  276. package/plugins/ai-delivery/plugin.json +1 -1
  277. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
  278. package/plugins/ai-delivery/runtime/dist/cli.js +358 -115
  279. package/plugins/ai-delivery/runtime/package.json +1 -1
  280. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  281. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  282. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  283. package/dist/investigationCompletion.test.js +0 -728
  284. package/dist/investigationCompletion.test.js.map +0 -1
  285. package/dist/setup.d.ts +0 -60
  286. package/dist/setup.js +0 -585
  287. package/dist/setup.js.map +0 -1
  288. package/dist/setup.test.js +0 -3329
  289. package/dist/setup.test.js.map +0 -1
  290. package/dist/worktreeTransition.d.ts +0 -211
  291. package/dist/worktreeTransition.js +0 -1037
  292. package/dist/worktreeTransition.js.map +0 -1
  293. package/dist/worktreeTransition.test.js +0 -1191
  294. package/dist/worktreeTransition.test.js.map +0 -1
  295. /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
  296. /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
  297. /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
@@ -1,1685 +1,1746 @@
1
- import assert from 'node:assert/strict';
2
- import { execFileSync } from 'node:child_process';
3
- import { cpSync, mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, realpathSync, symlinkSync, } from 'node:fs';
4
- import { fileURLToPath } from 'node:url';
5
- import { join } from 'node:path';
6
- import { tmpdir } from 'node:os';
7
- import { afterEach, test, vi } from 'vitest';
8
- import { loadDeliveryConfig } from './config/deliveryConfig.js';
9
- import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from './fixtures/discovery.js';
10
- import { IssueFields, parseIssueBody, renderIssueBody } from './issueContract.js';
11
- import { gitEnvironment } from './gitProcess.js';
12
- import * as board from './services/boardReconcileService.js';
13
- import * as version from './version.js';
14
- import { digestValue } from './delivery/common.js';
15
- import { executeTool } from './dispatch.js';
16
- import * as githubClients from './github/client.js';
17
- import * as issueModule from './issue.js';
18
- import { createAiDeliveryMcpServer } from './mcp/index.js';
19
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
20
- import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
1
+ import { issueProjectItemsResponse } from "./fixtures/issueProjectItems.js";
2
+ import assert from "node:assert/strict";
3
+ import { execFileSync } from "node:child_process";
4
+ import {
5
+ cpSync,
6
+ mkdtempSync,
7
+ mkdirSync,
8
+ writeFileSync,
9
+ readFileSync,
10
+ rmSync,
11
+ realpathSync,
12
+ symlinkSync
13
+ } from "node:fs";
14
+ import { fileURLToPath } from "node:url";
15
+ import { join } from "node:path";
16
+ import { tmpdir } from "node:os";
17
+ import { afterEach, test, vi } from "vitest";
18
+ import { loadDeliveryConfig } from "./config/deliveryConfig.js";
19
+ import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from "./fixtures/discovery.js";
20
+ import { IssueFields, parseIssueBody, renderIssueBody } from "./issueContract.js";
21
+ import { gitEnvironment } from "./gitProcess.js";
22
+ import * as board from "./services/boardReconcileService.js";
23
+ import * as version from "./version.js";
24
+ import { digestValue } from "./delivery/common.js";
25
+ import { executeTool } from "./dispatch.js";
26
+ import * as githubClients from "./github/client.js";
27
+ import * as issueModule from "./issue.js";
28
+ import { createAiDeliveryMcpServer } from "./mcp/index.js";
29
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
30
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
31
+ const ITEM_READ = /ProjectDelivery(Issue)?Items/u;
21
32
  afterEach(() => {
22
- vi.unstubAllEnvs();
23
- vi.restoreAllMocks();
33
+ vi.unstubAllEnvs();
34
+ vi.restoreAllMocks();
24
35
  });
25
- const boardName = 'board_reconcile';
36
+ const boardName = "board_reconcile";
26
37
  const collect = async (contexts, request, roots) => {
27
- return board.collectBoardReconcilePlan(contexts, request, { checkoutRoots: roots });
38
+ return board.collectBoardReconcilePlan(contexts, request, { checkoutRoots: roots });
28
39
  };
29
40
  async function applyPlan(f, plan, priorResult, signal) {
30
- const operation = Reflect.get(board, 'boardReconcile');
31
- assert.equal(typeof operation, 'function');
32
- const request = board.parseBoardReconcileRequest({
33
- repositories: f.request.repositories,
34
- mode: 'apply',
35
- plan,
36
- ...(priorResult === undefined ? {} : { priorResult }),
37
- });
38
- return board.BoardReconcileResultSchema.parse(await operation(f.contexts, request, { checkoutRoots: [f.root], ...(signal === undefined ? {} : { signal }) }));
41
+ const operation = Reflect.get(board, "boardReconcile");
42
+ assert.equal(typeof operation, "function");
43
+ const request = board.parseBoardReconcileRequest({
44
+ repositories: f.request.repositories,
45
+ mode: "apply",
46
+ plan,
47
+ ...priorResult === void 0 ? {} : { priorResult }
48
+ });
49
+ return board.BoardReconcileResultSchema.parse(
50
+ await operation(f.contexts, request, { checkoutRoots: [f.root], ...signal === void 0 ? {} : { signal } })
51
+ );
39
52
  }
40
53
  function redigest(plan) {
41
- plan.operations = plan.operations.map((operation) => {
42
- const { operationId: _id, ...intent } = operation;
43
- return { ...intent, operationId: digestValue(intent) };
44
- });
45
- const { planId: _id, collectionStartedAt: _start, collectionCompletedAt: _end, ...semantic } = plan;
46
- plan.planId = digestValue(semantic);
54
+ plan.operations = plan.operations.map((operation) => {
55
+ const { operationId: _id2, ...intent } = operation;
56
+ return { ...intent, operationId: digestValue(intent) };
57
+ });
58
+ const { planId: _id, collectionStartedAt: _start, collectionCompletedAt: _end, ...semantic } = plan;
59
+ plan.planId = digestValue(semantic);
47
60
  }
48
- async function boardFixture(count = 101, repositories = ['example/widget'], independentProjects = false) {
49
- const root = realpathSync(mkdtempSync(join(tmpdir(), 'board-reconcile-')));
50
- const roles = {
51
- author: {
52
- identity: 'synthetic-author',
53
- credentialEnv: {
54
- appId: 'AUTHOR_APP_ID',
55
- installationId: 'AUTHOR_INSTALLATION_ID',
56
- privateKeyPath: 'AUTHOR_KEY_PATH',
57
- },
58
- },
59
- reviewer: {
60
- identity: 'synthetic-reviewer',
61
- credentialEnv: {
62
- appId: 'REVIEWER_APP_ID',
63
- installationId: 'REVIEWER_INSTALLATION_ID',
64
- privateKeyPath: 'REVIEWER_KEY_PATH',
65
- },
66
- },
61
+ async function boardFixture(count = 101, repositories = ["example/widget"], independentProjects = false) {
62
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "board-reconcile-")));
63
+ const roles = {
64
+ author: {
65
+ identity: "synthetic-author",
66
+ credentialEnv: {
67
+ appId: "AUTHOR_APP_ID",
68
+ installationId: "AUTHOR_INSTALLATION_ID",
69
+ privateKeyPath: "AUTHOR_KEY_PATH"
70
+ }
71
+ },
72
+ reviewer: {
73
+ identity: "synthetic-reviewer",
74
+ credentialEnv: {
75
+ appId: "REVIEWER_APP_ID",
76
+ installationId: "REVIEWER_INSTALLATION_ID",
77
+ privateKeyPath: "REVIEWER_KEY_PATH"
78
+ }
79
+ }
80
+ };
81
+ const settingsPath = join(root, "settings.json");
82
+ writeFileSync(
83
+ settingsPath,
84
+ JSON.stringify({
85
+ schemaVersion: "ai-delivery.user@1",
86
+ roles,
87
+ checkoutRoots: [root],
88
+ project: 1,
89
+ pointsField: "Estimate",
90
+ priorityField: "Urgency",
91
+ statusField: "Flow",
92
+ statuses: syntheticDiscoveryConfig.native.project.statuses
93
+ })
94
+ );
95
+ vi.stubEnv("AI_DELIVERY_CONFIG", settingsPath);
96
+ const ready = IssueFields.parse({
97
+ title: "Reconcile native widget",
98
+ issueType: "Task",
99
+ points: 2,
100
+ problem: "Board drift obscures native truth.",
101
+ outcome: "Report scoped native truth.",
102
+ acceptanceCriteria: [
103
+ { behavior: "Exact reconciliation retains issue truth.", verifiedBy: "Synthetic scoped fixture." }
104
+ ],
105
+ outOfScope: ["Native field repair."]
106
+ });
107
+ const rows = /* @__PURE__ */ new Map();
108
+ const members = /* @__PURE__ */ new Map();
109
+ const children = /* @__PURE__ */ new Map();
110
+ const blockers = /* @__PURE__ */ new Map();
111
+ const branches = /* @__PURE__ */ new Map();
112
+ const writes = [];
113
+ const controls = {
114
+ itemPages: 0,
115
+ issuePages: 0,
116
+ hiddenContent: false,
117
+ writable: true,
118
+ failAfterAdd: false,
119
+ automaticStatus: null,
120
+ failAfterStatus: false,
121
+ beforeGraphql: void 0,
122
+ afterWrite: void 0
123
+ };
124
+ const git = (cwd, args) => execFileSync("/usr/bin/git", ["-c", "core.hooksPath=/dev/null", ...args], {
125
+ cwd,
126
+ env: gitEnvironment(),
127
+ encoding: "utf8"
128
+ }).trim();
129
+ const clones = /* @__PURE__ */ new Map();
130
+ for (const repository of repositories) {
131
+ const clone = join(root, repository.split("/")[1]);
132
+ mkdirSync(clone);
133
+ clones.set(repository, clone);
134
+ git(clone, ["init", "-q", "-b", "main"]);
135
+ git(clone, ["remote", "add", "origin", `https://github.com/${repository}.git`]);
136
+ writeFileSync(join(clone, "README"), "fixture\n");
137
+ git(clone, ["add", "README"]);
138
+ git(clone, ["-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid", "commit", "-qm", "fixture"]);
139
+ for (let number = 17; number < 17 + count; number++) {
140
+ const key = `${repository}:${String(number)}`;
141
+ const node = `ISSUE-${key}`;
142
+ rows.set(key, {
143
+ number,
144
+ id: number,
145
+ node_id: node,
146
+ title: ready.title,
147
+ body: renderIssueBody(ready),
148
+ state: "open",
149
+ html_url: `https://github.com/${repository}/issues/${String(number)}`,
150
+ labels: [{ name: "estimate:2" }, { name: "area:widget" }],
151
+ type: { name: "Task" },
152
+ points: 2
153
+ });
154
+ members.set(node, { itemId: `ITEM-${key}`, repository, number, status: "Todo", archived: false });
155
+ }
156
+ }
157
+ const contexts = [];
158
+ const names = {
159
+ Todo: "Queued",
160
+ "In Progress": "Active",
161
+ Blocked: "Waiting",
162
+ Done: "Shipped"
163
+ };
164
+ const option = {
165
+ Todo: "STATUS-0",
166
+ "In Progress": "STATUS-1",
167
+ Blocked: "STATUS-2",
168
+ Done: "STATUS-3"
169
+ };
170
+ for (const repository of repositories) {
171
+ const organization = repository.split("/")[0];
172
+ const projectId = independentProjects ? `PROJECT-${organization}` : "PROJECT-1";
173
+ const configured = {
174
+ ...syntheticDiscoveryConfig,
175
+ repository,
176
+ native: { ...syntheticDiscoveryConfig.native, organization }
67
177
  };
68
- const settingsPath = join(root, 'settings.json');
69
- writeFileSync(settingsPath, JSON.stringify({
70
- schemaVersion: 'ai-delivery.user@1',
71
- roles,
72
- checkoutRoots: [root],
73
- project: 1,
74
- pointsField: 'Estimate',
75
- priorityField: 'Urgency',
76
- statusField: 'Flow',
77
- statuses: syntheticDiscoveryConfig.native.project.statuses,
78
- }));
79
- vi.stubEnv('AI_DELIVERY_CONFIG', settingsPath);
80
- const ready = IssueFields.parse({
81
- title: 'Reconcile native widget',
82
- issueType: 'Task',
83
- points: 2,
84
- problem: 'Board drift obscures native truth.',
85
- outcome: 'Report scoped native truth.',
86
- acceptanceCriteria: [
87
- { behavior: 'Exact reconciliation retains issue truth.', verifiedBy: 'Synthetic scoped fixture.' },
88
- ],
89
- outOfScope: ['Native field repair.'],
90
- });
91
- const rows = new Map();
92
- const members = new Map();
93
- const children = new Map();
94
- const blockers = new Map();
95
- const branches = new Map();
96
- const writes = [];
97
- const controls = {
98
- itemPages: 0,
99
- issuePages: 0,
100
- hiddenContent: false,
101
- writable: true,
102
- failAfterAdd: false,
103
- automaticStatus: null,
104
- failAfterStatus: false,
105
- beforeGraphql: undefined,
106
- afterWrite: undefined,
178
+ const discovery = syntheticDiscoveryClients(configured);
179
+ const own = (number) => {
180
+ const row = rows.get(`${repository}:${String(number)}`);
181
+ assert.ok(row);
182
+ return row;
107
183
  };
108
- const git = (cwd, args) => execFileSync('/usr/bin/git', ['-c', 'core.hooksPath=/dev/null', ...args], {
109
- cwd,
110
- env: gitEnvironment(),
111
- encoding: 'utf8',
112
- }).trim();
113
- const clones = new Map();
114
- for (const repository of repositories) {
115
- const clone = join(root, repository.split('/')[1]);
116
- mkdirSync(clone);
117
- clones.set(repository, clone);
118
- git(clone, ['init', '-q', '-b', 'main']);
119
- git(clone, ['remote', 'add', 'origin', `https://github.com/${repository}.git`]);
120
- writeFileSync(join(clone, 'README'), 'fixture\n');
121
- git(clone, ['add', 'README']);
122
- git(clone, ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture']);
123
- for (let number = 17; number < 17 + count; number++) {
124
- const key = `${repository}:${String(number)}`;
125
- const node = `ISSUE-${key}`;
126
- rows.set(key, {
127
- number,
128
- id: number,
129
- node_id: node,
130
- title: ready.title,
131
- body: renderIssueBody(ready),
132
- state: 'open',
133
- html_url: `https://github.com/${repository}/issues/${String(number)}`,
134
- labels: [{ name: 'estimate:2' }, { name: 'area:widget' }],
135
- type: { name: 'Task' },
136
- points: 2,
137
- });
138
- members.set(node, { itemId: `ITEM-${key}`, repository, number, status: 'Todo', archived: false });
184
+ const item = (node, member) => ({
185
+ id: member.itemId,
186
+ isArchived: member.archived,
187
+ project: { id: projectId, number: 1 },
188
+ content: controls.hiddenContent ? null : { __typename: "Issue", id: node, number: member.number, repository: { nameWithOwner: member.repository } },
189
+ fieldValueByName: member.status === null ? null : { name: names[member.status], optionId: option[member.status] }
190
+ });
191
+ const graphql = (async (query, variables = {}) => {
192
+ controls.beforeGraphql?.(query, variables);
193
+ if (query.includes("mutation")) {
194
+ if (query.includes("AddProjectDeliveryItem")) {
195
+ const node = String(variables.contentId);
196
+ const row = [...rows.values()].find((r) => r.node_id === node);
197
+ assert.ok(row);
198
+ const rowRepository = row.html_url.split("/").slice(3, 5).join("/");
199
+ members.set(node, {
200
+ itemId: `ADDED-${node}`,
201
+ repository: rowRepository,
202
+ number: row.number,
203
+ status: controls.automaticStatus,
204
+ archived: false
205
+ });
206
+ writes.push({ kind: "add", subject: node });
207
+ controls.afterWrite?.("add", node);
208
+ if (controls.failAfterAdd) throw new Error("Lost add response");
209
+ return { addProjectV2ItemById: { item: { id: `ADDED-${node}` } } };
139
210
  }
140
- }
141
- const contexts = [];
142
- const names = {
143
- Todo: 'Queued',
144
- 'In Progress': 'Active',
145
- Blocked: 'Waiting',
146
- Done: 'Shipped',
147
- };
148
- const option = {
149
- Todo: 'STATUS-0',
150
- 'In Progress': 'STATUS-1',
151
- Blocked: 'STATUS-2',
152
- Done: 'STATUS-3',
153
- };
154
- for (const repository of repositories) {
155
- const organization = repository.split('/')[0];
156
- const projectId = independentProjects ? `PROJECT-${organization}` : 'PROJECT-1';
157
- const configured = {
158
- ...syntheticDiscoveryConfig,
159
- repository,
160
- native: { ...syntheticDiscoveryConfig.native, organization },
161
- };
162
- const discovery = syntheticDiscoveryClients(configured);
163
- const own = (number) => {
164
- const row = rows.get(`${repository}:${String(number)}`);
165
- assert.ok(row);
166
- return row;
167
- };
168
- const item = (node, member) => ({
169
- id: member.itemId,
170
- isArchived: member.archived,
171
- project: { id: projectId, number: 1 },
172
- content: controls.hiddenContent
173
- ? null
174
- : { __typename: 'Issue', id: node, number: member.number, repository: { nameWithOwner: member.repository } },
175
- fieldValueByName: member.status === null ? null : { name: names[member.status], optionId: option[member.status] },
176
- });
177
- const graphql = (async (query, variables = {}) => {
178
- controls.beforeGraphql?.(query, variables);
179
- if (query.includes('mutation')) {
180
- if (query.includes('AddProjectDeliveryItem')) {
181
- const node = String(variables.contentId);
182
- const row = [...rows.values()].find((r) => r.node_id === node);
183
- assert.ok(row);
184
- const rowRepository = row.html_url.split('/').slice(3, 5).join('/');
185
- members.set(node, {
186
- itemId: `ADDED-${node}`,
187
- repository: rowRepository,
188
- number: row.number,
189
- status: controls.automaticStatus,
190
- archived: false,
191
- });
192
- writes.push({ kind: 'add', subject: node });
193
- controls.afterWrite?.('add', node);
194
- if (controls.failAfterAdd)
195
- throw new Error('Lost add response');
196
- return { addProjectV2ItemById: { item: { id: `ADDED-${node}` } } };
197
- }
198
- if (query.includes('UpdateProjectDeliveryStatus')) {
199
- const found = [...members.entries()].find(([, m]) => m.itemId === variables.itemId);
200
- assert.ok(found);
201
- found[1].status = Object.keys(option).find((s) => option[s] === variables.optionId);
202
- writes.push({ kind: 'status', subject: found[0] });
203
- controls.afterWrite?.('status', found[0]);
204
- if (controls.failAfterStatus)
205
- throw new Error('Lost Status response');
206
- return { updateProjectV2ItemFieldValue: { projectV2Item: { id: variables.itemId } } };
207
- }
208
- throw new Error('Unexpected mutation');
209
- }
210
- if (query.includes('ProjectDeliveryItems')) {
211
- controls.itemPages++;
212
- const offset = typeof variables.cursor === 'string' ? Number(variables.cursor.slice(1)) : 0;
213
- const all = [...members.entries()].filter(([, member]) => !independentProjects || member.repository.split('/')[0] === organization);
214
- const slice = all.slice(offset, offset + 100);
215
- return {
216
- organization: {
217
- projectV2: {
218
- id: projectId,
219
- number: 1,
220
- items: {
221
- nodes: slice.map(([node, m]) => item(node, m)),
222
- pageInfo: { hasNextPage: offset + 100 < all.length, endCursor: `p${String(offset + 100)}` },
223
- },
224
- },
225
- },
226
- };
227
- }
228
- if (query.includes('ProjectDeliveryItemReadback')) {
229
- const found = [...members.entries()].find(([, m]) => m.itemId === variables.itemId);
230
- return { node: found ? item(found[0], found[1]) : null };
211
+ if (query.includes("UpdateProjectDeliveryStatus")) {
212
+ const found = [...members.entries()].find(([, m]) => m.itemId === variables.itemId);
213
+ assert.ok(found);
214
+ found[1].status = Object.keys(option).find(
215
+ (s) => option[s] === variables.optionId
216
+ );
217
+ writes.push({ kind: "status", subject: found[0] });
218
+ controls.afterWrite?.("status", found[0]);
219
+ if (controls.failAfterStatus) throw new Error("Lost Status response");
220
+ return { updateProjectV2ItemFieldValue: { projectV2Item: { id: variables.itemId } } };
221
+ }
222
+ throw new Error("Unexpected mutation");
223
+ }
224
+ if (query.includes("ProjectDeliveryIssueItems")) {
225
+ controls.itemPages++;
226
+ return issueProjectItemsResponse(
227
+ variables,
228
+ [...members.entries()].filter(([node]) => node === variables.issueNodeId).map(([node, m]) => item(node, m)),
229
+ { id: projectId, number: 1 }
230
+ );
231
+ }
232
+ if (query.includes("ProjectDeliveryItems")) {
233
+ controls.itemPages++;
234
+ const offset = typeof variables.cursor === "string" ? Number(variables.cursor.slice(1)) : 0;
235
+ const all = [...members.entries()].filter(
236
+ ([, member]) => !independentProjects || member.repository.split("/")[0] === organization
237
+ );
238
+ const slice = all.slice(offset, offset + 100);
239
+ return {
240
+ organization: {
241
+ projectV2: {
242
+ id: projectId,
243
+ number: 1,
244
+ items: {
245
+ nodes: slice.map(([node, m]) => item(node, m)),
246
+ pageInfo: { hasNextPage: offset + 100 < all.length, endCursor: `p${String(offset + 100)}` }
247
+ }
231
248
  }
232
- if (query.includes('blockedBy(first:')) {
233
- const row = own(Number(variables.number));
234
- const all = blockers.get(`${repository}:${String(row.number)}`) ?? [];
235
- const offset = typeof variables.cursor === 'string' ? Number(variables.cursor.slice(1)) : 0;
236
- return {
237
- repository: {
238
- issue: {
239
- id: row.node_id,
240
- number: row.number,
241
- repository: { nameWithOwner: repository },
242
- parent: null,
243
- blockedBy: {
244
- nodes: all.slice(offset, offset + 100),
245
- pageInfo: { hasNextPage: offset + 100 < all.length, endCursor: `b${String(offset + 100)}` },
246
- },
247
- },
248
- },
249
- };
249
+ }
250
+ };
251
+ }
252
+ if (query.includes("ProjectDeliveryItemReadback")) {
253
+ const found = [...members.entries()].find(([, m]) => m.itemId === variables.itemId);
254
+ return { node: found ? item(found[0], found[1]) : null };
255
+ }
256
+ if (query.includes("blockedBy(first:")) {
257
+ const row = own(Number(variables.number));
258
+ const all = blockers.get(`${repository}:${String(row.number)}`) ?? [];
259
+ const offset = typeof variables.cursor === "string" ? Number(variables.cursor.slice(1)) : 0;
260
+ return {
261
+ repository: {
262
+ issue: {
263
+ id: row.node_id,
264
+ number: row.number,
265
+ repository: { nameWithOwner: repository },
266
+ parent: null,
267
+ blockedBy: {
268
+ nodes: all.slice(offset, offset + 100),
269
+ pageInfo: { hasNextPage: offset + 100 < all.length, endCursor: `b${String(offset + 100)}` }
270
+ }
250
271
  }
251
- if (query.includes('DeliveryIssueBranches'))
252
- return {
253
- repository: {
254
- issue: {
255
- linkedBranches: {
256
- nodes: (branches.get(`${repository}:${String(variables.issue)}`) ?? []).map((name) => ({
257
- ref: { name, target: { oid: '1'.repeat(40) }, repository: { nameWithOwner: repository } },
258
- })),
259
- pageInfo: { hasNextPage: false, endCursor: null },
260
- },
261
- },
262
- },
263
- };
264
- const response = await discovery.graphql(query, variables);
265
- if (query.includes('DeliveryRepository'))
266
- return {
267
- repository: {
268
- id: `REPO-${repository}`,
269
- nameWithOwner: repository,
270
- isFork: false,
271
- owner: { __typename: 'Organization', login: organization },
272
- },
273
- };
274
- if (query.includes('ProjectDeliveryConfiguration')) {
275
- const data = response;
276
- data.organization.projectV2.id = projectId;
277
- data.organization.projectV2.viewerCanUpdate = controls.writable;
272
+ }
273
+ };
274
+ }
275
+ if (query.includes("DeliveryIssueBranches"))
276
+ return {
277
+ repository: {
278
+ issue: {
279
+ linkedBranches: {
280
+ nodes: (branches.get(`${repository}:${String(variables.issue)}`) ?? []).map((name) => ({
281
+ ref: { name, target: { oid: "1".repeat(40) }, repository: { nameWithOwner: repository } }
282
+ })),
283
+ pageInfo: { hasNextPage: false, endCursor: null }
284
+ }
278
285
  }
279
- return response;
280
- });
281
- const rest = {
282
- issues: {
283
- listForRepo: async (input) => {
284
- controls.issuePages++;
285
- return {
286
- data: [...rows.entries()]
287
- .filter(([key]) => key.startsWith(`${repository}:`))
288
- .map(([, r]) => r)
289
- .slice((input.page - 1) * input.per_page, input.page * input.per_page),
290
- };
291
- },
292
- get: async (input) => ({ data: { ...own(input.issue_number) } }),
293
- listSubIssues: async (input) => ({
294
- data: (children.get(`${repository}:${String(input.issue_number)}`) ?? [])
295
- .slice(0, input.per_page)
296
- .map((number) => own(number)),
297
- }),
298
- },
299
- request: async (route, input) => {
300
- assert.ok(route.startsWith('GET'));
301
- const offset = ((input.page ?? 1) - 1) * 100;
302
- if (route.includes('/orgs/'))
303
- return {
304
- data: [
305
- { id: 101, name: 'Estimate', data_type: 'single_select' },
306
- { id: 102, name: 'Urgency', data_type: 'single_select' },
307
- ...Array.from({ length: 101 }, (_, n) => ({
308
- id: 1000 + n,
309
- name: `Extra ${String(n)}`,
310
- data_type: 'text',
311
- })),
312
- ].slice(offset, offset + 100),
313
- };
314
- const row = own(input.issue_number);
315
- return {
316
- data: offset === 0 && row.points !== null
317
- ? [
318
- {
319
- issue_field_id: 101,
320
- issue_field_name: 'Estimate',
321
- data_type: 'single_select',
322
- value: row.points,
323
- single_select_option: { name: String(row.points) },
324
- },
325
- ]
326
- : [],
327
- };
328
- },
286
+ }
329
287
  };
330
- const clients = {
331
- graphql,
332
- rest,
333
- role: 'author',
334
- authSource: 'app',
335
- authenticatedAuthor: async () => ({
336
- actorLogin: 'synthetic-author[bot]',
337
- credentialIdentity: 'app:1:installation:2',
338
- }),
288
+ const response = await discovery.graphql(query, variables);
289
+ if (query.includes("DeliveryRepository"))
290
+ return {
291
+ repository: {
292
+ id: `REPO-${repository}`,
293
+ nameWithOwner: repository,
294
+ isFork: false,
295
+ owner: { __typename: "Organization", login: organization }
296
+ }
339
297
  };
340
- const loaded = await loadDeliveryConfig('', { clients, repository, readPageLimit: 20 });
341
- contexts.push({
342
- clients,
343
- config: loaded.config,
344
- configuration: loaded,
345
- repo: { owner: organization, repo: repository.split('/')[1] },
346
- root: '',
347
- readPageLimit: 20,
348
- });
349
- }
350
- return {
351
- root,
352
- contexts,
353
- rows,
354
- members,
355
- children,
356
- blockers,
357
- branches,
358
- writes,
359
- controls,
360
- request: { repositories, mode: 'dry-run' },
361
- statusFor: (node) => members.get(node)?.status ?? null,
362
- get writesSinceResume() {
363
- return writes;
364
- },
365
- checkout: (repository, issueNumber) => {
366
- const path = join(root, `checkout ü ${String(issueNumber)}`);
367
- const name = `native/${String(issueNumber)}`;
368
- git(clones.get(repository), ['worktree', 'add', '-q', '-b', name, path]);
369
- branches.set(`${repository}:${String(issueNumber)}`, [name]);
370
- return { repository, issueNumber, path };
298
+ if (query.includes("ProjectDeliveryConfiguration")) {
299
+ const data = response;
300
+ data.organization.projectV2.id = projectId;
301
+ data.organization.projectV2.viewerCanUpdate = controls.writable;
302
+ }
303
+ return response;
304
+ });
305
+ const rest = {
306
+ issues: {
307
+ listForRepo: async (input) => {
308
+ controls.issuePages++;
309
+ return {
310
+ data: [...rows.entries()].filter(([key]) => key.startsWith(`${repository}:`)).map(([, r]) => r).slice((input.page - 1) * input.per_page, input.page * input.per_page)
311
+ };
371
312
  },
372
- git,
373
- cleanup: () => rmSync(root, { recursive: true, force: true }),
313
+ get: async (input) => ({ data: { ...own(input.issue_number) } }),
314
+ listSubIssues: async (input) => ({
315
+ data: (children.get(`${repository}:${String(input.issue_number)}`) ?? []).slice(0, input.per_page).map((number) => own(number))
316
+ })
317
+ },
318
+ request: async (route, input) => {
319
+ assert.ok(route.startsWith("GET"));
320
+ const offset = ((input.page ?? 1) - 1) * 100;
321
+ if (route.includes("/orgs/"))
322
+ return {
323
+ data: [
324
+ { id: 101, name: "Estimate", data_type: "single_select" },
325
+ { id: 102, name: "Urgency", data_type: "single_select" },
326
+ ...Array.from({ length: 101 }, (_, n) => ({
327
+ id: 1e3 + n,
328
+ name: `Extra ${String(n)}`,
329
+ data_type: "text"
330
+ }))
331
+ ].slice(offset, offset + 100)
332
+ };
333
+ const row = own(input.issue_number);
334
+ return {
335
+ data: offset === 0 && row.points !== null ? [
336
+ {
337
+ issue_field_id: 101,
338
+ issue_field_name: "Estimate",
339
+ data_type: "single_select",
340
+ value: row.points,
341
+ single_select_option: { name: String(row.points) }
342
+ }
343
+ ] : []
344
+ };
345
+ }
346
+ };
347
+ const clients = {
348
+ graphql,
349
+ rest,
350
+ role: "author",
351
+ authSource: "app",
352
+ authenticatedAuthor: async () => ({
353
+ actorLogin: "synthetic-author[bot]",
354
+ credentialIdentity: "app:1:installation:2"
355
+ })
374
356
  };
357
+ const loaded = await loadDeliveryConfig("", { clients, repository, readPageLimit: 20 });
358
+ contexts.push({
359
+ clients,
360
+ config: loaded.config,
361
+ configuration: loaded,
362
+ repo: { owner: organization, repo: repository.split("/")[1] },
363
+ root: "",
364
+ readPageLimit: 20
365
+ });
366
+ }
367
+ return {
368
+ root,
369
+ contexts,
370
+ rows,
371
+ members,
372
+ children,
373
+ blockers,
374
+ branches,
375
+ writes,
376
+ controls,
377
+ request: { repositories, mode: "dry-run" },
378
+ statusFor: (node) => members.get(node)?.status ?? null,
379
+ get writesSinceResume() {
380
+ return writes;
381
+ },
382
+ checkout: (repository, issueNumber) => {
383
+ const path = join(root, `checkout \xFC ${String(issueNumber)}`);
384
+ const name = `native/${String(issueNumber)}`;
385
+ git(clones.get(repository), ["worktree", "add", "-q", "-b", name, path]);
386
+ branches.set(`${repository}:${String(issueNumber)}`, [name]);
387
+ return { repository, issueNumber, path };
388
+ },
389
+ git,
390
+ cleanup: () => rmSync(root, { recursive: true, force: true })
391
+ };
375
392
  }
376
- test('dry-run includes all scoped issues and writes nothing', async () => {
377
- const f = await boardFixture(101, ['example/widget', 'example/second']);
378
- try {
379
- const first = f.rows.get('example/widget:17');
380
- first.state = 'closed';
381
- const draft = { ...IssueFields.parse({ title: first.title, draft: true }), draft: true };
382
- f.rows.get('example/widget:18').body = renderIssueBody(draft);
383
- f.blockers.set('example/widget:18', [
384
- ...Array.from({ length: 101 }, (_, n) => ({
385
- id: `CLOSED-${String(n)}`,
386
- number: 1000 + n,
387
- title: 'Closed blocker',
388
- state: 'CLOSED',
389
- repository: { nameWithOwner: 'foreign/repo' },
390
- })),
391
- {
392
- id: 'FOREIGN',
393
- number: 17,
394
- title: 'Foreign blocker',
395
- state: 'OPEN',
396
- repository: { nameWithOwner: 'foreign/repo' },
397
- },
398
- ]);
399
- f.rows.get('example/widget:19').body = renderIssueBody(draft);
400
- f.children.set('example/widget:20', [17]);
401
- f.members.delete(f.rows.get('example/widget:21').node_id);
402
- f.rows.get('example/widget:22').state = 'closed';
403
- f.members.delete(f.rows.get('example/widget:22').node_id);
404
- f.members.get(f.rows.get('example/widget:23').node_id).archived = true;
405
- const plan = await collect(f.contexts, f.request, [f.root]);
406
- assert.equal(plan.scopeComplete, true);
407
- assert.equal(plan.issues.length, 202);
408
- assert.equal(new Set(plan.issues.map((i) => `${i.repository}:${String(i.issueNumber)}`)).size, 202);
409
- const issue = (number) => plan.issues.find((i) => i.repository === 'example/widget' && i.issueNumber === number);
410
- assert.equal(issue(17).status.target, 'Done');
411
- assert.equal(issue(18).status.target, 'Blocked');
412
- assert.equal(issue(19).status.target, 'Todo');
413
- assert.equal(issue(20).status.target, null);
414
- assert.equal(issue(18).native.blockers.length, 102);
415
- assert.equal(issue(20).metadata.some((d) => d.code === 'parent-points'), true);
416
- assert.equal(issue(22).membership.kind, 'not-required');
417
- assert.equal(issue(23).membership.kind, 'archived-preserved');
418
- assert.equal(plan.operations.some((o) => o.issueNumber === 21 && o.kind === 'add-membership'), true);
419
- assert.deepEqual(f.writes, []);
420
- }
421
- finally {
422
- f.cleanup();
423
- }
393
+ test("dry-run includes all scoped issues and writes nothing", async () => {
394
+ const f = await boardFixture(101, ["example/widget", "example/second"]);
395
+ try {
396
+ const first = f.rows.get("example/widget:17");
397
+ first.state = "closed";
398
+ const draft = { ...IssueFields.parse({ title: first.title, draft: true }), draft: true };
399
+ f.rows.get("example/widget:18").body = renderIssueBody(draft);
400
+ f.blockers.set("example/widget:18", [
401
+ ...Array.from({ length: 101 }, (_, n) => ({
402
+ id: `CLOSED-${String(n)}`,
403
+ number: 1e3 + n,
404
+ title: "Closed blocker",
405
+ state: "CLOSED",
406
+ repository: { nameWithOwner: "foreign/repo" }
407
+ })),
408
+ {
409
+ id: "FOREIGN",
410
+ number: 17,
411
+ title: "Foreign blocker",
412
+ state: "OPEN",
413
+ repository: { nameWithOwner: "foreign/repo" }
414
+ }
415
+ ]);
416
+ f.rows.get("example/widget:19").body = renderIssueBody(draft);
417
+ f.children.set("example/widget:20", [17]);
418
+ f.members.delete(f.rows.get("example/widget:21").node_id);
419
+ f.rows.get("example/widget:22").state = "closed";
420
+ f.members.delete(f.rows.get("example/widget:22").node_id);
421
+ f.members.get(f.rows.get("example/widget:23").node_id).archived = true;
422
+ const plan = await collect(f.contexts, f.request, [f.root]);
423
+ assert.equal(plan.scopeComplete, true);
424
+ assert.equal(plan.issues.length, 202);
425
+ assert.equal(new Set(plan.issues.map((i) => `${i.repository}:${String(i.issueNumber)}`)).size, 202);
426
+ const issue = (number) => plan.issues.find((i) => i.repository === "example/widget" && i.issueNumber === number);
427
+ assert.equal(issue(17).status.target, "Done");
428
+ assert.equal(issue(18).status.target, "Blocked");
429
+ assert.equal(issue(19).status.target, "Todo");
430
+ assert.equal(issue(20).status.target, null);
431
+ assert.equal(issue(18).native.blockers.length, 102);
432
+ assert.equal(
433
+ issue(20).metadata.some((d) => d.code === "parent-points"),
434
+ true
435
+ );
436
+ assert.equal(issue(22).membership.kind, "not-required");
437
+ assert.equal(issue(23).membership.kind, "archived-preserved");
438
+ assert.equal(
439
+ plan.operations.some((o) => o.issueNumber === 21 && o.kind === "add-membership"),
440
+ true
441
+ );
442
+ assert.deepEqual(f.writes, []);
443
+ } finally {
444
+ f.cleanup();
445
+ }
424
446
  });
425
- test('physical checkout is positive evidence only after live native association', async () => {
426
- const f = await boardFixture(1);
427
- try {
428
- const noSelection = await collect(f.contexts, f.request, [f.root]);
429
- assert.equal(noSelection.issues[0].status.target, null);
430
- const checkout = f.checkout('example/widget', 17);
431
- writeFileSync(join(checkout.path, 'README'), 'dirty bytes\n');
432
- const indexPath = f.git(checkout.path, ['rev-parse', '--path-format=absolute', '--git-path', 'index']);
433
- const indexBefore = readFileSync(indexPath);
434
- const active = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
435
- assert.equal(active.issues[0].status.target, 'In Progress', JSON.stringify(active.issues[0]));
436
- assert.equal(readFileSync(join(checkout.path, 'README'), 'utf8'), 'dirty bytes\n');
437
- assert.deepEqual(readFileSync(indexPath), indexBefore);
438
- f.branches.clear();
439
- const gone = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
440
- assert.equal(gone.issues[0].status.target, null);
441
- assert.deepEqual(f.writes, []);
442
- }
443
- finally {
444
- f.cleanup();
445
- }
447
+ test("physical checkout is positive evidence only after live native association", async () => {
448
+ const f = await boardFixture(1);
449
+ try {
450
+ const noSelection = await collect(f.contexts, f.request, [f.root]);
451
+ assert.equal(noSelection.issues[0].status.target, null);
452
+ const checkout = f.checkout("example/widget", 17);
453
+ writeFileSync(join(checkout.path, "README"), "dirty bytes\n");
454
+ const indexPath = f.git(checkout.path, ["rev-parse", "--path-format=absolute", "--git-path", "index"]);
455
+ const indexBefore = readFileSync(indexPath);
456
+ const active = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
457
+ assert.equal(active.issues[0].status.target, "In Progress", JSON.stringify(active.issues[0]));
458
+ assert.equal(readFileSync(join(checkout.path, "README"), "utf8"), "dirty bytes\n");
459
+ assert.deepEqual(readFileSync(indexPath), indexBefore);
460
+ f.branches.clear();
461
+ const gone = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
462
+ assert.equal(gone.issues[0].status.target, null);
463
+ assert.deepEqual(f.writes, []);
464
+ } finally {
465
+ f.cleanup();
466
+ }
446
467
  });
447
- test('executing package identity ignores cwd', () => {
448
- const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
449
- const identity = version.readPackageArtifactIdentity();
450
- assert.equal(identity.packageVersion, manifest.version);
451
- assert.match(identity.packageManifestDigest, /^sha256:[a-f0-9]{64}$/u);
452
- assert.match(identity.packageDistDigest, /^sha256:[a-f0-9]{64}$/u);
468
+ test("executing package identity ignores cwd", () => {
469
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
470
+ const identity = version.readPackageArtifactIdentity();
471
+ assert.equal(identity.packageVersion, manifest.version);
472
+ assert.match(identity.packageManifestDigest, /^sha256:[a-f0-9]{64}$/u);
473
+ assert.match(identity.packageDistDigest, /^sha256:[a-f0-9]{64}$/u);
453
474
  });
454
- test('copied executing artifact changes identity with same-version bytes and refuses links', () => {
455
- const root = realpathSync(mkdtempSync(join(tmpdir(), 'reconcile-artifact-')));
475
+ test(
476
+ "copied executing artifact changes identity with same-version bytes and refuses links",
477
+ { tags: ["release"] },
478
+ () => {
479
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "reconcile-artifact-")));
456
480
  try {
457
- cpSync(fileURLToPath(new URL('.', import.meta.url)), join(root, 'dist'), { recursive: true });
458
- cpSync(fileURLToPath(new URL('../package.json', import.meta.url)), join(root, 'package.json'));
459
- symlinkSync(fileURLToPath(new URL('../node_modules', import.meta.url)), join(root, 'node_modules'), 'dir');
460
- const read = () => JSON.parse(execFileSync(process.execPath, [
461
- '--input-type=module',
462
- '-e',
463
- 'const m = await import(process.argv[1]); process.stdout.write(JSON.stringify(m.readPackageArtifactIdentity()));',
464
- join(root, 'dist/version.js'),
465
- ], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1024 * 1024 }));
466
- assert.deepEqual(read(), version.readPackageArtifactIdentity());
467
- writeFileSync(join(root, 'dist/changed-bytes'), 'different bytes, same package version\n');
468
- const changed = read();
469
- assert.equal(changed.packageVersion, version.readPackageArtifactIdentity().packageVersion);
470
- assert.notEqual(changed.packageDistDigest, version.readPackageArtifactIdentity().packageDistDigest);
471
- symlinkSync(join(root, 'package.json'), join(root, 'dist/unsupported-link'));
472
- assert.throws(read);
473
- }
474
- finally {
475
- rmSync(root, { recursive: true, force: true });
476
- }
481
+ cpSync(fileURLToPath(new URL(".", import.meta.url)), join(root, "dist"), { recursive: true });
482
+ cpSync(fileURLToPath(new URL("../package.json", import.meta.url)), join(root, "package.json"));
483
+ symlinkSync(fileURLToPath(new URL("../node_modules", import.meta.url)), join(root, "node_modules"), "dir");
484
+ const read = () => JSON.parse(
485
+ execFileSync(
486
+ process.execPath,
487
+ [
488
+ "--input-type=module",
489
+ "-e",
490
+ "const m = await import(process.argv[1]); process.stdout.write(JSON.stringify(m.readPackageArtifactIdentity()));",
491
+ join(root, "dist/version.js")
492
+ ],
493
+ { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 1024 * 1024 }
494
+ )
495
+ );
496
+ assert.deepEqual(read(), version.readPackageArtifactIdentity());
497
+ writeFileSync(join(root, "dist/changed-bytes"), "different bytes, same package version\n");
498
+ const changed = read();
499
+ assert.equal(changed.packageVersion, version.readPackageArtifactIdentity().packageVersion);
500
+ assert.notEqual(changed.packageDistDigest, version.readPackageArtifactIdentity().packageDistDigest);
501
+ symlinkSync(join(root, "package.json"), join(root, "dist/unsupported-link"));
502
+ assert.throws(read);
503
+ } finally {
504
+ rmSync(root, { recursive: true, force: true });
505
+ }
506
+ }
507
+ );
508
+ test("request bounds and conflicting selectors refuse before collection", () => {
509
+ for (const input of [
510
+ { repositories: [] },
511
+ { repositories: Array.from({ length: 11 }, (_, n) => `example/r${String(n)}`) },
512
+ { repositories: ["example/widget", "EXAMPLE/WIDGET"] },
513
+ { repositories: ["invalid"] },
514
+ { repositories: ["example/widget", "example/other"], repo: "example/widget" },
515
+ {
516
+ repositories: ["example/widget"],
517
+ checkouts: [{ repository: "other/repo", issueNumber: 1, path: "/tmp/example" }]
518
+ },
519
+ {
520
+ repositories: ["example/widget"],
521
+ checkouts: [{ repository: "example/widget", issueNumber: 1, path: "relative" }]
522
+ },
523
+ { repositories: ["example/widget"], mode: "apply" },
524
+ { repositories: ["example/widget"], priorResult: {} }
525
+ ])
526
+ assert.equal(board.BoardReconcileInput.safeParse(input).success, false);
527
+ assert.equal(board.BoardReconcileInput.parse({ repositories: [" example/widget "] }).mode, "dry-run");
528
+ const text = "\u{1F600}".repeat(43e5);
529
+ assert.ok(text.length < 16 * 1024 * 1024);
530
+ assert.throws(
531
+ () => board.parseBoardReconcileRequest({ repositories: ["example/widget"], oversized: text }),
532
+ /16 MiB/u
533
+ );
534
+ const cyclic = {};
535
+ cyclic.self = cyclic;
536
+ assert.throws(() => board.parseBoardReconcileRequest(cyclic), /serializable JSON/u);
477
537
  });
478
- test('request bounds and conflicting selectors refuse before collection', () => {
479
- for (const input of [
480
- { repositories: [] },
481
- { repositories: Array.from({ length: 11 }, (_, n) => `example/r${String(n)}`) },
482
- { repositories: ['example/widget', 'EXAMPLE/WIDGET'] },
483
- { repositories: ['invalid'] },
484
- { repositories: ['example/widget', 'example/other'], repo: 'example/widget' },
485
- {
486
- repositories: ['example/widget'],
487
- checkouts: [{ repository: 'other/repo', issueNumber: 1, path: '/tmp/example' }],
488
- },
489
- {
490
- repositories: ['example/widget'],
491
- checkouts: [{ repository: 'example/widget', issueNumber: 1, path: 'relative' }],
492
- },
493
- { repositories: ['example/widget'], mode: 'apply' },
494
- { repositories: ['example/widget'], priorResult: {} },
495
- ])
496
- assert.equal(board.BoardReconcileInput.safeParse(input).success, false);
497
- assert.equal(board.BoardReconcileInput.parse({ repositories: [' example/widget '] }).mode, 'dry-run');
498
- const text = '😀'.repeat(4_300_000);
499
- assert.ok(text.length < 16 * 1024 * 1024);
500
- assert.throws(() => board.parseBoardReconcileRequest({ repositories: ['example/widget'], oversized: text }), /16 MiB/u);
501
- const cyclic = {};
502
- cyclic.self = cyclic;
503
- assert.throws(() => board.parseBoardReconcileRequest(cyclic), /serializable JSON/u);
538
+ test("native metadata reports drafts, closed-child parents and mapped duplicate labels without repair", async () => {
539
+ const f = await boardFixture(3);
540
+ try {
541
+ f.rows.get("example/widget:17").points = null;
542
+ f.rows.get("example/widget:17").body = renderIssueBody(
543
+ IssueFields.parse({ title: f.rows.get("example/widget:17").title, draft: true })
544
+ );
545
+ f.children.set("example/widget:18", [19]);
546
+ f.rows.get("example/widget:19").state = "closed";
547
+ f.rows.get("example/widget:18").labels = [
548
+ "points:2",
549
+ "estimate:4",
550
+ "urgency:unmapped",
551
+ "flow:Todo",
552
+ "area:widget"
553
+ ].map((name) => ({ name }));
554
+ const plan = await collect(f.contexts, f.request, [f.root]);
555
+ assert.equal(
556
+ plan.issues.find((i) => i.issueNumber === 17).metadata.some((d) => d.code === "missing-points"),
557
+ true
558
+ );
559
+ const reports = plan.issues.find((i) => i.issueNumber === 18).metadata;
560
+ assert.equal(
561
+ reports.some((d) => d.code === "parent-points"),
562
+ true
563
+ );
564
+ assert.deepEqual(
565
+ reports.filter((d) => d.code === "duplicate-field-label").map((d) => [d.label, d.mapping]),
566
+ [
567
+ ["points:2", "exact"],
568
+ ["estimate:4", "conflicting"],
569
+ ["urgency:unmapped", "unknown"],
570
+ ["flow:Todo", "exact"]
571
+ ]
572
+ );
573
+ assert.deepEqual(f.writes, []);
574
+ } finally {
575
+ f.cleanup();
576
+ }
504
577
  });
505
- test('native metadata reports drafts, closed-child parents and mapped duplicate labels without repair', async () => {
506
- const f = await boardFixture(3);
507
- try {
508
- f.rows.get('example/widget:17').points = null;
509
- f.rows.get('example/widget:17').body = renderIssueBody(IssueFields.parse({ title: f.rows.get('example/widget:17').title, draft: true }));
510
- f.children.set('example/widget:18', [19]);
511
- f.rows.get('example/widget:19').state = 'closed';
512
- f.rows.get('example/widget:18').labels = [
513
- 'points:2',
514
- 'estimate:4',
515
- 'urgency:unmapped',
516
- 'flow:Todo',
517
- 'area:widget',
518
- ].map((name) => ({ name }));
519
- const plan = await collect(f.contexts, f.request, [f.root]);
520
- assert.equal(plan.issues.find((i) => i.issueNumber === 17).metadata.some((d) => d.code === 'missing-points'), true);
521
- const reports = plan.issues.find((i) => i.issueNumber === 18).metadata;
522
- assert.equal(reports.some((d) => d.code === 'parent-points'), true);
523
- assert.deepEqual(reports.filter((d) => d.code === 'duplicate-field-label').map((d) => [d.label, d.mapping]), [
524
- ['points:2', 'exact'],
525
- ['estimate:4', 'conflicting'],
526
- ['urgency:unmapped', 'unknown'],
527
- ['flow:Todo', 'exact'],
528
- ]);
529
- assert.deepEqual(f.writes, []);
530
- }
531
- finally {
532
- f.cleanup();
533
- }
578
+ test("dry-run read access does not require Project write permission", async () => {
579
+ const f = await boardFixture(1);
580
+ try {
581
+ f.controls.writable = false;
582
+ const plan = await collect(f.contexts, f.request, [f.root]);
583
+ assert.equal(plan.scopeComplete, true);
584
+ assert.deepEqual(f.writes, []);
585
+ } finally {
586
+ f.cleanup();
587
+ }
534
588
  });
535
- test('dry-run read access does not require Project write permission', async () => {
536
- const f = await boardFixture(1);
537
- try {
538
- f.controls.writable = false;
539
- const plan = await collect(f.contexts, f.request, [f.root]);
540
- assert.equal(plan.scopeComplete, true);
541
- assert.deepEqual(f.writes, []);
542
- }
543
- finally {
544
- f.cleanup();
545
- }
546
- });
547
- test('hidden Project content makes the scoped inventory incomplete', async () => {
548
- const f = await boardFixture(1, ['example/widget', 'example/other']);
549
- try {
550
- f.controls.hiddenContent = true;
551
- const plan = await collect(f.contexts, f.request, [f.root]);
552
- assert.equal(plan.scopeComplete, false);
553
- assert.equal(plan.issues.length, 2);
554
- assert.deepEqual(f.writes, []);
555
- }
556
- finally {
557
- f.cleanup();
558
- }
589
+ test("hidden Project content makes the scoped inventory incomplete", async () => {
590
+ const f = await boardFixture(1, ["example/widget", "example/other"]);
591
+ try {
592
+ f.controls.hiddenContent = true;
593
+ const plan = await collect(f.contexts, f.request, [f.root]);
594
+ assert.equal(plan.scopeComplete, false);
595
+ assert.equal(plan.issues.length, 2);
596
+ assert.deepEqual(f.writes, []);
597
+ } finally {
598
+ f.cleanup();
599
+ }
559
600
  });
560
- test.each(['source', 'duplicate'])('wrong %s blocker evidence cannot prove a Status rule', async (failure) => {
561
- const f = await boardFixture(1);
562
- try {
563
- f.blockers.set('example/widget:17', [
564
- {
565
- id: 'BLOCKER',
566
- number: 99,
567
- title: 'Native blocker',
568
- state: 'OPEN',
569
- repository: { nameWithOwner: 'foreign/repo' },
570
- },
571
- ]);
572
- const context = f.contexts[0], original = context.clients.graphql;
573
- context.clients.graphql = (async (query, variables) => {
574
- const response = await original(query, variables);
575
- if (!query.includes('blockedBy(first:'))
576
- return response;
577
- const data = response;
578
- if (failure === 'source')
579
- data.repository.issue.id = 'WRONG-SOURCE';
580
- else
581
- data.repository.issue.blockedBy.nodes.push(data.repository.issue.blockedBy.nodes[0]);
582
- return data;
583
- });
584
- const plan = await collect(f.contexts, f.request, [f.root]);
585
- assert.equal(plan.issues[0].status.target, null, failure);
586
- assert.deepEqual(f.writes, []);
587
- }
588
- finally {
589
- f.cleanup();
590
- }
601
+ test.each(["source", "duplicate"])("wrong %s blocker evidence cannot prove a Status rule", async (failure) => {
602
+ const f = await boardFixture(1);
603
+ try {
604
+ f.blockers.set("example/widget:17", [
605
+ {
606
+ id: "BLOCKER",
607
+ number: 99,
608
+ title: "Native blocker",
609
+ state: "OPEN",
610
+ repository: { nameWithOwner: "foreign/repo" }
611
+ }
612
+ ]);
613
+ const context = f.contexts[0], original = context.clients.graphql;
614
+ context.clients.graphql = (async (query, variables) => {
615
+ const response = await original(query, variables);
616
+ if (!query.includes("blockedBy(first:")) return response;
617
+ const data = response;
618
+ if (failure === "source") data.repository.issue.id = "WRONG-SOURCE";
619
+ else data.repository.issue.blockedBy.nodes.push(data.repository.issue.blockedBy.nodes[0]);
620
+ return data;
621
+ });
622
+ const plan = await collect(f.contexts, f.request, [f.root]);
623
+ assert.equal(plan.issues[0].status.target, null, failure);
624
+ assert.deepEqual(f.writes, []);
625
+ } finally {
626
+ f.cleanup();
627
+ }
591
628
  });
592
- test.each(['detached', 'locked', 'missing', 'remote', 'ambiguous-link', 'root-escape'])('physical %s observation stays unknown', async (failure) => {
629
+ test.each(["detached", "locked", "missing", "remote", "ambiguous-link", "root-escape"])(
630
+ "physical %s observation stays unknown",
631
+ async (failure) => {
593
632
  const f = await boardFixture(1);
594
633
  try {
595
- const checkout = f.checkout('example/widget', 17);
596
- let roots = [f.root];
597
- if (failure === 'detached')
598
- f.git(checkout.path, ['checkout', '--detach', '--quiet']);
599
- if (failure === 'locked')
600
- f.git(checkout.path, ['worktree', 'lock', checkout.path]);
601
- if (failure === 'missing')
602
- rmSync(checkout.path, { recursive: true });
603
- if (failure === 'remote')
604
- f.git(checkout.path, ['remote', 'set-url', 'origin', 'https://github.com/foreign/repo.git']);
605
- if (failure === 'ambiguous-link')
606
- f.branches.set('example/widget:17', ['native/17', 'native/17']);
607
- if (failure === 'root-escape') {
608
- const allowed = join(f.root, 'only-allowed');
609
- mkdirSync(allowed);
610
- roots = [allowed];
611
- }
612
- const plan = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, roots);
613
- assert.equal(plan.issues[0].activity.state, 'unknown');
614
- assert.equal(plan.issues[0].status.target, null);
615
- assert.deepEqual(f.writes, []);
616
- }
617
- finally {
618
- f.cleanup();
619
- }
620
- });
621
- test('cancellation after a completed unit preserves an incomplete zero-write plan', async () => {
622
- const f = await boardFixture(3);
623
- try {
624
- const cancellation = new AbortController(), context = f.contexts[0], get = context.clients.rest.issues.get;
625
- context.clients.rest.issues.get = (async (input) => {
626
- const response = await get(input);
627
- if (input?.issue_number === 18)
628
- cancellation.abort();
629
- return response;
630
- });
631
- const plan = await board.collectBoardReconcilePlan(f.contexts, f.request, {
632
- checkoutRoots: [f.root],
633
- signal: cancellation.signal,
634
- });
635
- assert.equal(plan.scopeComplete, false);
636
- assert.ok(plan.issues.some((i) => i.issueNumber === 17));
637
- assert.deepEqual(f.writes, []);
638
- }
639
- finally {
640
- f.cleanup();
641
- }
634
+ const checkout = f.checkout("example/widget", 17);
635
+ let roots = [f.root];
636
+ if (failure === "detached") f.git(checkout.path, ["checkout", "--detach", "--quiet"]);
637
+ if (failure === "locked") f.git(checkout.path, ["worktree", "lock", checkout.path]);
638
+ if (failure === "missing") rmSync(checkout.path, { recursive: true });
639
+ if (failure === "remote")
640
+ f.git(checkout.path, ["remote", "set-url", "origin", "https://github.com/foreign/repo.git"]);
641
+ if (failure === "ambiguous-link") f.branches.set("example/widget:17", ["native/17", "native/17"]);
642
+ if (failure === "root-escape") {
643
+ const allowed = join(f.root, "only-allowed");
644
+ mkdirSync(allowed);
645
+ roots = [allowed];
646
+ }
647
+ const plan = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, roots);
648
+ assert.equal(plan.issues[0].activity.state, "unknown");
649
+ assert.equal(plan.issues[0].status.target, null);
650
+ assert.deepEqual(f.writes, []);
651
+ } finally {
652
+ f.cleanup();
653
+ }
654
+ }
655
+ );
656
+ test("cancellation after a completed unit preserves an incomplete zero-write plan", async () => {
657
+ const f = await boardFixture(3);
658
+ try {
659
+ const cancellation = new AbortController(), context = f.contexts[0], get = context.clients.rest.issues.get;
660
+ context.clients.rest.issues.get = (async (input) => {
661
+ const response = await get(input);
662
+ if (input?.issue_number === 18) cancellation.abort();
663
+ return response;
664
+ });
665
+ const plan = await board.collectBoardReconcilePlan(f.contexts, f.request, {
666
+ checkoutRoots: [f.root],
667
+ signal: cancellation.signal
668
+ });
669
+ assert.equal(plan.scopeComplete, false);
670
+ assert.ok(plan.issues.some((i) => i.issueNumber === 17));
671
+ assert.deepEqual(f.writes, []);
672
+ } finally {
673
+ f.cleanup();
674
+ }
642
675
  });
643
- test.each([500, 501])('native issue limit %s requires complete boundary evidence', async (count) => {
644
- const f = await boardFixture(count);
645
- try {
646
- const plan = await collect(f.contexts, f.request, [f.root]);
647
- assert.equal(plan.scopeComplete, count === 500);
648
- assert.equal(plan.issues.length, 500);
649
- assert.equal(f.controls.issuePages, 6); // exact 500 requires the empty completion page
650
- if (count === 501)
651
- assert.equal(plan.gaps.some((g) => g.collection === 'repository-issues' && g.limit === 500), true);
652
- assert.deepEqual(f.writes, []);
653
- }
654
- finally {
655
- f.cleanup();
656
- }
676
+ test.each([500, 501])("native issue limit %s requires complete boundary evidence", async (count) => {
677
+ const f = await boardFixture(count);
678
+ try {
679
+ const plan = await collect(f.contexts, f.request, [f.root]);
680
+ assert.equal(plan.scopeComplete, count === 500);
681
+ assert.equal(plan.issues.length, 500);
682
+ assert.equal(f.controls.issuePages, 6);
683
+ if (count === 501)
684
+ assert.equal(
685
+ plan.gaps.some((g) => g.collection === "repository-issues" && g.limit === 500),
686
+ true
687
+ );
688
+ assert.deepEqual(f.writes, []);
689
+ } finally {
690
+ f.cleanup();
691
+ }
657
692
  });
658
- test('Project page 21 is not requested and cannot truncate into successful absence', async () => {
659
- const f = await boardFixture(1);
660
- try {
661
- const context = f.contexts[0], original = context.clients.graphql;
662
- let requests = 0;
663
- context.clients.graphql = (async (query, variables) => {
664
- if (!query.includes('ProjectDeliveryItems'))
665
- return original(query, variables);
666
- requests++;
667
- const page = typeof variables.cursor === 'string' ? Number(variables.cursor.slice(1)) + 1 : 1;
668
- return {
669
- organization: {
670
- projectV2: {
671
- id: 'PROJECT-1',
672
- number: 1,
673
- items: { nodes: [], pageInfo: { hasNextPage: page < 21, endCursor: `c${String(page)}` } },
674
- },
675
- },
676
- };
677
- });
678
- const plan = await collect(f.contexts, f.request, [f.root]);
679
- assert.equal(plan.scopeComplete, false);
680
- assert.equal(plan.gaps.some((g) => g.collection === 'project-items' && g.pagesRequested === 20 && g.limit === 20), true);
681
- assert.equal(requests, 20); // metadata cannot restart an incomplete Project collection
682
- assert.deepEqual(f.writes, []);
683
- }
684
- finally {
685
- f.cleanup();
686
- }
693
+ test("Project page 21 is not requested and cannot truncate into successful absence", async () => {
694
+ const f = await boardFixture(1);
695
+ try {
696
+ const context = f.contexts[0], original = context.clients.graphql;
697
+ let requests = 0;
698
+ context.clients.graphql = (async (query, variables) => {
699
+ if (!query.includes("ProjectDeliveryItems")) return original(query, variables);
700
+ requests++;
701
+ const page = typeof variables.cursor === "string" ? Number(variables.cursor.slice(1)) + 1 : 1;
702
+ return {
703
+ organization: {
704
+ projectV2: {
705
+ id: "PROJECT-1",
706
+ number: 1,
707
+ items: { nodes: [], pageInfo: { hasNextPage: page < 21, endCursor: `c${String(page)}` } }
708
+ }
709
+ }
710
+ };
711
+ });
712
+ const plan = await collect(f.contexts, f.request, [f.root]);
713
+ assert.equal(plan.scopeComplete, false);
714
+ assert.equal(
715
+ plan.gaps.some((g) => g.collection === "project-items" && g.pagesRequested === 20 && g.limit === 20),
716
+ true
717
+ );
718
+ assert.equal(requests, 20);
719
+ assert.deepEqual(f.writes, []);
720
+ } finally {
721
+ f.cleanup();
722
+ }
687
723
  });
688
- test('incomplete child existence cannot activate a checkout or fabricate a leaf', async () => {
689
- const f = await boardFixture(1);
690
- try {
691
- const checkout = f.checkout('example/widget', 17);
692
- f.contexts[0].clients.rest.issues.listSubIssues = (async () => ({
693
- data: [],
694
- headers: {
695
- link: '<https://api.github.com/repos/example/widget/issues/17/sub_issues?page=2&per_page=1>; rel="next"',
696
- },
697
- }));
698
- const plan = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
699
- assert.equal(plan.issues[0].native.hasChildren, null);
700
- assert.equal(plan.issues[0].status.target, null);
701
- assert.equal(plan.issues[0].metadata.some((d) => d.code === 'unknown-metadata'), true);
702
- assert.deepEqual(f.writes, []);
703
- }
704
- finally {
705
- f.cleanup();
706
- }
724
+ test("incomplete child existence cannot activate a checkout or fabricate a leaf", async () => {
725
+ const f = await boardFixture(1);
726
+ try {
727
+ const checkout = f.checkout("example/widget", 17);
728
+ f.contexts[0].clients.rest.issues.listSubIssues = (async () => ({
729
+ data: [],
730
+ headers: {
731
+ link: '<https://api.github.com/repos/example/widget/issues/17/sub_issues?page=2&per_page=1>; rel="next"'
732
+ }
733
+ }));
734
+ const plan = await collect(f.contexts, { ...f.request, checkouts: [checkout] }, [f.root]);
735
+ assert.equal(plan.issues[0].native.hasChildren, null);
736
+ assert.equal(plan.issues[0].status.target, null);
737
+ assert.equal(
738
+ plan.issues[0].metadata.some((d) => d.code === "unknown-metadata"),
739
+ true
740
+ );
741
+ assert.deepEqual(f.writes, []);
742
+ } finally {
743
+ f.cleanup();
744
+ }
707
745
  });
708
- test.each(['catalog', 'values'])('an incomplete %s collection is not retried through later reads', async (collection) => {
709
- const f = await boardFixture(collection === 'catalog' ? 3 : 1);
746
+ test.each(["catalog", "values"])(
747
+ "an incomplete %s collection is not retried through later reads",
748
+ async (collection) => {
749
+ const f = await boardFixture(collection === "catalog" ? 3 : 1);
710
750
  try {
711
- const context = f.contexts[0], request = context.clients.rest.request;
712
- let pages = 0;
713
- context.clients.rest.request = (async (route, input) => {
714
- if (route.includes('/orgs/') !== (collection === 'catalog'))
715
- return request(route, input);
716
- pages++;
717
- return {
718
- data: input.page > 20
719
- ? []
720
- : Array.from({ length: 100 }, (_, n) => {
721
- const id = input.page * 100 + n + 1000;
722
- return collection === 'catalog'
723
- ? { id, name: `Extra ${String(id)}`, data_type: 'text' }
724
- : {
725
- issue_field_id: id,
726
- issue_field_name: `Extra ${String(id)}`,
727
- data_type: 'text',
728
- value: 'value',
729
- };
730
- }),
751
+ const context = f.contexts[0], request = context.clients.rest.request;
752
+ let pages = 0;
753
+ context.clients.rest.request = (async (route, input) => {
754
+ if (route.includes("/orgs/") !== (collection === "catalog")) return request(route, input);
755
+ pages++;
756
+ return {
757
+ data: input.page > 20 ? [] : Array.from({ length: 100 }, (_, n) => {
758
+ const id = input.page * 100 + n + 1e3;
759
+ return collection === "catalog" ? { id, name: `Extra ${String(id)}`, data_type: "text" } : {
760
+ issue_field_id: id,
761
+ issue_field_name: `Extra ${String(id)}`,
762
+ data_type: "text",
763
+ value: "value"
731
764
  };
732
- });
733
- const checkouts = collection === 'values' ? [f.checkout('example/widget', 17)] : [];
734
- const plan = await collect(f.contexts, { ...f.request, checkouts }, [f.root]);
735
- assert.equal(plan.scopeComplete, false);
736
- assert.equal(pages, 20);
737
- assert.deepEqual(f.writes, []);
738
- }
739
- finally {
740
- f.cleanup();
741
- }
742
- });
743
- test.each([401, 429])('global HTTP %s failure makes preflight incomplete and stops further requests', async (status) => {
765
+ })
766
+ };
767
+ });
768
+ const checkouts = collection === "values" ? [f.checkout("example/widget", 17)] : [];
769
+ const plan = await collect(f.contexts, { ...f.request, checkouts }, [f.root]);
770
+ assert.equal(plan.scopeComplete, false);
771
+ assert.equal(pages, 20);
772
+ assert.deepEqual(f.writes, []);
773
+ } finally {
774
+ f.cleanup();
775
+ }
776
+ }
777
+ );
778
+ test.each([401, 429])(
779
+ "global HTTP %s failure makes preflight incomplete and stops further requests",
780
+ async (status) => {
744
781
  const f = await boardFixture(3);
745
782
  try {
746
- let requests = 0;
747
- f.contexts[0].clients.rest.request = (async () => {
748
- requests++;
749
- throw Object.assign(new Error('not-public-error-details'), {
750
- status,
751
- headers: status === 429 ? { 'retry-after': '2' } : {},
752
- });
783
+ let requests = 0;
784
+ f.contexts[0].clients.rest.request = (async () => {
785
+ requests++;
786
+ throw Object.assign(new Error("not-public-error-details"), {
787
+ status,
788
+ headers: status === 429 ? { "retry-after": "2" } : {}
753
789
  });
754
- const plan = await collect(f.contexts, f.request, [f.root]);
755
- assert.equal(plan.scopeComplete, false);
756
- assert.equal(requests, 1);
757
- assert.equal(plan.issues.length, 3);
758
- assert.equal(JSON.stringify(plan).includes('not-public-error-details'), false);
759
- assert.deepEqual(f.writes, []);
760
- }
761
- finally {
762
- f.cleanup();
763
- }
764
- });
765
- test.each(['selected', 'unselected'])('unreadable %s Status does not fabricate an unset preimage', async (scope) => {
790
+ });
791
+ const plan = await collect(f.contexts, f.request, [f.root]);
792
+ assert.equal(plan.scopeComplete, false);
793
+ assert.equal(requests, 1);
794
+ assert.equal(plan.issues.length, 3);
795
+ assert.equal(JSON.stringify(plan).includes("not-public-error-details"), false);
796
+ assert.deepEqual(f.writes, []);
797
+ } finally {
798
+ f.cleanup();
799
+ }
800
+ }
801
+ );
802
+ test.each(["selected", "unselected"])(
803
+ "unreadable %s Status does not fabricate an unset preimage",
804
+ async (scope) => {
766
805
  const f = await boardFixture(2);
767
806
  try {
768
- f.rows.get('example/widget:17').state = 'closed';
769
- f.members.delete(f.rows.get('example/widget:18').node_id);
770
- const context = f.contexts[0], original = context.clients.graphql;
771
- context.clients.graphql = (async (query, variables) => {
772
- const response = await original(query, variables);
773
- if (!query.includes('ProjectDeliveryItems'))
774
- return response;
775
- const data = response;
776
- const nodes = data.organization.projectV2.items.nodes;
777
- if (scope === 'selected')
778
- nodes[0].fieldValueByName = { name: 'Other', optionId: 'OTHER' };
779
- else
780
- nodes.push({
781
- id: 'UNSELECTED',
782
- isArchived: false,
783
- content: {
784
- __typename: 'Issue',
785
- id: 'FOREIGN-ISSUE',
786
- number: 1,
787
- repository: { nameWithOwner: 'other/repo' },
788
- },
789
- fieldValueByName: { name: 'Other', optionId: 'OTHER' },
790
- });
791
- return data;
792
- });
793
- const plan = await collect(f.contexts, f.request, [f.root]);
794
- assert.equal(plan.scopeComplete, true);
795
- assert.equal(plan.operations.some((o) => o.kind === 'add-membership' && o.issueNumber === 18), true);
796
- assert.equal(plan.operations.some((o) => o.kind === 'set-status' && o.issueNumber === 17), scope === 'unselected');
797
- if (scope === 'selected')
798
- assert.equal(plan.issues.find((i) => i.issueNumber === 17).gaps.some((g) => g.stage === 'project-status'), true);
799
- assert.deepEqual(f.writes, []);
800
- }
801
- finally {
802
- f.cleanup();
803
- }
804
- });
805
- test.each(['verified', 'foreign-marker', 'duplicate'])('mixed inventory %s PR evidence is checked before exclusion', async (kind) => {
806
- const f = await boardFixture(1);
807
- try {
808
- const context = f.contexts[0], list = context.clients.rest.issues.listForRepo;
809
- context.clients.rest.issues.listForRepo = (async (input) => {
810
- const response = await list(input);
811
- const pr = {
812
- number: 18,
813
- node_id: 'PR18',
814
- html_url: 'https://github.com/example/widget/pull/18',
815
- pull_request: {
816
- url: kind === 'foreign-marker'
817
- ? 'https://foreign.invalid/pulls/18'
818
- : 'https://api.github.com/repos/example/widget/pulls/18',
819
- },
820
- };
821
- return { data: [...response.data, pr, ...(kind === 'duplicate' ? [pr] : [])] };
822
- });
823
- const plan = await collect(f.contexts, f.request, [f.root]);
824
- assert.equal(plan.scopeComplete, kind === 'verified');
825
- assert.equal(plan.issues.length, 1);
826
- assert.deepEqual(f.writes, []);
827
- }
828
- finally {
829
- f.cleanup();
830
- }
831
- });
832
- test('membership-only apply and resume preserve automatic Todo and unresolved activity', async () => {
833
- const f = await boardFixture(1);
834
- try {
835
- const node = f.rows.get('example/widget:17').node_id;
836
- f.members.delete(node);
837
- f.controls.automaticStatus = 'Todo';
838
- const plan = await collect(f.contexts, f.request, [f.root]);
839
- const applied = await applyPlan(f, plan);
840
- assert.equal(applied.summary.applied, 1);
841
- assert.equal(applied.summary.unresolved, 1);
842
- assert.equal(f.statusFor(node), 'Todo');
843
- assert.deepEqual(f.writes.map((w) => w.kind), ['add']);
844
- f.writes.length = 0;
845
- const resumed = await applyPlan(f, plan, applied);
846
- assert.equal(resumed.planId, plan.planId);
847
- assert.equal(resumed.summary.applied, 0);
848
- assert.equal(resumed.summary.satisfied, 1);
849
- assert.equal(resumed.summary.unresolved, 1);
850
- assert.equal(f.statusFor(node), 'Todo');
851
- assert.deepEqual(f.writes, []);
852
- }
853
- finally {
854
- f.cleanup();
855
- }
856
- });
857
- test.each(['actor', 'access', 'inventory', 'archive', 'configuration'])('apply preflight %s drift refuses before writes', async (failure) => {
858
- const f = await boardFixture(1);
859
- try {
860
- const row = f.rows.get('example/widget:17');
861
- row.state = 'closed';
862
- const plan = await collect(f.contexts, f.request, [f.root]);
863
- assert.equal(plan.operations.length, 1);
864
- if (failure === 'actor')
865
- f.contexts[0].clients.authenticatedAuthor = async () => ({
866
- actorLogin: 'different-actor',
867
- credentialIdentity: 'user:1',
868
- });
869
- if (failure === 'access')
870
- f.controls.writable = false;
871
- if (failure === 'inventory')
872
- f.rows.set('example/widget:99', {
873
- ...row,
874
- number: 99,
875
- id: 99,
876
- node_id: 'NEW-ISSUE99',
877
- state: 'open',
878
- html_url: 'https://github.com/example/widget/issues/99',
879
- });
880
- if (failure === 'archive')
881
- f.members.get(row.node_id).archived = true;
882
- if (failure === 'configuration') {
883
- const path = join(f.root, 'settings.json');
884
- const settings = JSON.parse(readFileSync(path, 'utf8'));
885
- settings.checkoutRoots = [];
886
- writeFileSync(path, JSON.stringify(settings));
887
- }
888
- const result = await applyPlan(f, plan);
889
- assert.equal(result.planId, plan.planId);
890
- assert.ok(result.summary.refused + result.summary.drifted > 0);
891
- assert.equal(result.summary.applied, 0);
892
- assert.deepEqual(f.writes, []);
893
- }
894
- finally {
895
- f.cleanup();
896
- }
897
- });
898
- test.each(['destination', 'artifact'])('a recomputed %s digest cannot authorize different intent', async (failure) => {
899
- const f = await boardFixture(1);
900
- try {
901
- f.rows.get('example/widget:17').state = 'closed';
902
- const plan = await collect(f.contexts, f.request, [f.root]);
903
- if (failure === 'destination')
904
- plan.operations[0].projectId = 'FOREIGN-PROJECT';
807
+ f.rows.get("example/widget:17").state = "closed";
808
+ f.members.delete(f.rows.get("example/widget:18").node_id);
809
+ const context = f.contexts[0], original = context.clients.graphql;
810
+ context.clients.graphql = (async (query, variables) => {
811
+ const response = await original(query, variables);
812
+ if (!query.includes("ProjectDeliveryItems")) return response;
813
+ const data = response;
814
+ const nodes = data.organization.projectV2.items.nodes;
815
+ if (scope === "selected") nodes[0].fieldValueByName = { name: "Other", optionId: "OTHER" };
905
816
  else
906
- plan.packageIdentity.packageDistDigest = `sha256:${'a'.repeat(64)}`;
907
- redigest(plan);
908
- assert.equal(board.BoardReconcileInput.safeParse({ ...f.request, mode: 'apply', plan }).success, true);
909
- const result = await applyPlan(f, plan);
910
- assert.ok(result.summary.refused + result.summary.drifted > 0);
911
- assert.deepEqual(f.writes, []);
912
- }
913
- finally {
914
- f.cleanup();
915
- }
916
- });
917
- test('validated prior item evidence prevents recreating a deleted membership', async () => {
817
+ nodes.push({
818
+ id: "UNSELECTED",
819
+ isArchived: false,
820
+ content: {
821
+ __typename: "Issue",
822
+ id: "FOREIGN-ISSUE",
823
+ number: 1,
824
+ repository: { nameWithOwner: "other/repo" }
825
+ },
826
+ fieldValueByName: { name: "Other", optionId: "OTHER" }
827
+ });
828
+ return data;
829
+ });
830
+ const plan = await collect(f.contexts, f.request, [f.root]);
831
+ assert.equal(plan.scopeComplete, true);
832
+ assert.equal(
833
+ plan.operations.some((o) => o.kind === "add-membership" && o.issueNumber === 18),
834
+ true
835
+ );
836
+ assert.equal(
837
+ plan.operations.some((o) => o.kind === "set-status" && o.issueNumber === 17),
838
+ scope === "unselected"
839
+ );
840
+ if (scope === "selected")
841
+ assert.equal(
842
+ plan.issues.find((i) => i.issueNumber === 17).gaps.some((g) => g.stage === "project-status"),
843
+ true
844
+ );
845
+ assert.deepEqual(f.writes, []);
846
+ } finally {
847
+ f.cleanup();
848
+ }
849
+ }
850
+ );
851
+ test.each(["verified", "foreign-marker", "duplicate"])(
852
+ "mixed inventory %s PR evidence is checked before exclusion",
853
+ async (kind) => {
918
854
  const f = await boardFixture(1);
919
855
  try {
920
- const node = f.rows.get('example/widget:17').node_id;
921
- f.members.delete(node);
922
- const plan = await collect(f.contexts, f.request, [f.root]);
923
- const prior = await applyPlan(f, plan);
924
- f.members.delete(node);
925
- f.writes.length = 0;
926
- const result = await applyPlan(f, plan, prior);
927
- assert.ok(result.summary.refused + result.summary.drifted > 0);
928
- assert.deepEqual(f.writes, []);
929
- }
930
- finally {
931
- f.cleanup();
932
- }
856
+ const context = f.contexts[0], list = context.clients.rest.issues.listForRepo;
857
+ context.clients.rest.issues.listForRepo = (async (input) => {
858
+ const response = await list(input);
859
+ const pr = {
860
+ number: 18,
861
+ node_id: "PR18",
862
+ html_url: "https://github.com/example/widget/pull/18",
863
+ pull_request: {
864
+ url: kind === "foreign-marker" ? "https://foreign.invalid/pulls/18" : "https://api.github.com/repos/example/widget/pulls/18"
865
+ }
866
+ };
867
+ return { data: [...response.data, pr, ...kind === "duplicate" ? [pr] : []] };
868
+ });
869
+ const plan = await collect(f.contexts, f.request, [f.root]);
870
+ assert.equal(plan.scopeComplete, kind === "verified");
871
+ assert.equal(plan.issues.length, 1);
872
+ assert.deepEqual(f.writes, []);
873
+ } finally {
874
+ f.cleanup();
875
+ }
876
+ }
877
+ );
878
+ test("membership-only apply and resume preserve automatic Todo and unresolved activity", async () => {
879
+ const f = await boardFixture(1);
880
+ try {
881
+ const node = f.rows.get("example/widget:17").node_id;
882
+ f.members.delete(node);
883
+ f.controls.automaticStatus = "Todo";
884
+ const plan = await collect(f.contexts, f.request, [f.root]);
885
+ const applied = await applyPlan(f, plan);
886
+ assert.equal(applied.summary.applied, 1);
887
+ assert.equal(applied.summary.unresolved, 1);
888
+ assert.equal(f.statusFor(node), "Todo");
889
+ assert.deepEqual(
890
+ f.writes.map((w) => w.kind),
891
+ ["add"]
892
+ );
893
+ f.writes.length = 0;
894
+ const resumed = await applyPlan(f, plan, applied);
895
+ assert.equal(resumed.planId, plan.planId);
896
+ assert.equal(resumed.summary.applied, 0);
897
+ assert.equal(resumed.summary.satisfied, 1);
898
+ assert.equal(resumed.summary.unresolved, 1);
899
+ assert.equal(f.statusFor(node), "Todo");
900
+ assert.deepEqual(f.writes, []);
901
+ } finally {
902
+ f.cleanup();
903
+ }
933
904
  });
934
- test('known add response item survives a failed readback and constrains resume', async () => {
905
+ test.each(["actor", "access", "inventory", "archive", "configuration"])(
906
+ "apply preflight %s drift refuses before writes",
907
+ async (failure) => {
935
908
  const f = await boardFixture(1);
936
909
  try {
937
- const node = f.rows.get('example/widget:17').node_id;
938
- f.members.delete(node);
939
- const plan = await collect(f.contexts, f.request, [f.root]);
940
- f.controls.beforeGraphql = (query) => {
941
- if (query.includes('ProjectDeliveryItemReadback'))
942
- throw new Error('Unreadable exact item');
943
- };
944
- const prior = await applyPlan(f, plan);
945
- assert.equal(prior.operations[0].attempted, true);
946
- assert.equal(prior.operations[0].outcome, 'unknown');
947
- assert.deepEqual(prior.operations[0].knownItemIds, [`ADDED-${node}`]);
948
- f.controls.beforeGraphql = undefined;
949
- f.members.delete(node);
950
- f.writes.length = 0;
951
- const resumed = await applyPlan(f, plan, prior);
952
- assert.equal(resumed.summary.applied, 0);
953
- assert.deepEqual(f.writes, []);
954
- }
955
- finally {
956
- f.cleanup();
957
- }
958
- });
959
- test.each(['add', 'status'])('lost %s response is unknown until fresh resume proves the postimage', async (kind) => {
910
+ const row = f.rows.get("example/widget:17");
911
+ row.state = "closed";
912
+ const plan = await collect(f.contexts, f.request, [f.root]);
913
+ assert.equal(plan.operations.length, 1);
914
+ if (failure === "actor")
915
+ f.contexts[0].clients.authenticatedAuthor = async () => ({
916
+ actorLogin: "different-actor",
917
+ credentialIdentity: "user:1"
918
+ });
919
+ if (failure === "access") f.controls.writable = false;
920
+ if (failure === "inventory")
921
+ f.rows.set("example/widget:99", {
922
+ ...row,
923
+ number: 99,
924
+ id: 99,
925
+ node_id: "NEW-ISSUE99",
926
+ state: "open",
927
+ html_url: "https://github.com/example/widget/issues/99"
928
+ });
929
+ if (failure === "archive") f.members.get(row.node_id).archived = true;
930
+ if (failure === "configuration") {
931
+ const path = join(f.root, "settings.json");
932
+ const settings = JSON.parse(readFileSync(path, "utf8"));
933
+ settings.checkoutRoots = [];
934
+ writeFileSync(path, JSON.stringify(settings));
935
+ }
936
+ const result = await applyPlan(f, plan);
937
+ assert.equal(result.planId, plan.planId);
938
+ assert.ok(result.summary.refused + result.summary.drifted > 0);
939
+ assert.equal(result.summary.applied, 0);
940
+ assert.deepEqual(f.writes, []);
941
+ } finally {
942
+ f.cleanup();
943
+ }
944
+ }
945
+ );
946
+ test.each(["destination", "artifact"])(
947
+ "a recomputed %s digest cannot authorize different intent",
948
+ async (failure) => {
960
949
  const f = await boardFixture(1);
961
950
  try {
962
- const row = f.rows.get('example/widget:17');
963
- if (kind === 'add') {
964
- f.members.delete(row.node_id);
965
- f.controls.automaticStatus = 'Todo';
966
- }
967
- else
968
- row.state = 'closed';
969
- const plan = await collect(f.contexts, f.request, [f.root]);
970
- f.controls.failAfterAdd = kind === 'add';
971
- f.controls.failAfterStatus = kind === 'status';
972
- const prior = await applyPlan(f, plan);
973
- assert.equal(prior.summary.unknown, 1);
974
- assert.equal(prior.operations[0].attempted, true);
975
- f.controls.failAfterAdd = false;
976
- f.controls.failAfterStatus = false;
977
- f.writes.length = 0;
978
- const resumed = await applyPlan(f, plan, prior);
979
- assert.equal(resumed.summary.satisfied, 1);
980
- assert.equal(resumed.summary.applied, 0);
981
- assert.deepEqual(f.writesSinceResume, []);
982
- assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, 'unknown');
983
- assert.equal(resumed.operations[0].priorEvidence.at(-1).attempted, true);
984
- }
985
- finally {
986
- f.cleanup();
987
- }
951
+ f.rows.get("example/widget:17").state = "closed";
952
+ const plan = await collect(f.contexts, f.request, [f.root]);
953
+ if (failure === "destination") plan.operations[0].projectId = "FOREIGN-PROJECT";
954
+ else plan.packageIdentity.packageDistDigest = `sha256:${"a".repeat(64)}`;
955
+ redigest(plan);
956
+ assert.equal(board.BoardReconcileInput.safeParse({ ...f.request, mode: "apply", plan }).success, true);
957
+ const result = await applyPlan(f, plan);
958
+ assert.ok(result.summary.refused + result.summary.drifted > 0);
959
+ assert.deepEqual(f.writes, []);
960
+ } finally {
961
+ f.cleanup();
962
+ }
963
+ }
964
+ );
965
+ test("validated prior item evidence prevents recreating a deleted membership", async () => {
966
+ const f = await boardFixture(1);
967
+ try {
968
+ const node = f.rows.get("example/widget:17").node_id;
969
+ f.members.delete(node);
970
+ const plan = await collect(f.contexts, f.request, [f.root]);
971
+ const prior = await applyPlan(f, plan);
972
+ f.members.delete(node);
973
+ f.writes.length = 0;
974
+ const result = await applyPlan(f, plan, prior);
975
+ assert.ok(result.summary.refused + result.summary.drifted > 0);
976
+ assert.deepEqual(f.writes, []);
977
+ } finally {
978
+ f.cleanup();
979
+ }
980
+ });
981
+ test("known add response item survives a failed readback and constrains resume", async () => {
982
+ const f = await boardFixture(1);
983
+ try {
984
+ const node = f.rows.get("example/widget:17").node_id;
985
+ f.members.delete(node);
986
+ const plan = await collect(f.contexts, f.request, [f.root]);
987
+ f.controls.beforeGraphql = (query) => {
988
+ if (query.includes("ProjectDeliveryItemReadback")) throw new Error("Unreadable exact item");
989
+ };
990
+ const prior = await applyPlan(f, plan);
991
+ assert.equal(prior.operations[0].attempted, true);
992
+ assert.equal(prior.operations[0].outcome, "unknown");
993
+ assert.deepEqual(prior.operations[0].knownItemIds, [`ADDED-${node}`]);
994
+ f.controls.beforeGraphql = void 0;
995
+ f.members.delete(node);
996
+ f.writes.length = 0;
997
+ const resumed = await applyPlan(f, plan, prior);
998
+ assert.equal(resumed.summary.applied, 0);
999
+ assert.deepEqual(f.writes, []);
1000
+ } finally {
1001
+ f.cleanup();
1002
+ }
988
1003
  });
989
- test.each(['absent', 'unexpected-auto-status'])('Status follow-up after membership preserves %s preimage', async (variant) => {
1004
+ test.each(["add", "status"])(
1005
+ "lost %s response is unknown until fresh resume proves the postimage",
1006
+ async (kind) => {
990
1007
  const f = await boardFixture(1);
991
1008
  try {
992
- const row = f.rows.get('example/widget:17');
1009
+ const row = f.rows.get("example/widget:17");
1010
+ if (kind === "add") {
993
1011
  f.members.delete(row.node_id);
994
- f.blockers.set('example/widget:17', [
995
- {
996
- id: 'OPEN-BLOCKER',
997
- number: 90,
998
- title: 'Open',
999
- state: 'OPEN',
1000
- repository: { nameWithOwner: 'example/widget' },
1001
- },
1002
- ]);
1003
- const plan = await collect(f.contexts, f.request, [f.root]);
1004
- assert.equal(plan.operations.length, 2);
1005
- f.controls.automaticStatus = variant === 'absent' ? null : 'Todo';
1006
- const first = await applyPlan(f, plan);
1007
- assert.equal(first.operations[0].outcome, 'applied');
1008
- assert.equal(first.operations[1].outcome, variant === 'absent' ? 'applied' : 'refused');
1009
- assert.equal(f.statusFor(row.node_id), variant === 'absent' ? 'Blocked' : 'Todo');
1010
- f.writes.length = 0;
1011
- const resumed = await applyPlan(f, plan, first);
1012
- assert.deepEqual(f.writes, []);
1013
- assert.equal(resumed.operations[0].outcome, 'satisfied');
1014
- }
1015
- finally {
1016
- f.cleanup();
1017
- }
1018
- });
1019
- test.each(['add', 'status'])('native truth is guarded immediately before %s', async (kind) => {
1012
+ f.controls.automaticStatus = "Todo";
1013
+ } else row.state = "closed";
1014
+ const plan = await collect(f.contexts, f.request, [f.root]);
1015
+ f.controls.failAfterAdd = kind === "add";
1016
+ f.controls.failAfterStatus = kind === "status";
1017
+ const prior = await applyPlan(f, plan);
1018
+ assert.equal(prior.summary.unknown, 1);
1019
+ assert.equal(prior.operations[0].attempted, true);
1020
+ f.controls.failAfterAdd = false;
1021
+ f.controls.failAfterStatus = false;
1022
+ f.writes.length = 0;
1023
+ const resumed = await applyPlan(f, plan, prior);
1024
+ assert.equal(resumed.summary.satisfied, 1);
1025
+ assert.equal(resumed.summary.applied, 0);
1026
+ assert.deepEqual(f.writesSinceResume, []);
1027
+ assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, "unknown");
1028
+ assert.equal(resumed.operations[0].priorEvidence.at(-1).attempted, true);
1029
+ } finally {
1030
+ f.cleanup();
1031
+ }
1032
+ }
1033
+ );
1034
+ test.each(["absent", "unexpected-auto-status"])(
1035
+ "Status follow-up after membership preserves %s preimage",
1036
+ async (variant) => {
1020
1037
  const f = await boardFixture(1);
1021
1038
  try {
1022
- const row = f.rows.get('example/widget:17');
1023
- if (kind === 'add')
1024
- f.members.delete(row.node_id);
1025
- else
1026
- row.state = 'closed';
1027
- const plan = await collect(f.contexts, f.request, [f.root]);
1028
- let itemReads = 0;
1029
- f.controls.beforeGraphql = (query) => {
1030
- if (query.includes('ProjectDeliveryItems') && ++itemReads === 3)
1031
- row.state = kind === 'add' ? 'closed' : 'open';
1032
- };
1033
- const result = await applyPlan(f, plan);
1034
- assert.deepEqual(f.writes, []);
1035
- assert.equal(result.operations[0].attempted, false);
1036
- assert.equal(result.summary.drifted, 1);
1037
- }
1038
- finally {
1039
- f.cleanup();
1040
- }
1039
+ const row = f.rows.get("example/widget:17");
1040
+ f.members.delete(row.node_id);
1041
+ f.blockers.set("example/widget:17", [
1042
+ {
1043
+ id: "OPEN-BLOCKER",
1044
+ number: 90,
1045
+ title: "Open",
1046
+ state: "OPEN",
1047
+ repository: { nameWithOwner: "example/widget" }
1048
+ }
1049
+ ]);
1050
+ const plan = await collect(f.contexts, f.request, [f.root]);
1051
+ assert.equal(plan.operations.length, 2);
1052
+ f.controls.automaticStatus = variant === "absent" ? null : "Todo";
1053
+ const first = await applyPlan(f, plan);
1054
+ assert.equal(first.operations[0].outcome, "applied");
1055
+ assert.equal(first.operations[1].outcome, variant === "absent" ? "applied" : "refused");
1056
+ assert.equal(f.statusFor(row.node_id), variant === "absent" ? "Blocked" : "Todo");
1057
+ f.writes.length = 0;
1058
+ const resumed = await applyPlan(f, plan, first);
1059
+ assert.deepEqual(f.writes, []);
1060
+ assert.equal(resumed.operations[0].outcome, "satisfied");
1061
+ } finally {
1062
+ f.cleanup();
1063
+ }
1064
+ }
1065
+ );
1066
+ test.each(["add", "status"])("native truth is guarded immediately before %s", async (kind) => {
1067
+ const f = await boardFixture(1);
1068
+ try {
1069
+ const row = f.rows.get("example/widget:17");
1070
+ if (kind === "add") f.members.delete(row.node_id);
1071
+ else row.state = "closed";
1072
+ const plan = await collect(f.contexts, f.request, [f.root]);
1073
+ let itemReads = 0;
1074
+ f.controls.beforeGraphql = (query) => {
1075
+ if (ITEM_READ.test(query) && ++itemReads === 3) row.state = kind === "add" ? "closed" : "open";
1076
+ };
1077
+ const result = await applyPlan(f, plan);
1078
+ assert.deepEqual(f.writes, []);
1079
+ assert.equal(result.operations[0].attempted, false);
1080
+ assert.equal(result.summary.drifted, 1);
1081
+ } finally {
1082
+ f.cleanup();
1083
+ }
1041
1084
  });
1042
- test.each(['native-drift', 'cancel'])('post-write %s retains attempted evidence and stops the shared Project', async (failure) => {
1085
+ test.each(["native-drift", "cancel"])(
1086
+ "post-write %s retains attempted evidence and stops the shared Project",
1087
+ async (failure) => {
1043
1088
  const f = await boardFixture(2);
1044
1089
  const controller = new AbortController();
1045
1090
  try {
1046
- for (const row of f.rows.values())
1047
- row.state = 'closed';
1048
- const plan = await collect(f.contexts, f.request, [f.root]);
1049
- f.controls.afterWrite = (_kind, node) => {
1050
- if (failure === 'cancel')
1051
- controller.abort();
1052
- else
1053
- [...f.rows.values()].find((row) => row.node_id === node).state = 'open';
1054
- };
1055
- const result = await applyPlan(f, plan, undefined, controller.signal);
1056
- assert.equal(f.writes.length, 1);
1057
- assert.equal(result.operations[0].attempted, true);
1058
- if (failure === 'cancel')
1059
- assert.equal(result.scopeComplete, false);
1060
- assert.equal(result.operations[0].outcome, failure === 'cancel' ? 'unknown' : 'drifted');
1061
- assert.equal(result.operations[1].attempted, false);
1062
- }
1063
- finally {
1064
- f.cleanup();
1065
- }
1066
- });
1067
- test('late prerequisite overflow preserves an earlier applied operation', async () => {
1068
- const f = await boardFixture(2);
1069
- try {
1070
- for (const row of f.rows.values())
1071
- row.state = 'closed';
1072
- const plan = await collect(f.contexts, f.request, [f.root]);
1073
- let readsAfterWrite = 0, overflowRequests = 0;
1074
- const original = f.contexts[0].clients.graphql;
1075
- f.contexts[0].clients.graphql = (async (query, variables) => {
1076
- if (f.writes.length && query.includes('ProjectDeliveryItems') && ++readsAfterWrite >= 2) {
1077
- overflowRequests++;
1078
- return {
1079
- organization: {
1080
- projectV2: {
1081
- id: 'PROJECT-1',
1082
- number: 1,
1083
- items: { nodes: [], pageInfo: { hasNextPage: true, endCursor: `late-${String(overflowRequests)}` } },
1084
- },
1085
- },
1086
- };
1091
+ for (const row of f.rows.values()) row.state = "closed";
1092
+ const plan = await collect(f.contexts, f.request, [f.root]);
1093
+ f.controls.afterWrite = (_kind, node) => {
1094
+ if (failure === "cancel") controller.abort();
1095
+ else [...f.rows.values()].find((row) => row.node_id === node).state = "open";
1096
+ };
1097
+ const result = await applyPlan(f, plan, void 0, controller.signal);
1098
+ assert.equal(f.writes.length, 1);
1099
+ assert.equal(result.operations[0].attempted, true);
1100
+ if (failure === "cancel") assert.equal(result.scopeComplete, false);
1101
+ assert.equal(result.operations[0].outcome, failure === "cancel" ? "unknown" : "drifted");
1102
+ assert.equal(result.operations[1].attempted, false);
1103
+ } finally {
1104
+ f.cleanup();
1105
+ }
1106
+ }
1107
+ );
1108
+ test("late prerequisite overflow preserves an earlier applied operation", async () => {
1109
+ const f = await boardFixture(2);
1110
+ try {
1111
+ for (const row of f.rows.values()) row.state = "closed";
1112
+ const plan = await collect(f.contexts, f.request, [f.root]);
1113
+ let readsAfterWrite = 0, overflowRequests = 0;
1114
+ const original = f.contexts[0].clients.graphql;
1115
+ f.contexts[0].clients.graphql = (async (query, variables) => {
1116
+ if (f.writes.length && query.includes("ProjectDeliveryItems") && ++readsAfterWrite >= 2) {
1117
+ overflowRequests++;
1118
+ return {
1119
+ organization: {
1120
+ projectV2: {
1121
+ id: "PROJECT-1",
1122
+ number: 1,
1123
+ items: { nodes: [], pageInfo: { hasNextPage: true, endCursor: `late-${String(overflowRequests)}` } }
1087
1124
  }
1088
- return original(query, variables);
1089
- });
1090
- const result = await applyPlan(f, plan);
1091
- assert.equal(result.scopeComplete, false);
1092
- assert.equal(result.summary.applied, 1);
1093
- assert.equal(result.summary.refused, 1);
1094
- assert.equal(result.operations[0].outcome, 'applied');
1095
- assert.equal(result.operations[1].attempted, false);
1096
- assert.equal(result.gaps.at(-1).pagesRequested, 20);
1097
- assert.equal(result.gaps.at(-1).collection, 'project-items');
1098
- assert.equal(overflowRequests, 20);
1099
- assert.equal(f.writes.length, 1);
1100
- }
1101
- finally {
1102
- f.cleanup();
1103
- }
1125
+ }
1126
+ };
1127
+ }
1128
+ return original(query, variables);
1129
+ });
1130
+ const result = await applyPlan(f, plan);
1131
+ assert.equal(result.scopeComplete, false);
1132
+ assert.equal(result.summary.applied, 1);
1133
+ assert.equal(result.summary.refused, 1);
1134
+ assert.equal(result.operations[0].outcome, "applied");
1135
+ assert.equal(result.operations[1].attempted, false);
1136
+ assert.equal(result.gaps.at(-1).pagesRequested, 20);
1137
+ assert.equal(result.gaps.at(-1).collection, "project-items");
1138
+ assert.equal(overflowRequests, 20);
1139
+ assert.equal(f.writes.length, 1);
1140
+ } finally {
1141
+ f.cleanup();
1142
+ }
1104
1143
  });
1105
- test('an oversized readback cannot erase an attempted write', async () => {
1106
- const f = await boardFixture(1);
1107
- try {
1108
- const row = f.rows.get('example/widget:17');
1109
- row.state = 'closed';
1110
- const plan = await collect(f.contexts, f.request, [f.root]);
1111
- f.controls.afterWrite = () => (f.controls.beforeGraphql = (query) => {
1112
- if (query.includes('ProjectDeliveryItemReadback'))
1113
- throw new Error('x'.repeat(17 * 1024 * 1024));
1114
- });
1115
- const result = await applyPlan(f, plan);
1116
- assert.equal(result.operations[0].attempted, true);
1117
- assert.equal(result.operations[0].outcome, 'unknown');
1118
- assert.equal(result.operations[0].issueNodeId, row.node_id);
1119
- assert.ok(Buffer.byteLength(JSON.stringify(result)) < 16 * 1024 * 1024);
1120
- }
1121
- finally {
1122
- f.cleanup();
1123
- }
1144
+ test("an oversized readback cannot erase an attempted write", async () => {
1145
+ const f = await boardFixture(1);
1146
+ try {
1147
+ const row = f.rows.get("example/widget:17");
1148
+ row.state = "closed";
1149
+ const plan = await collect(f.contexts, f.request, [f.root]);
1150
+ f.controls.afterWrite = () => f.controls.beforeGraphql = (query) => {
1151
+ if (query.includes("ProjectDeliveryItemReadback")) throw new Error("x".repeat(17 * 1024 * 1024));
1152
+ };
1153
+ const result = await applyPlan(f, plan);
1154
+ assert.equal(result.operations[0].attempted, true);
1155
+ assert.equal(result.operations[0].outcome, "unknown");
1156
+ assert.equal(result.operations[0].issueNodeId, row.node_id);
1157
+ assert.ok(Buffer.byteLength(JSON.stringify(result)) < 16 * 1024 * 1024);
1158
+ } finally {
1159
+ f.cleanup();
1160
+ }
1124
1161
  });
1125
- test('retained result capacity is reserved before a next mutation', async () => {
1126
- const f = await boardFixture(1);
1127
- try {
1128
- const row = f.rows.get('example/widget:17');
1129
- row.state = 'closed';
1130
- const plan = await collect(f.contexts, f.request, [f.root]);
1131
- const prior = board.incompleteBoardReconcile({ repositories: plan.scope, mode: 'apply', plan }, { repository: plan.scope[0], stage: 'prior', reason: 'evidence-unavailable' });
1132
- const entry = { outcome: 'unknown', attempted: true, before: null, readback: null };
1133
- const entryBytes = Buffer.byteLength(JSON.stringify(entry)) + 1;
1134
- const baseline = Buffer.byteLength(JSON.stringify({ repositories: plan.scope, mode: 'apply', plan, priorResult: prior }));
1135
- prior.operations[0].priorEvidence = Array.from({ length: Math.floor((16 * 1024 * 1024 - baseline - 512) / entryBytes) }, () => entry);
1136
- const result = await applyPlan(f, plan, prior);
1137
- assert.deepEqual(f.writes, []);
1138
- assert.equal(result.summary.applied, 0);
1139
- assert.ok(result.summary.refused > 0);
1140
- assert.ok(Buffer.byteLength(JSON.stringify(result)) <= 16 * 1024 * 1024);
1141
- }
1142
- finally {
1143
- f.cleanup();
1144
- }
1162
+ test("retained result capacity is reserved before a next mutation", async () => {
1163
+ const f = await boardFixture(1);
1164
+ try {
1165
+ const row = f.rows.get("example/widget:17");
1166
+ row.state = "closed";
1167
+ const plan = await collect(f.contexts, f.request, [f.root]);
1168
+ const prior = board.incompleteBoardReconcile(
1169
+ { repositories: plan.scope, mode: "apply", plan },
1170
+ { repository: plan.scope[0], stage: "prior", reason: "evidence-unavailable" }
1171
+ );
1172
+ const entry = { outcome: "unknown", attempted: true, before: null, readback: null };
1173
+ const entryBytes = Buffer.byteLength(JSON.stringify(entry)) + 1;
1174
+ const baseline = Buffer.byteLength(
1175
+ JSON.stringify({ repositories: plan.scope, mode: "apply", plan, priorResult: prior })
1176
+ );
1177
+ prior.operations[0].priorEvidence = Array.from(
1178
+ { length: Math.floor((16 * 1024 * 1024 - baseline - 512) / entryBytes) },
1179
+ () => entry
1180
+ );
1181
+ const result = await applyPlan(f, plan, prior);
1182
+ assert.deepEqual(f.writes, []);
1183
+ assert.equal(result.summary.applied, 0);
1184
+ assert.ok(result.summary.refused > 0);
1185
+ assert.ok(Buffer.byteLength(JSON.stringify(result)) <= 16 * 1024 * 1024);
1186
+ } finally {
1187
+ f.cleanup();
1188
+ }
1145
1189
  });
1146
- test('an exact Status target appearing at the final boundary skips the mutation', async () => {
1147
- const f = await boardFixture(1);
1148
- try {
1149
- const row = f.rows.get('example/widget:17');
1150
- row.state = 'closed';
1151
- const plan = await collect(f.contexts, f.request, [f.root]);
1152
- let reads = 0;
1153
- f.controls.beforeGraphql = (query) => {
1154
- if (query.includes('ProjectDeliveryItems') && ++reads === 4)
1155
- f.members.get(row.node_id).status = 'Done';
1156
- };
1157
- const result = await applyPlan(f, plan);
1158
- assert.deepEqual(f.writes, []);
1159
- assert.equal(result.summary.satisfied, 1);
1160
- assert.equal(result.operations[0].attempted, false);
1161
- }
1162
- finally {
1163
- f.cleanup();
1164
- }
1190
+ test("an exact Status target appearing at the final boundary skips the mutation", async () => {
1191
+ const f = await boardFixture(1);
1192
+ try {
1193
+ const row = f.rows.get("example/widget:17");
1194
+ row.state = "closed";
1195
+ const plan = await collect(f.contexts, f.request, [f.root]);
1196
+ let reads = 0;
1197
+ f.controls.beforeGraphql = (query) => {
1198
+ if (ITEM_READ.test(query) && ++reads === 4) f.members.get(row.node_id).status = "Done";
1199
+ };
1200
+ const result = await applyPlan(f, plan);
1201
+ assert.deepEqual(f.writes, []);
1202
+ assert.equal(result.summary.satisfied, 1);
1203
+ assert.equal(result.operations[0].attempted, false);
1204
+ } finally {
1205
+ f.cleanup();
1206
+ }
1165
1207
  });
1166
- test('cancellation between add and update resumes the same frozen intent', async () => {
1167
- const f = await boardFixture(1);
1168
- const controller = new AbortController();
1169
- try {
1170
- const row = f.rows.get('example/widget:17');
1171
- f.members.delete(row.node_id);
1172
- f.blockers.set('example/widget:17', [
1173
- { id: 'BLOCKER', number: 91, title: 'Open', state: 'OPEN', repository: { nameWithOwner: 'example/widget' } },
1174
- ]);
1175
- const plan = await collect(f.contexts, f.request, [f.root]);
1176
- f.controls.afterWrite = () => controller.abort();
1177
- const first = await applyPlan(f, plan, undefined, controller.signal);
1178
- assert.equal(first.operations[0].outcome, 'unknown');
1179
- assert.equal(first.operations[1].attempted, false);
1180
- f.controls.afterWrite = undefined;
1181
- f.writes.length = 0;
1182
- const resumed = await applyPlan(f, plan, first);
1183
- assert.deepEqual(f.writes.map((write) => write.kind), ['status']);
1184
- assert.equal(resumed.operations[0].outcome, 'satisfied');
1185
- assert.equal(resumed.operations[1].outcome, 'applied');
1186
- assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, 'unknown');
1187
- assert.equal(f.statusFor(row.node_id), 'Blocked');
1188
- }
1189
- finally {
1190
- f.cleanup();
1191
- }
1208
+ test("cancellation between add and update resumes the same frozen intent", async () => {
1209
+ const f = await boardFixture(1);
1210
+ const controller = new AbortController();
1211
+ try {
1212
+ const row = f.rows.get("example/widget:17");
1213
+ f.members.delete(row.node_id);
1214
+ f.blockers.set("example/widget:17", [
1215
+ { id: "BLOCKER", number: 91, title: "Open", state: "OPEN", repository: { nameWithOwner: "example/widget" } }
1216
+ ]);
1217
+ const plan = await collect(f.contexts, f.request, [f.root]);
1218
+ f.controls.afterWrite = () => controller.abort();
1219
+ const first = await applyPlan(f, plan, void 0, controller.signal);
1220
+ assert.equal(first.operations[0].outcome, "unknown");
1221
+ assert.equal(first.operations[1].attempted, false);
1222
+ f.controls.afterWrite = void 0;
1223
+ f.writes.length = 0;
1224
+ const resumed = await applyPlan(f, plan, first);
1225
+ assert.deepEqual(
1226
+ f.writes.map((write) => write.kind),
1227
+ ["status"]
1228
+ );
1229
+ assert.equal(resumed.operations[0].outcome, "satisfied");
1230
+ assert.equal(resumed.operations[1].outcome, "applied");
1231
+ assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, "unknown");
1232
+ assert.equal(f.statusFor(row.node_id), "Blocked");
1233
+ } finally {
1234
+ f.cleanup();
1235
+ }
1192
1236
  });
1193
- test.each([false, true])('Project ambiguity stops dependents while independent groups finish (%s)', async (independent) => {
1194
- const f = await boardFixture(1, independent ? ['example/widget', 'other/second'] : ['example/widget', 'example/second'], independent);
1237
+ test.each([false, true])(
1238
+ "Project ambiguity stops dependents while independent groups finish (%s)",
1239
+ async (independent) => {
1240
+ const f = await boardFixture(
1241
+ 1,
1242
+ independent ? ["example/widget", "other/second"] : ["example/widget", "example/second"],
1243
+ independent
1244
+ );
1195
1245
  try {
1196
- for (const row of f.rows.values())
1197
- row.state = 'closed';
1198
- const plan = await collect(f.contexts, f.request, [f.root]);
1199
- assert.equal(plan.scopeComplete, true);
1200
- let first = true;
1201
- const orderedFirst = plan.operations[0];
1202
- f.controls.beforeGraphql = (query, variables) => {
1203
- if (first && query.includes('ProjectDeliveryItems') && f.controls.itemPages >= 1) {
1204
- // Wait until global preflight has collected every selected inventory.
1205
- if (f.controls.issuePages >= plan.scope.length * 2) {
1206
- first = false;
1207
- const member = f.members.get(orderedFirst.issueNodeId);
1208
- member.archived = true;
1209
- }
1210
- }
1211
- void variables;
1212
- };
1213
- const result = await applyPlan(f, plan);
1214
- assert.equal(result.operations[0].outcome, 'drifted');
1215
- assert.equal(f.writes.length, independent ? 1 : 0);
1216
- if (independent)
1217
- assert.equal(result.operations[1].outcome, 'applied');
1218
- }
1219
- finally {
1220
- f.cleanup();
1221
- }
1246
+ for (const row of f.rows.values()) row.state = "closed";
1247
+ const plan = await collect(f.contexts, f.request, [f.root]);
1248
+ assert.equal(plan.scopeComplete, true);
1249
+ let first = true;
1250
+ const orderedFirst = plan.operations[0];
1251
+ f.controls.beforeGraphql = (query, variables) => {
1252
+ if (first && ITEM_READ.test(query) && f.controls.itemPages >= 1) {
1253
+ if (f.controls.issuePages >= plan.scope.length * 2) {
1254
+ first = false;
1255
+ const member = f.members.get(orderedFirst.issueNodeId);
1256
+ member.archived = true;
1257
+ }
1258
+ }
1259
+ void variables;
1260
+ };
1261
+ const result = await applyPlan(f, plan);
1262
+ assert.equal(result.operations[0].outcome, "drifted");
1263
+ assert.equal(f.writes.length, independent ? 1 : 0);
1264
+ if (independent) assert.equal(result.operations[1].outcome, "applied");
1265
+ } finally {
1266
+ f.cleanup();
1267
+ }
1268
+ }
1269
+ );
1270
+ test.each([401, 429])("global failure %s after an applied operation stops independent groups", async (status) => {
1271
+ const f = await boardFixture(1, ["example/widget", "other/second"], true);
1272
+ try {
1273
+ for (const row of f.rows.values()) row.state = "closed";
1274
+ const plan = await collect(f.contexts, f.request, [f.root]);
1275
+ let configurationReadsAfterWrite = 0;
1276
+ f.controls.beforeGraphql = (query) => {
1277
+ if (f.writes.length && query.includes("ProjectDeliveryConfiguration") && ++configurationReadsAfterWrite === 3)
1278
+ throw Object.assign(new Error("Provider unavailable"), { status });
1279
+ };
1280
+ const result = await applyPlan(f, plan);
1281
+ assert.equal(result.operations[0].outcome, "applied");
1282
+ assert.equal(f.writes.length, 1);
1283
+ assert.equal(result.operations[1].attempted, false);
1284
+ assert.ok(result.gaps.some((value) => value.reason === (status === 401 ? "authentication" : "rate-limit")));
1285
+ } finally {
1286
+ f.cleanup();
1287
+ }
1222
1288
  });
1223
- test.each([401, 429])('global failure %s after an applied operation stops independent groups', async (status) => {
1224
- const f = await boardFixture(1, ['example/widget', 'other/second'], true);
1225
- try {
1226
- for (const row of f.rows.values())
1227
- row.state = 'closed';
1228
- const plan = await collect(f.contexts, f.request, [f.root]);
1229
- let configurationReadsAfterWrite = 0;
1230
- f.controls.beforeGraphql = (query) => {
1231
- if (f.writes.length && query.includes('ProjectDeliveryConfiguration') && ++configurationReadsAfterWrite === 3)
1232
- throw Object.assign(new Error('Provider unavailable'), { status });
1233
- };
1234
- const result = await applyPlan(f, plan);
1235
- assert.equal(result.operations[0].outcome, 'applied');
1236
- assert.equal(f.writes.length, 1);
1237
- assert.equal(result.operations[1].attempted, false);
1238
- assert.ok(result.gaps.some((value) => value.reason === (status === 401 ? 'authentication' : 'rate-limit')));
1239
- }
1240
- finally {
1241
- f.cleanup();
1242
- }
1289
+ test("resumed and uninterrupted operations reach identical exact postimages", async () => {
1290
+ const f = await boardFixture(2);
1291
+ try {
1292
+ for (const row of f.rows.values()) row.state = "closed";
1293
+ const plan = await collect(f.contexts, f.request, [f.root]);
1294
+ const uninterrupted = await applyPlan(f, plan);
1295
+ assert.equal(uninterrupted.summary.applied, 2);
1296
+ for (const member of f.members.values()) member.status = "Todo";
1297
+ f.writes.length = 0;
1298
+ f.controls.failAfterStatus = true;
1299
+ const interrupted = await applyPlan(f, plan);
1300
+ assert.equal(interrupted.operations[0].outcome, "unknown");
1301
+ assert.equal(interrupted.operations[1].attempted, false);
1302
+ f.controls.failAfterStatus = false;
1303
+ f.writes.length = 0;
1304
+ const resumed = await applyPlan(f, plan, interrupted);
1305
+ const postimages = (result) => result.operations.map((operation) => ({
1306
+ operationId: operation.operationId,
1307
+ repository: operation.repository,
1308
+ issueNodeId: operation.issueNodeId,
1309
+ projectId: operation.projectId,
1310
+ target: operation.target,
1311
+ readback: operation.readback
1312
+ }));
1313
+ assert.deepEqual(postimages(resumed), postimages(uninterrupted));
1314
+ assert.deepEqual(
1315
+ resumed.operations.map((operation) => operation.attempted),
1316
+ [false, true]
1317
+ );
1318
+ assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, "unknown");
1319
+ } finally {
1320
+ f.cleanup();
1321
+ }
1243
1322
  });
1244
- test('resumed and uninterrupted operations reach identical exact postimages', async () => {
1245
- const f = await boardFixture(2);
1246
- try {
1247
- for (const row of f.rows.values())
1248
- row.state = 'closed';
1249
- const plan = await collect(f.contexts, f.request, [f.root]);
1250
- const uninterrupted = await applyPlan(f, plan);
1251
- assert.equal(uninterrupted.summary.applied, 2);
1252
- for (const member of f.members.values())
1253
- member.status = 'Todo';
1254
- f.writes.length = 0;
1255
- f.controls.failAfterStatus = true;
1256
- const interrupted = await applyPlan(f, plan);
1257
- assert.equal(interrupted.operations[0].outcome, 'unknown');
1258
- assert.equal(interrupted.operations[1].attempted, false);
1259
- f.controls.failAfterStatus = false;
1260
- f.writes.length = 0;
1261
- const resumed = await applyPlan(f, plan, interrupted);
1262
- const postimages = (result) => result.operations.map((operation) => ({
1263
- operationId: operation.operationId,
1264
- repository: operation.repository,
1265
- issueNodeId: operation.issueNodeId,
1266
- projectId: operation.projectId,
1267
- target: operation.target,
1268
- readback: operation.readback,
1269
- }));
1270
- assert.deepEqual(postimages(resumed), postimages(uninterrupted));
1271
- assert.deepEqual(resumed.operations.map((operation) => operation.attempted), [false, true]);
1272
- assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, 'unknown');
1273
- }
1274
- finally {
1275
- f.cleanup();
1276
- }
1323
+ test("an interruption before add leaves a revalidated incomplete operation retryable", async () => {
1324
+ const f = await boardFixture(1);
1325
+ const controller = new AbortController();
1326
+ try {
1327
+ const row = f.rows.get("example/widget:17");
1328
+ f.members.delete(row.node_id);
1329
+ const plan = await collect(f.contexts, f.request, [f.root]);
1330
+ let reads = 0;
1331
+ f.controls.beforeGraphql = (query) => {
1332
+ if (ITEM_READ.test(query) && ++reads === 3) controller.abort();
1333
+ };
1334
+ const interrupted = await applyPlan(f, plan, void 0, controller.signal);
1335
+ assert.equal(f.writes.length, 0);
1336
+ assert.equal(interrupted.operations[0].attempted, false);
1337
+ f.controls.beforeGraphql = void 0;
1338
+ const resumed = await applyPlan(f, plan, interrupted);
1339
+ assert.equal(resumed.summary.applied, 1);
1340
+ assert.deepEqual(
1341
+ f.writes.map((write) => write.kind),
1342
+ ["add"]
1343
+ );
1344
+ } finally {
1345
+ f.cleanup();
1346
+ }
1277
1347
  });
1278
- test('an interruption before add leaves a revalidated incomplete operation retryable', async () => {
1279
- const f = await boardFixture(1);
1280
- const controller = new AbortController();
1281
- try {
1282
- const row = f.rows.get('example/widget:17');
1283
- f.members.delete(row.node_id);
1284
- const plan = await collect(f.contexts, f.request, [f.root]);
1285
- let reads = 0;
1286
- f.controls.beforeGraphql = (query) => {
1287
- if (query.includes('ProjectDeliveryItems') && ++reads === 3)
1288
- controller.abort();
1289
- };
1290
- const interrupted = await applyPlan(f, plan, undefined, controller.signal);
1291
- assert.equal(f.writes.length, 0);
1292
- assert.equal(interrupted.operations[0].attempted, false);
1293
- f.controls.beforeGraphql = undefined;
1294
- const resumed = await applyPlan(f, plan, interrupted);
1295
- assert.equal(resumed.summary.applied, 1);
1296
- assert.deepEqual(f.writes.map((write) => write.kind), ['add']);
1297
- }
1298
- finally {
1299
- f.cleanup();
1300
- }
1348
+ test("actual MCP registrar and library share bounded explicit-scope reconciliation", async () => {
1349
+ const f = await boardFixture(1);
1350
+ const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1351
+ const client = new Client({ name: "board-reconcile-fixture", version: "1" });
1352
+ const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1353
+ const clients = vi.spyOn(githubClients, "createDeliveryGitHubClients").mockResolvedValue(f.contexts[0].clients);
1354
+ const loads = vi.spyOn(issueModule, "loadDeliveryContext");
1355
+ try {
1356
+ await server.connect(serverTransport);
1357
+ await client.connect(transport);
1358
+ const listed = await client.listTools();
1359
+ const tool = listed.tools.find((value) => value.name === boardName);
1360
+ assert.ok(tool);
1361
+ assert.equal(tool.inputSchema.type, "object");
1362
+ assert.equal(tool.inputSchema.additionalProperties, false);
1363
+ for (const input of [
1364
+ { repositories: [] },
1365
+ { repositories: Array.from({ length: 11 }, (_, n) => `example/r${String(n)}`) },
1366
+ { repositories: ["example/widget", "EXAMPLE/Widget"] },
1367
+ { repositories: ["invalid"] },
1368
+ { repositories: ["example/widget"], mode: "apply" },
1369
+ { repositories: ["example/widget"], mode: "dry-run", extra: true },
1370
+ { repositories: ["example/widget"], repo: "example/other" },
1371
+ {
1372
+ repositories: ["example/widget"],
1373
+ checkouts: [
1374
+ { repository: "example/widget", issueNumber: 17, path: f.root },
1375
+ { repository: "example/widget", issueNumber: 17, path: f.root }
1376
+ ]
1377
+ }
1378
+ ]) {
1379
+ const response2 = await client.callTool({ name: boardName, arguments: input });
1380
+ assert.equal(response2.isError, true);
1381
+ assert.equal(clients.mock.calls.length, 0);
1382
+ }
1383
+ await assert.rejects(
1384
+ executeTool(boardName, { repositories: ["example/widget"] }, { repoRoot: f.root, repo: "example/other" })
1385
+ );
1386
+ assert.equal(clients.mock.calls.length, 0);
1387
+ const fromLibrary = board.BoardReconcilePlanSchema.parse(
1388
+ await executeTool(boardName, f.request, { repoRoot: f.root })
1389
+ );
1390
+ const beforeInvalid = clients.mock.calls.length;
1391
+ for (const input of [
1392
+ { ...f.request, plan: fromLibrary },
1393
+ { ...f.request, priorResult: {} },
1394
+ { repositories: fromLibrary.scope, mode: "apply", plan: fromLibrary, checkouts: [] }
1395
+ ])
1396
+ await assert.rejects(executeTool(boardName, input, { repoRoot: f.root }));
1397
+ assert.equal(clients.mock.calls.length, beforeInvalid);
1398
+ const response = await client.callTool({ name: boardName, arguments: f.request });
1399
+ assert.equal(response.isError, void 0, JSON.stringify(response));
1400
+ const fromMcp = board.BoardReconcilePlanSchema.parse(JSON.parse(response.content[0].text));
1401
+ assert.equal(fromMcp.planId, fromLibrary.planId);
1402
+ assert.equal(fromMcp.scopeComplete, true);
1403
+ assert.ok(loads.mock.calls.length >= 2);
1404
+ assert.equal(
1405
+ loads.mock.calls.every(([input]) => input.readPageLimit === 20),
1406
+ true
1407
+ );
1408
+ assert.deepEqual(f.writes, []);
1409
+ } finally {
1410
+ await client.close();
1411
+ await server.close();
1412
+ f.cleanup();
1413
+ }
1301
1414
  });
1302
- test('actual MCP registrar and library share bounded explicit-scope reconciliation', async () => {
1415
+ test.each(["dry-run", "apply"])(
1416
+ "pre-context access failure preserves %s output without writes",
1417
+ async (mode) => {
1303
1418
  const f = await boardFixture(1);
1304
1419
  const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1305
- const client = new Client({ name: 'board-reconcile-fixture', version: '1' });
1420
+ const client = new Client({ name: "board-access-fixture", version: "1" });
1306
1421
  const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1307
- const clients = vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockResolvedValue(f.contexts[0].clients);
1308
- const loads = vi.spyOn(issueModule, 'loadDeliveryContext');
1309
1422
  try {
1310
- await server.connect(serverTransport);
1311
- await client.connect(transport);
1312
- const listed = await client.listTools();
1313
- const tool = listed.tools.find((value) => value.name === boardName);
1314
- assert.ok(tool);
1315
- assert.equal(tool.inputSchema.type, 'object');
1316
- assert.equal(tool.inputSchema.additionalProperties, false);
1317
- for (const input of [
1318
- { repositories: [] },
1319
- { repositories: Array.from({ length: 11 }, (_, n) => `example/r${String(n)}`) },
1320
- { repositories: ['example/widget', 'EXAMPLE/Widget'] },
1321
- { repositories: ['invalid'] },
1322
- { repositories: ['example/widget'], mode: 'apply' },
1323
- { repositories: ['example/widget'], mode: 'dry-run', extra: true },
1324
- { repositories: ['example/widget'], repo: 'example/other' },
1325
- {
1326
- repositories: ['example/widget'],
1327
- checkouts: [
1328
- { repository: 'example/widget', issueNumber: 17, path: f.root },
1329
- { repository: 'example/widget', issueNumber: 17, path: f.root },
1330
- ],
1331
- },
1332
- ]) {
1333
- const response = await client.callTool({ name: boardName, arguments: input });
1334
- assert.equal(response.isError, true);
1335
- assert.equal(clients.mock.calls.length, 0);
1336
- }
1337
- await assert.rejects(executeTool(boardName, { repositories: ['example/widget'] }, { repoRoot: f.root, repo: 'example/other' }));
1338
- assert.equal(clients.mock.calls.length, 0);
1339
- const fromLibrary = board.BoardReconcilePlanSchema.parse(await executeTool(boardName, f.request, { repoRoot: f.root }));
1340
- const beforeInvalid = clients.mock.calls.length;
1341
- for (const input of [
1342
- { ...f.request, plan: fromLibrary },
1343
- { ...f.request, priorResult: {} },
1344
- { repositories: fromLibrary.scope, mode: 'apply', plan: fromLibrary, checkouts: [] },
1345
- ])
1346
- await assert.rejects(executeTool(boardName, input, { repoRoot: f.root }));
1347
- assert.equal(clients.mock.calls.length, beforeInvalid);
1348
- const response = await client.callTool({ name: boardName, arguments: f.request });
1349
- assert.equal(response.isError, undefined, JSON.stringify(response));
1350
- const fromMcp = board.BoardReconcilePlanSchema.parse(JSON.parse(response.content[0].text));
1351
- assert.equal(fromMcp.planId, fromLibrary.planId);
1352
- assert.equal(fromMcp.scopeComplete, true);
1353
- assert.ok(loads.mock.calls.length >= 2);
1354
- assert.equal(loads.mock.calls.every(([input]) => input.readPageLimit === 20), true);
1355
- assert.deepEqual(f.writes, []);
1356
- }
1357
- finally {
1358
- await client.close();
1359
- await server.close();
1360
- f.cleanup();
1361
- }
1423
+ f.rows.get("example/widget:17").state = "closed";
1424
+ const plan = await collect(f.contexts, f.request, [f.root]);
1425
+ const request = mode === "apply" ? { repositories: plan.scope, mode, plan } : f.request;
1426
+ f.controls.beforeGraphql = (query) => {
1427
+ if (query.includes("DeliveryRepository"))
1428
+ throw Object.assign(new Error("No repository read access"), { status: 403 });
1429
+ };
1430
+ vi.spyOn(githubClients, "createDeliveryGitHubClients").mockResolvedValue(f.contexts[0].clients);
1431
+ await server.connect(serverTransport);
1432
+ await client.connect(transport);
1433
+ const library = await executeTool(boardName, request, { repoRoot: f.root });
1434
+ const response = await client.callTool({ name: boardName, arguments: request });
1435
+ assert.equal(response.isError, void 0, JSON.stringify(response));
1436
+ for (const value of [library, JSON.parse(response.content[0].text)]) {
1437
+ if (mode === "apply") {
1438
+ const result = board.BoardReconcileResultSchema.parse(value);
1439
+ assert.equal(result.planId, plan.planId);
1440
+ assert.equal(result.scopeComplete, false);
1441
+ assert.equal(result.summary.applied, 0);
1442
+ } else assert.equal(board.BoardReconcilePlanSchema.parse(value).scopeComplete, false);
1443
+ }
1444
+ assert.deepEqual(f.writes, []);
1445
+ } finally {
1446
+ await client.close();
1447
+ await server.close();
1448
+ f.cleanup();
1449
+ }
1450
+ }
1451
+ );
1452
+ test("public dry-run permits a readable Project without write access", async () => {
1453
+ const f = await boardFixture(1);
1454
+ try {
1455
+ f.controls.writable = false;
1456
+ vi.spyOn(githubClients, "createDeliveryGitHubClients").mockResolvedValue(f.contexts[0].clients);
1457
+ const result = board.BoardReconcilePlanSchema.parse(await executeTool(boardName, f.request, { repoRoot: f.root }));
1458
+ assert.equal(result.scopeComplete, true);
1459
+ assert.deepEqual(f.writes, []);
1460
+ } finally {
1461
+ f.cleanup();
1462
+ }
1362
1463
  });
1363
- test.each(['dry-run', 'apply'])('pre-context access failure preserves %s output without writes', async (mode) => {
1464
+ test.each(["dry-run", "apply", "apply-empty"])(
1465
+ "pre-context 21st routing page preserves %s mode through real library and MCP",
1466
+ async (variant) => {
1364
1467
  const f = await boardFixture(1);
1365
1468
  const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1366
- const client = new Client({ name: 'board-access-fixture', version: '1' });
1469
+ const client = new Client({ name: "board-pre-context-fixture", version: "1" });
1367
1470
  const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1368
1471
  try {
1369
- f.rows.get('example/widget:17').state = 'closed';
1370
- const plan = await collect(f.contexts, f.request, [f.root]);
1371
- const request = mode === 'apply' ? { repositories: plan.scope, mode, plan } : f.request;
1372
- f.controls.beforeGraphql = (query) => {
1373
- if (query.includes('DeliveryRepository'))
1374
- throw Object.assign(new Error('No repository read access'), { status: 403 });
1472
+ if (variant === "apply") f.rows.get("example/widget:17").state = "closed";
1473
+ const plan = await collect(f.contexts, f.request, [f.root]);
1474
+ const prior = board.incompleteBoardReconcile(
1475
+ { repositories: plan.scope, mode: "apply", plan },
1476
+ { repository: plan.scope[0], stage: "prior", reason: "evidence-unavailable" }
1477
+ );
1478
+ if (prior.operations[0]) {
1479
+ const operation = prior.operations[0];
1480
+ operation.outcome = "unknown";
1481
+ operation.attempted = true;
1482
+ operation.before = {
1483
+ itemId: operation.expected.itemId,
1484
+ archived: false,
1485
+ status: { current: "Todo", kind: "verified", name: "Queued", optionId: "STATUS-0" }
1375
1486
  };
1376
- vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockResolvedValue(f.contexts[0].clients);
1377
- await server.connect(serverTransport);
1378
- await client.connect(transport);
1379
- const library = await executeTool(boardName, request, { repoRoot: f.root });
1380
- const response = await client.callTool({ name: boardName, arguments: request });
1381
- assert.equal(response.isError, undefined, JSON.stringify(response));
1382
- for (const value of [library, JSON.parse(response.content[0].text)]) {
1383
- if (mode === 'apply') {
1384
- const result = board.BoardReconcileResultSchema.parse(value);
1385
- assert.equal(result.planId, plan.planId);
1386
- assert.equal(result.scopeComplete, false);
1387
- assert.equal(result.summary.applied, 0);
1388
- }
1389
- else
1390
- assert.equal(board.BoardReconcilePlanSchema.parse(value).scopeComplete, false);
1487
+ operation.readback = structuredClone(operation.before);
1488
+ }
1489
+ const request = variant === "dry-run" ? f.request : { repositories: plan.scope, mode: "apply", plan, priorResult: prior };
1490
+ const original = f.contexts[0].clients.graphql;
1491
+ let requests = 0;
1492
+ const limited = (async (query, variables) => {
1493
+ const response = await original(query, variables);
1494
+ if (!query.includes("ProjectDeliveryConfiguration")) return response;
1495
+ requests++;
1496
+ const cloned = JSON.parse(JSON.stringify(response));
1497
+ if (variables.cursor != null) cloned.organization.projectV2.fields.nodes = [];
1498
+ cloned.organization.projectV2.fields.pageInfo = { hasNextPage: true, endCursor: `bounded-${String(requests)}` };
1499
+ return cloned;
1500
+ });
1501
+ vi.spyOn(githubClients, "createDeliveryGitHubClients").mockResolvedValue({
1502
+ ...f.contexts[0].clients,
1503
+ graphql: limited
1504
+ });
1505
+ await server.connect(serverTransport);
1506
+ await client.connect(transport);
1507
+ for (const surface of ["library", "mcp"]) {
1508
+ const before = requests;
1509
+ const value = surface === "library" ? await executeTool(boardName, request, { repoRoot: f.root }) : await (async () => {
1510
+ const response = await client.callTool({ name: boardName, arguments: request });
1511
+ assert.equal(response.isError, void 0, JSON.stringify(response));
1512
+ return JSON.parse(response.content[0].text);
1513
+ })();
1514
+ assert.equal(requests - before, 20);
1515
+ if (variant === "dry-run") {
1516
+ const result = board.BoardReconcilePlanSchema.parse(value);
1517
+ assert.equal(result.scopeComplete, false);
1518
+ assert.equal(result.gaps[0].pagesRequested, 20);
1519
+ } else {
1520
+ const result = board.BoardReconcileResultSchema.parse(value);
1521
+ assert.equal(result.scopeComplete, false);
1522
+ assert.equal(result.planId, plan.planId);
1523
+ assert.deepEqual(
1524
+ result.operations.map((operation) => operation.operationId),
1525
+ plan.operations.map((operation) => operation.operationId)
1526
+ );
1527
+ assert.equal(result.summary.applied, 0);
1528
+ assert.equal(result.summary.satisfied, 0);
1529
+ if (result.operations[0]) {
1530
+ assert.deepEqual(result.operations[0].priorEvidence.at(-1), {
1531
+ outcome: "unknown",
1532
+ attempted: true,
1533
+ before: prior.operations[0].before,
1534
+ readback: prior.operations[0].readback
1535
+ });
1536
+ assert.ok(result.operations[0].knownItemIds.includes(prior.operations[0].expected.itemId));
1537
+ }
1391
1538
  }
1392
1539
  assert.deepEqual(f.writes, []);
1393
- }
1394
- finally {
1395
- await client.close();
1396
- await server.close();
1397
- f.cleanup();
1398
- }
1540
+ }
1541
+ } finally {
1542
+ await client.close();
1543
+ await server.close();
1544
+ f.cleanup();
1545
+ }
1546
+ }
1547
+ );
1548
+ test("apply development-token override is rejected before clients while configured personal author remains valid", async () => {
1549
+ const f = await boardFixture(1);
1550
+ try {
1551
+ f.rows.get("example/widget:17").state = "closed";
1552
+ const plan = await collect(f.contexts, f.request, [f.root]);
1553
+ const clients = vi.spyOn(githubClients, "createDeliveryGitHubClients").mockResolvedValue(f.contexts[0].clients);
1554
+ await assert.rejects(
1555
+ executeTool(
1556
+ boardName,
1557
+ { repositories: plan.scope, mode: "apply", plan },
1558
+ { repoRoot: f.root, identity: "personal", personalAuth: true }
1559
+ ),
1560
+ /override/u
1561
+ );
1562
+ assert.equal(clients.mock.calls.length, 0);
1563
+ const settingsPath = join(f.root, "settings.json");
1564
+ const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
1565
+ settings.roles.author = {
1566
+ authSource: "personal",
1567
+ identity: "host-author",
1568
+ credentialEnv: { token: "SYNTHETIC_TOKEN" }
1569
+ };
1570
+ writeFileSync(settingsPath, JSON.stringify(settings));
1571
+ f.contexts[0].clients.authSource = "personal";
1572
+ f.contexts[0].clients.authenticatedAuthor = async () => ({
1573
+ actorLogin: "host-author",
1574
+ credentialIdentity: "user:1"
1575
+ });
1576
+ const personal = board.BoardReconcilePlanSchema.parse(
1577
+ await executeTool(boardName, f.request, { repoRoot: f.root })
1578
+ );
1579
+ const result = board.BoardReconcileResultSchema.parse(
1580
+ await executeTool(
1581
+ boardName,
1582
+ { repositories: personal.scope, mode: "apply", plan: personal },
1583
+ { repoRoot: f.root }
1584
+ )
1585
+ );
1586
+ assert.equal(result.summary.applied, 1);
1587
+ } finally {
1588
+ f.cleanup();
1589
+ }
1399
1590
  });
1400
- test('public dry-run permits a readable Project without write access', async () => {
1401
- const f = await boardFixture(1);
1402
- try {
1403
- f.controls.writable = false;
1404
- vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockResolvedValue(f.contexts[0].clients);
1405
- const result = board.BoardReconcilePlanSchema.parse(await executeTool(boardName, f.request, { repoRoot: f.root }));
1406
- assert.equal(result.scopeComplete, true);
1407
- assert.deepEqual(f.writes, []);
1408
- }
1409
- finally {
1410
- f.cleanup();
1411
- }
1591
+ test("opaque actor revalidation failure stops every remaining independent Project group", async () => {
1592
+ const f = await boardFixture(1, ["example/widget", "other/second", "third/last"], true);
1593
+ try {
1594
+ for (const row of f.rows.values()) row.state = "closed";
1595
+ const plan = await collect(f.contexts, f.request, [f.root]);
1596
+ const actor = f.contexts[1].clients.authenticatedAuthor;
1597
+ f.contexts[1].clients.authenticatedAuthor = async (signal) => {
1598
+ if (f.writes.length > 0)
1599
+ throw new (await import("./errors.js")).DeliveryError("Personal author identity readback failed.");
1600
+ return actor(signal);
1601
+ };
1602
+ const result = await applyPlan(f, plan);
1603
+ assert.equal(result.operations[0].outcome, "applied");
1604
+ assert.equal(result.operations[1].outcome, "refused");
1605
+ assert.equal(result.operations[2].attempted, false);
1606
+ assert.equal(f.writes.length, 1);
1607
+ assert.equal(result.scopeComplete, false);
1608
+ } finally {
1609
+ f.cleanup();
1610
+ }
1412
1611
  });
1413
- test.each(['dry-run', 'apply', 'apply-empty'])('pre-context 21st routing page preserves %s mode through real library and MCP', async (variant) => {
1612
+ test.each(["closure", "points", "status"])(
1613
+ "%s observed by the final readiness reread refuses activation before mutation",
1614
+ async (change) => {
1414
1615
  const f = await boardFixture(1);
1415
- const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1416
- const client = new Client({ name: 'board-pre-context-fixture', version: '1' });
1417
- const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1418
1616
  try {
1419
- if (variant === 'apply')
1420
- f.rows.get('example/widget:17').state = 'closed';
1421
- const plan = await collect(f.contexts, f.request, [f.root]);
1422
- const prior = board.incompleteBoardReconcile({ repositories: plan.scope, mode: 'apply', plan }, { repository: plan.scope[0], stage: 'prior', reason: 'evidence-unavailable' });
1423
- if (prior.operations[0]) {
1424
- const operation = prior.operations[0];
1425
- operation.outcome = 'unknown';
1426
- operation.attempted = true;
1427
- operation.before = {
1428
- itemId: operation.expected.itemId,
1429
- archived: false,
1430
- status: { current: 'Todo', kind: 'verified', name: 'Queued', optionId: 'STATUS-0' },
1431
- };
1432
- operation.readback = structuredClone(operation.before);
1433
- }
1434
- const request = variant === 'dry-run' ? f.request : { repositories: plan.scope, mode: 'apply', plan, priorResult: prior };
1435
- const original = f.contexts[0].clients.graphql;
1436
- let requests = 0;
1437
- const limited = (async (query, variables) => {
1438
- const response = await original(query, variables);
1439
- if (!query.includes('ProjectDeliveryConfiguration'))
1440
- return response;
1441
- requests++;
1442
- const cloned = JSON.parse(JSON.stringify(response));
1443
- if (variables.cursor != null)
1444
- cloned.organization.projectV2.fields.nodes = [];
1445
- cloned.organization.projectV2.fields.pageInfo = { hasNextPage: true, endCursor: `bounded-${String(requests)}` };
1446
- return cloned;
1447
- });
1448
- vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockResolvedValue({
1449
- ...f.contexts[0].clients,
1450
- graphql: limited,
1451
- });
1452
- await server.connect(serverTransport);
1453
- await client.connect(transport);
1454
- for (const surface of ['library', 'mcp']) {
1455
- const before = requests;
1456
- const value = surface === 'library'
1457
- ? await executeTool(boardName, request, { repoRoot: f.root })
1458
- : await (async () => {
1459
- const response = await client.callTool({ name: boardName, arguments: request });
1460
- assert.equal(response.isError, undefined, JSON.stringify(response));
1461
- return JSON.parse(response.content[0].text);
1462
- })();
1463
- assert.equal(requests - before, 20);
1464
- if (variant === 'dry-run') {
1465
- const result = board.BoardReconcilePlanSchema.parse(value);
1466
- assert.equal(result.scopeComplete, false);
1467
- assert.equal(result.gaps[0].pagesRequested, 20);
1468
- }
1469
- else {
1470
- const result = board.BoardReconcileResultSchema.parse(value);
1471
- assert.equal(result.scopeComplete, false);
1472
- assert.equal(result.planId, plan.planId);
1473
- assert.deepEqual(result.operations.map((operation) => operation.operationId), plan.operations.map((operation) => operation.operationId));
1474
- assert.equal(result.summary.applied, 0);
1475
- assert.equal(result.summary.satisfied, 0);
1476
- if (result.operations[0]) {
1477
- assert.deepEqual(result.operations[0].priorEvidence.at(-1), {
1478
- outcome: 'unknown',
1479
- attempted: true,
1480
- before: prior.operations[0].before,
1481
- readback: prior.operations[0].readback,
1482
- });
1483
- assert.ok(result.operations[0].knownItemIds.includes(prior.operations[0].expected.itemId));
1484
- }
1485
- }
1486
- assert.deepEqual(f.writes, []);
1617
+ const row = f.rows.get("example/widget:17");
1618
+ const request = { ...f.request, checkouts: [f.checkout("example/widget", 17)] };
1619
+ const plan = await collect(f.contexts, request, [f.root]);
1620
+ assert.equal(plan.operations[0].target, "In Progress");
1621
+ const original = f.contexts[0].clients.rest.issues.get;
1622
+ let reads = 0;
1623
+ f.contexts[0].clients.rest.issues.get = (async (input) => {
1624
+ if (++reads === 6) {
1625
+ if (change === "closure") row.state = "closed";
1626
+ if (change === "points") row.points = 4;
1627
+ if (change === "status") f.members.get(row.node_id).status = "Blocked";
1487
1628
  }
1488
- }
1489
- finally {
1490
- await client.close();
1491
- await server.close();
1492
- f.cleanup();
1493
- }
1629
+ return original(input);
1630
+ });
1631
+ const result = await applyPlan(f, plan);
1632
+ assert.equal(reads >= 6, true);
1633
+ assert.equal(f.writes.length, 0);
1634
+ assert.equal(result.operations[0].attempted, false);
1635
+ assert.ok(result.summary.refused + result.summary.drifted > 0);
1636
+ } finally {
1637
+ f.cleanup();
1638
+ }
1639
+ }
1640
+ );
1641
+ test("verified Status postimage refreshes current duplicate-label migration advice", async () => {
1642
+ const f = await boardFixture(1);
1643
+ try {
1644
+ const row = f.rows.get("example/widget:17");
1645
+ row.state = "closed";
1646
+ row.labels = [{ name: "status:Todo" }];
1647
+ const plan = await collect(f.contexts, f.request, [f.root]);
1648
+ assert.equal(plan.issues[0].metadata.find((value) => value.label === "status:Todo").mapping, "exact");
1649
+ const result = await applyPlan(f, plan);
1650
+ assert.equal(result.summary.applied, 1);
1651
+ assert.equal(result.issues[0].status.current, "Done");
1652
+ const duplicate = result.issues[0].metadata.find((value) => value.label === "status:Todo");
1653
+ assert.equal(duplicate.authoritativeValue, "Shipped");
1654
+ assert.equal(duplicate.mapping, "conflicting");
1655
+ assert.deepEqual(row.labels, [{ name: "status:Todo" }]);
1656
+ } finally {
1657
+ f.cleanup();
1658
+ }
1494
1659
  });
1495
- test('apply development-token override is rejected before clients while configured personal author remains valid', async () => {
1660
+ test.each(["active", "parked", "deferred"])(
1661
+ "%s Status apply and lost-response recovery retain the exact original intent",
1662
+ async (mode) => {
1496
1663
  const f = await boardFixture(1);
1497
1664
  try {
1498
- f.rows.get('example/widget:17').state = 'closed';
1499
- const plan = await collect(f.contexts, f.request, [f.root]);
1500
- const clients = vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockResolvedValue(f.contexts[0].clients);
1501
- await assert.rejects(executeTool(boardName, { repositories: plan.scope, mode: 'apply', plan }, { repoRoot: f.root, identity: 'personal', personalAuth: true }), /override/u);
1502
- assert.equal(clients.mock.calls.length, 0);
1503
- const settingsPath = join(f.root, 'settings.json');
1504
- const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
1505
- settings.roles.author = {
1506
- authSource: 'personal',
1507
- identity: 'host-author',
1508
- credentialEnv: { token: 'SYNTHETIC_TOKEN' },
1509
- };
1510
- writeFileSync(settingsPath, JSON.stringify(settings));
1511
- f.contexts[0].clients.authSource = 'personal';
1512
- f.contexts[0].clients.authenticatedAuthor = async () => ({
1513
- actorLogin: 'host-author',
1514
- credentialIdentity: 'user:1',
1515
- });
1516
- const personal = board.BoardReconcilePlanSchema.parse(await executeTool(boardName, f.request, { repoRoot: f.root }));
1517
- const result = board.BoardReconcileResultSchema.parse(await executeTool(boardName, { repositories: personal.scope, mode: 'apply', plan: personal }, { repoRoot: f.root }));
1518
- assert.equal(result.summary.applied, 1);
1519
- }
1520
- finally {
1521
- f.cleanup();
1522
- }
1523
- });
1524
- test('opaque actor revalidation failure stops every remaining independent Project group', async () => {
1525
- const f = await boardFixture(1, ['example/widget', 'other/second', 'third/last'], true);
1526
- try {
1527
- for (const row of f.rows.values())
1528
- row.state = 'closed';
1529
- const plan = await collect(f.contexts, f.request, [f.root]);
1530
- const actor = f.contexts[1].clients.authenticatedAuthor;
1531
- f.contexts[1].clients.authenticatedAuthor = async (signal) => {
1532
- if (f.writes.length > 0)
1533
- throw new (await import('./errors.js')).DeliveryError('Personal author identity readback failed.');
1534
- return actor(signal);
1535
- };
1536
- const result = await applyPlan(f, plan);
1537
- assert.equal(result.operations[0].outcome, 'applied');
1538
- assert.equal(result.operations[1].outcome, 'refused');
1539
- assert.equal(result.operations[2].attempted, false);
1540
- assert.equal(f.writes.length, 1);
1541
- assert.equal(result.scopeComplete, false);
1542
- }
1543
- finally {
1544
- f.cleanup();
1545
- }
1546
- });
1547
- test.each(['closure', 'points', 'status'])('%s observed by the final readiness reread refuses activation before mutation', async (change) => {
1548
- const f = await boardFixture(1);
1549
- try {
1550
- const row = f.rows.get('example/widget:17');
1551
- const request = { ...f.request, checkouts: [f.checkout('example/widget', 17)] };
1552
- const plan = await collect(f.contexts, request, [f.root]);
1553
- assert.equal(plan.operations[0].target, 'In Progress');
1554
- const original = f.contexts[0].clients.rest.issues.get;
1555
- let reads = 0;
1556
- f.contexts[0].clients.rest.issues.get = (async (input) => {
1557
- if (++reads === 6) {
1558
- // global pair, outer guard pair, then final boundary pair
1559
- if (change === 'closure')
1560
- row.state = 'closed';
1561
- if (change === 'points')
1562
- row.points = 4;
1563
- if (change === 'status')
1564
- f.members.get(row.node_id).status = 'Blocked';
1565
- }
1566
- return original(input);
1665
+ const row = f.rows.get("example/widget:17");
1666
+ const checkouts = mode === "active" ? [f.checkout("example/widget", 17)] : [];
1667
+ if (mode !== "active") {
1668
+ f.members.get(row.node_id).status = "In Progress";
1669
+ const fields = parseIssueBody(row.body, { title: row.title }).issue;
1670
+ row.body = renderIssueBody({
1671
+ ...fields,
1672
+ ...mode === "parked" ? { draft: true } : { deferral: { trigger: "Await the synthetic fixture signal." } }
1567
1673
  });
1568
- const result = await applyPlan(f, plan);
1569
- assert.equal(reads >= 6, true);
1570
- assert.equal(f.writes.length, 0);
1571
- assert.equal(result.operations[0].attempted, false);
1572
- assert.ok(result.summary.refused + result.summary.drifted > 0);
1573
- }
1574
- finally {
1575
- f.cleanup();
1576
- }
1577
- });
1578
- test('verified Status postimage refreshes current duplicate-label migration advice', async () => {
1674
+ }
1675
+ const plan = await collect(f.contexts, { ...f.request, checkouts }, [f.root]);
1676
+ const target = mode === "active" ? "In Progress" : "Todo";
1677
+ assert.equal(plan.operations[0].target, target);
1678
+ f.controls.failAfterStatus = true;
1679
+ const interrupted = await applyPlan(f, plan);
1680
+ assert.equal(interrupted.summary.unknown, 1);
1681
+ assert.equal(f.statusFor(row.node_id), target);
1682
+ f.controls.failAfterStatus = false;
1683
+ f.writes.length = 0;
1684
+ const resumed = await applyPlan(f, plan, interrupted);
1685
+ assert.equal(resumed.summary.satisfied, 1);
1686
+ assert.equal(resumed.summary.applied, 0);
1687
+ assert.equal(f.writes.length, 0);
1688
+ assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, "unknown");
1689
+ f.members.get(row.node_id).status = mode === "active" ? "Todo" : "In Progress";
1690
+ const applied = await applyPlan(f, plan);
1691
+ assert.equal(applied.summary.applied, 1);
1692
+ assert.equal(applied.operations[0].readback.status.current, target);
1693
+ } finally {
1694
+ f.cleanup();
1695
+ }
1696
+ }
1697
+ );
1698
+ test.each(["archived", "missing", "unwritable"])(
1699
+ "later readiness cannot hide %s membership behind initially unset Status",
1700
+ async (change) => {
1579
1701
  const f = await boardFixture(1);
1580
1702
  try {
1581
- const row = f.rows.get('example/widget:17');
1582
- row.state = 'closed';
1583
- row.labels = [{ name: 'status:Todo' }];
1584
- const plan = await collect(f.contexts, f.request, [f.root]);
1585
- assert.equal(plan.issues[0].metadata.find((value) => value.label === 'status:Todo').mapping, 'exact');
1586
- const result = await applyPlan(f, plan);
1587
- assert.equal(result.summary.applied, 1);
1588
- assert.equal(result.issues[0].status.current, 'Done');
1589
- const duplicate = result.issues[0].metadata.find((value) => value.label === 'status:Todo');
1590
- assert.equal(duplicate.authoritativeValue, 'Shipped');
1591
- assert.equal(duplicate.mapping, 'conflicting');
1592
- assert.deepEqual(row.labels, [{ name: 'status:Todo' }]);
1593
- }
1594
- finally {
1595
- f.cleanup();
1596
- }
1597
- });
1598
- test.each(['active', 'parked', 'deferred'])('%s Status apply and lost-response recovery retain the exact original intent', async (mode) => {
1599
- const f = await boardFixture(1);
1600
- try {
1601
- const row = f.rows.get('example/widget:17');
1602
- const checkouts = mode === 'active' ? [f.checkout('example/widget', 17)] : [];
1603
- if (mode !== 'active') {
1604
- f.members.get(row.node_id).status = 'In Progress';
1605
- const fields = parseIssueBody(row.body, { title: row.title }).issue;
1606
- row.body = renderIssueBody({
1607
- ...fields,
1608
- ...(mode === 'parked' ? { draft: true } : { deferral: { trigger: 'Await the synthetic fixture signal.' } }),
1609
- });
1703
+ const row = f.rows.get("example/widget:17");
1704
+ f.members.get(row.node_id).status = null;
1705
+ const plan = await collect(f.contexts, { ...f.request, checkouts: [f.checkout("example/widget", 17)] }, [f.root]);
1706
+ assert.equal(plan.operations[0].target, "In Progress");
1707
+ const original = f.contexts[0].clients.rest.issues.get;
1708
+ let reads = 0;
1709
+ f.contexts[0].clients.rest.issues.get = (async (input) => {
1710
+ if (++reads === 6) {
1711
+ if (change === "archived") f.members.get(row.node_id).archived = true;
1712
+ if (change === "missing") f.members.delete(row.node_id);
1713
+ if (change === "unwritable") f.controls.writable = false;
1610
1714
  }
1611
- const plan = await collect(f.contexts, { ...f.request, checkouts }, [f.root]);
1612
- const target = mode === 'active' ? 'In Progress' : 'Todo';
1613
- assert.equal(plan.operations[0].target, target);
1614
- f.controls.failAfterStatus = true;
1615
- const interrupted = await applyPlan(f, plan);
1616
- assert.equal(interrupted.summary.unknown, 1);
1617
- assert.equal(f.statusFor(row.node_id), target);
1618
- f.controls.failAfterStatus = false;
1619
- f.writes.length = 0;
1620
- const resumed = await applyPlan(f, plan, interrupted);
1621
- assert.equal(resumed.summary.satisfied, 1);
1622
- assert.equal(resumed.summary.applied, 0);
1623
- assert.equal(f.writes.length, 0);
1624
- assert.equal(resumed.operations[0].priorEvidence.at(-1).outcome, 'unknown');
1625
- f.members.get(row.node_id).status = mode === 'active' ? 'Todo' : 'In Progress';
1626
- const applied = await applyPlan(f, plan);
1627
- assert.equal(applied.summary.applied, 1);
1628
- assert.equal(applied.operations[0].readback.status.current, target);
1629
- }
1630
- finally {
1631
- f.cleanup();
1632
- }
1633
- });
1634
- test.each(['archived', 'missing', 'unwritable'])('later readiness cannot hide %s membership behind initially unset Status', async (change) => {
1635
- const f = await boardFixture(1);
1636
- try {
1637
- const row = f.rows.get('example/widget:17');
1638
- f.members.get(row.node_id).status = null;
1639
- const plan = await collect(f.contexts, { ...f.request, checkouts: [f.checkout('example/widget', 17)] }, [f.root]);
1640
- assert.equal(plan.operations[0].target, 'In Progress');
1641
- const original = f.contexts[0].clients.rest.issues.get;
1642
- let reads = 0;
1643
- f.contexts[0].clients.rest.issues.get = (async (input) => {
1644
- if (++reads === 6) {
1645
- if (change === 'archived')
1646
- f.members.get(row.node_id).archived = true;
1647
- if (change === 'missing')
1648
- f.members.delete(row.node_id);
1649
- if (change === 'unwritable')
1650
- f.controls.writable = false;
1651
- }
1652
- return original(input);
1653
- });
1654
- const result = await applyPlan(f, plan);
1655
- assert.equal(reads >= 6, true);
1656
- assert.equal(result.operations[0].attempted, false);
1657
- assert.equal(f.writes.length, 0);
1658
- assert.ok(result.summary.refused + result.summary.drifted > 0);
1659
- }
1660
- finally {
1661
- f.cleanup();
1662
- }
1663
- });
1664
- test('a compatible active postimage observed during readiness is satisfied without a repeated update', async () => {
1665
- const f = await boardFixture(1);
1666
- try {
1667
- const row = f.rows.get('example/widget:17');
1668
- const plan = await collect(f.contexts, { ...f.request, checkouts: [f.checkout('example/widget', 17)] }, [f.root]);
1669
- const original = f.contexts[0].clients.rest.issues.get;
1670
- let reads = 0;
1671
- f.contexts[0].clients.rest.issues.get = (async (input) => {
1672
- if (++reads === 6)
1673
- f.members.get(row.node_id).status = 'In Progress';
1674
- return original(input);
1675
- });
1676
- const result = await applyPlan(f, plan);
1677
- assert.equal(result.summary.satisfied, 1);
1678
- assert.equal(result.operations[0].attempted, false);
1679
- assert.equal(f.writes.length, 0);
1680
- }
1681
- finally {
1682
- f.cleanup();
1683
- }
1715
+ return original(input);
1716
+ });
1717
+ const result = await applyPlan(f, plan);
1718
+ assert.equal(reads >= 6, true);
1719
+ assert.equal(result.operations[0].attempted, false);
1720
+ assert.equal(f.writes.length, 0);
1721
+ assert.ok(result.summary.refused + result.summary.drifted > 0);
1722
+ } finally {
1723
+ f.cleanup();
1724
+ }
1725
+ }
1726
+ );
1727
+ test("a compatible active postimage observed during readiness is satisfied without a repeated update", async () => {
1728
+ const f = await boardFixture(1);
1729
+ try {
1730
+ const row = f.rows.get("example/widget:17");
1731
+ const plan = await collect(f.contexts, { ...f.request, checkouts: [f.checkout("example/widget", 17)] }, [f.root]);
1732
+ const original = f.contexts[0].clients.rest.issues.get;
1733
+ let reads = 0;
1734
+ f.contexts[0].clients.rest.issues.get = (async (input) => {
1735
+ if (++reads === 6) f.members.get(row.node_id).status = "In Progress";
1736
+ return original(input);
1737
+ });
1738
+ const result = await applyPlan(f, plan);
1739
+ assert.equal(result.summary.satisfied, 1);
1740
+ assert.equal(result.operations[0].attempted, false);
1741
+ assert.equal(f.writes.length, 0);
1742
+ } finally {
1743
+ f.cleanup();
1744
+ }
1684
1745
  });
1685
- //# sourceMappingURL=boardReconcile.test.js.map
1746
+ //# sourceMappingURL=boardReconcile.test.js.map