feat: implement queue operations and add comprehensive test suite for…#411
Open
Kaycee276 wants to merge 1 commit into
Open
feat: implement queue operations and add comprehensive test suite for…#411Kaycee276 wants to merge 1 commit into
Kaycee276 wants to merge 1 commit into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



… task management
Description
Closes #186
PR #178 introduced a task queue with priority ordering, retry backoff logic, and a dead-letter queue, but it lacked unit tests and a few core internal functions required by the acceptance criteria. This PR fully implements the missing functions and provides a comprehensive test suite to guarantee queue behavior and stability without making any real network calls.
Changes Made
1. Task Queue Implementation Updates (
lib/agent-runtime/task-queue.ts)Added the missing queue management functions to fulfill the required behaviors:
peekNext(agentId?: string): Retrieves the highest-prioritypendingtask without leasing it.dequeue(agentId?: string): Finds the highest-prioritypendingtask, updates its status toleased, and returns it.retryAll(): Iterates over all tasks currently in thedead-letterstate, resetting their retries and moving them back topending.2. Comprehensive Test Suite (
lib/task-queue/__tests__/task-queue.test.ts)Added a new Vitest-based test suite leveraging
vi.useFakeTimers()to instantly validate time-dependent logic (such as retry backoffs and FIFO sorting based on timestamps).The test suite validates all 8 requested acceptance criteria:
maxRetries) correctly transitions to thedead-letterqueue.retryAll()successfully moves dead-letter tasks back to the main queue.peekNext()returns the correct item without affecting the queue state.nullondequeue()./api/tasksVerification: MocksRequest/NextResponseto ensure the endpoint correctly processes inputs and returns a201status along with the task ID./api/tasks/[id]Verification: Validates that querying a specific task ID successfully returns the current task status.Testing Instructions
To run the newly added tests locally:
npm run test -- lib/task-queue/__tests__/task-queue.test.tsAll tests execute rapidly and entirely in-memory using mocked
NextResponseboundaries to prevent any real network activity.