# Testing implementation

How a runtime delivers the language-level testing contract
(LTES, LTSL) with the engine it already has: the mock clock, assertion and
pumping as the test driver, the stream callback as the observation surface,
recording and replay, the in-process introspection queries, and the `.dstest`
interpreter.

The integrator-facing half — how a test written against libds uses these — is
NTST; the introspection queries themselves are NDBG.

## What this is not

- Not the test-file language — see LTSL.
- Not the conformance catalogue or how its fixtures are evaluated — see RCTS.
- Not a debugger protocol — see NDBG.
- Not a CI or build-integration guide.

---

(RTIM-1)=
## Test-harness commitments [RTIM.1]

(RTIM-1-1)=
- [RTIM.1.1] **Test mode is a configuration of the ordinary engine, not a
  separate engine and not an entry point.** A harness creates and drives an
  engine through the same operations an integrator uses ([RTIM.2.1]). The
  runtime must not give tests a second evaluation path.

*see also:* [RTIM.2.1](#RTIM-2-1)

(RTIM-1-2)=
- [RTIM.1.2] **The clock source is the only reader of host time whose value
  a rule can observe.** Every time the engine computes with — `now()`, fact
  timestamps, TTL and timer deadlines, the clock tick — must come from it, so
  putting the mock clock in its place ([RTIM.3.1.4]) puts every
  time-dependent decision under the harness's control. The one other reading
  of host time is a real-time tier's pump-WCET measurement, which no rule reads
  and which decides only the halt of [RTCT.7.3].

*see also:* [RTCT.7.3](#RTCT-7-3), [RTIM.3.1.4](#RTIM-3-1-4)

(RTIM-1-3)=
- [RTIM.1.3] **A mock registers through the integrator callbacks, the
  same surface a real adapter registers through.** The dispatcher
  ([RARC.5.7]) cannot tell a mock from an adapter, so a rule under test
  behaves as it would in production ([RTIM.4.1.1]).

*see also:* [RARC.5.7](#RARC-5-7), [RTIM.4.1.1](#RTIM-4-1-1)

(RTIM-1-4)=
- [RTIM.1.4] **Assertion is the test driver.** Every kind of test — a
  `.dstest` case, a conformance fixture, the replay of a recording — drives the
  engine by asserting and retracting facts, moving the mock clock and pumping
  ([RTIM.5]).

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

(RTIM-1-5)=
- [RTIM.1.5] **A harness observes the engine through the integrator's
  surfaces.** It reads the stream callback ([NCBK.2.1]) and the in-process
  introspection queries an inspector uses ([RTIM.6]). A harness runs in the
  process that owns the engine; the engine offers it no protocol of its own.

*see also:* [NCBK.2.1](#NCBK-2-1), [RTIM.6](#RTIM-6)

(RTIM-1-6)=
- [RTIM.1.6] **Recording drops nothing.** The engine delivers every
  observable event to the stream callback, in `seq` order ([RTIM.9.2.1]). A
  recording made from that stream replays to the same observable output on
  the same platform ([RTIM.9.3.1]).

*see also:* [RTIM.9.2.1](#RTIM-9-2-1), [RTIM.9.3.1](#RTIM-9-3-1)

(RTIM-1-7)=
- [RTIM.1.7] **A clock step is a clock move followed by a pump.** Moving the
  mock clock changes the time and nothing else; the next pump does every piece
  of time-driven work due at the new instant, and returns at quiescence
  ([RTIM.3.2]). The harness observes the engine between pumps, at a consistent
  boundary.

---

*see also:* [RTIM.3.2](#RTIM-3-2)

(RTIM-2)=
## Putting an engine under test [RTIM.2]

(RTIM-2-1)=
[RTIM.2.1] **A harness tests an ordinary engine.** It puts the engine under test with operations every integrator has: it takes the clock off
live before the first input ([NLFC.5.2]), registers the callbacks the program
under test needs — a mock is one of them ([RTIM.4.1.1]) — registers the stream
callback it observes through ([NCBK.2.1]), and loads the compiled program. The
engine holds no state that distinguishes a test from production.

*see also:* [NCBK.2.1](#NCBK-2-1), [NLFC.5.2](#NLFC-5-2), [RTIM.4.1.1](#RTIM-4-1-1)

(RTIM-2-14)=
### Replay is a harness [RTIM.2.14]

(RTIM-2-14-1)=
[RTIM.2.14.1] Replaying a recording is test mode with a replay driver as the
harness. The driver decodes the recording and makes the assert, retract, clock
and pump operations the recorded run's inputs made ([RTIM.5.2.1]); the engine
processes them exactly as it processes any other harness's.

---

*see also:* [RTIM.5.2.1](#RTIM-5-2-1)

(RTIM-3)=
## Deterministic-clock mechanism [RTIM.3]

(RTIM-3-1)=
### Clock source under test [RTIM.3.1]

(RTIM-3-1-1)=
[RTIM.3.1.1] The engine's clock source has two modes:

(RTIM-3-1-2)=
- [RTIM.3.1.2] **Live clock.** Reads the host's monotonic clock, translated
  into the engine's `clock_ns` space, and the host's UTC wall clock
  ([LTIM.2.8.1]).

*see also:* [LTIM.2.8.1](#LTIM-2-8-1)

(RTIM-3-1-3)=
- [RTIM.3.1.3] **Harness clock.** Returns, for each clock, the value the
  harness most recently set.

(RTIM-3-1-4)=
[RTIM.3.1.4] Selecting the mock mode puts the harness clock in place of the
live one for every reader of the clock source: the pump, the timer agenda, TTL
expiry, the clock tick, fact timestamps, and every expression that reads the
time ([RTIM.1.2]). The switch, its origin and when it is admitted are
[NLFC.5.4]'s.

*see also:* [NLFC.5.4](#NLFC-5-4), [RTIM.1.2](#RTIM-1-2)

(RTIM-3-2)=
### Advancing the clock [RTIM.3.2]

(RTIM-3-2-1)=
[RTIM.3.2.1] The harness moves the mock clock by setting it to an instant or
advancing it by a duration ([NTST.3.1]). The move changes the time and emits a
tick event carrying the new value ([NTST.3.3]); it does no time-driven work.
The next pump does that work, in this order:

*ratified*  —  *see also:* [NTST.3.1](#NTST-3-1), [NTST.3.3](#NTST-3-3)

(RTIM-3-2-2)=
1. [RTIM.3.2.2] It retracts every fact whose TTL deadline is at or before the
   current instant, then removes every expired cache entry ([NTST.3.4]).

*ratified*  —  *see also:* [NTST.3.4](#NTST-3-4)

(RTIM-3-2-3)=
2. [RTIM.3.2.3] It cycles the clock tick once, so a rule waiting on an
   `after` timer re-checks its deadline at the current instant. There is one
   tick per pump; the tick has no interval of its own.

(RTIM-3-2-4)=
3. [RTIM.3.2.4] It fires the agenda to quiescence: each firing cascades
   through the network as usual, and the activations it produces fire before
   the pump returns.

(RTIM-3-2-5)=
[RTIM.3.2.5] Every event the pump produces reaches the stream callback in
`seq` order ([NCBK.2.1]).

*see also:* [NCBK.2.1](#NCBK-2-1)

(RTIM-3-2-6)=
[RTIM.3.2.6] **A move does not visit the instants it skips.** Everything due
at or before the new instant is done at the new instant, and an expression that
reads the time reads the new instant. A harness that needs an effect to happen
at an earlier instant moves the clock to that instant and pumps there first,
which is how the `.dstest` interpreter walks a timeline ([RTIM.14.5]).

*ratified*  —  *checks:* `idris×5`  —  *see also:* [RTIM.14.5](#RTIM-14-5)

(RTIM-3-3)=
### Atomic-step guarantee [RTIM.3.3]

(RTIM-3-3-1)=
[RTIM.3.3.1] **The pump is the atomic step.** When it returns, every piece of
time-driven work the current instant implies has been done, and the harness
sees no intermediate engine state. A real-time tier's pump may stop at a
declared cap before quiescence ([RTCT.7.1]); it then reports the cap, and that
step is not complete.

*see also:* [RTCT.7.1](#RTCT-7-1)

(RTIM-3-3-2)=
[RTIM.3.3.2] This is what makes "move the clock five seconds, pump, and
observe" a test operation. Without it, a test would have to poll the engine
for a stable state.

---

(RTIM-4)=
## Adapter mocks [RTIM.4]

(RTIM-4-1)=
### Registration [RTIM.4.1]

(RTIM-4-1-1)=
[RTIM.4.1.1] A mock registers exactly as a real adapter does, because
there is only one way in: the integrator callbacks ([NCBK.12.3]). A mock
service is a call callback like any other; a mock fact source is the
harness asserting test data.

*see also:* [NCBK.12.3](#NCBK-12-3)

(RTIM-4-1-2)=
[RTIM.4.1.2] The mock is integrator code the harness controls. It runs on the
pump thread, so it must not block, for the same reason an adapter must not
([NADP.5.1]). It answers a `call` the way an adapter does, by the harness
asserting the response facts ([RTIM.4.2.1]).

*see also:* [NADP.5.1](#NADP-5-1), [RTIM.4.2.1](#RTIM-4-2-1)

(RTIM-4-1-4)=
[RTIM.4.1.4] The dispatcher cannot distinguish a mock from a real
adapter, and this is the property the whole arrangement exists for: a
call dispatches the same way and its response populates the same fact
shapes either way, so a rule under test cannot tell that it is under
test. The dispatcher is specified at [RARC.5.7].

*see also:* [RARC.5.7](#RARC-5-7)

(RTIM-4-2)=
### Mock responses [RTIM.4.2]

(RTIM-4-2-1)=
[RTIM.4.2.1] The harness answers a call by asserting its response or error
facts: at once, after a clock move, or never. Which of those a mock does, and
how it chooses — by service, by arguments, by correlation, by its own history
— is the harness's. The engine treats the asserted facts as it treats an
adapter's.

(RTIM-4-3)=
### Facts from a mock source [RTIM.4.3]

(RTIM-4-3-1)=
[RTIM.4.3.1] A mock fact source is the harness asserting facts at the
instants it chooses on the mock clock. An asserted fact enters the engine as an
adapter's does: it takes its `seq` when the engine consumes it, its assert
event reaches the stream callback, and working memory updates.

(RTIM-4-4)=
### Call observation [RTIM.4.4]

(RTIM-4-4-1)=
[RTIM.4.4.1] Every `call` the engine issues reaches the stream callback as a
call event ([NCBK.2.1]), carrying:

*see also:* [NCBK.2.1](#NCBK-2-1)

(RTIM-4-4-2)=
- [RTIM.4.4.2] The service called, and the firing that issued it: its rule and
  its activation's timetag.

(RTIM-4-4-3)=
- [RTIM.4.4.3] Its arguments, as the call carries them.

(RTIM-4-4-4)=
- [RTIM.4.4.4] Its correlation ([LCRS.3.1]).

*see also:* [LCRS.3.1](#LCRS-3-1)

(RTIM-4-4-5)=
- [RTIM.4.4.5] Its `seq`, which orders it among every other event.

---

(RTIM-5)=
## Driving the engine [RTIM.5]

(RTIM-5-1)=
### The driving operations [RTIM.5.1]

(RTIM-5-1-1)=
[RTIM.5.1.1] A harness drives the engine with the operations an integrator
has:

(RTIM-5-1-2)=
- [RTIM.5.1.2] Assert a fact.

(RTIM-5-1-3)=
- [RTIM.5.1.3] Retract a fact.

(RTIM-5-1-4)=
- [RTIM.5.1.4] Set or advance the mock clock ([RTIM.3.2.1]).

*see also:* [RTIM.3.2.1](#RTIM-3-2-1)

(RTIM-5-1-8)=
- [RTIM.5.1.8] Pump ([RTIM.3.2]).

*see also:* [RTIM.3.2](#RTIM-3-2)

(RTIM-5-1-7)=
[RTIM.5.1.7] An assert or retract takes its `seq` when the engine consumes
it, and its event reaches the stream callback in that order; a clock move emits
its tick event the same way ([NTST.3.3]).

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

(RTIM-5-2)=
### Replaying a recording [RTIM.5.2]

(RTIM-5-2-1)=
[RTIM.5.2.1] A replay driver reads a replayable trace ([LFST.9.2.1]) in `seq`
order and turns each recorded input back into the operation of [RTIM.5.1] that
produced it, then compares what the engine reports against what the trace
recorded.

*see also:* [LFST.9.2.1](#LFST-9-2-1), [RTIM.5.1](#RTIM-5-1)

(RTIM-5-2-2)=
[RTIM.5.2.2] The engine processes a replayed input exactly as it processes the
same operation from any other harness; it has no replay path of its own.

(RTIM-5-3)=
### Recording for later replay [RTIM.5.3]

(RTIM-5-3-1)=
[RTIM.5.3.1] A harness records a session by registering a stream callback
that keeps what it receives ([NCBK.2.1]); the result is a replayable trace
([LFST.9.2.1]). Where it goes — memory, a file, a writer the test supplies — is
the harness's.

*see also:* [LFST.9.2.1](#LFST-9-2-1), [NCBK.2.1](#NCBK-2-1)

(RTIM-5-3-2)=
[RTIM.5.3.2] A recording replays to the same observable output on the same
platform ([LDET.1.1]), so a scenario captured against real adapters replays in
CI from the recording alone.

---

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

(RTIM-6)=
## Harness-facing introspection surface [RTIM.6]

(RTIM-6-1)=
[RTIM.6.1] The harness queries the engine with the in-process introspection
queries an inspector uses ([NDBG.1]). The harness reads them between pumps, where
they are meaningful ([NDBG.1.2]).

*see also:* [NDBG.1](#NDBG-1), [NDBG.1.2](#NDBG-1-2)

(RTIM-6-2)=
[RTIM.6.2] What the harness can observe, and where:

(RTIM-6-3)=
- [RTIM.6.3] **Working memory** — every live fact, with its schema and slot
  values, and the schema and rule metadata ([NDBG.2]).

*see also:* [NDBG.2](#NDBG-2)

(RTIM-6-4)=
- [RTIM.6.4] **Rete network** — topology, live node occupancy, and the match
  trace of one fact through the alpha nodes ([NDBG.4]).

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

(RTIM-6-5)=
- [RTIM.6.5] **Refracted activations** — the activations refraction blocks,
  every entry of the terminals' refraction sets, with the facts each matched
  ([NDBG.4.3]). Fired activations are observed on the stream, as rule-fire
  events.

*see also:* [NDBG.4.3](#NDBG-4-3)

(RTIM-6-6)=
- [RTIM.6.6] **Truth-maintenance justifiers** — the activations that
  logically support a fact, with their rules ([NDBG.5]).

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

(RTIM-6-7)=
- [RTIM.6.7] **Timers** — on the stream, not by query: each `after` timer's
  arming and firing is an event ([RTIM.6.13.1]).

*see also:* [RTIM.6.13.1](#RTIM-6-13-1)

(RTIM-6-8)=
- [RTIM.6.8] **Calls** — on the stream, not by query: each call is an event
  ([RTIM.4.4.1]), and its response is a fact the harness asserted.

*see also:* [RTIM.4.4.1](#RTIM-4-4-1)

(RTIM-6-11)=
- [RTIM.6.11] **Operator log** — every `log` an action performs, as a
  stream event and through its own callback.

(RTIM-6-12)=
[RTIM.6.12] A harness builds its assertions on these observables and on the
stream ([RTIM.6.13.1]), and on nothing else: a test that read engine internals
would verify something no integrator can see ([NTST.2.1]).

*see also:* [NTST.2.1](#NTST-2-1), [RTIM.6.13.1](#RTIM-6-13-1)

(RTIM-6-13)=
### Stream subscription for assertions [RTIM.6.13]

(RTIM-6-13-1)=
[RTIM.6.13.1] The harness registers the stream callback ([NCBK.2.1]) and
asserts against the sequence of events it received. This is the mechanism for
"did the right events happen in the right order" assertions.

---

*ratified*  —  *see also:* [NCBK.2.1](#NCBK-2-1)

(RTIM-7)=
## Conformance-suite runner [RTIM.7]

(RTIM-7-1)=
### Purpose [RTIM.7.1]

(RTIM-7-1-1)=
[RTIM.7.1.1] The reference runtime ships a conformance-suite runner that runs
the conformance catalogue against the engine and reports pass or fail per test.
The runner is a harness on this document's terms: an ordinary engine, the mock
clock, the driving operations and the stream ([RTIM.2.1]). The catalogue, its
fixture shapes and how the runner evaluates them are RCTS; the category
contract the catalogue satisfies is LCON.

*see also:* [RTIM.2.1](#RTIM-2-1)

(RTIM-7-3)=
### Determinism guarantee [RTIM.7.3]

(RTIM-7-3-1)=
[RTIM.7.3.1] Every conformance test must pass byte-for-byte on
every run on the same platform. Flakiness is a
bug — either in the runtime (violating
determinism) or in the test (depending on
observably variable state).

(RTIM-7-4)=
### Cross-platform tolerance [RTIM.7.4]

(RTIM-7-4-1)=
[RTIM.7.4.1] The conformance suite's float-dependent tests are
bit-identical across platforms ([LDET.3.4.1]), on the
same terms as its integer, string, rule-order and
fact-identity tests.

---

*see also:* [LDET.3.4.1](#LDET-3-4-1)

(RTIM-8)=
## User-rule test runner [RTIM.8]

(RTIM-8-1)=
### Purpose [RTIM.8.1]

(RTIM-8-1-1)=
[RTIM.8.1.1] A rule author's `.dstest` files carry the scenarios and their
expectations ([LTSL]). The compiler lowers them into the artefact
([RLOW.17.1]), and the `.dstest` interpreter ([RTIM.14]) runs them and reports
pass or fail per test case. The interpreter is a harness: it drives a runtime's
own engine through the operations an integrator has ([RTIM.14.1]), and it is
the one thing that executes the `Test*` and `Oracle*` atoms.

*see also:* [RLOW.17.1](#RLOW-17-1), [RTIM.14](#RTIM-14), [RTIM.14.1](#RTIM-14-1)

(RTIM-8-3)=
### Keeping tests out of a production bundle [RTIM.8.3]

(RTIM-8-3-1)=
[RTIM.8.3.1] Tests are a separate file type, not a gated
capability, so a production build does not have to
refuse anything: a bundle carries no scenarios
unless the modules it compiles have tests
([LTSL.2.4], [LTES.7.6]), and `strip-tests` removes
them ([RCLI.1.6]).

A runtime that meets those atoms anyway skips them
rather than refusing the bundle (skip-don't-reject,
[RDSC.9.4]).

---

*ratified*  —  *see also:* [LTES.7.6](#LTES-7-6), [LTSL.2.4](#LTSL-2-4), [RCLI.1.6](#RCLI-1-6), [RDSC.9.4](#RDSC-9-4)

(RTIM-9)=
## Recording-mode contract [RTIM.9]

(RTIM-9-1)=
### When recording happens [RTIM.9.1]

(RTIM-9-1-1)=
- [RTIM.9.1.1] **Live or under test.** The engine delivers every event to
  the stream callback whenever one is registered; recording is the integrator
  or harness keeping them. Where the recording lands — filesystem, storage
  adapter, in-memory buffer — is the integrator's ([RARC.6.5.1]).

*see also:* [RARC.6.5.1](#RARC-6-5-1)

(RTIM-9-1-3)=
- [RTIM.9.1.3] **Replay.** A replay driver feeds the engine a recording
  ([RTIM.5.2.1]); the engine's stream during the replay may be recorded in
  turn.

*see also:* [RTIM.5.2.1](#RTIM-5-2-1)

(RTIM-9-2)=
### Recording-fidelity contract [RTIM.9.2]

(RTIM-9-2-1)=
[RTIM.9.2.1] **Delivery drops nothing.** The engine hands every event to the
integrator within the call that produced it ([RARC.5.8.7]), so there is no
buffer to overflow. A non-OK status from the callback does not change what the
engine does; it is reported to the caller of the public call that fired it
([NCBK.1.5]).

*see also:* [NCBK.1.5](#NCBK-1-5), [RARC.5.8.7](#RARC-5-8-7)

(RTIM-9-3)=
### Replay-from-recording [RTIM.9.3]

(RTIM-9-3-1)=
[RTIM.9.3.1] A replayable trace ([LFST.9.2.1]) is valid replay input.
Replaying it produces the same observable output as the original session on
the same platform ([LDET.1.1]), and the replay is an ordinary harness run
([RTIM.2.14.1]).

*see also:* [LDET.1.1](#LDET-1-1), [LFST.9.2.1](#LFST-9-2-1), [RTIM.2.14.1](#RTIM-2-14-1)

(RTIM-9-4)=
### Multi-tier recordings [RTIM.9.4]

(RTIM-9-4-1)=
[RTIM.9.4.1] A multi-tier deployment produces one recording per tier. A
harness correlates them by the `session_id` their headers share ([LFST.4.1])
and by values the facts carry ([LFST.7.2.4]). An `event_id` matches nothing on
another tier ([LFST.5.6]).

---

*see also:* [LFST.4.1](#LFST-4-1), [LFST.5.6](#LFST-5-6), [LFST.7.2.4](#LFST-7-2-4)

(RTIM-14)=
## The `.dstest` test-mode interpreter [RTIM.14]

(RTIM-14-1)=
[RTIM.14.1] **Purpose.** The runtime executes a compiled `.dstest` — the `Test*`
scenario and `Oracle*` oracle atoms ([RDSC.7.1]) — with a test-mode interpreter that
is a harness on this document's terms ([RTIM.2], [RTIM.3], [RTIM.5], [RTIM.6]):
an ordinary engine on the mock clock, driven by assertion and pumping, observed
through the stream. The interpreter adds no evaluation machinery of its own.
Its surface contract is `LTSL`; its lowering is [RLOW.17].

*see also:* [RDSC.7.1](#RDSC-7-1), [RLOW.17](#RLOW-17), [RTIM.2](#RTIM-2), [RTIM.3](#RTIM-3), [RTIM.5](#RTIM-5), [RTIM.6](#RTIM-6)

(RTIM-14-2)=
[RTIM.14.2] **Fresh engine per case.** The interpreter drives a fresh engine per
`TestCase`, on the mock clock ([RTIM.3]). State must not leak between cases.

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

(RTIM-14-3)=
[RTIM.14.3] **Compiled-`.dsc` load, not hand registration.** The interpreter
drives each case by loading the compiled `.dsc`, so schemas and rules register
through the normal load path. It never registers a schema or a rule by hand.

(RTIM-14-15)=
[RTIM.14.15] **Test atoms the interpreter cannot read refuse the run.** A
runtime's load skips the `Test*` / `Oracle*` family ([RDSC.9.4]), so the
interpreter reads it itself, whole, before any case runs. It **must** refuse
the run, running no case, when a test atom's body does not decode
([RDSC.9.5]), with `DS_ERR_DSC_DECODE`, or when a test atom names something no
atom in the artefact defines ([RDSC.8.7]), with `DS_ERR_DSC_DANGLING`. In each
case it names the atom, and it checks the bodies before the names, as a load
does.

A conforming compiler writes neither ([RLOW.17.1], [RDSC.9.9]), so either is
a damaged or forged artefact, and no case's verdict over it means anything.

*see also:* [RDSC.8.7](#RDSC-8-7), [RDSC.9.4](#RDSC-9-4), [RDSC.9.5](#RDSC-9-5), [RDSC.9.9](#RDSC-9-9), [RLOW.17.1](#RLOW-17-1)

(RTIM-14-4)=
[RTIM.14.4] **Arrange.** The interpreter applies the `TestCacheSeed` cache seeds and the
initial `TestFact` facts before the timeline ([LTSL.5]); these are arrange and the
oracle must not observe them.

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

(RTIM-14-5)=
[RTIM.14.5] **Timeline replay.** The interpreter replays the `TestFact` timeline in
`(when_ns, source-order)` order ([LTSL.3.3]), advancing the mock clock across the
union of all input stamps, `TestCase.until_ns`, and **scheduled reply deadlines** —
a delayed reply's deadline (`call_time + after_ns`, [RTIM.14.6]) is discovered
mid-run when the outbound call is issued, so the clock advances to it exactly as
to an input stamp. At each instant the interpreter sets the clock, asserts, and
pumps to quiescence with the driving operations of [RTIM.5.1]; there is no
author-driven `pump` or `advance`. At a **shared instant**, input facts are applied **before** scheduled
replies, so the constructed input stream is well-defined: the interpreter builds
the asserted sequence, and [LDET.5] guarantees deterministic firing only given a
fixed stream, so this construction order is itself normative — a runtime that
delivered a co-timed reply before its input fact would diverge.

*see also:* [LDET.5](#LDET-5), [LTSL.3.3](#LTSL-3-3), [RTIM.14.6](#RTIM-14-6), [RTIM.5.1](#RTIM-5-1)

(RTIM-14-6)=
[RTIM.14.6] **Stub answering.** For each outbound `call`, the interpreter answers
from the matching `TestResponse` stub: it asserts the stub's `TestReply` reply facts —
immediately (same instant, `after_ns = 0`) or scheduled for delivery at
`call_time + after_ns` ([LTSL.7.4]) — or nothing for `no_response`. **Replies due
at the same instant are delivered in call order** — the order the outbound calls
were issued — so the input stream is deterministic ([RTIM.14.5]). An outbound
call with no matching `TestResponse` **must fail the test case** ([LTSL.7.6]); the
interpreter must not treat it as a silent no-op.

*see also:* [LTSL.7.4](#LTSL-7-4), [LTSL.7.6](#LTSL-7-6), [RTIM.14.5](#RTIM-14-5)

(RTIM-14-14)=
[RTIM.14.14] **A step the engine refuses fails the case.** The interpreter
drives a case by operations that each return a status: a cache seed, an
arrange or input assertion, a reply's assertion, a clock move and a pump
([RTIM.14.4], [RTIM.14.5], [RTIM.14.6]). When one returns anything but success,
whether or not the engine halted ([NCBK.2.9]), the interpreter **must** fail
the case, naming the operation and its status, and **must** stop driving the
case there: it delivers no later instant and no later reply. It **may** report
the case's assertions over what it observed until then. The case does not pass
on them.

No assertion head observes a refused step ([LTSL.8.2]): a pump that refuses a
cache write past its cap or drops a call on a NaN argument leaves nothing an
assertion could read. So a refusal the interpreter passed over would let a
program that breaks a bound pass a test that never looked for it.

*see also:* [LTSL.8.2](#LTSL-8-2), [NCBK.2.9](#NCBK-2-9), [RTIM.14.4](#RTIM-14-4), [RTIM.14.5](#RTIM-14-5), [RTIM.14.6](#RTIM-14-6)

(RTIM-14-16)=
[RTIM.14.16] **A failing case names the faults it met.** When a case fails,
for any reason, the interpreter **must** report with it every fault event
([NCBK.2.8]) the case's engine raised while the interpreter drove it, in
stream order. Each one names its kind, the mock-clock instant of the step that
raised it, the rule whose activation it abandoned where the event names one,
and what the event gives of its cause: a `ComputationError`'s kind
([LERR.1.4.9]), a `TypeError`'s schema and slot ([RARC.5.2.7]), a
`BoundsError`'s cap. For a case that passes, the interpreter **may** report
them.

A fault does not fail a case by itself. A case is judged by its assertions
([LTSL.8.5]) and by [RTIM.14.14], and a test may drive a rule into a fault on
purpose.

An activation a fault abandons makes none of the observations its rule would
have made, so the assertions over them fail with a count of zero. Without the
fault beside them, that count points at the rule's conditions and not at the
fault.

*see also:* [LERR.1.4.9](#LERR-1-4-9), [LTSL.8.5](#LTSL-8-5), [NCBK.2.8](#NCBK-2-8), [RARC.5.2.7](#RARC-5-2-7), [RTIM.14.14](#RTIM-14-14)

(RTIM-14-7)=
[RTIM.14.7] **Oracle check.** The interpreter observes the engine's stream events
and final working memory and checks every `Oracle*` atom over the whole run — `POS`
requires ≥ 1 occurrence, `NEVER` requires 0 ([LTSL.8.3]) — matching by partial
(subset) equality or, on an `OracleEmit` that carries
`has_where`, by the `where` predicate in its place ([LTSL.8.4]). The
predicate is evaluated by a **compiler-synthesized oracle rule matched by the real
engine** ([RTIM.14.11]), never a shadow or parallel evaluator ([RTIM.14.8]): the
rule's LHS is `<schema> <binding> where <pred>`, and the interpreter binds the
`OracleEmit` to that rule by the deterministic name convention. A `where` match
is a firing of that oracle rule on a fact that was **emitted** this
run — the interpreter attributes each firing to an `ACTION_EMIT`
by fact identity (the matched fact handle on the pre-fire event); a firing on an
input / arrange fact that merely satisfies the predicate is **not** a match. The
oracle rule's own effects are not part of the observed output. v1 exact-value
makes a float match exact ([LDET.3.2]).

An `OracleEmit` that carries both `has_where` and a `slot_match`, and an
`OraclePublish` that carries `has_where`, are ones no conforming compiler writes
([LTSL.8.4]). The interpreter **must** fail the case and name the atom, as it fails an assertion
it does not understand ([RTIM.14.9]), and **must not** check either half alone.

*see also:* [LDET.3.2](#LDET-3-2), [LTSL.8.3](#LTSL-8-3), [LTSL.8.4](#LTSL-8-4), [RTIM.14.11](#RTIM-14-11), [RTIM.14.8](#RTIM-14-8), [RTIM.14.9](#RTIM-14-9)

(RTIM-14-9)=
[RTIM.14.9] **Every oracle atom must be evaluated.** For each test case, the
interpreter **must** account for every oracle atom the bundle carries under that
`test_id`, and **must** fail the case when it evaluated fewer than it found,
naming the unrecognised atom. An assertion the interpreter does not understand
is a **failure**, never a skipped line.

The count is of atoms present versus atoms evaluated. A case that carries five
assertions and evaluates four has not passed with four; it has not run.

**An atom is understood only whole.** A `Test*` or `Oracle*` atom that carries a
field its interpreter does not know is not understood, whatever its head and its
other fields: the interpreter **must** fail the atom's case, naming the atom and
the field's number, and **must not** run the atom as though the field were
absent. That field is the unknown modifier [RTIM.14.10] names. So the
interpreter **must** read each test atom in a way that lets a field it does not
know reach it.

*see also:* [RTIM.14.10](#RTIM-14-10)

(RTIM-14-10)=
[RTIM.14.10] **The loader's skip-don't-reject does not discharge [RTIM.14.9],
and cannot.** The `Test*` / `Oracle*` family is additive metadata: a runtime that does
not run tests skips it and **must not** reject a bundle on its presence
([RDSC.9.4]), and it needs no release of its own to carry them
([LDET.1.10]). Both are correct for a production runtime, which has no
business refusing a program because it carries assertions it will never read.

They are wrong for a test interpreter, and the obligation therefore splits by
**consumer** rather than by atom. A skipped assertion in production is inert; a
skipped assertion in a test run is a case reporting success over a check that
did not happen.

The consequence to note is that **the version series is not the guard here.**
For every other wire extension a reader outside the series refuses the bundle;
because this family is deliberately skippable, such a reader instead runs a
weaker test silently — an unknown modifier on a known head
degrades to the head's bare meaning, and an unknown head vanishes. [RTIM.14.9]
is the only thing standing where the ladder normally stands.

---

*see also:* [LDET.1.10](#LDET-1-10), [RDSC.9.4](#RDSC-9-4), [RTIM.14.9](#RTIM-14-9)

(RTIM-14-8)=
[RTIM.14.8] **Single eval path.** The interpreter **must**
drive the real engine and assert against the real observation surface — the mock
clock, assertion as the driver, and the stream-callback / introspection
surface ([RTIM.6]). It **must not** be a shadow or parallel evaluator: a second
evaluation path drifts from production semantics. Fresh-engine-per-case makes
the isolation free.

---

*see also:* [RTIM.6](#RTIM-6)

(RTIM-14-11)=
[RTIM.14.11] **The `where` predicate is a real rule, and that is the whole
guarantee.** A `.dstest` `produces` assertion may carry a `where` predicate on
the `emitted` head ([LTSL.8.4]). The compiler realizes it as a
**compiler-synthesized internal rule** whose LHS is `<schema> <binding> where
<pred>` — an ordinary rule `where` clause, evaluated by the same engine that
evaluates every other rule.

This is what makes the single-eval-path guard ([RTIM.14.8]) enforceable rather
than aspirational: the interpreter **must not** run a standalone or parallel
predicate evaluator, and after this realization there is no second evaluator for
it to run. A rule `where` is a network condition, not a free-standing expression
an oracle could point at.

The oracle atom (`OracleEmit`, [RDSC.7.1]) carries `has_where`, and the
interpreter binds it to its synthesized rule by the deterministic name convention
of [RTIM.14.7].

**`where_expr_id` is reserved and unassigned.** The oracle is identified by its
rule, not by an expression reference, so the field has no referent. It is
reserved under [STYL.2.8.7] and never reissued.

*see also:* [LTSL.8.4](#LTSL-8-4), [RTIM.14.8](#RTIM-14-8), [RTIM.14.7](#RTIM-14-7), [RDSC.7.1](#RDSC-7-1)

(RTIM-14-13)=
[RTIM.14.13] **The oracle rule's name.** The compiler must name the rule
[RTIM.14.11] synthesizes for a `produces` assertion `$dstest_oracle_<t>_<i>`,
and the interpreter binds the `OracleEmit` / `OraclePublish` to the rule of that
name. `<t>` is the test's `test_id`, its 1-based place among the tests the
artefact carries ([RLOW.17.1]); `<i>` is the assertion's 0-based position, in source
order, among the assertions of that test's one `produces` section ([LTSL.2.3]).
Both are written in decimal with no leading zeros.

The name is synthetic ([LLEX.10.6.1]), so no
author-declared rule can bear it, and no source text refers to it.

*ratified*  —  *see also:* [LLEX.10.6.1](#LLEX-10-6-1), [LTSL.2.3](#LTSL-2-3), [RLOW.17.1](#RLOW-17-1), [RTIM.14.11](#RTIM-14-11)

(RTIM-14-12)=
[RTIM.14.12] **The synthesized oracle rule is always built into the engine**,
unconditionally and on every compile of a test case ([RLOW.17.2]) — it is not
gated on any emission mode ([RCLI.2.1]). So the predicate of [RTIM.14.11] is load-bearing on
the test path with nothing extra required to carry it.

The synthesized oracle rules and the `Oracle*` atoms are test content, with the `Test*`
atoms ([RDSC.7.1]): test scaffolding, which a production runtime skips
([RDSC.9.4]) and does not need.

---

*see also:* [RCLI.2.1](#RCLI-2-1), [RDSC.7.1](#RDSC-7-1), [RDSC.9.4](#RDSC-9-4), [RLOW.17.2](#RLOW-17-2), [RTIM.14.11](#RTIM-14-11)

