Skip to content

fix(tests): green the Windows test suite across agent, loop, channels, tui and cli - #576

Merged
huichen merged 3 commits into
mainfrom
claude/win-test-fixes
Sep 12, 2026
Merged

huichen merged 3 commits into
mainfrom
claude/win-test-fixes

Conversation

@huichen

@huichen huichen commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Why

Running the test suites on Windows surfaced two different problems: platform assumptions baked
into tests, and real Windows-only bugs those tests were hiding. Both are fixed here — the
suites are green locally on all five workspace crates.

Before → after (Windows, --no-fail-fast):

crate before after
future-agent 31 lib + 2 cli_smoke 1710 lib + all integration targets pass
future-loop 10 lib + 6 integration 396 lib + all integration targets pass
future-channel 6 lib + one wedged test 362 lib + integration pass
future-tui 16 lib 809 lib + 13 integration pass
future-cli 16 lib + 2 bin 682 lib + 15 integration pass

cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean on Windows for those
crates; CI (Linux) is the backstop for the other platforms.

Production fixes (Windows behaviour, each one covered by a test)

  • Home resolution ignored a redirected home. dirs::home_dir() reads the token profile on
    Windows and observes neither $HOME nor USERPROFILE, so channels config, the loop console/leak
    scan, the TUI's logs and ~ handling, and the CLI's browser config all resolved to the real user
    profile. The affected tests were reading — and writing — the developer's actual ~/.future (a
    channels test loaded real credentials and started a bridge, which is where the suite wedged).
    Everything now resolves $HOME → USERPROFILE first, with the profile API as a last resort.
  • future-loop: dead holders were never reclaimed. pid_alive returned true unconditionally
    off unix, so a killed run's lease or the ACTIVE_GOAL_STATE.md.lock sidecar stayed "live"
    forever. Windows now probes via OpenProcess + GetExitCodeProcess; an inaccessible process
    still counts as alive, and a live lock holder is waited for briefly (it holds the lock for one
    projection write) instead of failing the command outright.
  • future-loop: a locked ledger read replayed as empty. Windows byte-range locks are mandatory,
    so reading events.jsonl while a concurrent append held it failed with
    ERROR_LOCK_VIOLATION — and the read path swallowed the error, reporting a registered agent as
    "not registered" and an existing todo as "unknown". The read now retries that window and surfaces
    anything else.
  • future-loop: workspace paths leaked the \\?\ extended-length prefix that canonicalize
    returns on Windows, into stored rules, ledger audits and user-facing conflict reports.
  • future-cli: a corrupt skill archive installed as if it were valid. PowerShell's
    Expand-Archive reports a bad zip as a non-terminating error (message on stdout) and still exits
    0, so unzip reported success and the caller blamed the package contents.
  • future-agent: the models-cache fallback used a hard-coded /tmp (not a real path on
    Windows) — it now uses the platform temp dir; and a saved ~/… rule is rendered with forward
    slashes so the rule round-trips through tilde expansion.

Test fixes

  • Paths, separators and temp-dir expectations are platform-spelled instead of POSIX literals.
  • The Windows shell contract is asserted as-is — a killed run returns [exit: signal] output rather
    than a timeout error, commands run through PowerShell, cmd.exe is the shell that must resolve.
  • future-cli: the embedded-agent failure test asked the agent to serve on port 1 and expected a
    bind failure. Port 1 is only privileged on POSIX, so on Windows the agent served happily, never
    exited, and its stray process then broke every other 127.0.0.1:1 "nothing is listening"
    fixture in the suite. It now binds a port first and hands that over. (I killed the leftover agents
    this had accumulated locally.)
  • future-cli: the tools call --stdin test isolated HOME and cleared the API-key env vars (a
    logged-in machine made it exit 0), and the saved-endpoint probe uses a bound-but-silent listener
    instead of the default 127.0.0.1:9222, which a developer's own Chrome with DevTools serves.
  • future-tui: the late-agent startup test drives readiness through the mock instead of relying
    on TCP refusal timing (a refused loopback connect takes ~2 s on Windows, longer than the fixtures'
    budgets), and the async UI assertions wait for the message rather than a fixed pump window.
  • Tests that exercise a platform we are not on are gated to it: symlink installs, #!/bin/sh fake
    binaries, broken-symlink and read-only-directory fixtures, pprof flamegraphs, and the Linux sandbox
    helper protocol (POSIX absolute paths / bwrap). TUI tests that need a console now skip instead of
    unwrapping when a redirected runner has none.

Notes for review

  • The Linux sandbox helper test modules became #[cfg(all(test, unix))]; they still run on Linux CI
    unchanged.
  • orchestration/loop gained a Windows-only windows-sys dependency (already used by agent and
    tui) for the process probe.
  • Two of the pre-existing flakes I did not touch: tui rpc::grpc_client::tests::subscribe_stream_event_bookkeeping
    (fixed sleeps) failed once in ~8 local runs.

…, tui and cli

Running the suites on Windows surfaced two kinds of problems: platform
assumptions baked into tests, and real Windows-only bugs the tests were
papering over. Both are fixed here.

Production fixes (Windows behaviour, verified by the tests):
- resolve home as HOME -> USERPROFILE instead of `dirs::home_dir()`, which
  reads the token profile on Windows and ignores a redirected home (channels
  config, loop console/leak scan, tui logs and `~` handling, cli browser
  config). The affected tests were reading and writing the developer's real
  `~/.future`.
- loop: `pid_alive` probes Windows (`OpenProcess` + exit code) instead of
  always reporting alive, so dead lease/lock holders are reclaimed; a live
  ACTIVE_GOAL_STATE.md holder is waited for briefly instead of failing the
  command; `read_ledger` retries the mandatory byte-range lock a concurrent
  appender holds instead of silently replaying an empty ledger; workspace
  paths are stored without the `\\?\` extended-length prefix.
- cli: `unzip` on Windows now fails for a corrupt archive (PowerShell reports
  it as a non-terminating error and still exits 0).
- agent: the models-cache fallback uses the platform temp dir, and a saved
  home-prefix rule is rendered as `~/...`.

Test fixes:
- platform-spelled paths and separators instead of hard-coded POSIX fixtures.
- the Windows shell contract is asserted as-is (a killed run reports
  `[exit: signal]`, commands run through PowerShell) instead of Unix
  expectations.
- loop: the late-agent startup test drives readiness through the mock rather
  than relying on TCP refusal timing; async/UI assertions wait for the
  message instead of a fixed pump window.
- cli: the embedded-agent failure test binds the port it asks the agent to
  serve on (port 1 is only privileged on POSIX, so Windows served there and
  left a stray agent that then broke every `127.0.0.1:1` fixture); the
  tools-stdin test isolates HOME and clears the key env vars; endpoint
  probing uses a bound-but-silent listener instead of the default 9222 port a
  developer's Chrome may own.
- Unix-only tests (symlink installs, `#!/bin/sh` fakes, broken-symlink and
  read-only-dir fixtures, pprof flamegraphs, and the Linux sandbox helper
  protocol) are gated to the platforms they exercise; the tui tests that need
  a console skip when one is unavailable.
The home-prefix shortening renders `\` as `/` so a saved rule or an
agent-list row reads the same on every host. Limit the rewrite to Windows:
on POSIX a backslash is an ordinary filename character, so replacing it
would misreport a path that genuinely contains one.
@huichen
huichen enabled auto-merge (squash) September 12, 2026 14:46
@huichen
huichen merged commit 9e4464c into main Sep 12, 2026
12 checks passed
@huichen
huichen deleted the claude/win-test-fixes branch September 12, 2026 14:51
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