@boopkit/cap-testing 0.1.0 → 0.3.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/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @boopkit/cap-testing
2
+
3
+ **Part of [Boop](https://www.npmjs.com/package/@boopkit/cli)** — a bootstrap platform for AI-first builders. `boop init` scaffolds a running Node/TypeScript web app from composable **capabilities**, each one bundling the code, dependencies, middleware wiring, and agent skills needed for a feature. You pick the capabilities; `boop add` handles the rest.
4
+
5
+ `cap-testing` sets up Jest for a TypeScript project and installs the testing skills agents need to use it well. It's mostly skills — the testing philosophy, the Light TDD loop, and Express-specific patterns — with a small scaffold so `npm test` works from the first commit.
6
+
7
+ ## What You Get
8
+
9
+ Agent skills plus a minimal Jest + ts-jest scaffold. The scaffold is intentionally thin: one sample test, one config file, one test-specific tsconfig — enough that `npm test` runs green on day one and new tests follow a known layout.
10
+
11
+ ### Scaffold files
12
+
13
+ Copied into your project on install:
14
+
15
+ - `jest.config.js` — ts-jest preset, Node test environment, test matcher at `tests/**/*.test.ts`
16
+ - `tsconfig.test.json` — extends your project tsconfig and includes `tests/`
17
+ - `tests/app.test.ts` — a starter test asserting the Express app boots and has body parsing wired
18
+
19
+ ### Scripts added to `package.json`
20
+
21
+ | Script | Command |
22
+ |--------|---------|
23
+ | `test` | `jest --runInBand` |
24
+ | `test:watch` | `jest --watch` |
25
+
26
+ ### Skills installed
27
+
28
+ Copied into `skills/` on install:
29
+
30
+ - `test.testing.skill.md` — the testing philosophy: functional tests over ceremony, observe failures before claiming success, mocks as a last resort, and a checklist for when the spec is silent (resolve the ambiguity first, then test).
31
+ - `test.tdd-light.skill.md` — the Red → Green → Verify loop, including bug fixes (write the failing test before the fix).
32
+ - `test.testing-express-web.skill.md` — Express-specific guidance: how to run focused Jest commands, test file layout, and patterns for services, controllers, middleware, and HTTP routes.
33
+
34
+ ## Requirements
35
+
36
+ **Other capabilities:** none. The sample test expects `src/app` to export an Express app, which is provided by `cap-api` in the default `web-app` profile. If you add `cap-testing` to a project without an Express app, edit or delete `tests/app.test.ts`.
37
+
38
+ **npm devDependencies added to your project:**
39
+
40
+ - `jest` — test runner
41
+ - `ts-jest` — TypeScript preset for Jest
42
+ - `@types/jest` — TypeScript types for Jest
43
+
44
+ **Environment variables:** none required for the scaffold. Individual tests may need service credentials (the Express testing skill documents the integration-test prerequisites — local Postgres, etc.) — those are project-specific and not enforced by this capability.
45
+
46
+ ## Usage
47
+
48
+ Run the suite:
49
+
50
+ ```bash
51
+ npm test # full suite, serialized
52
+ npm run test:watch # watch mode
53
+ ```
54
+
55
+ Targeted runs (documented in `test.testing-express-web.skill.md`):
56
+
57
+ ```bash
58
+ npx jest tests/services/foo.test.ts --no-coverage
59
+ npx jest tests/services/foo.test.ts -t "handles replay"
60
+ ```
61
+
62
+ New tests go under `tests/`, mirroring the `src/` layout (`tests/services/foo.test.ts` for `src/services/foo.ts`). The three skill files are the canonical guide — agents should read `test.testing.skill.md` for philosophy before writing any test, `test.tdd-light.skill.md` to stay in the Red → Green → Verify loop, and `test.testing-express-web.skill.md` for the project-specific layout and commands.
63
+
64
+ ## Added by
65
+
66
+ Included by default in the `web-app` profile.
67
+
68
+ Add to an existing project with:
69
+
70
+ ```bash
71
+ boop add testing
72
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boopkit/cap-testing",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Jest testing setup and testing skills for AI agents",
5
5
  "files": [
6
6
  "scaffold/",
@@ -1,9 +1,9 @@
1
1
  # Light TDD Flow
2
- When you need to build features or implement changes, follow the Light TDD Flow:
2
+ When you need to build features, implement changes, or fix bugs, follow the Light TDD Flow. This includes bug fixes found during UAT — write the failing test *before* applying the fix.
3
3
 
4
4
  Red → Green → Refactor. Document "before" and "after" states.
5
5
 
6
- 1. **Red**: Run/write tests that expose the gap (failing test for new feature, reproduced bug, baseline metric). Verify that issues is *observed* and that tests fail for the expected reason. Document the "before" state.
6
+ 1. **Red**: Run/write tests that expose the gap (failing test for new feature, reproduced bug, baseline metric). Verify that the issue is *observed* and that tests fail for the expected reason. Document the "before" state. **For bug fixes**: write a test that reproduces the exact failure, then confirm it fails for the right reason before touching the implementation.
7
7
  2. **Green**: Implement the minimum change. Add any additional tests.
8
8
  3. **Verify**: Re-run all tests from steps 1-2. Type-checking alone is **not sufficient** — functional tests must pass. Check for regressions in related functionality. Verify from the user's perspective — don't just test internal state. For example, if the feature writes files the user interacts with, verify those files exist and are correct.
9
9
 
@@ -48,6 +48,8 @@ When the shared boundary is the filesystem or an in-memory data structure (CLI t
48
48
 
49
49
  ### Mock boundaries
50
50
 
51
+ Mocks are helpful for isolating orchestration logic, but their limitations must be recognized: a mock silently accepts anything, so it cannot catch failures that occur at real system boundaries. When you use a mock, acknowledge what it *doesn't* cover and ensure integration tests fill the gap.
52
+
51
53
  | Mock this | Don't mock this |
52
54
  |---|---|
53
55
  | Third-party HTTP (email, OAuth) | Adjacent services you own (use real `getServices()`) |
@@ -64,6 +66,39 @@ When code is backed by a config table (patterns, routes, flags, enums):
64
66
 
65
67
  ---
66
68
 
69
+ ## Bug found during UAT
70
+
71
+ When a bug is discovered through manual testing or UAT, follow this checklist:
72
+
73
+ 1. **Reproduce** — confirm the failure and understand the root cause.
74
+ 2. **Find the test gap** — look for an existing test that *should* have caught it. If one exists, understand why it didn't (usually: it mocked the boundary where the failure lives).
75
+ 3. **Write a failing test first** — TDD applies to bug fixes, not just features. Write a test that reproduces the exact failure, confirm it fails for the right reason (Red), *then* apply the fix (Green). See [tdd-light.skill.md](test.tdd-light.skill.md).
76
+ 4. **Choose the right test level** — if the bug occurred at a system boundary (database, external API, serialization), the test must cross that boundary. A mock-based test cannot catch a boundary failure.
77
+
78
+ ---
79
+
80
+ ## Raw SQL and integration tests
81
+
82
+ Any service function that uses `$queryRaw` or `$executeRaw` **must have an integration test that runs against the real database**. Mock-based tests for raw SQL provide false confidence — the mock accepts any query shape, but the real database may reject it (wrong column types, deserialization failures, missing columns).
83
+
84
+ **Pattern**: insert fixture data via raw SQL or Prisma, call the function under test, assert the result, clean up in `afterAll`.
85
+
86
+ **Especially important for `Unsupported` columns**: Prisma columns marked `Unsupported(...)` (e.g., pgvector `vector(1536)`) will cause runtime deserialization errors if selected in `$queryRaw`. TypeScript won't catch this, and mocks won't catch this. Only a real DB query will.
87
+
88
+ ---
89
+
90
+ ## Schema contract testing
91
+
92
+ When code produces a schema or structure that is validated by an external system, test the schema against that system's documented rules — don't assume your code is the arbiter of truth.
93
+
94
+ **Pattern**: write a test that walks the schema and asserts every invariant the consuming system requires. No mocks, no API calls — just structural validation.
95
+
96
+ **Example**: OpenAI structured outputs with `strict: true` require `additionalProperties: false` on every object node. A test walks the schema tree and asserts the property exists on each object. This catches schema authoring mistakes before they reach the API.
97
+
98
+ **When to apply**: any time your code produces configuration, schemas, or structured data that an external system validates — OpenAI schemas, JSON Schema for APIs, database DDL consumed by migration tools, etc.
99
+
100
+ ---
101
+
67
102
  ## Subsystem Testing Skills
68
103
 
69
104
  | Subsystem | Skill |