Refactor preview deployments to use a single shared Caddy gateway container with subdomain routing (<previewId>.localhost:<port>) instead of one Caddy sidecar and one port per preview. Adds dev/preview modes, git worktree support for branch checkouts, and auto-start on phase:pending_review. - Add GatewayManager for shared Caddy lifecycle + Caddyfile generation - Add git worktree helpers for preview mode branch checkouts - Add dev mode: volume-mount + dev server image instead of build - Remove per-preview Caddy sidecar and port publishing - Use shared cw-preview-net Docker network with container name DNS - Auto-start previews when phase enters pending_review - Delete unused PreviewPanel.tsx - Update all tests (40 pass), docs, events, CLI, tRPC, frontend
33 lines
859 B
TypeScript
33 lines
859 B
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { createServer } from 'node:net';
|
|
|
|
import { allocatePort } from './port-allocator.js';
|
|
|
|
describe('allocatePort', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('returns BASE_PORT (9100) when the port is available', async () => {
|
|
const port = await allocatePort();
|
|
expect(port).toBe(9100);
|
|
});
|
|
|
|
it('skips a port that is bound by another process', async () => {
|
|
// 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());
|
|
});
|
|
}
|
|
});
|
|
});
|