@feigi/fleet-ctl 0.0.0 → 3.16.3
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/agents/{fleet-implementer.agent.md → fleet-implementer-slow-high.agent.md} +23 -2
- package/agents/fleet-implementer-slow-medium.agent.md +231 -0
- package/agents/fleet-implementer-smol-high.agent.md +231 -0
- package/agents/{fleet-implementer-alt.agent.md → fleet-implementer-task-high.agent.md} +23 -2
- package/agents/fleet-implementer-task-max.agent.md +231 -0
- package/agents/fleet-review-comments.agent.md +4 -2
- package/agents/fleet-review-correctness.agent.md +2 -1
- package/agents/fleet-review-runner.agent.md +14 -10
- package/agents/fleet-review-silent-failure.agent.md +4 -3
- package/agents/fleet-review-simplify.agent.md +2 -1
- package/agents/fleet-review-snapshot.agent.md +2 -1
- package/agents/fleet-review-test-run.agent.md +29 -0
- package/agents/fleet-review-tests.agent.md +10 -5
- package/agents/fleet-review-types.agent.md +4 -2
- package/agents/fleet-review-verifier.agent.md +4 -3
- package/commands/review-and-fix.md +7 -6
- package/commands/run-merge-bot.md +14 -4
- package/package.json +4 -2
- package/scripts/agent-test.test.mjs +36 -32
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +23 -13
- package/scripts/apply-ruleset.test.mjs +4 -3
- package/scripts/arg-header-probes-prose.test.mjs +1 -0
- package/scripts/arg.test.mjs +18 -18
- package/scripts/board-cli.test.mjs +18 -21
- package/scripts/board-identity.test.mjs +9 -9
- package/scripts/board-liveness-banner.test.mjs +6 -6
- package/scripts/board-prev-shape.test.mjs +12 -13
- package/scripts/board-tryparse-null.test.mjs +7 -7
- package/scripts/board.mjs +4 -7
- package/scripts/board.test.mjs +57 -61
- package/scripts/candidates.test.mjs +228 -17
- package/scripts/ci-completes-premise-prose.test.mjs +1 -1
- package/scripts/ci-state-prose.test.mjs +2 -2
- package/scripts/ci-state.mjs +389 -187
- package/scripts/ci-state.test.mjs +458 -165
- package/scripts/citation-sweep-prose.test.mjs +59 -1
- package/scripts/claim-lifecycle.test.mjs +2 -1
- package/scripts/claim-ticket.test.mjs +35 -34
- package/scripts/closing-keyword-prose.test.mjs +1 -1
- package/scripts/cockpit-tick-nonblocking.test.mjs +8 -8
- package/scripts/compute-board.mjs +13 -3
- package/scripts/compute-board.test.mjs +64 -1
- package/scripts/compute-spend.mjs +46 -8
- package/scripts/compute-spend.test.mjs +64 -10
- package/scripts/cross-repo-citation-prose.test.mjs +18 -19
- package/scripts/delete-merged-branch.sh +218 -0
- package/scripts/delete-merged-branch.test.mjs +576 -0
- package/scripts/derive-testcmd.sh +18 -7
- package/scripts/derive-testcmd.test.mjs +9 -8
- package/scripts/diff-stats.mjs +2 -2
- package/scripts/diff-stats.test.mjs +7 -11
- package/scripts/dispatch-block-golden-prose.test.mjs +111 -6
- package/scripts/dispatch-block-pins-prose.test.mjs +5 -5
- package/scripts/dispositions-check.mjs +507 -0
- package/scripts/dispositions-check.test.mjs +843 -0
- package/scripts/dispositions-gate-prose.test.mjs +114 -0
- package/scripts/drop-merged-label.test.mjs +3 -4
- package/scripts/exec-stub.mjs +93 -0
- package/scripts/exec-stub.test.mjs +69 -0
- package/scripts/filing-bar-seat-prose.test.mjs +1 -1
- package/scripts/finisher-test-verdict-prose.test.mjs +102 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +11 -10
- package/scripts/fleet-bootstrap +5 -20
- package/scripts/fleet-bootstrap.test.mjs +75 -0
- package/scripts/fleet-heartbeat.mjs +2 -2
- package/scripts/fleet-provenance +15 -24
- package/scripts/fleet-provenance.test.mjs +86 -12
- package/scripts/fleet-run.test.mjs +5 -5
- package/scripts/fleet-state.mjs +33 -11
- package/scripts/fleet-state.test.mjs +90 -3
- package/scripts/fleet-tick.mjs +346 -70
- package/scripts/fleet-tick.test.mjs +566 -16
- package/scripts/force-with-lease-reason-prose.test.mjs +1 -1
- package/scripts/frontmatter-check.mjs +3 -2
- package/scripts/frontmatter-check.test.mjs +6 -6
- package/scripts/immutable-body-claim-prose.test.mjs +53 -262
- package/scripts/implementer-model-tier.test.mjs +98 -506
- package/scripts/inflight.test.mjs +18 -127
- package/scripts/is-cli.mjs +26 -0
- package/scripts/is-cli.test.mjs +99 -0
- package/scripts/json.test.mjs +3 -3
- package/scripts/ledger-dispatch.test.mjs +368 -7
- package/scripts/ledger-grammar.mjs +85 -1
- package/scripts/ledger-grammar.test.mjs +86 -1
- package/scripts/ledger-read-require-file.test.mjs +7 -7
- package/scripts/ledger-rotate.test.mjs +142 -0
- package/scripts/ledger.mjs +181 -17
- package/scripts/ledger.test.mjs +12 -130
- package/scripts/main-checkout.mjs +312 -0
- package/scripts/main-checkout.test.mjs +332 -0
- package/scripts/member-outcomes-header.test.mjs +3 -3
- package/scripts/member-outcomes.mjs +4 -5
- package/scripts/member-outcomes.test.mjs +92 -18
- package/scripts/member-prompt-prose.test.mjs +17 -13
- package/scripts/member-record.mjs +8 -3
- package/scripts/member-record.test.mjs +5 -5
- package/scripts/member-write-guard.mjs +5 -5
- package/scripts/member-write-guard.test.mjs +6 -3
- package/scripts/no-undo-audit.sh +24 -21
- package/scripts/no-undo-audit.test.mjs +9 -13
- package/scripts/pointer-target-prose.test.mjs +1 -1
- package/scripts/pr-overlap.test.mjs +6 -9
- package/scripts/prompt-renderer.mjs +10 -9
- package/scripts/prose-pin.mjs +10 -11
- package/scripts/prove-merge.test.mjs +3 -3
- package/scripts/quiet-payload-prose.test.mjs +1 -1
- package/scripts/reap.test.mjs +3 -4
- package/scripts/release-label-split-prose.test.mjs +17 -2
- package/scripts/release-ticket.test.mjs +35 -44
- package/scripts/review-core-cwd-isolation.test.mjs +7 -6
- package/scripts/review-core-reads.test.mjs +1 -1
- package/scripts/review-core-scratch-refusal.test.mjs +64 -0
- package/scripts/review-core-shared-test-run.test.mjs +238 -0
- package/scripts/review-core-snapshot-path.test.mjs +59 -12
- package/scripts/review-core-specialist-scratch.test.mjs +12 -10
- package/scripts/review-core-testcmd.test.mjs +76 -45
- package/scripts/review-core-unrun.test.mjs +154 -168
- package/scripts/review-core.mjs +250 -56
- package/scripts/review-eval.mjs +11 -4
- package/scripts/review-host-fixture.mjs +12 -3
- package/scripts/review-in-run-retry.test.mjs +27 -3
- package/scripts/review-runner-spawns.test.mjs +5 -3
- package/scripts/review-runner.test.mjs +14 -3
- package/scripts/review-tier-audit.test.mjs +1 -1
- package/scripts/run-merge-bot-prose.test.mjs +29 -6
- package/scripts/scratch-partition-invariant-prose.test.mjs +1 -1
- package/scripts/section-between-guard-prose.test.mjs +4 -3
- package/scripts/select-dimensions.test.mjs +1 -1
- package/scripts/shell-traps-prose.test.mjs +6 -9
- package/scripts/shortlist.mjs +4 -1
- package/scripts/shortlist.test.mjs +30 -16
- package/scripts/snapshot-repo.test.mjs +177 -4
- package/scripts/stash-prohibition-prose.test.mjs +1 -1
- package/scripts/temp-dir.mjs +47 -0
- package/scripts/tier-check.mjs +95 -28
- package/scripts/tier-check.test.mjs +131 -29
- package/scripts/tier-outcomes-header.test.mjs +11 -54
- package/scripts/tier-outcomes.mjs +34 -12
- package/scripts/tier-outcomes.test.mjs +157 -4
- package/scripts/tier-roles.mjs +118 -29
- package/scripts/tier-roles.test.mjs +226 -61
- package/scripts/tracker-block-copy-prose.test.mjs +3 -3
- package/scripts/verify-sha.test.mjs +4 -5
- package/scripts/watcher-degraded-block.test.mjs +5 -8
- package/scripts/within-run-pair-prose.test.mjs +43 -75
- package/scripts/worktree-audit.test.mjs +2 -1
- package/skills/next-ticket/SKILL.md +2 -2
- package/skills/run-team/SKILL.md +433 -303
- package/skills/run-team/references/ci-and-staleness.md +7 -6
- package/skills/run-team/references/correction-tickets.md +3 -3
- package/skills/run-team/references/isolation.md +1 -1
- package/skills/sizing-a-ticket/SKILL.md +8 -8
- package/scripts/tier-guard-gate-prose.test.mjs +0 -216
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// The disposition record and its gate, as the prose states them to the
|
|
2
|
+
// two seats that act on it: review-and-fix.md step 2 tells the fix-applier to
|
|
3
|
+
// write `<scratch>/dispositions-<pr>.json` and what passes, and run-team's
|
|
4
|
+
// gate paragraph tells the controller when `ledger.mjs dispatch` refuses a
|
|
5
|
+
// finisher and what each refusal asks of it. The fix-applier prompt block that
|
|
6
|
+
// restates the record is a `>` block, which the dispatch-block golden fixture
|
|
7
|
+
// pins whole; these two paragraphs sit outside every `>` block, so nothing
|
|
8
|
+
// else holds them.
|
|
9
|
+
//
|
|
10
|
+
// THE CEILING: presence pins over bounded slices, each a contiguous clause —
|
|
11
|
+
// the rule and its condition in one span, so an inverted verdict (`ok` →
|
|
12
|
+
// `mismatch`), a flipped consequence (`no finisher` → `a finisher`) or a
|
|
13
|
+
// renamed file reds, where a keyword pin would not. They prove the clauses are
|
|
14
|
+
// there, not that nothing near them contradicts them. One pin crosses into
|
|
15
|
+
// code: the deferral reasons the prose lists are read against ALLOWED_DEFER,
|
|
16
|
+
// the list the check enforces, so the two cannot drift apart silently.
|
|
17
|
+
import { test } from "node:test";
|
|
18
|
+
import assert from "node:assert/strict";
|
|
19
|
+
import { readFileSync } from "node:fs";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { between, paragraph, phrase } from "./prose-pin.mjs";
|
|
22
|
+
import { ALLOWED_DEFER } from "./dispositions-check.mjs";
|
|
23
|
+
|
|
24
|
+
const REPO = join(import.meta.dirname, "..");
|
|
25
|
+
const REVIEW_AND_FIX = readFileSync(join(REPO, "commands", "review-and-fix.md"), "utf8");
|
|
26
|
+
const SKILL = readFileSync(join(REPO, "skills", "run-team", "SKILL.md"), "utf8");
|
|
27
|
+
|
|
28
|
+
// Step 2's record paragraph: one line, bounded by step 3's opener.
|
|
29
|
+
const recordStep = () =>
|
|
30
|
+
between(REVIEW_AND_FIX, "**Write every ruling to `<scratch>/dispositions-<pr>.json`", "\n3. **Run `testCmd`", "review-and-fix.md");
|
|
31
|
+
const gate = () => paragraph(SKILL, "That `dispatch` refuses a finisher", "run-team/SKILL.md");
|
|
32
|
+
|
|
33
|
+
test("step 2 names the record's file, beside the review file, and that the check judges it before any finisher", () => {
|
|
34
|
+
assert.match(recordStep(), phrase(
|
|
35
|
+
"**Write every ruling to `<scratch>/dispositions-<pr>.json`, beside the review result file — the disposition record `dispositions-check.mjs` judges against it before any finisher is dispatched.**",
|
|
36
|
+
));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("step 2 reads scope off the diff before the declared scope", () => {
|
|
40
|
+
assert.match(recordStep(), phrase(
|
|
41
|
+
"a finding with no `line`, or on a line `git diff` touches from the PR's merge-base with `origin/main` to the review's `head`, is in scope whatever `scope` says, and only otherwise does the declared one stand.",
|
|
42
|
+
));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("step 2's deferral reasons are exactly the ones the check accepts, and anything else refuses the finisher", () => {
|
|
46
|
+
const s = recordStep();
|
|
47
|
+
const listed = /An in-scope `survived` finding deferred passes only with `reason` `([^`]+)`, `([^`]+)`, `([^`]+)` or `([^`]+)`\./.exec(s);
|
|
48
|
+
assert.ok(listed, "step 2 no longer lists the in-scope deferral reasons in one sentence — update this test");
|
|
49
|
+
assert.deepEqual(listed.slice(1), [...ALLOWED_DEFER]);
|
|
50
|
+
assert.match(s, phrase(
|
|
51
|
+
"Any other reason, none, or a `survived` or `unverified` finding with no entry is a mismatch: the script exits 1 naming each violating entry's bucket, index and rule, and `ledger.mjs dispatch` refuses the PR's finisher.",
|
|
52
|
+
));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("step 2 requires a remedy file absent from the PR's diff for remedy-outside-diff, and refuses none or every one inside it", () => {
|
|
56
|
+
assert.match(recordStep(), phrase(
|
|
57
|
+
"`remedy-outside-diff` — the remedy would edit a file the PR's diff does not touch — also needs `remedyFiles` to name at least one file absent from `git diff` from that merge-base to the review's `head`: none named, or every one in that diff, is a mismatch.",
|
|
58
|
+
));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("the gate refuses a finisher unless the verdict answering the latest review's head is ok", () => {
|
|
62
|
+
const s = gate();
|
|
63
|
+
assert.match(s, phrase(
|
|
64
|
+
"That `dispatch` refuses a finisher — exit 2, nothing written — on a PR whose latest `reviewed=` counts a survived or unverified finding, unless the dispositions verdict answering that review's head is `ok`**",
|
|
65
|
+
));
|
|
66
|
+
assert.match(s, phrase("A PR whose latest review counts `0/<n>/0` is not gated."));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the gate says what each refusal asks of the controller", () => {
|
|
70
|
+
const s = gate();
|
|
71
|
+
assert.match(s, phrase(
|
|
72
|
+
"`dispositions unchecked` — no verdict answers that head: run `dispositions-check.mjs` for the fix-applier that answered the review",
|
|
73
|
+
));
|
|
74
|
+
assert.match(s, phrase(
|
|
75
|
+
"`dispositions mismatch` — no finisher: post the check's output, which names each violating entry, with `gh pr comment <M>`, and flag the PR for a human",
|
|
76
|
+
));
|
|
77
|
+
assert.match(s, phrase(
|
|
78
|
+
"`dispositions escalate` — no finisher, and no retry: a `critical` or `important` finding was deferred `remedy-outside-diff`, which only a human can rule on. Post the check's output, which names each escalated finding, with `gh pr comment <M>`, and flag the PR for a human; dispatch no fix-applier and no finisher for that review's head",
|
|
79
|
+
));
|
|
80
|
+
assert.match(s, phrase(
|
|
81
|
+
"it refuses too while a fix-applier on the PR is still live, verdict or not** — `fix-pr-<M>[-x] still live`: settle it, run the check for it, then dispatch again.",
|
|
82
|
+
));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a reversed refutation reaches the ledger from the disposition record", () => {
|
|
86
|
+
assert.match(paragraph(SKILL, "`refuted` comes back deliberately as well", "run-team/SKILL.md"), phrase(
|
|
87
|
+
"The fix-applier may reverse one; it records each reversal as a `refuted` entry in its disposition record, the evidence in `reason`, and you copy those entries to the ledger's `ruled` line",
|
|
88
|
+
));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Step 6's label conditions: the check over the member's own record is the
|
|
92
|
+
// fourth, so a standalone run — no controller, no ledger — holds its own label.
|
|
93
|
+
const labelStep = () => paragraph(REVIEW_AND_FIX, "6. Diff-check green (run-bound", "review-and-fix.md");
|
|
94
|
+
|
|
95
|
+
test("step 6 makes the dispositions check over the member's own record a label condition", () => {
|
|
96
|
+
assert.match(labelStep(), phrase(
|
|
97
|
+
"**and** `dispositions-check.mjs --member fix-pr-<pr> --scratch <scratch>` run over your own record exiting 0",
|
|
98
|
+
));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("step 6 halts a non-zero dispositions exit before the label and has the member report its violations", () => {
|
|
102
|
+
assert.match(labelStep(), phrase(
|
|
103
|
+
"A non-zero dispositions exit halts you before the label, and you report the violations it printed.",
|
|
104
|
+
));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("step 6 has a standalone member pass --no-ledger: no token is written and the exit status is the verdict", () => {
|
|
108
|
+
assert.match(labelStep(), phrase(
|
|
109
|
+
"standalone you pass `--no-ledger`, so it writes no token and the exit status is the verdict",
|
|
110
|
+
));
|
|
111
|
+
assert.match(labelStep(), phrase(
|
|
112
|
+
"without the flag it exits 2 for a ledger with no row for you",
|
|
113
|
+
));
|
|
114
|
+
});
|
|
@@ -19,6 +19,7 @@ import { spawnSync, execFileSync } from "node:child_process";
|
|
|
19
19
|
import { tmpdir } from "node:os";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { writeExecStub } from "./exec-stub.mjs";
|
|
22
23
|
|
|
23
24
|
const SCRIPT = fileURLToPath(new URL("./drop-merged-label.sh", import.meta.url));
|
|
24
25
|
|
|
@@ -33,7 +34,7 @@ function stub(t) {
|
|
|
33
34
|
mkdirSync(bin);
|
|
34
35
|
const log = join(root, "gh.log");
|
|
35
36
|
writeFileSync(log, "");
|
|
36
|
-
|
|
37
|
+
writeExecStub(
|
|
37
38
|
join(bin, "gh"),
|
|
38
39
|
`#!/bin/sh
|
|
39
40
|
printf '%s\\n' "$*" >> "${log}"
|
|
@@ -74,7 +75,6 @@ case "$1 $2" in
|
|
|
74
75
|
esac
|
|
75
76
|
exit 0
|
|
76
77
|
`,
|
|
77
|
-
{ mode: 0o755 },
|
|
78
78
|
);
|
|
79
79
|
return {
|
|
80
80
|
log,
|
|
@@ -222,10 +222,9 @@ function grepFailShim(t, trigger) {
|
|
|
222
222
|
const bin = mkdtempSync(join(tmpdir(), "drop-merged-label-grep-shim-"));
|
|
223
223
|
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
224
224
|
const realGrep = execFileSync("/bin/sh", ["-c", "command -v grep"], { encoding: "utf8" }).trim();
|
|
225
|
-
|
|
225
|
+
writeExecStub(
|
|
226
226
|
join(bin, "grep"),
|
|
227
227
|
`#!/bin/sh\ncase "$*" in\n *${trigger}*) echo "grep: illegal byte sequence" >&2; exit 2 ;;\nesac\nexec ${realGrep} "$@"\n`,
|
|
228
|
-
{ mode: 0o755 },
|
|
229
228
|
);
|
|
230
229
|
return bin;
|
|
231
230
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Executable stubs for test fixtures, at one new executable inode per process.
|
|
2
|
+
//
|
|
3
|
+
// macOS holds the FIRST direct exec of every newly created executable inode
|
|
4
|
+
// for a system scan: 1.2-1.9s measured on an idle machine, and unbounded under
|
|
5
|
+
// load. A second exec of the same inode costs ~0.01s, and so does exec'ing a
|
|
6
|
+
// HARD LINK to an already-scanned inode (~0.03s), while a `cp` of one is a new
|
|
7
|
+
// inode and pays the scan again (1.35s). A fixture that writes a fresh `gh` or
|
|
8
|
+
// `git` stub per case therefore pays that scan once per case.
|
|
9
|
+
//
|
|
10
|
+
// So every stub this module writes is a hard link to ONE trampoline, written
|
|
11
|
+
// and exec'd once per process, and the stub's own body goes in a plain,
|
|
12
|
+
// non-executable file beside it that the trampoline reads. Reading a file is
|
|
13
|
+
// not an exec, so a body may differ in every case, interpolate per-case paths,
|
|
14
|
+
// or be rewritten mid-case, for free. Per-case state stays per case because
|
|
15
|
+
// the body file lives in the caller's own directory.
|
|
16
|
+
//
|
|
17
|
+
// The trampoline locates the body from `$0`, which for a PATH lookup is the
|
|
18
|
+
// absolute path of the link that was found: `<dir>/<name>` reads
|
|
19
|
+
// `<dir>/.stub-<name>`. That name ends in the stub's own name, so the body file
|
|
20
|
+
// has whatever extension the stub itself had (none, for `gh` or `node`): node
|
|
21
|
+
// picks a loader by extension, and a suffix of our own would make it refuse a
|
|
22
|
+
// `#!/usr/bin/env node` body under an `--import` preload or a `"type":
|
|
23
|
+
// "module"` package, where the extensionless script it replaced still runs.
|
|
24
|
+
//
|
|
25
|
+
// A `#!/bin/sh` body, exactly that line, is SOURCED, so it runs in the same
|
|
26
|
+
// shell with the same `$0` (the stub's own path) and `"$@"` it would have had
|
|
27
|
+
// as a script of its own, and its `exit`/`exec` end the stub as before. It
|
|
28
|
+
// also sees `__stub`, the body file's path, which the `.` that sources it
|
|
29
|
+
// needs. Any other interpreter line (`#!/usr/bin/env node`, `#!/bin/sh -e`,
|
|
30
|
+
// `#!/bin/bash`) is exec'd with the body file as its script, the way the
|
|
31
|
+
// kernel would have run the stub, with one difference: that body's own path —
|
|
32
|
+
// `$0`, `process.argv[1]` — is the body file, not the stub. Its arguments,
|
|
33
|
+
// stdin and exit status are the stub's.
|
|
34
|
+
//
|
|
35
|
+
// Not a fit, and left to a plain write, wherever the executable ITSELF is
|
|
36
|
+
// under test: its mode bits, its freshness, a rewrite through an existing
|
|
37
|
+
// link, or a script that reads the executable's content rather than running
|
|
38
|
+
// it. Nor reached through a symlink from another directory: `$0` is then the
|
|
39
|
+
// symlink, and no body file sits beside it. `chmod` or `writeFileSync` on a
|
|
40
|
+
// stub path would reach the shared inode, which is why the trampoline is
|
|
41
|
+
// 0o555: an accidental write into it fails EACCES instead of silently
|
|
42
|
+
// rewriting every stub in the process — for any user but root, whose writes
|
|
43
|
+
// mode bits do not stop.
|
|
44
|
+
//
|
|
45
|
+
// Deliberately not a `.test.mjs`, so `node --test` never loads it as a suite.
|
|
46
|
+
|
|
47
|
+
import { spawnSync } from "node:child_process";
|
|
48
|
+
import { linkSync, rmSync, writeFileSync } from "node:fs";
|
|
49
|
+
import { basename, dirname, join } from "node:path";
|
|
50
|
+
import { tempDir } from "./temp-dir.mjs";
|
|
51
|
+
|
|
52
|
+
// `__stub`/`__stub_l` rather than short names: a sourced body shares this
|
|
53
|
+
// shell's variables, and one that tests `$s` or `$l` must not find them set.
|
|
54
|
+
const TRAMPOLINE = `#!/bin/sh
|
|
55
|
+
__stub="\${0%/*}/.stub-\${0##*/}"
|
|
56
|
+
IFS= read -r __stub_l < "$__stub"
|
|
57
|
+
case $__stub_l in
|
|
58
|
+
'#!/bin/sh') unset __stub_l; . "$__stub" ;;
|
|
59
|
+
*) exec \${__stub_l#??} "$__stub" "$@" ;;
|
|
60
|
+
esac
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
// Written and exec'd at import, so the scan is paid before any case starts and
|
|
64
|
+
// never against a case's own timeout. Removed at exit rather than in a
|
|
65
|
+
// node:test `after()`: an import has no test to hang a hook on, and one hung on
|
|
66
|
+
// whichever test first wrote a stub would pull the inode out from under the
|
|
67
|
+
// rest of the file. Unbounded on purpose: a first exec killed before the scan
|
|
68
|
+
// finishes leaves it unpaid.
|
|
69
|
+
const trampoline = (() => {
|
|
70
|
+
const dir = tempDir("exec-stub-");
|
|
71
|
+
const path = join(dir, "trampoline");
|
|
72
|
+
writeFileSync(path, TRAMPOLINE, { mode: 0o555 });
|
|
73
|
+
writeFileSync(join(dir, ".stub-trampoline"), "#!/bin/sh\nexit 0\n");
|
|
74
|
+
const warm = spawnSync(path);
|
|
75
|
+
if (warm.status !== 0) throw new Error(`exec-stub: trampoline warm-up failed: ${warm.error ?? warm.stderr}`);
|
|
76
|
+
return path;
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Make `path` an executable that runs `body` as a script of its own would,
|
|
81
|
+
* with the `$0` difference the header describes for a body that is not
|
|
82
|
+
* `#!/bin/sh`.
|
|
83
|
+
*
|
|
84
|
+
* Replaces whatever is at `path`. Calling it again on the same path swaps the
|
|
85
|
+
* body and leaves the shared inode untouched. `body` must start with a `#!`
|
|
86
|
+
* line, since that line is what selects how the trampoline runs it.
|
|
87
|
+
*/
|
|
88
|
+
export function writeExecStub(path, body) {
|
|
89
|
+
if (!body.startsWith("#!")) throw new Error(`exec-stub: body for ${path} has no #! line`);
|
|
90
|
+
writeFileSync(join(dirname(path), `.stub-${basename(path)}`), body);
|
|
91
|
+
rmSync(path, { force: true });
|
|
92
|
+
linkSync(trampoline, path);
|
|
93
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// exec-stub.mjs: every stub is a link to one shared trampoline, and the body
|
|
2
|
+
// lives in a file beside it. What a fixture relies on is that a stub still
|
|
3
|
+
// behaves as its body would as a script of its own, and that one stub's body
|
|
4
|
+
// never leaks into another's through the shared inode.
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { writeExecStub } from "./exec-stub.mjs";
|
|
12
|
+
|
|
13
|
+
function bins(t, n) {
|
|
14
|
+
return Array.from({ length: n }, () => {
|
|
15
|
+
// A space in the path: the trampoline locates the body from `$0`, and an
|
|
16
|
+
// unquoted expansion of it would split here.
|
|
17
|
+
const d = mkdtempSync(join(tmpdir(), "exec stub-"));
|
|
18
|
+
t.after(() => rmSync(d, { recursive: true, force: true }));
|
|
19
|
+
return d;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test("a sh stub found on PATH sees its own path, its argv, its stdin, and exits with its own status", (t) => {
|
|
24
|
+
const [bin] = bins(t, 1);
|
|
25
|
+
writeExecStub(join(bin, "gh"), `#!/bin/sh\nprintf '%s|' "$0" "$#" "$@"\nread -r line; printf '%s' "$line"\nexit 7\n`);
|
|
26
|
+
const r = spawnSync("gh", ["a b", "", "c"], {
|
|
27
|
+
input: "from stdin\n", encoding: "utf8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
|
|
28
|
+
});
|
|
29
|
+
assert.equal(r.status, 7, r.stderr);
|
|
30
|
+
assert.equal(r.stdout, `${join(bin, "gh")}|3|a b||c|from stdin`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("rewriting one stub changes that stub alone, never another written from the same process", (t) => {
|
|
34
|
+
const [a, b] = bins(t, 2);
|
|
35
|
+
writeExecStub(join(a, "tool"), "#!/bin/sh\necho a1\n");
|
|
36
|
+
writeExecStub(join(b, "tool"), "#!/bin/sh\necho b1\n");
|
|
37
|
+
writeExecStub(join(a, "tool"), "#!/bin/sh\necho a2\n");
|
|
38
|
+
assert.equal(spawnSync(join(a, "tool"), { encoding: "utf8" }).stdout, "a2\n");
|
|
39
|
+
assert.equal(spawnSync(join(b, "tool"), { encoding: "utf8" }).stdout, "b1\n");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a body for another interpreter runs under that interpreter, argv intact", (t) => {
|
|
43
|
+
const [bin] = bins(t, 1);
|
|
44
|
+
writeExecStub(join(bin, "gh"), "#!/usr/bin/env node\nprocess.stdout.write(JSON.stringify(process.argv.slice(2)));\nprocess.exit(3);\n");
|
|
45
|
+
const r = spawnSync(join(bin, "gh"), ["x y", "z"], { encoding: "utf8" });
|
|
46
|
+
assert.equal(r.status, 3, r.stderr);
|
|
47
|
+
assert.deepEqual(JSON.parse(r.stdout), ["x y", "z"]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("a node body runs wherever the extensionless script it replaces would: an --import preload, a type:module package", (t) => {
|
|
51
|
+
// Node picks a loader by the script's extension, so the body file must not
|
|
52
|
+
// carry one the stub did not have: both conditions refuse an unknown one.
|
|
53
|
+
const [bin] = bins(t, 1);
|
|
54
|
+
writeFileSync(join(bin, "package.json"), '{"type":"module"}');
|
|
55
|
+
writeFileSync(join(bin, "preload.mjs"), "");
|
|
56
|
+
writeExecStub(join(bin, "gh"), "#!/usr/bin/env node\nprocess.stdout.write(process.argv.slice(2).join());\n");
|
|
57
|
+
// Quoted: NODE_OPTIONS splits on spaces, and `bins` puts one in the path.
|
|
58
|
+
const r = spawnSync(join(bin, "gh"), ["a"], {
|
|
59
|
+
encoding: "utf8", env: { ...process.env, NODE_OPTIONS: `--import="${join(bin, "preload.mjs")}"` },
|
|
60
|
+
});
|
|
61
|
+
assert.equal(r.status, 0, r.stderr);
|
|
62
|
+
assert.equal(r.stdout, "a");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("a body with no #! line is refused, since that line is what picks the interpreter", (t) => {
|
|
66
|
+
const [bin] = bins(t, 1);
|
|
67
|
+
assert.throws(() => writeExecStub(join(bin, "gh"), "exit 0\n"), /no #! line/);
|
|
68
|
+
assert.throws(() => writeExecStub(join(bin, "gh"), "#exit 0\n"), /no #! line/);
|
|
69
|
+
});
|
|
@@ -50,7 +50,7 @@ const step5 = () => flat(between(REVIEW_AND_FIX, "5. File each deferred finding"
|
|
|
50
50
|
// Bounded by the two phase-0 markers that bracket the note, never by the note
|
|
51
51
|
// itself: anchoring on the sentence under test turns its deletion into a
|
|
52
52
|
// slicing error rather than a failed assertion.
|
|
53
|
-
const decidedNote = () => flat(between(RUN_TEAM, "**Torn → surface, never guess**", "**
|
|
53
|
+
const decidedNote = () => flat(between(RUN_TEAM, "**Torn → surface, never guess**", "4. **Collision scan", "run-team phase 0 decided? note"));
|
|
54
54
|
|
|
55
55
|
test("step 5 routes a confirmed defect with an open remedy to ready-for-agent", () => {
|
|
56
56
|
const s = step5();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// A finisher's duty-2 `<testCmd>` run can be killed from outside — an external
|
|
2
|
+
// `timeout`, SIGKILL, an `eval` cell deadline — and a killed `node --test`
|
|
3
|
+
// still prints a summary covering only the tests it reached. Read as a verdict
|
|
4
|
+
// it turns a partial suite into a clean pass; read the same way in the
|
|
5
|
+
// mutation direction it turns cancelled files into a mutant that "reddened".
|
|
6
|
+
// `cancelled` above 0 does not tell the two runs apart: a failing `before` hook
|
|
7
|
+
// or a per-test `timeout` cancels tests inside a run that completed, so the
|
|
8
|
+
// block tells the finisher to judge a run by how it ended.
|
|
9
|
+
// The finisher's agent definition carries no duty text, so the rule reaches
|
|
10
|
+
// it only through the verbatim block the controller hands over — which is
|
|
11
|
+
// what this file pins, one sentence per pin so a clause deleted from inside
|
|
12
|
+
// the block reds its own pin rather than being satisfied by a neighbour. The
|
|
13
|
+
// lead-in paragraph above the block is what tells the controller to hand it
|
|
14
|
+
// over, and is pinned on its own.
|
|
15
|
+
|
|
16
|
+
import { test } from "node:test";
|
|
17
|
+
import assert from "node:assert/strict";
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { paragraph, quoteBlock, sentences, stripQuoteGutter } from "./prose-pin.mjs";
|
|
21
|
+
import { HALT_CAUSES } from "./ledger-grammar.mjs";
|
|
22
|
+
|
|
23
|
+
const RUN_TEAM = readFileSync(join(import.meta.dirname, "..", "skills", "run-team", "SKILL.md"), "utf8");
|
|
24
|
+
|
|
25
|
+
const OPENER = "**A test run is a verdict only if it ran to completion";
|
|
26
|
+
const block = () =>
|
|
27
|
+
stripQuoteGutter(quoteBlock(RUN_TEAM, OPENER, "the finisher's test-run verdict block")).replace(/\s+/g, " ");
|
|
28
|
+
const sentenceWith = (re, what) => {
|
|
29
|
+
const hits = sentences(block()).filter((s) => re.test(s));
|
|
30
|
+
assert.equal(hits.length, 1, `${what}: ${hits.length} sentences match ${re} in the verdict block`);
|
|
31
|
+
return hits[0];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
test("a run is a verdict only on the command's own exit 0 with tests above 0 and cancelled 0", () => {
|
|
35
|
+
const s = sentenceWith(/is a verdict only when/, "verdict condition");
|
|
36
|
+
assert.match(s, /exit status is 0/);
|
|
37
|
+
assert.match(s, /`tests` above 0/);
|
|
38
|
+
assert.match(s, /`cancelled` 0/);
|
|
39
|
+
assert.match(sentenceWith(/summary line without that/, "bare summary"), /is not a verdict, whatever pass count it prints/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a run completed only when it returned on its own, and `cancelled` does not say whether it did", () => {
|
|
43
|
+
const s = sentenceWith(/A run completed when/, "completion rule");
|
|
44
|
+
assert.match(s, /the command itself returned on its own\*\* — an exit code, no signal, and no `timeout`, deadline or kill of yours having fired/);
|
|
45
|
+
const judge = sentenceWith(/Judge that by how the run ended/, "judge by how it ended");
|
|
46
|
+
assert.match(judge, /never by its `cancelled` count/);
|
|
47
|
+
assert.match(judge, /a failing `before` hook or a per-test `timeout` cancels tests inside a run that completed/);
|
|
48
|
+
assert.match(judge, /a SIGTERM'd `node --test` can exit 1 with `cancelled` above 0 in a run that did not/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("124, 137 and 143 are a killed run, FAILED for green, and never a pass or a mutant reddening", () => {
|
|
52
|
+
const s = sentenceWith(/124/, "kill signatures");
|
|
53
|
+
assert.match(s, /Any run that did not complete is a killed run/);
|
|
54
|
+
assert.match(s, /137 \(SIGKILL\), 143 \(SIGTERM\), a signal in the spawn result, an `eval` cell's deadline/);
|
|
55
|
+
assert.match(s, /read for green it is FAILED, the same bucket as `tests 0`, however many tests had passed before the kill/);
|
|
56
|
+
const mutation = sentenceWith(/not a mutant that reddened/, "mutation direction");
|
|
57
|
+
assert.match(mutation, /The same holds for the mutation gate/);
|
|
58
|
+
assert.match(mutation, /files it cancelled are not failures/);
|
|
59
|
+
assert.match(mutation, /only a run that completed can kill a mutant/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("the halt for a killed run names cause `other` with the exit code and summary as evidence", () => {
|
|
63
|
+
assert.ok(HALT_CAUSES.includes("other"), "ledger grammar no longer accepts the `other` halt cause this block names");
|
|
64
|
+
const s = sentenceWith(/Halt with cause/, "halt cause");
|
|
65
|
+
assert.match(s, /cause `other`/);
|
|
66
|
+
assert.match(s, /exit code plus the summary line as evidence/);
|
|
67
|
+
assert.match(s, /label nothing/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("the exit status is read off the test command itself, never a pipeline's", () => {
|
|
71
|
+
const s = sentenceWith(/Never read the status of/, "pipeline rule");
|
|
72
|
+
assert.match(s, /`<testCmd> \| tail`/);
|
|
73
|
+
assert.match(s, /`<testCmd> \| grep`/);
|
|
74
|
+
assert.match(s, /a pipeline's status is its last stage's, so the filter's 0 hides the run's own exit/);
|
|
75
|
+
assert.match(s, /earlier stages' statuses is spelled differently per shell/);
|
|
76
|
+
assert.match(sentenceWith(/Redirect the run's output to a file/, "redirect rule"), /read the command's own `\$\?` straight after it, then read the file/);
|
|
77
|
+
const bridge = sentenceWith(/there is no `\$\?`/, "eval bridge");
|
|
78
|
+
assert.match(bridge, /In an `eval` cell there is no `\$\?`: spawn `<testCmd>` with its output going to that file/);
|
|
79
|
+
assert.match(bridge, /read the exit code and the signal off the spawn result/);
|
|
80
|
+
assert.match(bridge, /`exitCode` and `signalCode` on Bun's `spawnSync`, `returncode` on Python's `subprocess.run`, which is negative for a signal/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("testCmd is never wrapped in an external timeout, and a long suite runs in one eval cell with timeout 0", () => {
|
|
84
|
+
assert.match(sentenceWith(/Do not wrap/, "no external timeout"), /external `timeout`/);
|
|
85
|
+
assert.match(sentenceWith(/Run a long suite/, "eval cell"), /one `eval` cell with `timeout: 0`/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// The other half: what the rule must ACCEPT. A completed run that exits 1 is
|
|
89
|
+
// a plain failure the finisher reports as one whatever `cancelled` says, and
|
|
90
|
+
// `tests 0` keeps its own bucket.
|
|
91
|
+
test("a completed run that exits 1 and a zero-test run keep their own verdicts", () => {
|
|
92
|
+
const s = sentenceWith(/A completed run that exits 1/, "completed red run");
|
|
93
|
+
assert.match(s, /A completed run that exits 1 is a plain failure, not a killed run, whatever its `cancelled` count/);
|
|
94
|
+
assert.match(s, /exit 0 with `tests 0` stays FAILED/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// The block reaches a finisher only because the controller is told to hand it
|
|
98
|
+
// over, and the same sentence says what duty 2 uses `<testCmd>` for.
|
|
99
|
+
test("the lead-in tells the controller to hand the verdict rule over, and says duty 2 runs testCmd for the acceptance mutation", () => {
|
|
100
|
+
const p = paragraph(RUN_TEAM, "Give the finisher the test-run verdict rule verbatim too.", "the verdict block's lead-in").replace(/\s+/g, " ");
|
|
101
|
+
assert.match(p, /^Give the finisher the test-run verdict rule verbatim too\.\*\* Duty 2 runs `<testCmd>` for the acceptance mutation,/);
|
|
102
|
+
});
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// inside the fix-applier's own prompt slice either; the two files that pin
|
|
16
16
|
// this text (`immutable-body-claim-prose.test.mjs`,
|
|
17
17
|
// `cross-repo-citation-prose.test.mjs`) both scope to the IMPLEMENTER'S copy,
|
|
18
|
-
// which lives in `plugin/agents/fleet-implementer
|
|
18
|
+
// which lives in `plugin/agents/fleet-implementer-<cell>.agent.md`, not in this
|
|
19
19
|
// section of SKILL.md. `grep -n '### Reviewers\|You are ALREADY in
|
|
20
20
|
// worktree\|Put the standing CI facts\|Two of the rules above are what
|
|
21
21
|
// caught both\|Fallback: hand-dispatched' skills/run-team/SKILL.md` against
|
|
@@ -82,16 +82,17 @@ const fixApplierPrompt = () =>
|
|
|
82
82
|
between(reviewersSection(), PROMPT_ANCHOR, PROMPT_END, "run-team fix-applier prompt");
|
|
83
83
|
|
|
84
84
|
// The implementer's own copy of the count rule, the OTHER seat #859 requires
|
|
85
|
-
// the qualification to reach.
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
85
|
+
// the qualification to reach. It lives in the claim-discipline block of the
|
|
86
|
+
// implementer agent body, which the harness injects as every implementer's
|
|
87
|
+
// system prompt; bounded to that block so a rewording anywhere else in the
|
|
88
|
+
// body cannot satisfy this slice by accident.
|
|
89
|
+
const AGENT = readFileSync(join(REPO, "agents", "fleet-implementer-slow-high.agent.md"), "utf8");
|
|
89
90
|
const implementerCountRule = () =>
|
|
90
91
|
between(
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
92
|
+
AGENT,
|
|
93
|
+
"**Claim discipline, on every ticket:**",
|
|
94
|
+
"Commit incrementally as you go",
|
|
95
|
+
"the implementer agent body's claim-discipline block",
|
|
95
96
|
);
|
|
96
97
|
|
|
97
98
|
// `**` emphasis and the `>` blockquote gutter are stripped and whitespace
|
|
@@ -160,7 +161,7 @@ test("the implementer's own count rule carries the identical past-tense/live-pro
|
|
|
160
161
|
const rule = flatten(implementerCountRule());
|
|
161
162
|
assert.match(
|
|
162
163
|
rule,
|
|
163
|
-
/
|
|
164
|
+
/Never write a count or tally into present-tense prose; state the property instead.{0,40}?A past-tense record of a measurement you performed stays as written/,
|
|
164
165
|
"the implementer's own count rule lost its past-tense/live-property qualification — #859 requires both seats to carry it, not only the fix-applier's new copy",
|
|
165
166
|
);
|
|
166
167
|
});
|
package/scripts/fleet-bootstrap
CHANGED
|
@@ -51,24 +51,6 @@ function sha256(buf) {
|
|
|
51
51
|
return crypto.createHash("sha256").update(buf).digest("hex");
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// Both sides of the checkout-vs-install comparison, normalized the same
|
|
55
|
-
// way: `ownDir`'s parent may have been reached through a symlinked path
|
|
56
|
-
// (macOS resolves `/tmp` through `/private/tmp`, measured), and nothing
|
|
57
|
-
// forbids a resolved install root from carrying a trailing separator.
|
|
58
|
-
// `fs.realpathSync` where the path exists; a plain
|
|
59
|
-
// `path.normalize` with the trailing separator stripped otherwise (an
|
|
60
|
-
// absent/`null` install path, or one this process cannot stat) — either way
|
|
61
|
-
// the two sides are compared in the same shape rather than raw strings from
|
|
62
|
-
// two different sources.
|
|
63
|
-
function canonical(p) {
|
|
64
|
-
if (typeof p !== "string" || p === "") return p;
|
|
65
|
-
try {
|
|
66
|
-
return fs.realpathSync(p);
|
|
67
|
-
} catch {
|
|
68
|
-
return path.normalize(p).replace(/[\\/]+$/, "");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
54
|
function main() {
|
|
73
55
|
const argv = process.argv.slice(2);
|
|
74
56
|
const fromCheckoutFlag = argv.includes("--from-checkout");
|
|
@@ -86,8 +68,11 @@ function main() {
|
|
|
86
68
|
const home = os.homedir();
|
|
87
69
|
const PLUGIN_KEY = "@feigi/fleet-ctl"; // ADR 0006 name; ADR 0021 — the node_modules package dir.
|
|
88
70
|
const ompInstall = readInstallPath(path.join(home, ".omp", "plugins", "node_modules", PLUGIN_KEY));
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
// Both sides are realpaths — readInstallPath() already resolved the install,
|
|
72
|
+
// and this file's own directory exists, so its parent resolves too — so a
|
|
73
|
+
// path reached through a symlink (macOS /tmp → /private/tmp) compares equal.
|
|
74
|
+
const parent = fs.realpathSync(path.dirname(ownDir));
|
|
75
|
+
const runningFromInstall = parent === ompInstall;
|
|
91
76
|
|
|
92
77
|
const target = path.join(home, ".fleet", "bin", "fleet-run");
|
|
93
78
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// fleet-bootstrap's checkout-vs-install decision (ADR 0003 point 4, ADR
|
|
2
|
+
// 0021): it places `~/.fleet/bin/fleet-run` from its own sibling copy, and
|
|
3
|
+
// only without `--from-checkout` when its own directory's parent IS the
|
|
4
|
+
// realpath of `~/.omp/plugins/node_modules/@feigi/fleet-ctl`. Driven through
|
|
5
|
+
// the real CLI — the script reads `__dirname` and `os.homedir()` and
|
|
6
|
+
// `process.exit()`s — so the installed shape runs a copy placed inside a fake
|
|
7
|
+
// install's scripts/.
|
|
8
|
+
//
|
|
9
|
+
// Every fixture's env is built from scratch (never `...process.env`), so
|
|
10
|
+
// these tests are deterministic regardless of the box they run on.
|
|
11
|
+
import { test } from "node:test";
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
import { copyFileSync, existsSync, mkdtempSync, mkdirSync, readFileSync, writeFileSync, symlinkSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const BOOTSTRAP = fileURLToPath(new URL("./fleet-bootstrap", import.meta.url));
|
|
20
|
+
const CHECKOUT_RESOLVER = fileURLToPath(new URL("./fleet-run", import.meta.url));
|
|
21
|
+
|
|
22
|
+
function runBootstrap(script, home, args = []) {
|
|
23
|
+
return spawnSync(process.execPath, [script, ...args], {
|
|
24
|
+
encoding: "utf8",
|
|
25
|
+
env: { HOME: home, PATH: process.env.PATH },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// A linked install (the dev-loop shape, and a marketplace install's): a
|
|
30
|
+
// payload dir carrying fleet-bootstrap and a resolver in scripts/,
|
|
31
|
+
// symlinked into node_modules/@feigi/fleet-ctl.
|
|
32
|
+
function fakeInstall() {
|
|
33
|
+
const home = mkdtempSync(join(tmpdir(), "fleet-bootstrap-home-"));
|
|
34
|
+
const payload = join(home, "checkout", "plugin");
|
|
35
|
+
mkdirSync(join(payload, "scripts"), { recursive: true });
|
|
36
|
+
copyFileSync(BOOTSTRAP, join(payload, "scripts", "fleet-bootstrap"));
|
|
37
|
+
writeFileSync(join(payload, "scripts", "fleet-run"), "installed resolver\n");
|
|
38
|
+
const nm = join(home, ".omp", "plugins", "node_modules");
|
|
39
|
+
mkdirSync(join(nm, "@feigi"), { recursive: true });
|
|
40
|
+
symlinkSync(payload, join(nm, "@feigi", "fleet-ctl"));
|
|
41
|
+
return { home, installedBootstrap: join(payload, "scripts", "fleet-bootstrap") };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const placed = (home) => join(home, ".fleet", "bin", "fleet-run");
|
|
45
|
+
|
|
46
|
+
test("run from the install root it places the installed resolver with no flag and no exception notice", () => {
|
|
47
|
+
const { home, installedBootstrap } = fakeInstall();
|
|
48
|
+
const r = runBootstrap(installedBootstrap, home);
|
|
49
|
+
assert.equal(r.status, 0, `expected the install run to proceed, got status ${r.status}: ${r.stderr}`);
|
|
50
|
+
assert.doesNotMatch(r.stderr, /BOOTSTRAP EXCEPTION/);
|
|
51
|
+
assert.equal(readFileSync(placed(home), "utf8"), "installed resolver\n");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("run from a checkout that is not the install root without --from-checkout: exit 2, nothing placed", () => {
|
|
55
|
+
const { home } = fakeInstall();
|
|
56
|
+
const r = runBootstrap(BOOTSTRAP, home);
|
|
57
|
+
assert.equal(r.status, 2, `expected a refusal, got status ${r.status}: ${r.stdout}${r.stderr}`);
|
|
58
|
+
assert.match(r.stderr, /refusing to place .* which is not omp's resolved install root/);
|
|
59
|
+
assert.equal(existsSync(placed(home)), false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("run from a checkout with no install at all: the refusal says omp is not installed", () => {
|
|
63
|
+
const home = mkdtempSync(join(tmpdir(), "fleet-bootstrap-home-"));
|
|
64
|
+
const r = runBootstrap(BOOTSTRAP, home);
|
|
65
|
+
assert.equal(r.status, 2, `expected a refusal, got status ${r.status}: ${r.stdout}${r.stderr}`);
|
|
66
|
+
assert.match(r.stderr, /omp: not installed/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("run from a checkout with --from-checkout: places the checkout's resolver and announces the exception", () => {
|
|
70
|
+
const { home } = fakeInstall();
|
|
71
|
+
const r = runBootstrap(BOOTSTRAP, home, ["--from-checkout"]);
|
|
72
|
+
assert.equal(r.status, 0, `expected the licensed exception to proceed, got status ${r.status}: ${r.stderr}`);
|
|
73
|
+
assert.match(r.stderr, /BOOTSTRAP EXCEPTION/);
|
|
74
|
+
assert.deepEqual(readFileSync(placed(home)), readFileSync(CHECKOUT_RESOLVER));
|
|
75
|
+
});
|
|
@@ -77,7 +77,7 @@ export function heldThisCall({ elapsed, target, hold }) {
|
|
|
77
77
|
// I/O. Everything below runs only as a CLI — importing this file must never
|
|
78
78
|
// parse argv or touch the filesystem, or the pure half stops being unit-testable.
|
|
79
79
|
|
|
80
|
-
import {
|
|
80
|
+
import { isCLI } from "./is-cli.mjs";
|
|
81
81
|
import { parseArgs } from "node:util";
|
|
82
82
|
import { makeDie, isDigits } from "./arg.mjs";
|
|
83
83
|
import { statePath, readState, writeState, DEFAULT_CEILING_S } from "./fleet-state.mjs";
|
|
@@ -269,4 +269,4 @@ function main() {
|
|
|
269
269
|
: `heartbeat: held ${held}s, ${target - elapsed}s of ${target}s remain (quiet=${state.quiet}) → re-issue this command now, do not end your turn`);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
if (import.meta.url
|
|
272
|
+
if (isCLI(import.meta.url)) main();
|