Skip to content

test(nxz): restore 100% coverage on memlimit.ts after parser refactor#121

Merged
oorabona merged 1 commit into
masterfrom
chore/memlimit-coverage-100
Apr 30, 2026
Merged

test(nxz): restore 100% coverage on memlimit.ts after parser refactor#121
oorabona merged 1 commit into
masterfrom
chore/memlimit-coverage-100

Conversation

@oorabona
Copy link
Copy Markdown
Owner

Summary

PR #120 extract-method refactor introduced 3 defensive paths in parseSuffixed that vitest's v8 flagged as unreachable :

  • match[1] ?? '' (L43) and match[2] ?? '' (L44) — fallbacks on regex capture groups that are guaranteed defined when regex.exec() returns non-null.
  • if (mult === undefined) return null (L46) — guard required by TS noUncheckedIndexedAccess but structurally unreachable since the regex constrains the suffix to keys present in the multiplier map.

Fix

Coverage

Metric Before After
Lines 95.2% (20/21) 100% (19/19)
Branches 83.3% (15/18) 100% (15/15)

Diff

1 file, +4 / -2.

Gates

  • pnpm install --frozen-lockfile: EXIT 0
  • pnpm --filter nxz-cli build: EXIT 0
  • pnpm type-check: EXIT 0
  • pnpm exec biome check .: EXIT 0, 0 warnings
  • pnpm test: 707 pass / 0 fail / 3 skipped

Test plan

  • CI green
  • Codecov reports 100% on memlimit.ts

The PR #120 extract-method refactor introduced three defensive paths
in parseSuffixed that vitest's v8 instrumentation flagged as
unreachable: the '?? ""' fallbacks on regex capture groups
(unreachable when exec returns non-null) and the 'mult === undefined'
guard (unreachable because the regex constrains the suffix to keys
present in the multiplier map).

- Replace 'match[1] ?? ""' and 'match[2] ?? ""' with 'as string'
  type assertions: compile-time only, no runtime branch for v8 to
  instrument, and not flagged by biome's noNonNullAssertion rule
  (unlike non-null '!' which would re-introduce the lint warning we
  resolved in PR #117 fix-round 1).
- Wrap the noUncheckedIndexedAccess-required mult-undefined guard
  with /* v8 ignore start ... stop */: TypeScript strict mode demands
  the check but the regex+map alignment makes it structurally
  unreachable. Project convention is start/stop pairs (never 'next').

Coverage: lines 95.2 -> 100, branches 83.3 -> 100 on memlimit.ts.
707 tests still pass byte-identical.
@oorabona oorabona merged commit 7c87610 into master Apr 30, 2026
6 of 7 checks passed
@oorabona oorabona deleted the chore/memlimit-coverage-100 branch April 30, 2026 13:13
oorabona added a commit that referenced this pull request Apr 30, 2026
…ve guards) (#122)

Two defensive branches in root src/ were flagged as uncovered by
vitest's v8 instrumentation. Both are intentional fail-closed safety
nets that should remain in code (TypeScript noUncheckedIndexedAccess
widens the runtime-narrowed types) but are unreachable under current
invariants and so cannot be exercised by tests.

- src/errors.ts:176 — 'if (msg === undefined) return Unknown LZMA
  error code: ...' is preceded by a bounds check on errno, so the
  array lookup is always defined. Wrapped with v8 ignore start/stop.
- src/pool.ts:168 — 'if (item === undefined) throw Invariant
  violation' is preceded by a queue.length===0 early return, so
  shift() never returns undefined. Wrapped with v8 ignore start/stop.

Per project convention the start/stop pair form is mandatory (never
'next' or 'next N' which only excludes line coverage and not branch
coverage).

Coverage restored across the entire repo: root src/ now 100%/100%/
100%/100% (statements/branches/functions/lines), packages/nxz
already at 100% from PR #121, packages/tar-xz unchanged. 707 tests
still pass byte-identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant