salvage: uncommitted work from dewey-r156-wt (disk cleanup #824, 2026-11-06)
This commit is contained in:
1 parent
de74dd4735
commit
0ee3365717
14 files changed
+757
-90
No files matched your search
@@ -384,33 +384,212 @@ test("each launch makes sure the workspace has a clone of the project: cloned, f
|
||||
});
|
||||
|
||||
// Row 137 (#1631): the chief holds neither git.push.working nor
|
||||
// review.verdict, so only landHeld can give it land_work and the git socket.
|
||||
// landHeld is the broker's (packages/bus/tests/land.test.mjs); here the host
|
||||
// answers it, since a real answer needs a merge decision the human resolved
|
||||
// through the CLI.
|
||||
test("a role the broker says holds a merge decision gets land_work, its prompt line and the git socket; without it, none", { skip, timeout: 30000 }, async (t) => {
|
||||
// review.verdict, so only a held merge decision can give it land_work and the
|
||||
// git socket. Row 156 (#1651): for a non-thread launch that read is
|
||||
// landHolders, which also gives session.json its landing. Both are the
|
||||
// broker's (packages/bus/tests/land.test.mjs); here the host answers, since a
|
||||
// real answer needs a merge decision the human resolved through the CLI.
|
||||
test("a role the broker says holds a merge decision gets land_work, its prompt line, its landing and the git socket; without it, none", { skip, timeout: 30000 }, async (t) => {
|
||||
const asked = [];
|
||||
const answering = (held) => ({ wrap: (host) => Object.create(host, { op: { value: async (m) => (m.op === "landHeld" ? (asked.push(m.record), held) : host.op(m)) } }) });
|
||||
const held = [{ instance: "chief", decision: "d1", task_ref: "vikunja:1/2" }, { instance: "coder", decision: "d2", task_ref: "vikunja:1/3" }];
|
||||
const answering = (holders) => ({ wrap: (host) => Object.create(host, { op: { value: async (m) => (m.op === "landHolders" ? (asked.push(m), holders) : host.op(m)) } }) });
|
||||
const landing = "- Landing: once your merge decision is approved, land_work it with the task.";
|
||||
const read = (f, run, file) => readFileSync(join(f.dataRoot, "launches", "acme", run, file), "utf8");
|
||||
|
||||
const one = await setup(t, undefined, undefined, answering(true));
|
||||
const one = await setup(t, undefined, undefined, answering(held));
|
||||
const pm1 = await one.launcher.launchPm();
|
||||
assert.deepEqual(asked, [{ business: "acme", role: "chief", thread: null }]);
|
||||
assert.deepEqual(asked, [{ op: "landHolders", business: "acme" }]);
|
||||
const tool = JSON.parse(read(one.f, pm1.run, "bundle/tools.json")).find((x) => x.name === "land_work");
|
||||
assert.equal(tool.verb, "working.land");
|
||||
assert.equal(tool.action, "git.merge.protected");
|
||||
assert.deepEqual(tool.parameters.required, ["task_ref", "decision"]);
|
||||
assert.ok(read(one.f, pm1.run, "bundle/prompt.md").includes(landing));
|
||||
assert.equal(JSON.parse(read(one.f, pm1.run, "session.json")).gitSocket, gitSocketPath(one.f.dataRoot));
|
||||
// Only the chief's own entry, from the same read as land_work.
|
||||
assert.deepEqual(JSON.parse(read(one.f, pm1.run, "session.json")).landing, [{ decision: "d1", task_ref: "vikunja:1/2" }]);
|
||||
|
||||
// A separate fixture, so its business and data root are new.
|
||||
const two = await setup(t, undefined, undefined, answering(false));
|
||||
// A separate fixture, so its business and data root are new. Another
|
||||
// instance's decision gives the chief nothing.
|
||||
const two = await setup(t, undefined, undefined, answering(held.slice(1)));
|
||||
const pm2 = await two.launcher.launchPm();
|
||||
assert.equal(asked.length, 2);
|
||||
assert.equal(JSON.parse(read(two.f, pm2.run, "bundle/tools.json")).some((x) => x.name === "land_work"), false);
|
||||
assert.equal(read(two.f, pm2.run, "bundle/prompt.md").includes(landing), false);
|
||||
assert.equal(JSON.parse(read(two.f, pm2.run, "session.json")).gitSocket, null);
|
||||
assert.equal("landing" in JSON.parse(read(two.f, pm2.run, "session.json")), false);
|
||||
});
|
||||
|
||||
// Row 156 (#1651): the landing pass. The host answers landHolders and
|
||||
// landRelease from `state`, as above; the broker's side of both is in
|
||||
// packages/bus/tests/land.test.mjs. With no state.release, landRelease goes
|
||||
// to the real host. The tick timer is an hour, so only the test's own tick()
|
||||
// calls run a pass. The coder is listed in launch.instances and the chief
|
||||
// isn't.
|
||||
const LANDING = "- Landing: once your merge decision is approved, land_work it with the task.";
|
||||
function landingHost(state) {
|
||||
const op = (host) => async (m) => {
|
||||
if (m.op === "landHolders") return state.holders;
|
||||
if (m.op === "landRelease") return (state.released.push(m.record), state.release ?? host.op(m));
|
||||
return host.op(m);
|
||||
};
|
||||
return { threadTickMs: 3600000, wrap: (host) => Object.create(host, { op: { value: op(host) } }) };
|
||||
}
|
||||
const runFile = (f, run, file) => readFileSync(join(f.dataRoot, "launches", "acme", run, file), "utf8");
|
||||
const runnerText = (f, run) => (existsSync(join(f.dataRoot, "launches", "acme", run, "runner.log")) ? runFile(f, run, "runner.log") : "");
|
||||
const landingOf = (f, run) => JSON.parse(runFile(f, run, "session.json")).landing;
|
||||
const hasLand = (f, run) => JSON.parse(runFile(f, run, "bundle/tools.json")).some((x) => x.name === "land_work");
|
||||
const coderRuns = (f) => log(f).filter((e) => e.event === "launch" && e.instance === "coder").map((e) => e.run);
|
||||
const D1 = { instance: "coder", decision: "d1", task_ref: "vikunja:1/2" };
|
||||
|
||||
test("REQ-LAUNCH-1 the tick starts a listed merge decision holder once, with land_work, the Landing line and its landing turn; an unlisted holder starts nothing", { skip, timeout: 30000 }, async (t) => {
|
||||
const state = { holders: [{ instance: "chief", decision: "d0", task_ref: "vikunja:1/1" }, D1], release: { released: false, unread: 0 }, released: [] };
|
||||
const { f, launcher } = await setup(t, undefined, undefined, landingHost(state));
|
||||
await launcher.tick();
|
||||
assert.deepEqual(log(f).filter((e) => e.event === "launch").map((e) => [e.instance, e.launchedBy]), [["coder", "jason"]]);
|
||||
const [run] = coderRuns(f);
|
||||
assert.equal(hasLand(f, run), true);
|
||||
assert.ok(runFile(f, run, "bundle/prompt.md").includes(LANDING));
|
||||
assert.deepEqual(landingOf(f, run), [{ decision: "d1", task_ref: "vikunja:1/2" }]);
|
||||
await until(() => runnerText(f, run).includes("runner: landing turn 1 for decision d1 (vikunja:1/2): ok"));
|
||||
|
||||
// Running with the decision in its landing: no second start, no release.
|
||||
await launcher.tick();
|
||||
await launcher.tick();
|
||||
assert.deepEqual(coderRuns(f), [run]);
|
||||
assert.deepEqual(state.released, []);
|
||||
assert.equal(log(f).some((e) => e.event === "refused"), false);
|
||||
});
|
||||
|
||||
test("a holder running since before the resolution is stopped once the broker releases it, land-relaunch, and the next tick starts it: landing turn first, then the message that waited", { skip, timeout: 45000 }, async (t) => {
|
||||
const state = { holders: [], released: [] };
|
||||
const { f, host, launcher, client, logs } = await setup(t, undefined, undefined, landingHost(state));
|
||||
const chief = await host.bindLaunch({ business: "acme", role: "chief", run: "chief-test", harness: "pi", pid: process.pid, startTime: startTimeOf(process.pid) });
|
||||
await new Client({ path: host.path, cap: chief.cap }).call("role.claim");
|
||||
const launched = await launcher.fromSession(chief.cap, "coder");
|
||||
assert.equal(launched.ok, true, JSON.stringify(launched));
|
||||
const old = launched.result.run;
|
||||
assert.equal(landingOf(f, old), undefined);
|
||||
assert.equal(hasLand(f, old), false);
|
||||
await until(() => runnerText(f, old).includes("claimed by run"));
|
||||
|
||||
// Resolved now. The real broker holds no such decision and refuses through
|
||||
// the broker process; the launcher logs it once, and nothing stops.
|
||||
state.holders = [D1];
|
||||
await launcher.tick();
|
||||
await launcher.tick();
|
||||
assert.deepEqual(state.released, [{ business: "acme", run: old, decision: "d1" }, { business: "acme", run: old, decision: "d1" }]);
|
||||
assert.deepEqual(logs.filter((l) => l.includes("landRelease refused")), [`run ${old}: landRelease refused: decision-not-held`]);
|
||||
// The broker keeps the claim (a message delivered and unread): nothing stops.
|
||||
state.release = { released: false, unread: 1 };
|
||||
await launcher.tick();
|
||||
assert.equal(state.released.length, 3);
|
||||
assert.equal(log(f).some((e) => e.event === "land-relaunch"), false);
|
||||
assert.deepEqual(coderRuns(f), [old]);
|
||||
assert.equal(readSessions(f.dataRoot).find((s) => s.run === old)?.live, true);
|
||||
|
||||
// Released: one land-relaunch record, a SIGTERM, and no start while it ends.
|
||||
state.release = { released: true };
|
||||
await launcher.tick();
|
||||
assert.equal(state.released.length, 4);
|
||||
assert.deepEqual(log(f).filter((e) => e.event === "land-relaunch").map(({ event, instance, run, decision }) => ({ event, instance, run, decision })), [{ event: "land-relaunch", instance: "coder", run: old, decision: "d1" }]);
|
||||
const end = await until(() => log(f).find((e) => e.event === "end" && e.run === old));
|
||||
assert.deepEqual([end.reason, end.exitCode], ["stopped", 0]);
|
||||
assert.deepEqual(coderRuns(f), [old]);
|
||||
|
||||
// A message for the coder waits with no run. The next tick starts the
|
||||
// holder with land_work and its landing; the landing turn is turn 1 and the
|
||||
// message is answered by the new run after it.
|
||||
const sent = await client.call("message.send", { to: "coder", class: "REQUEST", body: "hello" });
|
||||
await launcher.tick();
|
||||
const [, next] = coderRuns(f);
|
||||
assert.ok(next);
|
||||
assert.equal(hasLand(f, next), true);
|
||||
assert.deepEqual(landingOf(f, next), [{ decision: "d1", task_ref: "vikunja:1/2" }]);
|
||||
const reply = await until(async () => (await client.call("message.receive")).find((m) => m.in_reply_to === sent.id));
|
||||
assert.equal(reply.from_run, next);
|
||||
assert.match(runnerText(f, next), /runner: landing turn 1 for decision d1 \(vikunja:1\/2\): ok/);
|
||||
|
||||
// Started after the resolution: left alone.
|
||||
await launcher.tick();
|
||||
assert.equal(state.released.length, 4);
|
||||
assert.deepEqual(coderRuns(f), [old, next]);
|
||||
});
|
||||
|
||||
test("a landing run that ended isn't started again for its decision, a spent decision starts nothing, and a new decision starts the holder", { skip, timeout: 45000 }, async (t) => {
|
||||
const state = { holders: [D1], release: { released: false, unread: 0 }, released: [] };
|
||||
const { f, launcher } = await setup(t, undefined, undefined, landingHost(state));
|
||||
await launcher.tick();
|
||||
const [first] = coderRuns(f);
|
||||
await until(() => runnerText(f, first).includes("landing turn 1 for decision d1"));
|
||||
const s = readSessions(f.dataRoot).find((x) => x.run === first);
|
||||
process.kill(s.runnerPid, "SIGTERM");
|
||||
await until(() => log(f).find((e) => e.event === "end" && e.run === first));
|
||||
|
||||
// Still listed, as if the run ended without landing: no second start.
|
||||
await launcher.tick();
|
||||
assert.deepEqual(coderRuns(f), [first]);
|
||||
// Spent: not listed.
|
||||
state.holders = [];
|
||||
await launcher.tick();
|
||||
assert.deepEqual(coderRuns(f), [first]);
|
||||
// A new decision for the same instance starts it once more.
|
||||
state.holders = [{ ...D1, decision: "d2" }];
|
||||
await launcher.tick();
|
||||
const runs = coderRuns(f);
|
||||
assert.equal(runs.length, 2);
|
||||
assert.deepEqual(landingOf(f, runs[1]), [{ decision: "d2", task_ref: "vikunja:1/2" }]);
|
||||
assert.deepEqual(state.released, []);
|
||||
});
|
||||
|
||||
test("after a restart, the new host's first tick starts a holder whose decision is still held", { skip, timeout: 45000 }, async (t) => {
|
||||
const given = prepare(t);
|
||||
const state = { holders: [D1], release: { released: false, unread: 0 }, released: [] };
|
||||
const one = await setup(t, undefined, given, landingHost(state));
|
||||
await one.launcher.tick();
|
||||
const [first] = coderRuns(given.f);
|
||||
await until(() => runnerText(given.f, first).includes("landing turn 1 for decision d1"));
|
||||
await one.client.call("role.release"); // the test's own cto claim, so the next host's can claim again
|
||||
assert.equal(await one.close(), 0);
|
||||
assert.deepEqual(readSessions(given.f.dataRoot), []);
|
||||
|
||||
const two = await setup(t, undefined, given, landingHost(state));
|
||||
assert.deepEqual(coderRuns(given.f), [first]);
|
||||
await two.launcher.tick();
|
||||
const runs = coderRuns(given.f);
|
||||
assert.equal(runs.length, 2);
|
||||
assert.equal(hasLand(given.f, runs[1]), true);
|
||||
assert.deepEqual(landingOf(given.f, runs[1]), [{ decision: "d1", task_ref: "vikunja:1/2" }]);
|
||||
await until(() => runnerText(given.f, runs[1]).includes("landing turn 1 for decision d1 (vikunja:1/2): ok"));
|
||||
await two.client.call("role.release");
|
||||
assert.equal(await two.close(), 0);
|
||||
});
|
||||
|
||||
// The reviewer and the coder share sonnet's one place, so a running coder
|
||||
// makes the reviewer's landing start refuse capacity-full.
|
||||
test("a refused landing start is logged once per code with its decision, isn't a start, and the next tick with room starts the holder", { skip, timeout: 45000 }, async (t) => {
|
||||
const state = { holders: [], release: { released: false, unread: 0 }, released: [] };
|
||||
const { f, host, launcher, logs } = await setup(t, undefined, undefined, landingHost(state));
|
||||
const chief = await host.bindLaunch({ business: "acme", role: "chief", run: "chief-test", harness: "pi", pid: process.pid, startTime: startTimeOf(process.pid) });
|
||||
await new Client({ path: host.path, cap: chief.cap }).call("role.claim");
|
||||
const coder = await launcher.fromSession(chief.cap, "coder");
|
||||
assert.equal(coder.ok, true, JSON.stringify(coder));
|
||||
await until(() => runnerText(f, coder.result.run).includes("claimed by run"));
|
||||
state.holders = [{ instance: "reviewer", decision: "d3", task_ref: "vikunja:1/4" }];
|
||||
await launcher.tick();
|
||||
await launcher.tick();
|
||||
const refused = log(f).filter((e) => e.event === "refused");
|
||||
assert.deepEqual(refused.map(({ by, instance, decision, code }) => ({ by, instance, decision, code })), [{ by: "jason", instance: "reviewer", decision: "d3", code: "capacity-full" }]);
|
||||
assert.deepEqual(logs.filter((l) => l.includes("landing start refused")), ["decision d3 (reviewer): landing start refused: capacity-full"]);
|
||||
assert.equal(log(f).some((e) => e.event === "launch" && e.instance === "reviewer"), false);
|
||||
|
||||
const s = readSessions(f.dataRoot).find((x) => x.run === coder.result.run);
|
||||
process.kill(s.runnerPid, "SIGTERM");
|
||||
await until(() => !readSessions(f.dataRoot).some((x) => x.run === coder.result.run) && log(f).some((e) => e.event === "end" && e.run === coder.result.run));
|
||||
await launcher.tick();
|
||||
const [run] = log(f).filter((e) => e.event === "launch" && e.instance === "reviewer").map((e) => e.run);
|
||||
assert.ok(run);
|
||||
assert.deepEqual(landingOf(f, run), [{ decision: "d3", task_ref: "vikunja:1/4" }]);
|
||||
await until(() => runnerText(f, run).includes("runner: landing turn 1 for decision d3 (vikunja:1/4): ok"));
|
||||
});
|
||||
|
||||
test("a project clone that can't be made refuses checkout-failed, from --chief and from a session, with no run and no clone left", { skip, timeout: 30000 }, async (t) => {
|
||||
|
||||
@@ -86,6 +86,8 @@ async function start(t, { f, adapter }, { tickMs = 100, ops: replace } = {}) {
|
||||
threadIdle: (m) => runtime.threadIdle(m.record),
|
||||
mayLaunch: (m) => runtime.mayLaunch(m),
|
||||
landHeld: (m) => runtime.landHeld(m.record),
|
||||
landHolders: (m) => runtime.landHolders(m.business),
|
||||
landRelease: (m) => runtime.landRelease(m.record),
|
||||
...replace?.(runtime),
|
||||
};
|
||||
const refusing = (what, fn) => async (m) => {
|
||||
|
||||
Reference in new issue
Block a user