salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r137/wt4 (disk cleanup #824)
This commit is contained in:
1 parent
63c82f1c47
commit
0bcee35167
31 files changed
+2160
-255
No files matched your search
+38
-6
@@ -401,9 +401,12 @@ The launcher also serves `<dataRoot>/bus-host/git.sock` (0600,
|
||||
`src/git-socket.mjs`, row 93, #1587). A coder's runner pushes work to the
|
||||
business's working repository through it, and a reviewer's runner fetches a
|
||||
commit it was asked to review (`push_working` and `fetch_review`,
|
||||
`packages/harness/README.md`). The sandbox binds it only for a role that
|
||||
holds git.push.working or review.verdict, and a session's `session.json`
|
||||
names it as `gitSocket` only then.
|
||||
`packages/harness/README.md`). A role granted git.merge.protected
|
||||
cross-role whose merge decision was approved, by its arbiter or the human,
|
||||
lands its task on the repository's `main` (`land_work`, row 137, #1631). The sandbox binds the socket only for a role that holds
|
||||
git.push.working or review.verdict, or one the broker's `landHeld` says
|
||||
holds a merge decision it could land. A session's `session.json` names it
|
||||
as `gitSocket` only then.
|
||||
|
||||
Only a git bundle crosses. The host never runs git in a session's clone
|
||||
and never opens a path in its workspace; `packages/seat/README.md` ("The
|
||||
@@ -414,11 +417,12 @@ JSON line of at most 4096 bytes:
|
||||
|---|---|---|
|
||||
| push | `{cap, op: "push", task_ref, project, branch, size}` | `{ok: true, send: <size>}`; the runner sends exactly that many bundle bytes; then `{ok: true, result: {ref, commit, previous}}` |
|
||||
| fetch | `{cap, op: "fetch", task_ref, request, have}` | `{ok: true, result: {project, ref, commit, size}}`, then that many bytes of a bundle whose one ref is `refs/mosaic/review` |
|
||||
| land | `{cap, op: "land", task_ref, decision}` | `{ok: true, result: {landing: "started", commit, base, reviewed, patch_id}}` once every check before the gate passed; `commit` is the squash that will land |
|
||||
|
||||
The host checks the caller's identity (a role of this business), then the
|
||||
request (task ref, project, branch name, a size of at most 32 MiB), then
|
||||
the broker: `checkPush` for a push, `reviewFetch` for a fetch. Only
|
||||
then does it read bundle bytes. The broker records a push with
|
||||
the broker: `checkPush` for a push, `reviewFetch` for a fetch,
|
||||
`checkLand` for a landing. Only then does it read bundle bytes. The broker records a push with
|
||||
`recordPush` under the repository's lock once the ref moved; when it
|
||||
refuses, the ref goes back. A refusal is `{ok: false, error: <code>}` and
|
||||
ends the connection. The host's own refusals go through the broker's
|
||||
@@ -444,11 +448,39 @@ Codes a reviewer may see that aren't the broker's:
|
||||
`rollback-failed` (a push the broker refused whose work ref couldn't go
|
||||
back) are the host's own faults, and the host logs them as well.
|
||||
|
||||
A landing runs land-work's steps (`scripts/land-work.sh`) against the
|
||||
working repository's `main`, never the project root:
|
||||
|
||||
1. The broker's `checkLand` checks the decision and the verdict and gives
|
||||
the host a ticket (`packages/bus/README.md`).
|
||||
2. `prepareLand` builds the squash in a worktree under
|
||||
`bus-host/land/<id>/` (`packages/seat/README.md`, "Landing on main").
|
||||
The message is land-work's. Its Resolved line names the channel from
|
||||
the ticket's `via`: the human via the CLI, or the arbiter via the broker.
|
||||
3. The project root has to be a mosaic-stack checkout with `node_modules`
|
||||
(`isMosaicStack`), or `gate-missing`. The root's `node_modules` is
|
||||
linked into the worktree.
|
||||
4. The host answers `started`, and the gate runs in the background, in the
|
||||
squash's worktree, with `gateEnv`'s variables only.
|
||||
5. `finishLand` moves `main` and the broker's `recordLand` records it.
|
||||
|
||||
One landing runs at a time; another refuses `land-busy`. From the ticket
|
||||
on, every refusal goes to the broker's `landRefused`, on the task's trail.
|
||||
A refusal before the `started` answer is also the reply. After it, the role
|
||||
learns the outcome as a RESULT message from the bus: the landing, or
|
||||
`gate-failed` (naming the step and its log), `base-moved`, a broker
|
||||
refusal, or `host-closing` when the launcher closed during the gate, in
|
||||
which case nothing moved. The logs stay in `bus-host/land/<id>/`. The
|
||||
worktree and the gate's Docker network, `<id>_default`, go on every path.
|
||||
`createGitSocket({gate})` takes the gate's three parts (`LAND_GATE`:
|
||||
`classify`, `run`, `dropNetwork`) so the tests can run a fake one.
|
||||
|
||||
A bundle file lives in `bus-host/` (0700) under a random name and is
|
||||
deleted on every path. On close the launcher answers `host-closing` to a
|
||||
connection still sending its request line, since nothing of it ran yet,
|
||||
and drops every other connection. It waits for any push in flight to finish
|
||||
under its lock before the broker stops. It waits at most 2 s
|
||||
under its lock before the broker stops, and stops a running gate, whose
|
||||
landing is refused `host-closing`. It waits at most 2 s
|
||||
(`CLOSE_WAIT_MS`) for its `host-closing` answers to leave, then drops those
|
||||
connections too, so a peer that never reads can't hold the close.
|
||||
|
||||
|
||||
+130
-10
@@ -1,10 +1,12 @@
|
||||
// The host's git socket (#1587), `<dataRoot>/bus-host/git.sock` (0600). A
|
||||
// coder's runner pushes its work to the business's working repository
|
||||
// through it, and a reviewer's runner fetches a commit it was asked to
|
||||
// review. The bundle is the only thing that crosses: the host never runs git
|
||||
// in a session's clone and never opens a path in a session's workspace
|
||||
// (packages/seat/src/working.mjs says why). The sandbox binds the socket only
|
||||
// for a role that holds git.push.working or review.verdict.
|
||||
// through it, a reviewer's runner fetches a commit it was asked to review,
|
||||
// and a run holding an approved merge decision lands its task on the
|
||||
// repository's main (row 137, #1631). The bundle is the only thing that
|
||||
// crosses: the host never runs git in a session's clone and never opens a
|
||||
// path in a session's workspace (packages/seat/src/working.mjs says why). The
|
||||
// sandbox binds the socket only for a role that holds git.push.working or
|
||||
// review.verdict, or a merge decision a landing could use (landHeld).
|
||||
//
|
||||
// Every connection starts with one JSON line of at most 4096 bytes.
|
||||
//
|
||||
@@ -17,6 +19,13 @@
|
||||
// The host answers {"ok": true, "result": {project, ref, commit,
|
||||
// size}} followed by <size> bytes of a bundle whose one ref is
|
||||
// refs/mosaic/review, or a refusal.
|
||||
// land {"cap", "op": "land", "task_ref", "decision"}
|
||||
// The host answers {"ok": true, "result": {landing: "started",
|
||||
// commit, base, reviewed, patch_id}} once everything that can
|
||||
// refuse before the gate has passed, or a refusal. `commit` is the
|
||||
// squash that will land. The gate runs after the answer, and its
|
||||
// outcome is the broker's: recordLand or landRefused, each on the
|
||||
// task's trail and told to the role as a RESULT message.
|
||||
//
|
||||
// A refusal is {"ok": false, "error": "<code>"}, and the connection ends.
|
||||
// The host checks, in order: identity (a role of this business), the request
|
||||
@@ -41,13 +50,23 @@
|
||||
//
|
||||
// A bundle file lives in bus-host/ (0700) under a random name, and the host
|
||||
// deletes it on every path.
|
||||
//
|
||||
// A landing runs land-work's steps (scripts/land-work.sh): the broker's
|
||||
// checkLand, then prepareLand (working.mjs) under the repository's lock, the
|
||||
// gate check (gate-missing), the gate in the squash's worktree with the
|
||||
// root's node_modules linked, and finishLand, which moves main and records.
|
||||
// One landing runs at a time; another refuses land-busy. Its logs stay in
|
||||
// bus-host/land/<id>/, and its worktree and Docker network go on every path.
|
||||
// close() stops a running gate, and the landing is refused host-closing.
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { closeSync, createReadStream, existsSync, lstatSync, openSync, rmSync, statSync, writeSync, chmodSync } from "node:fs";
|
||||
import { closeSync, createReadStream, existsSync, lstatSync, mkdirSync, openSync, rmSync, statSync, symlinkSync, writeSync, chmodSync } from "node:fs";
|
||||
import { createServer } from "node:net";
|
||||
import { join } from "node:path";
|
||||
import { gitSocketPath } from "../../seat/src/session.mjs";
|
||||
import { BUNDLE_MAX, FSCK, HAVE_MAX, push, review, validBranch, workRef, WorkingError } from "../../seat/src/working.mjs";
|
||||
import { gateEnv, isMosaicStack, rootHits, runGate } from "../../seat/src/landing.mjs";
|
||||
import { BUNDLE_MAX, dropLand, finishLand, FSCK, HAVE_MAX, prepareLand, push, review, validBranch, workRef, WorkingError } from "../../seat/src/working.mjs";
|
||||
import { CliError } from "./errors.mjs";
|
||||
|
||||
const HEADER_MAX = 4096;
|
||||
@@ -217,9 +236,43 @@ export async function letGo(sockets, ms = CLOSE_WAIT_MS) {
|
||||
for (const s of sockets) s.destroy();
|
||||
}
|
||||
|
||||
// Removes the Docker network a gate's Compose project left. The project is
|
||||
// named after the worktree, so the network is <name>_default.
|
||||
function dropNetwork(name, env) {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn("docker", ["network", "rm", name], { env, stdio: "ignore" });
|
||||
child.on("error", () => resolve());
|
||||
child.on("close", () => resolve());
|
||||
});
|
||||
}
|
||||
export const LAND_GATE = { classify: isMosaicStack, run: runGate, dropNetwork };
|
||||
|
||||
// How the decision was resolved, by the resolution's via: the human through the CLI, or the
|
||||
// arbiter through the broker (row 137, REQ-DEC-2). readLanding takes no other.
|
||||
const RESOLVED_VIA = { cli: "via the CLI", broker: "as its arbiter, via the broker" };
|
||||
|
||||
// The squash's message: land-work's, applied under the git socket.
|
||||
function landMessage(f, { old, base, patch_id }) {
|
||||
return `${f.subject}
|
||||
|
||||
Squash of ${f.work_ref} (${f.task_ref}) at ${f.commit} onto main ${old},
|
||||
the reviewed diff ${base}..${f.commit}. Resolved ${f.choice} by ${f.by} ${RESOLVED_VIA[f.via] ?? `via ${f.via}`} at ${f.resolved_at}.
|
||||
|
||||
Decision: ${f.decision}
|
||||
Verdict: ${f.verdict}
|
||||
Work-ref: ${f.work_ref}
|
||||
Reviewed-commit: ${f.commit}
|
||||
Base: main ${old}
|
||||
Patch-id: ${patch_id}
|
||||
Gate: full, every package suite and every scripts/test-*.sh
|
||||
Applied-under: git socket land (bus host)
|
||||
`;
|
||||
}
|
||||
|
||||
// host: startHost()'s handle; business: loadBusiness() output. bundleMax,
|
||||
// bodyDeadline, bodyIdle, maxActive and fsck are for the tests.
|
||||
export function createGitSocket({ host, business: b, dataRoot, env = process.env, log = () => {}, bundleMax = BUNDLE_MAX, bodyDeadline: deadlineOf = bodyDeadline, bodyIdle = BODY_IDLE_MS, maxActive = MAX_ACTIVE, fsck = FSCK }) {
|
||||
// bodyDeadline, bodyIdle, maxActive, fsck and gate (LAND_GATE's shape) are
|
||||
// for the tests.
|
||||
export function createGitSocket({ host, business: b, dataRoot, env = process.env, log = () => {}, bundleMax = BUNDLE_MAX, bodyDeadline: deadlineOf = bodyDeadline, bodyIdle = BODY_IDLE_MS, maxActive = MAX_ACTIVE, fsck = FSCK, gate = LAND_GATE }) {
|
||||
const path = gitSocketPath(dataRoot);
|
||||
const dir = join(dataRoot, "bus-host");
|
||||
let server = null;
|
||||
@@ -228,6 +281,8 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
const active = new Set();
|
||||
// Connections still reading their request line (readHeader).
|
||||
const waiting = new Map();
|
||||
// The running landing, { abort, done }, or null.
|
||||
let landing = null;
|
||||
|
||||
const op = async (message) => {
|
||||
try {
|
||||
@@ -270,6 +325,67 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
await send(socket, file);
|
||||
}
|
||||
|
||||
async function doLand(socket, cap, req) {
|
||||
const { task_ref, decision } = req;
|
||||
if (typeof decision !== "string") throw new Refusal("invalid-request");
|
||||
workRef(task_ref);
|
||||
if (landing) throw new Refusal("land-busy", "another landing is running");
|
||||
// Taken before the first await, so two requests can't both pass.
|
||||
const slot = { abort: new AbortController(), done: null };
|
||||
landing = slot;
|
||||
try {
|
||||
await startLand(socket, cap, task_ref, decision, slot);
|
||||
} finally {
|
||||
if (!slot.done) landing = null;
|
||||
}
|
||||
}
|
||||
|
||||
// From the broker's ticket on, each refusal is the landing's (landRefused):
|
||||
// the run's cap may be gone by the time the gate ends.
|
||||
async function startLand(socket, cap, task_ref, decision, slot) {
|
||||
const facts = await op({ op: "checkLand", cap, args: { task_ref, decision } });
|
||||
const { ticket } = facts;
|
||||
const id = `land-${randomBytes(6).toString("hex")}`;
|
||||
const logs = join(dir, "land", id);
|
||||
const p = project(facts.project);
|
||||
const where = { dataRoot, business: b.id, project: facts.project, env };
|
||||
const refused = async (e, notify) => {
|
||||
const code = e instanceof Refusal || e instanceof Recorded || e instanceof WorkingError ? e.code : "git-failed";
|
||||
if (code === "git-failed" || code === "rollback-failed") log(`git socket: ${id}: ${code}: ${e.message}`);
|
||||
// The host's own faults stay in its log; the role gets the code.
|
||||
const detail = notify && code !== "git-failed" && e.message !== code ? e.message.slice(0, 1000) : null;
|
||||
await host.op({ op: "landRefused", ticket, args: { code, detail, notify } }).catch((x) => log(`git socket: ${id}: refusal ${code} not recorded: ${x.code ?? x.message}`));
|
||||
return code;
|
||||
};
|
||||
let prepared = null;
|
||||
try {
|
||||
if (!p) throw new Refusal("unknown-project");
|
||||
mkdirSync(logs, { recursive: true, mode: 0o700 });
|
||||
prepared = await prepareLand({ ...where, root: p.root, taskRef: task_ref, commit: facts.commit, dir: logs, name: id, rootHits, message: (m) => landMessage(facts, m) });
|
||||
if (!(await gate.classify(p.root, env))) throw new Refusal("gate-missing", `${p.root} isn't a mosaic-stack checkout with node_modules`);
|
||||
symlinkSync(join(p.root, "node_modules"), join(prepared.worktree, "node_modules"));
|
||||
} catch (e) {
|
||||
if (prepared) await dropLand({ ...where, worktree: prepared.worktree }).catch((x) => log(`git socket: ${id}: ${x.message}`));
|
||||
throw new Recorded(await refused(e, false));
|
||||
}
|
||||
const { commit, base, reviewed, patch_id } = prepared;
|
||||
socket.end(`${JSON.stringify({ ok: true, result: { landing: "started", commit, base, reviewed, patch_id } })}\n`);
|
||||
slot.done = (async () => {
|
||||
try {
|
||||
const r = await gate.run({ worktree: prepared.worktree, logs, env: gateEnv(env), signal: slot.abort.signal });
|
||||
if (r.aborted || slot.abort.signal.aborted) throw new Refusal("host-closing", "the host closed during the gate; nothing moved");
|
||||
if (!r.ok) throw new Refusal("gate-failed", `${r.step} failed, see ${r.log}`);
|
||||
await finishLand({ ...where, land: prepared, record: (m) => op({ op: "recordLand", ticket, land: { ...m, reviewed, base, patch_id } }) });
|
||||
} catch (e) {
|
||||
await refused(e, true);
|
||||
} finally {
|
||||
await dropLand({ ...where, worktree: prepared.worktree }).catch((x) => log(`git socket: ${id}: ${x.message}`));
|
||||
await gate.dropNetwork(`${id}_default`, gateEnv(env));
|
||||
landing = null;
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
async function serve(socket) {
|
||||
let cap = null;
|
||||
let subject = null;
|
||||
@@ -293,7 +409,8 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
file = join(dir, `${randomBytes(8).toString("hex")}.bundle`);
|
||||
if (req.op === "push") await doPush(socket, cap, req, rest, file);
|
||||
else if (req.op === "fetch") await doFetch(socket, cap, req, file);
|
||||
else throw new Refusal("invalid-request", "op is push or fetch");
|
||||
else if (req.op === "land") await doLand(socket, cap, req);
|
||||
else throw new Refusal("invalid-request", "op is push, fetch or land");
|
||||
} catch (e) {
|
||||
if (e instanceof Recorded) return fail(e.code);
|
||||
const code = e instanceof Refusal || e instanceof WorkingError ? e.code : "git-failed";
|
||||
@@ -330,6 +447,7 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
// A push whose bundle already came finishes, under its lock, while the
|
||||
// broker still runs: the launcher's close() runs before the host stops it.
|
||||
// A connection still waiting for its request line hears host-closing first.
|
||||
// A landing's gate is stopped, and its refusal recorded the same way.
|
||||
async function close() {
|
||||
closed = true;
|
||||
if (!server) return;
|
||||
@@ -337,7 +455,9 @@ export function createGitSocket({ host, business: b, dataRoot, env = process.env
|
||||
const told = new Set(waiting.keys());
|
||||
for (const stop of [...waiting.values()]) stop();
|
||||
for (const socket of sockets) if (!told.has(socket)) socket.destroy();
|
||||
landing?.abort.abort();
|
||||
await Promise.allSettled([...active]);
|
||||
await landing?.done;
|
||||
// The refusal is a few bytes; once it is flushed, or the peer is gone,
|
||||
// nothing more is owed, and past CLOSE_WAIT_MS it is dropped unsent.
|
||||
await letGo([...told]);
|
||||
|
||||
@@ -38,7 +38,8 @@
|
||||
//
|
||||
// listen() also serves the git socket (src/git-socket.mjs, row 93), which
|
||||
// the sandbox binds for a role that holds git.push.working or
|
||||
// review.verdict; session.json names it as gitSocket.
|
||||
// review.verdict, or a merge decision to land (landHeld, row 137);
|
||||
// session.json names it as gitSocket.
|
||||
//
|
||||
// Thread sessions (row 121, #1615). A thread instance (an instance whose
|
||||
// role definition is the assistant) runs once per thread, never on its own:
|
||||
@@ -256,6 +257,9 @@ export function createLauncher({
|
||||
const toolSocket = join(runDir, "tools.sock");
|
||||
const turnMarker = join(runDir, "turn.done");
|
||||
const v = versions ?? { pi: piVersion(), claude: model.harness === "claude-code" ? claudeVersion(env) : null };
|
||||
// Row 137 (#1631): a role and thread holding an approved, unspent merge decision get land_work.
|
||||
// The broker checks the decision again on every land; this only decides what the bundle shows.
|
||||
const land = await host.op({ op: "landHeld", record: { business: b.id, role: instance, thread } });
|
||||
const bundle = buildBundle({
|
||||
dir: join(runDir, "bundle"),
|
||||
resolved,
|
||||
@@ -267,11 +271,12 @@ export function createLauncher({
|
||||
session: { run, launchedBy, workspace, toolSocket, turnMarker, checkouts },
|
||||
piVersion: v.pi,
|
||||
claudeVersion: v.claude,
|
||||
land,
|
||||
});
|
||||
const { manifest, ...files } = bundle.files;
|
||||
// Row 93: the git socket, for a role that pushes work or reviews it.
|
||||
// Row 93: the git socket, for a role that pushes work or reviews it. Row 137: or lands it.
|
||||
const held = [...resolved.limits.authority.withinRole, ...resolved.limits.authority.crossRole];
|
||||
const git = held.includes("git.push.working") || held.includes("review.verdict") ? gitSocketPath(dataRoot) : null;
|
||||
const git = land || held.includes("git.push.working") || held.includes("review.verdict") ? gitSocketPath(dataRoot) : null;
|
||||
writeSessionFile(runDir, {
|
||||
...sessionDefaults,
|
||||
business: b.id,
|
||||
|
||||
@@ -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,217 @@ 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 cross-role merge decision its arbiter or the human resolved
|
||||
// (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", via: "cli",
|
||||
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/);
|
||||
assert.ok(msg.includes(" Resolved yes by jason via the CLI at 2026-10-16T00:00:00.000Z.\n"), msg);
|
||||
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, []);
|
||||
});
|
||||
|
||||
// Row 137 B1: the squash names the channel that resolved the decision. An arbiter's
|
||||
// resolution came through the broker, not the CLI.
|
||||
test("land: an arbiter-resolved landing's squash says the arbiter resolved it through the broker", async (t) => {
|
||||
const w = await landSetup(t);
|
||||
w.state.facts = { ...w.state.facts, by: "pm-run", via: "broker" };
|
||||
const r = await w.land();
|
||||
await w.ended();
|
||||
const msg = w.git("show", "-s", "--format=%B", r.commit);
|
||||
assert.ok(msg.includes(" Resolved yes by pm-run as its arbiter, via the broker at 2026-10-16T00:00:00.000Z.\n"), msg);
|
||||
assert.ok(!msg.includes("via the CLI"), msg);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
@@ -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 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 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) => {
|
||||
|
||||
Reference in new issue
Block a user