@aviaratech/ai-delivery 0.3.34 → 0.3.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +12 -206
- package/README.md +57 -506
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +76 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1746 -0
- package/dist/boardReconcile.test.js.map +7 -0
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +105 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +406 -485
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -25
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +434 -297
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +320 -14
- package/dist/config/deliveryConfig.js +472 -385
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +775 -584
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -477
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.d.ts +1 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +17 -12
- package/dist/dispatch.js +330 -322
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +16 -3
- package/dist/errors.js +104 -82
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +59 -19
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.js +73 -67
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +44 -51
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +3 -0
- package/dist/github/discovery.js +197 -201
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +53 -1
- package/dist/github/projectDelivery.js +623 -460
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.d.ts +5 -2
- package/dist/github/relationships.js +434 -333
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +103 -7
- package/dist/issue.js +2104 -1547
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +1004 -683
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1945 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1088 -593
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -90
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +790 -220
- package/dist/mcp/tools.js +267 -333
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1231
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1822 -1283
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +485 -305
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +132 -94
- package/dist/pr.js +1521 -1323
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +1678 -632
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +150 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +183 -0
- package/dist/readView.js +217 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +119 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +1204 -0
- package/dist/services/boardReconcileService.js +1445 -0
- package/dist/services/boardReconcileService.js.map +7 -0
- package/dist/services/deliveryAdmission.d.ts +2 -0
- package/dist/services/deliveryAdmission.js +129 -152
- package/dist/services/deliveryAdmission.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/services/worktreeRegistry.d.ts +27 -119
- package/dist/services/worktreeRegistry.js +765 -1182
- package/dist/services/worktreeRegistry.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +354 -350
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +305 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +463 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.js +84 -76
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.js +15 -18
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -19
- package/dist/verification.js +1020 -1929
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.js +24 -10
- package/dist/version.js.map +7 -1
- package/dist/worktree.d.ts +3 -15
- package/dist/worktree.js +97 -177
- package/dist/worktree.js.map +7 -1
- package/package.json +10 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
- package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3058
- package/dist/setup.test.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
package/dist/pr.test.js
CHANGED
|
@@ -1,669 +1,1715 @@
|
|
|
1
|
-
import assert from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
realpathSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
symlinkSync,
|
|
11
|
+
writeFileSync
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { addWorktreeEntry, listWorktreesStrict, removeWorktreeEntry } from "./services/worktreeRegistry.js";
|
|
16
|
+
import { describe, it } from "vitest";
|
|
17
|
+
import { ISSUE_CLI_DATA_DIR } from "./utils/filesystem.js";
|
|
18
|
+
import { publishPr, mergePr, finishIssue, prChecks, queueChecks } from "./pr.js";
|
|
19
|
+
import { digestValue } from "./delivery/common.js";
|
|
20
|
+
import { recordedBaseDrift, recordedZeroApproval } from "./fixtures/recordedGitHubFlows.js";
|
|
21
|
+
import * as prReaders from "./pr.js";
|
|
22
|
+
it("markers require their exact canonical footer/trailer", () => {
|
|
23
|
+
const bodyMarker = Reflect.get(prReaders, "hasDeliveryPrMarker");
|
|
24
|
+
const trailer = Reflect.get(prReaders, "hasDeliveryMergeTrailer");
|
|
25
|
+
assert.equal(typeof bodyMarker, "function");
|
|
26
|
+
assert.equal(typeof trailer, "function");
|
|
27
|
+
const marker = "<!-- ai-delivery:pr@1 -->";
|
|
28
|
+
assert.equal(bodyMarker(`Closes #17
|
|
29
|
+
|
|
30
|
+
Proof.
|
|
31
|
+
|
|
32
|
+
${marker}`), true);
|
|
33
|
+
assert.equal(bodyMarker(`Closes #17
|
|
34
|
+
|
|
35
|
+
Document ai-delivery:pr@1 semantics.
|
|
36
|
+
|
|
37
|
+
${marker}`), true);
|
|
38
|
+
assert.equal(bodyMarker(`Proof
|
|
39
|
+
|
|
40
|
+
\`\`\`md
|
|
41
|
+
${marker}
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
44
|
+
${marker}`), true);
|
|
45
|
+
assert.equal(bodyMarker(`Proof
|
|
46
|
+
|
|
47
|
+
> ${marker}
|
|
48
|
+
|
|
49
|
+
${marker}`), true);
|
|
50
|
+
for (const example of [
|
|
51
|
+
`Proof
|
|
52
|
+
|
|
53
|
+
${marker}`,
|
|
54
|
+
`Proof
|
|
55
|
+
|
|
56
|
+
${marker}`,
|
|
57
|
+
`Proof
|
|
58
|
+
|
|
59
|
+
~~~md
|
|
60
|
+
${marker}
|
|
61
|
+
~~~`,
|
|
62
|
+
`Proof \`multiline
|
|
63
|
+
text ${marker}
|
|
64
|
+
text\`.`,
|
|
65
|
+
`Escaped \\${marker} remains literal.`,
|
|
66
|
+
`The literal marker is \`${marker}\`.`,
|
|
67
|
+
`The literal marker is \`\`before \` ${marker}\`\`.`,
|
|
68
|
+
`Example \`multiline
|
|
69
|
+
text ${marker}
|
|
70
|
+
text\`.`,
|
|
71
|
+
"An unmatched backtick is literal: `"
|
|
72
|
+
])
|
|
73
|
+
assert.equal(bodyMarker(`Closes #17
|
|
74
|
+
|
|
75
|
+
${example}
|
|
76
|
+
|
|
77
|
+
${marker}`), true, example);
|
|
78
|
+
assert.equal(bodyMarker(`Closes #17
|
|
79
|
+
|
|
80
|
+
Escaped \\\`${marker} remains active.
|
|
81
|
+
|
|
82
|
+
${marker}`), false);
|
|
83
|
+
for (const indent of ["", " ", " ", " "])
|
|
84
|
+
assert.equal(
|
|
85
|
+
bodyMarker(`Closes #17
|
|
86
|
+
|
|
87
|
+
Example \`multiline
|
|
88
|
+
${indent}${marker}
|
|
89
|
+
text\`.
|
|
90
|
+
|
|
91
|
+
${marker}`),
|
|
92
|
+
false,
|
|
93
|
+
"A comment block interrupts the paragraph before inline code parsing"
|
|
94
|
+
);
|
|
95
|
+
for (const boundary of ["=", "--", "___"])
|
|
96
|
+
assert.equal(bodyMarker(`Proof \`open
|
|
97
|
+
${boundary}
|
|
98
|
+
text ${marker}
|
|
99
|
+
close\`.
|
|
100
|
+
|
|
101
|
+
${marker}`), false);
|
|
102
|
+
for (const body of [
|
|
103
|
+
`Proof
|
|
104
|
+
|
|
105
|
+
<div>
|
|
106
|
+
\`\`\`
|
|
107
|
+
${marker}
|
|
108
|
+
\`\`\`
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
${marker}`,
|
|
112
|
+
`Proof
|
|
113
|
+
|
|
114
|
+
<?instruction
|
|
115
|
+
|
|
116
|
+
${marker}`,
|
|
117
|
+
`Proof
|
|
118
|
+
|
|
119
|
+
<![CDATA[
|
|
120
|
+
|
|
121
|
+
${marker}`,
|
|
122
|
+
`Proof \`multiline
|
|
123
|
+
# Heading
|
|
124
|
+
text ${marker}
|
|
125
|
+
text\`.
|
|
126
|
+
|
|
127
|
+
${marker}`,
|
|
128
|
+
`Proof \`multiline
|
|
129
|
+
- New block
|
|
130
|
+
text ${marker}
|
|
131
|
+
text\`.
|
|
132
|
+
|
|
133
|
+
${marker}`,
|
|
134
|
+
`Proof
|
|
135
|
+
|
|
136
|
+
\`\`\`\`
|
|
137
|
+
${marker}
|
|
138
|
+
\`\`\`
|
|
139
|
+
|
|
140
|
+
${marker}`,
|
|
141
|
+
`Proof
|
|
142
|
+
|
|
143
|
+
\`\`\`
|
|
144
|
+
${marker}
|
|
145
|
+
~~~
|
|
146
|
+
|
|
147
|
+
${marker}`,
|
|
148
|
+
`Proof
|
|
149
|
+
|
|
150
|
+
<!-- outer comment
|
|
151
|
+
|
|
152
|
+
${marker}`,
|
|
153
|
+
`Proof
|
|
154
|
+
|
|
155
|
+
<pre>
|
|
156
|
+
|
|
157
|
+
${marker}`,
|
|
158
|
+
`Proof
|
|
159
|
+
${marker}
|
|
160
|
+
|
|
161
|
+
${marker}`,
|
|
162
|
+
`Proof
|
|
163
|
+
|
|
164
|
+
- Container
|
|
165
|
+
${marker}
|
|
166
|
+
|
|
167
|
+
${marker}`,
|
|
168
|
+
marker,
|
|
169
|
+
`Proof
|
|
170
|
+
${marker}`,
|
|
171
|
+
`Proof
|
|
172
|
+
|
|
173
|
+
> ${marker}`,
|
|
174
|
+
`Proof
|
|
175
|
+
|
|
176
|
+
\`\`\`
|
|
177
|
+
${marker}
|
|
178
|
+
\`\`\``,
|
|
179
|
+
`Proof
|
|
180
|
+
|
|
181
|
+
${marker}
|
|
182
|
+
extra`,
|
|
183
|
+
`Proof
|
|
184
|
+
|
|
185
|
+
${marker}
|
|
186
|
+
|
|
187
|
+
${marker}`,
|
|
188
|
+
`Proof
|
|
189
|
+
|
|
190
|
+
${marker}
|
|
191
|
+
`
|
|
192
|
+
])
|
|
193
|
+
assert.equal(bodyMarker(body), false, body);
|
|
194
|
+
for (const message of ["Title\n\nDelivered-by: ai-delivery", "Title\n\nDelivered-by: ai-delivery\n"])
|
|
195
|
+
assert.equal(trailer(message), true);
|
|
196
|
+
assert.equal(trailer("Document Delivered-by: ai-delivery in the guide\n\nDelivered-by: ai-delivery"), true);
|
|
197
|
+
assert.equal(trailer("Document `multiline\nDelivered-by: ai-delivery\nexample`\n\nDelivered-by: ai-delivery"), true);
|
|
198
|
+
for (const message of [
|
|
199
|
+
"Delivered-by: ai-delivery\nextra",
|
|
200
|
+
"Title\n\n> Delivered-by: ai-delivery",
|
|
201
|
+
"Title\n\n```\nDelivered-by: ai-delivery\n```",
|
|
202
|
+
"Title\n\nDelivered-by: ai-delivery\n\nDelivered-by: ai-delivery",
|
|
203
|
+
"Title\n\nDelivered-by: other"
|
|
204
|
+
])
|
|
205
|
+
assert.equal(trailer(message), false, message);
|
|
206
|
+
});
|
|
207
|
+
async function boardFacts(context) {
|
|
208
|
+
const read = Reflect.get(prReaders, "readPrBoardFacts");
|
|
209
|
+
assert.equal(typeof read, "function", "read-only PR board facts are available");
|
|
210
|
+
return read({ clients: context.clients, repo: context.repo }, 23);
|
|
211
|
+
}
|
|
212
|
+
function boardFixture(option = {}) {
|
|
213
|
+
const { context } = fixture();
|
|
214
|
+
const projection = recordedZeroApproval.repository.pullRequest;
|
|
215
|
+
const head2 = projection.headRefOid;
|
|
216
|
+
const base = projection.baseRefOid;
|
|
217
|
+
const headRef = option.headRef ?? "issue/17";
|
|
218
|
+
const baseRef = option.baseRef ?? "main";
|
|
219
|
+
const calls = [];
|
|
220
|
+
let reads = 0;
|
|
221
|
+
const repository = { id: "REPO", nameWithOwner: "example/widget" };
|
|
222
|
+
const headRepository = option.fork ? { id: "FORK", nameWithOwner: "contributor/widget" } : repository;
|
|
223
|
+
const pr = () => ({
|
|
224
|
+
number: 23,
|
|
225
|
+
node_id: "PR23",
|
|
226
|
+
html_url: "https://github.com/example/widget/pull/23",
|
|
227
|
+
title: "Improve widget",
|
|
228
|
+
body: option.nonClosing ? "References example/widget#17\n\nProof." : "Closes #17\n\nProof.",
|
|
229
|
+
state: "open",
|
|
230
|
+
merged: false,
|
|
231
|
+
draft: option.draft ?? false,
|
|
232
|
+
mergeable: option.mergeable !== "CONFLICTING",
|
|
233
|
+
mergeable_state: "clean",
|
|
234
|
+
head: { sha: head2, ref: headRef, repo: { node_id: headRepository.id, full_name: headRepository.nameWithOwner } },
|
|
235
|
+
base: { sha: base, ref: baseRef, repo: { node_id: repository.id, full_name: repository.nameWithOwner } }
|
|
236
|
+
});
|
|
237
|
+
const run = { id: 10, name: "checks", head_sha: head2, app: { id: 7 }, status: "completed", conclusion: "success" };
|
|
238
|
+
context.clients.rest = {
|
|
239
|
+
request: async (route) => {
|
|
240
|
+
calls.push(route);
|
|
241
|
+
assert.ok(route.startsWith("GET "), "no native writes");
|
|
242
|
+
if (option.check === "requirements-unknown") throw { status: 403 };
|
|
243
|
+
if (route.endsWith("/rules/branches/{branch}"))
|
|
244
|
+
return {
|
|
245
|
+
status: 200,
|
|
246
|
+
headers: {},
|
|
247
|
+
data: option.check === "none" ? [] : [
|
|
248
|
+
{
|
|
249
|
+
type: "required_status_checks",
|
|
250
|
+
parameters: { required_status_checks: [{ context: "checks", integration_id: 7 }] }
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
};
|
|
254
|
+
assert.ok(route.endsWith("/protection"));
|
|
255
|
+
return { status: 200, headers: {}, data: { required_status_checks: null } };
|
|
256
|
+
},
|
|
257
|
+
pulls: {
|
|
258
|
+
get: async () => {
|
|
259
|
+
calls.push("pulls.get");
|
|
260
|
+
const result = pr();
|
|
261
|
+
if (++reads > 1) {
|
|
262
|
+
if (option.drift === "head") result.head.sha = "f".repeat(40);
|
|
263
|
+
if (option.drift === "base") result.base.sha = "e".repeat(40);
|
|
264
|
+
if (option.drift === "body") result.body += "\nChanged";
|
|
265
|
+
}
|
|
266
|
+
return { data: result };
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
checks: {
|
|
270
|
+
listForRef: async () => {
|
|
271
|
+
calls.push("checks.listForRef");
|
|
272
|
+
const check_runs = option.check === "missing" ? [] : option.check === "foreign" ? [{ ...run, app: { id: 8 } }] : option.check === "pending" ? [run, { ...run, id: 11, status: "in_progress", conclusion: null }] : option.check === "failed" ? [{ ...run, conclusion: "failure" }] : [run];
|
|
273
|
+
return {
|
|
274
|
+
status: 200,
|
|
275
|
+
headers: option.check === "truncated" ? { link: "next" } : {},
|
|
276
|
+
data: { total_count: check_runs.length, check_runs }
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
repos: {
|
|
281
|
+
getCombinedStatusForRef: async () => {
|
|
282
|
+
calls.push("repos.getCombinedStatusForRef");
|
|
283
|
+
return { status: 200, headers: {}, data: { sha: head2, total_count: 0, statuses: [] } };
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
git: {
|
|
287
|
+
getRef: async ({ ref }) => {
|
|
288
|
+
calls.push("git.getRef");
|
|
289
|
+
assert.equal(ref, `heads/${baseRef}`);
|
|
290
|
+
return {
|
|
291
|
+
data: {
|
|
292
|
+
ref: `refs/heads/${baseRef}`,
|
|
293
|
+
object: { type: "commit", sha: option.baseMoved ? "d".repeat(40) : base }
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
context.clients.graphql = (async (query) => {
|
|
300
|
+
assert.ok(query.trimStart().startsWith("query"), "no GraphQL writes");
|
|
301
|
+
if (query.includes("DeliveryReviewDecision")) {
|
|
302
|
+
calls.push("DeliveryReviewDecision");
|
|
303
|
+
if (option.unavailableReview) throw { status: 403 };
|
|
304
|
+
return {
|
|
305
|
+
repository: {
|
|
306
|
+
pullRequest: {
|
|
307
|
+
headRefOid: option.reviewHeadMoved ? "0".repeat(40) : head2,
|
|
308
|
+
...option.missingDecision ? {} : { reviewDecision: Object.hasOwn(option, "decision") ? option.decision : null }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
assert.ok(query.includes("DeliveryBoardPr"), "no extra review counts, approval or mutation queries");
|
|
314
|
+
calls.push("DeliveryBoardPr");
|
|
315
|
+
return {
|
|
316
|
+
repository: {
|
|
317
|
+
...repository,
|
|
318
|
+
pullRequest: {
|
|
319
|
+
id: "PR23",
|
|
320
|
+
number: 23,
|
|
321
|
+
state: "OPEN",
|
|
322
|
+
isDraft: option.draft ?? false,
|
|
323
|
+
headRefOid: head2,
|
|
324
|
+
baseRefOid: base,
|
|
325
|
+
headRefName: headRef,
|
|
326
|
+
baseRefName: baseRef,
|
|
327
|
+
baseRepository: repository,
|
|
328
|
+
headRepository,
|
|
329
|
+
mergeable: option.mergeable ?? "MERGEABLE",
|
|
330
|
+
mergeStateStatus: option.nativeState ?? "CLEAN",
|
|
331
|
+
closingIssuesReferences: {
|
|
332
|
+
nodes: option.nonClosing ? [] : [{ __typename: "Issue", id: "ISSUE17", number: 17, repository }],
|
|
333
|
+
pageInfo: { hasNextPage: option.linksIncomplete ?? false, endCursor: null }
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
36
337
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
338
|
+
});
|
|
339
|
+
return { context, calls, head: head2, base };
|
|
340
|
+
}
|
|
341
|
+
it("board accepts observed null with native CLEAN eligibility", async () => {
|
|
342
|
+
for (const option of [
|
|
343
|
+
{},
|
|
344
|
+
{ decision: "APPROVED" },
|
|
345
|
+
{ check: "none" },
|
|
346
|
+
{ fork: true },
|
|
347
|
+
{ fork: true, headRef: "fix/caf\xE9" },
|
|
348
|
+
{ headRef: "fix/$work", baseRef: "release/\xE9t\xE9" }
|
|
349
|
+
]) {
|
|
350
|
+
const f = boardFixture(option);
|
|
351
|
+
const result = await boardFacts(f.context);
|
|
352
|
+
assert.equal(result.ready, true, JSON.stringify(option));
|
|
353
|
+
assert.equal(result.review.observed, true);
|
|
354
|
+
assert.equal(result.review.reviewDecision, option.decision ?? null);
|
|
355
|
+
assert.equal(result.checks.state, "passed");
|
|
356
|
+
assert.equal(result.closingLinks.complete, true);
|
|
357
|
+
assert.equal(result.headRepository.name, option.fork ? "contributor/widget" : "example/widget");
|
|
358
|
+
assert.equal(f.calls.filter((x) => x === "DeliveryReviewDecision").length, 1);
|
|
359
|
+
if (option.check === "none") {
|
|
360
|
+
assert.equal(f.calls.filter((x) => x === "checks.listForRef").length, 0);
|
|
361
|
+
assert.equal(
|
|
362
|
+
(await queueChecks(f.context, "main", f.head)).state,
|
|
363
|
+
"waiting",
|
|
364
|
+
"queue still requires actual checks"
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
it("board distinguishes unavailable review from explicit null", async () => {
|
|
370
|
+
for (const option of [
|
|
371
|
+
{ unavailableReview: true },
|
|
372
|
+
{ missingDecision: true },
|
|
373
|
+
{ decision: "malformed" },
|
|
374
|
+
{ reviewHeadMoved: true },
|
|
375
|
+
{ decision: "REVIEW_REQUIRED" },
|
|
376
|
+
{ decision: "CHANGES_REQUESTED" },
|
|
377
|
+
{ nativeState: "UNKNOWN" },
|
|
378
|
+
{ draft: true },
|
|
379
|
+
{ mergeable: "UNKNOWN" },
|
|
380
|
+
{ mergeable: "CONFLICTING" },
|
|
381
|
+
{ nonClosing: true },
|
|
382
|
+
{ linksIncomplete: true }
|
|
383
|
+
]) {
|
|
384
|
+
const result = await boardFacts(boardFixture(option).context);
|
|
385
|
+
assert.equal(result.ready, false, JSON.stringify(option));
|
|
386
|
+
assert.ok(result.reasons.length > 0);
|
|
387
|
+
if (option.unavailableReview || option.missingDecision || option.decision === "malformed" || option.reviewHeadMoved)
|
|
388
|
+
assert.equal(result.review.observed, false);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
it("board retains required App producer and current base proof", async () => {
|
|
392
|
+
const ready = await boardFacts(boardFixture().context);
|
|
393
|
+
assert.deepEqual(ready.checks.proof, [{ name: "checks", appId: 7, id: 10 }]);
|
|
394
|
+
for (const option of [
|
|
395
|
+
...["missing", "foreign", "pending", "failed", "truncated", "requirements-unknown"].map((check) => ({
|
|
396
|
+
check
|
|
397
|
+
})),
|
|
398
|
+
...["head", "base", "body"].map((drift) => ({ drift })),
|
|
399
|
+
{ baseMoved: true }
|
|
400
|
+
]) {
|
|
401
|
+
const result = await boardFacts(boardFixture(option).context);
|
|
402
|
+
assert.equal(result.ready, false, JSON.stringify(option));
|
|
403
|
+
assert.ok(result.reasons.length > 0);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
const head = "a".repeat(40);
|
|
407
|
+
const merge = "b".repeat(40);
|
|
408
|
+
for (const mode of [
|
|
409
|
+
"complete",
|
|
410
|
+
"generic-404",
|
|
411
|
+
"forbidden",
|
|
412
|
+
"unreadable-repository",
|
|
413
|
+
"wrong-repository",
|
|
414
|
+
"no-write",
|
|
415
|
+
"wrong-branch",
|
|
416
|
+
"missing-summary",
|
|
417
|
+
"partial-rules",
|
|
418
|
+
"partial-rulesets",
|
|
419
|
+
"mismatched-ruleset",
|
|
420
|
+
"inactive-ruleset",
|
|
421
|
+
"wrong-source"
|
|
422
|
+
]) {
|
|
423
|
+
it(`queue discovers ruleset-only required checks with ${mode} visibility`, async () => {
|
|
424
|
+
const { context } = fixture();
|
|
425
|
+
const rule = {
|
|
426
|
+
type: "required_status_checks",
|
|
427
|
+
ruleset_id: 41,
|
|
428
|
+
ruleset_source_type: "Repository",
|
|
429
|
+
ruleset_source: mode === "wrong-source" ? "elsewhere/widget" : "example/widget",
|
|
430
|
+
parameters: { required_status_checks: [{ context: "checks", integration_id: 7 }] }
|
|
40
431
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
432
|
+
Object.assign(context.clients.rest, {
|
|
433
|
+
request: async (route) => {
|
|
434
|
+
if (route.endsWith("/protection"))
|
|
435
|
+
throw mode === "generic-404" ? { status: 404 } : mode === "forbidden" ? { status: 403 } : { status: 404, response: { status: 404, data: { message: "Branch not protected" } } };
|
|
436
|
+
if (route.includes("/rules/branches/"))
|
|
437
|
+
return { status: 200, headers: mode === "partial-rules" ? { link: "next" } : {}, data: [rule] };
|
|
438
|
+
if (route.endsWith("/rulesets"))
|
|
439
|
+
return {
|
|
440
|
+
status: 200,
|
|
441
|
+
headers: mode === "partial-rulesets" ? { link: "next" } : {},
|
|
442
|
+
data: [
|
|
443
|
+
{
|
|
444
|
+
id: mode === "mismatched-ruleset" ? 42 : 41,
|
|
445
|
+
source_type: "Repository",
|
|
446
|
+
source: "example/widget",
|
|
447
|
+
enforcement: mode === "inactive-ruleset" ? "disabled" : "active"
|
|
448
|
+
}
|
|
449
|
+
]
|
|
450
|
+
};
|
|
451
|
+
if (route.endsWith("/branches/{branch}"))
|
|
452
|
+
return {
|
|
453
|
+
status: 200,
|
|
454
|
+
data: {
|
|
455
|
+
name: mode === "wrong-branch" ? "other" : "main",
|
|
456
|
+
protected: true,
|
|
457
|
+
...mode === "missing-summary" ? {} : { protection: { enabled: false } }
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
if (mode === "unreadable-repository") throw { status: 403 };
|
|
461
|
+
return {
|
|
462
|
+
status: 200,
|
|
463
|
+
data: {
|
|
464
|
+
full_name: mode === "wrong-repository" ? "elsewhere/widget" : "example/widget",
|
|
465
|
+
permissions: { push: mode !== "no-write" }
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
65
469
|
});
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
status: 200,
|
|
73
|
-
headers: {},
|
|
74
|
-
data: option.requirementsViaClassic
|
|
75
|
-
? []
|
|
76
|
-
: [
|
|
77
|
-
{
|
|
78
|
-
type: 'required_status_checks',
|
|
79
|
-
parameters: {
|
|
80
|
-
required_status_checks: (option.configuredRequiredChecks ??
|
|
81
|
-
[
|
|
82
|
-
...(option.nativeChecks ?? []).filter((check) => check.required),
|
|
83
|
-
...(option.nativeStatuses ?? []).filter((check) => check.required),
|
|
84
|
-
].map((check) => check.name)).map((context) => ({ context })),
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
status: 200,
|
|
91
|
-
headers: {},
|
|
92
|
-
data: {
|
|
93
|
-
required_pull_request_reviews: { required_approving_review_count: 0 },
|
|
94
|
-
required_status_checks: option.requirementsViaClassic
|
|
95
|
-
? { contexts: option.configuredRequiredChecks ?? [] }
|
|
96
|
-
: null,
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
checks: {
|
|
101
|
-
listForRef: async () => ({
|
|
102
|
-
data: {
|
|
103
|
-
total_count: (option.nativeChecks ?? []).length,
|
|
104
|
-
check_runs: (option.nativeChecks ?? []).slice(0, 100).map((check) => ({
|
|
105
|
-
name: check.name,
|
|
106
|
-
status: check.status.toLowerCase(),
|
|
107
|
-
conclusion: check.conclusion?.toLowerCase() ?? null,
|
|
108
|
-
})),
|
|
109
|
-
},
|
|
110
|
-
}),
|
|
111
|
-
},
|
|
112
|
-
repos: {
|
|
113
|
-
getCombinedStatusForRef: async () => ({
|
|
114
|
-
data: {
|
|
115
|
-
state: (option.nativeStatuses ?? []).some((check) => ['FAILURE', 'ERROR'].includes(check.state))
|
|
116
|
-
? 'failure'
|
|
117
|
-
: 'success',
|
|
118
|
-
total_count: (option.nativeStatuses ?? []).length,
|
|
119
|
-
statuses: (option.nativeStatuses ?? [])
|
|
120
|
-
.slice(0, 100)
|
|
121
|
-
.map((check) => ({ context: check.name, state: check.state.toLowerCase() })),
|
|
122
|
-
},
|
|
123
|
-
}),
|
|
124
|
-
get: async () => ({ data: { node_id: 'REPO', default_branch: 'main', full_name: 'example/widget' } }),
|
|
125
|
-
},
|
|
126
|
-
git: {
|
|
127
|
-
getCommit: async () => ({ data: { sha: head, tree: { sha: '0'.repeat(40) } } }),
|
|
128
|
-
getRef: async ({ ref }) => ({
|
|
129
|
-
data: {
|
|
130
|
-
ref: `refs/${ref}`,
|
|
131
|
-
object: {
|
|
132
|
-
type: 'commit',
|
|
133
|
-
sha: ref === 'heads/main' || ref === 'heads/other'
|
|
134
|
-
? option.baseMoved
|
|
135
|
-
? 'e'.repeat(40)
|
|
136
|
-
: 'c'.repeat(40)
|
|
137
|
-
: head,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
pulls: {
|
|
143
|
-
get: async () => ({ data: { ...pr(), head: { ...pr().head, sha: option.headMoved ? 'f'.repeat(40) : head } } }),
|
|
144
|
-
list: async () => ({ data: [] }),
|
|
145
|
-
listFiles: async () => ({ data: [{ filename: 'change.ts' }] }),
|
|
146
|
-
create: async (input) => {
|
|
147
|
-
assert.equal(input.body, 'Plain explanation\n\nCloses #17');
|
|
148
|
-
assert.equal(typeof input.title, 'string');
|
|
149
|
-
assert.equal(typeof input.draft, 'boolean');
|
|
150
|
-
publicationBody = input.body;
|
|
151
|
-
publicationTitle = input.title;
|
|
152
|
-
publicationDraft = input.draft;
|
|
153
|
-
return { data: pr() };
|
|
154
|
-
},
|
|
155
|
-
getReview: async () => ({
|
|
156
|
-
data: {
|
|
157
|
-
id: 99,
|
|
158
|
-
user: { login: 'reviewer[bot]' },
|
|
159
|
-
state: 'APPROVED',
|
|
160
|
-
commit_id: head,
|
|
161
|
-
body: reviewBody,
|
|
162
|
-
html_url: 'https://github.com/example/widget/pull/23#pullrequestreview-99',
|
|
163
|
-
},
|
|
164
|
-
}),
|
|
165
|
-
listReviews: async () => ({
|
|
166
|
-
data: [
|
|
167
|
-
{
|
|
168
|
-
id: 99,
|
|
169
|
-
user: { login: 'reviewer[bot]' },
|
|
170
|
-
state: 'APPROVED',
|
|
171
|
-
commit_id: head,
|
|
172
|
-
body: reviewBody,
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
}),
|
|
176
|
-
merge: async (input) => {
|
|
177
|
-
merges.push(input);
|
|
178
|
-
merged = true;
|
|
179
|
-
if (option.mergeAckLost)
|
|
180
|
-
throw new Error('Merge acknowledgement lost');
|
|
181
|
-
return { data: { merged: true, sha: merge } };
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
issues: {
|
|
185
|
-
get: async () => ({
|
|
186
|
-
data: {
|
|
187
|
-
number: 17,
|
|
188
|
-
state: closes ? 'closed' : 'open',
|
|
189
|
-
node_id: 'ISSUE',
|
|
190
|
-
title: 'Improve widget',
|
|
191
|
-
body: merged && option.retainedIssueDrift ? 'Changed criteria' : 'Retained criteria',
|
|
192
|
-
html_url: 'https://github.com/example/widget/issues/17',
|
|
193
|
-
},
|
|
194
|
-
}),
|
|
195
|
-
update: async (input) => {
|
|
196
|
-
assert.equal(input.state, 'closed');
|
|
197
|
-
if (option.failedClose && closes === 0) {
|
|
198
|
-
closes++;
|
|
199
|
-
throw new Error('Interrupted close');
|
|
200
|
-
}
|
|
201
|
-
closes++;
|
|
202
|
-
return { data: { number: 17, state: 'closed' } };
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
const graphql = async (query) => {
|
|
207
|
-
if (query.includes('DeliveryNonClosingReferences'))
|
|
208
|
-
return {
|
|
209
|
-
repository: {
|
|
210
|
-
id: 'REPO',
|
|
211
|
-
nameWithOwner: 'example/widget',
|
|
212
|
-
issue: {
|
|
213
|
-
id: 'ISSUE',
|
|
214
|
-
number: 17,
|
|
215
|
-
state: 'OPEN',
|
|
216
|
-
timelineItems: {
|
|
217
|
-
nodes: [
|
|
218
|
-
{
|
|
219
|
-
id: 'REFERENCE',
|
|
220
|
-
actor: { login: 'author' },
|
|
221
|
-
isCrossRepository: false,
|
|
222
|
-
willCloseTarget: false,
|
|
223
|
-
source: {
|
|
224
|
-
__typename: 'PullRequest',
|
|
225
|
-
id: 'PR23',
|
|
226
|
-
number: 23,
|
|
227
|
-
repository: { id: 'REPO', nameWithOwner: 'example/widget' },
|
|
228
|
-
},
|
|
229
|
-
target: {
|
|
230
|
-
__typename: 'Issue',
|
|
231
|
-
id: 'ISSUE',
|
|
232
|
-
number: 17,
|
|
233
|
-
repository: { id: 'REPO', nameWithOwner: 'example/widget' },
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
if (query.includes('DeliveryNonClosingCommits'))
|
|
243
|
-
return {
|
|
244
|
-
repository: {
|
|
245
|
-
nameWithOwner: 'example/widget',
|
|
246
|
-
pullRequest: {
|
|
247
|
-
id: 'PR23',
|
|
248
|
-
number: 23,
|
|
249
|
-
headRefOid: head,
|
|
250
|
-
baseRefOid: 'c'.repeat(40),
|
|
251
|
-
baseRefName: 'main',
|
|
252
|
-
commits: {
|
|
253
|
-
totalCount: 1,
|
|
254
|
-
nodes: [
|
|
255
|
-
{
|
|
256
|
-
commit: {
|
|
257
|
-
oid: head,
|
|
258
|
-
message: option.commitMessage ?? 'Improve widget',
|
|
259
|
-
parents: {
|
|
260
|
-
totalCount: 1,
|
|
261
|
-
nodes: [{ oid: 'c'.repeat(40) }],
|
|
262
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
if (query.includes('DeliveryClosingIssues'))
|
|
273
|
-
return {
|
|
274
|
-
repository: {
|
|
275
|
-
nameWithOwner: 'example/widget',
|
|
276
|
-
pullRequest: {
|
|
277
|
-
id: 'PR23',
|
|
278
|
-
number: 23,
|
|
279
|
-
closingIssuesReferences: {
|
|
280
|
-
nodes: option.nonClosing
|
|
281
|
-
? []
|
|
282
|
-
: [{ number: option.wrongClosingIssue ? 18 : 17, repository: { nameWithOwner: 'example/widget' } }],
|
|
283
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
if (option.deletedAfterMerge && merged && query.includes('DeliveryIssueBranches'))
|
|
289
|
-
return {
|
|
290
|
-
repository: { issue: { linkedBranches: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } } } },
|
|
291
|
-
};
|
|
292
|
-
if (query.includes('DeliveryIssueBranches'))
|
|
293
|
-
return {
|
|
294
|
-
repository: {
|
|
295
|
-
issue: {
|
|
296
|
-
linkedBranches: {
|
|
297
|
-
nodes: [
|
|
298
|
-
{
|
|
299
|
-
ref: {
|
|
300
|
-
name: option.unrelatedBranch ? 'other/17' : 'issue/17',
|
|
301
|
-
target: { oid: head },
|
|
302
|
-
repository: { nameWithOwner: 'example/widget' },
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
],
|
|
306
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
if (query.includes('blockedBy'))
|
|
312
|
-
return {
|
|
313
|
-
repository: {
|
|
314
|
-
issue: { blockedBy: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } }, parent: null },
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
if (option.decisionUnavailable)
|
|
318
|
-
throw new Error('Fictional review decision unavailable');
|
|
319
|
-
decisionRead = true;
|
|
470
|
+
const reads = [];
|
|
471
|
+
let appId = 7, checkSha = head;
|
|
472
|
+
Object.assign(context.clients.rest.checks, {
|
|
473
|
+
listForRef: async ({ ref }) => {
|
|
474
|
+
reads.push(ref);
|
|
320
475
|
return {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
476
|
+
status: 200,
|
|
477
|
+
headers: {},
|
|
478
|
+
data: {
|
|
479
|
+
total_count: 1,
|
|
480
|
+
check_runs: [
|
|
481
|
+
{
|
|
482
|
+
id: 10,
|
|
483
|
+
name: "checks",
|
|
484
|
+
head_sha: checkSha,
|
|
485
|
+
app: { id: appId },
|
|
486
|
+
status: "completed",
|
|
487
|
+
conclusion: "success"
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
}
|
|
327
491
|
};
|
|
328
|
-
|
|
329
|
-
const reviewer = { role: 'reviewer', authSource: 'app', appActorLogin: async () => 'reviewer[bot]', rest, graphql };
|
|
330
|
-
const context = {
|
|
331
|
-
root: '/nonexistent-launch-directory',
|
|
332
|
-
repo: { owner: 'example', repo: 'widget' },
|
|
333
|
-
config: {
|
|
334
|
-
schemaVersion: 'ai-delivery.github@1',
|
|
335
|
-
repository: 'example/widget',
|
|
336
|
-
roles: { author: { authSource: 'personal', identity: 'author' }, reviewer: { identity: 'reviewer' } },
|
|
337
|
-
},
|
|
338
|
-
clients: {
|
|
339
|
-
role: 'author',
|
|
340
|
-
authSource: 'personal',
|
|
341
|
-
authenticatedAuthor: async () => ({ actorLogin: 'author', credentialIdentity: 'user:1' }),
|
|
342
|
-
rest,
|
|
343
|
-
graphql,
|
|
344
|
-
},
|
|
345
|
-
reviewerClients: reviewer,
|
|
346
|
-
};
|
|
347
|
-
return { context, merges, closes: () => closes };
|
|
348
|
-
}
|
|
349
|
-
describe('remote GitHub lifecycle', () => {
|
|
350
|
-
it('uses native eligibility without comparing historical artifact identity', async () => {
|
|
351
|
-
const { context, merges } = fixture('clean', { reviewBinding: 'stale-head' });
|
|
352
|
-
await mergePr(context, { issueNumber: 17, prNumber: 23, reviewedHeadSha: head });
|
|
353
|
-
assert.equal(merges.length, 1);
|
|
354
|
-
assert.equal(merges[0]?.sha, head);
|
|
492
|
+
}
|
|
355
493
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
494
|
+
Object.assign(context.clients.rest.repos, {
|
|
495
|
+
getCombinedStatusForRef: async () => ({
|
|
496
|
+
status: 200,
|
|
497
|
+
headers: {},
|
|
498
|
+
data: { sha: head, total_count: 0, statuses: [] }
|
|
499
|
+
})
|
|
360
500
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
throw new Error('Historical review comparison must not run');
|
|
375
|
-
});
|
|
376
|
-
context.clients.rest.git.getCommit = (async () => {
|
|
377
|
-
throw new Error('Historical tree comparison must not run');
|
|
378
|
-
});
|
|
379
|
-
context.clients.rest.pulls.listFiles = (async () => {
|
|
380
|
-
throw new Error('Historical diff comparison must not run');
|
|
381
|
-
});
|
|
382
|
-
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
383
|
-
assert.equal(merges.length, 1);
|
|
384
|
-
});
|
|
501
|
+
const result = await queueChecks(context, "main", head);
|
|
502
|
+
if (mode !== "complete") {
|
|
503
|
+
assert.equal(result.state, "waiting");
|
|
504
|
+
assert.deepEqual(reads, []);
|
|
505
|
+
} else {
|
|
506
|
+
assert.equal(result.state, "passed");
|
|
507
|
+
assert.deepEqual(reads, [head]);
|
|
508
|
+
assert.deepEqual(result.proof, [{ name: "checks", appId: 7, id: 10 }]);
|
|
509
|
+
appId = 8;
|
|
510
|
+
assert.equal((await queueChecks(context, "main", head)).state, "waiting");
|
|
511
|
+
appId = 7;
|
|
512
|
+
checkSha = "e".repeat(40);
|
|
513
|
+
assert.equal((await queueChecks(context, "main", head)).state, "waiting");
|
|
385
514
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
for (const appId of [null, 7]) {
|
|
518
|
+
for (const state of ["success", "failure", "error", "pending", "unknown"]) {
|
|
519
|
+
it(`queue evaluates a same-name ${state} status alongside a successful ${appId === null ? "wildcard" : "App-pinned"} run`, async () => {
|
|
520
|
+
const { context } = fixture();
|
|
521
|
+
Object.assign(context.clients.rest, {
|
|
522
|
+
request: async (route) => ({
|
|
523
|
+
status: 200,
|
|
524
|
+
headers: {},
|
|
525
|
+
data: route.endsWith("/protection") ? { required_status_checks: { checks: [{ context: "checks", app_id: appId }] } } : []
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
Object.assign(context.clients.rest.checks, {
|
|
529
|
+
listForRef: async () => ({
|
|
530
|
+
status: 200,
|
|
531
|
+
headers: {},
|
|
532
|
+
data: {
|
|
533
|
+
total_count: 1,
|
|
534
|
+
check_runs: [
|
|
535
|
+
{ id: 10, name: "checks", head_sha: head, app: { id: 7 }, status: "completed", conclusion: "success" }
|
|
536
|
+
]
|
|
537
|
+
}
|
|
538
|
+
})
|
|
539
|
+
});
|
|
540
|
+
Object.assign(context.clients.rest.repos, {
|
|
541
|
+
getCombinedStatusForRef: async () => ({
|
|
542
|
+
status: 200,
|
|
543
|
+
headers: {},
|
|
544
|
+
data: {
|
|
545
|
+
sha: head,
|
|
546
|
+
total_count: 1,
|
|
547
|
+
statuses: [{ id: 20, context: "checks", state, creator: { id: 7, login: "checks[bot]" } }]
|
|
548
|
+
}
|
|
549
|
+
})
|
|
550
|
+
});
|
|
551
|
+
const result = await queueChecks(context, "main", head);
|
|
552
|
+
assert.equal(
|
|
553
|
+
result.state,
|
|
554
|
+
appId !== null ? "waiting" : state === "success" ? "passed" : ["failure", "error"].includes(state) ? "failed" : "waiting"
|
|
555
|
+
);
|
|
556
|
+
if (appId !== null) assert.match(result.reason, /source/iu);
|
|
394
557
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
it("preserves legacy required contexts alongside pinned checks and requires the latest exact-SHA source", async () => {
|
|
561
|
+
const { context } = fixture();
|
|
562
|
+
const check = {
|
|
563
|
+
id: 10,
|
|
564
|
+
name: "pinned",
|
|
565
|
+
head_sha: head,
|
|
566
|
+
app: { id: 7 },
|
|
567
|
+
status: "completed",
|
|
568
|
+
conclusion: "success"
|
|
569
|
+
};
|
|
570
|
+
let runs = [check];
|
|
571
|
+
Object.assign(context.clients.rest, {
|
|
572
|
+
request: async (route) => ({
|
|
573
|
+
status: 200,
|
|
574
|
+
headers: {},
|
|
575
|
+
data: route.endsWith("/protection") ? { required_status_checks: { checks: [{ context: "pinned", app_id: 7 }], contexts: ["pinned", "legacy"] } } : []
|
|
576
|
+
})
|
|
577
|
+
});
|
|
578
|
+
Object.assign(context.clients.rest.checks, {
|
|
579
|
+
listForRef: async () => ({ status: 200, headers: {}, data: { total_count: runs.length, check_runs: runs } })
|
|
580
|
+
});
|
|
581
|
+
Object.assign(context.clients.rest.repos, {
|
|
582
|
+
getCombinedStatusForRef: async () => ({
|
|
583
|
+
status: 200,
|
|
584
|
+
headers: {},
|
|
585
|
+
data: {
|
|
586
|
+
sha: head,
|
|
587
|
+
state: "success",
|
|
588
|
+
total_count: 1,
|
|
589
|
+
statuses: [{ id: 20, context: "legacy", state: "success" }]
|
|
590
|
+
}
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
assert.deepEqual(
|
|
594
|
+
(await prChecks(context, 23)).requiredChecks.map((c) => c.name),
|
|
595
|
+
["legacy", "pinned"]
|
|
596
|
+
);
|
|
597
|
+
assert.equal((await queueChecks(context, "main", head)).state, "passed");
|
|
598
|
+
runs = [{ ...check, app: { id: 8 } }];
|
|
599
|
+
assert.equal((await queueChecks(context, "main", head)).state, "waiting");
|
|
600
|
+
runs = [check, { ...check, id: 11, status: "in_progress", conclusion: null }];
|
|
601
|
+
assert.equal((await queueChecks(context, "main", head)).state, "waiting");
|
|
602
|
+
runs = [{ ...check, head_sha: "e".repeat(40) }];
|
|
603
|
+
assert.equal((await queueChecks(context, "main", head)).state, "waiting");
|
|
604
|
+
});
|
|
605
|
+
it("queue guard retains native eligibility and records intent only after the last base/proof check", async () => {
|
|
606
|
+
for (const state of ["behind", "blocked"]) {
|
|
607
|
+
const f2 = fixture(state), stages2 = [];
|
|
608
|
+
await assert.rejects(
|
|
609
|
+
mergePr(
|
|
610
|
+
f2.context,
|
|
611
|
+
{ issueNumber: 17, prNumber: 23 },
|
|
612
|
+
{
|
|
613
|
+
expectedBase: "c".repeat(40),
|
|
614
|
+
checkProof: async () => {
|
|
615
|
+
stages2.push("proof");
|
|
616
|
+
},
|
|
617
|
+
beforeMutation: async () => {
|
|
618
|
+
stages2.push("intent");
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
),
|
|
622
|
+
/merge eligibility/u
|
|
623
|
+
);
|
|
624
|
+
assert.deepEqual(stages2, []);
|
|
625
|
+
assert.equal(f2.merges.length, 0);
|
|
626
|
+
}
|
|
627
|
+
const f = fixture(), stages = [];
|
|
628
|
+
await assert.rejects(
|
|
629
|
+
mergePr(
|
|
630
|
+
f.context,
|
|
631
|
+
{ issueNumber: 17, prNumber: 23 },
|
|
632
|
+
{
|
|
633
|
+
expectedBase: "c".repeat(40),
|
|
634
|
+
checkProof: async () => {
|
|
635
|
+
stages.push("proof");
|
|
636
|
+
const get = f.context.clients.rest.git.getRef;
|
|
637
|
+
f.context.clients.rest.git.getRef = (async (input) => {
|
|
638
|
+
const result = await get(input);
|
|
639
|
+
if (input.ref === "heads/main") result.data.object.sha = "d".repeat(40);
|
|
640
|
+
return result;
|
|
641
|
+
});
|
|
642
|
+
},
|
|
643
|
+
beforeMutation: async () => {
|
|
644
|
+
stages.push("intent");
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
),
|
|
648
|
+
/base moved/u
|
|
649
|
+
);
|
|
650
|
+
assert.deepEqual(stages, ["proof"]);
|
|
651
|
+
assert.equal(f.merges.length, 0);
|
|
652
|
+
});
|
|
653
|
+
function fixture(state = "clean", option = {}) {
|
|
654
|
+
const head2 = option.headSha ?? "a".repeat(40);
|
|
655
|
+
const merge2 = option.mergeSha ?? "b".repeat(40);
|
|
656
|
+
const base = option.baseSha ?? "c".repeat(40);
|
|
657
|
+
let merged = false;
|
|
658
|
+
let decisionRead = false;
|
|
659
|
+
let closes = 0;
|
|
660
|
+
let publicationBody;
|
|
661
|
+
let publicationTitle;
|
|
662
|
+
let publicationDraft;
|
|
663
|
+
const merges = [];
|
|
664
|
+
const artifactContent = {
|
|
665
|
+
authorIdentity: option.reviewBinding === "wrong-role" ? "collaborator" : "author",
|
|
666
|
+
reviewerIdentity: "reviewer",
|
|
667
|
+
checks: ["retained checks"],
|
|
668
|
+
diffScopeHash: digestValue([option.reviewBinding === "wrong-scope" ? "elsewhere.ts" : "change.ts"]),
|
|
669
|
+
elapsedMs: 1,
|
|
670
|
+
findings: [],
|
|
671
|
+
head: {
|
|
672
|
+
sha: option.reviewBinding === "stale-head" ? "e".repeat(40) : head2,
|
|
673
|
+
tree: option.reviewBinding === "wrong-tree" ? "f".repeat(40) : option.headTree ?? "0".repeat(40)
|
|
674
|
+
},
|
|
675
|
+
issueNumber: option.reviewBinding === "wrong-issue" ? 18 : 17,
|
|
676
|
+
prNumber: option.reviewBinding === "wrong-pr" ? 24 : 23,
|
|
677
|
+
readOnly: true,
|
|
678
|
+
requestedEffort: "xhigh",
|
|
679
|
+
requestedModel: "gpt-6-astra",
|
|
680
|
+
effectiveEffort: "unknown",
|
|
681
|
+
effectiveModel: "unknown",
|
|
682
|
+
schemaVersion: "ai-delivery.review-artifact@1",
|
|
683
|
+
summary: "Independent review.",
|
|
684
|
+
verdict: "approve"
|
|
685
|
+
};
|
|
686
|
+
const artifact = {
|
|
687
|
+
...artifactContent,
|
|
688
|
+
artifactId: option.reviewBinding === "invalid-digest" ? `sha256:${"d".repeat(64)}` : digestValue(artifactContent)
|
|
689
|
+
};
|
|
690
|
+
const marker = `<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->`;
|
|
691
|
+
const reviewBody = option.reviewBinding === "marker-only" ? marker : `${artifact.summary}
|
|
692
|
+
|
|
693
|
+
${marker}
|
|
694
|
+
<!-- ai-delivery-review-artifact-data: ${Buffer.from(JSON.stringify(artifact)).toString("base64url")} -->`;
|
|
695
|
+
const pr = () => ({
|
|
696
|
+
number: 23,
|
|
697
|
+
node_id: "PR23",
|
|
698
|
+
changed_files: 1,
|
|
699
|
+
title: decisionRead && option.messageChangedAfterDecision === "title" ? "Edited title" : publicationTitle ?? "Improve widget",
|
|
700
|
+
body: publicationBody ?? (decisionRead && option.messageChangedAfterDecision === "body" ? "Closes #17\n\nEdited body." : option.prBody) ?? (option.nonClosing ? "References example/widget#17\n\nImprove widget." : "Closes #17"),
|
|
701
|
+
html_url: "https://github.com/example/widget/pull/23",
|
|
702
|
+
state: merged ? "closed" : "open",
|
|
703
|
+
draft: publicationDraft ?? false,
|
|
704
|
+
merged,
|
|
705
|
+
merge_commit_sha: merged ? merge2 : null,
|
|
706
|
+
mergeable: state === "clean" || state === "unstable" || state === "has_hooks",
|
|
707
|
+
mergeable_state: state,
|
|
708
|
+
head: { sha: head2, ref: "issue/17", repo: { full_name: "example/widget" } },
|
|
709
|
+
base: {
|
|
710
|
+
sha: decisionRead && option.baseChangedAfterDecision === "sha" ? "d".repeat(40) : base,
|
|
711
|
+
ref: decisionRead && option.baseChangedAfterDecision === "name" ? "other" : "main",
|
|
712
|
+
repo: { full_name: "example/widget" }
|
|
713
|
+
},
|
|
714
|
+
user: { login: "author" }
|
|
715
|
+
});
|
|
716
|
+
const rest = {
|
|
717
|
+
request: async (route) => {
|
|
718
|
+
if (option.requirementsUnavailable) throw { status: 403 };
|
|
719
|
+
if (route.endsWith("/rules/branches/{branch}"))
|
|
720
|
+
return {
|
|
721
|
+
status: 200,
|
|
722
|
+
headers: {},
|
|
723
|
+
data: option.requirementsViaClassic ? [] : [
|
|
724
|
+
{
|
|
725
|
+
type: "required_status_checks",
|
|
726
|
+
parameters: {
|
|
727
|
+
required_status_checks: (option.configuredRequiredChecks ?? [
|
|
728
|
+
...(option.nativeChecks ?? []).filter((check) => check.required),
|
|
729
|
+
...(option.nativeStatuses ?? []).filter((check) => check.required)
|
|
730
|
+
].map((check) => check.name)).map((context2) => ({ context: context2 }))
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
]
|
|
734
|
+
};
|
|
735
|
+
return {
|
|
736
|
+
status: 200,
|
|
737
|
+
headers: {},
|
|
738
|
+
data: {
|
|
739
|
+
required_pull_request_reviews: { required_approving_review_count: 0 },
|
|
740
|
+
required_status_checks: option.requirementsViaClassic ? { contexts: option.configuredRequiredChecks ?? [] } : null
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
},
|
|
744
|
+
checks: {
|
|
745
|
+
listForRef: async () => ({
|
|
746
|
+
data: {
|
|
747
|
+
total_count: (option.nativeChecks ?? []).length,
|
|
748
|
+
check_runs: (option.nativeChecks ?? []).slice(0, 100).map((check) => ({
|
|
749
|
+
name: check.name,
|
|
750
|
+
status: check.status.toLowerCase(),
|
|
751
|
+
conclusion: check.conclusion?.toLowerCase() ?? null
|
|
752
|
+
}))
|
|
753
|
+
}
|
|
754
|
+
})
|
|
755
|
+
},
|
|
756
|
+
repos: {
|
|
757
|
+
getCombinedStatusForRef: async () => ({
|
|
758
|
+
data: {
|
|
759
|
+
state: (option.nativeStatuses ?? []).some((check) => ["FAILURE", "ERROR"].includes(check.state)) ? "failure" : "success",
|
|
760
|
+
total_count: (option.nativeStatuses ?? []).length,
|
|
761
|
+
statuses: (option.nativeStatuses ?? []).slice(0, 100).map((check) => ({ context: check.name, state: check.state.toLowerCase() }))
|
|
762
|
+
}
|
|
763
|
+
}),
|
|
764
|
+
get: async () => ({ data: { node_id: "REPO", default_branch: "main", full_name: "example/widget" } })
|
|
765
|
+
},
|
|
766
|
+
git: {
|
|
767
|
+
getCommit: async () => ({ data: { sha: head2, tree: { sha: option.headTree ?? "0".repeat(40) } } }),
|
|
768
|
+
getRef: async ({ ref }) => ({
|
|
769
|
+
data: {
|
|
770
|
+
ref: `refs/${ref}`,
|
|
771
|
+
object: {
|
|
772
|
+
type: "commit",
|
|
773
|
+
sha: ref === "heads/main" || ref === "heads/other" ? option.baseMoved ? "e".repeat(40) : merged ? option.remoteBaseSha ?? base : base : head2
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
})
|
|
777
|
+
},
|
|
778
|
+
pulls: {
|
|
779
|
+
get: async () => ({ data: { ...pr(), head: { ...pr().head, sha: option.headMoved ? "f".repeat(40) : head2 } } }),
|
|
780
|
+
list: async () => ({ data: [] }),
|
|
781
|
+
listFiles: async () => ({ data: [{ filename: "change.ts" }] }),
|
|
782
|
+
create: async (input) => {
|
|
783
|
+
assert.equal(input.body, "Closes #17\n\nPlain explanation\n\n<!-- ai-delivery:pr@1 -->");
|
|
784
|
+
assert.equal(typeof input.title, "string");
|
|
785
|
+
assert.equal(typeof input.draft, "boolean");
|
|
786
|
+
publicationBody = input.body;
|
|
787
|
+
publicationTitle = input.title;
|
|
788
|
+
publicationDraft = input.draft;
|
|
789
|
+
return { data: pr() };
|
|
790
|
+
},
|
|
791
|
+
getReview: async () => ({
|
|
792
|
+
data: {
|
|
793
|
+
id: 99,
|
|
794
|
+
user: { login: "reviewer[bot]" },
|
|
795
|
+
state: "APPROVED",
|
|
796
|
+
commit_id: head2,
|
|
797
|
+
body: reviewBody,
|
|
798
|
+
html_url: "https://github.com/example/widget/pull/23#pullrequestreview-99"
|
|
799
|
+
}
|
|
800
|
+
}),
|
|
801
|
+
listReviews: async () => ({
|
|
802
|
+
data: [
|
|
803
|
+
{
|
|
804
|
+
id: 99,
|
|
805
|
+
user: { login: "reviewer[bot]" },
|
|
806
|
+
state: "APPROVED",
|
|
807
|
+
commit_id: head2,
|
|
808
|
+
body: reviewBody
|
|
809
|
+
}
|
|
810
|
+
]
|
|
811
|
+
}),
|
|
812
|
+
merge: async (input) => {
|
|
813
|
+
merges.push(input);
|
|
814
|
+
merged = true;
|
|
815
|
+
if (option.mergeAckLost) throw new Error("Merge acknowledgement lost");
|
|
816
|
+
return { data: { merged: true, sha: merge2 } };
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
issues: {
|
|
820
|
+
get: async () => ({
|
|
821
|
+
data: {
|
|
822
|
+
number: 17,
|
|
823
|
+
state: closes ? "closed" : "open",
|
|
824
|
+
node_id: "ISSUE",
|
|
825
|
+
title: "Improve widget",
|
|
826
|
+
body: merged && option.retainedIssueDrift ? "Changed criteria" : "Retained criteria",
|
|
827
|
+
html_url: "https://github.com/example/widget/issues/17"
|
|
828
|
+
}
|
|
829
|
+
}),
|
|
830
|
+
update: async (input) => {
|
|
831
|
+
assert.equal(input.state, "closed");
|
|
832
|
+
if (option.failedClose && closes === 0) {
|
|
833
|
+
closes++;
|
|
834
|
+
throw new Error("Interrupted close");
|
|
835
|
+
}
|
|
836
|
+
closes++;
|
|
837
|
+
return { data: { number: 17, state: "closed" } };
|
|
838
|
+
}
|
|
407
839
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
840
|
+
};
|
|
841
|
+
const graphql = async (query) => {
|
|
842
|
+
if (query.includes("DeliveryNonClosingReferences"))
|
|
843
|
+
return {
|
|
844
|
+
repository: {
|
|
845
|
+
id: "REPO",
|
|
846
|
+
nameWithOwner: "example/widget",
|
|
847
|
+
issue: {
|
|
848
|
+
id: "ISSUE",
|
|
849
|
+
number: 17,
|
|
850
|
+
state: "OPEN",
|
|
851
|
+
timelineItems: {
|
|
852
|
+
nodes: [
|
|
853
|
+
{
|
|
854
|
+
id: "REFERENCE",
|
|
855
|
+
actor: { login: "author" },
|
|
856
|
+
isCrossRepository: false,
|
|
857
|
+
willCloseTarget: false,
|
|
858
|
+
source: {
|
|
859
|
+
__typename: "PullRequest",
|
|
860
|
+
id: "PR23",
|
|
861
|
+
number: 23,
|
|
862
|
+
repository: { id: "REPO", nameWithOwner: "example/widget" }
|
|
863
|
+
},
|
|
864
|
+
target: {
|
|
865
|
+
__typename: "Issue",
|
|
866
|
+
id: "ISSUE",
|
|
867
|
+
number: 17,
|
|
868
|
+
repository: { id: "REPO", nameWithOwner: "example/widget" }
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
],
|
|
872
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
if (query.includes("DeliveryNonClosingCommits"))
|
|
878
|
+
return {
|
|
879
|
+
repository: {
|
|
880
|
+
nameWithOwner: "example/widget",
|
|
881
|
+
pullRequest: {
|
|
882
|
+
id: "PR23",
|
|
883
|
+
number: 23,
|
|
884
|
+
headRefOid: head2,
|
|
885
|
+
baseRefOid: base,
|
|
886
|
+
baseRefName: "main",
|
|
887
|
+
commits: {
|
|
888
|
+
totalCount: 1,
|
|
889
|
+
nodes: [
|
|
890
|
+
{
|
|
891
|
+
commit: {
|
|
892
|
+
oid: head2,
|
|
893
|
+
message: option.commitMessage ?? "Improve widget",
|
|
894
|
+
parents: {
|
|
895
|
+
totalCount: 1,
|
|
896
|
+
nodes: [{ oid: base }],
|
|
897
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
],
|
|
902
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
if (query.includes("DeliveryClosingIssues"))
|
|
908
|
+
return {
|
|
909
|
+
repository: {
|
|
910
|
+
nameWithOwner: "example/widget",
|
|
911
|
+
pullRequest: {
|
|
912
|
+
id: "PR23",
|
|
913
|
+
number: 23,
|
|
914
|
+
closingIssuesReferences: {
|
|
915
|
+
nodes: option.nonClosing ? [] : [{ number: option.wrongClosingIssue ? 18 : 17, repository: { nameWithOwner: "example/widget" } }],
|
|
916
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
if (option.deletedAfterMerge && merged && query.includes("DeliveryIssueBranches"))
|
|
922
|
+
return {
|
|
923
|
+
repository: { issue: { linkedBranches: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } } } }
|
|
924
|
+
};
|
|
925
|
+
if (query.includes("DeliveryIssueBranches"))
|
|
926
|
+
return {
|
|
927
|
+
repository: {
|
|
928
|
+
issue: {
|
|
929
|
+
linkedBranches: {
|
|
930
|
+
nodes: [
|
|
931
|
+
{
|
|
932
|
+
ref: {
|
|
933
|
+
name: option.unrelatedBranch ? "other/17" : "issue/17",
|
|
934
|
+
target: { oid: head2 },
|
|
935
|
+
repository: { nameWithOwner: "example/widget" }
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
],
|
|
939
|
+
pageInfo: { hasNextPage: false, endCursor: null }
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
if (query.includes("blockedBy"))
|
|
945
|
+
return {
|
|
946
|
+
repository: {
|
|
947
|
+
issue: { blockedBy: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } }, parent: null }
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
if (option.decisionUnavailable) throw new Error("Fictional review decision unavailable");
|
|
951
|
+
decisionRead = true;
|
|
952
|
+
return {
|
|
953
|
+
repository: {
|
|
954
|
+
pullRequest: {
|
|
955
|
+
headRefOid: option.decisionHeadMoved ? "d".repeat(40) : head2,
|
|
956
|
+
reviewDecision: Object.hasOwn(option, "reviewDecision") ? option.reviewDecision : "APPROVED"
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
};
|
|
961
|
+
const reviewer = { role: "reviewer", authSource: "app", appActorLogin: async () => "reviewer[bot]", rest, graphql };
|
|
962
|
+
const context = {
|
|
963
|
+
root: "/nonexistent-launch-directory",
|
|
964
|
+
repo: { owner: "example", repo: "widget" },
|
|
965
|
+
config: {
|
|
966
|
+
schemaVersion: "ai-delivery.github@1",
|
|
967
|
+
repository: "example/widget",
|
|
968
|
+
roles: { author: { authSource: "personal", identity: "author" }, reviewer: { identity: "reviewer" } }
|
|
969
|
+
},
|
|
970
|
+
clients: {
|
|
971
|
+
role: "author",
|
|
972
|
+
authSource: "personal",
|
|
973
|
+
authenticatedAuthor: async () => ({ actorLogin: "author", credentialIdentity: "user:1" }),
|
|
974
|
+
rest,
|
|
975
|
+
graphql
|
|
976
|
+
},
|
|
977
|
+
reviewerClients: reviewer
|
|
978
|
+
};
|
|
979
|
+
return { context, merges, closes: () => closes };
|
|
980
|
+
}
|
|
981
|
+
describe("remote GitHub lifecycle", () => {
|
|
982
|
+
it("uses native eligibility without comparing historical artifact identity", async () => {
|
|
983
|
+
const { context, merges } = fixture("clean", { reviewBinding: "stale-head" });
|
|
984
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23, reviewedHeadSha: head });
|
|
985
|
+
assert.equal(merges.length, 1);
|
|
986
|
+
assert.equal(merges[0]?.sha, head);
|
|
987
|
+
});
|
|
988
|
+
it("accepts native PR association despite a superseded linked branch snapshot", async () => {
|
|
989
|
+
const { context, merges } = fixture("clean", { unrelatedBranch: true });
|
|
990
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
991
|
+
assert.equal(merges.length, 1);
|
|
992
|
+
});
|
|
993
|
+
for (const reviewBinding of [
|
|
994
|
+
"stale-head",
|
|
995
|
+
"wrong-tree",
|
|
996
|
+
"wrong-scope",
|
|
997
|
+
"invalid-digest",
|
|
998
|
+
"marker-only",
|
|
999
|
+
"wrong-issue",
|
|
1000
|
+
"wrong-pr",
|
|
1001
|
+
"wrong-role"
|
|
1002
|
+
]) {
|
|
1003
|
+
it(`defers ${reviewBinding} historical review eligibility to GitHub`, async () => {
|
|
1004
|
+
const { context, merges } = fixture("clean", { reviewBinding });
|
|
1005
|
+
context.clients.rest.pulls.listReviews = (async () => {
|
|
1006
|
+
throw new Error("Historical review comparison must not run");
|
|
1007
|
+
});
|
|
1008
|
+
context.clients.rest.git.getCommit = (async () => {
|
|
1009
|
+
throw new Error("Historical tree comparison must not run");
|
|
1010
|
+
});
|
|
1011
|
+
context.clients.rest.pulls.listFiles = (async () => {
|
|
1012
|
+
throw new Error("Historical diff comparison must not run");
|
|
1013
|
+
});
|
|
1014
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1015
|
+
assert.equal(merges.length, 1);
|
|
447
1016
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
for (const option of [
|
|
456
|
-
{ decisionHeadMoved: true },
|
|
457
|
-
{ baseChangedAfterDecision: 'name' },
|
|
458
|
-
{ baseChangedAfterDecision: 'sha' },
|
|
459
|
-
]) {
|
|
460
|
-
it(`refuses native head/base decision drift ${JSON.stringify(option)}`, async () => {
|
|
461
|
-
const { context, merges } = fixture('clean', option);
|
|
462
|
-
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }));
|
|
463
|
-
assert.equal(merges.length, 0);
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
it('accepts GitHub passing eligibility with native pre-receive hooks', async () => {
|
|
467
|
-
const { context, merges } = fixture('has_hooks');
|
|
468
|
-
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
469
|
-
assert.equal(merges.length, 1);
|
|
1017
|
+
}
|
|
1018
|
+
it("merges a native zero-review decision without requiring an extra App approval", async () => {
|
|
1019
|
+
const { context, merges } = fixture("clean", { reviewDecision: null });
|
|
1020
|
+
delete context.reviewerClients;
|
|
1021
|
+
context.clients.rest.pulls.listReviews = (async () => {
|
|
1022
|
+
throw new Error("Extra approval must not be required");
|
|
470
1023
|
});
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
1024
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1025
|
+
assert.equal(merges.length, 1);
|
|
1026
|
+
});
|
|
1027
|
+
for (const [status, conclusion] of [
|
|
1028
|
+
["IN_PROGRESS", null],
|
|
1029
|
+
["COMPLETED", "FAILURE"],
|
|
1030
|
+
["COMPLETED", "TIMED_OUT"]
|
|
1031
|
+
]) {
|
|
1032
|
+
it(`names the required native money-path-review blocker ${status}/${conclusion}`, async () => {
|
|
1033
|
+
const { context, merges } = fixture("blocked", {
|
|
1034
|
+
nativeChecks: [{ name: "money-path-review", required: true, status, conclusion }]
|
|
1035
|
+
});
|
|
1036
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /money-path-review/u);
|
|
1037
|
+
assert.equal(merges.length, 0);
|
|
480
1038
|
});
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
assert.deepEqual(checks.requiredChecks, [{ name: 'money-path-review', headState: 'not-reported' }]);
|
|
1039
|
+
}
|
|
1040
|
+
it("reports discovered required check names and permits a failed optional check", async () => {
|
|
1041
|
+
const { context, merges } = fixture("unstable", {
|
|
1042
|
+
nativeChecks: [
|
|
1043
|
+
{ name: "local-verify", required: true, status: "COMPLETED", conclusion: "SUCCESS" },
|
|
1044
|
+
{ name: "money-path-review", required: true, status: "COMPLETED", conclusion: "NEUTRAL" },
|
|
1045
|
+
{ name: "optional", required: false, status: "COMPLETED", conclusion: "FAILURE" }
|
|
1046
|
+
]
|
|
490
1047
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
1048
|
+
const checks = await prChecks(context, 23);
|
|
1049
|
+
assert.deepEqual(
|
|
1050
|
+
checks.requiredChecks.map((check) => check.name),
|
|
1051
|
+
["local-verify", "money-path-review"]
|
|
1052
|
+
);
|
|
1053
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1054
|
+
assert.equal(merges.length, 1);
|
|
1055
|
+
});
|
|
1056
|
+
it("discovers required legacy names alongside a full page of head check runs", async () => {
|
|
1057
|
+
const { context, merges } = fixture("clean", {
|
|
1058
|
+
nativeChecks: Array.from({ length: 100 }, (_, i) => ({
|
|
1059
|
+
name: `optional${i}`,
|
|
1060
|
+
required: false,
|
|
1061
|
+
status: "COMPLETED",
|
|
1062
|
+
conclusion: "SUCCESS"
|
|
1063
|
+
})),
|
|
1064
|
+
nativeStatuses: [{ name: "legacy-required", required: true, state: "SUCCESS" }]
|
|
499
1065
|
});
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /money-path-review/u);
|
|
512
|
-
assert.equal(merges.length, 0);
|
|
1066
|
+
const checks = await prChecks(context, 23);
|
|
1067
|
+
assert.deepEqual(
|
|
1068
|
+
checks.requiredChecks.map((check) => check.name),
|
|
1069
|
+
["legacy-required"]
|
|
1070
|
+
);
|
|
1071
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1072
|
+
assert.equal(merges.length, 1);
|
|
1073
|
+
});
|
|
1074
|
+
it("refuses GitHub blocked eligibility for a failing required legacy status", async () => {
|
|
1075
|
+
const { context, merges } = fixture("blocked", {
|
|
1076
|
+
nativeStatuses: [{ name: "legacy-required", required: true, state: "FAILURE" }]
|
|
513
1077
|
});
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
1078
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /legacy-required/u);
|
|
1079
|
+
assert.equal(merges.length, 0);
|
|
1080
|
+
});
|
|
1081
|
+
it("refuses unavailable review decision readback even when GitHub REST is clean", async () => {
|
|
1082
|
+
const { context, merges } = fixture("clean", { decisionUnavailable: true });
|
|
1083
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }));
|
|
1084
|
+
assert.equal(merges.length, 0);
|
|
1085
|
+
});
|
|
1086
|
+
for (const reviewDecision of [void 0, "UNKNOWN", false, 0, {}, "REVIEW_REQUIRED", "CHANGES_REQUESTED"]) {
|
|
1087
|
+
it(`refuses unavailable or blocking native review decision ${JSON.stringify(reviewDecision)}`, async () => {
|
|
1088
|
+
const { context, merges } = fixture("clean", { reviewDecision });
|
|
1089
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }));
|
|
1090
|
+
assert.equal(merges.length, 0);
|
|
518
1091
|
});
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
await assert.rejects(publishPr(context, { issueNumber: 17, dryRun: true }), /author/u);
|
|
1092
|
+
}
|
|
1093
|
+
for (const option of [
|
|
1094
|
+
{ decisionHeadMoved: true },
|
|
1095
|
+
{ baseChangedAfterDecision: "name" },
|
|
1096
|
+
{ baseChangedAfterDecision: "sha" }
|
|
1097
|
+
]) {
|
|
1098
|
+
it(`refuses native head/base decision drift ${JSON.stringify(option)}`, async () => {
|
|
1099
|
+
const { context, merges } = fixture("clean", option);
|
|
1100
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }));
|
|
1101
|
+
assert.equal(merges.length, 0);
|
|
530
1102
|
});
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
1103
|
+
}
|
|
1104
|
+
it("accepts GitHub passing eligibility with native pre-receive hooks", async () => {
|
|
1105
|
+
const { context, merges } = fixture("has_hooks");
|
|
1106
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1107
|
+
assert.equal(merges.length, 1);
|
|
1108
|
+
});
|
|
1109
|
+
it("names a configured required check that has never reported", async () => {
|
|
1110
|
+
const { context, merges } = fixture("blocked", {
|
|
1111
|
+
configuredRequiredChecks: ["local-verify", "money-path-review"],
|
|
1112
|
+
nativeChecks: [{ name: "local-verify", required: true, status: "COMPLETED", conclusion: "SUCCESS" }]
|
|
534
1113
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
1114
|
+
const checks = await prChecks(context, 23);
|
|
1115
|
+
assert.deepEqual(
|
|
1116
|
+
checks.requiredChecks.map((check) => check.name),
|
|
1117
|
+
["local-verify", "money-path-review"]
|
|
1118
|
+
);
|
|
1119
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /money-path-review/u);
|
|
1120
|
+
assert.equal(merges.length, 0);
|
|
1121
|
+
});
|
|
1122
|
+
it("retains configured requirements without relying on a check rollup", async () => {
|
|
1123
|
+
const { context } = fixture("blocked", { configuredRequiredChecks: ["money-path-review"] });
|
|
1124
|
+
const read = context.clients.graphql;
|
|
1125
|
+
context.clients.graphql = (async (query, variables) => {
|
|
1126
|
+
assert.ok(!query.includes("statusCheckRollup"));
|
|
1127
|
+
return read(query, variables);
|
|
541
1128
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
1129
|
+
const checks = await prChecks(context, 23);
|
|
1130
|
+
assert.deepEqual(checks.requiredChecks, [{ name: "money-path-review", headState: "not-reported" }]);
|
|
1131
|
+
});
|
|
1132
|
+
it("discovers an unreported classic-protection requirement", async () => {
|
|
1133
|
+
const { context } = fixture("blocked", {
|
|
1134
|
+
requirementsViaClassic: true,
|
|
1135
|
+
configuredRequiredChecks: ["classic-required"]
|
|
548
1136
|
});
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
assert.equal(result.prNumber, 23);
|
|
1137
|
+
const checks = await prChecks(context, 23);
|
|
1138
|
+
assert.deepEqual(checks.requiredChecks, [{ name: "classic-required", headState: "not-reported" }]);
|
|
1139
|
+
assert.equal(checks.requiredCheckDiscovery, "complete");
|
|
1140
|
+
});
|
|
1141
|
+
it("preserves a failing legacy status beside a successful same-name required check run", async () => {
|
|
1142
|
+
const { context, merges } = fixture("blocked", {
|
|
1143
|
+
nativeChecks: [{ name: "money-path-review", required: true, status: "COMPLETED", conclusion: "SUCCESS" }],
|
|
1144
|
+
nativeStatuses: [{ name: "money-path-review", required: true, state: "FAILURE" }]
|
|
558
1145
|
});
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1146
|
+
const checks = await prChecks(context, 23);
|
|
1147
|
+
assert.equal(checks.headChecksComplete, true);
|
|
1148
|
+
assert.equal(checks.combinedStatus, "failure");
|
|
1149
|
+
assert.equal(checks.requiredChecks.length, 1);
|
|
1150
|
+
assert.match(checks.requiredChecks[0].headState, /success/u);
|
|
1151
|
+
assert.match(checks.requiredChecks[0].headState, /failure/u);
|
|
1152
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /money-path-review/u);
|
|
1153
|
+
assert.equal(merges.length, 0);
|
|
1154
|
+
});
|
|
1155
|
+
it("declares requirement discovery partial when native rule reads are unavailable", async () => {
|
|
1156
|
+
const { context } = fixture("blocked", { requirementsUnavailable: true });
|
|
1157
|
+
const checks = await prChecks(context, 23);
|
|
1158
|
+
assert.equal(checks.requiredCheckDiscovery, "partial");
|
|
1159
|
+
});
|
|
1160
|
+
it("refuses publication of a collaborator PR before promotion", async () => {
|
|
1161
|
+
const { context } = fixture();
|
|
1162
|
+
context.clients.rest.pulls.list = (async () => ({
|
|
1163
|
+
data: [{ number: 23 }]
|
|
1164
|
+
}));
|
|
1165
|
+
const get = context.clients.rest.pulls.get;
|
|
1166
|
+
context.clients.rest.pulls.get = (async (...args) => {
|
|
1167
|
+
const response = await get(...args);
|
|
1168
|
+
return { ...response, data: { ...response.data, user: { ...response.data.user, login: "collaborator" } } };
|
|
571
1169
|
});
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
1170
|
+
await assert.rejects(publishPr(context, { issueNumber: 17, dryRun: true }), /author/u);
|
|
1171
|
+
});
|
|
1172
|
+
it("refuses a non-default PR base before publication", async () => {
|
|
1173
|
+
const { context } = fixture();
|
|
1174
|
+
await assert.rejects(publishPr(context, { issueNumber: 17, baseBranch: "release" }), /default branch/u);
|
|
1175
|
+
});
|
|
1176
|
+
it("refuses conflicting prior PR metadata during dry-run before promotion", async () => {
|
|
1177
|
+
const { context } = fixture();
|
|
1178
|
+
context.clients.rest.pulls.list = (async () => ({
|
|
1179
|
+
data: [{ number: 23 }]
|
|
1180
|
+
}));
|
|
1181
|
+
await assert.rejects(publishPr(context, { issueNumber: 17, body: "Different intent", dryRun: true }), /conflict/u);
|
|
1182
|
+
});
|
|
1183
|
+
it("reads every PR match page before refusing ambiguous branch publication", async () => {
|
|
1184
|
+
const { context } = fixture();
|
|
1185
|
+
context.clients.rest.pulls.list = (async (input) => ({
|
|
1186
|
+
data: input.page === 2 ? [{ number: 24 }] : Array.from({ length: 100 }, () => ({ number: 23 }))
|
|
1187
|
+
}));
|
|
1188
|
+
await assert.rejects(publishPr(context, { issueNumber: 17, dryRun: true }), /conflict/u);
|
|
1189
|
+
});
|
|
1190
|
+
it("creates a PR from its remote issue branch with a plain body and no local evidence", async () => {
|
|
1191
|
+
const { context } = fixture();
|
|
1192
|
+
const result = await publishPr(context, {
|
|
1193
|
+
issueNumber: 17,
|
|
1194
|
+
title: "Improve widget",
|
|
1195
|
+
body: "Plain explanation",
|
|
1196
|
+
draft: false
|
|
578
1197
|
});
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const { context, merges, closes } = fixture('clean', option);
|
|
587
|
-
await assert.rejects(finishIssue(context, { issueNumber: 17, prNumber: 23 }));
|
|
588
|
-
assert.equal(merges.length, 0);
|
|
589
|
-
assert.equal(closes(), 0);
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
it('finishes a merged PR after its issue branch was deleted', async () => {
|
|
593
|
-
const { context, merges, closes } = fixture('clean', { deletedAfterMerge: true });
|
|
594
|
-
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
595
|
-
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
596
|
-
assert.equal(merges.length, 1);
|
|
597
|
-
assert.equal(closes(), 1);
|
|
1198
|
+
assert.equal(result.prNumber, 23);
|
|
1199
|
+
});
|
|
1200
|
+
for (const state of ["blocked", "behind", "dirty", "unknown", null]) {
|
|
1201
|
+
it(`refuses GitHub merge eligibility ${String(state)} without a local receipt fallback`, async () => {
|
|
1202
|
+
const { context, merges } = fixture(state);
|
|
1203
|
+
await assert.rejects(mergePr(context, { issueNumber: 17, prNumber: 23 }), /GitHub|mergeable|clean|CLEAN/u);
|
|
1204
|
+
assert.equal(merges.length, 0);
|
|
598
1205
|
});
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
1206
|
+
}
|
|
1207
|
+
it("uses the independent reviewed SHA as the server merge precondition", async () => {
|
|
1208
|
+
const { context, merges } = fixture();
|
|
1209
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1210
|
+
assert.equal(merges.length, 1);
|
|
1211
|
+
assert.equal(merges[0]?.sha, head);
|
|
1212
|
+
});
|
|
1213
|
+
it("finishes remotely and reuses the merged PR on an interrupted close retry", async () => {
|
|
1214
|
+
const { context, merges, closes } = fixture();
|
|
1215
|
+
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
1216
|
+
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
1217
|
+
assert.equal(merges.length, 1);
|
|
1218
|
+
assert.equal(closes(), 1);
|
|
1219
|
+
});
|
|
1220
|
+
for (const [name, option] of [
|
|
1221
|
+
["moved base", { baseMoved: true }],
|
|
1222
|
+
["moved reviewed head", { headMoved: true }],
|
|
1223
|
+
["unknown decision", { reviewDecision: "UNKNOWN" }],
|
|
1224
|
+
["required review", { reviewDecision: "REVIEW_REQUIRED" }]
|
|
1225
|
+
]) {
|
|
1226
|
+
it(`refuses ${name} without merge or issue closure`, async () => {
|
|
1227
|
+
const { context, merges, closes } = fixture("clean", option);
|
|
1228
|
+
await assert.rejects(finishIssue(context, { issueNumber: 17, prNumber: 23 }));
|
|
1229
|
+
assert.equal(merges.length, 0);
|
|
1230
|
+
assert.equal(closes(), 0);
|
|
604
1231
|
});
|
|
1232
|
+
}
|
|
1233
|
+
it("finishes a merged PR after its issue branch was deleted", async () => {
|
|
1234
|
+
const { context, merges, closes } = fixture("clean", { deletedAfterMerge: true });
|
|
1235
|
+
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
1236
|
+
await finishIssue(context, { issueNumber: 17, prNumber: 23 });
|
|
1237
|
+
assert.equal(merges.length, 1);
|
|
1238
|
+
assert.equal(closes(), 1);
|
|
1239
|
+
});
|
|
1240
|
+
it("never closes another issue after merged-PR association readback disagrees", async () => {
|
|
1241
|
+
const { context, closes, merges } = fixture("clean", { wrongClosingIssue: true });
|
|
1242
|
+
await assert.rejects(finishIssue(context, { issueNumber: 17, prNumber: 23 }));
|
|
1243
|
+
assert.equal(merges.length, 0);
|
|
1244
|
+
assert.equal(closes(), 0);
|
|
1245
|
+
});
|
|
605
1246
|
});
|
|
606
|
-
describe(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
1247
|
+
describe("managed squash usage trailer", () => {
|
|
1248
|
+
const footer = "\n\n<!-- ai-delivery:pr@1 -->";
|
|
1249
|
+
const trailer = "\n\nDelivered-by: ai-delivery";
|
|
1250
|
+
const content = "Closes #17\n\nOriginal body. \r\n\n```md\n<!-- ai-delivery:pr@1 -->\n```";
|
|
1251
|
+
for (const marked of [false, true]) {
|
|
1252
|
+
for (const queued of [false, true]) {
|
|
1253
|
+
it(`sends one closing squash trailer with exact substantive bytes (${marked}, queue=${queued})`, async () => {
|
|
1254
|
+
const { context, merges } = fixture("clean", { prBody: content + (marked ? footer : "") });
|
|
1255
|
+
const input = { issueNumber: 17, prNumber: 23, reviewedHeadSha: head };
|
|
610
1256
|
const preview = await mergePr(context, { ...input, dryRun: true });
|
|
611
|
-
assert.
|
|
612
|
-
assert.equal(preview
|
|
613
|
-
assert.
|
|
1257
|
+
assert.equal(Reflect.get(preview, "commit_title"), "Improve widget");
|
|
1258
|
+
assert.equal(Reflect.get(preview, "commit_message"), content + trailer);
|
|
1259
|
+
assert.notEqual(Reflect.get(preview, "nonClosing"), true);
|
|
614
1260
|
assert.equal(merges.length, 0);
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1261
|
+
const stages = [];
|
|
1262
|
+
await mergePr(
|
|
1263
|
+
context,
|
|
1264
|
+
input,
|
|
1265
|
+
queued ? {
|
|
1266
|
+
expectedBase: "c".repeat(40),
|
|
1267
|
+
checkProof: async () => {
|
|
1268
|
+
stages.push("proof");
|
|
1269
|
+
},
|
|
1270
|
+
beforeMutation: async () => {
|
|
1271
|
+
stages.push("intent");
|
|
1272
|
+
}
|
|
1273
|
+
} : void 0
|
|
1274
|
+
);
|
|
1275
|
+
assert.deepEqual(stages, queued ? ["proof", "intent"] : []);
|
|
1276
|
+
assert.deepEqual(merges[0], {
|
|
1277
|
+
owner: "example",
|
|
1278
|
+
repo: "widget",
|
|
1279
|
+
pull_number: 23,
|
|
1280
|
+
sha: head,
|
|
1281
|
+
merge_method: "squash",
|
|
1282
|
+
commit_title: "Improve widget",
|
|
1283
|
+
commit_message: content + trailer
|
|
1284
|
+
});
|
|
621
1285
|
assert.equal((await mergePr(context, input)).reused, true);
|
|
622
1286
|
assert.equal(merges.length, 1);
|
|
623
|
-
|
|
624
|
-
});
|
|
625
|
-
for (const strategy of ['merge', 'rebase']) {
|
|
626
|
-
it(`refuses ${strategy} before any lifecycle mutation`, async () => {
|
|
627
|
-
const { context, merges, closes } = fixture('clean', { nonClosing: true });
|
|
628
|
-
await assert.rejects(mergePr(context, { ...input, strategy }), /squash/u);
|
|
629
|
-
assert.equal(merges.length, 0);
|
|
630
|
-
assert.equal(closes(), 0);
|
|
631
|
-
});
|
|
1287
|
+
});
|
|
632
1288
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
1289
|
+
}
|
|
1290
|
+
for (const strategy of ["merge", "rebase"]) {
|
|
1291
|
+
it(`preserves native ${strategy} messages without a squash trailer`, async () => {
|
|
1292
|
+
const { context, merges } = fixture("clean", { prBody: content + footer, messageChangedAfterDecision: "body" });
|
|
1293
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23, strategy });
|
|
1294
|
+
assert.deepEqual(merges[0], {
|
|
1295
|
+
owner: "example",
|
|
1296
|
+
repo: "widget",
|
|
1297
|
+
pull_number: 23,
|
|
1298
|
+
sha: head,
|
|
1299
|
+
merge_method: strategy
|
|
1300
|
+
});
|
|
641
1301
|
});
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
{
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
1302
|
+
}
|
|
1303
|
+
for (const field of ["title", "body"]) {
|
|
1304
|
+
for (const mode of ["direct", "queued", "dry-run"]) {
|
|
1305
|
+
it(`refuses closing squash ${field} drift after the review read (${mode})`, async () => {
|
|
1306
|
+
const { context, merges } = fixture("clean", { messageChangedAfterDecision: field });
|
|
1307
|
+
const stages = [];
|
|
1308
|
+
await assert.rejects(
|
|
1309
|
+
mergePr(
|
|
1310
|
+
context,
|
|
1311
|
+
{ issueNumber: 17, prNumber: 23, dryRun: mode === "dry-run" },
|
|
1312
|
+
mode === "queued" ? {
|
|
1313
|
+
expectedBase: "c".repeat(40),
|
|
1314
|
+
checkProof: async () => {
|
|
1315
|
+
stages.push("proof");
|
|
1316
|
+
},
|
|
1317
|
+
beforeMutation: async () => {
|
|
1318
|
+
stages.push("intent");
|
|
1319
|
+
}
|
|
1320
|
+
} : void 0
|
|
1321
|
+
),
|
|
1322
|
+
/message.*changed|message.*drift/iu
|
|
1323
|
+
);
|
|
1324
|
+
assert.equal(merges.length, 0);
|
|
1325
|
+
assert.deepEqual(stages, []);
|
|
1326
|
+
});
|
|
654
1327
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
1328
|
+
}
|
|
1329
|
+
it("does not duplicate a canonical final trailer already present in substantive content", async () => {
|
|
1330
|
+
const { context, merges } = fixture("clean", { prBody: content + trailer + footer });
|
|
1331
|
+
await mergePr(context, { issueNumber: 17, prNumber: 23 });
|
|
1332
|
+
assert.equal(merges[0].commit_message, content + trailer);
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
describe("retained issue guarded squash delivery", () => {
|
|
1336
|
+
const input = { issueNumber: 17, prNumber: 23, reviewedHeadSha: head, nonClosing: true };
|
|
1337
|
+
it("sends explicit safe squash messages at the approved SHA and reuses merged readback without closing", async () => {
|
|
1338
|
+
const { context, merges, closes } = fixture("clean", { nonClosing: true });
|
|
1339
|
+
const preview = await mergePr(context, { ...input, dryRun: true });
|
|
1340
|
+
assert.ok("commit_title" in preview && "commit_message" in preview);
|
|
1341
|
+
assert.equal(preview.commit_title, "Improve widget");
|
|
1342
|
+
assert.equal(
|
|
1343
|
+
preview.commit_message,
|
|
1344
|
+
"References example/widget#17\n\nDelivered by PR #23.\n\nDelivered-by: ai-delivery"
|
|
1345
|
+
);
|
|
1346
|
+
assert.equal(merges.length, 0);
|
|
1347
|
+
const result = await mergePr(context, input);
|
|
1348
|
+
assert.equal(result.mergeSha, merge);
|
|
1349
|
+
assert.equal(merges[0].sha, head);
|
|
1350
|
+
assert.equal(merges[0].merge_method, "squash");
|
|
1351
|
+
assert.equal(merges[0].commit_title, preview.commit_title);
|
|
1352
|
+
assert.equal(merges[0].commit_message, preview.commit_message);
|
|
1353
|
+
assert.equal((await mergePr(context, input)).reused, true);
|
|
1354
|
+
assert.equal(merges.length, 1);
|
|
1355
|
+
assert.equal(closes(), 0);
|
|
1356
|
+
});
|
|
1357
|
+
for (const strategy of ["merge", "rebase"]) {
|
|
1358
|
+
it(`refuses ${strategy} before any lifecycle mutation`, async () => {
|
|
1359
|
+
const { context, merges, closes } = fixture("clean", { nonClosing: true });
|
|
1360
|
+
await assert.rejects(mergePr(context, { ...input, strategy }), /squash/u);
|
|
1361
|
+
assert.equal(merges.length, 0);
|
|
1362
|
+
assert.equal(closes(), 0);
|
|
660
1363
|
});
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
1364
|
+
}
|
|
1365
|
+
it("refuses finish before even reading or merging the PR", async () => {
|
|
1366
|
+
const { context, merges, closes } = fixture("clean", { nonClosing: true });
|
|
1367
|
+
context.clients.rest.pulls.get = (() => {
|
|
1368
|
+
throw new Error("No lifecycle call allowed");
|
|
1369
|
+
});
|
|
1370
|
+
await assert.rejects(finishIssue(context, input), /cannot finish/u);
|
|
1371
|
+
assert.equal(merges.length, 0);
|
|
1372
|
+
assert.equal(closes(), 0);
|
|
1373
|
+
});
|
|
1374
|
+
for (const option of [
|
|
1375
|
+
{ reviewDecision: "REVIEW_REQUIRED" },
|
|
1376
|
+
{ baseMoved: true },
|
|
1377
|
+
{ headMoved: true },
|
|
1378
|
+
{ commitMessage: "Fixes: other/repo#5" }
|
|
1379
|
+
]) {
|
|
1380
|
+
it(`preserves fail-closed merge guards: ${JSON.stringify(option)}`, async () => {
|
|
1381
|
+
const { context, merges, closes } = fixture("clean", { ...option, nonClosing: true });
|
|
1382
|
+
await assert.rejects(mergePr(context, input));
|
|
1383
|
+
assert.equal(merges.length, 0);
|
|
1384
|
+
assert.equal(closes(), 0);
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
it("reports post-merge issue criteria drift without reopening or replaying the merge", async () => {
|
|
1388
|
+
const { context, merges, closes } = fixture("clean", { nonClosing: true, retainedIssueDrift: true });
|
|
1389
|
+
await assert.rejects(mergePr(context, input), /criteria drifted/u);
|
|
1390
|
+
assert.equal(merges.length, 1);
|
|
1391
|
+
assert.equal(closes(), 0);
|
|
1392
|
+
});
|
|
1393
|
+
it("reconciles an uncertain merge acknowledgement through authoritative merged readback", async () => {
|
|
1394
|
+
const { context, merges, closes } = fixture("clean", { nonClosing: true, mergeAckLost: true });
|
|
1395
|
+
await assert.rejects(mergePr(context, input), /acknowledgement lost/u);
|
|
1396
|
+
assert.equal((await mergePr(context, input)).reused, true);
|
|
1397
|
+
assert.equal(merges.length, 1);
|
|
1398
|
+
assert.equal(closes(), 0);
|
|
1399
|
+
});
|
|
1400
|
+
});
|
|
1401
|
+
function recordedFlow(input = {}) {
|
|
1402
|
+
const headSha = input.headSha ?? recordedZeroApproval.repository.pullRequest.headRefOid;
|
|
1403
|
+
const baseSha = input.baseSha ?? recordedZeroApproval.repository.pullRequest.baseRefOid;
|
|
1404
|
+
const current = fixture(input.state ?? "clean", {
|
|
1405
|
+
headSha,
|
|
1406
|
+
baseSha,
|
|
1407
|
+
reviewDecision: null,
|
|
1408
|
+
configuredRequiredChecks: ["checks"],
|
|
1409
|
+
nativeChecks: input.missingCheck ? [] : [
|
|
1410
|
+
{
|
|
1411
|
+
name: "checks",
|
|
1412
|
+
required: true,
|
|
1413
|
+
status: "COMPLETED",
|
|
1414
|
+
conclusion: input.failedCheck ? "FAILURE" : "SUCCESS"
|
|
1415
|
+
}
|
|
1416
|
+
]
|
|
1417
|
+
});
|
|
1418
|
+
const { context } = current;
|
|
1419
|
+
const events = [];
|
|
1420
|
+
const { pulls, git, issues } = context.clients.rest;
|
|
1421
|
+
const get = pulls.get;
|
|
1422
|
+
pulls.get = (async (...args) => {
|
|
1423
|
+
assert.deepEqual(args[0], { owner: "example", repo: "widget", pull_number: 23 });
|
|
1424
|
+
events.push("pr");
|
|
1425
|
+
const result = await get(...args);
|
|
1426
|
+
return { ...result, data: { ...result.data, draft: input.draft ?? false } };
|
|
1427
|
+
});
|
|
1428
|
+
const graphql = context.clients.graphql;
|
|
1429
|
+
context.clients.graphql = (async (query, variables) => {
|
|
1430
|
+
if (!query.includes("DeliveryReviewDecision")) return graphql(query, variables);
|
|
1431
|
+
assert.deepEqual(variables, { owner: "example", name: "widget", number: 23 });
|
|
1432
|
+
events.push("decision");
|
|
1433
|
+
return {
|
|
1434
|
+
repository: {
|
|
1435
|
+
pullRequest: {
|
|
1436
|
+
headRefOid: headSha,
|
|
1437
|
+
...input.missingDecision ? {} : { reviewDecision: recordedZeroApproval.repository.pullRequest.reviewDecision }
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
});
|
|
1442
|
+
const getRef = git.getRef;
|
|
1443
|
+
git.getRef = (async (...args) => {
|
|
1444
|
+
const result = await getRef(...args);
|
|
1445
|
+
if (args[0]?.ref !== "heads/main") return result;
|
|
1446
|
+
events.push("main");
|
|
1447
|
+
return { ...result, data: { ...result.data, object: { type: "commit", sha: input.mainSha ?? baseSha } } };
|
|
1448
|
+
});
|
|
1449
|
+
const merge2 = pulls.merge;
|
|
1450
|
+
pulls.merge = (async (...args) => {
|
|
1451
|
+
events.push("merge");
|
|
1452
|
+
assert.deepEqual(args[0], {
|
|
1453
|
+
owner: "example",
|
|
1454
|
+
repo: "widget",
|
|
1455
|
+
pull_number: 23,
|
|
1456
|
+
sha: headSha,
|
|
1457
|
+
merge_method: "squash",
|
|
1458
|
+
commit_title: "Improve widget",
|
|
1459
|
+
commit_message: "Closes #17\n\nDelivered-by: ai-delivery"
|
|
1460
|
+
});
|
|
1461
|
+
return merge2(...args);
|
|
1462
|
+
});
|
|
1463
|
+
const update = issues.update;
|
|
1464
|
+
issues.update = (async (...args) => {
|
|
1465
|
+
events.push("close");
|
|
1466
|
+
assert.deepEqual(args[0], {
|
|
1467
|
+
owner: "example",
|
|
1468
|
+
repo: "widget",
|
|
1469
|
+
issue_number: 17,
|
|
1470
|
+
state: "closed",
|
|
1471
|
+
state_reason: "completed"
|
|
1472
|
+
});
|
|
1473
|
+
return update(...args);
|
|
1474
|
+
});
|
|
1475
|
+
return { ...current, events };
|
|
1476
|
+
}
|
|
1477
|
+
describe("recorded public fragments with labeled synthetic transitions", () => {
|
|
1478
|
+
it("keeps the observed zero-review draft ineligible without merge or closure", async () => {
|
|
1479
|
+
const current = recordedFlow({ draft: recordedZeroApproval.repository.pullRequest.isDraft });
|
|
1480
|
+
await assert.rejects(finishIssue(current.context, { issueNumber: 17, prNumber: 23 }), /open and ready/u);
|
|
1481
|
+
assert.deepEqual(current.events, ["pr"]);
|
|
1482
|
+
assert.equal(current.merges.length + current.closes(), 0);
|
|
1483
|
+
});
|
|
1484
|
+
it("finishes a synthetic ready/CLEAN transition with observed null and exact head", async () => {
|
|
1485
|
+
const current = recordedFlow();
|
|
1486
|
+
const result = await finishIssue(current.context, { issueNumber: 17, prNumber: 23 });
|
|
1487
|
+
assert.equal(result.headSha, "4b54bd4b663a32957e4571e2af112f828fbc0a58");
|
|
1488
|
+
assert.equal(current.closes(), 1);
|
|
1489
|
+
assert.equal(current.merges.length, 1);
|
|
1490
|
+
assert.deepEqual(current.events, ["pr", "pr", "decision", "pr", "main", "merge", "pr", "pr", "close"]);
|
|
1491
|
+
});
|
|
1492
|
+
it("performs no mutation for the synthetic ready/null finish dry-run", async () => {
|
|
1493
|
+
const current = recordedFlow();
|
|
1494
|
+
const result = await finishIssue(current.context, { issueNumber: 17, prNumber: 23, dryRun: true });
|
|
1495
|
+
assert.ok("dryRun" in result && result.dryRun);
|
|
1496
|
+
assert.deepEqual(current.events, ["pr", "pr", "decision", "pr", "main"]);
|
|
1497
|
+
assert.equal(current.merges.length + current.closes(), 0);
|
|
1498
|
+
});
|
|
1499
|
+
it("refuses a synthetic missing decision rather than treating it as observed null", async () => {
|
|
1500
|
+
const current = recordedFlow({ missingDecision: true });
|
|
1501
|
+
await assert.rejects(finishIssue(current.context, { issueNumber: 17, prNumber: 23 }), /review eligibility/u);
|
|
1502
|
+
assert.deepEqual(current.events, ["pr", "pr", "decision", "pr"]);
|
|
1503
|
+
assert.equal(current.merges.length + current.closes(), 0);
|
|
1504
|
+
});
|
|
1505
|
+
for (const [name, input] of [
|
|
1506
|
+
["failed required check", { state: "blocked", failedCheck: true }],
|
|
1507
|
+
["missing required check", { state: "blocked", missingCheck: true }],
|
|
1508
|
+
["behind", { state: "behind" }],
|
|
1509
|
+
["dirty", { state: "dirty" }]
|
|
1510
|
+
]) {
|
|
1511
|
+
it(`refuses synthetic native ${name} without merge or closure`, async () => {
|
|
1512
|
+
const current = recordedFlow(input);
|
|
1513
|
+
await assert.rejects(
|
|
1514
|
+
finishIssue(current.context, { issueNumber: 17, prNumber: 23 }),
|
|
1515
|
+
/GitHub merge eligibility/u
|
|
1516
|
+
);
|
|
1517
|
+
assert.deepEqual(current.events, ["pr", "pr", "decision", "pr"]);
|
|
1518
|
+
assert.equal(current.merges.length + current.closes(), 0);
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
it("refuses recorded UNKNOWN drift and a synthetic CLEAN interleaving, then accepts a fresh retry", async () => {
|
|
1522
|
+
const before = recordedBaseDrift.before.repository.pullRequest;
|
|
1523
|
+
const drift = recordedBaseDrift.after.repository;
|
|
1524
|
+
const unknown = recordedFlow({
|
|
1525
|
+
headSha: before.headRefOid,
|
|
1526
|
+
baseSha: before.baseRefOid,
|
|
1527
|
+
state: drift.pullRequest.mergeStateStatus.toLowerCase()
|
|
1528
|
+
});
|
|
1529
|
+
await assert.rejects(mergePr(unknown.context, { issueNumber: 17, prNumber: 23 }), /GitHub merge eligibility/u);
|
|
1530
|
+
assert.deepEqual(unknown.events, ["pr", "pr", "decision", "pr"]);
|
|
1531
|
+
const race = recordedFlow({
|
|
1532
|
+
headSha: before.headRefOid,
|
|
1533
|
+
baseSha: before.baseRefOid,
|
|
1534
|
+
mainSha: drift.defaultBranchRef.target.oid
|
|
1535
|
+
});
|
|
1536
|
+
await assert.rejects(finishIssue(race.context, { issueNumber: 17, prNumber: 23 }), /base moved/u);
|
|
1537
|
+
assert.deepEqual(race.events, ["pr", "pr", "decision", "pr", "main"]);
|
|
1538
|
+
assert.equal(unknown.merges.length + race.merges.length + race.closes(), 0);
|
|
1539
|
+
const retry = recordedFlow({ headSha: before.headRefOid, baseSha: drift.defaultBranchRef.target.oid });
|
|
1540
|
+
await mergePr(retry.context, {
|
|
1541
|
+
issueNumber: 17,
|
|
1542
|
+
prNumber: 23,
|
|
1543
|
+
reviewedHeadSha: "47cb7643c494c44bdecdfe8ca7449c7b3b884aaa"
|
|
1544
|
+
});
|
|
1545
|
+
assert.equal(retry.merges.length, 1);
|
|
1546
|
+
assert.deepEqual(retry.events, ["pr", "pr", "decision", "pr", "main", "merge", "pr"]);
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
describe("verified finish registered source cleanup", () => {
|
|
1550
|
+
for (const mode of [
|
|
1551
|
+
"clean",
|
|
1552
|
+
"squash",
|
|
1553
|
+
"dirty",
|
|
1554
|
+
"unretained",
|
|
1555
|
+
"mismatched",
|
|
1556
|
+
"ignored",
|
|
1557
|
+
"hidden",
|
|
1558
|
+
"unregistered",
|
|
1559
|
+
"absent",
|
|
1560
|
+
"wrong-pr",
|
|
1561
|
+
"overlap",
|
|
1562
|
+
"pr-overlap",
|
|
1563
|
+
"owner-race",
|
|
1564
|
+
"symbolic",
|
|
1565
|
+
"aliased",
|
|
1566
|
+
"ineligible",
|
|
1567
|
+
"dry-run"
|
|
1568
|
+
]) {
|
|
1569
|
+
it(`finishes with ${mode} local source without losing unretained data`, async () => {
|
|
1570
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "finish-cleanup-")));
|
|
1571
|
+
const git = (cwd, ...args) => execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
1572
|
+
try {
|
|
1573
|
+
git(root, "init", "-q", "-b", "main");
|
|
1574
|
+
git(root, "config", "user.name", "Fixture");
|
|
1575
|
+
git(root, "config", "user.email", "fixture@example.invalid");
|
|
1576
|
+
writeFileSync(join(root, "change.ts"), "base\n");
|
|
1577
|
+
git(root, "add", ".");
|
|
1578
|
+
git(root, "commit", "-qm", "base");
|
|
1579
|
+
const base = git(root, "rev-parse", "HEAD");
|
|
1580
|
+
git(root, "remote", "add", "origin", "https://github.com/example/widget.git");
|
|
1581
|
+
const path = join(root, ".worktrees", "issue-17");
|
|
1582
|
+
git(root, "worktree", "add", "-b", "issue/17", path);
|
|
1583
|
+
writeFileSync(join(path, "change.ts"), "delivered\n");
|
|
1584
|
+
git(path, "commit", "-qam", "change");
|
|
1585
|
+
const source = git(path, "rev-parse", "HEAD");
|
|
1586
|
+
let merged = source;
|
|
1587
|
+
if (mode === "squash" || mode === "owner-race") {
|
|
1588
|
+
git(root, "merge", "--squash", "issue/17");
|
|
1589
|
+
git(root, "commit", "-qm", "squash");
|
|
1590
|
+
merged = git(root, "rev-parse", "HEAD");
|
|
1591
|
+
}
|
|
1592
|
+
git(root, "update-ref", "refs/remotes/origin/main", mode === "unretained" ? base : merged);
|
|
1593
|
+
git(root, "update-ref", "refs/heads/unrelated", base);
|
|
1594
|
+
if (mode !== "unregistered")
|
|
1595
|
+
await addWorktreeEntry(
|
|
1596
|
+
{
|
|
1597
|
+
path,
|
|
1598
|
+
branch: "issue/17",
|
|
1599
|
+
type: "issue",
|
|
1600
|
+
identity: "author",
|
|
1601
|
+
issueNumber: 17,
|
|
1602
|
+
...mode === "pr-overlap" ? {} : { prNumber: mode === "wrong-pr" ? 24 : 23 },
|
|
1603
|
+
status: mode === "pr-overlap" ? "active" : "pr-published",
|
|
1604
|
+
createdAt: "2026-01-01T00:00:00.000Z",
|
|
1605
|
+
updatedAt: "2026-01-01T00:00:00.000Z"
|
|
1606
|
+
},
|
|
1607
|
+
root
|
|
1608
|
+
);
|
|
1609
|
+
let competingRegistry;
|
|
1610
|
+
const registryPath = join(root, ISSUE_CLI_DATA_DIR, "worktrees.json");
|
|
1611
|
+
if (mode === "overlap" || mode === "pr-overlap") {
|
|
1612
|
+
const registry = { worktrees: listWorktreesStrict(root) };
|
|
1613
|
+
const other = { ...registry.worktrees[0], type: "standalone" };
|
|
1614
|
+
delete other.issueNumber;
|
|
1615
|
+
if (mode === "pr-overlap") {
|
|
1616
|
+
other.path = join(root, ".worktrees", "claimed-pr");
|
|
1617
|
+
other.branch = "claimed-pr";
|
|
1618
|
+
other.prNumber = 23;
|
|
1619
|
+
await addWorktreeEntry(other, root);
|
|
1620
|
+
competingRegistry = readFileSync(registryPath, "utf8");
|
|
1621
|
+
} else {
|
|
1622
|
+
delete other.prNumber;
|
|
1623
|
+
registry.worktrees.push(other);
|
|
1624
|
+
competingRegistry = JSON.stringify(registry);
|
|
1625
|
+
writeFileSync(registryPath, competingRegistry);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
if (mode === "dirty" || mode === "hidden") writeFileSync(join(path, "change.ts"), "local data\n");
|
|
1629
|
+
if (mode === "hidden") git(path, "update-index", "--assume-unchanged", "change.ts");
|
|
1630
|
+
if (mode === "mismatched") git(path, "checkout", "-b", "other");
|
|
1631
|
+
if (mode === "ignored") {
|
|
1632
|
+
writeFileSync(join(root, ".git", "info", "exclude"), "cached.txt\n");
|
|
1633
|
+
writeFileSync(join(path, "cached.txt"), "local data\n");
|
|
1634
|
+
}
|
|
1635
|
+
if (mode === "absent") {
|
|
1636
|
+
git(root, "worktree", "remove", path);
|
|
1637
|
+
git(root, "update-ref", "-d", "refs/heads/issue/17", source);
|
|
1638
|
+
}
|
|
1639
|
+
if (mode === "symbolic") {
|
|
1640
|
+
git(root, "worktree", "remove", path);
|
|
1641
|
+
git(root, "update-ref", "refs/heads/unrelated", source);
|
|
1642
|
+
git(root, "symbolic-ref", "refs/heads/issue/17", "refs/heads/unrelated");
|
|
1643
|
+
}
|
|
1644
|
+
if (mode === "aliased") {
|
|
1645
|
+
renameSync(join(root, ".worktrees"), join(root, "physical-source"));
|
|
1646
|
+
symlinkSync(join(root, "physical-source"), join(root, ".worktrees"), "dir");
|
|
1647
|
+
}
|
|
1648
|
+
const f = fixture(mode === "ineligible" ? "blocked" : "clean", {
|
|
1649
|
+
headSha: source,
|
|
1650
|
+
headTree: git(root, "rev-parse", `${source}^{tree}`),
|
|
1651
|
+
baseSha: base,
|
|
1652
|
+
mergeSha: mode === "unretained" ? "b".repeat(40) : merged,
|
|
1653
|
+
remoteBaseSha: merged
|
|
1654
|
+
});
|
|
1655
|
+
f.context.root = root;
|
|
1656
|
+
if (mode === "owner-race") {
|
|
1657
|
+
const getRef = f.context.clients.rest.git.getRef;
|
|
1658
|
+
let replaced = false;
|
|
1659
|
+
Object.assign(f.context.clients.rest.git, {
|
|
1660
|
+
getRef: async (input) => {
|
|
1661
|
+
if (f.closes() > 0 && input.ref === "heads/main" && !replaced) {
|
|
1662
|
+
replaced = true;
|
|
1663
|
+
const current = listWorktreesStrict(root)[0];
|
|
1664
|
+
await removeWorktreeEntry(path, root);
|
|
1665
|
+
await addWorktreeEntry({ ...current, identity: "other-owner" }, root);
|
|
1666
|
+
}
|
|
1667
|
+
return getRef(input);
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
if (mode === "ineligible" || mode === "dry-run") {
|
|
1672
|
+
const finish = () => finishIssue(f.context, { issueNumber: 17, prNumber: 23, dryRun: mode === "dry-run" });
|
|
1673
|
+
if (mode === "ineligible") await assert.rejects(finish());
|
|
1674
|
+
else await finish();
|
|
1675
|
+
assert.equal(existsSync(path), true);
|
|
1676
|
+
assert.equal(git(root, "rev-parse", "refs/heads/issue/17"), source);
|
|
1677
|
+
assert.equal(readFileSync(join(path, "change.ts"), "utf8"), "delivered\n");
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
const result = await finishIssue(f.context, { issueNumber: 17, prNumber: 23 });
|
|
1681
|
+
assert.ok("issueClosed" in result && result.issueClosed);
|
|
1682
|
+
assert.ok("cleanup" in result);
|
|
1683
|
+
if (mode === "clean" || mode === "squash" || mode === "absent") {
|
|
1684
|
+
assert.deepEqual(result.cleanup, { status: "removed" });
|
|
1685
|
+
assert.equal(existsSync(path), false);
|
|
1686
|
+
assert.throws(() => git(root, "rev-parse", "--verify", "refs/heads/issue/17"));
|
|
1687
|
+
assert.deepEqual(listWorktreesStrict(root), []);
|
|
1688
|
+
const replay = await finishIssue(f.context, { issueNumber: 17, prNumber: 23 });
|
|
1689
|
+
assert.ok("issueClosed" in replay && replay.issueClosed);
|
|
1690
|
+
} else if (mode === "symbolic") {
|
|
1691
|
+
assert.equal(existsSync(path), false);
|
|
1692
|
+
assert.equal(git(root, "symbolic-ref", "refs/heads/issue/17"), "refs/heads/unrelated");
|
|
1693
|
+
assert.equal(git(root, "rev-parse", "refs/heads/unrelated"), source);
|
|
1694
|
+
assert.equal(result.cleanup.status, "retained");
|
|
1695
|
+
} else {
|
|
1696
|
+
assert.equal(existsSync(path), true);
|
|
1697
|
+
assert.equal(git(root, "rev-parse", "refs/heads/issue/17"), source);
|
|
1698
|
+
assert.equal(
|
|
1699
|
+
readFileSync(join(path, "change.ts"), "utf8"),
|
|
1700
|
+
mode === "dirty" || mode === "hidden" ? "local data\n" : "delivered\n"
|
|
1701
|
+
);
|
|
1702
|
+
if (mode === "ignored") assert.equal(readFileSync(join(path, "cached.txt"), "utf8"), "local data\n");
|
|
1703
|
+
assert.ok(JSON.stringify(result).includes(mode === "unregistered" ? "absent" : "retained"));
|
|
1704
|
+
}
|
|
1705
|
+
if (mode === "overlap" || mode === "pr-overlap")
|
|
1706
|
+
assert.equal(readFileSync(registryPath, "utf8"), competingRegistry);
|
|
1707
|
+
if (mode === "owner-race") assert.equal(listWorktreesStrict(root)[0].identity, "other-owner");
|
|
1708
|
+
assert.equal(git(root, "rev-parse", "refs/heads/unrelated"), mode === "symbolic" ? source : base);
|
|
1709
|
+
} finally {
|
|
1710
|
+
rmSync(root, { recursive: true, force: true });
|
|
1711
|
+
}
|
|
667
1712
|
});
|
|
1713
|
+
}
|
|
668
1714
|
});
|
|
669
|
-
//# sourceMappingURL=pr.test.js.map
|
|
1715
|
+
//# sourceMappingURL=pr.test.js.map
|