Skip to content

test(opencode): deflake file and tool timing#17859

Merged
Hona merged 3 commits intoanomalyco:devfrom
Hona:fix/effect-scoped-file-tests
Mar 17, 2026
Merged

test(opencode): deflake file and tool timing#17859
Hona merged 3 commits intoanomalyco:devfrom
Hona:fix/effect-scoped-file-tests

Conversation

@Hona
Copy link
Member

@Hona Hona commented Mar 17, 2026

Why These Tests Started Flaking

  • 2cbdf04ec made FileTime.read/get/assert/withLock async and instance-runtime backed, but the affected tests still treated FileTime.read(...) like a fire-and-forget synchronous boundary.
  • 69381f6ae left File.init() as a background warmup, while the search tests were trying to use it as a readiness signal and then sleeping for 500ms.
  • The file and tool tests also boot the full existing instance runtime, which pulls in provider auth and default plugin loading. In practice that unrelated bootstrap was consuming most of the 5s test budget before the file/edit assertions even ran.

What This PR Changes

  • keep the production Effect/runtime architecture as-is
  • make File.init() wait for the initial scan so callers and tests can use it as a real readiness boundary
  • await FileTime.read(...) in the affected tests so they stop racing the async service boundary
  • replace timestamp and lock-order sleeps with explicit fs mtimes and manual gates
  • disable default plugins in test preload so unrelated provider/plugin bootstrap does not make file and tool tests time out

Testing

  • bun typecheck
  • bun test ./test/file/index.test.ts ./test/file/time.test.ts
  • bun test ./test/tool/edit.test.ts ./test/tool/write.test.ts
  • bun test ./test/tool/bash.test.ts ./test/plugin/auth-override.test.ts ./test/pty/pty-output-isolation.test.ts ./test/pty/pty-session.test.ts ./test/session/prompt.test.ts ./test/session/llm.test.ts
  • repeated the previously flaky single tests for File.read() and EditTool creation three times each

Hona added 2 commits March 17, 2026 10:00
Run File, FileTime, and Format through scoped instance runtimes so edit and file paths no longer initialize unrelated services. Update the affected tests to await async boundaries and drive file timestamps and lock ordering deterministically instead of relying on wall clock sleeps.
Drop the scoped runtime experiment and keep the production Effect path unchanged. Stabilize the affected tests by awaiting FileTime reads, removing wall-clock timestamp races, and mocking plugin loading in the file/edit/write tests so unrelated provider bootstrap does not consume the 5s test budget.
@Hona Hona changed the title fix(opencode): isolate file runtimes from instance bootstrap test(opencode): deflake file and tool timing Mar 17, 2026
Default plugin loading was consuming much of the 5s budget in file and tool tests, and local module mocks leaked into unrelated suites. Disable default plugins in test preload so the existing runtime stays intact, then keep the deterministic await and filesystem timestamp cleanup in the affected tests.
@Hona Hona marked this pull request as ready for review March 17, 2026 00:44
Copilot AI review requested due to automatic review settings March 17, 2026 00:44
@Hona Hona enabled auto-merge (squash) March 17, 2026 00:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR deflakes opencode’s file- and tool-related tests by turning previously timing-dependent assumptions into explicit async boundaries and deterministic filesystem timestamp manipulation, while also reducing unrelated bootstrap work during tests.

Changes:

  • Await FileTime.read(...) in affected tool tests to avoid racing the async FileTime service boundary.
  • Make File.init() a real readiness boundary by waiting for the initial scan (so search tests no longer rely on arbitrary sleeps).
  • Reduce test runtime variance by disabling default plugins in the test preload and replacing sleep-based timing with explicit mtimes and manual gates.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/opencode/test/tool/write.test.ts Awaits FileTime.read so write tool tests don’t race async FileTime initialization.
packages/opencode/test/tool/edit.test.ts Awaits FileTime.read and replaces sleep-based timestamp changes with explicit fs.utimes touches.
packages/opencode/test/preload.ts Disables default plugins during tests to avoid unrelated bootstrap consuming the test time budget.
packages/opencode/test/file/time.test.ts Replaces sleep-based flake-prone timing with explicit utimes and deterministic concurrency gates for lock tests.
packages/opencode/test/file/index.test.ts Awaits File.init() instead of sleeping, using it as a proper readiness boundary.
packages/opencode/src/file/index.ts Updates FileService.init to await the initial scan (kick()) so File.init() can be awaited as a readiness boundary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona Hona merged commit cb69501 into anomalyco:dev Mar 17, 2026
14 checks passed
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.

2 participants