From 02b44064c107cdd6d2465ac887a577810d75fe69 Mon Sep 17 00:00:00 2001 From: galz10 Date: Mon, 9 Mar 2026 16:14:52 -0700 Subject: [PATCH] chore: fix lint and test errors --- packages/cli/src/config/sandboxConfig.test.ts | 102 +++++++++++++++--- packages/cli/src/config/sandboxConfig.ts | 4 +- packages/cli/src/gemini.test.tsx | 44 ++++---- 3 files changed, 111 insertions(+), 39 deletions(-) diff --git a/packages/cli/src/config/sandboxConfig.test.ts b/packages/cli/src/config/sandboxConfig.test.ts index 51c4f7d83c..b264074fa2 100644 --- a/packages/cli/src/config/sandboxConfig.test.ts +++ b/packages/cli/src/config/sandboxConfig.test.ts @@ -90,7 +90,13 @@ describe('loadSandboxConfig', () => { process.env['GEMINI_SANDBOX'] = 'docker'; mockedCommandExistsSync.mockReturnValue(true); const config = await loadSandboxConfig({}, {}); - expect(config).toEqual({ command: 'docker', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker'); }); @@ -113,7 +119,13 @@ describe('loadSandboxConfig', () => { process.env['GEMINI_SANDBOX'] = 'lxc'; mockedCommandExistsSync.mockReturnValue(true); const config = await loadSandboxConfig({}, {}); - expect(config).toEqual({ command: 'lxc', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'lxc', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('lxc'); }); @@ -134,6 +146,9 @@ describe('loadSandboxConfig', () => { ); const config = await loadSandboxConfig({}, { sandbox: true }); expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, command: 'sandbox-exec', image: 'default/image', }); @@ -144,6 +159,9 @@ describe('loadSandboxConfig', () => { mockedCommandExistsSync.mockReturnValue(true); // all commands exist const config = await loadSandboxConfig({}, { sandbox: true }); expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, command: 'sandbox-exec', image: 'default/image', }); @@ -153,14 +171,26 @@ describe('loadSandboxConfig', () => { mockedOsPlatform.mockReturnValue('linux'); mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'docker'); const config = await loadSandboxConfig({ tools: { sandbox: true } }, {}); - expect(config).toEqual({ command: 'docker', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'default/image', + }); }); it('should use podman if available and docker is not', async () => { mockedOsPlatform.mockReturnValue('linux'); mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'podman'); const config = await loadSandboxConfig({}, { sandbox: true }); - expect(config).toEqual({ command: 'podman', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'podman', + image: 'default/image', + }); }); it('should throw if sandbox: true but no command is found', async () => { @@ -177,7 +207,13 @@ describe('loadSandboxConfig', () => { it('should use the specified command if it exists', async () => { mockedCommandExistsSync.mockReturnValue(true); const config = await loadSandboxConfig({}, { sandbox: 'podman' }); - expect(config).toEqual({ command: 'podman', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'podman', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('podman'); }); @@ -205,14 +241,26 @@ describe('loadSandboxConfig', () => { process.env['GEMINI_SANDBOX'] = 'docker'; mockedCommandExistsSync.mockReturnValue(true); const config = await loadSandboxConfig({}, {}); - expect(config).toEqual({ command: 'docker', image: 'env/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'env/image', + }); }); it('should use image from package.json if env var is not set', async () => { process.env['GEMINI_SANDBOX'] = 'docker'; mockedCommandExistsSync.mockReturnValue(true); const config = await loadSandboxConfig({}, {}); - expect(config).toEqual({ command: 'docker', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'default/image', + }); }); it('should return undefined if command is found but no image is configured', async () => { @@ -234,7 +282,13 @@ describe('loadSandboxConfig', () => { 'should enable sandbox for value: %s', async (value) => { const config = await loadSandboxConfig({}, { sandbox: value }); - expect(config).toEqual({ command: 'docker', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'default/image', + }); }, ); @@ -257,7 +311,13 @@ describe('loadSandboxConfig', () => { it('should use runsc via CLI argument on Linux', async () => { const config = await loadSandboxConfig({}, { sandbox: 'runsc' }); - expect(config).toEqual({ command: 'runsc', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'runsc', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('runsc'); expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker'); }); @@ -266,7 +326,13 @@ describe('loadSandboxConfig', () => { process.env['GEMINI_SANDBOX'] = 'runsc'; const config = await loadSandboxConfig({}, {}); - expect(config).toEqual({ command: 'runsc', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'runsc', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('runsc'); expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker'); }); @@ -277,7 +343,13 @@ describe('loadSandboxConfig', () => { {}, ); - expect(config).toEqual({ command: 'runsc', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'runsc', + image: 'default/image', + }); expect(mockedCommandExistsSync).toHaveBeenCalledWith('runsc'); expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker'); }); @@ -289,7 +361,13 @@ describe('loadSandboxConfig', () => { { sandbox: 'podman' }, ); - expect(config).toEqual({ command: 'runsc', image: 'default/image' }); + expect(config).toEqual({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'runsc', + image: 'default/image', + }); }); it('should reject runsc on macOS (Linux-only)', async () => { diff --git a/packages/cli/src/config/sandboxConfig.ts b/packages/cli/src/config/sandboxConfig.ts index 281e5c0a9f..6d7328d30d 100644 --- a/packages/cli/src/config/sandboxConfig.ts +++ b/packages/cli/src/config/sandboxConfig.ts @@ -23,7 +23,7 @@ const __dirname = path.dirname(__filename); interface SandboxCliArgs { sandbox?: boolean | string | null; } -const VALID_SANDBOX_COMMANDS: ReadonlyArray = [ +const VALID_SANDBOX_COMMANDS = [ 'docker', 'podman', 'sandbox-exec', @@ -34,7 +34,7 @@ const VALID_SANDBOX_COMMANDS: ReadonlyArray = [ function isSandboxCommand( value: string, ): value is Exclude { - return (VALID_SANDBOX_COMMANDS as readonly string[]).includes(value); + return VALID_SANDBOX_COMMANDS.includes(value); } function getSandboxCommand( diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index 47008c9991..5cf0d306a0 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -190,26 +190,22 @@ vi.mock('./ui/utils/terminalCapabilityManager.js', () => ({ vi.mock('./config/config.js', () => ({ loadCliConfig: vi.fn().mockImplementation(async () => createMockConfig()), - parseArguments: vi - .fn() - .mockResolvedValue({ - enabled: true, - allowedPaths: [], - networkAccess: false, - }), + parseArguments: vi.fn().mockResolvedValue({ + enabled: true, + allowedPaths: [], + networkAccess: false, + }), isDebugMode: vi.fn(() => false), })); vi.mock('read-package-up', () => ({ - readPackageUp: vi - .fn() - .mockResolvedValue({ - enabled: true, - allowedPaths: [], - networkAccess: false, - packageJson: { name: 'test-pkg', version: 'test-version' }, - path: '/fake/path/package.json', - }), + readPackageUp: vi.fn().mockResolvedValue({ + enabled: true, + allowedPaths: [], + networkAccess: false, + packageJson: { name: 'test-pkg', version: 'test-version' }, + path: '/fake/path/package.json', + }), })); vi.mock('update-notifier', () => ({ @@ -243,15 +239,13 @@ vi.mock('./utils/relaunch.js', () => ({ })); vi.mock('./config/sandboxConfig.js', () => ({ - loadSandboxConfig: vi - .fn() - .mockResolvedValue({ - enabled: true, - allowedPaths: [], - networkAccess: false, - command: 'docker', - image: 'test-image', - }), + loadSandboxConfig: vi.fn().mockResolvedValue({ + enabled: true, + allowedPaths: [], + networkAccess: false, + command: 'docker', + image: 'test-image', + }), })); vi.mock('./deferred.js', () => ({