merge: combine row 219 with landed row 302
This commit is contained in:
commit
06d7cc2f0f
112 files changed
+13616
-46
No files matched your search
@@ -53,7 +53,7 @@
|
||||
// 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:
|
||||
// role definition is in THREAD_DEFINITIONS) runs once per thread, never on its own:
|
||||
// a launch from a session or --pm refuses thread-required. Every tick
|
||||
// (threadTickMs) the host asks the broker for the business's threads
|
||||
// (launch op threadsState) and:
|
||||
@@ -139,6 +139,7 @@ import { createServer } from "node:net";
|
||||
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
|
||||
import { dirname, join, relative } from "node:path";
|
||||
import { configDir, loadBusiness, resolveInstance, systemVars } from "../../business/src/index.mjs";
|
||||
import { THREAD_DEFINITIONS } from "../../business/src/vocabulary.mjs";
|
||||
import { limitHit } from "../../business/src/launch.mjs";
|
||||
import { BundleError, buildBundle, hasFallback, readSkills, sessionModel } from "../../harness/src/bundle.mjs";
|
||||
import { createLoader } from "../../plugins/src/loader.mjs";
|
||||
@@ -176,8 +177,6 @@ const STOP_TIMEOUT_MS = 30000;
|
||||
const LINE_MAX = 4096;
|
||||
// How often the host asks for the threads' state; a poll period, not a limit.
|
||||
const THREAD_TICK_MS = 2000;
|
||||
// The broker's thread instance definition (packages/bus/src/broker.mjs).
|
||||
const THREAD_DEFINITION = "assistant";
|
||||
// Row 194: the broker's LIFECYCLE_REQUEST_MS. A regenerate's old run must be gone by then.
|
||||
const LIFECYCLE_REQUEST_MS = 60000;
|
||||
|
||||
@@ -331,7 +330,7 @@ export function createLauncher({
|
||||
try { b=loadBusiness(host.business,{dir:configDir(env),rolesDir:rolesDir(env)}); } catch(e){throw new Refusal("organization-refused",e.message);}
|
||||
if (!b.launch) throw new Refusal("launch-not-configured", `business ${b.id} has no launch block`);
|
||||
if (!(pm ? instance === b.launch.by : b.launch.instances.includes(instance) || (human && Object.hasOwn(b.roles, instance)))) throw new Refusal("instance-not-listed");
|
||||
const threaded = b.roles[instance]?.definition === THREAD_DEFINITION;
|
||||
const threaded = THREAD_DEFINITIONS.includes(b.roles[instance]?.definition);
|
||||
if (threaded && !thread) throw new Refusal("thread-required", `${instance} runs only for a thread`);
|
||||
if (!threaded && thread) throw new Refusal("thread-not-allowed", `${instance} isn't a thread instance`);
|
||||
if (threaded && !session) throw new Refusal("session-required", `${instance} runs for one session of a thread`);
|
||||
@@ -997,7 +996,7 @@ export function createLauncher({
|
||||
function ending(r) {
|
||||
const runs = r.runs ?? [];
|
||||
const at = Date.parse(r.at);
|
||||
const threaded = b.roles[r.instance]?.definition === THREAD_DEFINITION;
|
||||
const threaded = THREAD_DEFINITIONS.includes(b.roles[r.instance]?.definition);
|
||||
return registry.sessions.filter((s) => s.business === b.id && (runs.includes(s.run) ||
|
||||
(!threaded && s.instance === r.instance && (spawnedAt.get(s.run) ?? Date.parse(s.startedAt)) <= at)));
|
||||
}
|
||||
|
||||
@@ -773,21 +773,34 @@ test("row 213 a creative instance's persona is read from <configDir>/personas: o
|
||||
const dir = join(given.root, "config", "personas", "acme");
|
||||
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
writeFileSync(join(dir, "bean.md"), "Not the pinned text.\n", { mode: 0o600 });
|
||||
const { f, host, launcher } = await setup(t, undefined, given);
|
||||
// The chief of staff holds role.launch; a test chief session bound to this process asks.
|
||||
const chief = await host.bindLaunch({ business: "acme", role: "chief", run: "chief-test", harness: "pi", pid: process.pid, startTime: startTimeOf(process.pid) });
|
||||
await new Client({ path: host.path, cap: chief.cap }).call("role.claim");
|
||||
// The bundle's refusal comes back as launch-failed, as webPlan's does, with its reason in the log.
|
||||
assert.deepEqual(await launcher.fromSession(chief.cap, "bean"), { ok: false, error: "launch-failed" });
|
||||
const [e] = log(f);
|
||||
assert.deepEqual([e.event, e.code, log(f).length], ["refused", "launch-failed", 1]);
|
||||
// Row 219: creative instances launch from their thread, not from a chief's standalone request.
|
||||
// The mismatch occurs before bindLaunch, so only the host's thread-state snapshot is a fixture.
|
||||
const thread = 'persona-thread';
|
||||
const SESSION = 'persona-session';
|
||||
const { f, launcher } = await setup(t, undefined, given, { wrap: host => ({
|
||||
...host,
|
||||
op: message => message.op === 'threadsState'
|
||||
? Promise.resolve([{ thread, session: SESSION, instance: 'bean', holder: null, pending: 1 }])
|
||||
: host.op(message),
|
||||
}) });
|
||||
// The thread path records row 270's run-start count before the bundle's persona refusal.
|
||||
await launcher.tick();
|
||||
const runs = readdirSync(join(f.dataRoot, "launches", "acme"));
|
||||
const entries = log(f);
|
||||
assert.equal(entries.length, 2);
|
||||
const { at, ...compactions } = entries[0];
|
||||
assert.deepEqual(compactions, { event: 'compactions', instance: 'bean', thread, session: SESSION, run: runs[0], count: 0, known: true, reason: null });
|
||||
const e = entries[1];
|
||||
assert.deepEqual([e.event, e.code], ["refused", "launch-failed"]);
|
||||
assert.equal(e.thread, thread);
|
||||
assert.equal(e.why, `instance bean: persona file ${join(dir, "bean.md")} isn't the file persona.sha256 names`);
|
||||
assert.ok(!JSON.stringify(log(f)).includes("PERSONA-MARKER-d2"));
|
||||
assert.deepEqual(readSessions(f.dataRoot), []);
|
||||
// The run directory exists by then (BUILD.md residual); the persona is read before any bundle file.
|
||||
const runs = readdirSync(join(f.dataRoot, "launches", "acme"));
|
||||
assert.equal(runs.length, 1);
|
||||
assert.deepEqual(readdirSync(join(f.dataRoot, "launches", "acme", runs[0])), ["session"]);
|
||||
assert.deepEqual(readdirSync(join(f.dataRoot, "launches", "acme", runs[0])), []);
|
||||
assert.equal(existsSync(join(f.dataRoot, "threads", "acme", thread, "sessions", SESSION, "session")), true);
|
||||
assert.equal(existsSync(join(f.dataRoot, "threads", "acme", thread, "session")), false);
|
||||
});
|
||||
|
||||
test("row 64 on Claude Code a role skill that isn't enabled refuses the same way, before anything starts", { timeout: 30000 }, async (t) => {
|
||||
|
||||
@@ -396,6 +396,22 @@ test("REQ-THREAD-1 REQ-LAUNCH-1 the chief can't launch the assistant outside a t
|
||||
assert.deepEqual(launchLog(f).map((e) => [e.event, e.instance, e.code]), [["refused", "assistant", "thread-required"]]);
|
||||
});
|
||||
|
||||
// Admission refuses before bundle construction or a sandbox is needed.
|
||||
test('C2-09a: fromSession refuses a creative instance outside a thread without a sandbox', { timeout: 30000 }, async t => {
|
||||
const prepared = prepare(t, { edit: doc => {
|
||||
doc.roles.bean = { ...doc.roles.assistant, definition: 'companion' };
|
||||
doc.launch.instances.push('bean');
|
||||
return doc;
|
||||
} });
|
||||
const { f } = prepared;
|
||||
const host = await start(t, prepared);
|
||||
const chief = await host.host.bindLaunch({ business: 'acme', role: 'chief', run: 'chief-bean-refusal', harness: 'pi', pid: process.pid, startTime: startTimeOf(process.pid) });
|
||||
await new Client({ path: host.host.path, cap: chief.cap }).call('role.claim');
|
||||
assert.deepEqual(await host.launcher.fromSession(chief.cap, 'bean'), { ok: false, error: 'thread-required' });
|
||||
assert.deepEqual(readSessions(f.dataRoot), []);
|
||||
assert.deepEqual(launchLog(f).map(e => [e.event, e.instance, e.code]), [['refused', 'bean', 'thread-required']]);
|
||||
});
|
||||
|
||||
// Row 125 (#1619, REQ-LIMIT-3, REQ-LIMIT-4): the token-limit check switched on, with the
|
||||
// assistant's limit at 0, so it is at its limit before any turn. The real check runs through the
|
||||
// bus's plug-in loader.
|
||||
@@ -443,3 +459,73 @@ test("REQ-LIMIT-4 a thread run at its token limit stops at the end of its turn:
|
||||
assert.deepEqual(threadRuns(f, A), []);
|
||||
assert.equal(host.runtime.threadsState("acme").find((x) => x.thread === A).holder, null);
|
||||
});
|
||||
|
||||
test('C2-09a: creative thread messages start distinct runs and keep each instance history separate', { skip, timeout: 90000 }, async t => {
|
||||
const prepared = prepare(t, { sonnet: 2, idle: 60, edit: doc => {
|
||||
const vars = { ...doc.roles.assistant.vars };
|
||||
delete doc.roles.assistant;
|
||||
doc.roles.bean = { definition: 'companion', vars: { ...vars } };
|
||||
doc.roles.chet = { definition: 'continuity', vars: { ...vars } };
|
||||
doc.launch.instances = ['coder', 'bean', 'chet'];
|
||||
return doc;
|
||||
} });
|
||||
const host = await start(t, prepared), { f } = prepared;
|
||||
const project = host.call('project.create', { name: 'Writing' }).id;
|
||||
const bean = host.call('thread.create', { project, name: 'Bean', instance: 'bean' }).id;
|
||||
const chet = host.call('thread.create', { project, name: 'Chet', instance: 'chet' }).id;
|
||||
const send = async (thread, instance, body) => {
|
||||
const message = host.call('thread.send', { thread, body });
|
||||
const outcome = await until(() => host.call('thread.messages', { thread }).find(m => m.in_reply_to === message.id) ||
|
||||
launchLog(f).find(row => row.thread === thread && row.event === 'refused'));
|
||||
assert.notEqual(outcome.event, 'refused', `creative thread launch refused: ${outcome.code}`);
|
||||
const reply = outcome;
|
||||
assert.equal(reply.from_role, instance);
|
||||
assert.equal(reply.to_role, 'human');
|
||||
return JSON.parse(reply.body.match(/THREAD (\{.*\})/)[1]);
|
||||
};
|
||||
assert.deepEqual((await send(bean, 'bean', 'Bean input')).before, []);
|
||||
assert.deepEqual((await send(chet, 'chet', 'Chet input')).before, []);
|
||||
assert.deepEqual((await send(bean, 'bean', 'Bean again')).before, ['Bean input']);
|
||||
assert.equal(readFileSync(join(f.dataRoot, 'threads', 'acme', bean, 'sessions', host.runtime.threadsState('acme').find(x => x.thread === bean).session, 'session', 'history'), 'utf8'), 'Bean input\nBean again\n');
|
||||
assert.equal(readFileSync(join(f.dataRoot, 'threads', 'acme', chet, 'sessions', host.runtime.threadsState('acme').find(x => x.thread === chet).session, 'session', 'history'), 'utf8'), 'Chet input\n');
|
||||
assert.equal(existsSync(join(f.dataRoot, 'threads', 'acme', bean, 'session')), false);
|
||||
assert.equal(existsSync(join(f.dataRoot, 'threads', 'acme', chet, 'session')), false);
|
||||
const launches = launchLog(f).filter(row => row.event === 'launch');
|
||||
assert.ok(launches.some(row => row.instance === 'bean' && row.thread === bean));
|
||||
assert.ok(launches.some(row => row.instance === 'chet' && row.thread === chet));
|
||||
const chief = await host.host.bindLaunch({ business: 'acme', role: 'chief', run: 'chief-creative-test', harness: 'pi', pid: process.pid, startTime: startTimeOf(process.pid) });
|
||||
await new Client({ path: host.host.path, cap: chief.cap }).call('role.claim');
|
||||
assert.deepEqual(await host.launcher.fromSession(chief.cap, 'bean'), { ok: false, error: 'thread-required' });
|
||||
});
|
||||
|
||||
test('C2-09a: terminating one creative thread does not signal an unselected peer of the same instance', { skip, timeout: 90000 }, async t => {
|
||||
const prepared = prepare(t, { sonnet: 2, idle: 60, edit: doc => {
|
||||
doc.roles.bean = { ...doc.roles.assistant, definition: 'companion' };
|
||||
delete doc.roles.assistant;
|
||||
doc.launch.instances = ['coder', 'bean'];
|
||||
return doc;
|
||||
} });
|
||||
let requests = [];
|
||||
const host = await start(t, prepared, { ops: () => ({
|
||||
lifecycleRequests: () => requests,
|
||||
lifecycleTake: () => ({ ...requests[0], go: true }),
|
||||
lifecycleDone: () => { requests = []; return {}; },
|
||||
}) });
|
||||
const { f } = prepared;
|
||||
const project = host.call('project.create', { name: 'Writing' }).id;
|
||||
const threads = ['one', 'two'].map(name => host.call('thread.create', { project, name, instance: 'bean' }).id);
|
||||
for (const thread of threads) {
|
||||
const message = host.call('thread.send', { thread, body: 'Stay in this thread' });
|
||||
const outcome = await until(() => host.call('thread.messages', { thread }).find(row => row.in_reply_to === message.id) ||
|
||||
launchLog(f).find(row => row.thread === thread && row.event === 'refused'));
|
||||
assert.notEqual(outcome.event, 'refused', `creative thread launch refused: ${outcome.code}`);
|
||||
}
|
||||
const runs = threads.map(thread => launchLog(f).find(row => row.thread === thread && row.event === 'launch').run);
|
||||
requests = [{ request: 'one-thread-end', state: 'open', business: 'acme', action: 'lifecycle.end',
|
||||
instance: 'bean', runs: [runs[0]], by: f.doc.human, at: new Date(Date.now() + 1000).toISOString() }];
|
||||
await host.launcher.tick();
|
||||
await until(() => launchLog(f).some(row => row.event === 'lifecycle-end' && row.run === runs[0]));
|
||||
assert.deepEqual(launchLog(f).filter(row => row.event === 'lifecycle-end').map(row => row.run), [runs[0]]);
|
||||
await until(() => !readSessions(f.dataRoot).some(row => row.run === runs[0]));
|
||||
assert.ok(readSessions(f.dataRoot).some(row => row.run === runs[1]));
|
||||
});
|
||||
Reference in new issue
Block a user