@feigi/fleet-ctl 0.0.0
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/.claude-plugin/plugin.json +9 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/agents/fleet-finisher.agent.md +7 -0
- package/agents/fleet-implementer-alt.agent.md +210 -0
- package/agents/fleet-implementer.agent.md +210 -0
- package/agents/fleet-merge-bot.agent.md +7 -0
- package/agents/fleet-review-comments.agent.md +40 -0
- package/agents/fleet-review-correctness.agent.md +43 -0
- package/agents/fleet-review-runner.agent.md +73 -0
- package/agents/fleet-review-silent-failure.agent.md +49 -0
- package/agents/fleet-review-simplify.agent.md +46 -0
- package/agents/fleet-review-snapshot.agent.md +24 -0
- package/agents/fleet-review-tests.agent.md +46 -0
- package/agents/fleet-review-types.agent.md +41 -0
- package/agents/fleet-review-verifier.agent.md +29 -0
- package/commands/review-and-fix.md +98 -0
- package/commands/run-merge-bot.md +357 -0
- package/commands/run-team-help.md +17 -0
- package/package.json +23 -0
- package/scripts/agent-test-dir-prose.test.mjs +59 -0
- package/scripts/agent-test.test.mjs +1636 -0
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
- package/scripts/ambient-git-vars-prose.test.mjs +192 -0
- package/scripts/ancestry-check-position-prose.test.mjs +175 -0
- package/scripts/apply-ruleset.test.mjs +420 -0
- package/scripts/arg-header-probes-prose.test.mjs +393 -0
- package/scripts/arg.mjs +600 -0
- package/scripts/arg.test.mjs +1354 -0
- package/scripts/board-cli.test.mjs +694 -0
- package/scripts/board-identity.test.mjs +429 -0
- package/scripts/board-liveness-banner.test.mjs +119 -0
- package/scripts/board-prev-shape.test.mjs +229 -0
- package/scripts/board-tryparse-null.test.mjs +119 -0
- package/scripts/board.html +471 -0
- package/scripts/board.mjs +2037 -0
- package/scripts/board.test.mjs +3086 -0
- package/scripts/brief-after-cut-prose.test.mjs +53 -0
- package/scripts/candidates-exit3-prose.test.mjs +302 -0
- package/scripts/candidates.mjs +674 -0
- package/scripts/candidates.test.mjs +2101 -0
- package/scripts/caveat-unification-prose.test.mjs +98 -0
- package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
- package/scripts/ci-completes-premise-prose.test.mjs +257 -0
- package/scripts/ci-state-prose.test.mjs +113 -0
- package/scripts/ci-state.mjs +761 -0
- package/scripts/ci-state.test.mjs +1640 -0
- package/scripts/ci-vacuous-green.test.mjs +368 -0
- package/scripts/citation-sweep-prose.test.mjs +1572 -0
- package/scripts/claim-lifecycle.test.mjs +185 -0
- package/scripts/claim-ticket.sh +417 -0
- package/scripts/claim-ticket.test.mjs +1121 -0
- package/scripts/closing-keyword-prose.test.mjs +193 -0
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
- package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
- package/scripts/compute-board.mjs +579 -0
- package/scripts/compute-board.test.mjs +1060 -0
- package/scripts/compute-spend.mjs +329 -0
- package/scripts/compute-spend.test.mjs +451 -0
- package/scripts/cross-repo-citation-prose.test.mjs +156 -0
- package/scripts/cwd-isolation-pins.mjs +83 -0
- package/scripts/dedupe-guard-prose.test.mjs +243 -0
- package/scripts/derive-testcmd.sh +239 -0
- package/scripts/derive-testcmd.test.mjs +380 -0
- package/scripts/diff-stats.mjs +231 -0
- package/scripts/diff-stats.test.mjs +408 -0
- package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
- package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
- package/scripts/drop-merged-label.sh +173 -0
- package/scripts/drop-merged-label.test.mjs +480 -0
- package/scripts/expected-jobs-prose.test.mjs +80 -0
- package/scripts/filing-bar-seat-prose.test.mjs +242 -0
- package/scripts/filing-claim-bar-prose.test.mjs +166 -0
- package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
- package/scripts/finisher-halt-prose.test.mjs +106 -0
- package/scripts/finisher-name-prose.test.mjs +134 -0
- package/scripts/finisher-own-tree-prose.test.mjs +285 -0
- package/scripts/finisher-pin-race-prose.test.mjs +339 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
- package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
- package/scripts/fleet-bootstrap +155 -0
- package/scripts/fleet-heartbeat.mjs +272 -0
- package/scripts/fleet-heartbeat.test.mjs +450 -0
- package/scripts/fleet-provenance +207 -0
- package/scripts/fleet-provenance.test.mjs +64 -0
- package/scripts/fleet-run +148 -0
- package/scripts/fleet-run.test.mjs +90 -0
- package/scripts/fleet-state.mjs +400 -0
- package/scripts/fleet-state.test.mjs +373 -0
- package/scripts/fleet-tick-prose.test.mjs +299 -0
- package/scripts/fleet-tick.mjs +832 -0
- package/scripts/fleet-tick.test.mjs +1332 -0
- package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
- package/scripts/frontmatter-allowlist.json +64 -0
- package/scripts/frontmatter-check.mjs +256 -0
- package/scripts/frontmatter-check.test.mjs +436 -0
- package/scripts/git-env.mjs +124 -0
- package/scripts/git-env.test.mjs +149 -0
- package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
- package/scripts/gone-walk.test.mjs +213 -0
- package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
- package/scripts/head-moved-after-label-prose.test.mjs +233 -0
- package/scripts/immutable-body-claim-prose.test.mjs +413 -0
- package/scripts/implementer-model-tier.test.mjs +643 -0
- package/scripts/inflight-citation-prose.test.mjs +144 -0
- package/scripts/inflight-exit2-prose.test.mjs +81 -0
- package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
- package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
- package/scripts/inflight.sh +1106 -0
- package/scripts/inflight.test.mjs +2984 -0
- package/scripts/injection-control-prose.test.mjs +404 -0
- package/scripts/install-root-audit.test.mjs +464 -0
- package/scripts/instrument-check-prose.test.mjs +235 -0
- package/scripts/instruments.sh +394 -0
- package/scripts/instruments.test.mjs +787 -0
- package/scripts/issue-tracker-prose.test.mjs +71 -0
- package/scripts/json.sh +248 -0
- package/scripts/json.test.mjs +364 -0
- package/scripts/ledger-dispatch.test.mjs +516 -0
- package/scripts/ledger-grammar.mjs +85 -0
- package/scripts/ledger-grammar.test.mjs +142 -0
- package/scripts/ledger-read-require-file.test.mjs +197 -0
- package/scripts/ledger.mjs +1753 -0
- package/scripts/ledger.test.mjs +3554 -0
- package/scripts/line-distance-prose.test.mjs +245 -0
- package/scripts/liveness-rationale-prose.test.mjs +83 -0
- package/scripts/locale-pin-prose.test.mjs +189 -0
- package/scripts/member-outcome-prose.test.mjs +167 -0
- package/scripts/member-outcomes-header.test.mjs +148 -0
- package/scripts/member-outcomes-prose.test.mjs +63 -0
- package/scripts/member-outcomes.mjs +231 -0
- package/scripts/member-outcomes.test.mjs +507 -0
- package/scripts/member-prompt-prose.test.mjs +161 -0
- package/scripts/member-record.mjs +605 -0
- package/scripts/member-record.test.mjs +516 -0
- package/scripts/member-write-guard.mjs +279 -0
- package/scripts/member-write-guard.test.mjs +211 -0
- package/scripts/merge-commit-probe-prose.test.mjs +122 -0
- package/scripts/merge-gate.mjs +262 -0
- package/scripts/merge-gate.test.mjs +613 -0
- package/scripts/muted-git-guard-sweep.test.mjs +493 -0
- package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
- package/scripts/net-watchdog-prose.test.mjs +79 -0
- package/scripts/net.sh +409 -0
- package/scripts/net.test.mjs +211 -0
- package/scripts/no-ci-gate-prose.test.mjs +108 -0
- package/scripts/no-undo-audit.sh +1134 -0
- package/scripts/no-undo-audit.test.mjs +3965 -0
- package/scripts/no-wave.test.mjs +138 -0
- package/scripts/node-floor-sweep.test.mjs +611 -0
- package/scripts/pointer-target-prose.test.mjs +186 -0
- package/scripts/pr-overlap.mjs +417 -0
- package/scripts/pr-overlap.test.mjs +695 -0
- package/scripts/printf-die-sweep.test.mjs +384 -0
- package/scripts/prompt-renderer.mjs +39 -0
- package/scripts/prompt-renderer.test.mjs +68 -0
- package/scripts/prose-pin.mjs +808 -0
- package/scripts/prose-pin.test.mjs +1034 -0
- package/scripts/prove-merge.sh +228 -0
- package/scripts/prove-merge.test.mjs +995 -0
- package/scripts/pull-table-relabel-prose.test.mjs +60 -0
- package/scripts/quiet-payload-prose.test.mjs +222 -0
- package/scripts/reap.sh +1768 -0
- package/scripts/reap.test.mjs +4395 -0
- package/scripts/reaping-prose.test.mjs +159 -0
- package/scripts/refuter-scratch-prose.test.mjs +135 -0
- package/scripts/release-label-required-prose.test.mjs +71 -0
- package/scripts/release-label-split-prose.test.mjs +169 -0
- package/scripts/release-ticket.sh +1716 -0
- package/scripts/release-ticket.test.mjs +5106 -0
- package/scripts/renovate-release-contract.test.mjs +379 -0
- package/scripts/repo-root.mjs +544 -0
- package/scripts/repo-root.test.mjs +873 -0
- package/scripts/reporter-output-rule-prose.test.mjs +208 -0
- package/scripts/review-agent-report-only.test.mjs +49 -0
- package/scripts/review-core-cwd-isolation.test.mjs +374 -0
- package/scripts/review-core-reads.test.mjs +478 -0
- package/scripts/review-core-refuter-scratch.test.mjs +148 -0
- package/scripts/review-core-snapshot-path.test.mjs +777 -0
- package/scripts/review-core-specialist-scratch.test.mjs +189 -0
- package/scripts/review-core-testcmd.test.mjs +288 -0
- package/scripts/review-core-unrun.test.mjs +530 -0
- package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
- package/scripts/review-core.mjs +1028 -0
- package/scripts/review-eval-resolver-path.test.mjs +55 -0
- package/scripts/review-eval.mjs +197 -0
- package/scripts/review-host-fixture.mjs +73 -0
- package/scripts/review-in-run-retry.test.mjs +187 -0
- package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
- package/scripts/review-path-default.test.mjs +796 -0
- package/scripts/review-runner-spawns.test.mjs +93 -0
- package/scripts/review-runner.test.mjs +155 -0
- package/scripts/review-tier-audit.test.mjs +140 -0
- package/scripts/run-artifact-pr-prose.test.mjs +341 -0
- package/scripts/run-merge-bot-prose.test.mjs +1391 -0
- package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
- package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
- package/scripts/section-between-guard-prose.test.mjs +378 -0
- package/scripts/select-dimensions.test.mjs +674 -0
- package/scripts/shared-refusal.test.mjs +388 -0
- package/scripts/shell-traps-prose.test.mjs +507 -0
- package/scripts/shortlist.mjs +355 -0
- package/scripts/shortlist.test.mjs +366 -0
- package/scripts/slow-transport.mjs +72 -0
- package/scripts/snapshot-repo.test.mjs +772 -0
- package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
- package/scripts/spend-view.test.mjs +312 -0
- package/scripts/staleness-qualifier-prose.test.mjs +251 -0
- package/scripts/staleness-verdict-prose.test.mjs +142 -0
- package/scripts/staleness.mjs +414 -0
- package/scripts/staleness.test.mjs +893 -0
- package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
- package/scripts/stash-prohibition-prose.test.mjs +313 -0
- package/scripts/strip-comments.mjs +44 -0
- package/scripts/tier-check.mjs +468 -0
- package/scripts/tier-check.test.mjs +726 -0
- package/scripts/tier-guard-gate-prose.test.mjs +216 -0
- package/scripts/tier-outcomes-header.test.mjs +586 -0
- package/scripts/tier-outcomes.mjs +441 -0
- package/scripts/tier-outcomes.test.mjs +342 -0
- package/scripts/tier-roles.mjs +250 -0
- package/scripts/tier-roles.test.mjs +316 -0
- package/scripts/tracker-block-copy-prose.test.mjs +288 -0
- package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
- package/scripts/unattended-git-sweep.test.mjs +142 -0
- package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
- package/scripts/verify-sha.sh +117 -0
- package/scripts/verify-sha.test.mjs +693 -0
- package/scripts/watcher-degraded-block.test.mjs +372 -0
- package/scripts/watcher-key-prose.test.mjs +106 -0
- package/scripts/within-run-pair-prose.test.mjs +208 -0
- package/scripts/worktree-audit.sh +482 -0
- package/scripts/worktree-audit.test.mjs +1407 -0
- package/scripts/worktree-head-prose.test.mjs +276 -0
- package/scripts/worktree-listing-sweep.test.mjs +217 -0
- package/scripts/worktree-model-prose.test.mjs +216 -0
- package/scripts/worktree.sh +470 -0
- package/skills/next-ticket/SKILL.md +138 -0
- package/skills/run-team/SKILL.md +3603 -0
- package/skills/run-team/references/ci-and-staleness.md +75 -0
- package/skills/run-team/references/correction-tickets.md +37 -0
- package/skills/run-team/references/isolation.md +23 -0
- package/skills/run-team/references/member-lifecycle.md +73 -0
- package/skills/run-team/references/reaping.md +73 -0
- package/skills/sizing-a-ticket/SKILL.md +39 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
// Regression gate for merge-gate.mjs (#1800), the merge bot's pre-merge
|
|
2
|
+
// conjunction — spec docs/specs/2026-09-24-slot-based-fleet-loop-design.md
|
|
3
|
+
// § 5, whose exit-vocabulary table every row below is named after.
|
|
4
|
+
//
|
|
5
|
+
// Zero deps: `node --test plugin/scripts/merge-gate.test.mjs`.
|
|
6
|
+
//
|
|
7
|
+
// `gh` is stubbed on PATH. ci-state.mjs and instruments.sh are resolved beside
|
|
8
|
+
// merge-gate.mjs itself (its SCRIPT_DIR), so each fixture runs a COPY of the
|
|
9
|
+
// gate out of a stub scripts directory holding stub siblings — the pattern
|
|
10
|
+
// fleet-tick.test.mjs uses for candidates.mjs — with every module the gate
|
|
11
|
+
// imports copied alongside. All three stubs append to one call log, which is
|
|
12
|
+
// how the "ci-state runs on every call, with --declare-no-ci" and "read-only"
|
|
13
|
+
// assertions are made. The cwd is a real `git init`-ed repository, because
|
|
14
|
+
// the gate derives instruments.sh's `--repo` from `git rev-parse
|
|
15
|
+
// --git-common-dir`.
|
|
16
|
+
//
|
|
17
|
+
// Each row gets a case that proves it blocks ON ITS OWN, the discipline
|
|
18
|
+
// drop-merged-label.test.mjs states: every input except the one under test is
|
|
19
|
+
// held at the mergeable baseline, so deleting a check fails the case named
|
|
20
|
+
// after it, not merely some case somewhere.
|
|
21
|
+
|
|
22
|
+
import { after, test } from "node:test";
|
|
23
|
+
import assert from "node:assert/strict";
|
|
24
|
+
import { spawnSync } from "node:child_process";
|
|
25
|
+
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync, realpathSync } from "node:fs";
|
|
26
|
+
import { tmpdir } from "node:os";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
|
|
30
|
+
const SCRIPT = fileURLToPath(new URL("./merge-gate.mjs", import.meta.url));
|
|
31
|
+
// Every non-builtin module the copied gate imports. An unlisted one is a
|
|
32
|
+
// module-not-found at startup — Node's exit 1, which is this gate's
|
|
33
|
+
// "blocked". Add a row whenever merge-gate.mjs gains an import.
|
|
34
|
+
const SIBLING_MODULES = ["arg.mjs", "git-env.mjs"].map((m) => [m, fileURLToPath(new URL(`./${m}`, import.meta.url))]);
|
|
35
|
+
|
|
36
|
+
const PRE = "a".repeat(40);
|
|
37
|
+
const POST = "b".repeat(40);
|
|
38
|
+
const THIRD = "c".repeat(40);
|
|
39
|
+
const DIGEST = "d".repeat(64);
|
|
40
|
+
|
|
41
|
+
const PR_VIEW = { labels: [{ name: "patch" }, { name: "ready-to-merge" }], reviewDecision: "APPROVED", headRefOid: PRE };
|
|
42
|
+
|
|
43
|
+
// Shaped like ci-state.mjs's own payload (its `payload` literal, plus
|
|
44
|
+
// `jobs`/`missing` outside --quiet), green at exit 0.
|
|
45
|
+
const CI_GREEN = {
|
|
46
|
+
pr: 42,
|
|
47
|
+
branch: "fix/42",
|
|
48
|
+
prHead: PRE,
|
|
49
|
+
runId: 7,
|
|
50
|
+
attempt: 1,
|
|
51
|
+
runHeadSha: PRE,
|
|
52
|
+
status: "completed",
|
|
53
|
+
conclusion: "success",
|
|
54
|
+
behind: 0,
|
|
55
|
+
verdict: "green",
|
|
56
|
+
reasons: [],
|
|
57
|
+
jobs: [{ name: "check", status: "completed", conclusion: "success" }],
|
|
58
|
+
missing: [],
|
|
59
|
+
};
|
|
60
|
+
const ci = (patch) => JSON.stringify({ ...CI_GREEN, ...patch });
|
|
61
|
+
|
|
62
|
+
const CI_STATE_STUB = `import { appendFileSync, readFileSync } from "node:fs";
|
|
63
|
+
appendFileSync(process.env.CALL_LOG, "ci-state.mjs " + process.argv.slice(2).join(" ") + "\\n");
|
|
64
|
+
process.stderr.write(process.env.CI_STDERR ?? "");
|
|
65
|
+
process.stdout.write(readFileSync(process.env.CI_STDOUT_FILE));
|
|
66
|
+
process.exitCode = Number(process.env.CI_EXIT);
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
const INSTRUMENTS_STUB = `printf 'instruments.sh %s\\n' "$*" >> "$CALL_LOG"
|
|
70
|
+
[ -z "$INSTR_STDOUT" ] || printf '%s\\n' "$INSTR_STDOUT"
|
|
71
|
+
exit "$INSTR_EXIT"
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const GH_STUB = `#!/bin/sh
|
|
75
|
+
printf 'gh %s\\n' "$*" >> "$CALL_LOG"
|
|
76
|
+
case "$1 $2" in
|
|
77
|
+
"pr view") cat "$PR_VIEW_FILE"; exit "$PR_VIEW_EXIT" ;;
|
|
78
|
+
*) echo "gh: unstubbed call: $*" >&2; exit 1 ;;
|
|
79
|
+
esac
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
function mktemp(t, prefix) {
|
|
83
|
+
const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
|
|
84
|
+
t.after(() => rmSync(d, { recursive: true, force: true }));
|
|
85
|
+
return d;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// One `gh` stub for the whole file, on every fixture's PATH. macOS scans a
|
|
89
|
+
// newly created executable inode on its first direct exec (~1-2s, measured in
|
|
90
|
+
// #2249), so a fresh stub per gate() call cost the file one scan per case. The
|
|
91
|
+
// stub is stateless — CALL_LOG, PR_VIEW_FILE and PR_VIEW_EXIT come from each
|
|
92
|
+
// call's env — so sharing it changes nothing a case asserts; everything else
|
|
93
|
+
// stays per call.
|
|
94
|
+
const BIN = realpathSync(mkdtempSync(join(tmpdir(), "merge-gate-bin-")));
|
|
95
|
+
after(() => rmSync(BIN, { recursive: true, force: true }));
|
|
96
|
+
writeFileSync(join(BIN, "gh"), GH_STUB, { mode: 0o755 });
|
|
97
|
+
|
|
98
|
+
function git(cwd, ...args) {
|
|
99
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", env: cleanEnv() });
|
|
100
|
+
assert.equal(r.status, 0, `fixture: git ${args.join(" ")} failed: ${r.stderr}`);
|
|
101
|
+
return r.stdout;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The runner's own ambient GIT_DIR/GIT_WORK_TREE must not reach a fixture;
|
|
105
|
+
// the one case that wants one sets it explicitly.
|
|
106
|
+
function cleanEnv() {
|
|
107
|
+
const env = { ...process.env };
|
|
108
|
+
delete env.GIT_DIR;
|
|
109
|
+
delete env.GIT_WORK_TREE;
|
|
110
|
+
return env;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Runs a copy of the gate against stubbed readings. Every option defaults to
|
|
115
|
+
* the mergeable baseline, so a case names only the one reading it changes.
|
|
116
|
+
*/
|
|
117
|
+
function gate(
|
|
118
|
+
t,
|
|
119
|
+
{
|
|
120
|
+
argv = ["--pr", "42", "--pre", PRE],
|
|
121
|
+
prView = JSON.stringify(PR_VIEW),
|
|
122
|
+
prViewExit = 0,
|
|
123
|
+
ciOut = JSON.stringify(CI_GREEN),
|
|
124
|
+
ciExit = 0,
|
|
125
|
+
ciStderr = "",
|
|
126
|
+
instrOut = DIGEST,
|
|
127
|
+
instrExit = 0,
|
|
128
|
+
cwd = null,
|
|
129
|
+
env = {},
|
|
130
|
+
realInstruments = false,
|
|
131
|
+
instrPre = null,
|
|
132
|
+
} = {},
|
|
133
|
+
) {
|
|
134
|
+
const root = mktemp(t, "merge-gate-");
|
|
135
|
+
const scripts = join(root, "scripts");
|
|
136
|
+
mkdirSync(scripts);
|
|
137
|
+
const script = join(scripts, "merge-gate.mjs");
|
|
138
|
+
writeFileSync(script, readFileSync(SCRIPT));
|
|
139
|
+
for (const [name, path] of SIBLING_MODULES) writeFileSync(join(scripts, name), readFileSync(path));
|
|
140
|
+
writeFileSync(join(scripts, "ci-state.mjs"), CI_STATE_STUB);
|
|
141
|
+
// The cross-workspace cases run the REAL instruments.sh beside the copied
|
|
142
|
+
// gate — the two-tree contract lives in that script, and a stub can only
|
|
143
|
+
// echo a verdict, never produce one. The stub stays the default: every
|
|
144
|
+
// other case here holds the instruments leg at mergeable and varies one
|
|
145
|
+
// input.
|
|
146
|
+
writeFileSync(
|
|
147
|
+
join(scripts, "instruments.sh"),
|
|
148
|
+
realInstruments
|
|
149
|
+
? readFileSync(fileURLToPath(new URL("./instruments.sh", import.meta.url)))
|
|
150
|
+
: INSTRUMENTS_STUB,
|
|
151
|
+
);
|
|
152
|
+
const log = join(root, "calls.log");
|
|
153
|
+
writeFileSync(log, "");
|
|
154
|
+
writeFileSync(join(root, "pr-view.json"), prView);
|
|
155
|
+
writeFileSync(join(root, "ci.out"), ciOut);
|
|
156
|
+
|
|
157
|
+
const repo = join(root, "repo");
|
|
158
|
+
mkdirSync(repo);
|
|
159
|
+
git(repo, "init", "-q");
|
|
160
|
+
// A hook for the real-instruments cases: run before the gate, with the
|
|
161
|
+
// fixture's workspace repo and scripts dir in hand — this is where a
|
|
162
|
+
// baseline gets pinned over a tree the workspace does not carry.
|
|
163
|
+
if (instrPre) instrPre({ repo, scripts, root });
|
|
164
|
+
|
|
165
|
+
const res = spawnSync(process.execPath, [script, ...argv], {
|
|
166
|
+
cwd: cwd ?? repo,
|
|
167
|
+
encoding: "utf8",
|
|
168
|
+
env: {
|
|
169
|
+
...cleanEnv(),
|
|
170
|
+
PATH: `${BIN}:${process.env.PATH}`,
|
|
171
|
+
CALL_LOG: log,
|
|
172
|
+
PR_VIEW_FILE: join(root, "pr-view.json"),
|
|
173
|
+
PR_VIEW_EXIT: String(prViewExit),
|
|
174
|
+
CI_STDOUT_FILE: join(root, "ci.out"),
|
|
175
|
+
CI_EXIT: String(ciExit),
|
|
176
|
+
CI_STDERR: ciStderr,
|
|
177
|
+
INSTR_STDOUT: instrOut,
|
|
178
|
+
INSTR_EXIT: String(instrExit),
|
|
179
|
+
...env,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
code: res.status,
|
|
184
|
+
stdout: res.stdout,
|
|
185
|
+
stderr: res.stderr,
|
|
186
|
+
json: res.stdout.trim() ? JSON.parse(res.stdout) : null,
|
|
187
|
+
calls: readFileSync(log, "utf8").split("\n").filter(Boolean),
|
|
188
|
+
root,
|
|
189
|
+
repo,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const CI_CALL = "ci-state.mjs --pr 42 --declare-no-ci";
|
|
194
|
+
|
|
195
|
+
// Exit code, verdict, reason — and ci-state called exactly once, with
|
|
196
|
+
// --declare-no-ci, which the AC requires on every call whatever the verdict.
|
|
197
|
+
function assertRow(r, code, verdict, reason) {
|
|
198
|
+
assert.equal(r.code, code, `exit ${r.code}, expected ${code}\nstdout: ${r.stdout}\nstderr: ${r.stderr}`);
|
|
199
|
+
assert.equal(r.json.verdict, verdict);
|
|
200
|
+
assert.equal(r.json.reason, reason);
|
|
201
|
+
assert.deepEqual(r.calls.filter((c) => c.startsWith("ci-state.mjs")), [CI_CALL], "ci-state must run once per call, with --declare-no-ci");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// --- exit 0 ----------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
test("every check holds → 0 mergeable, one JSON line with every field, three read-only calls in spec order", (t) => {
|
|
207
|
+
const r = gate(t);
|
|
208
|
+
assertRow(r, 0, "mergeable", null);
|
|
209
|
+
assert.equal(r.stdout.split("\n").length, 2, "stdout must be exactly one line");
|
|
210
|
+
assert.deepEqual(r.json, {
|
|
211
|
+
pr: 42,
|
|
212
|
+
verdict: "mergeable",
|
|
213
|
+
reason: null,
|
|
214
|
+
head: PRE,
|
|
215
|
+
pre: PRE,
|
|
216
|
+
post: null,
|
|
217
|
+
behind: 0,
|
|
218
|
+
instruments: DIGEST,
|
|
219
|
+
ci: CI_GREEN,
|
|
220
|
+
});
|
|
221
|
+
// The whole call log: nothing merges, labels or rebases, and the three
|
|
222
|
+
// reads run in the order the spec names.
|
|
223
|
+
assert.deepEqual(r.calls, [
|
|
224
|
+
`instruments.sh --repo ${r.repo}`,
|
|
225
|
+
"gh pr view 42 --json labels,reviewDecision,headRefOid",
|
|
226
|
+
CI_CALL,
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("the rebased path: head and ci-state both on --post → 0", (t) => {
|
|
231
|
+
const r = gate(t, {
|
|
232
|
+
argv: ["--pr", "42", "--pre", PRE, "--post", POST],
|
|
233
|
+
prView: JSON.stringify({ ...PR_VIEW, headRefOid: POST }),
|
|
234
|
+
ciOut: ci({ prHead: POST, runHeadSha: POST }),
|
|
235
|
+
});
|
|
236
|
+
assertRow(r, 0, "mergeable", null);
|
|
237
|
+
assert.equal(r.json.post, POST);
|
|
238
|
+
assert.equal(r.json.head, POST);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("the no-rebase path: --post equal to --pre → 0", (t) => {
|
|
242
|
+
const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--post", PRE] });
|
|
243
|
+
assertRow(r, 0, "mergeable", null);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("no-ci verdict with the label present → 0, the arm that cleared visible in ci.verdict", (t) => {
|
|
247
|
+
const r = gate(t, {
|
|
248
|
+
ciOut: JSON.stringify({
|
|
249
|
+
pr: 42,
|
|
250
|
+
branch: "fix/42",
|
|
251
|
+
prHead: PRE,
|
|
252
|
+
runId: null,
|
|
253
|
+
attempt: null,
|
|
254
|
+
runHeadSha: null,
|
|
255
|
+
status: null,
|
|
256
|
+
conclusion: null,
|
|
257
|
+
behind: 0,
|
|
258
|
+
verdict: "no-ci",
|
|
259
|
+
reasons: ["no workflows configured under .github/workflows/ — --declare-no-ci passed, gating on the caller's verified suite run instead"],
|
|
260
|
+
}),
|
|
261
|
+
});
|
|
262
|
+
assertRow(r, 0, "mergeable", null);
|
|
263
|
+
assert.equal(r.json.ci.verdict, "no-ci");
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("ci-state's stderr noise never reaches the parse, and is passed through", (t) => {
|
|
267
|
+
const noise = '$ gh run view 7\n{"verdict":"not-green"}\nci-state: verdict=green\n';
|
|
268
|
+
const r = gate(t, { ciStderr: noise });
|
|
269
|
+
assertRow(r, 0, "mergeable", null);
|
|
270
|
+
assert.ok(r.stderr.includes(noise), "the child's diagnostics must reach the gate's stderr");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// --- exit 1: blocked ---------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
test("ready-to-merge absent → 1 label-pulled", (t) => {
|
|
276
|
+
const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, labels: [{ name: "patch" }] }) });
|
|
277
|
+
assertRow(r, 1, "blocked", "label-pulled");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("reviewDecision CHANGES_REQUESTED → 1 changes-requested", (t) => {
|
|
281
|
+
const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, reviewDecision: "CHANGES_REQUESTED" }) });
|
|
282
|
+
assertRow(r, 1, "blocked", "changes-requested");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// The two gh-read cases hold ci-state's own head read on --pre, so the gh
|
|
286
|
+
// read's check is the only one that can block them; the ci-state read's check
|
|
287
|
+
// has its own case below.
|
|
288
|
+
test("headRefOid outside {pre, post} → 1 head-moved-after-label", (t) => {
|
|
289
|
+
const r = gate(t, {
|
|
290
|
+
argv: ["--pr", "42", "--pre", PRE, "--post", POST],
|
|
291
|
+
prView: JSON.stringify({ ...PR_VIEW, headRefOid: THIRD }),
|
|
292
|
+
});
|
|
293
|
+
assertRow(r, 1, "blocked", "head-moved-after-label");
|
|
294
|
+
assert.equal(r.json.head, THIRD);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("--post omitted: a head that moved off --pre is not excused by any other SHA → 1 head-moved-after-label", (t) => {
|
|
298
|
+
const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, headRefOid: POST }) });
|
|
299
|
+
assertRow(r, 1, "blocked", "head-moved-after-label");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("ci-state's own head read outside {pre, post} → 1 head-moved-after-label, even with gh's read on --pre", (t) => {
|
|
303
|
+
// A push between the gate's gh pr view and ci-state's own head read: its
|
|
304
|
+
// CI would be judged while the label's audit belongs to the tree before it.
|
|
305
|
+
const r = gate(t, { ciOut: ci({ prHead: THIRD, runHeadSha: THIRD }) });
|
|
306
|
+
assertRow(r, 1, "blocked", "head-moved-after-label");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test("ci-state exit 1 (in progress, no conclusion) → 1 ci:<first reason>, runId and status carried for the wait", (t) => {
|
|
310
|
+
const reasons = ["run status is in_progress, not completed", "job check is in_progress, not success"];
|
|
311
|
+
const r = gate(t, {
|
|
312
|
+
ciOut: ci({ status: "in_progress", conclusion: null, verdict: "not-green", reasons }),
|
|
313
|
+
ciExit: 1,
|
|
314
|
+
});
|
|
315
|
+
assertRow(r, 1, "blocked", `ci:${reasons[0]}`);
|
|
316
|
+
assert.equal(r.json.ci.status, "in_progress");
|
|
317
|
+
assert.equal(r.json.ci.runId, 7);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("green with behind 3 → 1 behind:3", (t) => {
|
|
321
|
+
const r = gate(t, { ciOut: ci({ behind: 3 }) });
|
|
322
|
+
assertRow(r, 1, "blocked", "behind:3");
|
|
323
|
+
assert.equal(r.json.behind, 3);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// --- exit 2: could not evaluate -----------------------------------------------
|
|
327
|
+
|
|
328
|
+
test("ci-state rate-limited payload → 2 rate-limited", (t) => {
|
|
329
|
+
const r = gate(t, {
|
|
330
|
+
ciOut: JSON.stringify({ pr: 42, verdict: "rate-limited", reasons: ["gh run list was refused by the GitHub API rate limit — no CI state was read."] }),
|
|
331
|
+
ciExit: 2,
|
|
332
|
+
});
|
|
333
|
+
assertRow(r, 2, "unknown", "rate-limited");
|
|
334
|
+
assert.equal(r.json.ci.verdict, "rate-limited");
|
|
335
|
+
assert.equal(r.json.behind, null);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("ci-state {} payload → 2 ci-unreadable", (t) => {
|
|
339
|
+
const r = gate(t, { ciOut: "{}\n", ciExit: 2 });
|
|
340
|
+
assertRow(r, 2, "unknown", "ci-unreadable");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("ci-state zero-byte payload → 2 ci-unreadable", (t) => {
|
|
344
|
+
const r = gate(t, { ciOut: "", ciExit: 2 });
|
|
345
|
+
assertRow(r, 2, "unknown", "ci-unreadable");
|
|
346
|
+
assert.equal(r.json.ci, null);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("ci-state unparseable payload → 2 ci-unreadable", (t) => {
|
|
350
|
+
const r = gate(t, { ciOut: '{"pr":42,"verdict":"gre', ciExit: 2 });
|
|
351
|
+
assertRow(r, 2, "unknown", "ci-unreadable");
|
|
352
|
+
assert.equal(r.json.ci, null);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test("an exit code its payload does not back → 2 ci-unreadable, never a verdict", (t) => {
|
|
356
|
+
// Exit 0 with nothing to gate on is the vacuous pass; exit 1 with no
|
|
357
|
+
// payload is Node's own crash code, not ci-state's not-green; and a code
|
|
358
|
+
// contradicting the verdict it printed has answered nothing.
|
|
359
|
+
const shapes = [
|
|
360
|
+
["exit 0, {}", "{}\n", 0],
|
|
361
|
+
["exit 0, zero bytes", "", 0],
|
|
362
|
+
["exit 1, zero bytes (a crashed ci-state)", "", 1],
|
|
363
|
+
["exit 0, not-green verdict", ci({ verdict: "not-green", reasons: ["run status is queued, not completed"] }), 0],
|
|
364
|
+
["exit 1, green verdict", ci({}), 1],
|
|
365
|
+
["exit 0, green verdict with no behind field", JSON.stringify({ ...CI_GREEN, behind: undefined }), 0],
|
|
366
|
+
["exit 0, green verdict with no prHead", JSON.stringify({ ...CI_GREEN, prHead: undefined }), 0],
|
|
367
|
+
];
|
|
368
|
+
for (const [what, ciOut, ciExit] of shapes) {
|
|
369
|
+
const r = gate(t, { ciOut, ciExit });
|
|
370
|
+
assert.equal(r.code, 2, `${what}: exit ${r.code}\n${r.stdout}`);
|
|
371
|
+
assert.equal(r.json.reason, "ci-unreadable", what);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("green with behind null → 2 behind-unknown", (t) => {
|
|
376
|
+
const r = gate(t, { ciOut: ci({ behind: null }) });
|
|
377
|
+
assertRow(r, 2, "unknown", "behind-unknown");
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// An unusable payload that ALSO happens to carry a `behind: null` field must
|
|
381
|
+
// still read as ci-unreadable, not behind-unknown: readCi()'s `validated` is
|
|
382
|
+
// null whenever `usable` is false, so decide() cannot fall through to a
|
|
383
|
+
// `behind` read on an unvalidated shape no matter which check runs first.
|
|
384
|
+
test("an unusable payload that also carries behind:null → 2 ci-unreadable, never behind-unknown", (t) => {
|
|
385
|
+
const r = gate(t, { ciOut: ci({ verdict: "not-green", reasons: ["queued"], behind: null }), ciExit: 0 });
|
|
386
|
+
assertRow(r, 2, "unknown", "ci-unreadable");
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("instruments.sh exit 1 → 2 instrument-set-changed, the digest it printed carried", (t) => {
|
|
390
|
+
const changed = "e".repeat(64);
|
|
391
|
+
const r = gate(t, { instrOut: changed, instrExit: 1 });
|
|
392
|
+
assertRow(r, 2, "unknown", "instrument-set-changed");
|
|
393
|
+
assert.equal(r.json.instruments, changed);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test("instruments.sh exit 2 → 2 instruments-unanswerable", (t) => {
|
|
397
|
+
const r = gate(t, { instrOut: "", instrExit: 2 });
|
|
398
|
+
assertRow(r, 2, "unknown", "instruments-unanswerable");
|
|
399
|
+
assert.equal(r.json.instruments, null);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test("instruments.sh exit 0 that printed no digest → 2 instruments-unanswerable", (t) => {
|
|
403
|
+
const r = gate(t, { instrOut: "", instrExit: 0 });
|
|
404
|
+
assertRow(r, 2, "unknown", "instruments-unanswerable");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("no git checkout to name the instrument set from → 2 instruments-unanswerable, instruments.sh never run", (t) => {
|
|
408
|
+
const outside = mktemp(t, "merge-gate-nogit-");
|
|
409
|
+
const r = gate(t, { cwd: outside, env: { GIT_CEILING_DIRECTORIES: outside } });
|
|
410
|
+
assertRow(r, 2, "unknown", "instruments-unanswerable");
|
|
411
|
+
assert.equal(r.calls.filter((c) => c.startsWith("instruments.sh")).length, 0);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("gh pr view exits non-zero → 2 pr-unreadable", (t) => {
|
|
415
|
+
const r = gate(t, { prView: "", prViewExit: 1 });
|
|
416
|
+
assertRow(r, 2, "unknown", "pr-unreadable");
|
|
417
|
+
assert.equal(r.json.head, null);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test("gh pr view misparses → 2 pr-unreadable", (t) => {
|
|
421
|
+
const shapes = [
|
|
422
|
+
["non-JSON body at exit 0", "<html>502 Bad Gateway</html>"],
|
|
423
|
+
["labels missing", JSON.stringify({ reviewDecision: "APPROVED", headRefOid: PRE })],
|
|
424
|
+
["headRefOid empty", JSON.stringify({ ...PR_VIEW, headRefOid: "" })],
|
|
425
|
+
["reviewDecision missing", JSON.stringify({ labels: PR_VIEW.labels, headRefOid: PRE })],
|
|
426
|
+
];
|
|
427
|
+
for (const [what, prView] of shapes) {
|
|
428
|
+
const r = gate(t, { prView });
|
|
429
|
+
assert.equal(r.code, 2, `${what}: exit ${r.code}\n${r.stdout}`);
|
|
430
|
+
assert.equal(r.json.reason, "pr-unreadable", what);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("only CHANGES_REQUESTED blocks: reviewDecision \"\" (no review required), null and REVIEW_REQUIRED → 0", (t) => {
|
|
435
|
+
for (const reviewDecision of ["", null, "REVIEW_REQUIRED"]) {
|
|
436
|
+
const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, reviewDecision }) });
|
|
437
|
+
assert.equal(r.code, 0, `${JSON.stringify(reviewDecision)}: ${r.stdout}`);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
// --- precedence ----------------------------------------------------------------
|
|
442
|
+
|
|
443
|
+
test("the first failing row is the reason, and the JSON still carries every reading", (t) => {
|
|
444
|
+
const notGreen = ci({ status: "in_progress", verdict: "not-green", reasons: ["run status is in_progress, not completed"] });
|
|
445
|
+
const r = gate(t, {
|
|
446
|
+
prView: JSON.stringify({ ...PR_VIEW, labels: [] }),
|
|
447
|
+
ciOut: notGreen,
|
|
448
|
+
ciExit: 1,
|
|
449
|
+
instrOut: "e".repeat(64),
|
|
450
|
+
instrExit: 1,
|
|
451
|
+
});
|
|
452
|
+
assertRow(r, 1, "blocked", "label-pulled");
|
|
453
|
+
assert.equal(r.json.instruments, "e".repeat(64));
|
|
454
|
+
assert.deepEqual(r.json.ci, JSON.parse(notGreen));
|
|
455
|
+
assert.equal(r.json.head, PRE);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// --- --repo: the main checkout, whatever the cwd or the environment says ------
|
|
459
|
+
|
|
460
|
+
test("from a linked worktree, instruments.sh audits the main checkout (--git-common-dir), not the worktree", (t) => {
|
|
461
|
+
// The run's baseline lives in the main checkout's .fleet/, which a
|
|
462
|
+
// worktree does not carry: --show-toplevel there would exit 2 forever.
|
|
463
|
+
const probe = gate(t);
|
|
464
|
+
const main = probe.repo;
|
|
465
|
+
git(main, "-c", "user.email=t@example.com", "-c", "user.name=t", "commit", "-q", "--allow-empty", "-m", "init");
|
|
466
|
+
const wt = join(probe.root, "wt");
|
|
467
|
+
git(main, "worktree", "add", "-q", wt);
|
|
468
|
+
const r = gate(t, { cwd: wt });
|
|
469
|
+
assertRow(r, 0, "mergeable", null);
|
|
470
|
+
assert.deepEqual(r.calls.filter((c) => c.startsWith("instruments.sh")), [`instruments.sh --repo ${main}`]);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test("an ambient GIT_DIR cannot move the audited instrument set into another repository", (t) => {
|
|
474
|
+
const other = mktemp(t, "merge-gate-other-");
|
|
475
|
+
git(other, "init", "-q");
|
|
476
|
+
const r = gate(t, { env: { GIT_DIR: join(other, ".git") } });
|
|
477
|
+
assertRow(r, 0, "mergeable", null);
|
|
478
|
+
assert.deepEqual(r.calls.filter((c) => c.startsWith("instruments.sh")), [`instruments.sh --repo ${r.repo}`]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// --- interface ------------------------------------------------------------------
|
|
482
|
+
|
|
483
|
+
test("--declare-no-ci is not on the gate's surface: refused by name, nothing run", (t) => {
|
|
484
|
+
const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--declare-no-ci"] });
|
|
485
|
+
assert.equal(r.code, 2);
|
|
486
|
+
assert.match(r.stderr, /unknown flag --declare-no-ci/);
|
|
487
|
+
assert.equal(r.stdout, "");
|
|
488
|
+
assert.deepEqual(r.calls, []);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test("usage: --pr and --pre are both required, refused before any read", (t) => {
|
|
492
|
+
for (const argv of [["--pre", PRE], ["--pr", "42"], []]) {
|
|
493
|
+
const r = gate(t, { argv });
|
|
494
|
+
assert.equal(r.code, 2, argv.join(" "));
|
|
495
|
+
assert.match(r.stderr, /usage: merge-gate\.mjs --pr <n> --pre <sha>/);
|
|
496
|
+
assert.deepEqual(r.calls, []);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test("usage: an abbreviated SHA is refused, a full uppercase one is accepted", (t) => {
|
|
501
|
+
// Abbreviated can never equal gh's full headRefOid, so accepting it would
|
|
502
|
+
// skip every PR as head-moved-after-label.
|
|
503
|
+
for (const argv of [["--pr", "42", "--pre", PRE.slice(0, 7)], ["--pr", "42", "--pre", PRE, "--post", "HEAD"]]) {
|
|
504
|
+
const r = gate(t, { argv });
|
|
505
|
+
assert.equal(r.code, 2, argv.join(" "));
|
|
506
|
+
assert.match(r.stderr, /needs a full 40-character commit SHA/);
|
|
507
|
+
assert.deepEqual(r.calls, []);
|
|
508
|
+
}
|
|
509
|
+
const upper = gate(t, { argv: ["--pr", "42", "--pre", PRE.toUpperCase()] });
|
|
510
|
+
assertRow(upper, 0, "mergeable", null);
|
|
511
|
+
assert.equal(upper.json.pre, PRE);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
test("--out writes the same line, creating missing directories, whatever the verdict", (t) => {
|
|
515
|
+
for (const [label, code] of [["ready-to-merge", 0], ["patch", 1]]) {
|
|
516
|
+
const dir = mktemp(t, "merge-gate-out-");
|
|
517
|
+
const out = join(dir, "pr42", "merge-bot-3", "ci.json");
|
|
518
|
+
const r = gate(t, {
|
|
519
|
+
argv: ["--pr", "42", "--pre", PRE, "--out", out],
|
|
520
|
+
prView: JSON.stringify({ ...PR_VIEW, labels: [{ name: label }] }),
|
|
521
|
+
});
|
|
522
|
+
assert.equal(r.code, code, r.stderr);
|
|
523
|
+
assert.equal(readFileSync(out, "utf8"), r.stdout);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test("--out that cannot be written → 2, and no verdict on stdout the file does not carry", (t) => {
|
|
528
|
+
const dir = mktemp(t, "merge-gate-out-");
|
|
529
|
+
writeFileSync(join(dir, "file"), "");
|
|
530
|
+
const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--out", join(dir, "file", "ci.json")] });
|
|
531
|
+
assert.equal(r.code, 2);
|
|
532
|
+
assert.equal(r.stdout, "");
|
|
533
|
+
assert.match(r.stderr, /cannot write --out/);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// --- #2284: the instruments root and the gh root are different checkouts ----
|
|
537
|
+
//
|
|
538
|
+
// The live incident: a fleet running in a consumer repo that does not track
|
|
539
|
+
// `plugin/…`. Every leg but instruments was green; instruments.sh hashed the
|
|
540
|
+
// workspace tree, found no tracked instrument, refused on the empty set, and
|
|
541
|
+
// the gate exited 2 `instruments-unanswerable` forever — labelled PRs that
|
|
542
|
+
// could never merge. The fix records the audited root inside the baseline at
|
|
543
|
+
// pin time, so the SAME `--repo <workspace>` call the gate already makes
|
|
544
|
+
// reads one tree's home and another tree's bytes. These cases run the REAL
|
|
545
|
+
// instruments.sh beside the copied gate: the contract being proven is the two
|
|
546
|
+
// scripts' handoff across that seam, and a stubbed child proves only the row
|
|
547
|
+
// table — it can echo an exit code, never derive one from two trees.
|
|
548
|
+
|
|
549
|
+
// A checkout that carries the instrument set — the plugin's own repo, or an
|
|
550
|
+
// install's cache — separate from every gate fixture's workspace repo.
|
|
551
|
+
function pluginTree(t) {
|
|
552
|
+
const dir = mktemp(t, "merge-gate-plugin-");
|
|
553
|
+
git(dir, "init", "-q", "-b", "main");
|
|
554
|
+
mkdirSync(join(dir, "plugin", "scripts"), { recursive: true });
|
|
555
|
+
writeFileSync(join(dir, "plugin", "scripts", "probe.sh"), "echo probe\n");
|
|
556
|
+
git(dir, "-c", "user.email=t@example.com", "-c", "user.name=t", "add", "-A");
|
|
557
|
+
git(dir, "-c", "user.email=t@example.com", "-c", "user.name=t", "commit", "-qm", "fixture");
|
|
558
|
+
return dir;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// The phase-0 pin a controller runs from the plugin-less workspace: the
|
|
562
|
+
// baseline lands in the WORKSPACE's .fleet/, the digest covers the PLUGIN's
|
|
563
|
+
// tree, and the second line records which tree that was.
|
|
564
|
+
function pinAcrossSeam({ repo, scripts }, plugin) {
|
|
565
|
+
const r = spawnSync("sh", [join(scripts, "instruments.sh"), "--pin", "--audit", plugin], {
|
|
566
|
+
cwd: repo,
|
|
567
|
+
encoding: "utf8",
|
|
568
|
+
env: cleanEnv(),
|
|
569
|
+
});
|
|
570
|
+
assert.equal(r.status, 0, `fixture pin failed: ${r.stderr}`);
|
|
571
|
+
return r.stdout.trim();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
test("a plugin-less workspace reaches a verdict: the gate audits the root the baseline records, gh legs on the workspace", (t) => {
|
|
575
|
+
const plugin = pluginTree(t);
|
|
576
|
+
let digest = null;
|
|
577
|
+
const r = gate(t, {
|
|
578
|
+
realInstruments: true,
|
|
579
|
+
instrPre: (ws) => {
|
|
580
|
+
digest = pinAcrossSeam(ws, plugin);
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
assertRow(r, 0, "mergeable", null);
|
|
584
|
+
assert.equal(
|
|
585
|
+
r.json.instruments,
|
|
586
|
+
digest,
|
|
587
|
+
"the JSON carries the digest of the plugin tree — the workspace has no instruments to digest",
|
|
588
|
+
);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
test("tampering the recorded plugin tree still closes the gate across the seam: 2 instrument-set-changed", (t) => {
|
|
592
|
+
const plugin = pluginTree(t);
|
|
593
|
+
const r = gate(t, {
|
|
594
|
+
realInstruments: true,
|
|
595
|
+
instrPre: (ws) => {
|
|
596
|
+
pinAcrossSeam(ws, plugin);
|
|
597
|
+
writeFileSync(join(plugin, "plugin", "scripts", "probe.sh"), "echo TAMPERED\n");
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
assertRow(r, 2, "unknown", "instrument-set-changed");
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test("a plugin-less workspace with NO pin of any kind keeps its exit 2 — the refusal that says WHICH flag to pass", (t) => {
|
|
604
|
+
// The incident shape stays a refusal, never a silent pass: with no
|
|
605
|
+
// baseline there is no recorded root, the instruments leg answers nothing,
|
|
606
|
+
// and the gate lands on instruments-unanswerable. What changed is WHERE a
|
|
607
|
+
// run discovers this: the SKILL's phase-0 pin refuses once and names the
|
|
608
|
+
// empty tree, instead of dispatching finishers and merge bots into this
|
|
609
|
+
// leg forever.
|
|
610
|
+
const r = gate(t, { realInstruments: true });
|
|
611
|
+
assertRow(r, 2, "unknown", "instruments-unanswerable");
|
|
612
|
+
assert.equal(r.json.instruments, null);
|
|
613
|
+
});
|