An open-source, faster Devin alternative
TypeScript
test: cover agent invocation dashboard client
Igor Zalutski3d9943b93e25
diff --git a/web/src/api/agent-invocation-client.test.ts b/web/src/api/agent-invocation-client.test.tsnew file mode 100644index 00000000..6ec42f9b--- /dev/null+++ b/web/src/api/agent-invocation-client.test.ts@@ -0,0 +1,100 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import {+ createAgentHook,+ getAgentHooks,+ invokeAgent,+ revokeAgentHook,+} from './client'++const agentId = 'agt_0123456789abcdef01234567'++afterEach(() => vi.unstubAllGlobals())++describe('Agent URL dashboard client', () => {+ it('invokes through the signed dashboard proxy with a stable key', async () => {+ const fetchMock = vi.fn(+ (input: string | URL | Request, init?: RequestInit) => {+ void input+ void init+ return Promise.resolve(+ Response.json({+ request_id: 'req_1',+ session: { id: 'ses_1', status: 'queued', head: 1 },+ client_token: 'client-secret',+ links: {+ events: 'https://example.test/events',+ messages: 'https://example.test/messages',+ },+ replayed: false,+ }),+ )+ },+ )+ vi.stubGlobal('fetch', fetchMock)++ await expect(+ invokeAgent(agentId, { task: 'review' }, 'invoke-1'),+ ).resolves.toMatchObject({ session: { id: 'ses_1' } })+ const [input, init] = fetchMock.mock.calls[0]+ expect(input).toBe(`/api/dashboard/v3/agents/${agentId}/sessions`)+ expect(init).toMatchObject({+ method: 'POST',+ credentials: 'include',+ body: JSON.stringify({ task: 'review' }),+ })+ expect(new Headers(init?.headers).get('Idempotency-Key')).toBe('invoke-1')+ })+})++describe('Hook management dashboard client', () => {+ it('parses copy-once creation and secret-free list responses', async () => {+ const fetchMock = vi.fn((input: string | URL | Request) => {+ const path =+ typeof input === 'string'+ ? input+ : input instanceof URL+ ? input.href+ : input.url+ if (path.includes('?')) {+ return Promise.resolve(Response.json({ data: [], next_cursor: null }))+ }+ return Promise.resolve(+ Response.json(+ {+ hook: {+ id: 'hk_0123456789abcdef01234567',+ agent_id: agentId,+ name: 'grafana-prod',+ status: 'active',+ secret_last4: 'xYz0',+ revoked_reason: null,+ expires_at: null,+ created_at: '2026-07-22T00:00:00.000Z',+ },+ hook_url: 'https://agent.test/hooks/secret',+ },+ { status: 201 },+ ),+ )+ })+ vi.stubGlobal('fetch', fetchMock)++ const created = await createAgentHook(agentId, { name: 'grafana-prod' })+ expect(created.hook_url).toBe('https://agent.test/hooks/secret')+ await expect(getAgentHooks(agentId)).resolves.toEqual({+ data: [],+ next_cursor: null,+ })+ })++ it('revokes without expecting a response body', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(() => Promise.resolve(new Response(null, { status: 204 }))),+ )++ await expect(+ revokeAgentHook(agentId, 'hk_0123456789abcdef01234567'),+ ).resolves.toBeUndefined()+ })+})