feat(littleblue): agent seed + persona + chat route
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
38
tests/api/littleblue.test.js
Normal file
38
tests/api/littleblue.test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import { fileURLToPath } from 'url';
|
||||
import request from 'supertest';
|
||||
import { pool } from '../../lib/db/pool.js';
|
||||
import { createApp } from '../../server.js';
|
||||
import { resetDb } from '../helpers/db.js';
|
||||
import { migrateUp } from '../../lib/db/migrate.js';
|
||||
|
||||
const FAKE = fileURLToPath(new URL('../fixtures/fake-claude-blue.js', import.meta.url));
|
||||
let app;
|
||||
beforeAll(async () => {
|
||||
await resetDb(); await migrateUp();
|
||||
process.env.OWNER_TOKEN = 'test-token';
|
||||
app = createApp();
|
||||
app.locals.claudeExe = FAKE;
|
||||
});
|
||||
const auth = (r) => r.set('Authorization', 'Bearer test-token');
|
||||
|
||||
describe('Little Blue API', () => {
|
||||
it('GET creates the global conversation and returns Little Blue + empty history', async () => {
|
||||
const res = await auth(request(app).get('/api/little-blue'));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.agent.slug).toBe('little-blue');
|
||||
expect(res.body.conversation_id).toBeTruthy();
|
||||
expect(res.body.messages).toEqual([]);
|
||||
});
|
||||
it('POST /turn streams SSE and persists user+assistant', async () => {
|
||||
const res = await auth(request(app).post('/api/little-blue/turn')).send({ text: 'caddy is down, fix it' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers['content-type']).toMatch(/text\/event-stream/);
|
||||
expect(res.text).toMatch(/event: delta/);
|
||||
expect(res.text).toMatch(/event: tool/);
|
||||
expect(res.text).toMatch(/event: done/);
|
||||
const { rows: msgs } = await pool.query(`SELECT role, body FROM messages ORDER BY created_at`);
|
||||
expect(msgs.map(m => m.role)).toEqual(['user', 'assistant']);
|
||||
expect(msgs[1].body).toBe('Restarting it now.');
|
||||
});
|
||||
});
|
||||
17
tests/fixtures/fake-claude-blue.js
vendored
Executable file
17
tests/fixtures/fake-claude-blue.js
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env node
|
||||
// Fake claude CLI for the Little Blue route test. Emits text deltas + a
|
||||
// propose_action tool call (no draft). The tool's real HTTP call is irrelevant
|
||||
// here — the route only streams the fixture + persists.
|
||||
const ID = 'toolu_blue_01';
|
||||
const lines = [
|
||||
{ type: 'system', subtype: 'init', session_id: 'fake-blue', tools: [], cwd: '/tmp' },
|
||||
{ type: 'stream_event', event: { type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } } },
|
||||
{ type: 'stream_event', event: { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: 'Restarting it now.' } } },
|
||||
{ type: 'stream_event', event: { type: 'content_block_stop', index: 0 } },
|
||||
{ type: 'stream_event', event: { type: 'content_block_start', index: 1, content_block: { type: 'tool_use', id: ID, name: 'mcp__void__propose_action', input: {} } } },
|
||||
{ type: 'stream_event', event: { type: 'content_block_stop', index: 1 } },
|
||||
{ type: 'tool_result', tool_use_id: ID, content: [{ type: 'text', text: JSON.stringify({ executed: true }) }] },
|
||||
{ type: 'result', subtype: 'success', is_error: false, result: 'Restarting it now.', stop_reason: 'end_turn', session_id: 'fake-blue', total_cost_usd: 0.0001, usage: { input_tokens: 30, output_tokens: 3 } }
|
||||
];
|
||||
for (const l of lines) process.stdout.write(JSON.stringify(l) + '\n');
|
||||
process.exit(0);
|
||||
Reference in New Issue
Block a user