test(backends): add unit tests for OpenCode stream event handling#1051
Merged
test(backends): add unit tests for OpenCode stream event handling#1051
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
nhopeatall
approved these changes
Mar 25, 2026
Collaborator
nhopeatall
left a comment
There was a problem hiding this comment.
Summary
LGTM — Well-structured unit tests that accurately cover the exported stream event handling helpers.
I traced each test suite against the source implementation in src/backends/opencode/stream.ts and verified:
- Mock strategy is correct: Mocks are applied at the leaf dependency boundary (
runsRepository,node:fs,logging,nativeToolRetry) rather than at intermediate modules, which means the reallogLlmCallandappendEngineLoglogic is exercised through their actual code paths. - Session ID matching logic is properly tested: The casing asymmetry (
sessionIDin events vssessionIdin state) matches the source and is consistently used across all test suites. - Text deduplication logic is accurately verified: The tests correctly distinguish between streaming (delta-based, no dedup) and non-streaming (part.id-based dedup) paths through
getPartDelta+ theseenTextPartIdsguard. - Permission normalization chain is tested end-to-end:
resolvePermissionDecision → normalizePermissionDecisionmapping ('allow' → 'always','deny' → 'reject') is verified for each permission type. - Fire-and-forget
logLlmCallis handled correctly: ThemockStoreLlmCall.mockResolvedValue(undefined)reset inbeforeEachprevents the.catch()chain inlogLlmCallfrom throwing afterclearMocksresets return values — the PR description explains this well. retryNativeToolOperationpass-through mock is an appropriate simplification that avoids timer complexity while still exercising the actual permission response path.
53 tests covering all 6 exported functions with good edge case coverage (whitespace, undefined state, synthetic/ignored parts, session mismatches, deduplication). All CI checks pass.
🕵️ claude-code · claude-opus-4-6 · run details
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.
Summary
tests/unit/backends/opencode-stream.test.tswith 53 unit tests covering all stream event helper functions insrc/backends/opencode/stream.tsappendPartialOutput,getPartialOutput,reportToolPart,handleSessionTerminalEvent,handleMessagePartUpdated, andhandlePermissionEventopencode.test.tsandopencode-permissions.test.tsWhat was tested
reportedToolCallsSet, pending-state skip, distinct call trackingsession.error(with/without sessionID, error message extraction, fallback to name),session.idle(sessionID match/mismatch),session.statusidle detectionresolvePermissionDecision+normalizePermissionDecision, SDK client called with correct path/body shapeTechnical notes
@opencode-ai/sdk/client,node:fs,runsRepository,nativeToolRetry, andloggingat the module boundary — no full engine orchestrationnativeToolRetryis mocked as a pass-through to avoid timer complexityclearMocks: truein global vitest config requires abeforeEachresettingmockStoreLlmCalltomockResolvedValue(undefined)in the step-finish suite sologLlmCall's.catch()does not throwTrello card
https://trello.com/c/69c3e0fc5b8788ac3c9fe573
🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details