@feigi/fleet-ctl 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +9 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/agents/fleet-finisher.agent.md +7 -0
- package/agents/fleet-implementer-alt.agent.md +210 -0
- package/agents/fleet-implementer.agent.md +210 -0
- package/agents/fleet-merge-bot.agent.md +7 -0
- package/agents/fleet-review-comments.agent.md +40 -0
- package/agents/fleet-review-correctness.agent.md +43 -0
- package/agents/fleet-review-runner.agent.md +73 -0
- package/agents/fleet-review-silent-failure.agent.md +49 -0
- package/agents/fleet-review-simplify.agent.md +46 -0
- package/agents/fleet-review-snapshot.agent.md +24 -0
- package/agents/fleet-review-tests.agent.md +46 -0
- package/agents/fleet-review-types.agent.md +41 -0
- package/agents/fleet-review-verifier.agent.md +29 -0
- package/commands/review-and-fix.md +98 -0
- package/commands/run-merge-bot.md +357 -0
- package/commands/run-team-help.md +17 -0
- package/package.json +23 -0
- package/scripts/agent-test-dir-prose.test.mjs +59 -0
- package/scripts/agent-test.test.mjs +1636 -0
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
- package/scripts/ambient-git-vars-prose.test.mjs +192 -0
- package/scripts/ancestry-check-position-prose.test.mjs +175 -0
- package/scripts/apply-ruleset.test.mjs +420 -0
- package/scripts/arg-header-probes-prose.test.mjs +393 -0
- package/scripts/arg.mjs +600 -0
- package/scripts/arg.test.mjs +1354 -0
- package/scripts/board-cli.test.mjs +694 -0
- package/scripts/board-identity.test.mjs +429 -0
- package/scripts/board-liveness-banner.test.mjs +119 -0
- package/scripts/board-prev-shape.test.mjs +229 -0
- package/scripts/board-tryparse-null.test.mjs +119 -0
- package/scripts/board.html +471 -0
- package/scripts/board.mjs +2037 -0
- package/scripts/board.test.mjs +3086 -0
- package/scripts/brief-after-cut-prose.test.mjs +53 -0
- package/scripts/candidates-exit3-prose.test.mjs +302 -0
- package/scripts/candidates.mjs +674 -0
- package/scripts/candidates.test.mjs +2101 -0
- package/scripts/caveat-unification-prose.test.mjs +98 -0
- package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
- package/scripts/ci-completes-premise-prose.test.mjs +257 -0
- package/scripts/ci-state-prose.test.mjs +113 -0
- package/scripts/ci-state.mjs +761 -0
- package/scripts/ci-state.test.mjs +1640 -0
- package/scripts/ci-vacuous-green.test.mjs +368 -0
- package/scripts/citation-sweep-prose.test.mjs +1572 -0
- package/scripts/claim-lifecycle.test.mjs +185 -0
- package/scripts/claim-ticket.sh +417 -0
- package/scripts/claim-ticket.test.mjs +1121 -0
- package/scripts/closing-keyword-prose.test.mjs +193 -0
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
- package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
- package/scripts/compute-board.mjs +579 -0
- package/scripts/compute-board.test.mjs +1060 -0
- package/scripts/compute-spend.mjs +329 -0
- package/scripts/compute-spend.test.mjs +451 -0
- package/scripts/cross-repo-citation-prose.test.mjs +156 -0
- package/scripts/cwd-isolation-pins.mjs +83 -0
- package/scripts/dedupe-guard-prose.test.mjs +243 -0
- package/scripts/derive-testcmd.sh +239 -0
- package/scripts/derive-testcmd.test.mjs +380 -0
- package/scripts/diff-stats.mjs +231 -0
- package/scripts/diff-stats.test.mjs +408 -0
- package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
- package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
- package/scripts/drop-merged-label.sh +173 -0
- package/scripts/drop-merged-label.test.mjs +480 -0
- package/scripts/expected-jobs-prose.test.mjs +80 -0
- package/scripts/filing-bar-seat-prose.test.mjs +242 -0
- package/scripts/filing-claim-bar-prose.test.mjs +166 -0
- package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
- package/scripts/finisher-halt-prose.test.mjs +106 -0
- package/scripts/finisher-name-prose.test.mjs +134 -0
- package/scripts/finisher-own-tree-prose.test.mjs +285 -0
- package/scripts/finisher-pin-race-prose.test.mjs +339 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
- package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
- package/scripts/fleet-bootstrap +155 -0
- package/scripts/fleet-heartbeat.mjs +272 -0
- package/scripts/fleet-heartbeat.test.mjs +450 -0
- package/scripts/fleet-provenance +207 -0
- package/scripts/fleet-provenance.test.mjs +64 -0
- package/scripts/fleet-run +148 -0
- package/scripts/fleet-run.test.mjs +90 -0
- package/scripts/fleet-state.mjs +400 -0
- package/scripts/fleet-state.test.mjs +373 -0
- package/scripts/fleet-tick-prose.test.mjs +299 -0
- package/scripts/fleet-tick.mjs +832 -0
- package/scripts/fleet-tick.test.mjs +1332 -0
- package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
- package/scripts/frontmatter-allowlist.json +64 -0
- package/scripts/frontmatter-check.mjs +256 -0
- package/scripts/frontmatter-check.test.mjs +436 -0
- package/scripts/git-env.mjs +124 -0
- package/scripts/git-env.test.mjs +149 -0
- package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
- package/scripts/gone-walk.test.mjs +213 -0
- package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
- package/scripts/head-moved-after-label-prose.test.mjs +233 -0
- package/scripts/immutable-body-claim-prose.test.mjs +413 -0
- package/scripts/implementer-model-tier.test.mjs +643 -0
- package/scripts/inflight-citation-prose.test.mjs +144 -0
- package/scripts/inflight-exit2-prose.test.mjs +81 -0
- package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
- package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
- package/scripts/inflight.sh +1106 -0
- package/scripts/inflight.test.mjs +2984 -0
- package/scripts/injection-control-prose.test.mjs +404 -0
- package/scripts/install-root-audit.test.mjs +464 -0
- package/scripts/instrument-check-prose.test.mjs +235 -0
- package/scripts/instruments.sh +394 -0
- package/scripts/instruments.test.mjs +787 -0
- package/scripts/issue-tracker-prose.test.mjs +71 -0
- package/scripts/json.sh +248 -0
- package/scripts/json.test.mjs +364 -0
- package/scripts/ledger-dispatch.test.mjs +516 -0
- package/scripts/ledger-grammar.mjs +85 -0
- package/scripts/ledger-grammar.test.mjs +142 -0
- package/scripts/ledger-read-require-file.test.mjs +197 -0
- package/scripts/ledger.mjs +1753 -0
- package/scripts/ledger.test.mjs +3554 -0
- package/scripts/line-distance-prose.test.mjs +245 -0
- package/scripts/liveness-rationale-prose.test.mjs +83 -0
- package/scripts/locale-pin-prose.test.mjs +189 -0
- package/scripts/member-outcome-prose.test.mjs +167 -0
- package/scripts/member-outcomes-header.test.mjs +148 -0
- package/scripts/member-outcomes-prose.test.mjs +63 -0
- package/scripts/member-outcomes.mjs +231 -0
- package/scripts/member-outcomes.test.mjs +507 -0
- package/scripts/member-prompt-prose.test.mjs +161 -0
- package/scripts/member-record.mjs +605 -0
- package/scripts/member-record.test.mjs +516 -0
- package/scripts/member-write-guard.mjs +279 -0
- package/scripts/member-write-guard.test.mjs +211 -0
- package/scripts/merge-commit-probe-prose.test.mjs +122 -0
- package/scripts/merge-gate.mjs +262 -0
- package/scripts/merge-gate.test.mjs +613 -0
- package/scripts/muted-git-guard-sweep.test.mjs +493 -0
- package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
- package/scripts/net-watchdog-prose.test.mjs +79 -0
- package/scripts/net.sh +409 -0
- package/scripts/net.test.mjs +211 -0
- package/scripts/no-ci-gate-prose.test.mjs +108 -0
- package/scripts/no-undo-audit.sh +1134 -0
- package/scripts/no-undo-audit.test.mjs +3965 -0
- package/scripts/no-wave.test.mjs +138 -0
- package/scripts/node-floor-sweep.test.mjs +611 -0
- package/scripts/pointer-target-prose.test.mjs +186 -0
- package/scripts/pr-overlap.mjs +417 -0
- package/scripts/pr-overlap.test.mjs +695 -0
- package/scripts/printf-die-sweep.test.mjs +384 -0
- package/scripts/prompt-renderer.mjs +39 -0
- package/scripts/prompt-renderer.test.mjs +68 -0
- package/scripts/prose-pin.mjs +808 -0
- package/scripts/prose-pin.test.mjs +1034 -0
- package/scripts/prove-merge.sh +228 -0
- package/scripts/prove-merge.test.mjs +995 -0
- package/scripts/pull-table-relabel-prose.test.mjs +60 -0
- package/scripts/quiet-payload-prose.test.mjs +222 -0
- package/scripts/reap.sh +1768 -0
- package/scripts/reap.test.mjs +4395 -0
- package/scripts/reaping-prose.test.mjs +159 -0
- package/scripts/refuter-scratch-prose.test.mjs +135 -0
- package/scripts/release-label-required-prose.test.mjs +71 -0
- package/scripts/release-label-split-prose.test.mjs +169 -0
- package/scripts/release-ticket.sh +1716 -0
- package/scripts/release-ticket.test.mjs +5106 -0
- package/scripts/renovate-release-contract.test.mjs +379 -0
- package/scripts/repo-root.mjs +544 -0
- package/scripts/repo-root.test.mjs +873 -0
- package/scripts/reporter-output-rule-prose.test.mjs +208 -0
- package/scripts/review-agent-report-only.test.mjs +49 -0
- package/scripts/review-core-cwd-isolation.test.mjs +374 -0
- package/scripts/review-core-reads.test.mjs +478 -0
- package/scripts/review-core-refuter-scratch.test.mjs +148 -0
- package/scripts/review-core-snapshot-path.test.mjs +777 -0
- package/scripts/review-core-specialist-scratch.test.mjs +189 -0
- package/scripts/review-core-testcmd.test.mjs +288 -0
- package/scripts/review-core-unrun.test.mjs +530 -0
- package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
- package/scripts/review-core.mjs +1028 -0
- package/scripts/review-eval-resolver-path.test.mjs +55 -0
- package/scripts/review-eval.mjs +197 -0
- package/scripts/review-host-fixture.mjs +73 -0
- package/scripts/review-in-run-retry.test.mjs +187 -0
- package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
- package/scripts/review-path-default.test.mjs +796 -0
- package/scripts/review-runner-spawns.test.mjs +93 -0
- package/scripts/review-runner.test.mjs +155 -0
- package/scripts/review-tier-audit.test.mjs +140 -0
- package/scripts/run-artifact-pr-prose.test.mjs +341 -0
- package/scripts/run-merge-bot-prose.test.mjs +1391 -0
- package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
- package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
- package/scripts/section-between-guard-prose.test.mjs +378 -0
- package/scripts/select-dimensions.test.mjs +674 -0
- package/scripts/shared-refusal.test.mjs +388 -0
- package/scripts/shell-traps-prose.test.mjs +507 -0
- package/scripts/shortlist.mjs +355 -0
- package/scripts/shortlist.test.mjs +366 -0
- package/scripts/slow-transport.mjs +72 -0
- package/scripts/snapshot-repo.test.mjs +772 -0
- package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
- package/scripts/spend-view.test.mjs +312 -0
- package/scripts/staleness-qualifier-prose.test.mjs +251 -0
- package/scripts/staleness-verdict-prose.test.mjs +142 -0
- package/scripts/staleness.mjs +414 -0
- package/scripts/staleness.test.mjs +893 -0
- package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
- package/scripts/stash-prohibition-prose.test.mjs +313 -0
- package/scripts/strip-comments.mjs +44 -0
- package/scripts/tier-check.mjs +468 -0
- package/scripts/tier-check.test.mjs +726 -0
- package/scripts/tier-guard-gate-prose.test.mjs +216 -0
- package/scripts/tier-outcomes-header.test.mjs +586 -0
- package/scripts/tier-outcomes.mjs +441 -0
- package/scripts/tier-outcomes.test.mjs +342 -0
- package/scripts/tier-roles.mjs +250 -0
- package/scripts/tier-roles.test.mjs +316 -0
- package/scripts/tracker-block-copy-prose.test.mjs +288 -0
- package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
- package/scripts/unattended-git-sweep.test.mjs +142 -0
- package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
- package/scripts/verify-sha.sh +117 -0
- package/scripts/verify-sha.test.mjs +693 -0
- package/scripts/watcher-degraded-block.test.mjs +372 -0
- package/scripts/watcher-key-prose.test.mjs +106 -0
- package/scripts/within-run-pair-prose.test.mjs +208 -0
- package/scripts/worktree-audit.sh +482 -0
- package/scripts/worktree-audit.test.mjs +1407 -0
- package/scripts/worktree-head-prose.test.mjs +276 -0
- package/scripts/worktree-listing-sweep.test.mjs +217 -0
- package/scripts/worktree-model-prose.test.mjs +216 -0
- package/scripts/worktree.sh +470 -0
- package/skills/next-ticket/SKILL.md +138 -0
- package/skills/run-team/SKILL.md +3603 -0
- package/skills/run-team/references/ci-and-staleness.md +75 -0
- package/skills/run-team/references/correction-tickets.md +37 -0
- package/skills/run-team/references/isolation.md +23 -0
- package/skills/run-team/references/member-lifecycle.md +73 -0
- package/skills/run-team/references/reaping.md +73 -0
- package/skills/sizing-a-ticket/SKILL.md +39 -0
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
// Regression gate for staleness.mjs, the phase-0 probe that decides whether a
|
|
2
|
+
// shortlisted ticket is still live. Zero deps:
|
|
3
|
+
// `node --test plugin/scripts/staleness.test.mjs`.
|
|
4
|
+
//
|
|
5
|
+
// A script that reasons about git history can only be tested against real git
|
|
6
|
+
// history, so every case below builds a throwaway bare origin plus a clone in
|
|
7
|
+
// a temp dir and runs the script for real — the same fixture idiom as
|
|
8
|
+
// `prove-merge.test.mjs`.
|
|
9
|
+
//
|
|
10
|
+
// THE LOAD-BEARING CASES ARE THE ONES THAT MUST STILL OFFER. A wrong `fixed`
|
|
11
|
+
// silently retires real supply, which is the harm #238's evidence criterion
|
|
12
|
+
// exists to prevent, and it is invisible: the ticket simply stops being
|
|
13
|
+
// shortlisted and nobody is told. So `never at this path answers unknown`,
|
|
14
|
+
// `untracked in origin/main answers unknown`, and `a fix that is only local
|
|
15
|
+
// answers live` each pin a case the probe must NOT report as fixed. The last
|
|
16
|
+
// of those is the one a probe written against the working tree passes anyway.
|
|
17
|
+
// The same rule governs the cases added since: an empty tracked file, a
|
|
18
|
+
// pathspec with more than one answer, and a `fixed` whose citation has to name
|
|
19
|
+
// the commit that was pushed rather than one sitting in a local branch.
|
|
20
|
+
//
|
|
21
|
+
// `git unavailable answers unknown, never fixed` guards the exit code from the
|
|
22
|
+
// other end: Node exits 1 on an uncaught throw and 1 is `fixed` here, so any
|
|
23
|
+
// failure that escapes must not land there. staleness.mjs's outer catch is the
|
|
24
|
+
// backstop for the throws no CLI input can reach today — the reachable ones
|
|
25
|
+
// each have their own guard, and this case exercises the git-is-not-there
|
|
26
|
+
// branch of that set.
|
|
27
|
+
//
|
|
28
|
+
// THE CEILING: this pins the verdict each input earns and the evidence the
|
|
29
|
+
// `fixed` verdict carries. It does not pin the `why` wording, which is prose
|
|
30
|
+
// for a reader and is meant to be rewritable.
|
|
31
|
+
|
|
32
|
+
import { test } from "node:test";
|
|
33
|
+
import assert from "node:assert/strict";
|
|
34
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
35
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
36
|
+
import { tmpdir } from "node:os";
|
|
37
|
+
import { join } from "node:path";
|
|
38
|
+
import { fileURLToPath } from "node:url";
|
|
39
|
+
import { stripComments } from "./strip-comments.mjs";
|
|
40
|
+
|
|
41
|
+
const SCRIPT = fileURLToPath(new URL("./staleness.mjs", import.meta.url));
|
|
42
|
+
|
|
43
|
+
// Pin identity and cut the developer's ~/.gitconfig out of the fixture, so a
|
|
44
|
+
// local `pull.rebase`, hook or template cannot change what these repos look
|
|
45
|
+
// like. The GIT_* redirects would point the fixtures out of their own temp
|
|
46
|
+
// dirs; the fleet harness is exactly the caller that has them set.
|
|
47
|
+
const ENV = {
|
|
48
|
+
...process.env,
|
|
49
|
+
GIT_DIR: undefined,
|
|
50
|
+
GIT_WORK_TREE: undefined,
|
|
51
|
+
GIT_TEMPLATE_DIR: undefined,
|
|
52
|
+
GIT_INDEX_FILE: undefined,
|
|
53
|
+
GIT_AUTHOR_NAME: "t",
|
|
54
|
+
GIT_AUTHOR_EMAIL: "t@example.com",
|
|
55
|
+
GIT_COMMITTER_NAME: "t",
|
|
56
|
+
GIT_COMMITTER_EMAIL: "t@example.com",
|
|
57
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
58
|
+
GIT_CONFIG_SYSTEM: "/dev/null",
|
|
59
|
+
LANG: "C",
|
|
60
|
+
LC_ALL: "C",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const git = (cwd, ...args) =>
|
|
64
|
+
execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
|
|
65
|
+
|
|
66
|
+
/** Write `body` to `rel`, commit it, and return the commit sha. */
|
|
67
|
+
function commitFile(w, rel, body, msg) {
|
|
68
|
+
writeFileSync(join(w, rel), body);
|
|
69
|
+
git(w, "add", rel);
|
|
70
|
+
git(w, "commit", "-q", "-m", msg);
|
|
71
|
+
return git(w, "rev-parse", "HEAD");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Bare origin + working clone whose `main` is pushed. Returns the clone dir. */
|
|
75
|
+
function repo(t) {
|
|
76
|
+
const root = mkdtempSync(join(tmpdir(), "staleness-"));
|
|
77
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
78
|
+
const origin = join(root, "origin.git");
|
|
79
|
+
const w = join(root, "w");
|
|
80
|
+
execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
|
|
81
|
+
execFileSync("git", ["clone", "-q", origin, w], { env: ENV });
|
|
82
|
+
commitFile(w, "src.mjs", "const keep = 1;\n", "root");
|
|
83
|
+
git(w, "branch", "-M", "main");
|
|
84
|
+
git(w, "push", "-q", "-u", "origin", "main");
|
|
85
|
+
return w;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const push = (w) => git(w, "push", "-q", "origin", "main");
|
|
89
|
+
|
|
90
|
+
// process.execPath, not "node": one case runs with an empty PATH, and a bare
|
|
91
|
+
// "node" there is not found — the runner would die before the script does and
|
|
92
|
+
// the case would pass for the wrong reason.
|
|
93
|
+
function probe(cwd, args, env = ENV) {
|
|
94
|
+
const r = spawnSync(process.execPath, [SCRIPT, ...args], { cwd, env, encoding: "utf8" });
|
|
95
|
+
return { code: r.status, json: r.stdout.trim() ? JSON.parse(r.stdout) : null, stderr: r.stderr };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
test("a --present string the tree carries is fixed, and names the commit that added it", (t) => {
|
|
99
|
+
const w = repo(t);
|
|
100
|
+
const sha = commitFile(w, "src.mjs", "const keep = 1;\nfunction decodeArgs() {}\n", "add the guard");
|
|
101
|
+
push(w);
|
|
102
|
+
|
|
103
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "decodeArgs"]);
|
|
104
|
+
assert.equal(r.code, 1, `expected fixed (exit 1), got ${r.code}: ${r.stderr}`);
|
|
105
|
+
assert.equal(r.json.verdict, "fixed");
|
|
106
|
+
assert.equal(r.json.commit, sha, "the payload must name the commit a close would cite");
|
|
107
|
+
assert.equal(r.json.subject, "add the guard", "the subject is what tells the reader the commit is about this");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// MUST STILL OFFER. A pin ticket whose assertion has not landed under this
|
|
111
|
+
// spelling stays live — including the case where an equivalent rewording did
|
|
112
|
+
// land, which reads the same way here and is a reason to offer, not to close.
|
|
113
|
+
test("a --present string the tree lacks is live", (t) => {
|
|
114
|
+
const w = repo(t);
|
|
115
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "decodeArgs"]);
|
|
116
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
117
|
+
assert.equal(r.json.verdict, "live");
|
|
118
|
+
assert.equal(r.json.found, false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("a --gone string the tree still carries is live", (t) => {
|
|
122
|
+
const w = repo(t);
|
|
123
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
124
|
+
push(w);
|
|
125
|
+
|
|
126
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
127
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
128
|
+
assert.equal(r.json.verdict, "live");
|
|
129
|
+
assert.equal(r.json.found, true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("a --gone string a commit removed is fixed, and names the commit that removed it", (t) => {
|
|
133
|
+
const w = repo(t);
|
|
134
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
135
|
+
const sha = commitFile(w, "src.mjs", "const keep = 1;\nconst right = 3;\n", "fix it in passing");
|
|
136
|
+
push(w);
|
|
137
|
+
|
|
138
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
139
|
+
assert.equal(r.code, 1, `expected fixed (exit 1), got ${r.code}: ${r.stderr}`);
|
|
140
|
+
assert.equal(r.json.verdict, "fixed");
|
|
141
|
+
assert.equal(r.json.commit, sha);
|
|
142
|
+
assert.equal(r.json.subject, "fix it in passing");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// #1599: git()'s single spawn primitive — every git call in this file routes
|
|
146
|
+
// through it — passed no env at all before this fix, and #1020's own census
|
|
147
|
+
// could not see it — its scan is `.sh`-only. Measured directly: an ambient
|
|
148
|
+
// GIT_DIR or GIT_WORK_TREE (a git hook, `rebase --exec`, `bisect run`)
|
|
149
|
+
// corrupts this file's answer in its own distinct way, silently.
|
|
150
|
+
test("rev-parse: an inherited GIT_WORK_TREE must not substitute a foreign repo root, turning a fixed ticket unknown", (t) => {
|
|
151
|
+
const w = repo(t);
|
|
152
|
+
const sha = commitFile(w, "src.mjs", "const keep = 1;\nfunction decodeArgs() {}\n", "add the guard");
|
|
153
|
+
push(w);
|
|
154
|
+
const other = mkdtempSync(join(tmpdir(), "staleness-other-"));
|
|
155
|
+
t.after(() => rmSync(other, { recursive: true, force: true }));
|
|
156
|
+
execFileSync("git", ["init", "-q", other], { env: ENV });
|
|
157
|
+
|
|
158
|
+
// Unscrubbed, `git rev-parse --show-toplevel` answers with the AMBIENT
|
|
159
|
+
// GIT_WORK_TREE outright, regardless of the real cwd (`w`) — so `root`
|
|
160
|
+
// becomes `other`, every pathspec below resolves against a directory that
|
|
161
|
+
// does not track `src.mjs` at all, and a ticket that IS fixed reports as
|
|
162
|
+
// untracked/unknown instead.
|
|
163
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "decodeArgs"], { ...ENV, GIT_WORK_TREE: other });
|
|
164
|
+
assert.equal(r.code, 1, `expected fixed (exit 1), got ${r.code}: ${r.stderr}`);
|
|
165
|
+
assert.equal(r.json.verdict, "fixed");
|
|
166
|
+
assert.equal(r.json.commit, sha);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("ls-tree/log -S: an inherited GIT_DIR must not substitute a foreign repository's origin/main for this repository's own", (t) => {
|
|
170
|
+
const w = repo(t);
|
|
171
|
+
const sha = commitFile(w, "src.mjs", "const keep = 1;\nfunction decodeArgs() {}\n", "add the guard");
|
|
172
|
+
push(w);
|
|
173
|
+
const other = mkdtempSync(join(tmpdir(), "staleness-other-"));
|
|
174
|
+
t.after(() => rmSync(other, { recursive: true, force: true }));
|
|
175
|
+
execFileSync("git", ["init", "-q", other], { env: ENV });
|
|
176
|
+
|
|
177
|
+
// `w` IS the toplevel already (no subdirectory involved), so GIT_DIR alone
|
|
178
|
+
// leaves the rev-parse call above unaffected (measured) and this isolates
|
|
179
|
+
// the SECOND-through-FOURTH calls: `-C root ls-tree/cat-file/log -S`.
|
|
180
|
+
// Unscrubbed, GIT_DIR still outranks the explicit `-C root` — measured,
|
|
181
|
+
// `ls-tree origin/main` under this ambient GIT_DIR reads the OTHER
|
|
182
|
+
// (unrelated, ref-less) repository's object database instead and fails to
|
|
183
|
+
// resolve `origin/main` at all, which downgrades a fixed ticket to
|
|
184
|
+
// could-not-check rather than citing its real commit.
|
|
185
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "decodeArgs"], { ...ENV, GIT_DIR: join(other, ".git") });
|
|
186
|
+
assert.equal(r.code, 1, `expected fixed (exit 1), got ${r.code}: ${r.stderr}`);
|
|
187
|
+
assert.equal(r.json.verdict, "fixed");
|
|
188
|
+
assert.equal(r.json.commit, sha, "the citation must come from THIS repository's origin/main, never the ambient one's");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// MUST STILL OFFER, and this is the positive control. Absent from the current
|
|
192
|
+
// file is the same output whether the fix landed or the probe was pointed at a
|
|
193
|
+
// spelling this file never used — so absent-AND-never-here is unknown, never
|
|
194
|
+
// fixed. Without this the probe closes a live ticket on a typo.
|
|
195
|
+
test("a --gone string that was never at this path answers unknown, never fixed", (t) => {
|
|
196
|
+
const w = repo(t);
|
|
197
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "a spelling this file never had"]);
|
|
198
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
199
|
+
assert.equal(r.json.verdict, "unknown");
|
|
200
|
+
assert.equal(r.json.found, false);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// MUST STILL OFFER. The generated-artifact case: the file is right there on
|
|
204
|
+
// disk and untracked in origin/main, which is what `.agent-test.sh` looks like
|
|
205
|
+
// in any checkout `./agent-test` has run in. Reading the on-disk copy would
|
|
206
|
+
// measure whatever the last run emitted; reading the absence as a clean tree would close the
|
|
207
|
+
// ticket. Neither: unknown.
|
|
208
|
+
test("a path untracked in origin/main answers unknown even though the file is on disk", (t) => {
|
|
209
|
+
const w = repo(t);
|
|
210
|
+
writeFileSync(join(w, "generated"), "const wrong = 2;\n");
|
|
211
|
+
assert.ok(existsSync(join(w, "generated")), "the fixture must put the decoy on disk");
|
|
212
|
+
|
|
213
|
+
const r = probe(w, ["--path", "generated", "--gone", "const wrong = 2;"]);
|
|
214
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
215
|
+
assert.equal(r.json.verdict, "unknown");
|
|
216
|
+
assert.equal(r.json.tracked, false, "the payload must say the path is untracked, not that the string is gone");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// MUST STILL OFFER. `origin/main`, never the working tree — a fix committed
|
|
220
|
+
// locally and not pushed is not in the tree the fleet dispatches against, and a
|
|
221
|
+
// probe that read the checkout would retire the ticket on work nobody else can
|
|
222
|
+
// see.
|
|
223
|
+
test("a --gone fix that is only local, never pushed, is still live", (t) => {
|
|
224
|
+
const w = repo(t);
|
|
225
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
226
|
+
push(w);
|
|
227
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst right = 3;\n", "local fix, unpushed");
|
|
228
|
+
|
|
229
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
230
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
231
|
+
assert.equal(r.json.verdict, "live");
|
|
232
|
+
assert.equal(r.json.found, true, "the string must be read out of origin/main, where it is still present");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// The verdict here is `fixed` and it is the RIGHT verdict — what this pins is
|
|
236
|
+
// the evidence. The `-S` walk starts at origin/main so the commit it names is
|
|
237
|
+
// one everybody can see; walked from HEAD it answers `fixed` just as
|
|
238
|
+
// confidently and cites work that was never pushed, which is a close written
|
|
239
|
+
// against a commit nobody else has. The case above keeps a local fix from
|
|
240
|
+
// retiring the ticket; this one keeps a local commit out of the citation when
|
|
241
|
+
// the fix is real.
|
|
242
|
+
test("the commit a fixed verdict cites comes from origin/main, never a local one", (t) => {
|
|
243
|
+
const w = repo(t);
|
|
244
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
245
|
+
push(w);
|
|
246
|
+
const sha = commitFile(w, "src.mjs", "const keep = 1;\nconst right = 3;\n", "fix it upstream");
|
|
247
|
+
push(w);
|
|
248
|
+
// Both of these change the needle's count at this path and both are newer
|
|
249
|
+
// than the pushed fix, so a walk over HEAD names one of them instead.
|
|
250
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "local: reintroduce, unpushed");
|
|
251
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst right = 3;\n", "local: remove again, unpushed");
|
|
252
|
+
|
|
253
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
254
|
+
assert.equal(r.code, 1, `expected fixed (exit 1), got ${r.code}: ${r.stderr}`);
|
|
255
|
+
assert.equal(r.json.commit, sha, "the citation must be the pushed fix, not the unpushed local commit");
|
|
256
|
+
assert.equal(r.json.subject, "fix it upstream");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// MUST STILL OFFER. An empty file answers every search the same way, so
|
|
260
|
+
// without this the commit that emptied it gets cited as the fix — and the
|
|
261
|
+
// subject of a commit that wiped a file says nothing about the ticket.
|
|
262
|
+
test("an empty tracked file answers unknown, never fixed", (t) => {
|
|
263
|
+
const w = repo(t);
|
|
264
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
265
|
+
push(w);
|
|
266
|
+
commitFile(w, "src.mjs", "", "chore: reset generated file (unrelated)");
|
|
267
|
+
push(w);
|
|
268
|
+
|
|
269
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
270
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
271
|
+
assert.equal(r.json.verdict, "unknown");
|
|
272
|
+
assert.equal(r.json.bytes, 0, "the payload must say the search had no bytes to look at");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// MUST STILL OFFER. A pathspec with more than one answer is not an answer:
|
|
276
|
+
// without the guard the probe reads whichever entry git listed first and
|
|
277
|
+
// reports on a file nobody asked about — here the clean one, while the defect
|
|
278
|
+
// sits live in its neighbour.
|
|
279
|
+
test("a pathspec resolving to more than one entry answers unknown", (t) => {
|
|
280
|
+
const w = repo(t);
|
|
281
|
+
commitFile(w, "zzz.mjs", "const wrong = 2;\n", "the defect, in the second file");
|
|
282
|
+
push(w);
|
|
283
|
+
|
|
284
|
+
const r = probe(w, ["--path", ".", "--gone", "const wrong = 2;"]);
|
|
285
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
286
|
+
assert.equal(r.json.verdict, "unknown");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// The probe answers a question about the tree, so where it was run from must
|
|
290
|
+
// not change the answer. git resolves a pathspec against the process's cwd:
|
|
291
|
+
// unanchored, a tracked file reads as UNTRACKED from a subdirectory, and an
|
|
292
|
+
// absolute path — the spelling a caller that just read the file produces —
|
|
293
|
+
// reads as a pathspec that resolved to something else. Both are false
|
|
294
|
+
// statements about the tree, in the file whose whole job is not making those.
|
|
295
|
+
test("--path is read against the repo root, from any cwd and either spelling", (t) => {
|
|
296
|
+
const w = realpathSync(repo(t));
|
|
297
|
+
mkdirSync(join(w, "sub"));
|
|
298
|
+
|
|
299
|
+
const fromSub = probe(join(w, "sub"), ["--path", "src.mjs", "--gone", "const keep = 1;"]);
|
|
300
|
+
assert.equal(fromSub.code, 0, `expected live (exit 0) from a subdirectory, got ${fromSub.code}: ${fromSub.stderr}`);
|
|
301
|
+
assert.equal(fromSub.json.found, true, "a tracked file must not read as untracked because of the caller's cwd");
|
|
302
|
+
|
|
303
|
+
const absolute = probe(w, ["--path", join(w, "src.mjs"), "--gone", "const keep = 1;"]);
|
|
304
|
+
assert.equal(absolute.code, 0, `expected live (exit 0) for an absolute --path, got ${absolute.code}: ${absolute.stderr}`);
|
|
305
|
+
assert.equal(absolute.json.found, true, "an absolute path names the same file as its root-relative spelling");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// A tree read as a file greps a list of FILENAMES, and a needle absent from
|
|
309
|
+
// that list reads as clean.
|
|
310
|
+
test("a path that names a directory answers unknown", (t) => {
|
|
311
|
+
const w = repo(t);
|
|
312
|
+
mkdirSync(join(w, "sub"));
|
|
313
|
+
commitFile(w, "sub/inner.mjs", "const wrong = 2;\n", "a file in a directory");
|
|
314
|
+
push(w);
|
|
315
|
+
|
|
316
|
+
const r = probe(w, ["--path", "sub", "--gone", "const wrong = 2;"]);
|
|
317
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
318
|
+
assert.equal(r.json.verdict, "unknown");
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// The exit code from the other end: 1 means "provably fixed", and Node's own
|
|
322
|
+
// default for an uncaught throw is also 1. A probe that cannot run git at all
|
|
323
|
+
// must not land there.
|
|
324
|
+
test("git unavailable answers unknown, never fixed", (t) => {
|
|
325
|
+
const w = repo(t);
|
|
326
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "const keep = 1;"], { ...ENV, PATH: "" });
|
|
327
|
+
assert.equal(r.code, 2, `expected could-not-check (exit 2), got ${r.code}: ${r.stderr}`);
|
|
328
|
+
assert.equal(r.json.verdict, "unknown");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Neither mode given is a question the caller did not ask. Refusing beats
|
|
332
|
+
// picking a direction, because the wrong direction reports the opposite
|
|
333
|
+
// verdict with full confidence.
|
|
334
|
+
test("neither --gone nor --present refuses at exit 2 with no payload", (t) => {
|
|
335
|
+
const w = repo(t);
|
|
336
|
+
const r = probe(w, ["--path", "src.mjs"]);
|
|
337
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
338
|
+
assert.equal(r.json, null, "a refusal must print no verdict at all");
|
|
339
|
+
assert.match(r.stderr, /^\nstaleness: /m);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("both --gone and --present refuses at exit 2 with no payload", (t) => {
|
|
343
|
+
const w = repo(t);
|
|
344
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "a", "--present", "b"]);
|
|
345
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
346
|
+
assert.equal(r.json, null);
|
|
347
|
+
assert.match(r.stderr, /opposite questions/);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// #818: the end-of-options separator. Without it, a `--`-prefixed needle can
|
|
351
|
+
// never reach this script's question — arg() refuses it as a missing value,
|
|
352
|
+
// and #240's ticket quotes exactly that shape, `--label ready-for-agent`.
|
|
353
|
+
// `--gone -- '<value>'` reads the token after `--` literally, however it
|
|
354
|
+
// starts.
|
|
355
|
+
test("a --gone needle starting with -- is checked when given after the end-of-options separator", (t) => {
|
|
356
|
+
const w = repo(t);
|
|
357
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst flag = '--require-file';\n", "the defect");
|
|
358
|
+
push(w);
|
|
359
|
+
|
|
360
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--", "--require-file"]);
|
|
361
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
362
|
+
assert.equal(r.json.verdict, "live");
|
|
363
|
+
assert.equal(r.json.needle, "--require-file", "the payload must carry the literal needle, not the separator");
|
|
364
|
+
assert.equal(r.json.found, true);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// THE CONTROL. This is what proves #61/#169's original refusal survived
|
|
368
|
+
// #818: the identical needle, given bare with no separator, must still be
|
|
369
|
+
// refused — a flag swallowing the next flag as its own value was a real
|
|
370
|
+
// measured defect, and #818 only adds an opt-in past it, never weakens it.
|
|
371
|
+
test("the same --gone needle with NO separator is still refused at exit 2, today's message", (t) => {
|
|
372
|
+
const w = repo(t);
|
|
373
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst flag = '--require-file';\n", "the defect");
|
|
374
|
+
push(w);
|
|
375
|
+
|
|
376
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--require-file"]);
|
|
377
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
378
|
+
assert.equal(r.json, null, "a refusal must print no verdict at all");
|
|
379
|
+
assert.match(r.stderr, /^\nstaleness: --gone needs a value$/m);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// --present takes the same path through the separator opt-in as --gone;
|
|
383
|
+
// covered separately because a fix wiring only one of the two flags would
|
|
384
|
+
// pass every --gone case above.
|
|
385
|
+
test("a --present needle starting with -- is checked when given after the separator", (t) => {
|
|
386
|
+
const w = repo(t);
|
|
387
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "--", "--not-here"]);
|
|
388
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
389
|
+
assert.equal(r.json.verdict, "live");
|
|
390
|
+
assert.equal(r.json.needle, "--not-here");
|
|
391
|
+
assert.equal(r.json.found, false);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// A needle that does NOT start with -- must answer identically whether or
|
|
395
|
+
// not the separator wraps it — the separator is an opt-in for one shape of
|
|
396
|
+
// value, not a different code path for an ordinary one.
|
|
397
|
+
test("an ordinary needle answers the same with or without the separator", (t) => {
|
|
398
|
+
const w = repo(t);
|
|
399
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst wrong = 2;\n", "the defect");
|
|
400
|
+
push(w);
|
|
401
|
+
|
|
402
|
+
const bare = probe(w, ["--path", "src.mjs", "--gone", "const wrong = 2;"]);
|
|
403
|
+
const separated = probe(w, ["--path", "src.mjs", "--gone", "--", "const wrong = 2;"]);
|
|
404
|
+
assert.equal(bare.code, separated.code);
|
|
405
|
+
assert.deepEqual(bare.json, separated.json);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// The separator only counts immediately after the flag it modifies. A value
|
|
409
|
+
// given first with `--` trailing after it is the malformed order, not the
|
|
410
|
+
// opt-in spelling, and must refuse exactly like the no-separator case —
|
|
411
|
+
// otherwise the separator would forgive the exact invocation #61/#169
|
|
412
|
+
// exists to catch.
|
|
413
|
+
//
|
|
414
|
+
// The token AFTER the trailing `--` is what makes this discriminate, and it
|
|
415
|
+
// has to be a word the fixture carries. With nothing after the separator,
|
|
416
|
+
// a reader that took the LAST `--` in argv instead of the one immediately
|
|
417
|
+
// after the flag falls off the end of argv and dies on the same
|
|
418
|
+
// "needs a value" wording as the correct code — byte-identical stderr, exit
|
|
419
|
+
// and payload, so the case passes under the bug it names (measured). With
|
|
420
|
+
// `decoy` there and in the tree, that reader answers `live` at exit 0
|
|
421
|
+
// instead, on a needle nobody asked about.
|
|
422
|
+
test("a -- appearing AFTER the value, not before it, does not opt in — still refused", (t) => {
|
|
423
|
+
const w = repo(t);
|
|
424
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst decoy = 3;\n", "the decoy");
|
|
425
|
+
push(w);
|
|
426
|
+
|
|
427
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--require-file", "--", "decoy"]);
|
|
428
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
429
|
+
assert.equal(r.json, null);
|
|
430
|
+
assert.match(r.stderr, /--gone needs a value/);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// The separator with nothing after it is the same "no value" shape as
|
|
434
|
+
// today's bare-flag refusal, reached from the opt-in path instead.
|
|
435
|
+
test("-- as the very last token, with no value after it, refuses needs-a-value", (t) => {
|
|
436
|
+
const w = repo(t);
|
|
437
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--"]);
|
|
438
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
439
|
+
assert.equal(r.json, null);
|
|
440
|
+
assert.match(r.stderr, /--gone needs a value/);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// THE CLASS #818 EXISTS FOR, at its sharpest: the quoted needle spells one of
|
|
444
|
+
// this script's OWN flag names. A reader that resolves `--gone` over the whole
|
|
445
|
+
// argv before `--present` matches the token `--gone` sitting there as
|
|
446
|
+
// --present's already-quoted DATA, and refuses naming a flag the caller never
|
|
447
|
+
// typed — measured on that shape: `staleness: --gone needs a value`, exit 2.
|
|
448
|
+
// The needle here is absent from the tree, so the answer this must reach is
|
|
449
|
+
// `live` at exit 0; anything that reads it as a control token cannot get
|
|
450
|
+
// there.
|
|
451
|
+
test("a --present needle whose literal text is the sibling flag's own name is checked, not read as that flag", (t) => {
|
|
452
|
+
const w = repo(t);
|
|
453
|
+
const r = probe(w, ["--path", "src.mjs", "--present", "--", "--gone"]);
|
|
454
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
455
|
+
assert.equal(r.json.verdict, "live");
|
|
456
|
+
assert.equal(r.json.needle, "--gone", "the payload must carry the caller's needle, not the flag it spells");
|
|
457
|
+
assert.equal(r.json.found, false);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// Same class against `--path`, which is read AFTER the separator pass for
|
|
461
|
+
// exactly this reason: the quoted needle spells the flag whose value the
|
|
462
|
+
// script needs to find the file. Both assertions are load-bearing — the
|
|
463
|
+
// needle has to survive as data, and `--path` has to still resolve to
|
|
464
|
+
// src.mjs rather than to the quoted copy of its own name (measured on the
|
|
465
|
+
// resolve-path-first shape: `staleness: --path needs a value`, exit 2).
|
|
466
|
+
test("a --gone needle spelling --path leaves the real --path resolving to its own value", (t) => {
|
|
467
|
+
const w = repo(t);
|
|
468
|
+
commitFile(w, "src.mjs", "const keep = 1;\nconst flag = '--path';\n", "the defect");
|
|
469
|
+
push(w);
|
|
470
|
+
|
|
471
|
+
const r = probe(w, ["--gone", "--", "--path", "--path", "src.mjs"]);
|
|
472
|
+
assert.equal(r.code, 0, `expected live (exit 0), got ${r.code}: ${r.stderr}`);
|
|
473
|
+
assert.equal(r.json.verdict, "live");
|
|
474
|
+
assert.equal(r.json.needle, "--path");
|
|
475
|
+
assert.equal(r.json.path, "src.mjs", "the second --path is the flag; the first is the needle");
|
|
476
|
+
assert.equal(r.json.found, true);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// The both-flags refusal, reached through the separator form. The bare-form
|
|
480
|
+
// case above it is pinned by a raw argv scan too, so it alone cannot tell
|
|
481
|
+
// this guard's resolved-value reading from a `process.argv.includes("--gone")
|
|
482
|
+
// && process.argv.includes("--present")` one: the separator pass splices both
|
|
483
|
+
// flag tokens out of argv before the guard runs, so that scan finds neither
|
|
484
|
+
// and lets the run through — measured, exit 0 with a full-confidence `live`
|
|
485
|
+
// under `--gone` while `--present` is silently dropped.
|
|
486
|
+
test("both --gone and --present through the separator form refuses at exit 2", (t) => {
|
|
487
|
+
const w = repo(t);
|
|
488
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--", "--defect", "--present", "--", "--wanted"]);
|
|
489
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
490
|
+
assert.equal(r.json, null, "a refusal must print no verdict at all");
|
|
491
|
+
assert.match(r.stderr, /opposite questions/);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// A repeated `--gone -- <value>` must not silently answer about the LAST one.
|
|
495
|
+
// The separator pass consumes a name once and steps over any repeat, which
|
|
496
|
+
// leaves that repeat's `--` a token no flag owns — and sweep() refuses it,
|
|
497
|
+
// the same exit-2 wording this shape earned before the pass existed.
|
|
498
|
+
test("a second --gone -- <value> refuses, rather than overwriting the first", (t) => {
|
|
499
|
+
const w = repo(t);
|
|
500
|
+
const r = probe(w, ["--path", "src.mjs", "--gone", "--", "a", "--gone", "--", "b"]);
|
|
501
|
+
assert.equal(r.code, 2, `expected refusal (exit 2), got ${r.code}: ${r.stderr}`);
|
|
502
|
+
assert.equal(r.json, null);
|
|
503
|
+
assert.match(r.stderr, /unknown flag --/);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// ── #889/#1549: verdict() routes its write through arg.mjs's writeAll() ──
|
|
507
|
+
//
|
|
508
|
+
// A single writeSync call can short-write on a non-blocking pipe: it returns
|
|
509
|
+
// the count it actually wrote and throws nothing at all, so a `try`/`catch`
|
|
510
|
+
// wrapped around one call never fires and the verdict payload is silently
|
|
511
|
+
// truncated with no diagnostic — the same class ci-state.mjs's emit() had
|
|
512
|
+
// before #885. Unlike ci-state.mjs, staleness.mjs never initialises its own
|
|
513
|
+
// stream on fd 1 (nothing here calls console.log/process.stdout), so fd 1
|
|
514
|
+
// only goes non-blocking if a parent process hands it that way; the
|
|
515
|
+
// hardening still matters for that caller shape, which is why it is pinned
|
|
516
|
+
// here rather than dropped as unreachable. Racing a reader into that
|
|
517
|
+
// non-blocking state is what the NOT-PINNED comment above verdict() already
|
|
518
|
+
// refuses to do for the pipe-closed case, so this is a deterministic
|
|
519
|
+
// source-shape pin instead.
|
|
520
|
+
//
|
|
521
|
+
// #1549: the LOOP is no longer here to pin. It was one of three hand-mirrored
|
|
522
|
+
// copies and now lives once in arg.mjs's writeAll(), whose shape and
|
|
523
|
+
// behaviour are pinned and EXECUTED in arg.test.mjs. This file used to carry
|
|
524
|
+
// a near-copy of that same regex, differing from the other two only in head
|
|
525
|
+
// line and fd. What is pinned here instead is what stays verdict()'s OWN —
|
|
526
|
+
// the three things a caller of writeAll has to get right:
|
|
527
|
+
// - the write goes through writeAll on fd 1, not a re-inlined writeSync;
|
|
528
|
+
// - the payload's CONSTRUCTION sits inside the try, so a circular `extra`
|
|
529
|
+
// or a throwing toJSON downgrades instead of escaping verdict() uncaught;
|
|
530
|
+
// - the false return is actually READ, so a lost verdict becomes
|
|
531
|
+
// could-not-check rather than being reported as a delivered one.
|
|
532
|
+
// Measured: a mutant for each of those three reds this pin, and none of them
|
|
533
|
+
// reds arg.test.mjs's writeAll pins — the two files pin different halves, and
|
|
534
|
+
// neither alone catches both defects.
|
|
535
|
+
test("verdict() writes through writeAll() and downgrades on its false return, rather than re-inlining the loop", () => {
|
|
536
|
+
assert.match(
|
|
537
|
+
stripComments(readFileSync(SCRIPT, "utf8")),
|
|
538
|
+
/^\s*let ok = false;\s*^\s*try \{\s*^\s*ok = writeAll\(1, `\$\{JSON\.stringify\(\{[^`]*\)\}\\n`\);\s*^\s*\} catch \{\s*^\s*\}\s*^\s*if \(!ok\) die\("the verdict could not be written/m,
|
|
539
|
+
);
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// verdict()'s EAGAIN retry had the same #889 gap as die()'s: no cap, so a
|
|
543
|
+
// stdout reader that stays open but never drains left writeSync throwing
|
|
544
|
+
// EAGAIN forever and the "a failed write is a could-not-check" downgrade this
|
|
545
|
+
// function's own comment promises — the whole reason it writeSyncs instead of
|
|
546
|
+
// console.log — never ran. The cap lives in writeAll() now (#1549): past
|
|
547
|
+
// MAX_EAGAIN_RETRIES it returns false, verdict()'s `if (!ok)` calls die(), and
|
|
548
|
+
// the process still exits 2 with the could-not-check refusal on stderr. This
|
|
549
|
+
// test is untouched by that move and still measures the whole path end to
|
|
550
|
+
// end, which is what makes the extraction safe rather than merely tidy.
|
|
551
|
+
//
|
|
552
|
+
// Reproduced with a real non-blocking pipe, not a mock: fcntl sets O_NONBLOCK
|
|
553
|
+
// on the write end before the child ever touches it, so the OS — not a stub
|
|
554
|
+
// — is what throws EAGAIN. The read end is held open but never read, which is
|
|
555
|
+
// the case this pins: closing it instead would make every write EPIPE, a
|
|
556
|
+
// different (already-handled) failure this loop's cap is not needed for.
|
|
557
|
+
test("verdict() falls through to the could-not-check downgrade within a bound when stdout is a saturated pipe whose reader never drains — #889's retry cap", (t) => {
|
|
558
|
+
if (spawnSync("python3", ["-c", ""]).status !== 0) return t.skip("needs python3");
|
|
559
|
+
const w = repo(t);
|
|
560
|
+
|
|
561
|
+
const harness = [
|
|
562
|
+
"import fcntl, os, subprocess, sys, time",
|
|
563
|
+
"r, w = os.pipe()",
|
|
564
|
+
"fcntl.fcntl(w, fcntl.F_SETFL, fcntl.fcntl(w, fcntl.F_GETFL) | os.O_NONBLOCK)",
|
|
565
|
+
"try:",
|
|
566
|
+
" while True:",
|
|
567
|
+
" os.write(w, b'x' * 65536)",
|
|
568
|
+
"except BlockingIOError:",
|
|
569
|
+
" pass",
|
|
570
|
+
"start = time.time()",
|
|
571
|
+
"proc = subprocess.Popen(sys.argv[1:], stdout=w, stderr=subprocess.PIPE)",
|
|
572
|
+
"os.close(w)",
|
|
573
|
+
"try:",
|
|
574
|
+
" _, err = proc.communicate(timeout=5)",
|
|
575
|
+
"except subprocess.TimeoutExpired:",
|
|
576
|
+
" proc.kill()",
|
|
577
|
+
" proc.wait()",
|
|
578
|
+
" print('TIMEOUT')",
|
|
579
|
+
" sys.exit(1)",
|
|
580
|
+
"print(f'EXIT={proc.returncode} ELAPSED={time.time() - start:.3f}')",
|
|
581
|
+
"sys.stderr.write(err.decode())",
|
|
582
|
+
].join("\n");
|
|
583
|
+
|
|
584
|
+
const r = spawnSync(
|
|
585
|
+
"python3",
|
|
586
|
+
["-c", harness, process.execPath, SCRIPT, "--path", "src.mjs", "--gone", "a spelling this file never had"],
|
|
587
|
+
{ cwd: w, env: ENV, encoding: "utf8" },
|
|
588
|
+
);
|
|
589
|
+
assert.match(
|
|
590
|
+
r.stdout,
|
|
591
|
+
/^EXIT=2 ELAPSED=\d/m,
|
|
592
|
+
`verdict() must exit 2 within the bound against a permanently saturated stdout pipe; got stdout=${r.stdout} stderr=${r.stderr}`,
|
|
593
|
+
);
|
|
594
|
+
assert.match(
|
|
595
|
+
r.stderr,
|
|
596
|
+
/the verdict could not be written to stdout . could not check/,
|
|
597
|
+
`verdict() must still deliver the could-not-check refusal on stderr once the retry cap is hit; got: ${r.stderr}`,
|
|
598
|
+
);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// The needle reaches the script as a single argv item, and Linux caps ONE
|
|
602
|
+
// argv item at MAX_ARG_STRLEN — 32 pages, so 131072 bytes on a 4 KiB-page
|
|
603
|
+
// kernel, which is what CI runs on. Past it execve refuses the whole spawn
|
|
604
|
+
// with E2BIG. darwin caps only the total (~1 MiB ARG_MAX) and has no
|
|
605
|
+
// per-argument cap at all, which is why a needle sized against this machine
|
|
606
|
+
// alone passes here and reds on CI. `git log -S` takes the same needle as
|
|
607
|
+
// its own argv item, so the cap binds the grandchild too.
|
|
608
|
+
//
|
|
609
|
+
// Same name and number as ledger.test.mjs's own constant, which carries the
|
|
610
|
+
// measurement: that file hit this exact wall and records that the refusal is
|
|
611
|
+
// not a truncation — spawnSync comes back with a null status, reading like
|
|
612
|
+
// the very defect its tests exist to catch. It stays under the cap by
|
|
613
|
+
// splitting its payload across several argv elements; that is not available
|
|
614
|
+
// here, because `--gone` takes the needle as one value, so this fixture
|
|
615
|
+
// sizes the single element instead.
|
|
616
|
+
const ARG_STRLEN_MAX = 131_072;
|
|
617
|
+
|
|
618
|
+
// How much room the short-write fixture below leaves in the pipe before the
|
|
619
|
+
// child's first write. Small on purpose: what makes that write come back
|
|
620
|
+
// SHORT is this window, not the payload outgrowing some capacity, which is
|
|
621
|
+
// the whole of why the fixture no longer has to be sized against a ceiling
|
|
622
|
+
// it cannot reach (#1578). Not arbitrary, though (#1688): Linux gives pipe
|
|
623
|
+
// space back one whole slot — one page — at a time, so there the window has
|
|
624
|
+
// to be a whole number of pages. 4096 is one page on this repo's CI kernel
|
|
625
|
+
// (ubuntu-latest, x86_64); the harness measures that rather than assuming it.
|
|
626
|
+
const WRITE_WINDOW_BYTES = 4096;
|
|
627
|
+
|
|
628
|
+
// ── #1548: verdict()'s writeSync loop delivers the FULL payload, EXECUTED ─
|
|
629
|
+
//
|
|
630
|
+
// The retry-cap test above only proves the loop gives up in time against a
|
|
631
|
+
// pipe that never drains at all; it says nothing about what a loop that DOES
|
|
632
|
+
// keep draining actually delivers, and #889's source-shape pin above has the
|
|
633
|
+
// same gap arg.mjs's die() pin does: a mutant that collapses the while loop
|
|
634
|
+
// to one bare `writeSync(1, buf)` still satisfies a pin anchored on the try
|
|
635
|
+
// block's shape, and a short write from that single call would silently
|
|
636
|
+
// truncate the verdict with nothing here to catch it.
|
|
637
|
+
//
|
|
638
|
+
// #1578: this ran under a plain spawnSync for three CI rounds and never once
|
|
639
|
+
// exercised the loop on Linux. Sizing the payload to outgrow one write is
|
|
640
|
+
// what failed there, and it failed for a reason no number fixes. What a
|
|
641
|
+
// single non-blocking write to a pipe transfers is not the pipe's capacity:
|
|
642
|
+
// spawnSync's reader drains CONCURRENTLY, and Linux's pipe_write keeps
|
|
643
|
+
// filling slots as the reader frees them, returning only once it finds the
|
|
644
|
+
// pipe full. The ceiling is a RACE against the reader, not a constant —
|
|
645
|
+
// measured at 146176 bytes in one call on this repo's CI runner, with
|
|
646
|
+
// board-cli.test.mjs's independent 100-run ubuntu measurement reporting that
|
|
647
|
+
// same 146176 for one console.error write and a RANGE of 146239-182783 for
|
|
648
|
+
// the looped build. The spread is the race. And 146176 is past
|
|
649
|
+
// ARG_STRLEN_MAX, so on that runner NO needle both outgrows one write and
|
|
650
|
+
// survives execve: the two constraints do not overlap, and picking a bigger
|
|
651
|
+
// number cannot fix it. Raising the needle was tried twice and reddened CI
|
|
652
|
+
// against a correct build both times.
|
|
653
|
+
//
|
|
654
|
+
// So this stops racing the reader and removes it instead. The pipe is filled
|
|
655
|
+
// to capacity up front and exactly WRITE_WINDOW_BYTES freed back, and nothing
|
|
656
|
+
// reads it again until that window is gone. A reader that is not draining is
|
|
657
|
+
// one the kernel cannot keep handing slots to, so the first write stops at
|
|
658
|
+
// the window and returns short by construction, at a size the payload no
|
|
659
|
+
// longer has to beat. That decouples the needle from the write ceiling
|
|
660
|
+
// entirely, which is what leaves it free to sit far under ARG_STRLEN_MAX
|
|
661
|
+
// instead of straining against it.
|
|
662
|
+
//
|
|
663
|
+
// "By construction" holds only where the kernel hands a freed window back
|
|
664
|
+
// to a writer as one write, and that is not every platform (#1688).
|
|
665
|
+
// darwin's pipe is byte-granular: measured on this arm64 machine, any window
|
|
666
|
+
// tried — 1000, 2048, 4096, 6000, 16384 — came back as exactly that many
|
|
667
|
+
// bytes. Linux frees pipe space a page-sized slot at a time, so the window
|
|
668
|
+
// must be a whole number of pages. Measured on a 4 KiB-page aarch64 Linux
|
|
669
|
+
// kernel (docker, node 26.5.0): windows of 4096 and 8192 came back exact,
|
|
670
|
+
// 6000 came back as 4096, and 2048 — under one page — came back EAGAIN.
|
|
671
|
+
// 2048 on that kernel is what 4096 is on a 16 KiB- or 64 KiB-page one (some
|
|
672
|
+
// arm64 and ppc64 builds), and run through this test before the probe below
|
|
673
|
+
// existed it redded against a correct build after a 10s wait, blaming the
|
|
674
|
+
// build: "verdict()'s first write never filled the 2048-byte window ... the
|
|
675
|
+
// retry loop was never entered". The page size is not a usable proxy for
|
|
676
|
+
// that — this darwin machine reports 16384 for SC_PAGESIZE and still takes a
|
|
677
|
+
// 4096-byte window exactly — so the harness measures the premise itself: a
|
|
678
|
+
// probe write into the freed window must land exactly WRITE_WINDOW_BYTES, or
|
|
679
|
+
// it refuses with WINDOW_NOT_ONE_WRITE and the numbers it saw, before the
|
|
680
|
+
// child ever runs. Measured, that same 2048 run now reports
|
|
681
|
+
// `WINDOW_NOT_ONE_WRITE probe=0 window=2048 page=4096` instead.
|
|
682
|
+
//
|
|
683
|
+
// Measured both ways through this harness (darwin, pipe capacity 65536,
|
|
684
|
+
// window 4096): the shipped build delivers 40278 bytes of valid JSON, and
|
|
685
|
+
// writeAll() collapsed to one bare `writeSync(fd, buf)` delivers exactly
|
|
686
|
+
// 4096 — the window, and nothing after it — so the payload is truncated
|
|
687
|
+
// mid-needle and JSON.parse throws. That is the kill, and it no longer
|
|
688
|
+
// depends on which way a race fell.
|
|
689
|
+
//
|
|
690
|
+
// python3 is what supplies a reader that does not drain and a write end
|
|
691
|
+
// already in O_NONBLOCK: the same harness shape, and the same gate, as the
|
|
692
|
+
// retry-cap test above. That gate is a runtime-CAPABILITY gate, not the
|
|
693
|
+
// platform gate #951 removed — it does not track the platform under test, CI
|
|
694
|
+
// provisions python3 (ci.yml says so where it explains what the suite
|
|
695
|
+
// spawns), and both legs run it. #951 left a non-zero `skipped` on CI a real
|
|
696
|
+
// signal again, and this test keeps it one rather than becoming a new floor.
|
|
697
|
+
//
|
|
698
|
+
// fd 1 being non-blocking under this harness is NOT re-derived here: the
|
|
699
|
+
// retry-cap test above pins it and can only pass because of it — a blocking
|
|
700
|
+
// fd 1 against a permanently full pipe would hang that child until its 5s
|
|
701
|
+
// timeout instead of exiting 2 on the EAGAIN cap. Should a platform ever
|
|
702
|
+
// make fd 1 blocking, that test reds loudly rather than this one passing
|
|
703
|
+
// quietly on a write that blocked its way to completion in one call.
|
|
704
|
+
//
|
|
705
|
+
// The needle is real to git, not just a value verdict()'s own writeSync
|
|
706
|
+
// sees: an unmatched pathspec-scale string is still walked by `git log -S`,
|
|
707
|
+
// so this exercises the "gone" not-found path, not a stub — and THAT is
|
|
708
|
+
// asserted rather than merely documented, because the walk-found-nothing
|
|
709
|
+
// branch and the `git log -S`-failed branch both answer `unknown` at this
|
|
710
|
+
// exit code with the needle echoed back. Only the walk-found-nothing answer
|
|
711
|
+
// carries `found` and `bytes`; staleness.mjs's failed-walk downgrade passes
|
|
712
|
+
// no extra fields at all. `bytes` is the size of the blob origin/main holds
|
|
713
|
+
// at the asked-for path, derived from the fixture's own origin below rather
|
|
714
|
+
// than written as a literal, so changing what repo() commits cannot leave
|
|
715
|
+
// the number behind.
|
|
716
|
+
//
|
|
717
|
+
// The verdict's own prose (`why`) is not pinned here — this file's header
|
|
718
|
+
// already says why not — so the delivery assertion is round-trip fidelity
|
|
719
|
+
// instead: a truncated write lands mid `needle`, which is not valid JSON at
|
|
720
|
+
// all (measured: collapsing the loop makes `JSON.parse` throw on the payload
|
|
721
|
+
// this test's fixture produces).
|
|
722
|
+
test("verdict() resumes from a genuine short write and delivers the full payload, not just the first pipe buffer", (t) => {
|
|
723
|
+
if (spawnSync("python3", ["-c", ""]).status !== 0) return t.skip("needs python3");
|
|
724
|
+
const w = repo(t);
|
|
725
|
+
const scriptDir = mkdtempSync(join(tmpdir(), "staleness-short-"));
|
|
726
|
+
// repo(t) reaps its own tree; this dir holds the captured stdout, and had
|
|
727
|
+
// nothing reaping it.
|
|
728
|
+
t.after(() => rmSync(scriptDir, { recursive: true, force: true }));
|
|
729
|
+
const captured = join(scriptDir, "stdout.bin");
|
|
730
|
+
const needle = "y".repeat(40_000);
|
|
731
|
+
|
|
732
|
+
// Reproduced with a real non-blocking pipe, not a mock: fcntl sets
|
|
733
|
+
// O_NONBLOCK on the write end before the child ever touches it, so the OS —
|
|
734
|
+
// not a stub — is what short-writes. The read end is held open and is NOT
|
|
735
|
+
// read until the window has closed again, which is the whole mechanism:
|
|
736
|
+
// FIONREAD reports the pipe's fill level without consuming a byte, so the
|
|
737
|
+
// fixture can wait for the child's first write to land while still giving
|
|
738
|
+
// it nowhere to put a second one.
|
|
739
|
+
const harness = [
|
|
740
|
+
"import array, fcntl, os, select, subprocess, sys, termios, time",
|
|
741
|
+
"out_path, window = sys.argv[1], int(sys.argv[2])",
|
|
742
|
+
"r, w = os.pipe()",
|
|
743
|
+
"fcntl.fcntl(w, fcntl.F_SETFL, fcntl.fcntl(w, fcntl.F_GETFL) | os.O_NONBLOCK)",
|
|
744
|
+
"# Fill the pipe to capacity, then free exactly `window` bytes back.",
|
|
745
|
+
"pad = 0",
|
|
746
|
+
"try:",
|
|
747
|
+
" while True:",
|
|
748
|
+
" pad += os.write(w, b'x' * 4096)",
|
|
749
|
+
"except BlockingIOError:",
|
|
750
|
+
" pass",
|
|
751
|
+
"if pad <= window:",
|
|
752
|
+
" print(f'PAD_TOO_SMALL pad={pad} window={window}')",
|
|
753
|
+
" sys.exit(1)",
|
|
754
|
+
"def free_window():",
|
|
755
|
+
" freed = 0",
|
|
756
|
+
" while freed < window:",
|
|
757
|
+
" freed += len(os.read(r, window - freed))",
|
|
758
|
+
"free_window()",
|
|
759
|
+
"# Probe the premise before trusting it: a write bigger than the window",
|
|
760
|
+
"# must land exactly `window` bytes. A kernel that frees pipe space a",
|
|
761
|
+
"# page-sized slot at a time answers 0 (EAGAIN) to a window under a page,",
|
|
762
|
+
"# and short of `window` to one that is not a whole number of pages.",
|
|
763
|
+
"probe = 0",
|
|
764
|
+
"try:",
|
|
765
|
+
" probe = os.write(w, b'x' * (window * 2))",
|
|
766
|
+
"except BlockingIOError:",
|
|
767
|
+
" pass",
|
|
768
|
+
"if probe != window:",
|
|
769
|
+
" page = os.sysconf('SC_PAGESIZE')",
|
|
770
|
+
" print(f'WINDOW_NOT_ONE_WRITE probe={probe} window={window} page={page}')",
|
|
771
|
+
" sys.exit(1)",
|
|
772
|
+
"# The probe closed the window with more pad; free it again. What sits",
|
|
773
|
+
"# ahead of the child's output is still `pad - window` bytes of pad.",
|
|
774
|
+
"free_window()",
|
|
775
|
+
"proc = subprocess.Popen(sys.argv[3:], stdout=w, stderr=subprocess.PIPE)",
|
|
776
|
+
"os.close(w)",
|
|
777
|
+
"# Wait for the child's first write to close that window again WITHOUT",
|
|
778
|
+
"# reading: a full pipe is that write having returned short.",
|
|
779
|
+
"pending = array.array('i', [0])",
|
|
780
|
+
"consumed = 0",
|
|
781
|
+
"deadline = time.time() + 10",
|
|
782
|
+
"while time.time() < deadline:",
|
|
783
|
+
" fcntl.ioctl(r, termios.FIONREAD, pending)",
|
|
784
|
+
" if pending[0] >= pad:",
|
|
785
|
+
" consumed = 1",
|
|
786
|
+
" break",
|
|
787
|
+
" time.sleep(0.001)",
|
|
788
|
+
"# No settle sleep follows: measured, it is not load-bearing for any",
|
|
789
|
+
"# assertion below (`delivered` is the whole payload; `consumed` is a 0/1",
|
|
790
|
+
"# flag, not a byte count). The real bound is writeAll()'s own",
|
|
791
|
+
"# MAX_EAGAIN_RETRIES (arg.mjs) — the harness may hold the pipe undrained",
|
|
792
|
+
"# for at most that many milliseconds, and the FIONREAD poll above is",
|
|
793
|
+
"# what spends it.",
|
|
794
|
+
"chunks, err, fds = [], [], [r, proc.stderr.fileno()]",
|
|
795
|
+
"hard = time.time() + 20",
|
|
796
|
+
"while fds and time.time() < hard:",
|
|
797
|
+
" for fd in select.select(fds, [], [], 1)[0]:",
|
|
798
|
+
" data = os.read(fd, 1 << 16)",
|
|
799
|
+
" if not data:",
|
|
800
|
+
" fds.remove(fd)",
|
|
801
|
+
" elif fd == r:",
|
|
802
|
+
" chunks.append(data)",
|
|
803
|
+
" else:",
|
|
804
|
+
" err.append(data)",
|
|
805
|
+
"if fds:",
|
|
806
|
+
" proc.kill()",
|
|
807
|
+
" print('DRAIN_TIMEOUT')",
|
|
808
|
+
" sys.exit(1)",
|
|
809
|
+
"proc.wait()",
|
|
810
|
+
"blob = b''.join(chunks)",
|
|
811
|
+
"carry = pad - window",
|
|
812
|
+
"payload = blob[carry:]",
|
|
813
|
+
"with open(out_path, 'wb') as f:",
|
|
814
|
+
" f.write(payload)",
|
|
815
|
+
"print(f'EXIT={proc.returncode} PAD={pad} CONSUMED={consumed} PAYLOAD={len(payload)}')",
|
|
816
|
+
"sys.stderr.write(b''.join(err).decode('utf-8', 'replace'))",
|
|
817
|
+
].join("\n");
|
|
818
|
+
|
|
819
|
+
const r = spawnSync(
|
|
820
|
+
"python3",
|
|
821
|
+
[
|
|
822
|
+
"-c",
|
|
823
|
+
harness,
|
|
824
|
+
captured,
|
|
825
|
+
String(WRITE_WINDOW_BYTES),
|
|
826
|
+
process.execPath,
|
|
827
|
+
SCRIPT,
|
|
828
|
+
"--path",
|
|
829
|
+
"src.mjs",
|
|
830
|
+
"--gone",
|
|
831
|
+
needle,
|
|
832
|
+
],
|
|
833
|
+
{ cwd: w, env: ENV, encoding: "utf8" },
|
|
834
|
+
);
|
|
835
|
+
// The harness refuses rather than hanging when its own premises fail — a
|
|
836
|
+
// pipe too small to hold the window, a kernel that does not hand the freed
|
|
837
|
+
// window back as one write, a child that never finishes writing — so its
|
|
838
|
+
// exit code is checked before any number it reported is believed.
|
|
839
|
+
assert.equal(r.status, 0, `the short-write harness did not complete: stdout=${r.stdout} stderr=${r.stderr}`);
|
|
840
|
+
const report = /^EXIT=(\d+) PAD=(\d+) CONSUMED=(\d+) PAYLOAD=(\d+)$/m.exec(r.stdout);
|
|
841
|
+
assert.ok(report, `the harness printed no report line: stdout=${r.stdout} stderr=${r.stderr}`);
|
|
842
|
+
const [, exit, pad, consumed, delivered] = report.map(Number);
|
|
843
|
+
// Both ends of the needle's window. The lower end is the harness's own
|
|
844
|
+
// window now, not a pipe capacity or a racing reader's ceiling — 4 KiB is
|
|
845
|
+
// all the payload has to outgrow, which is what puts the upper end back
|
|
846
|
+
// within comfortable reach instead of a few KiB below it.
|
|
847
|
+
assert.ok(
|
|
848
|
+
needle.length > WRITE_WINDOW_BYTES,
|
|
849
|
+
`a ${needle.length}-byte needle no longer outgrows the ${WRITE_WINDOW_BYTES}-byte window, so the first write would not be short and this test would pass without proving anything`,
|
|
850
|
+
);
|
|
851
|
+
assert.ok(
|
|
852
|
+
needle.length < ARG_STRLEN_MAX,
|
|
853
|
+
`a ${needle.length}-byte needle is too long to survive execve as one argv item on a 4 KiB-page Linux kernel, so this fixture would refuse to spawn on CI while passing here`,
|
|
854
|
+
);
|
|
855
|
+
// The short write itself, measured rather than assumed: the window closed
|
|
856
|
+
// again while nothing was reading, so verdict()'s first write stopped at it.
|
|
857
|
+
assert.equal(
|
|
858
|
+
consumed,
|
|
859
|
+
1,
|
|
860
|
+
`verdict()'s first write never filled the ${WRITE_WINDOW_BYTES}-byte window (pipe capacity ${pad}), so nothing short-wrote and the retry loop was never entered`,
|
|
861
|
+
);
|
|
862
|
+
assert.equal(exit, 2, `expected the unknown verdict's exit code: stderr=${r.stderr}`);
|
|
863
|
+
// The kill. Every byte past that first window arrives only if the loop
|
|
864
|
+
// resumed; a collapsed loop stops at exactly WRITE_WINDOW_BYTES.
|
|
865
|
+
assert.ok(
|
|
866
|
+
delivered > WRITE_WINDOW_BYTES,
|
|
867
|
+
`verdict() delivered ${delivered} bytes — the ${WRITE_WINDOW_BYTES}-byte window and nothing after it — so the retry loop did not resume`,
|
|
868
|
+
);
|
|
869
|
+
let payload;
|
|
870
|
+
assert.doesNotThrow(
|
|
871
|
+
() => (payload = JSON.parse(readFileSync(captured, "utf8"))),
|
|
872
|
+
`verdict()'s payload is not valid JSON — a short write landed mid-needle: ${delivered} bytes captured`,
|
|
873
|
+
);
|
|
874
|
+
assert.equal(payload.verdict, "unknown");
|
|
875
|
+
assert.equal(
|
|
876
|
+
payload.needle.length,
|
|
877
|
+
needle.length,
|
|
878
|
+
`needle arrived truncated: got ${payload.needle.length} bytes, sent ${needle.length}`,
|
|
879
|
+
);
|
|
880
|
+
assert.equal(payload.needle, needle);
|
|
881
|
+
// The walk ran and came back empty, rather than the `git log -S` call
|
|
882
|
+
// failing into the same verdict: only the empty-walk answer carries these.
|
|
883
|
+
assert.equal(
|
|
884
|
+
payload.found,
|
|
885
|
+
false,
|
|
886
|
+
"the --gone needle must be absent from the current file for this to be the not-found path",
|
|
887
|
+
);
|
|
888
|
+
assert.equal(
|
|
889
|
+
payload.bytes,
|
|
890
|
+
Number(git(w, "cat-file", "-s", "origin/main:src.mjs")),
|
|
891
|
+
"`bytes` must be the size of the blob origin/main holds at the asked-for path — the failed-walk downgrade carries no `bytes` at all",
|
|
892
|
+
);
|
|
893
|
+
});
|