Skip to content

fix(opencode): improve Windows unit compatibility#148

Merged
Astro-Han merged 5 commits into
devfrom
codex/fix-i141-windows-opencode
Apr 22, 2026
Merged

fix(opencode): improve Windows unit compatibility#148
Astro-Han merged 5 commits into
devfrom
codex/fix-i141-windows-opencode

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Normalize runtime namespace tests for Windows path separators.
  • Port the narrow Bun Windows tar workaround for npm and Arborist installs.
  • Update managed ripgrep lookup and version for Windows, including arm64 and ia32 mappings.
  • Stabilize plugin workspace retry, worktree cleanup, shell queue timing, and cross-spawn stream tests on Windows.

Why

Issue #141's PR direction 1 targets the current unit-windows-opencode failure 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

cd packages/opencode
bun test test/global/runtime-namespace.test.ts
bun test test/effect/cross-spawn-spawner.test.ts
bun test test/config/config.test.ts test/config/seed-e2e.test.ts test/tool/registry.test.ts
bun test test/plugin/workspace-adaptor.test.ts
bun test test/session/prompt-effect.test.ts -t "loop waits while shell runs and starts after shell exits"
bun test test/session/prompt-effect.test.ts -t "shell completion resumes queued loop callers"
bun test test/file/ripgrep.test.ts
bun run test:ci

Latest local bun run test:ci result: 2016 pass, 8 skip, 1 todo, 0 fail.

Screenshots or Recordings

Not applicable. No visible UI changes.

Checklist

  • I linked the related issue, or stated why there is no issue
  • This PR has type, scope, and priority labels, or I requested maintainer labeling
  • I listed the relevant verification steps, including tests when behavior changed
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for desktop, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, or generated/local file changes when relevant
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

Summary by CodeRabbit

  • New Features

    • Added ia32-Windows platform support and updated ripgrep to v15.1.0
  • Bug Fixes

    • Windows runtime compatibility workaround to avoid tar-related issues
    • More reliable directory cleanup on Windows via increased retry handling
  • Tests

    • Improved test stability: concurrency handling, dynamic temp directories, polling helper for flaky timing, and increased timeouts for shell-related tests

@Astro-Han Astro-Han added bug Something isn't working windows Windows-specific P1 High priority upstream Tracked upstream or vendor behavior labels Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 53 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 90dcd7c7-79f5-4135-843c-f9e6ef97313b

📥 Commits

Reviewing files that changed from the base of the PR and between fec7605 and cf6d1cd.

📒 Files selected for processing (7)
  • packages/opencode/src/file/ripgrep.ts
  • packages/opencode/src/npm/index.ts
  • packages/opencode/src/worktree/index.ts
  • packages/opencode/test/effect/cross-spawn-spawner.test.ts
  • packages/opencode/test/global/runtime-namespace.test.ts
  • packages/opencode/test/plugin/workspace-adaptor.test.ts
  • packages/opencode/test/session/prompt-effect.test.ts
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Ripgrep Platform & Version
packages/opencode/src/file/ripgrep.ts
Added ia32-win32i686-pc-windows-msvc mapping and updated ripgrep release version from 14.1.1 to 15.1.0, changing filename/url used when downloading.
NPM Arborist Windows Workaround
packages/opencode/src/npm/index.ts
On Windows, sets process.env.__FAKE_PLATFORM__ = "linux" before loading Arborist; replaced static Arborist import with dynamic on-demand imports inside Npm.add and Npm.install.
Filesystem Operations
packages/opencode/src/worktree/index.ts
Worktree.cleanDirectory now uses platform-dependent maxRetries for fs.promises.rm (30 on win32, 5 otherwise).
Test Infrastructure & Polling
packages/opencode/test/global/runtime-namespace.test.ts, packages/opencode/test/plugin/workspace-adaptor.test.ts
Switched tests to use temporary runtime roots, injected roots into evaluated scripts, added waitForCounter() polling helper, and replaced fixed sleeps with polling-based waits.
Test Robustness
packages/opencode/test/effect/cross-spawn-spawner.test.ts, packages/opencode/test/session/prompt-effect.test.ts
Used Effect.all with explicit { concurrency: 2 } for stream decoding; increased two it.live timeouts from 3_000 to 10_000 ms.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hop through paths both short and long,
Ripgrep updated, the builds belong,
Fake platform set, retries bloom,
Tests wait patient — no more flaky gloom! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: improving Windows unit compatibility in the opencode package, which aligns with the substantive changes across multiple test and source files.
Description check ✅ Passed The pull request description comprehensively covers all required template sections: summary, rationale, related issue, verification steps with bash commands, and a completed checklist addressing platform considerations and commit conventions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-i141-windows-opencode

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

@Astro-Han Astro-Han force-pushed the codex/fix-i141-windows-opencode branch from 5fcd3cd to d35e026 Compare April 22, 2026 15:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread packages/opencode/src/npm/index.ts Outdated
Comment thread packages/opencode/src/file/ripgrep.ts Outdated
Comment thread packages/opencode/src/npm/index.ts Outdated
Comment thread packages/opencode/src/worktree/index.ts Outdated
Comment thread packages/opencode/test/plugin/workspace-adaptor.test.ts
Comment thread packages/opencode/src/file/ripgrep.ts
Comment thread packages/opencode/test/global/runtime-namespace.test.ts Outdated
Comment thread packages/opencode/test/effect/cross-spawn-spawner.test.ts

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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)

  1. ripgrep.ts: inconsistent executable suffix handling - The which() call now explicitly checks for rg.exe, but this should be verified against Bun's actual behavior on Windows.

  2. 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)

  1. worktree/index.ts: magic retry number - The 6x jump from 5 to 30 retries lacks justification.

  2. workspace-adaptor.test.ts: silent error masking - The catch handler returns "0" which could hide real issues.


P3 (Minor nitpicks)

  1. ripgrep.ts: version upgrade lacks changelog reference - Adding a comment would help future maintenance.

  2. runtime-namespace.test.ts: expectRoot incomplete - Only validates 4 of 6 fields.

  3. 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.

@Astro-Han Astro-Han force-pushed the codex/fix-i141-windows-opencode branch from d35e026 to 2e0fa17 Compare April 22, 2026 15:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a4e7b1 and 2e0fa17.

📒 Files selected for processing (7)
  • packages/opencode/src/file/ripgrep.ts
  • packages/opencode/src/npm/index.ts
  • packages/opencode/src/worktree/index.ts
  • packages/opencode/test/effect/cross-spawn-spawner.test.ts
  • packages/opencode/test/global/runtime-namespace.test.ts
  • packages/opencode/test/plugin/workspace-adaptor.test.ts
  • packages/opencode/test/session/prompt-effect.test.ts

Comment thread packages/opencode/test/global/runtime-namespace.test.ts Outdated
Comment thread packages/opencode/test/global/runtime-namespace.test.ts
@Astro-Han Astro-Han force-pushed the codex/fix-i141-windows-opencode branch from 2e0fa17 to fec7605 Compare April 22, 2026 15:30

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nitpick pass on the Windows stabilization PR. Nothing blocking — all P2/P3. Details inline.

  • P2: src/npm/index.ts mutates a Bun-global env var at module import time.
  • P2: waitForCounter silently returns last value on timeout; inconsistent with the waitFor helper right above it.
  • P3: test/fixture/fixture.ts still uses maxRetries: 5 for the same Windows-EBUSY reason.
  • P3: The ripgrep 14.1.1 → 15.1.0 bump is outside the stated scope of this PR.
  • P3: The 3_000 → 10_000 test timeout is applied to all platforms, not just Windows.

Comment thread packages/opencode/src/npm/index.ts Outdated
Comment thread packages/opencode/test/plugin/workspace-adaptor.test.ts
Comment thread packages/opencode/src/worktree/index.ts
Comment thread packages/opencode/src/file/ripgrep.ts
Comment thread packages/opencode/test/session/prompt-effect.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e0fa17 and fec7605.

📒 Files selected for processing (7)
  • packages/opencode/src/file/ripgrep.ts
  • packages/opencode/src/npm/index.ts
  • packages/opencode/src/worktree/index.ts
  • packages/opencode/test/effect/cross-spawn-spawner.test.ts
  • packages/opencode/test/global/runtime-namespace.test.ts
  • packages/opencode/test/plugin/workspace-adaptor.test.ts
  • packages/opencode/test/session/prompt-effect.test.ts

Comment thread packages/opencode/src/worktree/index.ts Outdated
Comment thread packages/opencode/test/plugin/workspace-adaptor.test.ts

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nitpick review for Windows stabilization PR. Issues graded P1-P3 per project convention.

Comment thread packages/opencode/src/npm/index.ts Outdated
Comment thread packages/opencode/test/plugin/workspace-adaptor.test.ts
Comment thread packages/opencode/src/worktree/index.ts
Comment thread packages/opencode/src/file/ripgrep.ts
Comment thread packages/opencode/src/file/ripgrep.ts
Comment thread packages/opencode/test/session/prompt-effect.test.ts

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Additional nitpick comments for PR #148.

Comment thread packages/opencode/src/file/ripgrep.ts
Comment thread packages/opencode/test/effect/cross-spawn-spawner.test.ts
Comment thread packages/opencode/test/global/runtime-namespace.test.ts Outdated
@Astro-Han Astro-Han force-pushed the codex/fix-i141-windows-opencode branch from fec7605 to a7d397b Compare April 22, 2026 15:58
@Astro-Han Astro-Han force-pushed the codex/fix-i141-windows-opencode branch from a7d397b to cf6d1cd Compare April 22, 2026 16:01
@Astro-Han Astro-Han merged commit 294f23c into dev Apr 22, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working P1 High priority upstream Tracked upstream or vendor behavior windows Windows-specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant