Skip to content
Merged
45 changes: 45 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,48 @@ its test, the `--preload` flag in both runners, and the "Fast Tests" note that
documents the override. Confirm the suite's slow-test report
(`SLOW_TEST_THRESHOLD_MS`) doesn't regress. Start points: `fast-expect.ts` for
what it did and why, and grep `\.toContain(` under `test/` for the call sites.

## Code-quality detector & test-strengthening follow-ups (from PR #1729)

*Origin: CodeRabbit review of PR #1729, deferred as out of scope for that
complexity-only refactor (which had to preserve behavior). All three are
pre-existing behaviors carried over unchanged from `main`, not regressions.*

### 1. `skipTypeParams` should not treat the `>` in `=>` as a closing angle bracket

`test/lib/code-quality/detectors.ts` — `skipTypeParams` counts every `>` as a
type-parameter close, so a type alias whose params contain an arrow default,
e.g. `type A<T = () => void> = { ... }`, is parsed as ending at the arrow and
`parseTypeAliasBody` silently ignores the (valid) alias. The sibling helper
`angleDepthDelta` already handles this token correctly (it ignores a `>`
preceded by `=`).

Fix direction: reuse `angleDepthDelta` in `skipTypeParams`. Note the naive
rewrite reintroduces an unreachable `return i` fall-through that fails the
repo's 100% line/branch coverage gate — so the fix must be paired with a
covering test that exercises an arrow-in-type-param alias (and keep the
fall-through on the covered path, as the current loop-with-`break` form does).

### 2. `skipTemplateSubstitution` should skip comment contents

`test/lib/code-quality/detectors.ts` — the template-substitution scanner tracks
brace depth but does not skip comments, so a `}` inside a comment inside a
`${...}` prematurely closes the substitution; a later nested backtick can then
end the outer template early and leak commas into `parseArgList`. Repro shape:
`` `${/* } */ `x,y`}` ``.

Fix direction: within the depth loop, skip line/block comments (a `skipComment`
helper) before the brace-depth checks, and add a direct regression test for the
comment-with-`}`-then-nested-template case asserting `parseArgList` doesn't
misinterpret the comma.

### 3. `foldOutcomeValid` should assert rejected folds preserve the prior quantity

`test/lib/fold-tree.test.ts` — for the above-cap (rejected) case the validator
checks `recordedQty !== running`, which only proves the quantity wasn't clamped
to the attempted total; it doesn't prove the rejected fold left the *prior*
recorded quantity unchanged.

Fix direction: capture the recorded quantity before calling `foldChild`, thread
it into `foldOutcomeValid`, and assert exact equality against that pre-fold
value for rejected outcomes (retaining the accepted-case checks).
19 changes: 3 additions & 16 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
"useTemplate": "error"
},
"suspicious": {
"noAssignInExpressions": "off",
"noAssignInExpressions": "error",
"noConsole": "error",
"noDoubleEquals": "error",
"noExplicitAny": "off",
"noFocusedTests": "error",
"noImplicitAnyLet": "off",
"noImplicitAnyLet": "error",
"noSkippedTests": "error",
"noVar": "error"
}
Expand All @@ -92,14 +92,6 @@
"includes": ["test/**/*.js", "test/**/*.ts", "test/**/*.tsx"],
"linter": {
"rules": {
"complexity": {
"noExcessiveCognitiveComplexity": {
"level": "error",
"options": {
"maxAllowedComplexity": 30
}
}
},
"correctness": {
"noUnusedFunctionParameters": "off",
"noUnusedVariables": "off"
Expand Down Expand Up @@ -129,13 +121,8 @@
"includes": ["scripts/**/*.ts"],
"linter": {
"rules": {
"complexity": {
"noExcessiveCognitiveComplexity": "off"
},
"suspicious": {
"noAssignInExpressions": "off",
"noConsole": "off",
"noImplicitAnyLet": "off"
"noConsole": "off"
Comment thread
stefan-burke marked this conversation as resolved.
Resolved
}
}
}
Expand Down
76 changes: 53 additions & 23 deletions scripts/compact-test-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,68 @@ const readYamlBlockScalar = (
return stripCommonIndent(block).trimEnd();
};

const parseYamlTapDiagnostic = (text: string): TapDiagnostic | undefined => {
const lines = text.split(/\r?\n/);
const diagnostic: TapDiagnostic = {};

const parseYamlMessage = (lines: string[]): string | undefined => {
for (let index = 0; index < lines.length; index++) {
const match = lines[index]?.match(/^(\s*)message:\s*(.*)$/);
if (!match) continue;
const value = match[2]?.trim() ?? "";
const baseIndent = (match[1] ?? "").length;
diagnostic.message =
value.startsWith("|") || value.startsWith(">")
? readYamlBlockScalar(lines, index, baseIndent)
: parseYamlScalar(value);
break;
return value.startsWith("|") || value.startsWith(">")
? readYamlBlockScalar(lines, index, baseIndent)
: parseYamlScalar(value);
}
return undefined;
};

type AtFieldAssign = (
at: NonNullable<TapDiagnostic["at"]>,
value: string,
) => void;

const AT_FIELD_ASSIGNERS: Record<string, AtFieldAssign | undefined> = {
column: (at, value) => {
at.column = Number(value);
},
file: (at, value) => {
at.file = value;
},
line: (at, value) => {
at.line = Number(value);
},
};

const assignAtField = (
at: NonNullable<TapDiagnostic["at"]>,
key: string,
value: string,
): void => {
AT_FIELD_ASSIGNERS[key]?.(at, value);
};

const parseYamlAt = (lines: string[]): TapDiagnostic["at"] | undefined => {
const atIndex = lines.findIndex((line) => /^(\s*)at:\s*$/.test(line));
if (atIndex !== -1) {
const atIndent = leadingWhitespaceLength(lines[atIndex] ?? "");
const at: TapDiagnostic["at"] = {};
for (const line of lines.slice(atIndex + 1)) {
if (line.trim() && leadingWhitespaceLength(line) <= atIndent) break;
const match = line.match(/^\s*(file|line|column):\s*(.*)$/);
if (!match) continue;
const key = match[1];
const value = parseYamlScalar(match[2] ?? "");
if (key === "file") at.file = value;
if (key === "line") at.line = Number(value);
if (key === "column") at.column = Number(value);
}
diagnostic.at = at;
if (atIndex === -1) return undefined;

const atIndent = leadingWhitespaceLength(lines[atIndex] ?? "");
const at: NonNullable<TapDiagnostic["at"]> = {};
for (const line of lines.slice(atIndex + 1)) {
if (line.trim() && leadingWhitespaceLength(line) <= atIndent) break;
const match = line.match(/^\s*(file|line|column):\s*(.*)$/);
if (!match) continue;
assignAtField(at, match[1] ?? "", parseYamlScalar(match[2] ?? ""));
}
return at;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const parseYamlTapDiagnostic = (text: string): TapDiagnostic | undefined => {
const lines = text.split(/\r?\n/);
const diagnostic: TapDiagnostic = {};

const message = parseYamlMessage(lines);
if (message !== undefined) diagnostic.message = message;

const at = parseYamlAt(lines);
if (at !== undefined) diagnostic.at = at;

return diagnostic.message || diagnostic.at ? diagnostic : undefined;
};
Expand Down
124 changes: 78 additions & 46 deletions scripts/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,44 @@ interface ParsedArgs {
useHarness: boolean;
}

const parseArgs = (args: string[]): ParsedArgs => {
const parsed: ParsedArgs = {
error: null,
exhaustive: false,
help: false,
sources: [],
tests: [],
timeout: DEFAULT_TIMEOUT,
useHarness: false,
};
const positional: string[] = [];
let index = 0;
while (index < args.length) {
const arg = args[index];
const next = args[index + 1];
if (arg === "--exhaustive") parsed.exhaustive = true;
else if (arg === "--harness") parsed.useHarness = true;
else if (arg === "-h" || arg === "--help") parsed.help = true;
else if (arg === "--source" && next !== undefined) {
parsed.sources.push(next);
index += 1;
} else if (arg === "--test" && next !== undefined) {
parsed.tests.push(next);
index += 1;
} else if (arg === "--timeout" && next !== undefined) {
parsed.timeout = Number(next);
index += 1;
} else if (arg === "--jobs" && next !== undefined) {
parsed.batchJobs = Number(next);
index += 1;
} else if (arg !== undefined) positional.push(arg);
index += 1;
}
if (parsed.sources.length > 0 || parsed.tests.length > 0) {
type ValueFlagApply = (parsed: ParsedArgs, value: string) => void;

/** Options that take a value; maps the flag to how it records `next` on `parsed`. */
const VALUE_FLAGS: Record<string, ValueFlagApply | undefined> = {
"--jobs": (parsed, value) => {
parsed.batchJobs = Number(value);
},
"--source": (parsed, value) => parsed.sources.push(value),
"--test": (parsed, value) => parsed.tests.push(value),
"--timeout": (parsed, value) => {
parsed.timeout = Number(value);
},
};

/**
* Apply a single argument to `parsed` (or collect it as positional). Returns
* true when it also consumed `next` as the flag's value.
*/
const applyArg = (
parsed: ParsedArgs,
positional: string[],
arg: string,
next: string | undefined,
): boolean => {
if (arg === "--exhaustive") parsed.exhaustive = true;
else if (arg === "--harness") parsed.useHarness = true;
else if (arg === "-h" || arg === "--help") parsed.help = true;
else if (VALUE_FLAGS[arg] !== undefined && next !== undefined) {
VALUE_FLAGS[arg]?.(parsed, next);
return true;
} else positional.push(arg);
return false;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/** Fold positional arguments into `parsed`, recording an error on misuse. */
const applyPositionals = (parsed: ParsedArgs, positional: string[]): void => {
const usedFlagForm = parsed.sources.length > 0 || parsed.tests.length > 0;
if (usedFlagForm) {
// Flag-form was used: positionals are not part of the grammar. Any leftover
// means a glob expanded past the single value --source/--test consumed
// (e.g. `--source src/*.ts` → src/a.ts src/b.ts …), which would silently
Expand All @@ -105,26 +109,54 @@ const parseArgs = (args: string[]): ParsedArgs => {
"A glob likely expanded to multiple files — quote it " +
`(e.g. --source 'src/lib/forms/*.ts') or pass repeated --source/--test flags.`;
}
} else {
if (positional[0] !== undefined) parsed.sources.push(positional[0]);
if (positional[1] !== undefined) parsed.tests.push(positional[1]);
if (positional.length > 2) {
parsed.error =
`Too many positional arguments (${positional.length}). Quote your globs ` +
`so the shell can't expand them — e.g. 'src/lib/forms/*.ts' ` +
`'test/lib/forms/*.test.ts' — or pass repeated --source/--test flags.`;
}
return;
}
if (positional[0] !== undefined) parsed.sources.push(positional[0]);
if (positional[1] !== undefined) parsed.tests.push(positional[1]);
if (positional.length > 2) {
parsed.error =
`Too many positional arguments (${positional.length}). Quote your globs ` +
`so the shell can't expand them — e.g. 'src/lib/forms/*.ts' ` +
`'test/lib/forms/*.test.ts' — or pass repeated --source/--test flags.`;
}
};

/** Validate the parsed numeric options, recording the first error found. */
const validateNumericArgs = (parsed: ParsedArgs): void => {
if (!Number.isFinite(parsed.timeout) || parsed.timeout < 0) {
parsed.error ??=
"Invalid --timeout: expected a non-negative number of milliseconds.";
}
if (
const invalidJobs =
parsed.batchJobs !== undefined &&
(!Number.isInteger(parsed.batchJobs) || parsed.batchJobs <= 0)
) {
(!Number.isInteger(parsed.batchJobs) || parsed.batchJobs <= 0);
if (invalidJobs) {
parsed.error ??= "Invalid --jobs: expected a positive integer.";
}
};

const parseArgs = (args: string[]): ParsedArgs => {
const parsed: ParsedArgs = {
error: null,
exhaustive: false,
help: false,
sources: [],
tests: [],
timeout: DEFAULT_TIMEOUT,
useHarness: false,
};
const positional: string[] = [];
let index = 0;
while (index < args.length) {
const arg = args[index];
if (arg !== undefined) {
const consumedNext = applyArg(parsed, positional, arg, args[index + 1]);
if (consumedNext) index += 1;
}
index += 1;
}
applyPositionals(parsed, positional);
validateNumericArgs(parsed);
return parsed;
};

Expand Down
Loading