@aviaratech/ai-delivery 0.3.34 → 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 -506
- 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 +1746 -0
- package/dist/boardReconcile.test.js.map +7 -0
- 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 +406 -485
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -25
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +434 -297
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +320 -14
- package/dist/config/deliveryConfig.js +472 -385
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +775 -584
- 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 -477
- 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.d.ts +1 -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 +17 -12
- package/dist/dispatch.js +330 -322
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +16 -3
- package/dist/errors.js +104 -82
- 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 -51
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +3 -0
- package/dist/github/discovery.js +197 -201
- 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 +53 -1
- package/dist/github/projectDelivery.js +623 -460
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.d.ts +5 -2
- package/dist/github/relationships.js +434 -333
- 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 +103 -7
- package/dist/issue.js +2104 -1547
- 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 +1004 -683
- 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 +1088 -593
- 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 -90
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +790 -220
- package/dist/mcp/tools.js +267 -333
- 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 -1231
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1822 -1283
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +485 -305
- 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 +1204 -0
- package/dist/services/boardReconcileService.js +1445 -0
- package/dist/services/boardReconcileService.js.map +7 -0
- package/dist/services/deliveryAdmission.d.ts +2 -0
- package/dist/services/deliveryAdmission.js +129 -152
- 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 +354 -350
- 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 -1929
- 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.d.ts +6 -0
- package/dist/version.js +24 -10
- 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 +10 -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 +261 -43
- package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
- 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 -3058
- 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 → boardReconcile.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
package/dist/issueIntake.test.js
CHANGED
|
@@ -1,144 +1,309 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { quietReadViewResponse } from "./fixtures/readView.js";
|
|
2
|
+
import { issueProjectItemsResponse } from "./fixtures/issueProjectItems.js";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { afterEach, test, vi } from "vitest";
|
|
9
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
10
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
11
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import {
|
|
14
|
+
createIssue,
|
|
15
|
+
updateIssue,
|
|
16
|
+
batchUpdateIssues,
|
|
17
|
+
getIncompleteIssueUpdate,
|
|
18
|
+
canonicalIssueBody,
|
|
19
|
+
renderIssueHistory,
|
|
20
|
+
readyCheck,
|
|
21
|
+
issueInfo,
|
|
22
|
+
listIssues
|
|
23
|
+
} from "./issue.js";
|
|
24
|
+
import { executeTool, startTrackedIssue } from "./dispatch.js";
|
|
25
|
+
import { digestValue } from "./delivery/common.js";
|
|
26
|
+
import { getAiDeliveryMcpTool } from "./mcp/tools.js";
|
|
27
|
+
import { IssueFields, ReadyIssue, renderIssueBody, parseIssueBody, ISSUE_BODY_MARKER } from "./issueContract.js";
|
|
28
|
+
import { syntheticDiscoveryConfig } from "./fixtures/discovery.js";
|
|
17
29
|
afterEach(() => {
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
vi.unstubAllEnvs();
|
|
20
32
|
});
|
|
21
|
-
test(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
test("create renders all five status fields with a UTC timestamp and optional milestone", async () => {
|
|
34
|
+
vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-10-16T20:30:00Z"));
|
|
35
|
+
for (const draft of [false, true]) {
|
|
36
|
+
const f2 = fixture();
|
|
37
|
+
const input = { ...ready(), draft, status: { nextMilestone: "Run checks" } };
|
|
38
|
+
const result = await createIssue(f2.context, input);
|
|
39
|
+
const status = result.body.split("## Status\n\n")[1].split("\n\n## Problem")[0];
|
|
40
|
+
assert.equal(
|
|
41
|
+
status,
|
|
42
|
+
`- **State:** ${draft ? "Draft" : "Ready"}
|
|
43
|
+
- **Last updated:** 2026-10-16T20:30:00.000Z UTC
|
|
44
|
+
- **Next milestone:** Run checks
|
|
45
|
+
- **Blockers:** None
|
|
46
|
+
- **Latest journal:** None yet`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const f = fixture();
|
|
50
|
+
assert.match((await createIssue(f.context, ready())).body, /\*\*Next milestone:\*\* Not started/u);
|
|
32
51
|
});
|
|
33
|
-
test(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const result = await updateIssue(f.context, patch);
|
|
46
|
-
const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, '$1$2');
|
|
47
|
-
assert.match(result.body, /\*\*Next milestone:\*\* Await review/u);
|
|
48
|
-
assert.equal(outside(result.body), outside(before));
|
|
49
|
-
assert.equal((await updateIssue(f.context, patch)).body, result.body);
|
|
50
|
-
assert.equal(f.comments.length, 0);
|
|
52
|
+
test("status-only patches preserve every outside-Status byte including canonical data and start markers", async () => {
|
|
53
|
+
const f = fixture();
|
|
54
|
+
const created = await createIssue(f.context, ready());
|
|
55
|
+
f.live.body = created.body + "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
|
|
56
|
+
const before = f.live.body;
|
|
57
|
+
const patch = { issueNumber: 17, status: { nextMilestone: "Await review", blockers: "None" } };
|
|
58
|
+
const result = await updateIssue(f.context, patch);
|
|
59
|
+
const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, "$1$2");
|
|
60
|
+
assert.match(result.body, /\*\*Next milestone:\*\* Await review/u);
|
|
61
|
+
assert.equal(outside(result.body), outside(before));
|
|
62
|
+
assert.equal((await updateIssue(f.context, patch)).body, result.body);
|
|
63
|
+
assert.equal(f.comments.length, 0);
|
|
51
64
|
});
|
|
52
|
-
test(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
assert.equal(f.comments.length, preserveHistory === false ? 0 : 1);
|
|
65
|
-
if (preserveHistory !== false) {
|
|
66
|
-
const retained = f.comments[0].body.match(/Body:\n<pre>([\s\S]*)<\/pre>/u)[1]
|
|
67
|
-
.replaceAll('<', '<')
|
|
68
|
-
.replaceAll('>', '>')
|
|
69
|
-
.replaceAll('&', '&');
|
|
70
|
-
assert.equal(retained, before);
|
|
71
|
-
}
|
|
72
|
-
const again = await updateIssue(f.context, {
|
|
73
|
-
issueNumber: 17,
|
|
74
|
-
...(preserveHistory === undefined ? {} : { preserveHistory }),
|
|
75
|
-
});
|
|
76
|
-
assert.equal(again.body, result.body);
|
|
77
|
-
assert.equal(f.comments.length, preserveHistory === false ? 0 : 1);
|
|
78
|
-
}
|
|
79
|
-
const f = fixture();
|
|
80
|
-
f.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
|
|
81
|
-
const drop = { issueNumber: 17, preserveHistory: false, retainLegacyBody: false };
|
|
82
|
-
const result = await updateIssue(f.context, drop);
|
|
83
|
-
assert.ok(!result.body.split('<!-- ai-delivery:issue-data@1 ')[0].includes(legacy));
|
|
84
|
-
assert.equal(f.comments.length, 0);
|
|
65
|
+
test("explicit Project status records its reason without rewriting native issue fields", async () => {
|
|
66
|
+
const f = fixture();
|
|
67
|
+
const before = f.live.body;
|
|
68
|
+
const input = { issueNumber: 17, projectStatus: { status: "Blocked", reason: " Waiting for review. " } };
|
|
69
|
+
const result = await updateIssue(f.context, input);
|
|
70
|
+
assert.equal(result.projectStatus, "Blocked");
|
|
71
|
+
assert.equal(f.live.body, before);
|
|
72
|
+
assert.deepEqual(f.writes, []);
|
|
73
|
+
assert.equal(f.comments.length, 1);
|
|
74
|
+
assert.equal(f.comments[0].body, "Requested Project Status: Blocked.\n\nWaiting for review.");
|
|
75
|
+
await updateIssue(f.context, input);
|
|
76
|
+
assert.equal(f.comments.length, 1);
|
|
85
77
|
});
|
|
86
|
-
test(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
test("explicit Project status validates public input and native truth before Project writes", async () => {
|
|
79
|
+
const schema = getAiDeliveryMcpTool("issue_update").inputSchema;
|
|
80
|
+
for (const projectStatus of [
|
|
81
|
+
{ status: "Todo", reason: " " },
|
|
82
|
+
{ status: "Queued", reason: "Review" },
|
|
83
|
+
{ status: "Blocked", reason: "x".repeat(65536) },
|
|
84
|
+
{ status: "Blocked", reason: "api_key=abcdefghijk12345" }
|
|
85
|
+
]) {
|
|
86
|
+
assert.throws(() => schema.parse({ issueNumber: 17, projectStatus }));
|
|
87
|
+
const f2 = fixture();
|
|
88
|
+
await assert.rejects(updateIssue(f2.context, { issueNumber: 17, projectStatus }));
|
|
89
|
+
assert.equal(f2.comments.length + f2.statusWrites.length + f2.writes.length, 0);
|
|
90
|
+
}
|
|
91
|
+
for (const mode of ["openDone", "blockedTodo", "conflict", "missing"]) {
|
|
92
|
+
const f2 = fixture();
|
|
93
|
+
f2.controls.blockers = mode === "blockedTodo" || mode === "conflict";
|
|
94
|
+
f2.controls.blockerClosed = mode === "conflict";
|
|
95
|
+
f2.controls.blockerConflict = mode === "conflict";
|
|
96
|
+
f2.controls.missingNative = mode === "missing";
|
|
97
|
+
await assert.rejects(
|
|
98
|
+
updateIssue(f2.context, {
|
|
99
|
+
issueNumber: 17,
|
|
100
|
+
projectStatus: { status: mode === "openDone" ? "Done" : "Todo", reason: "Inspect native state." }
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
assert.equal(f2.statusWrites.length + f2.membershipWrites.length + f2.comments.length, 0);
|
|
104
|
+
}
|
|
105
|
+
const f = fixture();
|
|
106
|
+
f.controls.blockers = true;
|
|
107
|
+
f.controls.blockerClosed = true;
|
|
108
|
+
assert.equal(
|
|
109
|
+
(await updateIssue(f.context, {
|
|
110
|
+
issueNumber: 17,
|
|
111
|
+
projectStatus: { status: "Todo", reason: "Prerequisite closed." }
|
|
112
|
+
})).projectStatus,
|
|
113
|
+
"Todo"
|
|
114
|
+
);
|
|
93
115
|
});
|
|
94
|
-
test(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
f.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
assert.equal(f.comments.length, 1);
|
|
109
|
-
assert.equal(f.comments[0].body, history);
|
|
110
|
-
assert.ok(!result.body.split('<!-- ai-delivery:issue-data@1 ')[0].includes('Retired synthetic criterion.'));
|
|
116
|
+
test("explicit Project status rechecks native state after the reason and retains pending recovery", async () => {
|
|
117
|
+
const f = fixture();
|
|
118
|
+
const create = f.context.clients.rest.issues.createComment;
|
|
119
|
+
f.context.clients.rest.issues.createComment = (async (...args) => {
|
|
120
|
+
const result = await create(...args);
|
|
121
|
+
f.live.state = "closed";
|
|
122
|
+
return result;
|
|
123
|
+
});
|
|
124
|
+
await assert.rejects(
|
|
125
|
+
updateIssue(f.context, { issueNumber: 17, projectStatus: { status: "In Progress", reason: "Begin work." } })
|
|
126
|
+
);
|
|
127
|
+
assert.equal(f.comments.length, 1);
|
|
128
|
+
assert.equal(f.statusWrites.length, 0);
|
|
129
|
+
assert.equal(f.writes.length, 0);
|
|
111
130
|
});
|
|
112
|
-
test(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
test("explicit Project partial recovery preserves reason and retries only pending work", async () => {
|
|
132
|
+
const f = fixture();
|
|
133
|
+
f.controls.projectFailure = "before";
|
|
134
|
+
const request = {
|
|
135
|
+
issueNumber: 17,
|
|
136
|
+
projectStatus: { status: "In Progress", reason: "Begin implementation." }
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
await updateIssue(f.context, request);
|
|
140
|
+
assert.fail("Expected an incomplete Project update.");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
const result = getIncompleteIssueUpdate(error);
|
|
143
|
+
assert.equal(result.native.status, "confirmed");
|
|
144
|
+
assert.equal(
|
|
145
|
+
result.native.projectStatusComment?.body,
|
|
146
|
+
"Requested Project Status: In Progress.\n\nBegin implementation."
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
assert.equal(f.comments.length, 1);
|
|
150
|
+
assert.equal(f.writes.length, 0);
|
|
151
|
+
f.controls.projectFailure = "";
|
|
152
|
+
const resumed = await batchUpdateIssues(f.context, { items: [request] });
|
|
153
|
+
assert.equal(resumed.results[0].status, "applied");
|
|
154
|
+
assert.deepEqual(Object.keys(resumed.results[0].changes), ["projectStatus"]);
|
|
155
|
+
assert.equal(f.comments.length, 1);
|
|
156
|
+
assert.equal(f.writes.length, 0);
|
|
157
|
+
assert.equal((await batchUpdateIssues(f.context, { items: [request] })).results[0].status, "unchanged");
|
|
158
|
+
f.controls.projectFailure = "readback";
|
|
159
|
+
assert.equal((await batchUpdateIssues(f.context, { items: [request] })).results[0].status, "failed");
|
|
160
|
+
assert.equal(f.comments.length, 1);
|
|
161
|
+
assert.equal(f.writes.length, 0);
|
|
162
|
+
});
|
|
163
|
+
test("explicit batch Project status waits for requested native closure", async () => {
|
|
164
|
+
const f = fixture();
|
|
165
|
+
const update = f.context.clients.rest.issues.update;
|
|
166
|
+
f.context.clients.rest.issues.update = (async (...args) => {
|
|
167
|
+
const result2 = await update(...args);
|
|
168
|
+
if (args[0]?.state === "closed") f.live.state = "closed";
|
|
169
|
+
return result2;
|
|
170
|
+
});
|
|
171
|
+
const result = await batchUpdateIssues(f.context, {
|
|
172
|
+
items: [
|
|
173
|
+
{ issueNumber: 17, state: "closed", projectStatus: { status: "Done", reason: "Implementation complete." } }
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
assert.equal(result.results[0].status, "applied");
|
|
177
|
+
assert.equal(result.results[0].relatedReadback.projectStatusReason, "Implementation complete.");
|
|
178
|
+
assert.equal(f.getStatus(), "Shipped");
|
|
179
|
+
});
|
|
180
|
+
test("explicit Project activation rechecks blockers after its capacity override comment", async () => {
|
|
181
|
+
const f = fixture();
|
|
182
|
+
f.controls.capacityMode = true;
|
|
183
|
+
f.live.labels = ["critical"];
|
|
184
|
+
f.context.config = {
|
|
185
|
+
...f.context.config,
|
|
186
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
187
|
+
};
|
|
188
|
+
const create = f.context.clients.rest.issues.createComment;
|
|
189
|
+
f.context.clients.rest.issues.createComment = (async (...args) => {
|
|
190
|
+
const result = await create(...args);
|
|
191
|
+
if (args[0]?.body.startsWith("WIP capacity override.")) f.controls.blockers = true;
|
|
192
|
+
return result;
|
|
193
|
+
});
|
|
194
|
+
await assert.rejects(
|
|
195
|
+
updateIssue(f.context, {
|
|
196
|
+
issueNumber: 17,
|
|
197
|
+
overrideReason: "Admit capacity exception.",
|
|
198
|
+
projectStatus: { status: "In Progress", reason: "Begin work." }
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
assert.equal(f.statusWrites.length, 0);
|
|
202
|
+
assert.equal(f.getStatus(), "Queued");
|
|
203
|
+
});
|
|
204
|
+
test("explicit batch status refuses contradictory Project snapshots before unchanged success", async () => {
|
|
205
|
+
const f = fixture();
|
|
206
|
+
const request = { issueNumber: 17, projectStatus: { status: "Blocked", reason: "Await review." } };
|
|
207
|
+
await updateIssue(f.context, request);
|
|
208
|
+
const read = f.context.clients.rest.issues.getComment;
|
|
209
|
+
f.context.clients.rest.issues.getComment = (async (...args) => {
|
|
210
|
+
const result2 = await read(...args);
|
|
211
|
+
f.setStatus("Queued");
|
|
212
|
+
return result2;
|
|
213
|
+
});
|
|
214
|
+
const result = await batchUpdateIssues(f.context, { items: [request] });
|
|
215
|
+
assert.equal(result.results[0].status, "failed");
|
|
216
|
+
assert.equal(f.statusWrites.length, 1);
|
|
217
|
+
});
|
|
218
|
+
test("legacy rendering drops only by explicit retention choice or verified history and does not grow on repeat", async () => {
|
|
219
|
+
const legacy = "Retired criterion: accept every invalid identifier.\n";
|
|
220
|
+
for (const preserveHistory of [void 0, false, true]) {
|
|
221
|
+
const f2 = fixture();
|
|
222
|
+
f2.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
|
|
223
|
+
const before = f2.live.body;
|
|
224
|
+
const result2 = await updateIssue(f2.context, {
|
|
225
|
+
issueNumber: 17,
|
|
226
|
+
...preserveHistory === void 0 ? {} : { preserveHistory }
|
|
121
227
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
228
|
+
const readable = result2.body.split("<!-- ai-delivery:issue-data@1 ")[0];
|
|
229
|
+
assert.equal(readable.includes(legacy), preserveHistory === false);
|
|
230
|
+
assert.equal(f2.comments.length, preserveHistory === false ? 0 : 1);
|
|
231
|
+
if (preserveHistory !== false) {
|
|
232
|
+
const retained = f2.comments[0].body.match(/Body:\n<pre>([\s\S]*)<\/pre>/u)[1].replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&");
|
|
233
|
+
assert.equal(retained, before);
|
|
128
234
|
}
|
|
129
|
-
|
|
130
|
-
|
|
235
|
+
const again = await updateIssue(f2.context, {
|
|
236
|
+
issueNumber: 17,
|
|
237
|
+
...preserveHistory === void 0 ? {} : { preserveHistory }
|
|
238
|
+
});
|
|
239
|
+
assert.equal(again.body, result2.body);
|
|
240
|
+
assert.equal(f2.comments.length, preserveHistory === false ? 0 : 1);
|
|
241
|
+
}
|
|
242
|
+
const f = fixture();
|
|
243
|
+
f.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
|
|
244
|
+
const drop = { issueNumber: 17, preserveHistory: false, retainLegacyBody: false };
|
|
245
|
+
const result = await updateIssue(f.context, drop);
|
|
246
|
+
assert.ok(!result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes(legacy));
|
|
247
|
+
assert.equal(f.comments.length, 0);
|
|
248
|
+
});
|
|
249
|
+
test("replacement legacy text remains visible until those incoming bytes have native history", async () => {
|
|
250
|
+
const f = fixture();
|
|
251
|
+
f.live.body = "Original operator text.\n";
|
|
252
|
+
const incoming = "New operator text that was never in the previous body.\n";
|
|
253
|
+
const result = await updateIssue(f.context, { issueNumber: 17, body: incoming, ...ready(), preserveHistory: true });
|
|
254
|
+
assert.ok(result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes(incoming));
|
|
255
|
+
assert.ok(!f.comments[0].body.includes(incoming));
|
|
256
|
+
});
|
|
257
|
+
test("default render omission reuses an existing exact authored history snapshot", async () => {
|
|
258
|
+
const f = fixture();
|
|
259
|
+
f.live.body = renderIssueBody({ ...ready(), legacyBody: "Retired synthetic criterion.\n" });
|
|
260
|
+
const before = f.live.body;
|
|
261
|
+
const history = renderIssueHistory(f.live.title, before);
|
|
262
|
+
f.comments.push({
|
|
263
|
+
id: 91,
|
|
264
|
+
body: history,
|
|
265
|
+
html_url: "https://github.com/example/widget/issues/17#issuecomment-91",
|
|
266
|
+
user: { login: "operator" },
|
|
267
|
+
issue_url: "https://api.github.com/repos/example/widget/issues/17"
|
|
268
|
+
});
|
|
269
|
+
const result = await updateIssue(f.context, { issueNumber: 17 });
|
|
270
|
+
assert.equal(result.historyComment?.reused, true);
|
|
271
|
+
assert.equal(f.comments.length, 1);
|
|
272
|
+
assert.equal(f.comments[0].body, history);
|
|
273
|
+
assert.ok(!result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes("Retired synthetic criterion."));
|
|
274
|
+
});
|
|
275
|
+
test("normal-start recovery preserves legacy rendering across repeated exact retries", async () => {
|
|
276
|
+
const f = fixture();
|
|
277
|
+
f.controls.created = false;
|
|
278
|
+
const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
|
|
279
|
+
title: ready().title,
|
|
280
|
+
body: renderIssueBody({ ...ready(), legacyBody: "Original operator context.\n" }),
|
|
281
|
+
issueType: "Task",
|
|
282
|
+
points: 2,
|
|
283
|
+
requestId: "legacy-status-retry"
|
|
284
|
+
});
|
|
285
|
+
await startTrackedIssue(f.context, request);
|
|
286
|
+
const before = f.live.body;
|
|
287
|
+
for (let retry = 0; retry < 2; retry++) {
|
|
288
|
+
const result = await startTrackedIssue(f.context, request);
|
|
289
|
+
assert.ok("reused" in result && result.reused);
|
|
290
|
+
assert.equal(f.live.body, before);
|
|
291
|
+
}
|
|
292
|
+
assert.equal(f.writes.filter((input) => !("issue_number" in input)).length, 1);
|
|
293
|
+
assert.equal(f.comments.length, 1);
|
|
131
294
|
});
|
|
132
|
-
test.each([{ points: 4 }, { issueType:
|
|
295
|
+
test.each([{ points: 4 }, { issueType: "Feature" }])(
|
|
296
|
+
"normal-start retry refuses changed contract metadata %j before native writes",
|
|
297
|
+
async (patch) => {
|
|
133
298
|
const f = fixture();
|
|
134
299
|
f.controls.created = false;
|
|
135
|
-
f.context.config = { ...f.context.config, native: { ...f.context.config.native, issueTypes: [
|
|
136
|
-
const request = getAiDeliveryMcpTool(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
300
|
+
f.context.config = { ...f.context.config, native: { ...f.context.config.native, issueTypes: ["Task", "Feature"] } };
|
|
301
|
+
const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
|
|
302
|
+
title: ready().title,
|
|
303
|
+
body: renderIssueBody(ready()),
|
|
304
|
+
issueType: "Task",
|
|
305
|
+
points: 2,
|
|
306
|
+
requestId: "contract-metadata-retry"
|
|
142
307
|
});
|
|
143
308
|
await startTrackedIssue(f.context, request);
|
|
144
309
|
await updateIssue(f.context, { issueNumber: 17, ...patch });
|
|
@@ -149,1814 +314,1862 @@ test.each([{ points: 4 }, { issueType: 'Feature' }])('normal-start retry refuses
|
|
|
149
314
|
assert.equal(f.live.body, before);
|
|
150
315
|
assert.equal(f.writes.length, writes);
|
|
151
316
|
assert.equal(f.comments.length, comments);
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
test("default legacy omission refuses drift between preparation and the history snapshot", async () => {
|
|
320
|
+
const f = fixture();
|
|
321
|
+
f.live.body = renderIssueBody({ ...ready(), legacyBody: "Original unpreserved legacy bytes.\n" });
|
|
322
|
+
f.controls.driftBeforeUpdate = true;
|
|
323
|
+
await assert.rejects(updateIssue(f.context, { issueNumber: 17 }), /content changed/u);
|
|
324
|
+
assert.equal(f.live.body, "Concurrent operator edit");
|
|
325
|
+
assert.equal(f.comments.length, 0);
|
|
326
|
+
assert.equal(f.writes.length, 0);
|
|
152
327
|
});
|
|
153
|
-
test(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
328
|
+
test("status-only updates preserve embedded metadata and old formatting despite different native metadata", async () => {
|
|
329
|
+
const f = fixture();
|
|
330
|
+
const data = {
|
|
331
|
+
...ready(),
|
|
332
|
+
acceptanceCriteria: [{ behavior: "Reject malformed input:\n- Empty input", verifiedBy: "Regression test." }]
|
|
333
|
+
};
|
|
334
|
+
f.live.body = renderIssueBody(data).replace(" - Empty input\n\n Verified", "- Empty input\n Verified") + "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
|
|
335
|
+
f.controls.livePoints = 4;
|
|
336
|
+
f.live.type.name = "Feature";
|
|
337
|
+
const before = f.live.body;
|
|
338
|
+
const patch = { issueNumber: 17, status: { nextMilestone: "Await review" } };
|
|
339
|
+
const result = await updateIssue(f.context, patch);
|
|
340
|
+
const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, "$1$2");
|
|
341
|
+
assert.equal(outside(result.body), outside(before));
|
|
342
|
+
assert.equal(f.controls.livePoints, 4);
|
|
343
|
+
assert.equal(f.live.type.name, "Feature");
|
|
344
|
+
assert.equal(f.writes.length, 1);
|
|
345
|
+
assert.deepEqual(Object.keys(f.writes[0]).sort(), ["body", "issue_number", "owner", "repo"]);
|
|
161
346
|
});
|
|
162
|
-
test(
|
|
347
|
+
test("status patches reject secrets, multiline and unknown fields without native writes", async () => {
|
|
348
|
+
for (const status of [
|
|
349
|
+
{ nextMilestone: "password=" + "X".repeat(16) },
|
|
350
|
+
{ nextMilestone: "Next\n## Problem" },
|
|
351
|
+
{ unknown: "unexpected" }
|
|
352
|
+
]) {
|
|
163
353
|
const f = fixture();
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
acceptanceCriteria: [{ behavior: 'Reject malformed input:\n- Empty input', verifiedBy: 'Regression test.' }],
|
|
167
|
-
};
|
|
168
|
-
f.live.body =
|
|
169
|
-
renderIssueBody(data).replace(' - Empty input\n\n Verified', '- Empty input\n Verified') +
|
|
170
|
-
'\n\n<!-- ai-delivery-start-intent: sha256:' +
|
|
171
|
-
'a'.repeat(64) +
|
|
172
|
-
' -->\n<!-- ai-delivery-start: sha256:' +
|
|
173
|
-
'b'.repeat(64) +
|
|
174
|
-
' -->';
|
|
175
|
-
f.controls.livePoints = 4;
|
|
176
|
-
f.live.type.name = 'Feature';
|
|
177
|
-
const before = f.live.body;
|
|
178
|
-
const patch = { issueNumber: 17, status: { nextMilestone: 'Await review' } };
|
|
179
|
-
const result = await updateIssue(f.context, patch);
|
|
180
|
-
const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, '$1$2');
|
|
181
|
-
assert.equal(outside(result.body), outside(before));
|
|
182
|
-
assert.equal(f.controls.livePoints, 4);
|
|
183
|
-
assert.equal(f.live.type.name, 'Feature');
|
|
184
|
-
assert.equal(f.writes.length, 1);
|
|
185
|
-
assert.deepEqual(Object.keys(f.writes[0]).sort(), ['body', 'issue_number', 'owner', 'repo']);
|
|
186
|
-
});
|
|
187
|
-
test('status patches reject secrets, multiline and unknown fields without native writes', async () => {
|
|
188
|
-
for (const status of [
|
|
189
|
-
{ nextMilestone: 'password=' + 'X'.repeat(16) },
|
|
190
|
-
{ nextMilestone: 'Next\n## Problem' },
|
|
191
|
-
{ unknown: 'unexpected' },
|
|
192
|
-
]) {
|
|
193
|
-
const f = fixture();
|
|
194
|
-
const patch = { issueNumber: 17, status };
|
|
195
|
-
await assert.rejects(updateIssue(f.context, patch));
|
|
196
|
-
assert.equal(f.writes.length, 0);
|
|
197
|
-
assert.equal(f.comments.length, 0);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
test('status-only patches refuse concurrent native body drift before overwriting it', async () => {
|
|
201
|
-
const f = fixture();
|
|
202
|
-
f.controls.driftBeforeUpdate = true;
|
|
203
|
-
const patch = { issueNumber: 17, status: { nextMilestone: 'Await review' } };
|
|
204
|
-
await assert.rejects(updateIssue(f.context, patch), /content changed/u);
|
|
205
|
-
assert.equal(f.live.body, 'Concurrent operator edit');
|
|
354
|
+
const patch = { issueNumber: 17, status };
|
|
355
|
+
await assert.rejects(updateIssue(f.context, patch));
|
|
206
356
|
assert.equal(f.writes.length, 0);
|
|
357
|
+
assert.equal(f.comments.length, 0);
|
|
358
|
+
}
|
|
207
359
|
});
|
|
208
|
-
test(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
assert.match(result.stderr, /Remove credentials and private keys from public status fields/u);
|
|
216
|
-
assert.ok(!result.stderr.includes('X'.repeat(16)));
|
|
217
|
-
}
|
|
218
|
-
finally {
|
|
219
|
-
rmSync(root, { recursive: true, force: true });
|
|
220
|
-
}
|
|
360
|
+
test("status-only patches refuse concurrent native body drift before overwriting it", async () => {
|
|
361
|
+
const f = fixture();
|
|
362
|
+
f.controls.driftBeforeUpdate = true;
|
|
363
|
+
const patch = { issueNumber: 17, status: { nextMilestone: "Await review" } };
|
|
364
|
+
await assert.rejects(updateIssue(f.context, patch), /content changed/u);
|
|
365
|
+
assert.equal(f.live.body, "Concurrent operator edit");
|
|
366
|
+
assert.equal(f.writes.length, 0);
|
|
221
367
|
});
|
|
222
|
-
test(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
assert.
|
|
233
|
-
assert.match(result.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
368
|
+
test("CLI typed field files reach status privacy validation before configuration", { tags: ["release"] }, () => {
|
|
369
|
+
const root = mkdtempSync(join(tmpdir(), "delivery130-status-"));
|
|
370
|
+
try {
|
|
371
|
+
const file = join(root, "fields.json");
|
|
372
|
+
writeFileSync(file, JSON.stringify({ ...ready(), status: { nextMilestone: "password=" + "X".repeat(16) } }));
|
|
373
|
+
const result = spawnSync(
|
|
374
|
+
process.execPath,
|
|
375
|
+
[resolve("dist/cli.js"), "--repo", "example/widget", "create", "--title", ready().title, "--fields-file", file],
|
|
376
|
+
{ encoding: "utf8" }
|
|
377
|
+
);
|
|
378
|
+
assert.notEqual(result.status, 0);
|
|
379
|
+
assert.match(result.stderr, /Remove credentials and private keys from public status fields/u);
|
|
380
|
+
assert.ok(!result.stderr.includes("X".repeat(16)));
|
|
381
|
+
} finally {
|
|
382
|
+
rmSync(root, { recursive: true, force: true });
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
test("status updates retain old multiline canonical formatting and reject ambiguous status blocks", async () => {
|
|
386
|
+
const f = fixture();
|
|
387
|
+
const data = {
|
|
388
|
+
...ready(),
|
|
389
|
+
acceptanceCriteria: [{ behavior: "Reject malformed input:\n- Empty input", verifiedBy: "Regression test." }]
|
|
390
|
+
};
|
|
391
|
+
f.live.body = renderIssueBody(data).replace(" - Empty input\n\n Verified", "- Empty input\n Verified");
|
|
392
|
+
const before = f.live.body.split("\n\n## Problem")[1];
|
|
393
|
+
const patch = { issueNumber: 17, status: { nextMilestone: "<literal> *text* [link]" } };
|
|
394
|
+
const result = await updateIssue(f.context, patch);
|
|
395
|
+
assert.equal(result.body.split("\n\n## Problem")[1], before);
|
|
396
|
+
assert.match(result.body, /<literal> \\\*text\\\* \\\[link\\\]/u);
|
|
397
|
+
f.live.body = result.body.replace("- **Blockers:** None", "- **Blockers:** None\n- **Blockers:** Other");
|
|
398
|
+
const writes = f.writes.length;
|
|
399
|
+
await assert.rejects(updateIssue(f.context, patch), /unambiguous status/u);
|
|
400
|
+
assert.equal(f.writes.length, writes);
|
|
238
401
|
});
|
|
239
402
|
const ready = () => IssueFields.parse({
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
403
|
+
title: "Reject invalid widget identifiers before persistence",
|
|
404
|
+
issueType: "Task",
|
|
405
|
+
points: 2,
|
|
406
|
+
problem: "Malformed identifiers reach persistence.",
|
|
407
|
+
outcome: "Reject malformed widget identifiers before persistence.",
|
|
408
|
+
acceptanceCriteria: [
|
|
409
|
+
{
|
|
410
|
+
behavior: "An invalid identifier returns an error with zero persistence calls.",
|
|
411
|
+
verifiedBy: "A portable mocked persistence regression test."
|
|
412
|
+
}
|
|
413
|
+
],
|
|
414
|
+
outOfScope: ["Storage changes."],
|
|
415
|
+
context: { components: ["widget"], files: [], evidence: [] }
|
|
253
416
|
});
|
|
254
417
|
function fixture() {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
418
|
+
const live = {
|
|
419
|
+
number: 17,
|
|
420
|
+
id: 117,
|
|
421
|
+
node_id: "ISSUE17",
|
|
422
|
+
title: ready().title,
|
|
423
|
+
body: renderIssueBody(ready()),
|
|
424
|
+
state: "open",
|
|
425
|
+
created_at: "2026-01-01T00:00:00Z",
|
|
426
|
+
updated_at: "2026-01-01T00:00:00Z",
|
|
427
|
+
labels: [],
|
|
428
|
+
type: { name: "Task" },
|
|
429
|
+
html_url: "https://github.com/example/widget/issues/17"
|
|
430
|
+
};
|
|
431
|
+
const writes = [];
|
|
432
|
+
const comments = [];
|
|
433
|
+
const controls = {
|
|
434
|
+
role: "author",
|
|
435
|
+
ignoreBody: false,
|
|
436
|
+
wrongCreateRepo: false,
|
|
437
|
+
driftAfterHistory: false,
|
|
438
|
+
driftBeforeUpdate: false,
|
|
439
|
+
created: true,
|
|
440
|
+
blockers: false,
|
|
441
|
+
blockerClosed: false,
|
|
442
|
+
blockerConflict: false,
|
|
443
|
+
missingNative: false,
|
|
444
|
+
closeAfterReason: false,
|
|
445
|
+
trackingParent: false,
|
|
446
|
+
livePoints: 2,
|
|
447
|
+
projectMember: true,
|
|
448
|
+
projectArchived: false,
|
|
449
|
+
projectFailure: "",
|
|
450
|
+
journalFailure: false,
|
|
451
|
+
branchFailure: false,
|
|
452
|
+
closeAfterBranch: false,
|
|
453
|
+
blockAfterBranch: false,
|
|
454
|
+
capacityMode: false,
|
|
455
|
+
growAfterBranch: false,
|
|
456
|
+
incompleteCapacity: false,
|
|
457
|
+
corruptCapacityComment: false,
|
|
458
|
+
capacityPageSize: 0
|
|
459
|
+
};
|
|
460
|
+
const capacity = [];
|
|
461
|
+
const branchWrites = [];
|
|
462
|
+
const branches = [];
|
|
463
|
+
let points = 2;
|
|
464
|
+
let status = "Queued";
|
|
465
|
+
const statusWrites = [];
|
|
466
|
+
const membershipWrites = [];
|
|
467
|
+
let issueReads = 0;
|
|
468
|
+
const optionId = () => ({ Queued: "TODO", Active: "ACTIVE", Waiting: "BLOCKED", Shipped: "DONE" })[status];
|
|
469
|
+
const values = (number = 17) => [
|
|
470
|
+
{
|
|
471
|
+
issue_field_id: 101,
|
|
472
|
+
issue_field_name: "Estimate",
|
|
473
|
+
data_type: "single_select",
|
|
474
|
+
value: String(controls.livePoints),
|
|
475
|
+
single_select_option: { name: String(controls.livePoints) }
|
|
476
|
+
},
|
|
477
|
+
...controls.capacityMode ? [
|
|
478
|
+
{
|
|
479
|
+
issue_field_id: 102,
|
|
480
|
+
issue_field_name: "Urgency",
|
|
481
|
+
data_type: "single_select",
|
|
482
|
+
single_select_option: {
|
|
483
|
+
name: number === 17 ? "High" : capacity.find((x) => x.number === number)?.value ?? "Low"
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
issue_field_id: 103,
|
|
488
|
+
issue_field_name: "Tags",
|
|
489
|
+
data_type: "multi_select",
|
|
490
|
+
multi_select_options: [{ name: "0" }]
|
|
491
|
+
}
|
|
492
|
+
] : []
|
|
493
|
+
];
|
|
494
|
+
const context = {
|
|
495
|
+
root: "/synthetic-non-git",
|
|
496
|
+
repo: { owner: "example", repo: "widget" },
|
|
497
|
+
config: syntheticDiscoveryConfig,
|
|
498
|
+
projectConfiguration: {
|
|
499
|
+
projectId: "PROJECT",
|
|
500
|
+
projectNumber: 1,
|
|
501
|
+
title: "Delivery",
|
|
502
|
+
writable: true,
|
|
503
|
+
pointsFieldId: "POINTS",
|
|
504
|
+
priorityFieldId: "PRIORITY",
|
|
505
|
+
statusFieldId: "STATUS",
|
|
506
|
+
statusOptionIds: { Todo: "TODO", "In Progress": "ACTIVE", Blocked: "BLOCKED", Done: "DONE" },
|
|
507
|
+
settings: {
|
|
508
|
+
number: 1,
|
|
509
|
+
title: "Delivery",
|
|
510
|
+
statusField: "Flow",
|
|
511
|
+
statuses: { Todo: "Queued", "In Progress": "Active", Blocked: "Waiting", Done: "Shipped" }
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
clients: {
|
|
515
|
+
get role() {
|
|
516
|
+
return controls.role;
|
|
517
|
+
},
|
|
518
|
+
authenticatedAuthor: async () => ({ actorLogin: "operator", credentialIdentity: "user:1" }),
|
|
519
|
+
rest: {
|
|
520
|
+
issues: {
|
|
521
|
+
listSubIssues: async () => ({
|
|
522
|
+
data: controls.trackingParent ? [
|
|
523
|
+
{
|
|
524
|
+
...live,
|
|
525
|
+
number: 18,
|
|
526
|
+
id: 118,
|
|
527
|
+
node_id: "ISSUE18",
|
|
528
|
+
html_url: "https://github.com/example/widget/issues/18",
|
|
529
|
+
url: "https://api.github.com/repos/example/widget/issues/18",
|
|
530
|
+
repository_url: "https://api.github.com/repos/example/widget"
|
|
531
|
+
}
|
|
532
|
+
] : []
|
|
533
|
+
}),
|
|
534
|
+
get: async (input) => {
|
|
535
|
+
if (controls.driftBeforeUpdate && ++issueReads > 1) live.body = "Concurrent operator edit";
|
|
536
|
+
if (input.issue_number === 18 && controls.blockers)
|
|
537
|
+
return {
|
|
538
|
+
data: {
|
|
539
|
+
...live,
|
|
540
|
+
number: 18,
|
|
541
|
+
node_id: "ISSUE18",
|
|
542
|
+
state: controls.blockerClosed ? "closed" : "open",
|
|
543
|
+
html_url: "https://github.com/example/widget/issues/18"
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
if (controls.capacityMode && input.issue_number !== 17) {
|
|
547
|
+
const row = capacity.find((x) => x.number === input.issue_number);
|
|
548
|
+
return {
|
|
549
|
+
data: {
|
|
550
|
+
...live,
|
|
551
|
+
number: row.number,
|
|
552
|
+
node_id: "ISSUE" + String(row.number),
|
|
553
|
+
labels: [row.label],
|
|
554
|
+
html_url: "https://github.com/example/widget/issues/" + String(row.number)
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
return { data: { ...live } };
|
|
559
|
+
},
|
|
560
|
+
listLabelsForRepo: async () => ({ data: [{ name: "critical" }, { name: "other" }] }),
|
|
561
|
+
listForRepo: async (input) => ({
|
|
562
|
+
headers: controls.capacityPageSize && (input.page ?? 1) === 1 ? { link: '<https://api.github.com/repos/example/widget/issues?page=2&per_page=100>; rel="next"' } : {},
|
|
563
|
+
data: controls.capacityMode ? (controls.incompleteCapacity ? [] : [
|
|
564
|
+
{ ...live },
|
|
565
|
+
...capacity.map((x) => ({
|
|
566
|
+
...live,
|
|
567
|
+
number: x.number,
|
|
568
|
+
node_id: "ISSUE" + String(x.number),
|
|
569
|
+
labels: [x.label],
|
|
570
|
+
html_url: "https://github.com/example/widget/issues/" + String(x.number)
|
|
571
|
+
}))
|
|
572
|
+
]).slice(
|
|
573
|
+
((input.page ?? 1) - 1) * (controls.capacityPageSize || input.per_page || 100),
|
|
574
|
+
(input.page ?? 1) * (controls.capacityPageSize || input.per_page || 100)
|
|
575
|
+
) : controls.created ? [{ ...live }] : []
|
|
576
|
+
}),
|
|
577
|
+
create: async (input) => {
|
|
578
|
+
writes.push(input);
|
|
579
|
+
controls.created = true;
|
|
580
|
+
live.title = String(input.title);
|
|
581
|
+
live.body = String(input.body);
|
|
582
|
+
live.type = { name: String(input.type) };
|
|
583
|
+
return {
|
|
584
|
+
data: {
|
|
585
|
+
...live,
|
|
586
|
+
...controls.wrongCreateRepo ? { html_url: "https://github.com/other/widget/issues/17" } : {}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
update: async (input) => {
|
|
591
|
+
writes.push(input);
|
|
592
|
+
if (!controls.ignoreBody && typeof input.body === "string") live.body = input.body;
|
|
593
|
+
if (typeof input.title === "string") live.title = input.title;
|
|
594
|
+
if (typeof input.type === "string") live.type = { name: input.type };
|
|
595
|
+
return { data: { ...live } };
|
|
596
|
+
},
|
|
597
|
+
listComments: async () => ({ data: comments }),
|
|
598
|
+
createComment: async (input) => {
|
|
599
|
+
const comment = {
|
|
600
|
+
id: 91 + comments.length,
|
|
601
|
+
body: input.body,
|
|
602
|
+
html_url: "https://github.com/example/widget/issues/17#issuecomment-" + String(91 + comments.length),
|
|
603
|
+
user: { login: "operator" },
|
|
604
|
+
issue_url: "https://api.github.com/repos/example/widget/issues/17"
|
|
605
|
+
};
|
|
606
|
+
comments.push(comment);
|
|
607
|
+
if (controls.journalFailure) throw new Error("Lost journal response");
|
|
608
|
+
return { data: comment };
|
|
609
|
+
},
|
|
610
|
+
getComment: async (input) => {
|
|
611
|
+
if (controls.driftAfterHistory) live.body = "Concurrent owner content";
|
|
612
|
+
const found = comments.find((c) => c.id === input.comment_id);
|
|
613
|
+
return {
|
|
614
|
+
data: controls.corruptCapacityComment && found ? { ...found, user: { login: "foreign-writer" } } : found
|
|
615
|
+
};
|
|
616
|
+
}
|
|
309
617
|
},
|
|
310
|
-
|
|
311
|
-
|
|
618
|
+
repos: { get: async () => ({ data: { default_branch: "main", node_id: "REPOSITORY" } }) },
|
|
619
|
+
git: { getRef: async () => ({ data: { object: { sha: "a".repeat(40) } } }) },
|
|
620
|
+
request: async (route, input) => {
|
|
621
|
+
if (route === "GET /orgs/{org}/issue-fields")
|
|
622
|
+
return {
|
|
623
|
+
data: [
|
|
312
624
|
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
name: number === 17 ? 'High' : (capacity.find((x) => x.number === number)?.value ?? 'Low'),
|
|
318
|
-
},
|
|
625
|
+
id: 101,
|
|
626
|
+
name: "Estimate",
|
|
627
|
+
data_type: "single_select",
|
|
628
|
+
options: ["1", "2", "4"].map((name) => ({ name }))
|
|
319
629
|
},
|
|
320
630
|
{
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
},
|
|
326
|
-
]
|
|
327
|
-
: []),
|
|
328
|
-
];
|
|
329
|
-
const context = {
|
|
330
|
-
root: '/synthetic-non-git',
|
|
331
|
-
repo: { owner: 'example', repo: 'widget' },
|
|
332
|
-
config: syntheticDiscoveryConfig,
|
|
333
|
-
projectConfiguration: {
|
|
334
|
-
projectId: 'PROJECT',
|
|
335
|
-
projectNumber: 1,
|
|
336
|
-
title: 'Delivery',
|
|
337
|
-
writable: true,
|
|
338
|
-
pointsFieldId: 'POINTS',
|
|
339
|
-
priorityFieldId: 'PRIORITY',
|
|
340
|
-
statusFieldId: 'STATUS',
|
|
341
|
-
statusOptionIds: { Todo: 'TODO', 'In Progress': 'ACTIVE', Blocked: 'BLOCKED', Done: 'DONE' },
|
|
342
|
-
settings: {
|
|
343
|
-
number: 1,
|
|
344
|
-
title: 'Delivery',
|
|
345
|
-
statusField: 'Flow',
|
|
346
|
-
statuses: { Todo: 'Queued', 'In Progress': 'Active', Blocked: 'Waiting', Done: 'Shipped' },
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
clients: {
|
|
350
|
-
get role() {
|
|
351
|
-
return controls.role;
|
|
352
|
-
},
|
|
353
|
-
authenticatedAuthor: async () => ({ actorLogin: 'operator', credentialIdentity: 'user:1' }),
|
|
354
|
-
rest: {
|
|
355
|
-
issues: {
|
|
356
|
-
listSubIssues: async () => ({ data: controls.trackingParent ? [{ number: 18 }] : [] }),
|
|
357
|
-
get: async (input) => {
|
|
358
|
-
if (controls.driftBeforeUpdate && ++issueReads > 1)
|
|
359
|
-
live.body = 'Concurrent operator edit';
|
|
360
|
-
if (controls.capacityMode && input.issue_number !== 17) {
|
|
361
|
-
const row = capacity.find((x) => x.number === input.issue_number);
|
|
362
|
-
return {
|
|
363
|
-
data: {
|
|
364
|
-
...live,
|
|
365
|
-
number: row.number,
|
|
366
|
-
node_id: 'ISSUE' + String(row.number),
|
|
367
|
-
labels: [row.label],
|
|
368
|
-
html_url: 'https://github.com/example/widget/issues/' + String(row.number),
|
|
369
|
-
},
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
return { data: { ...live } };
|
|
373
|
-
},
|
|
374
|
-
listLabelsForRepo: async () => ({ data: [{ name: 'critical' }, { name: 'other' }] }),
|
|
375
|
-
listForRepo: async (input) => ({
|
|
376
|
-
headers: controls.capacityPageSize && (input.page ?? 1) === 1
|
|
377
|
-
? { link: '<https://api.github.com/repos/example/widget/issues?page=2&per_page=100>; rel="next"' }
|
|
378
|
-
: {},
|
|
379
|
-
data: controls.capacityMode
|
|
380
|
-
? (controls.incompleteCapacity
|
|
381
|
-
? []
|
|
382
|
-
: [
|
|
383
|
-
{ ...live },
|
|
384
|
-
...capacity.map((x) => ({
|
|
385
|
-
...live,
|
|
386
|
-
number: x.number,
|
|
387
|
-
node_id: 'ISSUE' + String(x.number),
|
|
388
|
-
labels: [x.label],
|
|
389
|
-
html_url: 'https://github.com/example/widget/issues/' + String(x.number),
|
|
390
|
-
})),
|
|
391
|
-
]).slice(((input.page ?? 1) - 1) * (controls.capacityPageSize || input.per_page || 100), (input.page ?? 1) * (controls.capacityPageSize || input.per_page || 100))
|
|
392
|
-
: controls.created
|
|
393
|
-
? [{ ...live }]
|
|
394
|
-
: [],
|
|
395
|
-
}),
|
|
396
|
-
create: async (input) => {
|
|
397
|
-
writes.push(input);
|
|
398
|
-
controls.created = true;
|
|
399
|
-
live.title = String(input.title);
|
|
400
|
-
live.body = String(input.body);
|
|
401
|
-
live.type = { name: String(input.type) };
|
|
402
|
-
return {
|
|
403
|
-
data: {
|
|
404
|
-
...live,
|
|
405
|
-
...(controls.wrongCreateRepo ? { html_url: 'https://github.com/other/widget/issues/17' } : {}),
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
},
|
|
409
|
-
update: async (input) => {
|
|
410
|
-
writes.push(input);
|
|
411
|
-
if (!controls.ignoreBody && typeof input.body === 'string')
|
|
412
|
-
live.body = input.body;
|
|
413
|
-
if (typeof input.title === 'string')
|
|
414
|
-
live.title = input.title;
|
|
415
|
-
if (typeof input.type === 'string')
|
|
416
|
-
live.type = { name: input.type };
|
|
417
|
-
return { data: { ...live } };
|
|
418
|
-
},
|
|
419
|
-
listComments: async () => ({ data: comments }),
|
|
420
|
-
createComment: async (input) => {
|
|
421
|
-
const comment = {
|
|
422
|
-
id: 91 + comments.length,
|
|
423
|
-
body: input.body,
|
|
424
|
-
html_url: 'https://github.com/example/widget/issues/17#issuecomment-' + String(91 + comments.length),
|
|
425
|
-
user: { login: 'operator' },
|
|
426
|
-
issue_url: 'https://api.github.com/repos/example/widget/issues/17',
|
|
427
|
-
};
|
|
428
|
-
comments.push(comment);
|
|
429
|
-
if (controls.journalFailure)
|
|
430
|
-
throw new Error('Lost journal response');
|
|
431
|
-
return { data: comment };
|
|
432
|
-
},
|
|
433
|
-
getComment: async (input) => {
|
|
434
|
-
if (controls.driftAfterHistory)
|
|
435
|
-
live.body = 'Concurrent owner content';
|
|
436
|
-
const found = comments.find((c) => c.id === input.comment_id);
|
|
437
|
-
return {
|
|
438
|
-
data: controls.corruptCapacityComment && found ? { ...found, user: { login: 'foreign-writer' } } : found,
|
|
439
|
-
};
|
|
440
|
-
},
|
|
631
|
+
id: 102,
|
|
632
|
+
name: "Urgency",
|
|
633
|
+
data_type: "single_select",
|
|
634
|
+
options: ["High", "Low"].map((name) => ({ name }))
|
|
441
635
|
},
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
controls.livePoints = points;
|
|
467
|
-
return { data: values() };
|
|
636
|
+
...controls.capacityMode ? [{ id: 103, name: "Tags", data_type: "multi_select" }] : []
|
|
637
|
+
]
|
|
638
|
+
};
|
|
639
|
+
if (route.startsWith("POST ")) {
|
|
640
|
+
const fields = input.issue_field_values;
|
|
641
|
+
points = Number(fields.find((f) => f.field_id === 101)?.value ?? points);
|
|
642
|
+
controls.livePoints = points;
|
|
643
|
+
return { data: values() };
|
|
644
|
+
}
|
|
645
|
+
if (route.startsWith("GET ")) return { data: values(Number(input.issue_number ?? 17)) };
|
|
646
|
+
throw new Error("Unexpected native request " + route);
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
graphql: async (query, input) => {
|
|
650
|
+
if (query.includes("DeliveryIssueBranches"))
|
|
651
|
+
return {
|
|
652
|
+
repository: {
|
|
653
|
+
issue: {
|
|
654
|
+
linkedBranches: {
|
|
655
|
+
nodes: branches.map((branch) => ({
|
|
656
|
+
ref: {
|
|
657
|
+
name: branch.name,
|
|
658
|
+
target: { oid: branch.sha },
|
|
659
|
+
repository: { nameWithOwner: "example/widget" }
|
|
468
660
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
throw new Error('Unexpected native request ' + route);
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
graphql: async (query, input) => {
|
|
475
|
-
if (query.includes('DeliveryIssueBranches'))
|
|
476
|
-
return {
|
|
477
|
-
repository: {
|
|
478
|
-
issue: {
|
|
479
|
-
linkedBranches: {
|
|
480
|
-
nodes: branches.map((branch) => ({
|
|
481
|
-
ref: {
|
|
482
|
-
name: branch.name,
|
|
483
|
-
target: { oid: branch.sha },
|
|
484
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
485
|
-
},
|
|
486
|
-
})),
|
|
487
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
488
|
-
},
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
};
|
|
492
|
-
if (query.includes('DeliveryStartBranch')) {
|
|
493
|
-
const fields = input.input;
|
|
494
|
-
branchWrites.push(fields);
|
|
495
|
-
branches.push({ name: String(fields.name), sha: String(fields.oid) });
|
|
496
|
-
if (controls.closeAfterBranch)
|
|
497
|
-
live.state = 'closed';
|
|
498
|
-
if (controls.blockAfterBranch)
|
|
499
|
-
controls.blockers = true;
|
|
500
|
-
if (controls.growAfterBranch)
|
|
501
|
-
capacity.push({ number: 99, label: 'critical', value: 'High', status: 'Active' });
|
|
502
|
-
if (controls.branchFailure)
|
|
503
|
-
throw new Error('Lost branch response');
|
|
504
|
-
return { createLinkedBranch: { linkedBranch: { ref: { name: fields.name, target: { oid: fields.oid } } } } };
|
|
505
|
-
}
|
|
506
|
-
if (query.includes('blockedBy(first:'))
|
|
507
|
-
return {
|
|
508
|
-
repository: {
|
|
509
|
-
issue: {
|
|
510
|
-
parent: null,
|
|
511
|
-
blockedBy: {
|
|
512
|
-
nodes: controls.blockers
|
|
513
|
-
? [
|
|
514
|
-
{
|
|
515
|
-
id: 'ISSUE18',
|
|
516
|
-
number: 18,
|
|
517
|
-
title: 'Resolve prerequisite',
|
|
518
|
-
state: 'OPEN',
|
|
519
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
520
|
-
},
|
|
521
|
-
]
|
|
522
|
-
: [],
|
|
523
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
524
|
-
},
|
|
525
|
-
},
|
|
526
|
-
},
|
|
527
|
-
};
|
|
528
|
-
if (query.includes('ProjectDeliveryItems'))
|
|
529
|
-
return {
|
|
530
|
-
organization: {
|
|
531
|
-
projectV2: {
|
|
532
|
-
id: 'PROJECT',
|
|
533
|
-
number: 1,
|
|
534
|
-
items: {
|
|
535
|
-
nodes: [
|
|
536
|
-
...capacity.map((x) => ({
|
|
537
|
-
id: 'ITEM' + String(x.number),
|
|
538
|
-
isArchived: false,
|
|
539
|
-
content: { id: 'ISSUE' + String(x.number) },
|
|
540
|
-
fieldValueByName: x.status === 'Unset'
|
|
541
|
-
? null
|
|
542
|
-
: x.status === 'Missing'
|
|
543
|
-
? undefined
|
|
544
|
-
: { name: x.status, optionId: x.status === 'Active' ? 'ACTIVE' : 'TODO' },
|
|
545
|
-
})),
|
|
546
|
-
{
|
|
547
|
-
id: 'OTHER',
|
|
548
|
-
isArchived: false,
|
|
549
|
-
content: { id: 'OTHER-ISSUE' },
|
|
550
|
-
fieldValueByName: { name: 'Queued', optionId: 'TODO' },
|
|
551
|
-
},
|
|
552
|
-
...(controls.projectMember
|
|
553
|
-
? [
|
|
554
|
-
{
|
|
555
|
-
id: 'ITEM17',
|
|
556
|
-
isArchived: controls.projectArchived,
|
|
557
|
-
content: { id: 'ISSUE17' },
|
|
558
|
-
fieldValueByName: { name: status, optionId: optionId() },
|
|
559
|
-
},
|
|
560
|
-
]
|
|
561
|
-
: []),
|
|
562
|
-
],
|
|
563
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
564
|
-
},
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
};
|
|
568
|
-
if (query.includes('AddProjectDeliveryItem')) {
|
|
569
|
-
membershipWrites.push(input);
|
|
570
|
-
assert.equal(input.projectId, 'PROJECT');
|
|
571
|
-
assert.equal(input.contentId, 'ISSUE17');
|
|
572
|
-
controls.projectMember = true;
|
|
573
|
-
return { addProjectV2ItemById: { item: { id: 'ITEM17' } } };
|
|
661
|
+
})),
|
|
662
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
574
663
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
if (query.includes("DeliveryStartBranch")) {
|
|
668
|
+
const fields = input.input;
|
|
669
|
+
branchWrites.push(fields);
|
|
670
|
+
branches.push({ name: String(fields.name), sha: String(fields.oid) });
|
|
671
|
+
if (controls.closeAfterBranch) live.state = "closed";
|
|
672
|
+
if (controls.blockAfterBranch) controls.blockers = true;
|
|
673
|
+
if (controls.growAfterBranch)
|
|
674
|
+
capacity.push({ number: 99, label: "critical", value: "High", status: "Active" });
|
|
675
|
+
if (controls.branchFailure) throw new Error("Lost branch response");
|
|
676
|
+
return { createLinkedBranch: { linkedBranch: { ref: { name: fields.name, target: { oid: fields.oid } } } } };
|
|
677
|
+
}
|
|
678
|
+
if (query.includes("blockedBy(first:"))
|
|
679
|
+
return {
|
|
680
|
+
repository: {
|
|
681
|
+
issue: {
|
|
682
|
+
id: controls.missingNative ? void 0 : "ISSUE17",
|
|
683
|
+
number: 17,
|
|
684
|
+
repository: { nameWithOwner: "example/widget" },
|
|
685
|
+
parent: null,
|
|
686
|
+
blockedBy: {
|
|
687
|
+
nodes: controls.blockers ? [
|
|
688
|
+
{
|
|
689
|
+
id: "ISSUE18",
|
|
690
|
+
number: 18,
|
|
691
|
+
title: "Resolve prerequisite",
|
|
692
|
+
state: controls.blockerClosed && !controls.blockerConflict ? "CLOSED" : "OPEN",
|
|
693
|
+
repository: { nameWithOwner: "example/widget" }
|
|
694
|
+
}
|
|
695
|
+
] : [],
|
|
696
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
586
697
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
if (query.includes("ProjectDeliveryIssueItems"))
|
|
702
|
+
return issueProjectItemsResponse(
|
|
703
|
+
input,
|
|
704
|
+
[
|
|
705
|
+
...capacity.map((x) => ({
|
|
706
|
+
id: "ITEM" + String(x.number),
|
|
707
|
+
isArchived: false,
|
|
708
|
+
content: { id: "ISSUE" + String(x.number) },
|
|
709
|
+
fieldValueByName: x.status === "Unset" ? null : x.status === "Missing" ? void 0 : { name: x.status, optionId: x.status === "Active" ? "ACTIVE" : "TODO" }
|
|
710
|
+
})),
|
|
711
|
+
{
|
|
712
|
+
id: "OTHER",
|
|
713
|
+
isArchived: false,
|
|
714
|
+
content: { id: "OTHER-ISSUE" },
|
|
715
|
+
fieldValueByName: { name: "Queued", optionId: "TODO" }
|
|
716
|
+
},
|
|
717
|
+
...controls.projectMember ? [
|
|
718
|
+
{
|
|
719
|
+
id: "ITEM17",
|
|
720
|
+
isArchived: controls.projectArchived,
|
|
721
|
+
content: { id: "ISSUE17" },
|
|
722
|
+
fieldValueByName: { name: status, optionId: optionId() }
|
|
610
723
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
724
|
+
] : []
|
|
725
|
+
].filter((item) => item.content.id === input.issueNodeId)
|
|
726
|
+
);
|
|
727
|
+
if (query.includes("AddProjectDeliveryItem")) {
|
|
728
|
+
membershipWrites.push(input);
|
|
729
|
+
assert.equal(input.projectId, "PROJECT");
|
|
730
|
+
assert.equal(input.contentId, "ISSUE17");
|
|
731
|
+
controls.projectMember = true;
|
|
732
|
+
return { addProjectV2ItemById: { item: { id: "ITEM17" } } };
|
|
733
|
+
}
|
|
734
|
+
if (query.includes("UpdateProjectDeliveryStatus")) {
|
|
735
|
+
statusWrites.push(input);
|
|
736
|
+
assert.equal(input.projectId, "PROJECT");
|
|
737
|
+
assert.equal(input.itemId, "ITEM17");
|
|
738
|
+
assert.equal(input.fieldId, "STATUS");
|
|
739
|
+
if (input.optionId === "ACTIVE" && controls.projectFailure === "before")
|
|
740
|
+
throw new Error("Project write failed");
|
|
741
|
+
status = input.optionId === "TODO" ? "Queued" : input.optionId === "DONE" ? "Shipped" : input.optionId === "BLOCKED" ? "Waiting" : "Active";
|
|
742
|
+
if (input.optionId === "ACTIVE" && controls.projectFailure === "after")
|
|
743
|
+
throw new Error("Lost Project response");
|
|
744
|
+
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: "ITEM17" } } };
|
|
745
|
+
}
|
|
746
|
+
if (query.includes("ProjectDeliveryItemReadback")) {
|
|
747
|
+
const number = Number(String(input.itemId).replace("ITEM", ""));
|
|
748
|
+
const selected = number === 17 ? status : capacity.find((x) => x.number === number)?.status;
|
|
749
|
+
return {
|
|
750
|
+
node: {
|
|
751
|
+
id: input.itemId,
|
|
752
|
+
isArchived: false,
|
|
753
|
+
project: { id: "PROJECT", number: 1 },
|
|
754
|
+
content: {
|
|
755
|
+
id: status === "Active" && controls.projectFailure === "readback" ? "OTHER-ISSUE" : "ISSUE" + String(number)
|
|
756
|
+
},
|
|
757
|
+
fieldValueByName: selected === "Unset" ? null : selected === "Missing" ? void 0 : {
|
|
758
|
+
name: selected,
|
|
759
|
+
optionId: number === 17 ? optionId() : selected === "Active" ? "ACTIVE" : "TODO"
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
const quiet = quietReadViewResponse(query, input);
|
|
765
|
+
if (quiet !== void 0) return quiet;
|
|
766
|
+
throw new Error("Unexpected native query " + query);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
return {
|
|
771
|
+
context,
|
|
772
|
+
capacity,
|
|
773
|
+
live,
|
|
774
|
+
writes,
|
|
775
|
+
comments,
|
|
776
|
+
controls,
|
|
777
|
+
branches,
|
|
778
|
+
branchWrites,
|
|
779
|
+
statusWrites,
|
|
780
|
+
membershipWrites,
|
|
781
|
+
getStatus: () => status,
|
|
782
|
+
setStatus: (value) => {
|
|
783
|
+
status = value;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
631
786
|
}
|
|
632
|
-
test(
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
assert.equal(f.getStatus(), 'Active');
|
|
787
|
+
test("manual deferral survives other updates and past dates, appears in reads, and blocks all start writes", async () => {
|
|
788
|
+
const f = fixture();
|
|
789
|
+
const footer = "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
|
|
790
|
+
f.live.body += footer;
|
|
791
|
+
const condition = { until: "2020-01-01", trigger: "Upstream ships the prerequisite." };
|
|
792
|
+
const patch = getAiDeliveryMcpTool("issue_update").inputSchema.parse({ issueNumber: 17, defer: condition });
|
|
793
|
+
const deferred = await updateIssue(f.context, patch);
|
|
794
|
+
assert.deepEqual(Reflect.get(deferred, "deferred"), condition);
|
|
795
|
+
assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), "deferred"), condition);
|
|
796
|
+
assert.deepEqual(Reflect.get((await listIssues(f.context, {})).issues[0], "deferred"), condition);
|
|
797
|
+
const saved = parseIssueBody(deferred.body, { title: f.live.title }).issue;
|
|
798
|
+
assert.ok(deferred.body.endsWith(footer));
|
|
799
|
+
assert.deepEqual(Reflect.get(saved, "deferral"), condition);
|
|
800
|
+
assert.match(deferred.body, /Deferred/u);
|
|
801
|
+
assert.equal((await readyCheck(f.context, 17)).ready, false);
|
|
802
|
+
await updateIssue(f.context, { issueNumber: 17, status: { nextMilestone: "Wait for upstream" } });
|
|
803
|
+
assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), "deferred"), condition);
|
|
804
|
+
assert.ok(f.live.body.endsWith(footer));
|
|
805
|
+
const writes = f.writes.length;
|
|
806
|
+
const comments = f.comments.length;
|
|
807
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /deferred|undefer/iu);
|
|
808
|
+
assert.equal(f.branchWrites.length, 0);
|
|
809
|
+
assert.equal(f.statusWrites.filter((x) => x.optionId === "ACTIVE").length, 0);
|
|
810
|
+
assert.equal(f.writes.length, writes);
|
|
811
|
+
assert.equal(f.comments.length, comments);
|
|
812
|
+
const clear = { issueNumber: 17, undefer: true };
|
|
813
|
+
const resumed = await updateIssue(f.context, clear);
|
|
814
|
+
assert.equal(Reflect.get(resumed, "deferred"), null);
|
|
815
|
+
assert.ok(resumed.body.endsWith(footer));
|
|
816
|
+
assert.deepEqual(
|
|
817
|
+
parseIssueBody(resumed.body, { title: f.live.title }).issue.acceptanceCriteria,
|
|
818
|
+
saved.acceptanceCriteria
|
|
819
|
+
);
|
|
820
|
+
assert.equal((await readyCheck(f.context, 17)).ready, true);
|
|
821
|
+
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
822
|
+
assert.equal(f.branchWrites.length, 1);
|
|
823
|
+
assert.equal(f.getStatus(), "Active");
|
|
670
824
|
});
|
|
671
|
-
test(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
825
|
+
test("canonical new-start intent preserves supplied deferral rather than silently resuming it", async () => {
|
|
826
|
+
const deferred = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: "Explicit undefer" } }));
|
|
827
|
+
const canonical = canonicalIssueBody({ ...ready(), body: deferred });
|
|
828
|
+
assert.deepEqual(Reflect.get(parseIssueBody(canonical, { title: ready().title }).issue, "deferral"), {
|
|
829
|
+
trigger: "Explicit undefer"
|
|
830
|
+
});
|
|
831
|
+
const f = fixture();
|
|
832
|
+
f.controls.created = false;
|
|
833
|
+
const request = { ...ready(), body: deferred };
|
|
834
|
+
const first = await startTrackedIssue(f.context, request);
|
|
835
|
+
assert.equal(Reflect.get(first, "status"), "created-not-started");
|
|
836
|
+
assert.deepEqual(Reflect.get(parseIssueBody(f.live.body, { title: f.live.title }).issue, "deferral"), {
|
|
837
|
+
trigger: "Explicit undefer"
|
|
838
|
+
});
|
|
839
|
+
await startTrackedIssue(f.context, request);
|
|
840
|
+
assert.equal(f.writes.filter((write) => !Object.hasOwn(write, "issue_number")).length, 1);
|
|
841
|
+
assert.equal(f.branchWrites.length, 0);
|
|
842
|
+
});
|
|
843
|
+
test("WIP partial Project acknowledgment preserves the exact reason and reuses its authored comment", async () => {
|
|
844
|
+
const f = fixture();
|
|
845
|
+
f.controls.capacityMode = true;
|
|
846
|
+
f.live.labels = ["critical"];
|
|
847
|
+
f.context.config = {
|
|
848
|
+
...f.context.config,
|
|
849
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
850
|
+
};
|
|
851
|
+
f.controls.projectFailure = "after";
|
|
852
|
+
const result = await startTrackedIssue(f.context, {
|
|
853
|
+
issueNumber: 17,
|
|
854
|
+
overrideReason: "Approved synthetic exception."
|
|
855
|
+
});
|
|
856
|
+
assert.equal(Reflect.get(result, "status"), "start-incomplete");
|
|
857
|
+
const recovery = result;
|
|
858
|
+
assert.ok(recovery.safeResume);
|
|
859
|
+
const resume = recovery.safeResume.arguments;
|
|
860
|
+
assert.equal(resume.overrideReason, "Approved synthetic exception.");
|
|
861
|
+
assert.equal(f.comments.length, 1);
|
|
862
|
+
f.controls.projectFailure = "";
|
|
863
|
+
await startTrackedIssue(f.context, resume);
|
|
864
|
+
assert.equal(f.branchWrites.length, 1);
|
|
865
|
+
assert.equal(f.statusWrites.length, 1);
|
|
866
|
+
assert.equal(f.comments.length, 2);
|
|
867
|
+
});
|
|
868
|
+
test("deferral remains orthogonal to park and only explicit undefer clears it", async () => {
|
|
869
|
+
const f = fixture();
|
|
870
|
+
const patch = { issueNumber: 17, defer: {} };
|
|
871
|
+
await updateIssue(f.context, patch);
|
|
872
|
+
const parked = await updateIssue(f.context, { issueNumber: 17, park: true });
|
|
873
|
+
assert.deepEqual(Reflect.get(parked, "deferred"), {});
|
|
874
|
+
assert.equal(parseIssueBody(parked.body, { title: parked.title }).issue.draft, true);
|
|
875
|
+
const clear = { issueNumber: 17, undefer: true };
|
|
876
|
+
const cleared = await updateIssue(f.context, clear);
|
|
877
|
+
assert.equal(Reflect.get(cleared, "deferred"), null);
|
|
878
|
+
assert.equal(parseIssueBody(cleared.body, { title: cleared.title }).issue.draft, true);
|
|
879
|
+
assert.equal((await readyCheck(f.context, 17)).ready, false);
|
|
688
880
|
});
|
|
689
|
-
test(
|
|
881
|
+
test("deferral inputs reject invalid dates, empty reasons, conflicts and direct canonical bypass before writes", async () => {
|
|
882
|
+
const schema = getAiDeliveryMcpTool("issue_update").inputSchema;
|
|
883
|
+
assert.doesNotThrow(() => schema.parse({ issueNumber: 17, defer: { until: "2026-10-17" } }));
|
|
884
|
+
for (const input of [
|
|
885
|
+
{ defer: { until: "2026-02-30" } },
|
|
886
|
+
{ defer: { until: "tomorrow" } },
|
|
887
|
+
{ defer: { trigger: " " } },
|
|
888
|
+
{ defer: {}, undefer: true },
|
|
889
|
+
{ deferral: {} },
|
|
890
|
+
{ undefer: false }
|
|
891
|
+
])
|
|
892
|
+
assert.throws(() => schema.parse({ issueNumber: 17, ...input }));
|
|
893
|
+
const f = fixture();
|
|
894
|
+
const conflicting = { issueNumber: 17, defer: {}, undefer: true };
|
|
895
|
+
await assert.rejects(updateIssue(f.context, conflicting));
|
|
896
|
+
assert.equal(f.writes.length, 0);
|
|
897
|
+
assert.equal(f.comments.length, 0);
|
|
898
|
+
});
|
|
899
|
+
test("WIP label and field lanes reject full capacity before creating a branch or journal", async () => {
|
|
900
|
+
for (const match of [{ label: "critical" }, { field: "Urgency", value: "High" }]) {
|
|
690
901
|
const f = fixture();
|
|
691
902
|
f.controls.capacityMode = true;
|
|
692
|
-
f.live.labels = [
|
|
903
|
+
f.live.labels = ["critical"];
|
|
693
904
|
f.context.config = {
|
|
694
|
-
|
|
695
|
-
|
|
905
|
+
...f.context.config,
|
|
906
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match, limit: 1 }]
|
|
696
907
|
};
|
|
697
|
-
f.
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
});
|
|
702
|
-
assert.equal(Reflect.get(result, 'status'), 'start-incomplete');
|
|
703
|
-
const recovery = result;
|
|
704
|
-
assert.ok(recovery.safeResume);
|
|
705
|
-
const resume = recovery.safeResume.arguments;
|
|
706
|
-
assert.equal(resume.overrideReason, 'Approved synthetic exception.');
|
|
707
|
-
assert.equal(f.comments.length, 1);
|
|
708
|
-
f.controls.projectFailure = '';
|
|
709
|
-
await startTrackedIssue(f.context, resume);
|
|
710
|
-
assert.equal(f.branchWrites.length, 1);
|
|
711
|
-
assert.equal(f.statusWrites.length, 1);
|
|
712
|
-
assert.equal(f.comments.length, 2);
|
|
713
|
-
});
|
|
714
|
-
test('deferral remains orthogonal to park and only explicit undefer clears it', async () => {
|
|
715
|
-
const f = fixture();
|
|
716
|
-
const patch = { issueNumber: 17, defer: {} };
|
|
717
|
-
await updateIssue(f.context, patch);
|
|
718
|
-
const parked = await updateIssue(f.context, { issueNumber: 17, park: true });
|
|
719
|
-
assert.deepEqual(Reflect.get(parked, 'deferred'), {});
|
|
720
|
-
assert.equal(parseIssueBody(parked.body, { title: parked.title }).issue.draft, true);
|
|
721
|
-
const clear = { issueNumber: 17, undefer: true };
|
|
722
|
-
const cleared = await updateIssue(f.context, clear);
|
|
723
|
-
assert.equal(Reflect.get(cleared, 'deferred'), null);
|
|
724
|
-
assert.equal(parseIssueBody(cleared.body, { title: cleared.title }).issue.draft, true);
|
|
725
|
-
assert.equal((await readyCheck(f.context, 17)).ready, false);
|
|
726
|
-
});
|
|
727
|
-
test('deferral inputs reject invalid dates, empty reasons, conflicts and direct canonical bypass before writes', async () => {
|
|
728
|
-
const schema = getAiDeliveryMcpTool('issue_update').inputSchema;
|
|
729
|
-
assert.doesNotThrow(() => schema.parse({ issueNumber: 17, defer: { until: '2026-10-17' } }));
|
|
730
|
-
for (const input of [
|
|
731
|
-
{ defer: { until: '2026-02-30' } },
|
|
732
|
-
{ defer: { until: 'tomorrow' } },
|
|
733
|
-
{ defer: { trigger: ' ' } },
|
|
734
|
-
{ defer: {}, undefer: true },
|
|
735
|
-
{ deferral: {} },
|
|
736
|
-
{ undefer: false },
|
|
737
|
-
])
|
|
738
|
-
assert.throws(() => schema.parse({ issueNumber: 17, ...input }));
|
|
739
|
-
const f = fixture();
|
|
740
|
-
const conflicting = { issueNumber: 17, defer: {}, undefer: true };
|
|
741
|
-
await assert.rejects(updateIssue(f.context, conflicting));
|
|
742
|
-
assert.equal(f.writes.length, 0);
|
|
908
|
+
f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
|
|
909
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity|limit/u);
|
|
910
|
+
assert.equal(f.branchWrites.length, 0);
|
|
911
|
+
assert.equal(f.statusWrites.length, 0);
|
|
743
912
|
assert.equal(f.comments.length, 0);
|
|
913
|
+
}
|
|
744
914
|
});
|
|
745
|
-
test(
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
915
|
+
test("WIP rechecks after branch creation, retains that identity, and only admits a recorded capacity override", async () => {
|
|
916
|
+
const f = fixture();
|
|
917
|
+
f.controls.capacityMode = true;
|
|
918
|
+
f.controls.growAfterBranch = true;
|
|
919
|
+
f.live.labels = ["critical"];
|
|
920
|
+
f.context.config = {
|
|
921
|
+
...f.context.config,
|
|
922
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
923
|
+
};
|
|
924
|
+
const refused = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
925
|
+
assert.equal(Reflect.get(refused, "status"), "start-incomplete");
|
|
926
|
+
assert.equal(f.branchWrites.length, 1);
|
|
927
|
+
assert.equal(f.statusWrites.length, 0);
|
|
928
|
+
assert.equal(f.comments.length, 0);
|
|
929
|
+
f.controls.growAfterBranch = false;
|
|
930
|
+
await startTrackedIssue(f.context, {
|
|
931
|
+
issueNumber: 17,
|
|
932
|
+
overrideReason: "Operator authorizes this synthetic capacity exception."
|
|
933
|
+
});
|
|
934
|
+
assert.equal(f.branchWrites.length, 1);
|
|
935
|
+
assert.equal(f.getStatus(), "Active");
|
|
936
|
+
assert.equal(f.comments.length, 2);
|
|
937
|
+
assert.match(f.comments[0].body, /Operator authorizes this synthetic capacity exception/u);
|
|
938
|
+
assert.match(f.comments[0].body, /"count": 1/u);
|
|
939
|
+
assert.match(f.comments[0].body, /"limit": 1/u);
|
|
940
|
+
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
941
|
+
assert.equal(f.comments.length, 2);
|
|
760
942
|
});
|
|
761
|
-
test(
|
|
943
|
+
test("WIP capacity override refuses a mismatched native comment author and reconciles lost comment responses", async () => {
|
|
944
|
+
for (const failure of ["author", "response"]) {
|
|
762
945
|
const f = fixture();
|
|
763
946
|
f.controls.capacityMode = true;
|
|
764
|
-
f.
|
|
765
|
-
f.live.labels = ['critical'];
|
|
947
|
+
f.live.labels = ["critical"];
|
|
766
948
|
f.context.config = {
|
|
767
|
-
|
|
768
|
-
|
|
949
|
+
...f.context.config,
|
|
950
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
769
951
|
};
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
952
|
+
f.controls.corruptCapacityComment = failure === "author";
|
|
953
|
+
f.controls.journalFailure = failure === "response";
|
|
954
|
+
const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity authorization." };
|
|
955
|
+
const refused = await startTrackedIssue(f.context, input);
|
|
956
|
+
assert.equal(Reflect.get(refused, "status"), "start-incomplete");
|
|
957
|
+
assert.equal(f.getStatus(), "Queued");
|
|
773
958
|
assert.equal(f.statusWrites.length, 0);
|
|
774
|
-
assert.equal(f.comments.length,
|
|
775
|
-
f.controls.
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
});
|
|
780
|
-
assert.equal(f.branchWrites.length, 1);
|
|
781
|
-
assert.equal(f.getStatus(), 'Active');
|
|
782
|
-
assert.equal(f.comments.length, 2);
|
|
783
|
-
assert.match(f.comments[0].body, /Operator authorizes this synthetic capacity exception/u);
|
|
784
|
-
assert.match(f.comments[0].body, /"count": 1/u);
|
|
785
|
-
assert.match(f.comments[0].body, /"limit": 1/u);
|
|
786
|
-
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
959
|
+
assert.equal(f.comments.length, 1);
|
|
960
|
+
f.controls.corruptCapacityComment = false;
|
|
961
|
+
f.controls.journalFailure = false;
|
|
962
|
+
await startTrackedIssue(f.context, input);
|
|
963
|
+
assert.equal(f.getStatus(), "Active");
|
|
787
964
|
assert.equal(f.comments.length, 2);
|
|
965
|
+
assert.equal(f.branchWrites.length, 1);
|
|
966
|
+
}
|
|
788
967
|
});
|
|
789
|
-
test(
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
f.controls.capacityMode = true;
|
|
793
|
-
f.live.labels = ['critical'];
|
|
794
|
-
f.context.config = {
|
|
795
|
-
...f.context.config,
|
|
796
|
-
wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
|
|
797
|
-
};
|
|
798
|
-
f.controls.corruptCapacityComment = failure === 'author';
|
|
799
|
-
f.controls.journalFailure = failure === 'response';
|
|
800
|
-
const input = { issueNumber: 17, overrideReason: 'Explicit synthetic capacity authorization.' };
|
|
801
|
-
const refused = await startTrackedIssue(f.context, input);
|
|
802
|
-
assert.equal(Reflect.get(refused, 'status'), 'start-incomplete');
|
|
803
|
-
assert.equal(f.getStatus(), 'Queued');
|
|
804
|
-
assert.equal(f.statusWrites.length, 0);
|
|
805
|
-
assert.equal(f.comments.length, 1);
|
|
806
|
-
f.controls.corruptCapacityComment = false;
|
|
807
|
-
f.controls.journalFailure = false;
|
|
808
|
-
await startTrackedIssue(f.context, input);
|
|
809
|
-
assert.equal(f.getStatus(), 'Active');
|
|
810
|
-
assert.equal(f.comments.length, 2);
|
|
811
|
-
assert.equal(f.branchWrites.length, 1);
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
test.each(['edited', 'exact-and-edited'])('WIP override retry refuses %s authored evidence with the same operation marker', async (mode) => {
|
|
968
|
+
test.each(["edited", "exact-and-edited"])(
|
|
969
|
+
"WIP override retry refuses %s authored evidence with the same operation marker",
|
|
970
|
+
async (mode) => {
|
|
815
971
|
const f = fixture();
|
|
816
972
|
f.controls.capacityMode = true;
|
|
817
|
-
f.live.labels = [
|
|
973
|
+
f.live.labels = ["critical"];
|
|
818
974
|
f.context.config = {
|
|
819
|
-
|
|
820
|
-
|
|
975
|
+
...f.context.config,
|
|
976
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
821
977
|
};
|
|
822
978
|
f.controls.journalFailure = true;
|
|
823
|
-
const input = { issueNumber: 17, overrideReason:
|
|
824
|
-
assert.equal(Reflect.get(await startTrackedIssue(f.context, input),
|
|
979
|
+
const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity authorization." };
|
|
980
|
+
assert.equal(Reflect.get(await startTrackedIssue(f.context, input), "status"), "start-incomplete");
|
|
825
981
|
assert.equal(f.comments.length, 1);
|
|
826
982
|
const original = f.comments[0];
|
|
827
|
-
const edited = original.body.replace(
|
|
828
|
-
if (mode ===
|
|
829
|
-
original.body = edited;
|
|
983
|
+
const edited = original.body.replace("WIP capacity override.", "Edited capacity override.");
|
|
984
|
+
if (mode === "edited") original.body = edited;
|
|
830
985
|
else
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
986
|
+
f.comments.push({
|
|
987
|
+
...original,
|
|
988
|
+
id: 92,
|
|
989
|
+
html_url: "https://github.com/example/widget/issues/17#issuecomment-92",
|
|
990
|
+
body: edited
|
|
991
|
+
});
|
|
837
992
|
const before = structuredClone(f.comments);
|
|
838
993
|
f.controls.journalFailure = false;
|
|
839
994
|
const result = await startTrackedIssue(f.context, input);
|
|
840
|
-
assert.equal(Reflect.get(result,
|
|
841
|
-
assert.match(Reflect.get(result,
|
|
995
|
+
assert.equal(Reflect.get(result, "status"), "start-incomplete");
|
|
996
|
+
assert.match(Reflect.get(result, "failure").message, /conflict|duplicate|override/iu);
|
|
842
997
|
assert.deepEqual(f.comments, before);
|
|
843
998
|
assert.equal(f.branchWrites.length, 1);
|
|
844
999
|
assert.equal(f.statusWrites.length, 0);
|
|
845
|
-
assert.equal(f.getStatus(),
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
f.context.
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
1000
|
+
assert.equal(f.getStatus(), "Queued");
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
1003
|
+
test.each(
|
|
1004
|
+
["text", "number", "date", "single_select", "multi_select"].flatMap(
|
|
1005
|
+
(type) => [17, 18].map((number) => ({ type, number }))
|
|
1006
|
+
)
|
|
1007
|
+
)("WIP refuses omitted $type payload on issue $number even with an override reason", async ({ type, number }) => {
|
|
1008
|
+
const f = fixture();
|
|
1009
|
+
f.controls.capacityMode = true;
|
|
1010
|
+
f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
|
|
1011
|
+
const value = type === "number" ? 1 : type === "date" ? "2026-10-17" : "High";
|
|
1012
|
+
f.context.config = {
|
|
1013
|
+
...f.context.config,
|
|
1014
|
+
wipLimits: [{ repository: "example/widget", name: "Urgent work", match: { field: "Urgency", value }, limit: 1 }]
|
|
1015
|
+
};
|
|
1016
|
+
let capacityReadStarted = false;
|
|
1017
|
+
const list = f.context.clients.rest.issues.listForRepo;
|
|
1018
|
+
f.context.clients.rest.issues.listForRepo = (async (input) => {
|
|
1019
|
+
capacityReadStarted = true;
|
|
1020
|
+
return list(input);
|
|
1021
|
+
});
|
|
1022
|
+
const request = f.context.clients.rest.request;
|
|
1023
|
+
f.context.clients.rest.request = (async (route, input) => {
|
|
1024
|
+
const response = await request(route, input);
|
|
1025
|
+
if (!capacityReadStarted || typeof route !== "string" || !route.startsWith("GET ")) return response;
|
|
1026
|
+
const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
|
|
1027
|
+
const catalog = route === "GET /orgs/{org}/issue-fields";
|
|
1028
|
+
return {
|
|
1029
|
+
...response,
|
|
1030
|
+
data: rows.map((row) => {
|
|
1031
|
+
if ((catalog ? row.id : row.issue_field_id) !== 102) return row;
|
|
1032
|
+
if (catalog) return { ...row, data_type: type };
|
|
869
1033
|
return {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
if (catalog)
|
|
875
|
-
return { ...row, data_type: type };
|
|
876
|
-
return {
|
|
877
|
-
issue_field_id: 102,
|
|
878
|
-
issue_field_name: 'Urgency',
|
|
879
|
-
data_type: type,
|
|
880
|
-
...(input?.issue_number === number
|
|
881
|
-
? {}
|
|
882
|
-
: type === 'single_select'
|
|
883
|
-
? { single_select_option: { name: value } }
|
|
884
|
-
: type === 'multi_select'
|
|
885
|
-
? { multi_select_options: [{ name: value }] }
|
|
886
|
-
: { value }),
|
|
887
|
-
};
|
|
888
|
-
}),
|
|
1034
|
+
issue_field_id: 102,
|
|
1035
|
+
issue_field_name: "Urgency",
|
|
1036
|
+
data_type: type,
|
|
1037
|
+
...input?.issue_number === number ? {} : type === "single_select" ? { single_select_option: { name: value } } : type === "multi_select" ? { multi_select_options: [{ name: value }] } : { value }
|
|
889
1038
|
};
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1039
|
+
})
|
|
1040
|
+
};
|
|
1041
|
+
});
|
|
1042
|
+
await assert.rejects(
|
|
1043
|
+
startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity cannot override missing evidence." }),
|
|
1044
|
+
/capacity|payload|field/iu
|
|
1045
|
+
);
|
|
1046
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1047
|
+
assert.equal(f.statusWrites.length, 0);
|
|
1048
|
+
assert.equal(f.membershipWrites.length, 0);
|
|
1049
|
+
assert.equal(f.comments.length, 0);
|
|
896
1050
|
});
|
|
897
|
-
test.each([
|
|
1051
|
+
test.each(["absent", "null", "empty-multi"])(
|
|
1052
|
+
"WIP accepts complete native %s peer values as nonmatching",
|
|
1053
|
+
async (mode) => {
|
|
898
1054
|
const f = fixture();
|
|
899
1055
|
f.controls.capacityMode = true;
|
|
900
|
-
f.capacity.push({ number: 18, label:
|
|
901
|
-
const multi = mode ===
|
|
1056
|
+
f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
|
|
1057
|
+
const multi = mode === "empty-multi";
|
|
902
1058
|
f.context.config = {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1059
|
+
...f.context.config,
|
|
1060
|
+
wipLimits: [
|
|
1061
|
+
{
|
|
1062
|
+
repository: "example/widget",
|
|
1063
|
+
name: "Urgent work",
|
|
1064
|
+
match: { field: multi ? "Tags" : "Urgency", value: multi ? "0" : "High" },
|
|
1065
|
+
limit: 1
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
912
1068
|
};
|
|
913
1069
|
const request = f.context.clients.rest.request;
|
|
914
1070
|
f.context.clients.rest.request = (async (route, input) => {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
]),
|
|
933
|
-
};
|
|
1071
|
+
const response = await request(route, input);
|
|
1072
|
+
if (typeof route !== "string" || !route.endsWith("/issue-field-values") || input?.issue_number !== 18)
|
|
1073
|
+
return response;
|
|
1074
|
+
const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
|
|
1075
|
+
return {
|
|
1076
|
+
...response,
|
|
1077
|
+
data: rows.flatMap(
|
|
1078
|
+
(row) => row.issue_field_id !== (multi ? 103 : 102) ? [row] : mode === "absent" ? [] : [
|
|
1079
|
+
{
|
|
1080
|
+
issue_field_id: row.issue_field_id,
|
|
1081
|
+
issue_field_name: row.issue_field_name,
|
|
1082
|
+
data_type: row.data_type,
|
|
1083
|
+
...multi ? { multi_select_options: [] } : { value: null }
|
|
1084
|
+
}
|
|
1085
|
+
]
|
|
1086
|
+
)
|
|
1087
|
+
};
|
|
934
1088
|
});
|
|
935
1089
|
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
936
|
-
assert.equal(f.getStatus(),
|
|
1090
|
+
assert.equal(f.getStatus(), "Active");
|
|
937
1091
|
assert.equal(f.branchWrites.length, 1);
|
|
938
1092
|
assert.equal(f.comments.length, 1);
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
f.controls.capacityMode = true;
|
|
944
|
-
f.controls.incompleteCapacity = failure === 'target';
|
|
945
|
-
f.context.config = {
|
|
946
|
-
...f.context.config,
|
|
947
|
-
wipLimits: [
|
|
948
|
-
{
|
|
949
|
-
repository: 'example/widget',
|
|
950
|
-
name: 'Urgent work',
|
|
951
|
-
match: { field: failure === 'field' ? 'Nonexistent lane field' : 'Urgency', value: 'High' },
|
|
952
|
-
limit: 2,
|
|
953
|
-
},
|
|
954
|
-
],
|
|
955
|
-
};
|
|
956
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Cannot authorize missing evidence.' }), /capacity|field|target|WIP/iu);
|
|
957
|
-
assert.equal(f.branchWrites.length, 0);
|
|
958
|
-
assert.equal(f.comments.length, 0);
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
test('WIP follows native continuation evidence even when a page is short', async () => {
|
|
1093
|
+
}
|
|
1094
|
+
);
|
|
1095
|
+
test("WIP missing target and unknown native field evidence refuse rather than counting zero", async () => {
|
|
1096
|
+
for (const failure of ["target", "field"]) {
|
|
962
1097
|
const f = fixture();
|
|
963
1098
|
f.controls.capacityMode = true;
|
|
964
|
-
f.controls.
|
|
965
|
-
f.live.labels = ['critical'];
|
|
1099
|
+
f.controls.incompleteCapacity = failure === "target";
|
|
966
1100
|
f.context.config = {
|
|
967
|
-
|
|
968
|
-
|
|
1101
|
+
...f.context.config,
|
|
1102
|
+
wipLimits: [
|
|
1103
|
+
{
|
|
1104
|
+
repository: "example/widget",
|
|
1105
|
+
name: "Urgent work",
|
|
1106
|
+
match: { field: failure === "field" ? "Nonexistent lane field" : "Urgency", value: "High" },
|
|
1107
|
+
limit: 2
|
|
1108
|
+
}
|
|
1109
|
+
]
|
|
969
1110
|
};
|
|
970
|
-
|
|
971
|
-
|
|
1111
|
+
await assert.rejects(
|
|
1112
|
+
startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Cannot authorize missing evidence." }),
|
|
1113
|
+
/capacity|field|target|WIP/iu
|
|
1114
|
+
);
|
|
972
1115
|
assert.equal(f.branchWrites.length, 0);
|
|
1116
|
+
assert.equal(f.comments.length, 0);
|
|
1117
|
+
}
|
|
973
1118
|
});
|
|
974
|
-
test(
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
...(await list(input)),
|
|
987
|
-
headers: {
|
|
988
|
-
link: '<https://api.github.com/repos/example/widget/issues?page=1&per_page=100>; rel="prev", broken next continuation',
|
|
989
|
-
},
|
|
990
|
-
}));
|
|
991
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /capacity.*pagination/iu);
|
|
992
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1119
|
+
test("WIP follows native continuation evidence even when a page is short", async () => {
|
|
1120
|
+
const f = fixture();
|
|
1121
|
+
f.controls.capacityMode = true;
|
|
1122
|
+
f.controls.capacityPageSize = 1;
|
|
1123
|
+
f.live.labels = ["critical"];
|
|
1124
|
+
f.context.config = {
|
|
1125
|
+
...f.context.config,
|
|
1126
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
1127
|
+
};
|
|
1128
|
+
f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
|
|
1129
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity limit/u);
|
|
1130
|
+
assert.equal(f.branchWrites.length, 0);
|
|
993
1131
|
});
|
|
994
|
-
test(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1132
|
+
test("WIP rejects malformed continuation remnants instead of treating a short page as complete", async () => {
|
|
1133
|
+
const f = fixture();
|
|
1134
|
+
f.controls.capacityMode = true;
|
|
1135
|
+
f.controls.capacityPageSize = 1;
|
|
1136
|
+
f.live.labels = ["critical"];
|
|
1137
|
+
f.context.config = {
|
|
1138
|
+
...f.context.config,
|
|
1139
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
1140
|
+
};
|
|
1141
|
+
f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
|
|
1142
|
+
const list = f.context.clients.rest.issues.listForRepo;
|
|
1143
|
+
f.context.clients.rest.issues.listForRepo = (async (input) => ({
|
|
1144
|
+
...await list(input),
|
|
1145
|
+
headers: {
|
|
1146
|
+
link: '<https://api.github.com/repos/example/widget/issues?page=1&per_page=100>; rel="prev", broken next continuation'
|
|
1147
|
+
}
|
|
1148
|
+
}));
|
|
1149
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /capacity.*pagination/iu);
|
|
1150
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1151
|
+
});
|
|
1152
|
+
test("WIP rejects a native page larger than its requested window", async () => {
|
|
1153
|
+
const f = fixture();
|
|
1154
|
+
f.controls.capacityMode = true;
|
|
1155
|
+
f.live.labels = ["critical"];
|
|
1156
|
+
f.context.config = {
|
|
1157
|
+
...f.context.config,
|
|
1158
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
1159
|
+
};
|
|
1160
|
+
const list = f.context.clients.rest.issues.listForRepo;
|
|
1161
|
+
f.context.clients.rest.issues.listForRepo = (async (input) => ({
|
|
1162
|
+
headers: {},
|
|
1163
|
+
data: [
|
|
1164
|
+
...(await list(input)).data,
|
|
1165
|
+
...Array.from({ length: 100 }, (_, index) => ({ number: 1e3 + index, pull_request: {} }))
|
|
1166
|
+
]
|
|
1167
|
+
}));
|
|
1168
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity pagination/u);
|
|
1169
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1170
|
+
});
|
|
1171
|
+
test("WIP evaluates every matching lane and capacity overrides cannot resume a deferred or blocked issue", async () => {
|
|
1172
|
+
const f = fixture();
|
|
1173
|
+
f.controls.capacityMode = true;
|
|
1174
|
+
f.live.labels = ["critical"];
|
|
1175
|
+
f.context.config = {
|
|
1176
|
+
...f.context.config,
|
|
1177
|
+
wipLimits: [
|
|
1178
|
+
{ repository: "example/widget", name: "Labels allow", match: { label: "critical" }, limit: 1 },
|
|
1179
|
+
{ repository: "example/widget", name: "Field is full", match: { field: "Urgency", value: "High" }, limit: 1 }
|
|
1180
|
+
]
|
|
1181
|
+
};
|
|
1182
|
+
f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
|
|
1183
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Field is full/u);
|
|
1184
|
+
const deferred = { issueNumber: 17, defer: { trigger: "Manual approval" } };
|
|
1185
|
+
await updateIssue(f.context, deferred);
|
|
1186
|
+
await assert.rejects(
|
|
1187
|
+
startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }),
|
|
1188
|
+
/deferred/u
|
|
1189
|
+
);
|
|
1190
|
+
await updateIssue(f.context, { issueNumber: 17, undefer: true });
|
|
1191
|
+
f.controls.blockers = true;
|
|
1192
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }), /blocked/u);
|
|
1193
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1194
|
+
assert.equal(f.comments.length, 0);
|
|
1012
1195
|
});
|
|
1013
|
-
test(
|
|
1196
|
+
test("WIP distinguishes an explicitly unset native Status from omitted Status evidence", async () => {
|
|
1197
|
+
for (const status of ["Unset", "Missing"]) {
|
|
1014
1198
|
const f = fixture();
|
|
1015
1199
|
f.controls.capacityMode = true;
|
|
1016
|
-
f.live.labels = [
|
|
1200
|
+
f.live.labels = ["critical"];
|
|
1017
1201
|
f.context.config = {
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
{ repository: 'example/widget', name: 'Labels allow', match: { label: 'critical' }, limit: 1 },
|
|
1021
|
-
{ repository: 'example/widget', name: 'Field is full', match: { field: 'Urgency', value: 'High' }, limit: 1 },
|
|
1022
|
-
],
|
|
1202
|
+
...f.context.config,
|
|
1203
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
1023
1204
|
};
|
|
1024
|
-
f.capacity.push({ number: 18, label:
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Capacity only.' }), /blocked/u);
|
|
1032
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1033
|
-
assert.equal(f.comments.length, 0);
|
|
1034
|
-
});
|
|
1035
|
-
test('WIP distinguishes an explicitly unset native Status from omitted Status evidence', async () => {
|
|
1036
|
-
for (const status of ['Unset', 'Missing']) {
|
|
1037
|
-
const f = fixture();
|
|
1038
|
-
f.controls.capacityMode = true;
|
|
1039
|
-
f.live.labels = ['critical'];
|
|
1040
|
-
f.context.config = {
|
|
1041
|
-
...f.context.config,
|
|
1042
|
-
wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
|
|
1043
|
-
};
|
|
1044
|
-
f.capacity.push({ number: 18, label: 'critical', value: 'High', status });
|
|
1045
|
-
if (status === 'Unset') {
|
|
1046
|
-
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1047
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1048
|
-
}
|
|
1049
|
-
else {
|
|
1050
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity/u);
|
|
1051
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1052
|
-
}
|
|
1205
|
+
f.capacity.push({ number: 18, label: "critical", value: "High", status });
|
|
1206
|
+
if (status === "Unset") {
|
|
1207
|
+
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1208
|
+
assert.equal(f.getStatus(), "Active");
|
|
1209
|
+
} else {
|
|
1210
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity/u);
|
|
1211
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1053
1212
|
}
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
test("WIP evaluates distinct lanes using case aliases of the same native label", async () => {
|
|
1216
|
+
const f = fixture();
|
|
1217
|
+
f.controls.capacityMode = true;
|
|
1218
|
+
f.live.labels = ["critical"];
|
|
1219
|
+
f.context.config = {
|
|
1220
|
+
...f.context.config,
|
|
1221
|
+
wipLimits: [
|
|
1222
|
+
{ repository: "example/widget", name: "Available", match: { label: "critical" }, limit: 1 },
|
|
1223
|
+
{ repository: "EXAMPLE/WIDGET", name: "Hold lane", match: { label: "CRITICAL" }, limit: 0 }
|
|
1224
|
+
]
|
|
1225
|
+
};
|
|
1226
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Hold lane/u);
|
|
1227
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1054
1228
|
});
|
|
1055
|
-
test(
|
|
1229
|
+
test("WIP field matching preserves value types for multi-select member names", async () => {
|
|
1230
|
+
for (const value of [0, " 0 ", "0"]) {
|
|
1056
1231
|
const f = fixture();
|
|
1057
1232
|
f.controls.capacityMode = true;
|
|
1058
|
-
f.live.labels = ['critical'];
|
|
1059
1233
|
f.context.config = {
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
{ repository: 'example/widget', name: 'Available', match: { label: 'critical' }, limit: 1 },
|
|
1063
|
-
{ repository: 'EXAMPLE/WIDGET', name: 'Hold lane', match: { label: 'CRITICAL' }, limit: 0 },
|
|
1064
|
-
],
|
|
1234
|
+
...f.context.config,
|
|
1235
|
+
wipLimits: [{ repository: "example/widget", name: "Tagged work", match: { field: "Tags", value }, limit: 0 }]
|
|
1065
1236
|
};
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
f.controls.capacityMode = true;
|
|
1073
|
-
f.context.config = {
|
|
1074
|
-
...f.context.config,
|
|
1075
|
-
wipLimits: [{ repository: 'example/widget', name: 'Tagged work', match: { field: 'Tags', value }, limit: 0 }],
|
|
1076
|
-
};
|
|
1077
|
-
if (typeof value === 'number' || value === ' 0 ') {
|
|
1078
|
-
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1079
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Tagged work/u);
|
|
1083
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1084
|
-
}
|
|
1237
|
+
if (typeof value === "number" || value === " 0 ") {
|
|
1238
|
+
await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1239
|
+
assert.equal(f.getStatus(), "Active");
|
|
1240
|
+
} else {
|
|
1241
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Tagged work/u);
|
|
1242
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1085
1243
|
}
|
|
1244
|
+
}
|
|
1086
1245
|
});
|
|
1087
|
-
test.each([
|
|
1246
|
+
test.each(["status", "archive", "unreadable"])(
|
|
1247
|
+
"WIP refuses changed or incomplete native %s evidence after healthy readiness",
|
|
1248
|
+
async (failure) => {
|
|
1088
1249
|
const f = fixture();
|
|
1089
1250
|
f.controls.capacityMode = true;
|
|
1090
|
-
f.live.labels = [
|
|
1251
|
+
f.live.labels = ["critical"];
|
|
1091
1252
|
f.context.config = {
|
|
1092
|
-
|
|
1093
|
-
|
|
1253
|
+
...f.context.config,
|
|
1254
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
|
|
1094
1255
|
};
|
|
1095
1256
|
const graphql = f.context.clients.graphql;
|
|
1096
1257
|
let projectReads = 0;
|
|
1097
1258
|
f.context.clients.graphql = (async (query, variables) => {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
delete project.items.nodes[0].fieldValueByName;
|
|
1107
|
-
if (failure === 'archive')
|
|
1108
|
-
delete project.items.nodes[0].isArchived;
|
|
1109
|
-
if (failure === 'unreadable')
|
|
1110
|
-
project.items.nodes.push({ id: 'UNKNOWN', isArchived: false, content: null, fieldValueByName: null });
|
|
1111
|
-
}
|
|
1112
|
-
return value;
|
|
1259
|
+
const value = await graphql(query, variables);
|
|
1260
|
+
if (query.includes("ProjectDeliveryIssueItems") && ++projectReads > 1) {
|
|
1261
|
+
const nodes = value.node.projectItems.nodes;
|
|
1262
|
+
if (failure === "status") delete nodes[0].fieldValueByName;
|
|
1263
|
+
if (failure === "archive") delete nodes[0].isArchived;
|
|
1264
|
+
if (failure === "unreadable") nodes[0].content = null;
|
|
1265
|
+
}
|
|
1266
|
+
return value;
|
|
1113
1267
|
});
|
|
1114
|
-
await assert.rejects(
|
|
1268
|
+
await assert.rejects(
|
|
1269
|
+
startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }),
|
|
1270
|
+
/WIP|capacity/u
|
|
1271
|
+
);
|
|
1115
1272
|
assert.equal(f.branchWrites.length, 0);
|
|
1116
1273
|
assert.equal(f.comments.length, 0);
|
|
1274
|
+
}
|
|
1275
|
+
);
|
|
1276
|
+
test("WIP refuses observation drift after recording an override and preserves that attempt for reconciliation", async () => {
|
|
1277
|
+
const f = fixture();
|
|
1278
|
+
f.controls.capacityMode = true;
|
|
1279
|
+
f.live.labels = ["critical"];
|
|
1280
|
+
f.context.config = {
|
|
1281
|
+
...f.context.config,
|
|
1282
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
1283
|
+
};
|
|
1284
|
+
const createComment = f.context.clients.rest.issues.createComment;
|
|
1285
|
+
let drift = true;
|
|
1286
|
+
f.context.clients.rest.issues.createComment = (async (input2) => {
|
|
1287
|
+
const result2 = await createComment(input2);
|
|
1288
|
+
if (drift) {
|
|
1289
|
+
drift = false;
|
|
1290
|
+
f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
|
|
1291
|
+
}
|
|
1292
|
+
return result2;
|
|
1293
|
+
});
|
|
1294
|
+
const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity exception." };
|
|
1295
|
+
const result = await startTrackedIssue(f.context, input);
|
|
1296
|
+
assert.match(Reflect.get(result, "failure").message, /capacity changed/u);
|
|
1297
|
+
assert.equal(f.getStatus(), "Queued");
|
|
1298
|
+
assert.equal(f.comments.length, 1);
|
|
1299
|
+
await startTrackedIssue(f.context, input);
|
|
1300
|
+
assert.equal(f.getStatus(), "Active");
|
|
1301
|
+
assert.equal(f.comments.length, 3, "two distinct native capacity observations and one start journal");
|
|
1302
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1117
1303
|
});
|
|
1118
|
-
test(
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
f.context.clients.rest.issues.createComment = (async (input) => {
|
|
1129
|
-
const result = await createComment(input);
|
|
1130
|
-
if (drift) {
|
|
1131
|
-
drift = false;
|
|
1132
|
-
f.capacity.push({ number: 18, label: 'critical', value: 'High', status: 'Active' });
|
|
1133
|
-
}
|
|
1134
|
-
return result;
|
|
1135
|
-
});
|
|
1136
|
-
const input = { issueNumber: 17, overrideReason: 'Explicit synthetic capacity exception.' };
|
|
1137
|
-
const result = await startTrackedIssue(f.context, input);
|
|
1138
|
-
assert.match(Reflect.get(result, 'failure').message, /capacity changed/u);
|
|
1139
|
-
assert.equal(f.getStatus(), 'Queued');
|
|
1140
|
-
assert.equal(f.comments.length, 1);
|
|
1141
|
-
await startTrackedIssue(f.context, input);
|
|
1142
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1143
|
-
assert.equal(f.comments.length, 3, 'two distinct native capacity observations and one start journal');
|
|
1144
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1304
|
+
test("native create validates first, writes canonical fields, reads back metadata and returns warnings", async () => {
|
|
1305
|
+
const f = fixture();
|
|
1306
|
+
await assert.rejects(createIssue(f.context, { ...ready(), openQuestions: ["Select behavior."] }), /open-questions/u);
|
|
1307
|
+
assert.equal(f.writes.length, 0);
|
|
1308
|
+
const result = await createIssue(f.context, ready());
|
|
1309
|
+
assert.equal(f.writes.length, 1);
|
|
1310
|
+
assert.equal(canonicalIssueBody({ ...ready(), body: result.body }), renderIssueBody(ready()));
|
|
1311
|
+
assert.equal(parseIssueBody(result.body, { title: result.created.title }).issue.points, 2);
|
|
1312
|
+
assert.deepEqual(result.warnings, []);
|
|
1313
|
+
assert.equal(f.getStatus(), "Queued");
|
|
1145
1314
|
});
|
|
1146
|
-
test(
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1315
|
+
test("incomplete drafts write parked; reviewer-role writes and wrong native repository readback are refused", async () => {
|
|
1316
|
+
const f = fixture();
|
|
1317
|
+
await createIssue(f.context, { title: "Investigate invalid widget identifiers", draft: true });
|
|
1318
|
+
assert.equal(f.getStatus(), "Queued");
|
|
1319
|
+
assert.match(f.live.body, /\*\*State:\*\* Draft/u);
|
|
1320
|
+
f.controls.role = "reviewer";
|
|
1321
|
+
await assert.rejects(createIssue(f.context, ready()), /author role/u);
|
|
1322
|
+
await assert.rejects(updateIssue(f.context, { issueNumber: 17, draft: true }), /author role/u);
|
|
1323
|
+
const bad = fixture();
|
|
1324
|
+
bad.controls.wrongCreateRepo = true;
|
|
1325
|
+
await assert.rejects(createIssue(bad.context, ready()), /created but native tracking did not complete/u);
|
|
1326
|
+
assert.equal(bad.writes.length, 1);
|
|
1156
1327
|
});
|
|
1157
|
-
test(
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1328
|
+
test("first legacy update retains exact history and full diff, then typed patches preserve unspecified fields", async () => {
|
|
1329
|
+
const f = fixture();
|
|
1330
|
+
const legacy = "## Problem\nMalformed identifiers reach persistence.\n## Outcome\nReject malformed identifiers.\n## Acceptance Criteria\n- [ ] Invalid identifiers return an error without persistence.\n## Verification\nA portable regression asserts no write.\n## Out of scope\n- Storage changes.\n## Scope\nwidget component\n";
|
|
1331
|
+
f.live.body = legacy;
|
|
1332
|
+
const result = await updateIssue(f.context, { issueNumber: 17 });
|
|
1333
|
+
assert.equal(f.comments.length, 1);
|
|
1334
|
+
assert.equal(result.conversion?.priorBody, legacy);
|
|
1335
|
+
assert.match(result.conversion.diff, /^--- prior body\n\+\+\+ canonical body/u);
|
|
1336
|
+
assert.match(f.comments[0].body, /Malformed identifiers reach persistence/u);
|
|
1337
|
+
assert.equal(parseIssueBody(result.body, { title: result.title }).issue.legacyBody, legacy);
|
|
1338
|
+
const patched = await updateIssue(f.context, {
|
|
1339
|
+
issueNumber: 17,
|
|
1340
|
+
outcome: "Reject malformed identifiers with a typed error.",
|
|
1341
|
+
preserveHistory: true
|
|
1342
|
+
});
|
|
1343
|
+
assert.equal(parseIssueBody(patched.body, { title: patched.title }).issue.acceptanceCriteria.length, 1);
|
|
1344
|
+
assert.equal(patched.conversion, void 0);
|
|
1345
|
+
assert.equal(f.comments.length, 2);
|
|
1169
1346
|
});
|
|
1170
|
-
test(
|
|
1347
|
+
test("legacy replacement updates preserve the actual previous body and diff for canonical and handwritten input", async () => {
|
|
1348
|
+
const original = "Original native legacy bytes, including unclassified operator context.\n";
|
|
1349
|
+
for (const replacement of [renderIssueBody(ready()), "Replacement handwritten context.\n"]) {
|
|
1171
1350
|
const f = fixture();
|
|
1172
|
-
|
|
1173
|
-
f.
|
|
1174
|
-
const result = await updateIssue(f.context, { issueNumber: 17 });
|
|
1351
|
+
f.live.body = original;
|
|
1352
|
+
const result = await updateIssue(f.context, { issueNumber: 17, body: replacement, ...ready() });
|
|
1175
1353
|
assert.equal(f.comments.length, 1);
|
|
1176
|
-
assert.
|
|
1177
|
-
assert.
|
|
1178
|
-
assert.
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1354
|
+
assert.ok(f.comments[0].body.includes(original));
|
|
1355
|
+
assert.equal(result.conversion?.priorBody, original);
|
|
1356
|
+
assert.ok(result.conversion.diff.includes("-" + original.trim()));
|
|
1357
|
+
const preserved = parseIssueBody(result.body, { title: result.title }).issue.legacyBody;
|
|
1358
|
+
assert.ok(preserved?.includes(original));
|
|
1359
|
+
if (!replacement.startsWith(ISSUE_BODY_MARKER)) assert.ok(preserved?.includes(replacement));
|
|
1360
|
+
assert.equal(result.conversion?.canonicalBody, result.body);
|
|
1361
|
+
const patch = await updateIssue(f.context, {
|
|
1362
|
+
issueNumber: 17,
|
|
1363
|
+
outcome: "Reject invalid input before persistence."
|
|
1184
1364
|
});
|
|
1185
|
-
assert.equal(
|
|
1186
|
-
assert.equal(
|
|
1187
|
-
assert.equal(
|
|
1365
|
+
assert.equal(patch.conversion, void 0);
|
|
1366
|
+
assert.equal(f.comments.length, replacement.startsWith(ISSUE_BODY_MARKER) ? 1 : 2);
|
|
1367
|
+
assert.equal(parseIssueBody(patch.body, { title: patch.title }).issue.legacyBody, preserved);
|
|
1368
|
+
}
|
|
1188
1369
|
});
|
|
1189
|
-
test(
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1370
|
+
test("validation, history drift and corrupted native update readback fail without a fabricated success", async () => {
|
|
1371
|
+
const f = fixture();
|
|
1372
|
+
await assert.rejects(
|
|
1373
|
+
updateIssue(f.context, { issueNumber: 17, openQuestions: ["Choose a policy."] }),
|
|
1374
|
+
/open-questions/u
|
|
1375
|
+
);
|
|
1376
|
+
assert.equal(f.writes.length, 0);
|
|
1377
|
+
assert.equal(f.comments.length, 0);
|
|
1378
|
+
f.controls.driftAfterHistory = true;
|
|
1379
|
+
await assert.rejects(
|
|
1380
|
+
updateIssue(f.context, {
|
|
1381
|
+
issueNumber: 17,
|
|
1382
|
+
outcome: "Reject malformed input before all writes.",
|
|
1383
|
+
preserveHistory: true
|
|
1384
|
+
}),
|
|
1385
|
+
/content changed/u
|
|
1386
|
+
);
|
|
1387
|
+
assert.equal(f.writes.length, 0);
|
|
1388
|
+
const bad = fixture();
|
|
1389
|
+
bad.controls.ignoreBody = true;
|
|
1390
|
+
await assert.rejects(
|
|
1391
|
+
updateIssue(bad.context, { issueNumber: 17, outcome: "Reject malformed input before all writes." }),
|
|
1392
|
+
/update readback disagrees/u
|
|
1393
|
+
);
|
|
1212
1394
|
});
|
|
1213
|
-
test(
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
const bad = fixture();
|
|
1226
|
-
bad.controls.ignoreBody = true;
|
|
1227
|
-
await assert.rejects(updateIssue(bad.context, { issueNumber: 17, outcome: 'Reject malformed input before all writes.' }), /update readback disagrees/u);
|
|
1395
|
+
test("normal-start canonical retry body keeps exact intent markers through create/readiness", async () => {
|
|
1396
|
+
const issue = ready();
|
|
1397
|
+
const canonical = canonicalIssueBody(issue);
|
|
1398
|
+
const footer = "\n\n<!-- ai-delivery-start-intent: " + digestValue({ intent: "fixture" }) + " -->\n<!-- ai-delivery-start: " + digestValue({ request: "fixture" }) + " -->";
|
|
1399
|
+
const result = await createIssue(fixture().context, {
|
|
1400
|
+
title: issue.title,
|
|
1401
|
+
body: canonical + footer,
|
|
1402
|
+
points: 2,
|
|
1403
|
+
issueType: "Task"
|
|
1404
|
+
});
|
|
1405
|
+
assert.equal(canonicalIssueBody({ ...issue, body: result.body }), canonical + footer);
|
|
1406
|
+
assert.deepEqual(parseIssueBody(result.body, { title: issue.title }).issue, issue);
|
|
1228
1407
|
});
|
|
1229
|
-
test(
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1408
|
+
test("actual normal-start creation and retry reuse the exact canonical body, branch and authored journal", async () => {
|
|
1409
|
+
const clock = vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-10-16T20:30:00Z"));
|
|
1410
|
+
const f = fixture();
|
|
1411
|
+
f.controls.created = false;
|
|
1412
|
+
const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
|
|
1413
|
+
title: ready().title,
|
|
1414
|
+
body: renderIssueBody(ready()),
|
|
1415
|
+
issueType: "Task",
|
|
1416
|
+
points: 2,
|
|
1417
|
+
requestId: "issue68-normal-start"
|
|
1418
|
+
});
|
|
1419
|
+
const first = await startTrackedIssue(f.context, request);
|
|
1420
|
+
assert.ok("issueNumber" in first);
|
|
1421
|
+
assert.equal(first.issueNumber, 17);
|
|
1422
|
+
assert.ok("reused" in first && first.reused === false);
|
|
1423
|
+
const body = f.live.body;
|
|
1424
|
+
assert.match(body, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
1425
|
+
assert.match(body, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
1426
|
+
assert.deepEqual(parseIssueBody(body, { title: f.live.title }).issue, ready());
|
|
1427
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1428
|
+
assert.equal(
|
|
1429
|
+
f.branchWrites[0]?.clientMutationId,
|
|
1430
|
+
digestValue({ repository: "example/widget", issueNumber: 17, name: "issue/17", base: "a".repeat(40) })
|
|
1431
|
+
);
|
|
1432
|
+
assert.equal(f.comments.length, 1);
|
|
1433
|
+
clock.mockReturnValue(Date.parse("2026-10-17T20:30:00Z"));
|
|
1434
|
+
const retry = await startTrackedIssue(f.context, request);
|
|
1435
|
+
assert.ok("reused" in retry && retry.reused === true);
|
|
1436
|
+
assert.equal(retry.issueNumber, 17);
|
|
1437
|
+
assert.equal(f.writes.filter((input) => !("issue_number" in input)).length, 1);
|
|
1438
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1439
|
+
assert.equal(f.comments.length, 1);
|
|
1440
|
+
assert.equal(f.live.body, body);
|
|
1441
|
+
await assert.rejects(
|
|
1442
|
+
startTrackedIssue(f.context, {
|
|
1443
|
+
...request,
|
|
1444
|
+
body: renderIssueBody({ ...ready(), outcome: "A conflicting new outcome." })
|
|
1445
|
+
}),
|
|
1446
|
+
/conflicts/u
|
|
1447
|
+
);
|
|
1448
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1245
1449
|
});
|
|
1246
|
-
test(
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
requestId: 'issue68-normal-start',
|
|
1256
|
-
});
|
|
1257
|
-
const first = await startTrackedIssue(f.context, request);
|
|
1258
|
-
assert.ok('issueNumber' in first);
|
|
1259
|
-
assert.equal(first.issueNumber, 17);
|
|
1260
|
-
assert.ok('reused' in first && first.reused === false);
|
|
1261
|
-
const body = f.live.body;
|
|
1262
|
-
assert.match(body, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
1263
|
-
assert.match(body, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
1264
|
-
assert.deepEqual(parseIssueBody(body, { title: f.live.title }).issue, ready());
|
|
1265
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1266
|
-
assert.equal(f.branchWrites[0]?.clientMutationId, digestValue({ repository: 'example/widget', issueNumber: 17, name: 'issue/17', base: 'a'.repeat(40) }));
|
|
1267
|
-
assert.equal(f.comments.length, 1);
|
|
1268
|
-
clock.mockReturnValue(Date.parse('2026-10-17T20:30:00Z'));
|
|
1269
|
-
const retry = await startTrackedIssue(f.context, request);
|
|
1270
|
-
assert.ok('reused' in retry && retry.reused === true);
|
|
1271
|
-
assert.equal(retry.issueNumber, 17);
|
|
1272
|
-
assert.equal(f.writes.filter((input) => !('issue_number' in input)).length, 1);
|
|
1273
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1274
|
-
assert.equal(f.comments.length, 1);
|
|
1275
|
-
assert.equal(f.live.body, body);
|
|
1276
|
-
await assert.rejects(startTrackedIssue(f.context, {
|
|
1277
|
-
...request,
|
|
1278
|
-
body: renderIssueBody({ ...ready(), outcome: 'A conflicting new outcome.' }),
|
|
1279
|
-
}), /conflicts/u);
|
|
1280
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1450
|
+
test("a history rewrite refuses to republish secret-bearing prior text", async () => {
|
|
1451
|
+
const f = fixture();
|
|
1452
|
+
f.live.body = "An accidental fixture " + ["gh", "p_"].join("") + "A".repeat(24);
|
|
1453
|
+
await assert.rejects(
|
|
1454
|
+
updateIssue(f.context, { issueNumber: 17, body: renderIssueBody(ready()), preserveHistory: true }),
|
|
1455
|
+
/secrets/u
|
|
1456
|
+
);
|
|
1457
|
+
assert.equal(f.comments.length, 0);
|
|
1458
|
+
assert.equal(f.writes.length, 0);
|
|
1281
1459
|
});
|
|
1282
|
-
test(
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1460
|
+
test("ordinary start checks typed Draft, Points and live eligibility before branch or journal mutation", async () => {
|
|
1461
|
+
for (const [expected, change] of [
|
|
1462
|
+
[
|
|
1463
|
+
"draft",
|
|
1464
|
+
(f2) => {
|
|
1465
|
+
f2.live.body = renderIssueBody({ ...ready(), draft: true });
|
|
1466
|
+
}
|
|
1467
|
+
],
|
|
1468
|
+
[
|
|
1469
|
+
"points.sync",
|
|
1470
|
+
(f2) => {
|
|
1471
|
+
f2.controls.livePoints = 4;
|
|
1472
|
+
}
|
|
1473
|
+
],
|
|
1474
|
+
[
|
|
1475
|
+
"blocked",
|
|
1476
|
+
(f2) => {
|
|
1477
|
+
f2.controls.blockers = true;
|
|
1478
|
+
}
|
|
1479
|
+
],
|
|
1480
|
+
[
|
|
1481
|
+
"tracking-parent",
|
|
1482
|
+
(f2) => {
|
|
1483
|
+
f2.controls.trackingParent = true;
|
|
1484
|
+
}
|
|
1485
|
+
]
|
|
1486
|
+
]) {
|
|
1487
|
+
const f2 = fixture();
|
|
1488
|
+
change(f2);
|
|
1489
|
+
await assert.rejects(startTrackedIssue(f2.context, { issueNumber: 17 }), (error) => {
|
|
1490
|
+
assert.ok(error instanceof Error);
|
|
1491
|
+
const diagnostics = JSON.parse(error.message);
|
|
1492
|
+
assert(diagnostics.failures.some((failure) => failure.code === expected && failure.field && failure.fixHint));
|
|
1493
|
+
return true;
|
|
1494
|
+
});
|
|
1495
|
+
assert.equal(f2.branchWrites.length, 0);
|
|
1496
|
+
assert.equal(f2.comments.length, 0);
|
|
1497
|
+
assert.equal(f2.writes.length, 0);
|
|
1498
|
+
}
|
|
1499
|
+
const f = fixture();
|
|
1500
|
+
f.live.body = renderIssueBody({ ...ready(), outcome: "Retain the Todo label when validation passes." });
|
|
1501
|
+
const first = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1502
|
+
assert.ok("reused" in first && first.reused === false);
|
|
1503
|
+
assert.ok("reused" in await startTrackedIssue(f.context, { issueNumber: 17 }));
|
|
1504
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1505
|
+
assert.equal(f.comments.length, 1);
|
|
1288
1506
|
});
|
|
1289
|
-
test(
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
],
|
|
1303
|
-
[
|
|
1304
|
-
'blocked',
|
|
1305
|
-
(f) => {
|
|
1306
|
-
f.controls.blockers = true;
|
|
1307
|
-
},
|
|
1308
|
-
],
|
|
1309
|
-
[
|
|
1310
|
-
'tracking-parent',
|
|
1311
|
-
(f) => {
|
|
1312
|
-
f.controls.trackingParent = true;
|
|
1313
|
-
},
|
|
1314
|
-
],
|
|
1315
|
-
]) {
|
|
1316
|
-
const f = fixture();
|
|
1317
|
-
change(f);
|
|
1318
|
-
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), (error) => {
|
|
1319
|
-
assert.ok(error instanceof Error);
|
|
1320
|
-
const diagnostics = JSON.parse(error.message);
|
|
1321
|
-
assert(diagnostics.failures.some((failure) => failure.code === expected && failure.field && failure.fixHint));
|
|
1322
|
-
return true;
|
|
1323
|
-
});
|
|
1324
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1325
|
-
assert.equal(f.comments.length, 0);
|
|
1326
|
-
assert.equal(f.writes.length, 0);
|
|
1507
|
+
test("joined MCP start modes preserve ordinary input and reject mixed investigation or foreign repository calls before configuration", async () => {
|
|
1508
|
+
const schema = getAiDeliveryMcpTool("issue_start").inputSchema;
|
|
1509
|
+
assert(schema.safeParse({ issueNumber: 17, repo: "example/widget" }).success);
|
|
1510
|
+
assert(
|
|
1511
|
+
schema.safeParse({ body: renderIssueBody(ready()), title: ready().title, points: 2, issueType: "Task" }).success
|
|
1512
|
+
);
|
|
1513
|
+
for (const arguments_ of [
|
|
1514
|
+
{ issueNumber: 17, expectedHeadSha: "a".repeat(40) },
|
|
1515
|
+
{
|
|
1516
|
+
issueNumber: 17,
|
|
1517
|
+
investigationWorktree: "/fictional/issue-17",
|
|
1518
|
+
expectedHeadSha: "a".repeat(40),
|
|
1519
|
+
body: renderIssueBody(ready())
|
|
1327
1520
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1521
|
+
])
|
|
1522
|
+
assert.equal(schema.safeParse(arguments_).success, false);
|
|
1523
|
+
await assert.rejects(
|
|
1524
|
+
executeTool(
|
|
1525
|
+
"issue_start",
|
|
1526
|
+
{ repo: "foreign/widget", issueNumber: 17 },
|
|
1527
|
+
{ repo: "example/widget", repoRoot: "/synthetic-non-git" }
|
|
1528
|
+
),
|
|
1529
|
+
/selectors disagree/u
|
|
1530
|
+
);
|
|
1531
|
+
const finish = getAiDeliveryMcpTool("issue_finish").inputSchema;
|
|
1532
|
+
assert(finish.safeParse({ issueNumber: 17, prNumber: 23 }).success);
|
|
1533
|
+
assert.equal(finish.safeParse({ issueNumber: 17 }).success, false);
|
|
1534
|
+
assert.equal(
|
|
1535
|
+
finish.safeParse({ issueNumber: 17, investigation: true, resultPath: "/fictional/result", prNumber: 23 }).success,
|
|
1536
|
+
false
|
|
1537
|
+
);
|
|
1335
1538
|
});
|
|
1336
|
-
test(
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
if (interrupted.status !== 'created-not-started')
|
|
1370
|
-
assert.fail('Expected a known-created readiness refusal.');
|
|
1371
|
-
assert.equal(interrupted.status, 'created-not-started');
|
|
1372
|
-
const nativeBody = f.live.body;
|
|
1373
|
-
assert.match(nativeBody, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
1374
|
-
assert.match(nativeBody, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
1375
|
-
assert.equal(interrupted.safeResume.arguments.resumeCreated, undefined);
|
|
1376
|
-
assert.equal('body' in interrupted.safeResume.arguments, false);
|
|
1377
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1378
|
-
assert.equal(f.comments.length, 0);
|
|
1379
|
-
assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
|
|
1380
|
-
f.controls.trackingParent = false;
|
|
1381
|
-
const resumed = await startTrackedIssue(f.context, schema.parse(interrupted.safeResume.arguments));
|
|
1382
|
-
assert.ok('reused' in resumed && resumed.reused === false);
|
|
1383
|
-
assert.equal(f.live.body, nativeBody);
|
|
1384
|
-
const retry = await startTrackedIssue(f.context, request);
|
|
1385
|
-
assert.ok('reused' in retry && retry.reused === true);
|
|
1386
|
-
assert.equal(f.live.body, nativeBody);
|
|
1387
|
-
assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
|
|
1388
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1389
|
-
assert.equal(f.comments.length, 1);
|
|
1539
|
+
test("created readiness refusal returns exact retry markers through safe resume and original request retry", async () => {
|
|
1540
|
+
const f = fixture();
|
|
1541
|
+
f.controls.created = false;
|
|
1542
|
+
f.controls.trackingParent = true;
|
|
1543
|
+
const schema = getAiDeliveryMcpTool("issue_start").inputSchema;
|
|
1544
|
+
const request = schema.parse({
|
|
1545
|
+
title: ready().title,
|
|
1546
|
+
body: renderIssueBody(ready()),
|
|
1547
|
+
issueType: "Task",
|
|
1548
|
+
points: 2,
|
|
1549
|
+
requestId: "issue68-readiness-recovery"
|
|
1550
|
+
});
|
|
1551
|
+
const interrupted = await startTrackedIssue(f.context, request);
|
|
1552
|
+
if (interrupted.status !== "created-not-started") assert.fail("Expected a known-created readiness refusal.");
|
|
1553
|
+
assert.equal(interrupted.status, "created-not-started");
|
|
1554
|
+
const nativeBody = f.live.body;
|
|
1555
|
+
assert.match(nativeBody, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
1556
|
+
assert.match(nativeBody, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
1557
|
+
assert.equal(interrupted.safeResume.arguments.resumeCreated, void 0);
|
|
1558
|
+
assert.equal("body" in interrupted.safeResume.arguments, false);
|
|
1559
|
+
assert.equal(f.branchWrites.length, 0);
|
|
1560
|
+
assert.equal(f.comments.length, 0);
|
|
1561
|
+
assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
|
|
1562
|
+
f.controls.trackingParent = false;
|
|
1563
|
+
const resumed = await startTrackedIssue(f.context, schema.parse(interrupted.safeResume.arguments));
|
|
1564
|
+
assert.ok("reused" in resumed && resumed.reused === false);
|
|
1565
|
+
assert.equal(f.live.body, nativeBody);
|
|
1566
|
+
const retry = await startTrackedIssue(f.context, request);
|
|
1567
|
+
assert.ok("reused" in retry && retry.reused === true);
|
|
1568
|
+
assert.equal(f.live.body, nativeBody);
|
|
1569
|
+
assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
|
|
1570
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1571
|
+
assert.equal(f.comments.length, 1);
|
|
1390
1572
|
});
|
|
1391
|
-
test(
|
|
1392
|
-
|
|
1573
|
+
test(
|
|
1574
|
+
"actual compiled stdio MCP returns every Ready diagnostic before credentials and refuses a foreign caller repo",
|
|
1575
|
+
{ tags: ["release"] },
|
|
1576
|
+
async () => {
|
|
1577
|
+
const root = mkdtempSync(join(tmpdir(), "issue-contract-stdio-"));
|
|
1393
1578
|
const transport = new StdioClientTransport({
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1579
|
+
command: process.execPath,
|
|
1580
|
+
args: [resolve("dist/cli.js"), "--identity", "host-author", "--repo", "example/widget", "mcp:serve"],
|
|
1581
|
+
cwd: root,
|
|
1582
|
+
stderr: "pipe",
|
|
1583
|
+
env: {
|
|
1584
|
+
HOME: root,
|
|
1585
|
+
PATH: process.env.PATH ?? "",
|
|
1586
|
+
AI_DELIVERY_CONFIG: join(root, "missing-config.json"),
|
|
1587
|
+
LANG: "en_US.UTF-8"
|
|
1588
|
+
}
|
|
1404
1589
|
});
|
|
1405
|
-
const client = new Client({ name:
|
|
1590
|
+
const client = new Client({ name: "issue68-synthetic-client", version: "1.0.0" });
|
|
1406
1591
|
let spawnedPid = null;
|
|
1407
1592
|
let closeObserved = false;
|
|
1408
1593
|
try {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1594
|
+
await client.connect(transport);
|
|
1595
|
+
spawnedPid = transport.pid;
|
|
1596
|
+
assert.ok(spawnedPid);
|
|
1597
|
+
const original = transport.onclose;
|
|
1598
|
+
transport.onclose = () => {
|
|
1599
|
+
closeObserved = true;
|
|
1600
|
+
original?.();
|
|
1601
|
+
};
|
|
1602
|
+
const listing = await client.listTools();
|
|
1603
|
+
assert.ok(listing.tools.find((t) => t.name === "issue_create")?.inputSchema.properties?.acceptanceCriteria);
|
|
1604
|
+
const result = await client.callTool({
|
|
1605
|
+
name: "issue_create",
|
|
1606
|
+
arguments: { ...ready(), points: 13, openQuestions: ["Select behavior."] }
|
|
1607
|
+
});
|
|
1608
|
+
assert.equal(result.isError, true);
|
|
1609
|
+
const content = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(result.content);
|
|
1610
|
+
const diagnostic = z.object({
|
|
1611
|
+
contract: z.literal("ai-delivery.issue@1"),
|
|
1612
|
+
failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() }))
|
|
1613
|
+
}).parse(JSON.parse(content[0].text));
|
|
1614
|
+
assert.deepEqual(diagnostic.failures.map((f) => f.code).sort(), ["open-questions", "points"]);
|
|
1615
|
+
assert.ok(diagnostic.failures.every((f) => f.field && f.fixHint));
|
|
1616
|
+
for (const name of ["issue_create", "issue_update"]) {
|
|
1617
|
+
const malformed = await client.callTool({
|
|
1618
|
+
name,
|
|
1619
|
+
arguments: {
|
|
1620
|
+
...ready(),
|
|
1621
|
+
...name === "issue_update" ? { issueNumber: 17 } : {},
|
|
1622
|
+
acceptanceCriteria: [{ behavior: ready().acceptanceCriteria[0].behavior }],
|
|
1623
|
+
context: { components: 9 }
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
assert.equal(malformed.isError, true);
|
|
1627
|
+
const blocks = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(malformed.content);
|
|
1628
|
+
const failure = z.object({
|
|
1629
|
+
contract: z.literal("ai-delivery.issue@1"),
|
|
1630
|
+
failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() }))
|
|
1631
|
+
}).parse(JSON.parse(blocks[0].text));
|
|
1632
|
+
assert.deepEqual(failure.failures.map((f) => f.field).sort(), [
|
|
1633
|
+
"acceptanceCriteria.0.verifiedBy",
|
|
1634
|
+
"context.components"
|
|
1635
|
+
]);
|
|
1636
|
+
assert.ok(failure.failures.every((f) => f.code && f.fixHint));
|
|
1637
|
+
assert.doesNotMatch(blocks[0].text, /missing-config/u);
|
|
1638
|
+
const unknown = await client.callTool({
|
|
1639
|
+
name,
|
|
1640
|
+
arguments: {
|
|
1641
|
+
...ready(),
|
|
1642
|
+
...name === "issue_update" ? { issueNumber: 17 } : {},
|
|
1643
|
+
unexpectedField: "Root field must be refused.",
|
|
1644
|
+
context: { ...ready().context, unexpectedField: "Nested field must be refused." },
|
|
1645
|
+
acceptanceCriteria: [{ ...ready().acceptanceCriteria[0], unexpectedField: "Unknown criterion field." }]
|
|
1646
|
+
}
|
|
1422
1647
|
});
|
|
1423
|
-
assert.equal(
|
|
1424
|
-
const
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1648
|
+
assert.equal(unknown.isError, true);
|
|
1649
|
+
const unknownBlocks = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(unknown.content);
|
|
1650
|
+
const unknownFailure = z.object({
|
|
1651
|
+
contract: z.literal("ai-delivery.issue@1"),
|
|
1652
|
+
failures: z.array(z.object({ code: z.literal("field.unknown"), field: z.string(), fixHint: z.string() }))
|
|
1653
|
+
}).parse(JSON.parse(unknownBlocks[0].text));
|
|
1654
|
+
assert.deepEqual(unknownFailure.failures.map((f) => f.field).sort(), [
|
|
1655
|
+
"acceptanceCriteria.0",
|
|
1656
|
+
"context",
|
|
1657
|
+
"issue"
|
|
1658
|
+
]);
|
|
1659
|
+
assert.ok(unknownFailure.failures.every((f) => f.fixHint.length > 10));
|
|
1660
|
+
assert.doesNotMatch(
|
|
1661
|
+
unknownBlocks[0].text,
|
|
1662
|
+
/unexpectedField|Nested field|Unknown criterion/u,
|
|
1663
|
+
"Diagnostics do not echo untrusted keys or values."
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
const foreign = await client.callTool({ name: "issue_create", arguments: { ...ready(), repo: "other/widget" } });
|
|
1667
|
+
assert.equal(foreign.isError, true);
|
|
1668
|
+
assert.match(JSON.stringify(foreign.content), /repository selectors disagree/u);
|
|
1669
|
+
} finally {
|
|
1670
|
+
await client.close();
|
|
1671
|
+
assert.equal(closeObserved, true, "SDK spawned-child close event was actually observed");
|
|
1672
|
+
rmSync(root, { recursive: true, force: true });
|
|
1673
|
+
console.info(
|
|
1674
|
+
JSON.stringify({
|
|
1675
|
+
fixture: "issue68-compiled-stdio",
|
|
1676
|
+
spawnedPid,
|
|
1677
|
+
childCloseObserved: closeObserved,
|
|
1678
|
+
syntheticRootRemoved: true
|
|
1429
1679
|
})
|
|
1430
|
-
|
|
1431
|
-
assert.deepEqual(diagnostic.failures.map((f) => f.code).sort(), ['open-questions', 'points']);
|
|
1432
|
-
assert.ok(diagnostic.failures.every((f) => f.field && f.fixHint));
|
|
1433
|
-
for (const name of ['issue_create', 'issue_update']) {
|
|
1434
|
-
const malformed = await client.callTool({
|
|
1435
|
-
name,
|
|
1436
|
-
arguments: {
|
|
1437
|
-
...ready(),
|
|
1438
|
-
...(name === 'issue_update' ? { issueNumber: 17 } : {}),
|
|
1439
|
-
acceptanceCriteria: [{ behavior: ready().acceptanceCriteria[0].behavior }],
|
|
1440
|
-
context: { components: 9 },
|
|
1441
|
-
},
|
|
1442
|
-
});
|
|
1443
|
-
assert.equal(malformed.isError, true);
|
|
1444
|
-
const blocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(malformed.content);
|
|
1445
|
-
const failure = z
|
|
1446
|
-
.object({
|
|
1447
|
-
contract: z.literal('ai-delivery.issue@1'),
|
|
1448
|
-
failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() })),
|
|
1449
|
-
})
|
|
1450
|
-
.parse(JSON.parse(blocks[0].text));
|
|
1451
|
-
assert.deepEqual(failure.failures.map((f) => f.field).sort(), [
|
|
1452
|
-
'acceptanceCriteria.0.verifiedBy',
|
|
1453
|
-
'context.components',
|
|
1454
|
-
]);
|
|
1455
|
-
assert.ok(failure.failures.every((f) => f.code && f.fixHint));
|
|
1456
|
-
assert.doesNotMatch(blocks[0].text, /missing-config/u);
|
|
1457
|
-
const unknown = await client.callTool({
|
|
1458
|
-
name,
|
|
1459
|
-
arguments: {
|
|
1460
|
-
...ready(),
|
|
1461
|
-
...(name === 'issue_update' ? { issueNumber: 17 } : {}),
|
|
1462
|
-
unexpectedField: 'Root field must be refused.',
|
|
1463
|
-
context: { ...ready().context, unexpectedField: 'Nested field must be refused.' },
|
|
1464
|
-
acceptanceCriteria: [{ ...ready().acceptanceCriteria[0], unexpectedField: 'Unknown criterion field.' }],
|
|
1465
|
-
},
|
|
1466
|
-
});
|
|
1467
|
-
assert.equal(unknown.isError, true);
|
|
1468
|
-
const unknownBlocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(unknown.content);
|
|
1469
|
-
const unknownFailure = z
|
|
1470
|
-
.object({
|
|
1471
|
-
contract: z.literal('ai-delivery.issue@1'),
|
|
1472
|
-
failures: z.array(z.object({ code: z.literal('field.unknown'), field: z.string(), fixHint: z.string() })),
|
|
1473
|
-
})
|
|
1474
|
-
.parse(JSON.parse(unknownBlocks[0].text));
|
|
1475
|
-
assert.deepEqual(unknownFailure.failures.map((f) => f.field).sort(), [
|
|
1476
|
-
'acceptanceCriteria.0',
|
|
1477
|
-
'context',
|
|
1478
|
-
'issue',
|
|
1479
|
-
]);
|
|
1480
|
-
assert.ok(unknownFailure.failures.every((f) => f.fixHint.length > 10));
|
|
1481
|
-
assert.doesNotMatch(unknownBlocks[0].text, /unexpectedField|Nested field|Unknown criterion/u, 'Diagnostics do not echo untrusted keys or values.');
|
|
1482
|
-
}
|
|
1483
|
-
const foreign = await client.callTool({ name: 'issue_create', arguments: { ...ready(), repo: 'other/widget' } });
|
|
1484
|
-
assert.equal(foreign.isError, true);
|
|
1485
|
-
assert.match(JSON.stringify(foreign.content), /repository selectors disagree/u);
|
|
1680
|
+
);
|
|
1486
1681
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
childCloseObserved: closeObserved,
|
|
1495
|
-
syntheticRootRemoved: true,
|
|
1496
|
-
}));
|
|
1497
|
-
}
|
|
1498
|
-
});
|
|
1499
|
-
test('intake skill example is Ready and every CLI line has actual required options and an explicit identity', () => {
|
|
1500
|
-
const skill = readFileSync(resolve('plugins/ai-delivery/skills/intake-create/SKILL.md'), 'utf8');
|
|
1682
|
+
}
|
|
1683
|
+
);
|
|
1684
|
+
test(
|
|
1685
|
+
"intake skill example is Ready and every CLI line has actual required options and an explicit identity",
|
|
1686
|
+
{ tags: ["release"] },
|
|
1687
|
+
() => {
|
|
1688
|
+
const skill = readFileSync(resolve("plugins/ai-delivery/skills/intake-create/SKILL.md"), "utf8");
|
|
1501
1689
|
const examples = [...skill.matchAll(/```json\n([\s\S]*?)\n```/gu)].map((match) => {
|
|
1502
|
-
|
|
1503
|
-
|
|
1690
|
+
const json2 = match[1] ?? "";
|
|
1691
|
+
return { json: json2, value: JSON.parse(json2) };
|
|
1504
1692
|
});
|
|
1505
|
-
const readTool = getAiDeliveryMcpTool(
|
|
1506
|
-
assert.ok(readTool?.name ===
|
|
1693
|
+
const readTool = getAiDeliveryMcpTool("issue_info");
|
|
1694
|
+
assert.ok(readTool?.name === "issue_info");
|
|
1507
1695
|
const readSchema = readTool.inputSchema;
|
|
1508
1696
|
for (const example of examples) {
|
|
1509
|
-
|
|
1697
|
+
assert.ok(
|
|
1698
|
+
ReadyIssue.safeParse(example.value).success || readSchema.safeParse(example.value).success,
|
|
1699
|
+
"each documented JSON example must satisfy its supported contract"
|
|
1700
|
+
);
|
|
1510
1701
|
}
|
|
1511
1702
|
const readExample = examples.find((example) => readSchema.safeParse(example.value).success);
|
|
1512
|
-
assert.ok(readExample,
|
|
1703
|
+
assert.ok(readExample, "the read-first example must use the actual MCP schema");
|
|
1513
1704
|
const readArguments = readSchema.parse(readExample.value);
|
|
1514
|
-
assert.equal(readArguments.repo,
|
|
1705
|
+
assert.equal(readArguments.repo, "example/widget");
|
|
1515
1706
|
assert.equal(readArguments.issueNumber, 17);
|
|
1516
1707
|
const createExample = examples.find((example) => ReadyIssue.safeParse(example.value).success);
|
|
1517
|
-
assert.ok(createExample,
|
|
1708
|
+
assert.ok(createExample, "the creation example must remain Ready");
|
|
1518
1709
|
const json = createExample.json;
|
|
1519
|
-
const root = mkdtempSync(join(tmpdir(),
|
|
1710
|
+
const root = mkdtempSync(join(tmpdir(), "intake-cli-"));
|
|
1520
1711
|
try {
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1712
|
+
const fields = join(root, "issue.json");
|
|
1713
|
+
writeFileSync(fields, json);
|
|
1714
|
+
for (const line of skill.split("\n").filter((line2) => line2.startsWith("ai-delivery "))) {
|
|
1715
|
+
assert.match(line, /--identity host-author/u);
|
|
1716
|
+
assert.match(line, /--repo example\/widget/u);
|
|
1717
|
+
const argv = (line.match(/'[^']*'|[^\s]+/gu) ?? []).slice(1).map((token) => token.replace(/^'|'$/gu, "")).map((token) => token.replace("/owned/issue.json", fields));
|
|
1718
|
+
const command = argv.find((token) => ["create", "update", "info", "ready:check", "start"].includes(token));
|
|
1719
|
+
assert.ok(command);
|
|
1720
|
+
assert.ok(argv.includes(command === "create" ? "--title" : "--issue"));
|
|
1721
|
+
const result = spawnSync(process.execPath, [resolve("dist/cli.js"), ...argv], {
|
|
1722
|
+
cwd: root,
|
|
1723
|
+
env: {
|
|
1724
|
+
PATH: process.env.PATH ?? "",
|
|
1725
|
+
HOME: root,
|
|
1726
|
+
AI_DELIVERY_CONFIG: join(root, "missing-config.json"),
|
|
1727
|
+
LANG: "en_US.UTF-8"
|
|
1728
|
+
},
|
|
1729
|
+
encoding: "utf8"
|
|
1730
|
+
});
|
|
1731
|
+
assert.notEqual(result.status, 0);
|
|
1732
|
+
assert.doesNotMatch(result.stderr, /unknown option|unknown command|required option/u);
|
|
1733
|
+
assert.match(result.stderr, /missing-config|ENOENT|identity|configuration|config/iu);
|
|
1734
|
+
}
|
|
1735
|
+
const missing = spawnSync(
|
|
1736
|
+
process.execPath,
|
|
1737
|
+
[resolve("dist/cli.js"), "--identity", "host-author", "--repo", "example/widget", "create"],
|
|
1738
|
+
{ cwd: root, env: { HOME: root, PATH: process.env.PATH ?? "" }, encoding: "utf8" }
|
|
1739
|
+
);
|
|
1740
|
+
assert.match(missing.stderr, /required option.*--title/u);
|
|
1741
|
+
assert.ok(
|
|
1742
|
+
execFileSync(process.execPath, [resolve("dist/cli.js"), "--help"], {
|
|
1743
|
+
env: { HOME: root, PATH: process.env.PATH ?? "" },
|
|
1744
|
+
encoding: "utf8"
|
|
1745
|
+
}).includes("create")
|
|
1746
|
+
);
|
|
1747
|
+
} finally {
|
|
1748
|
+
rmSync(root, { recursive: true, force: true });
|
|
1556
1749
|
}
|
|
1557
1750
|
assert.ok(skill.includes(ISSUE_BODY_MARKER));
|
|
1558
|
-
assert.ok(!skill.includes(
|
|
1751
|
+
assert.ok(!skill.includes("ai-delivery develop"));
|
|
1752
|
+
}
|
|
1753
|
+
);
|
|
1754
|
+
test("explicit start changes Todo to the configured In Progress option and preserves unrelated items", async () => {
|
|
1755
|
+
const f = fixture();
|
|
1756
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1757
|
+
assert.ok("branch" in result);
|
|
1758
|
+
assert.equal(f.getStatus(), "Active");
|
|
1759
|
+
assert.equal(f.statusWrites.length, 1);
|
|
1760
|
+
assert.deepEqual(f.statusWrites[0], {
|
|
1761
|
+
projectId: "PROJECT",
|
|
1762
|
+
itemId: "ITEM17",
|
|
1763
|
+
fieldId: "STATUS",
|
|
1764
|
+
optionId: "ACTIVE"
|
|
1765
|
+
});
|
|
1766
|
+
assert.equal(f.comments.length, 1);
|
|
1767
|
+
const retry = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1768
|
+
assert.ok("reused" in retry && retry.reused);
|
|
1769
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1770
|
+
assert.equal(f.statusWrites.length, 1);
|
|
1771
|
+
assert.equal(f.comments.length, 1);
|
|
1559
1772
|
});
|
|
1560
|
-
test(
|
|
1773
|
+
test("explicit start adds missing membership only for its exact issue and accepts already active status", async () => {
|
|
1774
|
+
for (const member of [true, false]) {
|
|
1561
1775
|
const f = fixture();
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
assert.
|
|
1565
|
-
assert.equal(f.
|
|
1566
|
-
assert.
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
fieldId: 'STATUS',
|
|
1570
|
-
optionId: 'ACTIVE',
|
|
1571
|
-
});
|
|
1572
|
-
assert.equal(f.comments.length, 1);
|
|
1573
|
-
const retry = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1574
|
-
assert.ok('reused' in retry && retry.reused);
|
|
1575
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1576
|
-
assert.equal(f.statusWrites.length, 1);
|
|
1577
|
-
assert.equal(f.comments.length, 1);
|
|
1578
|
-
});
|
|
1579
|
-
test('explicit start adds missing membership only for its exact issue and accepts already active status', async () => {
|
|
1580
|
-
for (const member of [true, false]) {
|
|
1581
|
-
const f = fixture();
|
|
1582
|
-
f.controls.projectMember = member;
|
|
1583
|
-
if (member)
|
|
1584
|
-
f.setStatus('Active');
|
|
1585
|
-
assert.ok('branch' in (await startTrackedIssue(f.context, { issueNumber: 17 })));
|
|
1586
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1587
|
-
assert.equal(f.membershipWrites.length, member ? 0 : 1);
|
|
1588
|
-
assert.equal(f.statusWrites.length, member ? 0 : 1);
|
|
1589
|
-
}
|
|
1776
|
+
f.controls.projectMember = member;
|
|
1777
|
+
if (member) f.setStatus("Active");
|
|
1778
|
+
assert.ok("branch" in await startTrackedIssue(f.context, { issueNumber: 17 }));
|
|
1779
|
+
assert.equal(f.getStatus(), "Active");
|
|
1780
|
+
assert.equal(f.membershipWrites.length, member ? 0 : 1);
|
|
1781
|
+
assert.equal(f.statusWrites.length, member ? 0 : 1);
|
|
1782
|
+
}
|
|
1590
1783
|
});
|
|
1591
|
-
test.each([
|
|
1784
|
+
test.each(["before", "after", "readback"])(
|
|
1785
|
+
"existing start returns known-issue recovery for Project %s failure",
|
|
1786
|
+
async (failure) => {
|
|
1592
1787
|
const f = fixture();
|
|
1593
1788
|
f.controls.projectFailure = failure;
|
|
1594
1789
|
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1595
|
-
if (!(
|
|
1596
|
-
|
|
1597
|
-
assert.equal(result.
|
|
1598
|
-
assert.equal(result.failure.phase, 'project-status');
|
|
1790
|
+
if (!("status" in result)) assert.fail("Project failure must not report successful start");
|
|
1791
|
+
assert.equal(result.status, "start-incomplete");
|
|
1792
|
+
assert.equal(result.failure.phase, "project-status");
|
|
1599
1793
|
assert.equal(result.safeResume.arguments.issueNumber, 17);
|
|
1600
|
-
assert.equal(result.safeResume.arguments.repo,
|
|
1601
|
-
assert.equal(result.safeResume.arguments.branch,
|
|
1794
|
+
assert.equal(result.safeResume.arguments.repo, "example/widget");
|
|
1795
|
+
assert.equal(result.safeResume.arguments.branch, "issue/17");
|
|
1602
1796
|
assert.equal(f.comments.length, 0);
|
|
1603
|
-
f.controls.projectFailure =
|
|
1604
|
-
const resumed = await startTrackedIssue(
|
|
1605
|
-
|
|
1606
|
-
|
|
1797
|
+
f.controls.projectFailure = "";
|
|
1798
|
+
const resumed = await startTrackedIssue(
|
|
1799
|
+
f.context,
|
|
1800
|
+
getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
|
|
1801
|
+
);
|
|
1802
|
+
assert.ok("reused" in resumed && resumed.reused);
|
|
1803
|
+
assert.equal(f.getStatus(), "Active");
|
|
1607
1804
|
assert.equal(f.branchWrites.length, 1);
|
|
1608
1805
|
assert.equal(f.comments.length, 1);
|
|
1609
1806
|
assert.equal(f.writes.length, 0);
|
|
1610
|
-
assert.equal(f.statusWrites.length, failure ===
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1807
|
+
assert.equal(f.statusWrites.length, failure === "before" ? 2 : 1);
|
|
1808
|
+
}
|
|
1809
|
+
);
|
|
1810
|
+
test.each(["branch", "journal"])(
|
|
1811
|
+
"existing start reconciles a lost %s response without duplicate mutations",
|
|
1812
|
+
async (failure) => {
|
|
1613
1813
|
const f = fixture();
|
|
1614
|
-
f.controls.branchFailure = failure ===
|
|
1615
|
-
f.controls.journalFailure = failure ===
|
|
1814
|
+
f.controls.branchFailure = failure === "branch";
|
|
1815
|
+
f.controls.journalFailure = failure === "journal";
|
|
1616
1816
|
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1617
|
-
if (!(
|
|
1618
|
-
|
|
1619
|
-
assert.equal(result.status, 'start-incomplete');
|
|
1817
|
+
if (!("status" in result)) assert.fail("An uncertain start must retain recovery");
|
|
1818
|
+
assert.equal(result.status, "start-incomplete");
|
|
1620
1819
|
f.controls.branchFailure = false;
|
|
1621
1820
|
f.controls.journalFailure = false;
|
|
1622
|
-
assert.ok(
|
|
1821
|
+
assert.ok("reused" in await startTrackedIssue(f.context, result.safeResume.arguments));
|
|
1623
1822
|
assert.equal(f.branchWrites.length, 1);
|
|
1624
1823
|
assert.equal(f.comments.length, 1);
|
|
1625
|
-
assert.equal(f.getStatus(),
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1824
|
+
assert.equal(f.getStatus(), "Active");
|
|
1825
|
+
}
|
|
1826
|
+
);
|
|
1827
|
+
test("created start retains its exact issue recovery when Project synchronization fails", async () => {
|
|
1828
|
+
const f = fixture();
|
|
1829
|
+
f.controls.created = false;
|
|
1830
|
+
f.controls.projectFailure = "before";
|
|
1831
|
+
const request = {
|
|
1832
|
+
title: ready().title,
|
|
1833
|
+
body: renderIssueBody(ready()),
|
|
1834
|
+
issueType: "Task",
|
|
1835
|
+
points: 2,
|
|
1836
|
+
requestId: "project-recovery"
|
|
1837
|
+
};
|
|
1838
|
+
const result = await startTrackedIssue(f.context, request);
|
|
1839
|
+
if (!("status" in result)) assert.fail("Expected created recovery");
|
|
1840
|
+
assert.equal(result.status, "created-not-started");
|
|
1841
|
+
assert.equal(result.failure.phase, "project-status");
|
|
1842
|
+
f.controls.projectFailure = "";
|
|
1843
|
+
assert.ok("reused" in await startTrackedIssue(f.context, result.safeResume.arguments));
|
|
1844
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1845
|
+
assert.equal(f.comments.length, 1);
|
|
1846
|
+
assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
|
|
1847
|
+
assert.equal(f.getStatus(), "Active");
|
|
1649
1848
|
});
|
|
1650
|
-
test.each([
|
|
1849
|
+
test.each(["closed", "blocked", "parked", "archived"])(
|
|
1850
|
+
"start recovery refuses current %s truth before Project or journal writes",
|
|
1851
|
+
async (state) => {
|
|
1651
1852
|
const f = fixture();
|
|
1652
1853
|
f.controls.branchFailure = true;
|
|
1653
1854
|
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1654
|
-
if (result.status !==
|
|
1655
|
-
assert.fail('Expected recovery');
|
|
1855
|
+
if (result.status !== "start-incomplete") assert.fail("Expected recovery");
|
|
1656
1856
|
f.controls.branchFailure = false;
|
|
1657
|
-
if (state ===
|
|
1658
|
-
|
|
1659
|
-
if (state ===
|
|
1660
|
-
|
|
1661
|
-
if (state === 'parked')
|
|
1662
|
-
f.live.body = renderIssueBody({ ...ready(), draft: true });
|
|
1663
|
-
if (state === 'archived')
|
|
1664
|
-
f.controls.projectArchived = true;
|
|
1857
|
+
if (state === "closed") f.live.state = "closed";
|
|
1858
|
+
if (state === "blocked") f.controls.blockers = true;
|
|
1859
|
+
if (state === "parked") f.live.body = renderIssueBody({ ...ready(), draft: true });
|
|
1860
|
+
if (state === "archived") f.controls.projectArchived = true;
|
|
1665
1861
|
const retry = await startTrackedIssue(f.context, result.safeResume.arguments).catch((error) => {
|
|
1666
|
-
|
|
1667
|
-
|
|
1862
|
+
assert.ok(error instanceof Error);
|
|
1863
|
+
return void 0;
|
|
1668
1864
|
});
|
|
1669
|
-
assert.ok(retry ===
|
|
1865
|
+
assert.ok(retry === void 0 || "status" in retry, "Current refusal must not report success");
|
|
1670
1866
|
assert.equal(f.branchWrites.length, 1);
|
|
1671
1867
|
assert.equal(f.statusWrites.length, 0);
|
|
1672
1868
|
assert.equal(f.comments.length, 0);
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1869
|
+
}
|
|
1870
|
+
);
|
|
1871
|
+
test.each(["closeAfterBranch", "blockAfterBranch"])(
|
|
1872
|
+
"start rechecks live eligibility after %s before changing the board",
|
|
1873
|
+
async (control) => {
|
|
1675
1874
|
const f = fixture();
|
|
1676
1875
|
f.controls[control] = true;
|
|
1677
1876
|
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
1678
|
-
assert.ok(
|
|
1877
|
+
assert.ok("status" in result);
|
|
1679
1878
|
assert.equal(f.statusWrites.length, 0);
|
|
1680
1879
|
assert.equal(f.comments.length, 0);
|
|
1681
|
-
}
|
|
1880
|
+
}
|
|
1881
|
+
);
|
|
1682
1882
|
async function bindStartFixture(f) {
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1883
|
+
vi.stubEnv("AI_DELIVERY_CONFIG", "/synthetic-unconfigured-delivery-settings.json");
|
|
1884
|
+
const settings = await import("./config/deliveryConfig.js");
|
|
1885
|
+
const issues = await import("./issue.js");
|
|
1886
|
+
vi.spyOn(settings, "loadDeliverySettings").mockResolvedValue({
|
|
1887
|
+
roles: { author: { identity: "author", authSource: "personal" }, reviewer: { identity: "reviewer" } }
|
|
1888
|
+
});
|
|
1889
|
+
vi.spyOn(issues, "loadDeliveryContext").mockResolvedValue(f.context);
|
|
1690
1890
|
}
|
|
1691
|
-
test.each([
|
|
1891
|
+
test.each(["flags", "file", "undefer"])(
|
|
1892
|
+
"CLI update %s changes explicit deferral through current dispatch",
|
|
1893
|
+
async (mode) => {
|
|
1692
1894
|
vi.resetModules();
|
|
1693
1895
|
const f = fixture();
|
|
1694
|
-
if (mode ===
|
|
1695
|
-
|
|
1896
|
+
if (mode === "undefer")
|
|
1897
|
+
f.live.body = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: "Prior condition" } }));
|
|
1696
1898
|
await bindStartFixture(f);
|
|
1697
|
-
const root = mkdtempSync(join(tmpdir(),
|
|
1698
|
-
const fieldsFile = join(root,
|
|
1699
|
-
const condition = { until:
|
|
1899
|
+
const root = mkdtempSync(join(tmpdir(), "deferral-cli-"));
|
|
1900
|
+
const fieldsFile = join(root, "patch.json");
|
|
1901
|
+
const condition = { until: "2020-01-01", trigger: "CLI upstream condition" };
|
|
1700
1902
|
writeFileSync(fieldsFile, JSON.stringify({ defer: condition }));
|
|
1701
1903
|
const argv = process.argv;
|
|
1702
1904
|
const exitCode = process.exitCode;
|
|
1703
|
-
let stdout =
|
|
1704
|
-
let complete = () => {
|
|
1705
|
-
|
|
1706
|
-
|
|
1905
|
+
let stdout = "";
|
|
1906
|
+
let complete = () => {
|
|
1907
|
+
};
|
|
1908
|
+
const output = new Promise((resolve2) => {
|
|
1909
|
+
complete = resolve2;
|
|
1707
1910
|
});
|
|
1708
|
-
vi.spyOn(process.stdout,
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
return true;
|
|
1911
|
+
vi.spyOn(process.stdout, "write").mockImplementation((value) => {
|
|
1912
|
+
stdout += String(value);
|
|
1913
|
+
if (String(value).startsWith("{")) complete();
|
|
1914
|
+
return true;
|
|
1713
1915
|
});
|
|
1714
1916
|
try {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1737
|
-
finally {
|
|
1738
|
-
process.argv = argv;
|
|
1739
|
-
process.exitCode = exitCode;
|
|
1740
|
-
rmSync(root, { recursive: true, force: true });
|
|
1741
|
-
}
|
|
1742
|
-
});
|
|
1743
|
-
test('MCP explicit start returns Project recovery and reuses the exact branch on retry', async () => {
|
|
1744
|
-
const f = fixture();
|
|
1745
|
-
await bindStartFixture(f);
|
|
1746
|
-
f.controls.projectFailure = 'after';
|
|
1747
|
-
const server = (await import('./mcp/index.js')).createAiDeliveryMcpServer({ repoRoot: '/unrelated' });
|
|
1748
|
-
const client = new Client({ name: 'fictional-start-project', version: '1.0.0' });
|
|
1749
|
-
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
1750
|
-
try {
|
|
1751
|
-
await server.connect(serverTransport);
|
|
1752
|
-
await client.connect(clientTransport);
|
|
1753
|
-
const call = async (arguments_) => {
|
|
1754
|
-
const reply = await client.callTool({ name: 'issue_start', arguments: arguments_ });
|
|
1755
|
-
assert.equal(reply.isError, undefined);
|
|
1756
|
-
return JSON.parse(z.object({ content: z.array(z.object({ type: z.literal('text'), text: z.string() })) }).parse(reply).content[0]
|
|
1757
|
-
.text);
|
|
1758
|
-
};
|
|
1759
|
-
const interrupted = await call({ repo: 'example/widget', issueNumber: 17 });
|
|
1760
|
-
assert.equal(interrupted.status, 'start-incomplete');
|
|
1761
|
-
assert.ok(interrupted.safeResume);
|
|
1762
|
-
assert.equal(f.comments.length, 0);
|
|
1763
|
-
f.controls.projectFailure = '';
|
|
1764
|
-
const result = await call(interrupted.safeResume.arguments);
|
|
1765
|
-
assert.equal(result.branch, 'issue/17');
|
|
1766
|
-
assert.equal(result.issueNumber, 17);
|
|
1767
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1768
|
-
assert.equal(f.statusWrites.length, 1);
|
|
1769
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1770
|
-
assert.equal(f.comments.length, 1);
|
|
1771
|
-
}
|
|
1772
|
-
finally {
|
|
1773
|
-
await client.close();
|
|
1774
|
-
await server.close();
|
|
1917
|
+
process.exitCode = void 0;
|
|
1918
|
+
process.argv = [
|
|
1919
|
+
process.execPath,
|
|
1920
|
+
"ai-delivery",
|
|
1921
|
+
"--repo",
|
|
1922
|
+
"example/widget",
|
|
1923
|
+
"update",
|
|
1924
|
+
"--issue",
|
|
1925
|
+
"17",
|
|
1926
|
+
...mode === "undefer" ? ["--undefer"] : mode === "file" ? ["--fields-file", fieldsFile] : ["--defer-until", condition.until, "--defer-trigger", condition.trigger]
|
|
1927
|
+
];
|
|
1928
|
+
await import("./cli.js");
|
|
1929
|
+
await output;
|
|
1930
|
+
const result = z.object({ deferred: z.record(z.string(), z.string()).nullable() }).parse(JSON.parse(stdout));
|
|
1931
|
+
assert.deepEqual(result.deferred, mode === "undefer" ? null : condition);
|
|
1932
|
+
assert.equal(f.writes.length, 1);
|
|
1933
|
+
assert.equal(process.exitCode, void 0);
|
|
1934
|
+
} finally {
|
|
1935
|
+
process.argv = argv;
|
|
1936
|
+
process.exitCode = exitCode;
|
|
1937
|
+
rmSync(root, { recursive: true, force: true });
|
|
1775
1938
|
}
|
|
1939
|
+
}
|
|
1940
|
+
);
|
|
1941
|
+
test("MCP explicit start returns Project recovery and reuses the exact branch on retry", async () => {
|
|
1942
|
+
const f = fixture();
|
|
1943
|
+
await bindStartFixture(f);
|
|
1944
|
+
f.controls.projectFailure = "after";
|
|
1945
|
+
const server = (await import("./mcp/index.js")).createAiDeliveryMcpServer({ repoRoot: "/unrelated" });
|
|
1946
|
+
const client = new Client({ name: "fictional-start-project", version: "1.0.0" });
|
|
1947
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
1948
|
+
try {
|
|
1949
|
+
await server.connect(serverTransport);
|
|
1950
|
+
await client.connect(clientTransport);
|
|
1951
|
+
const call = async (arguments_) => {
|
|
1952
|
+
const reply = await client.callTool({ name: "issue_start", arguments: arguments_ });
|
|
1953
|
+
assert.equal(reply.isError, void 0);
|
|
1954
|
+
return JSON.parse(
|
|
1955
|
+
z.object({ content: z.array(z.object({ type: z.literal("text"), text: z.string() })) }).parse(reply).content[0].text
|
|
1956
|
+
);
|
|
1957
|
+
};
|
|
1958
|
+
const interrupted = await call({ repo: "example/widget", issueNumber: 17 });
|
|
1959
|
+
assert.equal(interrupted.status, "start-incomplete");
|
|
1960
|
+
assert.ok(interrupted.safeResume);
|
|
1961
|
+
assert.equal(f.comments.length, 0);
|
|
1962
|
+
f.controls.projectFailure = "";
|
|
1963
|
+
const result = await call(interrupted.safeResume.arguments);
|
|
1964
|
+
assert.equal(result.branch, "issue/17");
|
|
1965
|
+
assert.equal(result.issueNumber, 17);
|
|
1966
|
+
assert.equal(f.getStatus(), "Active");
|
|
1967
|
+
assert.equal(f.statusWrites.length, 1);
|
|
1968
|
+
assert.equal(f.branchWrites.length, 1);
|
|
1969
|
+
assert.equal(f.comments.length, 1);
|
|
1970
|
+
} finally {
|
|
1971
|
+
await client.close();
|
|
1972
|
+
await server.close();
|
|
1973
|
+
}
|
|
1776
1974
|
});
|
|
1777
|
-
test(
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1975
|
+
test("current MCP update/read/list/start routes enforce deferral and recorded WIP capacity override", async () => {
|
|
1976
|
+
const f = fixture();
|
|
1977
|
+
await bindStartFixture(f);
|
|
1978
|
+
const server = (await import("./mcp/index.js")).createAiDeliveryMcpServer({ repoRoot: "/unrelated" });
|
|
1979
|
+
const client = new Client({ name: "synthetic-deferral-wip", version: "1.0.0" });
|
|
1980
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
1981
|
+
const call = async (name, args, error = false) => {
|
|
1982
|
+
const result = await client.callTool({ name, arguments: { repo: "example/widget", ...args } });
|
|
1983
|
+
assert.equal(Boolean(result.isError), error, JSON.stringify(result.content));
|
|
1984
|
+
const content = result.content;
|
|
1985
|
+
const value = error ? content[0].text : JSON.parse(content[0].text);
|
|
1986
|
+
return value;
|
|
1987
|
+
};
|
|
1988
|
+
try {
|
|
1989
|
+
await server.connect(serverTransport);
|
|
1990
|
+
await client.connect(clientTransport);
|
|
1991
|
+
const condition = { until: "2020-01-01", trigger: "Upstream ships" };
|
|
1992
|
+
const readback = z.object({ deferred: z.record(z.string(), z.string()).nullable() });
|
|
1993
|
+
assert.deepEqual(
|
|
1994
|
+
readback.parse(await call("issue_update", { issueNumber: 17, defer: condition })).deferred,
|
|
1995
|
+
condition
|
|
1996
|
+
);
|
|
1997
|
+
assert.deepEqual(readback.parse(await call("issue_info", { issueNumber: 17 })).deferred, condition);
|
|
1998
|
+
assert.deepEqual(
|
|
1999
|
+
z.object({ issues: z.array(readback) }).parse(await call("issue_list", {})).issues[0].deferred,
|
|
2000
|
+
condition
|
|
2001
|
+
);
|
|
2002
|
+
assert.match(
|
|
2003
|
+
z.string().parse(await call("issue_start", { issueNumber: 17, overrideReason: "Capacity only." }, true)),
|
|
2004
|
+
/deferred/u
|
|
2005
|
+
);
|
|
2006
|
+
await call("issue_update", { issueNumber: 17, undefer: true });
|
|
2007
|
+
f.controls.capacityMode = true;
|
|
2008
|
+
f.live.labels = ["critical"];
|
|
2009
|
+
f.context.config = {
|
|
2010
|
+
...f.context.config,
|
|
2011
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
1789
2012
|
};
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
f.live.labels = ['critical'];
|
|
1802
|
-
f.context.config = {
|
|
1803
|
-
...f.context.config,
|
|
1804
|
-
wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
|
|
1805
|
-
};
|
|
1806
|
-
assert.match(z.string().parse(await call('issue_start', { issueNumber: 17 }, true)), /WIP/u);
|
|
1807
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1808
|
-
await call('issue_start', { issueNumber: 17, overrideReason: 'Explicit synthetic capacity exception.' });
|
|
1809
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1810
|
-
assert.equal(f.comments.length, 2);
|
|
1811
|
-
await call('issue_start', { issueNumber: 17 });
|
|
1812
|
-
assert.equal(f.comments.length, 2);
|
|
1813
|
-
}
|
|
1814
|
-
finally {
|
|
1815
|
-
await client.close();
|
|
1816
|
-
await server.close();
|
|
1817
|
-
}
|
|
2013
|
+
assert.match(z.string().parse(await call("issue_start", { issueNumber: 17 }, true)), /WIP/u);
|
|
2014
|
+
assert.equal(f.branchWrites.length, 0);
|
|
2015
|
+
await call("issue_start", { issueNumber: 17, overrideReason: "Explicit synthetic capacity exception." });
|
|
2016
|
+
assert.equal(f.getStatus(), "Active");
|
|
2017
|
+
assert.equal(f.comments.length, 2);
|
|
2018
|
+
await call("issue_start", { issueNumber: 17 });
|
|
2019
|
+
assert.equal(f.comments.length, 2);
|
|
2020
|
+
} finally {
|
|
2021
|
+
await client.close();
|
|
2022
|
+
await server.close();
|
|
2023
|
+
}
|
|
1818
2024
|
});
|
|
1819
|
-
test.each([
|
|
2025
|
+
test.each(["success", "failure", "capacity", "deferred", "capacity-override"])(
|
|
2026
|
+
"CLI explicit start shares Project transition and %s output",
|
|
2027
|
+
async (mode) => {
|
|
1820
2028
|
vi.resetModules();
|
|
1821
2029
|
const f = fixture();
|
|
1822
2030
|
await bindStartFixture(f);
|
|
1823
|
-
if (mode ===
|
|
1824
|
-
|
|
1825
|
-
if (mode ===
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
f.
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
|
|
1833
|
-
};
|
|
2031
|
+
if (mode === "failure") f.controls.projectFailure = "before";
|
|
2032
|
+
if (mode === "deferred") await updateIssue(f.context, { issueNumber: 17, defer: {} });
|
|
2033
|
+
if (mode === "capacity" || mode === "capacity-override") {
|
|
2034
|
+
f.controls.capacityMode = true;
|
|
2035
|
+
f.live.labels = ["critical"];
|
|
2036
|
+
f.context.config = {
|
|
2037
|
+
...f.context.config,
|
|
2038
|
+
wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
|
|
2039
|
+
};
|
|
1834
2040
|
}
|
|
1835
2041
|
const argv = process.argv;
|
|
1836
2042
|
const exitCode = process.exitCode;
|
|
1837
|
-
let stdout =
|
|
1838
|
-
let stderr =
|
|
1839
|
-
let completed = () => {
|
|
1840
|
-
|
|
1841
|
-
|
|
2043
|
+
let stdout = "";
|
|
2044
|
+
let stderr = "";
|
|
2045
|
+
let completed = () => {
|
|
2046
|
+
};
|
|
2047
|
+
const output = new Promise((resolve2) => {
|
|
2048
|
+
completed = resolve2;
|
|
1842
2049
|
});
|
|
1843
|
-
vi.spyOn(process.stdout,
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
return true;
|
|
2050
|
+
vi.spyOn(process.stdout, "write").mockImplementation((value) => {
|
|
2051
|
+
stdout += String(value);
|
|
2052
|
+
if (String(value).startsWith("{")) completed();
|
|
2053
|
+
return true;
|
|
1848
2054
|
});
|
|
1849
|
-
vi.spyOn(process.stderr,
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2055
|
+
vi.spyOn(process.stderr, "write").mockImplementation((value) => {
|
|
2056
|
+
stderr += String(value);
|
|
2057
|
+
completed();
|
|
2058
|
+
return true;
|
|
1853
2059
|
});
|
|
1854
2060
|
try {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
process.argv = argv;
|
|
1887
|
-
process.exitCode = exitCode;
|
|
2061
|
+
process.exitCode = void 0;
|
|
2062
|
+
process.argv = [process.execPath, "ai-delivery", "--repo", "example/widget", "start", "--issue", "17"];
|
|
2063
|
+
if (mode === "capacity-override")
|
|
2064
|
+
process.argv.push("--override-reason", "Explicit synthetic capacity exception.");
|
|
2065
|
+
await import("./cli.js");
|
|
2066
|
+
await output;
|
|
2067
|
+
if (mode === "deferred" || mode === "capacity") {
|
|
2068
|
+
assert.match(stderr, mode === "deferred" ? /deferred/u : /WIP/u);
|
|
2069
|
+
assert.equal(process.exitCode, 1);
|
|
2070
|
+
assert.equal(f.branchWrites.length, 0);
|
|
2071
|
+
assert.equal(f.statusWrites.filter((x) => x.optionId === "ACTIVE").length, 0);
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
const result = JSON.parse(stdout);
|
|
2075
|
+
if (mode === "failure") {
|
|
2076
|
+
assert.equal(result.status, "start-incomplete");
|
|
2077
|
+
assert.equal(result.safeResume?.arguments.issueNumber, 17);
|
|
2078
|
+
assert.equal(process.exitCode, 1);
|
|
2079
|
+
assert.equal(f.getStatus(), "Queued");
|
|
2080
|
+
assert.equal(f.comments.length, 0);
|
|
2081
|
+
} else {
|
|
2082
|
+
assert.equal(result.branch, "issue/17");
|
|
2083
|
+
assert.equal(process.exitCode, void 0);
|
|
2084
|
+
assert.equal(f.getStatus(), "Active");
|
|
2085
|
+
assert.equal(f.comments.length, mode === "capacity-override" ? 2 : 1);
|
|
2086
|
+
}
|
|
2087
|
+
assert.equal(f.branchWrites.length, 1);
|
|
2088
|
+
assert.equal(f.statusWrites.length, 1);
|
|
2089
|
+
} finally {
|
|
2090
|
+
process.argv = argv;
|
|
2091
|
+
process.exitCode = exitCode;
|
|
1888
2092
|
}
|
|
2093
|
+
}
|
|
2094
|
+
);
|
|
2095
|
+
test("info and unrelated body edits never imply explicit activation", async () => {
|
|
2096
|
+
const f = fixture();
|
|
2097
|
+
const { issueInfo: issueInfo2 } = await import("./issue.js");
|
|
2098
|
+
await issueInfo2(f.context, 17);
|
|
2099
|
+
await updateIssue(f.context, {
|
|
2100
|
+
issueNumber: 17,
|
|
2101
|
+
outcome: "Reject invalid widgets while retaining deferred execution."
|
|
2102
|
+
});
|
|
2103
|
+
assert.equal(f.getStatus(), "Queued");
|
|
2104
|
+
assert.equal(f.statusWrites.length, 0);
|
|
2105
|
+
assert.equal(f.branchWrites.length, 0);
|
|
2106
|
+
assert.equal(f.comments.length, 0);
|
|
1889
2107
|
});
|
|
1890
|
-
test(
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
await issueInfo(f.context, 17);
|
|
1894
|
-
await updateIssue(f.context, {
|
|
1895
|
-
issueNumber: 17,
|
|
1896
|
-
outcome: 'Reject invalid widgets while retaining deferred execution.',
|
|
1897
|
-
});
|
|
1898
|
-
assert.equal(f.getStatus(), 'Queued');
|
|
1899
|
-
assert.equal(f.statusWrites.length, 0);
|
|
1900
|
-
assert.equal(f.branchWrites.length, 0);
|
|
1901
|
-
assert.equal(f.comments.length, 0);
|
|
1902
|
-
});
|
|
1903
|
-
test.each(['project-status', 'journal'])('created recovery after %s preserves a subsequent native park', async (phase) => {
|
|
2108
|
+
test.each(["project-status", "journal"])(
|
|
2109
|
+
"created recovery after %s preserves a subsequent native park",
|
|
2110
|
+
async (phase) => {
|
|
1904
2111
|
const f = fixture();
|
|
1905
2112
|
f.controls.created = false;
|
|
1906
|
-
f.controls.projectFailure = phase ===
|
|
1907
|
-
f.controls.journalFailure = phase ===
|
|
2113
|
+
f.controls.projectFailure = phase === "project-status" ? "before" : "";
|
|
2114
|
+
f.controls.journalFailure = phase === "journal";
|
|
1908
2115
|
const result = await startTrackedIssue(f.context, {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
2116
|
+
title: ready().title,
|
|
2117
|
+
body: renderIssueBody(ready()),
|
|
2118
|
+
issueType: "Task",
|
|
2119
|
+
points: 2,
|
|
2120
|
+
requestId: "parked-created-" + phase
|
|
1914
2121
|
});
|
|
1915
|
-
if (result.status !==
|
|
1916
|
-
assert.fail('Expected known-created recovery');
|
|
2122
|
+
if (result.status !== "created-not-started") assert.fail("Expected known-created recovery");
|
|
1917
2123
|
assert.equal(result.failure.phase, phase);
|
|
1918
|
-
f.controls.projectFailure =
|
|
2124
|
+
f.controls.projectFailure = "";
|
|
1919
2125
|
f.controls.journalFailure = false;
|
|
1920
2126
|
await updateIssue(f.context, { issueNumber: 17, park: true });
|
|
1921
2127
|
const parkedBody = f.live.body;
|
|
1922
2128
|
const writesBeforeRetry = f.writes.length;
|
|
1923
2129
|
const statusWritesBeforeRetry = f.statusWrites.length;
|
|
1924
2130
|
const commentsBeforeRetry = f.comments.length;
|
|
1925
|
-
const retry = await startTrackedIssue(
|
|
1926
|
-
|
|
1927
|
-
|
|
2131
|
+
const retry = await startTrackedIssue(
|
|
2132
|
+
f.context,
|
|
2133
|
+
getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
|
|
2134
|
+
).catch((error) => {
|
|
2135
|
+
assert.ok(error instanceof Error);
|
|
2136
|
+
return void 0;
|
|
1928
2137
|
});
|
|
1929
2138
|
assert.equal(f.live.body, parkedBody);
|
|
1930
2139
|
assert.equal(parseIssueBody(f.live.body, { title: f.live.title }).issue.draft, true);
|
|
1931
|
-
assert.equal(f.getStatus(),
|
|
1932
|
-
assert.ok(retry ===
|
|
2140
|
+
assert.equal(f.getStatus(), "Queued");
|
|
2141
|
+
assert.ok(retry === void 0 || retry.status !== void 0, "Parked recovery must not succeed");
|
|
1933
2142
|
assert.equal(f.writes.length, writesBeforeRetry);
|
|
1934
2143
|
assert.equal(f.statusWrites.length, statusWritesBeforeRetry);
|
|
1935
2144
|
assert.equal(f.comments.length, commentsBeforeRetry);
|
|
1936
2145
|
assert.equal(f.branchWrites.length, 1);
|
|
2146
|
+
}
|
|
2147
|
+
);
|
|
2148
|
+
test("created post-tracking recovery preserves later ready content without replaying tracking writes", async () => {
|
|
2149
|
+
const f = fixture();
|
|
2150
|
+
f.controls.created = false;
|
|
2151
|
+
f.controls.projectFailure = "before";
|
|
2152
|
+
const result = await startTrackedIssue(f.context, {
|
|
2153
|
+
title: ready().title,
|
|
2154
|
+
body: renderIssueBody(ready()),
|
|
2155
|
+
issueType: "Task",
|
|
2156
|
+
points: 2,
|
|
2157
|
+
requestId: "edited-created-recovery"
|
|
2158
|
+
});
|
|
2159
|
+
if (result.status !== "created-not-started") assert.fail("Expected known-created recovery");
|
|
2160
|
+
f.controls.projectFailure = "";
|
|
2161
|
+
await updateIssue(f.context, { issueNumber: 17, outcome: "Deliver the revised current acceptance evidence." });
|
|
2162
|
+
const revised = f.live.body;
|
|
2163
|
+
const writes = f.writes.length;
|
|
2164
|
+
assert.ok(
|
|
2165
|
+
"reused" in await startTrackedIssue(
|
|
2166
|
+
f.context,
|
|
2167
|
+
getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
|
|
2168
|
+
)
|
|
2169
|
+
);
|
|
2170
|
+
assert.equal(f.live.body, revised);
|
|
2171
|
+
assert.equal(f.writes.length, writes);
|
|
2172
|
+
assert.equal(f.branchWrites.length, 1);
|
|
2173
|
+
assert.equal(f.getStatus(), "Active");
|
|
1937
2174
|
});
|
|
1938
|
-
test
|
|
1939
|
-
const f = fixture();
|
|
1940
|
-
f.controls.created = false;
|
|
1941
|
-
f.controls.projectFailure = 'before';
|
|
1942
|
-
const result = await startTrackedIssue(f.context, {
|
|
1943
|
-
title: ready().title,
|
|
1944
|
-
body: renderIssueBody(ready()),
|
|
1945
|
-
issueType: 'Task',
|
|
1946
|
-
points: 2,
|
|
1947
|
-
requestId: 'edited-created-recovery',
|
|
1948
|
-
});
|
|
1949
|
-
if (result.status !== 'created-not-started')
|
|
1950
|
-
assert.fail('Expected known-created recovery');
|
|
1951
|
-
f.controls.projectFailure = '';
|
|
1952
|
-
await updateIssue(f.context, { issueNumber: 17, outcome: 'Deliver the revised current acceptance evidence.' });
|
|
1953
|
-
const revised = f.live.body;
|
|
1954
|
-
const writes = f.writes.length;
|
|
1955
|
-
assert.ok('reused' in
|
|
1956
|
-
(await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments))));
|
|
1957
|
-
assert.equal(f.live.body, revised);
|
|
1958
|
-
assert.equal(f.writes.length, writes);
|
|
1959
|
-
assert.equal(f.branchWrites.length, 1);
|
|
1960
|
-
assert.equal(f.getStatus(), 'Active');
|
|
1961
|
-
});
|
|
1962
|
-
//# sourceMappingURL=issueIntake.test.js.map
|
|
2175
|
+
//# sourceMappingURL=issueIntake.test.js.map
|