@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,447 +1,2518 @@
|
|
|
1
|
-
import assert from
|
|
2
|
-
import { execFileSync } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}));
|
|
60
|
-
const chunks = [];
|
|
61
|
-
for (const member of members) {
|
|
62
|
-
const path = join(source, member.path);
|
|
63
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
64
|
-
writeFileSync(path, member.bytes);
|
|
65
|
-
chmodSync(path, member.mode);
|
|
66
|
-
const header = Buffer.alloc(512);
|
|
67
|
-
header.write(`package/${member.path}`, 0, 100);
|
|
68
|
-
const number = (value, offset, size) => header.write(value.toString(8).padStart(size - 1, '0') + '\0', offset, size);
|
|
69
|
-
number(member.mode, 100, 8);
|
|
70
|
-
number(0, 108, 8);
|
|
71
|
-
number(0, 116, 8);
|
|
72
|
-
number(member.bytes.length, 124, 12);
|
|
73
|
-
number(0, 136, 12);
|
|
74
|
-
header.fill(32, 148, 156);
|
|
75
|
-
header.write('0', 156);
|
|
76
|
-
header.write('ustar\0', 257);
|
|
77
|
-
header.write('00', 263);
|
|
78
|
-
header.write(header
|
|
79
|
-
.reduce((a, b) => a + b, 0)
|
|
80
|
-
.toString(8)
|
|
81
|
-
.padStart(6, '0') + '\0 ', 148, 8);
|
|
82
|
-
chunks.push(header, member.bytes, Buffer.alloc((512 - (member.bytes.length % 512)) % 512));
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
import {
|
|
6
|
+
chmodSync,
|
|
7
|
+
closeSync,
|
|
8
|
+
constants,
|
|
9
|
+
existsSync,
|
|
10
|
+
fstatSync,
|
|
11
|
+
linkSync,
|
|
12
|
+
lstatSync,
|
|
13
|
+
mkdirSync,
|
|
14
|
+
mkdtempSync,
|
|
15
|
+
openSync,
|
|
16
|
+
readFileSync,
|
|
17
|
+
readdirSync,
|
|
18
|
+
readSync,
|
|
19
|
+
realpathSync,
|
|
20
|
+
renameSync,
|
|
21
|
+
rmSync,
|
|
22
|
+
symlinkSync,
|
|
23
|
+
truncateSync,
|
|
24
|
+
writeFileSync
|
|
25
|
+
} from "node:fs";
|
|
26
|
+
import { tmpdir } from "node:os";
|
|
27
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
28
|
+
import { gzipSync } from "node:zlib";
|
|
29
|
+
import { Script } from "node:vm";
|
|
30
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
31
|
+
import { test } from "vitest";
|
|
32
|
+
const api = await import(new URL("../scripts/release-artifact.mjs", import.meta.url).href);
|
|
33
|
+
const canonical = await import(new URL("../scripts/current-consumer.mjs", import.meta.url).href);
|
|
34
|
+
const qualification = await import(new URL("../scripts/current-qualification.mjs", import.meta.url).href);
|
|
35
|
+
const laneChecks = await import(new URL("../scripts/checks.mjs", import.meta.url).href);
|
|
36
|
+
const gates = ["format", "lint", "types", "build", "tests", "inventory"];
|
|
37
|
+
function diagnosticStep(name) {
|
|
38
|
+
const workflow = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8");
|
|
39
|
+
const step = workflow.split(/(?=^ {6}- )/mu).find((value) => value.includes(`name: ${name}
|
|
40
|
+
`));
|
|
41
|
+
assert.ok(step, name);
|
|
42
|
+
return step;
|
|
43
|
+
}
|
|
44
|
+
function failureLogUpload(directory, outcome, scanned) {
|
|
45
|
+
const step = diagnosticStep("Upload scanned failure logs");
|
|
46
|
+
const expression = /if: \$\{\{ (.+) \}\}/u.exec(step)?.[1];
|
|
47
|
+
assert.ok(expression);
|
|
48
|
+
const values = {
|
|
49
|
+
"always()": true,
|
|
50
|
+
"inputs.qualification_only": true,
|
|
51
|
+
"steps.failure_log_scan.outcome": outcome,
|
|
52
|
+
"steps.failure_log_scan.outputs.scanned": scanned ?? ""
|
|
53
|
+
};
|
|
54
|
+
const admitted = expression.split(" && ").every((term) => {
|
|
55
|
+
const comparison = /^(\S+) == '([^']*)'$/u.exec(term);
|
|
56
|
+
if (comparison) {
|
|
57
|
+
assert.ok(comparison[1] in values, term);
|
|
58
|
+
return values[comparison[1]] === comparison[2];
|
|
83
59
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
60
|
+
assert.ok(term in values, term);
|
|
61
|
+
return values[term] === true;
|
|
62
|
+
});
|
|
63
|
+
if (!admitted) return [];
|
|
64
|
+
const paths = /path: \|\n([\s\S]*?)\n\s+if-no-files-found:/u.exec(step)?.[1];
|
|
65
|
+
assert.ok(paths);
|
|
66
|
+
return paths.trim().split("\n").map((line) => {
|
|
67
|
+
const prefix = "${{ steps.diagnostics.outputs.logs_directory }}/";
|
|
68
|
+
const path = line.trim();
|
|
69
|
+
assert.ok(path.startsWith(prefix));
|
|
70
|
+
const name = path.slice(prefix.length);
|
|
71
|
+
assert.ok(
|
|
72
|
+
[
|
|
73
|
+
"manifest.json",
|
|
74
|
+
"producer.stdout.txt",
|
|
75
|
+
"producer.stderr.txt",
|
|
76
|
+
"release.stdout.txt",
|
|
77
|
+
"release.stderr.txt"
|
|
78
|
+
].includes(name)
|
|
79
|
+
);
|
|
80
|
+
return { name, path: join(directory, name) };
|
|
81
|
+
}).filter((file) => existsSync(file.path));
|
|
82
|
+
}
|
|
83
|
+
function decodeDiagnostic(wire, source, sourceRoot, inventory = laneChecks.RELEASE_CASES) {
|
|
84
|
+
assert.match(source, /^[a-f0-9]{40}$/u);
|
|
85
|
+
assert.equal(wire["source"], source, "Diagnostic source differs.");
|
|
86
|
+
assert.deepEqual(Object.keys(wire).sort(), [
|
|
87
|
+
"consumer",
|
|
88
|
+
"inputs",
|
|
89
|
+
"logs",
|
|
90
|
+
"observationOnly",
|
|
91
|
+
"overall",
|
|
92
|
+
"pack",
|
|
93
|
+
"producer",
|
|
94
|
+
"promotionEligible",
|
|
95
|
+
"qualificationOutcome",
|
|
96
|
+
"qualified",
|
|
97
|
+
"release",
|
|
98
|
+
"runAttempt",
|
|
99
|
+
"runId",
|
|
100
|
+
"source"
|
|
101
|
+
]);
|
|
102
|
+
assert.equal(wire["observationOnly"], true);
|
|
103
|
+
assert.equal(wire["qualified"], false);
|
|
104
|
+
assert.equal(wire["promotionEligible"], false);
|
|
105
|
+
const logs = wire["logs"];
|
|
106
|
+
assert.deepEqual(Object.keys(logs).sort(), [
|
|
107
|
+
"bytes",
|
|
108
|
+
...Object.hasOwn(logs, "cleanupConfirmed") ? ["cleanupConfirmed"] : [],
|
|
109
|
+
"files",
|
|
110
|
+
"status"
|
|
111
|
+
]);
|
|
112
|
+
assert.ok(["unavailable", "staged", "refused"].includes(logs["status"]));
|
|
113
|
+
assert.ok(
|
|
114
|
+
Number.isSafeInteger(logs["bytes"]) && Number(logs["bytes"]) >= 0 && Number(logs["bytes"]) <= 64 * 1024 * 1024
|
|
115
|
+
);
|
|
116
|
+
if (Object.hasOwn(logs, "cleanupConfirmed")) assert.equal(typeof logs["cleanupConfirmed"], "boolean");
|
|
117
|
+
const logFiles = logs["files"];
|
|
118
|
+
assert.ok(Array.isArray(logFiles) && logFiles.length <= 4);
|
|
119
|
+
const logNames = ["producer.stdout.txt", "producer.stderr.txt", "release.stdout.txt", "release.stderr.txt"];
|
|
120
|
+
for (const [index, value] of logFiles.entries()) {
|
|
121
|
+
const entry = value;
|
|
122
|
+
assert.deepEqual(Object.keys(entry).sort(), ["name", "status"]);
|
|
123
|
+
assert.equal(entry["name"], logNames[index]);
|
|
124
|
+
assert.ok(["unavailable", "missing", "read", "unsafe", "oversized", "changed"].includes(entry["status"]));
|
|
125
|
+
}
|
|
126
|
+
const release = wire["release"];
|
|
127
|
+
assert.deepEqual(Object.keys(release).sort(), [
|
|
128
|
+
"caseEncoding",
|
|
129
|
+
"cases",
|
|
130
|
+
"cleanup",
|
|
131
|
+
"command",
|
|
132
|
+
"counts",
|
|
133
|
+
"inventory",
|
|
134
|
+
"status"
|
|
135
|
+
]);
|
|
136
|
+
assert.equal(release["caseEncoding"], "ai-delivery.release-case-tuples@1");
|
|
137
|
+
const identities = inventory.map(({ file, title, kind }) => ({ file, title, kind }));
|
|
138
|
+
assert.equal(new Set(identities.map(({ file, title }) => JSON.stringify([file, title]))).size, identities.length);
|
|
139
|
+
const files = [
|
|
140
|
+
...new Set(identities.flatMap(({ file }) => [file, file.replace(/^dist\//u, "src/").replace(/\.js$/u, ".ts")]))
|
|
141
|
+
];
|
|
142
|
+
assert.deepEqual(release["inventory"], {
|
|
143
|
+
sha256: createHash("sha256").update(JSON.stringify(identities)).digest("hex"),
|
|
144
|
+
caseCount: identities.length,
|
|
145
|
+
publicFileCount: files.length
|
|
146
|
+
});
|
|
147
|
+
const cases = release["cases"];
|
|
148
|
+
assert.ok(Array.isArray(cases));
|
|
149
|
+
assert.equal(cases.length, identities.length);
|
|
150
|
+
const code = /* @__PURE__ */ new Map();
|
|
151
|
+
const decoded = cases.map((row, ordinal) => {
|
|
152
|
+
assert.ok(Array.isArray(row));
|
|
153
|
+
assert.equal(row.length, 3);
|
|
154
|
+
assert.equal(row[0], ordinal, "Diagnostic case ordinal differs.");
|
|
155
|
+
const state = row[1];
|
|
156
|
+
assert.equal(typeof state, "string");
|
|
157
|
+
assert.ok(
|
|
158
|
+
["passed", "failed", "pending", "skipped", "todo", "disabled", "ambiguous", "unknown"].includes(state)
|
|
159
|
+
);
|
|
160
|
+
const identity = identities[ordinal];
|
|
161
|
+
if (state !== "failed") {
|
|
162
|
+
assert.equal(row[2], null);
|
|
163
|
+
return { file: identity.file, title: identity.title, status: state };
|
|
164
|
+
}
|
|
165
|
+
const failure = row[2];
|
|
166
|
+
assert.ok(Array.isArray(failure));
|
|
167
|
+
assert.equal(failure.length, 3);
|
|
168
|
+
const frameStatus = failure[0];
|
|
169
|
+
const truncated = failure[1];
|
|
170
|
+
assert.ok(typeof frameStatus === "string" && ["matched", "no-match", "unknown"].includes(frameStatus));
|
|
171
|
+
assert.equal(typeof truncated, "boolean");
|
|
172
|
+
assert.ok(Array.isArray(failure[2]) && failure[2].length <= 4);
|
|
173
|
+
let priorMessage = 1;
|
|
174
|
+
const frames = failure[2].map((frame) => {
|
|
175
|
+
assert.ok(Array.isArray(frame));
|
|
176
|
+
assert.equal(frame.length, 4);
|
|
177
|
+
const [file, line, column, message] = frame;
|
|
178
|
+
assert.ok(Number.isSafeInteger(file) && Number(file) >= 0 && Number(file) < files.length);
|
|
179
|
+
assert.ok(Number.isSafeInteger(line) && Number(line) > 0);
|
|
180
|
+
assert.ok(Number.isSafeInteger(column) && Number(column) > 0);
|
|
181
|
+
assert.ok((message === 1 || message === 2) && message >= priorMessage);
|
|
182
|
+
priorMessage = message;
|
|
183
|
+
const path = files[Number(file)];
|
|
184
|
+
if (!code.has(path)) {
|
|
185
|
+
const absolute = join(sourceRoot, path);
|
|
186
|
+
const stat = lstatSync(absolute);
|
|
187
|
+
assert.ok(stat.isFile() && !stat.isSymbolicLink() && stat.nlink === 1 && stat.size <= 4 * 1024 * 1024);
|
|
188
|
+
assert.equal(realpathSync(absolute), absolute);
|
|
189
|
+
const bytes = readFileSync(absolute);
|
|
190
|
+
assert.equal(bytes.length, stat.size);
|
|
191
|
+
code.set(path, bytes.toString("utf8").split(/\r?\n/u));
|
|
192
|
+
}
|
|
193
|
+
const lines = code.get(path);
|
|
194
|
+
assert.ok(Number(line) <= lines.length && Number(column) <= lines[Number(line) - 1].length + 1);
|
|
195
|
+
return { file: path, line, column, message };
|
|
151
196
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
'--json',
|
|
160
|
-
'--pack-destination',
|
|
161
|
-
dirname(archivePath),
|
|
162
|
-
],
|
|
197
|
+
if (frameStatus === "matched") assert.ok(frames.length > 0);
|
|
198
|
+
if (frameStatus === "no-match") assert.ok(frames.length === 0 && truncated === false);
|
|
199
|
+
return {
|
|
200
|
+
file: identity.file,
|
|
201
|
+
title: identity.title,
|
|
202
|
+
status: state,
|
|
203
|
+
failureFrames: { status: frameStatus, truncated, frames }
|
|
163
204
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
205
|
+
});
|
|
206
|
+
return { ...wire, release: { ...release, cases: decoded } };
|
|
207
|
+
}
|
|
208
|
+
function diagnosticFixture() {
|
|
209
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "ai-delivery-diagnostic-")));
|
|
210
|
+
const sourceRoot = join(root, "public source");
|
|
211
|
+
for (const file of new Set(laneChecks.RELEASE_CASES.map((entry2) => entry2.file))) {
|
|
212
|
+
for (const relative of [file, file.replace(/^dist\//u, "src/").replace(/\.js$/u, ".ts")]) {
|
|
213
|
+
const path = join(sourceRoot, relative);
|
|
214
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
215
|
+
writeFileSync(path, "// synthetic public coordinate bounds\n".repeat(1200));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const qualificationRoot = join(root, "release-qualification");
|
|
219
|
+
const runId = "11111111-1111-4111-8111-111111111111";
|
|
220
|
+
const releaseDirectory = join(qualificationRoot, `release-tests-${runId}`);
|
|
221
|
+
const consumerDirectory = join(qualificationRoot, `consumer-${runId}`);
|
|
222
|
+
const sensitive = "SENSITIVE_DIAGNOSTIC_SENTINEL";
|
|
223
|
+
const save = (path, value) => {
|
|
224
|
+
const destination = join(qualificationRoot, path);
|
|
225
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
226
|
+
writeFileSync(destination, JSON.stringify(value));
|
|
227
|
+
};
|
|
228
|
+
save("result.json", {
|
|
229
|
+
schemaVersion: "ai-delivery.current-qualification@1",
|
|
230
|
+
runId,
|
|
231
|
+
status: "failed",
|
|
232
|
+
qualified: false,
|
|
233
|
+
source: { commit: "a".repeat(40) },
|
|
234
|
+
error: sensitive,
|
|
235
|
+
environment: { token: sensitive },
|
|
236
|
+
pack: { status: "passed", exitCode: 0, signal: null, cleanupConfirmed: true, command: [sensitive] }
|
|
237
|
+
});
|
|
238
|
+
save("producer/result.json", {
|
|
239
|
+
status: "passed",
|
|
240
|
+
fullSuccess: true,
|
|
241
|
+
commands: gates.map((stage) => ({
|
|
242
|
+
stage,
|
|
243
|
+
status: "passed",
|
|
244
|
+
exitCode: 0,
|
|
245
|
+
signal: null,
|
|
246
|
+
cleanupConfirmed: true,
|
|
247
|
+
error: sensitive
|
|
248
|
+
}))
|
|
249
|
+
});
|
|
250
|
+
save("pack/producer.json", { archiveSha256: "b".repeat(64), error: sensitive });
|
|
251
|
+
save("release-tests-attempt.json", {
|
|
252
|
+
stage: "release-tests",
|
|
253
|
+
runId,
|
|
254
|
+
status: "completed",
|
|
255
|
+
directory: releaseDirectory,
|
|
256
|
+
resultPath: join(releaseDirectory, "result.json")
|
|
257
|
+
});
|
|
258
|
+
save(`release-tests-${runId}/result.json`, {
|
|
259
|
+
status: "failed",
|
|
260
|
+
commands: [
|
|
261
|
+
{
|
|
262
|
+
stage: "tests",
|
|
263
|
+
status: "failed",
|
|
264
|
+
exitCode: 1,
|
|
265
|
+
signal: null,
|
|
266
|
+
cleanupConfirmed: true,
|
|
267
|
+
stdoutPath: sensitive,
|
|
268
|
+
error: sensitive
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
release: { temporary: { removed: false, quiescent: true, error: sensitive } }
|
|
272
|
+
});
|
|
273
|
+
const entry = laneChecks.RELEASE_CASES[0];
|
|
274
|
+
save(`release-tests-${runId}/vitest.json`, {
|
|
275
|
+
numTotalTests: 24,
|
|
276
|
+
numPassedTests: 22,
|
|
277
|
+
numFailedTests: 1,
|
|
278
|
+
testResults: [
|
|
279
|
+
{
|
|
280
|
+
name: join(sourceRoot, entry.file),
|
|
281
|
+
assertionResults: [
|
|
282
|
+
{ fullName: entry.title, status: "failed", failureMessages: [sensitive] },
|
|
283
|
+
{ fullName: sensitive, status: "passed" }
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
save("consumer-attempt.json", {
|
|
289
|
+
schemaVersion: "ai-delivery.current-consumer-attempt@1",
|
|
290
|
+
runId,
|
|
291
|
+
status: "running",
|
|
292
|
+
directory: consumerDirectory,
|
|
293
|
+
consumerPath: join(consumerDirectory, "result.json"),
|
|
294
|
+
command: { status: "cancelled", signal: "SIGTERM", cleanupConfirmed: false }
|
|
295
|
+
});
|
|
296
|
+
save(`consumer-${runId}/result.json`, {
|
|
297
|
+
status: "incomplete",
|
|
298
|
+
qualified: false,
|
|
299
|
+
cleanup: { removed: false, quiescent: false, retainedDirectory: sensitive },
|
|
300
|
+
error: sensitive
|
|
301
|
+
});
|
|
302
|
+
save(`release-tests-${runId}/temporary/.npmrc`, sensitive);
|
|
303
|
+
save("producer/command/stderr.txt", sensitive);
|
|
304
|
+
let outputs = {};
|
|
305
|
+
const raw = (outcome = "failure", env = {}, inventory = laneChecks.RELEASE_CASES, overrides = {}) => {
|
|
306
|
+
const step = diagnosticStep("Prepare failed qualification diagnostics");
|
|
307
|
+
const script = /node --input-type=module <<'JS'\n([\s\S]*?)\n\s+JS/u.exec(step)?.[1];
|
|
308
|
+
assert.ok(script);
|
|
309
|
+
const program = script.replace(/^\s*import .+;\n/gmu, "");
|
|
310
|
+
const output = join(root, "output");
|
|
311
|
+
writeFileSync(output, "");
|
|
312
|
+
new Script(program).runInNewContext({
|
|
313
|
+
constants,
|
|
314
|
+
createHash,
|
|
315
|
+
closeSync,
|
|
316
|
+
fstatSync,
|
|
317
|
+
lstatSync,
|
|
318
|
+
mkdirSync,
|
|
319
|
+
mkdtempSync,
|
|
320
|
+
openSync,
|
|
321
|
+
readFileSync,
|
|
322
|
+
readSync,
|
|
323
|
+
realpathSync,
|
|
324
|
+
rmSync,
|
|
325
|
+
writeFileSync,
|
|
326
|
+
...overrides,
|
|
327
|
+
appendFileSync: (path2, value) => {
|
|
328
|
+
assert.equal(path2, output);
|
|
329
|
+
writeFileSync(path2, value, { flag: "a" });
|
|
330
|
+
},
|
|
331
|
+
basename,
|
|
332
|
+
dirname,
|
|
333
|
+
join,
|
|
334
|
+
resolve,
|
|
335
|
+
fileURLToPath,
|
|
336
|
+
URL,
|
|
337
|
+
Buffer,
|
|
338
|
+
RELEASE_CASES: inventory,
|
|
339
|
+
process: {
|
|
340
|
+
env: {
|
|
341
|
+
RUNNER_TEMP: root,
|
|
342
|
+
GITHUB_WORKSPACE: sourceRoot,
|
|
343
|
+
GITHUB_OUTPUT: output,
|
|
344
|
+
GITHUB_RUN_ID: "101",
|
|
345
|
+
GITHUB_RUN_ATTEMPT: "1",
|
|
346
|
+
REVIEWED_SOURCE_SHA: "a".repeat(40),
|
|
347
|
+
GITHUB_SHA: "a".repeat(40),
|
|
348
|
+
QUALIFICATION_OUTCOME: outcome,
|
|
349
|
+
SECRET_VALUE: sensitive,
|
|
350
|
+
...env
|
|
351
|
+
}
|
|
352
|
+
}
|
|
180
353
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
354
|
+
outputs = Object.fromEntries(
|
|
355
|
+
readFileSync(output, "utf8").trim().split("\n").map((line) => {
|
|
356
|
+
const equal = line.indexOf("=");
|
|
357
|
+
return [line.slice(0, equal), line.slice(equal + 1)];
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
const path = outputs["file"];
|
|
361
|
+
assert.ok(path);
|
|
362
|
+
assert.equal(dirname(dirname(path)), root);
|
|
363
|
+
const bytes = readFileSync(path, "utf8");
|
|
364
|
+
assert.ok(Buffer.byteLength(bytes) <= 64 * 1024);
|
|
365
|
+
assert.ok(!bytes.includes(sensitive));
|
|
366
|
+
assert.ok(!bytes.includes(root), "runtime paths must not cross the public projection");
|
|
367
|
+
return JSON.parse(bytes);
|
|
368
|
+
};
|
|
369
|
+
const execute = (outcome = "failure", overrides = {}) => decodeDiagnostic(raw(outcome, {}, laneChecks.RELEASE_CASES, overrides), "a".repeat(40), sourceRoot);
|
|
370
|
+
const failures = (failureMessages, status = "failed") => save(`release-tests-${runId}/vitest.json`, {
|
|
371
|
+
testResults: [
|
|
372
|
+
{
|
|
373
|
+
name: join(sourceRoot, entry.file),
|
|
374
|
+
assertionResults: [{ fullName: entry.title, status, failureMessages, location: { line: 12, column: 1 } }]
|
|
375
|
+
}
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
const frames = () => {
|
|
379
|
+
const cases = execute()["release"]["cases"];
|
|
380
|
+
return cases[0]["failureFrames"];
|
|
381
|
+
};
|
|
382
|
+
const log = (relative, bytes) => {
|
|
383
|
+
const path = join(qualificationRoot, relative);
|
|
384
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
385
|
+
writeFileSync(path, bytes, { mode: 384 });
|
|
386
|
+
return path;
|
|
387
|
+
};
|
|
388
|
+
return {
|
|
389
|
+
root,
|
|
390
|
+
sourceRoot,
|
|
391
|
+
qualificationRoot,
|
|
392
|
+
releaseDirectory,
|
|
393
|
+
runId,
|
|
394
|
+
save,
|
|
395
|
+
raw,
|
|
396
|
+
execute,
|
|
397
|
+
sensitive,
|
|
398
|
+
failures,
|
|
399
|
+
frames,
|
|
400
|
+
log,
|
|
401
|
+
logs: () => outputs["logs_directory"]
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
test.each(["producer", "release", "both"])(
|
|
405
|
+
"failed qualification stages exact fixed %s test output including the actual synthetic receipt",
|
|
406
|
+
(scope) => {
|
|
407
|
+
const f = diagnosticFixture();
|
|
408
|
+
try {
|
|
409
|
+
const receipt = 'SETUP_CLI_PHASE_RECEIPT {"scenario":"budget","nativeIdle":true}\n';
|
|
410
|
+
const expected = {};
|
|
411
|
+
for (const stage of ["producer", "release"]) {
|
|
412
|
+
if (scope !== "both" && scope !== stage) continue;
|
|
413
|
+
const directory2 = stage === "producer" ? "producer" : `release-tests-${f.runId}`;
|
|
414
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
415
|
+
const bytes = stream === "stdout" ? receipt : "Synthetic test failure\n";
|
|
416
|
+
f.log(`${directory2}/tests/${stream}.txt`, bytes);
|
|
417
|
+
expected[`${stage}.${stream}.txt`] = bytes;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (scope === "producer") rmSync(join(f.qualificationRoot, "release-tests-attempt.json"));
|
|
421
|
+
const projection = f.execute();
|
|
422
|
+
const directory = f.logs();
|
|
423
|
+
assert.ok(directory, "Fixed failed test logs must be staged for scanning.");
|
|
424
|
+
assert.equal(dirname(directory), f.root);
|
|
425
|
+
assert.equal(lstatSync(directory).mode & 511, 448);
|
|
426
|
+
const manifest = JSON.parse(readFileSync(join(directory, "manifest.json"), "utf8"));
|
|
427
|
+
assert.equal(manifest["observationOnly"], true);
|
|
428
|
+
assert.equal(manifest["qualified"], false);
|
|
429
|
+
assert.equal(manifest["promotionEligible"], false);
|
|
430
|
+
const files = manifest["files"];
|
|
431
|
+
assert.deepEqual(
|
|
432
|
+
files.map((file) => file.name),
|
|
433
|
+
Object.keys(expected)
|
|
434
|
+
);
|
|
435
|
+
for (const file of files) {
|
|
436
|
+
assert.equal(readFileSync(join(directory, file.name), "utf8"), expected[file.name]);
|
|
437
|
+
assert.equal(file.bytes, Buffer.byteLength(expected[file.name]));
|
|
438
|
+
assert.equal(file.sha256, canonical.sha256(expected[file.name]));
|
|
439
|
+
assert.equal(lstatSync(join(directory, file.name)).mode & 511, 384);
|
|
440
|
+
}
|
|
441
|
+
assert.equal(JSON.stringify(projection).includes("SETUP_CLI_PHASE_RECEIPT"), false);
|
|
442
|
+
assert.equal(JSON.stringify(manifest).includes(f.sensitive), false);
|
|
443
|
+
assert.equal(JSON.stringify(manifest).includes(f.root), false);
|
|
444
|
+
const upload = failureLogUpload(directory, "success", "true");
|
|
445
|
+
assert.deepEqual(upload.map((file) => file.name).sort(), ["manifest.json", ...Object.keys(expected)].sort());
|
|
446
|
+
assert.ok(upload.some((file) => readFileSync(file.path, "utf8").includes(receipt)));
|
|
447
|
+
assert.deepEqual(failureLogUpload(directory, "failure", "true"), []);
|
|
448
|
+
assert.deepEqual(failureLogUpload(directory, "success"), []);
|
|
449
|
+
} finally {
|
|
450
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
for (const fault of [
|
|
455
|
+
"leaf-link",
|
|
456
|
+
"parent-link",
|
|
457
|
+
"hardlink",
|
|
458
|
+
"fifo",
|
|
459
|
+
"oversized",
|
|
460
|
+
"combined-limit",
|
|
461
|
+
"changed",
|
|
462
|
+
"deleted",
|
|
463
|
+
"parent-changed",
|
|
464
|
+
"parent-deleted",
|
|
465
|
+
"before-open",
|
|
466
|
+
"before-leaf"
|
|
467
|
+
]) {
|
|
468
|
+
test(
|
|
469
|
+
`failed qualification refuses ${fault} test logs while retaining the safe projection`,
|
|
470
|
+
{ tags: fault === "fifo" ? ["release"] : [] },
|
|
471
|
+
() => {
|
|
472
|
+
const f = diagnosticFixture();
|
|
473
|
+
try {
|
|
474
|
+
const path = f.log("producer/tests/stdout.txt", "SETUP_CLI_PHASE_RECEIPT {}\n");
|
|
475
|
+
if (fault === "leaf-link" || fault === "hardlink") {
|
|
476
|
+
const outside = join(f.root, "private-unrelated");
|
|
477
|
+
writeFileSync(outside, f.sensitive);
|
|
478
|
+
rmSync(path);
|
|
479
|
+
if (fault === "leaf-link") symlinkSync(outside, path);
|
|
480
|
+
else linkSync(outside, path);
|
|
481
|
+
}
|
|
482
|
+
if (fault === "parent-link") {
|
|
483
|
+
const outside = join(f.root, "private-tests");
|
|
484
|
+
renameSync(dirname(path), outside);
|
|
485
|
+
symlinkSync(outside, dirname(path));
|
|
486
|
+
}
|
|
487
|
+
if (fault === "fifo") {
|
|
488
|
+
rmSync(path);
|
|
489
|
+
execFileSync("mkfifo", [path]);
|
|
490
|
+
}
|
|
491
|
+
if (fault === "oversized" || fault === "combined-limit") {
|
|
492
|
+
truncateSync(path, 32 * 1024 * 1024 + (fault === "oversized" ? 1 : 0));
|
|
493
|
+
if (fault === "combined-limit") f.log("producer/tests/stderr.txt", "x");
|
|
494
|
+
}
|
|
495
|
+
const changing = ["changed", "deleted", "parent-changed", "parent-deleted"].includes(fault);
|
|
496
|
+
const inode = changing ? lstatSync(path).ino : void 0;
|
|
497
|
+
const overrides = {};
|
|
498
|
+
if (changing)
|
|
499
|
+
overrides.readSync = ((...args) => {
|
|
500
|
+
const count = readSync(...args);
|
|
501
|
+
if (fstatSync(args[0]).ino === inode) {
|
|
502
|
+
if (fault === "deleted") rmSync(path);
|
|
503
|
+
else if (fault === "parent-changed" || fault === "parent-deleted") {
|
|
504
|
+
renameSync(dirname(path), join(f.root, "former-tests"));
|
|
505
|
+
if (fault === "parent-changed") {
|
|
506
|
+
mkdirSync(dirname(path));
|
|
507
|
+
writeFileSync(path, "replacement parent");
|
|
508
|
+
}
|
|
509
|
+
} else writeFileSync(path, "changed after read");
|
|
510
|
+
}
|
|
511
|
+
return count;
|
|
512
|
+
});
|
|
513
|
+
if (fault === "before-open" || fault === "before-leaf") {
|
|
514
|
+
f.log("producer/tests/stderr.txt", "Other available log must not authorize changed input.");
|
|
515
|
+
if (fault === "before-open")
|
|
516
|
+
overrides.openSync = ((...args) => {
|
|
517
|
+
if (args[0] === path) rmSync(path);
|
|
518
|
+
return openSync(...args);
|
|
519
|
+
});
|
|
520
|
+
else
|
|
521
|
+
overrides.lstatSync = ((...args) => {
|
|
522
|
+
if (args[0] === path) renameSync(dirname(path), join(f.root, "former-tests"));
|
|
523
|
+
return lstatSync(...args);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
const projection = f.execute("failure", overrides);
|
|
527
|
+
assert.equal(f.logs(), void 0, "Unsafe or oversized bytes must never be offered for upload.");
|
|
528
|
+
assert.equal(projection["observationOnly"], true);
|
|
529
|
+
assert.ok(projection["logs"], "The safe projection must report fixed log availability states.");
|
|
530
|
+
assert.equal(projection["logs"]["status"], "refused");
|
|
531
|
+
} finally {
|
|
532
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
test("missing failure logs retain explicit availability without inventing raw output", () => {
|
|
538
|
+
const f = diagnosticFixture();
|
|
539
|
+
try {
|
|
540
|
+
const projection = f.execute();
|
|
541
|
+
assert.equal(f.logs(), void 0);
|
|
542
|
+
assert.equal(projection["logs"]["status"], "unavailable");
|
|
543
|
+
assert.equal(projection["logs"]["files"].length, 4);
|
|
544
|
+
} finally {
|
|
545
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
async function scanFixture(scenario) {
|
|
549
|
+
const f = diagnosticFixture();
|
|
550
|
+
const receipt = 'SETUP_CLI_PHASE_RECEIPT {"scenario":"budget","nativeIdle":true}\n';
|
|
551
|
+
f.log("producer/tests/stdout.txt", receipt);
|
|
552
|
+
f.log("producer/tests/stderr.txt", "Synthetic test failure\n");
|
|
553
|
+
f.execute();
|
|
554
|
+
const directory = f.logs();
|
|
555
|
+
assert.ok(directory);
|
|
556
|
+
if (scenario === "extra-staged") writeFileSync(join(directory, "unrelated-config"), f.sensitive);
|
|
557
|
+
if (scenario === "unsafe-staged") {
|
|
558
|
+
rmSync(join(directory, "producer.stdout.txt"));
|
|
559
|
+
symlinkSync(join(f.qualificationRoot, "producer/tests/stdout.txt"), join(directory, "producer.stdout.txt"));
|
|
560
|
+
}
|
|
561
|
+
if (scenario === "manifest-fields") {
|
|
562
|
+
const path = join(directory, "manifest.json");
|
|
563
|
+
const manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
564
|
+
manifest["unreviewed"] = f.sensitive;
|
|
565
|
+
writeFileSync(path, JSON.stringify(manifest));
|
|
566
|
+
}
|
|
567
|
+
const statePath = join(f.root, "docker-state.json");
|
|
568
|
+
const image = "sha256:" + "1".repeat(64);
|
|
569
|
+
const owned = "c".repeat(64);
|
|
570
|
+
const unrelated = "f".repeat(64);
|
|
571
|
+
const initial = {
|
|
572
|
+
image,
|
|
573
|
+
scannedFiles: [],
|
|
574
|
+
imagePresent: scenario !== "image-pull",
|
|
575
|
+
containers: [{ Id: unrelated, Name: "/unrelated", Image: image, Config: { Labels: {} }, State: { Running: true } }]
|
|
576
|
+
};
|
|
577
|
+
writeFileSync(statePath, JSON.stringify(initial));
|
|
578
|
+
const bin = join(f.root, "bin");
|
|
579
|
+
mkdirSync(bin);
|
|
580
|
+
const cli = join(bin, "docker");
|
|
581
|
+
writeFileSync(
|
|
582
|
+
cli,
|
|
583
|
+
`#!${process.execPath}
|
|
584
|
+
const fs = require('node:fs');
|
|
585
|
+
const path = ${JSON.stringify(statePath)}, directory = ${JSON.stringify(directory)}, scenario = ${JSON.stringify(scenario)};
|
|
586
|
+
const args = process.argv.slice(2), state = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
587
|
+
const save = () => { fs.writeFileSync(path + '.next', JSON.stringify(state)); fs.renameSync(path + '.next', path); };
|
|
588
|
+
const out = value => process.stdout.write(JSON.stringify(value) + '\\n');
|
|
589
|
+
const option = name => args[args.indexOf(name) + 1];
|
|
590
|
+
if (process.env.GH_TOKEN || process.env.SECRET_VALUE) process.exit(96);
|
|
591
|
+
if (args[0] === 'image' && args[1] === 'inspect') {
|
|
592
|
+
if (!state.imagePresent) process.exit(1);
|
|
593
|
+
out({ Id: state.image, RepoDigests: ['ghcr.io/trufflesecurity/trufflehog@sha256:' + '2'.repeat(64)] });
|
|
594
|
+
} else if (args[0] === 'pull') { state.imagePresent = true; save(); process.stdout.write('synthetic pinned image ready\\n'); }
|
|
595
|
+
else if (args[0] === 'create') {
|
|
596
|
+
const labels = {};
|
|
597
|
+
args.forEach((value, index) => { if (value === '--label') { const [key, ...rest] = args[index + 1].split('='); labels[key] = rest.join('='); } });
|
|
598
|
+
const container = { Id: '${owned}', Name: '/' + option('--name'), Image: state.image, Config: { Labels: labels, User: args.includes('--user') ? option('--user') : '', Cmd: args.slice(args.indexOf(state.image) + 1) }, Mounts: [{ Type: 'bind', Source: directory, Destination: '/logs', RW: false }], HostConfig: { Memory: Number(option('--memory')), MemorySwap: Number(option('--memory-swap')), NetworkMode: option('--network'), ReadonlyRootfs: args.includes('--read-only'), CapDrop: [option('--cap-drop')], SecurityOpt: [option('--security-opt')], LogConfig: { Type: option('--log-driver') }, PidsLimit: Number(option('--pids-limit')) }, State: { Running: false, ExitCode: 0, OOMKilled: false } };
|
|
599
|
+
if (scenario === 'resource') container.HostConfig.Memory = 0;
|
|
600
|
+
if (scenario === 'inaccessible') container.Config.User = '999:999';
|
|
601
|
+
state.containers.push(container); save();
|
|
602
|
+
if (scenario === 'create-ack') process.exit(7);
|
|
603
|
+
if (scenario === 'malformed-ack') { process.stdout.write('created ' + container.Id + '\\n'); process.exit(0); }
|
|
604
|
+
process.stdout.write(container.Id + '\\n');
|
|
605
|
+
} else if (args[0] === 'start') {
|
|
606
|
+
const container = state.containers.find(value => value.Id === args.at(-1));
|
|
607
|
+
if (!container) process.exit(3);
|
|
608
|
+
container.State.Running = true; save();
|
|
609
|
+
if (scenario === 'cancel') setInterval(() => {}, 1000);
|
|
610
|
+
else if (scenario === 'overflow') process.stdout.write(Buffer.alloc(33 * 1024 * 1024, 120));
|
|
611
|
+
else {
|
|
612
|
+
container.State.Running = false;
|
|
613
|
+
container.State.ExitCode = scenario === 'findings' ? 183 : 0;
|
|
614
|
+
const user = fs.lstatSync(directory), canRead = container.Config.User === user.uid + ':' + user.gid;
|
|
615
|
+
const paths = container.Config.Cmd.slice(1).filter(value => value.startsWith('/logs'));
|
|
616
|
+
const explicit = paths.length > 0 && paths.every(value => value.startsWith('/logs/'));
|
|
617
|
+
const error = !canRead || scenario === 'scan-error' || scenario === 'directory-error';
|
|
618
|
+
state.scannedFiles = error ? [] : (explicit ? paths.map(value => value.slice(6)) : fs.readdirSync(directory));
|
|
619
|
+
// Pinned TruffleHog directory walking can log an error yet return zero; exact file-unit errors propagate.
|
|
620
|
+
if (error && container.Config.Cmd.includes('--fail-on-scan-errors') && (scenario === 'scan-error' || explicit)) container.State.ExitCode = 1;
|
|
621
|
+
if (scenario === 'foreign') container.Config.Labels = {};
|
|
622
|
+
if (scenario === 'drift') fs.writeFileSync(directory + '/producer.stdout.txt', 'changed after scan');
|
|
623
|
+
save();
|
|
624
|
+
if (scenario === 'findings') { process.stdout.write('SENSITIVE_SCANNER_FINDING\\n'); process.exit(183); }
|
|
625
|
+
if (container.State.ExitCode) { process.stderr.write('SENSITIVE_SCANNER_FINDING file read error\\n'); process.exit(container.State.ExitCode); }
|
|
626
|
+
}
|
|
627
|
+
} else if (args[0] === 'container' && args[1] === 'inspect') {
|
|
628
|
+
const selector = args.at(-1), container = state.containers.find(value => value.Id === selector || value.Name === '/' + selector);
|
|
629
|
+
if (!container) process.exit(1);
|
|
630
|
+
out(container);
|
|
631
|
+
} else if (args[0] === 'container' && args[1] === 'ls') {
|
|
632
|
+
const filters = args.flatMap((value, index) => value === '--filter' ? [args[index + 1]] : []);
|
|
633
|
+
for (const container of state.containers) {
|
|
634
|
+
const matches = filters.every(filter => {
|
|
635
|
+
if (filter.startsWith('name=')) return new RegExp(filter.slice(5)).test(container.Name);
|
|
636
|
+
if (filter.startsWith('label=')) { const [key, ...rest] = filter.slice(6).split('='); return container.Config.Labels[key] === rest.join('='); }
|
|
637
|
+
return false;
|
|
196
638
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
639
|
+
if (matches) process.stdout.write(container.Id + '\\n');
|
|
640
|
+
}
|
|
641
|
+
} else if (args[0] === 'container' && args[1] === 'rm') {
|
|
642
|
+
if (scenario === 'cleanup') process.exit(8);
|
|
643
|
+
state.containers = state.containers.filter(value => value.Id !== args.at(-1)); save();
|
|
644
|
+
} else process.exit(88);
|
|
645
|
+
`,
|
|
646
|
+
{ mode: 493 }
|
|
647
|
+
);
|
|
648
|
+
const output = join(f.root, "scan-output");
|
|
649
|
+
writeFileSync(output, "");
|
|
650
|
+
let visibleError = "";
|
|
651
|
+
const host = Object.assign(new EventEmitter(), {
|
|
652
|
+
env: {
|
|
653
|
+
PATH: bin + ":" + (process.env.PATH ?? ""),
|
|
654
|
+
RUNNER_TEMP: f.root,
|
|
655
|
+
LOGS_DIRECTORY: directory,
|
|
656
|
+
GITHUB_WORKSPACE: process.cwd(),
|
|
657
|
+
GITHUB_OUTPUT: output,
|
|
658
|
+
GITHUB_RUN_ID: "101",
|
|
659
|
+
GITHUB_RUN_ATTEMPT: "1",
|
|
660
|
+
REVIEWED_SOURCE_SHA: "a".repeat(40),
|
|
661
|
+
GH_TOKEN: f.sensitive,
|
|
662
|
+
SECRET_VALUE: f.sensitive
|
|
663
|
+
},
|
|
664
|
+
exitCode: 0,
|
|
665
|
+
stderr: {
|
|
666
|
+
write: (bytes) => {
|
|
667
|
+
visibleError += bytes;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
let timer;
|
|
672
|
+
try {
|
|
673
|
+
const script = /node --input-type=module <<'JS'\n([\s\S]*?)\n\s+JS/u.exec(
|
|
674
|
+
diagnosticStep("Scan failed qualification logs")
|
|
675
|
+
)?.[1];
|
|
676
|
+
assert.ok(script);
|
|
677
|
+
const program = script.replace(/^\s*import .+;\n/gmu, "");
|
|
678
|
+
if (scenario === "cancel")
|
|
679
|
+
timer = setInterval(() => {
|
|
680
|
+
const state2 = JSON.parse(readFileSync(statePath, "utf8"));
|
|
681
|
+
if (state2.containers.some((value) => value.Id === owned && value.State.Running)) host.emit("SIGTERM");
|
|
682
|
+
}, 50);
|
|
683
|
+
await new Script("(async () => {\n" + program + "\n})()").runInNewContext({
|
|
684
|
+
constants,
|
|
685
|
+
closeSync,
|
|
686
|
+
fstatSync,
|
|
687
|
+
lstatSync,
|
|
688
|
+
mkdirSync,
|
|
689
|
+
mkdtempSync,
|
|
690
|
+
openSync,
|
|
691
|
+
readFileSync,
|
|
692
|
+
readdirSync,
|
|
693
|
+
readSync,
|
|
694
|
+
realpathSync,
|
|
695
|
+
writeFileSync,
|
|
696
|
+
createHash,
|
|
697
|
+
randomUUID,
|
|
698
|
+
appendFileSync: (path, bytes) => writeFileSync(path, bytes, { flag: "a" }),
|
|
699
|
+
basename,
|
|
700
|
+
dirname,
|
|
701
|
+
join,
|
|
702
|
+
resolve,
|
|
703
|
+
Buffer,
|
|
704
|
+
AbortController,
|
|
705
|
+
process: host,
|
|
706
|
+
executeCommand: laneChecks.executeCommand
|
|
226
707
|
});
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
708
|
+
const values = Object.fromEntries(
|
|
709
|
+
readFileSync(output, "utf8").trim().split("\n").map((line) => {
|
|
710
|
+
const equal = line.indexOf("=");
|
|
711
|
+
return [line.slice(0, equal), line.slice(equal + 1)];
|
|
712
|
+
})
|
|
713
|
+
);
|
|
714
|
+
const resultPath = values["receipt"];
|
|
715
|
+
assert.ok(resultPath, "Scanner must retain its custody and cleanup result.");
|
|
716
|
+
const result = JSON.parse(readFileSync(resultPath, "utf8"));
|
|
717
|
+
const state = JSON.parse(readFileSync(statePath, "utf8"));
|
|
718
|
+
assert.deepEqual(
|
|
719
|
+
state.containers.find((value) => value.Id === unrelated),
|
|
720
|
+
initial.containers[0]
|
|
721
|
+
);
|
|
722
|
+
assert.equal(state.image, image, "Reusable pinned scanner image must remain available.");
|
|
723
|
+
assert.equal(visibleError.includes("SENSITIVE_SCANNER_FINDING"), false);
|
|
724
|
+
assert.equal(visibleError.includes(f.sensitive), false);
|
|
725
|
+
for (const command of result["commands"]) {
|
|
726
|
+
assert.ok(
|
|
727
|
+
lstatSync(command["stdoutPath"]).size + lstatSync(command["stderrPath"]).size <= 32 * 1024 * 1024
|
|
728
|
+
);
|
|
729
|
+
assert.equal(command["cleanupConfirmed"], true);
|
|
730
|
+
}
|
|
731
|
+
if (scenario === "success" || scenario === "image-pull") {
|
|
732
|
+
assert.equal(values["scanned"], "true");
|
|
733
|
+
assert.equal(host.exitCode, 0);
|
|
734
|
+
assert.deepEqual(
|
|
735
|
+
state.scannedFiles.sort(),
|
|
736
|
+
["manifest.json", "producer.stdout.txt", "producer.stderr.txt"].sort()
|
|
737
|
+
);
|
|
738
|
+
assert.equal(readFileSync(join(directory, "producer.stdout.txt"), "utf8"), receipt);
|
|
739
|
+
assert.ok(
|
|
740
|
+
failureLogUpload(directory, "success", values["scanned"]).some(
|
|
741
|
+
(file) => readFileSync(file.path, "utf8").includes(receipt)
|
|
742
|
+
)
|
|
743
|
+
);
|
|
744
|
+
} else {
|
|
745
|
+
assert.equal(values["scanned"], void 0, "Unscanned or uncertain bytes cannot become upload-eligible.");
|
|
746
|
+
assert.equal(host.exitCode, 1);
|
|
747
|
+
assert.deepEqual(failureLogUpload(directory, "failure", values["scanned"]), []);
|
|
748
|
+
}
|
|
749
|
+
const retained = state.containers.some((value) => value.Id === owned);
|
|
750
|
+
assert.equal(retained, scenario === "cleanup" || scenario === "foreign");
|
|
751
|
+
assert.equal(result["cleanupConfirmed"], !retained);
|
|
752
|
+
} finally {
|
|
753
|
+
if (timer !== void 0) clearInterval(timer);
|
|
754
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
test.each([
|
|
758
|
+
"success",
|
|
759
|
+
"image-pull",
|
|
760
|
+
"findings",
|
|
761
|
+
"overflow",
|
|
762
|
+
"cancel",
|
|
763
|
+
"resource",
|
|
764
|
+
"drift",
|
|
765
|
+
"create-ack",
|
|
766
|
+
"cleanup",
|
|
767
|
+
"foreign",
|
|
768
|
+
"extra-staged",
|
|
769
|
+
"unsafe-staged",
|
|
770
|
+
"manifest-fields",
|
|
771
|
+
"inaccessible",
|
|
772
|
+
"scan-error",
|
|
773
|
+
"directory-error",
|
|
774
|
+
"malformed-ack"
|
|
775
|
+
])(
|
|
776
|
+
"failure-log scanner gates upload and preserves unrelated resources after %s",
|
|
777
|
+
{ tags: ["release"] },
|
|
778
|
+
async (scenario) => scanFixture(scenario)
|
|
779
|
+
);
|
|
780
|
+
test.each([1110, 1114, 1122])("diagnostic frames preserve the public closure helper and caller at %s", (caller) => {
|
|
781
|
+
const f = diagnosticFixture();
|
|
782
|
+
try {
|
|
783
|
+
f.failures([
|
|
784
|
+
`AssertionError: ${f.sensitive}
|
|
785
|
+
at closure (${f.sourceRoot}/src/lifecycle.test.ts:1108:7)
|
|
786
|
+
at test (${f.sourceRoot}/src/lifecycle.test.ts:${caller}:3)`
|
|
787
|
+
]);
|
|
788
|
+
assert.deepEqual(f.frames(), {
|
|
789
|
+
status: "matched",
|
|
790
|
+
truncated: false,
|
|
791
|
+
frames: [
|
|
792
|
+
{ file: "src/lifecycle.test.ts", line: 1108, column: 7, message: 1 },
|
|
793
|
+
{ file: "src/lifecycle.test.ts", line: caller, column: 3, message: 1 }
|
|
794
|
+
]
|
|
238
795
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
796
|
+
} finally {
|
|
797
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
test("diagnostic frames preserve message order, repeats, file URLs and distinct source/dist coordinates", () => {
|
|
801
|
+
const f = diagnosticFixture();
|
|
802
|
+
try {
|
|
803
|
+
const source = pathToFileURL(join(f.sourceRoot, "src/lifecycle.test.ts")).href;
|
|
804
|
+
f.failures([
|
|
805
|
+
`${f.sensitive}
|
|
806
|
+
at privateFrame (/private/unrelated/src/lifecycle.test.ts:5:2)
|
|
807
|
+
at closure (\x1B[36m${source}:1108:7\x1B[0m)
|
|
808
|
+
at caller (${f.sourceRoot}/src/lifecycle.test.ts:1110:3)`,
|
|
809
|
+
`Error: ${f.sensitive}
|
|
810
|
+
at compiled (${f.sourceRoot}/dist/lifecycle.test.js:100:4)
|
|
811
|
+
at compiled (${f.sourceRoot}/dist/lifecycle.test.js:100:4)`
|
|
812
|
+
]);
|
|
813
|
+
assert.deepEqual(f.frames(), {
|
|
814
|
+
status: "matched",
|
|
815
|
+
truncated: false,
|
|
816
|
+
frames: [
|
|
817
|
+
{ file: "src/lifecycle.test.ts", line: 1108, column: 7, message: 1 },
|
|
818
|
+
{ file: "src/lifecycle.test.ts", line: 1110, column: 3, message: 1 },
|
|
819
|
+
{ file: "dist/lifecycle.test.js", line: 100, column: 4, message: 2 },
|
|
820
|
+
{ file: "dist/lifecycle.test.js", line: 100, column: 4, message: 2 }
|
|
821
|
+
]
|
|
822
|
+
});
|
|
823
|
+
} finally {
|
|
824
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
test.each([
|
|
828
|
+
{ GITHUB_SHA: void 0 },
|
|
829
|
+
{ GITHUB_SHA: "b".repeat(40) },
|
|
830
|
+
{ GITHUB_SHA: "invalid" },
|
|
831
|
+
{ REVIEWED_SOURCE_SHA: void 0 },
|
|
832
|
+
{ REVIEWED_SOURCE_SHA: "invalid" }
|
|
833
|
+
])("diagnostic writer refuses an unbound source before creating observations: %j", (env) => {
|
|
834
|
+
const f = diagnosticFixture();
|
|
835
|
+
try {
|
|
836
|
+
assert.throws(() => f.raw("failure", env), /Diagnostic source/u);
|
|
837
|
+
assert.equal(readFileSync(join(f.root, "output"), "utf8"), "");
|
|
838
|
+
} finally {
|
|
839
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
test("diagnostic writer and reader refuse duplicate or differently ordered source inventories", () => {
|
|
843
|
+
const f = diagnosticFixture();
|
|
844
|
+
try {
|
|
845
|
+
const inventory = laneChecks.RELEASE_CASES;
|
|
846
|
+
assert.throws(() => f.raw("failure", {}, [...inventory, inventory[0]]), /Diagnostic inventory/u);
|
|
847
|
+
const wire = f.raw();
|
|
848
|
+
assert.throws(() => decodeDiagnostic(wire, "b".repeat(40), f.sourceRoot), /Diagnostic source/u);
|
|
849
|
+
assert.throws(() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot, inventory.toReversed()));
|
|
850
|
+
assert.throws(() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot, [...inventory, inventory[0]]));
|
|
851
|
+
assert.throws(() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot, inventory.slice(1)));
|
|
852
|
+
assert.throws(
|
|
853
|
+
() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot, [
|
|
854
|
+
{ ...inventory[0], kind: "parent-launched-helper" },
|
|
855
|
+
...inventory.slice(1)
|
|
856
|
+
])
|
|
857
|
+
);
|
|
858
|
+
} finally {
|
|
859
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
test.each([
|
|
863
|
+
"encoding",
|
|
864
|
+
"extra-top",
|
|
865
|
+
"extra-release",
|
|
866
|
+
"extra-inventory",
|
|
867
|
+
"hash",
|
|
868
|
+
"count",
|
|
869
|
+
"file-count",
|
|
870
|
+
"source",
|
|
871
|
+
"duplicate",
|
|
872
|
+
"missing",
|
|
873
|
+
"order",
|
|
874
|
+
"negative",
|
|
875
|
+
"fractional",
|
|
876
|
+
"outside",
|
|
877
|
+
"extra-row",
|
|
878
|
+
"missing-row",
|
|
879
|
+
"case-status",
|
|
880
|
+
"frame-status",
|
|
881
|
+
"truncation",
|
|
882
|
+
"nonfailed-frames",
|
|
883
|
+
"file-negative",
|
|
884
|
+
"file-outside",
|
|
885
|
+
"file-fractional",
|
|
886
|
+
"line-zero",
|
|
887
|
+
"line-outside",
|
|
888
|
+
"column-zero",
|
|
889
|
+
"column-outside",
|
|
890
|
+
"message-zero",
|
|
891
|
+
"message-outside",
|
|
892
|
+
"extra-frame",
|
|
893
|
+
"missing-frame",
|
|
894
|
+
"too-many-frames",
|
|
895
|
+
"matched-empty",
|
|
896
|
+
"no-match-frames",
|
|
897
|
+
"message-order",
|
|
898
|
+
"logs-status",
|
|
899
|
+
"logs-extra",
|
|
900
|
+
"logs-path",
|
|
901
|
+
"logs-bytes",
|
|
902
|
+
"logs-duplicate"
|
|
903
|
+
])("diagnostic reader refuses malformed %s observations without guessing identities", (failure) => {
|
|
904
|
+
const f = diagnosticFixture();
|
|
905
|
+
try {
|
|
906
|
+
f.failures([` at caller (${f.sourceRoot}/src/lifecycle.test.ts:1110:3)`]);
|
|
907
|
+
const wire = f.raw();
|
|
908
|
+
const release = wire["release"];
|
|
909
|
+
const inventory = release["inventory"];
|
|
910
|
+
const rows = release["cases"];
|
|
911
|
+
const frames = rows[0][2];
|
|
912
|
+
const coordinates = frames[2];
|
|
913
|
+
if (failure === "encoding") release["caseEncoding"] = "ai-delivery.release-case-tuples@2";
|
|
914
|
+
if (failure === "extra-top") wire["extra"] = true;
|
|
915
|
+
if (failure === "extra-release") release["extra"] = true;
|
|
916
|
+
if (failure === "extra-inventory") inventory["extra"] = true;
|
|
917
|
+
if (failure === "hash") inventory["sha256"] = "b".repeat(64);
|
|
918
|
+
if (failure === "count") inventory["caseCount"] = rows.length - 1;
|
|
919
|
+
if (failure === "file-count") inventory["publicFileCount"] = 0;
|
|
920
|
+
if (failure === "source") delete wire["source"];
|
|
921
|
+
if (failure === "duplicate") rows[1] = rows[0];
|
|
922
|
+
if (failure === "missing") rows.pop();
|
|
923
|
+
if (failure === "order") rows.reverse();
|
|
924
|
+
if (failure === "negative") rows[0][0] = -1;
|
|
925
|
+
if (failure === "fractional") rows[0][0] = 0.5;
|
|
926
|
+
if (failure === "outside") rows[0][0] = rows.length;
|
|
927
|
+
if (failure === "extra-row") rows[0].push(null);
|
|
928
|
+
if (failure === "missing-row") rows[0].pop();
|
|
929
|
+
if (failure === "case-status") rows[0][1] = "invented";
|
|
930
|
+
if (failure === "frame-status") frames[0] = "invented";
|
|
931
|
+
if (failure === "truncation") frames[1] = "false";
|
|
932
|
+
if (failure === "nonfailed-frames") rows[0][1] = "passed";
|
|
933
|
+
if (failure === "file-negative") coordinates[0][0] = -1;
|
|
934
|
+
if (failure === "file-outside") coordinates[0][0] = inventory["publicFileCount"];
|
|
935
|
+
if (failure === "file-fractional") coordinates[0][0] = 0.5;
|
|
936
|
+
if (failure === "line-zero") coordinates[0][1] = 0;
|
|
937
|
+
if (failure === "line-outside") coordinates[0][1] = 1202;
|
|
938
|
+
if (failure === "column-zero") coordinates[0][2] = 0;
|
|
939
|
+
if (failure === "column-outside") coordinates[0][2] = 999;
|
|
940
|
+
if (failure === "message-zero") coordinates[0][3] = 0;
|
|
941
|
+
if (failure === "message-outside") coordinates[0][3] = 3;
|
|
942
|
+
if (failure === "extra-frame") coordinates[0].push(null);
|
|
943
|
+
if (failure === "missing-frame") coordinates[0].pop();
|
|
944
|
+
if (failure === "too-many-frames") frames[2] = Array.from({ length: 5 }, () => coordinates[0]);
|
|
945
|
+
if (failure === "matched-empty") frames[2] = [];
|
|
946
|
+
if (failure === "no-match-frames") frames[0] = "no-match";
|
|
947
|
+
if (failure === "message-order")
|
|
948
|
+
frames[2] = [
|
|
949
|
+
[...coordinates[0].slice(0, 3), 2],
|
|
950
|
+
[...coordinates[0].slice(0, 3), 1]
|
|
951
|
+
];
|
|
952
|
+
const logs = wire["logs"];
|
|
953
|
+
if (failure === "logs-status") logs["status"] = "invented";
|
|
954
|
+
if (failure === "logs-extra") logs["path"] = f.root;
|
|
955
|
+
if (failure === "logs-path") logs["files"][0]["name"] = f.root;
|
|
956
|
+
if (failure === "logs-bytes") logs["bytes"] = 64 * 1024 * 1024 + 1;
|
|
957
|
+
if (failure === "logs-duplicate") logs["files"][1] = logs["files"][0];
|
|
958
|
+
assert.throws(() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot));
|
|
959
|
+
} finally {
|
|
960
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
test.each(["link", "changed-coordinates"])("diagnostic reader refuses %s public source after projection", (failure) => {
|
|
964
|
+
const f = diagnosticFixture();
|
|
965
|
+
try {
|
|
966
|
+
const path = join(f.sourceRoot, "src/lifecycle.test.ts");
|
|
967
|
+
f.failures([` at caller (${path}:1110:3)`]);
|
|
968
|
+
const wire = f.raw();
|
|
969
|
+
if (failure === "link") {
|
|
970
|
+
rmSync(path);
|
|
971
|
+
symlinkSync(join(f.sourceRoot, "dist/lifecycle.test.js"), path);
|
|
972
|
+
} else writeFileSync(path, "// changed\n");
|
|
973
|
+
assert.throws(() => decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot));
|
|
974
|
+
} finally {
|
|
975
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
test("diagnostic tuples round-trip every identity and descriptive case status", () => {
|
|
979
|
+
const f = diagnosticFixture();
|
|
980
|
+
try {
|
|
981
|
+
const states = ["passed", "failed", "pending", "skipped", "todo", "disabled", "ambiguous", "unknown"];
|
|
982
|
+
f.save(`release-tests-${f.runId}/vitest.json`, {
|
|
983
|
+
testResults: [...new Set(laneChecks.RELEASE_CASES.map((entry) => entry.file))].map((file) => ({
|
|
984
|
+
name: join(f.sourceRoot, file),
|
|
985
|
+
assertionResults: laneChecks.RELEASE_CASES.flatMap((entry, index) => {
|
|
986
|
+
if (entry.file !== file || index >= states.length || states[index] === "unknown") return [];
|
|
987
|
+
const value = { fullName: entry.title, status: states[index], failureMessages: ["no public frames"] };
|
|
988
|
+
return states[index] === "ambiguous" ? [value, value] : [value];
|
|
989
|
+
})
|
|
990
|
+
}))
|
|
991
|
+
});
|
|
992
|
+
const wire = f.raw();
|
|
993
|
+
const decoded = decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot);
|
|
994
|
+
const observed = decoded["release"]["cases"];
|
|
995
|
+
assert.deepEqual(
|
|
996
|
+
observed.slice(0, states.length).map((entry) => entry["status"]),
|
|
997
|
+
states
|
|
998
|
+
);
|
|
999
|
+
assert.deepEqual(
|
|
1000
|
+
observed.map(({ file, title }) => ({ file, title })),
|
|
1001
|
+
laneChecks.RELEASE_CASES.map(({ file, title }) => ({ file, title }))
|
|
1002
|
+
);
|
|
1003
|
+
assert.deepEqual(observed[1]["failureFrames"], { status: "no-match", truncated: false, frames: [] });
|
|
1004
|
+
assert.throws(() => JSON.parse(JSON.stringify(wire).slice(0, -5)));
|
|
1005
|
+
} finally {
|
|
1006
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
test("diagnostics retain the complete release inventory with four seven-digit frames per case under64KiB", () => {
|
|
1010
|
+
const f = diagnosticFixture();
|
|
1011
|
+
try {
|
|
1012
|
+
const publicFiles = [
|
|
1013
|
+
...new Set(
|
|
1014
|
+
laneChecks.RELEASE_CASES.flatMap(({ file }) => [
|
|
1015
|
+
file,
|
|
1016
|
+
file.replace(/^dist\//u, "src/").replace(/\.js$/u, ".ts")
|
|
1017
|
+
])
|
|
1018
|
+
)
|
|
1019
|
+
];
|
|
1020
|
+
const publicFile = publicFiles.at(-1);
|
|
1021
|
+
writeFileSync(join(f.sourceRoot, publicFile), "\n".repeat(1e6) + "x".repeat(1e6));
|
|
1022
|
+
const command = {
|
|
1023
|
+
status: "incomplete",
|
|
1024
|
+
exitCode: -255,
|
|
1025
|
+
signal: "SIGTERM",
|
|
1026
|
+
cleanupConfirmed: false,
|
|
1027
|
+
outputBytes: Number.MAX_SAFE_INTEGER,
|
|
1028
|
+
peakRssBytes: Number.MAX_SAFE_INTEGER
|
|
275
1029
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
1030
|
+
f.save("result.json", {
|
|
1031
|
+
schemaVersion: "ai-delivery.current-qualification@1",
|
|
1032
|
+
runId: f.runId,
|
|
1033
|
+
status: "incomplete",
|
|
1034
|
+
pack: command
|
|
1035
|
+
});
|
|
1036
|
+
f.save("producer/result.json", {
|
|
1037
|
+
status: "incomplete",
|
|
1038
|
+
fullSuccess: false,
|
|
1039
|
+
commands: gates.map((stage) => ({ stage, ...command }))
|
|
1040
|
+
});
|
|
1041
|
+
f.save(`release-tests-${f.runId}/result.json`, {
|
|
1042
|
+
status: "incomplete",
|
|
1043
|
+
commands: [command],
|
|
1044
|
+
release: { temporary: { removed: false, quiescent: false } }
|
|
1045
|
+
});
|
|
1046
|
+
const consumerDirectory = join(f.qualificationRoot, `consumer-${f.runId}`);
|
|
1047
|
+
f.save("consumer-attempt.json", {
|
|
1048
|
+
runId: f.runId,
|
|
1049
|
+
directory: consumerDirectory,
|
|
1050
|
+
consumerPath: join(consumerDirectory, "result.json"),
|
|
1051
|
+
command
|
|
1052
|
+
});
|
|
1053
|
+
f.save(`consumer-${f.runId}/result.json`, { status: "incomplete", cleanup: { removed: false, quiescent: false } });
|
|
1054
|
+
const logBytes = "x".repeat(16 * 1024 * 1024);
|
|
1055
|
+
for (const directory of ["producer", `release-tests-${f.runId}`])
|
|
1056
|
+
for (const stream of ["stdout", "stderr"]) f.log(`${directory}/tests/${stream}.txt`, logBytes);
|
|
1057
|
+
f.save(`release-tests-${f.runId}/vitest.json`, {
|
|
1058
|
+
numTotalTests: Number.MAX_SAFE_INTEGER,
|
|
1059
|
+
numPassedTests: Number.MAX_SAFE_INTEGER,
|
|
1060
|
+
numFailedTests: Number.MAX_SAFE_INTEGER,
|
|
1061
|
+
testResults: [...new Set(laneChecks.RELEASE_CASES.map((entry) => entry.file))].map((file) => ({
|
|
1062
|
+
name: join(f.sourceRoot, file),
|
|
1063
|
+
assertionResults: laneChecks.RELEASE_CASES.filter((entry) => entry.file === file).map(({ title }) => ({
|
|
1064
|
+
fullName: title,
|
|
1065
|
+
status: "failed",
|
|
1066
|
+
failureMessages: [
|
|
1067
|
+
null,
|
|
1068
|
+
Array.from({ length: 4 }, () => ` at caller (${join(f.sourceRoot, publicFile)}:1000001:1000001)`).join(
|
|
1069
|
+
"\n"
|
|
1070
|
+
)
|
|
1071
|
+
]
|
|
1072
|
+
}))
|
|
1073
|
+
}))
|
|
1074
|
+
});
|
|
1075
|
+
const wire = f.raw("cancelled", {
|
|
1076
|
+
GITHUB_RUN_ID: String(Number.MAX_SAFE_INTEGER),
|
|
1077
|
+
GITHUB_RUN_ATTEMPT: String(Number.MAX_SAFE_INTEGER)
|
|
1078
|
+
});
|
|
1079
|
+
const bytes = Buffer.byteLength(JSON.stringify(wire) + "\n");
|
|
1080
|
+
assert.ok(bytes <= 64 * 1024);
|
|
1081
|
+
process.stdout.write(
|
|
1082
|
+
`DIAGNOSTIC_FIXED_BOUND ${JSON.stringify({ cases: laneChecks.RELEASE_CASES.length, frames: laneChecks.RELEASE_CASES.length * 4, bytes, bound: 64 * 1024 })}
|
|
1083
|
+
`
|
|
1084
|
+
);
|
|
1085
|
+
const observed = decodeDiagnostic(wire, "a".repeat(40), f.sourceRoot)["release"]["cases"];
|
|
1086
|
+
assert.equal(observed.length, laneChecks.RELEASE_CASES.length);
|
|
1087
|
+
for (const entry of observed) {
|
|
1088
|
+
assert.equal(entry["status"], "failed");
|
|
1089
|
+
const frames = entry["failureFrames"];
|
|
1090
|
+
assert.equal(frames["status"], "unknown");
|
|
1091
|
+
assert.equal(frames["truncated"], false);
|
|
1092
|
+
assert.deepEqual(
|
|
1093
|
+
frames["frames"],
|
|
1094
|
+
Array.from({ length: 4 }, () => ({ file: publicFile, line: 1000001, column: 1000001, message: 2 }))
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
} finally {
|
|
1098
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
test.each([
|
|
1102
|
+
{ messages: void 0, status: "unknown" },
|
|
1103
|
+
{ messages: null, status: "unknown" },
|
|
1104
|
+
{ messages: {}, status: "unknown" },
|
|
1105
|
+
{ messages: [], status: "unknown" },
|
|
1106
|
+
{ messages: [null], status: "unknown" },
|
|
1107
|
+
{ messages: [""], status: "no-match" },
|
|
1108
|
+
{ messages: ["an error without public frames"], status: "no-match" }
|
|
1109
|
+
])(
|
|
1110
|
+
"diagnostic frame availability distinguishes $status from test-declaration coordinates: $messages",
|
|
1111
|
+
({ messages, status }) => {
|
|
1112
|
+
const f = diagnosticFixture();
|
|
279
1113
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
assert.equal(bundle.records['overall']?.contents, readFileSync(join(f.results, 'result.json'), 'utf8'));
|
|
285
|
-
assert.equal(bundle.archive.sha256, f.inputs.digest);
|
|
286
|
-
assert.equal(execFileSync('git', ['status', '--porcelain'], { cwd: f.source, encoding: 'utf8' }), '');
|
|
287
|
-
assert.throws(() => api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source));
|
|
1114
|
+
f.failures(messages);
|
|
1115
|
+
assert.deepEqual(f.frames(), { status, truncated: false, frames: [] });
|
|
1116
|
+
} finally {
|
|
1117
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
288
1118
|
}
|
|
289
|
-
|
|
290
|
-
|
|
1119
|
+
}
|
|
1120
|
+
);
|
|
1121
|
+
test.each(["frames", "messages", "text", "lines", "line-bytes", "partial-line", "utf8-text"])(
|
|
1122
|
+
"diagnostic frames retain a bounded prefix and disclose %s truncation",
|
|
1123
|
+
(bound) => {
|
|
1124
|
+
const f = diagnosticFixture();
|
|
1125
|
+
try {
|
|
1126
|
+
const helper = ` at closure (${f.sourceRoot}/src/lifecycle.test.ts:1108:7)`;
|
|
1127
|
+
const caller = ` at caller (${f.sourceRoot}/src/lifecycle.test.ts:1110:3)`;
|
|
1128
|
+
let messages = [helper + "\n" + caller];
|
|
1129
|
+
let expected = [{ file: "src/lifecycle.test.ts", line: 1108, column: 7, message: 1 }];
|
|
1130
|
+
if (bound === "frames") {
|
|
1131
|
+
messages = [Array.from({ length: 5 }, () => helper).join("\n")];
|
|
1132
|
+
expected = Array.from({ length: 4 }, () => expected[0]);
|
|
1133
|
+
}
|
|
1134
|
+
if (bound === "messages") {
|
|
1135
|
+
messages = [helper, helper, helper];
|
|
1136
|
+
expected = [expected[0], { ...expected[0], message: 2 }];
|
|
1137
|
+
}
|
|
1138
|
+
if (bound === "text") messages = [helper + "\n" + "x".repeat(16 * 1024) + "\n" + caller];
|
|
1139
|
+
if (bound === "lines") messages = [helper + "\n" + "header\n".repeat(63) + caller];
|
|
1140
|
+
if (bound === "line-bytes") messages = [helper + "\n" + " ".repeat(2048) + caller];
|
|
1141
|
+
if (bound === "partial-line" || bound === "utf8-text") {
|
|
1142
|
+
messages = [(bound === "partial-line" ? " ".repeat(16370) : "\xE9".repeat(8190)) + caller];
|
|
1143
|
+
expected = [];
|
|
1144
|
+
}
|
|
1145
|
+
f.failures(messages);
|
|
1146
|
+
assert.deepEqual(f.frames(), {
|
|
1147
|
+
status: expected.length ? "matched" : "unknown",
|
|
1148
|
+
truncated: true,
|
|
1149
|
+
frames: expected
|
|
1150
|
+
});
|
|
1151
|
+
} finally {
|
|
1152
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
);
|
|
1156
|
+
test.each(["private-suffix", "path-traversal", "file-query", "file-host", "function-body"])(
|
|
1157
|
+
"diagnostic frames reject %s near-matches without exposing their bytes",
|
|
1158
|
+
(kind) => {
|
|
1159
|
+
const f = diagnosticFixture();
|
|
1160
|
+
try {
|
|
1161
|
+
const file = join(f.sourceRoot, "src/lifecycle.test.ts");
|
|
1162
|
+
let frame = ` at fake (/private${file}:1108:7)`;
|
|
1163
|
+
if (kind === "path-traversal") frame = ` at fake (${f.sourceRoot}/src/../src/lifecycle.test.ts:1108:7)`;
|
|
1164
|
+
if (kind === "file-query") frame = ` at fake (${pathToFileURL(file).href}?${f.sensitive}:1108:7)`;
|
|
1165
|
+
if (kind === "file-host") frame = ` at fake (file://unrelated${file}:1108:7)`;
|
|
1166
|
+
if (kind === "function-body") frame = `Error: (not a frame ${file}:1108:7)`;
|
|
1167
|
+
f.failures([frame]);
|
|
1168
|
+
assert.deepEqual(f.frames(), { status: "no-match", truncated: false, frames: [] });
|
|
1169
|
+
} finally {
|
|
1170
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
);
|
|
1174
|
+
test.each(["0:1", "-1:1", "1202:1", "1:999", "999999999999999999:1"])(
|
|
1175
|
+
"diagnostic frames keep invalid public coordinates %s unknown",
|
|
1176
|
+
(coordinates) => {
|
|
1177
|
+
const f = diagnosticFixture();
|
|
1178
|
+
try {
|
|
1179
|
+
f.failures([` at closure (${f.sourceRoot}/src/lifecycle.test.ts:${coordinates})`]);
|
|
1180
|
+
assert.deepEqual(f.frames(), { status: "unknown", truncated: false, frames: [] });
|
|
1181
|
+
} finally {
|
|
1182
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
291
1183
|
}
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1186
|
+
test("diagnostic frames do not follow public-code symlinks or claim malformed messages are complete", () => {
|
|
1187
|
+
const f = diagnosticFixture();
|
|
1188
|
+
try {
|
|
1189
|
+
const file = join(f.sourceRoot, "src/lifecycle.test.ts");
|
|
1190
|
+
rmSync(file);
|
|
1191
|
+
symlinkSync(join(f.sourceRoot, "dist/lifecycle.test.js"), file);
|
|
1192
|
+
f.failures([` at closure (${file}:1108:7)`]);
|
|
1193
|
+
assert.deepEqual(f.frames(), { status: "unknown", truncated: false, frames: [] });
|
|
1194
|
+
f.failures([null, ` at compiled (${f.sourceRoot}/dist/lifecycle.test.js:100:4)`]);
|
|
1195
|
+
assert.deepEqual(f.frames(), {
|
|
1196
|
+
status: "unknown",
|
|
1197
|
+
truncated: false,
|
|
1198
|
+
frames: [{ file: "dist/lifecycle.test.js", line: 100, column: 4, message: 2 }]
|
|
1199
|
+
});
|
|
1200
|
+
f.failures([` at compiled (${f.sourceRoot}/dist/lifecycle.test.js:100:4)`], "passed");
|
|
1201
|
+
assert.equal(f.frames(), void 0);
|
|
1202
|
+
} finally {
|
|
1203
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1204
|
+
}
|
|
292
1205
|
});
|
|
1206
|
+
test("failed qualification diagnostics have an isolated nonpromotable workflow boundary", () => {
|
|
1207
|
+
const prepare = diagnosticStep("Prepare failed qualification diagnostics");
|
|
1208
|
+
const upload = diagnosticStep("Upload failed qualification diagnostics");
|
|
1209
|
+
assert.match(prepare, /always\(\) && inputs\.qualification_only && steps\.origin\.outcome == 'success'/u);
|
|
1210
|
+
assert.match(
|
|
1211
|
+
prepare,
|
|
1212
|
+
/steps\.qualification\.outcome == 'failure' \|\| steps\.qualification\.outcome == 'cancelled'/u
|
|
1213
|
+
);
|
|
1214
|
+
assert.match(upload, /always\(\) && inputs\.qualification_only && steps\.diagnostics\.outcome == 'success'/u);
|
|
1215
|
+
assert.match(upload, /name: npm-qualification-diagnostics-\$\{\{ github\.run_attempt \}\}/u);
|
|
1216
|
+
assert.match(upload, /path: \$\{\{ steps\.diagnostics\.outputs\.file \}\}/u);
|
|
1217
|
+
assert.match(upload, /retention-days: 1/u);
|
|
1218
|
+
assert.match(upload, /if-no-files-found: error/u);
|
|
1219
|
+
assert.match(upload, /actions\/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a/u);
|
|
1220
|
+
assert.doesNotMatch(prepare + upload, /continue-on-error|overwrite:|id-token:|npm run|npm pack/u);
|
|
1221
|
+
const fixture2 = originFixture();
|
|
1222
|
+
fixture2.metadata.artifact["name"] = "npm-qualification-diagnostics-2";
|
|
1223
|
+
assert.throws(() => api.validateQualificationOrigin(fixture2.metadata, fixture2.inputs));
|
|
1224
|
+
fixture2.metadata.artifact["name"] = "npm-qualification-failure-logs-2";
|
|
1225
|
+
assert.throws(() => api.validateQualificationOrigin(fixture2.metadata, fixture2.inputs));
|
|
1226
|
+
});
|
|
1227
|
+
test.each(["failure", "cancelled"])(
|
|
1228
|
+
"diagnostics project bounded observations after %s without exposing raw evidence",
|
|
1229
|
+
(outcome) => {
|
|
1230
|
+
const f = diagnosticFixture();
|
|
1231
|
+
try {
|
|
1232
|
+
symlinkSync(process.cwd(), join(f.releaseDirectory, "temporary", "linked-source"));
|
|
1233
|
+
const observed = f.execute(outcome);
|
|
1234
|
+
assert.equal(observed["observationOnly"], true);
|
|
1235
|
+
assert.equal(observed["qualified"], false);
|
|
1236
|
+
assert.equal(observed["promotionEligible"], false);
|
|
1237
|
+
assert.equal(observed["qualificationOutcome"], outcome);
|
|
1238
|
+
const release = observed["release"];
|
|
1239
|
+
assert.equal(release["status"], "failed");
|
|
1240
|
+
assert.deepEqual(release["cleanup"], { removed: false, quiescent: true });
|
|
1241
|
+
const cases = release["cases"];
|
|
1242
|
+
assert.equal(cases.length, laneChecks.RELEASE_CASES.length);
|
|
1243
|
+
assert.equal(cases[0]["status"], "failed");
|
|
1244
|
+
assert.equal(cases[1]["status"], "unknown");
|
|
1245
|
+
assert.deepEqual(observed["consumer"]["cleanup"], { removed: false, quiescent: false });
|
|
1246
|
+
} finally {
|
|
1247
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
);
|
|
293
1251
|
test.each([
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
1252
|
+
"missing",
|
|
1253
|
+
"malformed",
|
|
1254
|
+
"oversized",
|
|
1255
|
+
"leaf-link",
|
|
1256
|
+
"parent-link",
|
|
1257
|
+
"root-link",
|
|
1258
|
+
"redirect",
|
|
1259
|
+
"wrong-run",
|
|
1260
|
+
"malformed-run",
|
|
1261
|
+
"duplicate",
|
|
1262
|
+
"unknown-fields"
|
|
1263
|
+
])("diagnostics preserve missing or unsafe %s evidence as unknown", (failure) => {
|
|
1264
|
+
const f = diagnosticFixture();
|
|
1265
|
+
try {
|
|
1266
|
+
const receipt = join(f.releaseDirectory, "result.json");
|
|
1267
|
+
if (failure === "missing") rmSync(receipt);
|
|
1268
|
+
if (failure === "malformed") writeFileSync(receipt, "{");
|
|
1269
|
+
if (failure === "malformed-run")
|
|
1270
|
+
f.save("result.json", { schemaVersion: "ai-delivery.current-qualification@1", runId: { toString: null } });
|
|
1271
|
+
if (failure === "oversized") writeFileSync(receipt, "x".repeat(4 * 1024 * 1024 + 1));
|
|
1272
|
+
if (failure === "leaf-link") {
|
|
1273
|
+
rmSync(receipt);
|
|
1274
|
+
symlinkSync(join(f.qualificationRoot, "result.json"), receipt);
|
|
1275
|
+
}
|
|
1276
|
+
if (failure === "parent-link") {
|
|
1277
|
+
rmSync(f.releaseDirectory, { recursive: true });
|
|
1278
|
+
symlinkSync(join(f.qualificationRoot, "producer"), f.releaseDirectory);
|
|
1279
|
+
}
|
|
1280
|
+
if (failure === "root-link") {
|
|
1281
|
+
const retained = join(f.root, "retained");
|
|
1282
|
+
mkdirSync(retained);
|
|
1283
|
+
rmSync(f.qualificationRoot, { recursive: true });
|
|
1284
|
+
symlinkSync(retained, f.qualificationRoot);
|
|
1285
|
+
}
|
|
1286
|
+
if (failure === "redirect" || failure === "wrong-run")
|
|
1287
|
+
f.save("release-tests-attempt.json", {
|
|
1288
|
+
stage: "release-tests",
|
|
1289
|
+
runId: failure === "wrong-run" ? "22222222-2222-4222-8222-222222222222" : f.runId,
|
|
1290
|
+
status: "completed",
|
|
1291
|
+
directory: failure === "redirect" ? f.root : f.releaseDirectory,
|
|
1292
|
+
resultPath: receipt
|
|
1293
|
+
});
|
|
1294
|
+
if (failure === "duplicate") {
|
|
1295
|
+
const entry = laneChecks.RELEASE_CASES[0];
|
|
1296
|
+
f.save(`release-tests-${f.runId}/vitest.json`, {
|
|
1297
|
+
testResults: [
|
|
1298
|
+
{
|
|
1299
|
+
name: join(f.sourceRoot, entry.file),
|
|
1300
|
+
assertionResults: [1, 2].map(() => ({ fullName: entry.title, status: "passed" }))
|
|
1301
|
+
}
|
|
1302
|
+
]
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
if (failure === "unknown-fields")
|
|
1306
|
+
f.save(`release-tests-${f.runId}/result.json`, {
|
|
1307
|
+
status: f.sensitive,
|
|
1308
|
+
release: { temporary: { removed: f.sensitive, quiescent: f.sensitive } },
|
|
1309
|
+
commands: [{ signal: f.sensitive, error: f.sensitive }]
|
|
1310
|
+
});
|
|
1311
|
+
const observed = f.execute();
|
|
1312
|
+
const release = observed["release"];
|
|
1313
|
+
if (failure === "duplicate") assert.equal(release["cases"][0]["status"], "ambiguous");
|
|
1314
|
+
else {
|
|
1315
|
+
assert.equal(release["status"], "unknown");
|
|
1316
|
+
assert.deepEqual(release["cleanup"], { removed: null, quiescent: null });
|
|
1317
|
+
}
|
|
1318
|
+
assert.equal(observed["qualified"], false);
|
|
1319
|
+
assert.equal(observed["promotionEligible"], false);
|
|
1320
|
+
} finally {
|
|
1321
|
+
rmSync(f.root, { recursive: true, force: true });
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
test("qualification without a digest cannot enter publication", () => {
|
|
1325
|
+
assert.equal(typeof api.releaseDispatch, "function");
|
|
1326
|
+
const inputs = { source: "a".repeat(40), version: "0.3.35", digest: "", qualificationOnly: "true", artifactId: "" };
|
|
1327
|
+
assert.deepEqual(api.releaseDispatch(inputs), {
|
|
1328
|
+
source: inputs.source,
|
|
1329
|
+
version: inputs.version,
|
|
1330
|
+
qualificationOnly: true
|
|
1331
|
+
});
|
|
1332
|
+
assert.throws(() => api.releaseDispatch({ ...inputs, qualificationOnly: "false" }));
|
|
1333
|
+
});
|
|
1334
|
+
test("accepted artifact dispatch requires the complete external tuple", () => {
|
|
1335
|
+
assert.equal(typeof api.releaseDispatch, "function");
|
|
1336
|
+
const inputs = {
|
|
1337
|
+
source: "a".repeat(40),
|
|
1338
|
+
version: "0.3.35",
|
|
1339
|
+
digest: "b".repeat(64),
|
|
1340
|
+
qualificationOnly: "false",
|
|
1341
|
+
artifactId: "42"
|
|
1342
|
+
};
|
|
1343
|
+
assert.deepEqual(api.releaseDispatch(inputs), {
|
|
1344
|
+
source: inputs.source,
|
|
1345
|
+
version: inputs.version,
|
|
1346
|
+
digest: inputs.digest,
|
|
1347
|
+
qualificationOnly: false,
|
|
1348
|
+
artifactId: 42
|
|
1349
|
+
});
|
|
1350
|
+
});
|
|
1351
|
+
test.each([
|
|
1352
|
+
"unknown-mode",
|
|
1353
|
+
"empty-mode",
|
|
1354
|
+
"missing-source",
|
|
1355
|
+
"missing-digest",
|
|
1356
|
+
"dummy-digest",
|
|
1357
|
+
"missing-id",
|
|
1358
|
+
"multiple-ids",
|
|
1359
|
+
"zero-id",
|
|
1360
|
+
"leading-zero-id",
|
|
1361
|
+
"unsafe-id",
|
|
1362
|
+
"qualification-digest",
|
|
1363
|
+
"qualification-id"
|
|
1364
|
+
])("release dispatch refuses %s before costly commands", (failure) => {
|
|
1365
|
+
assert.equal(typeof api.releaseDispatch, "function");
|
|
1366
|
+
const inputs = {
|
|
1367
|
+
source: "a".repeat(40),
|
|
1368
|
+
version: "0.3.35",
|
|
1369
|
+
digest: "b".repeat(64),
|
|
1370
|
+
qualificationOnly: "false",
|
|
1371
|
+
artifactId: "42"
|
|
1372
|
+
};
|
|
1373
|
+
if (failure === "unknown-mode") inputs.qualificationOnly = "automatic";
|
|
1374
|
+
if (failure === "empty-mode") inputs.qualificationOnly = "";
|
|
1375
|
+
if (failure === "missing-source") inputs.source = "";
|
|
1376
|
+
if (failure === "missing-digest") inputs.digest = "";
|
|
1377
|
+
if (failure === "dummy-digest") inputs.digest = "dummy";
|
|
1378
|
+
if (failure === "missing-id") inputs.artifactId = "";
|
|
1379
|
+
if (failure === "multiple-ids") inputs.artifactId = "42,43";
|
|
1380
|
+
if (failure === "zero-id") inputs.artifactId = "0";
|
|
1381
|
+
if (failure === "leading-zero-id") inputs.artifactId = "042";
|
|
1382
|
+
if (failure === "unsafe-id") inputs.artifactId = "9007199254740992";
|
|
1383
|
+
if (failure === "qualification-digest") {
|
|
1384
|
+
inputs.qualificationOnly = "true";
|
|
1385
|
+
inputs.artifactId = "";
|
|
1386
|
+
}
|
|
1387
|
+
if (failure === "qualification-id") {
|
|
1388
|
+
inputs.qualificationOnly = "true";
|
|
1389
|
+
inputs.digest = "";
|
|
1390
|
+
}
|
|
1391
|
+
assert.throws(() => api.releaseDispatch(inputs));
|
|
1392
|
+
});
|
|
1393
|
+
function originFixture() {
|
|
1394
|
+
const source = "a".repeat(40);
|
|
1395
|
+
const repository = "aviaratech/ai-delivery";
|
|
1396
|
+
const repo = { id: 123, full_name: repository };
|
|
1397
|
+
const artifact = {
|
|
1398
|
+
id: 42,
|
|
1399
|
+
name: "npm-qualified-2",
|
|
1400
|
+
expired: false,
|
|
1401
|
+
expires_at: "2099-01-01T00:00:00Z",
|
|
1402
|
+
workflow_run: { id: 101, repository_id: 123, head_repository_id: 123, head_branch: "main", head_sha: source }
|
|
1403
|
+
};
|
|
1404
|
+
const attempt = {
|
|
1405
|
+
id: 101,
|
|
1406
|
+
run_attempt: 2,
|
|
1407
|
+
event: "workflow_dispatch",
|
|
1408
|
+
head_branch: "main",
|
|
1409
|
+
head_sha: source,
|
|
1410
|
+
status: "completed",
|
|
1411
|
+
conclusion: "success",
|
|
1412
|
+
workflow_id: 201,
|
|
1413
|
+
repository: repo,
|
|
1414
|
+
head_repository: repo
|
|
1415
|
+
};
|
|
1416
|
+
const workflow = { id: 201, path: ".github/workflows/release.yml", state: "active" };
|
|
1417
|
+
const jobs = {
|
|
1418
|
+
total_count: 1,
|
|
1419
|
+
jobs: [
|
|
1420
|
+
{
|
|
1421
|
+
run_id: 101,
|
|
1422
|
+
run_attempt: 2,
|
|
1423
|
+
head_sha: source,
|
|
1424
|
+
name: "package",
|
|
1425
|
+
status: "completed",
|
|
1426
|
+
conclusion: "success",
|
|
1427
|
+
steps: ["Qualify and retain the exact archive", "Scan source history", "Upload qualified package"].map(
|
|
1428
|
+
(name) => ({ name, status: "completed", conclusion: "success" })
|
|
1429
|
+
)
|
|
1430
|
+
}
|
|
1431
|
+
]
|
|
1432
|
+
};
|
|
1433
|
+
return {
|
|
1434
|
+
metadata: { artifact, attempt, workflow, jobs },
|
|
1435
|
+
inputs: { repository, repositoryId: 123, source, artifactId: 42 }
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
async function runOriginWorkflow(qualificationOnly, inputs, failure) {
|
|
1439
|
+
const workflow = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8");
|
|
1440
|
+
const script = /node --input-type=module <<'JS'\n([\s\S]*?)\n\s+JS/u.exec(workflow)?.[1];
|
|
1441
|
+
assert.ok(script);
|
|
1442
|
+
const program = script.replace(/^\s*import .+;\n/gmu, "");
|
|
1443
|
+
const f = originFixture();
|
|
1444
|
+
f.metadata.artifact["workflow_run"]["head_sha"] = inputs.source;
|
|
1445
|
+
f.metadata.attempt["head_sha"] = inputs.source;
|
|
1446
|
+
f.metadata.jobs["jobs"][0]["head_sha"] = inputs.source;
|
|
1447
|
+
const prefix = "https://api.github.com/repos/aviaratech/ai-delivery/";
|
|
1448
|
+
const responses = {
|
|
1449
|
+
"branches/main": {
|
|
1450
|
+
name: "main",
|
|
1451
|
+
protected: true,
|
|
1452
|
+
commit: { sha: failure === "main" ? "b".repeat(40) : inputs.source },
|
|
1453
|
+
protection: { required_status_checks: { enforcement_level: "everyone", contexts: ["checks", "secrets"] } }
|
|
1454
|
+
},
|
|
1455
|
+
"actions/artifacts/42": f.metadata.artifact,
|
|
1456
|
+
"actions/runs/101/attempts/2": f.metadata.attempt,
|
|
1457
|
+
"actions/workflows/release.yml": f.metadata.workflow,
|
|
1458
|
+
"actions/runs/101/attempts/2/jobs?per_page=100": f.metadata.jobs
|
|
1459
|
+
};
|
|
1460
|
+
const commands = [];
|
|
1461
|
+
const requests = [];
|
|
1462
|
+
let output = "";
|
|
1463
|
+
const context = {
|
|
1464
|
+
pkg: {
|
|
1465
|
+
name: "@aviaratech/ai-delivery",
|
|
1466
|
+
version: inputs.version,
|
|
1467
|
+
private: false,
|
|
1468
|
+
license: "MIT",
|
|
1469
|
+
repository: { url: "git+https://github.com/aviaratech/ai-delivery.git" }
|
|
1470
|
+
},
|
|
1471
|
+
process: {
|
|
1472
|
+
env: {
|
|
1473
|
+
GITHUB_SHA: inputs.source,
|
|
1474
|
+
GITHUB_REPOSITORY: "aviaratech/ai-delivery",
|
|
1475
|
+
GITHUB_REPOSITORY_ID: "123",
|
|
1476
|
+
REVIEWED_SOURCE_SHA: inputs.source,
|
|
1477
|
+
RELEASE_VERSION: inputs.version,
|
|
1478
|
+
REVIEWED_ARCHIVE_SHA256: qualificationOnly ? "" : inputs.digest,
|
|
1479
|
+
QUALIFICATION_ONLY: String(qualificationOnly),
|
|
1480
|
+
QUALIFICATION_ARTIFACT_ID: qualificationOnly ? "" : "42",
|
|
1481
|
+
GITHUB_OUTPUT: "/synthetic/output",
|
|
1482
|
+
GH_TOKEN: "synthetic"
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
execFileSync: (command, args) => {
|
|
1486
|
+
commands.push({ command, args: Array.from(args) });
|
|
1487
|
+
assert.equal(command, "git");
|
|
1488
|
+
assert.deepEqual(Array.from(args), ["rev-parse", "HEAD"]);
|
|
1489
|
+
return inputs.source + "\n";
|
|
1490
|
+
},
|
|
1491
|
+
appendFileSync: (path, contents) => {
|
|
1492
|
+
assert.equal(path, "/synthetic/output");
|
|
1493
|
+
output += contents;
|
|
1494
|
+
},
|
|
1495
|
+
fetch: (url, options) => {
|
|
1496
|
+
requests.push(url);
|
|
1497
|
+
assert.equal(options.method ?? "GET", "GET");
|
|
1498
|
+
assert.equal(options.redirect, "error");
|
|
1499
|
+
assert.equal(options.headers["Authorization"], "Bearer synthetic");
|
|
1500
|
+
if (failure === "network") return Promise.reject(new Error("Synthetic request failure"));
|
|
1501
|
+
if (failure === "oversized") return Promise.resolve(new Response("x".repeat(4 * 1024 * 1024 + 1)));
|
|
1502
|
+
assert.ok(url.startsWith(prefix));
|
|
1503
|
+
const response = responses[url.slice(prefix.length)];
|
|
1504
|
+
assert.ok(response, "No latest/by-name/fallback endpoint is permitted.");
|
|
1505
|
+
return Promise.resolve(Response.json(response));
|
|
1506
|
+
},
|
|
1507
|
+
releaseDispatch: api.releaseDispatch,
|
|
1508
|
+
validateQualificationOrigin: api.validateQualificationOrigin,
|
|
1509
|
+
Buffer,
|
|
1510
|
+
AbortSignal
|
|
1511
|
+
};
|
|
1512
|
+
let error = null;
|
|
1513
|
+
try {
|
|
1514
|
+
await new Script(`(async () => {${program}
|
|
1515
|
+
})()`).runInNewContext(context);
|
|
1516
|
+
} catch (failure2) {
|
|
1517
|
+
error = String(failure2);
|
|
1518
|
+
}
|
|
1519
|
+
return { error, commands, requests, output };
|
|
1520
|
+
}
|
|
1521
|
+
test("actual qualification entry observes only protected source before any archive exists", async () => {
|
|
1522
|
+
const result = await runOriginWorkflow(true, { source: "a".repeat(40), version: "0.3.35", digest: "" });
|
|
1523
|
+
assert.equal(result.error, null);
|
|
1524
|
+
assert.deepEqual(result.commands, [{ command: "git", args: ["rev-parse", "HEAD"] }]);
|
|
1525
|
+
assert.deepEqual(result.requests, ["https://api.github.com/repos/aviaratech/ai-delivery/branches/main"]);
|
|
1526
|
+
assert.equal(result.output, "");
|
|
1527
|
+
});
|
|
1528
|
+
test("accepted artifact promotion executes no qualification graph", async () => {
|
|
1529
|
+
const f = fixture();
|
|
1530
|
+
try {
|
|
1531
|
+
api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source);
|
|
1532
|
+
writeFileSync(join(f.output, "SHA256SUMS"), `${f.inputs.digest} ${basename(f.archivePath)}
|
|
1533
|
+
`);
|
|
1534
|
+
const result = await runOriginWorkflow(false, f.inputs);
|
|
1535
|
+
assert.equal(result.error, null);
|
|
1536
|
+
assert.equal(result.output, "run_id=101\nrun_attempt=2\nartifact_id=42\n");
|
|
1537
|
+
assert.equal(result.requests.length, 5);
|
|
1538
|
+
assert.deepEqual(result.commands, [{ command: "git", args: ["rev-parse", "HEAD"] }]);
|
|
1539
|
+
const workflow = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8");
|
|
1540
|
+
const step = workflow.split(/(?=^ {6}- )/mu).find((step2) => step2.includes("name: Verify accepted original archive\n"));
|
|
1541
|
+
assert.ok(step);
|
|
1542
|
+
assert.match(step, /if: \$\{\{ !inputs\.qualification_only \}\}/u);
|
|
1543
|
+
const script = step.split(" run: |\n")[1]?.split("\n").map((line) => line.replace(/^ {10}/u, "")).join("\n");
|
|
1544
|
+
assert.ok(script);
|
|
1545
|
+
const trace = execFileSync("/bin/bash", ["-ex", "-c", "exec 2>&1\n" + script], {
|
|
1546
|
+
cwd: realpathSync(new URL("..", import.meta.url)),
|
|
1547
|
+
env: {
|
|
1548
|
+
...process.env,
|
|
1549
|
+
RUNNER_TEMP: f.directory,
|
|
1550
|
+
REVIEWED_SOURCE_SHA: f.inputs.source,
|
|
1551
|
+
RELEASE_VERSION: f.inputs.version,
|
|
1552
|
+
REVIEWED_ARCHIVE_SHA256: f.inputs.digest
|
|
1553
|
+
},
|
|
1554
|
+
encoding: "utf8"
|
|
1555
|
+
});
|
|
1556
|
+
assert.match(trace, /node scripts\/release-artifact\.mjs verify/u);
|
|
1557
|
+
assert.match(trace, /shasum -a 256 -c SHA256SUMS/u);
|
|
1558
|
+
assert.doesNotMatch(trace, /npm ci|npm run|npm pack|current-qualification|current-consumer/u);
|
|
1559
|
+
} finally {
|
|
1560
|
+
f.cleanup();
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
test.each(["main", "network", "oversized"])(
|
|
1564
|
+
"actual origin entry refuses %s readback without fallback commands",
|
|
1565
|
+
async (failure) => {
|
|
1566
|
+
const result = await runOriginWorkflow(
|
|
1567
|
+
false,
|
|
1568
|
+
{ source: "a".repeat(40), version: "0.3.35", digest: "b".repeat(64) },
|
|
1569
|
+
failure
|
|
1570
|
+
);
|
|
1571
|
+
assert.ok(result.error);
|
|
1572
|
+
assert.equal(result.requests.length, 1);
|
|
1573
|
+
assert.equal(result.output, "");
|
|
1574
|
+
assert.deepEqual(result.commands, [{ command: "git", args: ["rev-parse", "HEAD"] }]);
|
|
1575
|
+
}
|
|
1576
|
+
);
|
|
1577
|
+
test("origin binds the exact successful original release attempt", () => {
|
|
1578
|
+
const f = originFixture();
|
|
1579
|
+
assert.equal(typeof api.validateQualificationOrigin, "function");
|
|
1580
|
+
assert.deepEqual(api.validateQualificationOrigin(f.metadata, f.inputs), {
|
|
1581
|
+
artifactId: 42,
|
|
1582
|
+
runId: 101,
|
|
1583
|
+
runAttempt: 2,
|
|
1584
|
+
artifactName: "npm-qualified-2"
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
test.each([
|
|
1588
|
+
"missing-artifact",
|
|
1589
|
+
"different-id",
|
|
1590
|
+
"unsafe-id",
|
|
1591
|
+
"expired",
|
|
1592
|
+
"expiry",
|
|
1593
|
+
"promotion-namespace",
|
|
1594
|
+
"unsafe-attempt",
|
|
1595
|
+
"foreign-repository",
|
|
1596
|
+
"fork",
|
|
1597
|
+
"wrong-source",
|
|
1598
|
+
"wrong-branch",
|
|
1599
|
+
"wrong-event",
|
|
1600
|
+
"wrong-workflow",
|
|
1601
|
+
"wrong-workflow-path",
|
|
1602
|
+
"failed-original-attempt",
|
|
1603
|
+
"later-attempt",
|
|
1604
|
+
"incomplete-attempt",
|
|
1605
|
+
"missing-job",
|
|
1606
|
+
"incomplete-job-list",
|
|
1607
|
+
"wrong-job-attempt",
|
|
1608
|
+
"failed-package",
|
|
1609
|
+
"missing-qualification-step",
|
|
1610
|
+
"failed-scan",
|
|
1611
|
+
"skipped-upload"
|
|
1612
|
+
])("origin refuses %s without substituting latest qualification", (failure) => {
|
|
1613
|
+
const f = originFixture();
|
|
1614
|
+
assert.equal(typeof api.validateQualificationOrigin, "function");
|
|
1615
|
+
const { artifact, attempt, workflow, jobs } = f.metadata;
|
|
1616
|
+
const run = artifact["workflow_run"];
|
|
1617
|
+
const job = jobs["jobs"][0];
|
|
1618
|
+
const steps = job["steps"];
|
|
1619
|
+
if (failure === "missing-artifact") f.metadata.artifact = {};
|
|
1620
|
+
if (failure === "different-id") artifact["id"] = 43;
|
|
1621
|
+
if (failure === "unsafe-id") f.inputs.artifactId = Number.MAX_SAFE_INTEGER + 1;
|
|
1622
|
+
if (failure === "expired") artifact["expired"] = true;
|
|
1623
|
+
if (failure === "expiry") artifact["expires_at"] = "2000-01-01T00:00:00Z";
|
|
1624
|
+
if (failure === "promotion-namespace") artifact["name"] = "npm-package";
|
|
1625
|
+
if (failure === "unsafe-attempt") artifact["name"] = "npm-qualified-9007199254740992";
|
|
1626
|
+
if (failure === "foreign-repository") run["repository_id"] = 124;
|
|
1627
|
+
if (failure === "fork") run["head_repository_id"] = 124;
|
|
1628
|
+
if (failure === "wrong-source") run["head_sha"] = "b".repeat(40);
|
|
1629
|
+
if (failure === "wrong-branch") attempt["head_branch"] = "issue/166";
|
|
1630
|
+
if (failure === "wrong-event") attempt["event"] = "pull_request";
|
|
1631
|
+
if (failure === "wrong-workflow") attempt["workflow_id"] = 202;
|
|
1632
|
+
if (failure === "wrong-workflow-path") workflow["path"] = ".github/workflows/ci.yml";
|
|
1633
|
+
if (failure === "failed-original-attempt") attempt["conclusion"] = "failure";
|
|
1634
|
+
if (failure === "later-attempt") attempt["run_attempt"] = 3;
|
|
1635
|
+
if (failure === "incomplete-attempt") attempt["status"] = "in_progress";
|
|
1636
|
+
if (failure === "missing-job") jobs["jobs"] = [];
|
|
1637
|
+
if (failure === "incomplete-job-list") jobs["total_count"] = 2;
|
|
1638
|
+
if (failure === "wrong-job-attempt") job["run_attempt"] = 3;
|
|
1639
|
+
if (failure === "failed-package") job["conclusion"] = "failure";
|
|
1640
|
+
if (failure === "missing-qualification-step") steps.shift();
|
|
1641
|
+
if (failure === "failed-scan") steps[1]["conclusion"] = "failure";
|
|
1642
|
+
if (failure === "skipped-upload") steps[2]["conclusion"] = "skipped";
|
|
1643
|
+
assert.throws(() => api.validateQualificationOrigin(f.metadata, f.inputs));
|
|
1644
|
+
});
|
|
1645
|
+
function fixture() {
|
|
1646
|
+
const directory = realpathSync(mkdtempSync(join(tmpdir(), "synthetic-release-workflow-")));
|
|
1647
|
+
const source = join(directory, "source");
|
|
1648
|
+
const results = join(directory, "qualification");
|
|
1649
|
+
mkdirSync(source);
|
|
1650
|
+
mkdirSync(join(results, "pack"), { recursive: true });
|
|
1651
|
+
const version = "0.0.0";
|
|
1652
|
+
const manifest = {
|
|
1653
|
+
name: "@aviaratech/ai-delivery",
|
|
1654
|
+
version,
|
|
1655
|
+
type: "module",
|
|
1656
|
+
main: "./dist/index.js",
|
|
1657
|
+
bin: { "ai-delivery": "./dist/cli.js" },
|
|
1658
|
+
engines: { node: ">=24.21.0 <25 || 26.2.0", npm: "11.19.0" },
|
|
1659
|
+
exports: {
|
|
1660
|
+
".": { default: "./dist/index.js", types: "./dist/index.d.ts" },
|
|
1661
|
+
"./agent": { default: "./dist/agent.js", types: "./dist/agent.d.ts" },
|
|
1662
|
+
"./delivery": { default: "./dist/delivery/index.js", types: "./dist/delivery/index.d.ts" },
|
|
1663
|
+
"./mcp": { default: "./dist/mcp/index.js", types: "./dist/mcp/index.d.ts" }
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
const files = /* @__PURE__ */ new Map([["package.json", JSON.stringify(manifest)]]);
|
|
1667
|
+
for (const file of ["setup", "lifecycle", "targetPolicyLocal", "pluginPackaging"])
|
|
1668
|
+
files.set(`dist/${file}.test.js`, "// fictional compiled release test bytes\n");
|
|
1669
|
+
for (const path of [
|
|
1670
|
+
"LICENSE",
|
|
1671
|
+
"README.md",
|
|
1672
|
+
"CONTRIBUTING.md",
|
|
1673
|
+
"dist/cli.js",
|
|
1674
|
+
"plugins/ai-delivery/dist/mcp-launcher.js",
|
|
1675
|
+
"plugins/ai-delivery/runtime/dist/cli.js",
|
|
1676
|
+
"plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md"
|
|
1677
|
+
])
|
|
1678
|
+
files.set(path, "synthetic inert bytes\n");
|
|
1679
|
+
for (const path of ["index", "agent", "delivery/index", "mcp/index"])
|
|
1680
|
+
for (const ext of ["js", "d.ts"]) files.set(`dist/${path}.${ext}`, "synthetic inert export\n");
|
|
1681
|
+
for (const path of ["plugins/ai-delivery/plugin.json", "plugins/ai-delivery/.claude-plugin/plugin.json"])
|
|
1682
|
+
files.set(path, JSON.stringify({ name: "ai-delivery", version }));
|
|
1683
|
+
files.set("plugins/ai-delivery/runtime/package.json", JSON.stringify({ version }));
|
|
1684
|
+
files.set(
|
|
1685
|
+
"plugins/ai-delivery/mcp.json",
|
|
1686
|
+
JSON.stringify({
|
|
1687
|
+
mcpServers: { "ai-delivery": { type: "stdio", command: "node", args: ["${PLUGIN_ROOT}/dist/mcp-launcher.js"] } }
|
|
1688
|
+
})
|
|
1689
|
+
);
|
|
1690
|
+
for (const skill of ["intake-create", "worktree-lifecycle", "pr-handoff"])
|
|
1691
|
+
files.set(
|
|
1692
|
+
`plugins/ai-delivery/skills/${skill}/SKILL.md`,
|
|
1693
|
+
`---
|
|
1694
|
+
name: ai-delivery:${skill}
|
|
1695
|
+
description: Fictional release fixture
|
|
1696
|
+
---
|
|
1697
|
+
`
|
|
1698
|
+
);
|
|
1699
|
+
const members = [...files].map(([path, contents]) => ({
|
|
1700
|
+
path,
|
|
1701
|
+
bytes: Buffer.from(contents),
|
|
1702
|
+
mode: path.endsWith("/cli.js") || path.endsWith("/mcp-launcher.js") ? 493 : 420
|
|
1703
|
+
}));
|
|
1704
|
+
const chunks = [];
|
|
1705
|
+
for (const member of members) {
|
|
1706
|
+
const path = join(source, member.path);
|
|
1707
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1708
|
+
writeFileSync(path, member.bytes);
|
|
1709
|
+
chmodSync(path, member.mode);
|
|
1710
|
+
const header = Buffer.alloc(512);
|
|
1711
|
+
header.write(`package/${member.path}`, 0, 100);
|
|
1712
|
+
const number = (value, offset, size) => header.write(value.toString(8).padStart(size - 1, "0") + "\0", offset, size);
|
|
1713
|
+
number(member.mode, 100, 8);
|
|
1714
|
+
number(0, 108, 8);
|
|
1715
|
+
number(0, 116, 8);
|
|
1716
|
+
number(member.bytes.length, 124, 12);
|
|
1717
|
+
number(0, 136, 12);
|
|
1718
|
+
header.fill(32, 148, 156);
|
|
1719
|
+
header.write("0", 156);
|
|
1720
|
+
header.write("ustar\0", 257);
|
|
1721
|
+
header.write("00", 263);
|
|
1722
|
+
header.write(
|
|
1723
|
+
header.reduce((a, b) => a + b, 0).toString(8).padStart(6, "0") + "\0 ",
|
|
1724
|
+
148,
|
|
1725
|
+
8
|
|
1726
|
+
);
|
|
1727
|
+
chunks.push(header, member.bytes, Buffer.alloc((512 - member.bytes.length % 512) % 512));
|
|
1728
|
+
}
|
|
1729
|
+
chunks.push(Buffer.alloc(1024));
|
|
1730
|
+
const archive = gzipSync(Buffer.concat(chunks));
|
|
1731
|
+
const archivePath = join(results, "pack", `aviaratech-ai-delivery-${version}.tgz`);
|
|
1732
|
+
writeFileSync(archivePath, archive);
|
|
1733
|
+
writeFileSync(join(source, "package-lock.json"), '{"synthetic":true}\n');
|
|
1734
|
+
writeFileSync(
|
|
1735
|
+
join(source, ".gitignore"),
|
|
1736
|
+
["setup", "lifecycle", "targetPolicyLocal", "pluginPackaging"].map((name) => `/dist/${name}.test.js`).join("\n") + "\n"
|
|
1737
|
+
);
|
|
1738
|
+
execFileSync("git", ["init", "-q", source]);
|
|
1739
|
+
execFileSync("git", ["add", "."], { cwd: source });
|
|
1740
|
+
execFileSync(
|
|
1741
|
+
"git",
|
|
1742
|
+
[
|
|
1743
|
+
"-c",
|
|
1744
|
+
"user.name=Fictional Fixture",
|
|
1745
|
+
"-c",
|
|
1746
|
+
"user.email=fixture@example.invalid",
|
|
1747
|
+
"-c",
|
|
1748
|
+
"commit.gpgsign=false",
|
|
1749
|
+
"commit",
|
|
1750
|
+
"-qm",
|
|
1751
|
+
"synthetic source"
|
|
1752
|
+
],
|
|
1753
|
+
{ cwd: source }
|
|
1754
|
+
);
|
|
1755
|
+
const identity = qualification.sourceIdentity(source);
|
|
1756
|
+
const contract = {
|
|
1757
|
+
sourceRoot: source,
|
|
1758
|
+
sourceCommit: identity.commit,
|
|
1759
|
+
sourceTree: identity.tree,
|
|
1760
|
+
sourceManifestSha256: identity.manifestSha256,
|
|
1761
|
+
sourceLockSha256: identity.lockSha256,
|
|
1762
|
+
packageVersion: version,
|
|
1763
|
+
archivePath,
|
|
1764
|
+
archiveSha256: canonical.sha256(archive),
|
|
1765
|
+
dryInventory: members.map(({ path, bytes, mode }) => ({ path, size: bytes.length, mode })),
|
|
1766
|
+
node24: process.execPath,
|
|
1767
|
+
node26: "/fictional/node26",
|
|
1768
|
+
npmCli: "/fictional/npm"
|
|
1769
|
+
};
|
|
1770
|
+
const candidate = canonical.inspectCandidate(contract);
|
|
1771
|
+
const save = (path, object) => {
|
|
1772
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1773
|
+
const contents = JSON.stringify(object, null, 2) + "\n";
|
|
1774
|
+
writeFileSync(path, contents);
|
|
1775
|
+
return { path, sha256: canonical.sha256(contents) };
|
|
1776
|
+
};
|
|
1777
|
+
const command = { status: "passed", exitCode: 0, signal: null, cleanupConfirmed: true };
|
|
1778
|
+
const producer = save(join(results, "producer/result.json"), {
|
|
1779
|
+
schemaVersion: "contributor-checks@1",
|
|
1780
|
+
runId: "synthetic",
|
|
1781
|
+
scope: "full",
|
|
1782
|
+
status: "passed",
|
|
1783
|
+
fullSuccess: true,
|
|
1784
|
+
exitCode: 0,
|
|
1785
|
+
gates,
|
|
1786
|
+
omitted: [],
|
|
1787
|
+
tree: identity.fingerprint,
|
|
1788
|
+
commands: gates.map((stage) => ({ stage, ...command })),
|
|
1789
|
+
selectedTestFiles: ["src/fictional.test.ts"],
|
|
1790
|
+
tests: { files: 1, passed: 1, total: 1, skips: [] },
|
|
1791
|
+
toolchain: {
|
|
1792
|
+
controller: { executable: contract.node24, version: "v24.21.0" },
|
|
1793
|
+
npm: { executable: contract.npmCli, version: "11.19.0" },
|
|
1794
|
+
libraryConsumer: { executable: contract.node26, version: "v26.2.0" }
|
|
1795
|
+
},
|
|
1796
|
+
inventory: {
|
|
1797
|
+
kind: "dry-inventory-only",
|
|
1798
|
+
name: manifest.name,
|
|
1799
|
+
version,
|
|
1800
|
+
fileCount: members.length,
|
|
1801
|
+
files: candidate.inventory
|
|
1802
|
+
}
|
|
1803
|
+
});
|
|
1804
|
+
const packCommand = {
|
|
1805
|
+
...command,
|
|
1806
|
+
command: [
|
|
1807
|
+
contract.node24,
|
|
1808
|
+
contract.npmCli,
|
|
1809
|
+
"pack",
|
|
1810
|
+
"--ignore-scripts",
|
|
1811
|
+
"--json",
|
|
1812
|
+
"--pack-destination",
|
|
1813
|
+
dirname(archivePath)
|
|
1814
|
+
]
|
|
1815
|
+
};
|
|
1816
|
+
const artifact = save(join(results, "pack/producer.json"), {
|
|
1817
|
+
schemaVersion: "ai-delivery.current-artifact-producer@1",
|
|
1818
|
+
status: "passed",
|
|
1819
|
+
...contract,
|
|
1820
|
+
checksResultSha256: producer.sha256,
|
|
1821
|
+
inventorySha256: candidate.inventorySha256,
|
|
1822
|
+
sourceFingerprint: identity.fingerprint,
|
|
1823
|
+
pack: {
|
|
1824
|
+
status: "passed",
|
|
1825
|
+
exitCode: 0,
|
|
1826
|
+
quiescent: true,
|
|
1827
|
+
archiveSha256: contract.archiveSha256,
|
|
1828
|
+
command: packCommand,
|
|
1829
|
+
sourceBefore: identity,
|
|
1830
|
+
sourceAfter: identity
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
contract.producer = {
|
|
1834
|
+
checksResultPath: producer.path,
|
|
1835
|
+
checksResultSha256: producer.sha256,
|
|
1836
|
+
artifactReceiptPath: artifact.path,
|
|
1837
|
+
artifactReceiptSha256: artifact.sha256
|
|
1838
|
+
};
|
|
1839
|
+
const joinProof = canonical.verifyProducerJoin(contract, candidate);
|
|
1840
|
+
save(join(results, "contract.json"), contract);
|
|
1841
|
+
const contractSha256 = canonical.sha256(JSON.stringify(contract));
|
|
1842
|
+
const checkpoint = save(join(results, "checkpoint.json"), {
|
|
1843
|
+
schemaVersion: "ai-delivery.current-qualification-checkpoint@1",
|
|
1844
|
+
status: "producer-passed-consumer-required",
|
|
1845
|
+
source: identity,
|
|
1846
|
+
contract,
|
|
1847
|
+
contractSha256
|
|
1848
|
+
});
|
|
1849
|
+
const releaseDirectory = join(results, "release-tests-00000000-0000-4000-8000-000000000000");
|
|
1850
|
+
const releaseTests = save(join(releaseDirectory, "result.json"), {
|
|
1851
|
+
schemaVersion: "contributor-checks@1",
|
|
1852
|
+
scope: "release",
|
|
1853
|
+
status: "passed",
|
|
1854
|
+
exitCode: 0,
|
|
1855
|
+
fullSuccess: false,
|
|
1856
|
+
artifactQualified: false,
|
|
1857
|
+
resultsDir: releaseDirectory,
|
|
1858
|
+
gates: ["tests"],
|
|
1859
|
+
omitted: ["PR producer and consumer"],
|
|
1860
|
+
tree: identity.fingerprint,
|
|
1861
|
+
toolchain: {
|
|
1862
|
+
controller: { version: "v24.21.0", executable: contract.node24 },
|
|
1863
|
+
libraryConsumer: { version: "v26.2.0", executable: contract.node26 },
|
|
1864
|
+
npm: { version: "11.19.0", executable: contract.npmCli }
|
|
1865
|
+
},
|
|
1866
|
+
release: {
|
|
1867
|
+
...qualification.validateReleaseEntry(join(results, "contract.json"), source),
|
|
1868
|
+
contractSha256: canonical.sha256(readFileSync(join(results, "contract.json"))),
|
|
1869
|
+
historicalInputSupplied: false,
|
|
1870
|
+
temporary: { path: join(releaseDirectory, "temporary"), dev: 1, ino: 1, removed: true, quiescent: true }
|
|
1871
|
+
},
|
|
1872
|
+
commands: [{ stage: "tests", ...command }],
|
|
1873
|
+
selectedTestFiles: [...new Set(laneChecks.RELEASE_CASES.map((test2) => test2.file))],
|
|
1874
|
+
tests: {
|
|
1875
|
+
lane: "release",
|
|
1876
|
+
files: new Set(laneChecks.RELEASE_CASES.map((test2) => test2.file)).size,
|
|
1877
|
+
total: laneChecks.RELEASE_CASES.length,
|
|
1878
|
+
passed: laneChecks.RELEASE_CASES.filter((test2) => test2.kind === "mandatory").length,
|
|
1879
|
+
skips: laneChecks.RELEASE_CASES.filter((test2) => test2.kind !== "mandatory"),
|
|
1880
|
+
selectedCases: laneChecks.RELEASE_CASES.map(({ file, title }) => ({ file, title })),
|
|
1881
|
+
laneExcluded: []
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
save(join(results, "release-tests-attempt.json"), {
|
|
1885
|
+
stage: "release-tests",
|
|
1886
|
+
status: "completed",
|
|
1887
|
+
checkpointSha256: checkpoint.sha256,
|
|
1888
|
+
contractSha256,
|
|
1889
|
+
directory: releaseDirectory,
|
|
1890
|
+
resultPath: releaseTests.path,
|
|
1891
|
+
receipt: releaseTests,
|
|
1892
|
+
command: { stage: "tests", ...command }
|
|
1893
|
+
});
|
|
1894
|
+
const consumerDirectory = join(results, "consumer-00000000-0000-4000-8000-000000000000");
|
|
1895
|
+
const consumer = save(join(consumerDirectory, "result.json"), {
|
|
1896
|
+
schemaVersion: "ai-delivery.current-consumer@1",
|
|
1897
|
+
status: "passed",
|
|
1898
|
+
qualified: true,
|
|
1899
|
+
sourceIdentityVerified: true,
|
|
1900
|
+
scriptsDisabled: true,
|
|
1901
|
+
...contract,
|
|
1902
|
+
archiveManifestSha256: contract.sourceManifestSha256,
|
|
1903
|
+
inventorySha256: candidate.inventorySha256,
|
|
1904
|
+
inventory: candidate.inventory,
|
|
1905
|
+
producerJoin: joinProof,
|
|
1906
|
+
cleanup: { removed: true, quiescent: true },
|
|
1907
|
+
productionClosure: {},
|
|
1908
|
+
mcp: {},
|
|
1909
|
+
skills: ["fictional1", "fictional2", "fictional3"],
|
|
1910
|
+
resolutions: ["fictional"],
|
|
1911
|
+
phases: [
|
|
1912
|
+
"node24",
|
|
1913
|
+
"node26",
|
|
1914
|
+
"npm",
|
|
1915
|
+
"production-install",
|
|
1916
|
+
"production-closure",
|
|
1917
|
+
"cli-version",
|
|
1918
|
+
"cli-json",
|
|
1919
|
+
"exports-node24",
|
|
1920
|
+
"library-node26",
|
|
1921
|
+
"packaged-mcp"
|
|
1922
|
+
].map((phase) => ({ phase, code: 0, signal: null, quiescent: true }))
|
|
1923
|
+
});
|
|
1924
|
+
const attempt = save(join(results, "consumer-attempt.json"), {
|
|
1925
|
+
schemaVersion: "ai-delivery.current-consumer-attempt@1",
|
|
1926
|
+
status: "completed",
|
|
1927
|
+
temporaryRemoved: true,
|
|
1928
|
+
checkpointSha256: checkpoint.sha256,
|
|
1929
|
+
contractSha256,
|
|
1930
|
+
command,
|
|
1931
|
+
receipt: consumer,
|
|
1932
|
+
directory: consumerDirectory,
|
|
1933
|
+
consumerPath: consumer.path,
|
|
1934
|
+
tempRoot: join(consumerDirectory, "temporary")
|
|
1935
|
+
});
|
|
1936
|
+
const overall = {
|
|
1937
|
+
schemaVersion: "ai-delivery.current-qualification@1",
|
|
1938
|
+
status: "passed",
|
|
1939
|
+
qualified: true,
|
|
1940
|
+
exitCode: 0,
|
|
1941
|
+
omitted: [],
|
|
1942
|
+
resultsDir: results,
|
|
1943
|
+
source: identity,
|
|
1944
|
+
producer,
|
|
1945
|
+
artifact,
|
|
1946
|
+
checkpoint,
|
|
1947
|
+
releaseTests,
|
|
1948
|
+
consumer,
|
|
1949
|
+
consumerAttempt: attempt,
|
|
1950
|
+
consumerProcess: command,
|
|
1951
|
+
pack: packCommand
|
|
1952
|
+
};
|
|
1953
|
+
save(join(results, "result.json"), overall);
|
|
1954
|
+
const inputs = { source: identity.commit, version, digest: contract.archiveSha256 };
|
|
1955
|
+
const output = join(directory, "release-artifact");
|
|
1956
|
+
const edit = (path, action) => {
|
|
1957
|
+
const data = JSON.parse(readFileSync(path, "utf8"));
|
|
1958
|
+
action(data);
|
|
1959
|
+
save(path, data);
|
|
1960
|
+
};
|
|
1961
|
+
return {
|
|
1962
|
+
contract,
|
|
1963
|
+
directory,
|
|
1964
|
+
source,
|
|
1965
|
+
results,
|
|
1966
|
+
output,
|
|
1967
|
+
inputs,
|
|
1968
|
+
archivePath,
|
|
1969
|
+
consumerDirectory,
|
|
1970
|
+
releaseTests,
|
|
1971
|
+
overall,
|
|
1972
|
+
save,
|
|
1973
|
+
edit,
|
|
1974
|
+
cleanup: () => rmSync(directory, { recursive: true, force: true })
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
test("release selects and re-verifies exact synthetic qualified bytes and retains original receipts", () => {
|
|
1978
|
+
const f = fixture();
|
|
1979
|
+
try {
|
|
1980
|
+
const bundle = api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source);
|
|
1981
|
+
const selected = api.verifyReleaseArtifact(f.output, f.inputs);
|
|
1982
|
+
assert.equal(basename(selected), basename(f.archivePath));
|
|
1983
|
+
assert.deepEqual(readFileSync(selected), readFileSync(f.archivePath));
|
|
1984
|
+
assert.equal(bundle.records["overall"]?.contents, readFileSync(join(f.results, "result.json"), "utf8"));
|
|
1985
|
+
assert.equal(bundle.archive.sha256, f.inputs.digest);
|
|
1986
|
+
assert.equal(execFileSync("git", ["status", "--porcelain"], { cwd: f.source, encoding: "utf8" }), "");
|
|
1987
|
+
assert.throws(() => api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source));
|
|
1988
|
+
} finally {
|
|
1989
|
+
f.cleanup();
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1992
|
+
test("first qualification selects observed bytes without a pre-known digest", () => {
|
|
1993
|
+
const f = fixture();
|
|
1994
|
+
try {
|
|
1995
|
+
const bundle = api.selectReleaseArtifact(
|
|
1996
|
+
f.results,
|
|
1997
|
+
f.output,
|
|
1998
|
+
{ source: f.inputs.source, version: f.inputs.version },
|
|
1999
|
+
f.source
|
|
2000
|
+
);
|
|
2001
|
+
assert.equal(bundle.archive.sha256, f.inputs.digest);
|
|
2002
|
+
assert.equal(api.verifyReleaseArtifact(f.output, f.inputs), join(f.output, basename(f.archivePath)));
|
|
2003
|
+
} finally {
|
|
2004
|
+
f.cleanup();
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
test("packed helpers copy only the retained qualified archive without repacking", () => {
|
|
2008
|
+
assert.equal(typeof qualification.copyReleaseArchive, "function");
|
|
2009
|
+
const f = fixture();
|
|
2010
|
+
try {
|
|
2011
|
+
const original = readFileSync(f.archivePath);
|
|
2012
|
+
const contract = readFileSync(join(f.results, "contract.json"));
|
|
2013
|
+
const destination = join(f.directory, "helper.tgz");
|
|
2014
|
+
assert.deepEqual(qualification.copyReleaseArchive(join(f.results, "contract.json"), f.source, destination), {
|
|
2015
|
+
archivePath: destination,
|
|
2016
|
+
archiveSha256: f.inputs.digest
|
|
2017
|
+
});
|
|
2018
|
+
assert.deepEqual(readFileSync(destination), original);
|
|
2019
|
+
assert.deepEqual(readFileSync(f.archivePath), original);
|
|
2020
|
+
assert.deepEqual(readFileSync(join(f.results, "contract.json")), contract);
|
|
2021
|
+
assert.throws(() => qualification.copyReleaseArchive(join(f.results, "contract.json"), f.source, destination));
|
|
2022
|
+
} finally {
|
|
2023
|
+
f.cleanup();
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
test("release scope runs only the exact mandatory inventory without another build", async () => {
|
|
2027
|
+
const f = fixture();
|
|
2028
|
+
try {
|
|
2029
|
+
const context = qualification.validateReleaseEntry(join(f.results, "contract.json"), f.source);
|
|
2030
|
+
const files = [...new Set(laneChecks.RELEASE_CASES.map((test2) => test2.file))];
|
|
2031
|
+
let launched = 0;
|
|
2032
|
+
let driftDuringTest = false;
|
|
2033
|
+
let commandStatus = "passed";
|
|
2034
|
+
let confirmed = true;
|
|
2035
|
+
const unrelated = join(f.directory, "unrelated");
|
|
2036
|
+
writeFileSync(unrelated, "preserve");
|
|
2037
|
+
const toolchain = () => ({
|
|
2038
|
+
controller: { version: "v24.21.0", executable: f.contract.node24 },
|
|
2039
|
+
npm: { version: "11.19.0", executable: f.contract.npmCli },
|
|
2040
|
+
libraryConsumer: { version: "v26.2.0", executable: f.contract.node26 }
|
|
2041
|
+
});
|
|
2042
|
+
const execute = async (command, options) => {
|
|
2043
|
+
launched++;
|
|
2044
|
+
assert.ok(command.includes("--tags-filter=release"));
|
|
2045
|
+
assert.deepEqual(
|
|
2046
|
+
command.filter((arg) => arg.startsWith("dist/")),
|
|
2047
|
+
files
|
|
2048
|
+
);
|
|
2049
|
+
assert.equal(options.env.AI_DELIVERY_TEST_LANE, "release");
|
|
2050
|
+
assert.equal(options.env.AI_DELIVERY_RELEASE_CONTRACT, context.contractPath);
|
|
2051
|
+
assert.equal(options.env.TMPDIR, options.env.TEMP);
|
|
2052
|
+
assert.equal(options.env.TEMP, options.env.TMP);
|
|
2053
|
+
assert.ok(options.env.TMPDIR);
|
|
2054
|
+
writeFileSync(join(options.env.TMPDIR, "owned-leftover"), "remove after quiescence");
|
|
2055
|
+
mkdirSync(options.directory, { recursive: true });
|
|
2056
|
+
const output = command.find((arg) => arg.startsWith("--outputFile.json=")).slice("--outputFile.json=".length);
|
|
2057
|
+
writeFileSync(
|
|
2058
|
+
output,
|
|
2059
|
+
JSON.stringify({
|
|
2060
|
+
success: true,
|
|
2061
|
+
numTotalTests: laneChecks.RELEASE_CASES.length,
|
|
2062
|
+
numPassedTests: laneChecks.RELEASE_CASES.filter((test2) => test2.kind === "mandatory").length,
|
|
2063
|
+
testResults: files.map((file) => ({
|
|
2064
|
+
name: join(f.source, file),
|
|
2065
|
+
status: "passed",
|
|
2066
|
+
assertionResults: laneChecks.RELEASE_CASES.filter((test2) => test2.file === file).map((test2) => ({
|
|
2067
|
+
fullName: test2.title,
|
|
2068
|
+
status: test2.kind === "mandatory" ? "passed" : "pending",
|
|
2069
|
+
tags: ["release"]
|
|
2070
|
+
}))
|
|
2071
|
+
}))
|
|
2072
|
+
})
|
|
2073
|
+
);
|
|
2074
|
+
const stdoutPath = join(options.directory, "stdout.txt");
|
|
2075
|
+
const stderrPath = join(options.directory, "stderr.txt");
|
|
2076
|
+
writeFileSync(stdoutPath, "SETUP_INTERRUPTION_RECEIPT SETUP_CLI_PHASE_RECEIPT");
|
|
2077
|
+
writeFileSync(stderrPath, "");
|
|
2078
|
+
if (driftDuringTest) writeFileSync(join(f.source, files[0]), "// changed ignored compiled bytes\n");
|
|
2079
|
+
return {
|
|
2080
|
+
status: commandStatus,
|
|
2081
|
+
exitCode: commandStatus === "passed" ? 0 : 1,
|
|
2082
|
+
signal: commandStatus === "cancelled" ? "SIGTERM" : null,
|
|
2083
|
+
cleanupConfirmed: confirmed,
|
|
2084
|
+
stdoutPath,
|
|
2085
|
+
stderrPath
|
|
2086
|
+
};
|
|
2087
|
+
};
|
|
2088
|
+
const report = await laneChecks.runChecks({
|
|
2089
|
+
cwd: f.source,
|
|
2090
|
+
resultsDir: join(f.directory, "release-checks"),
|
|
2091
|
+
release: context,
|
|
2092
|
+
toolchain,
|
|
2093
|
+
execute
|
|
2094
|
+
});
|
|
2095
|
+
assert.equal(report.status, "passed", report.error);
|
|
2096
|
+
assert.equal(report.scope, "release");
|
|
2097
|
+
assert.equal(report.fullSuccess, false);
|
|
2098
|
+
assert.equal(report.artifactQualified, false);
|
|
2099
|
+
assert.equal(report.tests?.passed, laneChecks.RELEASE_CASES.filter((test2) => test2.kind === "mandatory").length);
|
|
2100
|
+
assert.deepEqual(
|
|
2101
|
+
report.commands.map((command) => command.stage),
|
|
2102
|
+
["tests"]
|
|
2103
|
+
);
|
|
2104
|
+
assert.equal(launched, 1);
|
|
2105
|
+
assert.equal(report.release?.temporary?.removed, true);
|
|
2106
|
+
assert.equal(existsSync(report.release.temporary.path), false);
|
|
2107
|
+
for (const status of ["failed", "cancelled"]) {
|
|
2108
|
+
commandStatus = status;
|
|
2109
|
+
const terminal = await laneChecks.runChecks({
|
|
2110
|
+
cwd: f.source,
|
|
2111
|
+
resultsDir: join(f.directory, `release-${status}`),
|
|
2112
|
+
release: context,
|
|
2113
|
+
toolchain,
|
|
2114
|
+
execute
|
|
2115
|
+
});
|
|
2116
|
+
assert.equal(terminal.status, status);
|
|
2117
|
+
assert.equal(terminal.release?.temporary?.removed, true);
|
|
2118
|
+
assert.equal(existsSync(terminal.release.temporary.path), false);
|
|
2119
|
+
assert.equal(readFileSync(unrelated, "utf8"), "preserve");
|
|
2120
|
+
}
|
|
2121
|
+
commandStatus = "passed";
|
|
2122
|
+
confirmed = false;
|
|
2123
|
+
const unconfirmed = await laneChecks.runChecks({
|
|
2124
|
+
cwd: f.source,
|
|
2125
|
+
resultsDir: join(f.directory, "unconfirmed-cleanup"),
|
|
2126
|
+
release: context,
|
|
2127
|
+
toolchain,
|
|
2128
|
+
execute
|
|
2129
|
+
});
|
|
2130
|
+
assert.equal(unconfirmed.status, "failed");
|
|
2131
|
+
assert.equal(unconfirmed.release?.temporary?.removed, false);
|
|
2132
|
+
assert.ok(existsSync(join(unconfirmed.release.temporary.path, "owned-leftover")));
|
|
2133
|
+
assert.match(unconfirmed.release.temporary.error, /quiescence/u);
|
|
2134
|
+
confirmed = true;
|
|
2135
|
+
const beforeRefusal = launched;
|
|
2136
|
+
const rejected = await laneChecks.runChecks({
|
|
2137
|
+
cwd: f.source,
|
|
2138
|
+
resultsDir: join(f.directory, "wrong-context"),
|
|
2139
|
+
release: { ...context, archiveSha256: "0".repeat(64) },
|
|
2140
|
+
toolchain,
|
|
2141
|
+
execute
|
|
2142
|
+
});
|
|
2143
|
+
assert.equal(rejected.status, "failed");
|
|
2144
|
+
assert.equal(launched, beforeRefusal, "A mismatched context must not launch another child.");
|
|
2145
|
+
driftDuringTest = true;
|
|
2146
|
+
const changed = await laneChecks.runChecks({
|
|
2147
|
+
cwd: f.source,
|
|
2148
|
+
resultsDir: join(f.directory, "changed-during-tests"),
|
|
2149
|
+
release: context,
|
|
2150
|
+
toolchain,
|
|
2151
|
+
execute
|
|
2152
|
+
});
|
|
2153
|
+
assert.equal(changed.status, "failed", "Ignored compiled changes during a release run must invalidate its proof.");
|
|
2154
|
+
assert.equal(launched, beforeRefusal + 1);
|
|
2155
|
+
assert.equal(
|
|
2156
|
+
execFileSync("git", ["status", "--porcelain"], { cwd: f.source, encoding: "utf8" }),
|
|
2157
|
+
"",
|
|
2158
|
+
"Git cleanliness cannot prove ignored test bytes."
|
|
2159
|
+
);
|
|
2160
|
+
const stale = await laneChecks.runChecks({
|
|
2161
|
+
cwd: f.source,
|
|
2162
|
+
resultsDir: join(f.directory, "stale-compiled"),
|
|
2163
|
+
release: context,
|
|
2164
|
+
toolchain,
|
|
2165
|
+
execute
|
|
2166
|
+
});
|
|
2167
|
+
assert.equal(stale.status, "failed");
|
|
2168
|
+
assert.equal(launched, beforeRefusal + 1, "Stale compiled release bytes must fail before launch.");
|
|
2169
|
+
} finally {
|
|
2170
|
+
f.cleanup();
|
|
2171
|
+
}
|
|
2172
|
+
});
|
|
2173
|
+
test.each(["archive-drift", "source-drift", "compiled-drift", "destination-link", "parent-alias"])(
|
|
2174
|
+
"packed archive copy refuses %s without replacing originals",
|
|
2175
|
+
(failure) => {
|
|
2176
|
+
assert.equal(typeof qualification.copyReleaseArchive, "function");
|
|
311
2177
|
const f = fixture();
|
|
312
2178
|
try {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
2179
|
+
let destination = join(f.directory, "helper.tgz");
|
|
2180
|
+
const original = readFileSync(f.archivePath);
|
|
2181
|
+
if (failure === "archive-drift") writeFileSync(f.archivePath, "changed archive");
|
|
2182
|
+
if (failure === "source-drift") writeFileSync(join(f.source, "untracked"), "changed source");
|
|
2183
|
+
if (failure === "compiled-drift") {
|
|
2184
|
+
writeFileSync(join(f.source, "dist/lifecycle.test.js"), "// changed ignored compiled bytes\n");
|
|
2185
|
+
assert.equal(execFileSync("git", ["status", "--porcelain"], { cwd: f.source, encoding: "utf8" }), "");
|
|
2186
|
+
}
|
|
2187
|
+
if (failure === "destination-link") symlinkSync(f.archivePath, destination);
|
|
2188
|
+
if (failure === "parent-alias") {
|
|
2189
|
+
symlinkSync(f.directory, join(f.directory, "alias"));
|
|
2190
|
+
destination = join(f.directory, "alias/helper.tgz");
|
|
2191
|
+
}
|
|
2192
|
+
assert.throws(() => qualification.copyReleaseArchive(join(f.results, "contract.json"), f.source, destination));
|
|
2193
|
+
if (failure !== "archive-drift") assert.deepEqual(readFileSync(f.archivePath), original);
|
|
2194
|
+
if (failure !== "destination-link") assert.equal(existsSync(destination), false);
|
|
2195
|
+
} finally {
|
|
2196
|
+
f.cleanup();
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
);
|
|
2200
|
+
test("publication verification never learns a missing expected digest", () => {
|
|
2201
|
+
const f = fixture();
|
|
2202
|
+
try {
|
|
2203
|
+
api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source);
|
|
2204
|
+
for (const digest of ["", "dummy", "0".repeat(64)])
|
|
2205
|
+
assert.throws(() => api.verifyReleaseArtifact(f.output, { ...f.inputs, digest }));
|
|
2206
|
+
} finally {
|
|
2207
|
+
f.cleanup();
|
|
2208
|
+
}
|
|
2209
|
+
});
|
|
2210
|
+
test("fresh outer resume selects and portably verifies original qualified bytes without replay", async () => {
|
|
2211
|
+
const f = fixture();
|
|
2212
|
+
try {
|
|
2213
|
+
const originalResult = readFileSync(join(f.results, "result.json"));
|
|
2214
|
+
const originalArchive = readFileSync(f.archivePath);
|
|
2215
|
+
const outer = join(f.directory, "resumed-outer");
|
|
2216
|
+
let commands = 0;
|
|
2217
|
+
const forbidden = async () => {
|
|
2218
|
+
commands++;
|
|
2219
|
+
throw new Error("Completed units must not replay.");
|
|
2220
|
+
};
|
|
2221
|
+
const resumed = await qualification.runQualification({
|
|
2222
|
+
cwd: f.source,
|
|
2223
|
+
resultsDir: outer,
|
|
2224
|
+
resume: join(f.results, "checkpoint.json"),
|
|
2225
|
+
checks: forbidden,
|
|
2226
|
+
execute: forbidden
|
|
2227
|
+
});
|
|
2228
|
+
assert.equal(resumed.qualified, true, resumed.error);
|
|
2229
|
+
assert.equal(commands, 0);
|
|
2230
|
+
const bundle = api.selectReleaseArtifact(outer, f.output, f.inputs, f.source);
|
|
2231
|
+
assert.deepEqual(readFileSync(join(f.results, "result.json")), originalResult);
|
|
2232
|
+
assert.equal(bundle.records["checkpoint"]?.contents, readFileSync(join(f.results, "checkpoint.json"), "utf8"));
|
|
2233
|
+
assert.deepEqual(readFileSync(f.archivePath), originalArchive);
|
|
2234
|
+
rmSync(f.results, { recursive: true });
|
|
2235
|
+
rmSync(outer, { recursive: true });
|
|
2236
|
+
assert.deepEqual(readFileSync(api.verifyReleaseArtifact(f.output, f.inputs)), originalArchive);
|
|
2237
|
+
} finally {
|
|
2238
|
+
f.cleanup();
|
|
2239
|
+
}
|
|
2240
|
+
});
|
|
2241
|
+
test.each([
|
|
2242
|
+
"missing",
|
|
2243
|
+
"corrupt",
|
|
2244
|
+
"PR-only",
|
|
2245
|
+
"source",
|
|
2246
|
+
"contract",
|
|
2247
|
+
"producer",
|
|
2248
|
+
"archive",
|
|
2249
|
+
"missing-case",
|
|
2250
|
+
"duplicate-case",
|
|
2251
|
+
"failed-case",
|
|
2252
|
+
"cleanup",
|
|
2253
|
+
"command-cleanup",
|
|
2254
|
+
"leftover-temp"
|
|
2255
|
+
])("release selection refuses %s release proof before retaining output", (failure) => {
|
|
2256
|
+
const f = fixture();
|
|
2257
|
+
try {
|
|
2258
|
+
if (failure === "missing")
|
|
2259
|
+
f.edit(join(f.results, "result.json"), (data) => {
|
|
2260
|
+
delete data["releaseTests"];
|
|
2261
|
+
});
|
|
2262
|
+
else if (failure === "corrupt") writeFileSync(f.releaseTests.path, "{}");
|
|
2263
|
+
else {
|
|
2264
|
+
f.edit(f.releaseTests.path, (data) => {
|
|
2265
|
+
const context = data["release"];
|
|
2266
|
+
const tests = data["tests"];
|
|
2267
|
+
if (failure === "PR-only") data["scope"] = "full";
|
|
2268
|
+
if (failure === "source") context["sourceCommit"] = "a".repeat(40);
|
|
2269
|
+
if (failure === "contract") context["contractSha256"] = "b".repeat(64);
|
|
2270
|
+
if (failure === "producer") context["producerSha256"] = "c".repeat(64);
|
|
2271
|
+
if (failure === "archive") context["archiveSha256"] = "d".repeat(64);
|
|
2272
|
+
if (failure === "missing-case") tests["selectedCases"].pop();
|
|
2273
|
+
if (failure === "duplicate-case")
|
|
2274
|
+
tests["selectedCases"].push(tests["selectedCases"][0]);
|
|
2275
|
+
if (failure === "failed-case") tests["passed"] = 22;
|
|
2276
|
+
if (failure === "cleanup") context["temporary"]["removed"] = false;
|
|
2277
|
+
if (failure === "command-cleanup") data["commands"][0]["cleanupConfirmed"] = false;
|
|
2278
|
+
});
|
|
2279
|
+
f.edit(join(f.results, "result.json"), (data) => {
|
|
2280
|
+
data["releaseTests"] = {
|
|
2281
|
+
path: f.releaseTests.path,
|
|
2282
|
+
sha256: canonical.sha256(readFileSync(f.releaseTests.path))
|
|
2283
|
+
};
|
|
2284
|
+
});
|
|
378
2285
|
}
|
|
379
|
-
|
|
380
|
-
|
|
2286
|
+
if (failure === "leftover-temp") mkdirSync(join(dirname(f.releaseTests.path), "temporary"));
|
|
2287
|
+
assert.throws(() => api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source));
|
|
2288
|
+
assert.equal(existsSync(f.output), false);
|
|
2289
|
+
} finally {
|
|
2290
|
+
f.cleanup();
|
|
2291
|
+
}
|
|
2292
|
+
});
|
|
2293
|
+
test("portable verification refuses missing or incomplete release proof even with consistent hashes", () => {
|
|
2294
|
+
const f = fixture();
|
|
2295
|
+
const diagnostic = diagnosticFixture();
|
|
2296
|
+
try {
|
|
2297
|
+
const bundle = api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source);
|
|
2298
|
+
const original = bundle.records["releaseTests"];
|
|
2299
|
+
assert.ok(original);
|
|
2300
|
+
const path = join(f.output, "qualification.json");
|
|
2301
|
+
f.edit(path, (data) => {
|
|
2302
|
+
delete data["records"]["releaseTests"];
|
|
2303
|
+
});
|
|
2304
|
+
assert.throws(() => api.verifyReleaseArtifact(f.output, f.inputs));
|
|
2305
|
+
bundle.records["releaseTests"] = original;
|
|
2306
|
+
const report = JSON.parse(original.contents);
|
|
2307
|
+
report["scope"] = "full";
|
|
2308
|
+
const observations = diagnostic.raw("failure", {
|
|
2309
|
+
REVIEWED_SOURCE_SHA: f.inputs.source,
|
|
2310
|
+
GITHUB_SHA: f.inputs.source
|
|
2311
|
+
});
|
|
2312
|
+
for (const invalid of [report, observations]) {
|
|
2313
|
+
const contents = JSON.stringify(invalid);
|
|
2314
|
+
bundle.records["releaseTests"] = { contents, sha256: canonical.sha256(contents) };
|
|
2315
|
+
const overall = JSON.parse(bundle.records["overall"].contents);
|
|
2316
|
+
overall["releaseTests"]["sha256"] = canonical.sha256(contents);
|
|
2317
|
+
const overallContents = JSON.stringify(overall);
|
|
2318
|
+
bundle.records["overall"] = { contents: overallContents, sha256: canonical.sha256(overallContents) };
|
|
2319
|
+
f.save(path, bundle);
|
|
2320
|
+
assert.throws(() => api.verifyReleaseArtifact(f.output, f.inputs));
|
|
381
2321
|
}
|
|
2322
|
+
} finally {
|
|
2323
|
+
rmSync(diagnostic.root, { recursive: true, force: true });
|
|
2324
|
+
f.cleanup();
|
|
2325
|
+
}
|
|
382
2326
|
});
|
|
383
|
-
test(
|
|
2327
|
+
test.each(["checkpoint-alias", "checkpoint-redirection", "output-inside-original", "output-inside-outer"])(
|
|
2328
|
+
"resumed selection refuses %s without changing original evidence",
|
|
2329
|
+
(failure) => {
|
|
384
2330
|
const f = fixture();
|
|
385
2331
|
try {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
2332
|
+
const outer = join(f.directory, "resumed-outer");
|
|
2333
|
+
mkdirSync(outer);
|
|
2334
|
+
const overall = { ...f.overall, resultsDir: outer };
|
|
2335
|
+
const checkpoint = f.overall["checkpoint"];
|
|
2336
|
+
if (failure === "checkpoint-alias") {
|
|
2337
|
+
const alias = join(f.directory, "checkpoint-alias");
|
|
2338
|
+
symlinkSync(f.results, alias);
|
|
2339
|
+
overall["checkpoint"] = { ...checkpoint, path: join(alias, "checkpoint.json") };
|
|
2340
|
+
}
|
|
2341
|
+
if (failure === "checkpoint-redirection") {
|
|
2342
|
+
const other = join(f.directory, "unrelated");
|
|
2343
|
+
mkdirSync(other);
|
|
2344
|
+
const path = join(other, "checkpoint.json");
|
|
2345
|
+
writeFileSync(path, readFileSync(checkpoint.path));
|
|
2346
|
+
overall["checkpoint"] = { ...checkpoint, path };
|
|
2347
|
+
}
|
|
2348
|
+
f.save(join(outer, "result.json"), overall);
|
|
2349
|
+
const output = failure === "output-inside-original" ? join(f.results, "selected") : failure === "output-inside-outer" ? join(outer, "selected") : f.output;
|
|
2350
|
+
assert.throws(() => api.selectReleaseArtifact(outer, output, f.inputs, f.source));
|
|
2351
|
+
assert.equal(existsSync(output), false);
|
|
2352
|
+
} finally {
|
|
2353
|
+
f.cleanup();
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
);
|
|
2357
|
+
test.each([
|
|
2358
|
+
"missing",
|
|
2359
|
+
"incomplete",
|
|
2360
|
+
"unqualified",
|
|
2361
|
+
"exit",
|
|
2362
|
+
"omission",
|
|
2363
|
+
"wrong-source",
|
|
2364
|
+
"wrong-version",
|
|
2365
|
+
"modified-archive",
|
|
2366
|
+
"unsafe-archive-path",
|
|
2367
|
+
"linked-archive",
|
|
2368
|
+
"producer-digest",
|
|
2369
|
+
"consumer-digest",
|
|
2370
|
+
"cleanup",
|
|
2371
|
+
"leftover-temp",
|
|
2372
|
+
"source-drift"
|
|
2373
|
+
])("release refuses %s before upload", (failure) => {
|
|
2374
|
+
const f = fixture();
|
|
2375
|
+
try {
|
|
2376
|
+
const resultPath = join(f.results, "result.json");
|
|
2377
|
+
if (failure === "missing") rmSync(resultPath);
|
|
2378
|
+
if (failure === "incomplete")
|
|
2379
|
+
f.edit(resultPath, (data) => {
|
|
2380
|
+
data["status"] = "incomplete";
|
|
2381
|
+
});
|
|
2382
|
+
if (failure === "unqualified")
|
|
2383
|
+
f.edit(resultPath, (data) => {
|
|
2384
|
+
data["qualified"] = false;
|
|
2385
|
+
});
|
|
2386
|
+
if (failure === "exit")
|
|
2387
|
+
f.edit(resultPath, (data) => {
|
|
2388
|
+
data["exitCode"] = 1;
|
|
2389
|
+
});
|
|
2390
|
+
if (failure === "omission")
|
|
2391
|
+
f.edit(resultPath, (data) => {
|
|
2392
|
+
data["omitted"] = ["consumer"];
|
|
2393
|
+
});
|
|
2394
|
+
if (failure === "wrong-source") f.inputs.source = "0".repeat(40);
|
|
2395
|
+
if (failure === "wrong-version") f.inputs.version = "0.0.1";
|
|
2396
|
+
if (failure === "modified-archive") writeFileSync(f.archivePath, "changed archive");
|
|
2397
|
+
if (failure === "unsafe-archive-path") {
|
|
2398
|
+
const path = join(f.results, "checkpoint.json");
|
|
2399
|
+
f.edit(path, (data) => {
|
|
2400
|
+
data["contract"]["archivePath"] = join(f.directory, "outside.tgz");
|
|
2401
|
+
});
|
|
2402
|
+
f.edit(resultPath, (data) => {
|
|
2403
|
+
data["checkpoint"] = { path, sha256: canonical.sha256(readFileSync(path)) };
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
if (failure === "linked-archive") {
|
|
2407
|
+
const other = join(f.directory, "other.tgz");
|
|
2408
|
+
writeFileSync(other, readFileSync(f.archivePath));
|
|
2409
|
+
rmSync(f.archivePath);
|
|
2410
|
+
symlinkSync(other, f.archivePath);
|
|
395
2411
|
}
|
|
396
|
-
|
|
397
|
-
|
|
2412
|
+
if (failure === "producer-digest")
|
|
2413
|
+
f.edit(join(f.results, "producer/result.json"), (data) => {
|
|
2414
|
+
data["fullSuccess"] = false;
|
|
2415
|
+
});
|
|
2416
|
+
if (failure === "consumer-digest")
|
|
2417
|
+
f.edit(join(f.consumerDirectory, "result.json"), (data) => {
|
|
2418
|
+
data["qualified"] = false;
|
|
2419
|
+
});
|
|
2420
|
+
if (failure === "cleanup") {
|
|
2421
|
+
const path = join(f.results, "consumer-attempt.json");
|
|
2422
|
+
f.edit(path, (data) => {
|
|
2423
|
+
data["temporaryRemoved"] = false;
|
|
2424
|
+
});
|
|
2425
|
+
f.edit(resultPath, (data) => {
|
|
2426
|
+
data["consumerAttempt"] = { path, sha256: canonical.sha256(readFileSync(path)) };
|
|
2427
|
+
});
|
|
398
2428
|
}
|
|
2429
|
+
if (failure === "leftover-temp") mkdirSync(join(f.consumerDirectory, "temporary"));
|
|
2430
|
+
if (failure === "source-drift") writeFileSync(join(f.source, "untracked"), "changed source");
|
|
2431
|
+
assert.throws(() => api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source));
|
|
2432
|
+
assert.equal(existsSync(f.output), false, "No upload directory may be created before validation.");
|
|
2433
|
+
} finally {
|
|
2434
|
+
f.cleanup();
|
|
2435
|
+
}
|
|
399
2436
|
});
|
|
400
|
-
test(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
assert.match(packageJob, /path: \$\{\{ runner\.temp \}\}\/release-artifact\//u);
|
|
408
|
-
assert.doesNotMatch(packageJob, /npm run build|npm pack/u);
|
|
409
|
-
assert.match(publishJob, /release-artifact\.mjs verify package-artifact/u);
|
|
410
|
-
assert.match(publishJob, /ref: \$\{\{ inputs\.reviewed_source_sha \}\}/u);
|
|
411
|
-
assert.match(publishJob, /npm pack --ignore-scripts --pack-destination .*repacked/u);
|
|
412
|
-
const expression = /spawnSync\('npm', (\['publish',[^\n]+?\]), \{ stdio: 'inherit' \}\)/u.exec(publishJob)?.[1];
|
|
413
|
-
assert.ok(expression);
|
|
414
|
-
const inputs = { version: '1.2.3', registry: 'https://registry.npmjs.org' };
|
|
415
|
-
const archivePath = '/fictional/verified/aviaratech-ai-delivery-1.2.3.tgz';
|
|
416
|
-
// Interpret only literal array arguments and the two known variables; no eval or npm execution.
|
|
417
|
-
const args = expression
|
|
418
|
-
.slice(1, -1)
|
|
419
|
-
.split(',')
|
|
420
|
-
.map((token) => {
|
|
421
|
-
const value = token.trim();
|
|
422
|
-
if (value === 'archivePath')
|
|
423
|
-
return archivePath;
|
|
424
|
-
if (value === 'registry')
|
|
425
|
-
return inputs.registry;
|
|
426
|
-
assert.match(value, /^'[^']*'$/u, 'Unexpected publication argument expression.');
|
|
427
|
-
return value.slice(1, -1);
|
|
2437
|
+
test("downloaded portable proof and bytes must still match before publication", () => {
|
|
2438
|
+
const f = fixture();
|
|
2439
|
+
try {
|
|
2440
|
+
api.selectReleaseArtifact(f.results, f.output, f.inputs, f.source);
|
|
2441
|
+
const proof = join(f.output, "qualification.json");
|
|
2442
|
+
f.edit(proof, (data) => {
|
|
2443
|
+
data["records"]["consumer"]["contents"] = "{}";
|
|
428
2444
|
});
|
|
429
|
-
assert.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
2445
|
+
assert.throws(() => api.verifyReleaseArtifact(f.output, f.inputs));
|
|
2446
|
+
api.selectReleaseArtifact(f.results, join(f.directory, "second-copy"), f.inputs, f.source);
|
|
2447
|
+
writeFileSync(join(f.directory, "second-copy", basename(f.archivePath)), "changed bytes");
|
|
2448
|
+
assert.throws(() => api.verifyReleaseArtifact(join(f.directory, "second-copy"), f.inputs));
|
|
2449
|
+
} finally {
|
|
2450
|
+
f.cleanup();
|
|
2451
|
+
}
|
|
2452
|
+
});
|
|
2453
|
+
test("actual release workflow passes the qualified archive through upload and direct npm argument", () => {
|
|
2454
|
+
const workflow = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8");
|
|
2455
|
+
const packageJob = workflow.slice(workflow.indexOf(" package:"), workflow.indexOf(" publish:"));
|
|
2456
|
+
const publishJob = workflow.slice(workflow.indexOf(" publish:"));
|
|
2457
|
+
assert.equal((packageJob.match(/npm run checks/gu) ?? []).length, 1);
|
|
2458
|
+
assert.match(packageJob, /npm run checks:release -- --results-dir "\$RUNNER_TEMP\/release-qualification"/u);
|
|
2459
|
+
assert.match(
|
|
2460
|
+
packageJob,
|
|
2461
|
+
/release-artifact\.mjs select "\$RUNNER_TEMP\/release-qualification" "\$RUNNER_TEMP\/release-artifact"/u
|
|
2462
|
+
);
|
|
2463
|
+
assert.match(packageJob, /path: \$\{\{ runner\.temp \}\}\/release-artifact\//u);
|
|
2464
|
+
assert.doesNotMatch(packageJob, /npm run build|npm pack/u);
|
|
2465
|
+
const steps = packageJob.split(/(?=^ {6}- )/mu);
|
|
2466
|
+
for (const name of [
|
|
2467
|
+
"Pin npm",
|
|
2468
|
+
"Qualify and retain the exact archive",
|
|
2469
|
+
"Scan source history",
|
|
2470
|
+
"Upload qualified package"
|
|
2471
|
+
]) {
|
|
2472
|
+
const step = steps.find((step2) => step2.includes(`name: ${name}
|
|
2473
|
+
`));
|
|
2474
|
+
assert.ok(step, name);
|
|
2475
|
+
assert.match(step, /if: \$\{\{ inputs\.qualification_only \}\}/u, name);
|
|
2476
|
+
}
|
|
2477
|
+
const promotion = steps.find((step) => step.includes("name: Verify accepted original archive\n"));
|
|
2478
|
+
assert.ok(promotion);
|
|
2479
|
+
assert.match(promotion, /if: \$\{\{ !inputs\.qualification_only \}\}/u);
|
|
2480
|
+
assert.doesNotMatch(promotion, /npm ci|npm run|npm pack|current-qualification|current-consumer/u);
|
|
2481
|
+
assert.match(packageJob, /artifact-ids: \$\{\{ inputs\.qualification_artifact_id \}\}/u);
|
|
2482
|
+
assert.match(packageJob, /run-id: \$\{\{ steps\.origin\.outputs\.run_id \}\}/u);
|
|
2483
|
+
assert.match(packageJob, /actions: read/u);
|
|
2484
|
+
assert.doesNotMatch(packageJob, /id-token: write/u);
|
|
2485
|
+
assert.match(publishJob, /!inputs\.qualification_only && needs\.package\.result == 'success'/u);
|
|
2486
|
+
assert.match(publishJob, /release-artifact\.mjs verify package-artifact/u);
|
|
2487
|
+
assert.match(publishJob, /ref: \$\{\{ inputs\.reviewed_source_sha \}\}/u);
|
|
2488
|
+
assert.match(publishJob, /npm pack --ignore-scripts --pack-destination .*repacked/u);
|
|
2489
|
+
const expression = /spawnSync\('npm', (\['publish',[^\n]+?\]), \{ stdio: 'inherit' \}\)/u.exec(publishJob)?.[1];
|
|
2490
|
+
assert.ok(expression);
|
|
2491
|
+
const inputs = { version: "1.2.3", registry: "https://registry.npmjs.org" };
|
|
2492
|
+
const archivePath = "/fictional/verified/aviaratech-ai-delivery-1.2.3.tgz";
|
|
2493
|
+
const args = expression.slice(1, -1).split(",").map((token) => {
|
|
2494
|
+
const value = token.trim();
|
|
2495
|
+
if (value === "archivePath") return archivePath;
|
|
2496
|
+
if (value === "registry") return inputs.registry;
|
|
2497
|
+
assert.match(value, /^'[^']*'$/u, "Unexpected publication argument expression.");
|
|
2498
|
+
return value.slice(1, -1);
|
|
2499
|
+
});
|
|
2500
|
+
assert.deepEqual(args, [
|
|
2501
|
+
"publish",
|
|
2502
|
+
archivePath,
|
|
2503
|
+
"--ignore-scripts",
|
|
2504
|
+
"--access",
|
|
2505
|
+
"public",
|
|
2506
|
+
"--tag",
|
|
2507
|
+
"latest",
|
|
2508
|
+
"--registry",
|
|
2509
|
+
inputs.registry,
|
|
2510
|
+
"--provenance"
|
|
2511
|
+
]);
|
|
2512
|
+
assert.match(publishJob, /const archivePath = resolve\(`\.\.\/\.\.\/aviaratech-ai-delivery-\$\{version\}\.tgz`\)/u);
|
|
2513
|
+
assert.match(publishJob, /readFileSync\(archivePath\)/u);
|
|
2514
|
+
assert.match(publishJob, /environment: npm-publish/u);
|
|
2515
|
+
assert.match(publishJob, /id-token: write/u);
|
|
2516
|
+
assert.match(publishJob, /Publication will not be repeated/u);
|
|
446
2517
|
});
|
|
447
|
-
//# sourceMappingURL=releaseWorkflow.test.js.map
|
|
2518
|
+
//# sourceMappingURL=releaseWorkflow.test.js.map
|