未載入 Skill5146 tokens · 77182 ms
I have not read your repository — this is an assessment of the two cases as you described them. Where a verdict depends on code I can't see, I've named the specific thing to check.
---
## Terminology I'm holding to
- **Seam** — a place where you can substitute behavior without editing the code in place.
- **Port / interface** — the declared shape (`charge(request): ChargeResult`).
- **Adapter** — an implementation that *translates* between your vocabulary and a foreign system's vocabulary.
- **Implementation** — any type satisfying the interface. Every adapter is an implementation; most implementations are not adapters.
This distinction does the real work below, because `FakePaymentAdapter` is misnamed: it adapts nothing. It is an implementation of the port with no foreign system on the other side. Only `StripePaymentAdapter` is an adapter.
---
## 1. Payment: `StripePaymentAdapter` / `FakePaymentAdapter`
### Is the seam real? — Yes, but not for the reason the code suggests
The seam is justified by what sits behind `StripePaymentAdapter`, not by the fact that two types satisfy the interface. Stripe is out-of-process, non-deterministic, rate-limited, latency-bearing, costs money, and can fail in a state where you *don't know* whether the charge happened. Any one of those makes substitution necessary; together they make it non-negotiable.
What is **not** evidence: "there are two implementations." One production adapter plus one fake you wrote yourself is the weakest possible support for an interface — the fake was shaped to fit the port, so it cannot disconfirm the port's design. Two independent adapters (Stripe + Adyen) would be evidence. A fake is not a second data point; it is a consequence of the first.
So: seam real, evidence for it misattributed. That matters because the same reasoning applied to `EmailFormatter` ("it has an interface, so it must need one") is what produced the second problem.
### Is the interface deep enough? — Conditionally, and the condition is `ChargeResult`
`charge(request): ChargeResult` is a *narrow* signature hiding a *large* amount of machinery, which is the correct shape. Depth here is decided entirely by whether `ChargeResult` is a domain-owned type or a Stripe-shaped one.
Check for these; each one means the interface is shallower than it looks:
- Stripe identifiers or Stripe enum values (`payment_intent.status`, raw `decline_code`) appearing in `ChargeResult`.
- `success: boolean` plus a free-form `errorCode: string` — this pushes interpretation back onto every caller and makes the fake unable to reproduce real semantics.
- **No representation of the indeterminate outcome** (request sent, response lost, charge state unknown). This is the most common depth failure in payment ports. If `ChargeResult` can only say succeeded/declined, `FakePaymentAdapter` is structurally incapable of simulating the failure mode most likely to lose you money, and the seam gives false confidence.
- Callers doing `switch` on strings that originate from Stripe.
A deep version enumerates *your* outcomes: authorized, captured, declined-with-domain-reason, requires-customer-action (SCA/3DS), retryable-failure, indeterminate. Stripe's vocabulary is then confined to the adapter's translation layer — which is what makes it an adapter rather than a pass-through.
### Where should testing happen?
Three surfaces, non-overlapping:
1. **Domain and use-case tests, against the port, using the fake.** The bulk of your tests. These assert *your* policy: what the order does after a decline, whether you retry, whether you double-charge under concurrent submits. The fake exists to make these fast and deterministic — nothing else.
2. **A shared contract test suite, run against both implementations.** One suite, two subjects: `StripePaymentAdapter` (against Stripe test mode, or recorded interactions) and `FakePaymentAdapter`. This is the load-bearing piece. Without it, the fake drifts from the adapter's real semantics and every green test in category 1 is asserting against a fiction. If you adopt one recommendation from this analysis, adopt this one.
3. **Adapter-only integration tests for `StripePaymentAdapter`.** Error-code translation, idempotency-key propagation, timeout handling, webhook/status reconciliation. These are about the *translation*, which is precisely the part no other implementation shares.
Anti-pattern to avoid: mocking the Stripe SDK *inside* `StripePaymentAdapter`'s tests. That tests your mock's configuration, not the translation. The adapter is the one place where a real (test-mode) dependency earns its cost.
### Recommendation: **keep**, with three changes
- Rename to separate the concepts: port `PaymentGateway`; adapter `StripePaymentGateway`; fake `InMemoryPaymentGateway` (or `FakePaymentGateway`) — dropping "Adapter" from the fake, since it adapts nothing.
- Move the fake into test fixtures if it currently ships in production source. A fake in the production module invites someone to wire it up.
- Deepen `ChargeResult` into domain-owned outcomes, explicitly including the indeterminate case, and add the shared contract suite.
---
## 2. `EmailFormatter` — one implementation, delegating to `template.replace`
### Is the seam real? — No
Three tests, all failing:
- **Nothing varies.** One implementation, no second one pending.
- **Nothing is crossed.** No process, no network, no clock, no randomness, no cost. `template.replace` is a pure library call.
- **Nothing needs substituting in tests.** A pure function is already fully controllable via its arguments. A seam buys you control you already have.
This is also not an adapter, and calling it one is the source of the confusion. An adapter translates between your model and a *foreign system's* model. A string-library call is not a foreign system; it is your own language. What exists here is a single implementation dressed in adapter clothing.
### Is the interface deep enough? — No; it has negative depth
The interface is one declaration, one registration/wiring site, and one indirection at every call site. What it hides is one line. The abstraction is larger than the thing abstracted — the textbook shallow module. It also costs real readability: someone tracing an email bug has to resolve an interface to discover the answer is "it calls replace."
### Where should testing happen?
Directly at the function, table-driven: template plus values in, string out. Cover the cases that actually bite — missing placeholder, unmatched token left in output, escaping, empty values. No doubles, no injection.
If any current caller injects a mock `EmailFormatter`, delete those assertions. A test that stubs the formatter to return `"hi"` and then asserts the email body is `"hi"` is verifying the stub configuration, which is tautological.
### Recommendation: **delete the interface, keep the code**
Collapse to a plain module-level function called directly. Delete the interface declaration, the wiring, and any registration entry. Keep a concrete type only if there is genuine shared state or logic (escaping rules, locale tables) that would otherwise be duplicated.
**What would reverse this verdict:** localization, HTML vs. plaintext variants, MJML rendering, or an external template service (a Handlebars server, Braze). If any of those is actually scheduled — not merely imaginable — the seam becomes real, but note it would sit at the *template-rendering* step, not at "format an email." Introduce it when the second implementation arrives, and derive the interface from both implementations rather than extrapolating from one. Predicting the shape of an interface from a single example is how the current one got its shape.
One thing worth checking: if email *sending* lives somewhere in this module, that is the genuine seam here (out-of-process, costly, non-deterministic — the same argument as payment). The formatter is not, and may have absorbed attention that belongs to the sender.
---
## The rule the two cases jointly imply
Justify a seam by the *nature of the collaborator* — does it cross out of your process, out of determinism, out of free — and justify the *interface* by the ratio of what it hides to what it exposes. Payment passes both. Email formatting passes neither.
Implementation count is not evidence, and a fake you authored is not an implementation for this purpose. `FakePaymentAdapter` counts toward the payment seam's *usefulness* but contributes nothing to its *justification* — and the habit of treating it as justification is what makes `EmailFormatter` look defensible.