Files
dashcaddy/dashcaddy-api/__tests__/routes/ai-intent.test.js
T
Hermes 87dd2712a0
CI / Test & Lint (push) Canceled after 0s
CI / Security audit (push) Canceled after 0s
[grade=A] AI Intent Router — natural language → structured actions
POST /api/v1/ai/intent takes natural language and returns structured intent:
- 'Deploy Plex' → { intent: deploy, appId: plex, deployPlan }
- 'I want to stream movies' → { intent: recommend, categories: [media-streaming] }
- 'Why is Plex down?' → { intent: diagnose, serviceId: plex }
- 'Back up everything' → { intent: backup }
- 'Is everything OK?' → { intent: health }

GET /api/v1/ai/capabilities returns self-describing capabilities for agent discovery.

Pattern-based matching works offline (no LLM call needed). LLM_PROXY_URL env
var can be set for complex query delegation.

18 intent tests covering deploy, recommend, diagnose, backup, health, list,
and unknown intents. 1770 total tests pass.
2026-08-12 16:32:44 -07:00

122 lines
4.0 KiB
JavaScript

/**
* Tests for the AI Intent Router
*/
const { routeIntent } = require('../../routes/ai-intent');
describe('AI Intent Router', () => {
describe('deploy intents', () => {
test('detects "deploy plex"', () => {
const result = routeIntent('Deploy Plex');
expect(result.intent).toBe('deploy');
expect(result.appId).toBe('plex');
});
test('detects "set up nextcloud"', () => {
const result = routeIntent('Set up Nextcloud');
expect(result.intent).toBe('deploy');
expect(result.appId).toBe('nextcloud');
});
test('detects "install gitea"', () => {
const result = routeIntent('Can you install Gitea for me?');
expect(result.intent).toBe('deploy');
expect(result.appId).toBe('gitea');
});
test('includes deploy info', () => {
const result = routeIntent('Deploy Plex');
expect(result.appId).toBe('plex');
expect(result.action).toBe('dashcaddy_deploy_app');
});
});
describe('recommend intents', () => {
test('media streaming → recommends Plex', () => {
const result = routeIntent('I want to stream movies');
expect(result.intent).toBe('recommend');
expect(result.categories).toContain('media-streaming');
});
test('password manager → recommends Vaultwarden', () => {
const result = routeIntent('I need a password manager');
expect(result.intent).toBe('recommend');
expect(result.response.recommendations[0].app).toBe('vaultwarden');
});
test('ad blocking → recommends AdGuard', () => {
const result = routeIntent('Block ads on my network');
expect(result.intent).toBe('recommend');
expect(result.response.recommendations[0].app).toBe('adguard');
});
test('includes categories for wizard', () => {
const result = routeIntent('I want to stream movies');
expect(result.categories).toContain('media-streaming');
expect(result.action).toBe('dashcaddy_wizard_recommend');
});
});
describe('diagnose intents', () => {
test('detects "why is plex down"', () => {
const result = routeIntent('Why is Plex down?');
expect(result.intent).toBe('diagnose');
expect(result.serviceId).toBe('plex');
});
test('detects "something is broken"', () => {
const result = routeIntent('Something is broken with my services');
expect(result.intent).toBe('diagnose');
});
});
describe('backup intents', () => {
test('detects "back up everything"', () => {
const result = routeIntent('Back up everything');
expect(result.intent).toBe('backup');
});
test('detects "create a snapshot"', () => {
const result = routeIntent('Create a snapshot');
expect(result.intent).toBe('backup');
});
});
describe('health intents', () => {
test('detects "is everything ok?"', () => {
const result = routeIntent('Is everything OK?');
expect(result.intent).toBe('health');
});
test('detects "system check"', () => {
const result = routeIntent('Run a system check');
expect(result.intent).toBe('health');
});
});
describe('list intents', () => {
test('detects "what services am I running?"', () => {
const result = routeIntent('What services am I running?');
expect(result.intent).toBe('list');
});
test('detects "show me everything"', () => {
const result = routeIntent('Show me everything that\'s deployed');
expect(result.intent).toBe('list');
});
});
describe('unknown intents', () => {
test('returns fallback for unrecognized input', () => {
const result = routeIntent('xyz random gibberish 123');
expect(result.intent).toBe('unknown');
expect(result.response.suggestions).toBeTruthy();
expect(result.response.suggestions.length).toBeGreaterThan(0);
});
test('fallback includes example queries', () => {
const result = routeIntent('hello world');
expect(result.response.suggestions.some(s => s.includes('Deploy'))).toBe(true);
});
});
});