test: AsyncQueue/work utility and State.invalidate coverage#364
Conversation
Add unit tests for AsyncQueue and work() concurrency utility (queue.ts) and State.invalidate (altimate_change in state.ts) — both were completely untested. These tests mitigate risk of race conditions in streaming and stale state after config invalidation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_01AkMKqcoyJ1vURZ4crtpEZu
📝 WalkthroughWalkthroughThese changes add comprehensive test coverage for existing utilities. The first file tests Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/opencode/test/util/queue.test.ts (1)
69-69: Consider using explicit numeric sort.
Array.sort()without a comparator sorts elements as strings. For single-digit numbers[1,2,3,4,5]this works correctly, but if the test is ever extended with multi-digit numbers (e.g.,[1,2,10]), it would produce[1,10,2]instead of[1,2,10].🔧 Suggested fix for robustness
- expect(results.sort()).toEqual([1, 2, 3, 4, 5]) + expect(results.sort((a, b) => a - b)).toEqual([1, 2, 3, 4, 5])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/util/queue.test.ts` at line 69, The test currently calls results.sort() which uses lexicographic sorting; change the assertion to sort numerically by providing an explicit numeric comparator to results.sort (i.e., compare numbers by subtraction) before comparing to the expected array so multi-digit numbers sort correctly; update the call site where results.sort() is used in the test (reference: results.sort in queue.test.ts).packages/opencode/test/project/state.test.ts (1)
141-144: Make the no-op assertion explicit and platform-neutral.This currently relies on implicit throw behavior. Consider asserting no-throw directly and using a non-filesystem-like key string.
Suggested tweak
test("State.invalidate on nonexistent key is a no-op", () => { - // Should not throw - State.invalidate("/nonexistent/path", () => {}) + expect(() => State.invalidate("nonexistent-key", () => {})).not.toThrow() })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/project/state.test.ts` around lines 141 - 144, The test for State.invalidate should explicitly assert no-throw and avoid filesystem-like keys; update the test that calls State.invalidate("/nonexistent/path", () => {}) to use a neutral key (e.g. "nonexistent:key") and wrap the call in an explicit assertion such as expect(() => State.invalidate("nonexistent:key", () => {})).not.toThrow(), referencing the State.invalidate function and the existing test name "State.invalidate on nonexistent key is a no-op".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/opencode/test/project/state.test.ts`:
- Around line 141-144: The test for State.invalidate should explicitly assert
no-throw and avoid filesystem-like keys; update the test that calls
State.invalidate("/nonexistent/path", () => {}) to use a neutral key (e.g.
"nonexistent:key") and wrap the call in an explicit assertion such as expect(()
=> State.invalidate("nonexistent:key", () => {})).not.toThrow(), referencing the
State.invalidate function and the existing test name "State.invalidate on
nonexistent key is a no-op".
In `@packages/opencode/test/util/queue.test.ts`:
- Line 69: The test currently calls results.sort() which uses lexicographic
sorting; change the assertion to sort numerically by providing an explicit
numeric comparator to results.sort (i.e., compare numbers by subtraction) before
comparing to the expected array so multi-digit numbers sort correctly; update
the call site where results.sort() is used in the test (reference: results.sort
in queue.test.ts).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9a57c84b-d768-4375-a655-a276177fc1fd
📒 Files selected for processing (2)
packages/opencode/test/project/state.test.tspackages/opencode/test/util/queue.test.ts
What does this PR do?
Adds missing test coverage for two completely untested modules discovered by the hourly test sweep.
1.
AsyncQueueandwork()—src/util/queue.ts(10 new tests)These utilities power streaming result delivery and concurrent task processing. Zero tests existed. New coverage includes:
work()concurrency limit enforcementpop())2.
State.invalidate—src/project/state.ts(2 new tests)This is an
altimate_changeaddition that clears cached state entries after config changes. It was untested. New coverage includes:Type of change
Issue for this PR
N/A — proactive test coverage
How did you verify your code works?
Checklist
https://claude.ai/code/session_01AkMKqcoyJ1vURZ4crtpEZu
Summary by CodeRabbit