refactor(cli): run local mode only (P1.1)
Team mode is not part of the community edition (ADR-0003), so the CLI no longer detects or switches to it. - Remove the mode detector, the --local and --team flags, the Clerk browser login (/login, /logout, /whoami) and /mode. - Remove the /admin command and its team-server REST client. - The welcome banner drops the Mode line. - The installed-REPL test starts plain `waggle` and checks that the team commands are gone.
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { AdminClient, formatTable } from '../src/commands/admin.js';
|
||||
|
||||
describe('AdminClient', () => {
|
||||
it('constructs with defaults', () => {
|
||||
const client = new AdminClient();
|
||||
expect(client).toBeInstanceOf(AdminClient);
|
||||
});
|
||||
|
||||
it('constructs with custom base URL and token', () => {
|
||||
const client = new AdminClient('http://localhost:9999', 'my-token');
|
||||
expect(client).toBeInstanceOf(AdminClient);
|
||||
});
|
||||
|
||||
it('has all admin methods', () => {
|
||||
const client = new AdminClient('http://localhost:3100', 'test-token');
|
||||
expect(typeof client.listTeams).toBe('function');
|
||||
expect(typeof client.listJobs).toBe('function');
|
||||
expect(typeof client.listCron).toBe('function');
|
||||
expect(typeof client.listAudit).toBe('function');
|
||||
expect(typeof client.getStats).toBe('function');
|
||||
});
|
||||
|
||||
it('methods return promises', () => {
|
||||
const client = new AdminClient('http://localhost:3100', 'test-token');
|
||||
// These will fail to connect, but they should return promises
|
||||
const p = client.listTeams();
|
||||
expect(p).toBeInstanceOf(Promise);
|
||||
// Suppress unhandled rejection
|
||||
p.catch(() => {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatTable', () => {
|
||||
it('returns "(no data)" for empty array', () => {
|
||||
expect(formatTable([])).toBe(' (no data)');
|
||||
});
|
||||
|
||||
it('formats rows into aligned columns', () => {
|
||||
const rows = [
|
||||
{ id: '1', name: 'Alice', role: 'admin' },
|
||||
{ id: '2', name: 'Bob', role: 'member' },
|
||||
];
|
||||
const result = formatTable(rows);
|
||||
expect(result).toContain('id');
|
||||
expect(result).toContain('name');
|
||||
expect(result).toContain('role');
|
||||
expect(result).toContain('Alice');
|
||||
expect(result).toContain('Bob');
|
||||
expect(result).toContain('admin');
|
||||
expect(result).toContain('member');
|
||||
});
|
||||
|
||||
it('respects explicit column selection', () => {
|
||||
const rows = [
|
||||
{ id: '1', name: 'Alice', secret: 'hidden' },
|
||||
];
|
||||
const result = formatTable(rows, ['id', 'name']);
|
||||
expect(result).toContain('id');
|
||||
expect(result).toContain('name');
|
||||
expect(result).not.toContain('secret');
|
||||
expect(result).not.toContain('hidden');
|
||||
});
|
||||
|
||||
it('handles missing values gracefully', () => {
|
||||
const rows = [
|
||||
{ id: '1', name: 'Alice' },
|
||||
{ id: '2' },
|
||||
];
|
||||
const result = formatTable(rows);
|
||||
expect(result).toContain('Alice');
|
||||
// Second row should have empty name
|
||||
expect(result).toContain('2');
|
||||
});
|
||||
});
|
||||
@@ -1,90 +0,0 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { AuthManager } from '../src/auth.js';
|
||||
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
describe('AuthManager', () => {
|
||||
let tempDir: string;
|
||||
let auth: AuthManager;
|
||||
|
||||
function setup() {
|
||||
tempDir = mkdtempSync(join(tmpdir(), 'waggle-auth-test-'));
|
||||
auth = new AuthManager(tempDir);
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (tempDir) {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('returns null when no token stored', () => {
|
||||
setup();
|
||||
expect(auth.getToken()).toBeNull();
|
||||
expect(auth.getEmail()).toBeNull();
|
||||
});
|
||||
|
||||
it('saves and retrieves token', () => {
|
||||
setup();
|
||||
auth.saveToken('test-jwt-token', 'user@example.com');
|
||||
expect(auth.getToken()).toBe('test-jwt-token');
|
||||
expect(auth.getEmail()).toBe('user@example.com');
|
||||
});
|
||||
|
||||
it('clears token on logout', () => {
|
||||
setup();
|
||||
auth.saveToken('test-jwt-token', 'user@example.com');
|
||||
expect(auth.getToken()).toBe('test-jwt-token');
|
||||
auth.logout();
|
||||
expect(auth.getToken()).toBeNull();
|
||||
expect(auth.getEmail()).toBeNull();
|
||||
});
|
||||
|
||||
it('isLoggedIn returns true/false correctly', () => {
|
||||
setup();
|
||||
expect(auth.isLoggedIn()).toBe(false);
|
||||
auth.saveToken('test-jwt-token', 'user@example.com');
|
||||
expect(auth.isLoggedIn()).toBe(true);
|
||||
auth.logout();
|
||||
expect(auth.isLoggedIn()).toBe(false);
|
||||
});
|
||||
|
||||
it('stores token in config.json file', () => {
|
||||
setup();
|
||||
auth.saveToken('file-check-token', 'file@example.com');
|
||||
const configPath = join(tempDir, 'config.json');
|
||||
const raw = readFileSync(configPath, 'utf-8');
|
||||
const config = JSON.parse(raw);
|
||||
expect(config.auth).toEqual({
|
||||
token: 'file-check-token',
|
||||
email: 'file@example.com',
|
||||
serverUrl: 'http://localhost:3000',
|
||||
});
|
||||
});
|
||||
|
||||
it('getServerUrl returns default', () => {
|
||||
setup();
|
||||
expect(auth.getServerUrl()).toBe('http://localhost:3000');
|
||||
});
|
||||
|
||||
it('preserves existing config keys when saving auth', () => {
|
||||
setup();
|
||||
// Write some pre-existing config
|
||||
const configPath = join(tempDir, 'config.json');
|
||||
try {
|
||||
mkdirSync(tempDir, { recursive: true });
|
||||
} catch {
|
||||
// tempDir already exists from setup(); recursive mkdir is idempotent.
|
||||
}
|
||||
writeFileSync(configPath, JSON.stringify({ apiKey: 'sk-existing', model: 'claude' }));
|
||||
|
||||
auth.saveToken('my-token', 'me@test.com');
|
||||
|
||||
const raw = readFileSync(configPath, 'utf-8');
|
||||
const config = JSON.parse(raw);
|
||||
expect(config.apiKey).toBe('sk-existing');
|
||||
expect(config.model).toBe('claude');
|
||||
expect(config.auth.token).toBe('my-token');
|
||||
});
|
||||
});
|
||||
@@ -458,7 +458,7 @@ describe('@waggle/cli runtime UX', () => {
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
child = spawnInCwd(bin('npx'), ['waggle', '--local'], projectDir, home);
|
||||
child = spawnInCwd(bin('npx'), ['waggle'], projectDir, home);
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
||||
@@ -484,9 +484,12 @@ describe('@waggle/cli runtime UX', () => {
|
||||
await waitFor(() => expectedText.every((text) => stdout.includes(text)), 10_000);
|
||||
};
|
||||
|
||||
await writeCommand('/help', ['Available commands:', '/models', '/whoami']);
|
||||
await writeCommand('/mode', 'Current mode: local');
|
||||
await writeCommand('/whoami', ['User:', 'not logged in', 'Server:']);
|
||||
await writeCommand('/help', ['Available commands:', '/models', '/cost']);
|
||||
// The CLI runs local mode only: team login and admin commands are gone (ADR-0003).
|
||||
for (const teamCommand of ['login', 'logout', 'whoami', 'mode', 'admin']) {
|
||||
expect(stdout).not.toMatch(new RegExp(`/${teamCommand}\\b`));
|
||||
}
|
||||
await writeCommand('/admin', 'Unknown command: /admin');
|
||||
await writeCommand('/models', ['Available models:', 'No models configured']);
|
||||
await writeCommand('/cost', ['Tokens: 0 in / 0 out', 'Est. cost: $0.0000']);
|
||||
await writeCommand('/clear', 'Conversation cleared.');
|
||||
@@ -496,10 +499,8 @@ describe('@waggle/cli runtime UX', () => {
|
||||
|
||||
expect(child.exitCode).toBe(0);
|
||||
expect(stdout).toContain('Waggle');
|
||||
expect(stdout).toContain('Mode:');
|
||||
expect(stdout).toContain('local');
|
||||
expect(stdout).not.toContain('Mode:');
|
||||
expect(stdout).toContain('Available commands:');
|
||||
expect(stdout).toContain('Current mode: local');
|
||||
expect(stdout).toContain('No models configured');
|
||||
expect(stdout).toContain('Conversation cleared.');
|
||||
expect(stdout).toContain('Goodbye!');
|
||||
@@ -592,7 +593,7 @@ describe('@waggle/cli runtime UX', () => {
|
||||
let stderr = '';
|
||||
child = spawnInCwd(
|
||||
bin('npx'),
|
||||
['waggle', '--local'],
|
||||
['waggle'],
|
||||
projectDir,
|
||||
home,
|
||||
{
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { detectMode, type ModeDetectorDeps } from '../src/mode-detector.js';
|
||||
|
||||
function makeDeps(overrides: Partial<ModeDetectorDeps> = {}): ModeDetectorDeps {
|
||||
return {
|
||||
hasToken: false,
|
||||
serverUrl: 'http://localhost:3000',
|
||||
forceLocal: false,
|
||||
forceTeam: false,
|
||||
healthCheck: vi.fn().mockResolvedValue(true),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('detectMode', () => {
|
||||
it('returns local when no token', async () => {
|
||||
const result = await detectMode(makeDeps({ hasToken: false }));
|
||||
expect(result).toEqual({ type: 'local' });
|
||||
});
|
||||
|
||||
it('returns team when token + server reachable', async () => {
|
||||
const result = await detectMode(makeDeps({
|
||||
hasToken: true,
|
||||
healthCheck: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
expect(result).toEqual({ type: 'team' });
|
||||
});
|
||||
|
||||
it('returns local with warning when token + server unreachable', async () => {
|
||||
const result = await detectMode(makeDeps({
|
||||
hasToken: true,
|
||||
healthCheck: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
expect(result).toEqual({
|
||||
type: 'local',
|
||||
warning: 'Server unreachable — running in local mode.',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns local when --local forced', async () => {
|
||||
const result = await detectMode(makeDeps({
|
||||
hasToken: true,
|
||||
forceLocal: true,
|
||||
healthCheck: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
expect(result).toEqual({ type: 'local' });
|
||||
});
|
||||
|
||||
it('returns team when --team forced + token', async () => {
|
||||
const healthCheck = vi.fn().mockResolvedValue(false);
|
||||
const result = await detectMode(makeDeps({
|
||||
hasToken: true,
|
||||
forceTeam: true,
|
||||
healthCheck,
|
||||
}));
|
||||
expect(result).toEqual({ type: 'team' });
|
||||
// Should not even check health when forced
|
||||
expect(healthCheck).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns error when --team forced + no token', async () => {
|
||||
const result = await detectMode(makeDeps({
|
||||
hasToken: false,
|
||||
forceTeam: true,
|
||||
}));
|
||||
expect(result).toEqual({
|
||||
type: 'error',
|
||||
error: 'Team mode requires login. Run: waggle login',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user