Files
waggle-os/packages/server/tests/unit/command-interpret.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

108 lines
4.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { interpretCommand, type InterpretDeps } from '../../src/local/command-interpret.js';
function deps(over: Partial<InterpretDeps> & { llm: InterpretDeps['llm'] }): InterpretDeps {
return {
text: 'do the thing',
workspaceId: 'w1',
workspaces: [
{ id: 'w1', name: 'Acme Redesign' },
{ id: 'w2', name: 'Personal Notes' },
],
memoryContext: 'Active: redesigning the Acme landing page.',
...over,
};
}
const llmReturning = (s: string) => async () => s;
describe('interpretCommand — Tier 1 resolver', () => {
it('resolves a create-workspace intent to a single action with the name filled', async () => {
const res = await interpretCommand(deps({
text: 'make a new workspace for the Phoenix project',
llm: llmReturning('{"kind":"action","actionId":"create_workspace","params":{"name":"Phoenix"}}'),
}));
expect(res.kind).toBe('action');
expect(res.action?.id).toBe('create_workspace');
expect(res.action?.sideEffect).toBe(true);
expect(res.action?.endpoint).toEqual({ method: 'POST', path: '/api/workspaces', body: { name: 'Phoenix', group: 'Personal' } });
});
it('resolves a memory-dependent "continue" intent against the recent workspaces', async () => {
const res = await interpretCommand(deps({
text: 'continue what I was working on',
llm: llmReturning('{"kind":"action","actionId":"open_workspace","params":{"workspaceId":"w1"}}'),
}));
expect(res.kind).toBe('action');
expect(res.action?.navigate).toEqual({ type: 'workspace', id: 'workspace:w1' });
});
it('resolves install_mcp to an action', async () => {
const res = await interpretCommand(deps({
text: 'install the postgres mcp server',
llm: llmReturning('{"kind":"action","actionId":"install_mcp","params":{"mcpId":"postgres"}}'),
}));
expect(res.kind).toBe('action');
expect(res.action?.id).toBe('install_mcp');
});
it('returns none (never an invented action) for an out-of-registry id', async () => {
const res = await interpretCommand(deps({
llm: llmReturning('{"kind":"action","actionId":"delete_production_db","params":{}}'),
}));
expect(res.kind).toBe('none');
expect(res.fallback).toBe(true);
});
it('passes clarify through', async () => {
const res = await interpretCommand(deps({
llm: llmReturning('{"kind":"clarify","question":"Which workspace?","options":["Acme","Personal"]}'),
}));
expect(res.kind).toBe('clarify');
expect(res.question).toBe('Which workspace?');
expect(res.options).toEqual(['Acme', 'Personal']);
});
it('collapses a single-step plan to one action', async () => {
const res = await interpretCommand(deps({
llm: llmReturning('{"kind":"plan","steps":[{"actionId":"open_app","params":{"app":"memory"}}]}'),
}));
expect(res.kind).toBe('action');
expect(res.action?.navigate).toEqual({ type: 'command', id: 'command:memory' });
});
it('downgrades a multi-step plan to clarify (v1 does not execute plans)', async () => {
const res = await interpretCommand(deps({
llm: llmReturning('{"kind":"plan","steps":[{"actionId":"create_workspace","params":{"name":"A"}},{"actionId":"open_app","params":{"app":"memory"}}]}'),
}));
expect(res.kind).toBe('clarify');
expect(res.steps?.length).toBe(2);
});
it('strips code fences before parsing', async () => {
const res = await interpretCommand(deps({
llm: llmReturning('```json\n{"kind":"action","actionId":"open_app","params":{"app":"settings"}}\n```'),
}));
expect(res.kind).toBe('action');
expect(res.action?.navigate?.id).toBe('command:settings');
});
it('degrades to a Tier-0 fallback on unparseable model output', async () => {
const res = await interpretCommand(deps({ llm: llmReturning('I think you want to open memory!') }));
expect(res.kind).toBe('none');
expect(res.fallback).toBe(true);
});
it('degrades to a Tier-0 fallback when the model is unavailable (no key → null)', async () => {
const res = await interpretCommand(deps({ llm: async () => null }));
expect(res.kind).toBe('none');
expect(res.fallback).toBe(true);
});
it('degrades to a Tier-0 fallback when the llm throws', async () => {
const res = await interpretCommand(deps({ llm: async () => { throw new Error('proxy down'); } }));
expect(res.kind).toBe('none');
expect(res.fallback).toBe(true);
});
});