Files
waggle-os/packages/team-server/tests/config.test.ts
shumeiko.it c25efe6c44 refactor(server): move the team runtime into a postponed package (P1.1)
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).
2026-10-24 12:17:41 +02:00

54 lines
2.0 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { loadConfig } from '../src/config.js';
// Guards the CORS_ORIGIN fail-closed contract on the TEAM server config
// (packages/server/src/config.ts). The team server (index.ts) is the only
// consumer of config.corsOrigin; the desktop/local server uses the separate
// hardcoded ALLOWED_ORIGINS allowlist (local/cors-config.ts) and is unaffected.
describe('loadConfig — CORS_ORIGIN', () => {
const SAVED = {
CORS_ORIGIN: process.env.CORS_ORIGIN,
NODE_ENV: process.env.NODE_ENV,
DATABASE_URL: process.env.DATABASE_URL,
};
beforeEach(() => {
delete process.env.CORS_ORIGIN;
delete process.env.NODE_ENV;
// DATABASE_URL also fails closed in production; set it so we isolate the
// CORS_ORIGIN behavior under test.
process.env.DATABASE_URL = 'postgres://localhost:5434/waggle';
});
afterEach(() => {
for (const [k, v] of Object.entries(SAVED)) {
if (v === undefined) delete process.env[k];
else process.env[k] = v;
}
});
it('defaults to the localhost dev origin when CORS_ORIGIN is unset (non-production)', () => {
expect(loadConfig().corsOrigin).toEqual(['http://localhost:5173']);
});
it('FAILS CLOSED in production when CORS_ORIGIN is unset (no silent localhost fallback)', () => {
process.env.NODE_ENV = 'production';
expect(() => loadConfig()).toThrow(/CORS_ORIGIN.*required in production/);
});
it('parses a comma-separated list, trimming whitespace and dropping empties', () => {
process.env.NODE_ENV = 'production';
process.env.CORS_ORIGIN = 'https://app.example.com, https://admin.example.com ,';
expect(loadConfig().corsOrigin).toEqual([
'https://app.example.com',
'https://admin.example.com',
]);
});
it('accepts a single explicit origin in production', () => {
process.env.NODE_ENV = 'production';
process.env.CORS_ORIGIN = 'https://app.example.com';
expect(loadConfig().corsOrigin).toEqual(['https://app.example.com']);
});
});