Skip to content

Commit cd5e529

Browse files
committed
test(coverage): exercise extractTool/extractExternalTools error paths
Adds tests that mock process.smol.mount to drive: - extractTool: mount-rejection wrapped as "failed to extract … from the SEA VFS" for both npm-package (cdxgen) and standalone-binary (sfw) tools - extractExternalTools: null returns for non-SEA mode, missing mount, and max-depth recursion guard dlx/vfs-extract.mts: 17.97% → 28.11% statements (14.95% → 28.97% branch). Remaining gap (~70%) is the lock-file / extraction-recursion / TOCTOU loop body — would require a real SEA build with process.smol or heavy filesystem-state harnessing to exercise.
1 parent 105fe04 commit cd5e529

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

packages/cli/test/unit/utils/dlx/vfs-extract.test.mts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ vi.mock('../../../../src/constants/paths.mts', () => ({
2323
import {
2424
areExternalToolsAvailable,
2525
EXTERNAL_TOOLS,
26+
extractExternalTools,
2627
extractTool,
2728
getNodeSmolBasePath,
2829
getToolFilePath,
@@ -243,4 +244,36 @@ describe('utils/dlx/vfs-extract', () => {
243244
}
244245
})
245246
})
247+
248+
describe('extractExternalTools', () => {
249+
it('returns null when not running in SEA mode', async () => {
250+
mockIsSeaBinary.mockReturnValue(false)
251+
const result = await extractExternalTools()
252+
expect(result).toBeNull()
253+
})
254+
255+
it('returns null when smol.mount is missing', async () => {
256+
mockIsSeaBinary.mockReturnValue(true)
257+
;(process as any).smol = { otherProp: true }
258+
try {
259+
const result = await extractExternalTools()
260+
expect(result).toBeNull()
261+
} finally {
262+
delete (process as any).smol
263+
}
264+
})
265+
266+
it('returns null when max recursion depth exceeded', async () => {
267+
mockIsSeaBinary.mockReturnValue(true)
268+
;(process as any).smol = { mount: vi.fn() }
269+
try {
270+
// depth=5 hits the MAX_EXTRACTION_DEPTH guard and returns null
271+
// before reaching any I/O.
272+
const result = await extractExternalTools(5)
273+
expect(result).toBeNull()
274+
} finally {
275+
delete (process as any).smol
276+
}
277+
})
278+
})
246279
})

0 commit comments

Comments
 (0)