mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 23:35:20 +00:00
* feat(agent-pool): fundacao read-only do orquestrador (fase A) - docs/plans/agent-pool-orchestrator.md: plano completo (14 secoes) - buildClaimQueue extraido de agent-claim para agent-github (comportamento identico, pinado) - agent-pool-eligibility: isAutonomousClaimable puro e fail-closed + buildPoolQueue - agent-pool-state: parsePoolConfig, marcadores pool-worker, classifyPoolClaim, spawn plan, auto-stop - agent-pool-github: leitura de repo variables (degrada nao-estrito), claims/PRs/migration-lock - pnpm agent:pool -- status|tick --dry-run (inspecao local; live chega na fase B) - 34 specs unit novos (992/992 verde); lint/tsc/knip/cycles/format verdes Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com> * feat(agent-pool): spawn remoto de workers via Cursor API (fase B) - agent-pool-cursor: client fino da Cloud Agents API v1 (fetch injetavel; CursorApiError com status/body) - agent-pool-models: resolvePoolModel contra /v1/models (id/alias, sufixo -fast -> param, fallback composer-2.5 com warn) - agent-pool-prompt: contrato do worker (claim pre-feito, pula passo 1; PR base stage + Closes #N; promote proibido) - claim coordenado no tick: lock otimista + flip + marcador; agentId idempotente bc-<uuid>; 409 recupera; rollback em falha de spawn - agent:pool workflow --action start|stop|pause|resume|tick|status (variables POOL_*); doctor; wrappers gh workflow run - .github/workflows/agent-pool.yml (dispatch-only; schedule/triggers na fase C) - 19 specs novos (1011/1011); lint/tsc/knip/cycles/format verdes Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com> * feat(agent-pool): ciclo de vida do supervisor (fase C) - derivePoolClaims com status real dos runs (getCursorRun), heal de spawn via agentId deterministico, cancel de duplicatas - reconcilePoolClaims: falha terminal -> comentario + blocked + archive; merge concluido -> slot livre + archive - auto-stop real: fila drenada + zero ativos -> POOL_ENABLED=false (exclusoes migration-busy nao desligam) - job summary markdown (GITHUB_STEP_SUMMARY) — superficie remota de status - workflow: schedule */10min + pull_request closed em stage (ativam na default branch apos promote) - 2 specs novos (1013/1013); lint/tsc/knip/cycles/format verdes Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com> * docs(agent-pool): runbook operacional e adendo do spike (fase D) - skill agent-pool: runbook humano (pre-requisitos, start/stop/pause remoto, ciclo de vida, triage, smoke de aceite) - AGENT-OPS: linha na tabela de comandos + secao Agent pool (canal, secrets, ativacao pos-promote) - CHANGELOG-AGENTS: entrada curta da entrega - engineering-audit: pause/resume do pool no protocolo do modo solitario - plano secao 14.1: evidencias do spike 2026-07-30 (environment repo-file confirmado, id bc-<uuid>, degradacao 403, pendencias do primeiro run com CURSOR_API_KEY) Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com> * fix(test): teardown flake no homeSearchUi.unit.spec (dono do CI) O scheduler do react (prefetch do next/link) podia disparar apos o teardown do jsdom e derrubar o job unit com 'window is not defined' (run 30587862940). afterEach(cleanup) — padrao dos 14 specs irmaos. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { CursorApiError, cursorApiRequest } from '../../scripts/lib/agent-pool-cursor.mjs'
|
|
|
|
const fakeResponse = (ok: boolean, status: number, payload: unknown) =>
|
|
({
|
|
ok,
|
|
status,
|
|
text: async () => (payload === null ? '' : JSON.stringify(payload)),
|
|
}) as Response
|
|
|
|
const captureFetch = (response: Response) => {
|
|
const calls: Array<{ url: string; init: RequestInit }> = []
|
|
const fetchImpl = async (url: string | URL | Request, init?: RequestInit) => {
|
|
calls.push({ url: String(url), init: init ?? {} })
|
|
return response
|
|
}
|
|
return { calls, fetchImpl: fetchImpl as typeof fetch }
|
|
}
|
|
|
|
describe('cursorApiRequest', () => {
|
|
it('sends Basic auth with the key as username and parses JSON', async () => {
|
|
const { calls, fetchImpl } = captureFetch(fakeResponse(true, 200, { ok: true }))
|
|
const result = await cursorApiRequest('/v1/me', { apiKey: 'crsr_teste', fetchImpl })
|
|
expect(result).toEqual({ ok: true })
|
|
expect(calls[0]!.url).toBe('https://api.cursor.com/v1/me')
|
|
const auth = (calls[0]!.init.headers as Record<string, string>).authorization
|
|
expect(auth).toBe(`Basic ${Buffer.from('crsr_teste:').toString('base64')}`)
|
|
})
|
|
|
|
it('posts a JSON body only when provided', async () => {
|
|
const { calls, fetchImpl } = captureFetch(fakeResponse(true, 200, { agent: {} }))
|
|
await cursorApiRequest('/v1/agents', {
|
|
method: 'POST',
|
|
body: { prompt: { text: 'oi' } },
|
|
apiKey: 'k',
|
|
fetchImpl,
|
|
})
|
|
expect(calls[0]!.init.body).toBe(JSON.stringify({ prompt: { text: 'oi' } }))
|
|
|
|
const getCalls = captureFetch(fakeResponse(true, 200, {}))
|
|
await cursorApiRequest('/v1/models', { apiKey: 'k', fetchImpl: getCalls.fetchImpl })
|
|
expect(getCalls.calls[0]!.init.body).toBeUndefined()
|
|
})
|
|
|
|
it('throws CursorApiError with status and parsed body on failure', async () => {
|
|
const { fetchImpl } = captureFetch(
|
|
fakeResponse(false, 409, { error: { code: 'agent_id_conflict' } }),
|
|
)
|
|
const failure = await cursorApiRequest('/v1/agents', {
|
|
method: 'POST',
|
|
body: {},
|
|
apiKey: 'k',
|
|
fetchImpl,
|
|
}).catch((error: unknown) => error)
|
|
expect(failure).toBeInstanceOf(CursorApiError)
|
|
expect((failure as InstanceType<typeof CursorApiError>).status).toBe(409)
|
|
expect((failure as InstanceType<typeof CursorApiError>).body).toEqual({
|
|
error: { code: 'agent_id_conflict' },
|
|
})
|
|
})
|
|
|
|
it('fails closed without an API key (status 0, no fetch)', async () => {
|
|
const { calls, fetchImpl } = captureFetch(fakeResponse(true, 200, {}))
|
|
const failure = await cursorApiRequest('/v1/me', { apiKey: '', fetchImpl }).catch(
|
|
(error: unknown) => error,
|
|
)
|
|
expect((failure as InstanceType<typeof CursorApiError>).status).toBe(0)
|
|
expect(calls).toHaveLength(0)
|
|
})
|
|
})
|