mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-01 23:44:15 -07:00
revert bad changes to tests (#17673)
This commit is contained in:
committed by
GitHub
parent
7904f973a0
commit
f03f2e8907
@@ -12,6 +12,7 @@ import {
|
|||||||
beforeEach,
|
beforeEach,
|
||||||
afterEach,
|
afterEach,
|
||||||
type Mocked,
|
type Mocked,
|
||||||
|
type Mock,
|
||||||
} from 'vitest';
|
} from 'vitest';
|
||||||
import { IdeClient, IDEConnectionStatus } from './ide-client.js';
|
import { IdeClient, IDEConnectionStatus } from './ide-client.js';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
@@ -25,48 +26,32 @@ import * as path from 'node:path';
|
|||||||
import { getIdeServerHost } from './ide-client.js';
|
import { getIdeServerHost } from './ide-client.js';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
|
|
||||||
// Mock os.tmpdir to control the temp directory in tests
|
|
||||||
vi.mock('node:os', async (importOriginal) => {
|
|
||||||
const actualOs = await importOriginal<typeof os>();
|
|
||||||
return {
|
|
||||||
...actualOs,
|
|
||||||
tmpdir: vi.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mock node:fs to allow spying on existsSync while keeping real implementation for others
|
|
||||||
vi.mock('node:fs', async (importOriginal) => {
|
vi.mock('node:fs', async (importOriginal) => {
|
||||||
const actual = await importOriginal<typeof fs>();
|
const actual = await importOriginal<typeof fs>();
|
||||||
return {
|
return {
|
||||||
...actual,
|
...(actual as object),
|
||||||
existsSync: vi.fn(actual.existsSync),
|
promises: {
|
||||||
|
...actual.promises,
|
||||||
|
readFile: vi.fn(),
|
||||||
|
readdir: vi.fn(),
|
||||||
|
},
|
||||||
|
realpathSync: (p: string) => p,
|
||||||
|
existsSync: vi.fn(() => false),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock('./process-utils.js');
|
vi.mock('./process-utils.js');
|
||||||
vi.mock('@modelcontextprotocol/sdk/client/index.js');
|
vi.mock('@modelcontextprotocol/sdk/client/index.js');
|
||||||
vi.mock('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
vi.mock('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
||||||
vi.mock('@modelcontextprotocol/sdk/client/stdio.js');
|
vi.mock('@modelcontextprotocol/sdk/client/stdio.js');
|
||||||
vi.mock('./detect-ide.js');
|
vi.mock('./detect-ide.js');
|
||||||
|
vi.mock('node:os');
|
||||||
|
|
||||||
describe('IdeClient', () => {
|
describe('IdeClient', () => {
|
||||||
let mockClient: Mocked<Client>;
|
let mockClient: Mocked<Client>;
|
||||||
let mockHttpTransport: Mocked<StreamableHTTPClientTransport>;
|
let mockHttpTransport: Mocked<StreamableHTTPClientTransport>;
|
||||||
let mockStdioTransport: Mocked<StdioClientTransport>;
|
let mockStdioTransport: Mocked<StdioClientTransport>;
|
||||||
let testTmpDir: string;
|
|
||||||
let ideConfigDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
// Setup temporary directory for tests
|
|
||||||
testTmpDir = await fs.promises.mkdtemp(
|
|
||||||
path.join(os.homedir(), 'ide-client-test-'),
|
|
||||||
);
|
|
||||||
ideConfigDir = path.join(testTmpDir, 'gemini', 'ide');
|
|
||||||
await fs.promises.mkdir(ideConfigDir, { recursive: true });
|
|
||||||
|
|
||||||
// Mock os.tmpdir to return our test temp directory
|
|
||||||
vi.mocked(os.tmpdir).mockReturnValue(testTmpDir);
|
|
||||||
|
|
||||||
// Reset singleton instance for test isolation
|
// Reset singleton instance for test isolation
|
||||||
(IdeClient as unknown as { instance: IdeClient | undefined }).instance =
|
(IdeClient as unknown as { instance: IdeClient | undefined }).instance =
|
||||||
undefined;
|
undefined;
|
||||||
@@ -85,6 +70,7 @@ describe('IdeClient', () => {
|
|||||||
pid: 12345,
|
pid: 12345,
|
||||||
command: 'test-ide',
|
command: 'test-ide',
|
||||||
});
|
});
|
||||||
|
vi.mocked(os.tmpdir).mockReturnValue('/tmp');
|
||||||
|
|
||||||
// Mock MCP client and transports
|
// Mock MCP client and transports
|
||||||
mockClient = {
|
mockClient = {
|
||||||
@@ -108,26 +94,27 @@ describe('IdeClient', () => {
|
|||||||
await IdeClient.getInstance();
|
await IdeClient.getInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(() => {
|
||||||
// Clean up temporary directory
|
|
||||||
if (testTmpDir) {
|
|
||||||
await fs.promises.rm(testTmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('connect', () => {
|
describe('connect', () => {
|
||||||
it('should connect using HTTP when port is provided in config file', async () => {
|
it('should connect using HTTP when port is provided in config file', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
|
|
||||||
|
expect(fs.promises.readFile).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp', 'gemini', 'ide', 'gemini-ide-server-12345.json'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
expect(StreamableHTTPClientTransport).toHaveBeenCalledWith(
|
expect(StreamableHTTPClientTransport).toHaveBeenCalledWith(
|
||||||
new URL('http://127.0.0.1:8080/mcp'),
|
new URL('http://127.0.0.1:8080/mcp'),
|
||||||
expect.any(Object),
|
expect.any(Object),
|
||||||
@@ -140,11 +127,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should connect using stdio when stdio config is provided in file', async () => {
|
it('should connect using stdio when stdio config is provided in file', async () => {
|
||||||
const config = { stdio: { command: 'test-cmd', args: ['--foo'] } };
|
const config = { stdio: { command: 'test-cmd', args: ['--foo'] } };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
@@ -164,11 +152,12 @@ describe('IdeClient', () => {
|
|||||||
port: '8080',
|
port: '8080',
|
||||||
stdio: { command: 'test-cmd', args: ['--foo'] },
|
stdio: { command: 'test-cmd', args: ['--foo'] },
|
||||||
};
|
};
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
@@ -181,6 +170,14 @@ describe('IdeClient', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should connect using HTTP when port is provided in environment variables', async () => {
|
it('should connect using HTTP when port is provided in environment variables', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(
|
||||||
|
new Error('File not found'),
|
||||||
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
@@ -197,6 +194,14 @@ describe('IdeClient', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should connect using stdio when stdio config is in environment variables', async () => {
|
it('should connect using stdio when stdio config is in environment variables', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(
|
||||||
|
new Error('File not found'),
|
||||||
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_STDIO_COMMAND'] = 'env-cmd';
|
process.env['GEMINI_CLI_IDE_SERVER_STDIO_COMMAND'] = 'env-cmd';
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_STDIO_ARGS'] = '["--bar"]';
|
process.env['GEMINI_CLI_IDE_SERVER_STDIO_ARGS'] = '["--bar"]';
|
||||||
|
|
||||||
@@ -215,12 +220,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should prioritize file config over environment variables', async () => {
|
it('should prioritize file config over environment variables', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
@@ -236,6 +241,15 @@ describe('IdeClient', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be disconnected if no config is found', async () => {
|
it('should be disconnected if no config is found', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(
|
||||||
|
new Error('File not found'),
|
||||||
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
|
|
||||||
@@ -253,11 +267,7 @@ describe('IdeClient', () => {
|
|||||||
describe('getConnectionConfigFromFile', () => {
|
describe('getConnectionConfigFromFile', () => {
|
||||||
it('should return config from the specific pid file if it exists', async () => {
|
it('should return config from the specific pid file if it exists', async () => {
|
||||||
const config = { port: '1234', workspacePath: '/test/workspace' };
|
const config = { port: '1234', workspacePath: '/test/workspace' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
|
||||||
'gemini-ide-server-12345.json',
|
|
||||||
);
|
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
// In tests, the private method can be accessed like this.
|
// In tests, the private method can be accessed like this.
|
||||||
@@ -268,9 +278,20 @@ describe('IdeClient', () => {
|
|||||||
).getConnectionConfigFromFile();
|
).getConnectionConfigFromFile();
|
||||||
|
|
||||||
expect(result).toEqual(config);
|
expect(result).toEqual(config);
|
||||||
|
expect(fs.promises.readFile).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp', 'gemini', 'ide', 'gemini-ide-server-12345.json'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined if no config files are found', async () => {
|
it('should return undefined if no config files are found', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(new Error('not found'));
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
const result = await (
|
const result = await (
|
||||||
ideClient as unknown as {
|
ideClient as unknown as {
|
||||||
@@ -283,12 +304,15 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should find and parse a single config file with the new naming scheme', async () => {
|
it('should find and parse a single config file with the new naming scheme', async () => {
|
||||||
const config = { port: '5678', workspacePath: '/test/workspace' };
|
const config = { port: '5678', workspacePath: '/test/workspace' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
ideConfigDir,
|
new Error('not found'),
|
||||||
'gemini-ide-server-12345-123.json',
|
); // For old path
|
||||||
);
|
(
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue(['gemini-ide-server-12345-123.json']);
|
||||||
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -301,6 +325,10 @@ describe('IdeClient', () => {
|
|||||||
).getConnectionConfigFromFile();
|
).getConnectionConfigFromFile();
|
||||||
|
|
||||||
expect(result).toEqual(config);
|
expect(result).toEqual(config);
|
||||||
|
expect(fs.promises.readFile).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp', 'gemini', 'ide', 'gemini-ide-server-12345-123.json'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should filter out configs with invalid workspace paths', async () => {
|
it('should filter out configs with invalid workspace paths', async () => {
|
||||||
@@ -312,17 +340,20 @@ describe('IdeClient', () => {
|
|||||||
port: '1111',
|
port: '1111',
|
||||||
workspacePath: '/invalid/workspace',
|
workspacePath: '/invalid/workspace',
|
||||||
};
|
};
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'),
|
|
||||||
JSON.stringify(invalidConfig),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
await fs.promises.writeFile(
|
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-222.json'),
|
|
||||||
JSON.stringify(validConfig),
|
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json',
|
||||||
|
'gemini-ide-server-12345-222.json',
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile)
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(invalidConfig))
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(validConfig));
|
||||||
|
|
||||||
const validateSpy = vi
|
const validateSpy = vi
|
||||||
.spyOn(IdeClient, 'validateWorkspacePath')
|
.spyOn(IdeClient, 'validateWorkspacePath')
|
||||||
@@ -350,18 +381,20 @@ describe('IdeClient', () => {
|
|||||||
it('should return the first valid config when multiple workspaces are valid', async () => {
|
it('should return the first valid config when multiple workspaces are valid', async () => {
|
||||||
const config1 = { port: '1111', workspacePath: '/test/workspace' };
|
const config1 = { port: '1111', workspacePath: '/test/workspace' };
|
||||||
const config2 = { port: '2222', workspacePath: '/test/workspace2' };
|
const config2 = { port: '2222', workspacePath: '/test/workspace2' };
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'),
|
|
||||||
JSON.stringify(config1),
|
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
await fs.promises.writeFile(
|
(
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-222.json'),
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
JSON.stringify(config2),
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
'utf8',
|
>
|
||||||
);
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json',
|
||||||
|
'gemini-ide-server-12345-222.json',
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile)
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config1))
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config2));
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -373,10 +406,6 @@ describe('IdeClient', () => {
|
|||||||
}
|
}
|
||||||
).getConnectionConfigFromFile();
|
).getConnectionConfigFromFile();
|
||||||
|
|
||||||
// readdir order is not guaranteed, but usually sorted by name or creation.
|
|
||||||
// The implementation of getConnectionConfigFromFile explicitly sorts the files:
|
|
||||||
// const matchingFiles = portFiles.filter(...).sort();
|
|
||||||
// So '111' should come before '222'.
|
|
||||||
expect(result).toEqual(config1);
|
expect(result).toEqual(config1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -384,18 +413,20 @@ describe('IdeClient', () => {
|
|||||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '2222';
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '2222';
|
||||||
const config1 = { port: '1111', workspacePath: '/test/workspace' };
|
const config1 = { port: '1111', workspacePath: '/test/workspace' };
|
||||||
const config2 = { port: '2222', workspacePath: '/test/workspace2' };
|
const config2 = { port: '2222', workspacePath: '/test/workspace2' };
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'),
|
|
||||||
JSON.stringify(config1),
|
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
await fs.promises.writeFile(
|
(
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-222.json'),
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
JSON.stringify(config2),
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
'utf8',
|
>
|
||||||
);
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json',
|
||||||
|
'gemini-ide-server-12345-222.json',
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile)
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config1))
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config2));
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -412,18 +443,20 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should handle invalid JSON in one of the config files', async () => {
|
it('should handle invalid JSON in one of the config files', async () => {
|
||||||
const validConfig = { port: '2222', workspacePath: '/test/workspace' };
|
const validConfig = { port: '2222', workspacePath: '/test/workspace' };
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'),
|
|
||||||
'invalid json',
|
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
await fs.promises.writeFile(
|
(
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-222.json'),
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
JSON.stringify(validConfig),
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
'utf8',
|
>
|
||||||
);
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json',
|
||||||
|
'gemini-ide-server-12345-222.json',
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile)
|
||||||
|
.mockResolvedValueOnce('invalid json')
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(validConfig));
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -438,25 +471,41 @@ describe('IdeClient', () => {
|
|||||||
expect(result).toEqual(validConfig);
|
expect(result).toEqual(validConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return undefined if readdir throws an error', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
|
new Error('not found'),
|
||||||
|
);
|
||||||
|
vi.mocked(fs.promises.readdir).mockRejectedValue(
|
||||||
|
new Error('readdir failed'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const ideClient = await IdeClient.getInstance();
|
||||||
|
const result = await (
|
||||||
|
ideClient as unknown as {
|
||||||
|
getConnectionConfigFromFile: () => Promise<unknown>;
|
||||||
|
}
|
||||||
|
).getConnectionConfigFromFile();
|
||||||
|
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('should ignore files with invalid names', async () => {
|
it('should ignore files with invalid names', async () => {
|
||||||
const validConfig = { port: '3333', workspacePath: '/test/workspace' };
|
const validConfig = { port: '3333', workspacePath: '/test/workspace' };
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'), // valid
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json', // valid
|
||||||
|
'not-a-config-file.txt', // invalid
|
||||||
|
'gemini-ide-server-asdf.json', // invalid
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile).mockResolvedValueOnce(
|
||||||
JSON.stringify(validConfig),
|
JSON.stringify(validConfig),
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
await fs.promises.writeFile(
|
|
||||||
path.join(ideConfigDir, 'not-a-config-file.txt'), // invalid
|
|
||||||
'some content',
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
await fs.promises.writeFile(
|
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-asdf.json'), // invalid
|
|
||||||
'some content',
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -469,24 +518,34 @@ describe('IdeClient', () => {
|
|||||||
).getConnectionConfigFromFile();
|
).getConnectionConfigFromFile();
|
||||||
|
|
||||||
expect(result).toEqual(validConfig);
|
expect(result).toEqual(validConfig);
|
||||||
|
expect(fs.promises.readFile).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp', 'gemini', 'ide', 'gemini-ide-server-12345-111.json'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
expect(fs.promises.readFile).not.toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp', 'gemini', 'ide', 'not-a-config-file.txt'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should match env port string to a number port in the config', async () => {
|
it('should match env port string to a number port in the config', async () => {
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '3333';
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '3333';
|
||||||
const config1 = { port: 1111, workspacePath: '/test/workspace' };
|
const config1 = { port: 1111, workspacePath: '/test/workspace' };
|
||||||
const config2 = { port: 3333, workspacePath: '/test/workspace2' };
|
const config2 = { port: 3333, workspacePath: '/test/workspace2' };
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValueOnce(
|
||||||
await fs.promises.writeFile(
|
new Error('not found'),
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-111.json'),
|
|
||||||
JSON.stringify(config1),
|
|
||||||
'utf8',
|
|
||||||
);
|
);
|
||||||
await fs.promises.writeFile(
|
(
|
||||||
path.join(ideConfigDir, 'gemini-ide-server-12345-222.json'),
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
JSON.stringify(config2),
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
'utf8',
|
>
|
||||||
);
|
).mockResolvedValue([
|
||||||
|
'gemini-ide-server-12345-111.json',
|
||||||
|
'gemini-ide-server-12345-222.json',
|
||||||
|
]);
|
||||||
|
vi.mocked(fs.promises.readFile)
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config1))
|
||||||
|
.mockResolvedValueOnce(JSON.stringify(config2));
|
||||||
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
vi.spyOn(IdeClient, 'validateWorkspacePath').mockReturnValue({
|
||||||
isValid: true,
|
isValid: true,
|
||||||
});
|
});
|
||||||
@@ -510,12 +569,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should return false if tool discovery fails', async () => {
|
it('should return false if tool discovery fails', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
mockClient.request.mockRejectedValue(new Error('Method not found'));
|
mockClient.request.mockRejectedValue(new Error('Method not found'));
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
@@ -529,12 +588,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should return false if diffing tools are not available', async () => {
|
it('should return false if diffing tools are not available', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
mockClient.request.mockResolvedValue({
|
mockClient.request.mockResolvedValue({
|
||||||
tools: [{ name: 'someOtherTool' }],
|
tools: [{ name: 'someOtherTool' }],
|
||||||
});
|
});
|
||||||
@@ -550,12 +609,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should return false if only openDiff tool is available', async () => {
|
it('should return false if only openDiff tool is available', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
mockClient.request.mockResolvedValue({
|
mockClient.request.mockResolvedValue({
|
||||||
tools: [{ name: 'openDiff' }],
|
tools: [{ name: 'openDiff' }],
|
||||||
});
|
});
|
||||||
@@ -571,12 +630,12 @@ describe('IdeClient', () => {
|
|||||||
|
|
||||||
it('should return true if connected and diffing tools are available', async () => {
|
it('should return true if connected and diffing tools are available', async () => {
|
||||||
const config = { port: '8080' };
|
const config = { port: '8080' };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
mockClient.request.mockResolvedValue({
|
mockClient.request.mockResolvedValue({
|
||||||
tools: [{ name: 'openDiff' }, { name: 'closeDiff' }],
|
tools: [{ name: 'openDiff' }, { name: 'closeDiff' }],
|
||||||
});
|
});
|
||||||
@@ -843,11 +902,12 @@ describe('IdeClient', () => {
|
|||||||
it('should connect with an auth token if provided in the discovery file', async () => {
|
it('should connect with an auth token if provided in the discovery file', async () => {
|
||||||
const authToken = 'test-auth-token';
|
const authToken = 'test-auth-token';
|
||||||
const config = { port: '8080', authToken };
|
const config = { port: '8080', authToken };
|
||||||
const configPath = path.join(
|
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(config));
|
||||||
ideConfigDir,
|
(
|
||||||
'gemini-ide-server-12345.json',
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
);
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
await fs.promises.writeFile(configPath, JSON.stringify(config), 'utf8');
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
@@ -868,6 +928,14 @@ describe('IdeClient', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should connect with an auth token from environment variable if config file is missing', async () => {
|
it('should connect with an auth token from environment variable if config file is missing', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(
|
||||||
|
new Error('File not found'),
|
||||||
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||||
process.env['GEMINI_CLI_IDE_AUTH_TOKEN'] = 'env-auth-token';
|
process.env['GEMINI_CLI_IDE_AUTH_TOKEN'] = 'env-auth-token';
|
||||||
|
|
||||||
@@ -892,12 +960,14 @@ describe('IdeClient', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('getIdeServerHost', () => {
|
describe('getIdeServerHost', () => {
|
||||||
|
let existsSyncMock: Mock;
|
||||||
let originalSshConnection: string | undefined;
|
let originalSshConnection: string | undefined;
|
||||||
let originalVscodeRemoteSession: string | undefined;
|
let originalVscodeRemoteSession: string | undefined;
|
||||||
let originalRemoteContainers: string | undefined;
|
let originalRemoteContainers: string | undefined;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(fs.existsSync).mockClear();
|
existsSyncMock = vi.mocked(fs.existsSync);
|
||||||
|
existsSyncMock.mockClear();
|
||||||
originalSshConnection = process.env['SSH_CONNECTION'];
|
originalSshConnection = process.env['SSH_CONNECTION'];
|
||||||
originalVscodeRemoteSession =
|
originalVscodeRemoteSession =
|
||||||
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
@@ -909,7 +979,7 @@ describe('getIdeServerHost', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.clearAllMocks();
|
||||||
if (originalSshConnection !== undefined) {
|
if (originalSshConnection !== undefined) {
|
||||||
process.env['SSH_CONNECTION'] = originalSshConnection;
|
process.env['SSH_CONNECTION'] = originalSshConnection;
|
||||||
} else {
|
} else {
|
||||||
@@ -933,18 +1003,15 @@ describe('getIdeServerHost', () => {
|
|||||||
dockerenvExists: boolean,
|
dockerenvExists: boolean,
|
||||||
containerenvExists: boolean,
|
containerenvExists: boolean,
|
||||||
) => {
|
) => {
|
||||||
vi.mocked(fs.existsSync).mockImplementation(
|
existsSyncMock.mockImplementation((path: string) => {
|
||||||
(path: string | fs.PathLike) => {
|
if (path === '/.dockerenv') {
|
||||||
const p = path.toString();
|
return dockerenvExists;
|
||||||
if (p === '/.dockerenv') {
|
}
|
||||||
return dockerenvExists;
|
if (path === '/run/.containerenv') {
|
||||||
}
|
return containerenvExists;
|
||||||
if (p === '/run/.containerenv') {
|
}
|
||||||
return containerenvExists;
|
return false;
|
||||||
}
|
});
|
||||||
return false;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should return 127.0.0.1 when not in container and no SSH_CONNECTION or Dev Container env vars', () => {
|
it('should return 127.0.0.1 when not in container and no SSH_CONNECTION or Dev Container env vars', () => {
|
||||||
@@ -953,8 +1020,8 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/run/.containerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/run/.containerenv');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when not in container but SSH_CONNECTION is set', () => {
|
it('should return 127.0.0.1 when not in container but SSH_CONNECTION is set', () => {
|
||||||
@@ -963,8 +1030,8 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/run/.containerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/run/.containerenv');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return host.docker.internal when in .dockerenv container and no SSH_CONNECTION or Dev Container env vars', () => {
|
it('should return host.docker.internal when in .dockerenv container and no SSH_CONNECTION or Dev Container env vars', () => {
|
||||||
@@ -973,8 +1040,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('host.docker.internal');
|
expect(getIdeServerHost()).toBe('host.docker.internal');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in .dockerenv container and SSH_CONNECTION is set', () => {
|
it('should return 127.0.0.1 when in .dockerenv container and SSH_CONNECTION is set', () => {
|
||||||
@@ -983,8 +1052,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in .dockerenv container and VSCODE_REMOTE_CONTAINERS_SESSION is set', () => {
|
it('should return 127.0.0.1 when in .dockerenv container and VSCODE_REMOTE_CONTAINERS_SESSION is set', () => {
|
||||||
@@ -992,8 +1063,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['SSH_CONNECTION'];
|
delete process.env['SSH_CONNECTION'];
|
||||||
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'] = 'some_session_id';
|
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'] = 'some_session_id';
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return host.docker.internal when in .containerenv container and no SSH_CONNECTION or Dev Container env vars', () => {
|
it('should return host.docker.internal when in .containerenv container and no SSH_CONNECTION or Dev Container env vars', () => {
|
||||||
@@ -1002,8 +1075,8 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('host.docker.internal');
|
expect(getIdeServerHost()).toBe('host.docker.internal');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/run/.containerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/run/.containerenv');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in .containerenv container and SSH_CONNECTION is set', () => {
|
it('should return 127.0.0.1 when in .containerenv container and SSH_CONNECTION is set', () => {
|
||||||
@@ -1012,8 +1085,8 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/run/.containerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/run/.containerenv');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in .containerenv container and REMOTE_CONTAINERS is set', () => {
|
it('should return 127.0.0.1 when in .containerenv container and REMOTE_CONTAINERS is set', () => {
|
||||||
@@ -1021,8 +1094,8 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['SSH_CONNECTION'];
|
delete process.env['SSH_CONNECTION'];
|
||||||
process.env['REMOTE_CONTAINERS'] = 'true';
|
process.env['REMOTE_CONTAINERS'] = 'true';
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/run/.containerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/run/.containerenv');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return host.docker.internal when in both containers and no SSH_CONNECTION or Dev Container env vars', () => {
|
it('should return host.docker.internal when in both containers and no SSH_CONNECTION or Dev Container env vars', () => {
|
||||||
@@ -1031,8 +1104,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('host.docker.internal');
|
expect(getIdeServerHost()).toBe('host.docker.internal');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in both containers and SSH_CONNECTION is set', () => {
|
it('should return 127.0.0.1 when in both containers and SSH_CONNECTION is set', () => {
|
||||||
@@ -1041,8 +1116,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
delete process.env['VSCODE_REMOTE_CONTAINERS_SESSION'];
|
||||||
delete process.env['REMOTE_CONTAINERS'];
|
delete process.env['REMOTE_CONTAINERS'];
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 127.0.0.1 when in both containers and VSCODE_REMOTE_CONTAINERS_SESSION is set', () => {
|
it('should return 127.0.0.1 when in both containers and VSCODE_REMOTE_CONTAINERS_SESSION is set', () => {
|
||||||
@@ -1050,8 +1127,10 @@ describe('getIdeServerHost', () => {
|
|||||||
delete process.env['SSH_CONNECTION'];
|
delete process.env['SSH_CONNECTION'];
|
||||||
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'] = 'some_session_id';
|
process.env['VSCODE_REMOTE_CONTAINERS_SESSION'] = 'some_session_id';
|
||||||
expect(getIdeServerHost()).toBe('127.0.0.1');
|
expect(getIdeServerHost()).toBe('127.0.0.1');
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('/.dockerenv');
|
expect(vi.mocked(fs.existsSync)).toHaveBeenCalledWith('/.dockerenv');
|
||||||
expect(fs.existsSync).not.toHaveBeenCalledWith('/run/.containerenv'); // Short-circuiting
|
expect(vi.mocked(fs.existsSync)).not.toHaveBeenCalledWith(
|
||||||
|
'/run/.containerenv',
|
||||||
|
); // Short-circuiting
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateWorkspacePath', () => {
|
describe('validateWorkspacePath', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user