test(tar-xz): close file.ts coverage partials with tests + v8 ignores#128
Merged
Conversation
Address ten remaining partial branches in file.ts: two are real reachable paths that get fixtures, eight are defensive guards that get v8 ignore start/stop wraps with inline rationale. Real tests added (2 in coverage-trivial-branches.spec.ts): - extractSymlinkEntry early-return: a SYMLINK entry whose linkname is a single component is silently skipped when strip=1, exercising the if (!strippedLinkname) return; branch. - extractHardlinkEntry early-return: same shape for hardlinks. The coverage-trivial-branches helper buildSingleEntryTar gains an optional linkname parameter so the tests can craft SYMLINK and HARDLINK archives without depending on coverage-final.spec.ts. v8 ignore wraps applied (7 sites in file.ts): - ensureSafeName: TS-defensive 'undefined' early-return AND the NUL-byte rejection. Discovery during this work: parseString in tar/format.ts already terminates a name field at the first 0x00, so any name reaching ensureSafeName cannot contain a NUL. The guard is meaningful only for non-TAR callers and is unreachable via the public extract path; suppress accordingly. - hasSymlinkAncestor non-ENOENT rethrow: race-window where the ancestor directory disappears between lstat calls; non-ENOENT branches are EACCES/EIO that test fixtures cannot trigger. - hasSymlinkAncestor parent === dir guard: filesystem-root invariant; tar entries are relative paths under cwd so the loop never reaches POSIX '/' or Windows 'C:\'. - ensureSafeTarget non-ENOENT rethrow: race-window in the stat-then-validate sequence. - extractSymlinkEntry non-ENOENT rethrow on unlink: race-window where the existing symlink disappears between ensureSafeTarget and the unlink call. - extractHardlinkEntry non-ENOENT rethrow on lstat: race-window on the link source. - openFileExclusive non-EEXIST rethrow on the first open: same race-window class as the existing wraps in the same function; closes the symmetry hole. Coverage: - file.ts branches 83.72% -> 92.85% (+9.13). - tar-xz overall branches 92.80% -> 94.98% (+2.18). - tar-xz lines stay 100%. tar-xz tests: 209 pass / 3 skipped -> 211 pass / 3 skipped (+2).
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
Address ten remaining partial branches in
file.ts. Two are real reachable paths that get fixtures, eight are defensive guards that getv8 ignore start/stopwraps with inline rationale. Brings file.ts branches from 83.72% to 92.85% (+9.13).Real tests added (2 in
coverage-trivial-branches.spec.ts)extractSymlinkEntryearly-return at L170only-one-part, strip=1 → silently skippedextractHardlinkEntryearly-return at L208The
buildSingleEntryTarhelper gains an optionallinknameparameter to craft these without importing fixtures fromcoverage-final.spec.ts.v8 ignore wraps applied (7 sites)
file.tsensureSafeName L38 (s === undefined)stringfile.tsensureSafeName L40 (s.includes('\x00'))parseString()intar/format.tsterminates name fields at the first0x00byte, so names reachingensureSafeNamecannot contain NUL. Guard is meaningful only for non-TAR callers.file.tshasSymlinkAncestor L82 (non-ENOENT rethrow)file.tshasSymlinkAncestor L85 (parent === dir)file.tsensureSafeTarget L134 (non-ENOENT rethrow)file.tsextractSymlinkEntry L178 (non-ENOENT rethrow on unlink)file.tsextractHardlinkEntry L223 (non-ENOENT rethrow on lstat)file.tsopenFileExclusive L319 (non-EEXIST rethrow)Coverage delta
file.tsbranchesDiff
2 files, +117 :
packages/tar-xz/src/node/file.ts(+16, 7 wraps)packages/tar-xz/test/coverage-trivial-branches.spec.ts(+101, 2 tests + linkname helper extension)Gates
pnpm install --frozen-lockfile: EXIT 0pnpm --filter tar-xz build: EXIT 0pnpm type-check: EXIT 0pnpm exec biome check .: EXIT 0, 0 warningspnpm test: tar-xz 209 → 211 passing (+2), 3 skipped unchangedTest plan