Skip to content

test(tar-xz): cover three trivial file.ts branches#126

Merged
oorabona merged 1 commit into
masterfrom
test/tarxz-trivial-branches
Apr 30, 2026
Merged

test(tar-xz): cover three trivial file.ts branches#126
oorabona merged 1 commit into
masterfrom
test/tarxz-trivial-branches

Conversation

@oorabona
Copy link
Copy Markdown
Owner

Summary

Three small cases that codecov flagged as partial branches inside already-line-covered code in packages/tar-xz/src/node/file.ts. Brings file.ts from 82.55% → 83.72% branches.

Tests added (3 cases in coverage-trivial-branches.spec.ts)

# Branch covered Test
1 writeFileEntryPosix line 287 false branch (if (entry.mtime > 0)) Entry with mtime: 0 extracts without calling utimes
2 extractFile line 519 truthy branch (entry.type === TarEntryType.FILE) Entry with type: TarEntryType.FILE explicitly (vs createHeader default)
3 extractFile line 523 (entry.mode ?? 0o644) left-hand truthy with mode=0 Entry with mode: 0 extracts to a file with permission bits 0 (POSIX-only, skipped on Windows)

Contract discovery

The right-hand side of (entry.mode ?? 0o644) is structurally unreachable :

  • parseOctal always returns number, never undefined
  • TarEntry.mode is typed as number

Wrapping the dead branch would need /* v8 ignore next */ on a mid-expression token, which the project convention forbids. The partial flag for line 523 persists by design — locked as a known ceiling.

Coverage delta

Metric Before After
file.ts lines 93.84% 93.84% (unchanged — no missed lines were covered, just partial branches)
file.ts branches 82.55% 83.72% (+1.17)
All tar-xz files lines 98.19% 98.19%
All tar-xz files branches 92.53% 92.80% (+0.27)

Diff

1 new file, +167 LOC (test only, no source change).

Gates

  • pnpm --filter tar-xz build : EXIT 0
  • pnpm type-check : EXIT 0
  • pnpm exec biome check . : EXIT 0, 0 warnings
  • pnpm test : tar-xz 206 → 209 passing (+3), 3 skipped unchanged ; full workspace 489 root + 209 tar-xz + 63 nxz = 761 passing, 0 fail

Test plan

  • CI green
  • Codecov reflects the small branch uplift on file.ts

…e, mode=0)

Three small cases that codecov flagged as partial branches inside
already-line-covered code:

- writeFileEntryPosix at line 287 — the false branch of
  if (entry.mtime > 0). A test entry with mtime: 0 verifies that
  utimes is not called and the file still extracts cleanly.
- extractFile at line 519 — the truthy branch of
  if (entry.type === TarEntryType.FILE). Existing tests reach the
  branch implicitly via createHeader defaults; this case passes
  type: TarEntryType.FILE explicitly so the dispatch is unambiguous.
- extractFile at line 523 — the truthy left-hand of
  (entry.mode ?? 0o644) & SAFE_MODE_MASK. A test entry with
  mode: 0 verifies the resulting file has permission bits 0
  (POSIX-only, skipped on Windows).

Note: the right-hand side of the ?? above is structurally
unreachable — parseOctal always returns a number, never undefined,
and TarEntry.mode is typed as number. Wrapping the dead branch
would need v8 ignore next on a mid-expression token, which the
project convention forbids; the partial flag for line 523 persists
by design.

Branch coverage on file.ts: 82.55% → 83.72% (+1.17). Workspace-wide
on all tar-xz files: 92.53% → 92.80% (+0.27). 209 tar-xz tests
passing (up from 206), 3 skipped unchanged.
@oorabona oorabona merged commit 5c496f8 into master Apr 30, 2026
6 of 7 checks passed
@oorabona oorabona deleted the test/tarxz-trivial-branches branch April 30, 2026 17:21
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