Skip to content

test(e2e): agent registration -> task assignment -> XP earned flow (#219) - #492

Open
blippip69 wants to merge 1 commit into
Bitcoindefi:mainfrom
blippip69:test/e2e-agent-task-xp-219
Open

test(e2e): agent registration -> task assignment -> XP earned flow (#219)#492
blippip69 wants to merge 1 commit into
Bitcoindefi:mainfrom
blippip69:test/e2e-agent-task-xp-219

Conversation

@blippip69

Copy link
Copy Markdown
Contributor

test(e2e): agent registration -> task assignment -> XP earned flow (#219)

EN

Adds e2e/agent-task-xp.e2e.test.ts - a Vitest e2e suite driving the REAL
Next.js route handlers (no mocks) through the full lifecycle:

  1. POST /api/agents register -> 201
  2. POST /api/agents/[id]/tasks assign -> 201
  3. task moves to running, PATCH .../tasks/[taskId] complete -> 200
  4. GET /api/agents/[id] -> xp increased, level matches the XP curve,
    tasksCompleted incremented

Error paths:

  • assigning a task to a non-existent agent -> 404
  • completing the same task twice is rejected (404) and XP does NOT move twice

Isolation: per-test in-memory stores (resetAgentRegistryForTests,
resetTaskQueue, resetAgentXpDb) + unique e2e-agent-<uuid> ids; cleanup
purges the queue via DELETE /api/agents/[id]/tasks. Cannot touch real data.
Every assert carries a message naming the broken step.

CI: vitest.config.ts now includes e2e/*.e2e.test.ts in the standard
npx vitest run, so it runs in the existing "Unit tests" CI job - no new
workflow needed. Playwright browser specs are unaffected.

Runtime: full flow suite finishes in ~15ms (< 10s requirement). Full repo run
green: 76 files / 471 tests passed.

> npx vitest run e2e/agent-task-xp.e2e.test.ts
 Test Files  1 passed (1)
      Tests  4 passed (4)

README section added explaining how to run it locally and what it needs.

ES

Agrega e2e/agent-task-xp.e2e.test.ts: suite e2e en Vitest que maneja los
route handlers REALES de Next.js por todo el ciclo de vida: registro (201) ->
asignacion de tarea (201) -> completado (200) -> xp / level /
tasksCompleted actualizados en GET /api/agents/[id]. Tambien cubre los
caminos de error: 404 para agente inexistente y doble completado rechazado sin
sumar XP dos veces. Aislamiento explicito con stores en memoria y nombres
unicos e2e-agent-<uuid>; corre en el job de CI existente (~15ms).

@sonarqubecloud

Copy link
Copy Markdown

Comment thread vitest.config.ts
Comment on lines +11 to 16
include: ["__tests__/**/*.test.ts", "e2e/*.e2e.test.ts"],
exclude: [
"**/node_modules/**",
"**/dist/**",
"packages/create-app/template/**",
"e2e/**",
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Bug: New vitest include globs silently drop ~22 test files from CI

Previously the config had no include, so vitest used its default (**/*.{test,spec}) and ran every *.test.ts in the repo except e2e/**. The new include: ["__tests__/**/*.test.ts", "e2e/*.e2e.test.ts"] is anchored to the repo root, so it only matches the top-level __tests__/ directory. All co-located and nested suites now stop running in npx vitest run / the CI "Unit tests" job: the entire tests/ tree (task-queue, task-drain, xp-leaderboard-store, webhook filters, skills versioning), co-located lib/**/*.test.ts (xp, x402, quest-store, reputation, notifications, executor, etc.), and nested __tests__ dirs (app/api/webhooks/__tests__/, lib/agent-runtime/__tests__/, lib/webhooks/__tests__/). That's roughly 22 test files silently excluded from CI — a large loss of coverage that will hide future regressions. Use a glob that matches nested locations.

Match all .test.ts anywhere (this also covers e2e/.e2e.test.ts) while excluding the create-app template via exclude, preserving the previous discovery behavior plus the new e2e suite.:

include: ["**/*.test.ts", "e2e/*.e2e.test.ts"],
exclude: [
  "**/node_modules/**",
  "**/dist/**",
  "packages/create-app/template/**",
],
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

Comment on lines +85 to +91
const completion = await completeTask(
post(`http://localhost/api/agents/${agentId}/tasks/${assigned.taskId}`, {
status: "completed",
result: { ok: true },
}),
taskContext(agentId, assigned.taskId),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: Task-completion request built with POST but handler is PATCH

The suite imports PATCH as completeTask and the README documents completion as PATCH /api/agents/[id]/tasks/[taskId], but the requests are constructed with the post() helper (method "POST"). It works only because the handler is invoked directly and never inspects req.method, so the mismatch is silently ignored and the test does not actually exercise the real HTTP method contract it claims to. Use a patch() helper (or set method: "PATCH") so the request matches the handler being called.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Code Review 🚫 Blocked 0 resolved / 2 findings

Adds an end-to-end Vitest suite covering the agent registration, task assignment, and XP earning lifecycle. However, the new glob patterns silently exclude existing test files in CI and the task completion requests use POST instead of PATCH.

🚨 Bug: New vitest include globs silently drop ~22 test files from CI

📄 vitest.config.ts:11-16

Previously the config had no include, so vitest used its default (**/*.{test,spec}) and ran every *.test.ts in the repo except e2e/**. The new include: ["__tests__/**/*.test.ts", "e2e/*.e2e.test.ts"] is anchored to the repo root, so it only matches the top-level __tests__/ directory. All co-located and nested suites now stop running in npx vitest run / the CI "Unit tests" job: the entire tests/ tree (task-queue, task-drain, xp-leaderboard-store, webhook filters, skills versioning), co-located lib/**/*.test.ts (xp, x402, quest-store, reputation, notifications, executor, etc.), and nested __tests__ dirs (app/api/webhooks/__tests__/, lib/agent-runtime/__tests__/, lib/webhooks/__tests__/). That's roughly 22 test files silently excluded from CI — a large loss of coverage that will hide future regressions. Use a glob that matches nested locations.

Match all *.test.ts anywhere (this also covers e2e/*.e2e.test.ts) while excluding the create-app template via exclude, preserving the previous discovery behavior plus the new e2e suite.
include: ["**/*.test.ts", "e2e/*.e2e.test.ts"],
exclude: [
  "**/node_modules/**",
  "**/dist/**",
  "packages/create-app/template/**",
],
💡 Quality: Task-completion request built with POST but handler is PATCH

📄 e2e/agent-task-xp.e2e.test.ts:85-91 📄 e2e/agent-task-xp.e2e.test.ts:130-135 📄 e2e/agent-task-xp.e2e.test.ts:141-144

The suite imports PATCH as completeTask and the README documents completion as PATCH /api/agents/[id]/tasks/[taskId], but the requests are constructed with the post() helper (method "POST"). It works only because the handler is invoked directly and never inspects req.method, so the mismatch is silently ignored and the test does not actually exercise the real HTTP method contract it claims to. Use a patch() helper (or set method: "PATCH") so the request matches the handler being called.

🤖 Prompt for agents
Code Review: Adds an end-to-end Vitest suite covering the agent registration, task assignment, and XP earning lifecycle. However, the new glob patterns silently exclude existing test files in CI and the task completion requests use POST instead of PATCH.

1. 🚨 Bug: New vitest include globs silently drop ~22 test files from CI
   Files: vitest.config.ts:11-16

   Previously the config had no `include`, so vitest used its default (`**/*.{test,spec}`) and ran every `*.test.ts` in the repo except `e2e/**`. The new `include: ["__tests__/**/*.test.ts", "e2e/*.e2e.test.ts"]` is anchored to the repo root, so it only matches the top-level `__tests__/` directory. All co-located and nested suites now stop running in `npx vitest run` / the CI "Unit tests" job: the entire `tests/` tree (task-queue, task-drain, xp-leaderboard-store, webhook filters, skills versioning), co-located `lib/**/*.test.ts` (xp, x402, quest-store, reputation, notifications, executor, etc.), and nested `__tests__` dirs (`app/api/webhooks/__tests__/`, `lib/agent-runtime/__tests__/`, `lib/webhooks/__tests__/`). That's roughly 22 test files silently excluded from CI — a large loss of coverage that will hide future regressions. Use a glob that matches nested locations.

   Fix (Match all *.test.ts anywhere (this also covers e2e/*.e2e.test.ts) while excluding the create-app template via exclude, preserving the previous discovery behavior plus the new e2e suite.):
   include: ["**/*.test.ts", "e2e/*.e2e.test.ts"],
   exclude: [
     "**/node_modules/**",
     "**/dist/**",
     "packages/create-app/template/**",
   ],

2. 💡 Quality: Task-completion request built with POST but handler is PATCH
   Files: e2e/agent-task-xp.e2e.test.ts:85-91, e2e/agent-task-xp.e2e.test.ts:130-135, e2e/agent-task-xp.e2e.test.ts:141-144

   The suite imports `PATCH as completeTask` and the README documents completion as `PATCH /api/agents/[id]/tasks/[taskId]`, but the requests are constructed with the `post()` helper (method "POST"). It works only because the handler is invoked directly and never inspects `req.method`, so the mismatch is silently ignored and the test does not actually exercise the real HTTP method contract it claims to. Use a `patch()` helper (or set `method: "PATCH"`) so the request matches the handler being called.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 7 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant