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).
280 lines
8.8 KiB
TypeScript
280 lines
8.8 KiB
TypeScript
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 } from '../src/config.js';
|
|
|
|
describe('WaggleConfig', () => {
|
|
const tempDirs: string[] = [];
|
|
|
|
function makeTempDir(): string {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-config-test-'));
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs) {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
tempDirs.length = 0;
|
|
});
|
|
|
|
it('creates config directory if missing', () => {
|
|
const base = makeTempDir();
|
|
const configDir = path.join(base, 'nested', '.waggle');
|
|
|
|
new WaggleConfig(configDir);
|
|
|
|
expect(fs.existsSync(configDir)).toBe(true);
|
|
});
|
|
|
|
it('returns default config when no file exists', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
expect(config.getDefaultModel()).toBe('claude-sonnet-4-6');
|
|
expect(config.getProviders()).toEqual({});
|
|
expect(config.getMindPath()).toBe(path.join(configDir, 'default.mind'));
|
|
});
|
|
|
|
it('saves and loads provider config', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
const provider: ProviderEntry = {
|
|
apiKey: 'sk-test-key',
|
|
models: ['claude-sonnet-4-6', 'claude-haiku-3'],
|
|
baseUrl: 'https://api.anthropic.com',
|
|
};
|
|
|
|
config.setProvider('anthropic', provider);
|
|
config.save();
|
|
|
|
// Load fresh instance from same directory
|
|
const config2 = new WaggleConfig(configDir);
|
|
const providers = config2.getProviders();
|
|
|
|
expect(providers['anthropic']).toEqual(provider);
|
|
expect(providers['anthropic'].apiKey).toBe('sk-test-key');
|
|
expect(providers['anthropic'].models).toHaveLength(2);
|
|
});
|
|
|
|
it('sets and gets default model', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
config.setDefaultModel('gpt-4o');
|
|
config.save();
|
|
|
|
const config2 = new WaggleConfig(configDir);
|
|
expect(config2.getDefaultModel()).toBe('gpt-4o');
|
|
});
|
|
|
|
it('returns mind file path', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
expect(config.getMindPath()).toBe(path.join(configDir, 'default.mind'));
|
|
});
|
|
|
|
it('removes a provider', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
config.setProvider('anthropic', { apiKey: 'key1', models: ['m1'] });
|
|
config.setProvider('openai', { apiKey: 'key2', models: ['m2'] });
|
|
config.removeProvider('anthropic');
|
|
config.save();
|
|
|
|
const config2 = new WaggleConfig(configDir);
|
|
const providers = config2.getProviders();
|
|
expect(providers['anthropic']).toBeUndefined();
|
|
expect(providers['openai']).toBeDefined();
|
|
});
|
|
|
|
it('returns config directory path', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
expect(config.getConfigDir()).toBe(configDir);
|
|
});
|
|
|
|
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('getTeamServer' in config).toBe(false);
|
|
config.setDefaultModel('gpt-4o');
|
|
config.save();
|
|
|
|
const raw = JSON.parse(fs.readFileSync(path.join(configDir, 'config.json'), 'utf-8'));
|
|
expect(raw.defaultModel).toBe('gpt-4o');
|
|
expect(raw.teamServer).toEqual(teamServer);
|
|
});
|
|
});
|
|
|
|
describe('governed CLI config', () => {
|
|
it('normalizes, deduplicates, and persists the CLI allowlist', () => {
|
|
const configDir = makeTempDir();
|
|
const config = new WaggleConfig(configDir);
|
|
|
|
config.setCliAllowlist([' node ', 'NODE', '', 'git']);
|
|
expect(config.getCliAllowlist()).toEqual(['node', 'git']);
|
|
config.save();
|
|
|
|
const config2 = new WaggleConfig(configDir);
|
|
expect(config2.getCliAllowlist()).toEqual(['node', 'git']);
|
|
});
|
|
});
|
|
|
|
describe('embedding config', () => {
|
|
const envNames = [
|
|
'EMBEDDING_PROVIDER',
|
|
'EMBEDDING_MODEL',
|
|
'OLLAMA_HOST',
|
|
'OLLAMA_EMBED_MODEL',
|
|
] as const;
|
|
const originalEnv = new Map<string, string | undefined>();
|
|
|
|
beforeEach(() => {
|
|
originalEnv.clear();
|
|
for (const name of envNames) {
|
|
originalEnv.set(name, process.env[name]);
|
|
delete process.env[name];
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
for (const name of envNames) {
|
|
const value = originalEnv.get(name);
|
|
if (value === undefined) delete process.env[name];
|
|
else process.env[name] = value;
|
|
}
|
|
});
|
|
|
|
it.each(['', ' '])('treats blank provider override %j as unset', override => {
|
|
process.env.EMBEDDING_PROVIDER = override;
|
|
const config = new WaggleConfig(makeTempDir());
|
|
|
|
expect(config.getEmbeddingConfig().provider).toBe('auto');
|
|
|
|
config.setEmbeddingProvider('inprocess');
|
|
expect(config.getEmbeddingConfig().provider).toBe('inprocess');
|
|
});
|
|
|
|
it('trims a valid provider override and keeps it authoritative', () => {
|
|
process.env.EMBEDDING_PROVIDER = ' inprocess ';
|
|
const config = new WaggleConfig(makeTempDir());
|
|
config.setEmbeddingProvider('ollama');
|
|
|
|
expect(config.getEmbeddingConfig().provider).toBe('inprocess');
|
|
});
|
|
|
|
it('treats blank embedding model and Ollama overrides as unset', () => {
|
|
const configDir = makeTempDir();
|
|
fs.writeFileSync(path.join(configDir, 'config.json'), JSON.stringify({
|
|
defaultModel: 'claude-sonnet-4-6',
|
|
providers: {},
|
|
embedding: {
|
|
provider: 'auto',
|
|
inprocessModel: 'persisted-inprocess-model',
|
|
ollamaUrl: 'http://127.0.0.1:11434',
|
|
ollamaModel: 'persisted-ollama-model',
|
|
},
|
|
}));
|
|
process.env.EMBEDDING_MODEL = ' ';
|
|
process.env.OLLAMA_HOST = '';
|
|
process.env.OLLAMA_EMBED_MODEL = ' ';
|
|
|
|
expect(new WaggleConfig(configDir).getEmbeddingConfig()).toMatchObject({
|
|
inprocess: { model: 'persisted-inprocess-model' },
|
|
ollama: {
|
|
baseUrl: 'http://127.0.0.1:11434',
|
|
model: 'persisted-ollama-model',
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Model Pilot config fields', () => {
|
|
let tmpDir: string;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-config-pilot-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('returns null for fallbackModel when not set', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
expect(config.getFallbackModel()).toBeNull();
|
|
});
|
|
|
|
it('persists fallbackModel', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
config.setFallbackModel('qwen/qwen3.6-plus:free');
|
|
config.save();
|
|
const config2 = new WaggleConfig(tmpDir);
|
|
expect(config2.getFallbackModel()).toBe('qwen/qwen3.6-plus:free');
|
|
});
|
|
|
|
it('returns null for budgetModel when not set', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
expect(config.getBudgetModel()).toBeNull();
|
|
});
|
|
|
|
it('persists budgetModel', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
config.setBudgetModel('deepseek/deepseek-chat-v3-0324:free');
|
|
config.save();
|
|
const config2 = new WaggleConfig(tmpDir);
|
|
expect(config2.getBudgetModel()).toBe('deepseek/deepseek-chat-v3-0324:free');
|
|
});
|
|
|
|
it('returns 0.8 as default budgetThreshold', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
expect(config.getBudgetThreshold()).toBe(0.8);
|
|
});
|
|
|
|
it('persists budgetThreshold', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
config.setBudgetThreshold(0.6);
|
|
config.save();
|
|
const config2 = new WaggleConfig(tmpDir);
|
|
expect(config2.getBudgetThreshold()).toBe(0.6);
|
|
});
|
|
|
|
it('clearFallbackModel removes the field', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
config.setFallbackModel('test-model');
|
|
config.save();
|
|
config.clearFallbackModel();
|
|
config.save();
|
|
const config2 = new WaggleConfig(tmpDir);
|
|
expect(config2.getFallbackModel()).toBeNull();
|
|
});
|
|
|
|
it('returns 90 as default maxIterations', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
expect(config.getMaxIterations()).toBe(90);
|
|
});
|
|
|
|
it('persists maxIterations', () => {
|
|
const config = new WaggleConfig(tmpDir);
|
|
config.setMaxIterations(50);
|
|
config.save();
|
|
const config2 = new WaggleConfig(tmpDir);
|
|
expect(config2.getMaxIterations()).toBe(50);
|
|
});
|
|
});
|
|
});
|