test(harness,plugins,conversation,cli): pi-fit-tmp re-check round: stand-in pis are built outside /tmp whatever the temp directory is, since the fit check now stays undecided for a pi under /tmp; the new fixtureDir(prefix) in pi-stand-in.mjs makes the directory under tmpdir() unless its real path is under /tmp, else under /var/tmp; every stand-in root in the harness, plugins, conversation and cli tests goes through it (harness-watch's piPackage gets its own root, its watch scratch stays under tmpdir() for the W1 redaction test); with TMPDIR unset pi-fit went 13/75 to 88/0 and claim 9/24 to 33/0; the guard's test gains a pi with only a root under /tmp; sessionCovers' comment sits above it, not above ended's

This commit is contained in:
jason.woltje committed 2026-11-20 12:37:08 -06:00
1 parent e698b7d785
commit 735e828aa2
10 files changed
+52 -28

No files matched your search

+7 -3
View File
@@ -25,7 +25,7 @@ import { bootConfig, loadSystem } from "../src/config.mjs";
import { cmdlineOf, startHost, startTimeOf } from "../src/host.mjs";
import { createLauncher } from "../src/launcher.mjs";
import { mockAnthropic, REPO } from "../../harness/tests/helpers.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import * as pi from "../../plugins/harness/pi/index.mjs";
import { fakeHarnesses, fixture, HOST_CREDENTIALS, tmp, withoutHostCredentials } from "./helpers.mjs";
@@ -82,7 +82,9 @@ function commit(dir, text) {
// Every credential variable of the shell running the tests is dropped, pi's own provider keys
// included (row 332 R2); a pi chief gets one made-up pi key instead.
function prepare(t, more = (doc) => doc) {
const root = tmp(t, "mosaic-launch-");
// pi-fit-tmp re-check: its pi stand-ins sit under root, which must not be under /tmp.
const root = fixtureDir("mosaic-launch-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const f = fixture(root, "acme", (doc) => more(edit(doc)));
withoutHostCredentials(f.env, { piKey: f.doc.roles.chief.vars.harness === "pi" || f.doc.roles.chief.vars["fallback.harness"] === "pi" });
f.env.CLAUDE_CODE_OAUTH_TOKEN = "stand-in";
@@ -332,7 +334,9 @@ function busPiBin(t, prepared, bin) {
test("pi-unpin re-check 8: the launcher starts pi's fit check when it starts, and the first launch joins it", { skip, timeout: 60000 }, async (t) => {
const { made, quiet } = fitRuns(t);
// One check on its own, for another stand-in: how many runs it makes.
const alone = piPrefix(tmp(t, "mosaic-launch-pi-"), {});
const aloneRoot = fixtureDir("mosaic-launch-pi-");
t.after(() => rmSync(aloneRoot, { recursive: true, force: true }));
const alone = piPrefix(aloneRoot, {});
await quiet();
made.clear();
assert.equal(await pi.preflight({ env: { ANTHROPIC_API_KEY: "stand-in", MOSAIC_PI_BIN: alone } }), null);
+3 -3
View File
@@ -12,7 +12,7 @@ import { tmpdir } from "node:os";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { sandboxProblem } from "../../seat/src/sandbox.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
const REPO = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
const missing = (e) => { if (e.code !== "ERR_MODULE_NOT_FOUND") throw e; return {}; };
@@ -31,7 +31,7 @@ const lockOf = (version) => ({ name: "fixture", lockfileVersion: 3, requires: tr
// A checkout with package.json's range, a lock that resolves `version`, and RELEASE.
function checkout(t, { version = "9.9.9", release = "0.0.13" } = {}) {
const root = mkdtempSync(join(tmpdir(), "s5-"));
const root = fixtureDir("s5-");
t.after(() => rmSync(root, { recursive: true, force: true }));
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "fixture", dependencies: { [NAME]: RANGE } }));
writeFileSync(join(root, "package-lock.json"), JSON.stringify(lockOf(version)));
@@ -267,7 +267,7 @@ test("pi-unpin S5: the image fit step can't tell, and refuses, when node_modules
// scripts/agent-host-dev.sh --check in a checkout with the range in package.json and a stand-in pi.
function hostCheckout(t, piScript) {
const root = mkdtempSync(join(tmpdir(), "s5h-"));
const root = fixtureDir("s5h-");
t.after(() => rmSync(root, { recursive: true, force: true }));
for (const d of ["scripts", "agents/fixture", "contracts", "user", "node_modules/.bin", "extensions/goal"]) mkdirSync(join(root, d), { recursive: true });
cpSync(join(REPO, "scripts/agent-host-dev.sh"), join(root, "scripts/agent-host-dev.sh"));
+2 -2
View File
@@ -11,7 +11,7 @@ import { ConversationClient } from "../src/client.mjs";
import { AUTHORITY } from "../src/cohort.mjs";
import { FixtureVerifier } from "../src/records.mjs";
import { FakeLauncher } from "./fake-pi.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { locate } from "../../plugins/harness/pi/binary.mjs";
export const REPO = resolve(import.meta.dirname, "..", "..", "..");
@@ -19,7 +19,7 @@ export const SESSION_ID = "0f5e1c2a-1111-4222-8333-944455556666";
export const FAST = Object.freeze({ ack: 1500, state: 1500, start: 1500, clear: 1500, abort: 3000, settle: 3000, grace: 50, write: 1500, maxRounds: 3 });
export const time = (i) => new Date(Date.UTC(2026, 9, 4, 12, 0, 0) + i * 1000).toISOString();
const tmp = mkdtempSync(join(tmpdir(), "chat03-"));
const tmp = fixtureDir("chat03-");
let serial = 0;
// #1873 S4: a stand-in pi package (packages/harness/tests/pi-stand-in.mjs,
+3 -3
View File
@@ -755,13 +755,13 @@ function spawned(argv, { input, timeout, signal }) {
});
}
// pi-fit-tmp: how a run ended, for a line that must say enough to diagnose: why the check killed
// it, else the signal that ended it, else its exit status. Never its output, which can name a host
// path.
// A path a session's private /tmp covers: /tmp itself or under it, by its spelling (what the
// session's bind names as its target).
const sessionCovers = (p) => typeof p === "string" && /^\/+tmp(\/|$)/.test(posix.normalize(p));
// pi-fit-tmp: how a run ended, for a line that must say enough to diagnose: why the check killed
// it, else the signal that ended it, else its exit status. Never its output, which can name a host
// path.
function ended(r) {
if (r.stopped) return r.stopped;
if (typeof r.signal === "string") return `ended by ${r.signal}`;
+10 -9
View File
@@ -10,7 +10,7 @@ import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import * as fitModule from "../src/pi-fit.mjs";
import { piStandIn } from "./pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "./pi-stand-in.mjs";
import { locate } from "../../plugins/harness/pi/binary.mjs";
import * as pi from "../../plugins/harness/pi/index.mjs";
import { BWRAP, UNSHARE, checkArgv, mountOrder, sandboxProblem, sessionSetenv } from "../../seat/src/sandbox.mjs";
@@ -29,7 +29,7 @@ const SKIP = sandboxProblem() ? { skip: "no working bwrap here" } : {};
// bin), named by MOSAIC_PI_BIN. Returns the env that names it and the paths a refusal must not
// carry.
function standIn(t, knobs, version = "2.0.0") {
const root = mkdtempSync(join(tmpdir(), "mosaic-pi-fit-t-"));
const root = fixtureDir("mosaic-pi-fit-t-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const pkg = join(root, "prefix", "lib", "node_modules", NAME);
mkdirSync(join(pkg, "dist", "bundle"), { recursive: true });
@@ -604,7 +604,7 @@ const procsNaming = (text) => readdirSync("/proc").filter((p) => /^\d+$/.test(p)
try { return readFileSync(`/proc/${p}/cmdline`, "utf8").includes(text); } catch { return false; }
});
test("pi-unpin S3 re-check 9: a fit check killed with its process leaves no process, and the next check removes its scratch", SKIP, async t => {
const dir = mkdtempSync(join(tmpdir(), "mosaic-pi-fit-t-"));
const dir = fixtureDir("mosaic-pi-fit-t-");
t.after(() => {
for (const p of procsNaming(dir)) try { process.kill(Number(p), "SIGKILL"); } catch {}
rmSync(dir, { recursive: true, force: true });
@@ -711,7 +711,7 @@ test("pi-unpin S3 re-check 10: bwrap's command line is the same with and without
// nothing. The child sees the host through an outer bwrap; for the missing case /usr/bin is a tmpfs
// with only the tools a check runs bound back.
test("pi-unpin S3 re-check 10: with an unshare that is refused or missing, real pi passes the fit check and no launch is refused", SKIP, async t => {
const dir = mkdtempSync(join(tmpdir(), "mosaic-pi-fit-t-"));
const dir = fixtureDir("mosaic-pi-fit-t-");
t.after(() => rmSync(dir, { recursive: true, force: true }));
const refusing = join(dir, "refusing-unshare");
writeFileSync(refusing, `#!/bin/sh\necho "unshare: write failed /proc/self/uid_map: Operation not permitted" >&2\nexit 1\n`, { mode: 0o755 });
@@ -766,7 +766,7 @@ test("pi-unpin S3 re-check 10: a failed probe names the tool that failed, and on
// is killed while runs are under way. The next check, in another process, must stop what the
// killed one left and remove its scratch, checked by command line.
test("pi-unpin S3 re-check 10: without unshare, a check killed with its process leaves nothing once the next check has run", SKIP, async t => {
const dir = mkdtempSync(join(tmpdir(), "mosaic-pi-fit-t-"));
const dir = fixtureDir("mosaic-pi-fit-t-");
t.after(() => {
for (const p of procsNaming(dir)) try { process.kill(Number(p), "SIGKILL"); } catch {}
rmSync(dir, { recursive: true, force: true });
@@ -847,7 +847,7 @@ exit $st
// stale directory's name, and one naming a directory from another pid namespace are left alone, and
// so are those directories.
test("pi-unpin S3 re-check 10: the sweep leaves a live owner's processes and another directory's processes alone", SKIP, async t => {
const dir = mkdtempSync(join(tmpdir(), "mosaic-pi-fit-t-"));
const dir = fixtureDir("mosaic-pi-fit-t-");
const kids = [];
t.after(() => {
for (const k of kids) try { k.kill("SIGKILL"); } catch {}
@@ -913,7 +913,7 @@ test("pi-unpin S3: real pi 0.85.1 from node_modules is accepted, and the event l
// directories: it lists both given skills and no planted one. A logging bwrap shows the run.
test("pi-skills: real pi 0.85.1 passes the fit check's worker-shaped run with --no-skills and two --skill directories", SKIP, async t => {
const found = locate({ PATH: "/usr/bin:/bin" });
const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-fit-"));
const root = fixtureDir("mosaic-pi-skills-fit-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const log = join(root, "bwrap.log");
const bwrap = join(root, "bwrap");
@@ -1105,6 +1105,7 @@ test("pi-fit-tmp: a pi mounted under /tmp, or a node there, can't be checked, si
writeFileSync(bwrap, `#!/bin/sh\necho x >> '${ran}'\nexec '${BWRAP}' "$@"\n`, { mode: 0o755 });
const found = locate(s.env);
const cases = [
[{ ...found, dest: null, root: "/tmp/mosaic-fit-root" }, {}, "the pi's package"],
[{ ...found, dest: "/tmp/mosaic-fit-dest" }, {}, "the pi's package"],
[{ ...found, dest: "//tmp" }, {}, "the pi's package"],
[found, { node: "/tmp/mosaic-fit-node" }, "node"],
@@ -1144,7 +1145,7 @@ test("pi-unpin S3: the adapter passes --no-mcp only when the module asks for it"
// pi-skills: a worker's MOSAIC_SKILLS. pi 0.85.1 adds a --skill directory to discovery, so the
// adapter keeps --no-skills and puts each --skill after it. A stub records the argv.
const workerAdapter = (t, extra = {}) => {
const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-t-"));
const root = fixtureDir("mosaic-pi-skills-t-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const stub = join(root, "pi");
writeFileSync(stub, '#!/bin/sh\nprintf "%s\\0" "$@" > "$ARGV_OUT"\n', { mode: 0o755 });
@@ -1204,7 +1205,7 @@ const UNSHARE_NET = spawnSync("unshare", ["-rn", "true"]).status === 0 ? {} : {
test("pi-skills: real pi 0.85.1 through the adapter with MOSAIC_SKILLS loads the given skills and no planted one", UNSHARE_NET, async t => {
const found = locate({ PATH: "/usr/bin:/bin" });
assert.equal(found.label, "the repository's pi");
const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-real-"));
const root = fixtureDir("mosaic-pi-skills-real-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const put = (p, text) => { mkdirSync(dirname(p), { recursive: true }); writeFileSync(p, text); };
const skill = (name) => put(join(root, ...name.split("/"), "SKILL.md"), `---\nname: ${name.split("/").pop()}\ndescription: a planted skill\n---\nA planted skill.\n`);
+17
View File
@@ -84,6 +84,23 @@
// APPEND_SYSTEM.md is appended whatever the flags, as 0.85.1 does when the project has none.
import { FIT_FLAGS } from "../src/pi-fit.mjs";
import { FIT_MODEL_ROUTE } from "../../plugins/harness/pi/session-env.mjs";
import { mkdtempSync, realpathSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
// pi-fit-tmp re-check: a new directory for a test's stand-in pi, made like
// mkdtempSync(join(tmpdir(), prefix)). The fit check is undecided for a pi under /tmp, since a
// session's sandbox mounts its private /tmp over it, so a stand-in must not sit there. When the
// temp directory's real path is under /tmp (TMPDIR unset, say), the directory goes under /var/tmp
// instead; otherwise it goes under tmpdir() as spelled, so a run with TMPDIR elsewhere is unchanged.
const underTmp = (p) => /^\/tmp(\/|$)/.test(p);
export function fixtureDir(prefix) {
let base = tmpdir();
try {
if (underTmp(realpathSync(base)) && !underTmp(realpathSync("/var/tmp"))) base = "/var/tmp";
} catch {}
return mkdtempSync(join(base, prefix));
}
const BODY = String.raw`
const fs = require("node:fs");
@@ -11,7 +11,7 @@ import { join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { tree } from "./helpers.mjs";
import { KINDS } from "../src/kinds.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { piFit } from "../../harness/src/pi-fit.mjs";
import { sandboxProblem, UNSHARE } from "../../seat/src/sandbox.mjs";
import * as pi from "../harness/pi/index.mjs";
@@ -27,7 +27,7 @@ const CREDENTIAL = { ANTHROPIC_API_KEY: "fixture-api-key" };
const DIGEST = /^[a-f0-9]{64}$/;
function scratch(t) {
const root = mkdtempSync(join(tmpdir(), "mosaic-watch-"));
const root = fixtureDir("mosaic-watch-");
t.after(() => rmSync(root, { recursive: true, force: true }));
return root;
}
@@ -11,7 +11,7 @@ import { join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { tree } from "./helpers.mjs";
import { KINDS } from "../src/kinds.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { sandboxProblem } from "../../seat/src/sandbox.mjs";
import * as pi from "../harness/pi/index.mjs";
import * as claude from "../harness/claude-code/index.mjs";
@@ -289,7 +289,9 @@ test("W1 real pi from node_modules gives a version, a digest and fit pass", NO_B
// A stand-in pi package named by MOSAIC_PI_BIN, as pi-fit.test.mjs makes one.
function piPackage(t, knobs) {
const root = scratch(t);
// Outside /tmp, so the fit check runs it whatever the temp directory is (pi-stand-in.mjs).
const root = fixtureDir("mosaic-watch-pi-");
t.after(() => rmSync(root, { recursive: true, force: true }));
const pkg = join(root, "prefix", "lib", "node_modules", PI_NAME);
mkdirSync(join(pkg, "dist", "bundle"), { recursive: true });
writeFileSync(join(pkg, "package.json"), JSON.stringify({ name: PI_NAME, version: "2.0.0", bin: { pi: "dist/bundle/cli.js" } }));
+2 -2
View File
@@ -10,7 +10,7 @@ import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process";
import { createLoader } from "../src/loader.mjs";
import { KINDS } from "../src/kinds.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
const REPO = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
@@ -25,7 +25,7 @@ async function load(name) {
}
function scratch(t) {
const root = mkdtempSync(join(tmpdir(), "mosaic-harness-plugin-"));
const root = fixtureDir("mosaic-harness-plugin-");
t.after(() => rmSync(root, { recursive: true, force: true }));
return root;
}
+2 -2
View File
@@ -9,14 +9,14 @@ import { dirname, join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { spawnSync } from "node:child_process";
import { sandboxProblem } from "../../seat/src/sandbox.mjs";
import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
import { fixtureDir, piStandIn } from "../../harness/tests/pi-stand-in.mjs";
const REPO = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
const MODULE = join(REPO, "packages", "plugins", "harness", "pi");
const NAME = "@earendil-works/pi-coding-agent";
function scratch(t) {
const root = mkdtempSync(join(tmpdir(), "mosaic-pi-bin-"));
const root = fixtureDir("mosaic-pi-bin-");
t.after(() => rmSync(root, { recursive: true, force: true }));
return root;
}