Skip to content

test: AsyncQueue/work utility and State.invalidate coverage#364

Merged
anandgupta42 merged 1 commit intomainfrom
claude/test-queue-state-invalidate-session_01AkMKqcoyJ1vURZ4crtpEZu
Mar 22, 2026
Merged

test: AsyncQueue/work utility and State.invalidate coverage#364
anandgupta42 merged 1 commit intomainfrom
claude/test-queue-state-invalidate-session_01AkMKqcoyJ1vURZ4crtpEZu

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 22, 2026

What does this PR do?

Adds missing test coverage for two completely untested modules discovered by the hourly test sweep.

1. AsyncQueue and work()src/util/queue.ts (10 new tests)

These utilities power streaming result delivery and concurrent task processing. Zero tests existed. New coverage includes:

  • Push-before-next vs next-before-push resolution ordering
  • Multiple concurrent waiters resolving in FIFO order
  • Async iterator correctness (yield + break)
  • Interleaved push/next sequences
  • work() concurrency limit enforcement
  • LIFO processing order (due to pop())
  • Error propagation from workers
  • Empty input handling

2. State.invalidatesrc/project/state.ts (2 new tests)

This is an altimate_change addition that clears cached state entries after config changes. It was untested. New coverage includes:

  • Invalidated entry is re-initialized on next access (not served from stale cache)
  • Calling invalidate with a nonexistent key is a safe no-op

Type of change

  • New feature (non-breaking change which adds functionality)

Issue for this PR

N/A — proactive test coverage

How did you verify your code works?

bun test test/util/queue.test.ts       # 10 pass
bun test test/project/state.test.ts    #  7 pass (5 existing + 2 new)

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_01AkMKqcoyJ1vURZ4crtpEZu

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for cache invalidation behavior, including handling of non-existent keys.
    • Added comprehensive tests for async queue utilities, verifying concurrent operations, FIFO ordering, and error propagation.

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
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

These changes add comprehensive test coverage for existing utilities. The first file tests State.invalidate cache removal behavior and its safety with nonexistent keys. The second introduces tests for AsyncQueue and work utilities, covering queue operations, concurrency limits, and error propagation.

Changes

Cohort / File(s) Summary
Test Coverage Additions
packages/opencode/test/project/state.test.ts, packages/opencode/test/util/queue.test.ts
Added tests for State.invalidate cache removal and FIFO queue behavior; added comprehensive tests for AsyncQueue operations (push, next, async iteration) and work utility concurrency handling, including edge cases and error scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

contributor

Poem

🐰 The tests hop in, row by row,
Async queues now steal the show,
States invalidate with care,
Coverage blooming everywhere! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely summarizes the main change: adding test coverage for AsyncQueue/work utility and State.invalidate.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description comprehensively addresses all required template sections: Summary explains what changed and why with specific module details, Test Plan documents verification steps with passing test results, and all Checklist items are marked complete.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/test-queue-state-invalidate-session_01AkMKqcoyJ1vURZ4crtpEZu

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between dd29651 and e570c8f.

📒 Files selected for processing (2)
  • packages/opencode/test/project/state.test.ts
  • packages/opencode/test/util/queue.test.ts

@anandgupta42 anandgupta42 merged commit d486295 into main Mar 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant