Skip to content

Commit cfe2130

Browse files
committed
test(scripts): remove duplicate parser facades
1 parent 25dda79 commit cfe2130

6 files changed

Lines changed: 14 additions & 90 deletions

‎scripts/build-all.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export const BUILD_ALL_PROFILE_STEP_ENV: Record<string, Record<string, NodeJS.Pr
402402
},
403403
};
404404

405-
export function buildAllUsage() {
405+
function buildAllUsage() {
406406
return [
407407
"Usage: node --import tsx scripts/build-all.mts [profile]",
408408
"",

‎scripts/check-gateway-watch-regression.mts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import { parseStrictNonNegativeDecimal as readNonNegativeInteger } from "./lib/n
1818
import { sleep } from "./lib/sleep.mjs";
1919
import { resolveBuildRequirement } from "./run-node.mts";
2020

21-
export { readNonNegativeInteger };
22-
2321
const DEFAULTS = {
2422
outputDir: path.join(process.cwd(), ".local", "gateway-watch-regression"),
2523
windowMs: 10_000,

‎scripts/check-memory-fd-repro.mts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { stripLeadingPackageManagerSeparator } from "./lib/arg-utils.mts";
1616
import { readBoundedResponseText } from "./lib/bounded-response.mjs";
1717
import { parseStrictNonNegativeDecimal as parseNonNegativeInteger } from "./lib/numeric-options.mjs";
1818

19-
export { parseNonNegativeInteger };
20-
2119
const ISSUE_FILE_COUNTS = [
2220
["memory/transcripts", 9394],
2321
["memory/transcripts.archived", 1695],
@@ -64,7 +62,7 @@ export const GATEWAY_READY_OUTPUT_MAX_CHARS = 128 * 1024;
6462
/**
6563
* Maximum bytes read from the memory_search HTTP response.
6664
*/
67-
export const MEMORY_SEARCH_RESPONSE_MAX_BYTES = 256 * 1024;
65+
const MEMORY_SEARCH_RESPONSE_MAX_BYTES = 256 * 1024;
6866
/**
6967
* Probe query expected to hit the synthetic top-level memory file.
7068
*/
@@ -130,7 +128,7 @@ function stripPackageManagerSeparatorForKnownFlags(argv: string[]) {
130128
/**
131129
* Parses a safe positive integer option.
132130
*/
133-
export function readPositiveNumber(value: unknown, label: string) {
131+
function readPositiveNumber(value: unknown, label: string) {
134132
const parsed = parseNonNegativeInteger(value, label);
135133
if (parsed <= 0) {
136134
throw new Error(`${label} must be greater than 0`);
@@ -583,8 +581,6 @@ export async function stopGatewayWithRuntime({
583581
/**
584582
* Reads an HTTP response body up to a configured byte limit.
585583
*/
586-
export { readBoundedResponseText };
587-
588584
function signalChild(child: StoppableGatewayChild, signal: GatewaySignal) {
589585
try {
590586
child.kill(signal);

‎test/scripts/build-all.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
BUILD_ALL_PROFILES,
1010
BUILD_ALL_PROFILE_STEP_ENV,
1111
BUILD_ALL_STEPS,
12-
buildAllUsage,
1312
finalizeBuildAllStepCache,
1413
formatBuildAllDuration,
1514
formatBuildAllTimingSummary,
@@ -351,7 +350,8 @@ describe("resolveBuildAllSteps", () => {
351350
expect(result.status).toBe(2);
352351
expect(result.stdout).toBe("");
353352
expect(result.stderr).toContain("unknown argument: --bogus");
354-
expect(result.stderr).toContain(buildAllUsage());
353+
expect(result.stderr).toContain("Usage: node --import tsx scripts/build-all.mts [profile]");
354+
expect(result.stderr).toContain("Profiles:");
355355
expect(result.stderr).not.toContain("[build-all]");
356356
expect(result.stderr).not.toContain("at ");
357357
});

‎test/scripts/check-gateway-watch-regression.test.ts‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
parseArgs,
1313
resolveTimedWatchShell,
1414
runTimedWatch,
15-
readNonNegativeInteger,
1615
shouldReportDuplicateDistRuntimeRegression,
1716
shouldRefreshBuildStampForRestoredArtifacts,
1817
stopTimedWatchChild,
@@ -34,8 +33,6 @@ describe("check-gateway-watch-regression", () => {
3433
});
3534

3635
it("parses timing and growth limits as strict non-negative integers", () => {
37-
expect(readNonNegativeInteger("0", "limit")).toBe(0);
38-
expect(readNonNegativeInteger(" 42 ", "limit")).toBe(42);
3936
expect(
4037
parseArgs([
4138
"--window-ms",
@@ -69,21 +66,15 @@ describe("check-gateway-watch-regression", () => {
6966
windowMs: 0,
7067
});
7168

72-
expect(() => readNonNegativeInteger("1.5", "limit")).toThrow(
73-
"limit must be a non-negative integer",
74-
);
75-
expect(() => readNonNegativeInteger("1e3", "limit")).toThrow(
76-
"limit must be a non-negative integer",
77-
);
78-
expect(() => readNonNegativeInteger("-1", "limit")).toThrow(
79-
"limit must be a non-negative integer",
80-
);
81-
expect(() => readNonNegativeInteger("9007199254740992", "limit")).toThrow(
82-
"limit must be a safe integer",
83-
);
84-
expect(() => parseArgs(["--window-ms", "soon"])).toThrow(
85-
"--window-ms must be a non-negative integer",
86-
);
69+
for (const [value, message] of [
70+
["1.5", "--window-ms must be a non-negative integer"],
71+
["1e3", "--window-ms must be a non-negative integer"],
72+
["-1", "--window-ms must be a non-negative integer"],
73+
["9007199254740992", "--window-ms must be a safe integer"],
74+
["soon", "--window-ms must be a non-negative integer"],
75+
] as const) {
76+
expect(() => parseArgs(["--window-ms", value])).toThrow(message);
77+
}
8778
});
8879

8980
it("recognizes current and legacy gateway ready logs", () => {

‎test/scripts/check-memory-fd-repro.test.ts‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ import { describe, expect, it, vi } from "vitest";
99
import {
1010
GATEWAY_READY_OUTPUT_MAX_CHARS,
1111
MEMORY_SEARCH_PROBE_QUERY,
12-
MEMORY_SEARCH_RESPONSE_MAX_BYTES,
1312
classifyMemorySearchInvokeResponse,
1413
hasChildExited,
1514
invokeMemorySearch,
1615
parseArgs,
17-
parseNonNegativeInteger,
18-
readBoundedResponseText,
19-
readPositiveNumber,
2016
stopGatewayWithRuntime,
2117
updateGatewayReadyOutputState,
2218
waitForGatewayReady,
@@ -41,23 +37,6 @@ async function listen(server: Server): Promise<number> {
4137
}
4238

4339
describe("check-memory-fd-repro", () => {
44-
it("parses file, fd, and timing limits as strict integers", () => {
45-
expect(parseNonNegativeInteger("0", "limit")).toBe(0);
46-
expect(parseNonNegativeInteger(" 42 ", "limit")).toBe(42);
47-
expect(readPositiveNumber("1", "limit")).toBe(1);
48-
49-
expect(() => parseNonNegativeInteger("1.5", "limit")).toThrow(
50-
"limit must be a non-negative integer",
51-
);
52-
expect(() => parseNonNegativeInteger("1e3", "limit")).toThrow(
53-
"limit must be a non-negative integer",
54-
);
55-
expect(() => parseNonNegativeInteger("10files", "limit")).toThrow(
56-
"limit must be a non-negative integer",
57-
);
58-
expect(() => readPositiveNumber("0", "limit")).toThrow("limit must be greater than 0");
59-
});
60-
6140
it("rejects loose numeric environment limits before generating files", () => {
6241
expect(
6342
withEnv(
@@ -384,44 +363,4 @@ describe("check-memory-fd-repro", () => {
384363
expect(state.readySeen).toBe(true);
385364
expect(state.tail).toBe("w output");
386365
});
387-
388-
it("reads memory_search response bodies under the byte cap", async () => {
389-
await expect(
390-
readBoundedResponseText(
391-
new Response("ok"),
392-
"memory_search",
393-
MEMORY_SEARCH_RESPONSE_MAX_BYTES,
394-
),
395-
).resolves.toBe("ok");
396-
});
397-
398-
it("rejects oversized memory_search response bodies from content-length", async () => {
399-
const response = new Response("ignored", {
400-
headers: { "content-length": String(MEMORY_SEARCH_RESPONSE_MAX_BYTES + 1) },
401-
});
402-
403-
await expect(
404-
readBoundedResponseText(response, "memory_search", MEMORY_SEARCH_RESPONSE_MAX_BYTES),
405-
).rejects.toThrow(
406-
`memory_search response body exceeded ${MEMORY_SEARCH_RESPONSE_MAX_BYTES} bytes`,
407-
);
408-
});
409-
410-
it("stops reading memory_search response streams after the byte cap", async () => {
411-
const chunk = new Uint8Array(MEMORY_SEARCH_RESPONSE_MAX_BYTES + 1);
412-
const response = new Response(
413-
new ReadableStream({
414-
start(controller) {
415-
controller.enqueue(chunk);
416-
controller.close();
417-
},
418-
}),
419-
);
420-
421-
await expect(
422-
readBoundedResponseText(response, "memory_search", MEMORY_SEARCH_RESPONSE_MAX_BYTES),
423-
).rejects.toThrow(
424-
`memory_search response body exceeded ${MEMORY_SEARCH_RESPONSE_MAX_BYTES} bytes`,
425-
);
426-
});
427366
});

0 commit comments

Comments
 (0)