@feigi/fleet-ctl 3.23.36 → 3.23.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/main-checkout.mjs +1 -1
- package/scripts/member-write-guard.mjs +1 -1
- package/scripts/repo-root.mjs +1 -1
- package/skills/run-team/references/reaping.md +1 -1
- package/scripts/agent-test-dir-prose.test.mjs +0 -59
- package/scripts/agent-test.test.mjs +0 -1640
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
- package/scripts/ambient-git-vars-prose.test.mjs +0 -192
- package/scripts/ancestry-check-position-prose.test.mjs +0 -175
- package/scripts/apply-ruleset.test.mjs +0 -421
- package/scripts/arg-header-probes-prose.test.mjs +0 -394
- package/scripts/arg.test.mjs +0 -1354
- package/scripts/board-cli.test.mjs +0 -710
- package/scripts/board-identity.test.mjs +0 -429
- package/scripts/board-liveness-banner.test.mjs +0 -119
- package/scripts/board-prev-shape.test.mjs +0 -228
- package/scripts/board-tryparse-null.test.mjs +0 -119
- package/scripts/board.test.mjs +0 -3121
- package/scripts/brief-after-cut-prose.test.mjs +0 -53
- package/scripts/candidates-exit3-prose.test.mjs +0 -302
- package/scripts/candidates.test.mjs +0 -2312
- package/scripts/caveat-unification-prose.test.mjs +0 -98
- package/scripts/cell-readout.test.mjs +0 -615
- package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
- package/scripts/ci-completes-premise-prose.test.mjs +0 -257
- package/scripts/ci-state-prose.test.mjs +0 -113
- package/scripts/ci-state.test.mjs +0 -1933
- package/scripts/ci-vacuous-green.test.mjs +0 -368
- package/scripts/citation-sweep-prose.test.mjs +0 -1712
- package/scripts/claim-lifecycle.test.mjs +0 -187
- package/scripts/claim-ticket.test.mjs +0 -1122
- package/scripts/closing-keyword-prose.test.mjs +0 -193
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
- package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
- package/scripts/compute-board.test.mjs +0 -1214
- package/scripts/compute-spend.test.mjs +0 -517
- package/scripts/consumer-technology-prose.test.mjs +0 -126
- package/scripts/cross-repo-citation-prose.test.mjs +0 -155
- package/scripts/cwd-isolation-pins.mjs +0 -83
- package/scripts/dedupe-guard-prose.test.mjs +0 -243
- package/scripts/delete-merged-branch.test.mjs +0 -576
- package/scripts/derive-testcmd.test.mjs +0 -595
- package/scripts/diff-stats.test.mjs +0 -404
- package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
- package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
- package/scripts/dispositions-check.test.mjs +0 -936
- package/scripts/dispositions-gate-prose.test.mjs +0 -129
- package/scripts/drop-merged-label.test.mjs +0 -479
- package/scripts/exec-stub.mjs +0 -93
- package/scripts/exec-stub.test.mjs +0 -69
- package/scripts/expected-jobs-prose.test.mjs +0 -80
- package/scripts/fan-out-authorization-prose.test.mjs +0 -80
- package/scripts/filing-bar-seat-prose.test.mjs +0 -242
- package/scripts/filing-claim-bar-prose.test.mjs +0 -166
- package/scripts/finisher-died-prose.test.mjs +0 -31
- package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
- package/scripts/finisher-halt-prose.test.mjs +0 -106
- package/scripts/finisher-name-prose.test.mjs +0 -134
- package/scripts/finisher-own-tree-prose.test.mjs +0 -299
- package/scripts/finisher-pin-race-prose.test.mjs +0 -339
- package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
- package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
- package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
- package/scripts/fleet-bootstrap.test.mjs +0 -75
- package/scripts/fleet-heartbeat.test.mjs +0 -450
- package/scripts/fleet-provenance.test.mjs +0 -138
- package/scripts/fleet-run.test.mjs +0 -90
- package/scripts/fleet-state.test.mjs +0 -460
- package/scripts/fleet-tick-prose.test.mjs +0 -300
- package/scripts/fleet-tick.test.mjs +0 -2444
- package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
- package/scripts/frontmatter-check.test.mjs +0 -436
- package/scripts/git-env.test.mjs +0 -149
- package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
- package/scripts/gone-walk.test.mjs +0 -213
- package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
- package/scripts/head-moved-after-label-prose.test.mjs +0 -233
- package/scripts/immutable-body-claim-prose.test.mjs +0 -204
- package/scripts/implementer-model-tier.test.mjs +0 -235
- package/scripts/inflight-citation-prose.test.mjs +0 -144
- package/scripts/inflight-exit2-prose.test.mjs +0 -81
- package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
- package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
- package/scripts/inflight.test.mjs +0 -2882
- package/scripts/injection-control-prose.test.mjs +0 -404
- package/scripts/install-root-audit.test.mjs +0 -464
- package/scripts/instrument-check-prose.test.mjs +0 -235
- package/scripts/instruments.test.mjs +0 -787
- package/scripts/is-cli.test.mjs +0 -99
- package/scripts/issue-tracker-prose.test.mjs +0 -71
- package/scripts/json.test.mjs +0 -364
- package/scripts/ledger-dispatch.test.mjs +0 -927
- package/scripts/ledger-grammar.test.mjs +0 -227
- package/scripts/ledger-read-require-file.test.mjs +0 -197
- package/scripts/ledger-rotate.test.mjs +0 -142
- package/scripts/ledger.test.mjs +0 -3436
- package/scripts/line-distance-prose.test.mjs +0 -245
- package/scripts/liveness-rationale-prose.test.mjs +0 -83
- package/scripts/locale-pin-prose.test.mjs +0 -189
- package/scripts/main-checkout.test.mjs +0 -332
- package/scripts/member-outcome-prose.test.mjs +0 -167
- package/scripts/member-outcomes-header.test.mjs +0 -129
- package/scripts/member-outcomes-prose.test.mjs +0 -63
- package/scripts/member-outcomes.test.mjs +0 -638
- package/scripts/member-prompt-prose.test.mjs +0 -165
- package/scripts/member-record.test.mjs +0 -541
- package/scripts/member-write-guard.test.mjs +0 -214
- package/scripts/merge-commit-probe-prose.test.mjs +0 -122
- package/scripts/merge-gate.test.mjs +0 -613
- package/scripts/muted-git-guard-sweep.test.mjs +0 -493
- package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
- package/scripts/net-watchdog-prose.test.mjs +0 -79
- package/scripts/net.test.mjs +0 -211
- package/scripts/no-ci-gate-prose.test.mjs +0 -108
- package/scripts/no-undo-audit.test.mjs +0 -3961
- package/scripts/no-wave.test.mjs +0 -138
- package/scripts/node-floor-sweep.test.mjs +0 -611
- package/scripts/pointer-target-prose.test.mjs +0 -186
- package/scripts/pr-cost.test.mjs +0 -521
- package/scripts/pr-overlap.test.mjs +0 -692
- package/scripts/printf-die-sweep.test.mjs +0 -384
- package/scripts/prompt-renderer.mjs +0 -40
- package/scripts/prompt-renderer.test.mjs +0 -68
- package/scripts/prose-pin.mjs +0 -807
- package/scripts/prose-pin.test.mjs +0 -1034
- package/scripts/prove-merge.test.mjs +0 -995
- package/scripts/pull-table-relabel-prose.test.mjs +0 -60
- package/scripts/quiet-payload-prose.test.mjs +0 -222
- package/scripts/reap-cherry-check-prose.test.mjs +0 -80
- package/scripts/reap.test.mjs +0 -4432
- package/scripts/reaping-prose.test.mjs +0 -239
- package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
- package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
- package/scripts/recipe-derivation-prose.test.mjs +0 -112
- package/scripts/recipe-prove.test.mjs +0 -1042
- package/scripts/refuter-scratch-prose.test.mjs +0 -135
- package/scripts/release-label-required-prose.test.mjs +0 -71
- package/scripts/release-label-split-prose.test.mjs +0 -184
- package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
- package/scripts/release-ticket.test.mjs +0 -5099
- package/scripts/renovate-release-contract.test.mjs +0 -379
- package/scripts/repo-root.test.mjs +0 -873
- package/scripts/reporter-output-rule-prose.test.mjs +0 -208
- package/scripts/review-agent-report-only.test.mjs +0 -49
- package/scripts/review-core-booking.test.mjs +0 -35
- package/scripts/review-core-cwd-isolation.test.mjs +0 -374
- package/scripts/review-core-reads.test.mjs +0 -478
- package/scripts/review-core-refuter-scratch.test.mjs +0 -148
- package/scripts/review-core-scratch-refusal.test.mjs +0 -64
- package/scripts/review-core-shared-test-run.test.mjs +0 -275
- package/scripts/review-core-snapshot-path.test.mjs +0 -830
- package/scripts/review-core-specialist-scratch.test.mjs +0 -191
- package/scripts/review-core-testcmd.test.mjs +0 -335
- package/scripts/review-core-unrun.test.mjs +0 -566
- package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
- package/scripts/review-eval-resolver-path.test.mjs +0 -55
- package/scripts/review-host-fixture.mjs +0 -89
- package/scripts/review-in-run-retry.test.mjs +0 -211
- package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
- package/scripts/review-path-default.test.mjs +0 -796
- package/scripts/review-runner-spawns.test.mjs +0 -95
- package/scripts/review-runner.test.mjs +0 -166
- package/scripts/review-tier-audit.test.mjs +0 -140
- package/scripts/run-artifact-pr-prose.test.mjs +0 -341
- package/scripts/run-merge-bot-prose.test.mjs +0 -1413
- package/scripts/run-team-local-hook.test.mjs +0 -442
- package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
- package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
- package/scripts/section-between-guard-prose.test.mjs +0 -379
- package/scripts/select-dimensions.test.mjs +0 -674
- package/scripts/shared-refusal.test.mjs +0 -388
- package/scripts/shell-traps-prose.test.mjs +0 -504
- package/scripts/shortlist.test.mjs +0 -380
- package/scripts/slow-transport.mjs +0 -72
- package/scripts/snapshot-repo.test.mjs +0 -1006
- package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
- package/scripts/spend-view.test.mjs +0 -312
- package/scripts/staleness-qualifier-prose.test.mjs +0 -251
- package/scripts/staleness-verdict-prose.test.mjs +0 -142
- package/scripts/staleness.test.mjs +0 -893
- package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
- package/scripts/stash-prohibition-prose.test.mjs +0 -313
- package/scripts/strip-comments.mjs +0 -44
- package/scripts/temp-dir.mjs +0 -47
- package/scripts/ticket-router.test.mjs +0 -981
- package/scripts/tier-check.test.mjs +0 -828
- package/scripts/tier-outcomes-header.test.mjs +0 -518
- package/scripts/tier-outcomes.test.mjs +0 -572
- package/scripts/tier-roles.test.mjs +0 -535
- package/scripts/tracker-block-copy-prose.test.mjs +0 -288
- package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
- package/scripts/unattended-git-sweep.test.mjs +0 -142
- package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
- package/scripts/verify-sha.test.mjs +0 -692
- package/scripts/watcher-degraded-block.test.mjs +0 -369
- package/scripts/watcher-key-prose.test.mjs +0 -106
- package/scripts/within-run-pair-prose.test.mjs +0 -212
- package/scripts/worktree-audit.test.mjs +0 -1408
- package/scripts/worktree-head-prose.test.mjs +0 -276
- package/scripts/worktree-listing-sweep.test.mjs +0 -217
- package/scripts/worktree-model-prose.test.mjs +0 -216
- package/scripts/worktree-porcelain.mjs +0 -35
- package/scripts/worktree-porcelain.test.mjs +0 -102
|
@@ -1,873 +0,0 @@
|
|
|
1
|
-
// The answers repo-root.mjs exists to keep apart, pinned directly rather than
|
|
2
|
-
// through a sub-suite.
|
|
3
|
-
//
|
|
4
|
-
// The sweep suites that import it (muted-git-guard-sweep, unattended-git-sweep,
|
|
5
|
-
// worktree-listing-sweep) skip themselves where there is no ambient working
|
|
6
|
-
// tree, and a skip is an ABSENCE of coverage. Nothing inside a skipped file can
|
|
7
|
-
// pin the condition that skipped it — so the pin lives here, where every answer
|
|
8
|
-
// is reachable in one process: `null` where the root lookup cannot answer, a
|
|
9
|
-
// path where it can, and a throw where it finds a repository whose own git
|
|
10
|
-
// does not TRACK this file (#1339, then twice more in #1354's review).
|
|
11
|
-
// Without the second half the guard could fire everywhere and the whole gate
|
|
12
|
-
// would be silently gone (#1149); without the third, a non-empty wrong root —
|
|
13
|
-
// a DIFFERENT checkout of this same plugin that merely shares its name, or an
|
|
14
|
-
// installed copy sitting untracked inside an ambient repository — would sail
|
|
15
|
-
// through as though it were a real answer.
|
|
16
|
-
//
|
|
17
|
-
// Several tests below need `repoRoot` to answer YES about a fixture, which
|
|
18
|
-
// tracked-ness makes harder to fake than either of the checks tried before
|
|
19
|
-
// it: a fixture has to actually TRACK a copy of repo-root.mjs and its
|
|
20
|
-
// manifest, at the same relative layout this file ships in, and the test
|
|
21
|
-
// then imports THAT copy rather than the module under test.
|
|
22
|
-
// `selfContainedFixture` builds the simple case; the #1339-precise tests
|
|
23
|
-
// build the installed-cache shape by hand.
|
|
24
|
-
//
|
|
25
|
-
// Zero deps: `node --test plugin/scripts/repo-root.test.mjs`.
|
|
26
|
-
|
|
27
|
-
import { test } from "node:test";
|
|
28
|
-
import assert from "node:assert/strict";
|
|
29
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
30
|
-
import {
|
|
31
|
-
chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync,
|
|
32
|
-
} from "node:fs";
|
|
33
|
-
import { tmpdir } from "node:os";
|
|
34
|
-
import { dirname, join, relative } from "node:path";
|
|
35
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
36
|
-
import {
|
|
37
|
-
ownPluginName, repoRoot, skipWithoutRepo, trackedNodeScripts, trackedPaths, trackedShellScripts,
|
|
38
|
-
} from "./repo-root.mjs";
|
|
39
|
-
|
|
40
|
-
const DIR = fileURLToPath(new URL(".", import.meta.url));
|
|
41
|
-
|
|
42
|
-
// This file's own use of the shape it pins. The last test asserts the answer for
|
|
43
|
-
// the tree this file ships in, which is a fact about the ENVIRONMENT, not about
|
|
44
|
-
// the code — so it declines in an extraction exactly as the sweeps do, rather
|
|
45
|
-
// than reporting the missing working tree as a failure. The three tests above it
|
|
46
|
-
// build their own repositories and hold anywhere.
|
|
47
|
-
const SKIP_WITHOUT_REPO = skipWithoutRepo(repoRoot(DIR), "the check on THIS checkout below");
|
|
48
|
-
|
|
49
|
-
// `git init` under an inherited GIT_DIR exits 0 and creates nothing in the
|
|
50
|
-
// target, so a fixture built with the ambient environment can be no repository
|
|
51
|
-
// at all while every status check passes. Scrubbed here, and the fixtures below
|
|
52
|
-
// assert the `.git` they were supposed to create rather than an exit code.
|
|
53
|
-
const ENV = {
|
|
54
|
-
...process.env,
|
|
55
|
-
GIT_DIR: undefined,
|
|
56
|
-
GIT_WORK_TREE: undefined,
|
|
57
|
-
GIT_AUTHOR_NAME: "t",
|
|
58
|
-
GIT_AUTHOR_EMAIL: "t@example.com",
|
|
59
|
-
GIT_COMMITTER_NAME: "t",
|
|
60
|
-
GIT_COMMITTER_EMAIL: "t@example.com",
|
|
61
|
-
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
62
|
-
GIT_CONFIG_SYSTEM: "/dev/null",
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* A directory with no `.git` in it, and no way for git to reach one above it.
|
|
67
|
-
*
|
|
68
|
-
* `GIT_CEILING_DIRECTORIES` set to the PARENT, not to the directory itself:
|
|
69
|
-
* measured, git starts its search in the working directory and only declines to
|
|
70
|
-
* chdir UP into a ceiling entry, so naming the directory itself still lets the
|
|
71
|
-
* walk reach a repository above it — inside a checkout that resolves to the
|
|
72
|
-
* checkout, and the fixture would silently be a repository. Naming the parent is
|
|
73
|
-
* what makes the answer independent of wherever `$TMPDIR` happens to live.
|
|
74
|
-
*/
|
|
75
|
-
function noRepo(t) {
|
|
76
|
-
const dir = realpathSync(mkdtempSync(join(tmpdir(), "repo-root-")));
|
|
77
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
78
|
-
return { dir, env: { ...ENV, GIT_CEILING_DIRECTORIES: dirname(dir) } };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Writes `dir/.claude-plugin/plugin.json` naming the same plugin as this
|
|
83
|
-
* checkout's own — via `ownPluginName()`, not a literal, for the same reason
|
|
84
|
-
* repo-root.mjs itself reads it that way rather than hardcoding "fleet"
|
|
85
|
-
* (#1352 is mid-rename). This alone does NOT make `repoRoot` accept `dir`
|
|
86
|
-
* since #1354: a name match is not containment, and `dir` does not contain
|
|
87
|
-
* this file. That gap is exactly what the same-name-foreign-checkout test
|
|
88
|
-
* below exercises; fixtures that need a root `repoRoot` genuinely accepts use
|
|
89
|
-
* `selfContainedFixture` instead.
|
|
90
|
-
*/
|
|
91
|
-
function ownManifestFixture(dir) {
|
|
92
|
-
mkdirSync(join(dir, ".claude-plugin"), { recursive: true });
|
|
93
|
-
writeFileSync(join(dir, ".claude-plugin", "plugin.json"), JSON.stringify({ name: ownPluginName() }));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* A fixture `repoRoot` can genuinely accept, post-#1354's tracked-ness check:
|
|
98
|
-
* a git repository that TRACKS a copy of repo-root.mjs at the same relative
|
|
99
|
-
* layout this file ships in (`scripts/repo-root.mjs` beside
|
|
100
|
-
* `.claude-plugin/plugin.json`), so the copy's own `import.meta.url` resolves
|
|
101
|
-
* inside the fixture AND `git ls-files --error-unmatch` finds it there.
|
|
102
|
-
*
|
|
103
|
-
* Returns the copy's own exports via dynamic `import()` — the module UNDER
|
|
104
|
-
* TEST (`./repo-root.mjs`) is never itself tracked by a disposable fixture,
|
|
105
|
-
* so asking it to answer for one always fails by construction. Every caller
|
|
106
|
-
* of this fixture is therefore exercising the SAME contract through a
|
|
107
|
-
* second, disposable instance of the module rather than a special case.
|
|
108
|
-
*/
|
|
109
|
-
async function selfContainedFixture(t) {
|
|
110
|
-
const { dir } = noRepo(t);
|
|
111
|
-
const scriptsDir = join(dir, "scripts");
|
|
112
|
-
mkdirSync(scriptsDir, { recursive: true });
|
|
113
|
-
copyFileSync(join(DIR, "repo-root.mjs"), join(scriptsDir, "repo-root.mjs"));
|
|
114
|
-
copyFileSync(join(DIR, "git-env.mjs"), join(scriptsDir, "git-env.mjs"));
|
|
115
|
-
ownManifestFixture(dir);
|
|
116
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
117
|
-
assert.ok(existsSync(join(dir, ".git")), "fixture was not initialised as a repository");
|
|
118
|
-
// Staged is enough for `git ls-files --error-unmatch` (measured) — no
|
|
119
|
-
// commit needed, and *.sh stays untracked either way since this fixture
|
|
120
|
-
// never writes any.
|
|
121
|
-
execFileSync("git", ["add", "-A"], { cwd: dir, env: ENV });
|
|
122
|
-
const mod = await import(pathToFileURL(join(scriptsDir, "repo-root.mjs")).href);
|
|
123
|
-
return { dir, scriptsDir, repoRoot: mod.repoRoot };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* A foreign git repository with tracked `hooks/x.sh` and `y.sh` — the shape
|
|
128
|
-
* #1339 measured (the operator's own dotfiles, complete with its own
|
|
129
|
-
* unrelated tracked scripts). Returns `{ dir }`; callers add whatever
|
|
130
|
-
* plugin-cache-like structure their scenario needs inside it.
|
|
131
|
-
*/
|
|
132
|
-
function foreignRepoWithTrackedScripts(t) {
|
|
133
|
-
const { dir } = noRepo(t);
|
|
134
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
135
|
-
const hooksDir = join(dir, "hooks");
|
|
136
|
-
mkdirSync(hooksDir);
|
|
137
|
-
writeFileSync(join(hooksDir, "x.sh"), "#!/bin/sh\n");
|
|
138
|
-
writeFileSync(join(dir, "y.sh"), "#!/bin/sh\n");
|
|
139
|
-
execFileSync("git", ["add", "hooks/x.sh", "y.sh"], { cwd: dir, env: ENV });
|
|
140
|
-
execFileSync("git", ["commit", "-q", "-m", "tracked scripts"], { cwd: dir, env: ENV });
|
|
141
|
-
assert.deepEqual(
|
|
142
|
-
execFileSync("git", ["ls-files", "*.sh"], { cwd: dir, encoding: "utf8" }).trim().split("\n").sort(),
|
|
143
|
-
["hooks/x.sh", "y.sh"],
|
|
144
|
-
"fixture must have exactly the two tracked scripts #1339 measured, or the old guard's non-emptiness isn't exercised",
|
|
145
|
-
);
|
|
146
|
-
return { dir };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Copies THIS checkout's own `scripts/repo-root.mjs` and
|
|
151
|
-
* `.claude-plugin/plugin.json` into
|
|
152
|
-
* `<foreignRoot>/plugins/cache/mkt/fleet/0.1.1/{scripts,.claude-plugin}` —
|
|
153
|
-
* the exact layout an installed plugin's cache directory takes (#1339's own
|
|
154
|
-
* measured shape, pre-cutover: `plugins/cache/fleet-plugin/fleet/0.1.1/...`
|
|
155
|
-
* under the operator's dotfiles checkout).
|
|
156
|
-
*
|
|
157
|
-
* `tracked` decides whether the copy is committed into `foreignRoot`'s own
|
|
158
|
-
* index. `false` is the real #1339 shape: a cache directory that ships
|
|
159
|
-
* ALONGSIDE the ambient repository's tracked tree, never inside it. `true` is
|
|
160
|
-
* what happens the moment that copy IS committed there — it stops being a
|
|
161
|
-
* foreign file and becomes genuinely that repository's own.
|
|
162
|
-
*/
|
|
163
|
-
function installedCacheCopy(foreignRoot, { tracked }) {
|
|
164
|
-
const payloadDir = join(foreignRoot, "plugins", "cache", "mkt", "fleet", "0.1.1");
|
|
165
|
-
const scriptsDir = join(payloadDir, "scripts");
|
|
166
|
-
mkdirSync(scriptsDir, { recursive: true });
|
|
167
|
-
mkdirSync(join(payloadDir, ".claude-plugin"), { recursive: true });
|
|
168
|
-
copyFileSync(join(DIR, "repo-root.mjs"), join(scriptsDir, "repo-root.mjs"));
|
|
169
|
-
copyFileSync(join(DIR, "git-env.mjs"), join(scriptsDir, "git-env.mjs"));
|
|
170
|
-
copyFileSync(join(DIR, "..", ".claude-plugin", "plugin.json"), join(payloadDir, ".claude-plugin", "plugin.json"));
|
|
171
|
-
if (tracked) {
|
|
172
|
-
execFileSync("git", ["add", "-A", "plugins"], { cwd: foreignRoot, env: ENV });
|
|
173
|
-
execFileSync("git", ["commit", "-q", "-m", "vendor the plugin payload"], { cwd: foreignRoot, env: ENV });
|
|
174
|
-
}
|
|
175
|
-
return scriptsDir;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Writes each of `files` (repo-relative, parent directories created) under
|
|
180
|
-
* `dir` and stages it — empty, or `contents[file]` where the caller names one.
|
|
181
|
-
* Staged is enough for `git ls-files` (the same measurement
|
|
182
|
-
* `selfContainedFixture` relies on), so no commit.
|
|
183
|
-
*/
|
|
184
|
-
function track(dir, files, contents = {}) {
|
|
185
|
-
for (const f of files) {
|
|
186
|
-
mkdirSync(dirname(join(dir, f)), { recursive: true });
|
|
187
|
-
writeFileSync(join(dir, f), contents[f] ?? "");
|
|
188
|
-
}
|
|
189
|
-
execFileSync("git", ["add", "--", ...files], { cwd: dir, env: ENV });
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* A git repository tracking `files` (written as `track` writes them), plus an
|
|
194
|
-
* UNTRACKED `scratch.mjs` at its top — a module nobody committed is not what
|
|
195
|
-
* ships, so it is on disk for a directory walk to find and must never reach
|
|
196
|
-
* an answer. Returns `{ dir }`.
|
|
197
|
-
*/
|
|
198
|
-
function repoTracking(t, files, contents = {}) {
|
|
199
|
-
const { dir } = noRepo(t);
|
|
200
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
201
|
-
assert.ok(existsSync(join(dir, ".git")), "fixture was not initialised as a repository");
|
|
202
|
-
track(dir, files, contents);
|
|
203
|
-
writeFileSync(join(dir, "scratch.mjs"), "");
|
|
204
|
-
return { dir };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
test("repoRoot answers null where there is no ambient working tree", (t) => {
|
|
208
|
-
const { dir, env } = noRepo(t);
|
|
209
|
-
// The fixture first, or the assertion below could pass over a directory that
|
|
210
|
-
// is a repository for some unrelated reason.
|
|
211
|
-
const probe = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd: dir, env, encoding: "utf8" });
|
|
212
|
-
assert.equal(probe.status, 128,
|
|
213
|
-
`the fixture is not repo-less — git answered ${JSON.stringify(probe.stdout)} at status ${probe.status}`);
|
|
214
|
-
|
|
215
|
-
// `repoRoot` reads the ambient environment, which is the whole point of it, so
|
|
216
|
-
// the ceiling has to be ambient too for the fixture to hold here. Restored
|
|
217
|
-
// afterwards — the last test in this file asserts the opposite answer in this
|
|
218
|
-
// very checkout, and a leaked ceiling would make it pass for the wrong reason.
|
|
219
|
-
const saved = ["GIT_CEILING_DIRECTORIES", "GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
220
|
-
t.after(() => {
|
|
221
|
-
for (const [k, v] of saved) {
|
|
222
|
-
if (v === undefined) delete process.env[k];
|
|
223
|
-
else process.env[k] = v;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
process.env.GIT_CEILING_DIRECTORIES = dirname(dir);
|
|
227
|
-
delete process.env.GIT_DIR;
|
|
228
|
-
delete process.env.GIT_WORK_TREE;
|
|
229
|
-
|
|
230
|
-
assert.equal(repoRoot(dir), null, "no ambient working tree must answer null, not throw and not a path");
|
|
231
|
-
assert.equal(typeof skipWithoutRepo(repoRoot(dir), "the tests"), "string",
|
|
232
|
-
"and that is the one condition that produces a skip reason");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("repoRoot answers the root where there IS one, and skipWithoutRepo then declines to skip", async (t) => {
|
|
236
|
-
// Since #1354, a bare `git init` plus a matching manifest is not enough —
|
|
237
|
-
// repoRoot also checks TRACKED-NESS, so the fixture has to actually track
|
|
238
|
-
// a copy of the module being asked about.
|
|
239
|
-
const { dir, scriptsDir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
240
|
-
|
|
241
|
-
const root = fixtureRepoRoot(scriptsDir);
|
|
242
|
-
assert.equal(root, dir);
|
|
243
|
-
assert.equal(skipWithoutRepo(root, "the tests"), false,
|
|
244
|
-
"a working tree that answers must never skip — that is the condition the sweeps are for");
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// #1599: repo-root.mjs's three git calls (isTrackedBy, repoRoot's own
|
|
248
|
-
// rev-parse, trackedShellScripts) passed no env at all before this fix, and
|
|
249
|
-
// #1020's own census could not see any of them — its scan is `.sh`-only.
|
|
250
|
-
// Measured directly against this file: an ambient GIT_DIR or GIT_WORK_TREE
|
|
251
|
-
// (a git hook, `rebase --exec`, `bisect run`) corrupts each call in its own
|
|
252
|
-
// distinct way, silently, at exit 0. The four fixtures below isolate each
|
|
253
|
-
// one, and a fifth reaches the third again through `trackedNodeScripts`;
|
|
254
|
-
// `noRepo(t)` doubles as "give me a disposable real repository" here,
|
|
255
|
-
// since none of them needs a repo-LESS fixture.
|
|
256
|
-
test("repoRoot()'s own rev-parse: an inherited GIT_WORK_TREE substitutes a foreign toplevel for the caller's own", async (t) => {
|
|
257
|
-
const { dir, scriptsDir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
258
|
-
const { dir: otherRepo } = noRepo(t);
|
|
259
|
-
execFileSync("git", ["init", "-q", "-b", "main", otherRepo], { env: ENV });
|
|
260
|
-
|
|
261
|
-
const saved = ["GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
262
|
-
t.after(() => { for (const [k, v] of saved) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } });
|
|
263
|
-
delete process.env.GIT_DIR;
|
|
264
|
-
process.env.GIT_WORK_TREE = otherRepo;
|
|
265
|
-
|
|
266
|
-
assert.equal(fixtureRepoRoot(scriptsDir), dir,
|
|
267
|
-
"an ambient GIT_WORK_TREE must not answer --show-toplevel with a DIFFERENT repository — measured: unscrubbed, this call returns the ambient path itself");
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
test("repoRoot()'s own rev-parse: an inherited GIT_DIR alone answers with cwd itself, not the tree's real root", async (t) => {
|
|
271
|
-
// GIT_DIR set with no GIT_WORK_TREE makes git assume the CURRENT directory
|
|
272
|
-
// is the top level — measured, called from a subdirectory (scriptsDir, the
|
|
273
|
-
// realistic shape: this function's caller is rarely sitting at the tree's
|
|
274
|
-
// own root) this answers with scriptsDir itself, not dir.
|
|
275
|
-
const { dir, scriptsDir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
276
|
-
const { dir: otherRepo } = noRepo(t);
|
|
277
|
-
execFileSync("git", ["init", "-q", "-b", "main", otherRepo], { env: ENV });
|
|
278
|
-
|
|
279
|
-
const saved = ["GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
280
|
-
t.after(() => { for (const [k, v] of saved) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } });
|
|
281
|
-
process.env.GIT_DIR = join(otherRepo, ".git");
|
|
282
|
-
delete process.env.GIT_WORK_TREE;
|
|
283
|
-
|
|
284
|
-
assert.equal(fixtureRepoRoot(scriptsDir), dir,
|
|
285
|
-
"an ambient GIT_DIR must not answer --show-toplevel with cwd unresolved to the tree's real root");
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
test("assertOwnRoot's tracked-ness check: an inherited GIT_DIR must not make isTrackedBy answer falsely for the caller's own tracked file", async (t) => {
|
|
289
|
-
// Called at the tree's OWN root (not a subdirectory), so the rev-parse
|
|
290
|
-
// half above answers correctly regardless of this fix — measured, an
|
|
291
|
-
// ambient GIT_DIR alone leaves --show-toplevel unaffected when cwd is
|
|
292
|
-
// already the toplevel. That isolates the SECOND git call repoRoot makes,
|
|
293
|
-
// isTrackedBy() inside assertOwnRoot, from the first: unscrubbed, `git
|
|
294
|
-
// ls-files --error-unmatch` under this ambient GIT_DIR answers for the
|
|
295
|
-
// OTHER repository's index, so a file this plugin's own git genuinely
|
|
296
|
-
// tracks comes back "did not match any files" — a false negative that
|
|
297
|
-
// makes repoRoot() throw on its own legitimate root.
|
|
298
|
-
const { dir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
299
|
-
const { dir: otherRepo } = noRepo(t);
|
|
300
|
-
execFileSync("git", ["init", "-q", "-b", "main", otherRepo], { env: ENV });
|
|
301
|
-
|
|
302
|
-
const saved = ["GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
303
|
-
t.after(() => { for (const [k, v] of saved) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } });
|
|
304
|
-
process.env.GIT_DIR = join(otherRepo, ".git");
|
|
305
|
-
delete process.env.GIT_WORK_TREE;
|
|
306
|
-
|
|
307
|
-
assert.equal(fixtureRepoRoot(dir), dir,
|
|
308
|
-
"an ambient GIT_DIR must not make the tracked-ness check refuse this plugin's own root");
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
test("trackedShellScripts: an inherited GIT_DIR must not substitute another repository's tracked *.sh list for this one", (t) => {
|
|
312
|
-
const { dir } = foreignRepoWithTrackedScripts(t);
|
|
313
|
-
const { dir: otherRepo } = noRepo(t);
|
|
314
|
-
execFileSync("git", ["init", "-q", "-b", "main", otherRepo], { env: ENV });
|
|
315
|
-
|
|
316
|
-
const saved = ["GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
317
|
-
t.after(() => { for (const [k, v] of saved) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } });
|
|
318
|
-
process.env.GIT_DIR = join(otherRepo, ".git");
|
|
319
|
-
delete process.env.GIT_WORK_TREE;
|
|
320
|
-
|
|
321
|
-
assert.deepEqual(trackedShellScripts(dir).sort(), ["hooks/x.sh", "y.sh"],
|
|
322
|
-
"an ambient GIT_DIR must not substitute the OTHER repository's tracked *.sh list for this one");
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// The same call reached through the sibling export — both lists come out of
|
|
326
|
-
// one `trackedFiles` — so this pins the scrub for the node-script answer
|
|
327
|
-
// rather than a second site. The other repository tracks a module of its own:
|
|
328
|
-
// the realistic shape (a hook's GIT_DIR names a repository with files in it),
|
|
329
|
-
// and the one where the substituted list is non-empty, i.e. the one a caller's
|
|
330
|
-
// non-vacuity guard lets through. No GIT_WORK_TREE twin: measured inert for
|
|
331
|
-
// this call (see `trackedFiles`), so a fixture for it could not red.
|
|
332
|
-
test("trackedNodeScripts: an inherited GIT_DIR must not substitute another repository's tracked list for this one", (t) => {
|
|
333
|
-
const { dir } = repoTracking(t, ["a.mjs", "a.test.mjs"]);
|
|
334
|
-
const { dir: otherRepo } = repoTracking(t, ["foreign.mjs"]);
|
|
335
|
-
|
|
336
|
-
const saved = ["GIT_DIR", "GIT_WORK_TREE"].map((k) => [k, process.env[k]]);
|
|
337
|
-
t.after(() => { for (const [k, v] of saved) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } });
|
|
338
|
-
process.env.GIT_DIR = join(otherRepo, ".git");
|
|
339
|
-
delete process.env.GIT_WORK_TREE;
|
|
340
|
-
|
|
341
|
-
assert.deepEqual(trackedNodeScripts(dir), ["a.mjs"],
|
|
342
|
-
"an ambient GIT_DIR must not substitute the OTHER repository's tracked list for this one");
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// The answer itself, for a root repoRoot vouched for: every tracked file the
|
|
346
|
-
// consumer's own `node` executes, and nothing else — a `.mjs` by its
|
|
347
|
-
// extension, any other file by a node shebang on its first line. #1855's own
|
|
348
|
-
// case is `scripts/fleet-tool`, the shape of this repository's extensionless
|
|
349
|
-
// entrypoints (`fleet-run`, `fleet-bootstrap`, `fleet-provenance`), which an
|
|
350
|
-
// extension-only rule never listed. `eval-only.js` is the other half of that
|
|
351
|
-
// ticket: ESM in a `.js` with no shebang, run only by a plugin-runner's own
|
|
352
|
-
// loader and never by plain node — the shape this repo's own retired review
|
|
353
|
-
// workflow script had — so no extension rule may pull it in.
|
|
354
|
-
// Each test file sits beside a shipped module its name extends — one carries a
|
|
355
|
-
// node shebang, and is still a test. `latest.mjs` is the boundary on the other
|
|
356
|
-
// side — it ends in `test.mjs` without being a test file, so a rule keyed on
|
|
357
|
-
// that looser suffix drops a shipped module — and the untracked `scratch.mjs`
|
|
358
|
-
// and `scratch-tool` are what a directory walk standing in for git would
|
|
359
|
-
// wrongly add.
|
|
360
|
-
test("trackedNodeScripts answers the shipped node-script set for a verified root — .mjs and node-shebang files, test files excluded", async (t) => {
|
|
361
|
-
const { dir, scriptsDir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
362
|
-
track(dir, [
|
|
363
|
-
"scripts/latest.mjs", "scripts/lib/deep.mjs", "scripts/repo-root.test.mjs", "scripts/lib/deep.test.mjs",
|
|
364
|
-
"scripts/fleet-tool", "workflows/eval-only.js",
|
|
365
|
-
], {
|
|
366
|
-
"scripts/lib/deep.test.mjs": "#!/usr/bin/env node\n",
|
|
367
|
-
"scripts/fleet-tool": "#!/usr/bin/env node\n\"use strict\";\n",
|
|
368
|
-
"workflows/eval-only.js": "export const meta = {};\n",
|
|
369
|
-
});
|
|
370
|
-
writeFileSync(join(scriptsDir, "scratch.mjs"), "");
|
|
371
|
-
writeFileSync(join(scriptsDir, "scratch-tool"), "#!/usr/bin/env node\n");
|
|
372
|
-
|
|
373
|
-
const root = fixtureRepoRoot(scriptsDir);
|
|
374
|
-
assert.equal(root, dir);
|
|
375
|
-
assert.deepEqual(trackedNodeScripts(root).sort(),
|
|
376
|
-
["scripts/fleet-tool", "scripts/git-env.mjs", "scripts/latest.mjs", "scripts/lib/deep.mjs", "scripts/repo-root.mjs"],
|
|
377
|
-
"the shipped set is every tracked *.mjs and node-shebang file, at any depth, less the *.test.mjs beside them");
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
// Which first lines hand a file to node. Through `env`, through `env -S` with
|
|
381
|
-
// the interpreter's own flags, through an `env` option that takes its OWN
|
|
382
|
-
// following bare argument (`-u FOO`, `--unset FOO`, `-C DIR`, `--chdir DIR`)
|
|
383
|
-
// rather than being the command itself, and by a direct interpreter path are
|
|
384
|
-
// all node, whatever the file's extension; `sh`, `bun` and `nodemon` are
|
|
385
|
-
// other programs — including where reached past an `-u`/`--unset`/`-C`/
|
|
386
|
-
// `--chdir` argument, which does not make the command after it any less "not
|
|
387
|
-
// node", and including where a flag that takes NO argument of its own
|
|
388
|
-
// (`-S`, `-i`) is immediately followed by a non-node command that is itself
|
|
389
|
-
// followed by the word `node` — that flag must not swallow the real command
|
|
390
|
-
// as if it were its own argument and let the non-node interpreter through. A
|
|
391
|
-
// shebang that is not the FIRST line is no shebang at all. An empty file,
|
|
392
|
-
// and one with no shebang, are simply not scripts.
|
|
393
|
-
test("trackedNodeScripts reads a non-.mjs file's first line: node by any shebang spelling, nothing else", (t) => {
|
|
394
|
-
const node = {
|
|
395
|
-
"bin/env": "#!/usr/bin/env node\n",
|
|
396
|
-
"bin/env-flags": "#!/usr/bin/env -S node --no-warnings\n",
|
|
397
|
-
"bin/env-assign": "#!/usr/bin/env FOO=bar node\n",
|
|
398
|
-
"bin/env-unset": "#!/usr/bin/env -u FOO node\n",
|
|
399
|
-
"bin/env-unset-long": "#!/usr/bin/env --unset FOO node\n",
|
|
400
|
-
"bin/env-unset-multi": "#!/usr/bin/env -u FOO -u BAR node\n",
|
|
401
|
-
"bin/env-chdir": "#!/usr/bin/env -C DIR node\n",
|
|
402
|
-
"bin/env-chdir-long": "#!/usr/bin/env --chdir DIR node\n",
|
|
403
|
-
"bin/direct": "#!/usr/local/bin/node\n",
|
|
404
|
-
"bin/hook.js": "#!/usr/bin/env node\n",
|
|
405
|
-
};
|
|
406
|
-
const other = {
|
|
407
|
-
"bin/check.sh": "#!/bin/sh\n",
|
|
408
|
-
"bin/bun-tool": "#!/usr/bin/env bun\n",
|
|
409
|
-
"bin/watch": "#!/usr/bin/env nodemon\n",
|
|
410
|
-
"bin/env-unset-other": "#!/usr/bin/env -u FOO bun\n",
|
|
411
|
-
"bin/env-split-other": "#!/usr/bin/env -S bun node\n",
|
|
412
|
-
"bin/env-ignore-other": "#!/usr/bin/env -i sh node\n",
|
|
413
|
-
"docs/notes.md": "# notes\n#!/usr/bin/env node\n",
|
|
414
|
-
"LICENSE": "MIT\n",
|
|
415
|
-
"bin/empty": "",
|
|
416
|
-
};
|
|
417
|
-
const files = { ...node, ...other };
|
|
418
|
-
const { dir } = repoTracking(t, Object.keys(files), files);
|
|
419
|
-
|
|
420
|
-
assert.deepEqual(trackedNodeScripts(dir).sort(), Object.keys(node).sort(),
|
|
421
|
-
"exactly the files whose first line runs node — no other interpreter, no later line, no extension rule");
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
// A first line is judged WHOLE, up to its cap (next test) — never on the
|
|
425
|
-
// prefix one fixed read of it holds (#1887). The first read is 256 bytes
|
|
426
|
-
// (`SHEBANG_BYTES`), and a verdict taken on those bytes alone parts from the
|
|
427
|
-
// whole line's both ways: a `node` past the cut goes unseen; `nodemon` cut
|
|
428
|
-
// right after its `node` reads as `node` at the end of the line, a false
|
|
429
|
-
// accept; and a two-byte character cut in half decodes to U+FFFD, so the
|
|
430
|
-
// character after `node` is no longer the one the file has. Each long line
|
|
431
|
-
// pads an `env -S` assignment so its tail starts at a chosen byte. That last
|
|
432
|
-
// case is pinned against its own short twin rather than to a verdict of its
|
|
433
|
-
// own: whether U+00A0 separates `node` from its flags is NODE_SHEBANG's call,
|
|
434
|
-
// and the cut must not change it. `short/node-at-eof` is a first line the END
|
|
435
|
-
// of the file closes, no newline, and git lists it right after `short/nbsp`,
|
|
436
|
-
// whose longer line leaves a newline in the read buffer past its last byte:
|
|
437
|
-
// that buffer is reused from file to file, so a newline search that ran on
|
|
438
|
-
// past the bytes actually read would end this line on a stale one.
|
|
439
|
-
test("trackedNodeScripts judges a first line whole — never on the prefix its first read holds", (t) => {
|
|
440
|
-
const padded = (at, tail) => {
|
|
441
|
-
const head = "#!/usr/bin/env -S A=";
|
|
442
|
-
return `${head}${"x".repeat(at - head.length - 1)} ${tail}`;
|
|
443
|
-
};
|
|
444
|
-
const files = {
|
|
445
|
-
"long/node": padded(300, "node --no-warnings\n// a later line\n"),
|
|
446
|
-
"long/node-at-eof": padded(1000, "node"),
|
|
447
|
-
"cut/nodemon": padded(252, "nodemon\n"),
|
|
448
|
-
"cut/nbsp": padded(251, "node\u00a0--no-warnings\n"),
|
|
449
|
-
"short/nbsp": "#!/usr/bin/env -S node\u00a0--no-warnings\n",
|
|
450
|
-
"short/node-at-eof": "#!/usr/bin/env node",
|
|
451
|
-
};
|
|
452
|
-
assert.equal(Buffer.from(files["cut/nodemon"]).indexOf("nodemon") + "node".length, 256,
|
|
453
|
-
"fixture: `cut/nodemon`'s `node` must end exactly at byte 256");
|
|
454
|
-
assert.equal(Buffer.from(files["cut/nbsp"]).indexOf(0xc2), 255,
|
|
455
|
-
"fixture: `cut/nbsp`'s U+00A0 must straddle byte 256");
|
|
456
|
-
const { dir } = repoTracking(t, Object.keys(files), files);
|
|
457
|
-
|
|
458
|
-
const listed = trackedNodeScripts(dir);
|
|
459
|
-
assert.equal(listed.includes("cut/nbsp"), listed.includes("short/nbsp"),
|
|
460
|
-
"a character cut in half by the first read must not change the verdict the whole line gets");
|
|
461
|
-
assert.deepEqual(listed.filter((f) => !f.endsWith("/nbsp")).sort(), ["long/node", "long/node-at-eof", "short/node-at-eof"],
|
|
462
|
-
"a node shebang past the first read is still one, and a `nodemon` the read cuts after its `node` is still not");
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
// A first line is read no further than 4096 bytes (`SHEBANG_MAX_BYTES`), and
|
|
466
|
-
// one that reaches the cap is not a node shebang (#1941): read to its end
|
|
467
|
-
// however long, a tracked `#!` file holding no newline was read into memory
|
|
468
|
-
// whole to answer one boolean. The cap is not a verdict on the bytes before it
|
|
469
|
-
// — every line here names node well inside its first read — so a line one byte
|
|
470
|
-
// short of the cap is still judged whole, closed by a newline or by the end of
|
|
471
|
-
// the file alike, and one that reaches it is refused either way.
|
|
472
|
-
test("trackedNodeScripts reads a first line no further than its cap — one that reaches it is not a node shebang", (t) => {
|
|
473
|
-
const line = (bytes) => {
|
|
474
|
-
const head = "#!/usr/bin/env -S node --title=";
|
|
475
|
-
return `${head}${"x".repeat(bytes - head.length)}`;
|
|
476
|
-
};
|
|
477
|
-
const files = {
|
|
478
|
-
"under/node": `${line(4095)}\n`,
|
|
479
|
-
"under/node-at-eof": line(4095),
|
|
480
|
-
"at/node": `${line(4096)}\n`,
|
|
481
|
-
"at/node-at-eof": line(4096),
|
|
482
|
-
};
|
|
483
|
-
assert.equal(Buffer.byteLength(line(4096)), 4096, "fixture: `line(n)` must be exactly n bytes");
|
|
484
|
-
const { dir } = repoTracking(t, Object.keys(files), files);
|
|
485
|
-
|
|
486
|
-
assert.deepEqual(trackedNodeScripts(dir).sort(), ["under/node", "under/node-at-eof"],
|
|
487
|
-
"a first line one byte short of the cap is judged whole; one that reaches it is not a node shebang");
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
// A tracked path the working tree holds no regular file at has no text for a
|
|
491
|
-
// sweep to read: an `rm` or `mv` not yet committed, a dangling symlink, a
|
|
492
|
-
// symlink that loops (ELOOP — no reader can ever open a file there, #1950), a
|
|
493
|
-
// directory where a file is tracked (a symlink to one, or a submodule's gitlink
|
|
494
|
-
// checked out on disk), and a file standing where a tracked path's own
|
|
495
|
-
// directory was. Every export passes over it, and none may throw: each sweep
|
|
496
|
-
// lists at module scope, so a throw here fails that whole file before any of
|
|
497
|
-
// its tests run (#1950), and it then reads every path it was handed, and one
|
|
498
|
-
// listed absent path aborted that read with a raw ENOENT — every real hit in
|
|
499
|
-
// every other file went unreported (#1910). A symlink to a regular file is the
|
|
500
|
-
// ACCEPT half: its text is there to read.
|
|
501
|
-
test("every export passes over a tracked path the working tree holds no regular file at", (t) => {
|
|
502
|
-
const { dir } = repoTracking(t, ["kept.sh", "kept.mjs", "NOTES", "gone.sh", "gone.mjs", "gone", "now-a-dir.sh", "was-a-dir/x.sh"]);
|
|
503
|
-
// Each link and what it names. Self-referential, and a two-link cycle: each
|
|
504
|
-
// resolves to itself forever. The extensionless one is what
|
|
505
|
-
// `trackedNodeScripts` would open to read a shebang from, where a `.mjs` is
|
|
506
|
-
// listed by its extension alone.
|
|
507
|
-
const links = {
|
|
508
|
-
"link-to-file.sh": "kept.sh", "dangling.sh": "nowhere.sh",
|
|
509
|
-
"loop.sh": "loop.sh", "loop.mjs": "loop.mjs", "loop": "loop",
|
|
510
|
-
"cycle-a.sh": "cycle-b.sh", "cycle-b.sh": "cycle-a.sh",
|
|
511
|
-
};
|
|
512
|
-
for (const [link, target] of Object.entries(links)) symlinkSync(target, join(dir, link));
|
|
513
|
-
execFileSync("git", ["add", "--", ...Object.keys(links)], { cwd: dir, env: ENV });
|
|
514
|
-
for (const f of ["gone.sh", "gone.mjs", "gone", "now-a-dir.sh"]) rmSync(join(dir, f));
|
|
515
|
-
mkdirSync(join(dir, "now-a-dir.sh"));
|
|
516
|
-
rmSync(join(dir, "was-a-dir"), { recursive: true });
|
|
517
|
-
writeFileSync(join(dir, "was-a-dir"), "");
|
|
518
|
-
|
|
519
|
-
assert.deepEqual(trackedPaths(dir).sort(), ["NOTES", "kept.mjs", "kept.sh", "link-to-file.sh"],
|
|
520
|
-
"every tracked path with a regular file behind it, and none of the paths without one");
|
|
521
|
-
assert.deepEqual(trackedShellScripts(dir).sort(), ["kept.sh", "link-to-file.sh"],
|
|
522
|
-
"the shell-script answer passes over the same absent paths");
|
|
523
|
-
assert.deepEqual(trackedNodeScripts(dir), ["kept.mjs"],
|
|
524
|
-
"the node-script answer passes over them too — an absent `.mjs` included, which its extension alone once listed");
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// The other side of that line, and what widening it would silently cost: a
|
|
528
|
-
// tracked path the probe could not LOOK at is not an answer about it — #1149's
|
|
529
|
-
// rule, the one `repoRoot` keeps below. A directory the reader may not search
|
|
530
|
-
// hides a file that may well be there and ship, so passing over it would drop
|
|
531
|
-
// it from every sweep with nothing to say so. Every export throws instead,
|
|
532
|
-
// naming the path; in a sweep that lands at module load, which is where
|
|
533
|
-
// `repoRoot`'s own "could not answer" lands too (#1950). Declines under root
|
|
534
|
-
// for the reason the unreadable-`.git` test below gives.
|
|
535
|
-
test("every export throws for a tracked path it could not look at — never passes over it", (t) => {
|
|
536
|
-
if (process.getuid?.() === 0) return t.skip("root reads every directory");
|
|
537
|
-
|
|
538
|
-
const { dir } = repoTracking(t, ["kept.sh", "locked/x.sh"]);
|
|
539
|
-
const locked = join(dir, "locked");
|
|
540
|
-
chmodSync(locked, 0o000);
|
|
541
|
-
try {
|
|
542
|
-
const couldNotLook = { code: "EACCES", path: join(locked, "x.sh") };
|
|
543
|
-
assert.throws(() => trackedPaths(dir), couldNotLook, "a path nobody could look at is not one with no file behind it");
|
|
544
|
-
assert.throws(() => trackedShellScripts(dir), couldNotLook, "the shell-script answer does not pass over it either");
|
|
545
|
-
assert.throws(() => trackedNodeScripts(dir), couldNotLook, "nor does the node-script answer");
|
|
546
|
-
} finally {
|
|
547
|
-
// Before the fixture's own cleanup, which cannot remove what it cannot enter.
|
|
548
|
-
chmodSync(locked, 0o700);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
// The module's second named probe that could not look: ENAMETOOLONG, a tracked
|
|
553
|
-
// file under a path longer than the OS will take whole — every component
|
|
554
|
-
// short, the checkout's path and the tracked one together past the limit
|
|
555
|
-
// (#1973). The file is really there and ships, so every export throws, naming
|
|
556
|
-
// it. The limit is the platform's own (1024 bytes on macOS, 4096 on Linux), so
|
|
557
|
-
// it is found rather than assumed: one short directory at a time until the
|
|
558
|
-
// kernel refuses the next for its length, which puts a file named that
|
|
559
|
-
// directory plus `.sh` past it by construction. The file is written from
|
|
560
|
-
// inside its own directory and tracked by git's plumbing, since
|
|
561
|
-
// `writeFileSync` takes the path whole and `git add` stats the repo-relative
|
|
562
|
-
// one, which under a short enough checkout path is over the limit too.
|
|
563
|
-
//
|
|
564
|
-
// EIO, the third, has no fixture: an I/O error from the device itself takes
|
|
565
|
-
// fault injection — a failing disk, a filesystem that answers EIO — that no
|
|
566
|
-
// unprivileged test can set up. It is reasoned, not executed:
|
|
567
|
-
// NO_REGULAR_FILE_THERE lists the codes that pass, not the ones that throw, so
|
|
568
|
-
// EIO takes the same rethrow the EACCES and ENAMETOOLONG fixtures pin.
|
|
569
|
-
test("every export throws for a tracked path past the OS's path limit — never passes over it", (t) => {
|
|
570
|
-
const { dir } = repoTracking(t, ["kept.sh"]);
|
|
571
|
-
const seg = "d".repeat(100);
|
|
572
|
-
let deepest = dir;
|
|
573
|
-
for (let depth = 0; ; depth++) {
|
|
574
|
-
assert.ok(depth < 100, `fixture: the kernel took a ${deepest.length}-byte path with no ENAMETOOLONG`);
|
|
575
|
-
try {
|
|
576
|
-
mkdirSync(join(deepest, seg));
|
|
577
|
-
} catch (e) {
|
|
578
|
-
if (e.code === "ENAMETOOLONG") break;
|
|
579
|
-
throw e;
|
|
580
|
-
}
|
|
581
|
-
deepest = join(deepest, seg);
|
|
582
|
-
}
|
|
583
|
-
const name = `${seg}.sh`;
|
|
584
|
-
execFileSync("touch", [name], { cwd: deepest });
|
|
585
|
-
try {
|
|
586
|
-
const blob = execFileSync("git", ["hash-object", "-w", "--stdin"], { cwd: dir, env: ENV, input: "", encoding: "utf8" }).trim();
|
|
587
|
-
const cacheinfo = `100644,${blob},${relative(dir, join(deepest, name))}`;
|
|
588
|
-
execFileSync("git", ["update-index", "--add", "--cacheinfo", cacheinfo], { cwd: dir, env: ENV });
|
|
589
|
-
|
|
590
|
-
const tooLong = { code: "ENAMETOOLONG", path: join(deepest, name) };
|
|
591
|
-
assert.throws(() => trackedPaths(dir), tooLong, "a path too long to look at whole is not one with no file behind it");
|
|
592
|
-
assert.throws(() => trackedShellScripts(dir), tooLong, "the shell-script answer does not pass over it either");
|
|
593
|
-
assert.throws(() => trackedNodeScripts(dir), tooLong, "nor does the node-script answer");
|
|
594
|
-
} finally {
|
|
595
|
-
// Before the fixture's own cleanup, which cannot name this file either.
|
|
596
|
-
execFileSync("rm", [name], { cwd: deepest });
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
// The half a skip cannot pin from inside itself, and the exact conflation #1149
|
|
601
|
-
// forbids: a repository with NOTHING matching. `trackedShellScripts` answers an
|
|
602
|
-
// empty list and `skipWithoutRepo` still declines to skip, so the importing
|
|
603
|
-
// sweep runs and its own non-vacuity guard is what fails. A skip here would turn
|
|
604
|
-
// the nested-under-an-unrelated-repo failure into a silent green.
|
|
605
|
-
test("an empty tracked-script list is NOT a skip — the sweep still runs and its guard still judges", async (t) => {
|
|
606
|
-
// The fixture's copy of repo-root.mjs and its manifest ARE tracked (the
|
|
607
|
-
// identity check needs that), but no *.sh file is — trackedShellScripts
|
|
608
|
-
// reads a disjoint glob, so its list stays empty regardless.
|
|
609
|
-
const { dir, scriptsDir, repoRoot: fixtureRepoRoot } = await selfContainedFixture(t);
|
|
610
|
-
|
|
611
|
-
const root = fixtureRepoRoot(scriptsDir);
|
|
612
|
-
assert.notEqual(root, null);
|
|
613
|
-
assert.deepEqual(trackedShellScripts(root), [], "a repository with no tracked shell scripts lists none");
|
|
614
|
-
assert.equal(skipWithoutRepo(root, "the tests"), false,
|
|
615
|
-
"an empty match list inside this plugin's own tree is a broken glob or path join, "
|
|
616
|
-
+ "and must reach the caller's guard as a FAILURE");
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
// The sibling's empty answer: a repository whose only tracked `.mjs` are test
|
|
620
|
-
// files, and whose only other file runs `sh`, ships no node script, and says so
|
|
621
|
-
// with `[]` — not `null`, not a throw, not a skip. Judging that emptiness is
|
|
622
|
-
// the importing sweep's non-vacuity guard's job, exactly as for the shell list
|
|
623
|
-
// above. The untracked `scratch.mjs` beside them keeps "none tracked" from
|
|
624
|
-
// passing for "none on disk".
|
|
625
|
-
test("trackedNodeScripts: a repository that ships no node script answers an empty list, not a skip", (t) => {
|
|
626
|
-
const { dir } = repoTracking(t, ["a.test.mjs", "lib/b.test.mjs", "run.sh"], { "run.sh": "#!/bin/sh\n" });
|
|
627
|
-
|
|
628
|
-
assert.deepEqual(trackedNodeScripts(dir), [], "a repository with only test *.mjs and a sh script tracked ships none");
|
|
629
|
-
assert.equal(skipWithoutRepo(dir, "the tests"), false,
|
|
630
|
-
"an empty match list inside a real repository is a broken glob or path join, "
|
|
631
|
-
+ "and must reach the caller's guard as a FAILURE");
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
// #1339's measured shape, broadly: a foreign git repository (the operator's
|
|
635
|
-
// own dotfiles, in the field) with tracked *.sh files, and inside it a
|
|
636
|
-
// directory that looks like an installed plugin's own scripts/ — no .git, no
|
|
637
|
-
// copy of repo-root.mjs at all — so the discovery walk that starts there
|
|
638
|
-
// lands on the foreign root. Before the fix, repoRoot returned that root
|
|
639
|
-
// because its only guard was non-vacuity, and the foreign repo's tracked
|
|
640
|
-
// scripts are a non-empty list; the caller's own non-vacuity guard never even
|
|
641
|
-
// got a chance to be wrong, because there was nothing vacuous about the
|
|
642
|
-
// answer.
|
|
643
|
-
//
|
|
644
|
-
// Measured against the pre-fix repoRoot (this file's repo-root.mjs copied to
|
|
645
|
-
// a scratch path before this commit and imported from there — `git stash` is
|
|
646
|
-
// forbidden by this repo's convention): `node prefix-repro.mjs` against that
|
|
647
|
-
// copy printed `BUG REPRODUCED: repoRoot did NOT throw. root =
|
|
648
|
-
// /private/var/.../repo-root-foreign-fhzHMH` and `trackedShellScripts(root) =
|
|
649
|
-
// [ 'hooks/x.sh', 'y.sh' ]` — the assertion below would have failed against
|
|
650
|
-
// it. Against the fixed repoRoot below: PASSES, and the thrown message names
|
|
651
|
-
// the foreign root and the file it does not track.
|
|
652
|
-
test("a foreign git repository with tracked scripts is refused, not returned — #1339", (t) => {
|
|
653
|
-
const { dir: foreignRoot } = foreignRepoWithTrackedScripts(t);
|
|
654
|
-
|
|
655
|
-
// The plugin-cache-like nested directory: no .git, no copy of this module,
|
|
656
|
-
// exactly what an installed copy's PARENT looks like when it lands inside
|
|
657
|
-
// an ambient working tree that is not its own (the shape #1339 measured,
|
|
658
|
-
// pre-cutover, under the operator's dotfiles checkout). The more precise
|
|
659
|
-
// test below places an actual copy of this file there and asks IT about
|
|
660
|
-
// itself.
|
|
661
|
-
const nested = join(foreignRoot, "plugins", "cache", "fleet-plugin", "fleet", "0.1.1", "scripts");
|
|
662
|
-
mkdirSync(nested, { recursive: true });
|
|
663
|
-
|
|
664
|
-
const saved = process.env.GIT_CEILING_DIRECTORIES;
|
|
665
|
-
t.after(() => {
|
|
666
|
-
if (saved === undefined) delete process.env.GIT_CEILING_DIRECTORIES;
|
|
667
|
-
else process.env.GIT_CEILING_DIRECTORIES = saved;
|
|
668
|
-
});
|
|
669
|
-
process.env.GIT_CEILING_DIRECTORIES = dirname(foreignRoot);
|
|
670
|
-
|
|
671
|
-
assert.throws(
|
|
672
|
-
() => repoRoot(nested),
|
|
673
|
-
(err) => err instanceof Error && err.message.includes(foreignRoot) && /does not TRACK/.test(err.message),
|
|
674
|
-
"a wrong root that is non-empty must be refused as loudly as an empty one — #1339",
|
|
675
|
-
);
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
// #1339's shape, PRECISELY: not merely "some foreign repo with tracked
|
|
679
|
-
// scripts" but the actual installed-cache layout — a real copy of THIS file
|
|
680
|
-
// at `plugins/cache/mkt/fleet/0.1.1/scripts/repo-root.mjs`, UNTRACKED by the
|
|
681
|
-
// ambient repository it happens to sit inside (a cache directory is never
|
|
682
|
-
// committed there). This is the exact configuration #1339 measured,
|
|
683
|
-
// pre-cutover, under the operator's dotfiles checkout: self genuinely lives
|
|
684
|
-
// inside the foreign repository — so a
|
|
685
|
-
// CONTAINMENT check (tried and reverted between #1354's first two rounds)
|
|
686
|
-
// wrongly accepts it, and only tracked-ness tells them apart.
|
|
687
|
-
//
|
|
688
|
-
// Mutation-tested by hand: reverted `assertOwnRoot` to the containment-only
|
|
689
|
-
// shape (`self.startsWith(realRoot + sep)`, no `isTrackedBy`) in a scratch
|
|
690
|
-
// copy laid out at the same relative depth as a real checkout, then ran this
|
|
691
|
-
// exact fixture shape against it — printed `MUTATION CONFIRMED LOAD-BEARING:
|
|
692
|
-
// containment-only wrongly accepted /private/tmp/true1339-mut-BzsU`, i.e. the
|
|
693
|
-
// untracked cache copy was answered about. Against the real, tracked-ness
|
|
694
|
-
// based repoRoot below: throws.
|
|
695
|
-
test("an untracked installed-cache copy inside a foreign repository is refused — #1339 (precise)", async (t) => {
|
|
696
|
-
const { dir: foreignRoot } = foreignRepoWithTrackedScripts(t);
|
|
697
|
-
const scriptsDir = installedCacheCopy(foreignRoot, { tracked: false });
|
|
698
|
-
|
|
699
|
-
const mod = await import(pathToFileURL(join(scriptsDir, "repo-root.mjs")).href);
|
|
700
|
-
assert.throws(
|
|
701
|
-
() => mod.repoRoot(scriptsDir),
|
|
702
|
-
(err) => err instanceof Error && err.message.includes(foreignRoot) && /does not TRACK/.test(err.message),
|
|
703
|
-
"an untracked cache copy must be refused even though it sits genuinely INSIDE the ambient repository — #1339",
|
|
704
|
-
);
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
// The other half: once the SAME copy is committed into the foreign
|
|
708
|
-
// repository's own index, it genuinely IS that repository's file — this is
|
|
709
|
-
// no longer a foreign root being mistaken for the answer, it is the
|
|
710
|
-
// vendoring repository's own tree, and repoRoot must accept it exactly as it
|
|
711
|
-
// would this checkout.
|
|
712
|
-
test("a committed installed-cache copy inside a foreign repository is accepted as that repository's own", async (t) => {
|
|
713
|
-
const { dir: foreignRoot } = foreignRepoWithTrackedScripts(t);
|
|
714
|
-
const scriptsDir = installedCacheCopy(foreignRoot, { tracked: true });
|
|
715
|
-
|
|
716
|
-
const mod = await import(pathToFileURL(join(scriptsDir, "repo-root.mjs")).href);
|
|
717
|
-
assert.equal(mod.repoRoot(scriptsDir), foreignRoot,
|
|
718
|
-
"once the copy is committed it IS that repository's own file, and repoRoot must say so");
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
// #1336's planned re-nesting of the whole payload under `plugin/`, simulated
|
|
722
|
-
// by committing this file's own scripts/ and .claude-plugin/ under a
|
|
723
|
-
// `plugin/` subdirectory of a fresh repository, so the git toplevel no
|
|
724
|
-
// longer has `.claude-plugin` directly beneath it. The self-relative
|
|
725
|
-
// manifest lookup (`dirname(thisFile)/../.claude-plugin/plugin.json`) must
|
|
726
|
-
// still find it regardless of how many levels separate it from the toplevel,
|
|
727
|
-
// and repoRoot must still accept the checkout as its own.
|
|
728
|
-
test("a plugin/-nested layout (#1336) is still accepted as this file's own tree", async (t) => {
|
|
729
|
-
const { dir } = noRepo(t);
|
|
730
|
-
const pluginDir = join(dir, "plugin");
|
|
731
|
-
const scriptsDir = join(pluginDir, "scripts");
|
|
732
|
-
mkdirSync(scriptsDir, { recursive: true });
|
|
733
|
-
mkdirSync(join(pluginDir, ".claude-plugin"), { recursive: true });
|
|
734
|
-
copyFileSync(join(DIR, "repo-root.mjs"), join(scriptsDir, "repo-root.mjs"));
|
|
735
|
-
copyFileSync(join(DIR, "git-env.mjs"), join(scriptsDir, "git-env.mjs"));
|
|
736
|
-
copyFileSync(join(DIR, "..", ".claude-plugin", "plugin.json"), join(pluginDir, ".claude-plugin", "plugin.json"));
|
|
737
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
738
|
-
execFileSync("git", ["add", "-A"], { cwd: dir, env: ENV });
|
|
739
|
-
execFileSync("git", ["commit", "-q", "-m", "nested payload"], { cwd: dir, env: ENV });
|
|
740
|
-
|
|
741
|
-
const mod = await import(pathToFileURL(join(scriptsDir, "repo-root.mjs")).href);
|
|
742
|
-
assert.equal(mod.repoRoot(scriptsDir), dir,
|
|
743
|
-
"a hardcoded root/.claude-plugin/plugin.json would refuse this; the self-relative lookup must not — #1336");
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
// #1354's review of the first fix: comparing the resolved root's OWN manifest
|
|
747
|
-
// name against this file's caught #1339's shape but missed a DIFFERENT
|
|
748
|
-
// checkout of this same plugin sitting above some unrelated caller directory
|
|
749
|
-
// — same name, wrong tree, still accepted. This fixture is exactly that: a
|
|
750
|
-
// foreign repository whose `.claude-plugin/plugin.json` genuinely matches
|
|
751
|
-
// this checkout's own plugin name, but which does not track this file.
|
|
752
|
-
test("a different checkout of this same plugin, not tracking this file, is refused — #1354", (t) => {
|
|
753
|
-
const { dir } = noRepo(t);
|
|
754
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
755
|
-
// Same plugin NAME as this checkout's own — the exact condition a
|
|
756
|
-
// name-only check would have accepted.
|
|
757
|
-
ownManifestFixture(dir);
|
|
758
|
-
|
|
759
|
-
const self = realpathSync(join(DIR, "repo-root.mjs"));
|
|
760
|
-
assert.throws(
|
|
761
|
-
() => repoRoot(dir),
|
|
762
|
-
(err) => err instanceof Error && err.message.includes(dir) && err.message.includes(self)
|
|
763
|
-
&& /does not TRACK/.test(err.message),
|
|
764
|
-
"a foreign tree that merely shares this plugin's name must be refused exactly as an unnamed one is — #1354",
|
|
765
|
-
);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
// #1149's own defect class, and the one place it could reappear inside the fix
|
|
769
|
-
// for it: a probe that could not look must never read as an answer. Every
|
|
770
|
-
// fixture below either HAS a repository or leaves the question unasked, so none
|
|
771
|
-
// of them is the absent working tree that licenses a skip — each must throw.
|
|
772
|
-
//
|
|
773
|
-
// The unreadable `.git` is why the answer cannot come from git's stderr alone:
|
|
774
|
-
// git steps over a `.git` it cannot enter and prints the same
|
|
775
|
-
// no-repository-anywhere message as a walk that genuinely found none (measured,
|
|
776
|
-
// git 2.50.1). Only the filesystem separates those two.
|
|
777
|
-
// Its own test because the fixture is not one every user can build: `chmod 000`
|
|
778
|
-
// is no barrier to root, and the repo's own convention for that is to decline
|
|
779
|
-
// rather than to assert over a fixture that is not the fault it means to be.
|
|
780
|
-
test("an unreadable .git is loud — the one fault git's own message cannot distinguish", (t) => {
|
|
781
|
-
if (process.getuid?.() === 0) return t.skip("root reads every directory");
|
|
782
|
-
|
|
783
|
-
const dir = realpathSync(mkdtempSync(join(tmpdir(), "repo-root-")));
|
|
784
|
-
t.after(() => {
|
|
785
|
-
if (existsSync(join(dir, ".git"))) chmodSync(join(dir, ".git"), 0o700);
|
|
786
|
-
rmSync(dir, { recursive: true, force: true });
|
|
787
|
-
});
|
|
788
|
-
execFileSync("git", ["init", "-q", "-b", "main", dir], { env: ENV });
|
|
789
|
-
assert.ok(existsSync(join(dir, ".git")), "fixture was not initialised as a repository");
|
|
790
|
-
chmodSync(join(dir, ".git"), 0o000);
|
|
791
|
-
|
|
792
|
-
// The fixture's whole point: git says the same thing here as it does over an
|
|
793
|
-
// extraction, so a reading of stderr alone answers "no repository" for a
|
|
794
|
-
// repository that is right there.
|
|
795
|
-
const probe = spawnSync("git", ["rev-parse", "--show-toplevel"],
|
|
796
|
-
{ cwd: dir, env: { ...ENV, LC_ALL: "C" }, encoding: "utf8" });
|
|
797
|
-
assert.match(probe.stderr, /not a git repository \(or any /,
|
|
798
|
-
"fixture is not the indistinguishable case — git gave a message that already separates it");
|
|
799
|
-
|
|
800
|
-
assert.throws(() => repoRoot(dir), /could not answer whether/,
|
|
801
|
-
"a `.git` git refuses to read is a repository, not an extraction");
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
test("git failures that are not an absent working tree are LOUD, never a skip", (t) => {
|
|
805
|
-
const notAnAnswer = /could not answer whether/;
|
|
806
|
-
|
|
807
|
-
const stale = noRepo(t).dir;
|
|
808
|
-
writeFileSync(join(stale, ".git"), "gitdir: /nonexistent/parent/.git/worktrees/wt1\n");
|
|
809
|
-
assert.throws(() => repoRoot(stale), notAnAnswer,
|
|
810
|
-
"a `.git` naming a gitdir that is not there is a broken pointer, not an absent tree");
|
|
811
|
-
|
|
812
|
-
const bare = join(noRepo(t).dir, "bare.git");
|
|
813
|
-
execFileSync("git", ["init", "-q", "--bare", bare], { env: ENV });
|
|
814
|
-
assert.throws(() => repoRoot(bare), notAnAnswer,
|
|
815
|
-
"a bare repository is a repository — git declines for want of a WORK TREE, which is a different sentence");
|
|
816
|
-
|
|
817
|
-
const noGit = noRepo(t).dir;
|
|
818
|
-
const savedPath = process.env.PATH;
|
|
819
|
-
t.after(() => { process.env.PATH = savedPath; });
|
|
820
|
-
process.env.PATH = "/nonexistent";
|
|
821
|
-
assert.throws(() => repoRoot(noGit), notAnAnswer,
|
|
822
|
-
"no git binary means the question was never put — spawnSync reports that as `error`, with no status and no stderr");
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
// The other direction, and the one this must not cost: the condition the skip
|
|
826
|
-
// exists for still answers `null` and still yields a reason.
|
|
827
|
-
test("a genuinely absent working tree still answers null, and still names why", (t) => {
|
|
828
|
-
const { dir, env } = noRepo(t);
|
|
829
|
-
const probe = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd: dir, env, encoding: "utf8" });
|
|
830
|
-
assert.equal(probe.status, 128, "the fixture is not repo-less");
|
|
831
|
-
|
|
832
|
-
const saved = process.env.GIT_CEILING_DIRECTORIES;
|
|
833
|
-
t.after(() => {
|
|
834
|
-
if (saved === undefined) delete process.env.GIT_CEILING_DIRECTORIES;
|
|
835
|
-
else process.env.GIT_CEILING_DIRECTORIES = saved;
|
|
836
|
-
});
|
|
837
|
-
process.env.GIT_CEILING_DIRECTORIES = dirname(dir);
|
|
838
|
-
|
|
839
|
-
assert.equal(repoRoot(dir), null, "no working tree anywhere above is the one condition that may answer null");
|
|
840
|
-
assert.match(skipWithoutRepo(repoRoot(dir), "the sweep"), /the sweep did not run/,
|
|
841
|
-
"and the reason names what did not run, in the caller's own words");
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
// `trackedShellScripts` cannot tell a null root from a good one on its own:
|
|
845
|
-
// `execFileSync` reads `cwd: null` as "inherit the calling process's
|
|
846
|
-
// directory", so an absorbed null answers some other repository's scripts.
|
|
847
|
-
test("trackedShellScripts refuses a root repoRoot did not answer", () => {
|
|
848
|
-
assert.throws(() => trackedShellScripts(null), /must come from repoRoot/);
|
|
849
|
-
assert.throws(() => trackedShellScripts(undefined), /must come from repoRoot/);
|
|
850
|
-
});
|
|
851
|
-
|
|
852
|
-
// The same guard for the sibling, which shares it — and needs it for the same
|
|
853
|
-
// reason: an absorbed null lists whatever repository the process sits in.
|
|
854
|
-
test("trackedNodeScripts refuses a root repoRoot did not answer", () => {
|
|
855
|
-
assert.throws(() => trackedNodeScripts(null), /must come from repoRoot/);
|
|
856
|
-
assert.throws(() => trackedNodeScripts(undefined), /must come from repoRoot/);
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
// The third export shares the guard — the one #1910 found a sweep's own
|
|
860
|
-
// inlined `git ls-files` had dropped.
|
|
861
|
-
test("trackedPaths refuses a root repoRoot did not answer", () => {
|
|
862
|
-
assert.throws(() => trackedPaths(null), /must come from repoRoot/);
|
|
863
|
-
assert.throws(() => trackedPaths(undefined), /must come from repoRoot/);
|
|
864
|
-
});
|
|
865
|
-
|
|
866
|
-
// And the guard must not fire in the tree it ships in.
|
|
867
|
-
test("this checkout resolves, so the sweeps that import this are not skipped here", { skip: SKIP_WITHOUT_REPO }, () => {
|
|
868
|
-
const root = repoRoot(DIR);
|
|
869
|
-
assert.notEqual(root, null, "no ambient working tree for a file that is itself tracked in one");
|
|
870
|
-
assert.equal(skipWithoutRepo(root, "the tests"), false);
|
|
871
|
-
assert.ok(trackedShellScripts(root).length > 0,
|
|
872
|
-
"this repository tracks shell scripts — an empty list here means a broken glob, not a missing repo");
|
|
873
|
-
});
|