You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ec84c10
Browse filesBrowse the repository at this point in the historyBrowse files
enhance(test): stabilize the unit suite and gate commits [anomalyco#245]
Test layering
- isolate integration dirs with trailing slashes and drop the stale snapshot dir
- move live-I/O tests out of the unit layer via the *-integration.test.ts convention
- include the runner's own script tests in the unit layer
Assertions and fixtures
- derive version and protocol assertions from their single sources
- pin fixture git commands to their temp repo and clear locator vars per test process
Commit gate
- run the opencode unit layer from .husky/pre-commit for staged .ts/.tsx
Specs
- sync the EN and zh test specs with the new layering, scopes and baseline
@@ -65,6 +68,8 @@ Wopal capabilities enter the engine through two module groups in `packages/openc
65
68
66
69
Tests cannot run from repo root. Run `./scripts/dev.sh help` and `./scripts/build.sh help` for full parameter documentation.
67
70
71
+
opencode tests run through the layered entries above (`test:unit` for the daily loop, `test:integration` when a change touches an integration directory or a `*-integration.test.ts` file, `test:e2e` for `*-e2e.test.ts` files, `test:all` for full regression). Commits are gated: when the staged change contains `.ts`/`.tsx` files, `.husky/pre-commit` runs the opencode package unit layer (`bun run --cwd packages/opencode test:unit`) and rejects the commit on failure, adding roughly twenty seconds to the commit. Documentation-only commits skip the gate.
Copy file name to clipboardExpand all lines: packages/opencode/AGENTS.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,10 @@ This is ellamaka's main engine package. It carries the OpenCode inherited runtim
40
40
|---|---|---|
41
41
| Dev |`bun run dev`| Local package dev entry |
42
42
| Typecheck |`bun typecheck`| After TypeScript changes; never run `tsc` directly |
43
-
| Test (default subset) |`bun run test:unit`| After behavior changes (fast unit subset, ~60s) |
43
+
| Test (default subset) |`bun run test:unit`| After behavior changes (fast unit subset, ~25s) |
44
44
| Test (heavy integration) |`bun run test:integration`| After behavior changes in integration-dir code (dir list in Testing below; `INTEGRATION_DIRS` is the source of truth) |
45
45
| Test (e2e) |`bun run test:e2e`| After changes to real provider-chain / browser e2e tests |
46
-
| Test (full regression) |`bun run test:all`| Full regression (equivalent to `bun test --timeout 30000 --force-exit`) |
46
+
| Test (full regression) |`bun run test:all`| Full regression (equivalent to `bun test --timeout 30000 --force-exit --max-concurrency=4`) |
47
47
| Build |`bun run build`| After runtime, CLI, or package build changes |
48
48
| Database migration |`bun run db generate --name <slug>`| After schema changes |
49
49
@@ -82,11 +82,11 @@ All commands run from `packages/opencode`.
82
82
83
83
## Testing
84
84
85
-
- Test subsets are expanded by `script/run-tests.ts` on a layer basis. `package.json` exposes four entries: `test:unit` (default dev subset — scans all `test/` subdirectories plus top-level `*.test.ts`, excluding the integration dirs and any `*-e2e.test.ts`), `test:integration` (only the integration directories: server/session/cli/snapshot/project/tool/control-plane/plugin/file/pty/skill/reference/share/mcp/lsp/publish-smoke), `test:e2e` (only `*-e2e.test.ts` files, recursively), and `test:all` (full regression). Use `test:unit` for daily development; when touching integration-dir code, run at least `test:integration`; run `test:all` before commit/merge.
85
+
- Test subsets are expanded by `script/run-tests.ts` on a layer basis. `package.json` exposes four entries: `test:unit` (default dev subset — scans all `test/` subdirectories, top-level `*.test.ts`, and the runner's own `script/*.test.ts`, excluding the integration dirs and any file named `*-e2e.test.ts` or `*-integration.test.ts`), `test:integration` (the integration directories plus every `*-integration.test.ts` under `test/` and `script/`: server/session/cli/project/tool/control-plane/plugin/file/pty/skill/reference/share/mcp/lsp/publish-smoke), `test:e2e` (only `*-e2e.test.ts` files under `test/` and `script/`, recursively), and `test:all` (full regression). The unit layer is the fast daily loop: it currently covers roughly 94 files / 1434 tests in the low twenties of seconds. Use `test:unit` for daily development; when touching integration-dir code or a `*-integration.test.ts` file, run at least `test:integration`; run `test:all` before commit/merge.
86
86
- e2e files follow the `*-e2e.test.ts` naming convention and are isolated from `test:unit`/`test:integration` via `pathIgnorePatterns` (CLI value overrides bunfig, not merged). They run only under `test:e2e`. Do not move e2e files out of their domain directories.
87
87
- New test directories are auto-included in `test:unit` (scan-based). If a directory is integration (real I/O), add its name to the `INTEGRATION_DIRS` constant in `script/run-tests.ts` and keep this file's integration-dir list in sync.
88
-
-**The unit layer must stay fast and deterministic.** A unit test must not fork subprocesses (`Process.run`/`spawn`), watch the filesystem, run git, hit the network, or rely on real clocks/`it.live`. Tests that need live OS behavior belong in an integration directory — put the file in the matching `INTEGRATION_DIRS` directory (or add the directory to that constant) so it runs under `test:integration`, not on every unit pass. The one exception: a test that merely needs a temp directory (`tmpdir`/`it.instance`) is still a unit test.
89
-
- Cross-package orchestration: from repo root, `bun run test:unit|test:integration|test:e2e` runs the matching layer across all packages via `script/run-tests.ts` (root). Use `--package <name>` to target a single package (e.g. `bun run test:unit --package opencode`).
88
+
-**The unit layer must stay fast and deterministic.** A unit test must not fork subprocesses (`Process.run`/`spawn`), watch the filesystem, run git against a real repository, hit the network, or rely on real clocks/`it.live`. Tests that need live OS behavior belong in the integration layer — put the file in the matching `INTEGRATION_DIRS` directory (or add the directory to that constant), or, when moving the file is not practical, name it `*-integration.test.ts`: the unit layer excludes that suffix and `test:integration` includes it explicitly, so it runs on demand rather than on every unit pass. The one exception: a test that merely needs a temp directory (`tmpdir`/`it.instance`) is still a unit test — including the fixture's own throwaway repo (`tmpdir({ git: true })`), whose git commands are pinned to the temp directory.
89
+
- Cross-package orchestration: from repo root, `bun run test:unit|test:integration|test:e2e` runs the matching layer across all packages via the root entry `packages/opencode/script/run-tests-root.ts`. Use `--package <name>` to target a single package (e.g. `bun run test:unit --package opencode`).
90
90
- Use the built-in tooling for test speedup work: `bun run bench:test` (full-suite benchmark) and `bun run profile:test` (locate slowest test files; narrow with `TEST_PROFILE_GLOB`/`TEST_PROFILE_LIMIT`). A speedup counts only if the target file's median across 3 repeated runs improves — a single full-suite run is noisy and can inflate a file's cost severalfold from mixed-scope contention, so never conclude from it alone.
91
91
- Code changes follow TDD: write a failing test first, then implement to make it pass.
92
92
- Run tests from `packages/opencode`; never from repo root.
- 测试提速用现成工具:`bun run bench:test`(全量基准)与 `bun run profile:test`(定位最慢测试文件,`TEST_PROFILE_GLOB`/`TEST_PROFILE_LIMIT` 收窄范围)。判定提速成立以目标文件 3 次重跑的中位数为准——单次全量运行噪声大,混跑时单文件耗时可被放大数倍,不得据此下结论。
0 commit comments