@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.
- package/CONTRIBUTING.md +12 -206
- package/README.md +57 -554
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +76 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +105 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +402 -515
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +329 -353
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +59 -19
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.js +73 -67
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +44 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1945 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +264 -286
- package/dist/mcp/tools.js +267 -340
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +460 -409
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +132 -94
- package/dist/pr.js +1521 -1323
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +1678 -632
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +150 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +183 -0
- package/dist/readView.js +217 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +119 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/deliveryAdmission.js +131 -154
- package/dist/services/deliveryAdmission.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/services/worktreeRegistry.d.ts +27 -119
- package/dist/services/worktreeRegistry.js +765 -1182
- package/dist/services/worktreeRegistry.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +353 -352
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +305 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +463 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.js +84 -76
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.js +15 -18
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -19
- package/dist/verification.js +1020 -1939
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +23 -24
- package/dist/version.js.map +7 -1
- package/dist/worktree.d.ts +3 -15
- package/dist/worktree.js +97 -177
- package/dist/worktree.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +358 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
|
@@ -1,947 +1,1051 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { issueProjectItemsResponse } from "./fixtures/issueProjectItems.js";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { afterEach, test, vi } from "vitest";
|
|
4
|
+
import * as issue from "./issue.js";
|
|
5
|
+
import * as configuration from "./config/deliveryConfig.js";
|
|
6
|
+
import { executeTool } from "./dispatch.js";
|
|
7
|
+
import { getAiDeliveryMcpTool } from "./mcp/tools.js";
|
|
8
|
+
import { DeliveryError, getRateLimitDiagnostics } from "./errors.js";
|
|
9
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
11
|
+
import { createAiDeliveryMcpServer } from "./mcp/index.js";
|
|
12
|
+
import { syntheticDiscoveryConfig } from "./fixtures/discovery.js";
|
|
13
|
+
import { IssueFields, renderIssueBody } from "./issueContract.js";
|
|
14
|
+
import { syncIssueProjectStatus } from "./github/projectDelivery.js";
|
|
13
15
|
function batchFixture() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
row.body = patch.body;
|
|
155
|
-
if (typeof patch.type === 'string')
|
|
156
|
-
row.type = { name: patch.type };
|
|
157
|
-
if (Array.isArray(patch.labels) && !controls.ignoreLabels)
|
|
158
|
-
row.labels = patch.labels.map((label) => label.toLowerCase());
|
|
159
|
-
if (patch.milestone !== undefined)
|
|
160
|
-
Object.assign(row, { milestone: patch.milestone === null ? null : { number: patch.milestone } });
|
|
161
|
-
if (typeof patch.state === 'string') {
|
|
162
|
-
row.state = patch.state;
|
|
163
|
-
reasons.set(issue_number, patch.state === 'closed'
|
|
164
|
-
? (typeof patch.state_reason === 'string' ? patch.state_reason : 'completed').toUpperCase()
|
|
165
|
-
: 'REOPENED');
|
|
166
|
-
}
|
|
167
|
-
if (typeof patch.duplicate_issue_id === 'number')
|
|
168
|
-
duplicates.set(issue_number, patch.duplicate_issue_id - 100);
|
|
169
|
-
if (controls.failAfterWrite === issue_number) {
|
|
170
|
-
controls.failAfterWrite = 0;
|
|
171
|
-
throw new Error('Synthetic acknowledgement lost');
|
|
172
|
-
}
|
|
173
|
-
return { data: rows.get(issue_number) };
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
paginate: async (_method, { issue_number }) => [...parents].filter(([, parent]) => parent === issue_number).map(([number]) => rows.get(number)),
|
|
177
|
-
request: async (route, params) => {
|
|
178
|
-
if (route.startsWith('GET /orgs'))
|
|
179
|
-
return {
|
|
180
|
-
data: [
|
|
181
|
-
...Object.values(syntheticDiscoveryConfig.native)
|
|
182
|
-
.filter((field) => typeof field === 'object' && field !== null && 'databaseId' in field)
|
|
183
|
-
.map((field) => ({
|
|
184
|
-
id: Number(field.databaseId),
|
|
185
|
-
name: field.name,
|
|
186
|
-
data_type: 'single_select',
|
|
187
|
-
options: field.values.map((name) => ({ name })),
|
|
188
|
-
})),
|
|
189
|
-
{ id: 103, name: 'Start date', data_type: 'date' },
|
|
190
|
-
{ id: 104, name: 'Target date', data_type: 'date' },
|
|
191
|
-
],
|
|
192
|
-
};
|
|
193
|
-
if (route.startsWith('POST ')) {
|
|
194
|
-
const dates = params.issue_field_values.filter((value) => value.field_id >= 103);
|
|
195
|
-
if (dates.length)
|
|
196
|
-
dateWrites.push(dates.map((value) => value.field_id));
|
|
197
|
-
writes.push('metadata');
|
|
198
|
-
metadata.set(params.issue_number, {
|
|
199
|
-
...metadata.get(params.issue_number),
|
|
200
|
-
...Object.fromEntries(params.issue_field_values.map((value) => [String(value.field_id), value.value])),
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
if (route.startsWith('DELETE ')) {
|
|
204
|
-
if (params.issue_field_id >= 103)
|
|
205
|
-
dateWrites.push([params.issue_field_id]);
|
|
206
|
-
writes.push('metadata');
|
|
207
|
-
delete metadata.get(params.issue_number)[String(params.issue_field_id)];
|
|
208
|
-
}
|
|
209
|
-
return { data: fieldValues(params.issue_number) };
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
graphql: async (query, variables) => {
|
|
213
|
-
if (controls.moveProjectToTodoAfterWrite &&
|
|
214
|
-
writes.includes('update:1') &&
|
|
215
|
-
query.includes('ProjectDeliveryItems') &&
|
|
216
|
-
++controls.projectReadsAfterWrite === 2)
|
|
217
|
-
throw new Error('PRIVATE_SYNC_READ_FAILURE');
|
|
218
|
-
if (controls.projectUnavailableAfterDependency &&
|
|
219
|
-
writes.includes('dependency') &&
|
|
220
|
-
query.includes('ProjectDelivery'))
|
|
221
|
-
throw new Error('PRIVATE_PROJECT_READ_FAILURE');
|
|
222
|
-
const numeric = variables.number ?? variables.issueNumber;
|
|
223
|
-
const nodeId = variables.issueNodeId ?? variables.itemId ?? '1';
|
|
224
|
-
const number = typeof numeric === 'number' ? numeric : typeof nodeId === 'string' ? Number(nodeId.replace(/\D/gu, '')) : NaN;
|
|
225
|
-
if (query.includes('IssueClosureReadback'))
|
|
226
|
-
return {
|
|
227
|
-
repository: {
|
|
228
|
-
issue: {
|
|
229
|
-
number,
|
|
230
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
231
|
-
state: rows.get(number).state.toUpperCase(),
|
|
232
|
-
stateReason: reasons.get(number) ?? null,
|
|
233
|
-
duplicateOf: duplicates.has(number)
|
|
234
|
-
? { number: duplicates.get(number), repository: { nameWithOwner: 'example/widget' } }
|
|
235
|
-
: null,
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
if (query.includes('blockedBy(first:'))
|
|
240
|
-
return {
|
|
241
|
-
repository: {
|
|
242
|
-
issue: {
|
|
243
|
-
parent: parents.has(number)
|
|
244
|
-
? {
|
|
245
|
-
id: controls.parentNodeId || `ISSUE${parents.get(number)}`,
|
|
246
|
-
number: parents.get(number),
|
|
247
|
-
repository: { nameWithOwner: controls.parentRepository },
|
|
248
|
-
}
|
|
249
|
-
: null,
|
|
250
|
-
blockedBy: {
|
|
251
|
-
nodes: (blockers.get(number) ?? []).map((n) => ({
|
|
252
|
-
id: `ISSUE${n}`,
|
|
253
|
-
number: n,
|
|
254
|
-
state: rows.get(n).state.toUpperCase(),
|
|
255
|
-
title: rows.get(n).title,
|
|
256
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
257
|
-
})),
|
|
258
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
if (query.includes('mutation') && (query.includes('addBlockedBy') || query.includes('removeBlockedBy'))) {
|
|
264
|
-
writes.push('dependency');
|
|
265
|
-
const dependent = Number(String(variables.issue).replace(/\D/gu, ''));
|
|
266
|
-
const blocker = Number(String(variables.blocking).replace(/\D/gu, ''));
|
|
267
|
-
blockers.set(dependent, query.includes('addBlockedBy')
|
|
268
|
-
? [...new Set([...(blockers.get(dependent) ?? []), blocker])]
|
|
269
|
-
: (blockers.get(dependent) ?? []).filter((n) => n !== blocker));
|
|
270
|
-
return {};
|
|
271
|
-
}
|
|
272
|
-
if (query.includes('ProjectDeliveryItems'))
|
|
273
|
-
return {
|
|
274
|
-
organization: {
|
|
275
|
-
projectV2: {
|
|
276
|
-
items: {
|
|
277
|
-
nodes: [...rows.keys()].map((n) => ({
|
|
278
|
-
id: `ITEM${n}`,
|
|
279
|
-
isArchived: controls.archived,
|
|
280
|
-
content: { id: `ISSUE${n}` },
|
|
281
|
-
fieldValueByName: {
|
|
282
|
-
name: statuses.get(n),
|
|
283
|
-
optionId: statuses.get(n) === 'Active'
|
|
284
|
-
? 'ACTIVE'
|
|
285
|
-
: statuses.get(n) === 'Shipped'
|
|
286
|
-
? 'DONE'
|
|
287
|
-
: statuses.get(n) === 'Waiting'
|
|
288
|
-
? 'BLOCKED'
|
|
289
|
-
: 'TODO',
|
|
290
|
-
},
|
|
291
|
-
})),
|
|
292
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
if (query.includes('UpdateProjectDeliveryStatus')) {
|
|
298
|
-
writes.push('project');
|
|
299
|
-
statuses.set(number, variables.optionId === 'DONE'
|
|
300
|
-
? 'Shipped'
|
|
301
|
-
: variables.optionId === 'BLOCKED'
|
|
302
|
-
? 'Waiting'
|
|
303
|
-
: variables.optionId === 'ACTIVE'
|
|
304
|
-
? 'Active'
|
|
305
|
-
: 'Queued');
|
|
306
|
-
if (controls.loseProjectAck) {
|
|
307
|
-
controls.loseProjectAck = false;
|
|
308
|
-
throw new Error('PRIVATE_PROJECT_ACK');
|
|
309
|
-
}
|
|
310
|
-
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: `ITEM${number}` } } };
|
|
16
|
+
const rows = new Map(
|
|
17
|
+
Array.from({ length: 5 }, (_, index) => {
|
|
18
|
+
const number = index + 1;
|
|
19
|
+
return [
|
|
20
|
+
number,
|
|
21
|
+
{
|
|
22
|
+
number,
|
|
23
|
+
id: number + 100,
|
|
24
|
+
node_id: `ISSUE${number}`,
|
|
25
|
+
title: `Synthetic item ${number}`,
|
|
26
|
+
body: renderIssueBody(IssueFields.parse({ title: `Synthetic item ${number}`, draft: true })),
|
|
27
|
+
state: "open",
|
|
28
|
+
type: { name: "Task" },
|
|
29
|
+
labels: [],
|
|
30
|
+
milestone: null,
|
|
31
|
+
html_url: `https://github.com/example/widget/issues/${number}`
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
const writes = [];
|
|
37
|
+
const dateWrites = [];
|
|
38
|
+
const controls = {
|
|
39
|
+
failAfterWrite: 0,
|
|
40
|
+
failReadback: 0,
|
|
41
|
+
driftOnRead: 0,
|
|
42
|
+
rateLimited: 0,
|
|
43
|
+
ignoreLabels: false,
|
|
44
|
+
parentRepository: "example/widget",
|
|
45
|
+
parentNodeId: "",
|
|
46
|
+
archived: false,
|
|
47
|
+
archiveAfterWrite: false,
|
|
48
|
+
loseProjectAck: false,
|
|
49
|
+
projectUnavailableAfterDependency: false,
|
|
50
|
+
nativeUnavailableAfterDependency: false,
|
|
51
|
+
moveProjectToTodoAfterWrite: false,
|
|
52
|
+
projectReadsAfterWrite: 0
|
|
53
|
+
};
|
|
54
|
+
const reads = /* @__PURE__ */ new Map();
|
|
55
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
56
|
+
const parents = /* @__PURE__ */ new Map();
|
|
57
|
+
const blockers = /* @__PURE__ */ new Map();
|
|
58
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
59
|
+
const duplicates = /* @__PURE__ */ new Map();
|
|
60
|
+
const fieldValues = (number) => Object.entries(metadata.get(number) ?? {}).map(([id, value]) => ({
|
|
61
|
+
data_type: Number(id) >= 103 ? "date" : "single_select",
|
|
62
|
+
issue_field_id: Number(id),
|
|
63
|
+
issue_field_name: id === "101" ? "Estimate" : id === "102" ? "Urgency" : id === "103" ? "Start date" : "Target date",
|
|
64
|
+
value
|
|
65
|
+
}));
|
|
66
|
+
const comments = [];
|
|
67
|
+
const statuses = new Map(Array.from(rows.keys(), (number) => [number, "Active"]));
|
|
68
|
+
const statusOptionIds = {
|
|
69
|
+
"In Review": "REVIEW",
|
|
70
|
+
Active: "ACTIVE",
|
|
71
|
+
Shipped: "DONE",
|
|
72
|
+
Waiting: "BLOCKED"
|
|
73
|
+
};
|
|
74
|
+
const context = {
|
|
75
|
+
root: "/synthetic",
|
|
76
|
+
repo: { owner: "example", repo: "widget" },
|
|
77
|
+
config: syntheticDiscoveryConfig,
|
|
78
|
+
projectConfiguration: {
|
|
79
|
+
projectId: "PROJECT",
|
|
80
|
+
projectNumber: 1,
|
|
81
|
+
title: "Delivery",
|
|
82
|
+
writable: true,
|
|
83
|
+
pointsFieldId: "POINTS",
|
|
84
|
+
priorityFieldId: "PRIORITY",
|
|
85
|
+
statusFieldId: "STATUS",
|
|
86
|
+
statusOptionIds: { Todo: "TODO", "In Progress": "ACTIVE", Blocked: "BLOCKED", Done: "DONE" },
|
|
87
|
+
reviewOptionId: "REVIEW",
|
|
88
|
+
settings: {
|
|
89
|
+
number: 1,
|
|
90
|
+
title: "Delivery",
|
|
91
|
+
statusField: "Flow",
|
|
92
|
+
statuses: { Todo: "Queued", "In Progress": "Active", Blocked: "Waiting", Done: "Shipped" }
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
clients: {
|
|
96
|
+
role: "author",
|
|
97
|
+
authenticatedAuthor: async () => ({ actorLogin: "operator", credentialIdentity: "user:1" }),
|
|
98
|
+
rest: {
|
|
99
|
+
issues: {
|
|
100
|
+
get: async ({ issue_number }) => {
|
|
101
|
+
if (controls.nativeUnavailableAfterDependency && writes.includes("dependency"))
|
|
102
|
+
throw new Error("PRIVATE_NATIVE_READ_FAILURE");
|
|
103
|
+
reads.set(issue_number, (reads.get(issue_number) ?? 0) + 1);
|
|
104
|
+
if (controls.failReadback === issue_number && writes.includes(`update:${issue_number}`))
|
|
105
|
+
throw new Error("Synthetic readback transport failure");
|
|
106
|
+
const row = rows.get(issue_number);
|
|
107
|
+
if (row && controls.driftOnRead === issue_number && reads.get(issue_number) === 2)
|
|
108
|
+
row.body = "Concurrent operator edit";
|
|
109
|
+
if (!row) throw new Error("Synthetic issue unavailable");
|
|
110
|
+
return { data: structuredClone(row) };
|
|
111
|
+
},
|
|
112
|
+
listComments: async ({ issue_number }) => ({
|
|
113
|
+
data: comments.filter((comment) => comment.issue_url.endsWith("/" + String(issue_number)))
|
|
114
|
+
}),
|
|
115
|
+
listLabelsForRepo: async () => ({ data: [{ name: "enhancement" }] }),
|
|
116
|
+
listSubIssues: async () => ({ data: [] }),
|
|
117
|
+
addSubIssue: async ({ issue_number, sub_issue_id }) => {
|
|
118
|
+
writes.push("parent");
|
|
119
|
+
parents.set(sub_issue_id - 100, issue_number);
|
|
120
|
+
return { data: {} };
|
|
121
|
+
},
|
|
122
|
+
removeSubIssue: async ({ sub_issue_id }) => {
|
|
123
|
+
writes.push("parent");
|
|
124
|
+
parents.delete(sub_issue_id - 100);
|
|
125
|
+
return { data: {} };
|
|
126
|
+
},
|
|
127
|
+
createComment: async ({ issue_number, body }) => {
|
|
128
|
+
writes.push("comment");
|
|
129
|
+
const comment = {
|
|
130
|
+
id: comments.length + 1e3,
|
|
131
|
+
body,
|
|
132
|
+
html_url: `https://github.com/example/widget/issues/${issue_number}#issuecomment-${comments.length + 1e3}`,
|
|
133
|
+
user: { login: "operator" },
|
|
134
|
+
issue_url: `https://api.github.com/repos/example/widget/issues/${issue_number}`
|
|
135
|
+
};
|
|
136
|
+
comments.push(comment);
|
|
137
|
+
return { data: comment };
|
|
138
|
+
},
|
|
139
|
+
getComment: async ({ comment_id }) => ({
|
|
140
|
+
data: comments.find((comment) => comment.id === comment_id)
|
|
141
|
+
}),
|
|
142
|
+
update: async ({ issue_number, ...patch }) => {
|
|
143
|
+
writes.push(`update:${issue_number}`);
|
|
144
|
+
if (controls.moveProjectToTodoAfterWrite) statuses.set(issue_number, "Queued");
|
|
145
|
+
if (controls.archiveAfterWrite) controls.archived = true;
|
|
146
|
+
if (controls.rateLimited === issue_number)
|
|
147
|
+
throw Object.assign(new Error("PRIVATE_REMOTE_CONTENT"), {
|
|
148
|
+
status: 429,
|
|
149
|
+
response: {
|
|
150
|
+
headers: {
|
|
151
|
+
"retry-after": "60",
|
|
152
|
+
"x-ratelimit-remaining": "0",
|
|
153
|
+
"x-ratelimit-reset": "1900000000",
|
|
154
|
+
authorization: "PRIVATE_TOKEN"
|
|
155
|
+
}
|
|
311
156
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
157
|
+
});
|
|
158
|
+
const row = rows.get(issue_number);
|
|
159
|
+
if (typeof patch.title === "string") row.title = patch.title;
|
|
160
|
+
if (typeof patch.body === "string") row.body = patch.body;
|
|
161
|
+
if (typeof patch.type === "string") row.type = { name: patch.type };
|
|
162
|
+
if (Array.isArray(patch.labels) && !controls.ignoreLabels)
|
|
163
|
+
row.labels = patch.labels.map((label) => label.toLowerCase());
|
|
164
|
+
if (patch.milestone !== void 0)
|
|
165
|
+
Object.assign(row, { milestone: patch.milestone === null ? null : { number: patch.milestone } });
|
|
166
|
+
if (typeof patch.state === "string") {
|
|
167
|
+
row.state = patch.state;
|
|
168
|
+
reasons.set(
|
|
169
|
+
issue_number,
|
|
170
|
+
patch.state === "closed" ? (typeof patch.state_reason === "string" ? patch.state_reason : "completed").toUpperCase() : "REOPENED"
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (typeof patch.duplicate_issue_id === "number")
|
|
174
|
+
duplicates.set(issue_number, patch.duplicate_issue_id - 100);
|
|
175
|
+
if (controls.failAfterWrite === issue_number) {
|
|
176
|
+
controls.failAfterWrite = 0;
|
|
177
|
+
throw new Error("Synthetic acknowledgement lost");
|
|
178
|
+
}
|
|
179
|
+
return { data: rows.get(issue_number) };
|
|
180
|
+
}
|
|
333
181
|
},
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
182
|
+
paginate: async (_method, { issue_number }) => [...parents].filter(([, parent]) => parent === issue_number).map(([number]) => rows.get(number)),
|
|
183
|
+
request: async (route, params) => {
|
|
184
|
+
if (route.startsWith("GET /orgs"))
|
|
185
|
+
return {
|
|
186
|
+
data: [
|
|
187
|
+
...Object.values(syntheticDiscoveryConfig.native).filter(
|
|
188
|
+
(field) => typeof field === "object" && field !== null && "databaseId" in field
|
|
189
|
+
).map((field) => ({
|
|
190
|
+
id: Number(field.databaseId),
|
|
191
|
+
name: field.name,
|
|
192
|
+
data_type: "single_select",
|
|
193
|
+
options: field.values.map((name) => ({ name }))
|
|
194
|
+
})),
|
|
195
|
+
{ id: 103, name: "Start date", data_type: "date" },
|
|
196
|
+
{ id: 104, name: "Target date", data_type: "date" }
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
if (route.startsWith("POST ")) {
|
|
200
|
+
const dates = params.issue_field_values.filter((value) => value.field_id >= 103);
|
|
201
|
+
if (dates.length) dateWrites.push(dates.map((value) => value.field_id));
|
|
202
|
+
writes.push("metadata");
|
|
203
|
+
metadata.set(params.issue_number, {
|
|
204
|
+
...metadata.get(params.issue_number),
|
|
205
|
+
...Object.fromEntries(params.issue_field_values.map((value) => [String(value.field_id), value.value]))
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (route.startsWith("DELETE ")) {
|
|
209
|
+
if (params.issue_field_id >= 103) dateWrites.push([params.issue_field_id]);
|
|
210
|
+
writes.push("metadata");
|
|
211
|
+
delete metadata.get(params.issue_number)[String(params.issue_field_id)];
|
|
212
|
+
}
|
|
213
|
+
return { data: fieldValues(params.issue_number) };
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
graphql: async (query, variables) => {
|
|
217
|
+
if (controls.moveProjectToTodoAfterWrite && writes.includes("update:1") && query.includes("ProjectDeliveryIssueItems") && ++controls.projectReadsAfterWrite === 2)
|
|
218
|
+
throw new Error("PRIVATE_SYNC_READ_FAILURE");
|
|
219
|
+
if (controls.projectUnavailableAfterDependency && writes.includes("dependency") && query.includes("ProjectDelivery"))
|
|
220
|
+
throw new Error("PRIVATE_PROJECT_READ_FAILURE");
|
|
221
|
+
const numeric = variables.number ?? variables.issueNumber;
|
|
222
|
+
const nodeId = variables.issueNodeId ?? variables.itemId ?? "1";
|
|
223
|
+
const number = typeof numeric === "number" ? numeric : typeof nodeId === "string" ? Number(nodeId.replace(/\D/gu, "")) : NaN;
|
|
224
|
+
if (query.includes("IssueClosureReadback"))
|
|
225
|
+
return {
|
|
226
|
+
repository: {
|
|
227
|
+
issue: {
|
|
228
|
+
number,
|
|
229
|
+
repository: { nameWithOwner: "example/widget" },
|
|
230
|
+
state: rows.get(number).state.toUpperCase(),
|
|
231
|
+
stateReason: reasons.get(number) ?? null,
|
|
232
|
+
duplicateOf: duplicates.has(number) ? { number: duplicates.get(number), repository: { nameWithOwner: "example/widget" } } : null
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
if (query.includes("blockedBy(first:"))
|
|
237
|
+
return {
|
|
238
|
+
repository: {
|
|
239
|
+
issue: {
|
|
240
|
+
parent: parents.has(number) ? {
|
|
241
|
+
id: controls.parentNodeId || `ISSUE${parents.get(number)}`,
|
|
242
|
+
number: parents.get(number),
|
|
243
|
+
repository: { nameWithOwner: controls.parentRepository }
|
|
244
|
+
} : null,
|
|
245
|
+
blockedBy: {
|
|
246
|
+
nodes: (blockers.get(number) ?? []).map((n) => ({
|
|
247
|
+
id: `ISSUE${n}`,
|
|
248
|
+
number: n,
|
|
249
|
+
state: rows.get(n).state.toUpperCase(),
|
|
250
|
+
title: rows.get(n).title,
|
|
251
|
+
repository: { nameWithOwner: "example/widget" }
|
|
252
|
+
})),
|
|
253
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
if (query.includes("mutation") && (query.includes("addBlockedBy") || query.includes("removeBlockedBy"))) {
|
|
259
|
+
writes.push("dependency");
|
|
260
|
+
const dependent = Number(String(variables.issue).replace(/\D/gu, ""));
|
|
261
|
+
const blocker = Number(String(variables.blocking).replace(/\D/gu, ""));
|
|
262
|
+
blockers.set(
|
|
263
|
+
dependent,
|
|
264
|
+
query.includes("addBlockedBy") ? [.../* @__PURE__ */ new Set([...blockers.get(dependent) ?? [], blocker])] : (blockers.get(dependent) ?? []).filter((n) => n !== blocker)
|
|
265
|
+
);
|
|
266
|
+
return {};
|
|
267
|
+
}
|
|
268
|
+
if (query.includes("ProjectDeliveryIssueItems"))
|
|
269
|
+
return issueProjectItemsResponse(
|
|
270
|
+
variables,
|
|
271
|
+
[...rows.keys()].filter((n) => `ISSUE${n}` === variables.issueNodeId).map((n) => ({
|
|
272
|
+
id: `ITEM${n}`,
|
|
273
|
+
isArchived: controls.archived,
|
|
274
|
+
content: { id: `ISSUE${n}` },
|
|
275
|
+
fieldValueByName: {
|
|
276
|
+
name: statuses.get(n),
|
|
277
|
+
optionId: statusOptionIds[statuses.get(n)] ?? "TODO"
|
|
278
|
+
}
|
|
279
|
+
}))
|
|
280
|
+
);
|
|
281
|
+
if (query.includes("UpdateProjectDeliveryStatus")) {
|
|
282
|
+
writes.push("project");
|
|
283
|
+
statuses.set(
|
|
284
|
+
number,
|
|
285
|
+
variables.optionId === "DONE" ? "Shipped" : variables.optionId === "BLOCKED" ? "Waiting" : variables.optionId === "ACTIVE" ? "Active" : "Queued"
|
|
286
|
+
);
|
|
287
|
+
if (controls.loseProjectAck) {
|
|
288
|
+
controls.loseProjectAck = false;
|
|
289
|
+
throw new Error("PRIVATE_PROJECT_ACK");
|
|
290
|
+
}
|
|
291
|
+
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: `ITEM${number}` } } };
|
|
292
|
+
}
|
|
293
|
+
if (query.includes("ProjectDeliveryItemReadback"))
|
|
294
|
+
return {
|
|
295
|
+
node: {
|
|
296
|
+
id: `ITEM${number}`,
|
|
297
|
+
isArchived: false,
|
|
298
|
+
project: { id: "PROJECT", number: 1 },
|
|
299
|
+
content: { id: `ISSUE${number}` },
|
|
300
|
+
fieldValueByName: {
|
|
301
|
+
name: statuses.get(number),
|
|
302
|
+
optionId: statusOptionIds[statuses.get(number)] ?? "TODO"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
throw new Error("Unexpected synthetic native query");
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
vi.spyOn(configuration, "loadDeliverySettings").mockResolvedValue({
|
|
311
|
+
roles: { author: { identity: "host-author", authSource: "personal" }, reviewer: { identity: "app-reviewer" } }
|
|
312
|
+
});
|
|
313
|
+
vi.spyOn(issue, "loadDeliveryContext").mockResolvedValue(context);
|
|
314
|
+
return { context, rows, writes, dateWrites, comments, controls, metadata, parents, blockers, statuses };
|
|
340
315
|
}
|
|
341
316
|
afterEach(() => vi.restoreAllMocks());
|
|
342
|
-
test(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
317
|
+
test("batch dry run returns each planned title change without native writes", async () => {
|
|
318
|
+
const f = batchFixture();
|
|
319
|
+
const result = await executeTool(
|
|
320
|
+
"issue_batch_update",
|
|
321
|
+
{
|
|
322
|
+
repo: "example/widget",
|
|
323
|
+
dryRun: true,
|
|
324
|
+
items: [
|
|
325
|
+
{ issueNumber: 1, title: "First requested title" },
|
|
326
|
+
{ issueNumber: 2, title: "Second requested title" }
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
{ repoRoot: "/synthetic", identity: "host-author" }
|
|
330
|
+
);
|
|
331
|
+
assert.equal(result.dryRun, true);
|
|
332
|
+
assert.deepEqual(
|
|
333
|
+
result.results.map((item) => [item.issueNumber, item.changes.title, item.readback.title]),
|
|
334
|
+
[
|
|
335
|
+
[1, "First requested title", "Synthetic item 1"],
|
|
336
|
+
[2, "Second requested title", "Synthetic item 2"]
|
|
337
|
+
]
|
|
338
|
+
);
|
|
339
|
+
assert.deepEqual(f.writes, []);
|
|
340
|
+
assert.equal(f.rows.get(1).title, "Synthetic item 1");
|
|
359
341
|
});
|
|
360
342
|
async function runBatch(input) {
|
|
361
|
-
|
|
343
|
+
return executeTool(
|
|
344
|
+
"issue_batch_update",
|
|
345
|
+
{ repo: "example/widget", ...input },
|
|
346
|
+
{ repoRoot: "/synthetic", identity: "host-author" }
|
|
347
|
+
);
|
|
362
348
|
}
|
|
363
|
-
test.each([{}, { status: { nextMilestone:
|
|
364
|
-
|
|
349
|
+
test.each([{}, { status: { nextMilestone: "Run checks" } }, { blockedBy: [2] }])(
|
|
350
|
+
"canonical-body retries with overrides %j preserve generated timestamps and history",
|
|
351
|
+
async (overrides) => {
|
|
352
|
+
const clock = vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-10-17T00:00:00.000Z"));
|
|
365
353
|
const f = batchFixture();
|
|
366
|
-
const body = renderIssueBody(
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
354
|
+
const body = renderIssueBody(
|
|
355
|
+
IssueFields.parse({ title: "Synthetic item 1", draft: true, problem: "Changed contract" }),
|
|
356
|
+
{
|
|
357
|
+
state: "Draft",
|
|
358
|
+
lastUpdated: "2026-01-01T00:00:00.000Z",
|
|
359
|
+
nextMilestone: "Not started",
|
|
360
|
+
blockers: "None",
|
|
361
|
+
latestJournal: "None yet"
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
f.statuses.set(1, "Queued");
|
|
374
365
|
const input = { items: [{ issueNumber: 1, body, preserveHistory: true, ...overrides }] };
|
|
375
366
|
const first = await runBatch(input);
|
|
376
|
-
assert.equal(first.results[0].status,
|
|
367
|
+
assert.equal(first.results[0].status, "applied", JSON.stringify(first));
|
|
377
368
|
const writtenBody = f.rows.get(1).body;
|
|
378
369
|
const writes = [...f.writes];
|
|
379
370
|
const comments = [...f.comments];
|
|
380
|
-
clock.mockReturnValue(Date.parse(
|
|
371
|
+
clock.mockReturnValue(Date.parse("2026-10-17T00:01:00.000Z"));
|
|
381
372
|
const retry = await runBatch(input);
|
|
382
|
-
assert.equal(retry.results[0].status,
|
|
373
|
+
assert.equal(retry.results[0].status, "unchanged", JSON.stringify(retry));
|
|
383
374
|
assert.equal(f.rows.get(1).body, writtenBody);
|
|
384
375
|
assert.deepEqual(f.writes, writes);
|
|
385
376
|
assert.deepEqual(f.comments, comments);
|
|
386
|
-
clock.mockReturnValue(Date.parse(
|
|
387
|
-
assert.equal((await runBatch(input)).results[0].status,
|
|
377
|
+
clock.mockReturnValue(Date.parse("2026-10-17T00:02:00.000Z"));
|
|
378
|
+
assert.equal((await runBatch(input)).results[0].status, "unchanged");
|
|
388
379
|
assert.deepEqual(f.writes, writes);
|
|
389
380
|
assert.deepEqual(f.comments, comments);
|
|
390
|
-
}
|
|
381
|
+
}
|
|
382
|
+
);
|
|
391
383
|
test.each([
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
])(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
384
|
+
["foreign/repository", "FOREIGN5"],
|
|
385
|
+
["example/widget", "DIFFERENT5"]
|
|
386
|
+
])("same-number parent in %s with node %s cannot satisfy a batch retry", async (repository, nodeId) => {
|
|
387
|
+
const f = batchFixture();
|
|
388
|
+
const input = { items: [{ issueNumber: 1, parentIssueNumber: 5 }] };
|
|
389
|
+
assert.equal((await runBatch(input)).results[0].status, "applied");
|
|
390
|
+
const writes = [...f.writes];
|
|
391
|
+
f.controls.parentRepository = repository;
|
|
392
|
+
f.controls.parentNodeId = nodeId;
|
|
393
|
+
const result = await runBatch(input);
|
|
394
|
+
assert.equal(result.results[0].status, "failed", JSON.stringify(result));
|
|
395
|
+
assert.deepEqual(f.writes, writes);
|
|
404
396
|
});
|
|
405
|
-
test(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
397
|
+
test("correctable local batch refusals retain distinct bounded reasons", async () => {
|
|
398
|
+
const f = batchFixture();
|
|
399
|
+
const result = await runBatch({
|
|
400
|
+
items: [
|
|
401
|
+
{ issueNumber: 1, priority: "Unsupported" },
|
|
402
|
+
{ issueNumber: 2, labels: ["unknown-label-private-content"] },
|
|
403
|
+
{ issueNumber: 3, blocks: [4] }
|
|
404
|
+
]
|
|
405
|
+
});
|
|
406
|
+
assert.deepEqual(
|
|
407
|
+
result.results.map((item) => item.status),
|
|
408
|
+
["failed", "failed", "failed"]
|
|
409
|
+
);
|
|
410
|
+
assert.match(result.results[0].reason, /configured Priority/u);
|
|
411
|
+
assert.match(result.results[1].reason, /labels.*selected repository/u);
|
|
412
|
+
assert.match(result.results[2].reason, /overrideReason/u);
|
|
413
|
+
assert.equal(JSON.stringify(result).includes("unknown-label-private-content"), false);
|
|
414
|
+
assert.deepEqual(f.writes, []);
|
|
420
415
|
});
|
|
421
|
-
test(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
416
|
+
test("a conflicting closure reason explains the required explicit reopen without more writes", async () => {
|
|
417
|
+
const f = batchFixture();
|
|
418
|
+
assert.equal(
|
|
419
|
+
(await runBatch({ items: [{ issueNumber: 1, state: "closed", closeReason: "not_planned" }] })).results[0].status,
|
|
420
|
+
"applied"
|
|
421
|
+
);
|
|
422
|
+
const writes = [...f.writes];
|
|
423
|
+
const comments = [...f.comments];
|
|
424
|
+
const result = await runBatch({ items: [{ issueNumber: 1, state: "closed", closeReason: "completed" }] });
|
|
425
|
+
assert.equal(result.results[0].status, "failed");
|
|
426
|
+
assert.match(result.results[0].reason, /different closure evidence; reopen it explicitly/u);
|
|
427
|
+
assert.deepEqual(f.writes, writes);
|
|
428
|
+
assert.deepEqual(f.comments, comments);
|
|
431
429
|
});
|
|
432
|
-
test(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
},
|
|
440
|
-
});
|
|
441
|
-
const proxy = new Proxy(new DeliveryError('PRIVATE_PROXY_CONTENT'), {
|
|
442
|
-
get() {
|
|
443
|
-
inspected++;
|
|
444
|
-
throw new Error('PRIVATE_PROXY_CONTENT');
|
|
445
|
-
},
|
|
446
|
-
getPrototypeOf() {
|
|
447
|
-
inspected++;
|
|
448
|
-
throw new Error('PRIVATE_PROXY_CONTENT');
|
|
449
|
-
},
|
|
450
|
-
});
|
|
451
|
-
const get = vi.spyOn(f.context.clients.rest.issues, 'get');
|
|
452
|
-
for (const error of [new DeliveryError('PRIVATE_REMOTE_CONTENT'), getter, proxy]) {
|
|
453
|
-
get.mockRejectedValue(error);
|
|
454
|
-
const result = await runBatch({ items: [{ issueNumber: 1, title: 'Requested update' }] });
|
|
455
|
-
assert.equal(result.results[0].status, 'failed');
|
|
456
|
-
assert.match(result.results[0].reason, /preparation failed/u);
|
|
457
|
-
assert.equal(JSON.stringify(result).includes('PRIVATE_'), false);
|
|
430
|
+
test("unknown remote errors, message getters and proxies retain the generic safe batch failure", async () => {
|
|
431
|
+
const f = batchFixture();
|
|
432
|
+
let inspected = 0;
|
|
433
|
+
const getter = Object.defineProperty(new DeliveryError(""), "message", {
|
|
434
|
+
get() {
|
|
435
|
+
inspected++;
|
|
436
|
+
throw new Error("PRIVATE_GETTER_CONTENT");
|
|
458
437
|
}
|
|
459
|
-
|
|
460
|
-
|
|
438
|
+
});
|
|
439
|
+
const proxy = new Proxy(new DeliveryError("PRIVATE_PROXY_CONTENT"), {
|
|
440
|
+
get() {
|
|
441
|
+
inspected++;
|
|
442
|
+
throw new Error("PRIVATE_PROXY_CONTENT");
|
|
443
|
+
},
|
|
444
|
+
getPrototypeOf() {
|
|
445
|
+
inspected++;
|
|
446
|
+
throw new Error("PRIVATE_PROXY_CONTENT");
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
const get = vi.spyOn(f.context.clients.rest.issues, "get");
|
|
450
|
+
for (const error of [new DeliveryError("PRIVATE_REMOTE_CONTENT"), getter, proxy]) {
|
|
451
|
+
get.mockRejectedValue(error);
|
|
452
|
+
const result = await runBatch({ items: [{ issueNumber: 1, title: "Requested update" }] });
|
|
453
|
+
assert.equal(result.results[0].status, "failed");
|
|
454
|
+
assert.match(result.results[0].reason, /preparation failed/u);
|
|
455
|
+
assert.equal(JSON.stringify(result).includes("PRIVATE_"), false);
|
|
456
|
+
}
|
|
457
|
+
assert.equal(inspected, 0);
|
|
458
|
+
assert.deepEqual(f.writes, []);
|
|
461
459
|
});
|
|
462
|
-
test(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
460
|
+
test("mixed failures retain later results and a rerun reports unchanged native outcomes", async () => {
|
|
461
|
+
const f = batchFixture();
|
|
462
|
+
const input = {
|
|
463
|
+
items: [
|
|
464
|
+
{ issueNumber: 1, title: "Changed title" },
|
|
465
|
+
{ issueNumber: 99, title: "Missing target" },
|
|
466
|
+
{ issueNumber: 2, defer: { trigger: "Review next sprint" } }
|
|
467
|
+
]
|
|
468
|
+
};
|
|
469
|
+
const first = await runBatch(input);
|
|
470
|
+
assert.deepEqual(
|
|
471
|
+
first.results.map((item) => item.status),
|
|
472
|
+
["applied", "failed", "applied"]
|
|
473
|
+
);
|
|
474
|
+
assert.equal(first.results[0].readback.title, "Changed title");
|
|
475
|
+
assert.match(first.results[1].reason, /preparation failed/u);
|
|
476
|
+
assert.match(first.results[1].readbackError, /unavailable/u);
|
|
477
|
+
assert.deepEqual(first.results[2].readback.deferred, { trigger: "Review next sprint" });
|
|
478
|
+
const writes = f.writes.length;
|
|
479
|
+
const second = await runBatch(input);
|
|
480
|
+
assert.deepEqual(
|
|
481
|
+
second.results.map((item) => item.status),
|
|
482
|
+
["unchanged", "failed", "unchanged"]
|
|
483
|
+
);
|
|
484
|
+
assert.equal(f.writes.length, writes);
|
|
481
485
|
});
|
|
482
|
-
test(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
486
|
+
test("lost acknowledgement exposes partial state and a rerun completes remaining Project work", async () => {
|
|
487
|
+
const f = batchFixture();
|
|
488
|
+
f.controls.failAfterWrite = 1;
|
|
489
|
+
const input = {
|
|
490
|
+
items: [
|
|
491
|
+
{ issueNumber: 1, title: "Acknowledgement lost", preserveHistory: true },
|
|
492
|
+
{ issueNumber: 2, title: "Later item proceeds" }
|
|
493
|
+
]
|
|
494
|
+
};
|
|
495
|
+
const first = await runBatch(input);
|
|
496
|
+
assert.deepEqual(
|
|
497
|
+
first.results.map((item) => item.status),
|
|
498
|
+
["failed", "applied"]
|
|
499
|
+
);
|
|
500
|
+
assert.equal(first.results[0].readback.title, "Acknowledgement lost");
|
|
501
|
+
assert.equal(first.results[0].readback.projectStatus, "In Progress");
|
|
502
|
+
const historyCount = f.comments.length;
|
|
503
|
+
const second = await runBatch(input);
|
|
504
|
+
assert.deepEqual(
|
|
505
|
+
second.results.map((item) => item.status),
|
|
506
|
+
["applied", "unchanged"]
|
|
507
|
+
);
|
|
508
|
+
assert.equal(second.results[0].readback.projectStatus, "Todo");
|
|
509
|
+
assert.equal(f.comments.length, historyCount);
|
|
510
|
+
assert.equal(
|
|
511
|
+
f.writes.filter((write) => write.startsWith("update:1")).length,
|
|
512
|
+
1,
|
|
513
|
+
"recovery must not replay the committed native update"
|
|
514
|
+
);
|
|
515
|
+
assert.deepEqual(
|
|
516
|
+
(await runBatch(input)).results.map((item) => item.status),
|
|
517
|
+
["unchanged", "unchanged"]
|
|
518
|
+
);
|
|
502
519
|
});
|
|
503
|
-
test(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
520
|
+
test("archived partial closure resumes only Project work after separate restoration and then becomes a no-op", async () => {
|
|
521
|
+
const f = batchFixture();
|
|
522
|
+
const unrelated = structuredClone(f.rows.get(2));
|
|
523
|
+
f.rows.get(1).labels.push("enhancement");
|
|
524
|
+
f.controls.archiveAfterWrite = true;
|
|
525
|
+
const input = {
|
|
526
|
+
items: [
|
|
527
|
+
{
|
|
528
|
+
issueNumber: 1,
|
|
529
|
+
title: "Closed item",
|
|
530
|
+
state: "closed",
|
|
531
|
+
closeReason: "not_planned",
|
|
532
|
+
preserveHistory: true
|
|
533
|
+
}
|
|
534
|
+
]
|
|
535
|
+
};
|
|
536
|
+
const first = await runBatch(input);
|
|
537
|
+
assert.equal(first.summary.failed, 1);
|
|
538
|
+
assert.equal(f.rows.get(1).state, "closed");
|
|
539
|
+
const nativeWrites = f.writes.filter((write) => write !== "project");
|
|
540
|
+
const comments = structuredClone(f.comments);
|
|
541
|
+
const archived = await runBatch(input);
|
|
542
|
+
assert.equal(archived.summary.failed, 1);
|
|
543
|
+
assert.deepEqual(
|
|
544
|
+
f.writes.filter((write) => write !== "project"),
|
|
545
|
+
nativeWrites
|
|
546
|
+
);
|
|
547
|
+
assert.deepEqual(f.comments, comments);
|
|
548
|
+
f.controls.archiveAfterWrite = false;
|
|
549
|
+
f.controls.archived = false;
|
|
550
|
+
const resumed = await runBatch(input);
|
|
551
|
+
assert.equal(resumed.summary.applied, 1);
|
|
552
|
+
assert.equal(resumed.results[0].readback.projectStatus, "Done");
|
|
553
|
+
assert.deepEqual(
|
|
554
|
+
f.writes.filter((write) => write !== "project"),
|
|
555
|
+
nativeWrites
|
|
556
|
+
);
|
|
557
|
+
assert.deepEqual(f.comments, comments);
|
|
558
|
+
const count = f.writes.length;
|
|
559
|
+
assert.equal((await runBatch(input)).summary.unchanged, 1);
|
|
560
|
+
assert.equal(f.writes.length, count);
|
|
561
|
+
assert.deepEqual(f.rows.get(1).labels, ["enhancement"]);
|
|
562
|
+
assert.deepEqual(f.rows.get(2), unrelated);
|
|
540
563
|
});
|
|
541
|
-
test(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
f.
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
564
|
+
test("archived date and parent updates resume only Project work without replaying committed native fields", async () => {
|
|
565
|
+
const f = batchFixture();
|
|
566
|
+
f.metadata.set(1, { "104": "2028-03-31" });
|
|
567
|
+
f.controls.archiveAfterWrite = true;
|
|
568
|
+
const input = {
|
|
569
|
+
items: [
|
|
570
|
+
{
|
|
571
|
+
issueNumber: 1,
|
|
572
|
+
title: "Dated item",
|
|
573
|
+
startDate: "2028-02-29",
|
|
574
|
+
targetDate: null,
|
|
575
|
+
parentIssueNumber: 5,
|
|
576
|
+
preserveHistory: true
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
};
|
|
580
|
+
const first = await runBatch(input);
|
|
581
|
+
assert.equal(first.summary.failed, 1);
|
|
582
|
+
assert.equal(first.results[0].incomplete?.native.status, "confirmed");
|
|
583
|
+
assert.equal(first.results[0].incomplete?.native.readback?.startDate, "2028-02-29");
|
|
584
|
+
assert.equal(first.results[0].incomplete?.native.readback?.targetDate, null);
|
|
585
|
+
const nativeWrites = f.writes.filter((write) => write !== "project");
|
|
586
|
+
const comments = structuredClone(f.comments);
|
|
587
|
+
assert.equal((await runBatch(input)).summary.failed, 1);
|
|
588
|
+
assert.deepEqual(
|
|
589
|
+
f.writes.filter((write) => write !== "project"),
|
|
590
|
+
nativeWrites
|
|
591
|
+
);
|
|
592
|
+
f.controls.archiveAfterWrite = false;
|
|
593
|
+
f.controls.archived = false;
|
|
594
|
+
const resumed = await runBatch(input);
|
|
595
|
+
assert.equal(resumed.summary.applied, 1);
|
|
596
|
+
assert.deepEqual(
|
|
597
|
+
f.writes.filter((write) => write !== "project"),
|
|
598
|
+
nativeWrites
|
|
599
|
+
);
|
|
600
|
+
assert.deepEqual(f.comments, comments);
|
|
601
|
+
assert.deepEqual(f.dateWrites, [[103], [104]]);
|
|
602
|
+
assert.equal(f.parents.get(1), 5);
|
|
603
|
+
assert.equal((await runBatch(input)).summary.unchanged, 1);
|
|
575
604
|
});
|
|
576
605
|
for (const [committedId, pendingId] of [
|
|
577
|
-
|
|
578
|
-
|
|
606
|
+
[103, 104],
|
|
607
|
+
[104, 103]
|
|
579
608
|
]) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
assert.equal(first.summary.applied, 1);
|
|
593
|
-
assert.deepEqual(f.dateWrites, [[pendingId]]);
|
|
594
|
-
assert.equal(f.metadata.get(1)[String(committedId)], '2028-02-29');
|
|
595
|
-
assert.equal(f.metadata.get(1)[String(pendingId)], undefined);
|
|
609
|
+
test(`mixed date retry writes only pending field ${pendingId} and preserves committed field ${committedId}`, async () => {
|
|
610
|
+
const f = batchFixture();
|
|
611
|
+
f.metadata.set(1, { [committedId]: "2028-02-29", [pendingId]: "2028-03-31" });
|
|
612
|
+
const first = await runBatch({
|
|
613
|
+
items: [
|
|
614
|
+
{
|
|
615
|
+
issueNumber: 1,
|
|
616
|
+
startDate: committedId === 103 ? "2028-02-29" : null,
|
|
617
|
+
targetDate: committedId === 104 ? "2028-02-29" : null
|
|
618
|
+
}
|
|
619
|
+
]
|
|
596
620
|
});
|
|
621
|
+
assert.equal(first.summary.applied, 1);
|
|
622
|
+
assert.deepEqual(f.dateWrites, [[pendingId]]);
|
|
623
|
+
assert.equal(f.metadata.get(1)[String(committedId)], "2028-02-29");
|
|
624
|
+
assert.equal(f.metadata.get(1)[String(pendingId)], void 0);
|
|
625
|
+
});
|
|
597
626
|
}
|
|
598
|
-
test(
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
627
|
+
test("lost Project acknowledgement is incomplete until a read-only batch reconciliation proves a no-op", async () => {
|
|
628
|
+
const f = batchFixture();
|
|
629
|
+
f.controls.loseProjectAck = true;
|
|
630
|
+
const input = { items: [{ issueNumber: 1, state: "closed", closeReason: "completed" }] };
|
|
631
|
+
const first = await runBatch(input);
|
|
632
|
+
assert.equal(first.summary.failed, 1);
|
|
633
|
+
assert.equal(first.results[0].incomplete?.native.status, "confirmed");
|
|
634
|
+
assert.equal(first.results[0].incomplete?.project.status, "unknown");
|
|
635
|
+
assert.equal(JSON.stringify(first).includes("PRIVATE_"), false);
|
|
636
|
+
const writes = [...f.writes];
|
|
637
|
+
const comments = structuredClone(f.comments);
|
|
638
|
+
assert.equal((await runBatch(input)).summary.unchanged, 1);
|
|
639
|
+
assert.deepEqual(f.writes, writes);
|
|
640
|
+
assert.deepEqual(f.comments, comments);
|
|
612
641
|
});
|
|
613
|
-
test.each([
|
|
642
|
+
test.each(["add", "remove"])(
|
|
643
|
+
"remaining Project target reflects the committed %s blocker change after Project reads fail",
|
|
644
|
+
async (action) => {
|
|
614
645
|
const f = batchFixture();
|
|
615
646
|
f.controls.projectUnavailableAfterDependency = true;
|
|
616
|
-
f.statuses.set(1, action ===
|
|
617
|
-
if (action ===
|
|
618
|
-
|
|
619
|
-
const blockers = action === 'remove' ? [] : [2];
|
|
647
|
+
f.statuses.set(1, action === "remove" ? "Waiting" : "Queued");
|
|
648
|
+
if (action === "remove") f.blockers.set(1, [2]);
|
|
649
|
+
const blockers = action === "remove" ? [] : [2];
|
|
620
650
|
const first = await runBatch({ items: [{ issueNumber: 1, blockedBy: blockers }] });
|
|
621
651
|
const partial = first.results[0].incomplete;
|
|
622
652
|
assert.equal(first.summary.failed, 1);
|
|
623
|
-
assert.equal(partial?.native.status,
|
|
653
|
+
assert.equal(partial?.native.status, "confirmed");
|
|
624
654
|
assert.deepEqual(partial?.native.readback?.blockedBy, blockers);
|
|
625
|
-
assert.equal(partial?.project.desiredStatus, action ===
|
|
626
|
-
assert.equal(JSON.stringify(first).includes(
|
|
627
|
-
const nativeWrites = f.writes.filter((write) => write !==
|
|
655
|
+
assert.equal(partial?.project.desiredStatus, action === "remove" ? "Todo" : "Blocked");
|
|
656
|
+
assert.equal(JSON.stringify(first).includes("PRIVATE_"), false);
|
|
657
|
+
const nativeWrites = f.writes.filter((write) => write !== "project");
|
|
628
658
|
f.controls.projectUnavailableAfterDependency = false;
|
|
629
659
|
assert.equal((await runBatch({ items: [{ issueNumber: 1, blockedBy: blockers }] })).summary.applied, 1);
|
|
630
|
-
assert.deepEqual(
|
|
660
|
+
assert.deepEqual(
|
|
661
|
+
f.writes.filter((write) => write !== "project"),
|
|
662
|
+
nativeWrites
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
);
|
|
666
|
+
test("unknown native blocker evidence does not claim a stale remaining Project target", async () => {
|
|
667
|
+
const f = batchFixture();
|
|
668
|
+
f.blockers.set(1, [2]);
|
|
669
|
+
f.statuses.set(1, "Waiting");
|
|
670
|
+
f.controls.nativeUnavailableAfterDependency = true;
|
|
671
|
+
const first = await runBatch({ items: [{ issueNumber: 1, blockedBy: [] }] });
|
|
672
|
+
const partial = first.results[0].incomplete;
|
|
673
|
+
assert.equal(partial?.native.status, "unknown");
|
|
674
|
+
assert.equal(partial?.project.desiredStatus, null);
|
|
675
|
+
assert.equal(JSON.stringify(first).includes("PRIVATE_"), false);
|
|
631
676
|
});
|
|
632
|
-
test(
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
677
|
+
test("a successful newer Project observation is retained when the subsequent synchronization fails", async () => {
|
|
678
|
+
const f = batchFixture();
|
|
679
|
+
f.controls.moveProjectToTodoAfterWrite = true;
|
|
680
|
+
const input = { items: [{ issueNumber: 1, status: { latestJournal: "Native journal updated" } }] };
|
|
681
|
+
const first = await runBatch(input);
|
|
682
|
+
assert.equal(first.summary.failed, 1);
|
|
683
|
+
const partial = first.results[0].incomplete;
|
|
684
|
+
assert.equal(partial?.native.status, "confirmed");
|
|
685
|
+
assert.equal(partial?.project.desiredStatus, "Todo");
|
|
686
|
+
assert.equal(JSON.stringify(first).includes("PRIVATE_"), false);
|
|
687
|
+
const writes = [...f.writes];
|
|
688
|
+
assert.equal((await runBatch(input)).summary.unchanged, 1);
|
|
689
|
+
assert.deepEqual(f.writes, writes);
|
|
642
690
|
});
|
|
643
|
-
test(
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
691
|
+
test("MCP serializes the actual incomplete update payload with error semantics", async () => {
|
|
692
|
+
const f = batchFixture();
|
|
693
|
+
f.controls.loseProjectAck = true;
|
|
694
|
+
const server = createAiDeliveryMcpServer({ repoRoot: "/synthetic", identity: "host-author" });
|
|
695
|
+
const client = new Client({ name: "partial-update-synthetic", version: "1" });
|
|
696
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
697
|
+
try {
|
|
698
|
+
await server.connect(serverTransport);
|
|
699
|
+
await client.connect(clientTransport);
|
|
700
|
+
const result = await client.callTool({
|
|
701
|
+
name: "issue_update",
|
|
702
|
+
arguments: { repo: "example/widget", issueNumber: 1, state: "closed", closeReason: "completed" }
|
|
703
|
+
});
|
|
704
|
+
assert.equal(result.isError, true);
|
|
705
|
+
const content = result.content;
|
|
706
|
+
const partial = JSON.parse(content[0].text);
|
|
707
|
+
assert.equal(partial.status, "update-incomplete");
|
|
708
|
+
assert.equal(partial.native.status, "confirmed");
|
|
709
|
+
assert.equal(partial.native.readback.state, "closed");
|
|
710
|
+
assert.equal(partial.project.desiredStatus, "Done");
|
|
711
|
+
} finally {
|
|
712
|
+
await client.close();
|
|
713
|
+
await server.close();
|
|
714
|
+
}
|
|
656
715
|
});
|
|
657
|
-
test(
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
await server.close();
|
|
681
|
-
}
|
|
716
|
+
test("dry run plans close, defer, metadata, parent Points and dependency side effects without writes", async () => {
|
|
717
|
+
const f = batchFixture();
|
|
718
|
+
f.metadata.set(5, { "101": "4" });
|
|
719
|
+
f.statuses.set(4, "Queued");
|
|
720
|
+
const result = await runBatch({
|
|
721
|
+
dryRun: true,
|
|
722
|
+
items: [
|
|
723
|
+
{ issueNumber: 1, state: "closed", closeReason: "duplicate", supersededBy: 5 },
|
|
724
|
+
{ issueNumber: 2, defer: { until: "2026-12-01" }, preserveHistory: true },
|
|
725
|
+
{ issueNumber: 3, labels: ["enhancement"], milestone: 1, points: 2, priority: "High", parentIssueNumber: 5 },
|
|
726
|
+
{ issueNumber: 4, blockedBy: [2] }
|
|
727
|
+
]
|
|
728
|
+
});
|
|
729
|
+
assert.deepEqual(
|
|
730
|
+
result.results.map((item) => item.status),
|
|
731
|
+
["planned", "planned", "planned", "planned"]
|
|
732
|
+
);
|
|
733
|
+
assert.deepEqual(result.results[2].changes.parentPoints, { issueNumber: 5, points: null });
|
|
734
|
+
assert.deepEqual(result.results[3].changes.blockedBy, [2]);
|
|
735
|
+
assert.equal(result.results[0].changes.closureComment, true);
|
|
736
|
+
assert.deepEqual(f.writes, []);
|
|
737
|
+
assert.deepEqual(f.metadata.get(5), { "101": "4" });
|
|
738
|
+
assert.equal(f.rows.get(1).state, "open");
|
|
682
739
|
});
|
|
683
|
-
test(
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
740
|
+
test("unchanged includes labels, metadata, native parent Points and blocker relationships", async () => {
|
|
741
|
+
const f = batchFixture();
|
|
742
|
+
f.metadata.set(5, { "101": "4" });
|
|
743
|
+
f.statuses.set(3, "Queued");
|
|
744
|
+
const input = {
|
|
745
|
+
items: [
|
|
746
|
+
{
|
|
747
|
+
issueNumber: 3,
|
|
748
|
+
labels: ["enhancement"],
|
|
749
|
+
milestone: 1,
|
|
750
|
+
points: 2,
|
|
751
|
+
priority: "High",
|
|
752
|
+
parentIssueNumber: 5,
|
|
753
|
+
blockedBy: [2]
|
|
754
|
+
}
|
|
755
|
+
]
|
|
756
|
+
};
|
|
757
|
+
const first = await runBatch(input);
|
|
758
|
+
assert.equal(first.results[0].status, "applied", JSON.stringify(first));
|
|
759
|
+
assert.deepEqual(first.results[0].readback.labels, ["enhancement"]);
|
|
760
|
+
assert.equal(first.results[0].readback.milestone, 1);
|
|
761
|
+
assert.equal(first.results[0].readback.points, 2);
|
|
762
|
+
assert.equal(first.results[0].readback.priority, "High");
|
|
763
|
+
assert.equal(f.parents.get(3), 5);
|
|
764
|
+
assert.equal(f.metadata.get(5)["101"], void 0);
|
|
765
|
+
assert.deepEqual(f.blockers.get(3), [2]);
|
|
766
|
+
assert.equal((await runBatch(input)).results[0].status, "unchanged");
|
|
767
|
+
f.metadata.set(5, { "101": "4" });
|
|
768
|
+
assert.equal(
|
|
769
|
+
(await runBatch(input)).results[0].status,
|
|
770
|
+
"applied",
|
|
771
|
+
"Parent Points repair cannot be classified unchanged"
|
|
772
|
+
);
|
|
703
773
|
});
|
|
704
|
-
test(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
f.metadata.set(5, { '101': '4' });
|
|
732
|
-
assert.equal((await runBatch(input)).results[0].status, 'applied', 'Parent Points repair cannot be classified unchanged');
|
|
774
|
+
test("readback disagreement and unavailable readback remain failures while later items proceed", async () => {
|
|
775
|
+
const f = batchFixture();
|
|
776
|
+
f.controls.ignoreLabels = true;
|
|
777
|
+
const result = await runBatch({
|
|
778
|
+
items: [
|
|
779
|
+
{ issueNumber: 1, labels: ["enhancement"] },
|
|
780
|
+
{ issueNumber: 2, title: "Later title" }
|
|
781
|
+
]
|
|
782
|
+
});
|
|
783
|
+
assert.deepEqual(
|
|
784
|
+
result.results.map((item) => item.status),
|
|
785
|
+
["failed", "applied"]
|
|
786
|
+
);
|
|
787
|
+
assert.deepEqual(result.results[0].readback.labels, []);
|
|
788
|
+
f.controls.failReadback = 3;
|
|
789
|
+
const unavailable = await runBatch({
|
|
790
|
+
items: [
|
|
791
|
+
{ issueNumber: 3, title: "Written before transport failure" },
|
|
792
|
+
{ issueNumber: 4, title: "Still executed" }
|
|
793
|
+
]
|
|
794
|
+
});
|
|
795
|
+
assert.deepEqual(
|
|
796
|
+
unavailable.results.map((item) => item.status),
|
|
797
|
+
["failed", "applied"]
|
|
798
|
+
);
|
|
799
|
+
assert.equal(unavailable.results[0].readback, null);
|
|
800
|
+
assert.match(unavailable.results[0].readbackError, /unavailable/u);
|
|
733
801
|
});
|
|
734
|
-
test(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
{ issueNumber: 4, title: 'Still executed' },
|
|
750
|
-
],
|
|
751
|
-
});
|
|
752
|
-
assert.deepEqual(unavailable.results.map((item) => item.status), ['failed', 'applied']);
|
|
753
|
-
assert.equal(unavailable.results[0].readback, null);
|
|
754
|
-
assert.match(unavailable.results[0].readbackError, /unavailable/u);
|
|
802
|
+
test("content drift after preparation refuses the stale write and preserves the operator edit", async () => {
|
|
803
|
+
const f = batchFixture();
|
|
804
|
+
f.controls.driftOnRead = 1;
|
|
805
|
+
const result = await runBatch({
|
|
806
|
+
items: [
|
|
807
|
+
{ issueNumber: 1, title: "Stale prepared update" },
|
|
808
|
+
{ issueNumber: 2, title: "Independent update" }
|
|
809
|
+
]
|
|
810
|
+
});
|
|
811
|
+
assert.deepEqual(
|
|
812
|
+
result.results.map((item) => item.status),
|
|
813
|
+
["failed", "applied"]
|
|
814
|
+
);
|
|
815
|
+
assert.equal(f.rows.get(1).body, "Concurrent operator edit");
|
|
816
|
+
assert.equal(f.rows.get(1).title, "Synthetic item 1");
|
|
755
817
|
});
|
|
756
|
-
test(
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
818
|
+
test("positive rate exhaustion suppresses remaining calls and exposes only numeric rate diagnostics", async () => {
|
|
819
|
+
const f = batchFixture();
|
|
820
|
+
f.controls.rateLimited = 1;
|
|
821
|
+
const result = await runBatch({
|
|
822
|
+
items: [
|
|
823
|
+
{ issueNumber: 1, title: "Rate limited" },
|
|
824
|
+
{ issueNumber: 2, title: "Not attempted" }
|
|
825
|
+
]
|
|
826
|
+
});
|
|
827
|
+
assert.deepEqual(
|
|
828
|
+
result.results.map((item) => item.status),
|
|
829
|
+
["failed", "failed"]
|
|
830
|
+
);
|
|
831
|
+
assert.deepEqual(result.summary.rateLimits, [{ retryAfterSeconds: 60, resetAtSeconds: 19e8, remaining: 0 }]);
|
|
832
|
+
assert.match(result.results[1].reason, /Not attempted/u);
|
|
833
|
+
assert.equal(f.rows.get(2).title, "Synthetic item 2");
|
|
834
|
+
assert.doesNotMatch(JSON.stringify(result), /PRIVATE_REMOTE_CONTENT|PRIVATE_TOKEN|authorization/u);
|
|
835
|
+
assert.equal(
|
|
836
|
+
getRateLimitDiagnostics({ status: 403, response: { headers: { "x-ratelimit-remaining": "2" } } }),
|
|
837
|
+
void 0
|
|
838
|
+
);
|
|
839
|
+
let getterRead = false;
|
|
840
|
+
assert.equal(
|
|
841
|
+
getRateLimitDiagnostics({
|
|
842
|
+
get status() {
|
|
843
|
+
getterRead = true;
|
|
844
|
+
return 429;
|
|
845
|
+
}
|
|
846
|
+
}),
|
|
847
|
+
void 0
|
|
848
|
+
);
|
|
849
|
+
assert.equal(getterRead, false);
|
|
768
850
|
});
|
|
769
|
-
test(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
get status() {
|
|
787
|
-
getterRead = true;
|
|
788
|
-
return 429;
|
|
789
|
-
},
|
|
790
|
-
}), undefined);
|
|
791
|
-
assert.equal(getterRead, false);
|
|
851
|
+
test("a wrapped native rate error still suppresses later batch writes", async () => {
|
|
852
|
+
const f = batchFixture();
|
|
853
|
+
let observation;
|
|
854
|
+
Object.assign(f.context.clients, { rateLimitObservation: () => observation });
|
|
855
|
+
f.context.clients.rest.issues.update = (async () => {
|
|
856
|
+
observation = { remaining: 0 };
|
|
857
|
+
throw new Error("Dependency helper wrapped the original failure");
|
|
858
|
+
});
|
|
859
|
+
const result = await runBatch({
|
|
860
|
+
items: [
|
|
861
|
+
{ issueNumber: 1, title: "Wrapped rate failure" },
|
|
862
|
+
{ issueNumber: 2, title: "Must stay unchanged" }
|
|
863
|
+
]
|
|
864
|
+
});
|
|
865
|
+
assert.equal(result.results[1].reason, "Not attempted: GitHub rate limit exhausted.");
|
|
866
|
+
assert.deepEqual(result.summary.rateLimits, [{ remaining: 0 }]);
|
|
867
|
+
assert.equal(f.rows.get(2).title, "Synthetic item 2");
|
|
792
868
|
});
|
|
793
|
-
test(
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
869
|
+
test("schema, selected repository and author refusals perform no writes; cancellation returns every item", async () => {
|
|
870
|
+
const f = batchFixture();
|
|
871
|
+
for (const input of [
|
|
872
|
+
{ items: [] },
|
|
873
|
+
{ items: Array.from({ length: 51 }, () => ({ issueNumber: 1 })) },
|
|
874
|
+
{ items: [{ issueNumber: 1, undefer: true, defer: {} }] },
|
|
875
|
+
{ items: [{ issueNumber: 1, closeReason: "completed" }] },
|
|
876
|
+
{ items: [{ issueNumber: 1, privateUnknown: "HIDDEN_PROPERTY" }] },
|
|
877
|
+
{ items: [{ issueNumber: 1, repo: "other/repository" }] }
|
|
878
|
+
])
|
|
879
|
+
await assert.rejects(runBatch(input));
|
|
880
|
+
await assert.rejects(
|
|
881
|
+
executeTool(
|
|
882
|
+
"issue_batch_update",
|
|
883
|
+
{ repo: "example/widget", items: [{ issueNumber: 1 }] },
|
|
884
|
+
{ repoRoot: "/synthetic", identity: "app-reviewer" }
|
|
885
|
+
),
|
|
886
|
+
/author/u
|
|
887
|
+
);
|
|
888
|
+
const abort = new AbortController();
|
|
889
|
+
abort.abort();
|
|
890
|
+
const cancelled = await issue.batchUpdateIssues(
|
|
891
|
+
f.context,
|
|
892
|
+
{ items: [{ issueNumber: 1 }, { issueNumber: 2 }] },
|
|
893
|
+
abort.signal
|
|
894
|
+
);
|
|
895
|
+
assert.deepEqual(
|
|
896
|
+
cancelled.results.map((item) => item.status),
|
|
897
|
+
["failed", "failed"]
|
|
898
|
+
);
|
|
899
|
+
assert.deepEqual(f.writes, []);
|
|
900
|
+
const shape = getAiDeliveryMcpTool("issue_update").inputSchema;
|
|
901
|
+
const complete = {
|
|
902
|
+
issueNumber: 1,
|
|
903
|
+
draft: true,
|
|
904
|
+
retainLegacyBody: true,
|
|
905
|
+
status: { latestJournal: "Checked" },
|
|
906
|
+
labels: [],
|
|
907
|
+
milestone: null,
|
|
908
|
+
parentIssueNumber: null,
|
|
909
|
+
blocks: [],
|
|
910
|
+
blockedBy: [],
|
|
911
|
+
undefer: true,
|
|
912
|
+
preserveHistory: false
|
|
913
|
+
};
|
|
914
|
+
assert.equal(shape.safeParse(complete).success, true);
|
|
915
|
+
assert.equal(getAiDeliveryMcpTool("issue_batch_update").inputSchema.safeParse({ items: [complete] }).success, true);
|
|
810
916
|
});
|
|
811
|
-
test(
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
917
|
+
test("close journals, duplicate reason and explicit undefer are idempotent through the batch path", async () => {
|
|
918
|
+
const f = batchFixture();
|
|
919
|
+
const input = {
|
|
920
|
+
items: [
|
|
921
|
+
{ issueNumber: 1, state: "closed", closeReason: "duplicate", supersededBy: 5 },
|
|
922
|
+
{ issueNumber: 2, defer: { trigger: "Quarterly review" } }
|
|
923
|
+
]
|
|
924
|
+
};
|
|
925
|
+
const first = await runBatch(input);
|
|
926
|
+
assert.deepEqual(
|
|
927
|
+
first.results.map((item) => item.status),
|
|
928
|
+
["applied", "applied"]
|
|
929
|
+
);
|
|
930
|
+
assert.equal(first.results[0].readback.state, "closed");
|
|
931
|
+
assert.equal(first.results[0].relatedReadback.closeReason, "duplicate");
|
|
932
|
+
const count = f.comments.length;
|
|
933
|
+
assert.deepEqual(
|
|
934
|
+
(await runBatch(input)).results.map((item) => item.status),
|
|
935
|
+
["unchanged", "unchanged"]
|
|
936
|
+
);
|
|
937
|
+
assert.equal(f.comments.length, count);
|
|
938
|
+
const resumed = await runBatch({ items: [{ issueNumber: 2, undefer: true }] });
|
|
939
|
+
assert.equal(resumed.results[0].status, "applied");
|
|
940
|
+
assert.equal(resumed.results[0].readback.deferred, null);
|
|
941
|
+
assert.equal((await runBatch({ items: [{ issueNumber: 2, undefer: true }] })).results[0].status, "unchanged");
|
|
942
|
+
});
|
|
943
|
+
test("public MCP and dispatch expose the same read-only per-item plan contract", async () => {
|
|
944
|
+
const f = batchFixture();
|
|
945
|
+
const server = createAiDeliveryMcpServer({ repoRoot: "/synthetic", identity: "host-author" });
|
|
946
|
+
const client = new Client({ name: "batch-synthetic", version: "1" });
|
|
947
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
948
|
+
try {
|
|
949
|
+
await server.connect(serverTransport);
|
|
950
|
+
await client.connect(clientTransport);
|
|
951
|
+
const input = { repo: "example/widget", dryRun: true, items: [{ issueNumber: 1, title: "MCP planned title" }] };
|
|
952
|
+
const result = await client.callTool({ name: "issue_batch_update", arguments: input });
|
|
953
|
+
assert.notEqual(result.isError, true);
|
|
954
|
+
const content = result.content;
|
|
955
|
+
const parsed = JSON.parse(content[0].text);
|
|
956
|
+
assert.equal(parsed.results[0].changes.title, "MCP planned title");
|
|
957
|
+
assert.equal(parsed.results[0].status, "planned");
|
|
958
|
+
assert.equal(parsed.summary.planned, 1);
|
|
959
|
+
assert.equal(parsed.results[0].readback.title, "Synthetic item 1");
|
|
960
|
+
const direct = await runBatch(input);
|
|
961
|
+
assert.deepEqual(direct.summary, parsed.summary);
|
|
962
|
+
assert.equal(direct.results[0].changes.title, parsed.results[0].changes.title);
|
|
827
963
|
assert.deepEqual(f.writes, []);
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
retainLegacyBody: true,
|
|
833
|
-
status: { latestJournal: 'Checked' },
|
|
834
|
-
labels: [],
|
|
835
|
-
milestone: null,
|
|
836
|
-
parentIssueNumber: null,
|
|
837
|
-
blocks: [],
|
|
838
|
-
blockedBy: [],
|
|
839
|
-
undefer: true,
|
|
840
|
-
preserveHistory: false,
|
|
841
|
-
};
|
|
842
|
-
assert.equal(shape.safeParse(complete).success, true);
|
|
843
|
-
assert.equal(getAiDeliveryMcpTool('issue_batch_update').inputSchema.safeParse({ items: [complete] }).success, true);
|
|
964
|
+
} finally {
|
|
965
|
+
await client.close();
|
|
966
|
+
await server.close();
|
|
967
|
+
}
|
|
844
968
|
});
|
|
845
|
-
test(
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
assert.deepEqual(first.results.map((item) => item.status), ['applied', 'applied']);
|
|
855
|
-
assert.equal(first.results[0].readback.state, 'closed');
|
|
856
|
-
assert.equal(first.results[0].relatedReadback.closeReason, 'duplicate');
|
|
857
|
-
const count = f.comments.length;
|
|
858
|
-
assert.deepEqual((await runBatch(input)).results.map((item) => item.status), ['unchanged', 'unchanged']);
|
|
859
|
-
assert.equal(f.comments.length, count);
|
|
860
|
-
const resumed = await runBatch({ items: [{ issueNumber: 2, undefer: true }] });
|
|
861
|
-
assert.equal(resumed.results[0].status, 'applied');
|
|
862
|
-
assert.equal(resumed.results[0].readback.deferred, null);
|
|
863
|
-
assert.equal((await runBatch({ items: [{ issueNumber: 2, undefer: true }] })).results[0].status, 'unchanged');
|
|
969
|
+
test("the documented fifty-item boundary returns every read-only plan", async () => {
|
|
970
|
+
const f = batchFixture();
|
|
971
|
+
const result = await runBatch({
|
|
972
|
+
dryRun: true,
|
|
973
|
+
items: Array.from({ length: 50 }, () => ({ issueNumber: 1, title: "Planned repeated item" }))
|
|
974
|
+
});
|
|
975
|
+
assert.equal(result.results.length, 50);
|
|
976
|
+
assert.equal(result.summary.planned, 50);
|
|
977
|
+
assert.deepEqual(f.writes, []);
|
|
864
978
|
});
|
|
865
|
-
test(
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
await client.connect(clientTransport);
|
|
873
|
-
const input = { repo: 'example/widget', dryRun: true, items: [{ issueNumber: 1, title: 'MCP planned title' }] };
|
|
874
|
-
const result = await client.callTool({ name: 'issue_batch_update', arguments: input });
|
|
875
|
-
assert.notEqual(result.isError, true);
|
|
876
|
-
const content = result.content;
|
|
877
|
-
const parsed = JSON.parse(content[0].text);
|
|
878
|
-
assert.equal(parsed.results[0].changes.title, 'MCP planned title');
|
|
879
|
-
assert.equal(parsed.results[0].status, 'planned');
|
|
880
|
-
assert.equal(parsed.summary.planned, 1);
|
|
881
|
-
assert.equal(parsed.results[0].readback.title, 'Synthetic item 1');
|
|
882
|
-
const direct = await runBatch(input);
|
|
883
|
-
assert.deepEqual(direct.summary, parsed.summary);
|
|
884
|
-
assert.equal(direct.results[0].changes.title, parsed.results[0].changes.title);
|
|
885
|
-
assert.deepEqual(f.writes, []);
|
|
886
|
-
}
|
|
887
|
-
finally {
|
|
888
|
-
await client.close();
|
|
889
|
-
await server.close();
|
|
890
|
-
}
|
|
979
|
+
test("native label casing preserves the existing case-insensitive update intent", async () => {
|
|
980
|
+
const f = batchFixture();
|
|
981
|
+
const input = { items: [{ issueNumber: 1, labels: ["ENHANCEMENT"] }] };
|
|
982
|
+
const first = await runBatch(input);
|
|
983
|
+
assert.equal(first.results[0].status, "applied");
|
|
984
|
+
assert.deepEqual(f.rows.get(1).labels, ["enhancement"]);
|
|
985
|
+
assert.equal((await runBatch(input)).results[0].status, "unchanged");
|
|
891
986
|
});
|
|
892
|
-
test(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
987
|
+
test("rate exhaustion during fallback readback stops later writes and appears in the summary", async () => {
|
|
988
|
+
const f = batchFixture();
|
|
989
|
+
f.controls.failAfterWrite = 1;
|
|
990
|
+
const get = f.context.clients.rest.issues.get;
|
|
991
|
+
f.context.clients.rest.issues.get = (async (params) => {
|
|
992
|
+
if (params.issue_number === 1 && f.writes.includes("update:1"))
|
|
993
|
+
throw Object.assign(new Error("Private readback error"), { status: 429, headers: { "retry-after": "10" } });
|
|
994
|
+
return get({ ...f.context.repo, ...params });
|
|
995
|
+
});
|
|
996
|
+
const result = await runBatch({
|
|
997
|
+
items: [
|
|
998
|
+
{ issueNumber: 1, title: "Partial item" },
|
|
999
|
+
{ issueNumber: 2, title: "No later write" }
|
|
1000
|
+
]
|
|
1001
|
+
});
|
|
1002
|
+
assert.deepEqual(
|
|
1003
|
+
result.results.map((item) => item.status),
|
|
1004
|
+
["failed", "failed"]
|
|
1005
|
+
);
|
|
1006
|
+
assert.match(result.results[1].reason, /Not attempted/u);
|
|
1007
|
+
assert.deepEqual(result.summary.rateLimits, [{ retryAfterSeconds: 10 }]);
|
|
1008
|
+
assert.equal(f.rows.get(2).title, "Synthetic item 2");
|
|
901
1009
|
});
|
|
902
|
-
test(
|
|
1010
|
+
test("closure reuse refuses duplicate authored journals and corrupted authoritative comment readback", async () => {
|
|
1011
|
+
for (const mode of ["duplicate", "corrupt"]) {
|
|
903
1012
|
const f = batchFixture();
|
|
904
|
-
const input = { items: [{ issueNumber: 1,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1013
|
+
const input = { items: [{ issueNumber: 1, state: "closed", closeReason: "completed" }] };
|
|
1014
|
+
assert.equal((await runBatch(input)).results[0].status, "applied");
|
|
1015
|
+
const existing = f.comments.find((comment) => comment.body === "Requested closure reason: completed.");
|
|
1016
|
+
if (mode === "duplicate") f.comments.push({ ...existing, id: 9999 });
|
|
1017
|
+
else
|
|
1018
|
+
f.context.clients.rest.issues.getComment = (async () => ({
|
|
1019
|
+
data: { ...existing, body: "Corrupted journal readback" }
|
|
1020
|
+
}));
|
|
1021
|
+
const writes = f.writes.length;
|
|
1022
|
+
assert.equal((await runBatch(input)).results[0].status, "failed", mode);
|
|
1023
|
+
assert.equal(f.writes.length, writes);
|
|
1024
|
+
}
|
|
909
1025
|
});
|
|
910
|
-
test(
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
return get({ ...f.context.repo, ...params });
|
|
918
|
-
});
|
|
919
|
-
const result = await runBatch({
|
|
920
|
-
items: [
|
|
921
|
-
{ issueNumber: 1, title: 'Partial item' },
|
|
922
|
-
{ issueNumber: 2, title: 'No later write' },
|
|
923
|
-
],
|
|
924
|
-
});
|
|
925
|
-
assert.deepEqual(result.results.map((item) => item.status), ['failed', 'failed']);
|
|
926
|
-
assert.match(result.results[1].reason, /Not attempted/u);
|
|
927
|
-
assert.deepEqual(result.summary.rateLimits, [{ retryAfterSeconds: 10 }]);
|
|
928
|
-
assert.equal(f.rows.get(2).title, 'Synthetic item 2');
|
|
1026
|
+
test("closing an issue whose archived Project item already shows Done reports applied", async () => {
|
|
1027
|
+
const f = batchFixture();
|
|
1028
|
+
f.controls.archived = true;
|
|
1029
|
+
f.statuses.set(1, "Shipped");
|
|
1030
|
+
const result = await runBatch({ items: [{ issueNumber: 1, state: "closed", closeReason: "not_planned" }] });
|
|
1031
|
+
assert.equal(f.rows.get(1).state, "closed");
|
|
1032
|
+
assert.deepEqual(result.summary, { total: 1, applied: 1, planned: 0, unchanged: 0, failed: 0, rateLimits: [] });
|
|
929
1033
|
});
|
|
930
|
-
test(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1034
|
+
test("an In Review item reads as active work, survives In Progress and moves to Done on close", async () => {
|
|
1035
|
+
const f = batchFixture();
|
|
1036
|
+
f.statuses.set(1, "In Review");
|
|
1037
|
+
const info = await issue.issueInfo(f.context, 1);
|
|
1038
|
+
assert.equal(info.projectStatus, "In Progress");
|
|
1039
|
+
assert.equal(info.inReview, true);
|
|
1040
|
+
await syncIssueProjectStatus({
|
|
1041
|
+
configuration: f.context.projectConfiguration,
|
|
1042
|
+
graphql: f.context.clients.graphql,
|
|
1043
|
+
issueNodeId: "ISSUE1",
|
|
1044
|
+
org: "example",
|
|
1045
|
+
status: "In Progress"
|
|
1046
|
+
});
|
|
1047
|
+
assert.equal(f.statuses.get(1), "In Review");
|
|
1048
|
+
await runBatch({ items: [{ issueNumber: 1, state: "closed", closeReason: "completed" }] });
|
|
1049
|
+
assert.equal(f.statuses.get(1), "Shipped");
|
|
946
1050
|
});
|
|
947
|
-
//# sourceMappingURL=issueBatchUpdate.test.js.map
|
|
1051
|
+
//# sourceMappingURL=issueBatchUpdate.test.js.map
|