@aviaratech/ai-delivery 0.3.35 → 0.3.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +12 -206
- package/README.md +57 -554
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +76 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +105 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +402 -515
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +329 -353
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +59 -19
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.js +73 -67
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +44 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1945 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +264 -286
- package/dist/mcp/tools.js +267 -340
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +460 -409
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +132 -94
- package/dist/pr.js +1521 -1323
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +1678 -632
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +150 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +183 -0
- package/dist/readView.js +217 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +119 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/deliveryAdmission.js +131 -154
- package/dist/services/deliveryAdmission.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/services/worktreeRegistry.d.ts +27 -119
- package/dist/services/worktreeRegistry.js +765 -1182
- package/dist/services/worktreeRegistry.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +353 -352
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +305 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +463 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.js +84 -76
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.js +15 -18
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -19
- package/dist/verification.js +1020 -1939
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +23 -24
- package/dist/version.js.map +7 -1
- package/dist/worktree.d.ts +3 -15
- package/dist/worktree.js +97 -177
- package/dist/worktree.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +358 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
package/dist/review.js
CHANGED
|
@@ -1,379 +1,632 @@
|
|
|
1
|
-
import { join } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { assertPrivateFile } from "./delivery/common.js";
|
|
5
|
+
import {
|
|
6
|
+
digestValue,
|
|
7
|
+
RepositoryApprovalBindingSchema
|
|
8
|
+
} from "./delivery/legacy.js";
|
|
9
|
+
import { DeliveryError } from "./errors.js";
|
|
10
|
+
import { git, gitCommonDir, gitExitCode } from "./git.js";
|
|
11
|
+
import { GIT_EXECUTABLE, gitEnvironment, inertGitArguments } from "./gitProcess.js";
|
|
12
|
+
import { writePrivateJsonFileAtomically } from "./utils/atomicJson.js";
|
|
8
13
|
const Sha = z.string().regex(/^[a-f0-9]{40}$/u);
|
|
9
14
|
const Digest = z.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
const Text = z.string().trim().min(1);
|
|
16
|
+
const Effort = z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra", "inherited"]);
|
|
17
|
+
const ReviewBase = z.strictObject({ baseSha: Sha, mergeBaseSha: Sha });
|
|
18
|
+
const Reuse = z.strictObject({ fromReviewId: z.number().int().positive(), verificationResultPath: Text });
|
|
19
|
+
const ReviewVerdictSchema = z.strictObject({
|
|
20
|
+
schemaVersion: z.literal("ai-delivery.review-verdict@1"),
|
|
21
|
+
verdict: z.enum(["approve", "request-changes"]),
|
|
22
|
+
summary: Text,
|
|
23
|
+
issueNumber: z.number().int().positive(),
|
|
24
|
+
scope: z.strictObject({
|
|
25
|
+
headSha: Sha,
|
|
26
|
+
headTree: Sha,
|
|
27
|
+
changedPaths: z.array(
|
|
28
|
+
z.string().min(1).refine((path) => !path.includes("\0"), "Paths cannot contain NUL.")
|
|
29
|
+
).transform((paths) => [...new Set(paths)].sort())
|
|
30
|
+
}),
|
|
31
|
+
verificationReproduced: z.array(Text).min(1),
|
|
32
|
+
requestedModel: Text,
|
|
33
|
+
requestedEffort: Effort.default("inherited"),
|
|
34
|
+
effectiveModel: Text,
|
|
35
|
+
effectiveEffort: Effort.default("inherited"),
|
|
36
|
+
elapsedMs: z.number().int().nonnegative(),
|
|
37
|
+
findings: z.array(Text),
|
|
38
|
+
readOnly: z.literal(true),
|
|
39
|
+
nonClosing: z.boolean().optional(),
|
|
40
|
+
reuse: Reuse.optional()
|
|
41
|
+
});
|
|
42
|
+
function parseReviewVerdict(raw) {
|
|
43
|
+
let value;
|
|
44
|
+
try {
|
|
45
|
+
value = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
46
|
+
} catch {
|
|
47
|
+
throw new DeliveryError("verdict: Invalid JSON.");
|
|
48
|
+
}
|
|
49
|
+
const result = ReviewVerdictSchema.safeParse(value);
|
|
50
|
+
if (!result.success)
|
|
51
|
+
throw new DeliveryError(
|
|
52
|
+
result.error.issues.map((issue) => `${issue.path.join(".") || "verdict"}: ${issue.message}`).join("; ")
|
|
53
|
+
);
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
function buildReviewArtifact(input) {
|
|
57
|
+
const verdict = parseReviewVerdict(input.verdict);
|
|
58
|
+
if (!Digest.safeParse(input.verdictFileSha256).success)
|
|
59
|
+
throw new DeliveryError("verdictFileSha256: Expected the exact verdict-file SHA256.");
|
|
60
|
+
if (input.identity.toLowerCase() === input.authorIdentity.toLowerCase())
|
|
61
|
+
throw new DeliveryError("identity: Reviewer and author must be distinct.");
|
|
62
|
+
assertReviewVerdictTarget(verdict, input.provider, input.expectedHead);
|
|
63
|
+
const content = {
|
|
64
|
+
schemaVersion: "ai-delivery.review-artifact@1",
|
|
65
|
+
verdictFileSha256: input.verdictFileSha256,
|
|
66
|
+
authorIdentity: input.authorIdentity,
|
|
67
|
+
reviewerIdentity: input.identity,
|
|
68
|
+
head: { sha: verdict.scope.headSha, tree: verdict.scope.headTree },
|
|
69
|
+
issueNumber: verdict.issueNumber,
|
|
70
|
+
prNumber: input.prNumber,
|
|
71
|
+
diffScopeHash: digestValue(verdict.scope.changedPaths),
|
|
72
|
+
changedPaths: verdict.scope.changedPaths,
|
|
73
|
+
...input.reviewBase === void 0 ? {} : { reviewBase: input.reviewBase },
|
|
74
|
+
...verdict.reuse === void 0 ? {} : { reuse: verdict.reuse },
|
|
75
|
+
checks: verdict.verificationReproduced,
|
|
76
|
+
elapsedMs: verdict.elapsedMs,
|
|
77
|
+
findings: verdict.findings,
|
|
78
|
+
readOnly: verdict.readOnly,
|
|
79
|
+
requestedModel: verdict.requestedModel,
|
|
80
|
+
requestedEffort: verdict.requestedEffort,
|
|
81
|
+
effectiveModel: verdict.effectiveModel,
|
|
82
|
+
effectiveEffort: verdict.effectiveEffort,
|
|
83
|
+
summary: verdict.summary,
|
|
84
|
+
verdict: verdict.verdict
|
|
85
|
+
};
|
|
86
|
+
const artifact = ReviewArtifactSchema.parse({ ...content, artifactId: digestValue(content) });
|
|
87
|
+
githubReviewBody(artifact);
|
|
88
|
+
return artifact;
|
|
89
|
+
}
|
|
90
|
+
function assertReviewVerdictTarget(verdict, selectedProvider, expectedHead) {
|
|
91
|
+
const provider = (model) => /^(?:gpt-|o[134](?:-|$))/u.test(model) ? "openai" : model.startsWith("claude-") ? "anthropic" : model.startsWith("gemini-") ? "google" : /^qwen[\d.-]/iu.test(model) ? "qwen" : null;
|
|
92
|
+
if (provider(verdict.requestedModel) === null || provider(verdict.requestedModel) !== selectedProvider || provider(verdict.effectiveModel) !== selectedProvider)
|
|
93
|
+
throw new DeliveryError(
|
|
94
|
+
"identity: Configured reviewer provider must match both requestedModel and effectiveModel families."
|
|
95
|
+
);
|
|
96
|
+
if (!Sha.safeParse(expectedHead).success || expectedHead !== verdict.scope.headSha)
|
|
97
|
+
throw new DeliveryError("scope.headSha: Verdict and requested exact head differ.");
|
|
98
|
+
}
|
|
99
|
+
const ReviewArtifactSchema = z.object({
|
|
100
|
+
artifactId: Digest,
|
|
101
|
+
verdictFileSha256: Digest.optional(),
|
|
102
|
+
authorIdentity: z.string().min(1),
|
|
103
|
+
checks: z.array(z.string().min(1)).min(1),
|
|
104
|
+
diffScopeHash: Digest,
|
|
105
|
+
deliveryMetrics: z.object({ blockerTimeMs: z.number().int().nonnegative().nullable(), reviewRound: z.number().int().positive() }).strict().optional(),
|
|
106
|
+
elapsedMs: z.number().int().nonnegative(),
|
|
107
|
+
findings: z.array(z.string()),
|
|
108
|
+
head: z.object({ sha: Sha, tree: Sha }).strict(),
|
|
109
|
+
reviewBase: ReviewBase.optional(),
|
|
110
|
+
reuse: Reuse.optional(),
|
|
111
|
+
reusedFrom: z.strictObject({
|
|
112
|
+
reviewId: z.number().int().positive(),
|
|
12
113
|
artifactId: Digest,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
.superRefine((artifact, ctx) => {
|
|
37
|
-
const { artifactId, ...content } = artifact;
|
|
38
|
-
if (artifactId !== digestValue(content) || artifact.authorIdentity === artifact.reviewerIdentity) {
|
|
39
|
-
ctx.addIssue({ code: 'custom', message: 'Review artifact identity or role separation is invalid.' });
|
|
40
|
-
}
|
|
114
|
+
oldHead: Sha,
|
|
115
|
+
newHead: Sha,
|
|
116
|
+
reason: Text
|
|
117
|
+
}).optional(),
|
|
118
|
+
changedPaths: z.array(
|
|
119
|
+
z.string().min(1).refine((path) => !path.includes("\0"))
|
|
120
|
+
).optional(),
|
|
121
|
+
issueNumber: z.number().int().positive(),
|
|
122
|
+
prNumber: z.number().int().positive().nullable(),
|
|
123
|
+
readOnly: z.literal(true),
|
|
124
|
+
requestedEffort: z.string().min(1),
|
|
125
|
+
requestedModel: z.string().min(1),
|
|
126
|
+
effectiveEffort: z.string().min(1),
|
|
127
|
+
effectiveModel: z.string().min(1),
|
|
128
|
+
reviewerIdentity: z.string().min(1),
|
|
129
|
+
schemaVersion: z.literal("ai-delivery.review-artifact@1"),
|
|
130
|
+
summary: z.string().min(1),
|
|
131
|
+
verdict: z.enum(["approve", "request-changes"])
|
|
132
|
+
}).strict().superRefine((artifact, ctx) => {
|
|
133
|
+
const { artifactId, ...content } = artifact;
|
|
134
|
+
if (artifactId !== digestValue(content) || artifact.authorIdentity === artifact.reviewerIdentity || artifact.changedPaths !== void 0 && artifact.diffScopeHash !== digestValue(artifact.changedPaths)) {
|
|
135
|
+
ctx.addIssue({ code: "custom", message: "Review artifact identity or role separation is invalid." });
|
|
136
|
+
}
|
|
41
137
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
if (receiptId !== digestValue(content) ||
|
|
60
|
-
receipt.headSha !== receipt.artifact.head.sha ||
|
|
61
|
-
(receipt.artifact.prNumber !== null && receipt.artifact.prNumber !== receipt.prNumber)) {
|
|
62
|
-
ctx.addIssue({ code: 'custom', message: 'Submitted review receipt is not bound to its artifact.' });
|
|
63
|
-
}
|
|
138
|
+
const SubmittedReviewReceiptSchema = z.object({
|
|
139
|
+
artifact: ReviewArtifactSchema,
|
|
140
|
+
completedAt: z.iso.datetime(),
|
|
141
|
+
githubReviewId: z.number().int().positive(),
|
|
142
|
+
githubReviewUrl: z.url(),
|
|
143
|
+
headSha: Sha,
|
|
144
|
+
login: z.string().min(1),
|
|
145
|
+
prNumber: z.number().int().positive(),
|
|
146
|
+
publicationEvidenceId: Digest,
|
|
147
|
+
receiptId: Digest,
|
|
148
|
+
schemaVersion: z.literal("ai-delivery.review-receipt@1"),
|
|
149
|
+
state: z.literal("APPROVED")
|
|
150
|
+
}).strict().superRefine((receipt, ctx) => {
|
|
151
|
+
const { receiptId, ...content } = receipt;
|
|
152
|
+
if (receiptId !== digestValue(content) || receipt.headSha !== receipt.artifact.head.sha || receipt.artifact.prNumber !== null && receipt.artifact.prNumber !== receipt.prNumber) {
|
|
153
|
+
ctx.addIssue({ code: "custom", message: "Submitted review receipt is not bound to its artifact." });
|
|
154
|
+
}
|
|
64
155
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
156
|
+
async function readRequiredReviewState(context, prNumber, expectedHead, submittedReview) {
|
|
157
|
+
let response;
|
|
158
|
+
try {
|
|
159
|
+
response = await context.clients.graphql(
|
|
160
|
+
"query DeliveryReviewDecision($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { headRefOid reviewDecision } } }",
|
|
161
|
+
{ owner: context.repo.owner, name: context.repo.repo, number: prNumber }
|
|
162
|
+
);
|
|
163
|
+
} catch {
|
|
164
|
+
return {
|
|
165
|
+
observed: false,
|
|
166
|
+
reviewDecision: null,
|
|
167
|
+
submittedReviewAuthorCanPushToRepository: null,
|
|
168
|
+
status: "unknown",
|
|
169
|
+
nextAction: "Inspect the PR review requirement in GitHub before merge; review decision readback is unavailable."
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const pr = response.repository?.pullRequest;
|
|
173
|
+
if (!pr) {
|
|
174
|
+
return {
|
|
175
|
+
observed: false,
|
|
176
|
+
reviewDecision: null,
|
|
177
|
+
submittedReviewAuthorCanPushToRepository: null,
|
|
178
|
+
status: "unknown",
|
|
179
|
+
nextAction: "Inspect the PR review requirement in GitHub before merge; PR decision readback is unavailable."
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (pr.headRefOid !== expectedHead) {
|
|
183
|
+
throw new DeliveryError("GitHub review decision does not match the exact PR head.");
|
|
184
|
+
}
|
|
185
|
+
if (pr.reviewDecision !== null && pr.reviewDecision !== "APPROVED" && pr.reviewDecision !== "REVIEW_REQUIRED" && pr.reviewDecision !== "CHANGES_REQUESTED") {
|
|
186
|
+
return {
|
|
187
|
+
observed: false,
|
|
188
|
+
reviewDecision: null,
|
|
189
|
+
submittedReviewAuthorCanPushToRepository: null,
|
|
190
|
+
status: "unknown",
|
|
191
|
+
nextAction: "Inspect the PR review requirement in GitHub before merge; review decision readback is malformed."
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
let submittedReviewAuthorCanPushToRepository = null;
|
|
195
|
+
if (submittedReview) {
|
|
68
196
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!pr) {
|
|
82
|
-
return {
|
|
83
|
-
observed: false,
|
|
84
|
-
reviewDecision: null,
|
|
85
|
-
submittedReviewAuthorCanPushToRepository: null,
|
|
86
|
-
status: 'unknown',
|
|
87
|
-
nextAction: 'Inspect the PR review requirement in GitHub before merge; PR decision readback is unavailable.',
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
if (pr.headRefOid !== expectedHead) {
|
|
91
|
-
throw new DeliveryError('GitHub review decision does not match the exact PR head.');
|
|
92
|
-
}
|
|
93
|
-
if (pr.reviewDecision !== null &&
|
|
94
|
-
pr.reviewDecision !== 'APPROVED' &&
|
|
95
|
-
pr.reviewDecision !== 'REVIEW_REQUIRED' &&
|
|
96
|
-
pr.reviewDecision !== 'CHANGES_REQUESTED') {
|
|
97
|
-
return {
|
|
98
|
-
observed: false,
|
|
99
|
-
reviewDecision: null,
|
|
100
|
-
submittedReviewAuthorCanPushToRepository: null,
|
|
101
|
-
status: 'unknown',
|
|
102
|
-
nextAction: 'Inspect the PR review requirement in GitHub before merge; review decision readback is malformed.',
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
let submittedReviewAuthorCanPushToRepository = null;
|
|
106
|
-
if (submittedReview) {
|
|
107
|
-
try {
|
|
108
|
-
const access = await context.clients.graphql('query DeliveryReviewAccess($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { reviews(last: 100) { nodes { fullDatabaseId author { login } authorCanPushToRepository commit { oid } state } } } } }', { owner: context.repo.owner, name: context.repo.repo, number: prNumber });
|
|
109
|
-
// REST review receipts include [bot], while GraphQL may omit it for the same App actor.
|
|
110
|
-
const submittedActor = submittedReview.login.toLowerCase().replace(/\[bot\]$/u, '');
|
|
111
|
-
const exact = access.repository?.pullRequest?.reviews.nodes.find((review) => review !== null &&
|
|
112
|
-
String(review.fullDatabaseId) === String(submittedReview.id) &&
|
|
113
|
-
review.author?.login.toLowerCase().replace(/\[bot\]$/u, '') === submittedActor &&
|
|
114
|
-
review.commit?.oid === expectedHead &&
|
|
115
|
-
review.state === 'APPROVED');
|
|
116
|
-
if (typeof exact?.authorCanPushToRepository === 'boolean') {
|
|
117
|
-
submittedReviewAuthorCanPushToRepository = exact.authorCanPushToRepository;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
// A review access read failure does not erase the live PR decision.
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (pr.reviewDecision === 'APPROVED') {
|
|
125
|
-
return {
|
|
126
|
-
observed: true,
|
|
127
|
-
reviewDecision: 'APPROVED',
|
|
128
|
-
submittedReviewAuthorCanPushToRepository,
|
|
129
|
-
status: 'satisfied',
|
|
130
|
-
nextAction: 'Continue only after required checks pass.',
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (pr.reviewDecision === 'REVIEW_REQUIRED') {
|
|
134
|
-
return {
|
|
135
|
-
observed: true,
|
|
136
|
-
reviewDecision: 'REVIEW_REQUIRED',
|
|
137
|
-
submittedReviewAuthorCanPushToRepository,
|
|
138
|
-
status: 'still-required',
|
|
139
|
-
nextAction: submittedReviewAuthorCanPushToRepository === false
|
|
140
|
-
? 'GitHub still requires a qualifying approval; the submitted reviewer App review has no repository write access. Inspect the active rule and the App installation Contents grant, then obtain approval from an eligible independent reviewer.'
|
|
141
|
-
: 'GitHub still requires a qualifying approval. Inspect the active rule and obtain approval from an eligible independent reviewer; do not change actors or protections automatically.',
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (pr.reviewDecision === 'CHANGES_REQUESTED') {
|
|
145
|
-
return {
|
|
146
|
-
observed: true,
|
|
147
|
-
reviewDecision: 'CHANGES_REQUESTED',
|
|
148
|
-
submittedReviewAuthorCanPushToRepository,
|
|
149
|
-
status: 'changes-requested',
|
|
150
|
-
nextAction: 'Resolve the blocking review and obtain a fresh exact-head independent approval.',
|
|
151
|
-
};
|
|
197
|
+
const access = await context.clients.graphql(
|
|
198
|
+
"query DeliveryReviewAccess($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { reviews(last: 100) { nodes { fullDatabaseId author { login } authorCanPushToRepository commit { oid } state } } } } }",
|
|
199
|
+
{ owner: context.repo.owner, name: context.repo.repo, number: prNumber }
|
|
200
|
+
);
|
|
201
|
+
const submittedActor = submittedReview.login.toLowerCase().replace(/\[bot\]$/u, "");
|
|
202
|
+
const exact = access.repository?.pullRequest?.reviews.nodes.find(
|
|
203
|
+
(review) => review !== null && String(review.fullDatabaseId) === String(submittedReview.id) && review.author?.login.toLowerCase().replace(/\[bot\]$/u, "") === submittedActor && review.commit?.oid === expectedHead && review.state === (submittedReview.state ?? "APPROVED")
|
|
204
|
+
);
|
|
205
|
+
if (typeof exact?.authorCanPushToRepository === "boolean") {
|
|
206
|
+
submittedReviewAuthorCanPushToRepository = exact.authorCanPushToRepository;
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
152
209
|
}
|
|
210
|
+
}
|
|
211
|
+
if (pr.reviewDecision === "APPROVED") {
|
|
212
|
+
return {
|
|
213
|
+
observed: true,
|
|
214
|
+
reviewDecision: "APPROVED",
|
|
215
|
+
submittedReviewAuthorCanPushToRepository,
|
|
216
|
+
status: "satisfied",
|
|
217
|
+
nextAction: "Continue only after required checks pass."
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (pr.reviewDecision === "REVIEW_REQUIRED") {
|
|
221
|
+
return {
|
|
222
|
+
observed: true,
|
|
223
|
+
reviewDecision: "REVIEW_REQUIRED",
|
|
224
|
+
submittedReviewAuthorCanPushToRepository,
|
|
225
|
+
status: "still-required",
|
|
226
|
+
nextAction: submittedReviewAuthorCanPushToRepository === false ? "GitHub still requires a qualifying approval; the submitted reviewer App review has no repository write access. Inspect the active rule and the App installation Contents grant, then obtain approval from an eligible independent reviewer." : "GitHub still requires a qualifying approval. Inspect the active rule and obtain approval from an eligible independent reviewer; do not change actors or protections automatically."
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (pr.reviewDecision === "CHANGES_REQUESTED") {
|
|
153
230
|
return {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
231
|
+
observed: true,
|
|
232
|
+
reviewDecision: "CHANGES_REQUESTED",
|
|
233
|
+
submittedReviewAuthorCanPushToRepository,
|
|
234
|
+
status: "changes-requested",
|
|
235
|
+
nextAction: "Resolve the blocking review and obtain a fresh exact-head independent approval."
|
|
159
236
|
};
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
observed: true,
|
|
240
|
+
reviewDecision: null,
|
|
241
|
+
submittedReviewAuthorCanPushToRepository,
|
|
242
|
+
status: "unknown",
|
|
243
|
+
nextAction: "Inspect the PR review requirement in GitHub before merge; no required-review decision was exposed."
|
|
244
|
+
};
|
|
160
245
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
246
|
+
function parseReviewArtifact(raw) {
|
|
247
|
+
const value = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
248
|
+
return ReviewArtifactSchema.parse(value);
|
|
164
249
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
throw new Error('Artifact identity differs.');
|
|
185
|
-
return artifact;
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
throw new DeliveryError('GitHub review artifact binding is missing, invalid or ambiguous; obtain a fresh review.');
|
|
189
|
-
}
|
|
250
|
+
function parseGitHubReviewArtifact(body) {
|
|
251
|
+
try {
|
|
252
|
+
if (typeof body !== "string" || Buffer.byteLength(body, "utf8") > 64 * 1024) throw new Error("Invalid size.");
|
|
253
|
+
const markers = body.match(/<!-- ai-delivery-review-artifact:[\s\S]*?-->/gu) ?? [];
|
|
254
|
+
const payloads = body.match(/<!-- ai-delivery-review-artifact-data:[\s\S]*?-->/gu) ?? [];
|
|
255
|
+
if (markers.length !== 1 || payloads.length !== 1) throw new Error("Ambiguous binding.");
|
|
256
|
+
const id = markers[0].match(/^<!-- ai-delivery-review-artifact: (sha256:[a-f0-9]{64}) -->$/u)?.[1];
|
|
257
|
+
const encoded = payloads[0].match(/^<!-- ai-delivery-review-artifact-data: ([A-Za-z0-9_-]+) -->$/u)?.[1];
|
|
258
|
+
if (!id || !encoded) throw new Error("Invalid binding.");
|
|
259
|
+
const bytes = Buffer.from(encoded, "base64url");
|
|
260
|
+
const json = bytes.toString("utf8");
|
|
261
|
+
if (bytes.toString("base64url") !== encoded || !Buffer.from(json, "utf8").equals(bytes))
|
|
262
|
+
throw new Error("Invalid encoding.");
|
|
263
|
+
const artifact = parseReviewArtifact(json);
|
|
264
|
+
if (artifact.artifactId !== id) throw new Error("Artifact identity differs.");
|
|
265
|
+
return artifact;
|
|
266
|
+
} catch {
|
|
267
|
+
throw new DeliveryError("GitHub review artifact binding is missing, invalid or ambiguous; obtain a fresh review.");
|
|
268
|
+
}
|
|
190
269
|
}
|
|
191
270
|
function githubReviewBody(artifact) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
271
|
+
ReviewArtifactSchema.parse(artifact);
|
|
272
|
+
const metadata = artifact.verdictFileSha256 === void 0 ? "" : `
|
|
273
|
+
|
|
274
|
+
Verdict: ${artifact.verdict}
|
|
275
|
+
Requested model/effort: ${artifact.requestedModel} / ${artifact.requestedEffort}
|
|
276
|
+
Effective model/effort: ${artifact.effectiveModel} / ${artifact.effectiveEffort}
|
|
277
|
+
Elapsed milliseconds: ${artifact.elapsedMs}
|
|
278
|
+
Verdict-file SHA256: ${artifact.verdictFileSha256}
|
|
279
|
+
Findings: ${artifact.findings.length ? artifact.findings.join("; ") : "none"}`;
|
|
280
|
+
const body = `${artifact.summary}${metadata}
|
|
281
|
+
|
|
282
|
+
<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->
|
|
283
|
+
<!-- ai-delivery-review-artifact-data: ${Buffer.from(JSON.stringify(artifact)).toString("base64url")} -->`;
|
|
284
|
+
if (Buffer.byteLength(body) > 64 * 1024)
|
|
285
|
+
throw new DeliveryError("Review body exceeds the 64 KiB publication limit; provide a concise verdict.");
|
|
286
|
+
parseGitHubReviewArtifact(body);
|
|
287
|
+
return body;
|
|
196
288
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
289
|
+
async function readGitHubPrPaths(context, prNumber, changedFiles, claimed) {
|
|
290
|
+
const files = [];
|
|
291
|
+
const renamed = /* @__PURE__ */ new Set();
|
|
292
|
+
for (let page = 1; page <= 30; page++) {
|
|
293
|
+
const batch = (await context.clients.rest.pulls.listFiles({ ...context.repo, pull_number: prNumber, page, per_page: 100 })).data;
|
|
294
|
+
files.push(...batch.map((file) => file.filename));
|
|
295
|
+
for (const file of batch)
|
|
296
|
+
if (file.status === "renamed" && file.previous_filename) renamed.add(file.previous_filename);
|
|
297
|
+
if (batch.length < 100) break;
|
|
298
|
+
}
|
|
299
|
+
if (!Number.isSafeInteger(changedFiles) || files.length !== changedFiles || new Set(files).size !== files.length)
|
|
300
|
+
throw new DeliveryError("Independent review scope is incomplete or differs from the remote PR diff.");
|
|
301
|
+
const current = new Set(files);
|
|
302
|
+
if (claimed && digestValue([...new Set(claimed.filter((path) => current.has(path) || !renamed.has(path)))].sort()) !== digestValue(files.sort()))
|
|
303
|
+
throw new DeliveryError("Independent review scope differs from the canonical remote rename inventory.");
|
|
304
|
+
return files.sort();
|
|
208
305
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
306
|
+
async function readGitHubPrScopeHash(context, prNumber, changedFiles) {
|
|
307
|
+
return digestValue(await readGitHubPrPaths(context, prNumber, changedFiles));
|
|
308
|
+
}
|
|
309
|
+
async function readGitHubReviewBase(context, prNumber, expectedHead) {
|
|
310
|
+
const pr = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
311
|
+
if (pr.number !== prNumber || pr.state !== "open" || pr.head.sha !== expectedHead || !Sha.safeParse(pr.base.sha).success)
|
|
312
|
+
throw new DeliveryError("Review comparison changed; obtain a fresh review.");
|
|
313
|
+
const comparison = (await context.clients.rest.repos.compareCommitsWithBasehead({
|
|
314
|
+
...context.repo,
|
|
315
|
+
basehead: `${pr.base.sha}...${expectedHead}`,
|
|
316
|
+
per_page: 1
|
|
317
|
+
})).data;
|
|
318
|
+
return ReviewBase.parse({ baseSha: pr.base.sha, mergeBaseSha: comparison.merge_base_commit.sha });
|
|
319
|
+
}
|
|
320
|
+
function reviewArtifactApproval(input) {
|
|
321
|
+
const { artifact, classification, config } = input;
|
|
322
|
+
ReviewArtifactSchema.parse(artifact);
|
|
323
|
+
if (artifact.verdict !== "approve" || artifact.issueNumber !== input.issueNumber || artifact.authorIdentity !== config.roles.author.identity || artifact.reviewerIdentity !== config.roles.reviewer.identity || artifact.head.sha !== classification.head.sha || artifact.head.tree !== classification.head.tree || artifact.diffScopeHash !== digestValue(classification.changedPaths) || input.prNumber !== void 0 && artifact.prNumber !== null && artifact.prNumber !== input.prNumber) {
|
|
324
|
+
throw new DeliveryError("Independent review artifact is stale, foreign, rejected, or covers another scope.");
|
|
325
|
+
}
|
|
326
|
+
return RepositoryApprovalBindingSchema.parse({
|
|
327
|
+
authorIdentity: artifact.authorIdentity,
|
|
328
|
+
diffScopeHash: artifact.diffScopeHash,
|
|
329
|
+
head: artifact.head,
|
|
330
|
+
result: "approved",
|
|
331
|
+
reviewerIdentity: artifact.reviewerIdentity,
|
|
332
|
+
reviewReceiptId: artifact.artifactId
|
|
333
|
+
});
|
|
230
334
|
}
|
|
231
335
|
function receiptPath(repoRoot, issueNumber, headSha) {
|
|
232
|
-
|
|
336
|
+
return join(gitCommonDir(repoRoot), "ai-delivery", "reviews", String(issueNumber), `${headSha}.json`);
|
|
233
337
|
}
|
|
234
338
|
function prepublicationPath(repoRoot, issueNumber, headSha) {
|
|
235
|
-
|
|
339
|
+
return join(gitCommonDir(repoRoot), "ai-delivery", "reviews", String(issueNumber), `${headSha}.prepublication.json`);
|
|
236
340
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
341
|
+
function savePrepublicationArtifact(input) {
|
|
342
|
+
if (input.artifact.prNumber !== null) throw new DeliveryError("Prepublication review must have a null PR number.");
|
|
343
|
+
reviewArtifactApproval(input);
|
|
344
|
+
writePrivateJsonFileAtomically(
|
|
345
|
+
prepublicationPath(input.repoRoot, input.issueNumber, input.artifact.head.sha),
|
|
346
|
+
input.artifact
|
|
347
|
+
);
|
|
242
348
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
return ReviewArtifactSchema.parse(raw);
|
|
349
|
+
function loadPrepublicationArtifact(repoRoot, issueNumber, headSha) {
|
|
350
|
+
let raw;
|
|
351
|
+
try {
|
|
352
|
+
raw = JSON.parse(assertPrivateFile(prepublicationPath(repoRoot, issueNumber, headSha)).toString("utf8"));
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (error.code === "ENOENT") return null;
|
|
355
|
+
throw new DeliveryError("Stored prepublication review is unreadable.");
|
|
356
|
+
}
|
|
357
|
+
return ReviewArtifactSchema.parse(raw);
|
|
254
358
|
}
|
|
255
359
|
async function listAllReviews(context, prNumber) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
360
|
+
const reviews = [];
|
|
361
|
+
for (let page = 1; page <= 20; page += 1) {
|
|
362
|
+
const result = await context.clients.rest.pulls.listReviews({
|
|
363
|
+
...context.repo,
|
|
364
|
+
pull_number: prNumber,
|
|
365
|
+
per_page: 100,
|
|
366
|
+
page
|
|
367
|
+
});
|
|
368
|
+
reviews.push(...result.data);
|
|
369
|
+
if (result.data.length < 100) return reviews;
|
|
370
|
+
}
|
|
371
|
+
throw new DeliveryError("Review history exceeds the bounded readback window.");
|
|
372
|
+
}
|
|
373
|
+
class ReviewSubmissionError extends DeliveryError {
|
|
374
|
+
constructor(message, submission) {
|
|
375
|
+
super(`${message} Reconcile this artifact's remote review before retrying; no automatic retry was attempted.`);
|
|
376
|
+
this.submission = submission;
|
|
377
|
+
}
|
|
378
|
+
submission;
|
|
379
|
+
}
|
|
380
|
+
async function validateReviewTarget(context, artifact, prNumber) {
|
|
381
|
+
const pr = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
382
|
+
if (pr.number !== prNumber || pr.head.sha !== artifact.head.sha || pr.state !== "open" || pr.base.repo?.full_name.toLowerCase() !== context.config.repository.toLowerCase() || pr.head.repo?.full_name.toLowerCase() !== context.config.repository.toLowerCase())
|
|
383
|
+
throw new DeliveryError("PR identity or head changed before formal review.");
|
|
384
|
+
const commit = (await context.clients.rest.git.getCommit({ ...context.repo, commit_sha: artifact.head.sha })).data;
|
|
385
|
+
if (commit.sha !== artifact.head.sha || commit.tree.sha !== artifact.head.tree)
|
|
386
|
+
throw new DeliveryError("Independent review tree differs from the remote commit.");
|
|
387
|
+
const reviewPaths = await readGitHubPrPaths(context, prNumber, pr.changed_files, artifact.changedPaths);
|
|
388
|
+
if (artifact.changedPaths === void 0 && artifact.diffScopeHash !== digestValue(reviewPaths))
|
|
389
|
+
throw new DeliveryError("Independent review scope is incomplete or differs from the remote PR diff.");
|
|
390
|
+
if (artifact.reviewBase && digestValue(artifact.reviewBase) !== digestValue(await readGitHubReviewBase(context, prNumber, artifact.head.sha)))
|
|
391
|
+
throw new DeliveryError("Review comparison changed; obtain a fresh review.");
|
|
392
|
+
return { ...pr, reviewPaths };
|
|
393
|
+
}
|
|
394
|
+
async function qualifyReviewReuse(context, artifact, prNumber, actor) {
|
|
395
|
+
try {
|
|
396
|
+
const request = artifact.reuse;
|
|
397
|
+
if (basename(request.verificationResultPath) !== "result.json") throw new Error("Verification is not finalized.");
|
|
398
|
+
const review = (await context.clients.rest.pulls.getReview({
|
|
399
|
+
...context.repo,
|
|
400
|
+
pull_number: prNumber,
|
|
401
|
+
review_id: request.fromReviewId
|
|
402
|
+
})).data;
|
|
403
|
+
const original = parseGitHubReviewArtifact(review.body);
|
|
404
|
+
if (review.id !== request.fromReviewId || review.state !== "APPROVED" || review.commit_id !== original.head.sha || review.user?.login.toLowerCase() !== actor.toLowerCase() || original.verdict !== "approve" || artifact.verdict !== "approve" || original.prNumber !== prNumber || original.issueNumber !== artifact.issueNumber || original.authorIdentity !== artifact.authorIdentity || original.reviewerIdentity !== artifact.reviewerIdentity || !original.reviewBase || !artifact.reviewBase || original.head.sha === artifact.head.sha)
|
|
405
|
+
throw new Error("Original comparison unavailable.");
|
|
406
|
+
const root = context.root;
|
|
407
|
+
const base = original.reviewBase;
|
|
408
|
+
const next = artifact.reviewBase;
|
|
409
|
+
const mergeBase = (baseSha, headSha) => {
|
|
410
|
+
const sha = git(root, "merge-base", "--all", baseSha, headSha);
|
|
411
|
+
return Sha.parse(sha);
|
|
412
|
+
};
|
|
413
|
+
if (mergeBase(base.baseSha, original.head.sha) !== base.mergeBaseSha || mergeBase(next.baseSha, artifact.head.sha) !== next.mergeBaseSha || gitExitCode(root, "merge-base", "--is-ancestor", base.baseSha, next.baseSha) !== 0 || gitExitCode(root, "merge-base", "--is-ancestor", base.mergeBaseSha, next.mergeBaseSha) !== 0 || git(root, "rev-parse", `${original.head.sha}^{tree}`) !== original.head.tree)
|
|
414
|
+
throw new Error("History differs.");
|
|
415
|
+
const run = (args, input) => execFileSync(GIT_EXECUTABLE, [...inertGitArguments(root), ...args], {
|
|
416
|
+
cwd: root,
|
|
417
|
+
env: gitEnvironment(),
|
|
418
|
+
input,
|
|
419
|
+
timeout: 1e4,
|
|
420
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
421
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
422
|
+
});
|
|
423
|
+
const diff = (from, to) => run([
|
|
424
|
+
"diff",
|
|
425
|
+
"--no-ext-diff",
|
|
426
|
+
"--no-textconv",
|
|
427
|
+
"--no-color",
|
|
428
|
+
"--no-renames",
|
|
429
|
+
"--no-relative",
|
|
430
|
+
"--src-prefix=a/",
|
|
431
|
+
"--dst-prefix=b/",
|
|
432
|
+
"--ignore-submodules=none",
|
|
433
|
+
"--binary",
|
|
434
|
+
"--full-index",
|
|
435
|
+
from,
|
|
436
|
+
to,
|
|
437
|
+
"--"
|
|
438
|
+
]);
|
|
439
|
+
const before = diff(base.mergeBaseSha, original.head.sha);
|
|
440
|
+
const after = diff(next.mergeBaseSha, artifact.head.sha);
|
|
441
|
+
const patch = run(["patch-id", "--stable"], before);
|
|
442
|
+
if (!before.length || !before.equals(after) || !patch.equals(run(["patch-id", "--stable"], after)) || !Sha.safeParse(patch.toString("utf8").split(/\s/u)[0]).success)
|
|
443
|
+
throw new Error("Patch differs.");
|
|
444
|
+
const paths = [
|
|
445
|
+
...new Set(
|
|
446
|
+
[
|
|
447
|
+
[base.mergeBaseSha, original.head.sha],
|
|
448
|
+
[next.mergeBaseSha, artifact.head.sha]
|
|
449
|
+
].flatMap(
|
|
450
|
+
([from, to]) => run(["diff", "--no-ext-diff", "--no-textconv", "--no-renames", "--name-only", "-z", from, to, "--"]).toString("utf8").split("\0").filter(Boolean)
|
|
451
|
+
)
|
|
452
|
+
)
|
|
453
|
+
];
|
|
454
|
+
const touched = (from, to) => run([
|
|
455
|
+
"--literal-pathspecs",
|
|
456
|
+
"log",
|
|
457
|
+
"--format=",
|
|
458
|
+
"--name-only",
|
|
459
|
+
"-z",
|
|
460
|
+
"--full-history",
|
|
461
|
+
"--diff-merges=separate",
|
|
462
|
+
`${from}..${to}`,
|
|
463
|
+
"--",
|
|
464
|
+
...paths
|
|
465
|
+
]).length !== 0;
|
|
466
|
+
if (touched(base.mergeBaseSha, next.mergeBaseSha) || touched(base.baseSha, next.baseSha))
|
|
467
|
+
throw new Error("Base touched review paths.");
|
|
468
|
+
const gates = ["format", "lint", "types", "build", "tests", "inventory"];
|
|
469
|
+
const report = z.object({
|
|
470
|
+
schemaVersion: z.literal("contributor-checks@1"),
|
|
471
|
+
scope: z.literal("full"),
|
|
472
|
+
status: z.literal("passed"),
|
|
473
|
+
exitCode: z.literal(0),
|
|
474
|
+
fullSuccess: z.literal(true),
|
|
475
|
+
omitted: z.array(Text).length(0),
|
|
476
|
+
completedAt: z.iso.datetime(),
|
|
477
|
+
verifiedHead: z.strictObject({ sha: Sha, tree: Sha }),
|
|
478
|
+
gates: z.array(Text),
|
|
479
|
+
commands: z.array(
|
|
480
|
+
z.object({
|
|
481
|
+
stage: Text,
|
|
482
|
+
status: z.literal("passed"),
|
|
483
|
+
exitCode: z.literal(0),
|
|
484
|
+
cleanupConfirmed: z.literal(true)
|
|
485
|
+
})
|
|
486
|
+
)
|
|
487
|
+
}).parse(
|
|
488
|
+
JSON.parse(assertPrivateFile(request.verificationResultPath, { maxBytes: 4 * 1024 * 1024 }).toString("utf8"))
|
|
489
|
+
);
|
|
490
|
+
if (digestValue(report.gates) !== digestValue(gates) || digestValue(report.commands.map((command) => command.stage)) !== digestValue(gates) || digestValue(report.verifiedHead) !== digestValue(artifact.head) || git(root, "rev-parse", "HEAD") !== artifact.head.sha || git(root, "rev-parse", "HEAD^{tree}") !== artifact.head.tree || git(root, "status", "--porcelain", "--untracked-files=all") !== "")
|
|
491
|
+
throw new Error("Exact-head required verification unavailable.");
|
|
492
|
+
return {
|
|
493
|
+
reviewId: review.id,
|
|
494
|
+
artifactId: original.artifactId,
|
|
495
|
+
oldHead: original.head.sha,
|
|
496
|
+
newHead: artifact.head.sha,
|
|
497
|
+
reason: "Exact patch, untouched base paths and successful exact-head required verification."
|
|
498
|
+
};
|
|
499
|
+
} catch {
|
|
500
|
+
throw new DeliveryError(
|
|
501
|
+
"Clean-rebase reuse lacks complete unchanged-content and verification proof; obtain a fresh review."
|
|
502
|
+
);
|
|
503
|
+
}
|
|
269
504
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
505
|
+
async function submitReview(input) {
|
|
506
|
+
const { context, issueNumber, prNumber } = input;
|
|
507
|
+
let artifact = input.artifact;
|
|
508
|
+
ReviewArtifactSchema.parse(artifact);
|
|
509
|
+
if (artifact.issueNumber !== issueNumber || artifact.authorIdentity !== context.config.roles.author.identity || artifact.reviewerIdentity !== context.config.roles.reviewer.identity || artifact.prNumber !== null && artifact.prNumber !== prNumber)
|
|
510
|
+
throw new DeliveryError("Independent review artifact is foreign or rejected.");
|
|
511
|
+
if (context.clients.authSource !== "app" || context.clients.role !== "reviewer" || !context.clients.appActorLogin)
|
|
512
|
+
throw new DeliveryError("Formal review requires the independent reviewer GitHub App role.");
|
|
513
|
+
const pr = await validateReviewTarget(context, artifact, prNumber);
|
|
514
|
+
const actor = await context.clients.appActorLogin();
|
|
515
|
+
if (!actor || !pr.user?.login || actor.toLowerCase() === pr.user.login.toLowerCase())
|
|
516
|
+
throw new DeliveryError("Reviewer GitHub actor must differ from PR author.");
|
|
517
|
+
if (artifact.reusedFrom) throw new DeliveryError("Reuse requires current comparison proof; obtain a fresh review.");
|
|
518
|
+
const { artifactId: _artifactId, reuse, ...content } = artifact;
|
|
519
|
+
const canonical = {
|
|
520
|
+
...content,
|
|
521
|
+
...artifact.changedPaths === void 0 ? {} : { changedPaths: pr.reviewPaths, diffScopeHash: digestValue(pr.reviewPaths) },
|
|
522
|
+
...reuse === void 0 ? {} : { reusedFrom: await qualifyReviewReuse(context, artifact, prNumber, actor) }
|
|
523
|
+
};
|
|
524
|
+
artifact = ReviewArtifactSchema.parse({ ...canonical, artifactId: digestValue(canonical) });
|
|
525
|
+
const body = githubReviewBody(artifact);
|
|
526
|
+
const expectedState = artifact.verdict === "approve" ? "APPROVED" : "CHANGES_REQUESTED";
|
|
527
|
+
const event = artifact.verdict === "approve" ? "APPROVE" : "REQUEST_CHANGES";
|
|
528
|
+
const marker = `<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->`;
|
|
529
|
+
const history = await listAllReviews(context, prNumber);
|
|
530
|
+
const matches = history.filter((review) => review.body?.includes(marker));
|
|
531
|
+
if (matches.length > 1) throw new DeliveryError("Conflicting GitHub reviews claim the same artifact identity.");
|
|
532
|
+
const prior = matches[0];
|
|
533
|
+
if (prior && (prior.state !== expectedState || prior.commit_id !== artifact.head.sha || prior.user?.login.toLowerCase() !== actor.toLowerCase() || !prior.html_url || parseGitHubReviewArtifact(prior.body).artifactId !== artifact.artifactId))
|
|
534
|
+
throw new DeliveryError("Prior GitHub review marker conflicts with exact-head approval.");
|
|
535
|
+
const fresh = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
536
|
+
if (fresh.head.sha !== artifact.head.sha || fresh.base.sha !== pr.base.sha || fresh.state !== "open")
|
|
537
|
+
throw new DeliveryError("PR moved during independent review validation.");
|
|
538
|
+
if (input.dryRun) return { dryRun: true, artifactId: artifact.artifactId, headSha: artifact.head.sha };
|
|
539
|
+
const pending = {
|
|
540
|
+
artifactId: artifact.artifactId,
|
|
541
|
+
repository: context.config.repository,
|
|
542
|
+
headSha: artifact.head.sha,
|
|
543
|
+
prNumber
|
|
544
|
+
};
|
|
545
|
+
let submitted;
|
|
546
|
+
try {
|
|
547
|
+
submitted = prior ?? (await context.clients.rest.pulls.createReview({
|
|
548
|
+
...context.repo,
|
|
549
|
+
pull_number: prNumber,
|
|
550
|
+
commit_id: artifact.head.sha,
|
|
551
|
+
body,
|
|
552
|
+
event
|
|
553
|
+
})).data;
|
|
554
|
+
} catch {
|
|
555
|
+
throw new ReviewSubmissionError("Review submission acknowledgement is unknown.", pending);
|
|
556
|
+
}
|
|
557
|
+
const known = {
|
|
558
|
+
...pending,
|
|
559
|
+
...submitted.id ? { githubReviewId: submitted.id } : {},
|
|
560
|
+
...submitted.html_url ? { githubReviewUrl: submitted.html_url } : {}
|
|
561
|
+
};
|
|
562
|
+
try {
|
|
563
|
+
if (!submitted.id || submitted.state !== expectedState || submitted.commit_id !== artifact.head.sha || submitted.user?.login.toLowerCase() !== actor.toLowerCase() || !submitted.html_url)
|
|
564
|
+
throw new DeliveryError("GitHub did not return complete exact-head independent approval.");
|
|
565
|
+
const content2 = {
|
|
566
|
+
artifact,
|
|
567
|
+
repository: context.config.repository,
|
|
568
|
+
baseSha: pr.base.sha,
|
|
569
|
+
headSha: artifact.head.sha,
|
|
570
|
+
githubReviewId: submitted.id,
|
|
571
|
+
githubReviewUrl: submitted.html_url,
|
|
572
|
+
login: submitted.user.login,
|
|
573
|
+
prNumber,
|
|
574
|
+
schemaVersion: "ai-delivery.github-review@1",
|
|
575
|
+
state: expectedState
|
|
340
576
|
};
|
|
341
|
-
const receipt = { ...
|
|
577
|
+
const receipt = { ...content2, receiptId: digestValue(content2) };
|
|
342
578
|
const readback = (await context.clients.rest.pulls.getReview({ ...context.repo, pull_number: prNumber, review_id: submitted.id })).data;
|
|
343
|
-
if (readback.id !== receipt.githubReviewId ||
|
|
344
|
-
|
|
345
|
-
readback.state !== 'APPROVED' ||
|
|
346
|
-
readback.commit_id !== receipt.headSha ||
|
|
347
|
-
readback.user?.login !== receipt.login ||
|
|
348
|
-
parseGitHubReviewArtifact(readback.body).artifactId !== artifact.artifactId)
|
|
349
|
-
throw new DeliveryError('GitHub exact-head App review readback disagrees.');
|
|
579
|
+
if (readback.id !== receipt.githubReviewId || readback.html_url !== receipt.githubReviewUrl || readback.state !== expectedState || readback.commit_id !== receipt.headSha || readback.user?.login !== receipt.login || parseGitHubReviewArtifact(readback.body).artifactId !== artifact.artifactId)
|
|
580
|
+
throw new DeliveryError("GitHub exact-head App review readback disagrees.");
|
|
350
581
|
const current = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
351
|
-
if (current.head.sha !== artifact.head.sha || current.base.sha !== pr.base.sha || current.state !==
|
|
352
|
-
|
|
582
|
+
if (current.head.sha !== artifact.head.sha || current.base.sha !== pr.base.sha || current.state !== "open")
|
|
583
|
+
throw new DeliveryError("PR moved during independent review submission; approval is not current.");
|
|
353
584
|
return receipt;
|
|
585
|
+
} catch (error) {
|
|
586
|
+
throw new ReviewSubmissionError(
|
|
587
|
+
error instanceof DeliveryError ? error.message : "Review post-submission readback is unavailable.",
|
|
588
|
+
known
|
|
589
|
+
);
|
|
590
|
+
}
|
|
354
591
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
return SubmittedReviewReceiptSchema.parse(raw);
|
|
592
|
+
function loadSubmittedReview(repoRoot, issueNumber, headSha) {
|
|
593
|
+
let raw;
|
|
594
|
+
try {
|
|
595
|
+
raw = JSON.parse(assertPrivateFile(receiptPath(repoRoot, issueNumber, headSha)).toString("utf8"));
|
|
596
|
+
} catch (error) {
|
|
597
|
+
if (error.code === "ENOENT") return null;
|
|
598
|
+
throw new DeliveryError("Stored review receipt is unreadable.");
|
|
599
|
+
}
|
|
600
|
+
return SubmittedReviewReceiptSchema.parse(raw);
|
|
366
601
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
parseGitHubReviewArtifact(review.body).artifactId !== receipt.artifact.artifactId) {
|
|
376
|
-
throw new DeliveryError('GitHub exact-head review no longer matches the stored receipt.');
|
|
377
|
-
}
|
|
602
|
+
async function assertSubmittedReviewCurrent(context, receipt) {
|
|
603
|
+
SubmittedReviewReceiptSchema.parse(receipt);
|
|
604
|
+
const review = (await listAllReviews(context, receipt.prNumber)).find(
|
|
605
|
+
(candidate) => candidate.id === receipt.githubReviewId
|
|
606
|
+
);
|
|
607
|
+
if (!review || review.state !== "APPROVED" || review.commit_id !== receipt.headSha || review.user?.login !== receipt.login || review.html_url !== receipt.githubReviewUrl || parseGitHubReviewArtifact(review.body).artifactId !== receipt.artifact.artifactId) {
|
|
608
|
+
throw new DeliveryError("GitHub exact-head review no longer matches the stored receipt.");
|
|
609
|
+
}
|
|
378
610
|
}
|
|
379
|
-
|
|
611
|
+
export {
|
|
612
|
+
ReviewArtifactSchema,
|
|
613
|
+
ReviewSubmissionError,
|
|
614
|
+
ReviewVerdictSchema,
|
|
615
|
+
SubmittedReviewReceiptSchema,
|
|
616
|
+
assertReviewVerdictTarget,
|
|
617
|
+
assertSubmittedReviewCurrent,
|
|
618
|
+
buildReviewArtifact,
|
|
619
|
+
loadPrepublicationArtifact,
|
|
620
|
+
loadSubmittedReview,
|
|
621
|
+
parseGitHubReviewArtifact,
|
|
622
|
+
parseReviewArtifact,
|
|
623
|
+
parseReviewVerdict,
|
|
624
|
+
readGitHubPrScopeHash,
|
|
625
|
+
readGitHubReviewBase,
|
|
626
|
+
readRequiredReviewState,
|
|
627
|
+
reviewArtifactApproval,
|
|
628
|
+
savePrepublicationArtifact,
|
|
629
|
+
submitReview,
|
|
630
|
+
validateReviewTarget
|
|
631
|
+
};
|
|
632
|
+
//# sourceMappingURL=review.js.map
|