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:
王冕
2026-06-26 15:36:52 +08:00
commit 7ef8852919
1310 changed files with 282074 additions and 0 deletions

View 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');
});
});