@aviaratech/ai-delivery 0.3.38 → 0.3.39

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 (170) hide show
  1. package/README.md +14 -18
  2. package/dist/agent.d.ts +0 -4
  3. package/dist/agent.js +1 -8
  4. package/dist/agent.js.map +2 -2
  5. package/dist/cli.js +2 -72
  6. package/dist/cli.js.map +2 -2
  7. package/dist/cliResult.js +2 -14
  8. package/dist/cliResult.js.map +2 -2
  9. package/dist/cliResult.test.js +0 -74
  10. package/dist/cliResult.test.js.map +2 -2
  11. package/dist/config/deliveryConfig.d.ts +0 -6
  12. package/dist/config/deliveryConfig.js +2 -35
  13. package/dist/config/deliveryConfig.js.map +2 -2
  14. package/dist/config/deliveryConfig.test.js +1 -25
  15. package/dist/config/deliveryConfig.test.js.map +2 -2
  16. package/dist/contributorChecks.test.js +0 -1
  17. package/dist/contributorChecks.test.js.map +2 -2
  18. package/dist/delivery/common.d.ts +0 -14
  19. package/dist/delivery/common.js +1 -44
  20. package/dist/delivery/common.js.map +2 -2
  21. package/dist/directoryIndependent.test.js +2 -24
  22. package/dist/directoryIndependent.test.js.map +2 -2
  23. package/dist/dispatch.js +0 -46
  24. package/dist/dispatch.js.map +3 -3
  25. package/dist/fixtures/inertTarget.js +3 -5
  26. package/dist/fixtures/inertTarget.js.map +2 -2
  27. package/dist/fixtures/recordedGitHubFlows.d.ts +0 -72
  28. package/dist/fixtures/recordedGitHubFlows.js +1 -57
  29. package/dist/fixtures/recordedGitHubFlows.js.map +2 -2
  30. package/dist/git.d.ts +0 -6
  31. package/dist/git.js +0 -15
  32. package/dist/git.js.map +2 -2
  33. package/dist/github/client.js +0 -3
  34. package/dist/github/client.js.map +2 -2
  35. package/dist/github/commandIdentityPolicy.js +0 -1
  36. package/dist/github/commandIdentityPolicy.js.map +2 -2
  37. package/dist/github/issueHistory.d.ts +0 -6
  38. package/dist/github/issueHistory.js +0 -39
  39. package/dist/github/issueHistory.js.map +2 -2
  40. package/dist/github/nativeIssueMetadata.d.ts +0 -10
  41. package/dist/github/nativeIssueMetadata.js +1 -33
  42. package/dist/github/nativeIssueMetadata.js.map +3 -3
  43. package/dist/github/projectDelivery.d.ts +0 -34
  44. package/dist/github/projectDelivery.js +0 -211
  45. package/dist/github/projectDelivery.js.map +2 -2
  46. package/dist/github/repo.d.ts +0 -8
  47. package/dist/github/repo.js +0 -72
  48. package/dist/github/repo.js.map +2 -2
  49. package/dist/issue.js +15 -15
  50. package/dist/issue.js.map +2 -2
  51. package/dist/issue63Routes.test.js +1 -72
  52. package/dist/issue63Routes.test.js.map +2 -2
  53. package/dist/issueIntake.test.js +12 -0
  54. package/dist/issueIntake.test.js.map +2 -2
  55. package/dist/issueJournal.d.ts +0 -9
  56. package/dist/issueJournal.js +10 -76
  57. package/dist/issueJournal.js.map +2 -2
  58. package/dist/issueJournal.test.js +1 -108
  59. package/dist/issueJournal.test.js.map +2 -2
  60. package/dist/issueTracking.test.js +0 -48
  61. package/dist/issueTracking.test.js.map +2 -2
  62. package/dist/lifecycle.test.js +12 -48
  63. package/dist/lifecycle.test.js.map +2 -2
  64. package/dist/logger.d.ts +0 -4
  65. package/dist/logger.js +0 -31
  66. package/dist/logger.js.map +2 -2
  67. package/dist/mcp/tools.d.ts +2 -618
  68. package/dist/mcp/tools.js +8 -34
  69. package/dist/mcp/tools.js.map +2 -2
  70. package/dist/pluginAuthProbe.js +0 -3
  71. package/dist/pluginAuthProbe.js.map +2 -2
  72. package/dist/pluginDoctor.test.js +1 -1
  73. package/dist/pluginDoctor.test.js.map +2 -2
  74. package/dist/pluginInstaller.js +0 -3
  75. package/dist/pluginInstaller.js.map +2 -2
  76. package/dist/pluginInstaller.test.js +3 -19
  77. package/dist/pluginInstaller.test.js.map +2 -2
  78. package/dist/pluginPackaging.test.js +1 -118
  79. package/dist/pluginPackaging.test.js.map +2 -2
  80. package/dist/pr.d.ts +2 -73
  81. package/dist/pr.js +27 -220
  82. package/dist/pr.js.map +3 -3
  83. package/dist/pr.test.js +11 -304
  84. package/dist/pr.test.js.map +2 -2
  85. package/dist/prAssociation.test.js +112 -22
  86. package/dist/prAssociation.test.js.map +2 -2
  87. package/dist/prDispatch.test.js +4 -11
  88. package/dist/prDispatch.test.js.map +2 -2
  89. package/dist/releaseWorkflow.test.js +0 -1
  90. package/dist/releaseWorkflow.test.js.map +2 -2
  91. package/dist/review.d.ts +0 -82
  92. package/dist/review.js +3 -94
  93. package/dist/review.js.map +2 -2
  94. package/dist/review.test.js +2 -4
  95. package/dist/review.test.js.map +2 -2
  96. package/dist/services/agentReadinessService.d.ts +0 -1
  97. package/dist/services/agentReadinessService.js.map +2 -2
  98. package/dist/stdoutRegression.test.js +3 -22
  99. package/dist/stdoutRegression.test.js.map +2 -2
  100. package/dist/targetPolicyDiscovery.test.js +0 -86
  101. package/dist/targetPolicyDiscovery.test.js.map +2 -2
  102. package/dist/targetPolicyEntrypoints.test.js +1 -54
  103. package/dist/targetPolicyEntrypoints.test.js.map +2 -2
  104. package/dist/targetRepositoryExecution.test.js +1 -49
  105. package/dist/targetRepositoryExecution.test.js.map +2 -2
  106. package/dist/terminalMessages.d.ts +0 -10
  107. package/dist/terminalMessages.js +1 -31
  108. package/dist/terminalMessages.js.map +2 -2
  109. package/dist/toolOutput.js +0 -2
  110. package/dist/toolOutput.js.map +2 -2
  111. package/dist/toolOutput.test.js +15 -1
  112. package/dist/toolOutput.test.js.map +2 -2
  113. package/dist/verification.d.ts +1 -186
  114. package/dist/verification.js +29 -587
  115. package/dist/verification.js.map +3 -3
  116. package/dist/verificationGate.test.js +4 -90
  117. package/dist/verificationGate.test.js.map +2 -2
  118. package/dist/version.d.ts +0 -6
  119. package/dist/version.js +2 -39
  120. package/dist/version.js.map +2 -2
  121. package/package.json +1 -1
  122. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  123. package/plugins/ai-delivery/plugin.json +1 -1
  124. package/plugins/ai-delivery/runtime/dist/cli.js +123 -167
  125. package/plugins/ai-delivery/runtime/package.json +1 -1
  126. package/dist/boardReconcile.test.d.ts +0 -1
  127. package/dist/boardReconcile.test.js +0 -1746
  128. package/dist/boardReconcile.test.js.map +0 -7
  129. package/dist/delivery/delivery.test.d.ts +0 -1
  130. package/dist/delivery/delivery.test.js +0 -560
  131. package/dist/delivery/delivery.test.js.map +0 -7
  132. package/dist/delivery/evidence.d.ts +0 -92
  133. package/dist/delivery/evidence.js +0 -139
  134. package/dist/delivery/evidence.js.map +0 -7
  135. package/dist/delivery/legacy.d.ts +0 -8
  136. package/dist/delivery/legacy.js +0 -65
  137. package/dist/delivery/legacy.js.map +0 -7
  138. package/dist/delivery/policy.d.ts +0 -252
  139. package/dist/delivery/policy.js +0 -221
  140. package/dist/delivery/policy.js.map +0 -7
  141. package/dist/delivery/stage.d.ts +0 -179
  142. package/dist/delivery/stage.js +0 -242
  143. package/dist/delivery/stage.js.map +0 -7
  144. package/dist/deliveryBoard.d.ts +0 -74
  145. package/dist/deliveryBoard.js +0 -644
  146. package/dist/deliveryBoard.js.map +0 -7
  147. package/dist/deliveryBoard.test.d.ts +0 -1
  148. package/dist/deliveryBoard.test.js +0 -649
  149. package/dist/deliveryBoard.test.js.map +0 -7
  150. package/dist/deliveryHealth.test.d.ts +0 -1
  151. package/dist/deliveryHealth.test.js +0 -191
  152. package/dist/deliveryHealth.test.js.map +0 -7
  153. package/dist/fixtures/deliveryBoardReplay.d.ts +0 -56
  154. package/dist/fixtures/deliveryBoardReplay.js +0 -617
  155. package/dist/fixtures/deliveryBoardReplay.js.map +0 -7
  156. package/dist/genericCompatibility.test.d.ts +0 -1
  157. package/dist/genericCompatibility.test.js +0 -66
  158. package/dist/genericCompatibility.test.js.map +0 -7
  159. package/dist/services/boardReconcileService.d.ts +0 -1204
  160. package/dist/services/boardReconcileService.js +0 -1445
  161. package/dist/services/boardReconcileService.js.map +0 -7
  162. package/dist/services/deliveryHealthService.d.ts +0 -84
  163. package/dist/services/deliveryHealthService.js +0 -204
  164. package/dist/services/deliveryHealthService.js.map +0 -7
  165. package/dist/services/legacyIssueMigration.d.ts +0 -46
  166. package/dist/services/legacyIssueMigration.js +0 -299
  167. package/dist/services/legacyIssueMigration.js.map +0 -7
  168. package/dist/utils/filesystem.d.ts +0 -1
  169. package/dist/utils/filesystem.js +0 -5
  170. package/dist/utils/filesystem.js.map +0 -7
@@ -1,1746 +0,0 @@
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;
32
- afterEach(() => {
33
- vi.unstubAllEnvs();
34
- vi.restoreAllMocks();
35
- });
36
- const boardName = "board_reconcile";
37
- const collect = async (contexts, request, roots) => {
38
- return board.collectBoardReconcilePlan(contexts, request, { checkoutRoots: roots });
39
- };
40
- async function applyPlan(f, plan, priorResult, 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
- );
52
- }
53
- function redigest(plan) {
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);
60
- }
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 }
177
- };
178
- const discovery = syntheticDiscoveryClients(configured);
179
- const own = (number) => {
180
- const row = rows.get(`${repository}:${String(number)}`);
181
- assert.ok(row);
182
- return row;
183
- };
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}` } } };
210
- }
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
- }
248
- }
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
- }
271
- }
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
- }
285
- }
286
- }
287
- };
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
- }
297
- };
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
- };
312
- },
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
- })
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
- };
392
- }
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
- }
446
- });
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
- }
467
- });
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);
474
- });
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-")));
480
- try {
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);
537
- });
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
- }
577
- });
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
- }
588
- });
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
- }
600
- });
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
- }
628
- });
629
- test.each(["detached", "locked", "missing", "remote", "ambiguous-link", "root-escape"])(
630
- "physical %s observation stays unknown",
631
- async (failure) => {
632
- const f = await boardFixture(1);
633
- try {
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
- }
675
- });
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
- }
692
- });
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
- }
723
- });
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
- }
745
- });
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);
750
- try {
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"
764
- };
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) => {
781
- const f = await boardFixture(3);
782
- try {
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" } : {}
789
- });
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) => {
805
- const f = await boardFixture(2);
806
- try {
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" };
816
- else
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) => {
854
- const f = await boardFixture(1);
855
- try {
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
- }
904
- });
905
- test.each(["actor", "access", "inventory", "archive", "configuration"])(
906
- "apply preflight %s drift refuses before writes",
907
- async (failure) => {
908
- const f = await boardFixture(1);
909
- try {
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) => {
949
- const f = await boardFixture(1);
950
- try {
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
- }
1003
- });
1004
- test.each(["add", "status"])(
1005
- "lost %s response is unknown until fresh resume proves the postimage",
1006
- async (kind) => {
1007
- const f = await boardFixture(1);
1008
- try {
1009
- const row = f.rows.get("example/widget:17");
1010
- if (kind === "add") {
1011
- f.members.delete(row.node_id);
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) => {
1037
- const f = await boardFixture(1);
1038
- try {
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
- }
1084
- });
1085
- test.each(["native-drift", "cancel"])(
1086
- "post-write %s retains attempted evidence and stops the shared Project",
1087
- async (failure) => {
1088
- const f = await boardFixture(2);
1089
- const controller = new AbortController();
1090
- try {
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)}` } }
1124
- }
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
- }
1143
- });
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
- }
1161
- });
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
- }
1189
- });
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
- }
1207
- });
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
- }
1236
- });
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
- );
1245
- try {
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
- }
1288
- });
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
- }
1322
- });
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
- }
1347
- });
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
- }
1414
- });
1415
- test.each(["dry-run", "apply"])(
1416
- "pre-context access failure preserves %s output without writes",
1417
- async (mode) => {
1418
- const f = await boardFixture(1);
1419
- const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1420
- const client = new Client({ name: "board-access-fixture", version: "1" });
1421
- const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1422
- try {
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
- }
1463
- });
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) => {
1467
- const f = await boardFixture(1);
1468
- const server = createAiDeliveryMcpServer({ repoRoot: f.root });
1469
- const client = new Client({ name: "board-pre-context-fixture", version: "1" });
1470
- const [transport, serverTransport] = InMemoryTransport.createLinkedPair();
1471
- try {
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" }
1486
- };
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
- }
1538
- }
1539
- assert.deepEqual(f.writes, []);
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
- }
1590
- });
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
- }
1611
- });
1612
- test.each(["closure", "points", "status"])(
1613
- "%s observed by the final readiness reread refuses activation before mutation",
1614
- async (change) => {
1615
- const f = await boardFixture(1);
1616
- try {
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";
1628
- }
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
- }
1659
- });
1660
- test.each(["active", "parked", "deferred"])(
1661
- "%s Status apply and lost-response recovery retain the exact original intent",
1662
- async (mode) => {
1663
- const f = await boardFixture(1);
1664
- try {
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." } }
1673
- });
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) => {
1701
- const f = await boardFixture(1);
1702
- try {
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;
1714
- }
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
- }
1745
- });
1746
- //# sourceMappingURL=boardReconcile.test.js.map