用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/SocketDev/action --skill writing-fast-tests命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | writing-fast-tests |
| description | Writing or reviewing tests, or a slow suite: pick the cheapest seam, keep files parallel-safe. |
A slow suite is a suite people skip. The fleet budget is under a minute for
the unit tier, hard-capped at vitest.unitBudgetMs (180s default); past that
cover.mts warns every 180s and tells you to investigate rather than wait.
Order of preference, cheapest first: in-process call → shared fixture → parallel file → isolated run. Reach for the next one only when the previous one genuinely cannot express the behaviour.
This skill covers how to make a suite fast. What an assertion may say is a
separate contract — assert outcomes and exit codes rather than message prose,
never re-implement the logic under test, never scan source text. See
test-layout → "What to
assert". A fake for I/O is right; a fake for LOGIC defeats the test.
Import the module and call its exported function. Spawning the same code as a child process to assert the same logic is the single most expensive mistake in the fleet's suites.
Measured on no-tail-install-out-guard (socket-wheelhouse, 2026-07-30):
| Seam | Cost per call |
|---|---|
spawn(node, [hook]) + JSON on stdin | 136 ms |
import + findOffendingPipe(cmd) | 0.002 ms |
That is ~68,000×. One cover run captured 2454 spawned children; at 136 ms each that is ~334 s of process boot, roughly 78% of a 430 s unit run.
So: export the pure decision function and assert against it. A hook, a CLI, and a codemod all have one — if yours doesn't, that's the refactor.
// Fast: the matcher is a pure function of its input.
const r = await check(bashPayload('pnpm i | tail -5'))
assert.equal(r?.kind, 'block')
Spawning is right for what only a real process shows: exit codes, stdio framing, signal handling, env isolation, argv parsing. Prove the wiring once per file, then assert every remaining behaviour in-process.
// One spawn proves stdin→stderr→exit 2 is wired. The other 68 specs don't respawn.
test('subprocess: blocks with exit 2', async () => {
const { code, stderr } = await runHook(bashPayload('pnpm i | tail -5'))
assert.equal(code, 2)
assert.match(stderr, /Blocked/)
})
If a file has N spawns for N assertions, collapse it: keep one, convert the rest.
Build a fixture repo, parse a config, or compile an artifact once per file
at module scope or in beforeAll — not in beforeEach. A git init per test
is a spawn per test wearing a different hat.
Share read-only fixtures freely. Only deep-copy when a test mutates one, and prefer designing the test not to mutate.
vitest runs files in parallel workers. Most "flaky under parallel" is a test reaching for a shared global. Keep files independent:
mkdtempSync(path.join(os.tmpdir(), 'my-fixture-')) — never a
fixed path two files can both claim.:0 and read back the assigned port — never a constant.{ cwd } to the call; never process.chdir (banned fleet-wide —
it is process-global, so it corrupts every other worker in flight).process.env and hope.git ls-remote
resolves locally with no network, and import the isolate-git-env side-effect
first so inherited git vars can't leak onto the live .git/config.describe.sequential, a --no-file-parallelism file, or a dedicated tier is a
real cost — it serializes what the machine could overlap. Justify it with a
named shared resource (one git index, a singleton, a fixed socket), and write
that resource into a comment. "It felt flaky" is not a justification; find the
shared state instead.
Genuinely heavy suites — external spec suites, cross-impl parity, built-artifact
checks — do not belong in the unit tier at all. List their globs under
vitest.conformanceExclude in .config/repo/socket-wheelhouse.json and pair
them with a test:conformance runner.
no-unmocked-net-guard and no-unmocked-ai-guard block live calls, and a
network round trip dwarfs everything above. Mock at the boundary. Fake timers
beat await sleep(500) — a sleep is dead wall-clock in every future run.
for f in $(rg -l 'spawn\(' test/); do echo "$(rg -c 'spawn\(' $f) $f"; done | sort -rn | headThe unit tier finishes under a minute, no file spawns a child to assert behaviour an exported function already decides, every shared fixture is built once, and any sequential/isolated run names the resource that forced it.
building-tdd for the red-green loop this feeds, updating-coverage for coverage gaps, and test-layout for seam and placement doctrine.