mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
chore: fix lint and test errors
This commit is contained in:
@@ -90,7 +90,13 @@ describe('loadSandboxConfig', () => {
|
|||||||
process.env['GEMINI_SANDBOX'] = 'docker';
|
process.env['GEMINI_SANDBOX'] = 'docker';
|
||||||
mockedCommandExistsSync.mockReturnValue(true);
|
mockedCommandExistsSync.mockReturnValue(true);
|
||||||
const config = await loadSandboxConfig({}, {});
|
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');
|
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -113,7 +119,13 @@ describe('loadSandboxConfig', () => {
|
|||||||
process.env['GEMINI_SANDBOX'] = 'lxc';
|
process.env['GEMINI_SANDBOX'] = 'lxc';
|
||||||
mockedCommandExistsSync.mockReturnValue(true);
|
mockedCommandExistsSync.mockReturnValue(true);
|
||||||
const config = await loadSandboxConfig({}, {});
|
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');
|
expect(mockedCommandExistsSync).toHaveBeenCalledWith('lxc');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -134,6 +146,9 @@ describe('loadSandboxConfig', () => {
|
|||||||
);
|
);
|
||||||
const config = await loadSandboxConfig({}, { sandbox: true });
|
const config = await loadSandboxConfig({}, { sandbox: true });
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
|
enabled: true,
|
||||||
|
allowedPaths: [],
|
||||||
|
networkAccess: false,
|
||||||
command: 'sandbox-exec',
|
command: 'sandbox-exec',
|
||||||
image: 'default/image',
|
image: 'default/image',
|
||||||
});
|
});
|
||||||
@@ -144,6 +159,9 @@ describe('loadSandboxConfig', () => {
|
|||||||
mockedCommandExistsSync.mockReturnValue(true); // all commands exist
|
mockedCommandExistsSync.mockReturnValue(true); // all commands exist
|
||||||
const config = await loadSandboxConfig({}, { sandbox: true });
|
const config = await loadSandboxConfig({}, { sandbox: true });
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
|
enabled: true,
|
||||||
|
allowedPaths: [],
|
||||||
|
networkAccess: false,
|
||||||
command: 'sandbox-exec',
|
command: 'sandbox-exec',
|
||||||
image: 'default/image',
|
image: 'default/image',
|
||||||
});
|
});
|
||||||
@@ -153,14 +171,26 @@ describe('loadSandboxConfig', () => {
|
|||||||
mockedOsPlatform.mockReturnValue('linux');
|
mockedOsPlatform.mockReturnValue('linux');
|
||||||
mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'docker');
|
mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'docker');
|
||||||
const config = await loadSandboxConfig({ tools: { sandbox: true } }, {});
|
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 () => {
|
it('should use podman if available and docker is not', async () => {
|
||||||
mockedOsPlatform.mockReturnValue('linux');
|
mockedOsPlatform.mockReturnValue('linux');
|
||||||
mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'podman');
|
mockedCommandExistsSync.mockImplementation((cmd) => cmd === 'podman');
|
||||||
const config = await loadSandboxConfig({}, { sandbox: true });
|
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 () => {
|
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 () => {
|
it('should use the specified command if it exists', async () => {
|
||||||
mockedCommandExistsSync.mockReturnValue(true);
|
mockedCommandExistsSync.mockReturnValue(true);
|
||||||
const config = await loadSandboxConfig({}, { sandbox: 'podman' });
|
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');
|
expect(mockedCommandExistsSync).toHaveBeenCalledWith('podman');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,14 +241,26 @@ describe('loadSandboxConfig', () => {
|
|||||||
process.env['GEMINI_SANDBOX'] = 'docker';
|
process.env['GEMINI_SANDBOX'] = 'docker';
|
||||||
mockedCommandExistsSync.mockReturnValue(true);
|
mockedCommandExistsSync.mockReturnValue(true);
|
||||||
const config = await loadSandboxConfig({}, {});
|
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 () => {
|
it('should use image from package.json if env var is not set', async () => {
|
||||||
process.env['GEMINI_SANDBOX'] = 'docker';
|
process.env['GEMINI_SANDBOX'] = 'docker';
|
||||||
mockedCommandExistsSync.mockReturnValue(true);
|
mockedCommandExistsSync.mockReturnValue(true);
|
||||||
const config = await loadSandboxConfig({}, {});
|
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 () => {
|
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',
|
'should enable sandbox for value: %s',
|
||||||
async (value) => {
|
async (value) => {
|
||||||
const config = await loadSandboxConfig({}, { sandbox: 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 () => {
|
it('should use runsc via CLI argument on Linux', async () => {
|
||||||
const config = await loadSandboxConfig({}, { sandbox: 'runsc' });
|
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('runsc');
|
||||||
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
||||||
});
|
});
|
||||||
@@ -266,7 +326,13 @@ describe('loadSandboxConfig', () => {
|
|||||||
process.env['GEMINI_SANDBOX'] = 'runsc';
|
process.env['GEMINI_SANDBOX'] = 'runsc';
|
||||||
const config = await loadSandboxConfig({}, {});
|
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('runsc');
|
||||||
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
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('runsc');
|
||||||
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
expect(mockedCommandExistsSync).toHaveBeenCalledWith('docker');
|
||||||
});
|
});
|
||||||
@@ -289,7 +361,13 @@ describe('loadSandboxConfig', () => {
|
|||||||
{ sandbox: 'podman' },
|
{ 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 () => {
|
it('should reject runsc on macOS (Linux-only)', async () => {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const __dirname = path.dirname(__filename);
|
|||||||
interface SandboxCliArgs {
|
interface SandboxCliArgs {
|
||||||
sandbox?: boolean | string | null;
|
sandbox?: boolean | string | null;
|
||||||
}
|
}
|
||||||
const VALID_SANDBOX_COMMANDS: ReadonlyArray<SandboxConfig['command']> = [
|
const VALID_SANDBOX_COMMANDS = [
|
||||||
'docker',
|
'docker',
|
||||||
'podman',
|
'podman',
|
||||||
'sandbox-exec',
|
'sandbox-exec',
|
||||||
@@ -34,7 +34,7 @@ const VALID_SANDBOX_COMMANDS: ReadonlyArray<SandboxConfig['command']> = [
|
|||||||
function isSandboxCommand(
|
function isSandboxCommand(
|
||||||
value: string,
|
value: string,
|
||||||
): value is Exclude<SandboxConfig['command'], undefined> {
|
): value is Exclude<SandboxConfig['command'], undefined> {
|
||||||
return (VALID_SANDBOX_COMMANDS as readonly string[]).includes(value);
|
return VALID_SANDBOX_COMMANDS.includes(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSandboxCommand(
|
function getSandboxCommand(
|
||||||
|
|||||||
@@ -190,26 +190,22 @@ vi.mock('./ui/utils/terminalCapabilityManager.js', () => ({
|
|||||||
|
|
||||||
vi.mock('./config/config.js', () => ({
|
vi.mock('./config/config.js', () => ({
|
||||||
loadCliConfig: vi.fn().mockImplementation(async () => createMockConfig()),
|
loadCliConfig: vi.fn().mockImplementation(async () => createMockConfig()),
|
||||||
parseArguments: vi
|
parseArguments: vi.fn().mockResolvedValue({
|
||||||
.fn()
|
enabled: true,
|
||||||
.mockResolvedValue({
|
allowedPaths: [],
|
||||||
enabled: true,
|
networkAccess: false,
|
||||||
allowedPaths: [],
|
}),
|
||||||
networkAccess: false,
|
|
||||||
}),
|
|
||||||
isDebugMode: vi.fn(() => false),
|
isDebugMode: vi.fn(() => false),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('read-package-up', () => ({
|
vi.mock('read-package-up', () => ({
|
||||||
readPackageUp: vi
|
readPackageUp: vi.fn().mockResolvedValue({
|
||||||
.fn()
|
enabled: true,
|
||||||
.mockResolvedValue({
|
allowedPaths: [],
|
||||||
enabled: true,
|
networkAccess: false,
|
||||||
allowedPaths: [],
|
packageJson: { name: 'test-pkg', version: 'test-version' },
|
||||||
networkAccess: false,
|
path: '/fake/path/package.json',
|
||||||
packageJson: { name: 'test-pkg', version: 'test-version' },
|
}),
|
||||||
path: '/fake/path/package.json',
|
|
||||||
}),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('update-notifier', () => ({
|
vi.mock('update-notifier', () => ({
|
||||||
@@ -243,15 +239,13 @@ vi.mock('./utils/relaunch.js', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./config/sandboxConfig.js', () => ({
|
vi.mock('./config/sandboxConfig.js', () => ({
|
||||||
loadSandboxConfig: vi
|
loadSandboxConfig: vi.fn().mockResolvedValue({
|
||||||
.fn()
|
enabled: true,
|
||||||
.mockResolvedValue({
|
allowedPaths: [],
|
||||||
enabled: true,
|
networkAccess: false,
|
||||||
allowedPaths: [],
|
command: 'docker',
|
||||||
networkAccess: false,
|
image: 'test-image',
|
||||||
command: 'docker',
|
}),
|
||||||
image: 'test-image',
|
|
||||||
}),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./deferred.js', () => ({
|
vi.mock('./deferred.js', () => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user