Author tests that actually catch regressions — picks WHAT to test by risk (branch points, boundaries, error paths, money/auth/concurrency), proves every new test can fail (a test never seen red is decoration), mocks only boundaries you don't own, and pins untested legacy code with labeled characterization tests before anything else touches it. Use this skill whenever the user says "write tests", "add tests", "test this", "add coverage", "unit test this function", "increase coverage", "add a regression test", "characterization tests", "TDD this", or "/write-tests" — even if they don't explicitly say "test skill". Do not use for diagnosing a failing test (use diagnose) or reviewing existing tests as part of a diff (use code-review).
编程
Write Better Tests
试用Use when Codex is adding, editing, selecting, reviewing, or explaining tests in any repository, including mocks, fixtures, snapshots, CI validation, regressi...
它能做什么
Use when Codex is adding, editing, selecting, reviewing, or explaining tests in any repository, including mocks, fixtures, snapshots, CI validation, regressi...
技能文档
Write Better Tests
Use this skill whenever test quality matters. The goal is not "more tests"; the goal is tests a skeptical maintainer would trust.
Core Rule
Before saying coverage is good, prove the test would fail for the old or broken behavior when practical. A passing test without a credible failure mode is weak evidence.
Accept a test only if it satisfies all three:
- It asserts the user-visible, API-visible, CLI-visible, data-contract, security, persistence, or regression behavior the change is actually about.
- It would fail if the implementation regressed in the specific way the change claims to fix or protect.
- It does not mock, snapshot, fixture, or helper-share away the behavior under test.
If a meaningful test is not practical, say that directly and use a different proof path. Do not add decorative coverage.
Workflow
- Reconstruct the behavioral thesis from source, issue, failing path, docs, logs, user report, or maintainer context: "When X happens, current code does Y; this change should make Z happen."
- Identify the contract boundary: public API, UI state, CLI output, database effect, filesystem effect, package command, config behavior, security boundary, migration, background job, or pure function.
- Pick the lowest test layer that still exercises the real contract. Prefer an existing local pattern over a new harness.
- Write or revise the test around the contract, not around the implementation shape.
- Produce red-green proof when practical:
- run the new test before the fix;
- temporarily revert the implementation hunk and run the test;
- check out the parent/base version and run the test there;
- or inject the old bug locally and confirm the test fails.
- Remove any temporary mutation or revert, then run the focused command again.
- Run proportional broader validation only after the focused test proves the contract.
- Re-read the test diff with the anti-pattern checklist in
references/test-smells.mdbefore calling the change ready.
Never keep a temporary mutation, broad debug fixture, or local-only proof artifact in the final diff.
What Good Looks Like
Prefer tests that:
- start from realistic inputs or repo fixtures rather than expected-output literals shaped by the implementation;
- assert exact behavior where exactness matters and semantic behavior where formatting is incidental;
- include the negative, empty, duplicate, unauthorized, stale, boundary, overflow, or race-adjacent case that caused the bug;
- exercise real parsers, routing, filtering, serialization, persistence, CLI wiring, or rendering behavior unless the unit boundary is explicitly the contract;
- fail with a useful message when the contract breaks;
- follow nearby test style, helpers, naming, and setup.
Reject These Tests
Reject or rewrite tests that:
- only prove the new code path returns the value the test hard-coded from the patch;
- mock the function, module, query, parser, or service whose behavior is the subject;
- assert "called with" on an internal helper while the observable behavior could still be wrong;
- use snapshots for behavior that should be asserted intentionally;
- use
toBeTruthy,not.toThrow, or "renders something" as the main proof for a concrete regression; - generate expected values with the same helper or normalization logic as the implementation;
- add broad fixture churn, unrelated cleanup, or public docs changes just to make the test look substantial;
- pass only because the mock omits the old failure case.
Read references/test-smells.md when a test feels plausible but maybe too convenient.
Repo-Specific Notes
For OpenClaw repositories, use this skill alongside openclaw-contributions.
For ClawHub Convex work, respect convex/_generated/ai/guidelines.md; avoid unindexed scans and tests that bless expensive exact-count behavior when the product should use bounded limit + 1 or hasMore contracts.
For openclaw/openclaw CLI, config, session, auth, filesystem, or sandbox work, isolate state with temp directories and test homes. Never run tests against Vyctor's real ~/.openclaw instance unless he explicitly asks for that exact path.
Reporting
In the final work summary, include:
- the behavioral thesis covered by the test;
- the focused command that passed;
- the red-green proof used, or the reason it was not practical;
- any broader validation run.
For public PR bodies, mention only repository-native commands and behavior. Do not mention this skill, Codex-local checks, local paths, or temporary mutation details.
相关技能
Drive a GitHub pull request through an iterative review-and-fix loop. Use when Codex needs to create a PR if none exists for the current branch, inspect revi...
Use when drafting, restructuring, reviewing, or submitting GitHub issues from investigation findings, bugs, security reviews, regressions, feature requests,...
Mandatory risk-driven verification workflow for maintained-code changes. Use when implementing, fixing, refactoring, deleting, migrating, or reviewing code to identify all materially affected behavior, map failure risks to sufficient tests, execute required evidence, and report unresolved test gaps
Write Storybook stories for a component's meaningful user-facing states with minimal, readable fixtures.
Orchestrate the complete coding workflow with multiple development modes (TDD/incremental/spec-dr...