Skip to content
10 changes: 9 additions & 1 deletion scripts/dev-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,16 @@ check_quiet_command() {
local remediation="$2"
shift 2

if "$@" >/dev/null 2>&1; then
# Capture output to classify the failure. Only match against it; never print
# it, because a failing command can name paths the report should not carry.
local output
if output="$("$@" 2>&1)"; then
pass "${label}"
elif printf '%s' "${output}" | grep -q 'JavaScript heap out of memory'; then
# Node.js derives its default old-space limit from host memory, so this
# reports the host size rather than a fault in the checked sources.
fail "${label}: ran out of Node.js heap" \
"Raise the limit, then rerun: export NODE_OPTIONS=--max-old-space-size=5120"
else
fail "${label}: failed" "${remediation}"
fi
Expand Down
34 changes: 34 additions & 0 deletions test/dev-setup-doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,40 @@ describe("contributor environment doctor", () => {
expect(result.output).toContain("Next: Run: npm run build:cli");
});

it("names the Node.js heap limit when a type check exhausts it (#8688)", () => {
const fixture = createFixture();
writeExecutable(
path.join(fixture.repo, "node_modules", ".bin", "tsc"),
[
"#!/usr/bin/env bash",
"echo 'tsc-path-that-must-not-be-reported'",
"echo 'FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory' >&2",
"exit 134",
].join("\n"),
);

const result = runDoctor(fixture);

expect(result.status).toBe(1);
expect(result.output).toContain("CLI type check: ran out of Node.js heap");
expect(result.output).toContain("--max-old-space-size=5120");
expect(result.output).not.toContain("tsc-path-that-must-not-be-reported");
});

it("keeps the build remediation when a type check fails for another reason (#8688)", () => {
const fixture = createFixture();
writeExecutable(
path.join(fixture.repo, "node_modules", ".bin", "tsc"),
["#!/usr/bin/env bash", "echo 'error TS2304: Cannot find name.' >&2", "exit 2"].join("\n"),
);

const result = runDoctor(fixture);

expect(result.status).toBe(1);
expect(result.output).toContain("CLI type check: failed");
expect(result.output).toContain("Next: Run: npm run typecheck:cli");
});

it("redacts failed GitHub and Docker command output", () => {
const fixture = createFixture();

Expand Down
Loading