@feigi/fleet-ctl 3.23.36 → 3.23.38
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/cell-readout.mjs +38 -11
- 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,1408 +0,0 @@
|
|
|
1
|
-
// Regression gate for worktree-audit.sh, the read-only report run before
|
|
2
|
-
// dispatching a replacement for a killed member. Zero deps:
|
|
3
|
-
// `node --test plugin/scripts/worktree-audit.test.mjs`.
|
|
4
|
-
//
|
|
5
|
-
// Three states, never two: present-and-readable (real counts), established
|
|
6
|
-
// absent (zero counts — a measurement), unknown (null counts, readable:false).
|
|
7
|
-
// Every negative case here asserts the SPECIFIC state, not merely
|
|
8
|
-
// readable:false — a fix that collapses "gone" and "unknown" into one
|
|
9
|
-
// direction is as broken as the bug it replaces (#82, #128).
|
|
10
|
-
|
|
11
|
-
import { test } from "node:test";
|
|
12
|
-
import assert from "node:assert/strict";
|
|
13
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
14
|
-
import { chmodSync, copyFileSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, symlinkSync, mkdirSync, writeFileSync } from "node:fs";
|
|
15
|
-
import { tmpdir } from "node:os";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import { fileURLToPath } from "node:url";
|
|
18
|
-
import { writeExecStub } from "./exec-stub.mjs";
|
|
19
|
-
|
|
20
|
-
const SCRIPT = fileURLToPath(new URL("./worktree-audit.sh", import.meta.url));
|
|
21
|
-
|
|
22
|
-
// Same identity pin as reap.test.mjs / release-ticket.test.mjs, for the same
|
|
23
|
-
// reason: cut the developer's ~/.gitconfig and any ambient GIT_DIR out of
|
|
24
|
-
// what these fixtures see.
|
|
25
|
-
const ENV = {
|
|
26
|
-
...process.env,
|
|
27
|
-
// Every `sh $SCRIPT` invocation below inherits the script's own
|
|
28
|
-
// `export LC_ALL=C` (worktree-audit.sh) regardless of what ENV carries —
|
|
29
|
-
// but the two direct `awk` calls in the C-quote-escape test bypass the
|
|
30
|
-
// script and its export entirely, so the pin has to live here. Without it,
|
|
31
|
-
// gawk under an ambient UTF-8 locale (CI's default) double-encodes the
|
|
32
|
-
// `\303\251` octal escape instead of decoding it to a single byte.
|
|
33
|
-
LC_ALL: "C",
|
|
34
|
-
BASE_REF: undefined,
|
|
35
|
-
GIT_DIR: undefined,
|
|
36
|
-
GIT_WORK_TREE: undefined,
|
|
37
|
-
GIT_TEMPLATE_DIR: undefined,
|
|
38
|
-
GIT_INDEX_FILE: undefined,
|
|
39
|
-
GIT_AUTHOR_NAME: "t",
|
|
40
|
-
GIT_AUTHOR_EMAIL: "t@example.com",
|
|
41
|
-
GIT_COMMITTER_NAME: "t",
|
|
42
|
-
GIT_COMMITTER_EMAIL: "t@example.com",
|
|
43
|
-
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
44
|
-
GIT_CONFIG_SYSTEM: "/dev/null",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const git = (cwd, ...args) =>
|
|
48
|
-
execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
|
|
49
|
-
|
|
50
|
-
const commit = (w, msg) => {
|
|
51
|
-
git(w, "commit", "-q", "--allow-empty", "-m", msg);
|
|
52
|
-
return git(w, "rev-parse", "HEAD");
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/** Bare origin + working clone with one commit on main. Returns the clone dir. */
|
|
56
|
-
function repo(t, dir = "w") {
|
|
57
|
-
// realpathSync: macOS resolves /var through /private, so a path built from
|
|
58
|
-
// the raw mkdtemp result would never string-equal what git itself reports
|
|
59
|
-
// (git canonicalises). Resolving once here, before any other path is
|
|
60
|
-
// derived from it, is what lets every assertion below use exact equality
|
|
61
|
-
// instead of a fragile `.endsWith` on every entry.
|
|
62
|
-
const root = realpathSync(mkdtempSync(join(tmpdir(), "worktree-audit-")));
|
|
63
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
64
|
-
const origin = join(root, "origin.git");
|
|
65
|
-
const w = join(root, dir);
|
|
66
|
-
execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
|
|
67
|
-
execFileSync("git", ["clone", "-q", origin, w], { env: ENV });
|
|
68
|
-
commit(w, "root");
|
|
69
|
-
git(w, "branch", "-M", "main");
|
|
70
|
-
git(w, "push", "-q", "-u", "origin", "main");
|
|
71
|
-
return w;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** A linked worktree on a fresh branch off origin/main, under .worktrees/. */
|
|
75
|
-
function addWorktree(w, name, base = "origin/main") {
|
|
76
|
-
const wt = join(w, ".worktrees", name);
|
|
77
|
-
git(w, "worktree", "add", "-q", wt, "-b", name, base);
|
|
78
|
-
return wt;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Re-point the registration for `wt` at `dest` and take the real directory away.
|
|
83
|
-
*
|
|
84
|
-
* `git worktree list --porcelain` derives the worktree path from the entry's
|
|
85
|
-
* `gitdir` file, so rewriting that file is how a fixture gets git to name a
|
|
86
|
-
* path whose FIRST component under `/` does not exist — the one shape
|
|
87
|
-
* `git worktree add` cannot produce, since it has to create the directory. In
|
|
88
|
-
* production this is the hand-added worktree outside the checkout whose
|
|
89
|
-
* ancestor chain was removed (`git worktree add /scratch/wt`, then
|
|
90
|
-
* `rm -rf /scratch`). The registry entry itself survives, so any
|
|
91
|
-
* listed-vs-registered count stays balanced.
|
|
92
|
-
*/
|
|
93
|
-
function relocate(w, wt, dest) {
|
|
94
|
-
const admin = join(w, ".git", "worktrees");
|
|
95
|
-
// realpathSync: git canonicalises what it writes into `gitdir`, and on macOS
|
|
96
|
-
// a tmpdir path reaches this suite as /var/... while git recorded
|
|
97
|
-
// /private/var/... — the scan matches nothing without resolving first.
|
|
98
|
-
const target = join(realpathSync(wt), ".git");
|
|
99
|
-
const name = readdirSync(admin).find(
|
|
100
|
-
(n) => readFileSync(join(admin, n, "gitdir"), "utf8").trim() === target,
|
|
101
|
-
);
|
|
102
|
-
assert.ok(name, `fixture: no registry entry points at ${wt}`);
|
|
103
|
-
writeFileSync(join(admin, name, "gitdir"), `${dest}/.git\n`);
|
|
104
|
-
rmSync(wt, { recursive: true, force: true });
|
|
105
|
-
return dest;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// `env` overrides ENV's scrub for the two #1020 cases below and nothing else:
|
|
109
|
-
// ENV deletes GIT_DIR and GIT_WORK_TREE for every fixture in this file, so a
|
|
110
|
-
// suite run under a poisoned environment cannot go vacuous, and the only way
|
|
111
|
-
// to exercise the path that scrub makes unreachable is to opt one case back in.
|
|
112
|
-
function runAudit(cwd, { env = {} } = {}) {
|
|
113
|
-
const r = spawnSync("sh", [SCRIPT], { cwd, env: { ...ENV, ...env }, encoding: "utf8" });
|
|
114
|
-
return { code: r.status, json: r.stdout.trim() ? JSON.parse(r.stdout) : null, stderr: r.stderr };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** The one entry in the payload for this exact worktree path. */
|
|
118
|
-
function entryFor(json, wt) {
|
|
119
|
-
const e = json.find((x) => x.worktree === wt);
|
|
120
|
-
assert.ok(e, `no entry for ${wt} in ${JSON.stringify(json)}`);
|
|
121
|
-
return e;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
test("a clean readable worktree ahead of base is reported with real counts", (t) => {
|
|
125
|
-
const w = repo(t);
|
|
126
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
127
|
-
commit(wt, "work");
|
|
128
|
-
|
|
129
|
-
const { code, json, stderr } = runAudit(w);
|
|
130
|
-
assert.equal(code, 0);
|
|
131
|
-
const e = entryFor(json, wt);
|
|
132
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: 1, dirty: 0, dirtyFiles: [], readable: true });
|
|
133
|
-
assert.doesNotMatch(stderr, /UNREADABLE|MISSING/);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// A stopped rebase or bisect DETACHES HEAD, so `git worktree list` gives the
|
|
137
|
-
// worktree a `detached` record instead of its branch — yet the branch is still
|
|
138
|
-
// that worktree's, with commits `origin/main` does not have, and HEAD has
|
|
139
|
-
// moved to wherever the operation took it. Counting `ahead` from HEAD alone
|
|
140
|
-
// read such a worktree as `DETACHED, ahead:0, dirty:0`: the "nothing here"
|
|
141
|
-
// row. The branch comes back through worktree.sh's `wt_op_state` (#2218). #2220
|
|
142
|
-
|
|
143
|
-
/** Run `git rebase -i <onto>` in `wt`, with its todo list piped through the sh filter `filter` (reads the todo on stdin, writes the new todo on stdout). */
|
|
144
|
-
function rebaseStopped(wt, onto, filter) {
|
|
145
|
-
const editor = join(wt, "..", "seq-editor.sh");
|
|
146
|
-
writeFileSync(editor, `${filter} < "$1" > "$1.t" && mv "$1.t" "$1"\n`);
|
|
147
|
-
execFileSync("git", ["rebase", "-q", "-i", onto], {
|
|
148
|
-
cwd: wt,
|
|
149
|
-
env: { ...ENV, GIT_SEQUENCE_EDITOR: `sh ${editor}` },
|
|
150
|
-
stdio: "pipe",
|
|
151
|
-
});
|
|
152
|
-
rmSync(editor);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
test("a worktree stopped mid-bisect is reported under the branch it holds, and its unpushed commits are counted (#2220)", (t) => {
|
|
156
|
-
const w = repo(t);
|
|
157
|
-
for (let i = 1; i <= 5; i++) commit(w, `main ${i}`);
|
|
158
|
-
git(w, "push", "-q", "origin", "main");
|
|
159
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
160
|
-
commit(wt, "work 1");
|
|
161
|
-
commit(wt, "work 2");
|
|
162
|
-
git(wt, "bisect", "start", "HEAD", "HEAD~7");
|
|
163
|
-
assert.equal(git(wt, "rev-list", "--count", "origin/main..HEAD"), "0",
|
|
164
|
-
"fixture: the bisect must have moved HEAD onto a commit origin/main already has");
|
|
165
|
-
|
|
166
|
-
const { code, json, stderr } = runAudit(w);
|
|
167
|
-
assert.equal(code, 0);
|
|
168
|
-
assert.deepEqual(entryFor(json, wt),
|
|
169
|
-
{ worktree: wt, branch: "fix/9-x", ahead: 2, dirty: 0, dirtyFiles: [], readable: true });
|
|
170
|
-
assert.match(stderr, /branch=fix\/9-x .*mid-bisect/, "the operator is told why HEAD and branch differ");
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("a worktree mid-`rebase -i`, stopped before any pick, is reported under its branch with the branch's commits (#2220)", (t) => {
|
|
174
|
-
const w = repo(t);
|
|
175
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
176
|
-
commit(wt, "work 1");
|
|
177
|
-
commit(wt, "work 2");
|
|
178
|
-
rebaseStopped(wt, "origin/main", `{ echo break; cat; }`);
|
|
179
|
-
assert.equal(git(wt, "rev-list", "--count", "origin/main..HEAD"), "0",
|
|
180
|
-
"fixture: the rebase must be stopped at `onto`, before any pick");
|
|
181
|
-
|
|
182
|
-
const { code, json, stderr } = runAudit(w);
|
|
183
|
-
assert.equal(code, 0);
|
|
184
|
-
assert.deepEqual(entryFor(json, wt),
|
|
185
|
-
{ worktree: wt, branch: "fix/9-x", ahead: 2, dirty: 0, dirtyFiles: [], readable: true });
|
|
186
|
-
assert.match(stderr, /branch=fix\/9-x .*mid-rebase/, "the operator is told why HEAD and branch differ");
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test("a worktree mid-rebase after a pick counts the branch's originals AND the replayed commit, not HEAD alone (#2220)", (t) => {
|
|
190
|
-
const w = repo(t);
|
|
191
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
192
|
-
commit(wt, "work 1");
|
|
193
|
-
commit(wt, "work 2");
|
|
194
|
-
// origin/main moves on, so the replayed pick is a NEW commit — neither
|
|
195
|
-
// reachable from the branch nor from the base.
|
|
196
|
-
commit(w, "main 1");
|
|
197
|
-
git(w, "push", "-q", "origin", "main");
|
|
198
|
-
rebaseStopped(wt, "origin/main", `awk 'NR==1{print; print "break"; next} {print}'`);
|
|
199
|
-
assert.equal(git(wt, "rev-list", "--count", "origin/main..HEAD"), "1",
|
|
200
|
-
"fixture: the rebase must be stopped after exactly one replayed pick");
|
|
201
|
-
|
|
202
|
-
const { code, json } = runAudit(w);
|
|
203
|
-
assert.equal(code, 0);
|
|
204
|
-
assert.deepEqual(entryFor(json, wt),
|
|
205
|
-
{ worktree: wt, branch: "fix/9-x", ahead: 3, dirty: 0, dirtyFiles: [], readable: true },
|
|
206
|
-
"two originals on the branch plus one replayed commit on HEAD");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test("a worktree with a rebase stopped AND a bisect started on top of it is not misnamed as one or the other (#2220)", (t) => {
|
|
210
|
-
// `wt_op` (#2218) is the LAST admin marker found, so a compound worktree —
|
|
211
|
-
// rebase-merge present from the stop, BISECT_LOG/BISECT_START present from
|
|
212
|
-
// a bisect started on the resulting detached HEAD — reads `wt_op=BISECT_LOG`
|
|
213
|
-
// even though the branch this row actually counts against came from the
|
|
214
|
-
// rebase, not the bisect. The JSON stays correct either way (`held` is
|
|
215
|
-
// filtered independently of `wt_op`); only a note keyed on `wt_op` alone
|
|
216
|
-
// would misname the operation.
|
|
217
|
-
const w = repo(t);
|
|
218
|
-
commit(w, "main 1");
|
|
219
|
-
commit(w, "main 2");
|
|
220
|
-
git(w, "push", "-q", "origin", "main");
|
|
221
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
222
|
-
commit(wt, "work 1");
|
|
223
|
-
rebaseStopped(wt, "origin/main", `{ echo break; cat; }`);
|
|
224
|
-
git(wt, "bisect", "start", "HEAD", "HEAD~1");
|
|
225
|
-
|
|
226
|
-
const { code, json, stderr } = runAudit(w);
|
|
227
|
-
assert.equal(code, 0);
|
|
228
|
-
assert.deepEqual(entryFor(json, wt),
|
|
229
|
-
{ worktree: wt, branch: "fix/9-x", ahead: 1, dirty: 0, dirtyFiles: [], readable: true },
|
|
230
|
-
"the branch and count still come from the rebase-held ref, unaffected by the bisect on top");
|
|
231
|
-
assert.doesNotMatch(stderr, /mid-bisect/,
|
|
232
|
-
"the held branch came from the rebase, not the bisect that ran on top of it");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("a real branch literally named as the hex SHA it resolves to is still counted, not dropped as a phantom self-reference (#2220)", (t) => {
|
|
236
|
-
// op_held()'s bisect-from-detached-HEAD filter drops an entry whose
|
|
237
|
-
// resolved commit SHA equals its own ref-name suffix — that is how it
|
|
238
|
-
// recognizes `BISECT_START`'s raw SHA reread as `refs/heads/<sha>` (#2218),
|
|
239
|
-
// which names no real ref. The same string match also fires for a REAL
|
|
240
|
-
// branch that happens to be named after the hex SHA it resolves to; the
|
|
241
|
-
// fix must tell them apart by whether `refs/heads/<name>` itself resolves,
|
|
242
|
-
// not by the coincidence alone.
|
|
243
|
-
const w = repo(t);
|
|
244
|
-
const wt = addWorktree(w, "tempname");
|
|
245
|
-
commit(wt, "work 1");
|
|
246
|
-
const tip = commit(wt, "work 2");
|
|
247
|
-
git(wt, "branch", "-m", "tempname", tip);
|
|
248
|
-
rebaseStopped(wt, "origin/main", `{ echo break; cat; }`);
|
|
249
|
-
|
|
250
|
-
const { code, json, stderr } = runAudit(w);
|
|
251
|
-
assert.equal(code, 0);
|
|
252
|
-
assert.deepEqual(entryFor(json, wt),
|
|
253
|
-
{ worktree: wt, branch: tip, ahead: 2, dirty: 0, dirtyFiles: [], readable: true },
|
|
254
|
-
"a real branch named as its own SHA must still be counted, not dropped as a phantom self-reference");
|
|
255
|
-
assert.match(stderr, /mid-rebase/);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test("a plain detached worktree, and one bisecting from a detached HEAD, still read DETACHED with HEAD's own count (#2220)", (t) => {
|
|
259
|
-
// The accept side: no rebase or bisect holds a branch here, so nothing may
|
|
260
|
-
// be relabelled, and nothing may be refused as unreadable. A bisect started
|
|
261
|
-
// from a detached HEAD writes that HEAD's SHA into BISECT_START, which
|
|
262
|
-
// `wt_op_state` still hands back as `refs/heads/<sha>` — a branch that never
|
|
263
|
-
// existed, and not one this row may go unreadable over.
|
|
264
|
-
const w = repo(t);
|
|
265
|
-
const plain = join(w, ".worktrees", "plain");
|
|
266
|
-
git(w, "worktree", "add", "-q", "--detach", plain, "origin/main");
|
|
267
|
-
commit(plain, "detached work");
|
|
268
|
-
const bisecting = join(w, ".worktrees", "bisecting");
|
|
269
|
-
git(w, "worktree", "add", "-q", "--detach", bisecting, "origin/main");
|
|
270
|
-
commit(bisecting, "detached work 1");
|
|
271
|
-
commit(bisecting, "detached work 2");
|
|
272
|
-
git(bisecting, "bisect", "start", "HEAD", "HEAD~2");
|
|
273
|
-
|
|
274
|
-
const { code, json, stderr } = runAudit(w);
|
|
275
|
-
assert.equal(code, 0);
|
|
276
|
-
assert.deepEqual(entryFor(json, plain),
|
|
277
|
-
{ worktree: plain, branch: "DETACHED", ahead: 1, dirty: 0, dirtyFiles: [], readable: true });
|
|
278
|
-
assert.deepEqual(entryFor(json, bisecting),
|
|
279
|
-
{ worktree: bisecting, branch: "DETACHED", ahead: 1, dirty: 0, dirtyFiles: [], readable: true });
|
|
280
|
-
assert.doesNotMatch(stderr, /UNREADABLE|mid-rebase|mid-bisect/);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test("a held branch whose ref no longer resolves is unreadable, never ahead:0 (#2220)", (t) => {
|
|
284
|
-
const w = repo(t);
|
|
285
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
286
|
-
commit(wt, "work 1");
|
|
287
|
-
git(wt, "bisect", "start", "HEAD", "HEAD~1");
|
|
288
|
-
git(wt, "checkout", "-q", "--detach", "origin/main");
|
|
289
|
-
// `branch -D` refuses a branch a bisect holds; `update-ref -d` is the
|
|
290
|
-
// route that does not ask.
|
|
291
|
-
git(w, "update-ref", "-d", "refs/heads/fix/9-x");
|
|
292
|
-
|
|
293
|
-
const { code, json, stderr } = runAudit(w);
|
|
294
|
-
assert.equal(code, 0);
|
|
295
|
-
const e = entryFor(json, wt);
|
|
296
|
-
assert.equal(e.readable, false);
|
|
297
|
-
assert.equal(e.ahead, null);
|
|
298
|
-
assert.equal(e.dirty, null);
|
|
299
|
-
assert.match(stderr, /UNREADABLE: /);
|
|
300
|
-
assert.doesNotMatch(stderr, /mid-bisect|mid-rebase/,
|
|
301
|
-
"a row whose count failed must not still claim which operation the count covered");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
test("a detached worktree whose admin dir cannot be read is unknown, with the #2220 reason, not the generic no-linkage one (#2220)", (t) => {
|
|
305
|
-
// op_held()'s own `wt_op_state "$wt" || return 1` is the only thing that
|
|
306
|
-
// turns a git failure reading the admin dir into this specific message.
|
|
307
|
-
// Unlike the "no .git linkage" guard above it (an ABSENT `.git`), this is
|
|
308
|
-
// an UNREADABLE one: the pointer file is there, `-f` sees it, but nothing
|
|
309
|
-
// downstream can open it. `wt_op_state` asks git FROM `$wt`
|
|
310
|
-
// (`rev-parse --absolute-git-dir`), which needs to read that same file.
|
|
311
|
-
const w = repo(t);
|
|
312
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
313
|
-
commit(wt, "work 1");
|
|
314
|
-
git(wt, "checkout", "-q", "--detach", "origin/main");
|
|
315
|
-
const gitFile = join(wt, ".git");
|
|
316
|
-
chmodSync(gitFile, 0o000);
|
|
317
|
-
const { code, json, stderr } = runAudit(w);
|
|
318
|
-
chmodSync(gitFile, 0o644);
|
|
319
|
-
|
|
320
|
-
assert.equal(code, 0);
|
|
321
|
-
const e = entryFor(json, wt);
|
|
322
|
-
assert.equal(e.readable, false);
|
|
323
|
-
assert.equal(e.ahead, null);
|
|
324
|
-
assert.equal(e.dirty, null);
|
|
325
|
-
assert.match(stderr, /UNREADABLE: .*cannot read its admin dir/);
|
|
326
|
-
assert.doesNotMatch(stderr, /no \.git linkage/,
|
|
327
|
-
"an unreadable .git is not the same defect as a missing one");
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
test("a local ref shadowing `origin/main` does not read the ahead count as 0 (#1329)", (t) => {
|
|
331
|
-
// release-ticket.sh (#1320) already measured this class: `origin/main` is a
|
|
332
|
-
// SHORTHAND, and git resolves a shorthand through its own disambiguation
|
|
333
|
-
// order (gitrevisions: refs/<name>, refs/tags/<name>, refs/heads/<name>,
|
|
334
|
-
// refs/remotes/<name>, …), in which refs/remotes/origin/main comes LAST. A
|
|
335
|
-
// local TAG literally named `origin/main` outranks the real remote-tracking
|
|
336
|
-
// branch, so `rev-list --count "$base"..HEAD` against the bare shorthand
|
|
337
|
-
// answers about the tag's target instead — silently, at rc 0, with nothing
|
|
338
|
-
// on stderr distinguishing it from a genuinely clean worktree. This script's
|
|
339
|
-
// own header comment (#82, #128) says an ahead:0/dirty:0 entry tells the fleet
|
|
340
|
-
// controller "nothing here", so a wrong 0 is not just an inaccurate number,
|
|
341
|
-
// it is a false "safe to discard" for a worktree that genuinely carries
|
|
342
|
-
// unpushed work.
|
|
343
|
-
const w = repo(t);
|
|
344
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
345
|
-
commit(wt, "work that exists nowhere else");
|
|
346
|
-
|
|
347
|
-
// Pointed at the worktree's own tip, the cheapest way to plant a colliding
|
|
348
|
-
// ref that makes the bare shorthand resolve to a commit already equal to
|
|
349
|
-
// HEAD — the shape that reads `ahead: 0` if the measurement is not
|
|
350
|
-
// requalified.
|
|
351
|
-
git(w, "tag", "origin/main", "refs/heads/fix/9-x");
|
|
352
|
-
assert.equal(
|
|
353
|
-
git(w, "rev-parse", "origin/main"),
|
|
354
|
-
git(w, "rev-parse", "refs/heads/fix/9-x"),
|
|
355
|
-
"fixture: the shorthand now resolves to the worktree's own tip",
|
|
356
|
-
);
|
|
357
|
-
assert.notEqual(
|
|
358
|
-
git(w, "rev-parse", "refs/remotes/origin/main"),
|
|
359
|
-
git(w, "rev-parse", "refs/heads/fix/9-x"),
|
|
360
|
-
"fixture: the real upstream is still a different, older commit",
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
const { code, json, stderr } = runAudit(w);
|
|
364
|
-
assert.equal(code, 0);
|
|
365
|
-
const e = entryFor(json, wt);
|
|
366
|
-
assert.equal(e.ahead, 1, "must measure against refs/remotes/origin/main, not the shadowing tag");
|
|
367
|
-
assert.doesNotMatch(stderr, /UNREADABLE|MISSING/);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
test("BASE_REF already qualified as refs/remotes/<name> is used as-is, not double-prefixed (#1329)", (t) => {
|
|
371
|
-
// The qualify step's `refs/remotes/*) base_rev=$base;;` arm exists to avoid
|
|
372
|
-
// turning an already-qualified BASE_REF into the nonsense
|
|
373
|
-
// `refs/remotes/refs/remotes/origin/main`. Nothing above this test ever set
|
|
374
|
-
// BASE_REF to a refs/remotes/-qualified value, so this arm ran on every
|
|
375
|
-
// fixture only by falling through the OTHER arm never firing — a bug that
|
|
376
|
-
// silently double-prefixed here would still show every other test green.
|
|
377
|
-
const w = repo(t);
|
|
378
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
379
|
-
commit(wt, "work that exists nowhere else");
|
|
380
|
-
|
|
381
|
-
const { code, json, stderr } = runAudit(w, { env: { BASE_REF: "refs/remotes/origin/main" } });
|
|
382
|
-
assert.equal(code, 0);
|
|
383
|
-
const e = entryFor(json, wt);
|
|
384
|
-
assert.equal(e.ahead, 1, "an already-qualified BASE_REF must resolve, not be rejected or double-prefixed");
|
|
385
|
-
assert.doesNotMatch(stderr, /UNREADABLE|MISSING/);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
test("BASE_REF spelled outside the remote-tracking namespace is refused, not silently mis-qualified (#1329)", (t) => {
|
|
389
|
-
// Before the accept-list, the qualify step below unconditionally prepended
|
|
390
|
-
// `refs/remotes/` to whatever BASE_REF was. A caller-supplied `refs/heads/
|
|
391
|
-
// main` — a shape sibling scripts (reap.sh, release-ticket.sh) also reject —
|
|
392
|
-
// turned into `refs/remotes/refs/heads/main`, which resolves nowhere, and
|
|
393
|
-
// the die message named the ORIGINAL `refs/heads/main` as "does not
|
|
394
|
-
// resolve" even though `refs/heads/main` itself resolves fine — the
|
|
395
|
-
// qualification this script chose to make was the actual cause, misspelled
|
|
396
|
-
// as a bad guess by the caller. The accept-list turns that into a refusal
|
|
397
|
-
// naming the real constraint before the qualify step ever runs.
|
|
398
|
-
const w = repo(t);
|
|
399
|
-
addWorktree(w, "fix/9-x");
|
|
400
|
-
|
|
401
|
-
const { code, json, stderr } = runAudit(w, { env: { BASE_REF: "refs/heads/main" } });
|
|
402
|
-
assert.equal(code, 2);
|
|
403
|
-
assert.equal(json, null);
|
|
404
|
-
assert.match(stderr, /BASE_REF must be a remote-tracking ref, got 'refs\/heads\/main'/);
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
test("a dirty worktree lists its dirty files and their count", (t) => {
|
|
408
|
-
const w = repo(t);
|
|
409
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
410
|
-
writeFileSync(join(wt, "scratch.txt"), "uncommitted\n");
|
|
411
|
-
|
|
412
|
-
const { json } = runAudit(w);
|
|
413
|
-
const e = entryFor(json, wt);
|
|
414
|
-
assert.equal(e.readable, true);
|
|
415
|
-
assert.equal(e.dirty, 1);
|
|
416
|
-
assert.deepEqual(e.dirtyFiles, ["scratch.txt"]);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
// #730 (see reap.sh's branch sweep for the full explanation) — a bare
|
|
420
|
-
// `--porcelain` reads `dirty: 0, dirtyFiles: []` over a dirty tree under
|
|
421
|
-
// `status.showUntrackedFiles = no`. This report is what a fleet controller
|
|
422
|
-
// reads to decide whether a replacement member would REDO work or DESTROY
|
|
423
|
-
// it, so a false clean here misinforms exactly the decision the audit
|
|
424
|
-
// exists to inform.
|
|
425
|
-
test("a dirty worktree is still reported dirty under status.showUntrackedFiles=no (#730)", (t) => {
|
|
426
|
-
const w = repo(t);
|
|
427
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
428
|
-
writeFileSync(join(wt, "scratch.txt"), "uncommitted\n");
|
|
429
|
-
git(w, "config", "status.showUntrackedFiles", "no");
|
|
430
|
-
// The fixture's own positive control: without it a git that stopped honouring
|
|
431
|
-
// the config would leave this test green while pinning nothing.
|
|
432
|
-
assert.equal(git(wt, "status", "--porcelain"), "",
|
|
433
|
-
"fixture: the config must really silence the unpinned probe, or this test measures nothing");
|
|
434
|
-
|
|
435
|
-
const { json } = runAudit(w);
|
|
436
|
-
const e = entryFor(json, wt);
|
|
437
|
-
// `readable: true` alongside the count: a fix that turned the silenced answer
|
|
438
|
-
// into an UNKNOWN would also stop reporting 0, and unknown is a different —
|
|
439
|
-
// and here wrong — verdict about a worktree git answered for perfectly well.
|
|
440
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: 0, dirty: 1, dirtyFiles: ["scratch.txt"], readable: true });
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// `-uall`, not `-unormal`: proves the granularity `-uall` buys is real, not
|
|
444
|
-
// just asserted in the script's comment. An untracked file inside an
|
|
445
|
-
// untracked SUBDIRECTORY is named on its own line — `-unormal` would
|
|
446
|
-
// collapse it to one entry for the directory (`sub/`), which is what
|
|
447
|
-
// reap.sh's `--ignored` reason-string probe switched to, same PR, because
|
|
448
|
-
// nothing downstream there reads per-file detail. Here something does:
|
|
449
|
-
// `dirtyFiles[]` is what a fleet controller reads to decide REDO vs DESTROY.
|
|
450
|
-
test("a dirty file inside an untracked subdirectory is named, not collapsed to the directory", (t) => {
|
|
451
|
-
const w = repo(t);
|
|
452
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
453
|
-
mkdirSync(join(wt, "sub"));
|
|
454
|
-
writeFileSync(join(wt, "sub", "deep.txt"), "uncommitted\n");
|
|
455
|
-
|
|
456
|
-
const { json } = runAudit(w);
|
|
457
|
-
const e = entryFor(json, wt);
|
|
458
|
-
assert.deepEqual(e.dirtyFiles, ["sub/deep.txt"]);
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
test("a dirty file whose own name holds a space is not truncated", (t) => {
|
|
462
|
-
// Porcelain v1 is "XY<space>PATH" — always three bytes before the path, so
|
|
463
|
-
// the fourth byte on is the whole rest of the line. Reading it as awk's $2
|
|
464
|
-
// stops at the file's own internal space and reports "a" for "a b.txt".
|
|
465
|
-
const w = repo(t);
|
|
466
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
467
|
-
writeFileSync(join(wt, "a b.txt"), "uncommitted\n");
|
|
468
|
-
|
|
469
|
-
const { json } = runAudit(w);
|
|
470
|
-
const e = entryFor(json, wt);
|
|
471
|
-
assert.deepEqual(e.dirtyFiles, ["a b.txt"]);
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
test("a staged rename reports its destination and leaves the payload parseable", (t) => {
|
|
475
|
-
// git prints a rename as `R <src> -> <dst>` and C-quotes either half on its
|
|
476
|
-
// own whenever it holds a space. Reading the whole line as one path wrapped
|
|
477
|
-
// the quotes git had already added inside a second pair, and the ONE bad
|
|
478
|
-
// element made the entire array unparseable — every other worktree entry
|
|
479
|
-
// destroyed with it, which is why this asserts the sibling entry too and why
|
|
480
|
-
// runAudit's JSON.parse of the full payload is the real gate here.
|
|
481
|
-
// `a -> b.txt` pins the split itself: gating on the literal " -> " instead of
|
|
482
|
-
// on the R status byte cuts that source name in half mid-path.
|
|
483
|
-
//
|
|
484
|
-
// The third rename, into a tab-holding destination, is the #617 interaction
|
|
485
|
-
// (survived-finding-adjacent suggestion 1): `jesc` runs on `p` unconditionally
|
|
486
|
-
// at the print below, rename or not, so a destination needing real escape
|
|
487
|
-
// translation (not just quote-stripping around a bare space) must round-trip
|
|
488
|
-
// through the rename-split path too.
|
|
489
|
-
const w = repo(t);
|
|
490
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
491
|
-
writeFileSync(join(wt, "old.txt"), "x\n");
|
|
492
|
-
writeFileSync(join(wt, "a -> b.txt"), "x\n");
|
|
493
|
-
writeFileSync(join(wt, "third.txt"), "x\n");
|
|
494
|
-
git(wt, "add", "-A");
|
|
495
|
-
commit(wt, "files to rename");
|
|
496
|
-
git(wt, "mv", "old.txt", "new name.txt");
|
|
497
|
-
git(wt, "mv", "a -> b.txt", "c.txt");
|
|
498
|
-
git(wt, "mv", "third.txt", "ta\tb2.txt");
|
|
499
|
-
|
|
500
|
-
const { code, json } = runAudit(w);
|
|
501
|
-
assert.equal(code, 0);
|
|
502
|
-
const e = entryFor(json, wt);
|
|
503
|
-
assert.equal(e.readable, true);
|
|
504
|
-
assert.equal(e.dirty, 3);
|
|
505
|
-
assert.deepEqual([...e.dirtyFiles].sort(), ["c.txt", "new name.txt", "ta\tb2.txt"].sort());
|
|
506
|
-
assert.equal(entryFor(json, w).readable, true);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
test("a genuinely deleted worktree is reported missing, with zero counts", (t) => {
|
|
510
|
-
const w = repo(t);
|
|
511
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
512
|
-
rmSync(wt, { recursive: true, force: true });
|
|
513
|
-
|
|
514
|
-
const { code, json, stderr } = runAudit(w);
|
|
515
|
-
assert.equal(code, 0);
|
|
516
|
-
const e = entryFor(json, wt);
|
|
517
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: 0, dirty: 0, dirtyFiles: [], readable: false });
|
|
518
|
-
assert.match(stderr, /MISSING on disk: .*fix\/9-x/);
|
|
519
|
-
assert.doesNotMatch(stderr, /UNREADABLE/);
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
test("a worktree behind an unreadable parent is unknown, never missing or clean", (t) => {
|
|
523
|
-
// Same worktree, holding real uncommitted work, is byte-identical to a
|
|
524
|
-
// deleted one under a bare `[ -d ]` test — the defect this script shipped
|
|
525
|
-
// with. `chmod 000` on the PARENT: the walk in `gone()` stops at the
|
|
526
|
-
// nearest ancestor that exists, so this is the ancestor that must read as
|
|
527
|
-
// unsearchable, not the worktree directory itself (which stays stat-able
|
|
528
|
-
// from outside were the parent readable).
|
|
529
|
-
if (process.getuid?.() === 0) return t.skip("root reads every directory");
|
|
530
|
-
const w = repo(t);
|
|
531
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
532
|
-
writeFileSync(join(wt, "precious.txt"), "work that exists nowhere else\n");
|
|
533
|
-
const parent = join(w, ".worktrees");
|
|
534
|
-
|
|
535
|
-
chmodSync(parent, 0o000);
|
|
536
|
-
const { code, json, stderr } = runAudit(w);
|
|
537
|
-
chmodSync(parent, 0o755);
|
|
538
|
-
|
|
539
|
-
assert.equal(code, 0);
|
|
540
|
-
const e = entryFor(json, wt);
|
|
541
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: null, dirty: null, dirtyFiles: [], readable: false });
|
|
542
|
-
assert.match(stderr, /UNREADABLE: .*ancestor could not be read/);
|
|
543
|
-
assert.doesNotMatch(stderr, /MISSING/);
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
test("a worktree with no surviving ancestor below / is MISSING, never unknown (#178)", (t) => {
|
|
547
|
-
// The escalation of the case above: there the parent could not be SEARCHED,
|
|
548
|
-
// which is genuinely unknown. Here every ancestor below `/` is absent — but
|
|
549
|
-
// `${p%/*}` on `/x` yields the empty string rather than `/`, so the walk fell
|
|
550
|
-
// out on "" and `[ -x "" ]` answered unknown about a path that is provably
|
|
551
|
-
// absent with a searchable root. Reported as UNREADABLE it sends a debugger
|
|
552
|
-
// at permissions that are fine, and hides the entry a prune would clear.
|
|
553
|
-
const w = repo(t);
|
|
554
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
555
|
-
const dest = relocate(w, wt, "/nonexistent-top-level-178/wt");
|
|
556
|
-
|
|
557
|
-
const { code, json, stderr } = runAudit(w);
|
|
558
|
-
|
|
559
|
-
assert.equal(code, 0);
|
|
560
|
-
const e = entryFor(json, dest);
|
|
561
|
-
assert.deepEqual(e, { worktree: dest, branch: "fix/9-x", ahead: 0, dirty: 0, dirtyFiles: [], readable: false });
|
|
562
|
-
assert.match(stderr, /MISSING on disk: \/nonexistent-top-level-178\/wt/);
|
|
563
|
-
assert.doesNotMatch(stderr, /UNREADABLE/, "an absent path with a searchable root is not an unknown one");
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
test("a worktree whose .git file is gone is unknown, never clean", (t) => {
|
|
567
|
-
// The directory EXISTS (so -d is true) and `git -C` does not fail on a
|
|
568
|
-
// missing .git — it walks UP to the enclosing repo and answers about THAT
|
|
569
|
-
// at rc 0. `.worktrees/` gitignored and the parent clean makes the leaked
|
|
570
|
-
// answer empty: a positive assertion of clean, produced without ever having
|
|
571
|
-
// looked at the worktree.
|
|
572
|
-
const w = repo(t);
|
|
573
|
-
writeFileSync(join(w, ".gitignore"), ".worktrees/\n");
|
|
574
|
-
git(w, "add", ".gitignore");
|
|
575
|
-
git(w, "commit", "-q", "-m", "ignore the worktrees dir");
|
|
576
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
577
|
-
writeFileSync(join(wt, "precious.txt"), "work that exists nowhere else\n");
|
|
578
|
-
rmSync(join(wt, ".git"));
|
|
579
|
-
assert.equal(git(w, "status", "--porcelain"), "", "fixture: the leaked answer really is an empty one");
|
|
580
|
-
|
|
581
|
-
const { code, json, stderr } = runAudit(w);
|
|
582
|
-
assert.equal(code, 0);
|
|
583
|
-
const e = entryFor(json, wt);
|
|
584
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: null, dirty: null, dirtyFiles: [], readable: false });
|
|
585
|
-
assert.match(stderr, /UNREADABLE: .*no \.git linkage/);
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
test("a worktree whose .git is an empty directory is unknown, never clean", (t) => {
|
|
589
|
-
// Same leak, different shape: -e is true for a .git DIRECTORY too, so only
|
|
590
|
-
// -f (not -e) tells the two apart.
|
|
591
|
-
const w = repo(t);
|
|
592
|
-
writeFileSync(join(w, ".gitignore"), ".worktrees/\n");
|
|
593
|
-
git(w, "add", ".gitignore");
|
|
594
|
-
git(w, "commit", "-q", "-m", "ignore the worktrees dir");
|
|
595
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
596
|
-
rmSync(join(wt, ".git"));
|
|
597
|
-
mkdirSync(join(wt, ".git"));
|
|
598
|
-
|
|
599
|
-
const { json, stderr } = runAudit(w);
|
|
600
|
-
const e = entryFor(json, wt);
|
|
601
|
-
assert.equal(e.readable, false);
|
|
602
|
-
assert.equal(e.ahead, null);
|
|
603
|
-
assert.match(stderr, /UNREADABLE: .*no \.git linkage/);
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
test("a worktree whose .git is a dangling symlink is unknown, never clean", (t) => {
|
|
607
|
-
// The other shape a broken linkage takes, preferred here over another chmod
|
|
608
|
-
// fixture: -e is false through a dangling link exactly as it is for an
|
|
609
|
-
// absent file, so this exercises the same -f branch by construction rather
|
|
610
|
-
// than by permission bits.
|
|
611
|
-
const w = repo(t);
|
|
612
|
-
writeFileSync(join(w, ".gitignore"), ".worktrees/\n");
|
|
613
|
-
git(w, "add", ".gitignore");
|
|
614
|
-
git(w, "commit", "-q", "-m", "ignore the worktrees dir");
|
|
615
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
616
|
-
rmSync(join(wt, ".git"));
|
|
617
|
-
symlinkSync(join(wt, "nowhere"), join(wt, ".git"));
|
|
618
|
-
|
|
619
|
-
const { json, stderr } = runAudit(w);
|
|
620
|
-
const e = entryFor(json, wt);
|
|
621
|
-
assert.equal(e.readable, false);
|
|
622
|
-
assert.equal(e.ahead, null);
|
|
623
|
-
assert.match(stderr, /UNREADABLE: .*no \.git linkage/);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
test("a worktree path that is a file, not a directory, is unknown — and says so", (t) => {
|
|
627
|
-
// git still LISTS a registered worktree whose directory was replaced by a
|
|
628
|
-
// regular file, branch line and all, so this loop still sees it. `-d` is
|
|
629
|
-
// false and `gone()` is false (the path plainly exists), which lands it in
|
|
630
|
-
// the final else — whose reason blamed an ancestor that read fine. The
|
|
631
|
-
// state is right either way; the cause was not. Same class, measured: a
|
|
632
|
-
// symlink to a file and a FIFO land here too.
|
|
633
|
-
const w = repo(t);
|
|
634
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
635
|
-
rmSync(wt, { recursive: true, force: true });
|
|
636
|
-
writeFileSync(wt, "not a directory\n");
|
|
637
|
-
|
|
638
|
-
const { code, json, stderr } = runAudit(w);
|
|
639
|
-
assert.equal(code, 0);
|
|
640
|
-
const e = entryFor(json, wt);
|
|
641
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/9-x", ahead: null, dirty: null, dirtyFiles: [], readable: false });
|
|
642
|
-
assert.match(stderr, /UNREADABLE: .*exists but is not a directory/);
|
|
643
|
-
assert.doesNotMatch(stderr, /ancestor could not be read/, "no ancestor failed to read here");
|
|
644
|
-
assert.doesNotMatch(stderr, /MISSING/, "the path is plainly there — this is unknown, not absent");
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
test("a repo path containing a space does not truncate the worktree it reads", (t) => {
|
|
648
|
-
const w = repo(t, "my repos");
|
|
649
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
650
|
-
writeFileSync(join(wt, "scratch.txt"), "uncommitted\n");
|
|
651
|
-
|
|
652
|
-
const { json } = runAudit(w);
|
|
653
|
-
const match = json.find((x) => x.worktree.endsWith("/my repos/.worktrees/fix/9-x"));
|
|
654
|
-
assert.ok(match, `no untruncated entry in ${JSON.stringify(json)}`);
|
|
655
|
-
assert.equal(match.readable, true);
|
|
656
|
-
assert.equal(match.dirty, 1);
|
|
657
|
-
assert.deepEqual(match.dirtyFiles, ["scratch.txt"]);
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
/** The design spec's script-surface row for this script, as one line. */
|
|
661
|
-
function specRow() {
|
|
662
|
-
const spec = readFileSync(
|
|
663
|
-
fileURLToPath(new URL("../../docs/specs/2026-07-23-fleet-plugin-design.md", import.meta.url)),
|
|
664
|
-
"utf8",
|
|
665
|
-
);
|
|
666
|
-
const row = spec.split("\n").find((l) => l.startsWith("| `worktree-audit.sh` |"));
|
|
667
|
-
assert.ok(row, "the script-surface table must still carry a worktree-audit.sh row");
|
|
668
|
-
return row;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// Sibling pin, same table, same reason: no-undo-audit.test.mjs. The design
|
|
672
|
-
// spec's script-surface row for this script named `commits` — a field that has
|
|
673
|
-
// never existed — and typed `dirty` as an array when it is a count, so a caller
|
|
674
|
-
// reading `.dirty[0]` off the table got a number-index on an integer (#48).
|
|
675
|
-
// Derived from a real run, never from a hand-written key list: a list typed
|
|
676
|
-
// here drifts from the script exactly the way the table did.
|
|
677
|
-
test("the design spec's script-surface row names every field the payload actually emits", (t) => {
|
|
678
|
-
const w = repo(t);
|
|
679
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
680
|
-
writeFileSync(join(wt, "scratch.txt"), "uncommitted\n");
|
|
681
|
-
|
|
682
|
-
const { json } = runAudit(w);
|
|
683
|
-
const e = entryFor(json, wt);
|
|
684
|
-
|
|
685
|
-
const row = specRow();
|
|
686
|
-
|
|
687
|
-
// Both halves read the Out cell alone, since the rest of the row legitimately
|
|
688
|
-
// names things that are not keys: scanning the whole row let the Script cell's
|
|
689
|
-
// `worktree-audit.sh` satisfy `worktree` and the `Non-zero when` prose's "a
|
|
690
|
-
// worktree that is dirty" satisfy `dirty`, so either could be dropped from the
|
|
691
|
-
// type signature with this test green — and `dirty` is one of the two fields
|
|
692
|
-
// the row got wrong (#48).
|
|
693
|
-
const out = row.split("|")[3];
|
|
694
|
-
|
|
695
|
-
// Word-boundary match, so `dirty` cannot be satisfied by `dirtyFiles` sitting
|
|
696
|
-
// elsewhere in the cell — the exact substring trap that would let the shorter
|
|
697
|
-
// key be dropped again while this test stayed green.
|
|
698
|
-
const missing = Object.keys(e).filter((k) => !new RegExp(`\\b${k}\\b`).test(out));
|
|
699
|
-
assert.deepEqual(missing, [], `the spec row omits fields the script emits: ${missing.join(", ")}`);
|
|
700
|
-
|
|
701
|
-
// The other direction: a field the row invents is as wrong as one it drops,
|
|
702
|
-
// and only this half catches `commits`.
|
|
703
|
-
const invented = (out.match(/[A-Za-z][A-Za-z0-9]*/g) ?? []).filter((k) => !(k in e));
|
|
704
|
-
assert.deepEqual(invented, [], `the spec row names fields the script never emits: ${invented.join(", ")}`);
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
// --- #119: the payload's own string fields.
|
|
708
|
-
//
|
|
709
|
-
// `$wt` and `$short` are spliced raw. Both are reachable and by different
|
|
710
|
-
// routes: a branch name accepts a `"` (git rejects `\` in a ref), while a
|
|
711
|
-
// worktree path is a filename and accepts both. This script's whole output is
|
|
712
|
-
// one JSON array, so a single unescaped byte costs the caller every entry, not
|
|
713
|
-
// just the offending one.
|
|
714
|
-
//
|
|
715
|
-
// `dirtyFiles[]` was left out of #119 because git C-quotes those paths itself,
|
|
716
|
-
// conditionally, and translating that form is a second and different problem.
|
|
717
|
-
// #617 settled it — see the test below and the `jesc` comment in the script.
|
|
718
|
-
test("a quote in a branch name still emits parseable JSON", (t) => {
|
|
719
|
-
const w = repo(t);
|
|
720
|
-
addWorktree(w, 'evil"branch');
|
|
721
|
-
|
|
722
|
-
const { code, json } = runAudit(w);
|
|
723
|
-
|
|
724
|
-
assert.equal(code, 0);
|
|
725
|
-
const e = entryFor(json, join(w, ".worktrees", 'evil"branch'));
|
|
726
|
-
assert.equal(e.branch, 'evil"branch', "the branch field round-trips to the name that went in");
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
test("a quote and a backslash in a worktree PATH still emit parseable JSON", (t) => {
|
|
730
|
-
// The vector a branch name cannot reach: git refuses `\` in a ref but a
|
|
731
|
-
// directory name carries one fine, so the path is the only field here that
|
|
732
|
-
// exercises the backslash rule.
|
|
733
|
-
const w = repo(t);
|
|
734
|
-
const wt = join(w, '.worktrees/od"d\\path');
|
|
735
|
-
git(w, "worktree", "add", "-q", wt, "-b", "fix/odd-path", "origin/main");
|
|
736
|
-
|
|
737
|
-
const { code, json } = runAudit(w);
|
|
738
|
-
|
|
739
|
-
assert.equal(code, 0);
|
|
740
|
-
const e = entryFor(json, wt);
|
|
741
|
-
assert.equal(e.worktree, wt, "the path round-trips through both the quote and the backslash rule");
|
|
742
|
-
assert.equal(e.branch, "fix/odd-path");
|
|
743
|
-
});
|
|
744
|
-
|
|
745
|
-
test("an ordinary worktree is byte-identical — the escaping accepts what it should", (t) => {
|
|
746
|
-
// The false-positive half: nothing here has anything to escape.
|
|
747
|
-
const w = repo(t);
|
|
748
|
-
const wt = addWorktree(w, "fix/119-json-sh-extract");
|
|
749
|
-
|
|
750
|
-
const { code, json } = runAudit(w);
|
|
751
|
-
|
|
752
|
-
assert.equal(code, 0);
|
|
753
|
-
const e = entryFor(json, wt);
|
|
754
|
-
assert.deepEqual(e, { worktree: wt, branch: "fix/119-json-sh-extract", ahead: 0, dirty: 0, dirtyFiles: [], readable: true });
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
// #617: `dirtyFiles[]` carries git's C-quoting, which is not JSON's. One
|
|
758
|
-
// `caf\u00e9.txt` used to emit the literal `"caf\\303\\251.txt"` — `\\3` is not a JSON
|
|
759
|
-
// escape — and took the WHOLE array down with it, every other worktree's entry
|
|
760
|
-
// included, which is why the sibling assertion at the end is the real gate.
|
|
761
|
-
//
|
|
762
|
-
// The remedy chosen is translate-then-emit: the payload names the file that is
|
|
763
|
-
// on disk, so a controller reading it can hand the string straight back to the
|
|
764
|
-
// filesystem. Every branch of that translation is exercised here:
|
|
765
|
-
// - an octal escape with the high bit set (`caf\u00e9.txt`)
|
|
766
|
-
// - an octal escape for a C0 byte with NO named short form in either format
|
|
767
|
-
// (`\\016`, SO) — the branch a mutation could break silently while every
|
|
768
|
-
// other case here stayed green, since BEL/VT below reach `jesc` by the
|
|
769
|
-
// letter branch, never the octal one (survived finding 2)
|
|
770
|
-
// - the two verbatim short forms (`\\"`, `\\\\`)
|
|
771
|
-
// - all four JSON-legal short forms git also spells with a letter
|
|
772
|
-
// (`\\b`, `\\f`, `\\r`, `\\t`) — only `\\t` was covered before this
|
|
773
|
-
// - BEL, which git spells `\\a` (a git short form JSON has none for)
|
|
774
|
-
// - VT, which git spells `\\v` (the other git-only short form, untested
|
|
775
|
-
// before this — survived finding 3)
|
|
776
|
-
// `jesc` treats BEL and VT alike: replaced with a space, the same treatment
|
|
777
|
-
// json.sh's `tr` gives every short-form-less C0 byte.
|
|
778
|
-
//
|
|
779
|
-
// Node re-encodes every JS string as UTF-8 on the way to the filesystem, so a
|
|
780
|
-
// source-literal `\u00e9` lands as the two bytes git C-quotes as `\\303\\251` — the
|
|
781
|
-
// exact input the bug needs. That route reaches VALID UTF-8 only: an invalid
|
|
782
|
-
// byte cannot be written from a JS string at all, and APFS refuses to hold one
|
|
783
|
-
// either; #582 covers that shape one script over. Every control byte here is
|
|
784
|
-
// spelled `\\uXXXX` rather than embedded, to keep a raw control byte out of
|
|
785
|
-
// this source file.
|
|
786
|
-
test("dirty filenames that git C-quotes round-trip to the real names", (t) => {
|
|
787
|
-
const w = repo(t);
|
|
788
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
789
|
-
const names = [
|
|
790
|
-
"caf\u00e9.txt",
|
|
791
|
-
'q"q.txt',
|
|
792
|
-
"b\\s.txt",
|
|
793
|
-
"so\u000e.txt",
|
|
794
|
-
"bs\u0008.txt",
|
|
795
|
-
"ff\u000c.txt",
|
|
796
|
-
"cr\u000d.txt",
|
|
797
|
-
"ta\tb.txt",
|
|
798
|
-
"bel\u0007.txt",
|
|
799
|
-
"vt\u000b.txt",
|
|
800
|
-
];
|
|
801
|
-
for (const n of names) writeFileSync(join(wt, n), "uncommitted\n");
|
|
802
|
-
|
|
803
|
-
const { code, json } = runAudit(w);
|
|
804
|
-
|
|
805
|
-
assert.equal(code, 0);
|
|
806
|
-
const e = entryFor(json, wt);
|
|
807
|
-
assert.equal(e.dirty, names.length);
|
|
808
|
-
// Sorted rather than in git's order: git orders by raw bytes and JS by UTF-16
|
|
809
|
-
// code unit, so pinning the order here would pin the wrong thing.
|
|
810
|
-
assert.deepEqual(
|
|
811
|
-
[...e.dirtyFiles].sort(),
|
|
812
|
-
[
|
|
813
|
-
"b\\s.txt",
|
|
814
|
-
"so .txt",
|
|
815
|
-
"bs\u0008.txt",
|
|
816
|
-
"ff\u000c.txt",
|
|
817
|
-
"cr\u000d.txt",
|
|
818
|
-
"bel .txt",
|
|
819
|
-
"vt .txt",
|
|
820
|
-
"caf\u00e9.txt",
|
|
821
|
-
'q"q.txt',
|
|
822
|
-
"ta\tb.txt",
|
|
823
|
-
].sort(),
|
|
824
|
-
"a C-quoted dirty filename no longer round-trips to the name on disk",
|
|
825
|
-
);
|
|
826
|
-
assert.equal(entryFor(json, w).readable, true, "one bad element must not cost the caller every other entry");
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
// #614: the BEHAVIOURAL twin of locale-pin-prose.test.mjs' source assertion for
|
|
830
|
-
// this script. That file checks the pin is PRESENT; this one checks it is
|
|
831
|
-
// LOAD-BEARING — with `export LC_ALL=C` deleted, the answer below changes.
|
|
832
|
-
//
|
|
833
|
-
// The ambient locale has to reach the child genuinely, not merely differ from
|
|
834
|
-
// `C`: a POSIX shell keeps a variable's export attribute once it is already in
|
|
835
|
-
// the environment, so seeding `LC_ALL: "en_US.UTF-8"` here would let a mutant
|
|
836
|
-
// that drops the `export` keyword still propagate `C` to every child. `LANG`
|
|
837
|
-
// with `LC_ALL` and `LC_CTYPE` absent is what an unset `LC_ALL` actually looks
|
|
838
|
-
// like — the shape #599's own regression test got wrong.
|
|
839
|
-
const AMBIENT_UTF8 = { LANG: "en_US.UTF-8", LC_ALL: undefined, LC_CTYPE: undefined };
|
|
840
|
-
|
|
841
|
-
/** Like runAudit, but byte-exact: an invalid UTF-8 byte cannot survive a utf8 decode. */
|
|
842
|
-
function runAuditBytes(cwd, envOverrides) {
|
|
843
|
-
const r = spawnSync("sh", [SCRIPT], { cwd, env: { ...ENV, ...envOverrides } });
|
|
844
|
-
return { code: r.status, stdout: r.stdout.toString("latin1"), stderr: r.stderr.toString("latin1") };
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
// Unlike every sibling fixture in this class, this one is vacuous on NEITHER
|
|
848
|
-
// platform — both halves of the payload below kill the mutant, on a different
|
|
849
|
-
// tool each:
|
|
850
|
-
// - macOS (BWK awk, BSD paste): `jesc` decodes `\377` back to the raw byte,
|
|
851
|
-
// and `paste -sd, -` then truncates its whole output at it, exit 0, stderr
|
|
852
|
-
// empty. Measured: `"dirtyFiles":["b` — an unterminated JSON string that
|
|
853
|
-
// takes the rest of the payload with it.
|
|
854
|
-
// - Linux CI (gawk 5.4.1): awk survives, but `sprintf("%c", 195)` emits the
|
|
855
|
-
// two-byte UTF-8 encoding of U+00C3 instead of the byte. Measured, mutant:
|
|
856
|
-
// `["b\303\277ad.txt","caf\303\203\302\251.txt"]` — every non-ASCII dirty
|
|
857
|
-
// filename double-encoded, and the payload no longer names a file the
|
|
858
|
-
// caller can hand back to the filesystem.
|
|
859
|
-
// Pinned, both awks answer `["b\377ad.txt","caf\303\251.txt"]`.
|
|
860
|
-
//
|
|
861
|
-
// The `\377` entry goes in through `update-index --cacheinfo` with no working
|
|
862
|
-
// tree write: APFS refuses the name outright, and git reports the index-only
|
|
863
|
-
// blob as `AD` — deleted from the worktree — which is dirty all the same. The
|
|
864
|
-
// name is spelled as a `printf` FORMAT because node re-encodes every JS string
|
|
865
|
-
// as UTF-8 on the way to argv, which would turn `\377` into valid UTF-8 and
|
|
866
|
-
// reproduce nothing.
|
|
867
|
-
test("dirty filenames survive an ambient UTF-8 locale byte-for-byte (#614)", (t) => {
|
|
868
|
-
const w = repo(t);
|
|
869
|
-
const wt = addWorktree(w, "fix/9-x");
|
|
870
|
-
writeFileSync(join(wt, "caf\u00e9.txt"), "uncommitted\n");
|
|
871
|
-
execFileSync("sh", ["-c",
|
|
872
|
-
'b=$(printf x | git hash-object -w --stdin) && git update-index --add --cacheinfo "100644,$b,$(printf "b\\377ad.txt")"'],
|
|
873
|
-
{ cwd: wt, env: ENV });
|
|
874
|
-
|
|
875
|
-
const { code, stdout, stderr } = runAuditBytes(w, AMBIENT_UTF8);
|
|
876
|
-
|
|
877
|
-
assert.equal(code, 0, `stderr: ${stderr}`);
|
|
878
|
-
assert.ok(
|
|
879
|
-
stdout.includes('"dirtyFiles":["b\u00ffad.txt","caf\u00c3\u00a9.txt"]'),
|
|
880
|
-
`the pin must hold both names whole and undecoded, got: ${JSON.stringify(stdout)}`,
|
|
881
|
-
);
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
// #617 survived finding 1: the unrecognized-escape fallback used to be
|
|
885
|
-
// `else out=out c` — a silently dropped backslash with the following byte
|
|
886
|
-
// passed through unescaped, no error, no non-zero exit. Dead code under real
|
|
887
|
-
// git 2.50.1 (the enumeration above is exhaustive against it), so this drives
|
|
888
|
-
// `jesc`'s own awk program directly with a synthetic C-quoted string rather
|
|
889
|
-
// than trying to make real git emit an escape it never does. The program text
|
|
890
|
-
// is extracted from the shipped script at test time, never hand-copied, so
|
|
891
|
-
// this cannot drift from what actually ships.
|
|
892
|
-
function extractJescAwkProgram() {
|
|
893
|
-
const src = readFileSync(SCRIPT, "utf8");
|
|
894
|
-
const anchor = src.indexOf("function jesc");
|
|
895
|
-
assert.ok(anchor > -1, "fixture: worktree-audit.sh must still define jesc");
|
|
896
|
-
const startMarker = "awk '";
|
|
897
|
-
const start = src.lastIndexOf(startMarker, anchor) + startMarker.length;
|
|
898
|
-
const end = src.indexOf("'); then", anchor);
|
|
899
|
-
assert.ok(start > startMarker.length - 1 && end > start, "fixture: could not locate jesc's awk program bounds");
|
|
900
|
-
return src.slice(start, end);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
test("jesc fails loud on an unrecognized C-quote escape, never corrupting the output", () => {
|
|
904
|
-
const program = extractJescAwkProgram();
|
|
905
|
-
const bad = spawnSync("awk", [program], { input: ' M "weird\\efile.txt"\n', env: ENV, encoding: "utf8" });
|
|
906
|
-
assert.notEqual(bad.status, 0, "an unrecognized escape must fail the awk program, not emit a corrupted string");
|
|
907
|
-
assert.equal(bad.stdout, "", "no corrupted string on stdout once the program has refused");
|
|
908
|
-
assert.match(bad.stderr, /unrecognized C-quote escape/);
|
|
909
|
-
|
|
910
|
-
// ACCEPT: the same program must still pass ordinary input, so the refusal
|
|
911
|
-
// above is discrimination, not a program that fails unconditionally.
|
|
912
|
-
const good = spawnSync("awk", [program], { input: ' M "caf\\303\\251.txt"\n', env: ENV, encoding: "utf8" });
|
|
913
|
-
assert.equal(good.status, 0);
|
|
914
|
-
assert.equal(good.stdout, '"caf\u00e9.txt"\n');
|
|
915
|
-
});
|
|
916
|
-
|
|
917
|
-
// #525: this script parses no positional argument — an argument was silently
|
|
918
|
-
// discarded, so a caller who thought they were scoping the audit to one
|
|
919
|
-
// worktree got a full audit of every worktree back at exit 0, first row the
|
|
920
|
-
// main checkout. Refuse instead, same contract as the missing-json.sh case
|
|
921
|
-
// below: exit 2, nothing on stdout.
|
|
922
|
-
test("a worktree path holding a newline is refused, never truncated (#551)", (t) => {
|
|
923
|
-
// The plain porcelain ends every attribute with a newline, so a path holding
|
|
924
|
-
// one split into two records: `substr($0,10)` stopped at the newline, and the
|
|
925
|
-
// `while IFS=<TAB> read -r` loop below it stopped there a second time. This
|
|
926
|
-
// script then reported `ahead=0 dirty=0 readable:true` about a path not on
|
|
927
|
-
// disk — a clean, confident answer, which is what the fleet controller reads
|
|
928
|
-
// to decide whether a replacement member would redo work or destroy it.
|
|
929
|
-
//
|
|
930
|
-
// The branch name cannot carry the newline (git rejects a control byte in a
|
|
931
|
-
// ref), so the worktree is added by hand rather than through addWorktree.
|
|
932
|
-
const w = repo(t);
|
|
933
|
-
const ordinary = addWorktree(w, "plain-77");
|
|
934
|
-
const wt = join(w, ".worktrees", "fix-33\nslug");
|
|
935
|
-
git(w, "worktree", "add", "-q", wt, "-b", "fix/33-slug", "origin/main");
|
|
936
|
-
|
|
937
|
-
const { code, json, stderr } = runAudit(w);
|
|
938
|
-
assert.equal(code, 0, "one unreadable entry must not take the whole audit down");
|
|
939
|
-
assert.match(stderr, /path holds a newline/, "the refusal names the problem");
|
|
940
|
-
|
|
941
|
-
// jstr renders the substituted byte as a space — the treatment every C0 byte
|
|
942
|
-
// without a JSON short form gets — so the reported path is WHOLE with the
|
|
943
|
-
// newline neutralised, never cut at it.
|
|
944
|
-
const reported = json.map((e) => e.worktree);
|
|
945
|
-
assert.ok(
|
|
946
|
-
reported.some((x) => x.startsWith(`${w}/.worktrees/fix-33`) && x.endsWith("slug")),
|
|
947
|
-
`the whole path must survive to the payload: ${JSON.stringify(reported)}`,
|
|
948
|
-
);
|
|
949
|
-
assert.ok(
|
|
950
|
-
!reported.includes(join(w, ".worktrees", "fix-33")),
|
|
951
|
-
"the truncated path is what this ticket exists to stop being reported",
|
|
952
|
-
);
|
|
953
|
-
const cut = json.find((e) => e.worktree.endsWith("slug"));
|
|
954
|
-
assert.deepEqual(
|
|
955
|
-
{ readable: cut.readable, ahead: cut.ahead, dirty: cut.dirty },
|
|
956
|
-
{ readable: false, ahead: null, dirty: null },
|
|
957
|
-
"nothing on disk was checked through that path, so nothing may be claimed about it",
|
|
958
|
-
);
|
|
959
|
-
|
|
960
|
-
// ACCEPT. A sibling ordinary worktree in the SAME listing must be audited
|
|
961
|
-
// exactly as before — otherwise this pins that the guard refuses, not that it
|
|
962
|
-
// discriminates, and a `nl_path` hard-wired true would pass every line above.
|
|
963
|
-
assert.deepEqual(
|
|
964
|
-
(({ worktree, ahead, dirty, readable }) => ({ worktree, ahead, dirty, readable }))(entryFor(json, ordinary)),
|
|
965
|
-
{ worktree: ordinary, ahead: 0, dirty: 0, readable: true },
|
|
966
|
-
);
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
test("a dangling symlink at a worktree path is occupied, not MISSING on disk (#725)", (t) => {
|
|
970
|
-
// `gone()` used `-e`, which STATS, so a dangling link was `-e` false and read
|
|
971
|
-
// as established-absent — and this script reported `MISSING on disk` with
|
|
972
|
-
// zero counts for a path `git worktree add` treats as occupied. Measured
|
|
973
|
-
// before the fix, exactly that. The wording stays hedged: such a link is
|
|
974
|
-
// rc-0 residue OR release-ticket.sh's rc-255 halt path with the branch and
|
|
975
|
-
// the in-progress label still alive, and only the hedge is true of both (#728).
|
|
976
|
-
const w = repo(t);
|
|
977
|
-
const wt = addWorktree(w, "33-slug");
|
|
978
|
-
rmSync(wt, { recursive: true, force: true });
|
|
979
|
-
symlinkSync(join(w, "nowhere"), wt);
|
|
980
|
-
|
|
981
|
-
const { code, json, stderr } = runAudit(w);
|
|
982
|
-
assert.equal(code, 0);
|
|
983
|
-
assert.doesNotMatch(stderr, /MISSING on disk/, "a link IS there — absence is the one thing this is not");
|
|
984
|
-
assert.match(stderr, /exists but is not a directory/);
|
|
985
|
-
const e = entryFor(json, wt);
|
|
986
|
-
assert.deepEqual(
|
|
987
|
-
{ readable: e.readable, ahead: e.ahead, dirty: e.dirty },
|
|
988
|
-
{ readable: false, ahead: null, dirty: null },
|
|
989
|
-
"null counts, never the 0/0 that reads as a clean worktree holding no work",
|
|
990
|
-
);
|
|
991
|
-
});
|
|
992
|
-
|
|
993
|
-
test("a positional argument is refused, not silently discarded (#525)", (t) => {
|
|
994
|
-
// No `addWorktree` here on purpose: `repo(t)` alone already yields one
|
|
995
|
-
// auditable worktree (the main checkout), so an un-guarded script still
|
|
996
|
-
// exits 0 with a non-empty array and the refusal assertion still reds.
|
|
997
|
-
// Measured — the added worktree changed neither the red nor the green side.
|
|
998
|
-
const w = repo(t);
|
|
999
|
-
|
|
1000
|
-
const r = spawnSync("sh", [SCRIPT, ".worktrees/fix/9-x"], { cwd: w, env: ENV, encoding: "utf8" });
|
|
1001
|
-
|
|
1002
|
-
assert.equal(r.status, 2, `must refuse, not silently audit everything; stdout: ${r.stdout}`);
|
|
1003
|
-
assert.equal(r.stdout, "", "no half-written array on a refusal");
|
|
1004
|
-
assert.match(r.stderr, /^worktree-audit: takes no arguments; audits every worktree$/m);
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
// --- #884/#894: the escape guard's FATALITY, not the message it carries.
|
|
1008
|
-
//
|
|
1009
|
-
// `wt_j=$(jstr "$wt") && short_j=$(jstr "$short") || die` is this script's
|
|
1010
|
-
// guard; verify-sha.sh's own guard (`branch_j=$(jstr "$branch") &&
|
|
1011
|
-
// sha_j=$(jstr "$sha") && tip_j=$(jstr "$tip") || die`) shares only the
|
|
1012
|
-
// jstr/&&/`|| die` structure, not this exact code, and #884 pinned only this
|
|
1013
|
-
// copy. Downgrade this one to a warning that does not exit and the script
|
|
1014
|
-
// walks into the `printf` below it, emitting an entry whose escaping it
|
|
1015
|
-
// never performed — a confident-looking
|
|
1016
|
-
// but wrong JSON array, on the report a fleet controller reads to decide
|
|
1017
|
-
// whether a replacement member would redo work or destroy it.
|
|
1018
|
-
//
|
|
1019
|
-
// Neither an exit-code nor a wording match can pin that. `die` here is 2, and
|
|
1020
|
-
// this script defines no exit 1 at all (json.sh's header records why for all
|
|
1021
|
-
// eight callers): a bare 1 out of it is a code its caller has no reading for.
|
|
1022
|
-
// Which abort the mutant takes is the SHELL's choice, not this script's —
|
|
1023
|
-
// measured with the guard downgraded to a non-exiting `printf … >&2`: /bin/sh
|
|
1024
|
-
// (macOS bash 3.2) aborts at 1 with `short_j: unbound variable`, /bin/dash at 2
|
|
1025
|
-
// with `short_j: parameter not set`. That 2 is the very status a firing guard
|
|
1026
|
-
// returns, and CI's `check` job runs on ubuntu-latest, where `sh` IS dash — so
|
|
1027
|
-
// an exit-code assertion pins this guard on a developer's Mac and lets the
|
|
1028
|
-
// mutant through on the runner that gates the merge, while a wording match pins
|
|
1029
|
-
// whichever shell uses that wording. The variable NAME is what discriminates:
|
|
1030
|
-
// both shells name it first and word the rest however they like.
|
|
1031
|
-
//
|
|
1032
|
-
// `short_j` and not `wt_j`: the `&&` short-circuits, so a first capture that
|
|
1033
|
-
// fails leaves `wt_j` set-and-empty and `short_j` never assigned at all.
|
|
1034
|
-
//
|
|
1035
|
-
// `jstr` escapes through a `sed`/`tr` pipeline, so shadowing `sed` reaches the
|
|
1036
|
-
// escaper and nothing else this run touches: the script itself runs no `sed`
|
|
1037
|
-
// (its `LC_ALL=C` note inventories that), `wt_listing` reads git's listing
|
|
1038
|
-
// through `tr`, and `jesc` is awk. The `branch=` status trace the loop prints
|
|
1039
|
-
// for each entry, just before it escapes that entry, stands in for the progress
|
|
1040
|
-
// marker this guard would otherwise lack — it proves the run reached the
|
|
1041
|
-
// escaping rather than an earlier step the shim happened to break, and
|
|
1042
|
-
// printf-die-sweep.test.mjs pins that trace, so it cannot be reworded out from
|
|
1043
|
-
// under the assertion below unseen. No assertion here names a `die` message:
|
|
1044
|
-
// rewording any of them, this guard's own included, leaves the pin standing.
|
|
1045
|
-
|
|
1046
|
-
// Resolved out here, where PATH is still the real one, and quoted at the exec:
|
|
1047
|
-
// a `sed` under a path with a space word-splits otherwise, and the passthrough
|
|
1048
|
-
// shim would then break the escaper it exists to leave working.
|
|
1049
|
-
const REAL_SED = execFileSync("sh", ["-c", "command -v sed"], { encoding: "utf8" }).trim();
|
|
1050
|
-
|
|
1051
|
-
/** A dir holding a `sed` shim with the given body, prepended to PATH. */
|
|
1052
|
-
function sedShim(t, body) {
|
|
1053
|
-
const bin = mkdtempSync(join(tmpdir(), "worktree-audit-sed-shim-"));
|
|
1054
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
1055
|
-
writeExecStub(join(bin, "sed"), `#!/bin/sh\n${body}\n`);
|
|
1056
|
-
return `${bin}:${ENV.PATH ?? process.env.PATH}`;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
test("an escaper that cannot run stops the audit, never an entry it failed to escape", (t) => {
|
|
1060
|
-
// `repo(t)` alone, no `addWorktree`: git lists the main checkout with its own
|
|
1061
|
-
// `branch` line, so the first iteration already reaches the guard.
|
|
1062
|
-
const w = repo(t);
|
|
1063
|
-
|
|
1064
|
-
const r = spawnSync("sh", [SCRIPT], {
|
|
1065
|
-
cwd: w,
|
|
1066
|
-
env: { ...ENV, PATH: sedShim(t, 'echo "sed: outage" >&2\nexit 1') },
|
|
1067
|
-
encoding: "utf8",
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
// Whether this fixture measured the guard at all is settled before its
|
|
1071
|
-
// verdict is read: an assertion that fails masks every one after it, and
|
|
1072
|
-
// "the shim broke something else" and "the guard is not fatal" are not
|
|
1073
|
-
// interchangeable diagnoses.
|
|
1074
|
-
assert.match(r.stderr, /sed: outage/, "the escaper ran and failed, which is the failure under test");
|
|
1075
|
-
assert.ok(
|
|
1076
|
-
r.stderr.includes(`${w} branch=main`),
|
|
1077
|
-
`the per-entry status trace printed, so the run reached the escaping — that is what failed here, not an earlier step the shim broke; got ${JSON.stringify(r.stderr)}`,
|
|
1078
|
-
);
|
|
1079
|
-
// And that the name it pins is still the one the shell would print: a rename
|
|
1080
|
-
// leaves the `doesNotMatch` below matching nothing and passing over a
|
|
1081
|
-
// downgraded guard forever, which is the one way this pin can rot silently.
|
|
1082
|
-
// `short_j` appears nowhere else in the script, comments included.
|
|
1083
|
-
assert.match(
|
|
1084
|
-
readFileSync(SCRIPT, "utf8"),
|
|
1085
|
-
/short_j/,
|
|
1086
|
-
"worktree-audit.sh no longer names `short_j` — re-derive the second capture's name from its escape guard and update the assertion below, which now pins nothing",
|
|
1087
|
-
);
|
|
1088
|
-
|
|
1089
|
-
// The pin itself goes first, ahead of the two contract assertions below it:
|
|
1090
|
-
// measured on the mutant, /bin/sh's abort status is 1, so an exit-code
|
|
1091
|
-
// assertion placed above this one reds on a developer's Mac with a diagnosis
|
|
1092
|
-
// about a bare 1 — and masks the real one — while on dash it passes and
|
|
1093
|
-
// leaves this the only assertion that can fire at all.
|
|
1094
|
-
assert.doesNotMatch(
|
|
1095
|
-
r.stderr,
|
|
1096
|
-
/short_j/,
|
|
1097
|
-
"the guard must stop the script itself, not warn and leave the `printf` below it reading a name the short-circuited `&&` never assigned. The NAME, never the wording or the status: /bin/sh says `short_j: unbound variable` at exit 1, dash `short_j: parameter not set` at exit 2 — the same 2 a firing guard returns, under the shell CI actually runs.",
|
|
1098
|
-
);
|
|
1099
|
-
|
|
1100
|
-
assert.equal(
|
|
1101
|
-
r.stdout,
|
|
1102
|
-
"[",
|
|
1103
|
-
"the opening bracket is already out and that is all a caller may see: a truncated array fails its parse, where an entry carrying escaping that never ran reads as a clean, confident answer. This is what catches the downgrade that defaults the name instead of leaving it unset, which the assertion above cannot see.",
|
|
1104
|
-
);
|
|
1105
|
-
assert.equal(
|
|
1106
|
-
r.status,
|
|
1107
|
-
2,
|
|
1108
|
-
`an entry that could not be escaped is "the question could not be answered", never the bare 1 this script's caller has no reading for; stdout: ${r.stdout}`,
|
|
1109
|
-
);
|
|
1110
|
-
});
|
|
1111
|
-
|
|
1112
|
-
test("a shadowed `sed` that works still escapes the entry — only a real outage refuses", (t) => {
|
|
1113
|
-
// The accept half, and the control the case above needs: shadowing `sed` on
|
|
1114
|
-
// PATH is not by itself fatal here, so the refusal up there is the escaper
|
|
1115
|
-
// failing rather than the shim's mere presence. A path holding a `"` and a
|
|
1116
|
-
// `\` rather than an ordinary one, so the sed rules the shim now fronts have
|
|
1117
|
-
// something to do — `jstr` returns before it forks at all on an empty value,
|
|
1118
|
-
// and an ordinary path exercises no rule.
|
|
1119
|
-
const w = repo(t);
|
|
1120
|
-
const wt = join(w, '.worktrees/od"d\\path');
|
|
1121
|
-
git(w, "worktree", "add", "-q", wt, "-b", "fix/894-shim", "origin/main");
|
|
1122
|
-
|
|
1123
|
-
const r = spawnSync("sh", [SCRIPT], {
|
|
1124
|
-
cwd: w,
|
|
1125
|
-
env: { ...ENV, PATH: sedShim(t, `exec "${REAL_SED}" "$@"`) },
|
|
1126
|
-
encoding: "utf8",
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
assert.equal(r.status, 0, `a working escaper must not change the answer; stderr: ${r.stderr}`);
|
|
1130
|
-
assert.deepEqual(
|
|
1131
|
-
entryFor(JSON.parse(r.stdout), wt),
|
|
1132
|
-
{ worktree: wt, branch: "fix/894-shim", ahead: 0, dirty: 0, dirtyFiles: [], readable: true },
|
|
1133
|
-
"both escape rules ran through the shim to the entry the unshimmed run emits — the refusal above is an outage, not a shadowed name",
|
|
1134
|
-
);
|
|
1135
|
-
});
|
|
1136
|
-
|
|
1137
|
-
// `.` is a POSIX special builtin, so failing to open its operand aborts a
|
|
1138
|
-
// non-interactive shell before any `||` on the line can run. This script's
|
|
1139
|
-
// contract is exit 0 or exit 2; a missing library must reach the 2.
|
|
1140
|
-
test("a missing json.sh is exit 2, with no half-written array", (t) => {
|
|
1141
|
-
const w = repo(t);
|
|
1142
|
-
addWorktree(w, "fix/1-thing");
|
|
1143
|
-
const lone = mkdtempSync(join(tmpdir(), "worktree-audit-nolib-"));
|
|
1144
|
-
t.after(() => rmSync(lone, { recursive: true, force: true }));
|
|
1145
|
-
copyFileSync(SCRIPT, join(lone, "worktree-audit.sh"));
|
|
1146
|
-
|
|
1147
|
-
const r = spawnSync("sh", [join(lone, "worktree-audit.sh")], { cwd: w, env: ENV, encoding: "utf8" });
|
|
1148
|
-
|
|
1149
|
-
assert.equal(r.status, 2, "a missing library is `the question could not be answered`");
|
|
1150
|
-
assert.match(r.stderr, /json\.sh/, "and it names the file rather than blaming the base ref");
|
|
1151
|
-
assert.equal(r.stdout, "",
|
|
1152
|
-
"and not even the opening `[` — the guard fires before the array is started, so no caller can see a truncated one");
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
// --- #1020: the ambient git variables, one fixture each.
|
|
1156
|
-
//
|
|
1157
|
-
// Deliberately NOT one fixture setting both. PR #1015 measured the cost of
|
|
1158
|
-
// that shortcut on release-ticket.sh: a case overriding only one of the pair
|
|
1159
|
-
// leaves the other half of `unset GIT_DIR GIT_WORK_TREE` unpinned and green,
|
|
1160
|
-
// and the two halves break this script in two different directions anyway —
|
|
1161
|
-
// GIT_DIR swaps the repository, GIT_WORK_TREE swaps the tree the dirty check
|
|
1162
|
-
// answers about. One detector cannot see both.
|
|
1163
|
-
|
|
1164
|
-
test("an ambient GIT_WORK_TREE does not report a dirty worktree as clean (#1020)", (t) => {
|
|
1165
|
-
// The silent-failure half. GIT_WORK_TREE outranks `-C`, so the loop's
|
|
1166
|
-
// `git -C "$wt" status --porcelain -uall` reads the ambient tree's status
|
|
1167
|
-
// against $wt's index and answers EMPTY at rc 0 — a false clean on a
|
|
1168
|
-
// worktree that genuinely holds uncommitted work.
|
|
1169
|
-
//
|
|
1170
|
-
// `.gitignore` naming `.worktrees/` is not decoration: it is the fleet's own
|
|
1171
|
-
// layout, and it is what makes the leaked answer an EMPTY one rather than a
|
|
1172
|
-
// noisy `?? .worktrees/`. Without it the poisoned status still reports
|
|
1173
|
-
// SOMETHING and the false clean never forms, so the fixture would pass
|
|
1174
|
-
// pre-fix while pinning nothing.
|
|
1175
|
-
const w = repo(t);
|
|
1176
|
-
writeFileSync(join(w, ".gitignore"), ".worktrees/\n");
|
|
1177
|
-
git(w, "add", ".gitignore");
|
|
1178
|
-
commit(w, "ignore worktrees");
|
|
1179
|
-
git(w, "push", "-q", "origin", "main");
|
|
1180
|
-
const wt = addWorktree(w, "fix/1020-x");
|
|
1181
|
-
writeFileSync(join(wt, "scratch.txt"), "uncommitted\n");
|
|
1182
|
-
|
|
1183
|
-
// The fixture's own positive control, in both directions — the same standard
|
|
1184
|
-
// the #730 case above holds itself to. Without the first, a git that stopped
|
|
1185
|
-
// honouring GIT_WORK_TREE would leave this green while measuring nothing;
|
|
1186
|
-
// without the second, the case could be passing because the worktree was
|
|
1187
|
-
// never dirty.
|
|
1188
|
-
assert.equal(
|
|
1189
|
-
git(wt, "status", "--porcelain"),
|
|
1190
|
-
"?? scratch.txt",
|
|
1191
|
-
"fixture: the worktree must really be dirty, or this case measures nothing",
|
|
1192
|
-
);
|
|
1193
|
-
assert.equal(
|
|
1194
|
-
execFileSync("git", ["-C", wt, "status", "--porcelain"], {
|
|
1195
|
-
cwd: w, env: { ...ENV, GIT_WORK_TREE: w }, encoding: "utf8",
|
|
1196
|
-
}),
|
|
1197
|
-
"",
|
|
1198
|
-
"fixture: the ambient GIT_WORK_TREE must really silence that answer, or the leak this pins no longer exists",
|
|
1199
|
-
);
|
|
1200
|
-
|
|
1201
|
-
const { code, json, stderr } = runAudit(w, { env: { GIT_WORK_TREE: w } });
|
|
1202
|
-
|
|
1203
|
-
assert.equal(code, 0, stderr);
|
|
1204
|
-
// `readable: true` alongside the count, for #730's reason: a fix that turned
|
|
1205
|
-
// the poisoned answer into an UNKNOWN would also stop reporting 0, and
|
|
1206
|
-
// unknown is a different — and here wrong — verdict about a worktree git can
|
|
1207
|
-
// answer for perfectly well once the variable is out of the way.
|
|
1208
|
-
assert.deepEqual(
|
|
1209
|
-
entryFor(json, wt),
|
|
1210
|
-
{ worktree: wt, branch: "fix/1020-x", ahead: 0, dirty: 1, dirtyFiles: ["scratch.txt"], readable: true },
|
|
1211
|
-
"an ambient GIT_WORK_TREE must not make a dirty worktree report as clean — this report is what decides REDO vs DESTROY",
|
|
1212
|
-
);
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
test("an ambient GIT_DIR does not audit a different repository (#1020)", (t) => {
|
|
1216
|
-
// The correctness half, and it cannot use the dirty check as its detector:
|
|
1217
|
-
// GIT_DIR does not misdirect the `git -C "$wt"` calls at all. What it
|
|
1218
|
-
// retargets is every BARE git call above the loop — `rev-parse --git-dir`,
|
|
1219
|
-
// `rev-parse --verify "$base"`, and the `worktree list` behind `wt_listing`
|
|
1220
|
-
// — so the audit is assembled from the other repository's registry and never
|
|
1221
|
-
// mentions this one. Measured pre-fix: rc 0, a well-formed array, nothing on
|
|
1222
|
-
// stderr.
|
|
1223
|
-
const w = repo(t);
|
|
1224
|
-
const wt = addWorktree(w, "fix/1020-here");
|
|
1225
|
-
const other = repo(t, "other");
|
|
1226
|
-
const otherWt = addWorktree(other, "fix/1020-there");
|
|
1227
|
-
|
|
1228
|
-
const { code, json, stderr } = runAudit(w, { env: { GIT_DIR: join(other, ".git") } });
|
|
1229
|
-
|
|
1230
|
-
assert.equal(code, 0, stderr);
|
|
1231
|
-
// Both directions asserted, and either alone would already go red pre-fix.
|
|
1232
|
-
// The pair is what says the answer is about the WRONG REPOSITORY rather than
|
|
1233
|
-
// merely incomplete: a truncated listing loses `wt`, a retargeted one gains
|
|
1234
|
-
// `otherWt`, and only the second distinguishes them.
|
|
1235
|
-
assert.ok(
|
|
1236
|
-
json.some((e) => e.worktree === wt),
|
|
1237
|
-
`the audit must describe this checkout's own worktrees: ${JSON.stringify(json)}`,
|
|
1238
|
-
);
|
|
1239
|
-
assert.deepEqual(
|
|
1240
|
-
json.filter((e) => e.worktree === otherWt),
|
|
1241
|
-
[],
|
|
1242
|
-
`an ambient GIT_DIR must not make the audit answer for another checkout: ${JSON.stringify(json)}`,
|
|
1243
|
-
);
|
|
1244
|
-
});
|
|
1245
|
-
|
|
1246
|
-
// --- #1108: the exit-2 cause census.
|
|
1247
|
-
//
|
|
1248
|
-
// The design spec's script-surface row states this script's failures as a
|
|
1249
|
-
// CLOSED enumeration — `exit 2 only — A, B, C` — and until this block nothing
|
|
1250
|
-
// in the repo read that cell. Two PRs in one fleet run each left a row asserting an
|
|
1251
|
-
// enumeration its script had outgrown with the suite green (#1104/#525,
|
|
1252
|
-
// #1105/#482), and on `main` this row was silent about three refusals the
|
|
1253
|
-
// script reaches: the worktree-readers library guard, either library failing
|
|
1254
|
-
// to load, and a worktree listing that could not be read. All three are
|
|
1255
|
-
// measured below by running the script, never read off its source.
|
|
1256
|
-
//
|
|
1257
|
-
// Two pins, closing opposite directions:
|
|
1258
|
-
//
|
|
1259
|
-
// TOO NARROW — the script grows a refusal the row does not carry. `CAUSES`
|
|
1260
|
-
// binds every `die` site to the phrase that represents it, and the census
|
|
1261
|
-
// test asserts that binding is EXACTLY the set of sites the script has. Add
|
|
1262
|
-
// a `die` and it reds on an unbound site; delete one and it reds on a
|
|
1263
|
-
// binding whose cause the script can no longer produce. The set is derived
|
|
1264
|
-
// from the script, so the binding cannot rot silently the way the row did —
|
|
1265
|
-
// a reworded message reds too, which is the point: the row is what then has
|
|
1266
|
-
// to be revisited.
|
|
1267
|
-
//
|
|
1268
|
-
// TOO BROAD — the row grows a cause no `die` produces. The census cannot see
|
|
1269
|
-
// that; a phrase added to the cell binds to nothing and no assert notices.
|
|
1270
|
-
// `EXIT2_ENUMERATION` is the pin that does: the whole closed list, byte for
|
|
1271
|
-
// byte, in the `UNKNOWN_LINE`/`ORPHAN_LINE` verbatim-constant discipline
|
|
1272
|
-
// no-undo-audit.test.mjs already uses on this same table.
|
|
1273
|
-
//
|
|
1274
|
-
// The span pin's cost is deliberate, and it was #1108's ruling: it reds on
|
|
1275
|
-
// EVERY edit to the enumeration, a legitimate rewording included. A structural
|
|
1276
|
-
// assertion loose enough to survive rewording cannot red on a rewrite that
|
|
1277
|
-
// quietly drops a real cause, which is the defect that was measured twice.
|
|
1278
|
-
//
|
|
1279
|
-
// Scoped to this script's own suite beside its siblings rather than lifted
|
|
1280
|
-
// into one shared table over every row: `.out-of-scope/cli-guard-test-
|
|
1281
|
-
// consolidation.md` refuses that consolidation for the CLI-guard pins, and its
|
|
1282
|
-
// reason holds unchanged here — a file no single script's suite runs recreates
|
|
1283
|
-
// the blind spot these pins exist to close.
|
|
1284
|
-
|
|
1285
|
-
/** The `Non-zero when` cell of this script's row, and no more of the row. */
|
|
1286
|
-
const exit2Cell = () => specRow().split("|")[4];
|
|
1287
|
-
|
|
1288
|
-
/**
|
|
1289
|
-
* The row's exit-2 enumeration, verbatim: from `exit 2 only` to the end of the
|
|
1290
|
-
* sentence that closes the list. The cell's remaining sentence states the
|
|
1291
|
-
* exit-0 findings and is read by the `Out`-cell test above, so the span stops
|
|
1292
|
-
* where the closed list does — the slice is the size of the claim.
|
|
1293
|
-
*/
|
|
1294
|
-
const EXIT2_ENUMERATION =
|
|
1295
|
-
"exit 2 only — any argument at all (#525), not a repository, `BASE_REF` does not name a remote-tracking ref (#1329), `${BASE_REF:-origin/main}` does not resolve, `json.sh` or `worktree.sh` is missing, unreadable or failed to load (both guards fire above the opening `[`, so nothing is emitted), the `git worktree list` the audit is assembled from could not be read (#551), or an entry could not be escaped (#119) — that one fires inside the emitting loop, so stdout carries the array truncated mid-element and unparseable, which the exit 2 and the named stderr line are what distinguish from a complete answer.";
|
|
1296
|
-
|
|
1297
|
-
/**
|
|
1298
|
-
* The clause that collapses this script's four library refusals into one
|
|
1299
|
-
* cause. Named because four bindings below share it and a phrase typed four
|
|
1300
|
-
* times drifts three ways.
|
|
1301
|
-
*/
|
|
1302
|
-
const LIBRARY_CLAUSE = "`json.sh` or `worktree.sh` is missing, unreadable or failed to load";
|
|
1303
|
-
|
|
1304
|
-
/**
|
|
1305
|
-
* Every `die` site in worktree-audit.sh, bound to the phrase in the row that
|
|
1306
|
-
* represents it.
|
|
1307
|
-
*
|
|
1308
|
-
* The KEY is the message as the script spells it, interpolations and all.
|
|
1309
|
-
* `die` is this script's only exit-2 path — `dieSites` asserts that of the
|
|
1310
|
-
* definition itself — so the message set IS the cause set, and keying on it is
|
|
1311
|
-
* what makes this derived rather than a third hand-written copy of the
|
|
1312
|
-
* contract sitting beside the script and the row.
|
|
1313
|
-
*
|
|
1314
|
-
* Sites share a phrase where the ROW collapses them, which is the row's
|
|
1315
|
-
* editorial call and not a looseness here: a reader who meets any of the four
|
|
1316
|
-
* library refusals does the same thing about it. The phrases are the short
|
|
1317
|
-
* load-bearing labels; their exact wording is `EXIT2_ENUMERATION`'s job.
|
|
1318
|
-
*/
|
|
1319
|
-
const CAUSES = new Map([
|
|
1320
|
-
["takes no arguments; audits every worktree", "any argument at all (#525)"],
|
|
1321
|
-
["cannot read $json_lib — refusing to audit without the JSON escaping helpers", LIBRARY_CLAUSE],
|
|
1322
|
-
["$json_lib failed to load", LIBRARY_CLAUSE],
|
|
1323
|
-
["cannot read $wt_lib — refusing to audit without the worktree readers", LIBRARY_CLAUSE],
|
|
1324
|
-
["$wt_lib failed to load", LIBRARY_CLAUSE],
|
|
1325
|
-
["not inside a git repository", "not a repository"],
|
|
1326
|
-
["BASE_REF must be a remote-tracking ref, got '$base'", "`BASE_REF` does not name a remote-tracking ref (#1329)"],
|
|
1327
|
-
["$base does not resolve", "`${BASE_REF:-origin/main}` does not resolve"],
|
|
1328
|
-
["$wt_err", "the `git worktree list` the audit is assembled from could not be read (#551)"],
|
|
1329
|
-
["could not escape the entry for $wt", "an entry could not be escaped (#119)"],
|
|
1330
|
-
]);
|
|
1331
|
-
|
|
1332
|
-
/**
|
|
1333
|
-
* The message of every `die` call in the script, read off the script.
|
|
1334
|
-
*
|
|
1335
|
-
* Comment lines are dropped: prose quoting a `die "…"` is not a call site, and
|
|
1336
|
-
* minting a cause out of one would red this suite over a comment. Greedy to
|
|
1337
|
-
* the last quote on the line, so a message carrying a nested `"$…"`
|
|
1338
|
-
* substitution arrives whole rather than truncated at its first inner quote.
|
|
1339
|
-
*/
|
|
1340
|
-
function dieSites() {
|
|
1341
|
-
const src = readFileSync(SCRIPT, "utf8");
|
|
1342
|
-
assert.match(
|
|
1343
|
-
src,
|
|
1344
|
-
/^die\(\) \{ printf '%s: %s\\n' "\$NAME" "\$1" >&2; exit 2; \}$/m,
|
|
1345
|
-
"the census derives its cause set from one `die` that exits 2 — that definition has changed, so re-derive before trusting this file",
|
|
1346
|
-
);
|
|
1347
|
-
const sites = src
|
|
1348
|
-
.split("\n")
|
|
1349
|
-
.filter((l) => !/^\s*#/.test(l))
|
|
1350
|
-
.flatMap((l) => [...l.matchAll(/(?:^|[;&|(\s])die "(.*)"/g)].map((m) => m[1]));
|
|
1351
|
-
assert.ok(sites.length > 1, `the scan found ${sites.length} die sites, so its spelling has drifted off the script`);
|
|
1352
|
-
assert.equal(new Set(sites).size, sites.length, `two die sites share a message, so one of them cannot be bound: ${sites.join(" / ")}`);
|
|
1353
|
-
return sites;
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
test("the design spec's row represents every exit-2 cause this script can reach, and none it cannot (#1108)", () => {
|
|
1357
|
-
// Both directions in one equality: an unbound site is a cause the row may be
|
|
1358
|
-
// silent about, and a binding with no site is a cause the row claims while
|
|
1359
|
-
// the script can no longer produce it.
|
|
1360
|
-
assert.deepEqual([...dieSites()].sort(), [...CAUSES.keys()].sort());
|
|
1361
|
-
|
|
1362
|
-
const cell = exit2Cell();
|
|
1363
|
-
for (const phrase of new Set(CAUSES.values())) {
|
|
1364
|
-
assert.equal(
|
|
1365
|
-
cell.split(phrase).length - 1,
|
|
1366
|
-
1,
|
|
1367
|
-
`the \`Non-zero when\` cell must carry "${phrase}" exactly once.\ncell: ${cell}`,
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
|
|
1372
|
-
test("the design spec's row states this script's exit-2 causes as a closed list, byte for byte (#1108)", () => {
|
|
1373
|
-
// A prefix, not a search: a cause smuggled in ahead of the list would sit
|
|
1374
|
-
// outside an `includes`, and this cell opens on the list.
|
|
1375
|
-
assert.equal(exit2Cell().trim().slice(0, EXIT2_ENUMERATION.length), EXIT2_ENUMERATION);
|
|
1376
|
-
});
|
|
1377
|
-
|
|
1378
|
-
// The worktree-readers guard had no fixture at all before #1108, which is how
|
|
1379
|
-
// its absence from the row survived: the missing-json.sh case above reaches the
|
|
1380
|
-
// json guard, which fires first, so a lone copy of this script can never reach
|
|
1381
|
-
// this one. json.sh travels with the copy; worktree.sh does not.
|
|
1382
|
-
test("a missing worktree.sh is exit 2, and the design spec's row names the library it blames (#1108)", (t) => {
|
|
1383
|
-
const w = repo(t);
|
|
1384
|
-
addWorktree(w, "fix/1-thing");
|
|
1385
|
-
const lone = mkdtempSync(join(tmpdir(), "worktree-audit-nowtlib-"));
|
|
1386
|
-
t.after(() => rmSync(lone, { recursive: true, force: true }));
|
|
1387
|
-
copyFileSync(SCRIPT, join(lone, "worktree-audit.sh"));
|
|
1388
|
-
copyFileSync(fileURLToPath(new URL("./json.sh", import.meta.url)), join(lone, "json.sh"));
|
|
1389
|
-
|
|
1390
|
-
const r = spawnSync("sh", [join(lone, "worktree-audit.sh")], { cwd: w, env: ENV, encoding: "utf8" });
|
|
1391
|
-
|
|
1392
|
-
assert.equal(r.status, 2, `a missing library is \`the question could not be answered\`: ${r.stderr}`);
|
|
1393
|
-
assert.equal(r.stdout, "",
|
|
1394
|
-
"and not even the opening `[` — the guard fires before the array is started, so no caller can see a truncated one");
|
|
1395
|
-
assert.match(r.stderr, /refusing to audit without the worktree readers/,
|
|
1396
|
-
"the fixture must reach the worktree-readers guard rather than the json.sh one above it");
|
|
1397
|
-
|
|
1398
|
-
// The library NAME off the real refusal, never typed here: the path around it
|
|
1399
|
-
// is the machine's to vary and no document can carry it. Pre-#1108 this row
|
|
1400
|
-
// named json.sh alone, so this assert is what demonstrates the omission by
|
|
1401
|
-
// running the script rather than by reading it.
|
|
1402
|
-
const blamed = /^worktree-audit: cannot read \S*\/([^/ ]+) —/m.exec(r.stderr);
|
|
1403
|
-
assert.ok(blamed, `the refusal must name the library it could not read: ${r.stderr}`);
|
|
1404
|
-
assert.ok(
|
|
1405
|
-
exit2Cell().includes(`\`${blamed[1]}\``),
|
|
1406
|
-
`the spec row must name the library this refusal blames, and does not carry \`${blamed[1]}\`.\ncell: ${exit2Cell()}`,
|
|
1407
|
-
);
|
|
1408
|
-
});
|