From 809e6bbafd7815c7767b4e2f1ff9c61f7453e93e Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:35:41 -0500 Subject: [PATCH] test(ida): consolidate readiness and regex deadline checks (#12992) --- src/ida/IdaBusyHealth.test.ts | 23 ++--- src/ida/IdaProvider.test.ts | 7 ++ src/ida/IdaSessionClient.test.ts | 165 ++++++++----------------------- 3 files changed, 59 insertions(+), 136 deletions(-) diff --git a/src/ida/IdaBusyHealth.test.ts b/src/ida/IdaBusyHealth.test.ts index 4674f4150f..8b88ca0ea6 100644 --- a/src/ida/IdaBusyHealth.test.ts +++ b/src/ida/IdaBusyHealth.test.ts @@ -4,9 +4,9 @@ import type { JsonValue } from "../domain/jsonValue.js"; import type { IdaMcpConnection } from "./IdaMcpConnection.js"; import { readSettledHealth } from "./IdaBusyHealth.js"; -const busy = (tool: string): JsonValue => ({ +const busy = (tool?: string): JsonValue => ({ status: "busy", - busy_tool: tool, + ...(tool === undefined ? {} : { busy_tool: tool }), busy_sec: 0, queued_calls: 0, }); @@ -112,8 +112,11 @@ it("clamps the last pause to the remaining budget and stops without another read }); }); -it("does not read again when the only pause consumes the whole budget", async () => { - const { connection, reads } = scripted([busy("config_json_get")]); +it.each([ + ["omitted", undefined], + ["over-length", "x".repeat(200)], +])("reports an %s busy tool as unknown", async (_label, tool) => { + const { connection, reads } = scripted([busy(tool)]); const { clock } = virtualClock(); const failure = await readSettledHealth(connection, { @@ -121,13 +124,11 @@ it("does not read again when the only pause consumes the whole budget", async () timeoutMs: 100, clock, }).catch((cause: unknown) => cause); - - expect(reads.length, "the single read before the pause is the only one").toBe( - 1, - ); - expect(failure, "the last busy payload ends the wait").toMatchObject({ - _tag: "AnalysisTimeoutError", - }); + if (!(failure instanceof AnalysisTimeoutError)) throw failure; + expect(failure.diagnostics).toMatchObject({ busy_tool: "unknown" }); + expect(failure.userMessage).toContain("busy tool was unknown"); + if (tool !== undefined) expect(failure.userMessage).not.toContain(tool); + expect(reads).toHaveLength(1); }); it("reports the busy tool of the last observation", async () => { diff --git a/src/ida/IdaProvider.test.ts b/src/ida/IdaProvider.test.ts index 991674b2eb..13f2f681c1 100644 --- a/src/ida/IdaProvider.test.ts +++ b/src/ida/IdaProvider.test.ts @@ -448,6 +448,13 @@ it("applies runtime regex budgets through a bound IDA client and recovers in the expect(failed).toMatchObject({ ok: false, error: { + _tag: "AnalysisResourceConstraintError", + operation: "search_strings", + resource: "cpu", + reportedLimits: { + matching_deadline_ms: 100, + matching_deadline_source: "runtime", + }, limit: { setting: "regex.matching_deadline_ms", effective_value: 100, diff --git a/src/ida/IdaSessionClient.test.ts b/src/ida/IdaSessionClient.test.ts index 610f856782..a6885c8e2c 100644 --- a/src/ida/IdaSessionClient.test.ts +++ b/src/ida/IdaSessionClient.test.ts @@ -21,10 +21,7 @@ import { } from "../../tests/fixtures/idaMcp.js"; import { nativeTools } from "./IdaNativeProtocol.js"; import { IdaSessionClient } from "./IdaSessionClient.js"; -import { - DEFAULT_REGEX_MATCHING_DEADLINE, - REGEX_MATCHING_DEADLINE_SETTING, -} from "../config/regexMatchingDeadline.js"; +import { DEFAULT_REGEX_MATCHING_DEADLINE } from "../config/regexMatchingDeadline.js"; import { functionDossierSchema } from "../domain/native/functionDossier.js"; import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js"; import { @@ -673,6 +670,14 @@ describe("attached IDA function observations", () => { ] as const) { const found = await client.execute("search_strings", { pattern, mode }); expect(found.ok && found.value.result).toHaveLength(count); + if (mode === "regex" && found.ok) { + const { deadlineMs } = DEFAULT_REGEX_MATCHING_DEADLINE; + expect(found.value.limitations).toContainEqual( + expect.stringContaining( + `${deadlineMs} ms matching deadline (source default)`, + ), + ); + } } const invalid = await client.execute("search_strings", { pattern: "[", @@ -792,51 +797,6 @@ describe("attached IDA regex supervision", () => { } }, ); - it("bounds regex matching without caller cancellation and preserves subsequent searches", async () => { - const { producer, client } = await fixture(); - const value = "a".repeat(40) + "!"; - producer.overrideCall = (name) => - name === "find_regex" - ? { - matches: [{ addr: "0x3000", string: value }], - cursor: { done: true }, - } - : undefined; - try { - const result = await client.execute("search_strings", { - pattern: "^(a+)+$", - mode: "regex", - }); - expect(result.ok).toBe(false); - if ( - result.ok || - !(result.error instanceof AnalysisResourceConstraintError) - ) - throw new Error("Expected a supervised regex deadline"); - expect(result.error).toMatchObject({ - operation: "search_strings", - resource: "cpu", - reportedLimits: { - matching_deadline_ms: DEFAULT_REGEX_MATCHING_DEADLINE.deadlineMs, - matching_deadline_source: DEFAULT_REGEX_MATCHING_DEADLINE.source, - }, - }); - expect(result.error.message).toContain(REGEX_MATCHING_DEADLINE_SETTING); - const recovered = await client.execute("search_strings", { - pattern: "!$", - mode: "regex", - }); - expect(recovered.ok && recovered.value.result).toEqual([ - expect.objectContaining({ address: "0x3000", value }), - ]); - if (recovered.ok) - expect(recovered.value.limitations.join("\n")).toContain( - REGEX_MATCHING_DEADLINE_SETTING, - ); - } finally { - await client.close(); - } - }); }); describe("attached IDA function failure handling", () => { @@ -982,10 +942,7 @@ describe("headless IDA transient busy health", () => { const busy = busyHealth("config_json_get"); producer.overrideCall = (name) => name === "server_health" ? busy : undefined; - const started = Date.now(); - const result = await client.execute("health", {}); - const elapsed = Date.now() - started; if (result.ok) throw new Error("expected a busy timeout"); expect(result.error._tag, "the neutral timeout class is used").toBe( @@ -1007,10 +964,7 @@ describe("headless IDA transient busy health", () => { projected.message, "the public error message names the busy tool", ).toContain("config_json_get"); - expect( - `${result.error.message} ${projected.message}`, - "no Hopper wording leaks in", - ).not.toContain("Hopper"); + expect(projected.remediation.action).toContain("REA_IDA_MCP_CONFIG"); expect( result.error.cause, "reattribution preserves the producing timeout", @@ -1020,90 +974,51 @@ describe("headless IDA transient busy health", () => { cause: busy, diagnostics: { busy_tool: "config_json_get" }, }); - expect( - elapsed, - "the wait runs to the deadline, not less", - ).toBeGreaterThanOrEqual(290); - expect( - healthCalls(producer), - "reads are spaced by the retry delay, not a tight loop", - ).toBeLessThanOrEqual(6); await expectCleanClose(producer, client); }); - it("never invents a busy tool the worker did not report", async () => { + it("reports free-form busy text as unknown without exposing it in the error message", async () => { const { producer, client } = await fixture("headless", 300); + const tool = "token=abc123 /private secret"; producer.overrideCall = (name) => - name === "server_health" ? busyHealth() : undefined; + name === "server_health" ? busyHealth(tool) : undefined; const result = await client.execute("health", {}); - - if (result.ok) throw new Error("expected a busy timeout"); - expect( - projectAnalysisError(result.error).details, - "the public operation stays independent of an omitted busy tool", - ).toMatchObject({ - operation: "health", - }); + if (result.ok) throw new Error("Expected a busy timeout"); + const projected = projectAnalysisError(result.error); + expect(projected.details).toMatchObject({ operation: "health" }); expect(result.error.diagnostics).toMatchObject({ busy_tool: "unknown" }); - expect(projectAnalysisError(result.error).message).toContain( - "busy tool was unknown", - ); + expect(projected.message).toContain("busy tool was unknown"); + expect(projected.message).not.toContain(tool); await expectCleanClose(producer, client); }); - it.each([ - ["free-form text", "token=abc123 /private secret"], - ["an over-long name", "x".repeat(200)], - ])( - "reports %s from the worker as unknown instead of echoing it", - async (_label, tool) => { - const { producer, client } = await fixture("headless", 300); - producer.overrideCall = (name) => - name === "server_health" ? busyHealth(tool) : undefined; - - const result = await client.execute("health", {}); - - if (result.ok) throw new Error("expected a busy timeout"); - expect( - projectAnalysisError(result.error).details, - "only a tool-name-shaped value is repeated", - ).toMatchObject({ - operation: "health", - }); - expect(result.error.diagnostics).toMatchObject({ busy_tool: "unknown" }); - expect( - projectAnalysisError(result.error).message, - "the producer text never reaches the public error message", - ).not.toContain(tool); - await expectCleanClose(producer, client); - }, - ); - - it("ends the wait at once when the caller aborts", async () => { + it("cancels a busy readiness wait before another read", async () => { const { producer, client } = await fixture("headless", 30_000); - producer.overrideCall = (name) => - name === "server_health" ? busyHealth("config_json_get") : undefined; + const secondBusy = phaseArrival(); + producer.overrideCall = (name) => { + if (name !== "server_health") return undefined; + const reads = healthCalls(producer); + if (reads === 2) secondBusy.arrive(); + if (reads > 2) throw new Error("Readiness polled after cancellation"); + return busyHealth("config_json_get"); + }; const controller = new AbortController(); - const started = Date.now(); + const reason = { request: "cancel busy IDA readiness" }; const call = client.execute("health", {}, { signal: controller.signal }); - while (healthCalls(producer) < 2) { - if (Date.now() - started > 5_000) throw new Error("never polled"); - await new Promise((resolve) => setTimeout(resolve, 10)); + try { + await secondBusy.reached(call, "second busy health response"); + controller.abort(reason); + const result = await call; + if (result.ok) throw new Error("Expected a cancelled busy wait"); + expect(result.error._tag).toBe("AnalysisCancelledError"); + expect(result.error.cause).toBe(reason); + expect(healthCalls(producer)).toBe(2); + await expectCleanClose(producer, client); + } finally { + controller.abort(reason); + await call.finally(() => client.close()); } - - controller.abort(); - const result = await call; - - if (result.ok) throw new Error("expected cancellation"); - expect(result.error._tag, "cancellation keeps today's outcome").toBe( - "AnalysisCancelledError", - ); - expect( - Date.now() - started, - "the wait does not run to the registration deadline", - ).toBeLessThan(5_000); - await expectCleanClose(producer, client); }); });