test(tar-xz): cover three trivial file.ts branches#126
Merged
Conversation
…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.
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
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)writeFileEntryPosixline 287 false branch (if (entry.mtime > 0))mtime: 0extracts without calling utimesextractFileline 519 truthy branch (entry.type === TarEntryType.FILE)type: TarEntryType.FILEexplicitly (vs createHeader default)extractFileline 523(entry.mode ?? 0o644)left-hand truthy with mode=0mode: 0extracts 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 :parseOctalalways returnsnumber, neverundefinedTarEntry.modeis typed asnumberWrapping 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
file.tslinesfile.tsbranchesDiff
1 new file, +167 LOC (test only, no source change).
Gates
pnpm --filter tar-xz build: EXIT 0pnpm type-check: EXIT 0pnpm exec biome check .: EXIT 0, 0 warningspnpm test: tar-xz 206 → 209 passing (+3), 3 skipped unchanged ; full workspace 489 root + 209 tar-xz + 63 nxz = 761 passing, 0 failTest plan