Files
reverse-engineering-anything/src/domain/native/nativeDeadlines.test.ts
T
morluto 8443930bd3 refactor(limits): declare the Node timer bound and duration schema once (#10640)
* refactor(limits): declare the Node timer bound and duration schema once

Fifteen modules re-declared 2_147_483_647 as their own timer maximum and
eleven built the same 1..2^31-1 millisecond schema. They now use
MAX_NODE_TIMER_DELAY_MS and timerDurationMsSchema from
src/domain/analysisResourceLimits.ts, and an architecture guard rejects the
literal outside that owner and five non-timer int32 bounds. The generated
MCP tool catalog is byte-identical.

* refactor(limits): keep the JVM processor-count bound separate from the timer bound

REA_JADX_ACTIVE_PROCESSOR_COUNT is a Java int count, not a timer delay, so it keeps its own named bound and a documented exception in the signed 32-bit guard. Remove the timer-bound and zod imports the duration-schema migration left unused.

* refactor(limits): keep the TShark packet-count bound separate from the timer bound

packet_limit is passed to TShark's -c as a C int packet count, not a timer delay, so it keeps its own named bound and a documented exception in the signed 32-bit guard.
2026-11-15 16:40:03 +08:00

51 lines
1.6 KiB
TypeScript

import { MAX_NODE_TIMER_DELAY_MS } from "../analysisResourceLimits.js";
import { expect, it } from "vitest";
import {
DEFAULT_NATIVE_COMMAND_TIMEOUT_MS,
DEFAULT_NATIVE_UI_DEADLINE_MS,
DEFAULT_PWNTOOLS_TIMEOUT_MS,
nativeCommandTimeoutField,
nativeUiDeadlineField,
pwntoolsTimeoutField,
readNativeDeadline,
} from "./nativeDeadlines.js";
it("keeps today's omitted native deadlines and the shared timer range", () => {
expect(DEFAULT_NATIVE_COMMAND_TIMEOUT_MS).toBe(60_000);
expect(DEFAULT_NATIVE_UI_DEADLINE_MS).toBe(180_000);
expect(DEFAULT_PWNTOOLS_TIMEOUT_MS).toBe(30_000);
expect(MAX_NODE_TIMER_DELAY_MS).toBe(2_147_483_647);
for (const field of [
nativeCommandTimeoutField,
nativeUiDeadlineField,
pwntoolsTimeoutField,
]) {
expect(field.safeParse(undefined).success).toBe(true);
expect(field.safeParse(1).success).toBe(true);
expect(field.safeParse(MAX_NODE_TIMER_DELAY_MS).success).toBe(true);
expect(field.safeParse(0).success).toBe(false);
expect(field.safeParse(MAX_NODE_TIMER_DELAY_MS + 1).success).toBe(false);
expect(field.safeParse(1.5).success).toBe(false);
}
});
it("reads an omitted deadline as the caller-supplied default", () => {
expect(readNativeDeadline(undefined, 60_000)).toEqual({
ok: true,
timeoutMs: 60_000,
});
expect(readNativeDeadline(2_500, 60_000)).toEqual({
ok: true,
timeoutMs: 2_500,
});
expect(readNativeDeadline(0, 60_000)).toMatchObject({
ok: false,
reason: "out_of_range",
});
expect(readNativeDeadline("60000", 60_000)).toMatchObject({
ok: false,
reason: "invalid_type",
});
});