Unit Test Philosophy
by @stevenobiajulu
Risk-based unit testing and Allure-readable behavioral spec style for open-agreements. Use when user says "add tests," "test quality," "coverage expansion,"...
clawhub install unit-test-philosophyπ About This Skill
name: unit-test-philosophy description: >- Risk-based unit testing and Allure-readable behavioral spec style for open-agreements. Use when user says "add tests," "test quality," "coverage expansion," "unit test style," or "Allure test spec." Applies when adding/updating tests, expanding coverage, or reviewing test quality across src, integration-tests, and workspace packages. metadata: short-description: Open Agreements testing philosophy version: "0.1.0" catalog_group: Developer Workflows catalog_order: 20
Unit Test Philosophy (Open Agreements)
Security model
Use this skill when
src/, integration-tests/, packages/contracts-workspace, or packages/contracts-workspace-mcp.Core philosophy
1. Test highest-risk behavior first. Focus first on mutating flows, parser/validator boundaries, and policy/safety checks. 2. Optimize for regression prevention, not just line coverage. Prioritize branches where failures could produce wrong legal output or unsafe automation behavior. 3. Treat Allure as test style, not test type. Use normal unit/integration tests with Allure labels, steps, and attachments in the same files. 4. Keep spec and test effectively coextensive. If behavior is important enough to test, map it to canonical OpenSpec scenarios or active change-package scenarios. 5. Keep assertions behavior-oriented. Verify user-observable outputs, diagnostics, and mutation outcomes before internals. 6. Make failures easy to debug. Attach structured context for inputs, normalized outputs, and error payloads.Repo standards
Test structure
Execute test body.Allure API
integration-tests/helpers/allure-test.ts
- Common helpers: itAllure, testAllure, allureStep, allureJsonAttachment, allurePrettyJsonAttachment, allureWordLikeTextAttachment, allureParameter, allureSeverity
allure-vitest in tests.src//*.test.ts and integration-tests//*.test.ts.scripts/patch_allure_html_sanitizer.mjs, invoked by npm run report:allure). Do not bypass this pipeline when generating reports for review.File naming and placement
src/.test.ts .*.allure.test.ts files to *.test.ts; do not introduce new *.allure.test.ts files.OpenSpec traceability
.openspec('OA-###') whenever a matching scenario ID exists for the behavior.openspec/specs/open-agreements/spec.md) or active change-package specs (openspec/changes//specs/open-agreements/spec.md ).Coverage expansion workflow
1. Read coverage summaries and identify branch-heavy modules insrc/core/** and integration flows.
2. Rank by blast radius and mutation risk.
3. Add tests in this order:
- Validation and error branches
- Strict vs permissive behavior
- No-partial-mutation / transactional guarantees
- Invariants (deterministic outputs, schema safety, idempotency)
4. Run targeted tests first, then full suite and coverage.Severity recommendation rubric
critical: mutation correctness, legal-output integrity, data-loss risk, security/policy guardrails.normal: standard behavior and compatibility scenarios.minor: narrow edge cases with low production impact.Command checklist
npm run test:run
npm run test:coverage
npm run check:spec-coverage
npm run check:allure-labels
Minimal test template (TypeScript)
import { describe, expect } from 'vitest';
import { itAllure as it, allureStep, allureJsonAttachment } from '../../../integration-tests/helpers/allure-test.js';describe('checklist patch behavior', () => {
it('applies replacement deterministically', async () => {
let result: { ok: boolean };
await allureStep('Given a valid patch payload', async () => {
await allureJsonAttachment('patch-input.json', {
patch_id: 'patch_001',
operations: [{ op: 'replace', path: '/issues/0/status', value: 'CLOSED' }],
});
});
await allureStep('When patch validation runs', async () => {
result = { ok: true };
});
await allureStep('Then validation succeeds', async () => {
expect(result!.ok).toBe(true);
});
});
});
Extended reference
references/allure-test-spec-writing-guide.md for full Allure step-writing guidance.