Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .changeset/conformance-rule-defect-outcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"@thomasfosterau/effect-jsonapi": minor
---

A `Conformance` rule that dies no longer loses the whole report. In 0.16.3 a defect in any one rule (a transport that throws, or a bug in the kit) failed `Conformance.verify` / `verifyWith` outright, so every other rule's outcome — and, with this release's write fixture, the `Report.writes` ledger of what the kit created and whether it was removed — went unreported. The rule now gets a new `Errored` outcome (`Conformance.Outcome` gains a fourth member, `{ _tag: "Errored", rule, message, defect }`), every other rule still runs and is reported in the suite's order, and `Report.writes` is still filled. That holds whether the rule dies inside its Effect or throws before returning one. Interruption is not turned into an outcome: it still stops the run. A write fixture that throws is not a defect and never was: a `create` or `update` that throws skips the rules it would have driven, and a `cleanup` that fails or throws is recorded in `Report.writes` as `cleanup-failed`.
A `Conformance` rule that dies no longer loses the whole report. In 0.16.3 a defect in any one rule (a transport that throws, or a bug in the kit) failed `Conformance.verify` / `verifyWith` outright, so every other rule's outcome — and, with this release's write fixture, the `Report.writes` ledger of what the kit created and whether it was removed — went unreported. The rule now gets a new `Errored` outcome (`Conformance.Outcome` gains a fourth member, `{ _tag: "Errored", rule, message, defect }`), every other rule still runs and is reported in the suite's order, and `Report.writes` is still filled. That holds whether the rule dies inside its Effect or throws before returning one. Interruption is not turned into an outcome: it still stops the run. A write fixture that throws a value the kit can render is not a defect: a `create` or `update` that throws one skips the rules it would have driven, and a `cleanup` that fails with or throws one is recorded in `Report.writes` as `cleanup-failed`. One that throws a value the kit can't render (a revoked `Proxy`, say) is still reported as `Errored` until #271.

**Behaviour change:** before, a dying rule failed the whole run; now the run succeeds with an `Errored` outcome, so a caller who gates on `summarise(report).failed`, `findings(report)` or `_tag === "Failed"` passes silently. If you gate on `failed`/`findings` rather than `Conformance.assert`, also check `summarise(report).errored === 0`.

`format` prints such a rule first in its tier, marked `DIED` with the defect's message (an `Error` as `Name: message`, any other thrown value as itself), and adds `· N died` to the tier and summary lines when one did (a run in which nothing died prints as before); `summarise` gains an `errored` count. `assert` dies on the first `Errored` outcome — with a defect tagged `RuleDied` (match it with `Predicate.isTagged(defect, "RuleDied")`) carrying the rule's id, a message naming the rule and the defect, and the original defect as its `cause` — before looking at failures, so the gate stays as strict as when the defect killed the run.
`format` prints such a rule first in its tier, marked `DIED` with the defect's message (an `Error` as `Name: message`, any other thrown value as itself; capped at 500 UTF-16 code units, a longer one ending in `…`; and `[unrenderable defect]` for a value that throws when inspected — a revoked `Proxy`, say — which still leaves the run complete), and adds `· N died` to the tier and summary lines when one did (a run in which nothing died prints as before); `summarise` gains an `errored` count. `assert` dies on the first `Errored` outcome — with a defect tagged `RuleDied` (match it with `Predicate.isTagged(defect, "RuleDied")`) carrying the rule's id, a message naming the rule and the defect, and the original defect as its `cause` — before looking at failures, so the gate stays as strict as when the defect killed the run.

A `switch` over `Outcome._tag` that relies on exhaustiveness needs an `Errored` case.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ Two tiers, separately runnable. `spec` is JSON:API v1.1 alone; `profile` is this

**It says what it did not check.** Every rule that could not run reports why — no endpoint of that shape, no sample id, no write fixture, a mutating probe not opted into — and `Conformance.gaps` declares the areas the kit does not cover at all (filter _evaluation_ semantics, pagination-link and sort-ordering correctness, the write rules beyond the success responses, atomic processing), each with its reason and tracking issue. Both are printed in every report, and skips are counted separately from passes, so a run that proved little cannot read as a clean bill of health.

**A rule that dies does not cost you the report.** A defect in one rule — a transport that throws, or a bug in the kit — becomes that rule's `Errored` outcome (printed as `DIED`, with the defect's message, and counted as `errored` by `Conformance.summarise`); every other rule still runs and is reported, and so is `report.writes`. Interruption is not caught: it still stops the run, after the cleanup of whatever the interrupted rule created. A write fixture that throws is not a defect: a `create` or `update` that throws skips the rules it would have driven, and a `cleanup` that fails is recorded in `report.writes`.
**A rule that dies does not cost you the report.** A defect in one rule — a transport that throws, or a bug in the kit — becomes that rule's `Errored` outcome (printed as `DIED`, with the defect's message, and counted as `errored` by `Conformance.summarise`); every other rule still runs and is reported, and so is `report.writes`. Interruption is not caught: it still stops the run, after the cleanup of whatever the interrupted rule created. A write fixture that throws a value the kit can render is not a defect: a `create` or `update` that throws one skips the rules it would have driven, and a `cleanup` that fails with one is recorded in `report.writes`. One that throws a value the kit can't render (a revoked `Proxy`, say) is still reported as `Errored` until [#271](https://github.com/thomasfosterau/effect-jsonapi/issues/271).

Use `Conformance.assert(report)` as a gate: it fails with a `ContractViolation` carrying the rule, its requirement, its citation and the request that decided it. A rule that died is not a finding about your server, but the run could not decide it either, so `assert` dies on it — with a defect tagged `RuleDied` naming the rule and the defect, the original as its `cause` — rather than passing. If you gate on `summarise(report).failed` or `findings(report)` instead of `assert`, also check `summarise(report).errored === 0`.

Expand Down
2 changes: 1 addition & 1 deletion docs/conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Conformance.verify(api, {
What the kit promises in return:

- **It refuses an id it evidently did not create.** Every write rule creates its own disposable target from `create` — the update rule PATCHes it, the delete rule DELETEs it — and acts on the id the server's create response named only after checking it: the response must name a resource of the type `create` returned (`data.type`, or `atomic:results[0].data.type` for an `add`), under an id that is a URL path segment of its own (not `""`, `.` or `..`, which `encodeURIComponent` leaves alone and URL normalisation turns into the collection or `/`, nor a lone surrogate, which no URL can carry), that is not an `ids` sample, that no successful `GET` earlier in the run returned (as primary data, in `included`, or as a relationship's linkage) unless the kit had already taken it from a create of its own, and that the run does not already hold a resource for that has not been removed (two live resources cannot share an id, so one of the two answers is wrong). Any other id is recorded as `left`, with `detail` naming what was named — "named `people:1`, which the kit did not create … — not touched" — and is never PATCHed, DELETEd or handed to `cleanup`; the rules that would have acted on it skip, saying so. An id the server hands out again once the kit has removed its first holder — a `size + 1` store, a SQLite rowid — is accepted, because refusing it would leave every later resource behind. (Before the fixture, `mutating: true` made the delete rule delete the `ids` sample.) Every rule that creates nothing (the profile tier's included) runs before the first rule that creates, so a create is checked against everything the run reads; the report keeps the suite's order. The read check can refuse falsely: linkage can name a resource since deleted, and a server that reuses ids may hand that id to the kit's create. That fails safe — the resource is recorded as `left` with a `detail` saying why, and the rules that would have acted on it skip.
- **Cleanup runs however the rule ends.** Each target is created inside `Effect.acquireUseRelease`, so `cleanup` runs after the rule that made it whether that rule passed, failed or died. A cleanup that fails is recorded, not propagated, so one bad cleanup cannot cost the run its report.
- **Cleanup runs however the rule ends.** Each target is created inside `Effect.acquireUseRelease`, so `cleanup` runs after the rule that made it whether that rule passed, failed or died. A cleanup that fails with a value the kit can render is recorded, not propagated, so one bad cleanup cannot cost the run its report; one that fails with a value the kit can't render (a revoked `Proxy`, say) is still reported as its rule's `Errored` outcome until [#271](https://github.com/thomasfosterau/effect-jsonapi/issues/271).
- **The run is auditable.** `Report.writes` lists every resource the kit created, the rule that created it and what became of it — `deleted` by the kit's own DELETE, `cleaned-up`, `cleanup-failed` with the cause, or `left`. `format` prints them under `WRITES`, with the count still in place.
- **Each sub-key gates only its own rules.** A type with no `create` skips every write rule naming `writes["<type>"].create`, exactly as a missing `ids` entry does; a create-only type omits `update` and skips only the update rule. Never a vacuous pass.
- **A rejected payload is not a verdict.** If the server does not accept `create` (a 4xx, say), the rules it was for report `Skipped` with the status and body — the fixture is wrong or the server is, and the kit cannot tell which.
Expand Down
Loading
Loading