@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
|
@@ -1,713 +1,791 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { issueProjectItemsResponse } from "./issueProjectItems.js";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
chmodSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
realpathSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
unlinkSync,
|
|
14
|
+
writeFileSync
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { basename, join } from "node:path";
|
|
18
|
+
import { pathToFileURL } from "node:url";
|
|
19
|
+
import { onTestFinished, vi } from "vitest";
|
|
20
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
21
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
22
|
+
import * as githubClients from "../github/client.js";
|
|
23
|
+
import { IssueFields, renderIssueBody } from "../issueContract.js";
|
|
24
|
+
import { digestBytes, digestValue } from "../delivery/common.js";
|
|
25
|
+
import { createAiDeliveryMcpServer } from "../mcp/index.js";
|
|
26
|
+
import { syntheticDiscoveryClients } from "./discovery.js";
|
|
27
|
+
const fixtureFields = IssueFields.parse({
|
|
28
|
+
title: "Reject invalid widget identifiers before persistence",
|
|
29
|
+
issueType: "Task",
|
|
30
|
+
points: 2,
|
|
31
|
+
problem: "Invalid widget identifiers currently reach persistence.",
|
|
32
|
+
outcome: "Reject invalid identifiers before any persistence call.",
|
|
33
|
+
acceptanceCriteria: [
|
|
34
|
+
{
|
|
35
|
+
behavior: "Invalid identifiers return an error with zero persistence calls.",
|
|
36
|
+
verifiedBy: "Synthetic port regression test; node consumer-trap.cjs and npm run trap are inert verification prose."
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
outOfScope: ["Storage format changes."],
|
|
40
|
+
context: { components: ["Widget validation"], files: [], evidence: [] }
|
|
29
41
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
function fixtureGit(root, ...args) {
|
|
43
|
+
return execFileSync(
|
|
44
|
+
"git",
|
|
45
|
+
["-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-c", "credential.helper=", "-C", root, ...args],
|
|
46
|
+
{
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
timeout: 5e3,
|
|
49
|
+
maxBuffer: 64 * 1024,
|
|
50
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
51
|
+
env: {
|
|
52
|
+
PATH: process.env.PATH,
|
|
53
|
+
HOME: tmpdir(),
|
|
54
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
55
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
56
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
57
|
+
GIT_AUTHOR_NAME: "Fictional Operator",
|
|
58
|
+
GIT_AUTHOR_EMAIL: "operator@example.invalid",
|
|
59
|
+
GIT_COMMITTER_NAME: "Fictional Operator",
|
|
60
|
+
GIT_COMMITTER_EMAIL: "operator@example.invalid"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
).trim();
|
|
49
64
|
}
|
|
50
65
|
let fixtureOwner;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
function inertTarget(signal, registerDisposal = (cleanup) => onTestFinished(cleanup)) {
|
|
67
|
+
assert.equal(fixtureOwner, void 0, "The previous fixture must finish disposal before another owns global ports");
|
|
68
|
+
signal?.throwIfAborted();
|
|
69
|
+
const base = realpathSync(mkdtempSync(join(tmpdir(), "ai-delivery-inert-target-")));
|
|
70
|
+
const owned = lstatSync(base);
|
|
71
|
+
const owner = /* @__PURE__ */ Symbol("inert-target");
|
|
72
|
+
fixtureOwner = owner;
|
|
73
|
+
const shutdown = new AbortController();
|
|
74
|
+
const fixtureSignal = signal === void 0 ? shutdown.signal : AbortSignal.any([shutdown.signal, signal]);
|
|
75
|
+
const activeCalls = /* @__PURE__ */ new Set();
|
|
76
|
+
const connections = /* @__PURE__ */ new Set();
|
|
77
|
+
const userPath = join(base, "user.json");
|
|
78
|
+
const previousConfig = process.env.AI_DELIVERY_CONFIG;
|
|
79
|
+
let configInstalled = false;
|
|
80
|
+
let restoreClients;
|
|
81
|
+
const restoreGlobals = () => {
|
|
82
|
+
assert.equal(fixtureOwner, owner, "A disposed fixture must not restore another fixture's globals");
|
|
83
|
+
try {
|
|
84
|
+
restoreClients?.();
|
|
85
|
+
if (configInstalled) {
|
|
86
|
+
assert.equal(process.env.AI_DELIVERY_CONFIG, userPath, "Fixture configuration ownership changed");
|
|
87
|
+
if (previousConfig === void 0) delete process.env.AI_DELIVERY_CONFIG;
|
|
88
|
+
else process.env.AI_DELIVERY_CONFIG = previousConfig;
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
fixtureOwner = void 0;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const observations = [];
|
|
96
|
+
const root = join(base, "consumer");
|
|
97
|
+
const sentinel = join(base, "policy-executed");
|
|
98
|
+
mkdirSync(root);
|
|
99
|
+
fixtureGit(root, "init", "-q", "-b", "main");
|
|
100
|
+
fixtureGit(root, "remote", "add", "origin", "https://github.com/example/widget.git");
|
|
101
|
+
writeFileSync(join(root, ".gitignore"), ".worktrees/\n.issue-cli/\n");
|
|
102
|
+
writeFileSync(join(root, "change.ts"), "export const fictional = true;\n");
|
|
103
|
+
const payload = (marker) => `import {writeFileSync} from 'node:fs';writeFileSync(${JSON.stringify(sentinel)},JSON.stringify({marker:${JSON.stringify(marker)},module:import.meta.url}),{flag:'wx'});export const deliverySettings={};
|
|
104
|
+
`;
|
|
105
|
+
const tracked = payload("tracked"), edited = payload("edited");
|
|
106
|
+
writeFileSync(join(root, "ai-delivery.policy.mjs"), tracked);
|
|
107
|
+
for (const file of ["ai-delivery.config.mjs", "ai-delivery.config.js"]) writeFileSync(join(root, file), tracked);
|
|
108
|
+
writeFileSync(
|
|
109
|
+
join(root, "consumer-trap.cjs"),
|
|
110
|
+
`require('node:fs').writeFileSync(${JSON.stringify(sentinel)},'repository script executed',{flag:'wx'});
|
|
111
|
+
`
|
|
112
|
+
);
|
|
113
|
+
writeFileSync(
|
|
114
|
+
join(root, "package.json"),
|
|
115
|
+
JSON.stringify({
|
|
116
|
+
name: "synthetic-hostile-consumer",
|
|
117
|
+
version: "1.0.0",
|
|
118
|
+
type: "module",
|
|
119
|
+
scripts: Object.fromEntries(["prepare", "postinstall", "test"].map((name) => [name, "node consumer-trap.cjs"]))
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
fixtureGit(root, "add", ".");
|
|
123
|
+
fixtureGit(root, "commit", "-qm", "Owned inert consumer");
|
|
124
|
+
const head = fixtureGit(root, "rev-parse", "HEAD");
|
|
125
|
+
const tree = fixtureGit(root, "rev-parse", "HEAD^{tree}");
|
|
126
|
+
for (const name of ["pre-commit", "post-commit", "post-checkout", "pre-push"]) {
|
|
127
|
+
const hook = join(root, ".git", "hooks", name);
|
|
128
|
+
writeFileSync(hook, `#!/bin/sh
|
|
129
|
+
printf 'repository hook executed' > '${sentinel.replaceAll("'", "'\\''")}'
|
|
130
|
+
`);
|
|
131
|
+
chmodSync(hook, 493);
|
|
132
|
+
}
|
|
133
|
+
fixtureGit(root, "update-ref", "refs/remotes/origin/main", head);
|
|
134
|
+
writeFileSync(
|
|
135
|
+
userPath,
|
|
136
|
+
JSON.stringify({
|
|
137
|
+
schemaVersion: "ai-delivery.user@1",
|
|
138
|
+
roles: {
|
|
139
|
+
author: { authSource: "personal", identity: "author", credentialEnv: { token: "FICTIONAL_AUTHOR_TOKEN" } },
|
|
140
|
+
reviewer: {
|
|
141
|
+
identity: "reviewer",
|
|
142
|
+
credentialEnv: {
|
|
143
|
+
appId: "FICTIONAL_REVIEW_APP",
|
|
144
|
+
installationId: "FICTIONAL_REVIEW_INSTALL",
|
|
145
|
+
privateKeyPath: "FICTIONAL_REVIEW_KEY"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
checkoutRoots: [base],
|
|
150
|
+
project: 1,
|
|
151
|
+
pointsField: "Estimate",
|
|
152
|
+
priorityField: "Urgency",
|
|
153
|
+
statusField: "Flow",
|
|
154
|
+
statuses: { blocked: "Waiting", done: "Shipped", inProgress: "Active", todo: "Queued" },
|
|
155
|
+
issueTypes: ["Task"]
|
|
156
|
+
}),
|
|
157
|
+
{ mode: 384 }
|
|
158
|
+
);
|
|
159
|
+
process.env.AI_DELIVERY_CONFIG = userPath;
|
|
160
|
+
configInstalled = true;
|
|
161
|
+
const calls = [];
|
|
162
|
+
const record = (name, input = null) => {
|
|
163
|
+
calls.push({ name, input });
|
|
164
|
+
};
|
|
165
|
+
const state = {
|
|
166
|
+
title: fixtureFields.title,
|
|
167
|
+
body: renderIssueBody(fixtureFields),
|
|
168
|
+
issueState: "open",
|
|
169
|
+
points: "2",
|
|
170
|
+
priority: "High",
|
|
171
|
+
projectOption: "STATUS-0",
|
|
172
|
+
linked: true,
|
|
173
|
+
published: true,
|
|
174
|
+
draft: false,
|
|
175
|
+
prTitle: "Reject invalid widget identifiers",
|
|
176
|
+
prBody: "Closes #17",
|
|
177
|
+
merged: false,
|
|
178
|
+
closedCount: 0,
|
|
179
|
+
reviewDecision: "APPROVED",
|
|
180
|
+
mergeAckLost: false
|
|
181
|
+
};
|
|
182
|
+
const artifactContent = {
|
|
183
|
+
authorIdentity: "author",
|
|
184
|
+
reviewerIdentity: "reviewer",
|
|
185
|
+
checks: ["Synthetic focused regression"],
|
|
186
|
+
diffScopeHash: digestValue(["change.ts"]),
|
|
187
|
+
elapsedMs: 1,
|
|
188
|
+
findings: [],
|
|
189
|
+
head: { sha: head, tree },
|
|
190
|
+
issueNumber: 17,
|
|
191
|
+
prNumber: 23,
|
|
192
|
+
readOnly: true,
|
|
193
|
+
requestedEffort: "xhigh",
|
|
194
|
+
requestedModel: "gpt-6-astra",
|
|
195
|
+
effectiveEffort: "unknown",
|
|
196
|
+
effectiveModel: "unknown",
|
|
197
|
+
schemaVersion: "ai-delivery.review-artifact@1",
|
|
198
|
+
summary: "Fictional independent review.",
|
|
199
|
+
verdict: "approve"
|
|
200
|
+
};
|
|
201
|
+
const artifact = { ...artifactContent, artifactId: digestValue(artifactContent) };
|
|
202
|
+
const artifactPath = join(base, "review.json");
|
|
203
|
+
writeFileSync(artifactPath, JSON.stringify(artifact), { mode: 384 });
|
|
204
|
+
const reviewBody = `${artifact.summary}
|
|
205
|
+
|
|
206
|
+
<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->
|
|
207
|
+
<!-- ai-delivery-review-artifact-data: ${Buffer.from(JSON.stringify(artifact)).toString("base64url")} -->`;
|
|
208
|
+
const review = {
|
|
209
|
+
id: 99,
|
|
210
|
+
user: { login: "reviewer[bot]", id: 99, type: "Bot" },
|
|
211
|
+
state: "APPROVED",
|
|
212
|
+
commit_id: head,
|
|
213
|
+
body: reviewBody,
|
|
214
|
+
html_url: "https://github.com/example/widget/pull/23#pullrequestreview-99"
|
|
215
|
+
};
|
|
216
|
+
const reviews = [review];
|
|
217
|
+
const comments = [];
|
|
218
|
+
let nextCommentId = 101;
|
|
219
|
+
const addComment = (id, body, app = false, number = 17) => {
|
|
220
|
+
const created = new Date(Date.now() + 1e3).toISOString();
|
|
221
|
+
const comment = {
|
|
222
|
+
id,
|
|
223
|
+
node_id: `COMMENT${id}`,
|
|
224
|
+
body,
|
|
225
|
+
html_url: `https://github.com/example/widget/issues/${number}#issuecomment-${id}`,
|
|
226
|
+
issue_url: `https://api.github.com/repos/example/widget/issues/${number}`,
|
|
227
|
+
created_at: created,
|
|
228
|
+
updated_at: created,
|
|
229
|
+
lastEditedAt: null,
|
|
230
|
+
editor: null,
|
|
231
|
+
isMinimized: false,
|
|
232
|
+
user: app ? { id: 99, login: "reviewer[bot]", type: "Bot" } : { id: 42, login: "operator", type: "User" }
|
|
233
|
+
};
|
|
234
|
+
comments.push(comment);
|
|
235
|
+
return comment;
|
|
236
|
+
};
|
|
237
|
+
const issue = (number = 17) => ({
|
|
238
|
+
number,
|
|
239
|
+
id: 100 + number,
|
|
240
|
+
node_id: `ISSUE${number}`,
|
|
241
|
+
title: state.title,
|
|
242
|
+
body: state.body,
|
|
243
|
+
state: state.issueState,
|
|
244
|
+
state_reason: state.issueState === "closed" ? "completed" : null,
|
|
245
|
+
html_url: `https://github.com/example/widget/issues/${number}`,
|
|
246
|
+
created_at: "2026-01-01T00:00:00Z",
|
|
247
|
+
updated_at: "2026-01-02T00:00:00Z",
|
|
248
|
+
labels: [],
|
|
249
|
+
type: { name: "Task" }
|
|
250
|
+
});
|
|
251
|
+
const pr = () => ({
|
|
252
|
+
number: 23,
|
|
253
|
+
node_id: "PR23",
|
|
254
|
+
changed_files: 1,
|
|
255
|
+
title: state.prTitle,
|
|
256
|
+
body: state.prBody,
|
|
257
|
+
html_url: "https://github.com/example/widget/pull/23",
|
|
258
|
+
state: state.merged ? "closed" : "open",
|
|
259
|
+
draft: state.draft,
|
|
260
|
+
merged: state.merged,
|
|
261
|
+
merge_commit_sha: state.merged ? "c".repeat(40) : null,
|
|
262
|
+
mergeable: true,
|
|
263
|
+
mergeable_state: "clean",
|
|
264
|
+
head: { sha: head, ref: "issue/17", repo: { full_name: "example/widget" } },
|
|
265
|
+
base: { sha: head, ref: "main", repo: { full_name: "example/widget" } },
|
|
266
|
+
user: { login: "operator" }
|
|
267
|
+
});
|
|
268
|
+
const fields = () => [
|
|
269
|
+
{
|
|
270
|
+
issue_field_id: 101,
|
|
271
|
+
issue_field_name: "Estimate",
|
|
272
|
+
data_type: "single_select",
|
|
273
|
+
value: state.points,
|
|
274
|
+
single_select_option: { name: state.points }
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
issue_field_id: 102,
|
|
278
|
+
issue_field_name: "Urgency",
|
|
279
|
+
data_type: "single_select",
|
|
280
|
+
value: state.priority,
|
|
281
|
+
single_select_option: { name: state.priority }
|
|
282
|
+
}
|
|
283
|
+
];
|
|
284
|
+
const item = () => ({
|
|
285
|
+
id: "ITEM17",
|
|
286
|
+
isArchived: false,
|
|
287
|
+
project: { id: "PROJECT-1", number: 1 },
|
|
288
|
+
content: { __typename: "Issue", id: "ISSUE17" },
|
|
289
|
+
fieldValueByName: {
|
|
290
|
+
__typename: "ProjectV2ItemFieldSingleSelectValue",
|
|
291
|
+
optionId: state.projectOption,
|
|
292
|
+
name: ["Queued", "Active", "Waiting", "Shipped"][Number(state.projectOption.slice(-1))],
|
|
293
|
+
field: { id: "STATUS-FIELD", name: "Flow" }
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
const rest = {
|
|
297
|
+
paginate: async (method, input) => {
|
|
298
|
+
assert.equal(method, rest.pulls.list, "Only the synthetic PR listing port may paginate");
|
|
299
|
+
return (await method(input)).data;
|
|
300
|
+
},
|
|
301
|
+
checks: {
|
|
302
|
+
listForRef: async (input) => {
|
|
303
|
+
record("checks.listForRef", input);
|
|
304
|
+
return {
|
|
305
|
+
data: { total_count: 1, check_runs: [{ name: "checks", status: "completed", conclusion: "success" }] }
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
request: async (route, input = {}) => {
|
|
310
|
+
record(route, input);
|
|
311
|
+
if (route === "GET /orgs/{org}/issue-fields")
|
|
312
|
+
return {
|
|
313
|
+
data: [
|
|
314
|
+
{
|
|
315
|
+
id: 101,
|
|
316
|
+
name: "Estimate",
|
|
317
|
+
data_type: "single_select",
|
|
318
|
+
options: ["1", "2", "4"].map((name) => ({ name }))
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
id: 102,
|
|
322
|
+
name: "Urgency",
|
|
323
|
+
data_type: "single_select",
|
|
324
|
+
options: ["High", "Low"].map((name) => ({ name }))
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
};
|
|
328
|
+
if (route === "POST /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values") {
|
|
329
|
+
const values = input.issue_field_values;
|
|
330
|
+
for (const value of values) {
|
|
331
|
+
if (value.field_id === 101) state.points = value.value;
|
|
332
|
+
if (value.field_id === 102) state.priority = value.value;
|
|
333
|
+
}
|
|
334
|
+
return { data: fields() };
|
|
335
|
+
}
|
|
336
|
+
if (route === "GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values") return { data: fields() };
|
|
337
|
+
if (route.includes("rules")) return { data: [] };
|
|
338
|
+
throw new Error(`Unexpected synthetic REST route: ${route}`);
|
|
339
|
+
},
|
|
340
|
+
repos: {
|
|
341
|
+
compareCommitsWithBasehead: async (input) => {
|
|
342
|
+
record("repos.compareCommitsWithBasehead", input);
|
|
343
|
+
assert.deepEqual(input, {
|
|
344
|
+
owner: "example",
|
|
345
|
+
repo: "widget",
|
|
346
|
+
basehead: `${head}...${head}`,
|
|
347
|
+
per_page: 1
|
|
348
|
+
});
|
|
349
|
+
return { data: { merge_base_commit: { sha: head } } };
|
|
350
|
+
},
|
|
351
|
+
getCombinedStatusForRef: async (input) => {
|
|
352
|
+
record("repos.getCombinedStatusForRef", input);
|
|
353
|
+
return { data: { state: "success", total_count: 0, statuses: [] } };
|
|
354
|
+
},
|
|
355
|
+
get: async (input) => {
|
|
356
|
+
record("repos.get", input);
|
|
357
|
+
return {
|
|
358
|
+
data: { node_id: "REPO", full_name: "example/widget", default_branch: "main", permissions: { push: true } }
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
git: {
|
|
363
|
+
getRef: async (input) => {
|
|
364
|
+
record("git.getRef", input);
|
|
365
|
+
return { data: { ref: `refs/${input.ref}`, object: { type: "commit", sha: head } } };
|
|
366
|
+
},
|
|
367
|
+
getCommit: async (input) => {
|
|
368
|
+
record("git.getCommit", input);
|
|
369
|
+
return { data: { sha: head, tree: { sha: tree } } };
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
issues: {
|
|
373
|
+
get: async (input) => {
|
|
374
|
+
record("issues.get", input);
|
|
375
|
+
return { data: issue() };
|
|
376
|
+
},
|
|
377
|
+
create: async (input) => {
|
|
378
|
+
record("issues.create", input);
|
|
379
|
+
state.title = input.title;
|
|
380
|
+
state.body = input.body;
|
|
381
|
+
return { data: issue() };
|
|
382
|
+
},
|
|
383
|
+
update: async (input) => {
|
|
384
|
+
record("issues.update", input);
|
|
385
|
+
if (input.title !== void 0) state.title = input.title;
|
|
386
|
+
if (input.body !== void 0) state.body = input.body;
|
|
387
|
+
if (input.state !== void 0) {
|
|
388
|
+
state.issueState = input.state;
|
|
389
|
+
if (input.state === "closed") state.closedCount++;
|
|
390
|
+
}
|
|
391
|
+
return { data: issue() };
|
|
392
|
+
},
|
|
393
|
+
listForRepo: async (input) => {
|
|
394
|
+
record("issues.listForRepo", input);
|
|
395
|
+
return { data: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()] };
|
|
396
|
+
},
|
|
397
|
+
listLabelsForRepo: async () => ({ data: [] }),
|
|
398
|
+
listSubIssues: async (input) => {
|
|
399
|
+
record("issues.listSubIssues", input);
|
|
400
|
+
return { data: [] };
|
|
401
|
+
},
|
|
402
|
+
listComments: async (input) => {
|
|
403
|
+
record("issues.listComments", input);
|
|
404
|
+
const size = input.per_page ?? 100, start = ((input.page ?? 1) - 1) * size;
|
|
405
|
+
return {
|
|
406
|
+
data: comments.filter((c) => c.issue_url.endsWith(`/issues/${input.issue_number}`)).slice(start, start + size)
|
|
407
|
+
};
|
|
408
|
+
},
|
|
409
|
+
createComment: async (input) => {
|
|
410
|
+
record("issues.createComment", input);
|
|
411
|
+
let id = Math.max(nextCommentId, 101 + comments.length);
|
|
412
|
+
while (comments.some((c) => c.id === id)) id++;
|
|
413
|
+
nextCommentId = id + 1;
|
|
414
|
+
return { data: addComment(id, input.body, false, input.issue_number) };
|
|
415
|
+
},
|
|
416
|
+
getComment: async (input) => {
|
|
417
|
+
record("issues.getComment", input);
|
|
418
|
+
return { data: comments.find((comment) => comment.id === input.comment_id) };
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
search: {
|
|
422
|
+
issuesAndPullRequests: async (input) => {
|
|
423
|
+
record("search.issuesAndPullRequests", input);
|
|
424
|
+
return {
|
|
425
|
+
data: {
|
|
426
|
+
total_count: 2,
|
|
427
|
+
incomplete_results: false,
|
|
428
|
+
items: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()]
|
|
77
429
|
}
|
|
430
|
+
};
|
|
78
431
|
}
|
|
79
|
-
|
|
80
|
-
|
|
432
|
+
},
|
|
433
|
+
pulls: {
|
|
434
|
+
get: async (input) => {
|
|
435
|
+
record("pulls.get", input);
|
|
436
|
+
return { data: pr() };
|
|
437
|
+
},
|
|
438
|
+
list: async (input) => {
|
|
439
|
+
record("pulls.list", input);
|
|
440
|
+
return { data: state.published ? [pr()] : [] };
|
|
441
|
+
},
|
|
442
|
+
listFiles: async (input) => {
|
|
443
|
+
record("pulls.listFiles", input);
|
|
444
|
+
return { data: [{ filename: "change.ts" }] };
|
|
445
|
+
},
|
|
446
|
+
create: async (input) => {
|
|
447
|
+
record("pulls.create", input);
|
|
448
|
+
state.published = true;
|
|
449
|
+
state.draft = input.draft;
|
|
450
|
+
state.prTitle = input.title;
|
|
451
|
+
state.prBody = input.body;
|
|
452
|
+
return { data: pr() };
|
|
453
|
+
},
|
|
454
|
+
update: async (input) => {
|
|
455
|
+
record("pulls.update", input);
|
|
456
|
+
if (input.draft !== void 0) state.draft = input.draft;
|
|
457
|
+
return { data: pr() };
|
|
458
|
+
},
|
|
459
|
+
createReview: async (input) => {
|
|
460
|
+
record("pulls.createReview", input);
|
|
461
|
+
assert.equal(input.commit_id, head);
|
|
462
|
+
review.body = input.body;
|
|
463
|
+
reviews.push(review);
|
|
464
|
+
return { data: review };
|
|
465
|
+
},
|
|
466
|
+
listReviews: async (input) => {
|
|
467
|
+
record("pulls.listReviews", input);
|
|
468
|
+
return { data: reviews };
|
|
469
|
+
},
|
|
470
|
+
getReview: async (input) => {
|
|
471
|
+
record("pulls.getReview", input);
|
|
472
|
+
return { data: review };
|
|
473
|
+
},
|
|
474
|
+
merge: async (input) => {
|
|
475
|
+
record("pulls.merge", input);
|
|
476
|
+
assert.equal(input.sha, head);
|
|
477
|
+
state.merged = true;
|
|
478
|
+
if (state.mergeAckLost) {
|
|
479
|
+
state.mergeAckLost = false;
|
|
480
|
+
throw new Error("Synthetic lost merge acknowledgement");
|
|
481
|
+
}
|
|
482
|
+
return { data: { merged: true, sha: "c".repeat(40) } };
|
|
81
483
|
}
|
|
484
|
+
}
|
|
82
485
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
checkoutRoots: [base],
|
|
114
|
-
project: 1,
|
|
115
|
-
pointsField: 'Estimate',
|
|
116
|
-
priorityField: 'Urgency',
|
|
117
|
-
statusField: 'Flow',
|
|
118
|
-
statuses: { blocked: 'Waiting', done: 'Shipped', inProgress: 'Active', todo: 'Queued' },
|
|
119
|
-
issueTypes: ['Task'],
|
|
120
|
-
}), { mode: 0o600 });
|
|
121
|
-
process.env.AI_DELIVERY_CONFIG = userPath;
|
|
122
|
-
configInstalled = true;
|
|
123
|
-
const calls = [];
|
|
124
|
-
const record = (name, input = null) => {
|
|
125
|
-
calls.push({ name, input });
|
|
126
|
-
};
|
|
127
|
-
const state = {
|
|
128
|
-
title: fixtureFields.title,
|
|
129
|
-
body: renderIssueBody(fixtureFields),
|
|
130
|
-
issueState: 'open',
|
|
131
|
-
points: '2',
|
|
132
|
-
priority: 'High',
|
|
133
|
-
projectOption: 'STATUS-0',
|
|
134
|
-
linked: true,
|
|
135
|
-
published: true,
|
|
136
|
-
draft: false,
|
|
137
|
-
prTitle: 'Reject invalid widget identifiers',
|
|
138
|
-
prBody: 'Closes #17',
|
|
139
|
-
merged: false,
|
|
140
|
-
closedCount: 0,
|
|
141
|
-
reviewDecision: 'APPROVED',
|
|
142
|
-
mergeAckLost: false,
|
|
143
|
-
};
|
|
144
|
-
const artifactContent = {
|
|
145
|
-
authorIdentity: 'author',
|
|
146
|
-
reviewerIdentity: 'reviewer',
|
|
147
|
-
checks: ['Synthetic focused regression'],
|
|
148
|
-
diffScopeHash: digestValue(['change.ts']),
|
|
149
|
-
elapsedMs: 1,
|
|
150
|
-
findings: [],
|
|
151
|
-
head: { sha: head, tree },
|
|
152
|
-
issueNumber: 17,
|
|
153
|
-
prNumber: 23,
|
|
154
|
-
readOnly: true,
|
|
155
|
-
requestedEffort: 'xhigh',
|
|
156
|
-
requestedModel: 'gpt-6-astra',
|
|
157
|
-
effectiveEffort: 'unknown',
|
|
158
|
-
effectiveModel: 'unknown',
|
|
159
|
-
schemaVersion: 'ai-delivery.review-artifact@1',
|
|
160
|
-
summary: 'Fictional independent review.',
|
|
161
|
-
verdict: 'approve',
|
|
162
|
-
};
|
|
163
|
-
const artifact = { ...artifactContent, artifactId: digestValue(artifactContent) };
|
|
164
|
-
const artifactPath = join(base, 'review.json');
|
|
165
|
-
writeFileSync(artifactPath, JSON.stringify(artifact), { mode: 0o600 });
|
|
166
|
-
const reviewBody = `${artifact.summary}\n\n<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->\n<!-- ai-delivery-review-artifact-data: ${Buffer.from(JSON.stringify(artifact)).toString('base64url')} -->`;
|
|
167
|
-
const review = {
|
|
168
|
-
id: 99,
|
|
169
|
-
user: { login: 'reviewer[bot]', id: 99, type: 'Bot' },
|
|
170
|
-
state: 'APPROVED',
|
|
171
|
-
commit_id: head,
|
|
172
|
-
body: reviewBody,
|
|
173
|
-
html_url: 'https://github.com/example/widget/pull/23#pullrequestreview-99',
|
|
174
|
-
};
|
|
175
|
-
const reviews = [review];
|
|
176
|
-
const comments = [];
|
|
177
|
-
const addComment = (id, body, app = false) => {
|
|
178
|
-
const comment = {
|
|
179
|
-
id,
|
|
180
|
-
body,
|
|
181
|
-
html_url: `https://github.com/example/widget/issues/17#issuecomment-${id}`,
|
|
182
|
-
issue_url: 'https://api.github.com/repos/example/widget/issues/17',
|
|
183
|
-
created_at: new Date(Date.now() + 1000).toISOString(),
|
|
184
|
-
user: app ? { id: 99, login: 'reviewer[bot]', type: 'Bot' } : { id: 42, login: 'operator', type: 'User' },
|
|
185
|
-
};
|
|
186
|
-
comments.push(comment);
|
|
187
|
-
return comment;
|
|
188
|
-
};
|
|
189
|
-
const issue = (number = 17) => ({
|
|
190
|
-
number,
|
|
191
|
-
id: 100 + number,
|
|
192
|
-
node_id: `ISSUE${number}`,
|
|
193
|
-
title: state.title,
|
|
194
|
-
body: state.body,
|
|
195
|
-
state: state.issueState,
|
|
196
|
-
state_reason: state.issueState === 'closed' ? 'completed' : null,
|
|
197
|
-
html_url: `https://github.com/example/widget/issues/${number}`,
|
|
198
|
-
created_at: '2026-01-01T00:00:00Z',
|
|
199
|
-
updated_at: '2026-01-02T00:00:00Z',
|
|
200
|
-
labels: [],
|
|
201
|
-
type: { name: 'Task' },
|
|
202
|
-
});
|
|
203
|
-
const pr = () => ({
|
|
204
|
-
number: 23,
|
|
205
|
-
node_id: 'PR23',
|
|
206
|
-
changed_files: 1,
|
|
207
|
-
title: state.prTitle,
|
|
208
|
-
body: state.prBody,
|
|
209
|
-
html_url: 'https://github.com/example/widget/pull/23',
|
|
210
|
-
state: state.merged ? 'closed' : 'open',
|
|
211
|
-
draft: state.draft,
|
|
212
|
-
merged: state.merged,
|
|
213
|
-
merge_commit_sha: state.merged ? 'c'.repeat(40) : null,
|
|
214
|
-
mergeable: true,
|
|
215
|
-
mergeable_state: 'clean',
|
|
216
|
-
head: { sha: head, ref: 'issue/17', repo: { full_name: 'example/widget' } },
|
|
217
|
-
base: { sha: head, ref: 'main', repo: { full_name: 'example/widget' } },
|
|
218
|
-
user: { login: 'operator' },
|
|
219
|
-
});
|
|
220
|
-
const fields = () => [
|
|
221
|
-
{
|
|
222
|
-
issue_field_id: 101,
|
|
223
|
-
issue_field_name: 'Estimate',
|
|
224
|
-
data_type: 'single_select',
|
|
225
|
-
value: state.points,
|
|
226
|
-
single_select_option: { name: state.points },
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
issue_field_id: 102,
|
|
230
|
-
issue_field_name: 'Urgency',
|
|
231
|
-
data_type: 'single_select',
|
|
232
|
-
value: state.priority,
|
|
233
|
-
single_select_option: { name: state.priority },
|
|
234
|
-
},
|
|
235
|
-
];
|
|
236
|
-
const item = () => ({
|
|
237
|
-
id: 'ITEM17',
|
|
238
|
-
isArchived: false,
|
|
239
|
-
project: { id: 'PROJECT-1', number: 1 },
|
|
240
|
-
content: { __typename: 'Issue', id: 'ISSUE17' },
|
|
241
|
-
fieldValueByName: {
|
|
242
|
-
__typename: 'ProjectV2ItemFieldSingleSelectValue',
|
|
243
|
-
optionId: state.projectOption,
|
|
244
|
-
name: ['Queued', 'Active', 'Waiting', 'Shipped'][Number(state.projectOption.slice(-1))],
|
|
245
|
-
field: { id: 'STATUS-FIELD', name: 'Flow' },
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
const rest = {
|
|
249
|
-
request: async (route, input = {}) => {
|
|
250
|
-
record(route, input);
|
|
251
|
-
if (route === 'GET /orgs/{org}/issue-fields')
|
|
252
|
-
return {
|
|
253
|
-
data: [
|
|
254
|
-
{
|
|
255
|
-
id: 101,
|
|
256
|
-
name: 'Estimate',
|
|
257
|
-
data_type: 'single_select',
|
|
258
|
-
options: ['1', '2', '4'].map((name) => ({ name })),
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: 102,
|
|
262
|
-
name: 'Urgency',
|
|
263
|
-
data_type: 'single_select',
|
|
264
|
-
options: ['High', 'Low'].map((name) => ({ name })),
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
};
|
|
268
|
-
if (route === 'POST /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values') {
|
|
269
|
-
const values = input.issue_field_values;
|
|
270
|
-
for (const value of values) {
|
|
271
|
-
if (value.field_id === 101)
|
|
272
|
-
state.points = value.value;
|
|
273
|
-
if (value.field_id === 102)
|
|
274
|
-
state.priority = value.value;
|
|
275
|
-
}
|
|
276
|
-
return { data: fields() };
|
|
277
|
-
}
|
|
278
|
-
if (route === 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values')
|
|
279
|
-
return { data: fields() };
|
|
280
|
-
if (route.includes('rules'))
|
|
281
|
-
return { data: [] };
|
|
282
|
-
throw new Error(`Unexpected synthetic REST route: ${route}`);
|
|
283
|
-
},
|
|
284
|
-
repos: {
|
|
285
|
-
get: async (input) => {
|
|
286
|
-
record('repos.get', input);
|
|
287
|
-
return {
|
|
288
|
-
data: { node_id: 'REPO', full_name: 'example/widget', default_branch: 'main', permissions: { push: true } },
|
|
289
|
-
};
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
git: {
|
|
293
|
-
getRef: async (input) => {
|
|
294
|
-
record('git.getRef', input);
|
|
295
|
-
return { data: { ref: `refs/${input.ref}`, object: { type: 'commit', sha: head } } };
|
|
296
|
-
},
|
|
297
|
-
getCommit: async (input) => {
|
|
298
|
-
record('git.getCommit', input);
|
|
299
|
-
return { data: { sha: head, tree: { sha: tree } } };
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
issues: {
|
|
303
|
-
get: async (input) => {
|
|
304
|
-
record('issues.get', input);
|
|
305
|
-
return { data: issue() };
|
|
306
|
-
},
|
|
307
|
-
create: async (input) => {
|
|
308
|
-
record('issues.create', input);
|
|
309
|
-
state.title = input.title;
|
|
310
|
-
state.body = input.body;
|
|
311
|
-
return { data: issue() };
|
|
312
|
-
},
|
|
313
|
-
update: async (input) => {
|
|
314
|
-
record('issues.update', input);
|
|
315
|
-
if (input.title !== undefined)
|
|
316
|
-
state.title = input.title;
|
|
317
|
-
if (input.body !== undefined)
|
|
318
|
-
state.body = input.body;
|
|
319
|
-
if (input.state !== undefined) {
|
|
320
|
-
state.issueState = input.state;
|
|
321
|
-
if (input.state === 'closed')
|
|
322
|
-
state.closedCount++;
|
|
323
|
-
}
|
|
324
|
-
return { data: issue() };
|
|
325
|
-
},
|
|
326
|
-
listForRepo: async (input) => {
|
|
327
|
-
record('issues.listForRepo', input);
|
|
328
|
-
return { data: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()] };
|
|
329
|
-
},
|
|
330
|
-
listLabelsForRepo: async () => ({ data: [] }),
|
|
331
|
-
listSubIssues: async () => ({ data: [] }),
|
|
332
|
-
listComments: async (input) => {
|
|
333
|
-
record('issues.listComments', input);
|
|
334
|
-
return { data: comments };
|
|
335
|
-
},
|
|
336
|
-
createComment: async (input) => {
|
|
337
|
-
record('issues.createComment', input);
|
|
338
|
-
return { data: addComment(101 + comments.length, input.body) };
|
|
339
|
-
},
|
|
340
|
-
getComment: async (input) => {
|
|
341
|
-
record('issues.getComment', input);
|
|
342
|
-
return { data: comments.find((comment) => comment.id === input.comment_id) };
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
search: {
|
|
346
|
-
issuesAndPullRequests: async (input) => {
|
|
347
|
-
record('search.issuesAndPullRequests', input);
|
|
348
|
-
return {
|
|
349
|
-
data: {
|
|
350
|
-
total_count: 2,
|
|
351
|
-
incomplete_results: false,
|
|
352
|
-
items: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()],
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
pulls: {
|
|
358
|
-
get: async (input) => {
|
|
359
|
-
record('pulls.get', input);
|
|
360
|
-
return { data: pr() };
|
|
361
|
-
},
|
|
362
|
-
list: async (input) => {
|
|
363
|
-
record('pulls.list', input);
|
|
364
|
-
return { data: state.published ? [pr()] : [] };
|
|
365
|
-
},
|
|
366
|
-
listFiles: async (input) => {
|
|
367
|
-
record('pulls.listFiles', input);
|
|
368
|
-
return { data: [{ filename: 'change.ts' }] };
|
|
369
|
-
},
|
|
370
|
-
create: async (input) => {
|
|
371
|
-
record('pulls.create', input);
|
|
372
|
-
state.published = true;
|
|
373
|
-
state.draft = input.draft;
|
|
374
|
-
state.prTitle = input.title;
|
|
375
|
-
state.prBody = input.body;
|
|
376
|
-
return { data: pr() };
|
|
377
|
-
},
|
|
378
|
-
update: async (input) => {
|
|
379
|
-
record('pulls.update', input);
|
|
380
|
-
if (input.draft !== undefined)
|
|
381
|
-
state.draft = input.draft;
|
|
382
|
-
return { data: pr() };
|
|
383
|
-
},
|
|
384
|
-
createReview: async (input) => {
|
|
385
|
-
record('pulls.createReview', input);
|
|
386
|
-
assert.equal(input.commit_id, head);
|
|
387
|
-
review.body = input.body;
|
|
388
|
-
reviews.push(review);
|
|
389
|
-
return { data: review };
|
|
390
|
-
},
|
|
391
|
-
listReviews: async (input) => {
|
|
392
|
-
record('pulls.listReviews', input);
|
|
393
|
-
return { data: reviews };
|
|
394
|
-
},
|
|
395
|
-
getReview: async (input) => {
|
|
396
|
-
record('pulls.getReview', input);
|
|
397
|
-
return { data: review };
|
|
398
|
-
},
|
|
399
|
-
merge: async (input) => {
|
|
400
|
-
record('pulls.merge', input);
|
|
401
|
-
assert.equal(input.sha, head);
|
|
402
|
-
state.merged = true;
|
|
403
|
-
if (state.mergeAckLost) {
|
|
404
|
-
state.mergeAckLost = false;
|
|
405
|
-
throw new Error('Synthetic lost merge acknowledgement');
|
|
486
|
+
const graphql = async (query, variables = {}) => {
|
|
487
|
+
record(query.match(/(?:query|mutation)\s+(\w+)/u)?.[1] ?? "relationships", variables);
|
|
488
|
+
if (query.includes("ProjectDeliveryIssueItems"))
|
|
489
|
+
return issueProjectItemsResponse(
|
|
490
|
+
variables,
|
|
491
|
+
[item()].filter((row) => row.content.id === variables.issueNodeId),
|
|
492
|
+
{ id: "PROJECT-1", number: 1 }
|
|
493
|
+
);
|
|
494
|
+
if (query.includes("UpdateProjectDeliveryStatus")) {
|
|
495
|
+
state.projectOption = String(variables.optionId);
|
|
496
|
+
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: "ITEM17" } } };
|
|
497
|
+
}
|
|
498
|
+
if (query.includes("ProjectDeliveryItemReadback")) return { node: item() };
|
|
499
|
+
if (query.includes("DeliveryStartBranch")) {
|
|
500
|
+
state.linked = true;
|
|
501
|
+
return { createLinkedBranch: { linkedBranch: { ref: { name: "issue/17", target: { oid: head } } } } };
|
|
502
|
+
}
|
|
503
|
+
if (query.includes("DeliveryIssueBranches"))
|
|
504
|
+
return {
|
|
505
|
+
repository: {
|
|
506
|
+
issue: {
|
|
507
|
+
linkedBranches: {
|
|
508
|
+
nodes: state.linked ? [
|
|
509
|
+
{
|
|
510
|
+
ref: {
|
|
511
|
+
name: "issue/17",
|
|
512
|
+
target: { oid: head },
|
|
513
|
+
repository: { nameWithOwner: "example/widget" }
|
|
406
514
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const graphql = async (query, variables = {}) => {
|
|
412
|
-
record(query.match(/(?:query|mutation)\s+(\w+)/u)?.[1] ?? 'relationships', variables);
|
|
413
|
-
if (query.includes('ProjectDeliveryItems'))
|
|
414
|
-
return {
|
|
415
|
-
organization: {
|
|
416
|
-
projectV2: {
|
|
417
|
-
id: 'PROJECT-1',
|
|
418
|
-
items: { nodes: [item()], pageInfo: { hasNextPage: false, endCursor: null } },
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
};
|
|
422
|
-
if (query.includes('UpdateProjectDeliveryStatus')) {
|
|
423
|
-
state.projectOption = String(variables.optionId);
|
|
424
|
-
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'ITEM17' } } };
|
|
425
|
-
}
|
|
426
|
-
if (query.includes('ProjectDeliveryItemReadback'))
|
|
427
|
-
return { node: item() };
|
|
428
|
-
if (query.includes('DeliveryStartBranch')) {
|
|
429
|
-
state.linked = true;
|
|
430
|
-
return { createLinkedBranch: { linkedBranch: { ref: { name: 'issue/17', target: { oid: head } } } } };
|
|
515
|
+
}
|
|
516
|
+
] : [],
|
|
517
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
518
|
+
}
|
|
431
519
|
}
|
|
432
|
-
|
|
433
|
-
return {
|
|
434
|
-
repository: {
|
|
435
|
-
issue: {
|
|
436
|
-
linkedBranches: {
|
|
437
|
-
nodes: state.linked
|
|
438
|
-
? [
|
|
439
|
-
{
|
|
440
|
-
ref: {
|
|
441
|
-
name: 'issue/17',
|
|
442
|
-
target: { oid: head },
|
|
443
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
]
|
|
447
|
-
: [],
|
|
448
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
449
|
-
},
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
};
|
|
453
|
-
if (query.includes('DeliveryClosingIssues'))
|
|
454
|
-
return {
|
|
455
|
-
repository: {
|
|
456
|
-
nameWithOwner: 'example/widget',
|
|
457
|
-
pullRequest: {
|
|
458
|
-
id: 'PR23',
|
|
459
|
-
number: 23,
|
|
460
|
-
closingIssuesReferences: {
|
|
461
|
-
nodes: [{ number: 17, repository: { nameWithOwner: 'example/widget' } }],
|
|
462
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
463
|
-
},
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
};
|
|
467
|
-
if (query.includes('DeliveryReviewAccess'))
|
|
468
|
-
return {
|
|
469
|
-
repository: {
|
|
470
|
-
pullRequest: {
|
|
471
|
-
headRefOid: head,
|
|
472
|
-
reviews: {
|
|
473
|
-
nodes: reviews.map((value) => ({
|
|
474
|
-
id: String(value.id),
|
|
475
|
-
fullDatabaseId: value.id,
|
|
476
|
-
author: value.user,
|
|
477
|
-
authorCanPushToRepository: true,
|
|
478
|
-
commit: { oid: head },
|
|
479
|
-
state: value.state,
|
|
480
|
-
})),
|
|
481
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
482
|
-
},
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
};
|
|
486
|
-
if (query.includes('DeliveryReviewDecision'))
|
|
487
|
-
return { repository: { pullRequest: { headRefOid: head, reviewDecision: state.reviewDecision } } };
|
|
488
|
-
if (query.includes('IssueClosureReadback'))
|
|
489
|
-
return {
|
|
490
|
-
repository: {
|
|
491
|
-
issue: {
|
|
492
|
-
number: 17,
|
|
493
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
494
|
-
state: state.issueState.toUpperCase(),
|
|
495
|
-
stateReason: state.issueState === 'closed' ? 'COMPLETED' : null,
|
|
496
|
-
duplicateOf: null,
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
};
|
|
500
|
-
if (query.includes('blockedBy(first:'))
|
|
501
|
-
return {
|
|
502
|
-
repository: {
|
|
503
|
-
issue: { parent: null, blockedBy: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } } },
|
|
504
|
-
},
|
|
505
|
-
};
|
|
506
|
-
return syntheticDiscoveryClients().graphql(query, variables);
|
|
507
|
-
};
|
|
508
|
-
const clientsSpy = vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockImplementation(async (input) => ({
|
|
509
|
-
role: input.role,
|
|
510
|
-
authSource: input.role === 'author' ? 'personal' : 'app',
|
|
511
|
-
authenticatedAuthor: async () => {
|
|
512
|
-
record('authenticatedAuthor');
|
|
513
|
-
return { actorLogin: 'operator', credentialIdentity: 'user:42' };
|
|
514
|
-
},
|
|
515
|
-
appActorLogin: async () => {
|
|
516
|
-
record('appActorLogin');
|
|
517
|
-
return 'reviewer[bot]';
|
|
518
|
-
},
|
|
519
|
-
rest,
|
|
520
|
-
graphql,
|
|
521
|
-
}));
|
|
522
|
-
restoreClients = () => clientsSpy.mockRestore();
|
|
523
|
-
const target = join(root, '.worktrees', 'issue-17');
|
|
524
|
-
const worktree = () => {
|
|
525
|
-
fixtureSignal.throwIfAborted();
|
|
526
|
-
fixtureGit(root, 'worktree', 'add', '-b', 'issue/17', target, head);
|
|
527
|
-
mkdirSync(join(root, '.issue-cli'), { recursive: true });
|
|
528
|
-
writeFileSync(join(root, '.issue-cli', 'worktrees.json'), JSON.stringify({ worktrees: [] }));
|
|
529
|
-
state.published = false;
|
|
530
|
-
return target;
|
|
520
|
+
}
|
|
531
521
|
};
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
: [
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
control: name,
|
|
551
|
-
module: control,
|
|
552
|
-
payloadDigest: digestBytes(Buffer.from(bytes)),
|
|
553
|
-
passed: true,
|
|
554
|
-
});
|
|
555
|
-
unlinkSync(sentinel);
|
|
522
|
+
if (query.includes("DeliveryClosingIssues"))
|
|
523
|
+
return {
|
|
524
|
+
repository: {
|
|
525
|
+
nameWithOwner: "example/widget",
|
|
526
|
+
pullRequest: {
|
|
527
|
+
id: "PR23",
|
|
528
|
+
number: 23,
|
|
529
|
+
closingIssuesReferences: {
|
|
530
|
+
nodes: [
|
|
531
|
+
{
|
|
532
|
+
__typename: "Issue",
|
|
533
|
+
id: "ISSUE17",
|
|
534
|
+
number: 17,
|
|
535
|
+
repository: { id: "REPO", nameWithOwner: "example/widget" }
|
|
536
|
+
}
|
|
537
|
+
],
|
|
538
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
539
|
+
}
|
|
556
540
|
}
|
|
557
|
-
|
|
558
|
-
writeFileSync(join(selected, 'ai-delivery.policy.mjs'), edited);
|
|
559
|
-
assert.equal(fixtureGit(selected, 'status', '--porcelain'), kind === 'edited' ? 'M ai-delivery.policy.mjs' : '');
|
|
560
|
-
observations.push({
|
|
561
|
-
policyState: kind,
|
|
562
|
-
selected,
|
|
563
|
-
indexedDigest: digestBytes(Buffer.from(tracked)),
|
|
564
|
-
headDigest: digestBytes(Buffer.from(tracked)),
|
|
565
|
-
worktreeDigest: digestBytes(Buffer.from(kind === 'edited' ? edited : tracked)),
|
|
566
|
-
});
|
|
541
|
+
}
|
|
567
542
|
};
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
});
|
|
585
|
-
connectionSignal.throwIfAborted();
|
|
586
|
-
const text = response.content[0]?.text ?? '';
|
|
587
|
-
observations.push({ publicTool: name, arguments: args, isError: response.isError === true, text });
|
|
588
|
-
assertInert();
|
|
589
|
-
return { response, text, value: response.isError ? undefined : JSON.parse(text) };
|
|
590
|
-
};
|
|
591
|
-
let closed;
|
|
592
|
-
const connection = {
|
|
593
|
-
call,
|
|
594
|
-
close: () => {
|
|
595
|
-
closed ??= (async () => {
|
|
596
|
-
closing.abort();
|
|
597
|
-
await Promise.allSettled(activeCalls);
|
|
598
|
-
try {
|
|
599
|
-
await client.close();
|
|
600
|
-
}
|
|
601
|
-
finally {
|
|
602
|
-
await server.close();
|
|
603
|
-
}
|
|
604
|
-
})();
|
|
605
|
-
return closed;
|
|
606
|
-
},
|
|
607
|
-
};
|
|
608
|
-
connections.add(connection);
|
|
609
|
-
try {
|
|
610
|
-
await server.connect(st);
|
|
611
|
-
await client.connect(ct);
|
|
612
|
-
connectionSignal.throwIfAborted();
|
|
613
|
-
return connection;
|
|
614
|
-
}
|
|
615
|
-
catch (error) {
|
|
616
|
-
await connection.close();
|
|
617
|
-
throw error;
|
|
543
|
+
if (query.includes("DeliveryReviewAccess"))
|
|
544
|
+
return {
|
|
545
|
+
repository: {
|
|
546
|
+
pullRequest: {
|
|
547
|
+
headRefOid: head,
|
|
548
|
+
reviews: {
|
|
549
|
+
nodes: reviews.map((value) => ({
|
|
550
|
+
id: String(value.id),
|
|
551
|
+
fullDatabaseId: value.id,
|
|
552
|
+
author: value.user,
|
|
553
|
+
authorCanPushToRepository: true,
|
|
554
|
+
commit: { oid: head },
|
|
555
|
+
state: value.state
|
|
556
|
+
})),
|
|
557
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
558
|
+
}
|
|
618
559
|
}
|
|
560
|
+
}
|
|
619
561
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
assert.equal(current.dev, owned.dev);
|
|
632
|
-
assert.equal(current.ino, owned.ino);
|
|
633
|
-
assert.equal(fixtureGit(root, 'rev-parse', '--git-common-dir'), '.git');
|
|
634
|
-
const worktrees = fixtureGit(root, 'worktree', 'list', '--porcelain')
|
|
635
|
-
.split('\n')
|
|
636
|
-
.filter((line) => line.startsWith('worktree '));
|
|
637
|
-
assert.ok(worktrees.every((line) => line.slice(9).startsWith(`${base}/`)), 'Cleanup requires owned worktrees');
|
|
638
|
-
rmSync(base, { recursive: true });
|
|
639
|
-
assert.equal(existsSync(base), false);
|
|
640
|
-
const evidence = process.env.AI_DELIVERY_INERT_EVIDENCE_DIR;
|
|
641
|
-
if (evidence)
|
|
642
|
-
writeFileSync(join(evidence, `${basename(base)}.json`), JSON.stringify({
|
|
643
|
-
head,
|
|
644
|
-
tree,
|
|
645
|
-
observations,
|
|
646
|
-
externalPortCalls: calls,
|
|
647
|
-
policyInert: inert,
|
|
648
|
-
ownedCleanup: true,
|
|
649
|
-
}) + '\n', { flag: 'wx', mode: 0o600 });
|
|
650
|
-
assert.equal(inert, true, 'A public route imported consumer policy');
|
|
651
|
-
}
|
|
652
|
-
finally {
|
|
653
|
-
restoreGlobals();
|
|
562
|
+
if (query.includes("DeliveryReviewDecision"))
|
|
563
|
+
return { repository: { pullRequest: { headRefOid: head, reviewDecision: state.reviewDecision } } };
|
|
564
|
+
if (query.includes("IssueClosureReadback"))
|
|
565
|
+
return {
|
|
566
|
+
repository: {
|
|
567
|
+
issue: {
|
|
568
|
+
number: 17,
|
|
569
|
+
repository: { nameWithOwner: "example/widget" },
|
|
570
|
+
state: state.issueState.toUpperCase(),
|
|
571
|
+
stateReason: state.issueState === "closed" ? "COMPLETED" : null,
|
|
572
|
+
duplicateOf: null
|
|
654
573
|
}
|
|
574
|
+
}
|
|
655
575
|
};
|
|
656
|
-
|
|
657
|
-
const dispose = (connection) => {
|
|
658
|
-
if (connection !== undefined)
|
|
659
|
-
connections.add(connection);
|
|
660
|
-
disposal ??= (async () => {
|
|
661
|
-
shutdown.abort();
|
|
662
|
-
await Promise.allSettled(activeCalls);
|
|
663
|
-
try {
|
|
664
|
-
const closures = await Promise.allSettled([...connections].map((ownedConnection) => ownedConnection.close()));
|
|
665
|
-
const failed = closures.find((result) => result.status === 'rejected');
|
|
666
|
-
if (failed?.status === 'rejected')
|
|
667
|
-
throw failed.reason;
|
|
668
|
-
}
|
|
669
|
-
finally {
|
|
670
|
-
cleanup();
|
|
671
|
-
}
|
|
672
|
-
})();
|
|
673
|
-
return disposal;
|
|
674
|
-
};
|
|
675
|
-
registerDisposal(() => dispose(undefined));
|
|
576
|
+
if (query.includes("blockedBy(first:"))
|
|
676
577
|
return {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
head,
|
|
681
|
-
tree,
|
|
682
|
-
target,
|
|
683
|
-
sentinel,
|
|
684
|
-
artifact,
|
|
685
|
-
artifactPath,
|
|
686
|
-
state,
|
|
687
|
-
calls,
|
|
688
|
-
comments,
|
|
689
|
-
reviews,
|
|
690
|
-
rest,
|
|
691
|
-
graphql,
|
|
692
|
-
addComment,
|
|
693
|
-
policy,
|
|
694
|
-
worktree,
|
|
695
|
-
connect,
|
|
696
|
-
assertInert,
|
|
697
|
-
dispose,
|
|
578
|
+
repository: {
|
|
579
|
+
issue: { parent: null, blockedBy: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } } }
|
|
580
|
+
}
|
|
698
581
|
};
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
582
|
+
return syntheticDiscoveryClients().graphql(query, variables);
|
|
583
|
+
};
|
|
584
|
+
const clientsSpy = vi.spyOn(githubClients, "createDeliveryGitHubClients").mockImplementation(
|
|
585
|
+
async (input) => ({
|
|
586
|
+
role: input.role,
|
|
587
|
+
authSource: input.role === "author" ? "personal" : "app",
|
|
588
|
+
authenticatedAuthor: async () => {
|
|
589
|
+
record("authenticatedAuthor");
|
|
590
|
+
return { actorLogin: "operator", credentialIdentity: "user:42" };
|
|
591
|
+
},
|
|
592
|
+
appActorLogin: async () => {
|
|
593
|
+
record("appActorLogin");
|
|
594
|
+
return "reviewer[bot]";
|
|
595
|
+
},
|
|
596
|
+
rest,
|
|
597
|
+
graphql
|
|
598
|
+
})
|
|
599
|
+
);
|
|
600
|
+
restoreClients = () => clientsSpy.mockRestore();
|
|
601
|
+
const target = join(root, ".worktrees", "issue-17");
|
|
602
|
+
const worktree = () => {
|
|
603
|
+
fixtureSignal.throwIfAborted();
|
|
604
|
+
fixtureGit(root, "worktree", "add", "-b", "issue/17", target, head);
|
|
605
|
+
mkdirSync(join(root, ".issue-cli"), { recursive: true });
|
|
606
|
+
writeFileSync(join(root, ".issue-cli", "worktrees.json"), JSON.stringify({ worktrees: [] }));
|
|
607
|
+
state.published = false;
|
|
608
|
+
return target;
|
|
609
|
+
};
|
|
610
|
+
const policy = (kind, selected = root) => {
|
|
611
|
+
fixtureSignal.throwIfAborted();
|
|
612
|
+
assert.equal(readFileSync(join(selected, "ai-delivery.policy.mjs"), "utf8"), tracked);
|
|
613
|
+
assert.equal(fixtureGit(selected, "show", "HEAD:ai-delivery.policy.mjs"), tracked.trim());
|
|
614
|
+
assert.equal(fixtureGit(selected, "show", ":ai-delivery.policy.mjs"), tracked.trim());
|
|
615
|
+
for (const [name, bytes] of kind === "tracked" ? [["tracked", tracked]] : [
|
|
616
|
+
["tracked", tracked],
|
|
617
|
+
["edited", edited]
|
|
618
|
+
]) {
|
|
619
|
+
const control = join(base, `control-${name}.mjs`);
|
|
620
|
+
writeFileSync(control, bytes);
|
|
621
|
+
execFileSync(process.execPath, [control], { env: process.env, timeout: 5e3, maxBuffer: 64 * 1024 });
|
|
622
|
+
const readback = JSON.parse(readFileSync(sentinel, "utf8"));
|
|
623
|
+
assert.deepEqual(readback, { marker: name, module: pathToFileURL(control).href });
|
|
624
|
+
observations.push({
|
|
625
|
+
control: name,
|
|
626
|
+
module: control,
|
|
627
|
+
payloadDigest: digestBytes(Buffer.from(bytes)),
|
|
628
|
+
passed: true
|
|
629
|
+
});
|
|
630
|
+
unlinkSync(sentinel);
|
|
631
|
+
}
|
|
632
|
+
if (kind === "edited") writeFileSync(join(selected, "ai-delivery.policy.mjs"), edited);
|
|
633
|
+
assert.equal(fixtureGit(selected, "status", "--porcelain"), kind === "edited" ? "M ai-delivery.policy.mjs" : "");
|
|
634
|
+
observations.push({
|
|
635
|
+
policyState: kind,
|
|
636
|
+
selected,
|
|
637
|
+
indexedDigest: digestBytes(Buffer.from(tracked)),
|
|
638
|
+
headDigest: digestBytes(Buffer.from(tracked)),
|
|
639
|
+
worktreeDigest: digestBytes(Buffer.from(kind === "edited" ? edited : tracked))
|
|
640
|
+
});
|
|
641
|
+
};
|
|
642
|
+
const assertInert = () => assert.equal(existsSync(sentinel), false, "A public route imported consumer policy");
|
|
643
|
+
const connect = async (extra = {}) => {
|
|
644
|
+
fixtureSignal.throwIfAborted();
|
|
645
|
+
const closing = new AbortController();
|
|
646
|
+
const connectionSignal = AbortSignal.any([
|
|
647
|
+
fixtureSignal,
|
|
648
|
+
closing.signal,
|
|
649
|
+
...extra.signal === void 0 ? [] : [extra.signal]
|
|
650
|
+
]);
|
|
651
|
+
const server = createAiDeliveryMcpServer({ repoRoot: root, ...extra, signal: connectionSignal }, activeCalls);
|
|
652
|
+
const client = new Client({ name: "inert-target-fixture", version: "1" });
|
|
653
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
654
|
+
const call = async (name, args) => {
|
|
655
|
+
connectionSignal.throwIfAborted();
|
|
656
|
+
const response = await client.callTool(
|
|
657
|
+
{ name, arguments: name === "delivery_board" ? args : { repo: "example/widget", ...args } },
|
|
658
|
+
void 0,
|
|
659
|
+
{ signal: connectionSignal }
|
|
660
|
+
);
|
|
661
|
+
connectionSignal.throwIfAborted();
|
|
662
|
+
const text = response.content[0]?.text ?? "";
|
|
663
|
+
observations.push({ publicTool: name, arguments: args, isError: response.isError === true, text });
|
|
664
|
+
assertInert();
|
|
665
|
+
return { response, text, value: response.isError ? void 0 : JSON.parse(text) };
|
|
666
|
+
};
|
|
667
|
+
let closed;
|
|
668
|
+
const connection = {
|
|
669
|
+
call,
|
|
670
|
+
close: () => {
|
|
671
|
+
closed ??= (async () => {
|
|
672
|
+
closing.abort();
|
|
673
|
+
await Promise.allSettled(activeCalls);
|
|
674
|
+
try {
|
|
675
|
+
await client.close();
|
|
676
|
+
} finally {
|
|
677
|
+
await server.close();
|
|
678
|
+
}
|
|
679
|
+
})();
|
|
680
|
+
return closed;
|
|
709
681
|
}
|
|
682
|
+
};
|
|
683
|
+
connections.add(connection);
|
|
684
|
+
try {
|
|
685
|
+
await server.connect(st);
|
|
686
|
+
await client.connect(ct);
|
|
687
|
+
connectionSignal.throwIfAborted();
|
|
688
|
+
return connection;
|
|
689
|
+
} catch (error) {
|
|
690
|
+
await connection.close();
|
|
710
691
|
throw error;
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
let cleaned = false;
|
|
695
|
+
const cleanup = () => {
|
|
696
|
+
if (cleaned) return;
|
|
697
|
+
assert.equal(activeCalls.size, 0, "Owned tool handlers must settle before fixture removal");
|
|
698
|
+
cleaned = true;
|
|
699
|
+
const inert = !existsSync(sentinel);
|
|
700
|
+
try {
|
|
701
|
+
const current = lstatSync(base);
|
|
702
|
+
assert.equal(current.isSymbolicLink(), false);
|
|
703
|
+
assert.equal(realpathSync(base), base);
|
|
704
|
+
assert.equal(current.dev, owned.dev);
|
|
705
|
+
assert.equal(current.ino, owned.ino);
|
|
706
|
+
assert.equal(fixtureGit(root, "rev-parse", "--git-common-dir"), ".git");
|
|
707
|
+
const worktrees = fixtureGit(root, "worktree", "list", "--porcelain").split("\n").filter((line) => line.startsWith("worktree "));
|
|
708
|
+
assert.ok(
|
|
709
|
+
worktrees.every((line) => line.slice(9).startsWith(`${base}/`)),
|
|
710
|
+
"Cleanup requires owned worktrees"
|
|
711
|
+
);
|
|
712
|
+
rmSync(base, { recursive: true });
|
|
713
|
+
assert.equal(existsSync(base), false);
|
|
714
|
+
const evidence = process.env.AI_DELIVERY_INERT_EVIDENCE_DIR;
|
|
715
|
+
if (evidence)
|
|
716
|
+
writeFileSync(
|
|
717
|
+
join(evidence, `${basename(base)}.json`),
|
|
718
|
+
JSON.stringify({
|
|
719
|
+
head,
|
|
720
|
+
tree,
|
|
721
|
+
observations,
|
|
722
|
+
externalPortCalls: calls,
|
|
723
|
+
policyInert: inert,
|
|
724
|
+
ownedCleanup: true
|
|
725
|
+
}) + "\n",
|
|
726
|
+
{ flag: "wx", mode: 384 }
|
|
727
|
+
);
|
|
728
|
+
assert.equal(inert, true, "A public route imported consumer policy");
|
|
729
|
+
} finally {
|
|
730
|
+
restoreGlobals();
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
let disposal;
|
|
734
|
+
const dispose = (connection) => {
|
|
735
|
+
if (connection !== void 0) connections.add(connection);
|
|
736
|
+
disposal ??= (async () => {
|
|
737
|
+
shutdown.abort();
|
|
738
|
+
await Promise.allSettled(activeCalls);
|
|
739
|
+
try {
|
|
740
|
+
const closures = await Promise.allSettled([...connections].map((ownedConnection) => ownedConnection.close()));
|
|
741
|
+
const failed = closures.find((result) => result.status === "rejected");
|
|
742
|
+
if (failed?.status === "rejected") throw failed.reason;
|
|
743
|
+
} finally {
|
|
744
|
+
cleanup();
|
|
745
|
+
}
|
|
746
|
+
})();
|
|
747
|
+
return disposal;
|
|
748
|
+
};
|
|
749
|
+
registerDisposal(() => dispose(void 0));
|
|
750
|
+
return {
|
|
751
|
+
signal: fixtureSignal,
|
|
752
|
+
base,
|
|
753
|
+
root,
|
|
754
|
+
head,
|
|
755
|
+
tree,
|
|
756
|
+
target,
|
|
757
|
+
sentinel,
|
|
758
|
+
artifact,
|
|
759
|
+
artifactPath,
|
|
760
|
+
state,
|
|
761
|
+
calls,
|
|
762
|
+
comments,
|
|
763
|
+
reviews,
|
|
764
|
+
observations,
|
|
765
|
+
rest,
|
|
766
|
+
graphql,
|
|
767
|
+
addComment,
|
|
768
|
+
policy,
|
|
769
|
+
worktree,
|
|
770
|
+
connect,
|
|
771
|
+
assertInert,
|
|
772
|
+
dispose
|
|
773
|
+
};
|
|
774
|
+
} catch (error) {
|
|
775
|
+
try {
|
|
776
|
+
const current = lstatSync(base);
|
|
777
|
+
assert.equal(current.dev, owned.dev);
|
|
778
|
+
assert.equal(current.ino, owned.ino);
|
|
779
|
+
rmSync(base, { recursive: true });
|
|
780
|
+
} finally {
|
|
781
|
+
restoreGlobals();
|
|
711
782
|
}
|
|
783
|
+
throw error;
|
|
784
|
+
}
|
|
712
785
|
}
|
|
713
|
-
|
|
786
|
+
export {
|
|
787
|
+
fixtureFields,
|
|
788
|
+
fixtureGit,
|
|
789
|
+
inertTarget
|
|
790
|
+
};
|
|
791
|
+
//# sourceMappingURL=inertTarget.js.map
|