audit follow-up: reduce warning hotspots in automation and gateway tests

This commit is contained in:
William Valentin
2026-02-15 22:49:45 -08:00
parent 1a075e62b0
commit e16c0bc2c7
7 changed files with 157 additions and 85 deletions
+24 -18
View File
@@ -1,5 +1,6 @@
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest';
import { execFile } from 'child_process';
import type { ChildProcess } from 'child_process';
// Mock child_process before importing module
vi.mock('child_process', () => ({
@@ -7,6 +8,11 @@ vi.mock('child_process', () => ({
}));
const mockExecFile = vi.mocked(execFile);
type ExecFileCallback = (error: Error | null, stdout: string, stderr: string) => void;
function mockChildProcess(): ChildProcess {
return {} as ChildProcess;
}
describe('tailscale', () => {
// Import after mocking
@@ -28,13 +34,13 @@ describe('tailscale', () => {
describe('isTailscaleAvailable', () => {
it('returns available when tailscale CLI works', async () => {
mockExecFile
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, '1.62.0', '');
return {} as any;
return mockChildProcess();
})
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, '{}', '');
return {} as any;
return mockChildProcess();
});
const result = await isTailscaleAvailable();
@@ -43,9 +49,9 @@ describe('tailscale', () => {
});
it('returns unavailable when tailscale CLI fails', async () => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(new Error('command not found'), '', 'command not found');
return {} as any;
return mockChildProcess();
});
const result = await isTailscaleAvailable();
@@ -58,14 +64,14 @@ describe('tailscale', () => {
it('calls tailscale serve with correct args', async () => {
mockExecFile
// serve command
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, '', '');
return {} as any;
return mockChildProcess();
})
// status for hostname
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, JSON.stringify({ Self: { DNSName: 'myhost.tailnet.ts.net.' } }), '');
return {} as any;
return mockChildProcess();
});
const url = await startTailscaleServe({ localPort: 18800 });
@@ -78,13 +84,13 @@ describe('tailscale', () => {
it('uses custom serve port', async () => {
mockExecFile
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, '', '');
return {} as any;
return mockChildProcess();
})
.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, JSON.stringify({ Self: { DNSName: 'myhost.tailnet.ts.net.' } }), '');
return {} as any;
return mockChildProcess();
});
const url = await startTailscaleServe({ localPort: 18800, servePort: 8443 });
@@ -97,9 +103,9 @@ describe('tailscale', () => {
describe('stopTailscaleServe', () => {
it('calls tailscale serve off', async () => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(null, '', '');
return {} as any;
return mockChildProcess();
});
await stopTailscaleServe({ localPort: 18800 });
@@ -111,9 +117,9 @@ describe('tailscale', () => {
});
it('does not throw on failure', async () => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: any) => {
mockExecFile.mockImplementationOnce((_cmd, _args, _opts, callback: ExecFileCallback) => {
callback(new Error('failed'), '', 'failed');
return {} as any;
return mockChildProcess();
});
// Should not throw