Skip to content

test(tar-xz): close file.ts coverage partials with tests + v8 ignores#128

Merged
oorabona merged 1 commit into
masterfrom
test/file-ts-final-partials
Apr 30, 2026
Merged

test(tar-xz): close file.ts coverage partials with tests + v8 ignores#128
oorabona merged 1 commit into
masterfrom
test/file-ts-final-partials

Conversation

@oorabona

Copy link
Copy Markdown
Owner

Summary

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. Brings file.ts branches from 83.72% to 92.85% (+9.13).

Real tests added (2 in coverage-trivial-branches.spec.ts)

Test Branch covered Setup
SYMLINK strip-removes-linkname extractSymlinkEntry early-return at L170 linkname=only-one-part, strip=1 → silently skipped
HARDLINK strip-removes-linkname extractHardlinkEntry early-return at L208 same shape

The buildSingleEntryTar helper gains an optional linkname parameter to craft these without importing fixtures from coverage-final.spec.ts.

v8 ignore wraps applied (7 sites)

File:Line Reason
file.ts ensureSafeName L38 (s === undefined) TS-defensive — callers always pass non-optional string
file.ts ensureSafeName L40 (s.includes('\x00')) Smart discovery : parseString() in tar/format.ts terminates name fields at the first 0x00 byte, so names reaching ensureSafeName cannot contain NUL. Guard is meaningful only for non-TAR callers.
file.ts hasSymlinkAncestor L82 (non-ENOENT rethrow) Race-window: ancestor dir deleted between lstat calls
file.ts hasSymlinkAncestor L85 (parent === dir) Filesystem-root invariant ; tar entries are relative to cwd
file.ts ensureSafeTarget L134 (non-ENOENT rethrow) Race-window in stat-then-validate sequence
file.ts extractSymlinkEntry L178 (non-ENOENT rethrow on unlink) Race-window: symlink disappears between check and unlink
file.ts extractHardlinkEntry L223 (non-ENOENT rethrow on lstat) Race-window: link source deleted during lstat
file.ts openFileExclusive L319 (non-EEXIST rethrow) Same race-window class as existing PR #114 wraps in same function ; closes symmetry hole

Coverage delta

Metric Before After
file.ts branches 83.72% 92.85% (+9.13)
tar-xz overall branches 92.80% 94.98% (+2.18)
tar-xz overall lines 100% 100%

Diff

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 0
  • pnpm --filter tar-xz build : EXIT 0
  • pnpm type-check : EXIT 0
  • pnpm exec biome check . : EXIT 0, 0 warnings
  • pnpm test : tar-xz 209 → 211 passing (+2), 3 skipped unchanged

Test plan

  • CI green
  • Codecov reflects file.ts and overall tar-xz branch uplift

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).
@oorabona oorabona merged commit 8e51020 into master Apr 30, 2026
6 of 7 checks passed
@oorabona oorabona deleted the test/file-ts-final-partials branch April 30, 2026 18:17
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