test: mock OS exports consistently and verify LAN discovery
This commit is contained in:
1 parent
b193bee03f
commit
fa39fb34fe
2 files changed
+31
-5
No files matched your search
@@ -255,4 +255,4 @@ Retry durations are parsed as complete values: `500ms` is milliseconds, and frac
|
|||||||
|
|
||||||
Focused checks: `pnpm exec vitest run src/tests/unit/rate-limit-tracker.test.ts src/tests/unit/ipc/proxy-advanced-handler.test.ts`. Run `pnpm test`, `pnpm type-check`, `pnpm lint` and `pnpm format` for the full non-E2E gates. Native SQLite/keytar are mocked by the unit-test configuration; Electron packaging, real account switching and E2E still require separate validation.
|
Focused checks: `pnpm exec vitest run src/tests/unit/rate-limit-tracker.test.ts src/tests/unit/ipc/proxy-advanced-handler.test.ts`. Run `pnpm test`, `pnpm type-check`, `pnpm lint` and `pnpm format` for the full non-E2E gates. Native SQLite/keytar are mocked by the unit-test configuration; Electron packaging, real account switching and E2E still require separate validation.
|
||||||
|
|
||||||
This review passes all 508 tests across 54 files, type checking, lint (327 existing warnings, no errors) and formatting with Node 24.19.0 and pnpm 10.11.0. The original lockfile is retained: its audit still reports two critical findings, in `tar` and `seroval`, requiring a separately validated dependency update.
|
This review passes all 509 tests across 54 files, type checking, lint (327 existing warnings, no errors) and formatting with Node 24.19.0 and pnpm 10.11.0. The original lockfile is retained: its audit still reports two critical findings, in `tar` and `seroval`, requiring a separately validated dependency update.
|
||||||
@@ -15,10 +15,15 @@ import {
|
|||||||
import { TrafficLogsRepo } from '../../../ipc/database/proxyMetricsHandler';
|
import { TrafficLogsRepo } from '../../../ipc/database/proxyMetricsHandler';
|
||||||
import { proxyAdvancedRegistry } from '../../../ipc/proxy-advanced/service-registry';
|
import { proxyAdvancedRegistry } from '../../../ipc/proxy-advanced/service-registry';
|
||||||
|
|
||||||
vi.mock('os', async (importOriginal) => ({
|
vi.mock('os', async (importOriginal) => {
|
||||||
...(await importOriginal<typeof import('os')>()),
|
const actual = await importOriginal<typeof import('os')>();
|
||||||
networkInterfaces: vi.fn().mockReturnValue({}),
|
const mockedNetworkInterfaces = vi.fn().mockReturnValue({});
|
||||||
}));
|
return {
|
||||||
|
...actual,
|
||||||
|
default: { ...actual, networkInterfaces: mockedNetworkInterfaces },
|
||||||
|
networkInterfaces: mockedNetworkInterfaces,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock('../../../utils/logger', () => ({
|
vi.mock('../../../utils/logger', () => ({
|
||||||
logger: {
|
logger: {
|
||||||
@@ -73,6 +78,7 @@ vi.mock('../../../ipc/proxy-advanced/service-registry', () => {
|
|||||||
describe('Proxy Advanced Handler', () => {
|
describe('Proxy Advanced Handler', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
vi.mocked(networkInterfaces).mockReset().mockReturnValue({});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRecentTrafficLogs', () => {
|
describe('getRecentTrafficLogs', () => {
|
||||||
@@ -426,10 +432,30 @@ describe('Proxy Advanced Handler', () => {
|
|||||||
throw new Error('network enumeration denied');
|
throw new Error('network enumeration denied');
|
||||||
});
|
});
|
||||||
const result = await generateIdeConfig('vscode');
|
const result = await generateIdeConfig('vscode');
|
||||||
|
expect(networkInterfaces).toHaveBeenCalledOnce();
|
||||||
expect(result.success, result.error).toBe(true);
|
expect(result.success, result.error).toBe(true);
|
||||||
expect(result.data?.content).toMatchObject({ 'openai.url': 'http://127.0.0.1:8045/v1' });
|
expect(result.data?.content).toMatchObject({ 'openai.url': 'http://127.0.0.1:8045/v1' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the discovered LAN address when enumeration succeeds', async () => {
|
||||||
|
vi.mocked(networkInterfaces).mockReturnValueOnce({
|
||||||
|
eth0: [
|
||||||
|
{
|
||||||
|
address: '192.0.2.10',
|
||||||
|
netmask: '255.255.255.0',
|
||||||
|
family: 'IPv4',
|
||||||
|
mac: '00:11:22:33:44:55',
|
||||||
|
internal: false,
|
||||||
|
cidr: '192.0.2.10/24',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const result = await generateIdeConfig('vscode');
|
||||||
|
expect(networkInterfaces).toHaveBeenCalledOnce();
|
||||||
|
expect(result.success, result.error).toBe(true);
|
||||||
|
expect(result.data?.content).toMatchObject({ 'openai.url': 'http://192.0.2.10:8045/v1' });
|
||||||
|
});
|
||||||
|
|
||||||
it('should generate fallback config when proxyIdeConfig is null', async () => {
|
it('should generate fallback config when proxyIdeConfig is null', async () => {
|
||||||
const result = await generateIdeConfig('vscode');
|
const result = await generateIdeConfig('vscode');
|
||||||
expect(result.success, result.error).toBe(true);
|
expect(result.success, result.error).toBe(true);
|
||||||
|
|||||||
Reference in new issue
Block a user