@zhongqian97-code/ecode 0.0.7 → 0.1.0

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 (34) hide show
  1. package/dist/index.js +375 -103
  2. package/package.json +2 -1
  3. package/skills/caveman/SKILL.md +49 -0
  4. package/skills/diagnose/SKILL.md +117 -0
  5. package/skills/grill-me/SKILL.md +10 -0
  6. package/skills/grill-with-docs/ADR-FORMAT.md +47 -0
  7. package/skills/grill-with-docs/CONTEXT-FORMAT.md +77 -0
  8. package/skills/grill-with-docs/SKILL.md +88 -0
  9. package/skills/improve-codebase-architecture/DEEPENING.md +37 -0
  10. package/skills/improve-codebase-architecture/INTERFACE-DESIGN.md +44 -0
  11. package/skills/improve-codebase-architecture/LANGUAGE.md +53 -0
  12. package/skills/improve-codebase-architecture/SKILL.md +71 -0
  13. package/skills/plan/SKILL.md +16 -0
  14. package/skills/search-first/SKILL.md +20 -0
  15. package/skills/security-review/SKILL.md +26 -0
  16. package/skills/setup-matt-pocock-skills/SKILL.md +121 -0
  17. package/skills/setup-matt-pocock-skills/domain.md +51 -0
  18. package/skills/setup-matt-pocock-skills/issue-tracker-github.md +22 -0
  19. package/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +23 -0
  20. package/skills/setup-matt-pocock-skills/issue-tracker-local.md +19 -0
  21. package/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  22. package/skills/tdd/SKILL.md +109 -0
  23. package/skills/tdd/deep-modules.md +33 -0
  24. package/skills/tdd/interface-design.md +31 -0
  25. package/skills/tdd/mocking.md +59 -0
  26. package/skills/tdd/refactoring.md +10 -0
  27. package/skills/tdd/tests.md +61 -0
  28. package/skills/to-issues/SKILL.md +83 -0
  29. package/skills/to-prd/SKILL.md +76 -0
  30. package/skills/triage/AGENT-BRIEF.md +168 -0
  31. package/skills/triage/OUT-OF-SCOPE.md +101 -0
  32. package/skills/triage/SKILL.md +103 -0
  33. package/skills/write-a-skill/SKILL.md +117 -0
  34. package/skills/zoom-out/SKILL.md +7 -0
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: search-first
3
+ description: Research-before-coding workflow. Search for existing tools, libraries, and patterns before writing custom code. Use when about to implement something that might already exist.
4
+ origin: https://github.com/affaan-m/everything-claude-code
5
+ ---
6
+
7
+ Before writing any code, search for existing solutions:
8
+
9
+ 1. **Check the existing codebase** — grep for similar patterns, utilities, or abstractions that could be reused or extended.
10
+
11
+ 2. **Check npm/package registries** — is there a battle-tested library that solves 80%+ of the problem? Prefer adopting proven code over hand-rolling.
12
+
13
+ 3. **Check GitHub** — search for open-source implementations or reference code (use `gh search code` or `gh search repos`).
14
+
15
+ 4. Present your findings:
16
+ - What you found and why it does/doesn't fit
17
+ - Recommended approach: reuse, adapt, or build new
18
+ - If building new, sketch the interface before writing implementation
19
+
20
+ Only proceed to implementation after confirming the approach with the user.
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: security-review
3
+ description: Security vulnerability scan of pending changes. Use when adding authentication, handling user input, creating API endpoints, or working with secrets and sensitive data.
4
+ origin: https://github.com/affaan-m/everything-claude-code
5
+ ---
6
+
7
+ Review the current branch changes (or the specified files) for security vulnerabilities.
8
+
9
+ Check for:
10
+ - Hardcoded secrets, API keys, passwords, or tokens
11
+ - SQL injection (raw string interpolation in queries)
12
+ - XSS (unsanitized HTML rendered to browser)
13
+ - Path traversal (user-controlled paths used in fs operations)
14
+ - Command injection (user input passed to shell without sanitization)
15
+ - Insecure deserialization
16
+ - Missing authentication or authorization checks
17
+ - Sensitive data logged or leaked in error messages
18
+ - Overly permissive CORS or CSP settings
19
+
20
+ For each finding, state:
21
+ 1. Severity: CRITICAL / HIGH / MEDIUM / LOW
22
+ 2. Location: file:line
23
+ 3. What the vulnerability is and how it could be exploited
24
+ 4. Recommended fix with a code example
25
+
26
+ If no issues found, explicitly confirm the review passed.
@@ -0,0 +1,121 @@
1
+ ---
2
+ name: setup-matt-pocock-skills
3
+ description: Sets up an `## Agent skills` block in AGENTS.md/CLAUDE.md and `docs/agents/` so the engineering skills know this repo's issue tracker (GitHub or local markdown), triage label vocabulary, and domain doc layout. Run before first use of `to-issues`, `to-prd`, `triage`, `diagnose`, `tdd`, `improve-codebase-architecture`, or `zoom-out` — or if those skills appear to be missing context about the issue tracker, triage labels, or domain docs.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Setup Matt Pocock's Skills
8
+
9
+ Scaffold the per-repo configuration that the engineering skills assume:
10
+
11
+ - **Issue tracker** — where issues live (GitHub by default; local markdown is also supported out of the box)
12
+ - **Triage labels** — the strings used for the five canonical triage roles
13
+ - **Domain docs** — where `CONTEXT.md` and ADRs live, and the consumer rules for reading them
14
+
15
+ This is a prompt-driven skill, not a deterministic script. Explore, present what you found, confirm with the user, then write.
16
+
17
+ ## Process
18
+
19
+ ### 1. Explore
20
+
21
+ Look at the current repo to understand its starting state. Read whatever exists; don't assume:
22
+
23
+ - `git remote -v` and `.git/config` — is this a GitHub repo? Which one?
24
+ - `AGENTS.md` and `CLAUDE.md` at the repo root — does either exist? Is there already an `## Agent skills` section in either?
25
+ - `CONTEXT.md` and `CONTEXT-MAP.md` at the repo root
26
+ - `docs/adr/` and any `src/*/docs/adr/` directories
27
+ - `docs/agents/` — does this skill's prior output already exist?
28
+ - `.scratch/` — sign that a local-markdown issue tracker convention is already in use
29
+
30
+ ### 2. Present findings and ask
31
+
32
+ Summarise what's present and what's missing. Then walk the user through the three decisions **one at a time** — present a section, get the user's answer, then move to the next. Don't dump all three at once.
33
+
34
+ Assume the user does not know what these terms mean. Each section starts with a short explainer (what it is, why these skills need it, what changes if they pick differently). Then show the choices and the default.
35
+
36
+ **Section A — Issue tracker.**
37
+
38
+ > Explainer: The "issue tracker" is where issues live for this repo. Skills like `to-issues`, `triage`, `to-prd`, and `qa` read from and write to it — they need to know whether to call `gh issue create`, write a markdown file under `.scratch/`, or follow some other workflow you describe. Pick the place you actually track work for this repo.
39
+
40
+ Default posture: these skills were designed for GitHub. If a `git remote` points at GitHub, propose that. If a `git remote` points at GitLab (`gitlab.com` or a self-hosted host), propose GitLab. Otherwise (or if the user prefers), offer:
41
+
42
+ - **GitHub** — issues live in the repo's GitHub Issues (uses the `gh` CLI)
43
+ - **GitLab** — issues live in the repo's GitLab Issues (uses the [`glab`](https://gitlab.com/gitlab-org/cli) CLI)
44
+ - **Local markdown** — issues live as files under `.scratch/<feature>/` in this repo (good for solo projects or repos without a remote)
45
+ - **Other** (Jira, Linear, etc.) — ask the user to describe the workflow in one paragraph; the skill will record it as freeform prose
46
+
47
+ **Section B — Triage label vocabulary.**
48
+
49
+ > Explainer: When the `triage` skill processes an incoming issue, it moves it through a state machine — needs evaluation, waiting on reporter, ready for an AFK agent to pick up, ready for a human, or won't fix. To do that, it needs to apply labels (or the equivalent in your issue tracker) that match strings *you've actually configured*. If your repo already uses different label names (e.g. `bug:triage` instead of `needs-triage`), map them here so the skill applies the right ones instead of creating duplicates.
50
+
51
+ The five canonical roles:
52
+
53
+ - `needs-triage` — maintainer needs to evaluate
54
+ - `needs-info` — waiting on reporter
55
+ - `ready-for-agent` — fully specified, AFK-ready (an agent can pick it up with no human context)
56
+ - `ready-for-human` — needs human implementation
57
+ - `wontfix` — will not be actioned
58
+
59
+ Default: each role's string equals its name. Ask the user if they want to override any. If their issue tracker has no existing labels, the defaults are fine.
60
+
61
+ **Section C — Domain docs.**
62
+
63
+ > Explainer: Some skills (`improve-codebase-architecture`, `diagnose`, `tdd`) read a `CONTEXT.md` file to learn the project's domain language, and `docs/adr/` for past architectural decisions. They need to know whether the repo has one global context or multiple (e.g. a monorepo with separate frontend/backend contexts) so they look in the right place.
64
+
65
+ Confirm the layout:
66
+
67
+ - **Single-context** — one `CONTEXT.md` + `docs/adr/` at the repo root. Most repos are this.
68
+ - **Multi-context** — `CONTEXT-MAP.md` at the root pointing to per-context `CONTEXT.md` files (typically a monorepo).
69
+
70
+ ### 3. Confirm and edit
71
+
72
+ Show the user a draft of:
73
+
74
+ - The `## Agent skills` block to add to whichever of `CLAUDE.md` / `AGENTS.md` is being edited (see step 4 for selection rules)
75
+ - The contents of `docs/agents/issue-tracker.md`, `docs/agents/triage-labels.md`, `docs/agents/domain.md`
76
+
77
+ Let them edit before writing.
78
+
79
+ ### 4. Write
80
+
81
+ **Pick the file to edit:**
82
+
83
+ - If `CLAUDE.md` exists, edit it.
84
+ - Else if `AGENTS.md` exists, edit it.
85
+ - If neither exists, ask the user which one to create — don't pick for them.
86
+
87
+ Never create `AGENTS.md` when `CLAUDE.md` already exists (or vice versa) — always edit the one that's already there.
88
+
89
+ If an `## Agent skills` block already exists in the chosen file, update its contents in-place rather than appending a duplicate. Don't overwrite user edits to the surrounding sections.
90
+
91
+ The block:
92
+
93
+ ```markdown
94
+ ## Agent skills
95
+
96
+ ### Issue tracker
97
+
98
+ [one-line summary of where issues are tracked]. See `docs/agents/issue-tracker.md`.
99
+
100
+ ### Triage labels
101
+
102
+ [one-line summary of the label vocabulary]. See `docs/agents/triage-labels.md`.
103
+
104
+ ### Domain docs
105
+
106
+ [one-line summary of layout — "single-context" or "multi-context"]. See `docs/agents/domain.md`.
107
+ ```
108
+
109
+ Then write the three docs files using the seed templates in this skill folder as a starting point:
110
+
111
+ - [issue-tracker-github.md](./issue-tracker-github.md) — GitHub issue tracker
112
+ - [issue-tracker-gitlab.md](./issue-tracker-gitlab.md) — GitLab issue tracker
113
+ - [issue-tracker-local.md](./issue-tracker-local.md) — local-markdown issue tracker
114
+ - [triage-labels.md](./triage-labels.md) — label mapping
115
+ - [domain.md](./domain.md) — domain doc consumer rules + layout
116
+
117
+ For "other" issue trackers, write `docs/agents/issue-tracker.md` from scratch using the user's description.
118
+
119
+ ### 5. Done
120
+
121
+ Tell the user the setup is complete and which engineering skills will now read from these files. Mention they can edit `docs/agents/*.md` directly later — re-running this skill is only necessary if they want to switch issue trackers or restart from scratch.
@@ -0,0 +1,51 @@
1
+ # Domain Docs
2
+
3
+ How the engineering skills should consume this repo's domain documentation when exploring the codebase.
4
+
5
+ ## Before exploring, read these
6
+
7
+ - **`CONTEXT.md`** at the repo root, or
8
+ - **`CONTEXT-MAP.md`** at the repo root if it exists — it points at one `CONTEXT.md` per context. Read each one relevant to the topic.
9
+ - **`docs/adr/`** — read ADRs that touch the area you're about to work in. In multi-context repos, also check `src/<context>/docs/adr/` for context-scoped decisions.
10
+
11
+ If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The producer skill (`/grill-with-docs`) creates them lazily when terms or decisions actually get resolved.
12
+
13
+ ## File structure
14
+
15
+ Single-context repo (most repos):
16
+
17
+ ```
18
+ /
19
+ ├── CONTEXT.md
20
+ ├── docs/adr/
21
+ │ ├── 0001-event-sourced-orders.md
22
+ │ └── 0002-postgres-for-write-model.md
23
+ └── src/
24
+ ```
25
+
26
+ Multi-context repo (presence of `CONTEXT-MAP.md` at the root):
27
+
28
+ ```
29
+ /
30
+ ├── CONTEXT-MAP.md
31
+ ├── docs/adr/ ← system-wide decisions
32
+ └── src/
33
+ ├── ordering/
34
+ │ ├── CONTEXT.md
35
+ │ └── docs/adr/ ← context-specific decisions
36
+ └── billing/
37
+ ├── CONTEXT.md
38
+ └── docs/adr/
39
+ ```
40
+
41
+ ## Use the glossary's vocabulary
42
+
43
+ When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `CONTEXT.md`. Don't drift to synonyms the glossary explicitly avoids.
44
+
45
+ If the concept you need isn't in the glossary yet, that's a signal — either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/grill-with-docs`).
46
+
47
+ ## Flag ADR conflicts
48
+
49
+ If your output contradicts an existing ADR, surface it explicitly rather than silently overriding:
50
+
51
+ > _Contradicts ADR-0007 (event-sourced orders) — but worth reopening because…_
@@ -0,0 +1,22 @@
1
+ # Issue tracker: GitHub
2
+
3
+ Issues and PRDs for this repo live as GitHub issues. Use the `gh` CLI for all operations.
4
+
5
+ ## Conventions
6
+
7
+ - **Create an issue**: `gh issue create --title "..." --body "..."`. Use a heredoc for multi-line bodies.
8
+ - **Read an issue**: `gh issue view <number> --comments`, filtering comments by `jq` and also fetching labels.
9
+ - **List issues**: `gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'` with appropriate `--label` and `--state` filters.
10
+ - **Comment on an issue**: `gh issue comment <number> --body "..."`
11
+ - **Apply / remove labels**: `gh issue edit <number> --add-label "..."` / `--remove-label "..."`
12
+ - **Close**: `gh issue close <number> --comment "..."`
13
+
14
+ Infer the repo from `git remote -v` — `gh` does this automatically when run inside a clone.
15
+
16
+ ## When a skill says "publish to the issue tracker"
17
+
18
+ Create a GitHub issue.
19
+
20
+ ## When a skill says "fetch the relevant ticket"
21
+
22
+ Run `gh issue view <number> --comments`.
@@ -0,0 +1,23 @@
1
+ # Issue tracker: GitLab
2
+
3
+ Issues and PRDs for this repo live as GitLab issues. Use the [`glab`](https://gitlab.com/gitlab-org/cli) CLI for all operations.
4
+
5
+ ## Conventions
6
+
7
+ - **Create an issue**: `glab issue create --title "..." --description "..."`. Use a heredoc for multi-line descriptions. Pass `--description -` to open an editor.
8
+ - **Read an issue**: `glab issue view <number> --comments`. Use `-F json` for machine-readable output.
9
+ - **List issues**: `glab issue list --state opened -F json` with appropriate `--label` filters. Note that GitLab uses `opened` (not `open`) for the state value.
10
+ - **Comment on an issue**: `glab issue note <number> --message "..."`. GitLab calls comments "notes".
11
+ - **Apply / remove labels**: `glab issue update <number> --label "..."` / `--unlabel "..."`. Multiple labels can be comma-separated or by repeating the flag.
12
+ - **Close**: `glab issue close <number>`. `glab issue close` does not accept a closing comment, so post the explanation first with `glab issue note <number> --message "..."`, then close.
13
+ - **Merge requests**: GitLab calls PRs "merge requests". Use `glab mr create`, `glab mr view`, `glab mr note`, etc. — the same shape as `gh pr ...` with `mr` in place of `pr` and `note`/`--message` in place of `comment`/`--body`.
14
+
15
+ Infer the repo from `git remote -v` — `glab` does this automatically when run inside a clone.
16
+
17
+ ## When a skill says "publish to the issue tracker"
18
+
19
+ Create a GitLab issue.
20
+
21
+ ## When a skill says "fetch the relevant ticket"
22
+
23
+ Run `glab issue view <number> --comments`.
@@ -0,0 +1,19 @@
1
+ # Issue tracker: Local Markdown
2
+
3
+ Issues and PRDs for this repo live as markdown files in `.scratch/`.
4
+
5
+ ## Conventions
6
+
7
+ - One feature per directory: `.scratch/<feature-slug>/`
8
+ - The PRD is `.scratch/<feature-slug>/PRD.md`
9
+ - Implementation issues are `.scratch/<feature-slug>/issues/<NN>-<slug>.md`, numbered from `01`
10
+ - Triage state is recorded as a `Status:` line near the top of each issue file (see `triage-labels.md` for the role strings)
11
+ - Comments and conversation history append to the bottom of the file under a `## Comments` heading
12
+
13
+ ## When a skill says "publish to the issue tracker"
14
+
15
+ Create a new file under `.scratch/<feature-slug>/` (creating the directory if needed).
16
+
17
+ ## When a skill says "fetch the relevant ticket"
18
+
19
+ Read the file at the referenced path. The user will normally pass the path or the issue number directly.
@@ -0,0 +1,15 @@
1
+ # Triage Labels
2
+
3
+ The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.
4
+
5
+ | Label in mattpocock/skills | Label in our tracker | Meaning |
6
+ | -------------------------- | -------------------- | ---------------------------------------- |
7
+ | `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
8
+ | `needs-info` | `needs-info` | Waiting on reporter for more information |
9
+ | `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
10
+ | `ready-for-human` | `ready-for-human` | Requires human implementation |
11
+ | `wontfix` | `wontfix` | Will not be actioned |
12
+
13
+ When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.
14
+
15
+ Edit the right-hand column to match whatever vocabulary you actually use.
@@ -0,0 +1,109 @@
1
+ ---
2
+ name: tdd
3
+ description: Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
4
+ ---
5
+
6
+ # Test-Driven Development
7
+
8
+ ## Philosophy
9
+
10
+ **Core principle**: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
11
+
12
+ **Good tests** are integration-style: they exercise real code paths through public APIs. They describe _what_ the system does, not _how_ it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
13
+
14
+ **Bad tests** are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
15
+
16
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
17
+
18
+ ## Anti-Pattern: Horizontal Slices
19
+
20
+ **DO NOT write all tests first, then all implementation.** This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."
21
+
22
+ This produces **crap tests**:
23
+
24
+ - Tests written in bulk test _imagined_ behavior, not _actual_ behavior
25
+ - You end up testing the _shape_ of things (data structures, function signatures) rather than user-facing behavior
26
+ - Tests become insensitive to real changes - they pass when behavior breaks, fail when behavior is fine
27
+ - You outrun your headlights, committing to test structure before understanding the implementation
28
+
29
+ **Correct approach**: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
30
+
31
+ ```
32
+ WRONG (horizontal):
33
+ RED: test1, test2, test3, test4, test5
34
+ GREEN: impl1, impl2, impl3, impl4, impl5
35
+
36
+ RIGHT (vertical):
37
+ RED→GREEN: test1→impl1
38
+ RED→GREEN: test2→impl2
39
+ RED→GREEN: test3→impl3
40
+ ...
41
+ ```
42
+
43
+ ## Workflow
44
+
45
+ ### 1. Planning
46
+
47
+ When exploring the codebase, use the project's domain glossary so that test names and interface vocabulary match the project's language, and respect ADRs in the area you're touching.
48
+
49
+ Before writing any code:
50
+
51
+ - [ ] Confirm with user what interface changes are needed
52
+ - [ ] Confirm with user which behaviors to test (prioritize)
53
+ - [ ] Identify opportunities for [deep modules](deep-modules.md) (small interface, deep implementation)
54
+ - [ ] Design interfaces for [testability](interface-design.md)
55
+ - [ ] List the behaviors to test (not implementation steps)
56
+ - [ ] Get user approval on the plan
57
+
58
+ Ask: "What should the public interface look like? Which behaviors are most important to test?"
59
+
60
+ **You can't test everything.** Confirm with the user exactly which behaviors matter most. Focus testing effort on critical paths and complex logic, not every possible edge case.
61
+
62
+ ### 2. Tracer Bullet
63
+
64
+ Write ONE test that confirms ONE thing about the system:
65
+
66
+ ```
67
+ RED: Write test for first behavior → test fails
68
+ GREEN: Write minimal code to pass → test passes
69
+ ```
70
+
71
+ This is your tracer bullet - proves the path works end-to-end.
72
+
73
+ ### 3. Incremental Loop
74
+
75
+ For each remaining behavior:
76
+
77
+ ```
78
+ RED: Write next test → fails
79
+ GREEN: Minimal code to pass → passes
80
+ ```
81
+
82
+ Rules:
83
+
84
+ - One test at a time
85
+ - Only enough code to pass current test
86
+ - Don't anticipate future tests
87
+ - Keep tests focused on observable behavior
88
+
89
+ ### 4. Refactor
90
+
91
+ After all tests pass, look for [refactor candidates](refactoring.md):
92
+
93
+ - [ ] Extract duplication
94
+ - [ ] Deepen modules (move complexity behind simple interfaces)
95
+ - [ ] Apply SOLID principles where natural
96
+ - [ ] Consider what new code reveals about existing code
97
+ - [ ] Run tests after each refactor step
98
+
99
+ **Never refactor while RED.** Get to GREEN first.
100
+
101
+ ## Checklist Per Cycle
102
+
103
+ ```
104
+ [ ] Test describes behavior, not implementation
105
+ [ ] Test uses public interface only
106
+ [ ] Test would survive internal refactor
107
+ [ ] Code is minimal for this test
108
+ [ ] No speculative features added
109
+ ```
@@ -0,0 +1,33 @@
1
+ # Deep Modules
2
+
3
+ From "A Philosophy of Software Design":
4
+
5
+ **Deep module** = small interface + lots of implementation
6
+
7
+ ```
8
+ ┌─────────────────────┐
9
+ │ Small Interface │ ← Few methods, simple params
10
+ ├─────────────────────┤
11
+ │ │
12
+ │ │
13
+ │ Deep Implementation│ ← Complex logic hidden
14
+ │ │
15
+ │ │
16
+ └─────────────────────┘
17
+ ```
18
+
19
+ **Shallow module** = large interface + little implementation (avoid)
20
+
21
+ ```
22
+ ┌─────────────────────────────────┐
23
+ │ Large Interface │ ← Many methods, complex params
24
+ ├─────────────────────────────────┤
25
+ │ Thin Implementation │ ← Just passes through
26
+ └─────────────────────────────────┘
27
+ ```
28
+
29
+ When designing interfaces, ask:
30
+
31
+ - Can I reduce the number of methods?
32
+ - Can I simplify the parameters?
33
+ - Can I hide more complexity inside?
@@ -0,0 +1,31 @@
1
+ # Interface Design for Testability
2
+
3
+ Good interfaces make testing natural:
4
+
5
+ 1. **Accept dependencies, don't create them**
6
+
7
+ ```typescript
8
+ // Testable
9
+ function processOrder(order, paymentGateway) {}
10
+
11
+ // Hard to test
12
+ function processOrder(order) {
13
+ const gateway = new StripeGateway();
14
+ }
15
+ ```
16
+
17
+ 2. **Return results, don't produce side effects**
18
+
19
+ ```typescript
20
+ // Testable
21
+ function calculateDiscount(cart): Discount {}
22
+
23
+ // Hard to test
24
+ function applyDiscount(cart): void {
25
+ cart.total -= discount;
26
+ }
27
+ ```
28
+
29
+ 3. **Small surface area**
30
+ - Fewer methods = fewer tests needed
31
+ - Fewer params = simpler test setup
@@ -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,10 @@
1
+ # Refactor Candidates
2
+
3
+ After TDD cycle, look for:
4
+
5
+ - **Duplication** → Extract function/class
6
+ - **Long methods** → Break into private helpers (keep tests on public interface)
7
+ - **Shallow modules** → Combine or deepen
8
+ - **Feature envy** → Move logic to where data lives
9
+ - **Primitive obsession** → Introduce value objects
10
+ - **Existing code** the new code reveals as problematic
@@ -0,0 +1,61 @@
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
+ ```