Files
Void-Homelab/tests/ai/agent/tools/blue.test.js

23 lines
1.3 KiB
JavaScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { listActionsTool, proposeActionTool } from '../../../../lib/ai/agent/tools/blue/actions.js';
beforeEach(() => { process.env.VOID_API_URL = 'http://127.0.0.1:3000'; process.env.VOID_AGENT_TOKEN = 'blue-tok'; });
describe('blue action tools', () => {
it('list_actions GETs the whitelist with the agent bearer', async () => {
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ actions: [{ id: 'restart-caddy-ct100', tier: 'safe' }] }) }));
const out = await listActionsTool.handler({}, {}, { fetchImpl: fetchMock });
expect(out.actions[0].id).toBe('restart-caddy-ct100');
const [url, opts] = fetchMock.mock.calls[0];
expect(url).toBe('http://127.0.0.1:3000/api/actions');
expect(opts.headers.Authorization).toBe('Bearer blue-tok');
});
it('propose_action POSTs run and returns the queued/executed result', async () => {
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ queued: true, action_row_id: 'r1' }) }));
const out = await proposeActionTool.handler({ action_id: 'stop-ct107' }, {}, { fetchImpl: fetchMock });
expect(out.queued).toBe(true);
expect(fetchMock.mock.calls[0][0]).toBe('http://127.0.0.1:3000/api/actions/stop-ct107/run');
expect(fetchMock.mock.calls[0][1].method).toBe('POST');
});
});