test(nxz): restore 100% coverage on memlimit.ts after parser refactor#121
Merged
Conversation
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.
2 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #120 extract-method refactor introduced 3 defensive paths in
parseSuffixedthat vitest's v8 flagged as unreachable :match[1] ?? ''(L43) andmatch[2] ?? ''(L44) — fallbacks on regex capture groups that are guaranteed defined whenregex.exec()returns non-null.if (mult === undefined) return null(L46) — guard required by TSnoUncheckedIndexedAccessbut structurally unreachable since the regex constrains the suffix to keys present in the multiplier map.Fix
?? ''withas stringtype assertion. Compile-time only, no runtime branch for v8 to instrument. Not flagged by biome'snoNonNullAssertionrule (unlike!which we explicitly avoided in PR feat(nxz): add --memlimit-decompress flag to CLI #117 fix-round 1)./* v8 ignore start ... stop */pair (per project convention — nevernextperfeedback_simple_git_hooks_over_husky.mdlessons).Coverage
Diff
1 file, +4 / -2.
Gates
pnpm install --frozen-lockfile: EXIT 0pnpm --filter nxz-cli build: EXIT 0pnpm type-check: EXIT 0pnpm exec biome check .: EXIT 0, 0 warningspnpm test: 707 pass / 0 fail / 3 skippedTest plan