mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
test(ida): consolidate startup diagnostics and remove fixture waits (#12994)
This commit is contained in:
1 parent
809e6bbafd
commit
a93f558d0e
2 files changed
+45
-103
No files matched your search
@@ -71,13 +71,20 @@ it("reports startup stderr drained after the handshake write fails", async () =>
|
||||
|
||||
it("keeps a failed handshake's incomplete cleanup observable with the redacted server tail", async () => {
|
||||
const child = new FixtureProcess();
|
||||
const credential = "cleanup-fixture-credential";
|
||||
let cleanupFails = true;
|
||||
let cleanupAttempts = 0;
|
||||
// A launcher can finish while its process-family cleanup is still unverified.
|
||||
child.stdin.once("finish", () => {
|
||||
child.emit("exit", 0, null);
|
||||
child.emit("close", 0, null);
|
||||
});
|
||||
// The server answers initialize with an unsupported protocol version, so the
|
||||
// SDK starts close without awaiting it while owned cleanup stays incomplete.
|
||||
createInterface({ input: child.stdin }).on("line", (line) => {
|
||||
const request = JSON.parse(line) as { id?: number; method?: string };
|
||||
if (request.method !== "initialize") return;
|
||||
child.stderr.write("server stopped: missing database\n");
|
||||
child.stderr.write(`server stopped: ${credential}\n`);
|
||||
child.stdout.write(
|
||||
`${JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
@@ -99,10 +106,9 @@ it("keeps a failed handshake's incomplete cleanup observable with the redacted s
|
||||
expectedParentPid: child.pid,
|
||||
},
|
||||
cleanup: async () => {
|
||||
cleanupAttempts += 1;
|
||||
if (cleanupFails)
|
||||
return { cleaned: false, reason: "ownership verification unavailable" };
|
||||
child.emit("exit", 0, null);
|
||||
child.emit("close", 0, null);
|
||||
return { cleaned: true, signaled: false };
|
||||
},
|
||||
});
|
||||
@@ -110,7 +116,8 @@ it("keeps a failed handshake's incomplete cleanup observable with the redacted s
|
||||
{
|
||||
command: "/opt/ida-mcp/server",
|
||||
args: [],
|
||||
env: {},
|
||||
env: { FIXTURE_CREDENTIAL: credential },
|
||||
sensitive: { env: ["FIXTURE_CREDENTIAL"], headers: [] },
|
||||
protocol: "native",
|
||||
mode: "attached",
|
||||
timeoutMs: 5000,
|
||||
@@ -118,17 +125,21 @@ it("keeps a failed handshake's incomplete cleanup observable with the redacted s
|
||||
{},
|
||||
{ platform: "darwin", launcher },
|
||||
);
|
||||
await expect(connection.connect()).rejects.toThrow();
|
||||
await expect(connection.connect()).rejects.toMatchObject({
|
||||
diagnostics: { reason: expect.stringContaining("1999-01-01") },
|
||||
});
|
||||
const failure: unknown = await connection.close().then(
|
||||
() => undefined,
|
||||
(cause: unknown) => cause,
|
||||
);
|
||||
if (!(failure instanceof ProviderCleanupError)) throw failure;
|
||||
expect(failure.cleanupIncomplete).toBe(true);
|
||||
expect(failure.capturedOutput?.stderr).toContain(
|
||||
"server stopped: missing database",
|
||||
expect(failure.capturedOutput?.stderr).toBe(
|
||||
"server stopped: [redacted transport credential]\n",
|
||||
);
|
||||
expect(cleanupAttempts).toBe(1);
|
||||
cleanupFails = false;
|
||||
await connection.close();
|
||||
expect(failure.cleanupIncomplete).toBe(false);
|
||||
expect(cleanupAttempts).toBe(2);
|
||||
});
|
||||
@@ -10,15 +10,31 @@ const launcherEnvironment = (): Readonly<Record<string, string>> => {
|
||||
return { SYSTEMROOT: systemRoot };
|
||||
};
|
||||
|
||||
const failureText = "FATAL: IDA runtime initialization failed\n";
|
||||
const tailMarker = "FATAL-END";
|
||||
|
||||
describe("IDA startup diagnostics", () => {
|
||||
it("preserves the failing launcher's stderr instead of reporting only a closed transport", async () => {
|
||||
it.each([
|
||||
{
|
||||
label: "keeps undecodable bytes when the launcher stderr fits",
|
||||
write: `Buffer.concat([Buffer.from([0x80]), Buffer.from(${JSON.stringify(failureText)})])`,
|
||||
stderr: "\ufffd" + failureText,
|
||||
bytes: 1 + Buffer.byteLength(failureText),
|
||||
truncated: false,
|
||||
},
|
||||
{
|
||||
label: "preserves the bounded tail and removes its partial UTF-8 prefix",
|
||||
write: `"discarded\\n" + "€".repeat(6000) + ${JSON.stringify(tailMarker)}`,
|
||||
stderr:
|
||||
"€".repeat(Math.floor((16384 - tailMarker.length) / 3)) + tailMarker,
|
||||
bytes: "discarded\n".length + 6000 * 3 + tailMarker.length,
|
||||
truncated: true,
|
||||
},
|
||||
])("$label", async ({ write, stderr, bytes, truncated }) => {
|
||||
const connection = createIdaMcpConnection(
|
||||
{
|
||||
command: process.execPath,
|
||||
args: [
|
||||
"-e",
|
||||
'process.stderr.write("FATAL: IDA runtime initialization failed\\n", () => process.exit(2));',
|
||||
],
|
||||
args: ["-e", `process.stderr.write(${write}, () => process.exit(2));`],
|
||||
env: launcherEnvironment(),
|
||||
mode: "headless",
|
||||
protocol: "modern",
|
||||
@@ -28,101 +44,16 @@ describe("IDA startup diagnostics", () => {
|
||||
idaConnectionDependencies(),
|
||||
);
|
||||
try {
|
||||
await expect(connection.connect()).rejects.toMatchObject({
|
||||
const failure = await connection
|
||||
.connect()
|
||||
.catch((cause: unknown) => cause);
|
||||
expect(failure).toMatchObject({
|
||||
_tag: "ProviderAdapterError",
|
||||
capturedOutput: {
|
||||
stderr: expect.stringContaining("IDA runtime initialization failed"),
|
||||
truncated: false,
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("retains only the bounded stderr tail and reports the original byte count", async () => {
|
||||
const connection = createIdaMcpConnection(
|
||||
{
|
||||
command: process.execPath,
|
||||
args: [
|
||||
"-e",
|
||||
'process.stderr.write("x".repeat(20000) + "FATAL-END", () => process.exit(2));',
|
||||
],
|
||||
env: launcherEnvironment(),
|
||||
mode: "headless",
|
||||
protocol: "modern",
|
||||
timeoutMs: 1000,
|
||||
},
|
||||
{},
|
||||
idaConnectionDependencies(),
|
||||
);
|
||||
try {
|
||||
await expect(connection.connect()).rejects.toMatchObject({
|
||||
_tag: "ProviderAdapterError",
|
||||
capturedOutput: {
|
||||
stderr: "x".repeat(16384 - "FATAL-END".length) + "FATAL-END",
|
||||
stderr_bytes: 20000 + "FATAL-END".length,
|
||||
truncated: true,
|
||||
},
|
||||
capturedOutput: { stderr, stderr_bytes: bytes, truncated },
|
||||
});
|
||||
expect(failure).not.toHaveProperty("diagnostics.upstream_stderr");
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("drops a leading partial UTF-8 character from the bounded stderr tail", async () => {
|
||||
const connection = createIdaMcpConnection(
|
||||
{
|
||||
command: process.execPath,
|
||||
args: [
|
||||
"-e",
|
||||
'process.stderr.write("€".repeat(6000), () => process.exit(2));',
|
||||
],
|
||||
env: launcherEnvironment(),
|
||||
mode: "headless",
|
||||
protocol: "modern",
|
||||
timeoutMs: 1000,
|
||||
},
|
||||
{},
|
||||
idaConnectionDependencies(),
|
||||
);
|
||||
try {
|
||||
await expect(connection.connect()).rejects.toMatchObject({
|
||||
capturedOutput: {
|
||||
stderr: "€".repeat(Math.floor(16384 / 3)),
|
||||
stderr_bytes: 18000,
|
||||
truncated: true,
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("retains an in-budget undecodable leading byte without claiming tail truncation", async () => {
|
||||
const connection = createIdaMcpConnection(
|
||||
{
|
||||
command: process.execPath,
|
||||
args: [
|
||||
"-e",
|
||||
"process.stderr.write(Buffer.from([0x80, 0x61, 0x62]), () => process.exit(2));",
|
||||
],
|
||||
env: launcherEnvironment(),
|
||||
mode: "headless",
|
||||
protocol: "modern",
|
||||
timeoutMs: 1000,
|
||||
},
|
||||
{},
|
||||
idaConnectionDependencies(),
|
||||
);
|
||||
try {
|
||||
const failure = await connection.connect().catch((cause: unknown) => cause);
|
||||
expect(failure).toMatchObject({
|
||||
capturedOutput: { stderr: "�ab", stderr_bytes: 3, truncated: false },
|
||||
});
|
||||
expect(failure).not.toHaveProperty("diagnostics.upstream_stderr");
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user