Unit Test Writer (PABX)
Plan and implement fast, isolated, high-quality unit tests for the PABX monorepo. Validates
logic without hitting real databases, HTTP, or filesystems. Never modifies production code —
if a test fails, only the test is adjusted.
Project scope: this skill assumes the PABX monorepo structure. All the hard,
project-specific rules (jQuery/localStorage mock order, Promise.all() mock pattern, file
locations, execution commands) are in references/pabx-rules.md — read it before writing.
Generic SDD flow docs: https://github.com/dayvisonassis/sdd-skills/blob/main/docs/GUIA_DO_WORKFLOW.md.
Scope:
- Frontend:
apps/frontend/ — Jest + jest-preset-angular, *.spec.ts co-located with the source.
- Backend:
apps/backend/__tests__/unit/ — Jest, *.test.js mirroring src/ (1:1).
INPUT
target_file (required) — the source file to test.
mode (optional) — interactive (default when a user calls directly) or autonomous (set by implement-feature/evaluator).
test_file_path (optional) — existing test file to expand; otherwise created automatically.
focus_areas / batch_size (optional) — prioritized methods; tests per batch (default 8, 5–10).
test_catalog_path (optional) — a Test Catalog entry to accelerate Phase 1.
evaluation_report (optional) — when present, run in correction mode (fix only the failing test named in the report).
OUTPUT
- New/expanded
.spec.ts / .test.js unit tests following the PABX rules, in the correct location.
- A
.unit-test.md checklist (planning may be Portuguese; all test code is English).
- Per-batch execution confirmation (tests run in milliseconds) and a final coverage summary.
- No production code is ever modified.
Invocation Modes
Interactive (user-invoked, default): run the full 3-phase process and stop at the Phase 2
checkpoint to get explicit user approval before implementing.
Autonomous (dispatched by implement-feature / evaluator): run the same 3 phases but skip
the approval checkpoint — auto-accept the checklist and proceed to batch implementation. Never
pause for a human. This mirrors spec-writer's Batch Mode.
Correction mode (dispatched by evaluator on a kind:test failure): an evaluation_report
is provided. Read the failing test's testFile/location/message, and fix only that test
(smallest footprint) so it conforms to the PABX rules and passes. Do not rewrite unrelated tests
and do not touch production code. Return control to the evaluator.
EXECUTION STEPS (3 Phases)
Phase 1 — Analysis & Planning
- If
test_catalog_path given, read the catalog entry (priority, gaps, methods, mocks, pattern) and validate it against the actual source.
- Backend: study existing
apps/backend/__tests__/unit/ for patterns. Frontend: IGNORE legacy Karma/Jasmine; write fresh Jest tests.
- Read the target file fully; map functionalities, dependencies, code paths.
- Identify every external dependency to mock (HttpClient, DB, services, localStorage, jQuery, Router, ActivatedRoute).
- Map scenarios: success, error handling, edge cases, boundary conditions.
Phase 2 — Checklist Creation
Create a .unit-test.md checklist organized by method/function, using the minimum categories
for the target type (component / service / backend util / controller / model — see
references/pabx-rules.md).
- Interactive: present the checklist and ask: does it guarantee max coverage of success+failure? missing edge cases? all deps identified? → WAIT for explicit approval.
- Autonomous / correction: skip the checkpoint; treat the checklist as approved and proceed.
Phase 3 — Batch Implementation (only after approval / autonomously)
- GROUP similar tests into batches of 5–10 (same method/scenario/mocks).
- IMPLEMENT the batch in one operation, applying the PABX rules (
references/pabx-rules.md).
- EXECUTE the batch — confirm milliseconds; a test > 1s means a broken mock.
- UPDATE the checklist; REPEAT until complete.
In correction mode, Phases 1–2 collapse to reading the report + the failing test; implement
only the corrected test(s) and run them.
RULES
Always:
- Follow
references/pabx-rules.md exactly (component/service/model/controller patterns, mock order, cleanup, performance).
- Write ALL test content in English; keep tests independent, deterministic, fast.
- Import the REAL component; instantiate services manually; mock localStorage/jQuery before imports.
- Use the correct
Promise.all() mock pattern (new builder per call, .then via Promise.resolve().then.bind).
- Place files per the location standard (frontend co-located; backend 1:1 mirror).
- In correction mode, fix only the flagged test (smallest footprint) and return to the evaluator.
Never:
- Modify production code (components, services, utils, controllers, models). Fix only tests.
- Use real DB/HTTP/filesystem;
TestBed.inject()/HttpClientTestingModule for services; inline test components.
- Write anything in Portuguese in test files.
- Pause for approval in autonomous/correction mode.
- Leave shared mutable state between tests or create slow tests.
Edge Cases
- Test file missing: create it in the correct location.
- Component uses jQuery: global
$ mock BEFORE all imports (else CRITICAL failure).
- Model uses
Promise.all(): apply the dedicated mock pattern or tests hang for minutes.
- Stack not PABX (no
apps/ layout): this skill is PABX-specific; report that the caller should use a generic approach instead.
- Called autonomously but the checklist reveals a blocking ambiguity: apply a best-practice default, note it, and proceed (do not pause).
1---2name: unit-test-writer3description: Plans and implements comprehensive unit tests for the PABX monorepo — Angular frontend (Jest + jest-preset-angular, .spec.ts) and Node.js backend (Jest, apps/backend/__tests__/unit/). Runs interactively (3 phases with an approval checkpoint) when called by a user, or autonomously (no pause) when dispatched by implement-feature/evaluator. Also runs in correction mode to fix a specific failing test flagged by the evaluator. Enforces PABX rules (real component imports, manual service instantiation, localStorage/jQuery mock order, Promise.all() mock correctness, cleanup, English-only). Never modifies production code.4---56# Unit Test Writer (PABX)78Plan and implement fast, isolated, high-quality **unit tests** for the PABX monorepo. Validates9logic without hitting real databases, HTTP, or filesystems. **Never modifies production code** —10if a test fails, only the test is adjusted.1112> **Project scope:** this skill assumes the **PABX monorepo** structure. All the hard,13> project-specific rules (jQuery/localStorage mock order, `Promise.all()` mock pattern, file14> locations, execution commands) are in **`references/pabx-rules.md`** — read it before writing.15> Generic SDD flow docs: `https://github.com/dayvisonassis/sdd-skills/blob/main/docs/GUIA_DO_WORKFLOW.md`.1617**Scope:**18- **Frontend:** `apps/frontend/` — Jest + jest-preset-angular, `*.spec.ts` co-located with the source.19- **Backend:** `apps/backend/__tests__/unit/` — Jest, `*.test.js` mirroring `src/` (1:1).2021## INPUT2223- `target_file` (required) — the source file to test.24- `mode` (optional) — `interactive` (default when a user calls directly) or `autonomous` (set by implement-feature/evaluator).25- `test_file_path` (optional) — existing test file to expand; otherwise created automatically.26- `focus_areas` / `batch_size` (optional) — prioritized methods; tests per batch (default 8, 5–10).27- `test_catalog_path` (optional) — a Test Catalog entry to accelerate Phase 1.28- `evaluation_report` (optional) — when present, run in **correction mode** (fix only the failing test named in the report).2930## OUTPUT3132- New/expanded `.spec.ts` / `.test.js` unit tests following the PABX rules, in the correct location.33- A `.unit-test.md` checklist (planning may be Portuguese; **all test code is English**).34- Per-batch execution confirmation (tests run in milliseconds) and a final coverage summary.35- No production code is ever modified.3637---3839## Invocation Modes4041**Interactive (user-invoked, default):** run the full 3-phase process and **stop at the Phase 242checkpoint** to get explicit user approval before implementing.4344**Autonomous (dispatched by implement-feature / evaluator):** run the same 3 phases but **skip45the approval checkpoint** — auto-accept the checklist and proceed to batch implementation. Never46pause for a human. This mirrors spec-writer's Batch Mode.4748**Correction mode (dispatched by evaluator on a `kind:test` failure):** an `evaluation_report`49is provided. Read the failing test's `testFile`/`location`/`message`, and **fix only that test**50(smallest footprint) so it conforms to the PABX rules and passes. Do not rewrite unrelated tests51and do not touch production code. Return control to the evaluator.5253---5455## EXECUTION STEPS (3 Phases)5657### Phase 1 — Analysis & Planning581. If `test_catalog_path` given, read the catalog entry (priority, gaps, methods, mocks, pattern) and validate it against the actual source.592. **Backend:** study existing `apps/backend/__tests__/unit/` for patterns. **Frontend:** IGNORE legacy Karma/Jasmine; write fresh Jest tests.603. Read the target file fully; map functionalities, dependencies, code paths.614. Identify every external dependency to mock (HttpClient, DB, services, localStorage, jQuery, Router, ActivatedRoute).625. Map scenarios: success, error handling, edge cases, boundary conditions.6364### Phase 2 — Checklist Creation65Create a `.unit-test.md` checklist organized by method/function, using the minimum categories66for the target type (component / service / backend util / controller / model — see67`references/pabx-rules.md`).6869- **Interactive:** present the checklist and ask: does it guarantee max coverage of success+failure? missing edge cases? all deps identified? → **WAIT for explicit approval.**70- **Autonomous / correction:** skip the checkpoint; treat the checklist as approved and proceed.7172### Phase 3 — Batch Implementation (only after approval / autonomously)731. GROUP similar tests into batches of 5–10 (same method/scenario/mocks).742. IMPLEMENT the batch in one operation, applying the PABX rules (`references/pabx-rules.md`).753. EXECUTE the batch — confirm milliseconds; a test > 1s means a broken mock.764. UPDATE the checklist; REPEAT until complete.7778In **correction mode**, Phases 1–2 collapse to reading the report + the failing test; implement79only the corrected test(s) and run them.8081---8283## RULES8485**Always:**86- Follow `references/pabx-rules.md` exactly (component/service/model/controller patterns, mock order, cleanup, performance).87- Write ALL test content in English; keep tests independent, deterministic, fast.88- Import the REAL component; instantiate services manually; mock localStorage/jQuery before imports.89- Use the correct `Promise.all()` mock pattern (new builder per call, `.then` via `Promise.resolve().then.bind`).90- Place files per the location standard (frontend co-located; backend 1:1 mirror).91- In correction mode, fix only the flagged test (smallest footprint) and return to the evaluator.9293**Never:**94- Modify production code (components, services, utils, controllers, models). Fix only tests.95- Use real DB/HTTP/filesystem; `TestBed.inject()`/`HttpClientTestingModule` for services; inline test components.96- Write anything in Portuguese in test files.97- Pause for approval in autonomous/correction mode.98- Leave shared mutable state between tests or create slow tests.99100---101102## Edge Cases103104- **Test file missing:** create it in the correct location.105- **Component uses jQuery:** global `$` mock BEFORE all imports (else CRITICAL failure).106- **Model uses `Promise.all()`:** apply the dedicated mock pattern or tests hang for minutes.107- **Stack not PABX (no `apps/` layout):** this skill is PABX-specific; report that the caller should use a generic approach instead.108- **Called autonomously but the checklist reveals a blocking ambiguity:** apply a best-practice default, note it, and proceed (do not pause).