20 lines
903 B
JavaScript
20 lines
903 B
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import * as aa from '../../lib/db/repos/agent_actions.js';
|
|
|
|
const owner = { kind: 'user', id: null };
|
|
beforeAll(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
describe('agent_actions repo', () => {
|
|
it('creates pending, lists it, resolves once', async () => {
|
|
const row = await aa.create({ action_id: 'stop-ct107', tier: 'risky', params: {}, requested_by: owner });
|
|
expect(row.status).toBe('pending');
|
|
expect((await aa.listPending()).some(r => r.id === row.id)).toBe(true);
|
|
const done = await aa.resolve(row.id, 'executed', { ok: true }, owner);
|
|
expect(done.status).toBe('executed');
|
|
const again = await aa.resolve(row.id, 'rejected', null, owner); // already resolved
|
|
expect(again).toBeUndefined();
|
|
});
|
|
});
|