← 返回列表
全部 Skill›测试与安全 Testing & Security›unit-tests

unit-tests

作者 @anomalyco · 语言 en
Use when writing, reviewing, speeding up, or fixing a flaky `bun test` unit test in any package (core, cli, server, ai, codemode, util, client, sdk, plugin, http-recorder, merman, app src and test-browser, desktop, gui-plugins, ui, session-ui, latex, ...), except OpenTUI renderer tests (see tui-tests). Also use when a test "timed out after 5000ms" on Windows CI, fails only on Windows, when the unit job is slow, when adding cli subprocess or service tests, or when adding a package's test task to turbo.json. Covers controlling time instead of sleeping, per-test timeouts, process and git spawn cost on Windows, Windows-only failures, temp dirs and process state, leaks between files, and reading CI timeouts.
测试与安全 Testing & Security测试通用执行命令敏感路径待翻译
最近源活动
2026-11-21 22:10
检测 SKILL.md 语言
en
星标 ★
228,069
分支 Fork
31,017
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Fast, Reliable Unit Tests

CI runs bun turbo test --affected --concurrency=3 on 4-vCPU Linux and Windows runners (unit job in .github/workflows/check-test.yml), so each suite shares the CPU with two others, and Windows is the slower leg. Most slow or flaky unit tests here wait on real time, spawn too many processes, or assert wall-clock speed.

Read these first; this skill does not repeat them:

  • Root AGENTS.md: the Testing and Style Guide sections.
  • packages/app/AGENTS.md Tests (packages/desktop and packages/gui-plugins follow it): one owner per contract, and no production seams for tests.
  • packages/ai/AGENTS.md: cassettes. The effect skill: it.effect and it.live.

Sibling skills: tui-tests (OpenTUI renderer tests in tui and cli), app-e2e-tests (Playwright in packages/app/e2e), component-tests (Playwright on stories, packages/stories). This skill owns cli subprocess and service tests.

Know the budget

  • Bun's default per-test timeout is 5000ms. Check the package's test script:
  • 30s: ai, cli, desktop, http-recorder, latex, merman, simulation, theme and tui pass --timeout 30000; core's script/test.ts passes --timeout=30000.
  • 5s: client, httpapi-codegen and sdk pass --timeout 5000; app, codemode, function, gui-plugins, plugin, plugin-browser, script, server, session-ui, ui and util use the default.
  • Size Windows risk by counting spawns, not by local wall time.
  • npm.test.ts "installs a Git package from an npm ::path: subdirectory at a branch" takes 0.4s locally and hit 5000ms on Windows CI. Each Npm.add Git case makes about 75 git process events: 3 clone --recurse-submodules, which run the git-submodule shell script.
  • Assume roughly 40ms per Git-for-Windows spawn (estimated from an earlier git.test run on Windows CI: ~24s for 564 spawns). Some core file groups run 5-9x slower on Windows than locally.
  • Those test.each cases (npm.test.ts:223, :251) hit 5000ms in 13 of 45 Windows core runs; that is why core's runner now defaults to 30s (comment at packages/core/script/test.ts:38).
  • A timeout loosens the budget only when it exceeds the package default.
  • In a 5s package, work that legitimately needs longer gets a per-test timeout and a comment naming the work: packages/server/test/fetch.test.ts:406-407 ("Real retries wait 18 \* 200 ms ...", { timeout: 10_000 }). test.each(table)(name, fn, 30_000) takes it as the third argument. Use file-wide setDefaultTimeout only when every test in the file does such work.
  • In core, the four file-level setDefaultTimeout(30_000) calls only restate the runner default, and a per-test { timeout: 15_000 } (still in tool-shell.test.ts, session-generate.test.ts and others) is stricter than it. Do not add values at or below 30s there.
  • Never absorb a sleep, poll or production interval with a larger timeout, --retry, or skipIf(win32); remove the wait. Skip on Windows only when the platform lacks the capability, with a comment (npm.test.ts:313, symlinks).

Control time; do not wait for it

  • Effect code. it.effect from packages/core/test/lib/effect.ts runs on TestClock; testEffect(layer) adds your layer. server and cli import it from ../../core/test/lib/effect; ai has packages/ai/test/lib/effect.ts.
  • Fork, then adjust. Fork with Effect.forkChild({ startImmediately: true }) (packages/ai/test/http-timeout.test.ts:58), or await a Deferred the code completes and then Effect.yieldNow (:80-81). Otherwise TestClock.adjust can run before the sleep is registered, and the join hangs until Bun's timeout.
  • Debounced streams and watchers. advance(condition) and drain in packages/core/test/lib/clock.ts alternate one real 1ms macrotask with 500ms adjusts, because debounces register sleeps across fiber hops. Use drain (4 such steps) before a "nothing happened" assertion instead of Bun.sleep(25). advance is bounded by 15s of real time, not a step count, because its condition can also wait on slow real work (a plugin import, a child, a large write) that took more than 100 steps on a loaded Linux runner (supervisor-reload.test.ts "retains a discovered plugin change during initial activation").
  • Real I/O between virtual steps. TestClock.withLive(Effect.sleep("10 millis")). registered() at packages/cli/test/service.test.ts:740 tests the 5s registration watch with real file I/O under it.effect. This departs from the effect skill's "filesystem → it.live" on purpose: the timer is the contract.
  • Real events need it.live. Under it.effect the clock moves only when the test adjusts it, so an Effect timeout on a path driven by real processes, sockets or file events never fires and a missing event hangs instead of failing. The AppProcess tests (packages/core/test/process/process.test.ts:13-14) use it.live because the spawner's 1-second post-exit capture deadline (packages/util/src/cross-spawn-spawner.ts:322) never fired under TestClock.
  • Give a racing component its own clock. When a real-time deadline races slow setup, provide that component a Clock that only the test moves past the deadline. packages/core/test/browser-idle.test.ts:24-38 wraps the live clock for `Locati
评论
Aanomalyco
anomalyco
anomalyco/opencode
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@anomalyco
所属大类测试与安全 Testing & Security / 测试
国内可用性通用
最近源活动2026-11-21 22:10
风险提示执行命令、敏感路径
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。