From 2c56a9fddb0872d41358c9c7bc2991fc7aa3f699 Mon Sep 17 00:00:00 2001 From: Aseem Shrey Date: Mon, 16 Feb 2026 19:18:51 -0500 Subject: [PATCH] fix(test): mock IsolatedContainerVolume in naabu tests to prevent flaky timeouts The naabu tests were flaky because component.execute() triggers real Docker commands via IsolatedContainerVolume (volume create, alpine container for file writes/chmod, volume rm) even when runComponentWithRunner is mocked. When Docker is cold or slow, these operations exceed the test timeout. This follows the same pattern already used in dnsx.test.ts and opencode.test.ts. Signed-off-by: Aseem Shrey --- .../security/__tests__/naabu.test.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/worker/src/components/security/__tests__/naabu.test.ts b/worker/src/components/security/__tests__/naabu.test.ts index 734784c0..676078b7 100644 --- a/worker/src/components/security/__tests__/naabu.test.ts +++ b/worker/src/components/security/__tests__/naabu.test.ts @@ -1,11 +1,28 @@ -import { describe, it, expect, beforeAll, afterEach, vi } from 'bun:test'; +import { describe, it, expect, beforeAll, afterEach, vi, mock } from 'bun:test'; import * as sdk from '@shipsec/component-sdk'; -import { componentRegistry } from '../../index'; import type { NaabuInput, NaabuOutput } from '../naabu'; +// Mock IsolatedContainerVolume BEFORE any component imports. +// ../../index eagerly imports naabu.ts which pulls in the real +// IsolatedContainerVolume; using a dynamic import in beforeAll() +// ensures the mock is registered first. +mock.module('../../../utils/isolated-volume', () => ({ + IsolatedContainerVolume: class { + async initialize() { + return 'mock-volume'; + } + getVolumeConfig(containerPath = '/inputs', readOnly = true) { + return { source: 'mock-volume', target: containerPath, readOnly }; + } + async cleanup() {} + }, +})); + +let componentRegistry: typeof import('@shipsec/component-sdk').componentRegistry; + describe('naabu component', () => { beforeAll(async () => { - await import('../../index'); + ({ componentRegistry } = await import('../../index')); }); afterEach(() => {