commit c302699c4f68ac7744f9bb3deb1c181970094d95
parent c1db0d61dda60407eceaddb0773e0b9f03a42d3b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 15 Oct 2026 07:41:23 -0400
common, mcp, scripts: debts — relocateDir counts directories that differ only in mtime apart (classifyDrift's mtimeOnly, "N directories differ only in mtime"; a reconcile whose only drift is that says the content matches); fetchPosts.test's paged walk and its resume's cancel are stepped by files (the fake's cursor and next page wait on gates; the cancel on the argv log), not 100/300/200 ms; queue-lock.test's holds are gates opened once the waiter has said it waits (banner, QUEUE_LOCK_HELD, E2E_QUEUE=0, the SIGKILL, two heavy, e2e behind heavy, two builds, the undeclared job, the nested build, named suites, the SIGTERM waiter, --scale-by); generate's answer for a media draft puts its video project first
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 217 insertions(+), 77 deletions(-)
diff --git a/common/controller/fetchPosts.test.ts b/common/controller/fetchPosts.test.ts
@@ -7,6 +7,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
+import { writeFileSync } from "node:fs";
import { chmod, mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
@@ -25,8 +26,11 @@ process.env.FAKE_ARGS_LOG = ARGS_LOG;
// blocks on a "rate limit" (the real stall); given the cursor after page 2 it
// emits page 3 and exits cleanly. FAKE_MODE=known emits page 1 then endless
// tweets older than the watermark, to prove the early stop kills it.
-// FAKE_MODE=pages emits six pages, each followed (after a pause) by an info
-// line, then its cursor: a walk with a page boundary every few hundred ms.
+// FAKE_MODE=pages walks six pages, each its records, an info line, then its
+// cursor — and the walk is the TEST's to step, not a clock's (release 29 D1):
+// a page's cursor waits for the file `cursor-<p>` in FAKE_GATES, the next page
+// for `page-<p+1>` (polled; 30 s and it gives up), so a drain lands exactly
+// between a page's records and its cursor however loaded the machine is.
await writeFile(
BIN,
`#!/usr/bin/env node
@@ -63,17 +67,21 @@ if (process.env.FAKE_MODE === "known") {
log("[twitter][error] AbortExtraction: 404 Not Found (GraphQL query id rotated)");
process.exit(4);
} else if (process.env.FAKE_MODE === "pages") {
+ const { existsSync } = await import("node:fs");
+ const gate = (name, then) => {
+ const file = process.env.FAKE_GATES + "/" + name;
+ const t = setInterval(() => { if (existsSync(file)) { clearInterval(t); then(); } }, 10);
+ };
+ setTimeout(() => process.exit(3), 30_000);
let p = 0;
const next = () => {
page(p);
- setTimeout(() => {
- log("[twitter][info] page " + p + " read");
- setTimeout(() => {
- log("[twitter][debug] Cursor: 1/PAGES-P" + p);
- p++;
- if (p < 6) setTimeout(next, 300); else process.exit(0);
- }, 300);
- }, 100);
+ log("[twitter][info] page " + p + " read");
+ gate("cursor-" + p, () => {
+ log("[twitter][debug] Cursor: 1/PAGES-P" + p);
+ p++;
+ if (p < 6) gate("page-" + p, next); else process.exit(0);
+ });
};
next();
} else if (cursor === "1/AFTER-P2") {
@@ -238,7 +246,11 @@ test("a drain mid-page waits for the page's cursor, stops there and keeps it; th
const root = await makeChannel(slug);
const drain = new AbortController();
const log: string[] = [];
+ const gates = path.join(ROOT, `gates-${slug}`);
+ await mkdir(gates, { recursive: true });
+ const open = (name: string) => writeFileSync(path.join(gates, name), "");
process.env.FAKE_MODE = "pages";
+ process.env.FAKE_GATES = gates;
let result;
try {
result = await fetchPosts({
@@ -248,12 +260,21 @@ test("a drain mid-page waits for the page's cursor, stops there and keeps it; th
drain: drain.signal,
onLog: (line) => {
log.push(line);
- // Page 1's records are in; its cursor is not yet.
- if (/page 1 read/.test(line)) drain.abort();
+ // Page 0 read: its cursor, then page 1. Page 1's records are in and its
+ // cursor is not yet: drain, THEN let the cursor come. Page 2 is never let.
+ if (/page 0 read/.test(line)) {
+ open("cursor-0");
+ open("page-1");
+ }
+ if (/page 1 read/.test(line)) {
+ drain.abort();
+ open("cursor-1");
+ }
},
});
} finally {
delete process.env.FAKE_MODE;
+ delete process.env.FAKE_GATES;
}
assert.equal(result.ok, true, log.join("\n"));
assert.equal(result.drained, true);
@@ -267,16 +288,26 @@ test("a drain mid-page waits for the page's cursor, stops there and keeps it; th
assert.equal(log.some((l) => /page 2 read/.test(l)), false, log.join("\n"));
assert.ok(log.some((l) => /Drained; the next run resumes from the last page read/.test(l)), log.join("\n"));
- // The next run resumes there (cancelled once it has started: only its argv
- // is wanted).
+ // The next run resumes there (cancelled once the fake has logged its argv:
+ // only that is wanted — a file, not a fixed wait).
const cancel = new AbortController();
+ const argvLines = async () => (await readFile(ARGS_LOG, "utf8")).trim().split("\n").length;
+ const had = await argvLines();
await fetchPosts({
paths: (await import("../lib/paths")).getPaths(),
slug,
settings: {},
signal: cancel.signal,
onLog: (line) => {
- if (/^Running /.test(line)) setTimeout(() => cancel.abort(), 200);
+ if (!/^Running /.test(line)) return;
+ const t = setInterval(() => {
+ void argvLines().then((n) => {
+ if (n > had) {
+ clearInterval(t);
+ cancel.abort();
+ }
+ });
+ }, 10);
},
});
assert.ok((await lastArgv()).includes("extractor.twitter.cursor=1/PAGES-P1"));
diff --git a/common/controller/relocateDir.test.ts b/common/controller/relocateDir.test.ts
@@ -502,13 +502,40 @@ test("rsync's itemized lines sort into extra, missing and changed", () => {
"v50t5yt/.audio.mp3.parakeet/",
]);
assert.deepEqual(d.missing, ["v51/transcript.json", "v52/"]);
- assert.deepEqual(d.changed, [
- "v1/transcript.json",
- "v1/",
- "rsync: something it wanted to say",
- ]);
+ // A directory whose only difference is its mtime is not "changed" (release 29 D1).
+ assert.deepEqual(d.changed, ["v1/transcript.json", "rsync: something it wanted to say"]);
+ assert.deepEqual(d.mtimeOnly, ["v1/"]);
assert.equal(
- describeDifferences({ extra: [], missing: ["a", "b", "c", "d", "e", "f", "g"], changed: [] }),
+ describeDifferences({ extra: [], missing: ["a", "b", "c", "d", "e", "f", "g"], changed: [], mtimeOnly: [] }),
"0 extra on the destination, 7 missing on the destination (a, b, c, d, e, … 2 more), 0 changed",
);
+ assert.equal(
+ describeDifferences({ extra: [], missing: [], changed: ["v2/x.json"], mtimeOnly: ["v1/", "v3/"] }),
+ "0 extra on the destination, 0 missing on the destination, 1 changed (v2/x.json), and 2 directories differ only in mtime (v1/, v3/)",
+ );
+});
+
+test("a reconcile whose only drift is directory timestamps says so — not that anything changed — and settles them", async () => {
+ await withTrees(async ({ src, dest }) => {
+ await put(src, "v1/audio.mp3", "one".repeat(10));
+ await put(src, "v2/audio.mp3", "two".repeat(10));
+ await put(dest, "v1/audio.mp3", "one".repeat(10));
+ await put(dest, "v2/audio.mp3", "two".repeat(10));
+ // Same bytes, same file times; only the two directories' mtimes differ.
+ const t = new Date("2026-01-05T00:00:00Z");
+ for (const f of ["v1/audio.mp3", "v2/audio.mp3"]) {
+ await utimes(path.join(src, f), t, t);
+ await utimes(path.join(dest, f), t, t);
+ }
+ await utimes(path.join(src, "v1"), t, t);
+ await utimes(path.join(src, "v2"), t, t);
+ await utimes(src, t, t);
+ await utimes(dest, t, t);
+ const lines: string[] = [];
+ await copyMirrorVerify({ rsyncBin: "rsync", src, dest, live: src, cancelled, reconcile: true, log: (m) => lines.push(m) });
+ const said = lines.find((l) => l.startsWith("Reconciling:")) ?? "";
+ assert.match(said, /content already matches the source; 2 directories differ only in mtime \(v1\/, v2\/\)/);
+ assert.doesNotMatch(said, /\d+ changed/);
+ assert.equal((await stat(path.join(dest, "v1"))).mtimeMs, t.getTime(), "the mirror pass settled them");
+ });
});
diff --git a/common/controller/relocateDir.ts b/common/controller/relocateDir.ts
@@ -382,12 +382,15 @@ function driftLines(output: string): string[] {
// The differences a verify's dry run reports, sorted into what the operator can
// act on: a path the destination has and the source does not ("extra on the
// destination" — the realcandaceo scratch dir), one the destination lacks
-// ("missing on the destination"), and one both have that differs ("changed",
-// a directory's timestamp included). Paths are relative to the tree.
+// ("missing on the destination"), and one both have that differs ("changed").
+// A directory whose only difference is its modification time (DIR_MTIME_ONLY)
+// is no content in question and is counted apart ("differ only in mtime"), as
+// the verify treats it (release 29 D1). Paths are relative to the tree.
export type CopyDifferences = {
extra: string[];
missing: string[];
changed: string[];
+ mtimeOnly: string[];
};
// rsync's itemize line is `YXcstpoguax path`: Y the update type, X the file
@@ -395,9 +398,11 @@ export type CopyDifferences = {
// does not exist on the receiving side yet. A deletion is `*deleting path`.
// Anything else (a warning rsync printed) is reported whole, as changed.
export function classifyDrift(lines: ReadonlyArray<string>): CopyDifferences {
- const out: CopyDifferences = { extra: [], missing: [], changed: [] };
+ const out: CopyDifferences = { extra: [], missing: [], changed: [], mtimeOnly: [] };
for (const line of lines) {
- if (line.startsWith("*deleting")) {
+ if (DIR_MTIME_ONLY.test(line)) {
+ out.mtimeOnly.push(line.replace(/^\S+\s+/, ""));
+ } else if (line.startsWith("*deleting")) {
out.extra.push(line.replace(/^\S+\s+/, ""));
} else if (/^[<>ch.][fdLDS]\+{5,}\s/.test(line)) {
out.missing.push(line.replace(/^\S+\s+/, ""));
@@ -410,25 +415,31 @@ export function classifyDrift(lines: ReadonlyArray<string>): CopyDifferences {
return out;
}
-function countDifferences(d: CopyDifferences): number {
+// What differs in content: a directory's timestamp alone is not counted.
+function countContentDifferences(d: CopyDifferences): number {
return d.extra.length + d.missing.length + d.changed.length;
}
+const paths5 = (n: string[]) => `${n.slice(0, 5).join(", ")}${n.length > 5 ? `, … ${n.length - 5} more` : ""}`;
+
+// "N directories differ only in mtime (v1/, v2/)", or "" for none.
+export function describeMtimeOnly(d: Pick<CopyDifferences, "mtimeOnly">): string {
+ const n = d.mtimeOnly?.length ?? 0;
+ if (n === 0) return "";
+ return `${n} ${n === 1 ? "directory differs" : "directories differ"} only in mtime (${paths5(d.mtimeOnly)})`;
+}
+
// "2 extra on the destination (v1/.x/meta.json, v1/.x/win-0000.json), 0
// missing on the destination, 1 changed (v2/transcript.json)" — at most five
-// paths of each kind, the rest counted.
+// paths of each kind, the rest counted — and, when there are any, "and 3
+// directories differ only in mtime (…)".
export function describeDifferences(d: CopyDifferences): string {
- const kind = (n: string[], words: string) => {
- if (n.length === 0) return `0 ${words}`;
- const shown = n.slice(0, 5).join(", ");
- const more = n.length > 5 ? `, … ${n.length - 5} more` : "";
- return `${n.length} ${words} (${shown}${more})`;
- };
- return [
- kind(d.extra, "extra on the destination"),
- kind(d.missing, "missing on the destination"),
- kind(d.changed, "changed"),
- ].join(", ");
+ const kind = (n: string[], words: string) => (n.length === 0 ? `0 ${words}` : `${n.length} ${words} (${paths5(n)})`);
+ const mtime = describeMtimeOnly(d);
+ return (
+ [kind(d.extra, "extra on the destination"), kind(d.missing, "missing on the destination"), kind(d.changed, "changed")].join(", ") +
+ (mtime ? `, and ${mtime}` : "")
+ );
}
// A verify that the second mirror pass did not settle. Carries the differences
@@ -590,11 +601,14 @@ export async function copyMirrorVerify(opts: {
if (opts.reconcile) {
const before = await diffTrees({ rsyncBin, src, dest, log, signal });
log(
- countDifferences(before) === 0
- ? "Reconciling: the destination copy already matches the source."
- : `Reconciling: the destination copy differs from the source — ` +
+ countContentDifferences(before) > 0
+ ? `Reconciling: the destination copy differs from the source — ` +
`${describeDifferences(before)}. The mirror pass makes it match ` +
- `the source; the source is not changed.`,
+ `the source; the source is not changed.`
+ : before.mtimeOnly.length > 0
+ ? `Reconciling: the destination copy's content already matches the source; ` +
+ `${describeMtimeOnly(before)}, which the mirror pass settles. The source is not changed.`
+ : "Reconciling: the destination copy already matches the source.",
);
} else {
const { exitCode } = await rsyncTree({
@@ -769,6 +783,7 @@ async function verifyMirrored(opts: {
...differences.extra,
...differences.missing,
...differences.changed,
+ ...differences.mtimeOnly,
][0];
throw new CopyVerificationError(
`Verification failed: after a second mirror pass the copy still differs ` +
diff --git a/mcp/src/generation.test.ts b/mcp/src/generation.test.ts
@@ -8,6 +8,7 @@ import {
generateTool,
generationPolicyTool,
planGeneration,
+ renderIterationSummary,
resultMarkerOf,
validateGenerateArgs,
} from "./generation";
@@ -336,6 +337,26 @@ test("generate: a media draft is a step on its iteration, routed like any task;
assert.match(code.text, /youtube is routed to Claude Code/);
});
+test("a media draft's answer puts its video project first, above the iteration's files (release 29 D1); any other task's keeps it under them", () => {
+ const iteration = {
+ n: 3,
+ kind: "sweep",
+ model: "qwen3:8b",
+ status: "done",
+ usage: {},
+ steps: [{ task: "social", model: "qwen3:8b", status: "done", jobId: "job-9", detail: "2 social posts drafted" }],
+ projectDir: "/srv/projects/synth-a/i3",
+ };
+ const files = { "sweep.md": "/srv/reports/synth-a/iterations/3/sweep.md", "report.json": "/srv/reports/synth-a/iterations/3/report.json" };
+ const step = renderIterationSummary({ task: "social", article: "synth-a", jobId: "job-9", marker: null, iteration: iteration as never, dir: "/srv/reports/synth-a/iterations/3", files }).split("\n");
+ assert.match(step[0]!, /^generate: social of synth-a i3 — \*\*done\*\*/);
+ assert.equal(step[1], "Video project: /srv/projects/synth-a/i3");
+ assert.equal(step.filter((l) => l.startsWith("Video project:")).length, 1);
+ assert.ok(step.indexOf("Where (the editor's disk): /srv/reports/synth-a/iterations/3") > 1);
+ const revise = renderIterationSummary({ task: "revise-video", article: "synth-a", jobId: "job-8", marker: null, iteration: { ...iteration, kind: "revise-video", steps: [] } as never, dir: "/srv/reports/synth-a/iterations/3", files }).split("\n");
+ assert.ok(revise.indexOf("Video project: /srv/projects/synth-a/i3") > revise.indexOf("Where (the editor's disk): /srv/reports/synth-a/iterations/3"));
+});
+
test("resultMarkerOf reads the job's @@report-draft line", () => {
assert.deepEqual(resultMarkerOf(["x", '@@report-draft {"article":"a","iteration":2}', "y"]), { article: "a", iteration: 2 });
assert.equal(resultMarkerOf(["nothing here"]), null);
diff --git a/mcp/src/generation.ts b/mcp/src/generation.ts
@@ -394,6 +394,10 @@ export function renderIterationSummary(
const status = step?.status ?? o.marker?.status ?? it.status;
const lines: string[] = [];
lines.push(`generate: ${o.task} of ${o.article} i${it.n} — **${status}** on ${step?.model ?? it.model} (job ${o.jobId})`);
+ // A media draft's work is the video project's (release 29 D1): it comes
+ // first, above the iteration's own files.
+ const projectFirst = isStepTask(o.task) && !!it.projectDir;
+ if (projectFirst) lines.push(`Video project: ${it.projectDir}`);
if (o.marker?.summary) lines.push(o.marker.summary);
if (it.error && status !== "done") lines.push(`error: ${it.error}`);
if (step?.detail) lines.push(`${o.task === "narrate" ? "narration" : o.task}: ${step.detail}`);
@@ -423,7 +427,7 @@ export function renderIterationSummary(
lines.push(`Where (the editor's disk): ${o.dir}`);
for (const [name, p] of present) if (name !== "turns.jsonl" && name !== "trace.jsonl") lines.push(` - ${name}: ${p}`);
}
- if (it.projectDir) lines.push(`Video project: ${it.projectDir}`);
+ if (it.projectDir && !projectFirst) lines.push(`Video project: ${it.projectDir}`);
if (it.kind === "research") {
const r = it.research ?? {};
lines.push(`Research: phase ${r.phase ?? "?"}, autonomy ${r.autonomy ?? "?"}${r.continuedBy ? `, continued by i${r.continuedBy}` : ""}`);
diff --git a/scripts/queue-lock.test.mjs b/scripts/queue-lock.test.mjs
@@ -145,7 +145,9 @@ test("serves waiters in arrival order (FIFO)", async () => {
// Each arrival waits until the one before it is in line: the first holds
// (its holder.json is written), the next two have printed their banner and
// had a moment to block in flock. A fixed stagger raced a loaded machine.
- const first = startLock(["--", ...markerCmd(log, "1", 600)], env);
+ // The first holds until both are in line (release 29 D1: a gate, not 600 ms).
+ const gate = path.join(dir, "gate-1");
+ const first = startLock(["--", ...gateCmd(log, "1", gate)], env);
await until(() => fs.existsSync(`${lock}.holder.json`));
const runs = [first.done];
for (const id of ["2", "3"]) {
@@ -154,6 +156,7 @@ test("serves waiters in arrival order (FIFO)", async () => {
await delay(150);
runs.push(r.done);
}
+ openGate(gate);
await Promise.all(runs);
assert.equal(fs.readFileSync(log, "utf8"), "S1E1S2E2S3E3");
@@ -164,9 +167,14 @@ test("prints a banner naming the holder while waiting", async () => {
const lock = path.join(dir, "q.lock");
const env = { E2E_QUEUE_LOCK_FILE: lock };
- const first = runLock(["--", process.execPath, "-e", "setTimeout(()=>{},600)"], env);
+ // The first holds until the second has said it waits (a gate, not 600 ms).
+ const gate = path.join(dir, "gate");
+ const first = runLock(["--", ...gateCmd(path.join(dir, "first.log"), "1", gate)], env);
await until(() => fs.existsSync(`${lock}.holder.json`));
- const second = await runLock(["--", process.execPath, "-e", "0"], env);
+ const waiting = startLock(["--", process.execPath, "-e", "0"], env);
+ await waiting.waitFor(/waiting for the e2e queue/);
+ openGate(gate);
+ const second = await waiting.done;
await first;
assert.equal(second.code, 0);
@@ -180,21 +188,23 @@ test("QUEUE_LOCK_HELD passes straight through without deadlocking", async () =>
const lock = path.join(dir, "q.lock");
const env = { E2E_QUEUE_LOCK_FILE: lock };
- // Hold the lock for a good while, then prove a nested invocation (the shape
- // of root `pnpm e2e` -> `pnpm --filter editor run e2e`) does not wait for it.
- const held = runLock(["--", process.execPath, "-e", "setTimeout(()=>{},1500)"], env);
- await delay(300);
+ // Hold the lock until the nested run is over, then prove a nested
+ // invocation (the shape of root `pnpm e2e` -> `pnpm --filter editor run
+ // e2e`) does not wait for it: it finishes while the lock is still held — a
+ // gate, not a 1500 ms hold and a 1000 ms stopwatch (release 29 D1).
+ const gate = path.join(dir, "gate");
+ const held = runLock(["--", ...gateCmd(path.join(dir, "held.log"), "h", gate)], env);
+ await until(() => fs.existsSync(`${lock}.holder.json`));
- const t0 = Date.now();
const nested = await runLock(["--", process.execPath, "-e", "0"], {
...env,
QUEUE_LOCK_HELD: "e2e",
});
- const elapsed = Date.now() - t0;
assert.equal(nested.code, 0);
- assert.ok(elapsed < 1000, `nested run waited ${elapsed}ms — it deadlocked on its parent's lock`);
+ assert.ok(fs.existsSync(`${lock}.holder.json`), "the nested run finished while its parent's lock was held");
assert.doesNotMatch(nested.stderr, /waiting for the e2e queue/);
+ openGate(gate);
await held;
});
@@ -203,13 +213,15 @@ test("E2E_QUEUE=0 bypasses the queue entirely", async () => {
const lock = path.join(dir, "q.lock");
const env = { E2E_QUEUE_LOCK_FILE: lock };
- const held = runLock(["--", process.execPath, "-e", "setTimeout(()=>{},1500)"], env);
- await delay(300);
+ const gate = path.join(dir, "gate");
+ const held = runLock(["--", ...gateCmd(path.join(dir, "held.log"), "h", gate)], env);
+ await until(() => fs.existsSync(`${lock}.holder.json`));
- const t0 = Date.now();
const bypass = await runLock(["--", process.execPath, "-e", "0"], { ...env, E2E_QUEUE: "0" });
assert.equal(bypass.code, 0);
- assert.ok(Date.now() - t0 < 1000, "E2E_QUEUE=0 still waited for the lock");
+ assert.ok(fs.existsSync(`${lock}.holder.json`), "E2E_QUEUE=0 still waited for the lock");
+ assert.doesNotMatch(bypass.stderr, /waiting for the e2e queue/);
+ openGate(gate);
await held;
});
@@ -223,7 +235,7 @@ test("a SIGKILLed run releases the lock immediately", async () => {
[SCRIPT, "--", process.execPath, "-e", "setTimeout(()=>{},30000)"],
{ env, stdio: "ignore" },
);
- await delay(500); // let it acquire
+ await until(() => fs.existsSync(`${lock}.holder.json`)); // it has acquired
victim.kill("SIGKILL");
await new Promise((r) => victim.on("exit", r));
@@ -413,9 +425,13 @@ test("two heavy contenders run one at a time; the second names what it waits beh
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir);
- const first = startLock(["--heavy", "--", ...markerCmd(log, "1", 600)], env);
+ const gate = path.join(dir, "gate");
+ const first = startLock(["--heavy", "--", ...gateCmd(log, "1", gate)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.holder.json`));
- const second = await runLock(["--heavy", "--", ...markerCmd(log, "2", 50)], env);
+ const waiting = startLock(["--heavy", "--", ...markerCmd(log, "2", 50)], env);
+ await waiting.waitFor(/waiting for the heavy slot/);
+ openGate(gate);
+ const second = await waiting.done;
assert.equal((await first.done).code, 0);
assert.equal(second.code, 0);
assert.equal(fs.readFileSync(log, "utf8"), "S1E1S2E2");
@@ -427,9 +443,13 @@ test("an e2e run takes the heavy slot too: it waits for a heavy job, then runs",
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir, { E2E_QUEUE_LOCK_FILE: path.join(dir, "q.lock") });
- const build = startLock(["--heavy", "--", ...markerCmd(log, "b", 600)], env);
+ const gate = path.join(dir, "gate");
+ const build = startLock(["--heavy", "--", ...gateCmd(log, "b", gate)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.holder.json`));
- const e2e = await runLock(["--", ...markerCmd(log, "e", 50)], env);
+ const waiting = startLock(["--", ...markerCmd(log, "e", 50)], env);
+ await waiting.waitFor(/waiting for the heavy slot/);
+ openGate(gate);
+ const e2e = await waiting.done;
await build.done;
assert.equal(e2e.code, 0);
assert.equal(fs.readFileSync(log, "utf8"), "SbEbSeEe");
@@ -682,9 +702,13 @@ test("two builds never overlap, whatever the memory; the second waits for the bu
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir);
- const first = startLock(["--heavy", "--build", "--estimate", "100", "--", ...markerCmd(log, "1", 600)], env);
+ const gate = path.join(dir, "gate");
+ const first = startLock(["--heavy", "--build", "--estimate", "100", "--", ...gateCmd(log, "1", gate)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.build.holder.json`));
- const second = await runLock(["--heavy", "--build", "--estimate", "100", "--", ...markerCmd(log, "2", 50)], env);
+ const waiting = startLock(["--heavy", "--build", "--estimate", "100", "--", ...markerCmd(log, "2", 50)], env);
+ await waiting.waitFor(/waiting for the build slot/);
+ openGate(gate);
+ const second = await waiting.done;
assert.equal((await first.done).code, 0);
assert.equal(second.code, 0, second.stderr);
assert.equal(fs.readFileSync(log, "utf8"), "S1E1S2E2");
@@ -695,11 +719,18 @@ test("an undeclared job runs alone: it waits for the weighted ones, and none sta
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir);
- const weighted = startLock(["--heavy", "--estimate", "100", "--", ...markerCmd(log, "w", 600)], env);
+ const gateW = path.join(dir, "gate-w");
+ const gateX = path.join(dir, "gate-x");
+ const weighted = startLock(["--heavy", "--estimate", "100", "--", ...gateCmd(log, "w", gateW)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.jobs`) && fs.readdirSync(`${env.HEAVY_LOCK_FILE}.jobs`).length > 0);
- const alone = startLock(["--heavy", "--", ...markerCmd(log, "x", 600)], env);
+ const alone = startLock(["--heavy", "--", ...gateCmd(log, "x", gateX)], env);
await alone.waitFor(/waiting for the heavy slot — held by .*pid \d+, 100 MB/);
+ openGate(gateW);
+ // `alone` has started (its S is in the log) before `later` asks: none starts beside it.
+ await until(() => fs.readFileSync(log, "utf8").includes("Sx"));
const later = startLock(["--heavy", "--estimate", "100", "--", ...markerCmd(log, "l", 50)], env);
+ await later.waitFor(/waiting for the heavy slot/);
+ openGate(gateX);
for (const r of await Promise.all([weighted.done, alone.done, later.done])) assert.equal(r.code, 0, r.stderr);
assert.equal(fs.readFileSync(log, "utf8"), "SwEwSxExSlEl");
});
@@ -708,10 +739,14 @@ test("a build nested in an admitted run waits for the build slot (one build at a
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir);
- const outer = startLock(["--heavy", "--build", "--estimate", "100", "--", ...markerCmd(log, "1", 700)], env);
+ const gate = path.join(dir, "gate");
+ const outer = startLock(["--heavy", "--build", "--estimate", "100", "--", ...gateCmd(log, "1", gate)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.build.holder.json`));
// The shape of an e2e config's rebuild inside a running suite: HEAVY_HELD set.
- const nested = await runLock(["--heavy", "--build", "--", ...markerCmd(log, "2", 50)], { ...env, HEAVY_HELD: "1" });
+ const waiting = startLock(["--heavy", "--build", "--", ...markerCmd(log, "2", 50)], { ...env, HEAVY_HELD: "1" });
+ await waiting.waitFor(/waiting for the build slot/);
+ openGate(gate);
+ const nested = await waiting.done;
assert.equal(nested.code, 0, nested.stderr);
await outer.done;
assert.equal(fs.readFileSync(log, "utf8"), "S1E1S2E2");
@@ -732,15 +767,18 @@ test("named suites run side by side; the same suite never runs twice", async ()
const dir = tmpDir();
const log = path.join(dir, "order.log");
const env = heavyEnv(dir, { E2E_QUEUE_LOCK_FILE: path.join(dir, "q.lock") });
- const suite = (name, id, ms) =>
- startLock(["--name", name, "--estimate", "100", "--", ...markerCmd(log, id, ms)], env);
- const a = suite("e2e-editor", "a", 900);
+ // a and b hold until the second editor run has said it waits: their overlap
+ // and its wait are the gate's, not a 900 ms hold's (release 29 D1).
+ const gate = path.join(dir, "gate-ab");
+ const held = (name, id) => startLock(["--name", name, "--estimate", "100", "--", ...gateCmd(log, id, gate)], env);
+ const a = held("e2e-editor", "a");
await until(() => fs.existsSync(path.join(dir, "q.lock.e2e-editor.holder.json")));
- const b = suite("e2e-umtool", "b", 900);
+ const b = held("e2e-umtool", "b");
const order = () => (fs.existsSync(log) ? fs.readFileSync(log, "utf8") : "");
- await until(() => order().includes("Sb") || order().includes("Ea"));
- const again = suite("e2e-editor", "c", 50);
+ await until(() => order().includes("Sb"));
+ const again = startLock(["--name", "e2e-editor", "--estimate", "100", "--", ...markerCmd(log, "c", 50)], env);
await again.waitFor(/waiting for the e2e queue — held by .*pid \d+/);
+ openGate(gate);
for (const r of await Promise.all([a.done, b.done, again.done])) assert.equal(r.code, 0, r.stderr);
const ran = order();
assert.ok(overlapped(ran), `editor and umtool did not overlap: ${ran}`);
@@ -784,7 +822,8 @@ test("--prebuild ensures the suite's build before its admission, and the config
test("a waiter stopped by SIGTERM leaves no holder file behind", async () => {
const dir = tmpDir();
const env = heavyEnv(dir);
- const first = startLock(["--heavy", "--", process.execPath, "-e", "setTimeout(()=>{},1500)"], env);
+ const gate = path.join(dir, "gate");
+ const first = startLock(["--heavy", "--", ...gateCmd(path.join(dir, "first.log"), "1", gate)], env);
await until(() => fs.existsSync(`${env.HEAVY_LOCK_FILE}.holder.json`));
const waiter = startLock(["--heavy", "--", "true"], env);
await waiter.waitFor(/waiting for the heavy slot/);
@@ -793,6 +832,7 @@ test("a waiter stopped by SIGTERM leaves no holder file behind", async () => {
const res = await waiter.done;
assert.equal(res.code, 128 + os.constants.signals.SIGTERM);
assert.equal(fs.existsSync(`${env.HEAVY_LOCK_FILE}.admit.holder.json`), false);
+ openGate(gate);
assert.equal((await first.done).code, 0);
});
@@ -805,11 +845,13 @@ test("--scale-by: an estimate per worker, times the editor suite's E2E_WORKERS",
const dir = tmpDir();
const env = heavyEnv(dir, { E2E_QUEUE_LOCK_FILE: path.join(dir, "q.lock"), E2E_WORKERS: "3" });
const jobs = path.join(dir, "heavy.lock.jobs");
- const cmd = [process.execPath, "-e", "setTimeout(()=>{},400)"];
- const run = startLock(["--name", "e2e-x", "--estimate", "1500", "--scale-by", "E2E_WORKERS", "--", ...cmd], env);
+ // Held until its ticket is read (a gate, not 400 ms).
+ const gate = path.join(dir, "gate");
+ const run = startLock(["--name", "e2e-x", "--estimate", "1500", "--scale-by", "E2E_WORKERS", "--", ...gateCmd(path.join(dir, "x.log"), "x", gate)], env);
await until(() => fs.existsSync(jobs) && fs.readdirSync(jobs).some((n) => n.endsWith(".json")));
const ticket = JSON.parse(fs.readFileSync(path.join(jobs, fs.readdirSync(jobs).find((n) => n.endsWith(".json"))), "utf8"));
assert.equal(ticket.estimateMb, 4500);
+ openGate(gate);
assert.equal((await run.done).code, 0);
});