@igor-guari/pi-skill-tdd 0.0.0-stage → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Matt Pocock
4
+ Copyright (c) 2025 Igor Guariroba
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,67 @@
1
- # Temporary Holding Version
1
+ # pi-skill-tdd
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Pi Package](https://img.shields.io/badge/pi--package-skill-blue)](https://github.com/IgorGuariroba/pi-skill-tdd)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+
6
+ Test-Driven Development (TDD) skill for the **[Pi coding agent](https://pi.dev)**, adapted from Matt Pocock's Engineering Skills.
7
+
8
+ This skill equips Pi with guidelines for the red → green loop: defining public seams, vertical slicing, avoiding tautological or implementation-coupled tests, and establishing disciplined testing habits.
9
+
10
+ ---
11
+
12
+ ## Installation
13
+
14
+ Install directly into Pi using `pi install`:
15
+
16
+ ```bash
17
+ pi install git:github.com/IgorGuariroba/pi-skill-tdd
18
+ ```
19
+
20
+ Or clone into your local/global skills directory:
21
+
22
+ ```bash
23
+ # Global Pi skills directory:
24
+ git clone https://github.com/IgorGuariroba/pi-skill-tdd.git ~/.pi/agent/skills/tdd
25
+
26
+ # Or Agent Skills standard path:
27
+ git clone https://github.com/IgorGuariroba/pi-skill-tdd.git ~/.agents/skills/tdd
28
+ ```
29
+
30
+ ---
31
+
32
+ ## How It Works
33
+
34
+ Pi automatically activates the skill when you ask to build features or fix bugs test-first, mention "red-green-refactor", or work with integration tests.
35
+
36
+ You can also trigger it explicitly:
37
+
38
+ ```text
39
+ /skill:tdd
40
+ ```
41
+
42
+ ### Core Principles
43
+
44
+ 1. **Seam-based testing**: Test only against pre-agreed public boundaries, never internals.
45
+ 2. **Vertical slices (tracer bullets)**: One test → one minimal implementation → repeat. Never write speculative tests in bulk.
46
+ 3. **Anti-pattern guards**: Eliminates tautological assertions and implementation coupling.
47
+ 4. **Mocking at system boundaries only**: Guidelines for external APIs, clocks, and databases while keeping application code real.
48
+
49
+ ---
50
+
51
+ ## Supporting References
52
+
53
+ - `tests.md`: Concrete examples of good integration-style tests vs. brittle implementation-detail tests.
54
+ - `mocking.md`: Clear guidelines on when to mock (system boundaries) and how to design for mockability using dependency injection and SDK interfaces.
55
+
56
+ ---
57
+
58
+ ## Credits
59
+
60
+ - **Original concept & methodology**: [Matt Pocock](https://github.com/mattpocock)
61
+ - **Adapted for Pi Agent**: [Igor Guariroba](https://github.com/IgorGuariroba)
62
+
63
+ ---
64
+
65
+ ## License
66
+
67
+ [MIT](LICENSE)
package/SKILL.md ADDED
@@ -0,0 +1,43 @@
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
+ license: MIT
5
+ metadata:
6
+ author: "Matt Pocock"
7
+ adapted_by: "Igor Guariroba"
8
+ version: "1.0.0"
9
+ ---
10
+
11
+ # Test-Driven Development
12
+
13
+ TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle: consult them before and during the loop, not after.
14
+
15
+ When exploring the codebase, read `GLOSSARY.md` (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you are touching.
16
+
17
+ ## What a good test is
18
+
19
+ 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 it survives refactors because it doesn't care about internal structure.
20
+
21
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
22
+
23
+ ## Seams: where tests go
24
+
25
+ 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.
26
+
27
+ **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, so agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
28
+
29
+ Ask: "What's the public interface, and which seams should we test?"
30
+
31
+ When the shape of that interface is itself in question (how deep the module is, where the seam belongs, what the interface should expose), refer to the `codebase-design` skill for 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.
32
+
33
+ ## Anti-patterns
34
+
35
+ - **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.
36
+ - **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.
37
+ - **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.
38
+
39
+ ## Rules of the loop
40
+
41
+ - **Red before green.** Write the failing test first, run it using the environment's test runner via `bash` to verify it fails for the expected reason, then write only enough code to pass it. Don't anticipate future tests or add speculative features.
42
+ - **One slice at a time.** One seam, one test, one minimal implementation per cycle.
43
+ - **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
package/mocking.md ADDED
@@ -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
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@igor-guari/pi-skill-tdd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Test-Driven Development skill for Pi Agent (adapted from Matt Pocock's Engineering Skills)",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi-skill",
8
+ "pi",
9
+ "tdd",
10
+ "test-driven-development",
11
+ "engineering-skills"
12
+ ],
13
+ "author": "Igor Guariroba",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/IgorGuariroba/pi-skill-tdd.git"
18
+ },
19
+ "homepage": "https://github.com/IgorGuariroba/pi-skill-tdd#readme",
20
+ "pi": {
21
+ "skills": [
22
+ "."
23
+ ]
24
+ },
25
+ "files": [
26
+ "SKILL.md",
27
+ "*.md"
28
+ ]
29
+ }
package/tests.md ADDED
@@ -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
+ ```