fix(agents): A3 excluded checkouts hidden, launch boundary rechecks unions, reload collisions and changed defines refuse (#1873)
- A checkout an earlier launch left for a project the instance may no longer work in is covered by an empty tmpfs inside the sandbox; the host copy stays. - The launcher rechecks every prepared project against the reloaded document after preparation, and the bus's final admission takes the instance and checks the broker's current unions. - A project define whose vars changed since boot refuses its copy until the next start. - Instance-name collisions are recomputed at each reload from the frozen root claims and the current project defines; every claimant refuses.
This commit is contained in:
1 parent
17a48217f6
commit
29f7c3af85
9 files changed
+252
-16
No files matched your search
@@ -1220,6 +1220,11 @@ export class Broker {
|
||||
this.#businesses[name] = next;
|
||||
this.#scheduleRequests();
|
||||
}
|
||||
// #1873 A3: host-only, for the launch boundary's admission: the code that refuses `instance` in code
|
||||
// project `repo` under the business's current document (the one the last reload swapped in), or null.
|
||||
projectBarred(business, instance, repo) {
|
||||
return this.#projectRefused(this.#business(business), instance, repo)?.code ?? null;
|
||||
}
|
||||
// Host-only current role resolver shared by the broker and built-in task tracker.
|
||||
taskRoles(business) {
|
||||
const roles = this.#business(business).roles;
|
||||
|
||||
@@ -88,7 +88,7 @@ function launchOp(m) {
|
||||
if (m.op === 'request.release') return runtime.requestRelease(m.cap, m.record);
|
||||
if (m.op === 'request.manifest') return runtime.requestManifest(m.record);
|
||||
if (m.op === 'request.chief') return runtime.requestChief(m.business);
|
||||
if (m.op === 'request.admission') return runtime.admission({ business: m.business, project: m.project, projects: m.projects, thread: m.thread, session: m.session });
|
||||
if (m.op === 'request.admission') return runtime.admission({ business: m.business, project: m.project, projects: m.projects, instance: m.instance, thread: m.thread, session: m.session });
|
||||
if (m.op === 'credentialStatus') return runtime.credentialStatus(m.business, m.role);
|
||||
if (m.op === 'modelAdmission') return runtime.modelAdmission(m);
|
||||
if (m.op === 'modelPreflight') return runtime.modelPreflight(m);
|
||||
|
||||
@@ -629,7 +629,9 @@ export async function startBroker({
|
||||
// product the broker holds is ready only while it has a complete marker and a committed activate receipt: the
|
||||
// answer is read from both on every call, so a marker removed after the activation closes it again, and the
|
||||
// broker's reload now follows both readiness records (#802).
|
||||
function admission({ business: id, project, projects, thread, session }) {
|
||||
// With `instance` (#1873 A3), the launch boundary also asks whether that instance may work in each
|
||||
// project as the business stands now: a project that excludes it, or whose union refuses, is not ready.
|
||||
function admission({ business: id, project, projects, instance, thread, session }) {
|
||||
if (projects !== undefined) {
|
||||
const no = code => ({ ready: false, revision: null, code });
|
||||
if (typeof id !== 'string' || !Object.hasOwn(businesses, id) || !Array.isArray(projects) || projects.some(p => typeof p !== 'string')) return no('project-unknown');
|
||||
@@ -638,9 +640,15 @@ export async function startBroker({
|
||||
if (!row) return no('session-not-found');
|
||||
if (row.archived) return no('project-archived');
|
||||
}
|
||||
if (instance !== undefined && typeof instance !== 'string') return no('project-unknown');
|
||||
for (const p of projects) {
|
||||
const result = admission({ business: id, project: p });
|
||||
if (!result.ready) return result;
|
||||
if (instance !== undefined) {
|
||||
// The broker holds the document the last writer reload swapped in; `businesses` is the boot one.
|
||||
const barred = broker.projectBarred(id, instance, p);
|
||||
if (barred) return no(barred);
|
||||
}
|
||||
}
|
||||
return { ready: true, revision: null, code: null };
|
||||
}
|
||||
|
||||
@@ -632,13 +632,15 @@ export function createLauncher({
|
||||
const codeProjects = {};
|
||||
// #1873 A3: an instance gets only the code projects it works in: a project agent its own one, and
|
||||
// no instance a project that excludes it or whose union refuses. A project agent refuses when its
|
||||
// own project isn't admitted.
|
||||
// own project isn't admitted. A checkout an earlier launch left in the workspace for a project
|
||||
// the instance may not work in now is hidden from the session, never deleted (sandbox.mjs).
|
||||
const own = copyOf(b, instance)?.project ?? null;
|
||||
const barred = [];
|
||||
for (const [project, entry] of Object.entries(b.projects)) {
|
||||
if (entry.kind === 'library') continue;
|
||||
if (own !== null && project !== own) continue;
|
||||
if (own !== null && project !== own) { barred.push(project); continue; }
|
||||
const unavailable = projectRefusal(b, instance, project);
|
||||
if (unavailable) { record({ event: "checkout-skipped", instance, project, reason: unavailable.code }); continue; }
|
||||
if (unavailable) { barred.push(project); record({ event: "checkout-skipped", instance, project, reason: unavailable.code }); continue; }
|
||||
let answer = null;
|
||||
try { answer = await host.op({ op: 'request.admission', business: b.id, project }); } catch (e) { answer = { ready: false, code: e.code ?? 'admission-unavailable' }; }
|
||||
if (answer?.ready !== true) { record({ event: "checkout-skipped", instance, project, reason: answer?.code ?? 'project-pending' }); continue; }
|
||||
@@ -671,6 +673,12 @@ export function createLauncher({
|
||||
let harness, route, routeReason, sessionProxy, resolver;
|
||||
({resolved,model,account,harness,route,routeReason,sessionProxy,resolver}=await check(instance,{pm:instance===b.launch.by,thread,session,human,proxyContext:admittedProxy,proxyReady:true}));
|
||||
admission(admissionGeneration);
|
||||
// #1873 A3: check() read the organization again. A project that excluded or refused this
|
||||
// instance while its checkouts were prepared refuses the launch; the next one leaves it out.
|
||||
for (const project of Object.keys(codeProjects)) {
|
||||
const unavailable = projectRefusal(b, instance, project);
|
||||
if (unavailable) throw new Refusal(unavailable.code, unavailable.message);
|
||||
}
|
||||
const { run, runDir } = newRun(dataRoot, b.id);
|
||||
let modelKeyId;
|
||||
if (admittedProxy) {
|
||||
@@ -766,6 +774,7 @@ export function createLauncher({
|
||||
gitSocket: git,
|
||||
threadStore: store,
|
||||
readOnly,
|
||||
hidden: barred.map((project) => join(workspace, project)).filter((p) => { try { return lstatSync(p).isDirectory(); } catch { return false; } }),
|
||||
};
|
||||
admission(admissionGeneration);
|
||||
await threadAdmission(thread, session);
|
||||
@@ -776,7 +785,7 @@ export function createLauncher({
|
||||
}
|
||||
// One synchronous broker snapshot covers the thread and the entire manifest after every
|
||||
// asynchronous preparation read. Admission is the launch boundary; bindLaunch remains a fence.
|
||||
const finalAdmission = await host.op({ op: "request.admission", business: b.id, projects: Object.keys(codeProjects), thread, session });
|
||||
const finalAdmission = await host.op({ op: "request.admission", business: b.id, projects: Object.keys(codeProjects), instance, thread, session });
|
||||
if (finalAdmission?.ready !== true) throw new Refusal(finalAdmission?.code ?? "project-pending");
|
||||
const managed = registerRuntime(dataRoot, { kind: 'session', business: b.id, run });
|
||||
let child;
|
||||
|
||||
@@ -270,6 +270,120 @@ test("A3: a project's exclude takes its mount from an inherited agent, and its n
|
||||
assert.deepEqual(skipped.map(({ instance, project, reason }) => ({ instance, project, reason })), [{ instance: "gate", project: "web", reason: "project-refused" }]);
|
||||
});
|
||||
|
||||
// Writes the organization file the way a human edit does, outside any writer verb.
|
||||
const editOrg = (p, change) => {
|
||||
const file = join(p.root, "config", "businesses", "acme.json");
|
||||
const doc = JSON.parse(readFileSync(file, "utf8"));
|
||||
change(doc);
|
||||
writeFileSync(file, JSON.stringify(doc, null, 2) + "\n", { mode: 0o600 });
|
||||
};
|
||||
// A writer verb reloads the broker from the file. Keeping coder twice changes nothing and refuses,
|
||||
// so a repeat reload drops the keep instead.
|
||||
const reload = (s) => {
|
||||
try { return s.call("veto.set", { revision: s.call("instances").revision, op: "keep", name: "coder" }); }
|
||||
catch (e) { if (e.code !== "organization-no-change") throw e; }
|
||||
return s.call("veto.set", { revision: s.call("instances").revision, op: "unkeep", name: "coder" });
|
||||
};
|
||||
// What the run's first turn said, from inside the real sandbox, about the web checkout.
|
||||
async function webSeen(s, run) {
|
||||
await until(() => existsSync(join(run.runDir, "runner.log")) && readFileSync(join(run.runDir, "runner.log"), "utf8").includes("claimed by run"));
|
||||
s.call("message.send", { to: run.instance, class: "REQUEST", body: "fixture" });
|
||||
const said = join(run.runDir, "turns", "0001.stderr");
|
||||
await until(() => existsSync(said) && /WEB-(READABLE|ABSENT)/.test(readFileSync(said, "utf8")));
|
||||
return readFileSync(said, "utf8").match(/WEB-(READABLE|ABSENT)/)[1];
|
||||
}
|
||||
|
||||
test("A3: a checkout an earlier launch made is out of sight in the sandbox once its project excludes the agent, and stays on the host", { skip, timeout: 90000 }, async (t) => {
|
||||
const p = prepare(t);
|
||||
// The adapter runs inside the sandbox and says only whether the web checkout's file is readable.
|
||||
writeFileSync(p.adapter, `if test -r "$MOSAIC_WORKSPACE/web/file.txt"; then echo WEB-READABLE >&2; else echo WEB-ABSENT >&2; fi\nexec '${process.execPath}' '${FAKE}'\n`);
|
||||
const s = await start(t, p);
|
||||
let out = await s.carry(s.call("instance.launch", { instance: "gate" }).request);
|
||||
assert.equal(out.done.refusal, null, JSON.stringify(out));
|
||||
let [run] = s.running("gate");
|
||||
assert.deepEqual(projectsOf(run), ["stack", "web"]);
|
||||
assert.equal(await webSeen(s, run), "READABLE");
|
||||
await s.carry(s.call("instance.end", { instance: "gate" }).request);
|
||||
await until(() => s.running("gate").length === 0);
|
||||
for (const exclude of [{ gate: { exclude: true } }, { ghost: { exclude: true } }]) {
|
||||
// The project excludes gate, then refuses its whole union.
|
||||
editOrg(p, (d) => { d.projects.web.agents = exclude; });
|
||||
reload(s);
|
||||
out = await s.carry(s.call("instance.launch", { instance: "gate" }).request);
|
||||
assert.equal(out.done.refusal, null, JSON.stringify(out));
|
||||
[run] = s.running("gate");
|
||||
assert.deepEqual(projectsOf(run), ["stack"]);
|
||||
assert.equal(await webSeen(s, run), "ABSENT");
|
||||
await s.carry(s.call("instance.end", { instance: "gate" }).request);
|
||||
await until(() => s.running("gate").length === 0);
|
||||
}
|
||||
// The earlier work is still on the host, untouched.
|
||||
assert.equal(readFileSync(join(s.dataRoot, "workspaces", "acme", "gate", "web", "file.txt"), "utf8"), "one\n");
|
||||
});
|
||||
|
||||
test("A3: a project that excludes the agent while its launch is prepared refuses the launch; the bus's last admission asks too", { skip, timeout: 60000 }, async (t) => {
|
||||
const p = prepare(t);
|
||||
const s = await start(t, p);
|
||||
const op = s.host.op;
|
||||
let changed = false;
|
||||
s.host.op = async (m) => {
|
||||
const out = await op(m);
|
||||
if (!changed && m.op === "request.admission" && m.project === "web") {
|
||||
changed = true;
|
||||
editOrg(p, (d) => { d.projects.web.agents = { gate: { exclude: true } }; });
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const out = await s.carry(s.call("instance.launch", { instance: "gate" }).request);
|
||||
assert.equal(changed, true);
|
||||
assert.equal(out.done.refusal, "project-refused", JSON.stringify(out));
|
||||
assert.equal(s.running("gate").length, 0);
|
||||
// Once the bus has the change, its launch-boundary admission refuses the instance there too.
|
||||
reload(s);
|
||||
assert.deepEqual(s.runtime.admission({ business: "acme", projects: ["stack", "web"], instance: "gate" }).code, "project-refused");
|
||||
assert.equal(s.runtime.admission({ business: "acme", projects: ["stack"], instance: "gate" }).ready, true);
|
||||
assert.equal(s.runtime.admission({ business: "acme", projects: ["stack", "web"] }).ready, true);
|
||||
});
|
||||
|
||||
test("A3: a project define whose vars change after boot refuses until the next start rather than launch with the old ones", { skip, timeout: 90000 }, async (t) => {
|
||||
const p = prepare(t);
|
||||
let s = await start(t, p);
|
||||
editOrg(p, (d) => { d.projects.stack.agents.checker.vars["limits.tools"] = ["read"]; });
|
||||
reload(s);
|
||||
const copy = s.call("instances").copies["checker.stack"];
|
||||
assert.equal(copy.state, "refused");
|
||||
assert.match(copy.reason, /^project stack changed checker's vars since the bus started/);
|
||||
assert.equal(refusedAt(s, "checker.stack").code, "project-refused");
|
||||
await s.close();
|
||||
s = await start(t, p);
|
||||
const out = await s.carry(s.call("instance.launch", { instance: "checker.stack" }).request);
|
||||
assert.equal(out.done.refusal, null, JSON.stringify(out));
|
||||
const tools = bundleOf(s.running("checker.stack")[0], "policy.json").tools;
|
||||
assert.ok(tools.includes("read"), JSON.stringify(tools));
|
||||
assert.equal(tools.includes("grep"), false, JSON.stringify(tools));
|
||||
});
|
||||
|
||||
test("A3: a collision a project brings in after boot refuses the copy it collides with, naming both claimants", { skip, timeout: 60000 }, async (t) => {
|
||||
const p = prepare(t);
|
||||
const rootFile = join(p.root, "config", "agents.json");
|
||||
const root = JSON.parse(readFileSync(rootFile, "utf8"));
|
||||
root.agents["new.stack"] = { definition: "security-reviewer", vars: VARS };
|
||||
writeFileSync(rootFile, JSON.stringify(root));
|
||||
const s = await start(t, p);
|
||||
assert.equal(s.call("instances").copies["new.stack"].state, "instance");
|
||||
editOrg(p, (d) => { d.projects.stack.agents.new = { definition: "merge-gate", vars: VARS }; });
|
||||
reload(s);
|
||||
const copy = s.call("instances").copies["new.stack"];
|
||||
assert.equal(copy.state, "refused");
|
||||
assert.deepEqual(copy.claims, [{ name: "new.stack", project: null }, { name: "new", project: "stack" }]);
|
||||
assert.equal(copy.reason, "the instance name new.stack is claimed by root agent new.stack and project stack's new");
|
||||
assert.equal(refusedAt(s, "new.stack").code, "copy-refused");
|
||||
// Taking the project's define back out frees the root copy again.
|
||||
editOrg(p, (d) => { delete d.projects.stack.agents.new; });
|
||||
reload(s);
|
||||
assert.equal(s.call("instances").copies["new.stack"].state, "instance");
|
||||
});
|
||||
|
||||
test("A3: an organization instance written over a root copy after boot launches as itself, with its own role", { skip, timeout: 60000 }, async (t) => {
|
||||
const p = prepare(t);
|
||||
const s = await start(t, p);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
//
|
||||
// Nothing in a copy's view carries a var value, a credential reference, a path or file bytes.
|
||||
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import { HOST_SERVICE } from "./vocabulary.mjs";
|
||||
import { loadRole } from "./role.mjs";
|
||||
import { resolveAgentLevels } from "./agent-levels.mjs";
|
||||
@@ -25,6 +26,9 @@ import { organizationWriter } from "./organization.mjs";
|
||||
import { deepFreeze } from "./util.mjs";
|
||||
|
||||
const ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
||||
// How a refusal names one claimant of an instance name.
|
||||
const claimLabel = ({ name, project }) => (project === null ? `root agent ${name}` : `project ${project}'s ${name}`);
|
||||
const collision = (key, claimants) => `the instance name ${key} is claimed by ${claimants.map(claimLabel).join(" and ")}`;
|
||||
// The root assistant is shown, not copied (A6); agent-levels.mjs names it the same way.
|
||||
const ASSISTANT = "assistant";
|
||||
export const COPY_STATES = Object.freeze(["instance", "unbound", "refused"]);
|
||||
@@ -66,26 +70,22 @@ export function materializeCopies({ orgId, doc, root, rolesDir }) {
|
||||
}
|
||||
const cache = new Map();
|
||||
const copies = {};
|
||||
const claims = {};
|
||||
const add = (agent, project, refusal = null) => {
|
||||
const instance = copyInstanceName(agent.name, project);
|
||||
// An over-long project agent name has no instance; it refuses under its own name.
|
||||
const key = instance ?? `${agent.name}.${project}`;
|
||||
const base = { name: agent.name, level: project === null ? "root" : "project", project, definition: agent.definition, vars: agent.vars };
|
||||
const claim = project === null ? `root agent ${agent.name}` : `project ${project}'s ${agent.name}`;
|
||||
// Two agents whose instance names come out the same (root checker.stack and project stack's
|
||||
// checker, or two dotted names) refuse both, naming each; neither overwrites the other. The
|
||||
// entry lists every claimant, so a reader finds each agent's copy by its name and project.
|
||||
if (Object.hasOwn(copies, key)) {
|
||||
claims[key].push(claim);
|
||||
const claimants = [...(copies[key].claims ?? [{ name: copies[key].name, project: copies[key].project }]), { name: agent.name, project }];
|
||||
copies[key] = { ...copies[key], state: "refused", reason: `the instance name ${key} is claimed by ${claims[key].join(" and ")}`, claims: claimants };
|
||||
copies[key] = { ...copies[key], state: "refused", reason: collision(key, claimants), claims: claimants };
|
||||
delete copies[key].missing;
|
||||
return;
|
||||
}
|
||||
claims[key] = [claim];
|
||||
// The organization file's own instance of that name wins: no copy is made (design section 3).
|
||||
if (instance !== null && Object.hasOwn(doc?.roles ?? {}, instance)) { delete claims[key]; return; }
|
||||
if (instance !== null && Object.hasOwn(doc?.roles ?? {}, instance)) return;
|
||||
if (refusal) { copies[key] = { ...base, state: "refused", reason: refusal }; return; }
|
||||
if (instance === null) { copies[key] = { ...base, state: "refused", reason: `project ${project}: ${agent.name}.${project} is longer than an instance name may be` }; return; }
|
||||
const missing = needs(agent.definition, rolesDir, cache);
|
||||
@@ -159,8 +159,10 @@ function narrowVars(level, vars, narrows) {
|
||||
const unionInstance = (agent, project) => (agent.level === "project" ? copyInstanceName(agent.name, project) ?? `${agent.name}.${project}` : agent.name);
|
||||
|
||||
// Why a project copy can't join this document, or null when it can: its project is still a declared
|
||||
// code project, the project still defines it, and the project's union, recomputed from this
|
||||
// document, still accepts it.
|
||||
// code project, the project still defines it with the definition and vars the bus started with, and
|
||||
// the project's union, recomputed from this document, still accepts it. A copy is made at boot, so
|
||||
// a changed definition or vars waits for the next start; until then the copy refuses rather than
|
||||
// launch with settings the project no longer gives it.
|
||||
function projectCopyRefusal(copy, document, levels) {
|
||||
const p = document.projects?.[copy.project];
|
||||
if (!p || p.kind === "library") return `project ${copy.project} is no longer declared`;
|
||||
@@ -168,6 +170,7 @@ function projectCopyRefusal(copy, document, levels) {
|
||||
if (!union.ok) return `project ${copy.project} refuses its agents: ${union.reason}`;
|
||||
const entry = levels.projects[copy.project]?.[copy.name];
|
||||
if (entry?.form !== "define" || entry.definition !== copy.definition) return `project ${copy.project} no longer defines ${copy.name} as ${copy.definition}`;
|
||||
if (!isDeepStrictEqual(entry.vars ?? {}, copy.vars ?? {})) return `project ${copy.project} changed ${copy.name}'s vars since the bus started; the change takes effect at the next start`;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -207,10 +210,25 @@ export function withCopies(document, file, { rolesDir, snapshot }) {
|
||||
}
|
||||
const narrowed = { ...document, roles };
|
||||
const view = copiesView(copies);
|
||||
// Who claims each copy's instance name now: the boot's root copies and the projects' define
|
||||
// entries as this document has them. A project that comes to define an agent whose name collides
|
||||
// with a copy refuses that copy, naming every claimant, as the boot does.
|
||||
const claimants = {};
|
||||
const claim = (key, who) => { if (!(claimants[key] ??= []).some((c) => c.name === who.name && c.project === who.project)) claimants[key].push(who); };
|
||||
for (const [instance, copy] of Object.entries(copies)) for (const c of copy.claims ?? [{ name: copy.name, project: copy.project }]) if (c.project === null) claim(instance, c);
|
||||
for (const [project, entries] of Object.entries(levels.projects)) {
|
||||
for (const [name, entry] of Object.entries(entries)) if (entry.form === "define") claim(copyInstanceName(name, project) ?? `${name}.${project}`, { name, project });
|
||||
}
|
||||
const join = {};
|
||||
for (const [instance, copy] of Object.entries(copies)) {
|
||||
// The organization file's own instance of this name wins; the copy is gone, not refused.
|
||||
if (Object.hasOwn(roles, instance)) { delete view[instance]; continue; }
|
||||
if ((claimants[instance]?.length ?? 0) > 1) {
|
||||
const all = claimants[instance].map(({ name, project }) => ({ name, project }));
|
||||
const { missing: _, ...rest } = view[instance];
|
||||
view[instance] = { ...rest, state: "refused", reason: collision(instance, all), claims: all };
|
||||
continue;
|
||||
}
|
||||
if (copy.state !== "instance") continue;
|
||||
const refused = copy.project === null ? null : projectCopyRefusal(copy, document, levels);
|
||||
if (refused) { view[instance] = { ...view[instance], state: "refused", reason: refused }; continue; }
|
||||
|
||||
@@ -212,6 +212,59 @@ test("A3: two agents whose instance names come out the same both refuse, naming
|
||||
assert.deepEqual(business.copies["c.a.b"].claims, [{ name: "c", project: "a.b" }, { name: "c.a", project: "b" }]);
|
||||
});
|
||||
|
||||
test("A3: a collision the current file brings in after boot refuses every claimant it reaches, and lifts when the file drops it", () => {
|
||||
const dir = tmp();
|
||||
mkdirSync(join(dir, "a.b"), { recursive: true });
|
||||
mkdirSync(join(dir, "b"), { recursive: true });
|
||||
const file = businessFilePath("acme", dir);
|
||||
const doc = org(dir, "acme", (d) => {
|
||||
d.projects["a.b"] = { root: join(dir, "a.b"), agents: { c: { definition: "merge-gate" } } };
|
||||
d.projects.b = { root: join(dir, "b") };
|
||||
return d;
|
||||
});
|
||||
const { snapshot, business } = boot(dir, "acme", doc, root({ "new.stack": { definition: "security-reviewer" } }));
|
||||
assert.equal(business.copies["c.a.b"].state, "instance");
|
||||
assert.equal(business.copies["new.stack"].state, "instance");
|
||||
// Project b's c.a and project stack's new now come out as the names of copies made at boot.
|
||||
const edited = structuredClone(doc);
|
||||
edited.projects.b.agents = { "c.a": { definition: "merge-gate" } };
|
||||
edited.projects.stack.agents = { new: { definition: "merge-gate" } };
|
||||
const later = withCopies(edited, file, { rolesDir, snapshot });
|
||||
for (const [instance, claims, reason] of [
|
||||
["c.a.b", [{ name: "c", project: "a.b" }, { name: "c.a", project: "b" }], "the instance name c.a.b is claimed by project a.b's c and project b's c.a"],
|
||||
["new.stack", [{ name: "new.stack", project: null }, { name: "new", project: "stack" }], "the instance name new.stack is claimed by root agent new.stack and project stack's new"],
|
||||
]) {
|
||||
assert.equal(later.copies[instance].state, "refused", instance);
|
||||
assert.deepEqual(later.copies[instance].claims, claims, instance);
|
||||
assert.equal(later.copies[instance].reason, reason, instance);
|
||||
assert.equal(Object.hasOwn(later.roles, instance), false, instance);
|
||||
assert.ok(copyRefusal(later, instance), instance);
|
||||
}
|
||||
// Without the new defines, both copies are instances again.
|
||||
const back = withCopies(doc, file, { rolesDir, snapshot });
|
||||
assert.equal(back.copies["c.a.b"].state, "instance");
|
||||
assert.equal(back.copies["new.stack"].state, "instance");
|
||||
});
|
||||
|
||||
test("A3: a project define whose vars change after boot refuses its copy until the next boot", () => {
|
||||
const dir = tmp();
|
||||
const file = businessFilePath("acme", dir);
|
||||
const doc = org(dir, "acme", (d) => { d.projects.stack.agents = { checker: { definition: "merge-gate" } }; return d; });
|
||||
const { snapshot, business } = boot(dir, "acme", doc, root({}));
|
||||
assert.equal(business.copies["checker.stack"].state, "instance");
|
||||
const edited = structuredClone(doc);
|
||||
edited.projects.stack.agents.checker.vars = { "limits.tools": ["read"] };
|
||||
const later = withCopies(edited, file, { rolesDir, snapshot });
|
||||
const r = copyRefusal(later, "checker.stack");
|
||||
assert.equal(r.code, "project-refused");
|
||||
assert.match(r.message, /project stack changed checker's vars since the bus started; the change takes effect at the next start$/);
|
||||
assert.equal(Object.hasOwn(later.roles, "checker.stack"), false);
|
||||
// The next boot makes the copy from the new vars.
|
||||
const next = boot(dir, "acme", edited, root({})).business;
|
||||
assert.equal(next.copies["checker.stack"].state, "instance");
|
||||
assert.deepEqual(next.roles["checker.stack"].vars["limits.tools"], ["read"]);
|
||||
});
|
||||
|
||||
test("A3: each project's union is recomputed from the current file: a refused union refuses its own copy and every agent in it; exclude and narrow reach the instance", () => {
|
||||
const dir = tmp();
|
||||
mkdirSync(join(dir, "web"), { recursive: true });
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync, lstatSync, mkdirSync, readlinkSync, realpathSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { ID_PATTERN } from "../../organization/src/vocabulary.mjs";
|
||||
|
||||
@@ -111,8 +111,11 @@ function systemBinds(node = process.execPath) {
|
||||
// sessionStore(), or null) and node. workspaceDest (row 269) is where the
|
||||
// workspace shows inside the sandbox when that isn't its host path: a legacy
|
||||
// thread session's, so its harness finds the cwd its history recorded.
|
||||
// `hidden` (#1873 A3) lists directories inside the workspace the session may not see: a project
|
||||
// checkout a launch before this one made, in a project that now excludes or refuses the instance.
|
||||
// Each gets an empty tmpfs over it, so its files stay on the host, untouched, and out of sight.
|
||||
// `readOnly` adds files, for tests only.
|
||||
export function binds({ runDir, workspace, workspaceDest = null, adapter, harnessMounts = [], brokerSocket, launchSocket = null, gitSocket = null, threadStore = null, node = process.execPath, readOnly = [] }) {
|
||||
export function binds({ runDir, workspace, workspaceDest = null, hidden = [], adapter, harnessMounts = [], brokerSocket, launchSocket = null, gitSocket = null, threadStore = null, node = process.execPath, readOnly = [] }) {
|
||||
const out = systemBinds(node);
|
||||
for (const f of RUNNER_FILES) out.push({ kind: "ro", src: f, why: "a repository file the runner loads" });
|
||||
out.push({ kind: "ro", src: adapter, why: "the harness adapter the runner starts each turn" });
|
||||
@@ -123,6 +126,11 @@ export function binds({ runDir, workspace, workspaceDest = null, adapter, harnes
|
||||
for (const f of readOnly) out.push({ kind: "ro", src: f, why: "a test fixture" });
|
||||
out.push(
|
||||
{ kind: "rw", src: workspace, ...(workspaceDest && workspaceDest !== workspace ? { dest: workspaceDest } : {}), why: "the instance's workspace, where the harness works" },
|
||||
...hidden.map((h) => {
|
||||
const inside = relative(workspace, h);
|
||||
if (!inside || inside.startsWith("..") || isAbsolute(inside)) throw new Error(`hidden path ${h} is not inside the workspace`);
|
||||
return { kind: "tmpfs", dest: join(workspaceDest ?? workspace, inside), why: "a project checkout this launch may not see, covered by an empty tmpfs" };
|
||||
}),
|
||||
{ kind: "rw", src: runDir, why: "the run directory: turns/, session/, tools.sock, turn.done, home/, tmp/" },
|
||||
{ kind: "ro", src: join(runDir, "bundle"), why: "the run's bundle stays as the host wrote it" },
|
||||
{ kind: "ro", src: join(runDir, "session.json"), why: "the session file stays as the host wrote it" },
|
||||
@@ -146,6 +154,7 @@ function argsOf(list) {
|
||||
else if (b.kind === "symlink") args.push("--symlink", b.src, b.dest);
|
||||
else if (b.kind === "dev") args.push("--dev", b.dest);
|
||||
else if (b.kind === "proc") args.push("--proc", b.dest);
|
||||
else if (b.kind === "tmpfs") args.push("--tmpfs", b.dest);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,26 @@ test("every bind says why; the bundle and session file stay read-only over the r
|
||||
assert.ok(!list.some((b) => b.src === realpathSync(join(REPO, "node_modules"))), "no harness mounts unless the module names them");
|
||||
});
|
||||
|
||||
// #1873 A3: a checkout the launch may not see is covered by an empty tmpfs after the workspace bind,
|
||||
// at the path the session sees; a path outside the workspace is refused, never mounted.
|
||||
test("A3 a hidden checkout is a tmpfs over the workspace bind; a path outside the workspace refuses", (t) => {
|
||||
const root = scratch(t);
|
||||
const workspace = join(root, "ws");
|
||||
const args = { runDir: join(root, "run"), workspace, adapter: join(root, "a.sh"), brokerSocket: join(root, "bus.sock") };
|
||||
const list = binds({ ...args, hidden: [join(workspace, "web")] });
|
||||
const ws = list.findIndex((b) => b.src === workspace);
|
||||
const hide = list.findIndex((b) => b.kind === "tmpfs");
|
||||
assert.ok(ws >= 0 && hide > ws, "the tmpfs comes after the workspace bind");
|
||||
assert.equal(list[hide].dest, join(workspace, "web"));
|
||||
assert.ok(list[hide].why);
|
||||
const moved = binds({ ...args, workspaceDest: "/work", hidden: [join(workspace, "web")] });
|
||||
assert.equal(moved.find((b) => b.kind === "tmpfs").dest, "/work/web");
|
||||
assert.equal(binds(args).some((b) => b.kind === "tmpfs"), false);
|
||||
for (const bad of [workspace, join(root, "other"), join(workspace, "..", "ws2")]) {
|
||||
assert.throws(() => binds({ ...args, hidden: [bad] }), /is not inside the workspace/, bad);
|
||||
}
|
||||
});
|
||||
|
||||
// Row 65: the harness module names its own mounts; binds() mounts each read-only, after the
|
||||
// adapter and before the broker socket, and names no harness itself.
|
||||
test("row 65 a harness module's mounts bind read-only after the adapter, each with the module's reason", async (t) => {
|
||||
|
||||
Reference in new issue
Block a user