Unit Test Standard Onboarding & Remediation
Usage
Two modes, default is Onboarding:
| Mode | Trigger | Action |
|---|---|---|
| A Onboarding (main) | New project adopting the standard, or adding test commands to an existing project | Inject AGENTS.md + package.json + docs/scripts, optionally generate projects config skeleton |
| B Remediation | Existing tests slowing down iteration, need to align to the standard in one pass | Diagnose → Triage → Batch delete/extract/split/migrate → Verify, see Remediation Playbook |
This skill only modifies documentation, configurations (except isolate), and scripts – it never modifies business logic or the behavior of tests. Deletions/extractions in remediation mode must be committed separately.
Hard Rules
- Never modify
isolateinvitest*.config.*: logic / integration is fixed totrue, DOM / slow is fixed tofalse. This is a tier definition, not a failure-fix mechanism; if adjustments are truly needed, stop and have a human confirm (UT-L10). - Do not enable DOM / slow tiers unless UT-M8 adaptation is complete, and do not use
isolate: trueas a workaround. - Changing
isolateis a tier definition change, not a test fix.
Included Files
| Path | Purpose |
|---|---|
agents.md | The "Testing Convention" body to inject (single source of truth; edit here) |
docs/unit-test-standard.md | Main rule file; command table §9 (UT-R1), red lines §8, self-check §11 |
docs/testing-guidelines.md | jsdom / antd performance specifics (referenced by main rules; must be copied together) |
docs/unit-test-isolation-notes.md | isolate: false migration notes (UT-M8) |
scripts/apply.mjs | Idempotent injector: merge AGENTS.md, modify package.json, copy docs/scripts, optionally generate projects config |
scripts/test-audit.mjs | Static specification checker, written to target scripts/, corresponds to test:audit |
templates/vitest.config.ts | Four-tier test.projects skeleton; must be adapted to the target project before use |
references/example-scripts/ | Source repository's setup / report / mock reference implementations (with @/... placeholder paths; read-only reference) |
references/state.md, references/mock-inventory.md | Source repository's remediation data and mock consolidation list (examples, not target project state) |
To read the rules, refer to
docs/within this skill; after injection, the target project will also have its own copy ofdocs/unit-test-standard.mdfor direct reference by project AI and reviewers.
Mode A: Onboarding
A0 Pre-check
- Target project root directory (must have
package.json). - Package manager:
pnpm-lock.yaml/yarn.lock/package-lock.json. - vitest already installed (minimum version 3.2, test environment version 5.1.1;
test.projects/defineProjectfrom 3.2, 3.0 / 3.1 usetest.workspace); whethervitest.config.*already hastest.projects(whether four tiers are already migrated to projects). - Whether the target already has
AGENTS.md, and if so, whether it already contains a "Testing Convention" section.
A1 Inject AGENTS.md & package.json
Dry-run first, then write:
node <skill>/scripts/apply.mjs --target <project-root>
node <skill>/scripts/apply.mjs --target <project-root> --write
- AGENTS.md: Create
AGENTS.mdif it doesn't exist (ifagents.mdalready exists, reuse original filename). If a "Testing Convention" section already exists and its content matches, only add management markers. If content differs, report a conflict, and only proceed with--force-sectionafter confirmation. - package.json: Inject
test/test:dom/test:slow/test:integration/test:all/test:auditper UT-R1 (do not providetest:changed: running import graphs is usually slower than running the full logic suite; also do not create a separatecheckcommand; keep the command table minimal). - Documents & Scripts: Copy the three documents (e.g.,
docs/unit-test-standard.md),scripts/test-audit.mjs. - By default, never overwrite existing content: same script name but different value → skip and report; only overwrite with confirmation using
--overwrite-scripts(docs use--overwrite-docs, tool scripts use--overwrite-support). - If the script cannot run (target environment has no Node.js): directly read
agents.md, merge it into the rootAGENTS.mdusing the same<!-- BEGIN/END unit-test-standard -->markers, and manually add each command from the UT-R1 table topackage.jsonwithout overwriting existing names.
Command form for manual injection (replace project names with the actual target):
{
"test": "vitest run --project=logic",
"test:dom": "vitest run --project=dom",
"test:slow": "vitest run --project=slow",
"test:integration": "vitest run --project=integration",
"test:all": "vitest run",
"test:audit": "node scripts/test-audit.mjs"
}
test:all must NOT include --project – it runs all four projects. Single-tier commands MUST explicitly include --project=; omitting it will accidentally run the full suite.
A2 When There Is No Projects Configuration
apply.mjs only supports test.projects. If the target configuration is not in this form, it will immediately report an error and will NOT inject runnable commands. You can first generate a skeleton:
node <skill>/scripts/apply.mjs --target <project-root> --scaffold-configs --write
After generation, only modify resolve.alias, setupFiles, include/exclude. Do NOT change isolate – keep it as is from the template (logic / integration = true, DOM / slow = false). If UT-M8 adaptation is not complete, do not enable DOM / slow tiers; stop and report. For projects that still have the old four separate config files, first manually migrate to test.projects before running apply.
A3 Verification (must actually run)
node scripts/test-audit.mjs # or pnpm test:audit
pnpm test # or npm run test / yarn test
pnpm test:all
test:auditmay have existing errors initially (especially missing@cost); handle them per the Remediation Playbook. Do not claim "expected to pass" in reports.- CI gate: use
node scripts/test-audit.mjs --changed --strict && pnpm test:all; do NOT rely on a separatecheckcommand. test:allruns all projects; single-tier commands MUST include--project; omitting it runs the full suite.- If commands fail, first fix alias / setup / dependencies. If the issue involves
isolate, stop and report; do NOT modify isolation configuration.
A4 Delivery Report
| Item | Content |
|---|---|
| Written | What was changed in AGENTS.md / package.json / docs / scripts |
| Conflicts | Which scripts or sections with the same name were skipped, and why |
| Verification | Actual results and durations for test / test:all / test:audit |
| To-Do | Missing config, existing audit errors, DOM/slow tiers not yet adapted for UT-M8 |
Mode B: Remediation
Read references/audit-playbook.md. Core order: first measure the cost map, then apply "delete → migrate → extract → split" to the most expensive 20%, each batch as a separate commit, finally achieve test:audit 0 errors + test:all all green.
Common Mistakes
| Mistake | Consequence | Correct Approach |
|---|---|---|
| Directly overwrite existing AGENTS.md / scripts in the target | Lose the project's own conventions | Dry-run first to see the report; confirm each conflict manually |
| Only modify package.json but not create config | All commands fail to run | First align test.projects, or use --scaffold-configs then adapt |
Omit --project in single-tier commands | Run the full suite accidentally, doubling test time | Every single-tier script MUST explicitly include --project=<tier> |
Target still has four separate vitest.*.config.* files | apply immediately errors out, does not inject commands | First migrate to a single test.projects config, then run apply |
Copy references/example-scripts directly into the target | Missing test-mocks/ and business modules; imports fail | Use the generic versions from scripts/; reference implementations are read-only |
| Declare completion without running tests | Delivery is not trustworthy | At least run test and test:audit from section A3 |
| Use retries / increase timeouts to make audit green | Mask actual cost | Fix test cases or split slow tests (X12) |
Modify isolate to make DOM/slow pass | Breaks tier definitions; failure set drifts with worker scheduling | Forbidden; stop and have a human confirm (UT-L10) |