Skip to content

fix: Windows tar for rg auto-install, GNU grep fallback fixes, portable tests - #23

Merged
dhaern merged 4 commits into
mainfrom
fix/windows-portability
Nov 7, 2026
Merged

dhaern merged 4 commits into
mainfrom
fix/windows-portability

Conversation

@dhaern

@dhaern dhaern commented Nov 7, 2026

Copy link
Copy Markdown
Owner

The suite was written and run on Linux. On Windows about 176 tests failed, and on Linux 12 depended on the readdir order of the temp filesystem. Almost all of them were test assumptions: GNU grep on PATH, POSIX shebang fakes, / in expected paths, file names NTFS cannot hold. Looking into them turned up three product bugs and a misleading README line.

Production changes

  • bettergrep and betterglob, utils/zip-extractor.ts: on Windows the rg auto-install now runs %SystemRoot%\System32\tar.exe for the probe and the extraction. It used to run tar from PATH. When OpenCode is started from Git Bash or MSYS2, Git's GNU tar comes first and fails on drive letters (tar: Cannot connect to C: resolve failed). betterglob could not install rg at all, and bettergrep fell back to an old GNU grep. If SystemRoot is not set, the existing Expand-Archive branch is used.
  • bettergrep, tools/grep/fallback.ts and fallback-content.ts: GNU grep older than 3.5 prints Binary file X matches on stdout, not stderr. The fallback now recognizes that line, does not count it as a match, marks the result as truncated and adds the same warning as the stderr case. Before, the result looked complete and had one match fewer than rg. json-stream.ts gains a peek() the parser needs for this.
  • bettergrep, tools/grep/path-utils.ts: resolveAbsolutePath also normalizes absolute paths, so on Windows the GNU grep fallback no longer returns mixed separators such as C:\repo\src/a.ts.
  • betterglob README and root README: under Bun on Linux and macOS, node on PATH is required in every session. The README said a validated rg on PATH could search without it, but the validation is kept in memory and runs again in each process.

Each of the three code fixes has one new test that fails on main.

Test changes

  • The GNU grep characterization snapshots with sort: mtime were sorted by readdir order, since the fallback ignores mtime. They are now sorted, so they pass on tmpfs, ext4 and NTFS.
  • Tests isolate LOCALAPPDATA as well as XDG_CACHE_HOME. On Windows they wrote into the real managed-rg cache and downloaded from the network.
  • Tests that run shebang fakes, check exec bits, use the POSIX-only process supervisor or create names NTFS cannot hold are skipped on Windows. Tests that need GNU grep are skipped when it is not on PATH. Six betterglob tests that were skipped on Windows without needing POSIX now run there.
  • Expected paths and snapshots use portable separators. Where the product emits / on purpose (permission patterns), the expectation no longer uses path.join.
  • The betterread UTF-8 byte-cap test no longer depends on the length of the temp directory path.
  • CONTRIBUTING.md lists what the tests need: Bun 1.4.4 or newer, node, rg, and GNU grep 3.5 or newer for the fallback tests.

Verification

Bun 1.4.4. check, typecheck and build are clean in the three packages on both systems.

bettergrep betterglob betterread
Windows 11, no GNU grep 232 pass, 86 skip 142 pass, 56 skip 171 pass, 10 skip
Windows 11, GNU grep 3.0 on PATH 285 pass, 33 skip
Linux x64 (Ubuntu 26.04, tmpfs), Node 24 316 pass, 2 skip 197 pass, 1 skip 181 pass

No test fails. The skips on Linux are the new Windows-only tests. bun test -u leaves the snapshots unchanged, and the real LOCALAPPDATA cache is not touched by the tests.

Version 1.2.3 for the three packages and the root.

Refs #21: the auto-install no longer depends on finding tar through PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant