Files
reverse-engineering-anything/tests/boundary/signals/decoderDiscovery.test.ts
T
morluto fb5b6d4abb test: assert the refusal each MCP, boundary and verifier check expects (#15531)
Replace bare toThrow() across the MCP, CLI and other boundary tests, the
Hopper and fixture conformance verifiers, the evaluation guards and the
process-global tests with the SDK cancellation code and reason, schema
issue paths, tagged error reasons, cleanup facts, errno codes and
verifier messages each case is meant to refuse.
2026-12-01 17:02:41 +00:00

98 lines
3.0 KiB
TypeScript

import { expect, it } from "vitest";
import {
inspectSignalDecodersInputSchema,
SIGNAL_DECODER_PAGE_RECORDS,
} from "../../../src/domain/signals/signalDecoders.js";
import { parseDecoderDiscovery } from "../../../src/signals/parseDecoderDiscovery.js";
it("rejects malformed catalogs and the wrong decoder identity", () => {
for (const [text, failure] of [
["", "sigrok decoder catalog heading is missing"],
[
"Supported protocol decoders:\n",
"sigrok returned an empty decoder catalog",
],
[
"Supported protocol decoders:\n uart UART\n uart Duplicate",
"Malformed or duplicate sigrok decoder catalog record",
],
[
"Supported protocol decoders:\n malformed",
"Malformed or duplicate sigrok decoder catalog record",
],
] as const) {
expect(() =>
parseDecoderDiscovery(
text,
inspectSignalDecodersInputSchema.parse({ limit: 1 }),
),
).toThrow(failure);
}
expect(() =>
parseDecoderDiscovery(
"ID: spi\nOptions:",
inspectSignalDecodersInputSchema.parse({ decoder: "uart" }),
),
).toThrow("Decoder help does not identify the selected decoder");
});
it("keeps help line ordinals, blank lines and literal special characters through selection", () => {
const text = "ID: uart\r\nOptions:\r\n\r\n- mode: A[0] (default 'x')\r\n";
const result = parseDecoderDiscovery(
text,
inspectSignalDecodersInputSchema.parse({
decoder: "uart",
query: "[0]",
offset: 0,
limit: 1,
}),
);
expect(result.help_lines).toEqual([
{ line_number: 4, text: "- mode: A[0] (default 'x')" },
]);
expect(result.output_window.examined).toBe(4);
});
it("ends a help page at the page record budget without refusing longer output", () => {
const text = "ID: uart" + "\n".repeat(SIGNAL_DECODER_PAGE_RECORDS + 4);
const all = parseDecoderDiscovery(
text,
inspectSignalDecodersInputSchema.parse({ decoder: "uart", limit: null }),
);
expect(all.help_lines).toHaveLength(SIGNAL_DECODER_PAGE_RECORDS);
expect(all.output_window).toEqual({
unit: "help-lines",
examined: SIGNAL_DECODER_PAGE_RECORDS + 4,
matching: SIGNAL_DECODER_PAGE_RECORDS + 4,
returned: SIGNAL_DECODER_PAGE_RECORDS,
has_more: true,
record_budget_reached: true,
});
expect(
parseDecoderDiscovery(
text,
inspectSignalDecodersInputSchema.parse({
decoder: "uart",
offset: SIGNAL_DECODER_PAGE_RECORDS,
limit: null,
}),
),
).toEqual({
decoders: [],
help_lines: [
{ line_number: SIGNAL_DECODER_PAGE_RECORDS + 1, text: "" },
{ line_number: SIGNAL_DECODER_PAGE_RECORDS + 2, text: "" },
{ line_number: SIGNAL_DECODER_PAGE_RECORDS + 3, text: "" },
{ line_number: SIGNAL_DECODER_PAGE_RECORDS + 4, text: "" },
],
output_window: {
unit: "help-lines",
examined: SIGNAL_DECODER_PAGE_RECORDS + 4,
matching: SIGNAL_DECODER_PAGE_RECORDS + 4,
returned: 4,
has_more: false,
record_budget_reached: false,
},
});
});