@feigi/fleet-ctl 3.23.35 → 3.23.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/main-checkout.mjs +1 -1
- package/scripts/member-write-guard.mjs +1 -1
- package/scripts/repo-root.mjs +1 -1
- package/skills/run-team/references/reaping.md +1 -1
- package/scripts/agent-test-dir-prose.test.mjs +0 -59
- package/scripts/agent-test.test.mjs +0 -1640
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
- package/scripts/ambient-git-vars-prose.test.mjs +0 -192
- package/scripts/ancestry-check-position-prose.test.mjs +0 -175
- package/scripts/apply-ruleset.test.mjs +0 -421
- package/scripts/arg-header-probes-prose.test.mjs +0 -394
- package/scripts/arg.test.mjs +0 -1354
- package/scripts/board-cli.test.mjs +0 -710
- package/scripts/board-identity.test.mjs +0 -429
- package/scripts/board-liveness-banner.test.mjs +0 -119
- package/scripts/board-prev-shape.test.mjs +0 -228
- package/scripts/board-tryparse-null.test.mjs +0 -119
- package/scripts/board.test.mjs +0 -3121
- package/scripts/brief-after-cut-prose.test.mjs +0 -53
- package/scripts/candidates-exit3-prose.test.mjs +0 -302
- package/scripts/candidates.test.mjs +0 -2312
- package/scripts/caveat-unification-prose.test.mjs +0 -98
- package/scripts/cell-readout.test.mjs +0 -615
- package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
- package/scripts/ci-completes-premise-prose.test.mjs +0 -257
- package/scripts/ci-state-prose.test.mjs +0 -113
- package/scripts/ci-state.test.mjs +0 -1933
- package/scripts/ci-vacuous-green.test.mjs +0 -368
- package/scripts/citation-sweep-prose.test.mjs +0 -1712
- package/scripts/claim-lifecycle.test.mjs +0 -187
- package/scripts/claim-ticket.test.mjs +0 -1122
- package/scripts/closing-keyword-prose.test.mjs +0 -193
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
- package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
- package/scripts/compute-board.test.mjs +0 -1214
- package/scripts/compute-spend.test.mjs +0 -517
- package/scripts/consumer-technology-prose.test.mjs +0 -126
- package/scripts/cross-repo-citation-prose.test.mjs +0 -155
- package/scripts/cwd-isolation-pins.mjs +0 -83
- package/scripts/dedupe-guard-prose.test.mjs +0 -243
- package/scripts/delete-merged-branch.test.mjs +0 -576
- package/scripts/derive-testcmd.test.mjs +0 -595
- package/scripts/diff-stats.test.mjs +0 -404
- package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
- package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
- package/scripts/dispositions-check.test.mjs +0 -936
- package/scripts/dispositions-gate-prose.test.mjs +0 -129
- package/scripts/drop-merged-label.test.mjs +0 -479
- package/scripts/exec-stub.mjs +0 -93
- package/scripts/exec-stub.test.mjs +0 -69
- package/scripts/expected-jobs-prose.test.mjs +0 -80
- package/scripts/fan-out-authorization-prose.test.mjs +0 -80
- package/scripts/filing-bar-seat-prose.test.mjs +0 -242
- package/scripts/filing-claim-bar-prose.test.mjs +0 -166
- package/scripts/finisher-died-prose.test.mjs +0 -31
- package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
- package/scripts/finisher-halt-prose.test.mjs +0 -106
- package/scripts/finisher-name-prose.test.mjs +0 -134
- package/scripts/finisher-own-tree-prose.test.mjs +0 -299
- package/scripts/finisher-pin-race-prose.test.mjs +0 -339
- package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
- package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
- package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
- package/scripts/fleet-bootstrap.test.mjs +0 -75
- package/scripts/fleet-heartbeat.test.mjs +0 -450
- package/scripts/fleet-provenance.test.mjs +0 -138
- package/scripts/fleet-run.test.mjs +0 -90
- package/scripts/fleet-state.test.mjs +0 -460
- package/scripts/fleet-tick-prose.test.mjs +0 -300
- package/scripts/fleet-tick.test.mjs +0 -2444
- package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
- package/scripts/frontmatter-check.test.mjs +0 -436
- package/scripts/git-env.test.mjs +0 -149
- package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
- package/scripts/gone-walk.test.mjs +0 -213
- package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
- package/scripts/head-moved-after-label-prose.test.mjs +0 -233
- package/scripts/immutable-body-claim-prose.test.mjs +0 -204
- package/scripts/implementer-model-tier.test.mjs +0 -235
- package/scripts/inflight-citation-prose.test.mjs +0 -144
- package/scripts/inflight-exit2-prose.test.mjs +0 -81
- package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
- package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
- package/scripts/inflight.test.mjs +0 -2882
- package/scripts/injection-control-prose.test.mjs +0 -404
- package/scripts/install-root-audit.test.mjs +0 -464
- package/scripts/instrument-check-prose.test.mjs +0 -235
- package/scripts/instruments.test.mjs +0 -787
- package/scripts/is-cli.test.mjs +0 -99
- package/scripts/issue-tracker-prose.test.mjs +0 -71
- package/scripts/json.test.mjs +0 -364
- package/scripts/ledger-dispatch.test.mjs +0 -927
- package/scripts/ledger-grammar.test.mjs +0 -227
- package/scripts/ledger-read-require-file.test.mjs +0 -197
- package/scripts/ledger-rotate.test.mjs +0 -142
- package/scripts/ledger.test.mjs +0 -3436
- package/scripts/line-distance-prose.test.mjs +0 -245
- package/scripts/liveness-rationale-prose.test.mjs +0 -83
- package/scripts/locale-pin-prose.test.mjs +0 -189
- package/scripts/main-checkout.test.mjs +0 -332
- package/scripts/member-outcome-prose.test.mjs +0 -167
- package/scripts/member-outcomes-header.test.mjs +0 -129
- package/scripts/member-outcomes-prose.test.mjs +0 -63
- package/scripts/member-outcomes.test.mjs +0 -638
- package/scripts/member-prompt-prose.test.mjs +0 -165
- package/scripts/member-record.test.mjs +0 -541
- package/scripts/member-write-guard.test.mjs +0 -214
- package/scripts/merge-commit-probe-prose.test.mjs +0 -122
- package/scripts/merge-gate.test.mjs +0 -613
- package/scripts/muted-git-guard-sweep.test.mjs +0 -493
- package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
- package/scripts/net-watchdog-prose.test.mjs +0 -79
- package/scripts/net.test.mjs +0 -211
- package/scripts/no-ci-gate-prose.test.mjs +0 -108
- package/scripts/no-undo-audit.test.mjs +0 -3961
- package/scripts/no-wave.test.mjs +0 -138
- package/scripts/node-floor-sweep.test.mjs +0 -611
- package/scripts/pointer-target-prose.test.mjs +0 -186
- package/scripts/pr-cost.test.mjs +0 -521
- package/scripts/pr-overlap.test.mjs +0 -692
- package/scripts/printf-die-sweep.test.mjs +0 -384
- package/scripts/prompt-renderer.mjs +0 -40
- package/scripts/prompt-renderer.test.mjs +0 -68
- package/scripts/prose-pin.mjs +0 -807
- package/scripts/prose-pin.test.mjs +0 -1034
- package/scripts/prove-merge.test.mjs +0 -995
- package/scripts/pull-table-relabel-prose.test.mjs +0 -60
- package/scripts/quiet-payload-prose.test.mjs +0 -222
- package/scripts/reap-cherry-check-prose.test.mjs +0 -80
- package/scripts/reap.test.mjs +0 -4432
- package/scripts/reaping-prose.test.mjs +0 -239
- package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
- package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
- package/scripts/recipe-derivation-prose.test.mjs +0 -112
- package/scripts/recipe-prove.test.mjs +0 -1042
- package/scripts/refuter-scratch-prose.test.mjs +0 -135
- package/scripts/release-label-required-prose.test.mjs +0 -71
- package/scripts/release-label-split-prose.test.mjs +0 -184
- package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
- package/scripts/release-ticket.test.mjs +0 -5099
- package/scripts/renovate-release-contract.test.mjs +0 -379
- package/scripts/repo-root.test.mjs +0 -873
- package/scripts/reporter-output-rule-prose.test.mjs +0 -208
- package/scripts/review-agent-report-only.test.mjs +0 -49
- package/scripts/review-core-booking.test.mjs +0 -35
- package/scripts/review-core-cwd-isolation.test.mjs +0 -374
- package/scripts/review-core-reads.test.mjs +0 -478
- package/scripts/review-core-refuter-scratch.test.mjs +0 -148
- package/scripts/review-core-scratch-refusal.test.mjs +0 -64
- package/scripts/review-core-shared-test-run.test.mjs +0 -275
- package/scripts/review-core-snapshot-path.test.mjs +0 -830
- package/scripts/review-core-specialist-scratch.test.mjs +0 -191
- package/scripts/review-core-testcmd.test.mjs +0 -335
- package/scripts/review-core-unrun.test.mjs +0 -566
- package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
- package/scripts/review-eval-resolver-path.test.mjs +0 -55
- package/scripts/review-host-fixture.mjs +0 -89
- package/scripts/review-in-run-retry.test.mjs +0 -211
- package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
- package/scripts/review-path-default.test.mjs +0 -796
- package/scripts/review-runner-spawns.test.mjs +0 -95
- package/scripts/review-runner.test.mjs +0 -166
- package/scripts/review-tier-audit.test.mjs +0 -140
- package/scripts/run-artifact-pr-prose.test.mjs +0 -341
- package/scripts/run-merge-bot-prose.test.mjs +0 -1413
- package/scripts/run-team-local-hook.test.mjs +0 -442
- package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
- package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
- package/scripts/section-between-guard-prose.test.mjs +0 -379
- package/scripts/select-dimensions.test.mjs +0 -674
- package/scripts/shared-refusal.test.mjs +0 -388
- package/scripts/shell-traps-prose.test.mjs +0 -504
- package/scripts/shortlist.test.mjs +0 -380
- package/scripts/slow-transport.mjs +0 -72
- package/scripts/snapshot-repo.test.mjs +0 -1006
- package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
- package/scripts/spend-view.test.mjs +0 -312
- package/scripts/staleness-qualifier-prose.test.mjs +0 -251
- package/scripts/staleness-verdict-prose.test.mjs +0 -142
- package/scripts/staleness.test.mjs +0 -893
- package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
- package/scripts/stash-prohibition-prose.test.mjs +0 -313
- package/scripts/strip-comments.mjs +0 -44
- package/scripts/temp-dir.mjs +0 -47
- package/scripts/ticket-router.test.mjs +0 -981
- package/scripts/tier-check.test.mjs +0 -828
- package/scripts/tier-outcomes-header.test.mjs +0 -518
- package/scripts/tier-outcomes.test.mjs +0 -572
- package/scripts/tier-roles.test.mjs +0 -535
- package/scripts/tracker-block-copy-prose.test.mjs +0 -288
- package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
- package/scripts/unattended-git-sweep.test.mjs +0 -142
- package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
- package/scripts/verify-sha.test.mjs +0 -692
- package/scripts/watcher-degraded-block.test.mjs +0 -369
- package/scripts/watcher-key-prose.test.mjs +0 -106
- package/scripts/within-run-pair-prose.test.mjs +0 -212
- package/scripts/worktree-audit.test.mjs +0 -1408
- package/scripts/worktree-head-prose.test.mjs +0 -276
- package/scripts/worktree-listing-sweep.test.mjs +0 -217
- package/scripts/worktree-model-prose.test.mjs +0 -216
- package/scripts/worktree-porcelain.mjs +0 -35
- package/scripts/worktree-porcelain.test.mjs +0 -102
|
@@ -1,692 +0,0 @@
|
|
|
1
|
-
// Regression gate for verify-sha.sh, the check that says whether a member's
|
|
2
|
-
// reported SHA is really on the branch it claims. Zero deps:
|
|
3
|
-
// `node --test plugin/scripts/verify-sha.test.mjs`.
|
|
4
|
-
//
|
|
5
|
-
// A shell script that reasons about git history can only be tested against real
|
|
6
|
-
// git history, so the cases below that reason about history build a throwaway
|
|
7
|
-
// origin+clone in a temp dir and run the script for real; a case that fails
|
|
8
|
-
// before the script reaches git does not.
|
|
9
|
-
//
|
|
10
|
-
// The load-bearing case is `a merge-base that fails rather than answers is exit
|
|
11
|
-
// 2, never reachable:false` (#266). Every non-zero status used to collapse into
|
|
12
|
-
// the definite verdict reachable:false at exit 1, so "the repository could not
|
|
13
|
-
// answer" and "the SHA is not on the branch" — the one distinction this script
|
|
14
|
-
// exists to make — were indistinguishable to the controller. Its two neighbours
|
|
15
|
-
// here, the reachable and the genuinely-not-reachable cases, are what keep the
|
|
16
|
-
// guard from over-firing: exit 1 has to survive as a real answer.
|
|
17
|
-
|
|
18
|
-
import { test } from "node:test";
|
|
19
|
-
import assert from "node:assert/strict";
|
|
20
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
21
|
-
import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
22
|
-
import { tmpdir } from "node:os";
|
|
23
|
-
import { join } from "node:path";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { writeExecStub } from "./exec-stub.mjs";
|
|
26
|
-
|
|
27
|
-
const SCRIPT = fileURLToPath(new URL("./verify-sha.sh", import.meta.url));
|
|
28
|
-
|
|
29
|
-
// Pin identity and cut the developer's ~/.gitconfig out of the fixture, so a
|
|
30
|
-
// local `pull.rebase` or hook cannot change what these repos look like. The
|
|
31
|
-
// GIT_* redirects would point the fixtures out of their own temp dirs.
|
|
32
|
-
const ENV = {
|
|
33
|
-
...process.env,
|
|
34
|
-
GIT_DIR: undefined,
|
|
35
|
-
GIT_WORK_TREE: undefined,
|
|
36
|
-
GIT_TEMPLATE_DIR: undefined,
|
|
37
|
-
GIT_INDEX_FILE: undefined,
|
|
38
|
-
GIT_AUTHOR_NAME: "t",
|
|
39
|
-
GIT_AUTHOR_EMAIL: "t@example.com",
|
|
40
|
-
GIT_COMMITTER_NAME: "t",
|
|
41
|
-
GIT_COMMITTER_EMAIL: "t@example.com",
|
|
42
|
-
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
43
|
-
GIT_CONFIG_SYSTEM: "/dev/null",
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const git = (cwd, ...args) =>
|
|
47
|
-
execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
|
|
48
|
-
|
|
49
|
-
// Absolute path to the real git, for any test that shadows `git` on PATH.
|
|
50
|
-
const REAL_GIT = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
51
|
-
|
|
52
|
-
// Absolute path to the real sed, for the passthrough shim that controls the
|
|
53
|
-
// broken-escaper case. Resolved out here, where PATH is still the real one, and
|
|
54
|
-
// quoted at the exec, for the reasons the git shims below record at length.
|
|
55
|
-
const REAL_SED = execFileSync("sh", ["-c", "command -v sed"], { encoding: "utf8" }).trim();
|
|
56
|
-
|
|
57
|
-
/** Empty commit on the current branch; returns its sha. */
|
|
58
|
-
const commit = (w, msg) => {
|
|
59
|
-
git(w, "commit", "-q", "--allow-empty", "-m", msg);
|
|
60
|
-
return git(w, "rev-parse", "HEAD");
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/** Bare origin + working clone with one commit on main. Returns the clone dir. */
|
|
64
|
-
function repo(t) {
|
|
65
|
-
const root = mkdtempSync(join(tmpdir(), "verify-sha-"));
|
|
66
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
67
|
-
const origin = join(root, "origin.git");
|
|
68
|
-
const w = join(root, "w");
|
|
69
|
-
execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
|
|
70
|
-
execFileSync("git", ["clone", "-q", origin, w], { env: ENV });
|
|
71
|
-
commit(w, "root");
|
|
72
|
-
git(w, "branch", "-M", "main");
|
|
73
|
-
git(w, "push", "-q", "-u", "origin", "main");
|
|
74
|
-
return w;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function verify(cwd, branch, sha, env = ENV) {
|
|
78
|
-
const r = spawnSync("sh", [SCRIPT, branch, sha], { cwd, env, encoding: "utf8" });
|
|
79
|
-
return { code: r.status, json: r.stdout.trim() ? JSON.parse(r.stdout) : null, stderr: r.stderr };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
test("a sha on the branch is reachable — exit 0", (t) => {
|
|
83
|
-
const w = repo(t);
|
|
84
|
-
const head = commit(w, "work that really landed");
|
|
85
|
-
git(w, "push", "-q", "origin", "main");
|
|
86
|
-
|
|
87
|
-
const { code, json } = verify(w, "main", head);
|
|
88
|
-
assert.equal(code, 0);
|
|
89
|
-
assert.equal(json.reachable, true);
|
|
90
|
-
assert.equal(json.sha, head);
|
|
91
|
-
assert.equal(json.tip, head);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test("a sha on a stray branch is not reachable — exit 1, the answer the script exists to give", (t) => {
|
|
95
|
-
const w = repo(t);
|
|
96
|
-
// The nested-worktree scenario from the script's header: a real commit in this
|
|
97
|
-
// repository that never made it onto the branch the member claims.
|
|
98
|
-
git(w, "checkout", "-q", "-b", "stray");
|
|
99
|
-
const stray = commit(w, "committed somewhere else");
|
|
100
|
-
git(w, "checkout", "-q", "main");
|
|
101
|
-
const tip = commit(w, "main moves on without it");
|
|
102
|
-
git(w, "push", "-q", "origin", "main");
|
|
103
|
-
|
|
104
|
-
const { code, json, stderr } = verify(w, "main", stray);
|
|
105
|
-
assert.equal(code, 1, "a real negative stays exit 1 — it is an answer, not a failure");
|
|
106
|
-
assert.equal(json.reachable, false);
|
|
107
|
-
assert.equal(json.tip, tip);
|
|
108
|
-
// Dropping `2>/dev/null` from the probe must not start leaking git noise onto
|
|
109
|
-
// the ordinary negative path: git says nothing at all when the answer is "no".
|
|
110
|
-
assert.doesNotMatch(stderr, /error:/, "a plain negative answer prints no git error");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("a merge-base that fails rather than answers is exit 2, never reachable:false", (t) => {
|
|
114
|
-
// The #266 defect: `git merge-base --is-ancestor` exits 128 when it cannot walk
|
|
115
|
-
// the history — a corrupt or unreadable object — and every non-zero status used
|
|
116
|
-
// to collapse into the definite verdict reachable:false at exit 1. Shim only
|
|
117
|
-
// `merge-base`; everything else is real git, so the fetch and both preconditions
|
|
118
|
-
// pass exactly as they do in the field and none of the existing exit-2 guards
|
|
119
|
-
// fires. This is the same collapse #17 fixed in the sibling prove-merge.sh.
|
|
120
|
-
const w = repo(t);
|
|
121
|
-
const head = commit(w, "work that really landed");
|
|
122
|
-
git(w, "push", "-q", "origin", "main");
|
|
123
|
-
|
|
124
|
-
const bin = mkdtempSync(join(tmpdir(), "verify-sha-shim-"));
|
|
125
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
126
|
-
// Ask the shell where git is, rather than deriving it from `--exec-path`: that
|
|
127
|
-
// answer is `<prefix>/libexec/git-core` on macOS but `/usr/lib/git-core` on
|
|
128
|
-
// Debian, where a `libexec` rewrite matches nothing and the shim execs a
|
|
129
|
-
// DIRECTORY — the fetch then fails first and this test measures the wrong
|
|
130
|
-
// failure. Resolved out here, where PATH is still the real one, and quoted at
|
|
131
|
-
// the exec: a git under a path with a space word-splits otherwise, and the
|
|
132
|
-
// fetch then dies first — which still satisfies the exit-2 and null-json
|
|
133
|
-
// assertions below, so only the stderr match would catch it.
|
|
134
|
-
writeExecStub(
|
|
135
|
-
join(bin, "git"),
|
|
136
|
-
`#!/bin/sh\n[ "$1" = merge-base ] && { echo "error: could not parse commit deadbeef" >&2; exit 128; }\nexec "${REAL_GIT}" "$@"\n`,
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const { code, json, stderr } = verify(w, "main", head, {
|
|
140
|
-
...ENV,
|
|
141
|
-
PATH: `${bin}:${ENV.PATH ?? process.env.PATH}`,
|
|
142
|
-
});
|
|
143
|
-
assert.equal(json, null, "no verdict may be printed for a question that was never answered");
|
|
144
|
-
assert.equal(code, 2, "unanswerable is exit 2, not the exit 1 that means definitely-not-reachable");
|
|
145
|
-
assert.match(stderr, /cannot tell reachable from unanswerable/);
|
|
146
|
-
// The cause has to reach the operator, which is why the probe drops 2>/dev/null.
|
|
147
|
-
assert.match(stderr, /could not parse commit/, "git's own diagnosis must survive to stderr");
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test("a sha that is not a commit in this repository is exit 2, not a negative verdict", (t) => {
|
|
151
|
-
// repo(t)'s root commit is enough: the 40-zero sha dies at the `cat-file -e`
|
|
152
|
-
// guard before merge-base runs, so where the tip sits is unobservable here.
|
|
153
|
-
const w = repo(t);
|
|
154
|
-
const { code, json, stderr } = verify(w, "main", "0".repeat(40));
|
|
155
|
-
assert.equal(code, 2);
|
|
156
|
-
assert.equal(json, null);
|
|
157
|
-
// Names the guard that fired, so this cannot pass on some other exit 2 — the
|
|
158
|
-
// fetch failing is also exit 2 with no stdout, which is why the code alone
|
|
159
|
-
// and an empty stdout are not enough to tell these two cases apart.
|
|
160
|
-
assert.match(stderr, /cannot resolve 0{40} to a commit in this repository/);
|
|
161
|
-
assert.match(stderr, /Not a valid object name/, "git's own diagnosis must survive to stderr");
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("a failed fetch carries git's own cause, and a bad URL no longer reads like a removed remote", (t) => {
|
|
165
|
-
// #559: these two produced byte-identical output, "cannot fetch origin/main —
|
|
166
|
-
// branch missing, or no network", naming neither failure. The sha is never
|
|
167
|
-
// reached in any of these — the fetch guard fires first — so 40 zeros will do.
|
|
168
|
-
const dead = "0".repeat(40);
|
|
169
|
-
|
|
170
|
-
const badUrl = repo(t);
|
|
171
|
-
git(badUrl, "remote", "set-url", "origin", "/nonexistent/path.git");
|
|
172
|
-
const a = verify(badUrl, "main", dead);
|
|
173
|
-
|
|
174
|
-
const noRemote = repo(t);
|
|
175
|
-
git(noRemote, "remote", "remove", "origin");
|
|
176
|
-
const b = verify(noRemote, "main", dead);
|
|
177
|
-
|
|
178
|
-
for (const r of [a, b]) {
|
|
179
|
-
assert.equal(r.code, 2);
|
|
180
|
-
assert.equal(r.json, null, "no verdict for a question that was never answered");
|
|
181
|
-
assert.match(r.stderr, /cannot fetch origin\/main/);
|
|
182
|
-
assert.doesNotMatch(r.stderr, /branch missing|no network/, "the guard no longer asserts a cause it cannot know");
|
|
183
|
-
assert.match(r.stderr, /does not appear to be a git repository/, "git's own diagnosis must survive to stderr");
|
|
184
|
-
}
|
|
185
|
-
// Only git's line tells the two apart, which is exactly what was discarded.
|
|
186
|
-
assert.match(a.stderr, /'\/nonexistent\/path\.git'/);
|
|
187
|
-
assert.doesNotMatch(b.stderr, /nonexistent/, "two distinct faults must not collapse into one message");
|
|
188
|
-
|
|
189
|
-
// The one cause the old list did name is still reported — now by git, and
|
|
190
|
-
// precisely, so dropping the list refuses nothing it used to explain.
|
|
191
|
-
const c = verify(repo(t), "nosuchbranch", dead);
|
|
192
|
-
assert.equal(c.code, 2);
|
|
193
|
-
assert.match(c.stderr, /cannot fetch origin\/nosuchbranch/);
|
|
194
|
-
assert.match(c.stderr, /couldn't find remote ref nosuchbranch/);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test("a failed fetch is fatal — the script stops rather than answering off a stale ref", (t) => {
|
|
198
|
-
// #574: the case above asserts exit 2, no JSON, and git's cause on stderr, and
|
|
199
|
-
// every one of those survives downgrading this guard's `die` to a warning. With
|
|
200
|
-
// the guard advisory the script runs ON: `origin/main` still resolves from the
|
|
201
|
-
// tracking ref the clone left behind, and the sha then dies at the `cat-file -e`
|
|
202
|
-
// guard — which independently gives exit 2, no stdout, and leaves the `cannot
|
|
203
|
-
// fetch` line and git's diagnosis sitting on stderr. Exit code, empty stdout and
|
|
204
|
-
// a stderr substring are each reproducible by a later guard, so no conjunction
|
|
205
|
-
// of them can see whether this one was fatal.
|
|
206
|
-
//
|
|
207
|
-
// What only fatality produces is the absence of progress: the `tip =` trace is
|
|
208
|
-
// echoed once the `rev-parse --verify` guard that follows this one has passed
|
|
209
|
-
// — and it does pass here, off the tracking ref — so the trace appears if and
|
|
210
|
-
// only if execution got past THIS guard. That line is pinned verbatim by "a
|
|
211
|
-
// healthy run stays quiet", so it cannot be reworded out from under this
|
|
212
|
-
// assertion unseen — and unlike a `doesNotMatch` on some later guard's
|
|
213
|
-
// message, it does not depend on which of them happens to fire, or on how it
|
|
214
|
-
// is worded.
|
|
215
|
-
const w = repo(t);
|
|
216
|
-
// One fixture: a bad URL and a removed remote both take this guard's `|| die`
|
|
217
|
-
// branch, differing only in git's own line — the distinction #565 pinned next
|
|
218
|
-
// door. This test is about the guard's fatality, not about telling causes apart.
|
|
219
|
-
git(w, "remote", "set-url", "origin", "/nonexistent/path.git");
|
|
220
|
-
|
|
221
|
-
const { code, json, stderr } = verify(w, "main", "0".repeat(40));
|
|
222
|
-
assert.equal(code, 2);
|
|
223
|
-
assert.equal(json, null);
|
|
224
|
-
assert.doesNotMatch(
|
|
225
|
-
stderr,
|
|
226
|
-
/origin\/main tip =/,
|
|
227
|
-
"a fetch that failed must stop the script, not warn and answer against an unupdated ref",
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("a fetch that succeeds but leaves origin/<branch> unresolvable is exit 2 at the rev-parse guard", (t) => {
|
|
232
|
-
const w = repo(t);
|
|
233
|
-
// Real git throughout, no shim: with no fetch refspec configured, `git fetch
|
|
234
|
-
// origin main` still succeeds — into FETCH_HEAD — without updating the
|
|
235
|
-
// remote-tracking ref, so deleting that ref leaves the second guard to fire
|
|
236
|
-
// while the first passes. A shim that killed the fetch would measure the
|
|
237
|
-
// wrong failure, since that is also exit 2 with no stdout.
|
|
238
|
-
git(w, "config", "--unset", "remote.origin.fetch");
|
|
239
|
-
git(w, "update-ref", "-d", "refs/remotes/origin/main");
|
|
240
|
-
|
|
241
|
-
const { code, json, stderr } = verify(w, "main", "0".repeat(40));
|
|
242
|
-
assert.equal(code, 2);
|
|
243
|
-
assert.equal(json, null);
|
|
244
|
-
assert.match(stderr, /origin\/main does not resolve after fetch/);
|
|
245
|
-
// #1146 added --verify to this capture, which changes git's own wording for
|
|
246
|
-
// this exact failure: `fatal: Needed a single revision`, not the `ambiguous
|
|
247
|
-
// argument` a bare `git rev-parse` prints for the same unresolvable ref.
|
|
248
|
-
assert.match(stderr, /fatal: Needed a single revision/, "git's own diagnosis must survive to stderr");
|
|
249
|
-
assert.doesNotMatch(stderr, /cannot fetch/, "the fetch passed — this is the guard after it");
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("a rev-parse that cannot resolve origin/<branch> is fatal — the script stops rather than answering off an empty tip", (t) => {
|
|
253
|
-
// #580, the defect #574 fixed one guard up. The case above asserts exit 2, no
|
|
254
|
-
// JSON, this guard's own message and git's cause — and every one of those
|
|
255
|
-
// survives downgrading this guard's `die` to a warning. With it advisory `tip`
|
|
256
|
-
// is empty, the script runs ON, and the `cat-file -e` guard below kills it:
|
|
257
|
-
// exit 2 again, no stdout again, and this guard's own line still sitting on
|
|
258
|
-
// stderr. Measured — the whole suite stayed green under that mutant, so no
|
|
259
|
-
// conjunction of those three can see whether this guard was fatal.
|
|
260
|
-
//
|
|
261
|
-
// What only fatality produces is the absence of progress. The `tip =` trace is
|
|
262
|
-
// echoed by the `echo` this guard falls through to, so it appears if and only
|
|
263
|
-
// if execution got past it, and it is pinned verbatim by "a healthy run stays
|
|
264
|
-
// quiet", so it cannot be reworded out from under this assertion unseen.
|
|
265
|
-
// git's own `Needed a single revision` (#1146 added --verify, which is what
|
|
266
|
-
// produces this exact wording rather than a bare rev-parse's `ambiguous
|
|
267
|
-
// argument`) is the other bracket: it proves rev-parse ran and failed HERE,
|
|
268
|
-
// rather than this test passing off an earlier guard that stopped the script
|
|
269
|
-
// before it. Neither bracket names a `die` string, so rewording any guard's
|
|
270
|
-
// message — this one included — leaves both standing.
|
|
271
|
-
const w = repo(t);
|
|
272
|
-
// The fixture of the case above: with no refspec configured the fetch still
|
|
273
|
-
// succeeds, into FETCH_HEAD, so deleting the tracking ref leaves this guard to
|
|
274
|
-
// fire while the one before it passes.
|
|
275
|
-
git(w, "config", "--unset", "remote.origin.fetch");
|
|
276
|
-
git(w, "update-ref", "-d", "refs/remotes/origin/main");
|
|
277
|
-
|
|
278
|
-
const { code, json, stderr } = verify(w, "main", "0".repeat(40));
|
|
279
|
-
assert.equal(code, 2);
|
|
280
|
-
assert.equal(json, null);
|
|
281
|
-
assert.match(stderr, /fatal: Needed a single revision/, "rev-parse ran and failed here, not some earlier guard");
|
|
282
|
-
assert.doesNotMatch(
|
|
283
|
-
stderr,
|
|
284
|
-
/origin\/main tip =/,
|
|
285
|
-
"a ref that does not resolve must stop the script, not warn and carry an empty tip onward",
|
|
286
|
-
);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// #1146: the tip capture (`tip=$(git rev-parse "origin/$branch")`) had no
|
|
290
|
-
// `--verify`. Without it, an unresolvable "origin/<branch>" falls back to
|
|
291
|
-
// treating the argument as a PATH: if a file or dir of that name sits in the
|
|
292
|
-
// cwd, rev-parse prints it and exits 0, and this guard's own `|| die` never
|
|
293
|
-
// fires. This differs from the case above only in that a colliding path
|
|
294
|
-
// exists — same missing tracking ref, same fetch, same everything else.
|
|
295
|
-
test("a rev-parse that would fall back to a colliding path is still fatal, and names the tip guard as the cause", (t) => {
|
|
296
|
-
const w = repo(t);
|
|
297
|
-
git(w, "config", "--unset", "remote.origin.fetch");
|
|
298
|
-
git(w, "update-ref", "-d", "refs/remotes/origin/main");
|
|
299
|
-
// The collision: a file at the exact path "origin/main" would print, at
|
|
300
|
-
// exit 0, wherever this guard let a bare `git rev-parse` fall back to it.
|
|
301
|
-
mkdirSync(join(w, "origin"), { recursive: true });
|
|
302
|
-
writeFileSync(join(w, "origin", "main"), "not a sha\n");
|
|
303
|
-
|
|
304
|
-
const { code, json, stderr } = verify(w, "main", "0".repeat(40));
|
|
305
|
-
assert.equal(code, 2);
|
|
306
|
-
assert.equal(json, null);
|
|
307
|
-
assert.match(stderr, /origin\/main does not resolve after fetch/, "this guard is what catches it");
|
|
308
|
-
assert.match(stderr, /fatal: Needed a single revision/, "git's own --verify diagnosis must survive to stderr");
|
|
309
|
-
// The discriminating pair: without --verify this guard does not catch this
|
|
310
|
-
// fixture at all. Measured 2026-09-03 against a single-point mutant (this
|
|
311
|
-
// capture with `--verify` removed, nothing else): the capture exits 0 with
|
|
312
|
-
// the colliding PATH as the tip, and the run dies at the `git cat-file -e`
|
|
313
|
-
// guard with `cannot resolve 0000… to a commit in this repository` — a
|
|
314
|
-
// refusal about the sha, not about the ref. It never reaches
|
|
315
|
-
// `git merge-base --is-ancestor`: an all-zero sha cannot clear `cat-file`.
|
|
316
|
-
// Reaching merge-base takes a real commit for a sha, which is the mutant
|
|
317
|
-
// test's fixture, not this one.
|
|
318
|
-
assert.doesNotMatch(stderr, /cannot resolve .* to a commit/,
|
|
319
|
-
"without --verify the colliding path is carried onward and the cat-file guard is what refuses — this guard must be the one that fires");
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
// The positive control criterion #1146 names explicitly: a real ref and a
|
|
323
|
-
// same-named path coexisting must still resolve the ref. Git's own
|
|
324
|
-
// precedence — try revision resolution before ever falling back to a path —
|
|
325
|
-
// makes this true for both the bare and the --verify forms; pinned here so a
|
|
326
|
-
// reader does not need to trust that reasoning, only this measurement.
|
|
327
|
-
test("a colliding path does not shadow a real remote-tracking ref", (t) => {
|
|
328
|
-
const w = repo(t);
|
|
329
|
-
const head = commit(w, "the ref, not the path, must win");
|
|
330
|
-
git(w, "push", "-q", "origin", "main");
|
|
331
|
-
mkdirSync(join(w, "origin"), { recursive: true });
|
|
332
|
-
writeFileSync(join(w, "origin", "main"), "not a sha\n");
|
|
333
|
-
|
|
334
|
-
const { code, json } = verify(w, "main", head);
|
|
335
|
-
assert.equal(code, 0);
|
|
336
|
-
assert.equal(json.reachable, true);
|
|
337
|
-
assert.equal(json.tip, head, "the real ref's sha, never the colliding path's name");
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// The regression control: what a fixture whose sha is a REAL commit catches
|
|
341
|
-
// WITHOUT --verify. Not the fixture of the colliding-path test above, whose
|
|
342
|
-
// all-zero sha is refused earlier, by `git cat-file -e`; the sha is what
|
|
343
|
-
// routes a run to one guard or the other. And not the shape a reader might
|
|
344
|
-
// assume from the ticket's general description of this bug class (a
|
|
345
|
-
// malformed-but-parseable payload at exit 0). Measured 2026-09-03: the
|
|
346
|
-
// `git merge-base --is-ancestor` guard re-resolves the identical
|
|
347
|
-
// "origin/$branch" string, and merge-base has no path fallback, so it
|
|
348
|
-
// independently refuses (rc 128) whenever the ref genuinely does not exist.
|
|
349
|
-
// That guard's own `|| die` already fires — this script was fail-closed
|
|
350
|
-
// before this fix too, by whichever guard the sha routed it to. What the
|
|
351
|
-
// mutant actually costs is the DIAGNOSIS: it dies with "cannot tell reachable
|
|
352
|
-
// from unanswerable" — a guard that exists to catch a broken `merge-base`,
|
|
353
|
-
// not an unresolvable ref — never with the tip guard's own "does not resolve
|
|
354
|
-
// after fetch". An operator reading the refusal is told the wrong thing
|
|
355
|
-
// failed.
|
|
356
|
-
test("mutant: without --verify, the same fixture is still caught, but by the wrong guard", (t) => {
|
|
357
|
-
const w = repo(t);
|
|
358
|
-
// A real commit, so the mutant's bogus tip gets past `git cat-file -e` and
|
|
359
|
-
// reaches merge-base — the deepest point this bug can reach. Local existence
|
|
360
|
-
// is the whole requirement: what makes merge-base refuse is the deleted
|
|
361
|
-
// tracking ref, so this commit is deliberately NOT pushed.
|
|
362
|
-
const head = commit(w, "a real commit, so the mutant runs all the way to merge-base");
|
|
363
|
-
git(w, "config", "--unset", "remote.origin.fetch");
|
|
364
|
-
git(w, "update-ref", "-d", "refs/remotes/origin/main");
|
|
365
|
-
mkdirSync(join(w, "origin"), { recursive: true });
|
|
366
|
-
writeFileSync(join(w, "origin", "main"), "not a sha\n");
|
|
367
|
-
|
|
368
|
-
const scriptText = readFileSync(SCRIPT, "utf8");
|
|
369
|
-
const FIXED_LINE = 'tip=$(git rev-parse --verify "origin/$branch")';
|
|
370
|
-
assert.ok(scriptText.includes(FIXED_LINE), "the capture line moved — update this mutant to match");
|
|
371
|
-
const scratch = mkdtempSync(join(tmpdir(), "verify-sha-mutant-"));
|
|
372
|
-
t.after(() => rmSync(scratch, { recursive: true, force: true }));
|
|
373
|
-
const mutant = join(scratch, "verify-sha.sh");
|
|
374
|
-
writeFileSync(mutant, scriptText.replace(FIXED_LINE, 'tip=$(git rev-parse "origin/$branch")'), { mode: 0o755 });
|
|
375
|
-
// The mutant sources json.sh/net.sh next to itself ("$(dirname "$0")"), so
|
|
376
|
-
// both siblings have to travel with it or the run dies at the library guard
|
|
377
|
-
// instead of measuring anything about this mutant.
|
|
378
|
-
copyFileSync(fileURLToPath(new URL("./json.sh", import.meta.url)), join(scratch, "json.sh"));
|
|
379
|
-
copyFileSync(fileURLToPath(new URL("./net.sh", import.meta.url)), join(scratch, "net.sh"));
|
|
380
|
-
|
|
381
|
-
const r = spawnSync("sh", [mutant, "main", head], { cwd: w, env: ENV, encoding: "utf8" });
|
|
382
|
-
assert.equal(r.status, 2, "still fails closed — merge-base's own guard catches it either way");
|
|
383
|
-
assert.equal(r.stdout, "", "no payload either way — this bug never reaches the printf");
|
|
384
|
-
assert.match(r.stderr, /cannot tell reachable from unanswerable/, "caught by the WRONG guard");
|
|
385
|
-
assert.doesNotMatch(r.stderr, /origin\/main does not resolve after fetch/,
|
|
386
|
-
"and never names the real cause — restoring that name is what this fix buys");
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
test("an object that is present but is not a commit is not reported as absent", (t) => {
|
|
390
|
-
const w = repo(t);
|
|
391
|
-
const tree = git(w, "rev-parse", "HEAD^{tree}");
|
|
392
|
-
const { code, json, stderr } = verify(w, "main", tree);
|
|
393
|
-
assert.equal(code, 2);
|
|
394
|
-
assert.equal(json, null);
|
|
395
|
-
assert.match(stderr, /cannot resolve .+ to a commit in this repository/);
|
|
396
|
-
// The old wording asserted this object "is not a commit object in this
|
|
397
|
-
// repository". It is in this repository — git reads it and reports its real
|
|
398
|
-
// type, which is the half the guard was throwing away.
|
|
399
|
-
assert.match(stderr, /dereferences to tree type/, "git's own diagnosis must survive to stderr");
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
test("a sha the cat-file guard rejects is fatal — the script stops rather than asking merge-base about it", (t) => {
|
|
403
|
-
// #580's second site, and the one where the #574 remedy does not transcribe.
|
|
404
|
-
// The guards around this one each emit a progress marker once they pass — the
|
|
405
|
-
// `tip =` trace after the rev-parse guard, the `IS reachable` / `is NOT
|
|
406
|
-
// reachable` echoes inside the merge-base branch; this one emits none. The
|
|
407
|
-
// script emits nothing between it and the merge-base status guard, and on
|
|
408
|
-
// both fixtures its two sibling cases use — 40
|
|
409
|
-
// zeros, and a tree object — merge-base cannot resolve the object either, so
|
|
410
|
-
// it exits 128 and that status guard kills the run. Measured: exit 2, empty
|
|
411
|
-
// stdout and this guard's own line on stderr, all reproduced, and the suite
|
|
412
|
-
// stayed green under the mutant. Neither `reachable` echo is ever reached, so
|
|
413
|
-
// there is no marker here whose absence could be asserted.
|
|
414
|
-
//
|
|
415
|
-
// This fixture therefore removes the mask rather than looking for a marker
|
|
416
|
-
// that is not there. `git cat-file` is shimmed to fail — standing in for the
|
|
417
|
-
// unreadable object store this guard's own comment names as one of the things
|
|
418
|
-
// it fires on — and every other git call is real. `$sha` is a genuinely
|
|
419
|
-
// reachable commit, so with the guard downgraded merge-base answers normally
|
|
420
|
-
// and the script runs to completion, printing `reachable:true` at exit 0. The
|
|
421
|
-
// downgrade does not take a different route to exit 2; it returns the WRONG
|
|
422
|
-
// ANSWER, which is why the exit code and the payload are pinned here too.
|
|
423
|
-
const w = repo(t);
|
|
424
|
-
const head = commit(w, "work that really landed");
|
|
425
|
-
git(w, "push", "-q", "origin", "main");
|
|
426
|
-
|
|
427
|
-
const bin = mkdtempSync(join(tmpdir(), "verify-sha-catfile-shim-"));
|
|
428
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
429
|
-
// Resolved out here, where PATH is still the real one, and quoted at the exec,
|
|
430
|
-
// for the reasons the merge-base shim above records at length.
|
|
431
|
-
writeExecStub(
|
|
432
|
-
join(bin, "git"),
|
|
433
|
-
`#!/bin/sh\n[ "$1" = cat-file ] && { echo "error: unable to read object" >&2; exit 1; }\nexec "${REAL_GIT}" "$@"\n`,
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
const { code, json, stderr } = verify(w, "main", head, {
|
|
437
|
-
...ENV,
|
|
438
|
-
PATH: `${bin}:${ENV.PATH ?? process.env.PATH}`,
|
|
439
|
-
});
|
|
440
|
-
assert.equal(code, 2);
|
|
441
|
-
assert.equal(json, null);
|
|
442
|
-
// The positive control, and this test needs one: shimming `git` wholesale
|
|
443
|
-
// could break the fetch instead, and a run that died two guards earlier gives
|
|
444
|
-
// exit 2 with an empty stdout just the same — this test would pass while
|
|
445
|
-
// measuring nothing. The `tip =` trace sits between the two, so it proves
|
|
446
|
-
// execution reached THIS guard, and the shim's own line proves cat-file is
|
|
447
|
-
// what failed. Both are pinned elsewhere: the trace verbatim by "a healthy run
|
|
448
|
-
// stays quiet", the shim's line by the shim right here.
|
|
449
|
-
assert.match(stderr, /origin\/main tip =/, "the fetch and the rev-parse guard both passed — this is the guard after them");
|
|
450
|
-
assert.match(stderr, /unable to read object/, "cat-file ran and failed, which is the failure under test");
|
|
451
|
-
assert.doesNotMatch(
|
|
452
|
-
stderr,
|
|
453
|
-
/IS reachable on origin\/main/,
|
|
454
|
-
"a sha this guard could not resolve must stop the script, not warn and then report it as reachable",
|
|
455
|
-
);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
test("a healthy run stays quiet — the unmuted guards add nothing to stderr", (t) => {
|
|
459
|
-
const w = repo(t);
|
|
460
|
-
// Push from a second clone so `w`'s fetch has real objects to transfer: an
|
|
461
|
-
// already-up-to-date fetch would not exercise the path that could go noisy.
|
|
462
|
-
const other = join(w, "..", "other");
|
|
463
|
-
execFileSync("git", ["clone", "-q", join(w, "..", "origin.git"), other], { env: ENV });
|
|
464
|
-
const head = commit(other, "work that really landed");
|
|
465
|
-
git(other, "push", "-q", "origin", "main");
|
|
466
|
-
|
|
467
|
-
const { code, json, stderr } = verify(w, "main", head);
|
|
468
|
-
assert.equal(code, 0);
|
|
469
|
-
assert.equal(json.reachable, true);
|
|
470
|
-
// Exact, not a /fatal:/ sniff. Dropping `2>/dev/null` from three guards is
|
|
471
|
-
// only safe while all three stay silent when they succeed, and this script's
|
|
472
|
-
// stderr is read by the fleet controller. Anything git starts printing on an
|
|
473
|
-
// ordinary run shows up here as a fourth line.
|
|
474
|
-
assert.deepEqual(stderr.split("\n").filter(Boolean), [
|
|
475
|
-
"$ git fetch --quiet origin main",
|
|
476
|
-
` origin/main tip = ${head}`,
|
|
477
|
-
` ${head} IS reachable on origin/main`,
|
|
478
|
-
]);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// No git fixture: the argc guard fires before the script runs any git at all,
|
|
482
|
-
// so the cwd never has to be a repository.
|
|
483
|
-
test("a wrong argument count is exit 2", () => {
|
|
484
|
-
const r = spawnSync("sh", [SCRIPT, "main"], { cwd: tmpdir(), env: ENV, encoding: "utf8" });
|
|
485
|
-
assert.equal(r.status, 2);
|
|
486
|
-
assert.match(r.stderr, /usage: verify-sha\.sh/);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
// --- #119: the payload's own string fields.
|
|
490
|
-
//
|
|
491
|
-
// `git check-ref-format --branch 'evil"branch'` exits 0 — git accepts a double
|
|
492
|
-
// quote in a ref — so pushing a branch is all the access this needs. Spliced
|
|
493
|
-
// raw, the script emitted `{"branch":"evil"branch",…}` at **exit 0**: an
|
|
494
|
-
// unparseable payload with no signal at all that anything went wrong, while the
|
|
495
|
-
// contract row in `docs/specs/2026-07-23-fleet-plugin-design.md` documents the
|
|
496
|
-
// exit-0/1 payload as `{branch, sha, reachable, tip}`.
|
|
497
|
-
//
|
|
498
|
-
// Two of the three are reachable, not one. `$tip` is `git rev-parse`, which
|
|
499
|
-
// emits 40 hex characters and nothing else, and is wrapped for uniformity. But
|
|
500
|
-
// `$sha` is not: it is argv, and `git cat-file -e "${sha}^{commit}"` resolves
|
|
501
|
-
// any rev expression rather than only a hex object name — a REF name included —
|
|
502
|
-
// so a tag or branch holding a quote passes that gate and reaches the payload.
|
|
503
|
-
// The second test below is that vector, and it fails without the wrapping.
|
|
504
|
-
test("a branch name holding a double quote still emits parseable JSON", (t) => {
|
|
505
|
-
const w = repo(t);
|
|
506
|
-
const head = commit(w, "work on a hostile branch name");
|
|
507
|
-
git(w, "branch", 'evil"branch');
|
|
508
|
-
git(w, "push", "-q", "origin", 'evil"branch');
|
|
509
|
-
|
|
510
|
-
const r = spawnSync("sh", [SCRIPT, 'evil"branch', head], { cwd: w, env: ENV, encoding: "utf8" });
|
|
511
|
-
|
|
512
|
-
assert.equal(r.status, 0, "the sha IS on that branch — the quote must not change the verdict");
|
|
513
|
-
const json = JSON.parse(r.stdout);
|
|
514
|
-
assert.equal(json.branch, 'evil"branch', "and the field round-trips to the name that went in");
|
|
515
|
-
assert.equal(json.reachable, true);
|
|
516
|
-
assert.equal(json.tip, head);
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
// The `$sha` half of the same vector. `git cat-file -e 'evil"tag^{commit}'`
|
|
520
|
-
// resolves the TAG, so argv reaches the payload carrying a quote and the field
|
|
521
|
-
// is emitted as `"sha":"evil"tag"` — unparseable, at exit 0 — with the wrapping
|
|
522
|
-
// removed. Pinned separately from `$branch` because the two are independent
|
|
523
|
-
// operands of the same `&&` chain and either could be dropped alone.
|
|
524
|
-
test("a sha argument naming a quote-bearing ref still emits parseable JSON", (t) => {
|
|
525
|
-
const w = repo(t);
|
|
526
|
-
const head = commit(w, "work reachable by a hostile tag name");
|
|
527
|
-
git(w, "tag", 'evil"tag', head);
|
|
528
|
-
git(w, "push", "-q", "origin", "main");
|
|
529
|
-
|
|
530
|
-
const r = spawnSync("sh", [SCRIPT, "main", 'evil"tag'], { cwd: w, env: ENV, encoding: "utf8" });
|
|
531
|
-
|
|
532
|
-
assert.equal(r.status, 0, "the tag IS reachable on origin/main — the quote must not change the verdict");
|
|
533
|
-
const json = JSON.parse(r.stdout);
|
|
534
|
-
assert.equal(json.sha, 'evil"tag', "and the field round-trips to the argument that went in");
|
|
535
|
-
assert.equal(json.reachable, true);
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
// No backslash case here, deliberately: measured, `git branch 'back\slash'`
|
|
539
|
-
// and `git check-ref-format --branch 'back\slash'` both exit 128 — git refuses
|
|
540
|
-
// a backslash in a ref outright. A branch name is this script's ONLY string
|
|
541
|
-
// input, so `\` is unreachable and a test for it would pin fiction. The
|
|
542
|
-
// backslash vector is real on the scripts whose input is a worktree PATH.
|
|
543
|
-
|
|
544
|
-
test("an ordinary branch name is untouched — the escaping accepts what it should", (t) => {
|
|
545
|
-
// The false-positive half. A guard that mangles or refuses the names this
|
|
546
|
-
// script sees on every healthy run is a different bug from the one above.
|
|
547
|
-
const w = repo(t);
|
|
548
|
-
const head = commit(w, "ordinary");
|
|
549
|
-
git(w, "branch", "fix/119-json-sh-extract");
|
|
550
|
-
git(w, "push", "-q", "origin", "fix/119-json-sh-extract");
|
|
551
|
-
|
|
552
|
-
const r = spawnSync("sh", [SCRIPT, "fix/119-json-sh-extract", head], { cwd: w, env: ENV, encoding: "utf8" });
|
|
553
|
-
|
|
554
|
-
assert.equal(r.status, 0);
|
|
555
|
-
assert.equal(r.stdout, `{"branch":"fix/119-json-sh-extract","sha":"${head}","reachable":true,"tip":"${head}"}\n`,
|
|
556
|
-
"byte-identical to what this script has always emitted for a name with nothing to escape");
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
// #884: the escaping guard's FATALITY, which every case above is blind to. They
|
|
560
|
-
// each assert what a WORKING escaper produces, so none of them reaches the
|
|
561
|
-
// `|| die` that covers the escaper failing — measured, downgrading it to a
|
|
562
|
-
// message-preserving warning left this whole suite green.
|
|
563
|
-
//
|
|
564
|
-
// The downgrade does not emit a malformed payload. `branch_j`, `sha_j` and
|
|
565
|
-
// `tip_j` are assigned by one `&&` chain, so the first `jstr` that fails
|
|
566
|
-
// short-circuits the rest and leaves those names unset; with the guard advisory
|
|
567
|
-
// the `printf` references one and `set -u` aborts the shell. Measured on this
|
|
568
|
-
// fixture, whose sha IS reachable, stdout empty in every run: unmutated,
|
|
569
|
-
// /bin/sh (macOS bash 3.2.57) and /bin/dash alike exit 2 with the guard's own
|
|
570
|
-
// line. Downgraded, /bin/sh aborts at exit 1 saying `sha_j: unbound variable`,
|
|
571
|
-
// and /bin/dash aborts at exit 2 saying `sha_j: parameter not set`.
|
|
572
|
-
//
|
|
573
|
-
// Exit 1 is what this script's contract reads as "the sha is NOT reachable", so
|
|
574
|
-
// under a bash-family `sh` the downgrade is a confident wrong verdict. An
|
|
575
|
-
// unparseable payload would at least fail the caller's parse; a bare exit 1
|
|
576
|
-
// instead has `run-team/SKILL.md` flag the member, withhold the enqueue and
|
|
577
|
-
// hold the ticket until a maintainer rules — spent on a SHA that was on the
|
|
578
|
-
// branch the whole time.
|
|
579
|
-
//
|
|
580
|
-
// Which abort it is, though, is the shell's to choose and not this script's,
|
|
581
|
-
// and dash's lands on 2 — the very status a firing guard returns. `verify`
|
|
582
|
-
// spawns a bare `sh`, and `.github/workflows/ci.yml`'s `check` job runs on
|
|
583
|
-
// `ubuntu-latest`, where that name resolves to dash: an exit-code assertion
|
|
584
|
-
// therefore pins this guard on a developer's Mac and lets the mutant through
|
|
585
|
-
// on the runner that gates the merge. `sha_j` is what discriminates instead.
|
|
586
|
-
// It reaches stderr only from that nounset abort — measured under /bin/sh and
|
|
587
|
-
// /bin/dash, no healthy run, no genuine `not reachable`, no ordinary `die` and
|
|
588
|
-
// no firing of this guard puts it there — while a shell aborting on it names
|
|
589
|
-
// it first and words the rest however it likes. Matching a wording pins the
|
|
590
|
-
// shell that uses that wording and no other.
|
|
591
|
-
//
|
|
592
|
-
// `jstr` escapes through a `sed`/`tr` pipeline, so shadowing `sed` breaks the
|
|
593
|
-
// escaper without touching git. The git shims elsewhere in this file cannot
|
|
594
|
-
// reach this guard: every failure they inject kills the run before the payload
|
|
595
|
-
// is built.
|
|
596
|
-
//
|
|
597
|
-
// Two brackets stand in for a progress marker this guard does not have — the
|
|
598
|
-
// script prints nothing between the escaping and the `printf` it protects. The
|
|
599
|
-
// `IS reachable` trace is echoed only once merge-base has answered, so it
|
|
600
|
-
// proves the run cleared every earlier guard, and the shim's own line proves
|
|
601
|
-
// the escaper is what failed. Between them, no other guard can produce this
|
|
602
|
-
// signature. The trace is pinned verbatim by "a healthy run stays quiet", so it
|
|
603
|
-
// cannot be reworded out from under this assertion unseen, and no assertion
|
|
604
|
-
// here names a `die` message — rewording any of them, this guard's own
|
|
605
|
-
// included, leaves the pin standing.
|
|
606
|
-
|
|
607
|
-
/** A dir holding a `sed` shim with the given body, prepended to PATH. */
|
|
608
|
-
function sedShim(t, body) {
|
|
609
|
-
const bin = mkdtempSync(join(tmpdir(), "verify-sha-sed-shim-"));
|
|
610
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
611
|
-
writeExecStub(join(bin, "sed"), `#!/bin/sh\n${body}\n`);
|
|
612
|
-
return `${bin}:${ENV.PATH ?? process.env.PATH}`;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
test("an escaper that cannot run is exit 2, never the exit 1 that means `not reachable`", (t) => {
|
|
616
|
-
const w = repo(t);
|
|
617
|
-
const head = commit(w, "work that really landed");
|
|
618
|
-
git(w, "push", "-q", "origin", "main");
|
|
619
|
-
|
|
620
|
-
const { code, json, stderr } = verify(w, "main", head, {
|
|
621
|
-
...ENV,
|
|
622
|
-
PATH: sedShim(t, 'echo "sed: outage" >&2\nexit 1'),
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// Whether this fixture measured the guard at all is settled before its
|
|
626
|
-
// verdict is read: an assertion that fails masks every one after it, and
|
|
627
|
-
// "the shim broke something else" and "the guard is not fatal" are not
|
|
628
|
-
// interchangeable diagnoses.
|
|
629
|
-
assert.match(stderr, /sed: outage/, "the escaper ran and failed, which is the failure under test");
|
|
630
|
-
assert.match(
|
|
631
|
-
stderr,
|
|
632
|
-
/IS reachable on origin\/main/,
|
|
633
|
-
"merge-base answered — this is the guard after it, not an earlier one the shim happened to break",
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
assert.equal(
|
|
637
|
-
code,
|
|
638
|
-
2,
|
|
639
|
-
"a payload that could not be escaped is `the question could not be answered`. Exit 1 would report a sha that IS on the branch as missing from it, and the controller would flag the member and hold its ticket for a maintainer's ruling.",
|
|
640
|
-
);
|
|
641
|
-
assert.equal(json, null, "no verdict may be printed for a payload that was never escaped");
|
|
642
|
-
assert.doesNotMatch(
|
|
643
|
-
stderr,
|
|
644
|
-
/sha_j/,
|
|
645
|
-
"the guard must stop the script, not warn and leave the payload `printf` reading names the `&&` chain never assigned. The NAME, never the wording: bash says `sha_j: unbound variable` at exit 1 and dash `sha_j: parameter not set` at exit 2, so a wording match and the exit-2 assertion each pass on the mutant under the shell CI actually runs.",
|
|
646
|
-
);
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
test("a shadowed `sed` that works is answered normally — the guard refuses only a real outage", (t) => {
|
|
650
|
-
// The false-positive half, and the control the case above needs: shadowing
|
|
651
|
-
// `sed` on PATH is not by itself fatal to this script. Same fixture and the
|
|
652
|
-
// same shadowed name, a passthrough body — so the exit 2 up there is the
|
|
653
|
-
// escaper failing, not the shim's mere presence. Without this, that case
|
|
654
|
-
// could be measuring a PATH it broke wholesale and still read green.
|
|
655
|
-
const w = repo(t);
|
|
656
|
-
const head = commit(w, "ordinary");
|
|
657
|
-
git(w, "push", "-q", "origin", "main");
|
|
658
|
-
|
|
659
|
-
const r = spawnSync("sh", [SCRIPT, "main", head], {
|
|
660
|
-
cwd: w,
|
|
661
|
-
env: { ...ENV, PATH: sedShim(t, `exec "${REAL_SED}" "$@"`) },
|
|
662
|
-
encoding: "utf8",
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
assert.equal(r.status, 0, "the sha IS reachable — a working escaper must not change the verdict");
|
|
666
|
-
assert.equal(
|
|
667
|
-
r.stdout,
|
|
668
|
-
`{"branch":"main","sha":"${head}","reachable":true,"tip":"${head}"}\n`,
|
|
669
|
-
"byte-identical to the payload this script emits with no shim in the way",
|
|
670
|
-
);
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
// `.` is a POSIX special builtin, so failing to open its operand aborts a
|
|
674
|
-
// non-interactive shell before any `||` on the line can run — measured, /bin/sh
|
|
675
|
-
// (macOS bash 3.2), bash 3.2 and `bash --posix` all exit 1 with the guard
|
|
676
|
-
// unfired. Exit 1 out of THIS script means `the sha is not reachable`, the one
|
|
677
|
-
// distinction it exists to make. A missing file must never be able to say that.
|
|
678
|
-
test("a missing json.sh is exit 2, never the exit 1 that means `not reachable`", (t) => {
|
|
679
|
-
const w = repo(t);
|
|
680
|
-
const head = commit(w, "work");
|
|
681
|
-
git(w, "push", "-q", "origin", "main");
|
|
682
|
-
const lone = mkdtempSync(join(tmpdir(), "verify-sha-nolib-"));
|
|
683
|
-
t.after(() => rmSync(lone, { recursive: true, force: true }));
|
|
684
|
-
copyFileSync(SCRIPT, join(lone, "verify-sha.sh"));
|
|
685
|
-
|
|
686
|
-
const r = spawnSync("sh", [join(lone, "verify-sha.sh"), "main", head], { cwd: w, env: ENV, encoding: "utf8" });
|
|
687
|
-
|
|
688
|
-
assert.equal(r.status, 2,
|
|
689
|
-
"a missing library is `the question could not be answered`. Exit 1 would report a sha that IS on the branch as missing from it, and the controller would reject a PR that is exactly where it claims to be.");
|
|
690
|
-
assert.match(r.stderr, /json\.sh/, "and it names the file rather than blaming the fetch or the ref");
|
|
691
|
-
assert.equal(r.stdout, "", "no payload: nothing was answered");
|
|
692
|
-
});
|