Team mode stays in the repository but is not built or shipped (ADR-0003). - The team server (index.ts, config, db, daemons, plugins, proactive, routes, scheduler, services, ws, drizzle migrations) and its tests move from @waggle/server to packages/team-server (@waggle/team-server, private). It keeps its own copies of the logger and the agent-group executor, so it does not import @waggle/server. @clerk/fastify, bullmq, ioredis, postgres, drizzle-orm, drizzle-kit, cron-parser and @waggle/waggle-dance leave @waggle/server; the launcher drops the same team-only dependencies. - build:packages no longer builds waggle-dance or the worker: nothing in the community edition imports them, and the worker's project reference would otherwise build the team server. The worker now imports from team-server; the team Dockerfile builds both explicitly. - The sidecar no longer starts the team server when DATABASE_URL is set, and loses the team routes (/api/team/*, /api/teams), the WaggleDance routes and bridge (/api/waggle-dance/*), the Team server binding and egress guard, the WebSocket team client, the TeamSync cache and pushes, team audit forwarding, team workspace registration and the team capability-policy lookup in chat. The in-process room signal bus stays: agent groups, fleet runs and external tool runs use it. middleware/audit.ts was dead and is deleted. - @waggle/core loses TeamSync and the teamServer part of WaggleConfig. A teamServer key in config.json is ignored and kept on save, as P0.1 does for the tier keys. Workspaces lose teamServerUrl and teamUserId; teamId and teamRole stay because workspaces from a shared data directory still carry them and the viewer write guards read them. POST /api/workspaces ignores team fields. - The sidecar bundle no longer marks the team packages as external. The agent still references the TeamSync type in orchestrator.ts and pattern-write-back.ts; those files are being rewritten in P1.5 and drop it there. Logs UF-030 and UF-031 (team sync and team policy defects found while removing the code).
73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
import { installShutdownHandlers, isDirectModule } from '../src/index.js';
|
|
|
|
const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url));
|
|
|
|
describe('cloud worker production entrypoint', () => {
|
|
it('keeps a standalone compiled build outside the community-edition package build', () => {
|
|
const rootPackage = JSON.parse(readFileSync(resolve(REPO_ROOT, 'package.json'), 'utf8')) as {
|
|
scripts: Record<string, string>;
|
|
};
|
|
const workerPackage = JSON.parse(
|
|
readFileSync(resolve(REPO_ROOT, 'packages/worker/package.json'), 'utf8'),
|
|
) as {
|
|
main?: string;
|
|
types?: string;
|
|
exports?: Record<string, { import?: string; types?: string }>;
|
|
scripts?: Record<string, string>;
|
|
};
|
|
const build = rootPackage.scripts['build:packages'];
|
|
|
|
// Team mode, the worker included, is postponed and not built (ADR-0003).
|
|
expect(build).not.toContain('../worker');
|
|
expect(workerPackage.scripts?.build).toContain('tsc --build --force');
|
|
expect(workerPackage.scripts?.build).toContain('--bundle');
|
|
expect(workerPackage.main).toBe('dist/index.js');
|
|
expect(workerPackage.types).toBe('dist/src/index.d.ts');
|
|
expect(workerPackage.exports?.['.']).toEqual({
|
|
types: './dist/src/index.d.ts',
|
|
import: './dist/index.js',
|
|
});
|
|
});
|
|
|
|
it('runs the compiled worker as a production Compose service', () => {
|
|
const compose = readFileSync(resolve(REPO_ROOT, 'docker-compose.production.yml'), 'utf8');
|
|
|
|
expect(compose).toMatch(/\n {2}worker:\r?\n/);
|
|
expect(compose).toContain("command: ['node', 'packages/worker/dist/index.js']");
|
|
expect(compose).toContain('DATABASE_URL=postgres://waggle:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/waggle');
|
|
expect(compose).toContain('REDIS_URL=redis://redis:6379');
|
|
});
|
|
|
|
it('recognizes the compiled entrypoint by URL identity', () => {
|
|
const distPath = resolve(REPO_ROOT, 'packages/worker/dist/index.js');
|
|
|
|
expect(isDirectModule(distPath, pathToFileURL(distPath).href)).toBe(true);
|
|
expect(isDirectModule(distPath, pathToFileURL(resolve(REPO_ROOT, 'consumer.js')).href)).toBe(false);
|
|
expect(isDirectModule(undefined, pathToFileURL(distPath).href)).toBe(false);
|
|
});
|
|
|
|
it('drains the worker once across repeated shutdown signals', async () => {
|
|
const listeners = new Map<string, () => void>();
|
|
let releaseClose!: () => void;
|
|
const close = vi.fn(() => new Promise<void>(resolve => { releaseClose = resolve; }));
|
|
const shutdown = installShutdownHandlers(
|
|
{ close },
|
|
{ once: (signal, listener) => { listeners.set(signal, listener); } },
|
|
);
|
|
|
|
expect([...listeners.keys()]).toEqual(['SIGTERM', 'SIGINT']);
|
|
listeners.get('SIGTERM')!();
|
|
listeners.get('SIGINT')!();
|
|
const draining = shutdown();
|
|
|
|
expect(shutdown()).toBe(draining);
|
|
expect(close).toHaveBeenCalledTimes(1);
|
|
releaseClose();
|
|
await draining;
|
|
});
|
|
});
|