Files
oh-my-pi/packages/coding-agent/test/xterm-runtime-ownership.test.ts
T
2026-07-27 01:17:19 +00:00

51 lines
1.7 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import * as path from "node:path";
interface CacheProbeResult {
modules: number;
bytes: number;
rss: number;
heapUsed: number;
paths: string[];
}
const fixture = (name: string): string => path.resolve(import.meta.dir, "fixtures", name);
async function runProbe(childPath: string): Promise<CacheProbeResult> {
const proc = Bun.spawn([process.execPath, childPath], {
cwd: path.resolve(import.meta.dir, "../.."),
stderr: "pipe",
stdout: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
proc.exited,
]);
expect(exitCode, stderr).toBe(0);
return JSON.parse(stdout) as CacheProbeResult;
}
describe("launch xterm runtime ownership", () => {
test("cache detector observes the direct xterm positive control", async () => {
const result = await runProbe(fixture("xterm-cache-positive-control.ts"));
expect(result.modules, JSON.stringify(result)).toBe(1);
expect(result.bytes, JSON.stringify(result)).toBeGreaterThan(0);
});
test("normal main startup evaluates no xterm CommonJS module", async () => {
const result = await runProbe(fixture("xterm-cache-main-probe.ts"));
expect(result.modules, JSON.stringify(result)).toBe(0);
});
test("static Hub import evaluates no xterm CommonJS module", async () => {
const result = await runProbe(fixture("xterm-cache-hub-probe.ts"));
expect(result.modules, JSON.stringify(result)).toBe(0);
});
test("broker import owns exactly one xterm CommonJS module", async () => {
const result = await runProbe(fixture("xterm-cache-broker-probe.ts"));
expect(result.modules, JSON.stringify(result)).toBe(1);
});
});