summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2026-02-12 12:10:21 -0500
committerDax Raad <[email protected]>2026-02-12 12:10:21 -0500
commit789705ea96ae28af7e30801fd6039ce89b6ac48e (patch)
tree9c5c5685f45b69785a7571f31ca4859a8ebf2666 /packages
parentba54cee55e18b47fb70badc84ae2cbac7c83d258 (diff)
downloadopencode-789705ea96ae28af7e30801fd6039ce89b6ac48e.tar.gz
opencode-789705ea96ae28af7e30801fd6039ce89b6ac48e.zip
ignore: document test fixtures for agents
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/test/AGENTS.md81
1 files changed, 81 insertions, 0 deletions
diff --git a/packages/opencode/test/AGENTS.md b/packages/opencode/test/AGENTS.md
new file mode 100644
index 000000000..209cf72da
--- /dev/null
+++ b/packages/opencode/test/AGENTS.md
@@ -0,0 +1,81 @@
+# Test Fixtures Guide
+
+## Temporary Directory Fixture
+
+The `tmpdir` function in `fixture/fixture.ts` creates temporary directories for tests with automatic cleanup.
+
+### Basic Usage
+
+```typescript
+import { tmpdir } from "./fixture/fixture"
+
+test("example", async () => {
+ await using tmp = await tmpdir()
+ // tmp.path is the temp directory path
+ // automatically cleaned up when test ends
+})
+```
+
+### Options
+
+- `git?: boolean` - Initialize a git repo with a root commit
+- `config?: Partial<Config.Info>` - Write an `opencode.json` config file
+- `init?: (dir: string) => Promise<T>` - Custom setup function, returns value accessible as `tmp.extra`
+- `dispose?: (dir: string) => Promise<T>` - Custom cleanup function
+
+### Examples
+
+**Git repository:**
+
+```typescript
+await using tmp = await tmpdir({ git: true })
+```
+
+**With config file:**
+
+```typescript
+await using tmp = await tmpdir({
+ config: { model: "test/model", username: "testuser" },
+})
+```
+
+**Custom initialization (returns extra data):**
+
+```typescript
+await using tmp = await tmpdir<string>({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "file.txt"), "content")
+ return "extra data"
+ },
+})
+// Access extra data via tmp.extra
+console.log(tmp.extra) // "extra data"
+```
+
+**With cleanup:**
+
+```typescript
+await using tmp = await tmpdir({
+ init: async (dir) => {
+ const specialDir = path.join(dir, "special")
+ await fs.mkdir(specialDir)
+ return specialDir
+ },
+ dispose: async (dir) => {
+ // Custom cleanup logic
+ await fs.rm(path.join(dir, "special"), { recursive: true })
+ },
+})
+```
+
+### Returned Object
+
+- `path: string` - Absolute path to the temp directory (realpath resolved)
+- `extra: T` - Value returned by the `init` function
+- `[Symbol.asyncDispose]` - Enables automatic cleanup via `await using`
+
+### Notes
+
+- Directories are created in the system temp folder with prefix `opencode-test-`
+- Use `await using` for automatic cleanup when the variable goes out of scope
+- Paths are sanitized to strip null bytes (defensive fix for CI environments)