@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,1042 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tempDir } from "./temp-dir.mjs";
|
|
7
|
-
import { writeExecStub } from "./exec-stub.mjs";
|
|
8
|
-
import { commandBudget } from "./recipe-prove.mjs";
|
|
9
|
-
|
|
10
|
-
// recipe-prove.mjs is the Recipe derivation step's proof and the ONE writer of
|
|
11
|
-
// the Recipe cache: the deriving agent chooses the Install step and the Test
|
|
12
|
-
// entrypoint by reading the repository, and this script is what turns that
|
|
13
|
-
// guess into a cache — or refuses to. These fixtures stand in for two
|
|
14
|
-
// ecosystems the plugin keeps no knowledge of: a Maven-shaped repo and a
|
|
15
|
-
// Go-shaped one, each run through a stub of its own toolchain on PATH, so the
|
|
16
|
-
// suite needs neither `mvn` nor `go` and still exercises a command the
|
|
17
|
-
// plugin never names.
|
|
18
|
-
const SCRIPT = join(import.meta.dirname, "recipe-prove.mjs");
|
|
19
|
-
const READER = join(import.meta.dirname, "derive-testcmd.sh");
|
|
20
|
-
|
|
21
|
-
// Fixture construction must not inherit an ambient GIT_DIR: under one, `git
|
|
22
|
-
// init` re-inits whatever it names and the fixture is built nowhere.
|
|
23
|
-
const FIXTURE_ENV = { ...process.env, GIT_DIR: undefined, GIT_WORK_TREE: undefined };
|
|
24
|
-
|
|
25
|
-
// A stub `mvn`: `test` counts the @Test methods under src/test/java, prints
|
|
26
|
-
// Surefire's own summary line, and fails when a test asserts 1 == 2. Any other
|
|
27
|
-
// goal stands in for a dependency fetch and writes into `target/`, which the
|
|
28
|
-
// fixture ignores — the build output a real install leaves behind.
|
|
29
|
-
const MVN = `#!/bin/sh
|
|
30
|
-
if [ "$1" = -q ]; then shift; fi
|
|
31
|
-
case $1 in
|
|
32
|
-
test)
|
|
33
|
-
n=0; fail=0
|
|
34
|
-
for f in $(find src/test/java -name '*Test.java' 2>/dev/null); do
|
|
35
|
-
c=$(grep -c '@Test' "$f"); n=$((n + c))
|
|
36
|
-
if grep -q 'assertEquals(1, 2)' "$f"; then fail=1; fi
|
|
37
|
-
done
|
|
38
|
-
if [ "$n" -eq 0 ]; then echo "No tests to run."; exit 0; fi
|
|
39
|
-
echo "Tests run: $n, Failures: $fail, Errors: 0, Skipped: 0"
|
|
40
|
-
if [ "$fail" -ne 0 ]; then echo "BUILD FAILURE"; exit 1; fi
|
|
41
|
-
echo "BUILD SUCCESS" ;;
|
|
42
|
-
*) mkdir -p target && : > target/deps ;;
|
|
43
|
-
esac
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
// A stub `go`: `go test ./...` reports "[no test files]" and passes when no
|
|
47
|
-
// _test.go is tracked — the vacuous green the real one gives — and otherwise
|
|
48
|
-
// passes only while Add still adds. It prints no test count, like the real
|
|
49
|
-
// one without -v: the mutation proof is the only proof this fixture offers.
|
|
50
|
-
const GO = `#!/bin/sh
|
|
51
|
-
[ "$1" = test ] || exit 0
|
|
52
|
-
if [ -z "$(find . -name '*_test.go' -not -path './.git/*')" ]; then
|
|
53
|
-
printf '? \\texample.com/calc\\t[no test files]\\n'; exit 0
|
|
54
|
-
fi
|
|
55
|
-
if grep -q 'return a + b' calc.go; then printf 'ok \\texample.com/calc\\t0.001s\\n'; exit 0; fi
|
|
56
|
-
printf -- '--- FAIL: TestAdd\\nFAIL\\texample.com/calc\\n'; exit 1
|
|
57
|
-
`;
|
|
58
|
-
|
|
59
|
-
function toolchain() {
|
|
60
|
-
const bin = tempDir("recipe-prove-bin-");
|
|
61
|
-
writeExecStub(join(bin, "mvn"), MVN);
|
|
62
|
-
writeExecStub(join(bin, "go"), GO);
|
|
63
|
-
return bin;
|
|
64
|
-
}
|
|
65
|
-
const BIN = toolchain();
|
|
66
|
-
|
|
67
|
-
const MAVEN_FILES = {
|
|
68
|
-
"pom.xml": "<project><modelVersion>4.0.0</modelVersion><groupId>x</groupId><artifactId>foo</artifactId><version>1</version></project>\n",
|
|
69
|
-
".gitignore": "target/\n",
|
|
70
|
-
"src/main/java/x/Foo.java": "package x; public class Foo { public int one() { return 1; } }\n",
|
|
71
|
-
"src/test/java/x/FooTest.java":
|
|
72
|
-
"package x;\nimport org.junit.jupiter.api.Test;\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n" +
|
|
73
|
-
"class FooTest {\n @Test void one() { assertEquals(1, new Foo().one()); }\n}\n",
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const GO_FILES = {
|
|
77
|
-
"go.mod": "module example.com/calc\n\ngo 1.22\n",
|
|
78
|
-
"calc.go": "package calc\n\nfunc Add(a, b int) int { return a + b }\n",
|
|
79
|
-
"calc_test.go":
|
|
80
|
-
'package calc\n\nimport "testing"\n\nfunc TestAdd(t *testing.T) {\n\tif Add(1, 2) != 3 {\n\t\tt.Fatal("Add")\n\t}\n}\n',
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
function git(dir, ...a) {
|
|
84
|
-
return execFileSync("git", a, { cwd: dir, stdio: "pipe", env: FIXTURE_ENV, encoding: "utf8" }).trim();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function write(dir, files) {
|
|
88
|
-
for (const [name, body] of Object.entries(files)) {
|
|
89
|
-
mkdirSync(join(dir, name, ".."), { recursive: true });
|
|
90
|
-
writeFileSync(join(dir, name), body);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// A repository whose `origin/main` is the commit holding `files` — the ref the
|
|
95
|
-
// proof runs against. Set with update-ref, so no remote is needed.
|
|
96
|
-
function repo(files) {
|
|
97
|
-
const dir = tempDir("recipe-prove-");
|
|
98
|
-
git(dir, "init", "-q");
|
|
99
|
-
git(dir, "config", "user.email", "t@t");
|
|
100
|
-
git(dir, "config", "user.name", "t");
|
|
101
|
-
write(dir, files);
|
|
102
|
-
git(dir, "add", "-A");
|
|
103
|
-
git(dir, "commit", "-q", "-m", "files");
|
|
104
|
-
git(dir, "update-ref", "refs/remotes/origin/main", "HEAD");
|
|
105
|
-
return { dir, head: git(dir, "rev-parse", "HEAD") };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function withoutTests(files) {
|
|
109
|
-
return Object.fromEntries(Object.entries(files).filter(([n]) => !/(^src\/test\/|_test\.go$)/.test(n)));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const cachePath = (dir) => join(dir, ".fleet", "recipe.json");
|
|
113
|
-
|
|
114
|
-
function prove(dir, args, { env = {}, cwd = dir } = {}) {
|
|
115
|
-
const tmp = tempDir("recipe-prove-tmp-");
|
|
116
|
-
const r = spawnSync(process.execPath, [SCRIPT, dir, ...args], {
|
|
117
|
-
encoding: "utf8",
|
|
118
|
-
cwd,
|
|
119
|
-
env: { ...FIXTURE_ENV, PATH: `${BIN}:${process.env.PATH}`, TMPDIR: tmp, ...env },
|
|
120
|
-
timeout: 60_000,
|
|
121
|
-
});
|
|
122
|
-
return { status: r.status, out: r.stdout, err: r.stderr, tmp };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function read(dir, field) {
|
|
126
|
-
const r = spawnSync("sh", [READER, dir, field], {
|
|
127
|
-
encoding: "utf8",
|
|
128
|
-
env: { ...FIXTURE_ENV, PATH: `${BIN}:${process.env.PATH}` },
|
|
129
|
-
});
|
|
130
|
-
return { status: r.status, out: r.stdout.replace(/\n$/, ""), err: r.stderr };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const MAVEN_PROOF = ["--install", "mvn -q dependency:go-offline", "--test", "mvn -q test", "--count-line", "Tests run: 1,", "--test-count", "1"];
|
|
134
|
-
const GO_PROOF = [
|
|
135
|
-
"--install", "go mod download",
|
|
136
|
-
"--test", "go test ./...",
|
|
137
|
-
"--mutate", "printf 'package calc\\n\\nfunc Add(a, b int) int { return a - b }\\n' > calc.go",
|
|
138
|
-
"--mutation", "Add subtracts instead of adding",
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
test("a Maven-shaped repo gets a proven cache: the count proof, derivedAt, installClean — and the reader accepts it", () => {
|
|
142
|
-
const { dir, head } = repo(MAVEN_FILES);
|
|
143
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
144
|
-
assert.equal(r.status, 0, r.err);
|
|
145
|
-
const cache = JSON.parse(readFileSync(cachePath(dir), "utf8"));
|
|
146
|
-
assert.deepEqual(cache, {
|
|
147
|
-
install: "mvn -q dependency:go-offline",
|
|
148
|
-
test: "mvn -q test",
|
|
149
|
-
derivedAt: head,
|
|
150
|
-
installClean: true,
|
|
151
|
-
testCount: 1,
|
|
152
|
-
});
|
|
153
|
-
assert.deepEqual([read(dir, "install").out, read(dir, "test").out], ["mvn -q dependency:go-offline", "mvn -q test"]);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test("a Go-shaped repo gets a proven cache through the mutation proof, which records what turned the run red", () => {
|
|
157
|
-
const { dir, head } = repo(GO_FILES);
|
|
158
|
-
const r = prove(dir, GO_PROOF);
|
|
159
|
-
assert.equal(r.status, 0, r.err);
|
|
160
|
-
const cache = JSON.parse(readFileSync(cachePath(dir), "utf8"));
|
|
161
|
-
assert.equal(cache.install, "go mod download");
|
|
162
|
-
assert.equal(cache.test, "go test ./...");
|
|
163
|
-
assert.equal(cache.derivedAt, head);
|
|
164
|
-
assert.equal(cache.installClean, true);
|
|
165
|
-
assert.equal(cache.testCount, undefined);
|
|
166
|
-
assert.match(cache.mutation, /^Add subtracts instead of adding — turned the run red \(exit 1\); changed calc\.go$/);
|
|
167
|
-
assert.equal(read(dir, "test").out, "go test ./...");
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test("the Maven fixture with its tests deleted gets NO cache, and the refusal names vacuity", () => {
|
|
171
|
-
const { dir } = repo(withoutTests(MAVEN_FILES));
|
|
172
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
173
|
-
assert.equal(r.status, 1, r.err);
|
|
174
|
-
assert.match(r.err, /NOT PROVEN — vacuous: the Test entrypoint's output does not contain the count line 'Tests run: 1,'/);
|
|
175
|
-
assert.match(r.err, /No Recipe cache written/);
|
|
176
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("the Go fixture with its tests deleted gets NO cache: the mutation leaves the run green, which is vacuity", () => {
|
|
180
|
-
const { dir } = repo(withoutTests(GO_FILES));
|
|
181
|
-
const r = prove(dir, GO_PROOF);
|
|
182
|
-
assert.equal(r.status, 1, r.err);
|
|
183
|
-
assert.match(r.err, /NOT PROVEN — vacuous: the mutation \(Add subtracts instead of adding\) did not turn the run red/);
|
|
184
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test("a count proof of zero tests is a failed proof, even when the runner prints exactly that", () => {
|
|
188
|
-
const { dir } = repo(withoutTests(MAVEN_FILES));
|
|
189
|
-
const r = prove(dir, ["--install", "true", "--test", "echo 'tests 0'", "--count-line", "tests 0", "--test-count", "0"]);
|
|
190
|
-
assert.equal(r.status, 1);
|
|
191
|
-
assert.match(r.err, /NOT PROVEN — vacuous: a test count of 0/);
|
|
192
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
test("the claimed count must be the number on the count line, not any number", () => {
|
|
196
|
-
const { dir } = repo(MAVEN_FILES);
|
|
197
|
-
const r = prove(dir, ["--install", "true", "--test", "mvn -q test", "--count-line", "Tests run: 1,", "--test-count", "7"]);
|
|
198
|
-
assert.equal(r.status, 1);
|
|
199
|
-
assert.match(r.err, /the count line 'Tests run: 1,' does not carry the test count 7/);
|
|
200
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test("an Install step that changes a tracked file is not proven", () => {
|
|
204
|
-
const { dir } = repo(MAVEN_FILES);
|
|
205
|
-
const r = prove(dir, ["--install", "echo '<!-- -->' >> pom.xml", ...MAVEN_PROOF.slice(2)]);
|
|
206
|
-
assert.equal(r.status, 1);
|
|
207
|
-
assert.match(r.err, /NOT PROVEN — the Install step changed the tree \(first: M pom\.xml\)/);
|
|
208
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test("an Install step that creates a file the tree neither tracks nor ignores is not proven", () => {
|
|
212
|
-
const { dir } = repo(MAVEN_FILES);
|
|
213
|
-
const r = prove(dir, ["--install", ": > deps.lock", ...MAVEN_PROOF.slice(2)]);
|
|
214
|
-
assert.equal(r.status, 1);
|
|
215
|
-
assert.match(r.err, /the Install step changed the tree \(first: \?\? deps\.lock\)/);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test("an Install step whose output the repo ignores IS proven — build output is not a dirty tree", () => {
|
|
219
|
-
// The stub mvn's dependency goal writes target/deps; the fixture ignores
|
|
220
|
-
// target/. Refusing here would refuse every repo whose install builds.
|
|
221
|
-
const { dir } = repo(MAVEN_FILES);
|
|
222
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
223
|
-
assert.equal(r.status, 0, r.err);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("an Install step or Test entrypoint that does not RUN is named as such", () => {
|
|
227
|
-
const { dir } = repo(MAVEN_FILES);
|
|
228
|
-
const i = prove(dir, ["--install", "no-such-installer-xyz", ...MAVEN_PROOF.slice(2)]);
|
|
229
|
-
assert.equal(i.status, 1);
|
|
230
|
-
assert.match(i.err, /NOT PROVEN — the Install step 'no-such-installer-xyz' did not run \(exit 127: not executable or not found\)/);
|
|
231
|
-
const t = prove(dir, ["--install", "true", "--test", "no-such-runner-xyz", "--count-line", "x 1", "--test-count", "1"]);
|
|
232
|
-
assert.equal(t.status, 1);
|
|
233
|
-
assert.match(t.err, /NOT PROVEN — the Test entrypoint 'no-such-runner-xyz' did not run \(exit 127/);
|
|
234
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test("an Install step that fails is not proven", () => {
|
|
238
|
-
const { dir } = repo(MAVEN_FILES);
|
|
239
|
-
const r = prove(dir, ["--install", "exit 3", ...MAVEN_PROOF.slice(2)]);
|
|
240
|
-
assert.equal(r.status, 1);
|
|
241
|
-
assert.match(r.err, /NOT PROVEN — the Install step 'exit 3' failed \(exit 3\)/);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test("the mutation proof refuses a red baseline: a mutation turning a red run red proves nothing", () => {
|
|
245
|
-
const { dir } = repo(GO_FILES);
|
|
246
|
-
const r = prove(dir, ["--install", "true", "--test", "go test ./... && exit 1", ...GO_PROOF.slice(4)]);
|
|
247
|
-
assert.equal(r.status, 1);
|
|
248
|
-
assert.match(r.err, /the unmutated run is already red \(exit 1\), so a mutation turning it red proves nothing — use the count proof/);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test("a mutation that changes no tracked file is refused, not counted as red", () => {
|
|
252
|
-
const { dir } = repo(GO_FILES);
|
|
253
|
-
const r = prove(dir, ["--install", "true", "--test", "go test ./...", "--mutate", ": > new_test.go", "--mutation", "adds a file"]);
|
|
254
|
-
assert.equal(r.status, 1);
|
|
255
|
-
assert.match(r.err, /the mutation \(adds a file\) changed no tracked file/);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test("a mutation that stages its edit still counts as changing a tracked file", () => {
|
|
259
|
-
const { dir } = repo(GO_FILES);
|
|
260
|
-
const r = prove(dir, [...GO_PROOF.slice(0, 4), "--mutate", `${GO_PROOF[5]} && git add calc.go`, "--mutation", "Add subtracts, staged"]);
|
|
261
|
-
assert.equal(r.status, 0, r.err);
|
|
262
|
-
assert.match(JSON.parse(readFileSync(cachePath(dir), "utf8")).mutation, /changed calc\.go$/);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test("no proof given is a refusal that still shows where the run's output is", () => {
|
|
266
|
-
const { dir } = repo(MAVEN_FILES);
|
|
267
|
-
const r = prove(dir, ["--install", "true", "--test", "mvn -q test"]);
|
|
268
|
-
assert.equal(r.status, 1);
|
|
269
|
-
assert.match(r.err, /NOT PROVEN — no proof given/);
|
|
270
|
-
const log = r.err.match(/test output: (\S+)/);
|
|
271
|
-
assert.ok(log, r.err);
|
|
272
|
-
assert.match(readFileSync(log[1], "utf8"), /Tests run: 1, Failures: 0/);
|
|
273
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("the proof runs against origin/main, not the checkout's own HEAD, and derivedAt says so", () => {
|
|
277
|
-
// The local branch has deleted the tests; origin/main still has them. A
|
|
278
|
-
// proof run against the checkout would be vacuous — against origin/main it
|
|
279
|
-
// is not.
|
|
280
|
-
const { dir, head } = repo(MAVEN_FILES);
|
|
281
|
-
rmSync(join(dir, "src", "test"), { recursive: true });
|
|
282
|
-
git(dir, "commit", "-q", "-am", "drop tests locally");
|
|
283
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
284
|
-
assert.equal(r.status, 0, r.err);
|
|
285
|
-
assert.equal(JSON.parse(readFileSync(cachePath(dir), "utf8")).derivedAt, head);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
test("a failed proof leaves an existing cache byte-identical — it never writes on a guess", () => {
|
|
289
|
-
const { dir } = repo(withoutTests(MAVEN_FILES));
|
|
290
|
-
mkdirSync(join(dir, ".fleet"));
|
|
291
|
-
writeFileSync(cachePath(dir), "prior bytes");
|
|
292
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
293
|
-
assert.equal(r.status, 1);
|
|
294
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), "prior bytes");
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
test("a cache the reader would refuse is not left behind: it is rolled back to what stood before", () => {
|
|
298
|
-
// `mvn -q test;` runs fine under sh -c, but a trailing `;` would let a
|
|
299
|
-
// runner-appended argument run as its own command, so the reader refuses it.
|
|
300
|
-
const { dir } = repo(MAVEN_FILES);
|
|
301
|
-
mkdirSync(join(dir, ".fleet"));
|
|
302
|
-
writeFileSync(cachePath(dir), "prior bytes");
|
|
303
|
-
const r = prove(dir, ["--install", "true", "--test", "mvn -q test;", "--count-line", "Tests run: 1,", "--test-count", "1"]);
|
|
304
|
-
assert.equal(r.status, 1, r.err);
|
|
305
|
-
assert.match(r.err, /NOT PROVEN — the Recipe cache reader refuses what was proven: .*ends in ';'/);
|
|
306
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), "prior bytes");
|
|
307
|
-
|
|
308
|
-
const { dir: fresh } = repo(MAVEN_FILES);
|
|
309
|
-
const f = prove(fresh, ["--install", "true", "--test", "mvn -q test;", "--count-line", "Tests run: 1,", "--test-count", "1"]);
|
|
310
|
-
assert.equal(f.status, 1);
|
|
311
|
-
assert.equal(existsSync(cachePath(fresh)), false, "no prior cache: the refused one is removed, not left");
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test("from a linked worktree the cache lands beside the common git dir — the main checkout the reader reads", () => {
|
|
315
|
-
const { dir, head } = repo(MAVEN_FILES);
|
|
316
|
-
const wt = join(tempDir("recipe-prove-wt-"), "wt");
|
|
317
|
-
git(dir, "worktree", "add", "-q", "--detach", wt);
|
|
318
|
-
const r = prove(wt, MAVEN_PROOF);
|
|
319
|
-
assert.equal(r.status, 0, r.err);
|
|
320
|
-
assert.equal(JSON.parse(readFileSync(cachePath(dir), "utf8")).derivedAt, head);
|
|
321
|
-
assert.equal(existsSync(cachePath(wt)), false);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test("the throwaway worktree is removed afterwards, proven or not", () => {
|
|
325
|
-
const { dir } = repo(MAVEN_FILES);
|
|
326
|
-
prove(dir, MAVEN_PROOF);
|
|
327
|
-
prove(dir, ["--install", "exit 3", ...MAVEN_PROOF.slice(2)]);
|
|
328
|
-
assert.equal(worktrees(dir), 1);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test("an ambient GIT_DIR naming another repository does not change the answer", () => {
|
|
332
|
-
const { dir, head } = repo(MAVEN_FILES);
|
|
333
|
-
const { dir: other } = repo(withoutTests(MAVEN_FILES));
|
|
334
|
-
const r = prove(dir, MAVEN_PROOF, { env: { GIT_DIR: join(other, ".git"), GIT_WORK_TREE: other } });
|
|
335
|
-
assert.equal(r.status, 0, r.err);
|
|
336
|
-
assert.equal(JSON.parse(readFileSync(cachePath(dir), "utf8")).derivedAt, head);
|
|
337
|
-
assert.equal(existsSync(cachePath(other)), false);
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
test("a proof that cannot be attempted exits 2, distinct from a Recipe that is not proven", () => {
|
|
341
|
-
const usage = spawnSync(process.execPath, [SCRIPT], { encoding: "utf8", env: FIXTURE_ENV });
|
|
342
|
-
assert.equal(usage.status, 2);
|
|
343
|
-
assert.match(usage.stderr, /usage: recipe-prove\.mjs <repo> --install <cmd> --test <cmd>/);
|
|
344
|
-
|
|
345
|
-
const notRepo = prove(tempDir("recipe-prove-norepo-"), MAVEN_PROOF);
|
|
346
|
-
assert.equal(notRepo.status, 2);
|
|
347
|
-
assert.match(notRepo.err, /is not a git repository/);
|
|
348
|
-
|
|
349
|
-
const { dir } = repo(MAVEN_FILES);
|
|
350
|
-
git(dir, "update-ref", "-d", "refs/remotes/origin/main");
|
|
351
|
-
const noMain = prove(dir, MAVEN_PROOF);
|
|
352
|
-
assert.equal(noMain.status, 2);
|
|
353
|
-
assert.match(noMain.err, /origin\/main does not resolve to a commit/);
|
|
354
|
-
|
|
355
|
-
const { dir: half } = repo(MAVEN_FILES);
|
|
356
|
-
const r = prove(half, ["--install", "true", "--test", "mvn -q test", "--count-line", "Tests run: 1,"]);
|
|
357
|
-
assert.equal(r.status, 2);
|
|
358
|
-
assert.match(r.err, /--count-line and --test-count go together/);
|
|
359
|
-
|
|
360
|
-
const nan = prove(half, ["--install", "true", "--test", "mvn -q test", "--count-line", "Tests run: 1,", "--test-count", "1e0"]);
|
|
361
|
-
assert.equal(nan.status, 2);
|
|
362
|
-
assert.match(nan.err, /--test-count must be a whole number, got '1e0'/);
|
|
363
|
-
|
|
364
|
-
// A flag where a value belongs is a missing value, never the command. The
|
|
365
|
-
// fixture must be one whose swallowed value would otherwise be ACCEPTED: with
|
|
366
|
-
// `--install --test "mvn -q test"` the later iteration refuses on its own
|
|
367
|
-
// and the guard under test is never what fires.
|
|
368
|
-
const missing = prove(half, ["--install", "--test", "--test", "mvn -q test"]);
|
|
369
|
-
assert.equal(missing.status, 2);
|
|
370
|
-
assert.match(missing.err, /^recipe-prove: usage:/);
|
|
371
|
-
assert.equal(worktrees(half), 1,
|
|
372
|
-
"a refusal at the argument boundary creates no worktree");
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
// The number of worktrees the repository at `dir` has registered, the main checkout included.
|
|
376
|
-
const worktrees = (dir) => git(dir, "worktree", "list", "--porcelain").split("\n").filter((l) => l.startsWith("worktree ")).length;
|
|
377
|
-
|
|
378
|
-
// Every temp dir the proof made, scanned for the throwaway worktree it names `wt`.
|
|
379
|
-
function assertNoWorktreeLeft(tmp) {
|
|
380
|
-
for (const d of readdirSync(tmp)) {
|
|
381
|
-
assert.deepEqual(readdirSync(join(tmp, d)).filter((n) => n === "wt"), [], `${d} still holds the throwaway worktree`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// The log directories the proof made in its TMPDIR.
|
|
386
|
-
const logDirs = (tmp) => readdirSync(tmp).filter((n) => n.startsWith("recipe-prove-"));
|
|
387
|
-
|
|
388
|
-
test("a proof that held leaves neither a worktree nor a log directory behind in its TMPDIR", () => {
|
|
389
|
-
const { dir } = repo(MAVEN_FILES);
|
|
390
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
391
|
-
assert.equal(r.status, 0, r.err);
|
|
392
|
-
assert.deepEqual(logDirs(r.tmp), []);
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
test("a proof that did not hold keeps its log directory, with the log its refusal names", () => {
|
|
396
|
-
const { dir } = repo(MAVEN_FILES);
|
|
397
|
-
const r = prove(dir, ["--install", "echo fetching deps; exit 3", ...MAVEN_PROOF.slice(2)]);
|
|
398
|
-
assert.equal(r.status, 1, r.err);
|
|
399
|
-
const log = r.err.match(/install output: (\S+)/);
|
|
400
|
-
assert.ok(log, r.err);
|
|
401
|
-
const kept = logDirs(r.tmp);
|
|
402
|
-
assert.equal(kept.length, 1, `log directories in ${r.tmp}: ${kept}`);
|
|
403
|
-
assert.equal(log[1], join(r.tmp, kept[0], "install.log"));
|
|
404
|
-
assert.match(readFileSync(log[1], "utf8"), /fetching deps/);
|
|
405
|
-
assertNoWorktreeLeft(r.tmp);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
// Every refusal the proof stage throws names a log in the directory it keeps,
|
|
409
|
-
// so a kept directory is never one the caller has no path to.
|
|
410
|
-
const KEPT_REFUSALS = [
|
|
411
|
-
{
|
|
412
|
-
name: "an Install step that changed the tree",
|
|
413
|
-
files: MAVEN_FILES,
|
|
414
|
-
args: ["--install", ": > deps.lock", ...MAVEN_PROOF.slice(2)],
|
|
415
|
-
reason: /the Install step changed the tree/,
|
|
416
|
-
log: "install.log",
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
name: "a count line that lacks the claimed count",
|
|
420
|
-
files: MAVEN_FILES,
|
|
421
|
-
args: ["--install", "true", "--test", "mvn -q test", "--count-line", "Tests run: 1,", "--test-count", "7"],
|
|
422
|
-
reason: /does not carry the test count 7/,
|
|
423
|
-
log: "test.log",
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
name: "a mutation that changed no tracked file",
|
|
427
|
-
files: GO_FILES,
|
|
428
|
-
args: ["--install", "true", "--test", "go test ./...", "--mutate", ": > new_test.go", "--mutation", "adds a file"],
|
|
429
|
-
reason: /changed no tracked file/,
|
|
430
|
-
log: "mutate.log",
|
|
431
|
-
},
|
|
432
|
-
];
|
|
433
|
-
|
|
434
|
-
for (const c of KEPT_REFUSALS) {
|
|
435
|
-
test(`${c.name} keeps its log directory, and the refusal names the log in it`, () => {
|
|
436
|
-
const { dir } = repo(c.files);
|
|
437
|
-
const r = prove(dir, c.args);
|
|
438
|
-
assert.equal(r.status, 1, r.err);
|
|
439
|
-
assert.match(r.err, c.reason);
|
|
440
|
-
const kept = logDirs(r.tmp);
|
|
441
|
-
assert.equal(kept.length, 1, `log directories in ${r.tmp}: ${kept}`);
|
|
442
|
-
const log = join(r.tmp, kept[0], c.log);
|
|
443
|
-
assert.ok(r.err.includes(log), `${log} not named in: ${r.err}`);
|
|
444
|
-
assert.ok(existsSync(log), `${log} does not exist`);
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
test("a refusal that names no log leaves no log directory behind", () => {
|
|
449
|
-
// The Recipe cache reader refuses a Test entrypoint ending in `;` after the
|
|
450
|
-
// proof held, so no log in the directory is what the refusal is about.
|
|
451
|
-
const { dir } = repo(MAVEN_FILES);
|
|
452
|
-
const r = prove(dir, ["--install", "true", "--test", "mvn -q test;", "--count-line", "Tests run: 1,", "--test-count", "1"]);
|
|
453
|
-
assert.equal(r.status, 1, r.err);
|
|
454
|
-
assert.match(r.err, /the Recipe cache reader refuses what was proven/);
|
|
455
|
-
assert.deepEqual(logDirs(r.tmp), []);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
test("a throwaway worktree that cannot be made is exit 2 and leaves no log directory behind", () => {
|
|
459
|
-
const realGit = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
460
|
-
const { dir } = repo(MAVEN_FILES);
|
|
461
|
-
const bin = tempDir("recipe-prove-path-");
|
|
462
|
-
writeExecStub(join(bin, "git"), `#!/bin/sh\nif [ "$1" = worktree ] && [ "$2" = add ]; then echo 'fatal: no worktree here' >&2; exit 128; fi\nexec '${realGit}' "$@"\n`);
|
|
463
|
-
const r = prove(dir, MAVEN_PROOF, { env: { PATH: `${bin}:${BIN}:${process.env.PATH}` } });
|
|
464
|
-
assert.equal(r.status, 2, r.err);
|
|
465
|
-
assert.match(r.err, /could not create the throwaway worktree: fatal: no worktree here/);
|
|
466
|
-
assert.deepEqual(logDirs(r.tmp), []);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
test("a git that cannot be started is named as such, not reported as a missing repository", () => {
|
|
470
|
-
const { dir } = repo(MAVEN_FILES);
|
|
471
|
-
const r = prove(dir, MAVEN_PROOF, { env: { PATH: "/nonexistent" } });
|
|
472
|
-
assert.equal(r.status, 2, r.err);
|
|
473
|
-
assert.match(r.err, /^recipe-prove: could not start git: .*ENOENT/);
|
|
474
|
-
assert.doesNotMatch(r.err, /not a git repository/);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
// A PATH holding only `sh` and a `git` that execs the real one, so the Install
|
|
478
|
-
// step can take git away by deleting it: every later git call then
|
|
479
|
-
// fails to start, in the proof and in the worktree cleanup alike.
|
|
480
|
-
test("a git that stops starting during the Install step is no verdict, never NOT PROVEN — and the worktree is still removed", () => {
|
|
481
|
-
const realGit = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
482
|
-
const { dir } = repo(MAVEN_FILES);
|
|
483
|
-
const bin = tempDir("recipe-prove-path-");
|
|
484
|
-
writeExecStub(join(bin, "git"), `#!/bin/sh\nexec '${realGit}' "$@"\n`);
|
|
485
|
-
symlinkSync("/bin/sh", join(bin, "sh"));
|
|
486
|
-
const install = `'${process.execPath}' -e 'require("fs").rmSync(process.argv[1])' '${join(bin, "git")}'`;
|
|
487
|
-
const r = prove(dir, ["--install", install, "--test", "true", "--count-line", "x 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
488
|
-
assert.equal(r.status, 2, r.err);
|
|
489
|
-
assert.match(r.err, /could not start git: .*ENOENT/);
|
|
490
|
-
assert.match(r.err, /skipped git worktree remove/);
|
|
491
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
492
|
-
assert.deepEqual(logDirs(r.tmp), [], "no verdict keeps no logs");
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// A git that started and ran is never "could not start": here its status
|
|
496
|
-
// output outgrows spawnSync's default 1 MiB buffer, which kills it and sets
|
|
497
|
-
// `error` (ENOBUFS) on a process that did run. The tree the Install step left
|
|
498
|
-
// is unreadable, so the proof does not hold — NOT PROVEN, exit 1.
|
|
499
|
-
test("a git whose output outgrows the spawn buffer is a failed command, not a git that could not be started", () => {
|
|
500
|
-
const { dir } = repo(MAVEN_FILES);
|
|
501
|
-
const flood = 'const fs = require("fs"); for (let i = 0; i < 7000; i++) fs.writeFileSync("f".repeat(200) + i, "")';
|
|
502
|
-
const install = `'${process.execPath}' -e '${flood}'`;
|
|
503
|
-
const r = prove(dir, ["--install", install, "--test", "true", "--count-line", "x 1", "--test-count", "1"]);
|
|
504
|
-
assert.equal(r.status, 1, r.err);
|
|
505
|
-
assert.match(r.err, /NOT PROVEN — could not read the tree state in the throwaway worktree/);
|
|
506
|
-
assert.doesNotMatch(r.err, /could not start git/);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
// A `git` first on PATH that runs `act` when its arguments match the sh `case`
|
|
510
|
-
// pattern `when`, and otherwise execs the real one.
|
|
511
|
-
function fakeGit(when, act) {
|
|
512
|
-
const realGit = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
513
|
-
const bin = tempDir("recipe-prove-path-");
|
|
514
|
-
writeExecStub(join(bin, "git"), `#!/bin/sh\ncase "$*" in ${when}) ${act} ;; esac\nexec '${realGit}' "$@"\n`);
|
|
515
|
-
return `${bin}:${BIN}:${process.env.PATH}`;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
const COUNT_PROOF = ["--install", "true", "--test", "echo 'tests 1'", "--count-line", "tests 1", "--test-count", "1"];
|
|
519
|
-
|
|
520
|
-
// A git that ran and was killed has no exit status and, mostly, no stderr: its
|
|
521
|
-
// failure must name the kill, or every caller quoting git's reason quotes an
|
|
522
|
-
// empty one. Each caller keeps its own refusal class — NOT PROVEN (1) inside
|
|
523
|
-
// the proof, no verdict (2) for the probes that come before it.
|
|
524
|
-
const KILLED_GIT = [
|
|
525
|
-
{
|
|
526
|
-
name: "a git killed by SIGKILL reading the tree state",
|
|
527
|
-
when: "status*", act: "kill -9 $$",
|
|
528
|
-
status: 1, reason: /NOT PROVEN — could not read the tree state in the throwaway worktree: git was killed by SIGKILL; install output: /,
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
name: "a git killed by SIGTERM reading the tree state",
|
|
532
|
-
when: "status*", act: "kill -TERM $$",
|
|
533
|
-
status: 1, reason: /NOT PROVEN — could not read the tree state in the throwaway worktree: git was killed by SIGTERM; install output: /,
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
name: "a git killed for outgrowing the spawn buffer reading the tree state",
|
|
537
|
-
when: "status*", act: "yes | head -c 2000000; exit 0",
|
|
538
|
-
status: 1, reason: /NOT PROVEN — could not read the tree state in the throwaway worktree: git was killed by SIGTERM \(ENOBUFS: its output outgrew the spawn buffer\); install output: /,
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
name: "a git that wrote to stderr and was then killed",
|
|
542
|
-
when: "status*", act: "echo boom >&2; kill -9 $$",
|
|
543
|
-
status: 1, reason: /NOT PROVEN — could not read the tree state in the throwaway worktree: boom; git was killed by SIGKILL; install output: /,
|
|
544
|
-
},
|
|
545
|
-
{
|
|
546
|
-
name: "a git killed restoring the tree before the mutation",
|
|
547
|
-
when: "reset*", act: "kill -9 $$", files: GO_FILES, args: GO_PROOF,
|
|
548
|
-
status: 1, reason: /NOT PROVEN — could not restore the tree before the mutation: git was killed by SIGKILL; test output: /,
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
name: "a git killed reading what the mutation changed",
|
|
552
|
-
when: "diff*", act: "kill -9 $$", files: GO_FILES, args: GO_PROOF,
|
|
553
|
-
status: 1, reason: /NOT PROVEN — could not read what the mutation changed: git was killed by SIGKILL; its output: /,
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
name: "a git killed probing for the repository",
|
|
557
|
-
when: '"rev-parse --git-dir"', act: "kill -9 $$",
|
|
558
|
-
status: 2, reason: /^recipe-prove: .* is not a git repository: git was killed by SIGKILL$/m,
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
name: "a git killed resolving the common git dir",
|
|
562
|
-
when: '"rev-parse --path-format=absolute --git-common-dir"', act: "kill -9 $$",
|
|
563
|
-
status: 2, reason: /^recipe-prove: cannot resolve the common git dir of .*: git was killed by SIGKILL$/m,
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
name: "a git killed resolving origin/main",
|
|
567
|
-
when: '"rev-parse --verify"*', act: "kill -9 $$",
|
|
568
|
-
status: 2, reason: /^recipe-prove: origin\/main does not resolve to a commit \(git was killed by SIGKILL\) — fetch it/m,
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
name: "a git killed creating the throwaway worktree",
|
|
572
|
-
when: '"worktree add"*', act: "kill -9 $$",
|
|
573
|
-
status: 2, reason: /^recipe-prove: could not create the throwaway worktree: git was killed by SIGKILL$/m,
|
|
574
|
-
},
|
|
575
|
-
];
|
|
576
|
-
|
|
577
|
-
for (const c of KILLED_GIT) {
|
|
578
|
-
test(`${c.name} names the signal in its refusal`, () => {
|
|
579
|
-
const { dir } = repo(c.files ?? MAVEN_FILES);
|
|
580
|
-
const r = prove(dir, c.args ?? COUNT_PROOF, { env: { PATH: fakeGit(c.when, c.act) } });
|
|
581
|
-
assert.equal(r.status, c.status, r.err);
|
|
582
|
-
assert.match(r.err, c.reason);
|
|
583
|
-
assert.doesNotMatch(r.err, /could not start git/);
|
|
584
|
-
if (c.status === 2) assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// The control: a git that ran and exited non-zero is quoted as it wrote, with
|
|
589
|
-
// no kill named.
|
|
590
|
-
test("a git that exits non-zero is refused with exactly its stderr, naming no signal", () => {
|
|
591
|
-
const { dir } = repo(MAVEN_FILES);
|
|
592
|
-
const r = prove(dir, COUNT_PROOF, { env: { PATH: fakeGit("status*", "echo boom >&2; exit 3") } });
|
|
593
|
-
assert.equal(r.status, 1, r.err);
|
|
594
|
-
assert.match(r.err, /NOT PROVEN — could not read the tree state in the throwaway worktree: boom; install output: /);
|
|
595
|
-
assert.doesNotMatch(r.err, /killed/);
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
// A `status` stub that ignores SIGTERM — and so does every command it starts —
|
|
599
|
-
// writes `?? ` and then `bytes` x's, and exits 0.
|
|
600
|
-
const trapTermStatus = (bytes) => `trap '' TERM; printf '?? '; head -c ${bytes} /dev/zero | tr '\\0' x; exit 0`;
|
|
601
|
-
|
|
602
|
-
// Past spawnSync's default 1 MiB buffer the kill that ENOBUFS sends is
|
|
603
|
-
// ignored: git exits 0 with no signal, but its output was cut off. That is a
|
|
604
|
-
// failed git, refused with a reason naming the overrun — read as ok, the
|
|
605
|
-
// truncated status would pass for a dirty tree.
|
|
606
|
-
test("a git that exits 0 after outgrowing the spawn buffer is refused, naming the overrun", () => {
|
|
607
|
-
const { dir } = repo(MAVEN_FILES);
|
|
608
|
-
const r = prove(dir, COUNT_PROOF, { env: { PATH: fakeGit("status*", trapTermStatus(2_000_000)) } });
|
|
609
|
-
assert.equal(r.status, 1, r.err);
|
|
610
|
-
assert.match(r.err, /NOT PROVEN — could not read the tree state in the throwaway worktree: git exited 0 after an error \(ENOBUFS: its output outgrew the spawn buffer\); install output: /);
|
|
611
|
-
assert.doesNotMatch(r.err, /killed|could not start git/);
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
// The control: the same stub writing 1000 bytes is a git that succeeded, its
|
|
615
|
-
// output read whole — here, one untracked path the Install step left.
|
|
616
|
-
test("the same SIGTERM-trapping git with small output is ok, its output intact", () => {
|
|
617
|
-
const { dir } = repo(MAVEN_FILES);
|
|
618
|
-
const r = prove(dir, COUNT_PROOF, { env: { PATH: fakeGit("status*", trapTermStatus(997)) } });
|
|
619
|
-
assert.equal(r.status, 1, r.err);
|
|
620
|
-
assert.match(r.err, /NOT PROVEN — the Install step changed the tree \(first: \?\? x{997}\); /);
|
|
621
|
-
assert.doesNotMatch(r.err, /ENOBUFS|could not read the tree state/);
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
// A killed `worktree remove` is a failed one: cleanup falls back to the plain
|
|
625
|
-
// delete, and the proof's own NOT PROVEN — which keeps its log directory,
|
|
626
|
-
// the throwaway worktree's parent — stands.
|
|
627
|
-
test("a git killed removing the throwaway worktree still leaves it deleted", () => {
|
|
628
|
-
const { dir } = repo(MAVEN_FILES);
|
|
629
|
-
const r = prove(dir, ["--install", "false", "--test", "true", "--count-line", "x 1", "--test-count", "1"], {
|
|
630
|
-
env: { PATH: fakeGit('"worktree remove"*', "kill -9 $$") },
|
|
631
|
-
});
|
|
632
|
-
assert.equal(r.status, 1, r.err);
|
|
633
|
-
assert.match(r.err, /NOT PROVEN — the Install step 'false' failed/);
|
|
634
|
-
assert.doesNotMatch(r.err, /skipped git/);
|
|
635
|
-
const kept = logDirs(r.tmp);
|
|
636
|
-
assert.equal(kept.length, 1, `log directories in ${r.tmp}: ${kept}`);
|
|
637
|
-
assert.equal(existsSync(join(r.tmp, kept[0], "wt")), false, "the throwaway worktree is gone");
|
|
638
|
-
assert.equal(git(dir, "worktree", "list", "--porcelain").split("\n").filter((l) => l.startsWith("worktree ")).length, 1, "only the main worktree stays registered");
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
// A git that starts for the worktree removal and not for the prune after it:
|
|
642
|
-
// the stub deletes itself once `worktree remove` has run. The proof's own
|
|
643
|
-
// outcome is NOT PROVEN (the Install step fails), and the prune that cannot
|
|
644
|
-
// start must not replace it.
|
|
645
|
-
test("a git that stops starting during cleanup does not replace the proof's own NOT PROVEN", () => {
|
|
646
|
-
const realGit = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
647
|
-
const { dir } = repo(MAVEN_FILES);
|
|
648
|
-
const bin = tempDir("recipe-prove-path-");
|
|
649
|
-
const stub = join(bin, "git");
|
|
650
|
-
writeExecStub(stub, `#!/bin/sh\n'${realGit}' "$@"\nrc=$?\nif [ "$2" = remove ]; then /bin/rm -f '${stub}'; fi\nexit $rc\n`);
|
|
651
|
-
symlinkSync("/bin/sh", join(bin, "sh"));
|
|
652
|
-
const r = prove(dir, ["--install", "false", "--test", "true", "--count-line", "x 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
653
|
-
assert.equal(r.status, 1, r.err);
|
|
654
|
-
assert.match(r.err, /NOT PROVEN/);
|
|
655
|
-
assert.match(r.err, /skipped git worktree prune: could not start git/);
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
// A PATH holding exactly what the proof and the Recipe cache reader run — `sh`,
|
|
659
|
-
// a `git` that execs the real one, `node`, and the reader's `mktemp`, `cat`
|
|
660
|
-
// and `rm` — so the Test entrypoint can take git away by deleting it. With the
|
|
661
|
-
// count proof no proof step runs git after the Test entrypoint, so the first
|
|
662
|
-
// thing to meet the missing git is the reader, during the read-back.
|
|
663
|
-
function readerPath() {
|
|
664
|
-
const realGit = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
|
|
665
|
-
const bin = tempDir("recipe-prove-path-");
|
|
666
|
-
writeExecStub(join(bin, "git"), `#!/bin/sh\nexec '${realGit}' "$@"\n`);
|
|
667
|
-
symlinkSync("/bin/sh", join(bin, "sh"));
|
|
668
|
-
symlinkSync(process.execPath, join(bin, "node"));
|
|
669
|
-
for (const tool of ["mktemp", "cat", "rm"]) {
|
|
670
|
-
symlinkSync(execFileSync("sh", ["-c", `command -v ${tool}`], { encoding: "utf8" }).trim(), join(bin, tool));
|
|
671
|
-
}
|
|
672
|
-
return bin;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
test("a git that stops starting before the cache is read back is no verdict, never NOT PROVEN — and the prior cache is restored", () => {
|
|
676
|
-
// The control: the same PATH with git left in place is a proof that holds.
|
|
677
|
-
const kept = repo(MAVEN_FILES);
|
|
678
|
-
const ok = prove(kept.dir, ["--install", "true", "--test", "echo 'tests 1'", "--count-line", "tests 1", "--test-count", "1"], { env: { PATH: readerPath() } });
|
|
679
|
-
assert.equal(ok.status, 0, ok.err);
|
|
680
|
-
assert.match(ok.out, /^recipe-prove: PROVEN/);
|
|
681
|
-
|
|
682
|
-
const { dir } = repo(MAVEN_FILES);
|
|
683
|
-
mkdirSync(join(dir, ".fleet"));
|
|
684
|
-
writeFileSync(cachePath(dir), "prior bytes");
|
|
685
|
-
const bin = readerPath();
|
|
686
|
-
const r = prove(dir, ["--install", "true", "--test", `rm '${join(bin, "git")}'; echo 'tests 1'`, "--count-line", "tests 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
687
|
-
assert.equal(r.status, 2, r.err);
|
|
688
|
-
assert.match(r.err, /^recipe-prove: could not start git: .*ENOENT — the Recipe cache reader runs git, so its refusal is no verdict/m);
|
|
689
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
690
|
-
assert.doesNotMatch(r.err, /not a git repository/);
|
|
691
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), "prior bytes", "a cache the reader never settled is rolled back");
|
|
692
|
-
});
|
|
693
|
-
|
|
694
|
-
// A git that starts and cannot run fails the reader's own `git rev-parse` just
|
|
695
|
-
// as a git that will not start does, so its refusal is no verdict either. Each
|
|
696
|
-
// stub stands in for one such git: a wrapper whose target is gone exits 126 or
|
|
697
|
-
// 127, and a killed git has no exit status at all. The stubs differ in what
|
|
698
|
-
// they write to stderr, which the message quotes when there is anything to
|
|
699
|
-
// quote. The control — the same PATH with git left in place proves — is the
|
|
700
|
-
// unstartable-git test's. The Test entrypoint rewrites the stub's body, never
|
|
701
|
-
// the stub: that is a hard link to exec-stub.mjs's shared, read-only
|
|
702
|
-
// trampoline.
|
|
703
|
-
const GIT_THAT_CANNOT_RUN = [
|
|
704
|
-
{ name: "exits 126 and writes nothing", body: "exit 126", cause: " and wrote nothing to stderr" },
|
|
705
|
-
{ name: "exits 127 and writes to stderr", body: "echo boom >&2; exit 127", cause: ": boom" },
|
|
706
|
-
{ name: "is killed by a signal", body: "kill -9 $$", cause: ": git was killed by SIGKILL" },
|
|
707
|
-
];
|
|
708
|
-
for (const c of GIT_THAT_CANNOT_RUN) {
|
|
709
|
-
test(`a git that starts but ${c.name} before the cache is read back is no verdict, never NOT PROVEN — and the prior cache is restored`, () => {
|
|
710
|
-
const { dir } = repo(MAVEN_FILES);
|
|
711
|
-
mkdirSync(join(dir, ".fleet"));
|
|
712
|
-
writeFileSync(cachePath(dir), "prior bytes");
|
|
713
|
-
const bin = readerPath();
|
|
714
|
-
const r = prove(dir, ["--install", "true", "--test", `printf '#!/bin/sh\\n${c.body}\\n' > '${join(bin, ".stub-git")}'; echo 'tests 1'`, "--count-line", "tests 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
715
|
-
assert.equal(r.status, 2, r.err);
|
|
716
|
-
assert.ok(r.err.includes(`recipe-prove: git started but does not run: \`git --version\` did not exit 0${c.cause} — the Recipe cache reader runs git, so its refusal is no verdict on what was proven`), r.err);
|
|
717
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
718
|
-
assert.doesNotMatch(r.err, /not a git repository/);
|
|
719
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), "prior bytes", "a cache the reader never settled is rolled back");
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// The reader's own `sh`, taken away the same way: a read-back that never ran
|
|
724
|
-
// read nothing, so it is no verdict either.
|
|
725
|
-
test("an sh that stops starting before the cache is read back is no verdict, never NOT PROVEN — and no cache is left", () => {
|
|
726
|
-
const { dir } = repo(MAVEN_FILES);
|
|
727
|
-
const bin = readerPath();
|
|
728
|
-
const r = prove(dir, ["--install", "true", "--test", `rm '${join(bin, "sh")}'; echo 'tests 1'`, "--count-line", "tests 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
729
|
-
assert.equal(r.status, 2, r.err);
|
|
730
|
-
assert.match(r.err, /^recipe-prove: could not start sh to read the Recipe cache back: .*ENOENT/m);
|
|
731
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
732
|
-
assert.equal(existsSync(cachePath(dir)), false, "a cache the reader never read is rolled back");
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
// The reader's other external tools, taken away the same way after the proof's
|
|
736
|
-
// last step. The control is the same PATH with the tool left in place, which
|
|
737
|
-
// proves — so the no verdict below is about the missing tool, not a PATH too
|
|
738
|
-
// thin for the reader to run at all. `rm` is the reader's cleanup only: it
|
|
739
|
-
// decides nothing about the cache, so the verdict stands without it.
|
|
740
|
-
const READER_TOOLS = [
|
|
741
|
-
{ tool: "node", reason: /derive-testcmd: node is unusable, refusing to read the Recipe cache without the interpreter/ },
|
|
742
|
-
{ tool: "mktemp", reason: /derive-testcmd: cannot create a temporary file to read the Recipe cache/ },
|
|
743
|
-
{ tool: "cat", reason: /derive-testcmd: cat could not be started/ },
|
|
744
|
-
];
|
|
745
|
-
for (const c of READER_TOOLS) {
|
|
746
|
-
test(`a ${c.tool} that stops starting before the cache is read back is no verdict, never NOT PROVEN — and the prior cache is restored`, () => {
|
|
747
|
-
const args = (cmd) => ["--install", "true", "--test", cmd, "--count-line", "tests 1", "--test-count", "1"];
|
|
748
|
-
const kept = repo(MAVEN_FILES);
|
|
749
|
-
const ok = prove(kept.dir, args(`echo 'tests 1'`), { env: { PATH: readerPath() } });
|
|
750
|
-
assert.equal(ok.status, 0, ok.err);
|
|
751
|
-
assert.match(ok.out, /^recipe-prove: PROVEN/);
|
|
752
|
-
|
|
753
|
-
const { dir } = repo(MAVEN_FILES);
|
|
754
|
-
mkdirSync(join(dir, ".fleet"));
|
|
755
|
-
writeFileSync(cachePath(dir), "prior bytes");
|
|
756
|
-
const bin = readerPath();
|
|
757
|
-
const r = prove(dir, args(`rm '${join(bin, c.tool)}'; echo 'tests 1'`), { env: { PATH: bin } });
|
|
758
|
-
assert.equal(r.status, 2, r.err);
|
|
759
|
-
assert.match(r.err, c.reason);
|
|
760
|
-
assert.match(r.err, /the Recipe cache reader could not run a tool it needs, so its refusal is no verdict/);
|
|
761
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
762
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), "prior bytes", "a cache the reader never settled is rolled back");
|
|
763
|
-
assert.deepEqual(logDirs(r.tmp), [], "no verdict keeps no logs");
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
test("an rm that stops starting before the cache is read back leaves the proof standing — the reader's verdict never depended on it", () => {
|
|
768
|
-
const { dir } = repo(MAVEN_FILES);
|
|
769
|
-
const bin = readerPath();
|
|
770
|
-
// `echo` leads the command: the reader refuses a Test entrypoint whose first word does not resolve, and `rm` would not once the PATH link is gone.
|
|
771
|
-
const r = prove(dir, ["--install", "true", "--test", `echo 'tests 1'; rm '${join(bin, "rm")}'`, "--count-line", "tests 1", "--test-count", "1"], { env: { PATH: bin } });
|
|
772
|
-
assert.equal(r.status, 0, r.err);
|
|
773
|
-
assert.match(r.out, /^recipe-prove: PROVEN/);
|
|
774
|
-
assert.equal(existsSync(cachePath(dir)), true);
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
// Whether the process ignores file modes: root writes into a 0555 directory.
|
|
778
|
-
const IGNORES_MODES = process.getuid?.() === 0 && "root ignores file modes";
|
|
779
|
-
|
|
780
|
-
// An Install step whose output the repo ignores and leaves read-only — a Go
|
|
781
|
-
// module cache is the usual one. git's own removal of the worktree fails on it.
|
|
782
|
-
const READ_ONLY_INSTALL = "mkdir -p build/x && : > build/x/f && chmod 555 build/x";
|
|
783
|
-
const IGNORING_BUILD = { ...MAVEN_FILES, ".gitignore": "target/\nbuild/\n" };
|
|
784
|
-
|
|
785
|
-
test("read-only install output cannot turn a proof that held into a crash", { skip: IGNORES_MODES }, () => {
|
|
786
|
-
const { dir, head } = repo(IGNORING_BUILD);
|
|
787
|
-
const r = prove(dir, ["--install", READ_ONLY_INSTALL, ...MAVEN_PROOF.slice(2)]);
|
|
788
|
-
assert.equal(r.status, 0, r.err);
|
|
789
|
-
assert.equal(JSON.parse(readFileSync(cachePath(dir), "utf8")).derivedAt, head);
|
|
790
|
-
assert.deepEqual(logDirs(r.tmp), []);
|
|
791
|
-
assert.equal(worktrees(dir), 1);
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
test("read-only install output does not replace a refusal's reason with a stack trace", { skip: IGNORES_MODES }, () => {
|
|
795
|
-
const { dir } = repo(IGNORING_BUILD);
|
|
796
|
-
const r = prove(dir, ["--install", READ_ONLY_INSTALL, "--test", "echo 'tests 0'", "--count-line", "tests 0", "--test-count", "0"]);
|
|
797
|
-
assert.equal(r.status, 1);
|
|
798
|
-
assert.match(r.err, /NOT PROVEN — vacuous: a test count of 0/);
|
|
799
|
-
assert.doesNotMatch(r.err, /ENOTEMPTY/);
|
|
800
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
test("a cache that cannot be written is exit 2 with its reason, never a stack trace or a NOT PROVEN", { skip: IGNORES_MODES }, () => {
|
|
804
|
-
const { dir } = repo(MAVEN_FILES);
|
|
805
|
-
mkdirSync(join(dir, ".fleet"));
|
|
806
|
-
chmodSync(join(dir, ".fleet"), 0o555);
|
|
807
|
-
try {
|
|
808
|
-
const r = prove(dir, MAVEN_PROOF);
|
|
809
|
-
assert.equal(r.status, 2, r.err);
|
|
810
|
-
assert.match(r.err, /^recipe-prove: EACCES/);
|
|
811
|
-
assert.doesNotMatch(r.err, /\n\s+at /);
|
|
812
|
-
assert.doesNotMatch(r.err, /NOT PROVEN/);
|
|
813
|
-
assert.equal(r.out, "");
|
|
814
|
-
assert.deepEqual(logDirs(r.tmp), [], "no verdict keeps no logs");
|
|
815
|
-
} finally {
|
|
816
|
-
chmodSync(join(dir, ".fleet"), 0o755);
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
test("a command killed by a signal is refused, never counted as a red or a green run", () => {
|
|
821
|
-
// The count proof: the output carries the count line, then the run dies.
|
|
822
|
-
const { dir } = repo(MAVEN_FILES);
|
|
823
|
-
const t = prove(dir, ["--install", "true", "--test", "echo 'tests 3'; kill -9 $$", "--count-line", "tests 3", "--test-count", "3"]);
|
|
824
|
-
assert.equal(t.status, 1, t.err);
|
|
825
|
-
assert.match(t.err, /NOT PROVEN — 'echo 'tests 3'; kill -9 \$\$' was killed by SIGKILL/);
|
|
826
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
827
|
-
|
|
828
|
-
// The mutation proof: the unmutated run is green, the mutated one dies — a
|
|
829
|
-
// crash is not a test failing.
|
|
830
|
-
const { dir: go } = repo(GO_FILES);
|
|
831
|
-
const dies = "if grep -q 'a - b' calc.go; then kill -9 $$; else go test ./...; fi";
|
|
832
|
-
const m = prove(go, ["--install", "true", "--test", dies, ...GO_PROOF.slice(4)]);
|
|
833
|
-
assert.equal(m.status, 1, m.err);
|
|
834
|
-
assert.match(m.err, /NOT PROVEN — '.*kill -9 \$\$.*' was killed by SIGKILL/);
|
|
835
|
-
assert.equal(existsSync(cachePath(go)), false);
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
test("an untracked file an Install step creates is seen even under status.showUntrackedFiles=no", () => {
|
|
839
|
-
const { dir } = repo(MAVEN_FILES);
|
|
840
|
-
git(dir, "config", "status.showUntrackedFiles", "no");
|
|
841
|
-
const r = prove(dir, ["--install", ": > deps.lock", ...MAVEN_PROOF.slice(2)]);
|
|
842
|
-
assert.equal(r.status, 1, r.err);
|
|
843
|
-
assert.match(r.err, /the Install step changed the tree \(first: \?\? deps\.lock\)/);
|
|
844
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
test("the claimed count is a whole number on the count line, leading zeros aside", () => {
|
|
848
|
-
const claim = (line, n) => {
|
|
849
|
-
const { dir } = repo(MAVEN_FILES);
|
|
850
|
-
return { dir, ...prove(dir, ["--install", "true", "--test", `echo '${line}'`, "--count-line", line, "--test-count", n]) };
|
|
851
|
-
};
|
|
852
|
-
// 1 is a substring of 11 and of 21, and is not the number either line carries.
|
|
853
|
-
for (const line of ["Tests run: 11", "21 passed"]) {
|
|
854
|
-
const r = claim(line, "1");
|
|
855
|
-
assert.equal(r.status, 1, `${line}: ${r.err}`);
|
|
856
|
-
assert.match(r.err, /does not carry the test count 1/);
|
|
857
|
-
assert.equal(existsSync(cachePath(r.dir)), false);
|
|
858
|
-
}
|
|
859
|
-
// A runner that zero-pads its count still carries it.
|
|
860
|
-
const padded = claim("tests 01", "1");
|
|
861
|
-
assert.equal(padded.status, 0, padded.err);
|
|
862
|
-
assert.equal(JSON.parse(readFileSync(cachePath(padded.dir), "utf8")).testCount, 1);
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
test("the Install step and the Test entrypoint run against their own worktree whatever GIT_DIR the caller exports", () => {
|
|
866
|
-
// Each command asks git where it is: with an ambient GIT_DIR/GIT_WORK_TREE
|
|
867
|
-
// reaching the `sh -c` child, the answer is the other repository.
|
|
868
|
-
const here = 'test "$(git rev-parse --show-toplevel)" = "$(pwd -P)"';
|
|
869
|
-
const args = ["--install", here, "--test", `${here} && mvn -q test`, "--count-line", "Tests run: 1,", "--test-count", "1"];
|
|
870
|
-
const { dir } = repo(MAVEN_FILES);
|
|
871
|
-
const control = prove(dir, args);
|
|
872
|
-
assert.equal(control.status, 0, `the commands pass without an ambient GIT_DIR: ${control.err}`);
|
|
873
|
-
|
|
874
|
-
const { dir: other } = repo(withoutTests(MAVEN_FILES));
|
|
875
|
-
const { dir: dir2 } = repo(MAVEN_FILES);
|
|
876
|
-
const r = prove(dir2, args, { env: { GIT_DIR: join(other, ".git"), GIT_WORK_TREE: other } });
|
|
877
|
-
assert.equal(r.status, 0, r.err);
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
test("exit 126 and 127 both mean a command did not RUN, in the Install step and in the Test entrypoint", () => {
|
|
881
|
-
const { dir } = repo({ ...MAVEN_FILES, "t.sh": "echo 'Tests run: 1,'\n" });
|
|
882
|
-
// t.sh is committed 0644: `sh -c ./t.sh` exits 126, "found but not executable".
|
|
883
|
-
const i = prove(dir, ["--install", "./t.sh", ...MAVEN_PROOF.slice(2)]);
|
|
884
|
-
assert.equal(i.status, 1);
|
|
885
|
-
assert.match(i.err, /the Install step '\.\/t\.sh' did not run \(exit 126/);
|
|
886
|
-
const t = prove(dir, ["--install", "true", "--test", "./t.sh", "--count-line", "Tests run: 1,", "--test-count", "1"]);
|
|
887
|
-
assert.equal(t.status, 1);
|
|
888
|
-
assert.match(t.err, /the Test entrypoint '\.\/t\.sh' did not run \(exit 126/);
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
test("a mutation command that fails, or that leaves nothing runnable, or that breaks git itself, is refused for that reason", () => {
|
|
892
|
-
const { dir } = repo(GO_FILES);
|
|
893
|
-
const failing = prove(dir, ["--install", "true", "--test", "go test ./...", "--mutate", "exit 3", "--mutation", "x"]);
|
|
894
|
-
assert.equal(failing.status, 1);
|
|
895
|
-
assert.match(failing.err, /the mutation command 'exit 3' failed \(exit 3\)/);
|
|
896
|
-
|
|
897
|
-
// The Test entrypoint is an executable the mutation deletes: the mutated run
|
|
898
|
-
// exits 127, which is not a red suite.
|
|
899
|
-
const { dir: tool } = repo({ tool: "#!/bin/sh\necho 'Tests run: 1,'\n" });
|
|
900
|
-
git(tool, "update-index", "--chmod=+x", "tool");
|
|
901
|
-
git(tool, "commit", "-q", "--amend", "--no-edit");
|
|
902
|
-
git(tool, "update-ref", "refs/remotes/origin/main", "HEAD");
|
|
903
|
-
const gone = prove(tool, ["--install", "true", "--test", "./tool", "--mutate", "rm tool", "--mutation", "delete the runner"]);
|
|
904
|
-
assert.equal(gone.status, 1);
|
|
905
|
-
assert.match(gone.err, /the Test entrypoint did not run on the mutated tree \(exit 127\)/);
|
|
906
|
-
|
|
907
|
-
// A mutation that removes the worktree's link to its repository leaves
|
|
908
|
-
// git unable to say what changed.
|
|
909
|
-
const { dir: blind } = repo(GO_FILES);
|
|
910
|
-
const lost = prove(blind, ["--install", "true", "--test", "go test ./...", "--mutate", "rm .git", "--mutation", "orphan the tree"]);
|
|
911
|
-
assert.equal(lost.status, 1);
|
|
912
|
-
assert.match(lost.err, /could not read what the mutation changed/);
|
|
913
|
-
});
|
|
914
|
-
|
|
915
|
-
test("the mutation is credited only with what it changed, never with what the unmutated Test run rewrote", () => {
|
|
916
|
-
// t.sh is red while state.txt holds anything, and otherwise writes into it:
|
|
917
|
-
// the unmutated run rewrites a tracked file.
|
|
918
|
-
const files = { "state.txt": "", "t.sh": "if [ -s state.txt ]; then exit 1; fi\necho run > state.txt\n" };
|
|
919
|
-
const { dir } = repo(files);
|
|
920
|
-
const noop = prove(dir, ["--install", "true", "--test", "sh t.sh", "--mutate", "true", "--mutation", "no-op"]);
|
|
921
|
-
assert.equal(noop.status, 1, noop.err);
|
|
922
|
-
assert.match(noop.err, /the mutation \(no-op\) changed no tracked file/);
|
|
923
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
924
|
-
|
|
925
|
-
// A genuine mutation of a file the run also rewrites is still a mutation.
|
|
926
|
-
const { dir: real } = repo(files);
|
|
927
|
-
const r = prove(real, ["--install", "true", "--test", "sh t.sh", "--mutate", "echo x > state.txt", "--mutation", "poison the state"]);
|
|
928
|
-
assert.equal(r.status, 0, r.err);
|
|
929
|
-
assert.match(JSON.parse(readFileSync(cachePath(real), "utf8")).mutation, /changed state\.txt$/);
|
|
930
|
-
});
|
|
931
|
-
|
|
932
|
-
// Every Recipe command runs under a time bound, shortened here through
|
|
933
|
-
// RECIPE_PROVE_TIMEOUT so a hang costs seconds. Each case below hangs one of
|
|
934
|
-
// the four commands the proof runs; a bound that missed one would leave that
|
|
935
|
-
// case to the helper's own 60s spawn timeout, which reads as status null.
|
|
936
|
-
const timedOut = (cmd, seconds) =>
|
|
937
|
-
new RegExp(`NOT PROVEN — '${cmd.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}' timed out: still running after ${seconds}s, the bound on each Recipe command`);
|
|
938
|
-
|
|
939
|
-
const HANGS = [
|
|
940
|
-
{
|
|
941
|
-
name: "an Install step",
|
|
942
|
-
files: MAVEN_FILES,
|
|
943
|
-
seconds: 1,
|
|
944
|
-
hung: "echo fetching deps; exec sleep 30",
|
|
945
|
-
args: (hung) => ["--install", hung, ...MAVEN_PROOF.slice(2)],
|
|
946
|
-
log: "install.log",
|
|
947
|
-
output: /fetching deps/,
|
|
948
|
-
},
|
|
949
|
-
{
|
|
950
|
-
name: "a Test entrypoint",
|
|
951
|
-
files: MAVEN_FILES,
|
|
952
|
-
seconds: 1,
|
|
953
|
-
hung: "echo 'Tests run: 1,'; exec sleep 30",
|
|
954
|
-
args: (hung) => ["--install", "true", "--test", hung, "--count-line", "Tests run: 1,", "--test-count", "1"],
|
|
955
|
-
log: "test.log",
|
|
956
|
-
output: /Tests run: 1,/,
|
|
957
|
-
},
|
|
958
|
-
// The two below run a healthy command first, so their bound leaves it room.
|
|
959
|
-
{
|
|
960
|
-
name: "a mutation command",
|
|
961
|
-
files: GO_FILES,
|
|
962
|
-
seconds: 3,
|
|
963
|
-
hung: "echo mutating; exec sleep 30",
|
|
964
|
-
args: (hung) => [...GO_PROOF.slice(0, 4), "--mutate", hung, "--mutation", "never finishes"],
|
|
965
|
-
log: "mutate.log",
|
|
966
|
-
output: /mutating/,
|
|
967
|
-
},
|
|
968
|
-
{
|
|
969
|
-
name: "a mutated Test run",
|
|
970
|
-
files: GO_FILES,
|
|
971
|
-
seconds: 3,
|
|
972
|
-
hung: "if grep -q 'a - b' calc.go; then echo mutated; exec sleep 30; else go test ./...; fi",
|
|
973
|
-
args: (hung) => ["--install", "true", "--test", hung, ...GO_PROOF.slice(4)],
|
|
974
|
-
log: "test-mutated.log",
|
|
975
|
-
output: /mutated/,
|
|
976
|
-
},
|
|
977
|
-
];
|
|
978
|
-
|
|
979
|
-
for (const c of HANGS) {
|
|
980
|
-
test(`${c.name} that never finishes is refused as timed out, NOT PROVEN, naming the bound and its log`, () => {
|
|
981
|
-
const { dir } = repo(c.files);
|
|
982
|
-
// A cache from an earlier proof: a refusal must leave its bytes alone.
|
|
983
|
-
mkdirSync(join(dir, ".fleet"));
|
|
984
|
-
writeFileSync(cachePath(dir), '{"earlier":"cache"}\n');
|
|
985
|
-
const start = Date.now();
|
|
986
|
-
const r = prove(dir, c.args(c.hung), { env: { RECIPE_PROVE_TIMEOUT: String(c.seconds) } });
|
|
987
|
-
const elapsed = Date.now() - start;
|
|
988
|
-
assert.equal(r.status, 1, `status ${r.status} after ${elapsed} ms: ${r.err}`);
|
|
989
|
-
assert.match(r.err, timedOut(c.hung, c.seconds));
|
|
990
|
-
assert.doesNotMatch(r.err, /could not start sh/);
|
|
991
|
-
assert.doesNotMatch(r.err, /was killed by/, "a timeout is named as one, not as a bare signal");
|
|
992
|
-
assert.ok(elapsed < 20_000, `the 30s command was not cut at the ${c.seconds}s bound: ${elapsed} ms`);
|
|
993
|
-
// The log the refusal names is kept, with what the command printed before the kill.
|
|
994
|
-
const log = r.err.match(/output: (\S+)$/m);
|
|
995
|
-
assert.ok(log, r.err);
|
|
996
|
-
assert.ok(log[1].endsWith(`/${c.log}`), `${log[1]} is not the ${c.log}`);
|
|
997
|
-
assert.match(readFileSync(log[1], "utf8"), c.output);
|
|
998
|
-
// The throwaway worktree is removed and unregistered, and the cache untouched.
|
|
999
|
-
assertNoWorktreeLeft(r.tmp);
|
|
1000
|
-
assert.equal(worktrees(dir), 1, git(dir, "worktree", "list"));
|
|
1001
|
-
assert.equal(readFileSync(cachePath(dir), "utf8"), '{"earlier":"cache"}\n');
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// SIGTERM, the default kill signal, is one a command can trap: spawnSync then
|
|
1006
|
-
// waits on it forever. The bound must not depend on the command's consent.
|
|
1007
|
-
test("a command that ignores SIGTERM is still refused at the bound, not waited on", () => {
|
|
1008
|
-
const { dir } = repo(MAVEN_FILES);
|
|
1009
|
-
const hung = "trap '' TERM; while :; do sleep 1; done";
|
|
1010
|
-
const start = Date.now();
|
|
1011
|
-
const r = prove(dir, ["--install", "true", "--test", hung, "--count-line", "x", "--test-count", "1"], { env: { RECIPE_PROVE_TIMEOUT: "1" } });
|
|
1012
|
-
const elapsed = Date.now() - start;
|
|
1013
|
-
assert.equal(r.status, 1, `status ${r.status} after ${elapsed} ms: ${r.err}`);
|
|
1014
|
-
assert.match(r.err, timedOut(hung, 1));
|
|
1015
|
-
assert.ok(elapsed < 20_000, `the bound did not stop a command that traps SIGTERM: ${elapsed} ms`);
|
|
1016
|
-
assert.equal(existsSync(cachePath(dir)), false);
|
|
1017
|
-
assert.equal(worktrees(dir), 1, git(dir, "worktree", "list"));
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
// The bound is per command, never one budget for the whole proof: two
|
|
1021
|
-
// commands each under it, together over it, still prove.
|
|
1022
|
-
test("commands that each finish inside the bound still prove, whatever their total", () => {
|
|
1023
|
-
const { dir } = repo(MAVEN_FILES);
|
|
1024
|
-
const r = prove(dir, ["--install", "sleep 3", "--test", "sleep 3; mvn -q test", ...MAVEN_PROOF.slice(4)], { env: { RECIPE_PROVE_TIMEOUT: "5" } });
|
|
1025
|
-
assert.equal(r.status, 0, r.err);
|
|
1026
|
-
assert.equal(JSON.parse(readFileSync(cachePath(dir), "utf8")).testCount, 1);
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
|
-
// RECIPE_PROVE_TIMEOUT may only shorten the 20-minute default: a value that is
|
|
1030
|
-
// not a whole number of seconds strictly between 0 and the default leaves the
|
|
1031
|
-
// default standing. `3.5` and `-5` are numbers Number() would take; a bound
|
|
1032
|
-
// they set would be configuration lengthening or removing nothing it may.
|
|
1033
|
-
test("RECIPE_PROVE_TIMEOUT can only shorten the default bound", () => {
|
|
1034
|
-
const DEFAULT_MS = 20 * 60 * 1000;
|
|
1035
|
-
assert.equal(commandBudget(undefined), DEFAULT_MS);
|
|
1036
|
-
for (const ignored of ["", "0", "abc", "3.5", "-5", " 5", "5e3", "1200", "1201", "86400"]) {
|
|
1037
|
-
assert.equal(commandBudget(ignored), DEFAULT_MS, `RECIPE_PROVE_TIMEOUT=${JSON.stringify(ignored)} changed the bound`);
|
|
1038
|
-
}
|
|
1039
|
-
assert.equal(commandBudget("1"), 1000);
|
|
1040
|
-
assert.equal(commandBudget("1199"), 1_199_000);
|
|
1041
|
-
assert.equal(commandBudget("007"), 7000);
|
|
1042
|
-
});
|