Files
waggle-os/packages/server/tests/unit/command-registry.test.ts
shumeiko.it fe2eb0f648 refactor: remove the billing tier model (P0.1)
The community edition has no monetization (ADR-0001). Remove the tier
model (packages/shared/src/tiers.ts), the requireTier middleware and every
tier gate, GET/PATCH /api/tier and the trial start, and the Stripe
integration, which depends on the tier model.

Personal features a tier used to limit are open to everyone: unlimited
workspaces and connectors, every embedding provider including LiteLLM,
per-workspace costs, Approvals. The workspace session cap is one constant
(100). Team and enterprise surfaces are hidden instead of unlocked (team
dock zone, Settings Team/Enterprise/Plan tabs, workspace Team tab);
cloud sync reports unavailable, as it did for free users.

The sidecar ignores the tier keys in config.json but does not delete them:
both editions may still share ~/.waggle.

Web billing UI is deleted: plan cards, upgrade and trial modals, payment
success route, the KVARK sales block, tier 403 handling.
2026-10-15 19:31:50 +02:00

101 lines
3.6 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
ACTION_IDS,
validateAndBuildAction,
buildActionCatalog,
type RegistryContext,
} from '../../src/local/command-registry.js';
const ctx: RegistryContext = {
workspaceId: 'w1',
workspaces: [
{ id: 'w1', name: 'Acme Redesign' },
{ id: 'w2', name: 'Personal Notes' },
],
};
describe('command-registry — closed action registry', () => {
it('exposes only the v1 action ids', () => {
expect(ACTION_IDS).toEqual(['open_app', 'open_workspace', 'create_workspace', 'install_mcp']);
});
it('rejects an unknown action id (closed registry)', () => {
expect(validateAndBuildAction('rm_rf_slash', {}, ctx)).toBeNull();
expect(validateAndBuildAction('exec_shell', { cmd: 'whoami' }, ctx)).toBeNull();
});
describe('open_app (nav, read)', () => {
it('builds a navigate target for a valid app id', () => {
const a = validateAndBuildAction('open_app', { app: 'memory' }, ctx);
expect(a).toMatchObject({
id: 'open_app',
sideEffect: false,
riskLevel: 'low',
navigate: { type: 'command', id: 'command:memory' },
});
expect(a?.endpoint).toBeUndefined();
});
it('rejects an app id outside NAV_TARGETS (enum guard)', () => {
expect(validateAndBuildAction('open_app', { app: 'admin-secrets' }, ctx)).toBeNull();
});
});
describe('open_workspace (nav, read)', () => {
it('resolves by id', () => {
const a = validateAndBuildAction('open_workspace', { workspaceId: 'w2' }, ctx);
expect(a?.navigate).toEqual({ type: 'workspace', id: 'workspace:w2' });
});
it('resolves by fuzzy name when id is unknown', () => {
const a = validateAndBuildAction('open_workspace', { name: 'acme' }, ctx);
expect(a?.navigate).toEqual({ type: 'workspace', id: 'workspace:w1' });
});
it('returns null when the workspace cannot be resolved', () => {
expect(validateAndBuildAction('open_workspace', { name: 'Nonexistent' }, ctx)).toBeNull();
});
});
describe('create_workspace (side-effect, low)', () => {
it('builds a POST /api/workspaces endpoint with the name filled', () => {
const a = validateAndBuildAction('create_workspace', { name: 'X Project' }, ctx);
expect(a).toMatchObject({
id: 'create_workspace',
sideEffect: true,
riskLevel: 'low',
endpoint: { method: 'POST', path: '/api/workspaces', body: { name: 'X Project', group: 'Personal' } },
});
});
it('returns null without a name', () => {
expect(validateAndBuildAction('create_workspace', {}, ctx)).toBeNull();
});
});
describe('install_mcp (side-effect, medium — free/Solo)', () => {
it('builds a POST /api/mcps/install endpoint for a catalog id', () => {
const a = validateAndBuildAction('install_mcp', { mcpId: 'postgres' }, ctx);
expect(a).toMatchObject({
id: 'install_mcp',
sideEffect: true,
riskLevel: 'medium',
endpoint: { method: 'POST', path: '/api/mcps/install', body: { mcpId: 'postgres' } },
});
});
it('rejects an mcp id outside the surfaced popular set (enum guard)', () => {
expect(validateAndBuildAction('install_mcp', { mcpId: 'totally-made-up' }, ctx)).toBeNull();
});
});
it('renders a prompt catalog naming every action + nav/mcp targets', () => {
const catalog = buildActionCatalog();
for (const id of ACTION_IDS) expect(catalog).toContain(id);
expect(catalog).toContain('NAV TARGETS');
expect(catalog).toContain('memory');
expect(catalog).toContain('POPULAR MCP SERVERS');
expect(catalog).toContain('postgres');
});
});