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).
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { WaggleConfig, type ProviderEntry, type TeamServerConfig } from '../src/config.js';
|
||||
import { WaggleConfig, type ProviderEntry } from '../src/config.js';
|
||||
|
||||
describe('WaggleConfig', () => {
|
||||
const tempDirs: string[] = [];
|
||||
@@ -100,58 +100,23 @@ describe('WaggleConfig', () => {
|
||||
expect(config.getConfigDir()).toBe(configDir);
|
||||
});
|
||||
|
||||
describe('team server config', () => {
|
||||
it('returns null when no team server configured', () => {
|
||||
describe('commercial-edition keys', () => {
|
||||
it('ignores a teamServer key and keeps it in config.json on save', () => {
|
||||
const configDir = makeTempDir();
|
||||
const teamServer = { url: 'https://team.waggle.dev', token: 'clerk-jwt-token' };
|
||||
fs.writeFileSync(
|
||||
path.join(configDir, 'config.json'),
|
||||
JSON.stringify({ defaultModel: 'claude-sonnet-4-6', providers: {}, teamServer }),
|
||||
);
|
||||
|
||||
const config = new WaggleConfig(configDir);
|
||||
|
||||
expect(config.getTeamServer()).toBeNull();
|
||||
expect(config.isTeamConnected()).toBe(false);
|
||||
});
|
||||
|
||||
it('sets and gets team server config', () => {
|
||||
const configDir = makeTempDir();
|
||||
const config = new WaggleConfig(configDir);
|
||||
|
||||
const teamConfig: TeamServerConfig = {
|
||||
url: 'https://team.waggle.dev',
|
||||
token: 'clerk-jwt-token',
|
||||
userId: 'user-123',
|
||||
displayName: 'Marko',
|
||||
};
|
||||
|
||||
config.setTeamServer(teamConfig);
|
||||
expect('getTeamServer' in config).toBe(false);
|
||||
config.setDefaultModel('gpt-4o');
|
||||
config.save();
|
||||
|
||||
const config2 = new WaggleConfig(configDir);
|
||||
const loaded = config2.getTeamServer();
|
||||
expect(loaded).toEqual(teamConfig);
|
||||
expect(config2.isTeamConnected()).toBe(true);
|
||||
});
|
||||
|
||||
it('clears team server config', () => {
|
||||
const configDir = makeTempDir();
|
||||
const config = new WaggleConfig(configDir);
|
||||
|
||||
config.setTeamServer({ url: 'https://team.waggle.dev' });
|
||||
config.clearTeamServer();
|
||||
config.save();
|
||||
|
||||
const config2 = new WaggleConfig(configDir);
|
||||
expect(config2.getTeamServer()).toBeNull();
|
||||
expect(config2.isTeamConnected()).toBe(false);
|
||||
});
|
||||
|
||||
it('persists team server through save/load cycle', () => {
|
||||
const configDir = makeTempDir();
|
||||
const config = new WaggleConfig(configDir);
|
||||
|
||||
config.setTeamServer({ url: 'https://example.com', userId: 'u1' });
|
||||
config.save();
|
||||
|
||||
const config2 = new WaggleConfig(configDir);
|
||||
expect(config2.getTeamServer()!.url).toBe('https://example.com');
|
||||
expect(config2.getTeamServer()!.userId).toBe('u1');
|
||||
const raw = JSON.parse(fs.readFileSync(path.join(configDir, 'config.json'), 'utf-8'));
|
||||
expect(raw.defaultModel).toBe('gpt-4o');
|
||||
expect(raw.teamServer).toEqual(teamServer);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,301 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { frameToEntity, entityToSyncedFrame, TeamSync, type TeamSyncConfig } from '../src/team-sync.js';
|
||||
import type { MemoryFrame } from '@waggle/hive-mind-core';
|
||||
|
||||
describe('frameToEntity', () => {
|
||||
it('converts a MemoryFrame to team entity format', () => {
|
||||
const frame: MemoryFrame = {
|
||||
id: 42,
|
||||
frame_type: 'I',
|
||||
gop_id: 'project-context',
|
||||
t: 3,
|
||||
base_frame_id: null,
|
||||
content: 'The project uses React and TypeScript',
|
||||
importance: 'important',
|
||||
access_count: 5,
|
||||
created_at: '2026-03-12T10:00:00.000Z',
|
||||
last_accessed: '2026-03-12T12:00:00.000Z',
|
||||
};
|
||||
|
||||
const entity = frameToEntity(frame, 'user-abc', 'Marko');
|
||||
|
||||
expect(entity.entityType).toBe('memory_frame');
|
||||
expect(entity.name).toBe('project-context');
|
||||
expect(entity.properties.frameType).toBe('I');
|
||||
expect(entity.properties.t).toBe(3);
|
||||
expect(entity.properties.baseFrameId).toBeNull();
|
||||
expect(entity.properties.content).toBe('The project uses React and TypeScript');
|
||||
expect(entity.properties.importance).toBe('important');
|
||||
expect(entity.properties.authorId).toBe('user-abc');
|
||||
expect(entity.properties.authorName).toBe('Marko');
|
||||
expect(entity.properties.localId).toBe(42);
|
||||
});
|
||||
|
||||
it('preserves P-frame base_frame_id', () => {
|
||||
const frame: MemoryFrame = {
|
||||
id: 43,
|
||||
frame_type: 'P',
|
||||
gop_id: 'project-context',
|
||||
t: 4,
|
||||
base_frame_id: 42,
|
||||
content: 'Updated: now also using Tailwind',
|
||||
importance: 'normal',
|
||||
access_count: 0,
|
||||
created_at: '2026-03-12T11:00:00.000Z',
|
||||
last_accessed: '2026-03-12T11:00:00.000Z',
|
||||
};
|
||||
|
||||
const entity = frameToEntity(frame, 'user-xyz', 'Ana');
|
||||
|
||||
expect(entity.properties.frameType).toBe('P');
|
||||
expect(entity.properties.baseFrameId).toBe(42);
|
||||
expect(entity.properties.authorName).toBe('Ana');
|
||||
});
|
||||
});
|
||||
|
||||
describe('entityToSyncedFrame', () => {
|
||||
it('converts a team entity back to SyncedFrame', () => {
|
||||
const entity = {
|
||||
id: 'uuid-remote-1',
|
||||
name: 'project-context',
|
||||
properties: {
|
||||
frameType: 'I',
|
||||
t: 3,
|
||||
baseFrameId: null,
|
||||
content: 'The project uses React and TypeScript',
|
||||
importance: 'important',
|
||||
authorId: 'user-abc',
|
||||
authorName: 'Marko',
|
||||
localId: 42,
|
||||
},
|
||||
createdAt: '2026-03-12T10:00:00.000Z',
|
||||
};
|
||||
|
||||
const frame = entityToSyncedFrame(entity);
|
||||
|
||||
expect(frame.remoteId).toBe('uuid-remote-1');
|
||||
expect(frame.gopId).toBe('project-context');
|
||||
expect(frame.t).toBe(3);
|
||||
expect(frame.frameType).toBe('I');
|
||||
expect(frame.content).toBe('The project uses React and TypeScript');
|
||||
expect(frame.importance).toBe('important');
|
||||
expect(frame.authorId).toBe('user-abc');
|
||||
expect(frame.authorName).toBe('Marko');
|
||||
expect(frame.createdAt).toBe('2026-03-12T10:00:00.000Z');
|
||||
});
|
||||
|
||||
it('handles missing properties gracefully', () => {
|
||||
const entity = {
|
||||
id: 'uuid-remote-2',
|
||||
name: 'some-gop',
|
||||
properties: {},
|
||||
createdAt: '2026-03-12T10:00:00.000Z',
|
||||
};
|
||||
|
||||
const frame = entityToSyncedFrame(entity);
|
||||
|
||||
expect(frame.remoteId).toBe('uuid-remote-2');
|
||||
expect(frame.gopId).toBe('some-gop');
|
||||
expect(frame.t).toBe(0);
|
||||
expect(frame.frameType).toBe('I');
|
||||
expect(frame.content).toBe('');
|
||||
expect(frame.importance).toBe('normal');
|
||||
expect(frame.authorId).toBe('');
|
||||
expect(frame.authorName).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('TeamSync', () => {
|
||||
const mockConfig: TeamSyncConfig = {
|
||||
teamServerUrl: 'https://team.waggle.dev',
|
||||
teamSlug: 'test-team',
|
||||
authToken: 'test-jwt-token',
|
||||
userId: 'user-abc',
|
||||
displayName: 'Marko',
|
||||
};
|
||||
|
||||
let fetchSpy: ReturnType<typeof vi.fn>;
|
||||
let globalFetchSpy: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.fn();
|
||||
globalFetchSpy = vi.fn().mockRejectedValue(new Error('raw global fetch used'));
|
||||
vi.stubGlobal('fetch', globalFetchSpy);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('pushFrame', () => {
|
||||
it('sends frame to team server entities endpoint', async () => {
|
||||
fetchSpy.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'remote-uuid-1' }),
|
||||
});
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frame: MemoryFrame = {
|
||||
id: 1,
|
||||
frame_type: 'I',
|
||||
gop_id: 'test-gop',
|
||||
t: 0,
|
||||
base_frame_id: null,
|
||||
content: 'Test content',
|
||||
importance: 'normal',
|
||||
access_count: 0,
|
||||
created_at: '2026-03-12T10:00:00.000Z',
|
||||
last_accessed: '2026-03-12T10:00:00.000Z',
|
||||
};
|
||||
|
||||
const result = await sync.pushFrame(frame);
|
||||
|
||||
expect(result).toEqual({ remoteId: 'remote-uuid-1' });
|
||||
expect(fetchSpy).toHaveBeenCalledOnce();
|
||||
expect(globalFetchSpy).not.toHaveBeenCalled();
|
||||
|
||||
const [url, opts] = fetchSpy.mock.calls[0];
|
||||
expect(url).toBe('https://team.waggle.dev/api/teams/test-team/entities');
|
||||
expect(opts.method).toBe('POST');
|
||||
expect(opts.headers['Authorization']).toBe('Bearer test-jwt-token');
|
||||
|
||||
const body = JSON.parse(opts.body);
|
||||
expect(body.entityType).toBe('memory_frame');
|
||||
expect(body.name).toBe('test-gop');
|
||||
expect(body.properties.content).toBe('Test content');
|
||||
expect(body.properties.authorId).toBe('user-abc');
|
||||
expect(body.properties.authorName).toBe('Marko');
|
||||
});
|
||||
|
||||
it('returns null on server error', async () => {
|
||||
fetchSpy.mockResolvedValue({
|
||||
ok: false,
|
||||
status: 500,
|
||||
statusText: 'Internal Server Error',
|
||||
});
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frame: MemoryFrame = {
|
||||
id: 1, frame_type: 'I', gop_id: 'test', t: 0, base_frame_id: null,
|
||||
content: 'x', importance: 'normal', access_count: 0,
|
||||
created_at: '2026-03-12T10:00:00.000Z', last_accessed: '2026-03-12T10:00:00.000Z',
|
||||
};
|
||||
|
||||
const result = await sync.pushFrame(frame);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null on network error', async () => {
|
||||
fetchSpy.mockRejectedValue(new Error('Network unreachable'));
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frame: MemoryFrame = {
|
||||
id: 1, frame_type: 'I', gop_id: 'test', t: 0, base_frame_id: null,
|
||||
content: 'x', importance: 'normal', access_count: 0,
|
||||
created_at: '2026-03-12T10:00:00.000Z', last_accessed: '2026-03-12T10:00:00.000Z',
|
||||
};
|
||||
|
||||
const result = await sync.pushFrame(frame);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('pullFrames', () => {
|
||||
it('fetches frames from team server', async () => {
|
||||
fetchSpy.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ([
|
||||
{
|
||||
id: 'uuid-1',
|
||||
name: 'gop-a',
|
||||
properties: { frameType: 'I', t: 0, content: 'First', importance: 'important', authorId: 'u1', authorName: 'Marko' },
|
||||
createdAt: '2026-03-12T10:00:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 'uuid-2',
|
||||
name: 'gop-b',
|
||||
properties: { frameType: 'P', t: 1, content: 'Second', importance: 'normal', authorId: 'u2', authorName: 'Ana' },
|
||||
createdAt: '2026-03-12T11:00:00.000Z',
|
||||
},
|
||||
]),
|
||||
});
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frames = await sync.pullFrames();
|
||||
|
||||
expect(frames).toHaveLength(2);
|
||||
expect(frames[0].gopId).toBe('gop-a');
|
||||
expect(frames[0].authorName).toBe('Marko');
|
||||
expect(frames[1].gopId).toBe('gop-b');
|
||||
expect(frames[1].authorName).toBe('Ana');
|
||||
expect(globalFetchSpy).not.toHaveBeenCalled();
|
||||
|
||||
const [url, opts] = fetchSpy.mock.calls[0];
|
||||
expect(url).toContain('/api/teams/test-team/entities?type=memory_frame');
|
||||
expect(opts.headers['Authorization']).toBe('Bearer test-jwt-token');
|
||||
});
|
||||
|
||||
it('filters by since timestamp when provided', async () => {
|
||||
fetchSpy.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ([
|
||||
{
|
||||
id: 'uuid-1', name: 'gop-a',
|
||||
properties: { frameType: 'I', t: 0, content: 'Old', authorId: 'u1', authorName: 'M' },
|
||||
createdAt: '2026-03-11T10:00:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 'uuid-2', name: 'gop-b',
|
||||
properties: { frameType: 'I', t: 0, content: 'New', authorId: 'u2', authorName: 'A' },
|
||||
createdAt: '2026-03-12T15:00:00.000Z',
|
||||
},
|
||||
]),
|
||||
});
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frames = await sync.pullFrames('2026-03-12T00:00:00.000Z');
|
||||
|
||||
// Only the frame after the since timestamp
|
||||
expect(frames).toHaveLength(1);
|
||||
expect(frames[0].content).toBe('New');
|
||||
});
|
||||
|
||||
it('returns empty array on server error', async () => {
|
||||
fetchSpy.mockResolvedValue({ ok: false, status: 500, statusText: 'Error' });
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frames = await sync.pullFrames();
|
||||
expect(frames).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns empty array on network error', async () => {
|
||||
fetchSpy.mockRejectedValue(new Error('Offline'));
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
const frames = await sync.pullFrames();
|
||||
expect(frames).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sync timestamp tracking', () => {
|
||||
it('starts with null timestamp', () => {
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
expect(sync.getLastSyncTimestamp()).toBeNull();
|
||||
});
|
||||
|
||||
it('updates timestamp after successful pull', async () => {
|
||||
fetchSpy.mockResolvedValue({ ok: true, json: async () => ([]) });
|
||||
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
await sync.pullFrames();
|
||||
|
||||
expect(sync.getLastSyncTimestamp()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('allows manual timestamp setting', () => {
|
||||
const sync = new TeamSync(mockConfig, fetchSpy);
|
||||
sync.setLastSyncTimestamp('2026-03-12T10:00:00.000Z');
|
||||
expect(sync.getLastSyncTimestamp()).toBe('2026-03-12T10:00:00.000Z');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -370,24 +370,18 @@ describe('WorkspaceManager', () => {
|
||||
name: 'Team Project',
|
||||
group: 'Work',
|
||||
teamId: 'team-abc-123',
|
||||
teamServerUrl: 'https://team.waggle.dev',
|
||||
teamRole: 'member',
|
||||
teamUserId: 'user-xyz',
|
||||
});
|
||||
|
||||
expect(ws.teamId).toBe('team-abc-123');
|
||||
expect(ws.teamServerUrl).toBe('https://team.waggle.dev');
|
||||
expect(ws.teamRole).toBe('member');
|
||||
expect(ws.teamUserId).toBe('user-xyz');
|
||||
});
|
||||
|
||||
it('creates solo workspace without team fields', () => {
|
||||
const ws = manager.create({ name: 'Solo', group: 'Personal' });
|
||||
|
||||
expect(ws.teamId).toBeUndefined();
|
||||
expect(ws.teamServerUrl).toBeUndefined();
|
||||
expect(ws.teamRole).toBeUndefined();
|
||||
expect(ws.teamUserId).toBeUndefined();
|
||||
});
|
||||
|
||||
it('isTeamWorkspace returns true for team workspaces', () => {
|
||||
@@ -395,7 +389,6 @@ describe('WorkspaceManager', () => {
|
||||
name: 'Team WS',
|
||||
group: 'Work',
|
||||
teamId: 'team-1',
|
||||
teamServerUrl: 'https://example.com',
|
||||
});
|
||||
expect(manager.isTeamWorkspace('team-ws')).toBe(true);
|
||||
});
|
||||
@@ -411,9 +404,9 @@ describe('WorkspaceManager', () => {
|
||||
|
||||
it('listTeamWorkspaces filters to team-connected only', () => {
|
||||
manager.create({ name: 'Solo A', group: 'Work' });
|
||||
manager.create({ name: 'Team B', group: 'Work', teamId: 'team-1', teamServerUrl: 'https://a.com' });
|
||||
manager.create({ name: 'Team B', group: 'Work', teamId: 'team-1' });
|
||||
manager.create({ name: 'Solo C', group: 'Personal' });
|
||||
manager.create({ name: 'Team D', group: 'Work', teamId: 'team-2', teamServerUrl: 'https://b.com' });
|
||||
manager.create({ name: 'Team D', group: 'Work', teamId: 'team-2' });
|
||||
|
||||
const teamWs = manager.listTeamWorkspaces();
|
||||
expect(teamWs).toHaveLength(2);
|
||||
@@ -425,16 +418,12 @@ describe('WorkspaceManager', () => {
|
||||
name: 'Persist Test',
|
||||
group: 'Work',
|
||||
teamId: 'team-persist',
|
||||
teamServerUrl: 'https://persist.dev',
|
||||
teamRole: 'admin',
|
||||
teamUserId: 'user-persist',
|
||||
});
|
||||
|
||||
const ws = manager.get('persist-test');
|
||||
expect(ws!.teamId).toBe('team-persist');
|
||||
expect(ws!.teamServerUrl).toBe('https://persist.dev');
|
||||
expect(ws!.teamRole).toBe('admin');
|
||||
expect(ws!.teamUserId).toBe('user-persist');
|
||||
});
|
||||
|
||||
it('updates team fields', () => {
|
||||
|
||||
Reference in New Issue
Block a user