mocking-stubbinglisted
Install: claude install-skill charliehzm/medharness
# Mocking Stubbing
The "tests must pass against synthetic data" gate.
## Mock layers
| Layer | What's mocked | How |
|---|---|---|
| DB | All persistence | sqlite-in-memory or testcontainers + synthetic fixtures |
| External APIs | Hospital HIS / 3rd party | responses library / wiremock |
| LLM | Model calls | deterministic stub via mcp-model-router test mode |
| Time | clocks | freezegun / fake clock |
| Storage | Object store | localstack / minio |
## Discipline
- **No real service contacted during Step 9**. If a test "needs prod", the test is wrong.
- **No real PHI in fixtures** (enforced upstream by `test-data-generation`).
- **Deterministic** — LLM stubs return canned responses; flaky tests are bugs.
## Workflow
1. Load fixtures from `mock/阶段N-*/`.
2. Stand up mock services (script: `scripts/test/up_mocks.sh`).
3. Run test pyramid: unit → integration → e2e.
4. Collect results as JUnit XML.
5. If green → emit TEST_REPORT.md + hand off to Step 10.
6. If red → hand off to `systematic-debugging`.
## Common failure modes
1. **"Just this once" real call** — test reaches real LLM. Mitigation: hooks block production endpoints in test env.
2. **Flaky LLM stub** — random response in stub. Mitigation: deterministic by seed.
3. **Fixture drift** — fixtures stale vs schema. Mitigation: schema-driven generation.
4. **Mock leak** — test uses real env var. Mitigation: explicit env clear before each test.