feat(repos): agents (+ tokens + caps), conversations, messages
This commit is contained in:
37
tests/repos/agents.test.js
Normal file
37
tests/repos/agents.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { resetDb } from '../helpers/db.js';
|
||||
import { migrateUp } from '../../lib/db/migrate.js';
|
||||
import * as agents from '../../lib/db/repos/agents.js';
|
||||
|
||||
const owner = { kind: 'user', id: null };
|
||||
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
||||
|
||||
describe('agents repo', () => {
|
||||
it('creates agent with default capabilities', async () => {
|
||||
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
|
||||
expect(a.capabilities.read).toBe(true);
|
||||
expect(a.capabilities.write).toBe(false);
|
||||
});
|
||||
|
||||
it('createToken returns plaintext, verifyToken finds the agent', async () => {
|
||||
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
|
||||
const { token, id } = await agents.createToken(a.id, 'default');
|
||||
expect(token).toMatch(/^vk_/);
|
||||
const found = await agents.verifyToken(token);
|
||||
expect(found?.id).toBe(a.id);
|
||||
});
|
||||
|
||||
it('revoked token does not verify', async () => {
|
||||
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
|
||||
const { token, id } = await agents.createToken(a.id, 'default');
|
||||
await agents.revokeToken(id);
|
||||
expect(await agents.verifyToken(token)).toBeNull();
|
||||
});
|
||||
|
||||
it('setCapabilities updates the jsonb', async () => {
|
||||
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
|
||||
const u = await agents.setCapabilities(a.id, { read: true, suggest: true, write: true }, { pages: true });
|
||||
expect(u.capabilities.write).toBe(true);
|
||||
expect(u.scopes.pages).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user