fix(opencode): improve Windows unit compatibility#148
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 53 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR adds Windows-specific support and workarounds: ia32-win32 ripgrep mapping and version bump to 15.1.0; defers Arborist import and sets a fake platform env on Windows; increases rm retry counts on Windows; and stabilizes tests via concurrent stream decoding, polling helpers, and longer timeouts. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant NpmModule as Npm
participant ProcessEnv as Process
participant Arborist
participant Tar
Client->>NpmModule: call Npm.add / Npm.install
NpmModule->>ProcessEnv: if win32 set __FAKE_PLATFORM__="linux"
NpmModule->>Arborist: dynamic import Arborist (deferred until now)
Arborist->>Tar: (lazy) import tar when needed
Arborist-->>NpmModule: return Arborist instance
NpmModule-->>Client: proceed with package operations
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
5fcd3cd to
d35e026
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces several Windows-specific fixes and improvements, including support for the ia32-win32 platform, updating ripgrep to version 15.1.0, and addressing file system issues on Windows by increasing retry attempts and implementing a platform-faking workaround for Arborist. Additionally, test suites were refactored for better cross-platform compatibility and reliability. Feedback suggests avoiding global side effects in packages/opencode/src/npm/index.ts by making platform-specific values injectable rather than relying on top-level environment variable modifications.
Astro-Han
left a comment
There was a problem hiding this comment.
Review Summary
Overall this PR addresses Windows compatibility issues well. The changes are appropriate for fixing the unit test failures on Windows. However, I found several issues that should be addressed before merge.
P0 (Blocking)
None found.
P1 (Recommend fixing before merge)
-
ripgrep.ts: inconsistent executable suffix handling - The
which()call now explicitly checks forrg.exe, but this should be verified against Bun's actual behavior on Windows. -
npm/index.ts: global side effect at module load time - Setting
process.env.__FAKE_PLATFORM__affects the entire process. Consider wrapping this or documenting as a known compromise.
P2 (Nice to fix, optional)
-
worktree/index.ts: magic retry number - The 6x jump from 5 to 30 retries lacks justification.
-
workspace-adaptor.test.ts: silent error masking - The catch handler returns "0" which could hide real issues.
P3 (Minor nitpicks)
-
ripgrep.ts: version upgrade lacks changelog reference - Adding a comment would help future maintenance.
-
runtime-namespace.test.ts: expectRoot incomplete - Only validates 4 of 6 fields.
-
cross-spawn-spawner.test.ts: concurrency change lacks explanation - No comment clarifying intent.
Overall assessment
The PR is well-structured with clear intent. Most issues are minor (P2/P3). The P1 issues are worth addressing for code quality but may not block the Windows tests from passing. Recommend addressing P1 items or documenting why the current approach is acceptable.
d35e026 to
2e0fa17
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/test/global/runtime-namespace.test.ts`:
- Around line 4-9: The tests create a shared hard-coded roots object (named
roots) with /tmp paths; replace this with per-test tmpdir-managed directories by
importing tmpdir from fixture/fixture.ts and using `await using` to obtain
isolated temp dirs for data, cache, config, and state, then assign those paths
into the roots object (or directly replace usages of roots) so each test gets
its own lifecycle and automatic cleanup; update any setup/teardown that
references roots in runtime-namespace.test.ts to use the tmpdir handles returned
by tmpdir().
- Around line 13-19: The test currently only sets
process.env.PAWWORK_RUNTIME_NAMESPACE when namespace is provided, which allows
inherited values to leak; update the setup to explicitly clear or unset
PAWWORK_RUNTIME_NAMESPACE when namespace is undefined (e.g., delete
process.env.PAWWORK_RUNTIME_NAMESPACE or set it to undefined) so the child
process starts clean. Locate the test setup where process.env.XDG_* are assigned
and modify the logic around process.env.PAWWORK_RUNTIME_NAMESPACE and the local
variable namespace to ensure the env var is removed when namespace is not
passed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2d655287-e443-4fb5-a5b5-4a4178926a42
📒 Files selected for processing (7)
packages/opencode/src/file/ripgrep.tspackages/opencode/src/npm/index.tspackages/opencode/src/worktree/index.tspackages/opencode/test/effect/cross-spawn-spawner.test.tspackages/opencode/test/global/runtime-namespace.test.tspackages/opencode/test/plugin/workspace-adaptor.test.tspackages/opencode/test/session/prompt-effect.test.ts
2e0fa17 to
fec7605
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Nitpick pass on the Windows stabilization PR. Nothing blocking — all P2/P3. Details inline.
- P2:
src/npm/index.tsmutates a Bun-global env var at module import time. - P2:
waitForCountersilently returns last value on timeout; inconsistent with thewaitForhelper right above it. - P3:
test/fixture/fixture.tsstill usesmaxRetries: 5for the same Windows-EBUSY reason. - P3: The ripgrep
14.1.1 → 15.1.0bump is outside the stated scope of this PR. - P3: The
3_000 → 10_000test timeout is applied to all platforms, not just Windows.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/src/worktree/index.ts`:
- Around line 361-373: Replace the direct import/use of "fs/promises" in the
cleanup block with the injected AppFileSystem.Service instance used earlier
(refer to the AppFileSystem.Service symbol and the variable used at line 179)
and call its fs.remove(target, { recursive: true }) method instead of fsp.rm;
then wrap that call with Effect.retry (or a Schedule) to implement the
platform-specific retry behavior (use maxRetries = process.platform === "win32"
? 30 : 5 and retryDelay 100ms) following the pattern used at the other cleanup
site (see the usage around line 497) so the operation honors the service
abstraction and applies the same retry semantics.
In `@packages/opencode/test/plugin/workspace-adaptor.test.ts`:
- Around line 60-68: The waitForCounter helper currently returns the last read
value when the 5_000ms loop times out, which hides failure context; update
waitForCounter so that after the timeout (end loop controlled by Date.now() and
end) it throws an Error instead of returning value and include contextual
details (file identifier, expected min, and last observed value) in the error
message; locate the loop using read(), wait(50), value, end and replace the
final return value with a thrown Error that contains file, min and value for
easier debugging.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 042ea05f-d591-49f2-bd53-2bc637034b3f
📒 Files selected for processing (7)
packages/opencode/src/file/ripgrep.tspackages/opencode/src/npm/index.tspackages/opencode/src/worktree/index.tspackages/opencode/test/effect/cross-spawn-spawner.test.tspackages/opencode/test/global/runtime-namespace.test.tspackages/opencode/test/plugin/workspace-adaptor.test.tspackages/opencode/test/session/prompt-effect.test.ts
Astro-Han
left a comment
There was a problem hiding this comment.
Nitpick review for Windows stabilization PR. Issues graded P1-P3 per project convention.
fec7605 to
a7d397b
Compare
a7d397b to
cf6d1cd
Compare
Summary
Why
Issue #141's PR direction 1 targets the current
unit-windows-opencodefailure families from run 24781051308: runtime namespace path assertions, config dependency installs, plugin workspace timing and cleanup, and shell queue timing. Electron desktop Windows hardening remains a separate PR direction.Related Issue
Part of #141.
How To Verify
Latest local
bun run test:ciresult: 2016 pass, 8 skip, 1 todo, 0 fail.Screenshots or Recordings
Not applicable. No visible UI changes.
Checklist
dev, and my PR title and commit messages use Conventional Commits in EnglishSummary by CodeRabbit
New Features
Bug Fixes
Tests