fix(workspace): hide ephemeral quick runtimes
This commit is contained in:
@@ -47,6 +47,83 @@ function adapters() {
|
||||
};
|
||||
}
|
||||
|
||||
test("keeps quick runtimes out of workspace state until promotion", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "pi-quick-isolation-"));
|
||||
const home = join(root, "home");
|
||||
const feature = join(root, "feature");
|
||||
await Promise.all([mkdir(home), mkdir(feature)]);
|
||||
const fixture = adapters();
|
||||
const registry = createAgentRegistry({
|
||||
homeWorktree: home,
|
||||
sessionRoot: join(root, "sessions"),
|
||||
startAdapter: fixture.startAdapter,
|
||||
});
|
||||
await registry.start();
|
||||
assert.equal(
|
||||
registry.workspaceEventsAfter(0).events.at(-1).type,
|
||||
"runtime_opened",
|
||||
);
|
||||
const cursor = registry.getWorkspace().latestSeq;
|
||||
const received = [];
|
||||
const subscription = registry.subscribeWorkspace(cursor, (event) =>
|
||||
received.push(event),
|
||||
);
|
||||
const quick = await Promise.all(
|
||||
Array.from({ length: 5 }, () => registry.createQuickRuntime(feature)),
|
||||
);
|
||||
fixture.calls.at(-1).options.onEvent({
|
||||
type: "transcript",
|
||||
data: { event: { type: "message_end" } },
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
registry
|
||||
.getWorkspace()
|
||||
.directories.map((directory) => directory.worktreePath),
|
||||
[home],
|
||||
);
|
||||
assert.equal(registry.getWorkspace().directories[0].openCount, 1);
|
||||
assert.deepEqual(registry.getWorkspaceSummary(), {
|
||||
bridgeInstanceId: registry.bridgeInstanceId,
|
||||
latestSeq: cursor,
|
||||
openCount: 1,
|
||||
workingCount: 0,
|
||||
attentionCount: 0,
|
||||
recoveringCount: 0,
|
||||
errorCount: 0,
|
||||
directoryCount: 1,
|
||||
resourceWarning: false,
|
||||
});
|
||||
const quickSnapshot = await registry.getSessionRuntimeSnapshot(
|
||||
quick[0].runtimeId,
|
||||
);
|
||||
assert.equal(quickSnapshot.runtime.runtimeId, quick[0].runtimeId);
|
||||
await registry.closeQuickRuntime(quick.at(-1).runtimeId);
|
||||
assert.deepEqual(received, []);
|
||||
assert.deepEqual(registry.workspaceEventsAfter(cursor).events, []);
|
||||
|
||||
const promoted = await registry.promoteQuickRuntime(quick[0].runtimeId);
|
||||
const featureDirectory = registry
|
||||
.getWorkspace()
|
||||
.directories.find((directory) => directory.worktreePath === feature);
|
||||
assert.deepEqual(
|
||||
featureDirectory?.runtimes.map((runtime) => runtime.runtimeId),
|
||||
[quick[0].runtimeId],
|
||||
);
|
||||
assert.equal(promoted.runtimeId, quick[0].runtimeId);
|
||||
assert.equal(registry.getWorkspaceSummary().openCount, 2);
|
||||
assert.deepEqual(
|
||||
received.map((event) => event.type),
|
||||
["runtime_promoted"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
registry.workspaceEventsAfter(cursor).events.map((event) => event.type),
|
||||
["runtime_promoted"],
|
||||
);
|
||||
subscription.unsubscribe();
|
||||
await registry.stop();
|
||||
});
|
||||
|
||||
test("promotes an active quick runtime in place and makes stale quick cleanup harmless", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "pi-quick-promote-"));
|
||||
const home = join(root, "home");
|
||||
|
||||
Reference in New Issue
Block a user