Move src/ → apps/server/ and packages/web/ → apps/web/ to adopt standard monorepo conventions (apps/ for runnable apps, packages/ for reusable libraries). Update all config files, shared package imports, test fixtures, and documentation to reflect new paths. Key fixes: - Update workspace config to ["apps/*", "packages/*"] - Update tsconfig.json rootDir/include for apps/server/ - Add apps/web/** to vitest exclude list - Update drizzle.config.ts schema path - Fix ensure-schema.ts migration path detection (3 levels up in dev, 2 levels up in dist) - Fix tests/integration/cli-server.test.ts import paths - Update packages/shared imports to apps/server/ paths - Update all docs/ files with new paths
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { createServer } from 'node:net';
|
|
|
|
// Mock the docker-client module to avoid actual Docker calls
|
|
vi.mock('./docker-client.js', () => ({
|
|
getPreviewPorts: vi.fn(),
|
|
}));
|
|
|
|
import { allocatePort } from './port-allocator.js';
|
|
import { getPreviewPorts } from './docker-client.js';
|
|
|
|
const mockedGetPreviewPorts = vi.mocked(getPreviewPorts);
|
|
|
|
describe('allocatePort', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('returns BASE_PORT (9100) when no ports are in use', async () => {
|
|
mockedGetPreviewPorts.mockResolvedValue([]);
|
|
const port = await allocatePort();
|
|
expect(port).toBe(9100);
|
|
});
|
|
|
|
it('skips ports already used by previews', async () => {
|
|
mockedGetPreviewPorts.mockResolvedValue([9100, 9101]);
|
|
const port = await allocatePort();
|
|
expect(port).toBe(9102);
|
|
});
|
|
|
|
it('skips non-contiguous used ports', async () => {
|
|
mockedGetPreviewPorts.mockResolvedValue([9100, 9103]);
|
|
const port = await allocatePort();
|
|
expect(port).toBe(9101);
|
|
});
|
|
|
|
it('skips a port that is bound by another process', async () => {
|
|
mockedGetPreviewPorts.mockResolvedValue([]);
|
|
|
|
// Bind port 9100 to simulate external use
|
|
const server = createServer();
|
|
await new Promise<void>((resolve) => {
|
|
server.listen(9100, '127.0.0.1', () => resolve());
|
|
});
|
|
|
|
try {
|
|
const port = await allocatePort();
|
|
expect(port).toBe(9101);
|
|
} finally {
|
|
await new Promise<void>((resolve) => {
|
|
server.close(() => resolve());
|
|
});
|
|
}
|
|
});
|
|
});
|