Skip to content

Commit f5114b4

Browse files
committed
refactor(engine): drop the unreachable comparator arm in canonicalizeCase
codecov/patch held at 97.29% on this file under the `engine` flag: one line, the sort comparator's equality arm. It is genuinely unreachable -- Object.keys yields each key exactly once, so a comparator never sees two equal keys -- and the `v8 ignore` pragma covering it was flag-dependent: vitest's v8 provider honoured it, the engine package's own coverage run did not. Rather than chase pragmas across two coverage tools, the branch is gone. Sorting the keys with the default comparator gives the identical total order for strings, so the freeze point does not move -- which is not an assertion, it is what the pinned pre-move digest in both test suites verifies. An unreachable branch can only sit uncovered or carry an ignore comment; not writing one beats both.
1 parent 04b52b6 commit f5114b4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/loopover-engine/src/calibration/backtest-checksum.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ import type { BacktestCase } from "./backtest-corpus.js";
2323
/** Canonicalize one case (sort keys) so property-order differences don't change the checksum -- same technique
2424
* as scripts/export-d1-core.ts's canonicalizeRow. */
2525
function canonicalizeCase(backtestCase: BacktestCase): Record<string, unknown> {
26-
/* v8 ignore next -- the comparator's `0` arm is unreachable: Object.entries yields each key once, so the
27-
* two keys handed to a sort comparator are never equal. Kept anyway because a comparator that cannot
28-
* return 0 is not a total order, and rewriting it to drop the arm would be a worse function for a branch
29-
* counter's benefit. Every reachable arm (a < b, a > b) is exercised by the property-order test. */
30-
return Object.fromEntries(Object.entries(backtestCase).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
26+
// Sorted with the DEFAULT comparator over the keys, not a hand-written `a < b ? -1 : a > b ? 1 : 0`. For
27+
// strings the two give the identical total order -- the pinned digest in this module's two test suites is
28+
// what proves the output did not move -- but the hand-written form carries an equality arm that
29+
// Object.keys can never trigger, since it yields each key exactly once. An unreachable branch cannot be
30+
// tested, so it either sits uncovered or needs an ignore pragma; not writing it beats both. (The pragma
31+
// was also flag-dependent: vitest's v8 provider honoured it, the engine package's own coverage did not.)
32+
const source = backtestCase as unknown as Record<string, unknown>;
33+
return Object.fromEntries(Object.keys(source).sort().map((key) => [key, source[key]]));
3134
}
3235

3336
/** Deterministic SHA-256 over the canonicalized cases -- mirrors scripts/export-d1-core.ts's checksumRows

0 commit comments

Comments
 (0)