write-tests
Use when adding or changing behavior, signing code, contracts, or the UI. Chooses the right test level and applies the repository's test rules.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- write-tests
- description
- Use when adding or changing behavior, signing code, contracts, or the UI. Chooses the right test level and applies the repository's test rules.
03 SKILL.md 正文
write-tests
Prerequisites
- .ai/memories/testing.md (orientation) and the
testing section of the kit's spec (the rules:
specs/client-kit/testing-and-ci.mdand the Wrapper test plan).
Workflow
- Pick the level:
- pure logic, a use case, a parser, a validator → unit (Vitest, beside the code);
- a wire or crypto format → vector replay: run the vendored vector files through the code; add a vector rather than a one-off assertion;
- rendering of a Snapshot, accessibility of a component → component (Vitest with a DOM);
- a user path through the built Wrapper (win, loss, cash-out, offline, errors, two tabs, the sandbox) → e2e (Playwright, against the in-repo fake Play API);
- a contract copy → the hash check against the lock file.
- Unit tests: no real network, disk, timers, or clock; inject a clock and a random source; table-driven where it helps; one behavior per test.
- Assert on typed errors (their
codeor class), never on message text. - Money: assert on strings or
bigint, never onnumber. - Secrets: a test never prints or snapshots a key or token. The only keys in the repository are the public test keys of the vectors. Add a test that the thing you touched does not leak a credential into logs, errors, or storage when it handles one.
- e2e: unique ids per run; no dependence on test order; no real wallet or third-party service.
- Run the whole suite before pushing.
Constraints
- Deterministic and hermetic; no secrets; no test imports another package's
internals. The preview-stack e2e (the
previewproject, run by a backend-owned job, never part ofpnpm check) is the one non-hermetic suite; add to it only through the rows of the Wrapper's test plan, and prove its support code with hermetic tests ine2e/tests/preview-guard/. - Never weaken a vector assertion or skip a test to go green — fix the code, or change the spec through the development flow. A released vector file is never edited; add a new version.
Useful commands
pnpm test # unit and component (wireit skips what did not change)
pnpm test:e2e # Playwright against the fake Play API
pnpm check # everything the CI runs
A test that reads files outside its own package (a vector, the schema) must
have those files in its wireit files, or depend on the task that produces
them; otherwise a cached pass could hide a failure. tools/wireit-inputs.test.ts
checks the files of every script against the files on disk; it runs in
test:tools, whose files cover every workspace tree so that a new file
re-runs it. A root tools/ test that reads a file outside them adds that file
to test:tools files.
Expected output
Tests at the right level that fail without the change and pass with it.
References
04 同仓库更多 Skills
<skill-name>
Use when <situation>. One or two sentences.
spec-drift-sync
Use before merging any non-trivial change. Reconciles code with specs, and code/specs with memories, runbooks, and telemetry docs (Spec Drift Synchronization).
shepherd-a-pull-request
Use when reviewing a pull request on GitHub, following up on a review after new pushes, or answering review comments on your own pull request. The `gh` procedure behind the pr-shepherd agent, with draft-then-confirm posting.
prd-to-spec
Use when given a rough PRD, feature request, or raw requirement. Turns it into a spec update, an RFC when the change is significant or contested, and an ADR for hard-to-reverse decisions.
ask-the-human
Use when you hit an open question, a decision that is not yours to make, a gap or ambiguity in a spec, or a draft that needs a human's confirmation. Asks through the host's structured-question tool with concrete options and a recommendation, instead of guessing or burying the question in prose.
add-a-package
Use when adding a new package under packages/ (or an app under apps/). Covers the placement check, the dependency direction, public API, wiring, tests, and docs.