Repository navigation
test(e2e): wait for the agent post's enqueue before clearing events - #3633
Merged
Merged
Conversation
The runtime post route doesn't wait for its mention enqueue, so a post at the end of one test could write `message.posted` after afterEach cleared AgentEvent. The next test polled it: expected 1 event, got 2. This ejected #3577 and #3624 from the merge queue. Each test now waits for those calls before the clear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015AKgpN1QhxGKRxQeoqFeov
lilyshen0722
commented
Nov 6, 2026
lilyshen0722
left a comment
Contributor
Author
There was a problem hiding this comment.
HEAD: 026f76e — GATE: PASS
Reviewed as local commit ee6af44c3; this head is the same tree.
- Spy interception: holds. The route calls
AgentMentionService.enqueueAgentPost(...)as a property of the required module (backend/routes/agentsRuntime.ts~2520), and the test requires the same module. I did not compile the CJS output to confirm the export is writable, so that step is inferred, not run. - restoreMocks / clearMocks: no conflict. Jest restores spies at test start, before the
beforeEachre-spies. The top-levelafterEachruns before the next test's restore, so it still sees the current test'smock.results. The route records the call before it responds, so supertest completion means the call is already inmock.results. - Promise.allSettled: safe. The route attaches
.catch, so rejections are handled, andallSettledaccepts non-promise values.enqueueAgentPostis async, so it cannot throw synchronously. - Hook order: the only
beforeAllis the top-level one, before any spy. There are no nestedafterEachhooks, and the nestedbeforeEachhooks run after the spy is installed. - Gap, not a blocker: the same post path has other unawaited work that this does not cover.
void eventHandlers.dispatch('chat.message', …)(backend/services/agentMessageService.ts~2250) andvoid AgentMessageService.maybeRecordAgentDmConclusion(…)(~1483) could write events late. I did not confirm whether either writesAgentEventin this suite. A follow-up should check that, or spy on them too.
Written by a Haiku 5.5 review subagent.
GATE: PASS
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 43 seconds. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
clawdbot-e2e"should handle summary event from user chat activity" failed with expected 1 event, got 2, and ejected #3577 and #3624 from the merge queue.The second event is a
message.postedfor "Message from Commonly Bot", from the previous test. The runtime post route doesn't wait forenqueueAgentPost, so that write can land afterafterEachclearedAgentEvent, and the next poll picks it up.The fix is in the test:
afterEachnow waits for those calls before it clears. The route stays as it is, because not blocking a post on its wakes is deliberate. The spy goes inbeforeEach, sincerestoreMocks: trueundoes one set inbeforeAllbefore the first test.How I checked: I added a delay of 60–200 ms to
enqueueAgentPostin a scratch copy. Without the fix, this failure came back in 3 of 6 runs and the captured extra event was that post. With the fix, all 6 runs passed, and so did the plain file (29/29).Not covered: the same post path has two other unawaited calls, the
chat.messagedispatch andmaybeRecordAgentDmConclusion. Neither produced the extra event here.🤖 Generated with Claude Code
https://claude.ai/code/session_015AKgpN1QhxGKRxQeoqFeov