Skip to content

fix(desktop): make the backend test suite pass on Windows - #596

Merged
huichen merged 5 commits into
mainfrom
claude/windows-test-fixes
Sep 13, 2026
Merged

huichen merged 5 commits into
mainfrom
claude/windows-test-fixes

Conversation

@huichen

@huichen huichen commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

Running cargo test under desktop/src-tauri on Windows failed 26 tests, 100% reproducibly. Every one was a latent platform assumption rather than an environment quirk — and two were real product bugs that only the Windows path exposes.

A separate, intermittent failure (≈1 run in 6, a different test each time: DatabaseBusy: database is locked / StorageFull) turned out to be the disk being full: the fake-HOME test guards leak their temp directories (~19k dirs / 32.7 GB accumulated, leaving C: with 10 MB free). A full disk cannot write SQLite's WAL, which surfaces as those two errors.

Fixes

Product bugs

  • reconcile_thread_workspace compared a forward-slash cwd against an un-normalized home, so a chat cwd on Windows missed the chat branch and was routed to the project-workspace path, which requires the directory to already exist. Normalize the home separators, as is_desktop_chat_cwd already does.
  • best_effort_canonical returned the Windows extended-length spelling (\\?\D:\...) straight to the webview and the OS opener. Strip it, and normalize both sides of the credential denylist — otherwise the mismatch would silently stop blocking auth.json.

Test fixes

  • set_modified on a read-only handle raises ACCESS_DENIED on Windows (it needs FILE_WRITE_ATTRIBUTES). Open for writing instead — this alone accounted for 20 failures.
  • sh -c does not exist on Windows; build the non-zero-exit fixture with cmd /C.
  • Two tests hard-coded /Users/fake-home as HOME, which home_dir_from rejects as non-absolute on Windows and silently falls back to the real profile.
  • Presence awaits matched on the subject only, but the heartbeat, the disconnect notice and the unpair notice all publish to p.<pair>.presence, so the assertion could consume the wrong message. Match on the payload (await_publish_matching). Note: origin/main fixed one of these independently with an inline loop; this branch keeps the shared helper it already uses at three other sites.
  • Three tests asserted a task had finished after a fixed sleep. Replace with a bounded poll (wait_until), since an aborted NATS read surfaces much later on Windows.

Test-infrastructure leak

  • Both fake-HOME guards delete their directory on drop, but on Windows that delete failed silently: the connection pool still held an open handle to the home's SQLite database, and Windows refuses to unlink an open file. Add a test-only store::close_pool() and call it before removing the directory. The regression test leaves a pooled connection open across the drop and fails without the fix.

Result

cargo test under desktop/src-tauri: 1164 passed, 0 failed, green on 7 consecutive full-suite runs (the intermittent DatabaseBusy/StorageFull failures are gone). cargo fmt --check and cargo clippy --all-targets -- -D warnings clean.

Known remaining issue (not fixed here)

The guards still leak ~120 temp homes per run when a background task holds a checked-out connection past the guard's drop, so the directory is briefly undeletable. close_pool only releases pooled connections, not ones still in use. Reclaiming is safe when no run is active: rmdir /s /q %TEMP%\futureos*. Worth a follow-up that stops observers/heartbeats before the guard drops.

Running the desktop backend suite on Windows failed 26 tests. Each was a latent platform assumption rather than an environment quirk, and two were real product bugs the tests only caught on Windows:

- \set_modified\ on a read-only handle raises ACCESS_DENIED on Windows (FILE_WRITE_ATTRIBUTES); open for writing instead. This accounted for 20 failures across git_review and shadow_review.

- \
econcile_thread_workspace\ compared a forward-slash cwd against an un-normalized home, so a chat cwd on Windows missed the chat branch and was routed to the project-workspace path (which requires the directory to exist). Normalize the home separators, as \is_desktop_chat_cwd\ already does.

- \�est_effort_canonical\ returned the Windows extended-length spelling (\\\\\?\\D:\\...\) straight to the webview and the OS opener. Strip it, and normalize both sides of the credential denylist so the guard keeps blocking them.

- \sh -c\ does not exist on Windows; use \cmd /C\ for the non-zero-exit fixture.

- Two tests hard-coded \/Users/fake-home\ as HOME, which \home_dir_from\ rejects as non-absolute on Windows, silently falling back to the real profile.

- Presence awaits matched on the subject only, but the heartbeat, disconnect notice and unpair notice all publish to \p.<pair>.presence\, so the assertion could consume the wrong message. Match on the payload; add \�wait_publish_matching\.

- Three tests asserted a task had finished after a fixed sleep. Replace with a bounded poll (\wait_until\), since an aborted read surfaces much later on Windows.
Both fake-HOME guards delete their directory on drop, but on Windows the delete failed silently: the connection pool still held an open handle to that home's SQLite database, and Windows refuses to unlink an open file. Every run leaked its test homes - 18,963 directories / 32.7 GB had accumulated here, leaving C: with 10 MB free, which is what made unrelated tests fail intermittently with SQLite \DatabaseBusy\ (a full disk cannot write WAL) and \StorageFull\.

Add a test-only \store::close_pool()\ and call it from both guards before removing the directory, so the handles are released first. The accompanying regression test leaves a pooled connection open across the drop and fails without the fix.

Residual: some homes are still leaked (~120 per run) where a background task holds a checked-out connection past the guard, so the directory is briefly undeletable. Reclaiming is safe (\
mdir /s /q %TEMP%\\futureos*\).
…ixes

# Conflicts:
#	desktop/src-tauri/src/remote/mod.rs
@huichen
huichen enabled auto-merge (squash) September 13, 2026 10:55
@huichen
huichen merged commit 824e024 into main Sep 13, 2026
12 checks passed
@huichen
huichen deleted the claude/windows-test-fixes branch September 13, 2026 11:03
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