Files
rea/tests/boundary/providers/hopper/hopperClient.diagnostics.test.ts
T
morluto ba056e08a4 fix(providers): bound launcher diagnostics without losing byte counts
Give Ghidra and Hopper an 8 MiB aggregate retained-output budget while continuing to drain their process pipes. Expose total observed bytes at the supervisor boundary and retained bytes plus explicit truncation in provider diagnostics.

Redact known transport tokens even when the retained prefix ends inside one, preserving adjacent caller path/query evidence. Existing partial-launch and cleanup ownership remain intact.

Validation: 285 tests across 34 focused suites passed; the final cutoff-fixture refinement passed all 31 Ghidra/Hopper diagnostic tests. check:fast and architecture guards passed. Provider fixtures use real child processes; real Ghidra/Hopper applications were not verified.
2026-10-11 02:50:06 +08:00

89 lines
3.2 KiB
TypeScript

import { access } from "node:fs/promises";
import { expect, it, onTestFinished, vi } from "vitest";
import { HopperTimeoutError } from "../../../../src/domain/hopperErrors.js";
import {
HopperClient,
HOPPER_PROCESS_DIAGNOSTIC_BYTES,
} from "../../../../src/hopper/HopperClient.js";
import { HopperFixtureLauncher } from "./hopperClient.fixture.js";
it("bounds long-lived launcher output while keeping the bridge usable", async () => {
let observedStderrBytes = 0;
const diagnosticLauncher = new HopperFixtureLauncher(undefined, "noisy");
const client = new HopperClient({
launcher: diagnosticLauncher,
startupTimeoutMs: 10_000,
onDiagnostic(event) {
if (event.type === "launcher-stderr") observedStderrBytes += event.bytes;
},
});
onTestFinished(async () => {
await client.close();
});
await expect(client.start()).resolves.toMatchObject({ ok: true });
const session = await client.callTool("echo", { value: "still usable" });
expect(session).toEqual({ ok: true, value: { value: "still usable" } });
await vi.waitFor(() => {
expect(observedStderrBytes).toBeGreaterThan(
HOPPER_PROCESS_DIAGNOSTIC_BYTES,
);
});
await client.close();
const directory = diagnosticLauncher.directories[0] ?? "";
await expect(access(directory)).rejects.toMatchObject({ code: "ENOENT" });
expect(diagnosticLauncher.processes[0]?.exitCode).not.toBeNull();
});
it("reports observed and retained output when capture cuts a token", async () => {
const diagnosticLauncher = new HopperFixtureLauncher(
undefined,
"noisy_no_socket",
);
const client = new HopperClient({
launcher: diagnosticLauncher,
startupTimeoutMs: 1_000,
});
onTestFinished(async () => {
await client.close();
});
const started = await client.start();
if (started.ok || !(started.error instanceof HopperTimeoutError))
throw new Error("Expected the no-socket fixture to time out");
const outcome = started.error.launcherOutcome;
expect(outcome).toMatchObject({ diagnostic_truncated: true });
if (outcome === undefined) throw new Error("Launcher outcome was omitted");
expect(outcome.stdout.bytes + outcome.stderr.bytes).toBeGreaterThan(
HOPPER_PROCESS_DIAGNOSTIC_BYTES,
);
expect(
outcome.stdout.retained_bytes + outcome.stderr.retained_bytes,
).toBeLessThanOrEqual(HOPPER_PROCESS_DIAGNOSTIC_BYTES);
expect(outcome.stdout.bytes).toBeGreaterThanOrEqual(
outcome.stdout.retained_bytes,
);
expect(outcome.stderr.bytes).toBeGreaterThanOrEqual(
outcome.stderr.retained_bytes,
);
expect(outcome.stderr.retained_bytes).toBe(HOPPER_PROCESS_DIAGNOSTIC_BYTES);
const token = diagnosticLauncher.tokens[0] ?? "";
expect(JSON.stringify(outcome)).not.toContain(token);
expect(`${outcome.stdout.text}${outcome.stderr.text}`).toContain(
"[redacted transport credential]",
);
expect(
outcome.stderr.text.endsWith(
"source=/tmp/local-evidence.bin?cursor=keep&[redacted transport credential]",
),
).toBe(true);
await client.close();
const directory = diagnosticLauncher.directories[0] ?? "";
await expect(access(directory)).rejects.toMatchObject({ code: "ENOENT" });
expect(diagnosticLauncher.processes[0]?.exitCode).not.toBeNull();
});