Skip to content

test: unit tests for task queue (priority, retry, dead letter) - #452

Open
Kaycee276 wants to merge 4 commits into
Bitcoindefi:mainfrom
Kaycee276:fix/186-task-queue-tests
Open

test: unit tests for task queue (priority, retry, dead letter)#452
Kaycee276 wants to merge 4 commits into
Bitcoindefi:mainfrom
Kaycee276:fix/186-task-queue-tests

Conversation

@Kaycee276

Copy link
Copy Markdown

Title

test: unit tests for task queue (priority, retry, dead letter)

Context

PR #178 introduced a task queue with priority ordering, a dead-letter queue, and retry logic with backoff, but it did not include tests or fully expose the dequeue(), peekNext(), and retryAll() methods. This PR fulfills the acceptance criteria for issue #186 by implementing the missing methods and writing comprehensive unit tests.

Implementation Details

  • Added peekNext() to lib/agent-runtime/task-queue.ts: Retrieves the highest-priority pending task without modifying its state.
  • Added dequeue() to lib/agent-runtime/task-queue.ts: Uses peekNext() to get the next task and transitions its status to "leased".
  • Added retryAll() to lib/agent-runtime/task-queue.ts: Iterates over the dead-letter queue and calls retryDeadLetterTask() on all failed tasks.
  • Added Test Suite at lib/task-queue/__tests__/task-queue.test.ts:
    • Enqueues multiple priority levels to assert descending priority dequeue.
    • Tests equal priorities to ensure FIFO ordering.
    • Uses vi.useFakeTimers() to fast-forward through the N retry attempts and verify the task eventually moves to the dead-letter queue.
    • Verifies retryAll() accurately resets dead-letter tasks back to pending.
    • Asserts that dequeue() on an empty queue safely returns null.
    • Mocks Request objects to test both the POST /api/tasks and GET /api/tasks/[id] Next.js route handlers directly.

Verification

  • Unit tests verify all 8 required behaviors using Vitest.
  • Re-ran the existing suite to ensure no regressions were introduced to enqueueTask, failTask, or API routes.
  • Proof: (Please remember to attach your demo video or screenshots here as per the mandatory delivery requirements before opening the PR)

closes #186

@leocagli

Copy link
Copy Markdown
Collaborator

Hi @Kaycee276 👋 — the tests themselves look good (+158, clean diff, Sonar green), but the required CI fails at npm ci with ERESOLVE: your branch's lockfile resolves typescript@7.0.2, which conflicts with @typescript-eslint/eslint-plugin@8.64.x (requires TS <7). main is on typescript@5.7.3 and its CI is green.

Fix: rebase your branch onto the latest main (make sure your fork's main is synced first) and don't carry over package.json/package-lock.json changes — your PR shouldn't need any. Once CI is green I'll merge right away. 🙏

@Kaycee276

Copy link
Copy Markdown
Author

Hi @leocagli
Thanks for the review! 🙏

I've pushed an update that addresses your feedback:

  • Reverted the package.json and lockfile changes so they are now perfectly in sync with main (no more ESLint vs TypeScript 7.0 ERESOLVE conflicts).
  • Fixed the TS1005 syntax error in lib/agent-runtime/task-queue.ts that occurred during my previous conflict resolution.

The CI should be completely green now. Let me know if anything else is needed!

@leocagli

Copy link
Copy Markdown
Collaborator

Hi @Kaycee276 👋 — quick update: video/screenshots are not required to merge anymore, just a bonus — if you add one it'll be considered for GrantFox rewards on this issue. So I'll review this on code + checks alone now. 🙏

@sonarqubecloud

Copy link
Copy Markdown

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.

Tests: unit tests for task queue (priority, retry, dead letter)

2 participants