38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
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);
|
|
});
|
|
});
|