test(opencode): deflake file and tool timing#17859
Merged
Hona merged 3 commits intoanomalyco:devfrom Mar 17, 2026
Merged
Conversation
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.
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.
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why These Tests Started Flaking
2cbdf04ecmadeFileTime.read/get/assert/withLockasync and instance-runtime backed, but the affected tests still treatedFileTime.read(...)like a fire-and-forget synchronous boundary.69381f6aeleftFile.init()as a background warmup, while the search tests were trying to use it as a readiness signal and then sleeping for 500ms.What This PR Changes
File.init()wait for the initial scan so callers and tests can use it as a real readiness boundaryFileTime.read(...)in the affected tests so they stop racing the async service boundaryTesting
bun typecheckbun test ./test/file/index.test.ts ./test/file/time.test.tsbun test ./test/tool/edit.test.ts ./test/tool/write.test.tsbun 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.tsFile.read()andEditToolcreation three times each