From ec55242fac39c983a0499a0162229e43ae45d821 Mon Sep 17 00:00:00 2001 From: Olivier ORABONA Date: Thu, 30 Apr 2026 21:33:55 +0200 Subject: [PATCH] test(tar-xz): close extract.ts coverage partials with v8 ignores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close 5 defensive-unreachable branches in extract.ts by wrapping impossible parser states with v8 ignore markers: - drainEntryChunks: done:true guard (parseTar always emits 'end' first) - createEntryDataPull: dataGenInFlight condition guard - makeDataGen: done:true guard (same parseTar invariant) - extract outer loop: done:true guard (same parseTar invariant) - extract: ev.kind==='chunk' condition guard Coverage: 93.75% lines (5 partials) → 100% lines (0 partials). --- packages/tar-xz/src/node/extract.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/tar-xz/src/node/extract.ts b/packages/tar-xz/src/node/extract.ts index 50d7589..c656868 100644 --- a/packages/tar-xz/src/node/extract.ts +++ b/packages/tar-xz/src/node/extract.ts @@ -135,7 +135,9 @@ async function drainEntryChunks( ): Promise { while (true) { const result = await parser.next(); + /* v8 ignore start: parseTar always emits 'end' before returning; this done:true branch is unreachable via the public API */ if (result.done) return; + /* v8 ignore stop */ if (result.value.kind !== 'chunk') { lookaheadRef.value = result.value; return; @@ -193,6 +195,7 @@ function createEntryDataPull( ): () => AsyncGenerator { let dataGenInFlight = false; return function makeDataGen(): AsyncGenerator { + /* v8 ignore start: internal state machine invariant — makeTarEntryWithData() calls dataPull() exactly once per entry and never exposes makeDataGen to consumers; concurrent-iteration path is unreachable via public API */ if (dataGenInFlight) { // D-5 invariant violation: triggered if the same entry's data generator // is created twice (`makeDataGen()` called more than once for one @@ -202,7 +205,6 @@ function createEntryDataPull( // `code: 'TAR_PARSER_INVARIANT'` attribute matches the convention used // by other invariant errors in this module (e.g. stray-chunk in extract, // size-mismatch in bytes()) and keeps downstream filters consistent. - /* v8 ignore start: internal state machine invariant — makeTarEntryWithData() calls dataPull() exactly once per entry and never exposes makeDataGen to consumers; concurrent-iteration path is unreachable via public API */ const err = new Error('concurrent entry.data iteration is not supported') as Error & { code?: string; }; @@ -215,7 +217,9 @@ function createEntryDataPull( try { while (true) { const r = await parser.next(); + /* v8 ignore start: parseTar always emits 'end' before returning; this done:true branch is unreachable via the public API */ if (r.done) return; + /* v8 ignore stop */ if (r.value.kind === 'chunk') { yield r.value.data; } else { @@ -290,13 +294,15 @@ export async function* extract( try { while (true) { const result = await nextParseEvent(parser, lookaheadRef); + /* v8 ignore start: parseTar always emits 'end' before returning; this done:true branch is unreachable via the public API */ if (result.done) break; + /* v8 ignore stop */ const ev = result.value; if (ev.kind === 'end') break; + /* v8 ignore start: state machine invariant — parseTar never emits 'chunk' before 'entry'; this branch guards against a hypothetical parser bug that cannot be triggered via the public API */ if (ev.kind === 'chunk') { // Stray chunk at outer-loop level is a parser invariant violation (D-5). - /* v8 ignore start: state machine invariant — parseTar never emits 'chunk' before 'entry'; this branch guards against a hypothetical parser bug that cannot be triggered via the public API */ const err = new Error('parser invariant: chunk emitted before entry'); (err as Error & { code: string }).code = 'TAR_PARSER_INVARIANT'; throw err;