salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r137/wt (disk cleanup #824)

This commit is contained in:
mos committed 2026-11-06 10:03:20 -06:00
1 parent 7a2987cf51
commit ace2cb9e20
27 files changed
+1229 -255

No files matched your search

+200 -5
View File
@@ -20,9 +20,10 @@ import { configDir, loadBusiness } from "../../business/src/index.mjs";
import { gitEnv } from "../../seat/src/checkout.mjs";
import { gitSocketPath } from "../../seat/src/session.mjs";
import { workingRepo } from "../../seat/src/working.mjs";
import { fetchReview, pushWorking } from "../../harness/src/git-tools.mjs";
import { fetchReview, landWork, pushWorking } from "../../harness/src/git-tools.mjs";
import { gateEnv, isMosaicStack, runGate } from "../../seat/src/landing.mjs";
import { bootConfig, loadSystem, rolesDir } from "../src/config.mjs";
import { CLOSE_WAIT_MS, createGitSocket, letGo, send } from "../src/git-socket.mjs";
import { CLOSE_WAIT_MS, createGitSocket, LAND_GATE, letGo, send } from "../src/git-socket.mjs";
import { startHost, startTimeOf } from "../src/host.mjs";
import { fixture } from "./helpers.mjs";
@@ -158,7 +159,7 @@ test("the review loop: the coder pushes and asks, the reviewer fetches and appro
const c1 = commit(coder.clone, "two");
assert.deepEqual(await w.push("coder"), { ref: "work/vikunja-1-2", commit: c1, previous: null });
assert.equal(gitIn(coder.clone, "rev-parse", "refs/remotes/working/work/vikunja-1-2"), c1);
assert.equal(w.refs(), `refs/heads/main ${w.main}\nrefs/heads/work/vikunja-1-2 ${c1}`);
assert.equal(w.refs(), `refs/heads/main ${w.main}\nrefs/heads/root ${w.main}\nrefs/heads/work/vikunja-1-2 ${c1}`);
// Nothing new: the clone remembers the push.
await rejects(w.push("coder"), "nothing-to-push");
@@ -286,7 +287,7 @@ test("the socket refuses a request with no capability, an unknown one, and a bad
s.on("error", reject);
});
assert.deepEqual(JSON.parse(junk), { ok: false, error: "invalid-bundle" });
assert.equal(w.refs(), `refs/heads/main ${w.main}`);
assert.equal(w.refs(), `refs/heads/main ${w.main}\nrefs/heads/root ${w.main}`);
});
test("a rigged clone runs nothing: hooks, fsmonitor, a filter, a gitlink and a symlinked .git/config leave no marker", async (t) => {
@@ -620,9 +621,203 @@ test("a record that fails and can't be undone refuses rollback-failed, which the
const c1 = commit(coder.clone, "two");
lock = join(w.repo, "refs", "heads", "work", "vikunja-1-2.lock");
await rejects(w.push("coder"), "rollback-failed");
assert.equal(w.refs(), `refs/heads/main ${w.main}\nrefs/heads/work/vikunja-1-2 ${c1}`);
assert.equal(w.refs(), `refs/heads/main ${w.main}\nrefs/heads/root ${w.main}\nrefs/heads/work/vikunja-1-2 ${c1}`);
assert.equal(w.logs.length, 1);
assert.match(w.logs[0], /^git socket: rollback-failed: refs\/heads\/work\/vikunja-1-2 still names /);
assert.ok((await refusedOn(w)).includes("coder rollback-failed"));
rmSync(lock);
});
// Row 137 (#1631): the land op. The broker's side is a stand-in: checkLand
// needs a merge decision the human resolved through the CLI, and that proof
// needs a human shell (packages/bus/tests/land.test.mjs covers it). The
// working repository, prepareLand, finishLand and dropLand are real, and the
// gate is a stand-in the test passes as `gate`.
const TICKET = "0b1c2d3e-0000-4000-8000-000000000000";
async function landSetup(t, { gate = {}, ...opts } = {}) {
const calls = [];
const state = { facts: null, refuse: null, recordFails: null };
const w = await setup(t, {
gate: {
classify: async (root, env) => (calls.push(["classify", root, env]), true),
run: async () => ({ ok: true }),
dropNetwork: async (name, env) => calls.push(["dropNetwork", name, env]),
...gate,
},
wrap: (host) => ({
op: async (m) => {
if (m.op === "checkLand") {
calls.push(["checkLand", m.args]);
if (state.refuse) throw Object.assign(new Error(state.refuse), { code: state.refuse });
return { ...state.facts, ticket: TICKET };
}
if (m.op === "recordLand") {
calls.push(["recordLand", m.ticket, m.land]);
if (state.recordFails) throw Object.assign(new Error(state.recordFails), { code: state.recordFails });
return { task_ref: TASK, commit: m.land.commit };
}
if (m.op === "landRefused") return calls.push(["landRefused", m.ticket, m.args]), { task_ref: TASK };
return host.op(m);
},
}),
...opts,
});
gitIn(w.roles.coder.clone, "checkout", "-q", "-b", "feat");
const c1 = commit(w.roles.coder.clone, "two");
await w.push("coder");
state.facts = {
task_ref: TASK, work_ref: "work/vikunja-1-2", decision: "decision-1", project: "stack", ref: "work/vikunja-1-2", commit: c1,
verdict: "verdict-1", subject: "Land the parser fix", choice: "yes", by: "jason", resolved_at: "2026-10-16T00:00:00.000Z",
};
const land = () => landWork({ path: w.sock.path, cap: w.roles.coder.cap, task_ref: TASK, decision: "decision-1" });
const git = (...args) => gitIn(w.root, `--git-dir=${w.repo}`, ...args);
// Worktrees other than the bare repository itself.
const trees = () => git("worktree", "list", "--porcelain").split("\n").filter((l) => l.startsWith("worktree ")).length - 1;
const of = (kind) => calls.filter(([k]) => k === kind).map(([, ...rest]) => rest);
const ended = () => until(() => of("dropNetwork").length, "the landing's end");
return { ...w, calls, state, c1, land, git, trees, of, ended };
}
test("land: the squash runs the gate in its own worktree, then main moves and the broker records it", async (t) => {
const seen = [];
const w = await landSetup(t, {
gate: {
run: async (a) => {
seen.push({ ...a, head: gitIn(a.worktree, "rev-parse", "HEAD"), file: readFileSync(join(a.worktree, "file.txt"), "utf8"), link: readlinkSync(join(a.worktree, "node_modules")), status: gitIn(a.worktree, "status", "--porcelain", "--ignored=no") });
return { ok: true };
},
},
});
const r = await w.land();
assert.equal(r.landing, "started");
assert.equal(r.reviewed, w.c1);
assert.equal(r.base, w.main);
assert.match(r.patch_id, /^[0-9a-f]{40}$/);
await w.ended();
// main is the squash: one parent, the old main, and the reviewed commit's tree.
assert.equal(w.git("rev-parse", "refs/heads/main"), r.commit);
assert.equal(w.git("rev-parse", `${r.commit}^@`), w.main);
assert.equal(w.git("rev-parse", `${r.commit}^{tree}`), w.git("rev-parse", `${w.c1}^{tree}`));
const msg = w.git("show", "-s", "--format=%B", r.commit);
assert.match(msg, /^Land the parser fix\n/);
for (const line of [`Decision: decision-1`, `Verdict: verdict-1`, `Reviewed-commit: ${w.c1}`, `Base: main ${w.main}`, `Patch-id: ${r.patch_id}`]) assert.ok(msg.includes(`\n${line}\n`), line);
// w.git trims, so the last line has no newline after it.
assert.match(msg, /\nApplied-under: git socket land \(bus host\)$/);
// The gate ran once, at the squash, with the root's node_modules and the trimmed environment.
assert.equal(seen.length, 1);
const [g] = seen;
assert.equal(g.head, r.commit);
assert.equal(g.file, "two\n");
assert.equal(g.link, join(w.project, "node_modules"));
// Nothing but the link: the fixture project has no .gitignore for it.
assert.equal(g.status, "?? node_modules");
assert.deepEqual(g.env, gateEnv(w.f.env));
assert.equal(g.signal.aborted, false);
const id = g.worktree.split("/").pop();
assert.match(id, /^land-[0-9a-f]{12}$/);
assert.equal(g.worktree, join(w.f.dataRoot, "bus-host", "land", id, id));
assert.equal(g.logs, join(w.f.dataRoot, "bus-host", "land", id));
assert.ok(existsSync(join(g.logs, "reviewed.patch")), "the landing's files stay in its log directory");
assert.deepEqual(w.of("classify"), [[w.project, w.f.env]]);
assert.deepEqual(w.of("checkLand"), [[{ task_ref: TASK, decision: "decision-1" }]]);
assert.deepEqual(w.of("recordLand"), [[TICKET, { commit: r.commit, previous: w.main, reviewed: w.c1, base: w.main, patch_id: r.patch_id }]]);
assert.deepEqual(w.of("landRefused"), []);
assert.deepEqual(w.of("dropNetwork"), [[`${id}_default`, gateEnv(w.f.env)]]);
assert.equal(existsSync(g.worktree), false);
assert.equal(w.trees(), 0);
assert.deepEqual(await refusedOn(w), []);
assert.deepEqual(w.logs, []);
});
test("land: refusals before the gate answer the role at once and leave main and no worktree", async (t) => {
// Until `fit` goes false the gate fits; then the host's own check decides,
// and the fixture's project is no mosaic-stack checkout.
let fit = true;
const w = await landSetup(t, { gate: { classify: async (root, env) => fit || isMosaicStack(root, env) } });
assert.equal(LAND_GATE.classify, isMosaicStack);
assert.equal(LAND_GATE.run, runGate);
const before = w.refs();
// The broker's own refusal: it filed it, so the host files nothing more.
w.state.refuse = "decision-not-approved";
await rejects(w.land(), "decision-not-approved");
assert.deepEqual(w.of("landRefused"), []);
w.state.refuse = null;
// The work ref isn't where the verdict was.
w.state.facts = { ...w.state.facts, commit: "e".repeat(40) };
await rejects(w.land(), "ref-moved");
w.state.facts = { ...w.state.facts, commit: w.c1 };
// The project root isn't a mosaic-stack checkout, so it has no gate.
fit = false;
await rejects(w.land(), "gate-missing");
// A project the business no longer has.
w.state.facts = { ...w.state.facts, project: "gone" };
await rejects(w.land(), "unknown-project");
assert.deepEqual(
w.of("landRefused").map(([ticket, a]) => [ticket, a.code, a.detail, a.notify]),
[[TICKET, "ref-moved", null, false], [TICKET, "gate-missing", null, false], [TICKET, "unknown-project", null, false]],
);
// A request with no decision is the host's own refusal, on the task's trail.
assert.deepEqual(await raw(w.sock.path, `${JSON.stringify({ cap: w.roles.coder.cap, op: "land", task_ref: TASK })}\n`), { ok: false, error: "invalid-request" });
assert.ok((await refusedOn(w)).includes("coder invalid-request"));
assert.equal(w.refs(), before);
assert.equal(w.trees(), 0);
assert.deepEqual(w.of("recordLand"), []);
assert.deepEqual(w.of("dropNetwork"), []);
assert.deepEqual(w.logs, []);
});
test("land: a failed gate is refused gate-failed with its step, told to the role, and main stays", async (t) => {
const w = await landSetup(t, { gate: { run: async ({ logs }) => ({ ok: false, step: "pkg-bus", log: join(logs, "pkg-bus.log") }) } });
const r = await w.land();
await w.ended();
const [[ticket, a]] = w.of("landRefused");
assert.equal(ticket, TICKET);
assert.equal(a.code, "gate-failed");
assert.equal(a.notify, true);
assert.match(a.detail, /^pkg-bus failed, see \/.*\/bus-host\/land\/land-[0-9a-f]{12}\/pkg-bus\.log$/);
assert.equal(w.git("rev-parse", "refs/heads/main"), w.main);
assert.equal(w.git("cat-file", "-t", r.commit), "commit", "the squash was made, and only main didn't move");
assert.deepEqual(w.of("recordLand"), []);
assert.equal(w.trees(), 0);
});
test("land: a record the broker refuses moves main back, and the landing is refused with the broker's code", async (t) => {
const w = await landSetup(t);
w.state.recordFails = "decision-consumed";
await w.land();
await w.ended();
assert.equal(w.of("recordLand").length, 1);
assert.deepEqual(w.of("landRefused"), [[TICKET, { code: "decision-consumed", detail: null, notify: true }]]);
assert.equal(w.git("rev-parse", "refs/heads/main"), w.main);
assert.equal(w.trees(), 0);
assert.deepEqual(w.logs, []);
});
test("land: a second landing while one runs refuses land-busy, and close() stops the gate and refuses host-closing", async (t) => {
let started = null;
const running = new Promise((r) => (started = r));
const w = await landSetup(t, {
gate: {
run: ({ signal }) => {
started();
return new Promise((resolve) => signal.addEventListener("abort", () => resolve({ ok: false, aborted: true }), { once: true }));
},
},
});
await w.land();
await running;
await rejects(w.land(), "land-busy");
assert.ok((await refusedOn(w)).includes("coder land-busy"));
assert.deepEqual(w.of("checkLand").length, 1, "land-busy refuses before the broker is asked");
await w.sock.close();
assert.deepEqual(
w.of("landRefused").map(([, a]) => a),
[{ code: "host-closing", detail: "the host closed during the gate; nothing moved", notify: true }],
);
assert.equal(w.of("dropNetwork").length, 1);
assert.equal(w.git("rev-parse", "refs/heads/main"), w.main);
assert.equal(w.trees(), 0);
});
+33 -2
View File
@@ -80,7 +80,8 @@ function prepare(t, more = (doc) => doc) {
return { root, f, adapter };
}
async function setup(t, more = (doc) => doc, { root, f, adapter } = prepare(t, more), options = {}) {
// options.wrap(host) is what the launcher sees, so a test can change one of the host's answers.
async function setup(t, more = (doc) => doc, { root, f, adapter } = prepare(t, more), { wrap = (h) => h, ...options } = {}) {
const system = loadSystem({ env: f.env });
const boot = bootConfig({ system, businessId: "acme", env: f.env });
const logs = [];
@@ -88,7 +89,7 @@ async function setup(t, more = (doc) => doc, { root, f, adapter } = prepare(t, m
let launcher;
try {
launcher = createLauncher({
host,
host: wrap(host),
system,
env: f.env,
adapters: { pi: adapter, "claude-code": adapter },
@@ -382,6 +383,36 @@ test("each launch makes sure the workspace has a clone of the project: cloned, f
assert.equal(gitIn(project, "status", "--porcelain"), "");
});
// 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) => {
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 landing = "- Landing: once the human approved your merge decision, 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 pm1 = await one.launcher.launchPm();
assert.deepEqual(asked, [{ business: "acme", role: "chief", thread: null }]);
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));
// A separate fixture, so its business and data root are new.
const two = await setup(t, undefined, undefined, answering(false));
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);
});
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) => {
const given = prepare(t);
renameSync(join(given.f.doc.projects.stack.root, ".git"), join(given.root, "away.git"));
@@ -84,6 +84,7 @@ async function start(t, { f, adapter }, { tickMs = 100, ops: replace } = {}) {
credentialStatus: (m) => runtime.credentialStatus(m.business, m.role),
threadsState: (m) => runtime.threadsState(m.business),
threadIdle: (m) => runtime.threadIdle(m.record),
landHeld: (m) => runtime.landHeld(m.record),
...replace?.(runtime),
};
const refusing = (what, fn) => async (m) => {