Community코딩 & 개발github.com

unit-test-audit

把「分层分档 + 成本可观测」的单元测试规范落地到目标项目:将 agents.md 的测试约定注入项目根目录 AGENTS.md,按 docs/unit-test-standard.md(UT-R1)给 package.json 注入 test / test:dom / test:slow / test:integration / test:all / test:audit 等命令,并复制规范文档与脚本;也覆盖存量整治。用户要求统一单测规范、给项目加测试命令、拆分测试档位、或整治慢测试时使用。

unit-test-audit란 무엇인가요?

unit-test-audit is a Claude Code agent skill that 把「分层分档 + 成本可观测」的单元测试规范落地到目标项目:将 agents.md 的测试约定注入项目根目录 AGENTS.md,按 docs/unit-test-standard.md(UT-R1)给 package.json 注入 test / test:dom / test:slow / test:integration / test:all / test:audit 等命令,并复制规范文档与脚本;也覆盖存量整治。用户要求统一单测规范、给项目加测试命令、拆分测试档位、或整治慢测试时使用。.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lizongze/unit-test-audit/tree/HEAD

Installed? Explore more 코딩 & 개발 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Unit Test Standard Onboarding & Remediation

Usage

Two modes, default is Onboarding:

ModeTriggerAction
A Onboarding (main)New project adopting the standard, or adding test commands to an existing projectInject AGENTS.md + package.json + docs/scripts, optionally generate projects config skeleton
B RemediationExisting tests slowing down iteration, need to align to the standard in one passDiagnose → 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 isolate in vitest*.config.*: logic / integration is fixed to true, DOM / slow is fixed to false. 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: true as a workaround.
  • Changing isolate is a tier definition change, not a test fix.

Included Files

PathPurpose
agents.mdThe "Testing Convention" body to inject (single source of truth; edit here)
docs/unit-test-standard.mdMain rule file; command table §9 (UT-R1), red lines §8, self-check §11
docs/testing-guidelines.mdjsdom / antd performance specifics (referenced by main rules; must be copied together)
docs/unit-test-isolation-notes.mdisolate: false migration notes (UT-M8)
scripts/apply.mjsIdempotent injector: merge AGENTS.md, modify package.json, copy docs/scripts, optionally generate projects config
scripts/test-audit.mjsStatic specification checker, written to target scripts/, corresponds to test:audit
templates/vitest.config.tsFour-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.mdSource 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 of docs/unit-test-standard.md for direct reference by project AI and reviewers.

Mode A: Onboarding

A0 Pre-check

  1. Target project root directory (must have package.json).
  2. Package manager: pnpm-lock.yaml / yarn.lock / package-lock.json.
  3. vitest already installed (minimum version 3.2, test environment version 5.1.1; test.projects / defineProject from 3.2, 3.0 / 3.1 use test.workspace); whether vitest.config.* already has test.projects (whether four tiers are already migrated to projects).
  4. 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.md if it doesn't exist (if agents.md already 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-section after confirmation.
  • package.json: Inject test / test:dom / test:slow / test:integration / test:all / test:audit per UT-R1 (do not provide test:changed: running import graphs is usually slower than running the full logic suite; also do not create a separate check command; 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 root AGENTS.md using the same <!-- BEGIN/END unit-test-standard --> markers, and manually add each command from the UT-R1 table to package.json without 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:audit may 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 separate check command.
  • test:all runs 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

ItemContent
WrittenWhat was changed in AGENTS.md / package.json / docs / scripts
ConflictsWhich scripts or sections with the same name were skipped, and why
VerificationActual results and durations for test / test:all / test:audit
To-DoMissing 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

MistakeConsequenceCorrect Approach
Directly overwrite existing AGENTS.md / scripts in the targetLose the project's own conventionsDry-run first to see the report; confirm each conflict manually
Only modify package.json but not create configAll commands fail to runFirst align test.projects, or use --scaffold-configs then adapt
Omit --project in single-tier commandsRun the full suite accidentally, doubling test timeEvery single-tier script MUST explicitly include --project=<tier>
Target still has four separate vitest.*.config.* filesapply immediately errors out, does not inject commandsFirst migrate to a single test.projects config, then run apply
Copy references/example-scripts directly into the targetMissing test-mocks/ and business modules; imports failUse the generic versions from scripts/; reference implementations are read-only
Declare completion without running testsDelivery is not trustworthyAt least run test and test:audit from section A3
Use retries / increase timeouts to make audit greenMask actual costFix test cases or split slow tests (X12)
Modify isolate to make DOM/slow passBreaks tier definitions; failure set drifts with worker schedulingForbidden; stop and have a human confirm (UT-L10)

관련 스킬