Initial commit: OneOS prototype workspace baseline.
Include weekly report and other prototype sources with project tooling config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
44
vite-plugins/portOccupancy.test.ts
Normal file
44
vite-plugins/portOccupancy.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import {
|
||||
findListeningPidsOnPort,
|
||||
releaseListeningProcessesOnPort,
|
||||
} from './utils/portOccupancy';
|
||||
|
||||
describe('client port occupancy helpers', () => {
|
||||
it('reads listening PIDs with lsof on macOS and Linux', () => {
|
||||
const spawnSync = vi.fn(() => ({
|
||||
stdout: '123\n456\n123\n',
|
||||
stderr: '',
|
||||
status: 0,
|
||||
})) as any;
|
||||
|
||||
expect(findListeningPidsOnPort(51720, {
|
||||
platform: 'darwin',
|
||||
spawnSync,
|
||||
})).toEqual([123, 456]);
|
||||
expect(spawnSync).toHaveBeenCalledWith('lsof', [
|
||||
'-tiTCP',
|
||||
':51720',
|
||||
'-sTCP:LISTEN',
|
||||
], expect.objectContaining({ encoding: 'utf8' }));
|
||||
});
|
||||
|
||||
it('terminates other listening processes while ignoring the current process', () => {
|
||||
const spawnSync = vi.fn(() => ({
|
||||
stdout: '111\n222\n',
|
||||
stderr: '',
|
||||
status: 0,
|
||||
})) as any;
|
||||
const killPid = vi.fn();
|
||||
|
||||
expect(releaseListeningProcessesOnPort(51720, {
|
||||
platform: 'linux',
|
||||
spawnSync,
|
||||
killPid,
|
||||
currentPid: 111,
|
||||
waitMs: 0,
|
||||
})).toEqual([222]);
|
||||
expect(killPid).toHaveBeenCalledWith(222, 'SIGTERM');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user