RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/AGENTS.md/anomalyco/opencode

AGENTS.md

packages/opencode/test/AGENTS.md
AGENTS.md

Quality

81/100

Scores the file, not the repository.

Length

1,076 words

18 headings · 9 code blocks

Repository

193k

— · pushed 0 days ago

Last changed

3 days ago

First indexed 3 days ago.
anomalyco/opencode/packages/opencode/test/AGENTS.mdRawGitHub
1# Test Fixtures Guide
2 
3## Temporary Directory Fixture
4 
5The `tmpdir` function in `fixture/fixture.ts` creates temporary directories for tests with automatic cleanup.
6 
7### Basic Usage
8 
9```typescript
10import { tmpdir } from "./fixture/fixture"
11 
12test("example", async () => {
13 await using tmp = await tmpdir()
14 // tmp.path is the temp directory path
15 // automatically cleaned up when test ends
16})
17```
18 
19### Options
20 
21- `git?: boolean` - Initialize a git repo with a root commit
22- `config?: Partial<Config.Info>` - Write an `opencode.json` config file
23- `init?: (dir: string) => Promise<T>` - Custom setup function, returns value accessible as `tmp.extra`
24- `dispose?: (dir: string) => Promise<T>` - Custom cleanup function
25 
26### Examples
27 
28**Git repository:**
29 
30```typescript
31await using tmp = await tmpdir({ git: true })
32```
33 
34**With config file:**
35 
36```typescript
37await using tmp = await tmpdir({
38 config: { model: "test/model", username: "testuser" },
39})
40```
41 
42**Custom initialization (returns extra data):**
43 
44```typescript
45await using tmp = await tmpdir<string>({
46 init: async (dir) => {
47 await Bun.write(path.join(dir, "file.txt"), "content")
48 return "extra data"
49 },
50})
51// Access extra data via tmp.extra
52console.log(tmp.extra) // "extra data"
53```
54 
55**With cleanup:**
56 
57```typescript
58await using tmp = await tmpdir({
59 init: async (dir) => {
60 const specialDir = path.join(dir, "special")
61 await fs.mkdir(specialDir)
62 return specialDir
63 },
64 dispose: async (dir) => {
65 // Custom cleanup logic
66 await fs.rm(path.join(dir, "special"), { recursive: true })
67 },
68})
69```
70 
71### Returned Object
72 
73- `path: string` - Absolute path to the temp directory (realpath resolved)
74- `extra: T` - Value returned by the `init` function
75- `[Symbol.asyncDispose]` - Enables automatic cleanup via `await using`
76 
77### Notes
78 
79- Directories are created in the system temp folder with prefix `opencode-test-`
80- Use `await using` for automatic cleanup when the variable goes out of scope
81- Paths are sanitized to strip null bytes (defensive fix for CI environments)
82 
83## Testing With Effects
84 
85Use `testEffect(...)` from `test/lib/effect.ts` for tests that exercise Effect services or Effect-based workflows.
86 
87### Core Pattern
88 
89```typescript
90import { describe, expect } from "bun:test"
91import { Effect, Layer } from "effect"
92import { testEffect } from "../lib/effect"
93 
94const it = testEffect(Layer.mergeAll(MyService.defaultLayer))
95 
96describe("my service", () => {
97 it.instance("does the thing", () =>
98 Effect.gen(function* () {
99 const svc = yield* MyService.Service
100 const out = yield* svc.run()
101 expect(out).toEqual("ok")
102 }),
103 )
104})
105```
106 
107### `it.effect` vs `it.live`
108 
109- Use `it.effect(...)` when the test should run with `TestClock` and `TestConsole`.
110- Use `it.live(...)` when the test depends on real time, filesystem mtimes, child processes, git, locks, or other live OS behavior.
111- Use `it.instance(...)` for live Effect tests that need a scoped temporary directory and instance context.
112- Most integration-style tests in this package use `it.live(...)`.
113 
114### Effect Fixtures
115 
116Prefer the Effect-aware helpers from `fixture/fixture.ts` instead of building a manual runtime in each test.
117 
118- `tmpdirScoped(options?)` creates a scoped temp directory and cleans it up when the Effect scope closes.
119- `provideInstance(dir)(effect)` is the low-level helper. It does not create a directory; it runs an Effect with `InstanceRef` provided for `dir`.
120- `provideTmpdirInstance((dir) => effect, options?)` is the convenience helper. It creates a temp directory, binds it as the active instance, and disposes the instance on cleanup.
121- `provideTmpdirServer((input) => effect, options?)` does the same, but also provides the test LLM server.
122 
123Use `it.instance(...)` by default when a test only needs one temp instance. Yield `TestInstance` from `fixture/fixture.ts` when the test needs the temp directory path:
124 
125```typescript
126import { TestInstance } from "../fixture/fixture"
127 
128it.instance("uses the temp directory", () =>
129 Effect.gen(function* () {
130 const test = yield* TestInstance
131 expect(test.directory).toContain("opencode-test-")
132 }),
133)
134```
135 
136Use `provideTmpdirInstance(...)` or `tmpdirScoped()` plus `provideInstance(...)` when a test needs multiple directories, custom setup before binding, needs to switch instance context within one test, or explicitly tests instance disposal/reload lifetime.
137 
138### Style
139 
140- Define `const it = testEffect(...)` near the top of the file.
141- Keep the test body inside `Effect.gen(function* () { ... })`.
142- Yield services directly with `yield* MyService.Service` or `yield* MyTool`.
143- Avoid custom `ManagedRuntime`, `attach(...)`, or ad hoc `run(...)` wrappers when `testEffect(...)` already provides the runtime.
144- When a test needs instance-local state, prefer `it.instance(...)` over manual `Instance.provide(...)` inside Promise-style tests.
145 
146### Partial Service Stubs
147 
148When a test only needs to override one or two methods of a service, prefer `Layer.mock` over a hand-rolled `Layer.succeed(Service, Service.of({ ... }))`. `Layer.mock` lets you supply just the methods that matter — anything else throws an `UnimplementedError` defect if the test accidentally calls it, which is exactly the signal you want.
149 
150```typescript
151import { Effect, Layer } from "effect"
152import { Account } from "@/account/account"
153 
154const failingAccountLayer = Layer.mock(Account.Service, {
155 orgsByAccount: () => Effect.fail(new Account.AccountServiceError({ message: "simulated upstream failure" })),
156})
157```
158 
159This is much shorter than stubbing every method with `Effect.void` / `Effect.succeed(...)` placeholders, and it keeps the test focused on the behaviour under test.
160 
161## Synchronizing With Concurrent Work
162 
163### The Anti-Pattern
164 
165Using `Effect.sleep(N)` or `setTimeout` as a "wait for the forked fiber to be ready" hack races the scheduler. The forked fiber may not have reached the synchronization point within `N` ms on a slow CI host, and the test fails intermittently. See PR #27622 for a concrete flake that fell out of this exact pattern.
166 
167### The Fix
168 
169Wait on a **published readiness signal**, not wall-clock time. Available affordances:
170 
171- `pollWithTimeout(effect, message, duration?)` from `test/lib/effect.ts` — repeatedly run a predicate effect until it returns a non-`undefined` value, with a timeout.
172- `awaitWithTimeout(effect, message, duration?)` from `test/lib/effect.ts` — wrap any effect with `Effect.timeoutOrElse` and a custom error message.
173- `llm.wait(n)` from `test/lib/llm-server.ts` — wait until the mock LLM has received `n` HTTP calls.
174- `SessionStatus.Service` `.get(sessionID)` — observable per-session state (`{ type: "busy" | "idle" | ... }`).
175- `BackgroundJob.wait({ id, timeout })` from `src/background/job.ts` — wait for a background job to complete.
176- Bus subscriptions — fork `Stream.runForEach(bus.subscribe(Event), ...)` and open a `Latch` inside the callback to signal first-event readiness.
177- `Deferred.await(deferred).pipe(Effect.timeoutOrElse(...))` for one-shot signals.
178 
179### Example
180 
181```ts
182// Antipattern — race
183yield * prompt.shell({ command: "sleep 30" }).pipe(Effect.forkChild)
184yield * Effect.sleep(50)
185yield * prompt.cancel(chat.id)
186 
187// Fix — wait for a published readiness signal
188yield * prompt.shell({ command: "sleep 30" }).pipe(Effect.forkChild)
189yield *
190 pollWithTimeout(
191 Effect.gen(function* () {
192 const s = yield* (yield* SessionStatus.Service).get(chat.id)
193 return s.type === "busy" ? (true as const) : undefined
194 }),
195 "session never became busy",
196 )
197yield * prompt.cancel(chat.id)
198```
199 
200### When Fixed Sleeps Are OK
201 
202- Testing debounce or throttle behavior, where the sleep **is** the test.
203- Letting real wall-clock advance past a genuine timestamp resolution boundary (e.g. mtime granularity).
204- Simulating network latency in race-regression tests that intentionally exercise ordering.
205 

Commands it names

  • git?: boolean

Sections

  • Test Fixtures Guide
  • Temporary Directory Fixture
  • Basic Usage
  • Options
  • Examples
  • Returned Object
  • Notes
  • Testing With Effects
  • Core Pattern
  • `it.effect` vs `it.live`
  • Effect Fixtures
  • Style
  • Partial Service Stubs
  • Synchronizing With Concurrent Work
  • The Anti-Pattern
  • The Fix
  • Example
  • When Fixed Sleeps Are OK

What it covers

testcode-stylearchitecturetesting-strategydo-not

Stack — with the evidence

typescript

(1.00)

bun

(1.00)

turborepo

(1.00)

node

(0.70)

react

(0.70)

solid

(0.70)

drizzle

(0.70)

postgres

(0.70)

tailwind

(0.70)

vite

(0.70)

playwright

(0.70)

cloudflare

(0.70)

aws

(0.70)

javascript

(0.60)

monorepo

(0.60)

github-actions

(0.60)

Format

AGENTS.md

A plain-markdown README for coding agents, deliberately unopinionated: no frontmatter, no globs, no vendor keys. That minimalism is why it became the one file a dozen different agents will read, and why it carries the least per-file targeting power of any format here.

What the corpus says about it

Repository

Owner
anomalyco
Language
—
License
—
Archived
no

All configs in this repo

Also in anomalyco/opencode

Diff this repo’s formats

One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
anomalyco/opencodepackages/core/src/tool/AGENTS.md · 193kAGENTS.mdtypescriptbun+14stylesecurity58/1003 days ago
anomalyco/opencodepackages/opencode/test/server/AGENTS.md · 193kAGENTS.mdtypescriptbun+14teststyleapi38/1003 days ago
anomalyco/opencodepackages/schema/AGENTS.md · 193kAGENTS.mdtypescriptbun+14styletypesdatabaseapi+165/1003 days ago
anomalyco/opencodepackages/opencode/AGENTS.md · 193kAGENTS.mdtypescriptbun+15styledatabaseapido-not81/1003 days ago
anomalyco/opencodeAGENTS.md · 193kAGENTS.mdtypescriptbun+14testlint-formatstyletypes+380/1003 days ago
anomalyco/opencodepackages/app/AGENTS.md · 193kAGENTS.mdtypescriptbun+14style56/100today
anomalyco/opencodepackages/app/e2e/performance/AGENTS.md · 193kAGENTS.mdtypescriptbun+14no sections16/1003 days ago
anomalyco/opencodepackages/codemode/AGENTS.md · 193kAGENTS.mdtypescriptbun+14api43/1003 days ago
anomalyco/opencodepackages/desktop/AGENTS.md · 193kAGENTS.mdtypescriptbun+14no sections30/100today
anomalyco/opencodepackages/effect-drizzle-sqlite/AGENTS.md · 193kAGENTS.mdtypescriptbun+14database38/1003 days ago
anomalyco/opencodepackages/llm/AGENTS.md · 193kAGENTS.mdtypescriptbun+14stylearchtesting-strategygit+157/1003 days ago
anomalyco/opencodepackages/opencode/src/server/routes/instance/httpapi/AGENTS.md · 193kAGENTS.mdtypescriptbun+14styleapi40/1003 days ago
anomalyco/opencodepackages/opencode/src/session/llm/AGENTS.md · 193kAGENTS.mdtypescriptbun+14arch61/1003 days ago
anomalyco/opencodepackages/session-ui/AGENTS.md · 193kAGENTS.mdtypescriptbun+14no sections30/100today
anomalyco/opencodepackages/ui/AGENTS.md · 193kAGENTS.mdtypescriptbun+14no sections30/100today
Diff against packages/core/src/tool/AGENTS.md Diff against packages/opencode/test/server/AGENTS.md Diff against packages/schema/AGENTS.md Diff against packages/opencode/AGENTS.md Diff against AGENTS.md Diff against packages/app/AGENTS.md Diff against packages/app/e2e/performance/AGENTS.md Diff against packages/codemode/AGENTS.md Diff against packages/desktop/AGENTS.md Diff against packages/effect-drizzle-sqlite/AGENTS.md Diff against packages/llm/AGENTS.md Diff against packages/opencode/src/server/routes/instance/httpapi/AGENTS.md Diff against packages/opencode/src/session/llm/AGENTS.md Diff against packages/session-ui/AGENTS.md Diff against packages/ui/AGENTS.md

Similar configs

Same format, overlapping stack, ranked by quality.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
trick77/agents-md-syncAGENTS.md · 2AGENTS.mdtypescriptnode+4setupbuildteststyle+5100/1003 days ago
duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70AGENTS.mdtypescriptjavascript+5buildteststylearch+3100/1003 days ago
mui/material-uiAGENTS.md · 99kAGENTS.mdtypescriptjavascript+13setupbuildtestlint-format+9100/1003 days ago
n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199kAGENTS.mdtypescriptlangchain+16buildteststylearch+3100/1003 days ago
aaif-goose/gooseAGENTS.md · 52kAGENTS.mdrusttypescript+2setupbuildtestlint-format+6100/1003 days ago
TryGhost/Ghoste2e/AGENTS.md · 55kAGENTS.mdtypescriptjavascript+12setupteststylearch+2100/1003 days ago
code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67kAGENTS.mdtypescriptbun+10setupbuildtestlint-format+6100/1002 days ago
elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78kAGENTS.mdjavanode+4buildtestlint-formatstyle+2100/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack