refactor(app): split session and CLI workflows

This commit is contained in:
morluto
2026-07-18 05:49:14 +00:00
parent 3e61a63a10
commit c6ee0049c4
88 changed files with 7428 additions and 6024 deletions
+4 -3
View File
@@ -48,12 +48,13 @@ describe("cross-version inventory", () => {
const calls: string[] = [];
const controller = new AbortController();
const scanner: VersionInventoryScanner = (...arguments_) => {
const [path, roots, limits, signal, integrity] = arguments_;
const [path, roots, limits, options] = arguments_;
if (options === undefined) throw new Error("Expected scanner options");
calls.push(path);
expect(roots).toEqual([root]);
expect(limits).toBe(LIMITS);
expect(signal).toBe(controller.signal);
expect(integrity).toBe(INTEGRITY);
expect(options.signal).toBe(controller.signal);
expect(options.integrity).toBe(INTEGRITY);
return path === "left" ? left.promise : right.promise;
};
+32 -24
View File
@@ -8,13 +8,19 @@ type RuntimeDependencies = NonNullable<Parameters<typeof run>[0]>;
const nextTurn = (): Promise<void> =>
new Promise((resolve) => setImmediate(resolve));
const dependencies = (
serve: RuntimeDependencies["serve"],
output: string[],
shutdown: Array<() => void>,
exitCodes: number[],
shutdownUnregistrations: string[] = [],
): RuntimeDependencies => ({
const dependencies = ({
serve,
output,
shutdown,
exitCodes,
shutdownUnregistrations = [],
}: {
readonly serve: RuntimeDependencies["serve"];
readonly output: string[];
readonly shutdown: Array<() => void>;
readonly exitCodes: number[];
readonly shutdownUnregistrations?: string[];
}): RuntimeDependencies => ({
env: {},
serve,
writeStderr: (text) => output.push(text),
@@ -39,8 +45,8 @@ describe("MCP runtime errors", () => {
const exitCodes: number[] = [];
expect(
await run(
dependencies(
(_factory, received) => {
dependencies({
serve: (_factory, received) => {
options = received;
return { close };
},
@@ -48,7 +54,7 @@ describe("MCP runtime errors", () => {
shutdown,
exitCodes,
shutdownUnregistrations,
),
}),
),
).toBe(0);
options?.onerror?.(new Error("SECRET transport stack"));
@@ -67,17 +73,17 @@ describe("MCP runtime errors", () => {
const unregistrations: string[] = [];
let closeCalls = 0;
const runtime: RuntimeDependencies = {
...dependencies(
() => ({
...dependencies({
serve: () => ({
close: async () => {
closeCalls += 1;
},
}),
[],
output: [],
shutdown,
[],
unregistrations,
),
exitCodes: [],
shutdownUnregistrations: unregistrations,
}),
registerReload: (handler) => {
reload.push(handler);
return () => unregistrations.push("reload");
@@ -100,14 +106,14 @@ describe("MCP runtime errors", () => {
const output: string[] = [];
expect(
await run(
dependencies(
() => {
dependencies({
serve: () => {
throw new Error("SECRET startup stack");
},
output,
[],
[],
),
shutdown: [],
exitCodes: [],
}),
),
).toBe(1);
expect(output).toEqual([
@@ -120,12 +126,14 @@ describe("MCP runtime errors", () => {
const shutdown: Array<() => void> = [];
const exitCodes: number[] = [];
await run(
dependencies(
() => ({ close: () => Promise.reject(new Error("SECRET close")) }),
dependencies({
serve: () => ({
close: () => Promise.reject(new Error("SECRET close")),
}),
output,
shutdown,
exitCodes,
),
}),
);
shutdown[0]?.();
await nextTurn();