@aviaratech/ai-delivery 0.3.35 → 0.3.37
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 +56 -554
- package/dist/agent.d.ts +1 -3
- package/dist/agent.js +74 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +91 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +389 -517
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +316 -354
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +63 -23
- 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.d.ts +0 -3
- package/dist/git.js +59 -76
- 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 +42 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1938 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +252 -310
- package/dist/mcp/tools.js +235 -342
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +417 -413
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +114 -131
- package/dist/pr.js +1314 -1327
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +967 -653
- 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 +123 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +184 -0
- package/dist/readView.js +218 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +146 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/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/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 +321 -358
- 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 +274 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +451 -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.d.ts +0 -2
- package/dist/utils/atomicJson.js +81 -77
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.d.ts +0 -8
- package/dist/utils/filesystem.js +5 -19
- 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 -54
- package/dist/verification.js +976 -1941
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +45 -24
- package/dist/version.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/services/deliveryAdmission.d.ts +0 -49
- package/dist/services/deliveryAdmission.js +0 -165
- package/dist/services/deliveryAdmission.js.map +0 -1
- package/dist/services/worktreeRegistry.d.ts +0 -434
- package/dist/services/worktreeRegistry.js +0 -1248
- package/dist/services/worktreeRegistry.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktree.d.ts +0 -28
- package/dist/worktree.js +0 -188
- package/dist/worktree.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
|
@@ -1,301 +1,347 @@
|
|
|
1
|
-
import assert from
|
|
2
|
-
import { execFileSync, spawn, spawnSync } from
|
|
3
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from
|
|
4
|
-
import { tmpdir } from
|
|
5
|
-
import { join } from
|
|
6
|
-
import { test } from
|
|
7
|
-
import {
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { test } from "vitest";
|
|
7
|
+
import {
|
|
8
|
+
classifyRepositoryExactRange,
|
|
9
|
+
createRepositoryDeliveryEvidence,
|
|
10
|
+
createRepositoryStageAggregate,
|
|
11
|
+
createRepositoryStageInput,
|
|
12
|
+
createRepositoryStageReceipt,
|
|
13
|
+
digestBytes,
|
|
14
|
+
digestValue,
|
|
15
|
+
loadRepositoryStageCheckpoint,
|
|
16
|
+
loadSelectedRepositoryPolicy,
|
|
17
|
+
loadValidRepositoryDeliveryEvidence,
|
|
18
|
+
writeRepositoryCommandOutput,
|
|
19
|
+
writeRepositoryDeliveryEvidence,
|
|
20
|
+
writeRepositoryStageCheckpoint
|
|
21
|
+
} from "./legacy.js";
|
|
8
22
|
function git(root, ...args) {
|
|
9
|
-
|
|
23
|
+
return execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
|
|
10
24
|
}
|
|
11
25
|
function setup() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const root = mkdtempSync(join(tmpdir(), "ai-delivery-test-"));
|
|
27
|
+
git(root, "init", "-q");
|
|
28
|
+
git(root, "config", "user.email", "delivery@example.test");
|
|
29
|
+
git(root, "config", "user.name", "Delivery Test");
|
|
30
|
+
writeFileSync(
|
|
31
|
+
join(root, "policy.mjs"),
|
|
32
|
+
`export default { schemaVersion: 'RepositoryDeliveryPolicy@1', classifyExactRange() {}, validateBoundary() {} };
|
|
33
|
+
`
|
|
34
|
+
);
|
|
35
|
+
writeFileSync(join(root, "artifact.txt"), "proof");
|
|
36
|
+
writeFileSync(join(root, "output.txt"), "stage artifact");
|
|
37
|
+
git(root, "add", ".");
|
|
38
|
+
git(root, "commit", "-qm", "base");
|
|
39
|
+
const base = { sha: git(root, "rev-parse", "HEAD"), tree: git(root, "rev-parse", "HEAD^{tree}") };
|
|
40
|
+
writeFileSync(join(root, "change.txt"), "changed");
|
|
41
|
+
git(root, "add", ".");
|
|
42
|
+
git(root, "commit", "-qm", "head");
|
|
43
|
+
const head = { sha: git(root, "rev-parse", "HEAD"), tree: git(root, "rev-parse", "HEAD^{tree}") };
|
|
44
|
+
const policyDigest = digestBytes(readFileSync(join(root, "policy.mjs")));
|
|
45
|
+
const configDigest = digestValue({ repository: "example/delivery", policy: "policy.mjs" });
|
|
46
|
+
const gitCommonDir = join(root, ".git");
|
|
47
|
+
const cleanup = () => rmSync(root, { recursive: true, force: true });
|
|
48
|
+
return { root, base, head, policyDigest, configDigest, gitCommonDir, cleanup };
|
|
31
49
|
}
|
|
32
|
-
function makePolicy(state, risk =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
function makePolicy(state, risk = "standard") {
|
|
51
|
+
const hash = digestValue;
|
|
52
|
+
const definition = {
|
|
53
|
+
commands: [{ argv: ["node", "--version"], label: "check" }],
|
|
54
|
+
dependsOn: [],
|
|
55
|
+
id: "check",
|
|
56
|
+
resourceClass: "source_only",
|
|
57
|
+
semanticInputKeys: ["source"]
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
schemaVersion: "RepositoryDeliveryPolicy@1",
|
|
61
|
+
classifyExactRange(input) {
|
|
62
|
+
const content = {
|
|
63
|
+
artifacts: [
|
|
64
|
+
{
|
|
65
|
+
digest: digestBytes(readFileSync(join(state.root, "artifact.txt"))),
|
|
66
|
+
path: "artifact.txt",
|
|
67
|
+
producer: "synthetic"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
base: { sha: input.baseSha, tree: input.baseTree },
|
|
71
|
+
configDigest: input.configDigest,
|
|
72
|
+
head: { sha: input.headSha, tree: input.headTree },
|
|
73
|
+
opaquePayload: "synthetic proof",
|
|
74
|
+
policyDigest: state.policyDigest,
|
|
75
|
+
producer: "synthetic",
|
|
76
|
+
repository: input.repository,
|
|
77
|
+
schemaVersion: "ai-delivery.policy-evidence@1"
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
policyDigest: state.policyDigest,
|
|
81
|
+
policyEvidence: { ...content, evidenceId: hash(content) },
|
|
82
|
+
requiredStages: [definition],
|
|
83
|
+
risk
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
validateBoundary(input) {
|
|
87
|
+
const content = {
|
|
88
|
+
additionalConstraints: { exactBaseHeadLease: true, requiredAttestationIds: [] },
|
|
89
|
+
classificationReceiptId: input.classificationReceiptId,
|
|
90
|
+
configDigest: input.configDigest,
|
|
91
|
+
currentBase: input.currentBase,
|
|
92
|
+
currentHead: input.currentHead,
|
|
93
|
+
phase: input.phase,
|
|
94
|
+
policyEvidenceId: input.policyEvidence.evidenceId,
|
|
95
|
+
schemaVersion: "ai-delivery.policy-boundary@1",
|
|
96
|
+
stageReceiptSetHash: hash(input.stageReceiptIds)
|
|
97
|
+
};
|
|
98
|
+
return { ...content, boundaryId: hash(content) };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
83
101
|
}
|
|
84
102
|
function proof(state, policy = makePolicy(state)) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
103
|
+
const classification = classifyRepositoryExactRange({
|
|
104
|
+
repoRoot: state.root,
|
|
105
|
+
repository: "example/delivery",
|
|
106
|
+
base: state.base,
|
|
107
|
+
head: state.head,
|
|
108
|
+
changedPaths: ["change.txt"],
|
|
109
|
+
configDigest: state.configDigest,
|
|
110
|
+
policySourcePath: "./policy.mjs",
|
|
111
|
+
policy
|
|
112
|
+
});
|
|
113
|
+
const stageInput = createRepositoryStageInput({
|
|
114
|
+
classification,
|
|
115
|
+
environmentDigest: digestValue("environment"),
|
|
116
|
+
semanticInputs: [{ digest: digestValue(state.head.tree), key: "source" }],
|
|
117
|
+
stageId: "check",
|
|
118
|
+
upstream: []
|
|
119
|
+
});
|
|
120
|
+
const outputDigest = writeRepositoryCommandOutput({
|
|
121
|
+
bytes: Buffer.from("node 22"),
|
|
122
|
+
gitCommonDir: state.gitCommonDir
|
|
123
|
+
});
|
|
124
|
+
const receipt = createRepositoryStageReceipt({
|
|
125
|
+
classification,
|
|
126
|
+
stageInput,
|
|
127
|
+
artifacts: [{ digest: digestBytes(readFileSync(join(state.root, "output.txt"))), path: "output.txt" }],
|
|
128
|
+
commands: [{ exitCode: 0, label: "check", outputDigest }],
|
|
129
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
130
|
+
completedAt: "2026-01-01T00:00:01.000Z"
|
|
131
|
+
});
|
|
132
|
+
const aggregate = createRepositoryStageAggregate({ classification, receipts: [receipt] });
|
|
133
|
+
const input = {
|
|
134
|
+
aggregate,
|
|
135
|
+
classification,
|
|
136
|
+
approvalRoles: { authorIdentity: "author", reviewerIdentity: "reviewer" },
|
|
137
|
+
configDigest: state.configDigest,
|
|
138
|
+
currentBase: state.base,
|
|
139
|
+
currentHead: state.head,
|
|
140
|
+
gitCommonDir: state.gitCommonDir,
|
|
141
|
+
phase: "verify",
|
|
142
|
+
policy,
|
|
143
|
+
policySourcePath: "./policy.mjs",
|
|
144
|
+
repoRoot: state.root,
|
|
145
|
+
stageReceipts: [receipt]
|
|
146
|
+
};
|
|
147
|
+
return { classification, stageInput, receipt, aggregate, input };
|
|
130
148
|
}
|
|
131
|
-
test(
|
|
149
|
+
test(
|
|
150
|
+
"explicit component policy reuses compatible stages across heads and invalidates dependencies",
|
|
151
|
+
{ tags: ["release"] },
|
|
152
|
+
() => {
|
|
132
153
|
const state = setup();
|
|
133
154
|
try {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
const classify = () => classifyRepositoryExactRange({
|
|
165
|
-
repoRoot: state.root,
|
|
166
|
-
repository: 'example/delivery',
|
|
167
|
-
base: state.base,
|
|
168
|
-
head: { sha: git(state.root, 'rev-parse', 'HEAD'), tree: git(state.root, 'rev-parse', 'HEAD^{tree}') },
|
|
169
|
-
changedPaths: git(state.root, 'diff', '--name-only', state.base.sha, 'HEAD').split('\n'),
|
|
170
|
-
configDigest: state.configDigest,
|
|
171
|
-
policySourcePath: './policy.mjs',
|
|
172
|
-
policy,
|
|
173
|
-
});
|
|
174
|
-
const inputs = (classification, receipts = []) => classification.requiredStages.map((stage) => createRepositoryStageInput({
|
|
175
|
-
classification,
|
|
176
|
-
environmentDigest: digestValue('producer/worktree/environment'),
|
|
177
|
-
stageId: stage.id,
|
|
178
|
-
semanticInputs: stage.semanticInputs,
|
|
179
|
-
upstream: stage.dependsOn.map((stageId) => ({
|
|
180
|
-
stageId,
|
|
181
|
-
receiptId: receipts.find((r) => r.input.stageId === stageId).receiptId,
|
|
182
|
-
})),
|
|
183
|
-
}));
|
|
184
|
-
const first = classify();
|
|
185
|
-
const outputDigest = writeRepositoryCommandOutput({
|
|
186
|
-
bytes: Buffer.from('passed'),
|
|
187
|
-
gitCommonDir: state.gitCommonDir,
|
|
188
|
-
});
|
|
189
|
-
const receipts = [];
|
|
190
|
-
for (const stage of first.requiredStages) {
|
|
191
|
-
const stageInput = createRepositoryStageInput({
|
|
192
|
-
classification: first,
|
|
193
|
-
stageId: stage.id,
|
|
194
|
-
environmentDigest: digestValue('producer/worktree/environment'),
|
|
195
|
-
semanticInputs: stage.semanticInputs,
|
|
196
|
-
upstream: stage.dependsOn.map((stageId) => ({
|
|
197
|
-
stageId,
|
|
198
|
-
receiptId: receipts.find((r) => r.input.stageId === stageId).receiptId,
|
|
199
|
-
})),
|
|
200
|
-
});
|
|
201
|
-
const receipt = createRepositoryStageReceipt({
|
|
202
|
-
classification: first,
|
|
203
|
-
stageInput,
|
|
204
|
-
artifacts: [],
|
|
205
|
-
commands: [{ exitCode: 0, label: 'check', outputDigest }],
|
|
206
|
-
startedAt: '2026-01-01T00:00:00.000Z',
|
|
207
|
-
completedAt: '2026-01-01T00:00:01.000Z',
|
|
208
|
-
});
|
|
209
|
-
receipts.push(receipt);
|
|
210
|
-
writeRepositoryStageCheckpoint({ gitCommonDir: state.gitCommonDir, receipt, repoRoot: state.root });
|
|
211
|
-
}
|
|
212
|
-
writeFileSync(join(state.root, 'unrelated.txt'), 'documentation');
|
|
213
|
-
git(state.root, 'add', '.');
|
|
214
|
-
git(state.root, 'commit', '-qm', 'unrelated');
|
|
215
|
-
const current = classify();
|
|
216
|
-
assert.notEqual(current.receiptId, first.receiptId);
|
|
217
|
-
const currentInputs = inputs(current, receipts);
|
|
218
|
-
for (const [index, stageInput] of currentInputs.entries()) {
|
|
219
|
-
assert.equal(stageInput.inputId, receipts[index].input.inputId);
|
|
220
|
-
assert.equal(loadRepositoryStageCheckpoint({
|
|
221
|
-
gitCommonDir: state.gitCommonDir,
|
|
222
|
-
stageInput,
|
|
223
|
-
classification: current,
|
|
224
|
-
repoRoot: state.root,
|
|
225
|
-
configDigest: state.configDigest,
|
|
226
|
-
policySourcePath: './policy.mjs',
|
|
227
|
-
})?.receiptId, receipts[index].receiptId);
|
|
155
|
+
const legacy = makePolicy(state);
|
|
156
|
+
let component = digestValue("component a");
|
|
157
|
+
const policy = {
|
|
158
|
+
...legacy,
|
|
159
|
+
schemaVersion: "RepositoryDeliveryPolicy@2",
|
|
160
|
+
classifyExactRange(input) {
|
|
161
|
+
const selected = legacy.classifyExactRange(input);
|
|
162
|
+
const definition = selected.requiredStages[0];
|
|
163
|
+
return {
|
|
164
|
+
...selected,
|
|
165
|
+
requiredStages: [
|
|
166
|
+
{
|
|
167
|
+
...definition,
|
|
168
|
+
semanticInputKeys: ["B", "a"],
|
|
169
|
+
semanticInputs: [
|
|
170
|
+
{ key: "B", digest: component },
|
|
171
|
+
{ key: "a", digest: digestValue("mixed-case component") }
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
{ ...definition, id: "independent", semanticInputs: [{ key: "source", digest: digestValue("b") }] },
|
|
175
|
+
{
|
|
176
|
+
...definition,
|
|
177
|
+
id: "downstream",
|
|
178
|
+
dependsOn: ["check"],
|
|
179
|
+
semanticInputs: [{ key: "source", digest: digestValue("c") }]
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
};
|
|
228
183
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
184
|
+
};
|
|
185
|
+
const classify = () => classifyRepositoryExactRange({
|
|
186
|
+
repoRoot: state.root,
|
|
187
|
+
repository: "example/delivery",
|
|
188
|
+
base: state.base,
|
|
189
|
+
head: { sha: git(state.root, "rev-parse", "HEAD"), tree: git(state.root, "rev-parse", "HEAD^{tree}") },
|
|
190
|
+
changedPaths: git(state.root, "diff", "--name-only", state.base.sha, "HEAD").split("\n"),
|
|
191
|
+
configDigest: state.configDigest,
|
|
192
|
+
policySourcePath: "./policy.mjs",
|
|
193
|
+
policy
|
|
194
|
+
});
|
|
195
|
+
const inputs = (classification, receipts2 = []) => classification.requiredStages.map(
|
|
196
|
+
(stage) => createRepositoryStageInput({
|
|
197
|
+
classification,
|
|
198
|
+
environmentDigest: digestValue("producer/worktree/environment"),
|
|
199
|
+
stageId: stage.id,
|
|
200
|
+
semanticInputs: stage.semanticInputs,
|
|
201
|
+
upstream: stage.dependsOn.map((stageId) => ({
|
|
202
|
+
stageId,
|
|
203
|
+
receiptId: receipts2.find((r) => r.input.stageId === stageId).receiptId
|
|
204
|
+
}))
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
const first = classify();
|
|
208
|
+
const outputDigest = writeRepositoryCommandOutput({
|
|
209
|
+
bytes: Buffer.from("passed"),
|
|
210
|
+
gitCommonDir: state.gitCommonDir
|
|
211
|
+
});
|
|
212
|
+
const receipts = [];
|
|
213
|
+
for (const stage of first.requiredStages) {
|
|
214
|
+
const stageInput = createRepositoryStageInput({
|
|
215
|
+
classification: first,
|
|
216
|
+
stageId: stage.id,
|
|
217
|
+
environmentDigest: digestValue("producer/worktree/environment"),
|
|
218
|
+
semanticInputs: stage.semanticInputs,
|
|
219
|
+
upstream: stage.dependsOn.map((stageId) => ({
|
|
220
|
+
stageId,
|
|
221
|
+
receiptId: receipts.find((r) => r.input.stageId === stageId).receiptId
|
|
222
|
+
}))
|
|
250
223
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
writeRepositoryStageCheckpoint({ gitCommonDir: state.gitCommonDir, receipt: p.receipt, repoRoot: state.root });
|
|
273
|
-
assert.equal(loadRepositoryStageCheckpoint({
|
|
224
|
+
const receipt = createRepositoryStageReceipt({
|
|
225
|
+
classification: first,
|
|
226
|
+
stageInput,
|
|
227
|
+
artifacts: [],
|
|
228
|
+
commands: [{ exitCode: 0, label: "check", outputDigest }],
|
|
229
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
230
|
+
completedAt: "2026-01-01T00:00:01.000Z"
|
|
231
|
+
});
|
|
232
|
+
receipts.push(receipt);
|
|
233
|
+
writeRepositoryStageCheckpoint({ gitCommonDir: state.gitCommonDir, receipt, repoRoot: state.root });
|
|
234
|
+
}
|
|
235
|
+
writeFileSync(join(state.root, "unrelated.txt"), "documentation");
|
|
236
|
+
git(state.root, "add", ".");
|
|
237
|
+
git(state.root, "commit", "-qm", "unrelated");
|
|
238
|
+
const current = classify();
|
|
239
|
+
assert.notEqual(current.receiptId, first.receiptId);
|
|
240
|
+
const currentInputs = inputs(current, receipts);
|
|
241
|
+
for (const [index, stageInput] of currentInputs.entries()) {
|
|
242
|
+
assert.equal(stageInput.inputId, receipts[index].input.inputId);
|
|
243
|
+
assert.equal(
|
|
244
|
+
loadRepositoryStageCheckpoint({
|
|
274
245
|
gitCommonDir: state.gitCommonDir,
|
|
275
|
-
stageInput
|
|
276
|
-
classification:
|
|
246
|
+
stageInput,
|
|
247
|
+
classification: current,
|
|
277
248
|
repoRoot: state.root,
|
|
278
249
|
configDigest: state.configDigest,
|
|
279
|
-
policySourcePath:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
250
|
+
policySourcePath: "./policy.mjs"
|
|
251
|
+
})?.receiptId,
|
|
252
|
+
receipts[index].receiptId
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
assert.equal(
|
|
256
|
+
createRepositoryStageAggregate({ classification: current, receipts }).classificationReceiptId,
|
|
257
|
+
current.receiptId
|
|
258
|
+
);
|
|
259
|
+
component = digestValue("changed component a");
|
|
260
|
+
const changed = classify();
|
|
261
|
+
const changedInputs = inputs(changed, receipts);
|
|
262
|
+
assert.notEqual(changedInputs[0].inputId, currentInputs[0].inputId);
|
|
263
|
+
assert.equal(changedInputs[1].inputId, currentInputs[1].inputId);
|
|
264
|
+
assert.throws(() => createRepositoryStageAggregate({ classification: changed, receipts }));
|
|
265
|
+
assert.throws(
|
|
266
|
+
() => createRepositoryStageInput({
|
|
267
|
+
classification: changed,
|
|
268
|
+
stageId: "check",
|
|
269
|
+
environmentDigest: digestValue("producer/worktree/environment"),
|
|
270
|
+
upstream: [],
|
|
271
|
+
semanticInputs: [{ key: "source", digest: digestValue("inferred value") }]
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
const replacement = createRepositoryStageReceipt({
|
|
275
|
+
classification: changed,
|
|
276
|
+
stageInput: changedInputs[0],
|
|
277
|
+
artifacts: [],
|
|
278
|
+
commands: [{ exitCode: 0, label: "check", outputDigest }],
|
|
279
|
+
startedAt: "2026-01-02T00:00:00.000Z",
|
|
280
|
+
completedAt: "2026-01-02T00:00:01.000Z"
|
|
281
|
+
});
|
|
282
|
+
assert.notEqual(inputs(changed, [replacement])[2].inputId, currentInputs[2].inputId);
|
|
283
|
+
assert.throws(
|
|
284
|
+
() => classifyRepositoryExactRange({
|
|
285
|
+
repoRoot: state.root,
|
|
286
|
+
repository: current.repository,
|
|
287
|
+
base: current.base,
|
|
288
|
+
head: current.head,
|
|
289
|
+
changedPaths: current.changedPaths,
|
|
290
|
+
configDigest: state.configDigest,
|
|
291
|
+
policySourcePath: "./policy.mjs",
|
|
292
|
+
policy: { ...policy, schemaVersion: "RepositoryDeliveryPolicy@1" }
|
|
293
|
+
})
|
|
294
|
+
);
|
|
295
|
+
} finally {
|
|
296
|
+
state.cleanup();
|
|
287
297
|
}
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
test("synthetic exact delivery, private checkpoint resume and phase evidence", { tags: ["release"] }, async () => {
|
|
301
|
+
const state = setup();
|
|
302
|
+
try {
|
|
303
|
+
await assert.rejects(
|
|
304
|
+
loadSelectedRepositoryPolicy({ repoRoot: state.root, policySourcePath: "./policy.mjs" }),
|
|
305
|
+
/policy execution was removed/u
|
|
306
|
+
);
|
|
307
|
+
const p = proof(state);
|
|
308
|
+
writeRepositoryStageCheckpoint({ gitCommonDir: state.gitCommonDir, receipt: p.receipt, repoRoot: state.root });
|
|
309
|
+
assert.equal(
|
|
310
|
+
loadRepositoryStageCheckpoint({
|
|
311
|
+
gitCommonDir: state.gitCommonDir,
|
|
312
|
+
stageInput: p.stageInput,
|
|
313
|
+
classification: p.classification,
|
|
314
|
+
repoRoot: state.root,
|
|
315
|
+
configDigest: state.configDigest,
|
|
316
|
+
policySourcePath: "./policy.mjs"
|
|
317
|
+
})?.receiptId,
|
|
318
|
+
p.receipt.receiptId
|
|
319
|
+
);
|
|
320
|
+
const evidence = createRepositoryDeliveryEvidence(p.input);
|
|
321
|
+
writeRepositoryDeliveryEvidence({ evidence, gitCommonDir: state.gitCommonDir });
|
|
322
|
+
assert.equal(
|
|
323
|
+
loadValidRepositoryDeliveryEvidence({ createInput: p.input, evidenceId: evidence.evidenceId }).evidenceId,
|
|
324
|
+
evidence.evidenceId
|
|
325
|
+
);
|
|
326
|
+
} finally {
|
|
327
|
+
state.cleanup();
|
|
328
|
+
}
|
|
288
329
|
});
|
|
289
|
-
test(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
330
|
+
test(
|
|
331
|
+
"separate processes can read and reuse shared output during publication and after publisher interruption",
|
|
332
|
+
{ tags: ["release"] },
|
|
333
|
+
async () => {
|
|
334
|
+
const directory = mkdtempSync(join(tmpdir(), "ai-delivery-publication-"));
|
|
335
|
+
const ready = join(directory, "ready");
|
|
336
|
+
const release = join(directory, "release");
|
|
337
|
+
const moduleUrl = new URL("./stage.js", import.meta.url).href;
|
|
294
338
|
const input = { gitCommonDir: directory };
|
|
295
339
|
const publish = `const {writeRepositoryCommandOutput}=await import(${JSON.stringify(moduleUrl)});writeRepositoryCommandOutput({ ...${JSON.stringify(input)}, bytes: Buffer.from('shared immutable output') });`;
|
|
296
|
-
const worker = spawn(
|
|
297
|
-
|
|
298
|
-
|
|
340
|
+
const worker = spawn(
|
|
341
|
+
process.execPath,
|
|
342
|
+
[
|
|
343
|
+
"--input-type=module",
|
|
344
|
+
"-e",
|
|
299
345
|
`
|
|
300
346
|
import fs from 'node:fs'; import {syncBuiltinESMExports} from 'node:module';
|
|
301
347
|
for (const key of ['linkSync','renameSync']) { const original=fs[key]; fs[key]=(...args)=>{
|
|
@@ -304,45 +350,54 @@ test('separate processes can read and reuse shared output during publication and
|
|
|
304
350
|
while(!fs.existsSync(${JSON.stringify(release)})) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,20);
|
|
305
351
|
} return result;
|
|
306
352
|
}; } syncBuiltinESMExports(); ${publish}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
353
|
+
`
|
|
354
|
+
],
|
|
355
|
+
{ stdio: "ignore" }
|
|
356
|
+
);
|
|
357
|
+
const closed = new Promise((resolve) => worker.once("close", resolve));
|
|
310
358
|
try {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
359
|
+
for (let attempt = 0; attempt < 100 && !existsSync(ready); attempt++)
|
|
360
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
361
|
+
assert.ok(existsSync(ready));
|
|
362
|
+
const peer = spawnSync(process.execPath, ["--input-type=module", "-e", publish], {
|
|
363
|
+
encoding: "utf8",
|
|
364
|
+
timeout: 2e3,
|
|
365
|
+
maxBuffer: 32768
|
|
366
|
+
});
|
|
367
|
+
assert.equal(peer.status, 0, peer.stderr);
|
|
368
|
+
worker.kill("SIGKILL");
|
|
369
|
+
await closed;
|
|
370
|
+
const output = writeRepositoryCommandOutput({ ...input, bytes: Buffer.from("shared immutable output") });
|
|
371
|
+
assert.match(output, /^sha256:/u);
|
|
372
|
+
console.log(
|
|
373
|
+
"SHARED_OUTPUT_PUBLICATION_RECEIPT",
|
|
374
|
+
JSON.stringify({ peerSucceeded: true, interruptedPublisherOutputReused: true, digest: output })
|
|
375
|
+
);
|
|
376
|
+
} finally {
|
|
377
|
+
writeFileSync(release, "ready");
|
|
378
|
+
if (worker.exitCode === null && worker.signalCode === null) worker.kill("SIGKILL");
|
|
379
|
+
await closed;
|
|
380
|
+
rmSync(directory, { recursive: true, force: true });
|
|
332
381
|
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
test(
|
|
385
|
+
"separate processes durably create shared writer directories and reject a raced non-directory",
|
|
386
|
+
{ tags: ["release"] },
|
|
387
|
+
async () => {
|
|
388
|
+
const directory = mkdtempSync(join(tmpdir(), "ai-delivery-directory-"));
|
|
389
|
+
const shared = join(directory, "shared");
|
|
390
|
+
const target = join(shared, "writers@1");
|
|
391
|
+
const release = join(directory, "release");
|
|
392
|
+
const moduleUrl = new URL("../utils/atomicJson.js", import.meta.url).href;
|
|
340
393
|
const workers = [0, 1].map((index) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
394
|
+
const ready = join(directory, `ready-${String(index)}`);
|
|
395
|
+
const child = spawn(
|
|
396
|
+
process.execPath,
|
|
397
|
+
[
|
|
398
|
+
"--input-type=module",
|
|
399
|
+
"-e",
|
|
400
|
+
`
|
|
346
401
|
import fs from 'node:fs'; import {syncBuiltinESMExports} from 'node:module';
|
|
347
402
|
const original=fs.mkdirSync; fs.mkdirSync=(path, options)=>{
|
|
348
403
|
if(path===${JSON.stringify(shared)}) {
|
|
@@ -352,131 +407,154 @@ test('separate processes durably create shared writer directories and reject a r
|
|
|
352
407
|
}; syncBuiltinESMExports();
|
|
353
408
|
const {writePrivateJsonFileAtomically}=await import(${JSON.stringify(moduleUrl)});
|
|
354
409
|
writePrivateJsonFileAtomically(${JSON.stringify(join(target, `${String(index)}.json`))},{peer:${String(index)}});
|
|
355
|
-
|
|
356
|
-
],
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
410
|
+
`
|
|
411
|
+
],
|
|
412
|
+
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
413
|
+
);
|
|
414
|
+
let stderr = "";
|
|
415
|
+
child.stderr.on("data", (chunk) => {
|
|
416
|
+
stderr += chunk.toString();
|
|
417
|
+
});
|
|
418
|
+
const closed = new Promise((resolve) => child.once("close", resolve));
|
|
419
|
+
return { child, ready, closed, stderr: () => stderr };
|
|
363
420
|
});
|
|
364
421
|
try {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
422
|
+
for (let attempt = 0; attempt < 100 && !workers.every((worker) => existsSync(worker.ready)); attempt++)
|
|
423
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
424
|
+
assert.ok(workers.every((worker) => existsSync(worker.ready)));
|
|
425
|
+
writeFileSync(release, "ready");
|
|
426
|
+
const statuses = await Promise.all(workers.map((worker) => worker.closed));
|
|
427
|
+
workers.forEach((worker, index) => assert.equal(statuses[index], 0, worker.stderr()));
|
|
428
|
+
for (const index of [0, 1])
|
|
429
|
+
assert.deepEqual(JSON.parse(readFileSync(join(target, `${String(index)}.json`), "utf8")), { peer: index });
|
|
430
|
+
const racedFile = spawnSync(
|
|
431
|
+
process.execPath,
|
|
432
|
+
[
|
|
433
|
+
"--input-type=module",
|
|
434
|
+
"-e",
|
|
435
|
+
`
|
|
377
436
|
import fs from 'node:fs'; import {syncBuiltinESMExports} from 'node:module';
|
|
378
437
|
const original=fs.mkdirSync; fs.mkdirSync=(path,options)=>{
|
|
379
|
-
if(path===${JSON.stringify(join(directory,
|
|
438
|
+
if(path===${JSON.stringify(join(directory, "raced-file"))}) fs.writeFileSync(path,'unsafe');
|
|
380
439
|
return original(path,options);
|
|
381
440
|
}; syncBuiltinESMExports();
|
|
382
441
|
const {ensurePrivateDirectoryDurably}=await import(${JSON.stringify(moduleUrl)});
|
|
383
|
-
ensurePrivateDirectoryDurably(${JSON.stringify(join(directory,
|
|
384
|
-
|
|
385
|
-
],
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
test('missing policy, wrong repository, changed config and stale head fail closed', async () => {
|
|
399
|
-
const state = setup();
|
|
400
|
-
try {
|
|
401
|
-
await assert.rejects(loadSelectedRepositoryPolicy({ repoRoot: state.root, policySourcePath: 'missing.mjs' }));
|
|
402
|
-
const policy = makePolicy(state);
|
|
403
|
-
assert.throws(() => classifyRepositoryExactRange({
|
|
404
|
-
repoRoot: state.root,
|
|
405
|
-
repository: 'wrong/repository',
|
|
406
|
-
base: state.base,
|
|
407
|
-
head: state.head,
|
|
408
|
-
changedPaths: ['change.txt'],
|
|
409
|
-
configDigest: state.configDigest,
|
|
410
|
-
policySourcePath: './policy.mjs',
|
|
411
|
-
policy: {
|
|
412
|
-
...policy,
|
|
413
|
-
classifyExactRange: (input) => policy.classifyExactRange({ ...input, repository: 'example/delivery' }),
|
|
414
|
-
},
|
|
415
|
-
}));
|
|
416
|
-
const p = proof(state, policy);
|
|
417
|
-
assert.throws(() => createRepositoryDeliveryEvidence({
|
|
418
|
-
...p.input,
|
|
419
|
-
policy: { ...policy, schemaVersion: 'RepositoryDeliveryPolicy@99' },
|
|
420
|
-
}));
|
|
421
|
-
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, configDigest: digestValue('drift') }));
|
|
422
|
-
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, currentHead: { ...state.head, tree: state.base.tree } }));
|
|
423
|
-
writeFileSync(join(state.root, 'policy.mjs'), 'export default {};\n');
|
|
424
|
-
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
425
|
-
}
|
|
426
|
-
finally {
|
|
427
|
-
state.cleanup();
|
|
442
|
+
ensurePrivateDirectoryDurably(${JSON.stringify(join(directory, "raced-file"))});
|
|
443
|
+
`
|
|
444
|
+
],
|
|
445
|
+
{ encoding: "utf8", timeout: 2e3, maxBuffer: 32768 }
|
|
446
|
+
);
|
|
447
|
+
assert.notEqual(racedFile.status, 0);
|
|
448
|
+
assert.match(racedFile.stderr, /directory/u);
|
|
449
|
+
} finally {
|
|
450
|
+
writeFileSync(release, "ready");
|
|
451
|
+
for (const worker of workers)
|
|
452
|
+
if (worker.child.exitCode === null && worker.child.signalCode === null) worker.child.kill("SIGKILL");
|
|
453
|
+
await Promise.all(workers.map((worker) => worker.closed));
|
|
454
|
+
rmSync(directory, { recursive: true, force: true });
|
|
428
455
|
}
|
|
456
|
+
}
|
|
457
|
+
);
|
|
458
|
+
test("missing policy, wrong repository, changed config and stale head fail closed", { tags: ["release"] }, async () => {
|
|
459
|
+
const state = setup();
|
|
460
|
+
try {
|
|
461
|
+
await assert.rejects(loadSelectedRepositoryPolicy({ repoRoot: state.root, policySourcePath: "missing.mjs" }));
|
|
462
|
+
const policy = makePolicy(state);
|
|
463
|
+
assert.throws(
|
|
464
|
+
() => classifyRepositoryExactRange({
|
|
465
|
+
repoRoot: state.root,
|
|
466
|
+
repository: "wrong/repository",
|
|
467
|
+
base: state.base,
|
|
468
|
+
head: state.head,
|
|
469
|
+
changedPaths: ["change.txt"],
|
|
470
|
+
configDigest: state.configDigest,
|
|
471
|
+
policySourcePath: "./policy.mjs",
|
|
472
|
+
policy: {
|
|
473
|
+
...policy,
|
|
474
|
+
classifyExactRange: (input) => policy.classifyExactRange({ ...input, repository: "example/delivery" })
|
|
475
|
+
}
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
const p = proof(state, policy);
|
|
479
|
+
assert.throws(
|
|
480
|
+
() => createRepositoryDeliveryEvidence({
|
|
481
|
+
...p.input,
|
|
482
|
+
policy: { ...policy, schemaVersion: "RepositoryDeliveryPolicy@99" }
|
|
483
|
+
})
|
|
484
|
+
);
|
|
485
|
+
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, configDigest: digestValue("drift") }));
|
|
486
|
+
assert.throws(
|
|
487
|
+
() => createRepositoryDeliveryEvidence({ ...p.input, currentHead: { ...state.head, tree: state.base.tree } })
|
|
488
|
+
);
|
|
489
|
+
writeFileSync(join(state.root, "policy.mjs"), "export default {};\n");
|
|
490
|
+
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
491
|
+
} finally {
|
|
492
|
+
state.cleanup();
|
|
493
|
+
}
|
|
429
494
|
});
|
|
430
|
-
test(
|
|
495
|
+
test(
|
|
496
|
+
"missing stage, corrupt artifact/output and blocked merge or wrong approval fail closed",
|
|
497
|
+
{ tags: ["release"] },
|
|
498
|
+
() => {
|
|
431
499
|
const state = setup();
|
|
432
500
|
try {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
501
|
+
const p = proof(state);
|
|
502
|
+
assert.throws(() => createRepositoryStageAggregate({ classification: p.classification, receipts: [] }));
|
|
503
|
+
const approval = {
|
|
504
|
+
authorIdentity: "author",
|
|
505
|
+
reviewerIdentity: "author",
|
|
506
|
+
diffScopeHash: digestValue(["change.txt"]),
|
|
507
|
+
head: state.head,
|
|
508
|
+
result: "approved",
|
|
509
|
+
reviewReceiptId: digestValue("review")
|
|
510
|
+
};
|
|
511
|
+
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, phase: "merge", approval }));
|
|
512
|
+
const validApproval = { ...approval, reviewerIdentity: "reviewer" };
|
|
513
|
+
assert.throws(
|
|
514
|
+
() => createRepositoryDeliveryEvidence({
|
|
515
|
+
...p.input,
|
|
516
|
+
phase: "merge",
|
|
517
|
+
approval: { ...validApproval, reviewerIdentity: "outsider" }
|
|
518
|
+
})
|
|
519
|
+
);
|
|
520
|
+
assert.throws(
|
|
521
|
+
() => createRepositoryDeliveryEvidence({
|
|
522
|
+
...p.input,
|
|
523
|
+
phase: "merge",
|
|
524
|
+
approval: validApproval,
|
|
525
|
+
now: () => /* @__PURE__ */ new Date("2026-01-01T00:00:10.000Z"),
|
|
526
|
+
mergeReadback: {
|
|
527
|
+
blockedBy: [17],
|
|
528
|
+
checksPassed: true,
|
|
439
529
|
head: state.head,
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
467
|
-
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
468
|
-
writeFileSync(join(state.root, 'output.txt'), 'stage artifact');
|
|
469
|
-
const outputPath = join(state.gitCommonDir, 'ai-delivery', 'verification@1', 'command-output', `${p.receipt.commands[0].outputDigest.slice(7)}.bin`);
|
|
470
|
-
writeFileSync(outputPath, 'corrupt command output');
|
|
471
|
-
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
472
|
-
const bad = {
|
|
473
|
-
...p.receipt,
|
|
474
|
-
commands: [{ ...p.receipt.commands[0], outputDigest: digestValue('absent') }],
|
|
475
|
-
};
|
|
476
|
-
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, stageReceipts: [bad] }));
|
|
477
|
-
}
|
|
478
|
-
finally {
|
|
479
|
-
state.cleanup();
|
|
530
|
+
mergeable: true,
|
|
531
|
+
observedAt: "2026-01-01T00:00:00.000Z"
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
writeFileSync(join(state.root, "artifact.txt"), "tampered");
|
|
536
|
+
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
537
|
+
writeFileSync(join(state.root, "artifact.txt"), "proof");
|
|
538
|
+
writeFileSync(join(state.root, "output.txt"), "tampered stage artifact");
|
|
539
|
+
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
540
|
+
writeFileSync(join(state.root, "output.txt"), "stage artifact");
|
|
541
|
+
const outputPath = join(
|
|
542
|
+
state.gitCommonDir,
|
|
543
|
+
"ai-delivery",
|
|
544
|
+
"verification@1",
|
|
545
|
+
"command-output",
|
|
546
|
+
`${p.receipt.commands[0].outputDigest.slice(7)}.bin`
|
|
547
|
+
);
|
|
548
|
+
writeFileSync(outputPath, "corrupt command output");
|
|
549
|
+
assert.throws(() => createRepositoryDeliveryEvidence(p.input));
|
|
550
|
+
const bad = {
|
|
551
|
+
...p.receipt,
|
|
552
|
+
commands: [{ ...p.receipt.commands[0], outputDigest: digestValue("absent") }]
|
|
553
|
+
};
|
|
554
|
+
assert.throws(() => createRepositoryDeliveryEvidence({ ...p.input, stageReceipts: [bad] }));
|
|
555
|
+
} finally {
|
|
556
|
+
state.cleanup();
|
|
480
557
|
}
|
|
481
|
-
}
|
|
482
|
-
|
|
558
|
+
}
|
|
559
|
+
);
|
|
560
|
+
//# sourceMappingURL=delivery.test.js.map
|