# The `.dstest` Test Language

The `.dstest` test language **surface**. Prefix `LTSL`.

This document specifies the author-facing surface of a DS test: the `test` block
and its `initial` / `inputs` / `responses` / `produces` sections, the time model,
and the construction-versus-matching rules. It is the language companion to the
runtime execution contract ([RTIM]), the lowering-to-atoms contract ([RLOW.17]), and
the compiled test-atom registry (the `Test*` / `Oracle*` families, [RDSC.7.1]). The
substrate a test runs over — the single deterministic clock, the event-trace
primitive, the introspection surface — remains specified in [LTES]; `.dstest` is
the author language over that substrate.

`.dstest` is the whole author-facing test surface ([LTES.7.6]).

---

(LTSL-1)=
## Model [LTSL.1]

(LTSL-1-1)=
### A declarative input→output relation [LTSL.1.1]

A `.dstest` is a declarative relation between an **input timeline** and the
**outputs a program must produce** — not a script. The author places facts on a
timeline (data) and declares the expected outputs (data); the runtime owns all
execution. A test must not sequence engine operations: the surface has no `pump`,
no `advance`-as-command, and no ordered mutation list.

This is sound because the runtime derives every engine operation from the
timeline. Pump cadence is an input the engine records ([RFCS.22]), and two
inputs pumped together can produce a different output from the same two inputs
pumped apart, so the cadence is not left free: at each stamp the runtime asserts
that stamp's inputs in source order ([LTSL.3.3]) and then pumps to quiescence
([LTSL.3.4], [RTIM.14.5]). The cadence, and with it every output, is therefore a
function of the timeline alone, and an author has nothing to sequence.

*see also:* [LTSL.3.3](#LTSL-3-3), [LTSL.3.4](#LTSL-3-4), [RFCS.22](#RFCS-22), [RTIM.14.5](#RTIM-14-5)

(LTSL-1-2)=
### Compiled, never parsed at runtime [LTSL.1.2]

The DS compiler — the only parser in the system — reads a `.dstest` and lowers it
to the `Test*` (scenario) and `Oracle*` (oracle) test-atom families ([RLOW.17.1], [RDSC.7.1]).
The runtime must not parse test source; the test-mode interpreter executes the
lowered atoms ([RTIM]), as it interprets every other atom family.

*see also:* [RDSC.7.1](#RDSC-7-1), [RLOW.17.1](#RLOW-17-1)

(LTSL-1-3)=
### Reuse of the DS surface [LTSL.1.3]

A `.dstest` reuses DS's own surface rather than introducing a second fact syntax.
Constructing a fact uses `emit`-style colon-keyword arguments; matching a fact uses
DS pattern syntax; a stubbed call uses the real `call <service> … as "<corr>"`
form. The construction-versus-matching split is [LTSL.4].

---

*see also:* [LTSL.4](#LTSL-4)

(LTSL-2)=
## File structure and discovery [LTSL.2]

(LTSL-2-1)=
### `test` is a top-level clause [LTSL.2.1]

`test` is a top-level declaration — one production alongside `schema`, `rule`,
`use` and `import` ([LGRA]). A `test "<name>":` block may
therefore appear inline in a `.ds` file, co-located with the rules it exercises, or
be collected in a `.dstest` file. There is one grammar. A `.ds` holds a program
plus any inline tests, and a `.dstest` holds `test` declarations and nothing
else. The compiler **must** refuse any other top-level declaration in a
`.dstest` with `DS_VALIDATE_TEST_COMPANION_DECL`, and a `use` directive with
`DS_VALIDATE_USE_IN_TEST` ([LDIA.2.10.6]).

*ratified*  —  *see also:* [LDIA.2.10.6](#LDIA-2-10-6)

(LTSL-2-2)=
### Project binding and discovery [LTSL.2.2]

The compiler discovers tests by **project membership**: beside each module the
program compiles, wherever its import resolves ([LTSL.2.4]). A test is **bound to its project**: it sees that project's schemas
and rules, and runs under the program-under-test's resolved settings
([LDIA.1.3]). A `.dstest` file has no `use` directive of its own
([LDIA.2.10.6]). Indentation, comments, and string and unit literals are DS's
([LLEX]).

*see also:* [LDIA.1.3](#LDIA-1-3), [LDIA.2.10.6](#LDIA-2-10-6), [LTSL.2.4](#LTSL-2-4)

(LTSL-2-4)=
### Which tests a program carries [LTSL.2.4]

A compile carries the tests of every module it compiles: the program and every
module in its import closure. A module's tests are the `test` blocks of its
`.ds` file and of its **companion** `.dstest`, the file in the same directory
with the same stem: `board_model.dstest` beside `board_model.ds`. The compiler
**must** read each compiled module's companion, wherever the module's import
resolves ([LIMP.3.1]): beside the program, in a `-L` directory, or in the
bundled library. It **must not** read any other `.dstest`, so a `.dstest` that
is no compiled module's companion is not part of the compile. A program's
project is therefore the program and its import closure.

A module's tests see what that module sees: its own declarations and what it
imports. The references [RLOW.17.3] binds resolve there, as a declaration in
the module would resolve them. The tests are lowered under the program's
resolved settings, as the module's rules are ([LDIA.1.3]), and each test's
`TestCase` carries its module's `module_id` ([RDSC.4.7]). A test belongs to its
module, whichever of the module's two files holds it.

*ratified*  —  *see also:* [LDIA.1.3](#LDIA-1-3), [LIMP.3.1](#LIMP-3-1), [RDSC.4.7](#RDSC-4-7), [RLOW.17.3](#RLOW-17-3)

(LTSL-2-3)=
### Block shape [LTSL.2.3]

A test block is a name and a set of sections (`test_decl`, [LGRA.21.1]):
`initial`, the starting state; `inputs`, the input timeline; `responses`, the
replies to outbound calls; and `produces`, the expected outputs.

A test block must contain a `produces` section; `initial`, `inputs`, and
`responses` are optional, and an optional top-level `until <dur>` ([LTSL.3.5]) may
also appear. A section keyword must not appear more than once per test. A test with
no `inputs` asserts only over time passage and must supply `until` to advance the
clock.

The compiler must refuse each violation, with its own code: a test with no
`produces` section with `DS_VALIDATE_TEST_NO_PRODUCES`; a section keyword
repeated within one test with `DS_VALIDATE_TEST_DUPLICATE_SECTION`; and a test
with neither `inputs` nor `until` with `DS_VALIDATE_TEST_NO_INPUTS_OR_UNTIL`. A
repeated section is refused, not merged or overridden.

---

*ratified*  —  *see also:* [LGRA.21.1](#LGRA-21-1), [LTSL.3.5](#LTSL-3-5)

(LTSL-3)=
## Time model [LTSL.3]

(LTSL-3-1)=
### Relative-offset coordinates [LTSL.3.1]

Timeline coordinates are duration-literal offsets from the test's start (`0_s`,
`5_min`, `100_ms`), grouped in `at <dur>:` blocks. Relative offsets drive the
**monotonic** engine clock that `ttl`, `cooldown`, and `then within` read. The
test runner must set the wall clock ([LTIM.2.8.3]) to the coordinate's offset from
the Unix epoch, so `at 5_s` is 1970-01-01T00:00:05Z, and it is the epoch itself at
the test's start. `now()` and an engine-filled `ts` ([LFAC.9.2]) read it.

*see also:* [LFAC.9.2](#LFAC-9-2), [LTIM.2.8.3](#LTIM-2-8-3)

(LTSL-3-2)=
### Absolute coordinates [LTSL.3.2]

A test may instead use absolute coordinates — a `calendar.time` call in the `at`
/ `until` position, e.g. `at calendar.time(2026, 6, 18, 14, 0, 0):` — when the
calendar date is load-bearing ([LTIM.14.1]). A test must use one mode
throughout, recorded on the compiled test case (`TestCase.absolute_time`).
An author testing a rule that reads the calendar from `now()` should use absolute
coordinates, since in relative mode the rule reads a date in 1970 ([LTSL.3.1]). An
absolute coordinate sets the wall clock to its instant and advances the monotonic
clock ([LTIM.2.8.2]) by the interval since the previous coordinate.

*see also:* [LTIM.14.1](#LTIM-14-1), [LTIM.2.8.2](#LTIM-2-8-2), [LTSL.3.1](#LTSL-3-1)

(LTSL-3-3)=
### `at <dur>:` grouping and same-stamp order [LTSL.3.3]

`at <dur>:`, permitted in `inputs` only, groups the facts that arrive at that
logical time. Source order within a block is the deterministic tie-break for
same-stamp facts, per [LDET.5], and is the only place source order is significant.

*see also:* [LDET.5](#LDET-5)

(LTSL-3-4)=
### No author-driven pump or advance [LTSL.3.4]

The surface has no `pump` and no `advance`. The runtime processes the timeline to
quiescence at each stamp and advances the clock across the union of all stamps,
firing `$ClockTick` and TTL sweeps along the way ([RTIM]).

(LTSL-3-5)=
### `until <dur>` [LTSL.3.5]

An optional top-level `until <dur>` extends the run past the last input stamp. It
is required only for a pure time-passage assertion that has no later input — for
example, that a `ttl` fact expires after a period of silence.

(LTSL-3-6)=
### Whole-run expectations [LTSL.3.6]

Expectations in `produces` are not stamped; the runtime checks them over the
whole run ([LTSL.8.1]).

*see also:* [LTSL.8.1](#LTSL-8-1)

(LTSL-3-7)=
### Absolute coordinates are folded at compile time [LTSL.3.7]

An absolute coordinate must be a `calendar.time` call whose arguments fold
([LTIM.14.3]). The compiler resolves it to `TestCase.when_ns` at **compile** time
([RLOW.17.1]), so the same `.dstest` compiles to the same instant on every host
([LDET.3.2]). The compiler must refuse with `DS_VALIDATE_TEST_BAD_TIMESTAMP` a
coordinate of any other form, one whose fold would raise [LTIM.14.2]'s fault,
and one before 1970-01-01T00:00:00Z, which `when_ns` cannot carry.

---

*see also:* [LDET.3.2](#LDET-3-2), [LTIM.14.2](#LTIM-14-2), [LTIM.14.3](#LTIM-14-3), [RLOW.17.1](#RLOW-17-1)

(LTSL-4)=
## Facts: construction versus matching [LTSL.4]

(LTSL-4-1)=
### Construction [LTSL.4.1]

In `initial`, `inputs`, and `responses` replies a fact is **constructed** in
emit-style: the schema name followed by colon-keyword slot values, with all
author-supplied slots given (`TempReading zone: "cellar" celsius: 2.0`). A
`responses` reply may leave out its `corr`, which the test runner then supplies
([LTSL.7.2]). A
constructed fact's slot values must be literals; the compiler lowers them to
literal slot values (`TestFact` / `TestReply` / `TestCacheSeed`, [RLOW.17.2]).

A literal is an `Int` or `Float` literal, optionally negated; a duration
literal; a `Bool`; a `String` with no interpolation site; or `json("…")` over
one string literal ([LGRA.9.8.3]). A `json()` argument's escapes are decoded
and its braces are literal text, not an interpolation site. Its text must be a
JSON value, and the test runner must refuse a scenario whose `json()` text does
not parse as one. The name of a `const` ([LGRA.4]) is admitted wherever a
literal is when its folded value is of a kind a literal writes: an `Int` or a
`Float`, a quantity's stored number among them ([LUNI.7.6]), a duration, a
`Bool`, a `String` or a `Json` value. The compiler folds it to that value. A
`const` of any other kind, a `Time` or a `Date` among them, is not admitted. The
compiler must refuse any other value with `DS_VALIDATE_TEST_NON_LITERAL`.

*ratified*  —  *see also:* [LGRA.4](#LGRA-4), [LGRA.9.8.3](#LGRA-9-8-3), [LTSL.7.2](#LTSL-7-2), [LUNI.7.6](#LUNI-7-6), [RLOW.17.2](#RLOW-17-2)

(LTSL-4-2)=
### Matching [LTSL.4.2]

In `produces` assertions and `for call` keys a fact is **matched** in DS pattern
style. A bare head with slot arguments is **partial (subset) equality** —
`emitted HeaterOn zone: "cellar"` matches any `HeaterOn` whose `zone` is
`"cellar"`, other slots free. A `where` clause — on the `emitted`
head ([LTSL.8.4]) — is a full DS predicate — `emitted TempReading t where
t.celsius > 40` — that binds the matched fact and evaluates the expression surface
([LEXP]); the predicate lowers to the same `Expr` trees a rule's own `where`
lowers to ([RDSC.4a.9]).

*see also:* [LTSL.8.4](#LTSL-8-4), [RDSC.4a.9](#RDSC-4a-9)

(LTSL-4-3)=
### Exact value match [LTSL.4.3]

Because every v1 construct is EXACT — cross-platform byte-identical ([LDET.3.2]) —
a float slot value matches exactly.

A test compares a literal with an observed value in three places: a
subset-matching head's slots ([LTSL.8.2]), a `for call` stub's argument keys
([LTSL.7.2]) and a `cached` head's value. In each, the test runner **must** hold
the literal and the value equal exactly when:

- **both are numbers, and denote the same number.** An `Int`, `Duration` or
  `Float` literal compares with an `Int`, `Float`, `Duration`, `Time` or `Date`
  value by the number each denotes, so `42` and `42.0` are equal in either
  direction and no value equals a number it does not denote. Neither side is
  promoted or rounded first, as `==` promotes ([LEXP.7.3]);
- **a `String` or `Bool` literal and a value of its own kind hold the same
  value;**
- **a `Json` literal and a `Json` value, or any literal and a cache value, are
  the same JSON value:** numbers by the number they denote, an object by its
  members in any order, an array element by element in order. A whole `Float`
  keeps its `.0` when it is written as JSON ([LDET.3.2.7]), and still equals the
  same whole number;
- **a literal with no value, and a null value.**

Any other pair is unequal, so a `Json` literal is unequal to a `String` or a
number slot or argument, and a `String` literal to a `Json` one, whatever text
or number they hold. A slot a head names that the observed fact does not
carry is unequal to every literal.

---

*see also:* [LDET.3.2](#LDET-3-2), [LDET.3.2.7](#LDET-3-2-7), [LEXP.7.3](#LEXP-7-3), [LTSL.7.2](#LTSL-7-2), [LTSL.8.2](#LTSL-8-2)

(LTSL-4-4)=
[LTSL.4.4] **A schema is named in a test as it is in a rule.** Wherever a
test names a schema — a fact constructed in `initial`, `inputs` or a
`responses` reply ([LTSL.4.1]), and the schema of a `produces` head that
matches one: `emitted`, `published`, `retracted`, `wm has` and `wm count`
([LTSL.4.2], [LTSL.8.2]) — the name is a schema reference of the form a rule
pattern takes, `Name` or `lib.Name` ([LGRA.8.1]), and it resolves the same
way.

*ratified*  —  *see also:* [LGRA.8.1](#LGRA-8-1), [LTSL.4.1](#LTSL-4-1), [LTSL.4.2](#LTSL-4-2), [LTSL.8.2](#LTSL-8-2)

(LTSL-5)=
## `initial:` — the starting snapshot [LTSL.5]

(LTSL-5-1)=
### Trusted arrange [LTSL.5.1]

`initial` declares starting state established before the timeline runs. The runtime
must apply it as arrange and must not observe it: an `initial` fact or cache seed is
never itself checked by the oracle.

(LTSL-5-2)=
### Cache seed [LTSL.5.2]

`cache "key": value` (or a `cache:` sub-block of `"key": value` entries) seeds the
engine's live cache map before the run. A rule's later cache write is visible to a
later `cached("key")` read, as at runtime ([LSTO]).

(LTSL-5-3)=
### Pre-loaded facts [LTSL.5.3]

A bare construction line in `initial` places a fact in working memory before the
first input ([LTSL.4.1]). The runtime asserts it as arrange (`TestFact` with the
`is_initial` marker, [RLOW.17.1]).

---

*see also:* [LTSL.4.1](#LTSL-4-1), [RLOW.17.1](#RLOW-17-1)

(LTSL-6)=
## `inputs:` — the timeline [LTSL.6]

(LTSL-6-1)=
### The stamped input set [LTSL.6.1]

`inputs` is a set, unordered in source, of `at <dur>:` blocks of constructed facts.
The runtime orders the facts by stamp, and by source order within a stamp
([LTSL.3.3]).

*see also:* [LTSL.3.3](#LTSL-3-3)

(LTSL-6-2)=
### Assertion role [LTSL.6.2]

The runtime asserts each input fact into the engine as an external source would —
the assert role — and never by privileged registration ([RTIM]).

---

(LTSL-7)=
## `responses:` — the environment's replies [LTSL.7]

(LTSL-7-1)=
### Scope [LTSL.7.1]

A program's only external dependency is the outbound `call`; `emit`, `publish`
and `log` are pure outputs. `responses` stubs the
environment's replies to outbound calls, and nothing else.

(LTSL-7-2)=
### The `for call` stub [LTSL.7.2]

A stub is:

```
for call <service>[.<method>] [slot: val …] [as "<corr>"] [after <dur>]:
    <reply fact>          # one or more constructed facts, or
    no response
```

The stub keys on the outbound call — by its correlation (`as "<corr>"`) or by
argument equality (`slot: val`, [LTSL.4.3]). A stub **must** identify the call by correlation or
arguments (`DS_VALIDATE_TEST_STUB_UNKEYED`), because its reply must carry the matching `corr`; a bare service match is
reserved for the `called` assertion ([LTSL.8]), which has no reply to mis-key.

**A reply may omit `corr`, and the test runner supplies it.** When a reply fact
writes no `corr`, the test runner **must** give it the correlation of the call the
stub matched: the call's `as` value, or the value generated for it
([LCCO.3.4]), which a test cannot know when it is written. A `corr` the reply
writes is kept as written, so a test can answer under another correlation on
purpose. `corr` is the one slot a constructed fact may leave out ([LTSL.4.1]).

*see also:* [LCCO.3.4](#LCCO-3-4), [LTSL.4.1](#LTSL-4-1), [LTSL.4.3](#LTSL-4-3), [LTSL.8](#LTSL-8)

(LTSL-7-3)=
### Constructed replies [LTSL.7.3]

A stub's reply is one or more constructed facts ([LTSL.4.1]) — one for a single
reply, several for a batch. A reply to a call of a service declaring `response T`
is a fact of `T` ([LCRS.4.3.1]) or a `CallError`; the compiler must reject a
reply of any other schema (`DS_VALIDATE_TEST_STUB_REPLY_TYPE`).

*ratified*  —  *see also:* [LCRS.4.3.1](#LCRS-4-3-1), [LTSL.4.1](#LTSL-4-1)

(LTSL-7-4)=
### `after <dur>` [LTSL.7.4]

`after <dur>` delays the reply by that interval, for latency and race tests. The
default is an immediate reply at the same instant (`TestResponse.after_ns = 0`).

(LTSL-7-5)=
### `no response` [LTSL.7.5]

`no response` declares an intentionally-unanswered call — the timeout / absence path
a rule detects with a `timeout` continuation or a negated pattern over the
response schema bounded by `within` ([LCRS.7.1]).

A stub for a call of a service that declares `no response` ([LADP.8.4.2]) must
contain only `no response`; the compiler must reject one that contains a reply
(`DS_VALIDATE_TEST_STUB_NO_RESPONSE_MISMATCH`).

*ratified*  —  *see also:* [LADP.8.4.2](#LADP-8-4-2), [LCRS.7.1](#LCRS-7-1)

(LTSL-7-6)=
### Calls must be accounted for [LTSL.7.6]

Every outbound call a program makes during the run must match some `for call` entry
— a reply, an `after` reply, or `no response`. The runtime must fail the test case
on an **unaccounted** outbound call ([RTIM]); it must not treat one as a silent
no-op. This keeps a timeout test honest.

(LTSL-7-7)=
### Correlations are data [LTSL.7.7]

An author's `as` value is deterministic ([LDET], no RNG), so it is knowable at
compile time and is written explicitly on the `for call` key; a reply may omit
its `corr` slot ([LTSL.7.2]). A call with no `as` carries a generated correlation
([LCRS.3.1]), and a stub keys on its arguments ([LTSL.7.2]).

---

*see also:* [LCRS.3.1](#LCRS-3-1), [LTSL.7.2](#LTSL-7-2)

(LTSL-8)=
## `produces:` — the oracle [LTSL.8]

(LTSL-8-1)=
### Whole-run observation set [LTSL.8.1]

`produces` is an unordered set of observations checked over the whole run. There is
no output-side timeline: the author asserts *what* the program produces; *when* is
controlled by the input timeline.

(LTSL-8-2)=
### Assertion heads [LTSL.8.2]

Each head is a past-tense observation the compiler lowers to one `Oracle*` oracle atom
([RDSC.7.1], [RLOW.17.1]):

| Head | Asserts | Atom |
|---|---|---|
| `activated <rule>` | the rule produced and ran an activation | `OracleActivated` |
| `emitted <Schema> …` | an `emit` of a matching fact | `OracleEmit` |
| `published <Schema> …` | a `publish` of a matching fact | `OraclePublish` |
| `called <service> [as "corr"]` | an outbound call to the service (optionally a correlation) | `OracleCall` |
| `cached "k" [: v]` | a cache write of `k` (optionally value `v`) | `OracleCacheSet` |
| `cache_deleted "k"` | a cache delete of `k` | `OracleCacheDelete` |
| `logged <level> ["substr"]` | a `log` at that level (optionally matching a substring) | `OracleLog` |
| `retracted <Schema> …` | a matching fact left working memory | `OracleRetract` |
| `wm has <Schema> …` / `wm count <Schema> == N` / `wm empty` | working-memory state at end of run | `OracleWorkingMemory` |

A subset-matching head (`emitted` / `published` / `retracted` / `wm has`) matches
a schema-typed fact by **subset slot equality** — the given slots must equal the
observed fact's, other slots free — over exact values ([LTSL.4.3]). The one
non-schema value is the `cached "k": v` cache value, **opaque JSON**, which
matches `v` as two JSON values do ([LTSL.4.3]).

`recorded` is not a head: the compiler must reject it
(`DS_VALIDATE_TEST_RECORDED_RETIRED`) with a message naming `called`, the head
that asserts a call.

*ratified*  —  *see also:* [LTSL.4.3](#LTSL-4-3), [RDSC.7.1](#RDSC-7-1), [RLOW.17.1](#RLOW-17-1)

(LTSL-8-3)=
### Polarity [LTSL.8.3]

Each head carries a polarity. A bare head asserts the observation occurred **at
least once** over the run (`POS`); the `never` prefix asserts it occurred **zero
times** (`NEVER`). These are the only two polarities.

Polarity is an occurrence constraint at its coarsest: `POS` is "≥ 1" and
`NEVER` is "= 0". A head may narrow that axis with `exactly N`
([LTSL.8.7]), which states the exact tally. `never` and `exactly` do not
combine.

*see also:* [LTSL.8.7](#LTSL-8-7)

(LTSL-8-4)=
### Matching [LTSL.8.4]

A head with slot arguments matches by partial (subset) equality; a slot the head
does not name is free on the observed fact. An `emitted` head
matches either by slot arguments or by a binding and a `where` predicate
([LTSL.4.2]), never by both: a head carrying both does not parse ([LGRA.21.1]),
and an author states a condition on a slot inside the predicate.

A `published` head matches by slot arguments alone. The compiler must refuse a
`where` predicate on a `published` head, with or without `never`, with
`DS_VALIDATE_TEST_PUBLISHED_WHERE`: the predicate is a rule over working memory
([RTIM.14.11]), and a `publish` puts nothing there ([LTIE.4.3]).

The `OracleEmit` atom carries `has_where`, and an atom that
carries it carries no `slot_match` ([RDSC.7.1]); the predicate itself is realized as a
compiler-synthesized internal rule and the oracle is bound to it by name, not by
an expression reference ([RTIM.14.11]). A `retracted` head
matches by slot-subset equality only — its `OracleRetract` atom carries no `where`. The
remaining heads carry no slot arguments and match by their identifying key: `called`
by service and optional correlation, `cached` by key and
optional value, and `logged` by level and optional substring
([LTSL.8.2]). Call-argument equality is keyed on the `for call` response
stub ([LTSL.7.2]), not on the `called` oracle head.

*see also:* [LGRA.21.1](#LGRA-21-1), [LTIE.4.3](#LTIE-4-3), [LTSL.4.2](#LTSL-4-2), [LTSL.7.2](#LTSL-7-2), [LTSL.8.2](#LTSL-8-2), [RDSC.7.1](#RDSC-7-1), [RTIM.14.11](#RTIM-14-11)

(LTSL-8-5)=
### Subset by default [LTSL.8.5]

`produces` is satisfied when every listed observation holds; an output the test does
not mention does not fail it. The surface has no exhaustive "exactly these outputs"
form.

(LTSL-8-7)=
### Occurrence count — `exactly N` [LTSL.8.7]

A head may carry the modifier `exactly <N>`, asserting the observation occurred
**exactly N times** over the run.

`exactly` composes with matching ([LTSL.8.4]) and with `where` unchanged: the
count is of observations that match, not of all observations under the head.

**`exactly` refines polarity, it does not replace it.** A bare head is `POS`
(at least once) and `never` is zero times ([LTSL.8.3]); `exactly N` states the
exact tally on that same axis. `never <head> exactly <N>` has no single reading
and the compiler must reject it.

The count is an **equality**. The surface admits no `at least` or `at most`
form: `at least 1` is a bare head, and no other comparison has been asked for.

`N` is at least 1. `exactly 0` is not admitted — `never` is that assertion, and
admitting a second spelling for it would put two forms on one meaning. This
also keeps the wire encoding free of a presence flag: the atom carries a plain
count whose zero reads as "no occurrence constraint", which is the
`proto3 zero = absent` convention the rest of the corpus uses.

```{admonition} exactly N is a whole-run tally, not a per-trigger claim
:class: warning
It cannot distinguish two rules firing on ONE trigger from one rule firing on
TWO — both are two occurrences. So `published X exactly 1` constrains a
single-trigger scenario and nothing wider; in a scenario that pumps more than
once it will fail on correct programs.

To assert that two rules never both fire, use `exclusive` ([LTSL.8.8]), which
is scoped rather than tallied.
```

**The `wm` head does not admit `exactly`, and the compiler must reject it.**
`wm has` / `wm count` / `wm empty` inspect working memory at the END of the run
([LTSL.8.6]); they observe a state, not a stream of occurrences, so there is
nothing for an occurrence tally to count. `wm count <Schema> == N` keeps its own
spelling and is not an instance of this modifier: there `count` is the head and
the number is a final-state **cardinality**, while `exactly` is a modifier and
the number is an occurrence **tally**.

The exclusion is deliberate and costs a wart — the modifier reads as "every
head except one". The alternative is worse: one head carrying two different
meanings for a number, where `wm count == 2` and `wm has … exactly 2` would
look like the same assertion and be different ones, with nothing in the surface
to tell them apart. A reader can look up an exclusion; a reader cannot see a
conflated meaning.

*Deferred: not binding in this edition.*

*see also:* [LTSL.8.3](#LTSL-8-3), [LTSL.8.4](#LTSL-8-4), [LTSL.8.6](#LTSL-8-6), [LTSL.8.8](#LTSL-8-8)

(LTSL-8-8)=
### `exclusive` — rules that must not both fire [LTSL.8.8]

`exclusive <rule>, <rule>[, …]` asserts that **no two of the named rules fire
within the same pump**, for every pump in the scenario.

It names at least two rules; one is a compile error. Rule names are bound
against the program's rule inventory as `activated` binds them ([LTSL.8.2]), so
a misspelled rule fails to compile rather than passing vacuously. With more
than two names the assertion is **pairwise**: no two of the set may share a
pump.

**The scope is the pump.** A pump runs to quiescence, so rules that fire in one
pump are treated as responding to the same input regardless of which fact
triggered each. Scoping co-firing to rules that matched a common fact instead
would make two rules that both match a long-lived configuration fact never
exclusive, which is a silent false pass. A pump that batches unrelated inputs produces a false FAILURE
instead, and a test that wrongly fails is investigated.

The surface carries no scope selector. If a narrower one is ever needed it is a
new form, not a modifier on this one.

```{admonition} This is an observation, not a proof
:class: warning
`exclusive` holds when no co-firing was OBSERVED in the scenarios that ran. It
is not a statement that the rules are mutually exclusive by construction — a
dynamic test can only sample. An author who means "these can never both fire"
is making a claim about the rules' conditions, which this assertion does not
check and does not attempt to.
```

`never exclusive …` is not admitted. The inverse — asserting that two rules DO
co-fire — has not been asked for, and reserving the spelling costs nothing.

*Deferred: not binding in this edition.*

*see also:* [LTSL.8.2](#LTSL-8-2)

(LTSL-8-6)=
### `retracted` and `wm` semantics [LTSL.8.6]

`retracted <Schema> …` holds when a matching fact left working memory during the run
— by TTL expiry or logical supersedure. `wm has` / `wm count` / `wm empty` are
checked against working memory at the **end** of the run: `has` holds when some
matching fact is live, `count == N` when exactly N matching facts are live, and
`empty` when working memory holds no facts.

---

(LTSL-9)=
## Coverage [LTSL.9]

*Deferred: not binding in this edition.*

(LTSL-9-1)=
### An optional obligation vector [LTSL.9.1]

Coverage is optional. When enabled, the compiler derives a **vector of obligations**
from rule structure and reports, as definitive findings, the obligations no test
meets. The reachability obligation for a rule is met when some test asserts
`activated <rule>` — keyed on `activated` rather than on any output the rule
produces, since one schema may be emitted by several rules.

This clause states the shape and the reachability obligation: obligations derived
from rule structure, unmet ones reported as findings, the compiler advising while
the author writes every test.

---

(LTSL-10)=
## Relationship to the substrate [LTSL.10]

(LTSL-10-2)=
### The `LTES` substrate is retained [LTSL.10.2]

The substrate contracts remain in [LTES] — the single deterministic clock, the
event-trace primitive, and the introspection surface. `.dstest` is the author
language over that substrate, and the test-mode interpreter drives the real engine
and the real observation surface ([RTIM]).
