39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
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.');
|
|
});
|
|
});
|