@akagilnc/pi-workflow-roles 0.1.4444 → 0.1.4503

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/dist/acp-host/description.js +2 -3
  4. package/dist/acp-host/production-host.js +512 -288
  5. package/dist/auditor-soul.js +8 -1
  6. package/dist/headless-host/description.js +3 -3
  7. package/dist/headless-host/production-host.js +519 -257
  8. package/dist/host-descriptions.js +3 -18
  9. package/dist/method-host-plugin/.claude-plugin/plugin.json +5 -0
  10. package/dist/method-host-plugin/skills/ak-cross-m-review/CONTEXT.md +48 -0
  11. package/dist/method-host-plugin/skills/ak-cross-m-review/LICENSE +21 -0
  12. package/dist/method-host-plugin/skills/ak-cross-m-review/SKILL.md +170 -0
  13. package/dist/method-host-plugin/skills/ak-cross-m-review/prompts/cmr-completeness.md +118 -0
  14. package/dist/method-host-plugin/skills/ak-cross-m-review/prompts/cmr-reviewer.md +128 -0
  15. package/dist/method-host-plugin/skills/ak-cross-m-review/provenance.json +41 -0
  16. package/dist/method-host-plugin/skills/diagnosing-bugs/SKILL.md +134 -0
  17. package/dist/method-host-plugin/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  18. package/dist/method-host-plugin/skills/diagnosing-bugs/provenance.json +31 -0
  19. package/dist/method-host-plugin/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +41 -0
  20. package/dist/method-host-plugin/skills/resolving-merge-conflicts/SKILL.md +14 -0
  21. package/dist/method-host-plugin/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  22. package/dist/method-host-plugin/skills/resolving-merge-conflicts/provenance.json +26 -0
  23. package/dist/method-host-plugin/skills/tdd/SKILL.md +38 -0
  24. package/dist/method-host-plugin/skills/tdd/agents/openai.yaml +3 -0
  25. package/dist/method-host-plugin/skills/tdd/mocking.md +59 -0
  26. package/dist/method-host-plugin/skills/tdd/provenance.json +36 -0
  27. package/dist/method-host-plugin/skills/tdd/tests.md +77 -0
  28. package/dist/public-cli/countersign-run.js +214 -155
  29. package/dist/public-cli/diarist-run.js +4 -1
  30. package/dist/public-cli/invocation.js +129 -21
  31. package/dist/public-cli/main.js +386 -202
  32. package/dist/session-opening-materials.js +17 -5
  33. package/extensions/role-runtime.ts +16 -6
  34. package/package.json +1 -1
  35. package/resources/method-host-plugin/.claude-plugin/plugin.json +5 -0
  36. package/scripts/build-package.mjs +6 -1
  37. package/src/acp-host/description.ts +2 -4
  38. package/src/acp-host/production-host.ts +0 -1
  39. package/src/auditor-soul.ts +10 -1
  40. package/src/headless-host/description.ts +4 -3
  41. package/src/headless-host/role-turn-host.ts +27 -4
  42. package/src/host-descriptions.ts +3 -23
  43. package/src/host-native-method.ts +67 -0
  44. package/src/public-cli/countersign-run.ts +326 -218
  45. package/src/public-cli/diarist-run.ts +4 -0
  46. package/src/public-cli/invocation.ts +205 -23
  47. package/src/role-envelope.ts +17 -47
  48. package/src/role-runtime-dependencies.ts +17 -2
  49. package/src/role-runtime.ts +12 -7
  50. package/src/session-opening-materials.ts +27 -11
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: diagnosing-bugs
3
+ description: Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.
4
+ ---
5
+
6
+ # Diagnosing Bugs
7
+
8
+ A discipline for hard bugs. Skip phases only when explicitly justified.
9
+
10
+ When exploring the codebase, read `CONTEXT.md` (if it exists) to get a clear mental model of the relevant modules, and check ADRs in the area you're touching.
11
+
12
+ ## Phase 1 — Build a feedback loop
13
+
14
+ **This is the skill.** Everything else is mechanical. If you have a **tight** pass/fail signal for the bug — one that goes red on _this_ bug — you will find the cause; bisection, hypothesis-testing, and instrumentation all just consume it. If you don't have one, no amount of staring at code will save you.
15
+
16
+ Spend disproportionate effort here. **Be aggressive. Be creative. Refuse to give up.**
17
+
18
+ ### Ways to construct one — try them in roughly this order
19
+
20
+ 1. **Failing test** at whatever seam reaches the bug — unit, integration, e2e.
21
+ 2. **Curl / HTTP script** against a running dev server.
22
+ 3. **CLI invocation** with a fixture input, diffing stdout against a known-good snapshot.
23
+ 4. **Headless browser script** (Playwright / Puppeteer) — drives the UI, asserts on DOM/console/network.
24
+ 5. **Replay a captured trace.** Save a real network request / payload / event log to disk; replay it through the code path in isolation.
25
+ 6. **Throwaway harness.** Spin up a minimal subset of the system (one service, mocked deps) that exercises the bug code path with a single function call.
26
+ 7. **Property / fuzz loop.** If the bug is "sometimes wrong output", run 1000 random inputs and look for the failure mode.
27
+ 8. **Bisection harness.** If the bug appeared between two known states (commit, dataset, version), automate "boot at state X, check, repeat" so you can `git bisect run` it.
28
+ 9. **Differential loop.** Run the same input through old-version vs new-version (or two configs) and diff outputs.
29
+ 10. **HITL bash script.** Last resort. If a human must click, drive _them_ with `scripts/hitl-loop.template.sh` so the loop is still structured. Captured output feeds back to you.
30
+
31
+ Build the right feedback loop, and the bug is 90% fixed.
32
+
33
+ ### Tighten the loop
34
+
35
+ Treat the loop as a product. Once you have _a_ loop, **tighten** it:
36
+
37
+ - Can I make it faster? (Cache setup, skip unrelated init, narrow the test scope.)
38
+ - Can I make the signal sharper? (Assert on the specific symptom, not "didn't crash".)
39
+ - Can I make it more deterministic? (Pin time, seed RNG, isolate filesystem, freeze network.)
40
+
41
+ A 30-second flaky loop is barely better than no loop; a 2-second deterministic one is tight — a debugging superpower.
42
+
43
+ ### Non-deterministic bugs
44
+
45
+ The goal is not a clean repro but a **higher reproduction rate**. Loop the trigger 100×, parallelise, add stress, narrow timing windows, inject sleeps. A 50%-flake bug is debuggable; 1% is not — keep raising the rate until it's debuggable.
46
+
47
+ ### When you genuinely cannot build a loop
48
+
49
+ Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do **not** proceed to hypothesise without a loop.
50
+
51
+ ### Completion criterion — a tight loop that goes red
52
+
53
+ Phase 1 is done when the loop is **tight** and **red-capable**: you can name **one command** — a script path, a test invocation, a curl — that you have **already run at least once** (paste the invocation and its output), and that is:
54
+
55
+ - [ ] **Red-capable** — it drives the actual bug code path and asserts the **user's exact symptom**, so it can go red on this bug and green once fixed. Not "runs without erroring" — it must be able to _catch this specific bug_.
56
+ - [ ] **Deterministic** — same verdict every run (flaky bugs: a pinned, high reproduction rate, per above).
57
+ - [ ] **Fast** — seconds, not minutes.
58
+ - [ ] **Agent-runnable** — you can run it unattended; a human in the loop only via `scripts/hitl-loop.template.sh`.
59
+
60
+ If you catch yourself reading code to build a theory before this command exists, **stop — jumping straight to a hypothesis is the exact failure this skill prevents.** No red-capable command, no Phase 2.
61
+
62
+ ## Phase 2 — Reproduce + minimise
63
+
64
+ Run the loop. Watch it go red — the bug appears.
65
+
66
+ Confirm:
67
+
68
+ - [ ] The loop produces the failure mode the **user** described — not a different failure that happens to be nearby. Wrong bug = wrong fix.
69
+ - [ ] The failure is reproducible across multiple runs (or, for non-deterministic bugs, reproducible at a high enough rate to debug against).
70
+ - [ ] You have captured the exact symptom (error message, wrong output, slow timing) so later phases can verify the fix actually addresses it.
71
+
72
+ ### Minimise
73
+
74
+ Once it's red, shrink the repro to the **smallest scenario that still goes red**. Cut inputs, callers, config, data, and steps **one at a time**, re-running the loop after each cut — keep only what's load-bearing for the failure.
75
+
76
+ Why bother: a minimal repro shrinks the hypothesis space in Phase 3 (fewer moving parts left to suspect) and becomes the clean regression test in Phase 5.
77
+
78
+ Done when **every remaining element is load-bearing** — removing any one of them makes the loop go green.
79
+
80
+ Do not proceed until you have reproduced **and** minimised.
81
+
82
+ ## Phase 3 — Hypothesise
83
+
84
+ Generate **3–5 ranked hypotheses** before testing any of them. Single-hypothesis generation anchors on the first plausible idea.
85
+
86
+ Each hypothesis must be **falsifiable**: state the prediction it makes.
87
+
88
+ > Format: "If <X> is the cause, then <changing Y> will make the bug disappear / <changing Z> will make it worse."
89
+
90
+ If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
91
+
92
+ **Show the ranked list to the user before testing.** They often have domain knowledge that re-ranks instantly ("we just deployed a change to #3"), or know hypotheses they've already ruled out. Cheap checkpoint, big time saver. Don't block on it — proceed with your ranking if the user is AFK.
93
+
94
+ ## Phase 4 — Instrument
95
+
96
+ Each probe must map to a specific prediction from Phase 3. **Change one variable at a time.**
97
+
98
+ Tool preference:
99
+
100
+ 1. **Debugger / REPL inspection** if the env supports it. One breakpoint beats ten logs.
101
+ 2. **Targeted logs** at the boundaries that distinguish hypotheses.
102
+ 3. Never "log everything and grep".
103
+
104
+ **Tag every debug log** with a unique prefix, e.g. `[DEBUG-a4f2]`. Cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
105
+
106
+ **Perf branch.** For performance regressions, logs are usually wrong. Instead: establish a baseline measurement (timing harness, `performance.now()`, profiler, query plan), then bisect. Measure first, fix second.
107
+
108
+ ## Phase 5 — Fix + regression test
109
+
110
+ Prefer writing the regression test **before the fix** when there is a **correct seam** for it. This ordering is diagnostic guidance, not a retrospective delivery gate: disclose a sequence deviation, then assess the fix from current code, behavior, and evidence.
111
+
112
+ A correct seam is one where the test exercises the **real bug pattern** as it occurs at the call site. If the only available seam is too shallow (single-caller test when the bug needs multiple callers, unit test that can't replicate the chain that triggered the bug), a regression test there gives false confidence.
113
+
114
+ **If no correct seam exists, that itself is the finding.** Note it. The codebase architecture is preventing the bug from being locked down. Flag this for the next phase.
115
+
116
+ If a correct seam exists:
117
+
118
+ 1. Turn the minimised repro into a test at that seam.
119
+ 2. When practical, observe it fail before applying the fix.
120
+ 3. Apply the fix.
121
+ 4. Verify that it passes.
122
+ 5. Re-run the Phase 1 feedback loop against the original (un-minimised) scenario.
123
+
124
+ ## Phase 6 — Cleanup + post-mortem
125
+
126
+ Required before declaring done:
127
+
128
+ - [ ] Original repro no longer reproduces (re-run the Phase 1 loop)
129
+ - [ ] Regression test passes (or absence of seam is documented)
130
+ - [ ] All `[DEBUG-...]` instrumentation removed (`grep` the prefix)
131
+ - [ ] Throwaway prototypes deleted (or moved to a clearly-marked debug location)
132
+ - [ ] The hypothesis that turned out correct is stated in the commit / PR message — so the next debugger learns
133
+
134
+ **Then ask: what would have prevented this bug?** If the answer involves architectural change (no good test seam, tangled callers, hidden coupling), record that architectural finding in the Fixer report for the caller to dispose. Do **not** launch `/improve-codebase-architecture`, architecture Grill, or any other role-external Skill chain from this method. Make the recommendation **after** the fix is in, not before — you have more information now than when you started.
@@ -0,0 +1,3 @@
1
+ interface:
2
+ display_name: "Diagnosing Bugs"
3
+ short_description: "Diagnose hard bugs and regressions"
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "diagnosing-bugs",
3
+ "kind": "role-method-skill",
4
+ "upstream": {
5
+ "repository": "https://github.com/mattpocock/skills",
6
+ "path": "skills/engineering/diagnosing-bugs",
7
+ "commit": "8b36d4fb2635b3c21998dcd8144439c9e5ba7302",
8
+ "tag": "v1.2.2",
9
+ "license": "MIT",
10
+ "copyright": "Copyright (c) 2026 Matt Pocock",
11
+ "attribution": "mattpocock/skills"
12
+ },
13
+ "packageAdaptation": "fixer-boundary-no-external-skill-chain",
14
+ "files": {
15
+ "SKILL.md": {
16
+ "sha256": "600d0c8e84f01ceaf77137184c564e05f594cf49f8d5ef9860b4a794c5cd368f",
17
+ "byteLength": 8879,
18
+ "gitBlob": "9fae71cbf39944ce5dbe4404436b4fe5d0d5be10"
19
+ },
20
+ "agents/openai.yaml": {
21
+ "sha256": "3e430dbe4334a87597488c060cb3dc3786bb00c9182877d6f5ec41f62490e90b",
22
+ "byteLength": 103,
23
+ "gitBlob": "a13a755a77634ce61a649a3a0d905a66d3865b35"
24
+ },
25
+ "scripts/hitl-loop.template.sh": {
26
+ "sha256": "b2932630950e5210075bcd6f850e5accf30c101c5367b29eac3a29b4dd8084c8",
27
+ "byteLength": 1164,
28
+ "gitBlob": "40afc4652f6f52fc117b2b00e1fa65fcec235838"
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # Human-in-the-loop reproduction loop.
3
+ # Copy this file, edit the steps below, and run it.
4
+ # The agent runs the script; the user follows prompts in their terminal.
5
+ #
6
+ # Usage:
7
+ # bash hitl-loop.template.sh
8
+ #
9
+ # Two helpers:
10
+ # step "<instruction>" → show instruction, wait for Enter
11
+ # capture VAR "<question>" → show question, read response into VAR
12
+ #
13
+ # At the end, captured values are printed as KEY=VALUE for the agent to parse.
14
+
15
+ set -euo pipefail
16
+
17
+ step() {
18
+ printf '\n>>> %s\n' "$1"
19
+ read -r -p " [Enter when done] " _
20
+ }
21
+
22
+ capture() {
23
+ local var="$1" question="$2" answer
24
+ printf '\n>>> %s\n' "$question"
25
+ read -r -p " > " answer
26
+ printf -v "$var" '%s' "$answer"
27
+ }
28
+
29
+ # --- edit below ---------------------------------------------------------
30
+
31
+ step "Open the app at http://localhost:3000 and sign in."
32
+
33
+ capture ERRORED "Click the 'Export' button. Did it throw an error? (y/n)"
34
+
35
+ capture ERROR_MSG "Paste the error message (or 'none'):"
36
+
37
+ # --- edit above ---------------------------------------------------------
38
+
39
+ printf '\n--- Captured ---\n'
40
+ printf 'ERRORED=%s\n' "$ERRORED"
41
+ printf 'ERROR_MSG=%s\n' "$ERROR_MSG"
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: resolving-merge-conflicts
3
+ description: "Use when you need to resolve an in-progress ordinary two-parent git merge conflict without inventing new authority."
4
+ ---
5
+
6
+ 1. **See the current state** of the ordinary two-parent merge already in progress. Use the admitted Merger assignment envelope (target/source parents, complete conflict set, resolution scope, authorized checks). Check git history and the conflicting files. This method is **merge-only**: do **not** start, abort, or continue a rebase, and do **not** treat general non-merge conflict workflows as in scope.
7
+
8
+ 2. **Find the primary sources** for each conflict. Understand deeply why each change was made, and what the original intent was. Read the commit messages, check the PRs, check original issues/tickets. Prefer admitted task/authority materials and primary sources over guesswork.
9
+
10
+ 3. **Resolve each hunk within resolution scope.** Preserve both intents where possible. Where intents are compatible, keep both. Where incompatible, or where a new product or authority decision is required, stop and submit the existing typed **escalate** outcome with a clear diagnosis — do **not** invent new behaviour, do **not** guess authority, and do **not** silently pick a side that needs a new decision. Never `--abort` (the caller owns abort). Never continue a rebase.
11
+
12
+ 4. Run **authorized checks** from the admitted assignment when present. When the assignment lists none, discover the project's automated checks within the role boundary — typically typecheck, then tests, then format — and run them. Fix anything the merge resolution broke that stays inside scope.
13
+
14
+ 5. **Finish the ordinary two-parent merge commit** within resolution scope. Stage in-scope resolutions and create the merge commit with the frozen target then source parents. Title it `ak-roles: merge: …` (factory worker prefix first). Do **not** publish, push, or route another role. Do **not** broaden into rebase or general conflict cleanup outside the admitted merge.
@@ -0,0 +1,3 @@
1
+ interface:
2
+ display_name: "Resolving Merge Conflicts"
3
+ short_description: "Resolve ordinary two-parent merge conflicts; escalate new authority"
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "resolving-merge-conflicts",
3
+ "kind": "role-method-skill",
4
+ "upstream": {
5
+ "repository": "https://github.com/mattpocock/skills",
6
+ "path": "skills/engineering/resolving-merge-conflicts",
7
+ "commit": "8b36d4fb2635b3c21998dcd8144439c9e5ba7302",
8
+ "tag": "v1.2.2",
9
+ "license": "MIT",
10
+ "copyright": "Copyright (c) 2026 Matt Pocock",
11
+ "attribution": "mattpocock/skills"
12
+ },
13
+ "packageAdaptation": "merger-merge-only-escalate-new-intent",
14
+ "files": {
15
+ "SKILL.md": {
16
+ "sha256": "a7be3300cd1457cb9b4065935271f37759531ebb366a352896a7a617d8d9c18a",
17
+ "byteLength": 2015,
18
+ "gitBlob": "b88102a6e903c2e60d3b4898552a0931a2fa4c91"
19
+ },
20
+ "agents/openai.yaml": {
21
+ "sha256": "f283f1ac11525de29d2615163fc3239b979f67c8e88560644364ca6e1a3b8100",
22
+ "byteLength": 146,
23
+ "gitBlob": "dc388c3df1d0a72ae2cfe7c78a23747f26e96822"
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: tdd
3
+ description: Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
4
+ ---
5
+
6
+ # Test-Driven Development
7
+
8
+ TDD commonly uses a red → green loop. This skill is a reference for producing tests worth keeping: what a good test is, where tests go, the anti-patterns, and the practices of the loop. Consult the sections before and during the loop when they help; they are method guidance, not retrospective delivery gates.
9
+
10
+ When exploring the codebase, read `CONTEXT.md` (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
11
+
12
+ ## What a good test is
13
+
14
+ Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification — "user can checkout with valid cart" tells you exactly what capability exists — and survives refactors because it doesn't care about internal structure.
15
+
16
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
17
+
18
+ ## Seams — where tests go
19
+
20
+ A **seam** is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
21
+
22
+ **Test only at pre-agreed seams.** Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything — agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
23
+
24
+ Ask: "What's the public interface, and which seams should we test?"
25
+
26
+ When the shape of that interface is itself in question — how deep the module is, where the seam belongs, what the interface should expose — use the `/codebase-design` skill for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.
27
+
28
+ ## Anti-patterns
29
+
30
+ - **Implementation-coupled** — mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
31
+ - **Tautological** — the assertion recomputes the expected value the way the code does (`expect(add(a, b)).toBe(a + b)`, a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth — a known-good literal, a worked example, the spec.
32
+ - **Horizontal slicing** — writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in **vertical slices** instead — one test → one implementation → repeat, each test a **tracer bullet** that responds to what the last cycle taught you.
33
+
34
+ ## Rules of the loop
35
+
36
+ - **Prefer red before green.** When practical, write the failing test first, then only enough code to pass it. If that historical order cannot be demonstrated, disclose the deviation; assess delivery from the current code, behavior, and evidence rather than rejecting it for sequence alone. Don't anticipate future tests or add speculative features.
37
+ - **One slice at a time.** One seam, one test, one minimal implementation per cycle.
38
+ - **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
@@ -0,0 +1,3 @@
1
+ interface:
2
+ display_name: "TDD"
3
+ short_description: "Test-driven red-green-refactor"
@@ -0,0 +1,59 @@
1
+ # When to Mock
2
+
3
+ Mock at **system boundaries** only:
4
+
5
+ - External APIs (payment, email, etc.)
6
+ - Databases (sometimes - prefer test DB)
7
+ - Time/randomness
8
+ - File system (sometimes)
9
+
10
+ Don't mock:
11
+
12
+ - Your own classes/modules
13
+ - Internal collaborators
14
+ - Anything you control
15
+
16
+ ## Designing for Mockability
17
+
18
+ At system boundaries, design interfaces that are easy to mock:
19
+
20
+ **1. Use dependency injection**
21
+
22
+ Pass external dependencies in rather than creating them internally:
23
+
24
+ ```typescript
25
+ // Easy to mock
26
+ function processPayment(order, paymentClient) {
27
+ return paymentClient.charge(order.total);
28
+ }
29
+
30
+ // Hard to mock
31
+ function processPayment(order) {
32
+ const client = new StripeClient(process.env.STRIPE_KEY);
33
+ return client.charge(order.total);
34
+ }
35
+ ```
36
+
37
+ **2. Prefer SDK-style interfaces over generic fetchers**
38
+
39
+ Create specific functions for each external operation instead of one generic function with conditional logic:
40
+
41
+ ```typescript
42
+ // GOOD: Each function is independently mockable
43
+ const api = {
44
+ getUser: (id) => fetch(`/users/${id}`),
45
+ getOrders: (userId) => fetch(`/users/${userId}/orders`),
46
+ createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
47
+ };
48
+
49
+ // BAD: Mocking requires conditional logic inside the mock
50
+ const api = {
51
+ fetch: (endpoint, options) => fetch(endpoint, options),
52
+ };
53
+ ```
54
+
55
+ The SDK approach means:
56
+ - Each mock returns one specific shape
57
+ - No conditional logic in test setup
58
+ - Easier to see which endpoints a test exercises
59
+ - Type safety per endpoint
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "tdd",
3
+ "kind": "role-method-skill",
4
+ "upstream": {
5
+ "repository": "https://github.com/mattpocock/skills",
6
+ "path": "skills/engineering/tdd",
7
+ "commit": "8b36d4fb2635b3c21998dcd8144439c9e5ba7302",
8
+ "tag": "v1.2.2",
9
+ "license": "MIT",
10
+ "copyright": "Copyright (c) 2026 Matt Pocock",
11
+ "attribution": "mattpocock/skills"
12
+ },
13
+ "packageAdaptation": "red-green-advisory-no-historical-compliance-gate",
14
+ "files": {
15
+ "SKILL.md": {
16
+ "sha256": "26c74168236078b8e43510b49f8c4b30784ec3cc7d4b1356792cbc8500d5cae6",
17
+ "byteLength": 3798,
18
+ "gitBlob": "d6b6bebaa1d1fed58812f8809b9ebc1ff9a5d1e4"
19
+ },
20
+ "tests.md": {
21
+ "sha256": "859f9e592c188fda4fc7277dd180e4ce9c7a2e13f6efe1f6f29eccc9d28c106a",
22
+ "byteLength": 2214,
23
+ "gitBlob": "7ab86479f925a1f9e8ba680af33cb3b12e015381"
24
+ },
25
+ "mocking.md": {
26
+ "sha256": "3ceb807fdf4a47d6a93d4d9a891e5ba6d362a6247bd08adc451feebfc17361ef",
27
+ "byteLength": 1481,
28
+ "gitBlob": "71cbfee674d93244ce81d1830b930ca9a69200bd"
29
+ },
30
+ "agents/openai.yaml": {
31
+ "sha256": "ea6f01cf1b8c06a4b0f5b649d74b1b8ce8685e72af1b38d70d877693e092af0b",
32
+ "byteLength": 87,
33
+ "gitBlob": "651b838a7663e027b1b8884491e867f26bb9a021"
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,77 @@
1
+ # Good and Bad Tests
2
+
3
+ ## Good Tests
4
+
5
+ **Integration-style**: Test through real interfaces, not mocks of internal parts.
6
+
7
+ ```typescript
8
+ // GOOD: Tests observable behavior
9
+ test("user can checkout with valid cart", async () => {
10
+ const cart = createCart();
11
+ cart.add(product);
12
+ const result = await checkout(cart, paymentMethod);
13
+ expect(result.status).toBe("confirmed");
14
+ });
15
+ ```
16
+
17
+ Characteristics:
18
+
19
+ - Tests behavior users/callers care about
20
+ - Uses public API only
21
+ - Survives internal refactors
22
+ - Describes WHAT, not HOW
23
+ - One logical assertion per test
24
+
25
+ ## Bad Tests
26
+
27
+ **Implementation-detail tests**: Coupled to internal structure.
28
+
29
+ ```typescript
30
+ // BAD: Tests implementation details
31
+ test("checkout calls paymentService.process", async () => {
32
+ const mockPayment = jest.mock(paymentService);
33
+ await checkout(cart, payment);
34
+ expect(mockPayment.process).toHaveBeenCalledWith(cart.total);
35
+ });
36
+ ```
37
+
38
+ Red flags:
39
+
40
+ - Mocking internal collaborators
41
+ - Testing private methods
42
+ - Asserting on call counts/order
43
+ - Test breaks when refactoring without behavior change
44
+ - Test name describes HOW not WHAT
45
+ - Verifying through external means instead of interface
46
+
47
+ ```typescript
48
+ // BAD: Bypasses interface to verify
49
+ test("createUser saves to database", async () => {
50
+ await createUser({ name: "Alice" });
51
+ const row = await db.query("SELECT * FROM users WHERE name = ?", ["Alice"]);
52
+ expect(row).toBeDefined();
53
+ });
54
+
55
+ // GOOD: Verifies through interface
56
+ test("createUser makes user retrievable", async () => {
57
+ const user = await createUser({ name: "Alice" });
58
+ const retrieved = await getUser(user.id);
59
+ expect(retrieved.name).toBe("Alice");
60
+ });
61
+ ```
62
+
63
+ **Tautological tests**: Expected value restates the implementation, so the test passes by construction.
64
+
65
+ ```typescript
66
+ // BAD: Expected value is recomputed the way the code computes it
67
+ test("calculateTotal sums line items", () => {
68
+ const items = [{ price: 10 }, { price: 5 }];
69
+ const expected = items.reduce((sum, i) => sum + i.price, 0);
70
+ expect(calculateTotal(items)).toBe(expected);
71
+ });
72
+
73
+ // GOOD: Expected value is an independent, known literal
74
+ test("calculateTotal sums line items", () => {
75
+ expect(calculateTotal([{ price: 10 }, { price: 5 }])).toBe(15);
76
+ });
77
+ ```