# The check

> What `cases check` compares, where the code side comes from, and what it reports.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/contract/the-check/

For agents: `cases check` inputs: the map files (validated with the JSON Schema; navigation tree; event graph), the code side (Sypnorm use cases from `cases map --json`; and code without Sypnorm: `Case: <id>` trailers of the last 2000 commits and `// case: <id>` notes in the sources, also with #, /* or <!--), cases/plan.md (milestones: unbuilt; with --contract a milestone naming no case is broken-promise), production (the last 30 days of environment=production from Sypnia Telemetry when map.yaml app.telemetry or [cases] telemetry names the project and SYPNIA_TELEMETRY_TOKEN holds a read token; SYPNIA_TELEMETRY_API for another engine; without a token an info finding says so; --no-telemetry skips it), optionally the contract (--contract). Findings (errors unless marked): invalid, unmapped, unbuilt, drift, broken-promise, orphan (no starts), unknown-place, where-not-in-app, place-actor, nav-cycle, unknown-event, old-version (warning while an old event version is still emitted, error after its 90 days), internal-outcome, self-subscription, loop, breaking-change, undeclared-outcome, missing-outcome (a declared outcome the code never ends in, warning), unused-outcome (info), ai-task-unlisted, ai-task-unused, files-unlisted, files-unused, mail-unlisted, mail-unused, no-place (warning), and from production nav-missing-edge, nav-unreached, nav-unknown-route, case-unused (warnings), undeclared-outcome and unmapped (errors; runtime endings such as error, WindowExpired, LoopStopped never count). Output: a list of findings (kind, case id, file:line, message), exit 1 on errors; --json for machines; --ci for annotations. Table names compare by singular and plural (product = products); a use case whose code names no table is not compared on data; caseIds alone check the map by itself and report unknown ids as unmapped. Runs locally, in CI, and on the Cases server on every proposal.

```bash
npx @sypnia/cases check                # the map is valid, and the code matches it
npx @sypnia/cases check --contract     # also the landing and the plan
npx @sypnia/cases check --json         # for machines
npx @sypnia/cases check --no-telemetry # without production
```

## What it compares

1. **The map against its schema.** Every file is valid, every id is unique, every actor, area, case, place and event a file names exists.
2. **The map against itself.** Every case has a start and at least one outcome; the navigation tree has one parent per place and no cycles; the event graph has no loop without a stop, no case listening to itself, and no area listening to another area's internal outcome.
3. **The map against the code.** The code side comes from one of two places:
   - **[Sypnorm](https://cases.docs.sypnia.com/sypnorm)** (best): `npx @sypnia/cases map --json` lists every `useCase` with its actor, input, the tables it touches, the outcomes and failures it can end in, and who is allowed. The check matches them to cases by id. Table names compare by singular and plural, so `product` in a case file is the table `products` in the code. A use case whose code names no table (a fresh skeleton) is not compared on data.
   - **Code without Sypnorm** (any language): a commit among the last 2000 carries a trailer `Case: place-order`, or a source file carries a note `// case: place-order` (also after `#`, `/*` or `<!--`). The check learns which cases have code; it cannot compare data or outcomes. An id no case has is `unmapped`. Sent alone to the server's check (`caseIds`), the map is checked by itself, and an id it does not have is reported as `unmapped`.
4. **The plan.** `cases/plan.md` lists the milestones and their cases ([The contract](https://cases.docs.sypnia.com/contract/the-contract#the-plan)). An approved case of a delivered milestone with no code is `unbuilt`; a case whose `status` is `idea` or `retired` is skipped.
5. **Production**, with the map linked to [Telemetry](https://cases.docs.sypnia.com/links/telemetry): `app.telemetry` in `map.yaml`, or `telemetry` in the `[cases]` table of `sypnia.toml`, names the Telemetry project, and `SYPNIA_TELEMETRY_TOKEN` holds a read token of it (`SYPNIA_TELEMETRY_API` for an engine other than Sypnia Cloud's). The check reads the last 30 days of `environment=production`: real moves against the navigation tree, the cases that ran, and the outcomes seen against the outcomes declared. Endings the runtime records itself (`error`, `WindowExpired`, `LoopStopped`) are never a gap. Without a token the check says so, as information, and goes on; `--no-telemetry` skips it.
6. **The contract** (`--contract`): promises and milestones, as in [The contract](https://cases.docs.sypnia.com/contract/the-contract).

## What it reports

```text
✗ unmapped   GiftCardRedeem            src/cases/gift-cards.ts:12   no case describes this use case
✗ drift      place-order               writes customer_points       the case does not list it
✗ orphan     resume-deliveries         cases/deliveries/resume-deliveries.case.yaml   no starts: nothing can run it
✓ 18 cases match the code
1 waiver applies (rebuild-search-index, until 2027-03-01)
```

## Every finding

| Finding                          | Level               | What it means                                                                                                                                                                                                                                                                                                                               |
| -------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `invalid`                        | error               | a file does not match the format; the message says the file and the field                                                                                                                                                                                                                                                                   |
| `unmapped`                       | error               | code, a `Case:` trailer, a `// case:` note or production names a use case no case describes ([Scope errors](https://cases.docs.sypnia.com/contract/scope-errors))                                                                                                                                                                           |
| `unbuilt`                        | error               | an approved case in a delivered milestone of `cases/plan.md` has no code (a use case, a trailer or a note)                                                                                                                                                                                                                                  |
| `drift`                          | error               | code and case disagree on data, outcomes, failures or allowed actors                                                                                                                                                                                                                                                                        |
| `broken-promise`                 | error               | the landing promises something with no cases, or a milestone of the plan names no case (`--contract`)                                                                                                                                                                                                                                       |
| `orphan`                         | error               | a case has no `starts`: nothing can run it                                                                                                                                                                                                                                                                                                  |
| `unknown-place`                  | error               | a case's `where` is not in the navigation map                                                                                                                                                                                                                                                                                               |
| `where-not-in-app`               | error               | a case with `where` does not start `in_app`                                                                                                                                                                                                                                                                                                 |
| `place-actor`                    | error               | the case's actor does not come in through the root of its place                                                                                                                                                                                                                                                                             |
| `nav-cycle`                      | error               | following parents in the navigation map never reaches a root                                                                                                                                                                                                                                                                                |
| `unknown-event`                  | error               | a case listens to an outcome no case declares                                                                                                                                                                                                                                                                                               |
| `internal-outcome`               | error               | a case listens to another area's outcome that the area did not make public                                                                                                                                                                                                                                                                  |
| `self-subscription`              | error               | a case listens to its own outcome                                                                                                                                                                                                                                                                                                           |
| `loop`                           | error               | a cycle of events with no bounded loop ([Loops](https://cases.docs.sypnia.com/runtime/loops))                                                                                                                                                                                                                                               |
| `breaking-change`                | error               | an outcome's payload changed in a way that breaks its listeners, under the same version                                                                                                                                                                                                                                                     |
| `old-version`                    | warning, then error | a case listens to an old version of an event: a warning with the days left while both versions are emitted, an error once the 90 days are over and the old version is no longer emitted ([Versions](https://cases.docs.sypnia.com/map/outcomes-and-events#versions))                                                                        |
| `undeclared-outcome`             | error               | the code, or production, ends in an outcome or failure the case does not declare (a gap in the map)                                                                                                                                                                                                                                         |
| `missing-outcome`                | warning             | a declared outcome the code never ends in                                                                                                                                                                                                                                                                                                   |
| `ai-task-unlisted`               | error               | the case calls a Sypnia AI task it does not list in `ai.tasks`                                                                                                                                                                                                                                                                              |
| `ai-task-unused`                 | warning             | the case lists an AI task it never calls                                                                                                                                                                                                                                                                                                    |
| `files-unlisted`, `files-unused` | error, warning      | the case writes or reads a Files bucket it does not list, or lists one it never uses                                                                                                                                                                                                                                                        |
| `mail-unlisted`, `mail-unused`   | error, warning      | the case sends a Mail template it does not list, or lists one it never sends                                                                                                                                                                                                                                                                |
| `no-place`                       | warning             | a case that starts `in_app` has no `where`, in an app with a navigation map                                                                                                                                                                                                                                                                 |
| `unused-outcome`                 | info                | an outcome of an `external` or `scheduled` case nothing listens to, and nobody waits for                                                                                                                                                                                                                                                    |
| `nav-missing-edge`               | warning             | people moved between two places with no way between them on the map. A move is along the tree when it goes to a child, back up the chain, to a sibling (another tab of the same screen), to a root, or along a shortcut ([The navigation map](https://cases.docs.sypnia.com/map/navigation#generated-from-the-code-checked-by-real-clicks)) |
| `nav-unreached`                  | warning             | nobody reached a place of the map in 30 days                                                                                                                                                                                                                                                                                                |
| `nav-unknown-route`              | warning             | people visited a route that no place marks                                                                                                                                                                                                                                                                                                  |
| `case-unused`                    | warning             | a case on the map that never ran in 30 days: not built, not reachable or not used                                                                                                                                                                                                                                                           |

`ai-task-*`, `files-*` and `mail-*` need the project linked to [Sypnia AI](https://ai.docs.sypnia.com/using/cases-and-traces/), [Files](https://files.docs.sypnia.com/buckets/use-cases/) or [Mail](https://mail.docs.sypnia.com/events/use-cases/); `nav-*`, `case-unused`, and `undeclared-outcome` or `unmapped` from production need [Telemetry](https://cases.docs.sypnia.com/links/telemetry).

Exit code `1` when there is any error, `0` otherwise. With `--ci` it writes annotations that GitHub, Sypnia Git and Sypnia Run show on the lines.
