Skip to content

Latest commit

 

History

History
1190 lines (1028 loc) · 65.2 KB

netsuke-test-framework-technical-design.md

File metadata and controls

1190 lines (1028 loc) · 65.2 KB

Netsuke test framework technical design

Front matter

  • Status: Draft.
  • Scope: The implementation architecture of the Netsukefile testing framework: pipeline integration, injection seams, the test-suite parser, the mock engine, the fixture engine, command-line integration, and the verification obligations the implementation must discharge. The user-facing dialect is normative in the companion UX and semantic design; this document does not restate its semantics except where implementation detail depends on them.
  • Primary audience: Netsuke developers implementing netsuke test, and reviewers assessing the architecture.
  • Governing documents: RFC 0007; netsuke-design.md for the compiler pipeline; ADR-0008 for environment seams; ADR-0010 for filesystem capability scoping. Accepted ADRs take precedence over this document.

1. Constraints

Non-negotiable constraints the rest of the document assumes:

  • C1 — one compiler. netsuke test calls the same public library functions as the build path: the manifest loader, BuildGraph lowering, and ninja_gen::generate. The test runner adds overlays; it never re-implements manifest semantics.
  • C2 — no ambient mutation. The runner must not mutate the process environment, the project root, or global state. All test I/O happens inside per-case cap-std sandboxes; all environment values flow through injected readers per ADR-0008.
  • C3 — no execution. No action in the first version spawns Ninja, build commands, or fixture shell commands. The stdlib command helpers are disabled under test (§5.5). When the deferred execute action does arrive it should drive NinjaProcessOptions — the narrow execution type carrying working directory, job count, and stderr suppression — rather than fabricating a Cli, since that decoupling exists precisely so non-CLI callers can run Ninja.
  • C4 — deterministic by default. Clock, network, and environment are test-controlled. An unmocked impure call is an error, not a silent passthrough.
  • C5 — localized, stream-pure output. User-facing strings go through the Fluent localization layer; --json obeys the one-document stream contract that the wider CLI roadmap mandates.

2. The gap this closes

Netsukefiles carry logic — foreach expansion, when conditions, macros, environment probes, globbing, executable discovery — and nothing verifies it. An author changes a when condition and learns whether it still matches by running a build and reading the output. That check is slow, answers differently on different machines, and cannot express the cases that matter most: a target that must not be generated, or a manifest that must fail with a particular diagnostic.

The pipeline is already shaped to close this. Manifest loading is staged and injectable, BuildGraph::from_manifest and ninja_gen::generate are public functions over plain data, and netsuke help targets has already established a restricted load mode. What is missing is a way to drive that pipeline with substituted seams and assert on what comes out. The architecture below adds exactly that, and nothing else: no second evaluator, no re-implementation of manifest semantics.

3. Architecture summary

The feature adds one new subsystem, src/testing/, plus narrow seams in existing modules. The runner parses test files into a test-suite AST, then executes each case in a child process that builds a per-case TestContext (sandbox, doubles, environment, clock), drives pipeline actions through the existing manifest/IR/Ninja code with an overlay-carrying options structure, and evaluates assertions against structured result views. The parent supervises those children and renders the report.

The process boundary exists to make --timeout enforceable (§9.1); it is not a second evaluator. The diagram below shows the flow for one case, with the parent/child split marked: discovery and parsing happen once in the parent, case execution happens in a killable child, and the CaseResult returns over a versioned frame protocol for reporting.

graph TD
    subgraph parent["parent process"]
        A["netsuke test (CLI)"] --> B[discovery]
        B --> C[test-suite parser]
        C --> D["scheduler owner<br/>queue, fail-fast, report"]
        D --> S["case supervisor<br/>deadline, kill, reap"]
        D --> N["report renderer<br/>human / JSON"]
    end
    S -->|spawn| E
    subgraph child["child process (one case)"]
        E[TestContext<br/>sandbox, doubles, env, clock]
        E --> F[fixture engine]
        E --> G[pipeline actions]
        G --> H["manifest loader<br/>(with overlays)"]
        H --> I[BuildGraph lowering]
        I --> J[ninja_gen]
        H --> K[mock journal]
        G --> L[result views]
        L --> M[assertion evaluator]
        K --> M
    end
    M -->|CaseResult frames| D
    S -->|timeout: synthesized error| D
Loading

Figure 1: Test case execution flow across the process boundary. Existing compiler components (manifest loader, BuildGraph, ninja_gen) are reused unchanged apart from overlay injection at environment-construction time. The supervisor enforces the deadline and, on expiry, supplies a synthesized errored result in place of the child's. Every result returns to the scheduler owner, which alone holds scheduling state and writes the report.

4. Pipeline integration

4.1. The pipeline today

The loader driver evaluate_manifest (src/manifest/mod.rs:160), reached through the telemetry-adapting wrapper from_str_named (src/manifest/budget/adapter.rs:13), runs six stages: read, serde_saphyr parse into a JSON value tree, MiniJinja environment construction (strict undefined; env() and glob() registered from an injected EnvReader and the glob expander; stdlib registered according to the selected StdlibRegistration; manifest vars exposed as globals), macro registration plus expand_foreach (which also evaluates when), serde_json::from_value deserialization into NetsukeManifest, and render_manifest string rendering. The fullest-parameterized entry point is from_path_with_policy_and_env (src/manifest/path_loaders.rs:114), which already accepts a NetworkPolicy, an EnvReader, and a coarse ManifestLoadStage callback.

Two ordering facts drive the design. First, foreach and when evaluate against the raw value tree before typed deserialization, so doubles for glob, env, and friends must be installed in the environment before expand_foreach runs. Second, manifest macros are registered before expansion (register_manifest_macros, src/manifest/jinja_macros/mod.rs), so macro substitution is an overlay registered after manifest macros and before expansion.

4.2. The restricted-load precedent

netsuke help targets established the pattern this framework extends. The loader selects its standard-library boundary through an enum (StdlibRegistration, src/manifest/loader_options.rs:40). At the end of the execution plan (EP-M4) it has four variants: AmbientFull for the build path rooted at the process working directory, Full for a caller-configured build, ManifestQuery for side-effect-free discovery, and Test for the deny-by-default test surface. src/manifest/query.rs owns the query boundary, and register_manifest_query (src/stdlib/register.rs:139) implements it by registering the pure helpers and replacing env, glob, fetch, shell, grep, and contents with stubs that raise a located diagnostic naming the unavailable operation.

The test runner is a fourth load mode of exactly this shape, so it extends the existing enum rather than introducing a parallel mechanism:

pub(crate) enum StdlibRegistration {
    AmbientFull,               // process-rooted build stdlib
    Full(Box<StdlibConfig>),   // caller-configured build stdlib
    ManifestQuery,             // side-effect-free discovery
    Test(Box<TestSurface>),    // deny-by-default; impure helpers refuse
}

Three consequences follow, each replacing machinery this design would otherwise have invented:

  • The disabled-helper diagnostic already exists. manifest_query_operation_error (src/stdlib/restricted_helpers/query.rs:154) is the template for the "unavailable under test" messages in §5.5; the test mode reuses the mechanism with its own message keys rather than intercepting MiniJinja's unknown-function error.
  • disabled_env_reader (src/manifest/env/reader.rs:117) already provides a reader that refuses every lookup. The test reader is that reader with the case's declared variables layered over it (§5.1).
  • src/manifest/query.rs is the precedent module for a capability-scoped non-build load, and the test runner's loader entry belongs beside it rather than in a new location.

Both restricted modes are driven from one inventory: SURFACE (src/stdlib/restricted_helpers/mod.rs:107) records a query disposition and a test disposition beside every helper whose availability depends on the load surface. register_for_test, the query refusal stubs, and the real file-test registration all consume it, and a contract test checks it in both directions, so a new helper cannot be registered without stating what each mode does with it (C5, §5.5).

4.3. Loader options

The loader gains an options-carrying entry point; the existing entry points become thin wrappers over it with default options. As implemented in EP-M2 and extended in EP-M3 and EP-M4:

/// Inputs to one manifest load beyond the YAML text and its name.
pub struct ManifestLoadOptions<'a> {
    registration: StdlibRegistration,
    environment: ManifestEnvironment<'a>,
    budget_limits: ManifestBudgetLimits,
    on_stage: Option<&'a mut dyn FnMut(ManifestLoadStage)>,
}

impl<'a> ManifestLoadOptions<'a> {
    pub fn full(config: StdlibConfig, environment: ManifestEnvironment<'a>) -> Self;
    pub fn test(surface: TestSurface) -> Self;
    pub fn with_budget_limits(self, limits: ManifestBudgetLimits) -> Self;
    pub fn with_stage_observer(self, on_stage: &'a mut dyn FnMut(ManifestLoadStage)) -> Self;
    // crate-private: ambient, manifest_query, deferred, with_registration
}

/// The capabilities granted to a manifest under `netsuke test`.
pub struct TestSurface { /* config, reader, overlays */ }

impl TestSurface {
    pub fn new(config: StdlibConfig) -> Self;
    pub fn with_env_reader(self, reader: EnvReader) -> Self;
    pub fn with_overlays(self, overlays: TemplateOverlays) -> Self;
}

/// Test-supplied template functions, registered after stdlib and manifest
/// macros and before `foreach` expansion.
#[derive(Clone, Default)]
pub struct TemplateOverlays { /* functions: IndexMap<String, OverlayCallable> */ }

impl TemplateOverlays {
    pub fn with_function(self, name: impl Into<String>, callable: OverlayCallable) -> Self;
    pub fn is_empty(&self) -> bool;
}

The fields are private and reached through constructors and builders. The public entry is the string load, from_str_with_options(yaml, name, options). A path load needs a workspace before it can decide its stdlib configuration, so it goes through the crate-private query::from_path_with_options(path, registration_for, options), where registration_for: FnOnce(ManifestWorkspace) -> Result<StdlibRegistration> derives the registration from the opened directory. ManifestLoadOptions::deferred exists only so string and path loads can share one builder chain: its registration is a placeholder that from_path_with_options always replaces.

registration carries the stdlib boundary rather than a bare StdlibConfig plus a separate NetworkPolicy, because §4.2 already binds those together per mode: the network policy for a test load is a property of StdlibRegistration::Test, not an independently settable knob. This keeps one place where a load mode's capabilities are decided. Test boxes its payload like Full, keeping the variants near enough in size that the enum stays cheap to move, and StdlibRegistration itself stays crate-private so the four load modes remain the loader's decision rather than an embedder's.

TestSurface holds three things and no more: the StdlibConfig the surface grants (including, via StdlibConfig::with_clock, the clock now() may read); an EnvReader that env() answers from; and the TemplateOverlays. Keeping the payload here rather than in the options means the registration enum never grows a second capability field. TestSurface::new installs disabled_env_reader, so with no injected reader every lookup reports "not set" rather than consulting the process. The options' own environment is ignored under Test: StdlibRegistration::env_reader returns the surface's reader, and only the surface's.

The structure is named TemplateOverlays, not EnvOverlays: in this codebase "env" means the process environment (ADR-0008, EnvReader), and these overlays substitute callables in the MiniJinja template environment. The clock deliberately does not appear here — it has exactly one owner, StdlibConfig (§5.2). on_stage keeps the existing &mut dyn FnMut shape from from_path_with_policy_and_env.

TemplateOverlays ships with the functions map only. Macro substitution (§5.4) also has to rewrite the macro-import prelude rather than merely add a global, so macro_substitutions is deferred to roadmap 7.1.3; private fields make that addition non-breaking.

OverlayCallable wraps a double's dispatch closure (§7): an Arc<dyn Fn(&OverlayCall<'_, '_>) -> Result<Value, Error> + Send + Sync>. Each invocation is described by an OverlayCall, which carries the rendering State, the argument slice (keyword arguments appended as one trailing Value, so a forwarded call reproduces the original), and the function the overlay replaced, when there was one. That last field is shadowed(): MiniJinja offers no lookup by name, but registered functions are enumerable through Environment::globals, so the loader captures the displaced function before add_function replaces it and hands it to the overlay. An overlay can therefore wrap a helper rather than only discard it, which is how a Spy resolves to the real callable (§7).

Overlay names are checked at load time, because only a load knows which vars keys and macros the manifest defines:

  • An overlay may replace any name the stdlib registered, and glob() specifically: replacing a withheld helper is the reason the mechanism exists.
  • An overlay may not take env (the loader's environment seam), a name with the __netsuke_ prefix (loader internals), a key in the manifest's vars, or a name the manifest's macros define. Each is a typed TemplateOverlayError::NameCollision carrying the namespace it collided with, rendered through the localized manifest.overlay.name_collision message and the code [netsuke::manifest::overlay::collision].
  • Validation runs before any registration, so a rejected overlay leaves the template environment untouched.

Registration order inside environment construction is:

  1. env() and glob() from the effective EnvReader and glob expander, owned by the loader because whether a load may read the host is a property of the load (C5);
  2. the stdlib surface via register_stdlib (with the test's StdlibConfig);
  3. the manifest's claimed-name namespace is computed, before its vars are registered, and is reused by the reserved-name check so the two cannot disagree;
  4. manifest vars globals;
  5. manifest macros;
  6. overlays, registered last so they shadow same-named stdlib functions (MiniJinja add_function replaces an existing registration);
  7. expand_foreach, deserialization, rendering as today.

The overlay hook is compiled unconditionally: it is an ordinary parameter, not a test-only cfg, because the test runner is a production code path of the shipped binary (C9).

For screen readers: The following flowchart follows one manifest load through from_str_with_options, branching at the StdlibRegistration mode. The AmbientFull and Full modes register the whole stdlib; ManifestQuery registers the query helpers and their refusals, which are then classified; Test registers the pure helpers and typed refusals, and applies the overlays. Every branch converges on foreach/when expansion, then on rendering and validation. The environment reader is not part of the branch: AmbientFull reads the process environment, Full takes the caller's ManifestEnvironment, Test takes the surface's injected reader, and ManifestQuery refuses env() outright.

flowchart TD
    Start[from_str_with_options] --> Mode{StdlibRegistration mode}
    Mode -->|AmbientFull| AmbientFull[Register full helpers]
    Mode -->|Full| FullMode[Register full helpers]
    Mode -->|ManifestQuery| RestrictedQuery[Register query helpers and refusals]
    Mode -->|Test| RestrictedTest[Register pure helpers and typed refusals]
    AmbientFull --> AmbientEnv["Read env from the process environment"]
    FullMode --> FullEnv["Use the caller's env reader and clock"]
    RestrictedTest --> TestEnv["Use the surface's env reader and clock"]
    TestEnv --> Overlay[Check names and register overlays]
    RestrictedQuery --> QueryClassify[Classify query refusals]
    AmbientEnv --> Expand[Expand foreach and when]
    FullEnv --> Expand
    Overlay --> Expand
    QueryClassify --> Expand
    Expand --> Render[Render and validate manifest]
Loading

Figure 2: Manifest loading paths by StdlibRegistration mode. Only the Test mode applies overlays. Full takes an environment reader from ManifestLoadOptions::full; Test takes one from its TestSurface, whose StdlibConfig may also pin the clock now() reads through StdlibConfig::with_clock. The expansion, rendering, and validation stages after the branch are shared by every mode.

4.4. Result views

NetsukeManifest already derives Serialize (src/ast/mod.rs:102), and GraphView (src/graph_view/) is an existing deterministic projection of BuildGraph with sorted nodes and edges. The assertion layer builds on both:

  • result.manifest — the rendered manifest serialized to a MiniJinja value.
  • result.graph — a TestGraphView wrapping GraphView with the helper methods the UX design promises (has_target, has_rule, target(name) field access), exposed as a MiniJinja object.
  • result.ninja — the string from ninja_gen::generate (src/ninja_gen/mod.rs:108), which is already deterministic for snapshot tests.

The IR types themselves are not exposed: the views are a stable assertion surface that can hold shape while internal IR evolves.

5. Injection seams

Each seam follows the ADR-0008 taxonomy; two exist, two are new.

5.1. Environment (existing)

EnvReader (src/manifest/env/reader.rs:59) is an Arc<dyn Fn(&str) -> Result<String, EnvReadError> + Send + Sync>. The runner builds one from the case's given.env map: declared names return their values, unset names and everything else return EnvReadError::NotPresent. The host environment is reachable only through an explicit future opt-in; the default reader never consults it (C2, C4).

5.2. Clock

Implemented. The stdlib time module owns a clock provider in the EnvReader shape (an Arc closure, because MiniJinja registration requires Send + Sync):

pub type ClockProvider = Arc<dyn Fn() -> OffsetDateTime + Send + Sync>;

It lives in src/stdlib/time/clock/mod.rs with system_clock(), the production adapter wrapping OffsetDateTime::now_utc, and fixed_clock(instant), the deterministic adapter. The seam is held in StdlibConfig alongside the existing path_override and home_directory knobs — the clock's single owner — and with_clock is the injection point; register_functions captures the provider when it installs now(), so each evaluation reads the provider again, and no provider-less call path can bypass it.

StdlibConfig stores the provider in a private WallClock container, a mechanical addition this design did not name. It confines a handwritten Debug (a closure is not printable, so StdlibConfig could not have derived one) and normalizes every read to UTC, because an injected provider is free to return any offset while now() is documented to yield UTC. Manifest-query registration receives no clock and keeps its refusing now stub.

The test runner's given.clock.now input (UX design §7) is not yet wired to this seam; the BDD suite drives it with an explicit clock fixture step instead. That wiring belongs to the runner slices, for which this seam is the prerequisite.

5.3. Network (policy, not transport)

fetch() builds its HTTP agent inline (src/stdlib/network/mod.rs), so transport injection would be invasive. The test runner does not need it: a test that wants fetch results declares a double for the fetch function itself, and overlays register after the stdlib (§4.3), so the double shadows the refusing stub. The real network code is therefore unreachable under test — either the overlay answers the call, or the refusing stub raises a diagnostic telling the author to declare one. No transport seam is built, and no live agent is ever constructed.

5.4. Macro substitution (new mechanism)

substitute("stand_in") compiles the stand-in macro from the test file through the same register_macro path as manifest macros, then installs a journalling wrapper that records the call and delegates to the compiled stand-in. Signature arity is validated when the macro is called, as with ordinary manifest macros; earlier validation is a possible refinement, not a first-version requirement.

Installing that wrapper takes more than add_function. register_macro does two things per macro: it adds a global function, and it appends {% from '<template>' import <name> %} to a MACRO_IMPORTS_GLOBAL string that render_template (src/manifest/jinja_macros/mod.rs) prepends to every template it renders. An imported macro binds a template-local name, and template-local names resolve ahead of environment globals — so a same-named add_function overlay is shadowed at render time, and a substituted compile_cmd would still run the original macro while journalling nothing.

Macro substitution therefore edits the prelude as well as the global: for each substituted name the overlay removes that name's entry from MACRO_IMPORTS_GLOBAL and re-adds an import bound to the stand-in's compiled template. Both halves are one operation and must stay together; the phase-1 spike (§14) covers the prelude rewrite, not merely add_function replacement, because the prelude is the half that actually decides which macro renders.

5.5. Stdlib configuration under test

The runner constructs a per-case StdlibConfig (src/stdlib/config/mod.rs:26) rooted at the sandbox:

Knob Test value
workspace_root the case sandbox directory (cap-std Dir)
network_policy deny all
path_override, pathext_override empty; which refuses rather than searching
home_directory HomeDirectory::Missing
command helpers registered as refusing stubs (C3)

Table 1: Per-case stdlib configuration.

Every helper whose availability depends on the load surface has a TestDisposition row in SURFACE (src/stdlib/restricted_helpers/mod.rs:107), and register_for_test registers exactly the refused rows as stubs. The implemented inventory is:

Kind Refused under test Available under test
Function glob, fetch, which, command_available env (injected reader), timedelta
Filter which, shell, grep, contents, realpath, expanduser, size, linecount, hash, digest basename, dirname, with_suffix, relative_to, shell_quote, shell_join, uniq, flatten, compact, group_by
Test dir, file, symlink, pipe, block_device, char_device, device —

Table 2: The netsuke test stdlib surface.

now() is a fifth disposition, ClockInjected: it is the real helper when the surface's StdlibConfig carries an injected clock (§5.2) and a refusal otherwise, because the ambient clock is a host read. env() is available but reads only the surface's injected EnvReader, never the process.

Refusing stubs beat omission: under strict-undefined MiniJinja an absent function yields a generic unknown-function error, whereas a registered stub raises a located diagnostic that names the operation and points at the overlay syntax. The test mode supplies its own message key (stdlib.test_mode.helper_unavailable, [netsuke::jinja::test_mode::unavailable]) through the existing manifest_query_operation_error shape, and every refusal carries a typed TestModeRefusal source so a caller can tell a withheld capability from an unknown name without matching on text. Because a real helper documents various call shapes, each stub accepts any positional and keyword arguments; a narrower signature would report an argument-count error instead of the refusal.

Two refusals are deliberate deviations from the "just sandbox it" reading, and both are recorded in ADR-0070:

  • which refuses even though path_override and pathext_override exist. Those knobs choose where a build looks; a test load has no host path to look in, and a sandbox-rooted resolver is not implemented yet. Running which against an empty PATH would report a misleading "not found" instead of a refusal that names the withheld capability, so refusal is uniform with the rest of the surface.
  • expanduser refuses rather than resolving ~. The surface's home_directory is HomeDirectory::Missing, so the real filter would fail anyway, and a resolved home path would expose a host-shaped answer. The refusal names the operation instead.

Of the StdlibConfig settings, test mode honours only the clock in roadmap 7.1.2; the workspace root becomes load-bearing when 7.4.1 roots glob, the file tests, and the file-reading filters at it.

The functions among the refused rows (glob, which, fetch, command_available, and a system-clocked now) remain replaceable by overlays (§4.3); filters and tests are not mockable in the first version (UX design §8.6), so a manifest that pipes through shell or calls file under test fails with the refusal rather than a substituted answer.

workspace_root alone does not achieve that scoping, and the design must not pretend otherwise. Three groups of filesystem helpers do not honour it yet:

  • glob() is registered in src/manifest/mod.rs over glob::expand_glob(&pattern), which takes no workspace root. Its matcher traverses ambiently, and the capability it opens is rooted at the pattern's literal prefix — . for a relative pattern, meaning the process working directory. ADR-0010 records the ambient traversal as an accepted limitation of the build path.
  • File tests (dir, file, symlink, and the rest) reach path::file_type_matches, whose parent_dir helper calls Dir::open_ambient_dir(.., ambient_authority()). register_file_tests never receives StdlibConfig at all.
  • The file-reading filters contents, linecount, hash, and digest resolve through ReadingRoot, the workspace capability the build path supplies (see the design), so their argument no longer comes from the process working directory; size and realpath (src/stdlib/path/filters.rs) still take that directory. Test mode has no sandbox-rooted equivalent, so the group's confinement in a build does not give a test its own root.

Left unaddressed, a fixture-built project would be globbed from the runner's working directory instead of its own sandbox, which is both host-dependent and the exact non-determinism this framework exists to remove. The test registration will therefore supply sandbox-rooted adapters for all three groups: glob() resolves relative patterns against the case sandbox Dir, and the file tests and file-reading filters resolve their paths through the same handle, rejecting escapes rather than falling back to ambient authority. The filters matter as much as the other two because filters cannot be replaced by doubles in the first version (UX design §8.6): without an adapter, a manifest that hashes or reads a file could never be tested. These adapters are test-mode components, not changes to the build path's behaviour, so ADR-0010's accepted limitation stands for builds while tests get the stronger guarantee they require.

The adapters land in stages, and until they do the test registration refuses all three groups rather than falling back to ambient authority (roadmap 7.1.2). Refusal is the interim behaviour, so a manifest under test that globs, tests a file, or reads one gets a located diagnostic naming the withheld capability — not a host-dependent answer. Roadmap 7.4.1 replaces the refusals with the sandbox-rooted adapters for all three groups. The visibility consequence below holds in both states, because a refusal reaches no file at all.

Once those adapters are in place the visibility consequence is worth stating plainly: the project tree is not visible to a manifest under test. A default-subject test sees only the files its fixtures and given.fs created. Invariant I4 (§12) is scoped accordingly, and invariant I5's no-ambient-filesystem claim depends on these adapters existing.

6. Test-suite AST and parser

A separate AST in src/testing/ast.rs; NetsukeManifest is not stretched.

pub struct TestFile {
    pub netsuke_test_version: DialectVersion, // MAJOR.MINOR, not semver
    pub imports: Vec<Utf8PathBuf>,
    pub vars: IndexMap<String, YamlValue>,
    pub macros: Vec<MacroDefinition>,        // reused from src/ast/mod.rs
    pub fixtures: IndexMap<String, FixtureDef>,
    pub cases: IndexMap<String, TestCase>,   // test_* keys, document order
}

Parsing partitions top-level keys: the five known keys deserialize into typed structures with deny_unknown_fields; keys matching test_[A-Za-z0-9_]+ deserialize as TestCase; anything else is a diagnostic with a nearest-known-key suggestion. IndexMap preserves declaration order for cases, let bindings, and mock entries, because the dialect's semantics depend on document order.

Discovery reads the manifest's tests block by raw extraction of the top-level tests key from the serde_saphyr value tree, with no template evaluation — so discovery works before the subject's template environment exists, and succeeds even when the subject manifest does not load. Imports form a directed acyclic graph: a cycle is a suite error naming the cycle, and resolution depth is capped. Support files parse once per run into shared immutable declarations, not once per case.

Validation at parse time: duplicate keys (already fatal in serde_saphyr), at least one step per case, at least one of given/when/then per step, fixture references resolve, imports stay inside the test tree, expression fields reject {{-style template syntax (the UX design's expression/template split), and matcher objects use only the closed vocabulary.

The tests block on the manifest side is a new optional field on NetsukeManifest with deny_unknown_fields semantics preserved; compatibility consequences are covered in RFC 0007.

7. Mock engine

src/testing/mocks.rs owns double state:

pub struct DoubleRegistry {
    doubles: IndexMap<String, Double>,
    journal: Journal,
}

pub struct Double {
    pub kind: DoubleKind,                 // Stub | Mock | Spy
    pub ordered: bool,
    pub lenient: bool,
    pub entries: Vec<CallEntry>,          // first-match-wins
}

pub struct CallEntry {
    pub matchers: Vec<ArgMatcher>,
    pub response: Response,               // Returns(Value) | Raises(..)
    pub times: Option<u32>,
    pub matched: Cell<u32>,
}

Dispatch acquires the registry lock, appends the invocation to the journal, selects a response, and releases the lock before producing it. Selection scans entries for the first matcher-accepting entry with remaining times budget. Ordering changes both which entries are eligible and what a mismatch means:

  • Unordered (the default) considers every entry in declaration order and takes the first that accepts the arguments and has budget left.
  • ordered: true considers only the next unconsumed entry. An entry without times is never consumed, so it stays the candidate for every subsequent call and later entries remain unreachable behind it — an unbounded entry in an ordered double is therefore a terminal entry, and the parser warns when one precedes another. An entry with times: N is consumed after its Nth match, and the next entry becomes the candidate.

A mismatch never silently skips ahead in an ordered double: if the candidate entry rejects the arguments, dispatch fails rather than searching later entries, because declaration order is precisely what the author asked to pin. Unordered doubles fall through to later entries and fail only when none accepts. Tests cover repeated calls against an unbounded entry, an unbounded entry followed by another, and a mismatch under both ordering modes. A Mock with no accepting entry yields a MiniJinja error carrying a structured payload, which the runner converts into the unmatched-call report with its suggested YAML stanza. A Stub falls back to its default or Undefined. A Spy resolves to a handle for the real callable. MiniJinja offers no lookup by name, but registered functions are enumerable as environment globals, so a handle can be captured rather than reconstructed: the loader's overlay registration (§4.3) walks Environment::globals before add_function replaces a name and hands the displaced function to the overlay as OverlayCall::shadowed. A spy built on an overlay therefore delegates to the function it replaced instead of the runner having to re-create it.

Releasing the lock before invoking a spy's delegate is load-bearing, not an optimization. A spied callable may call another double — a spied macro whose body calls a mocked glob is the ordinary case — and that nested dispatch re-enters the same registry. Holding the lock across the delegate would deadlock the case. Dispatch therefore returns a resolved action while unlocked, and the nested call takes the lock in its own turn. A test covering a spy that invokes a second double guards this.

Journal entries record the arguments and the origin of the response. Where a CallEntry answered the call, that origin is a (double, entry_index) pair rather than a Rust reference or a cloned response value: a borrowed &CallEntry would make the journal self-referential within DoubleRegistry, whereas the index pair is stable across the case, keeps response-value deduplication a separate concern (the value still lives once in its CallEntry), and survives the registry being locked and unlocked around each dispatch.

Not every response comes from an entry, so the origin is an enum rather than a bare pair. A Stub that matched nothing answers from its default or with Undefined, and a Spy answers from the captured real callable; neither has an entry index to name. The journal therefore records ResponseOrigin::Entry { double, entry_index }, ::StubDefault, or ::Delegate, and every call appends exactly one entry whichever branch answered it. Routing all three through the same append keeps call_count and the ordered call list complete — an assertion on a spied or defaulted call would otherwise silently see nothing — and gives the serialized form an explicit discriminant instead of a sentinel index. The per-double journal ceiling from the UX design is enforced at append time; breaching it turns the case into an error naming the double.

Registry state is per case and lives behind an Arc<Mutex<..>> captured by the overlay closures; nothing is process-global, so parallel cases cannot observe each other (invariant I1, §12). Overlay dispatch runs under catch_unwind: a panic inside matcher evaluation or value conversion becomes a case error, and the registry lock recovers from poisoning so end-of-case verification can still report the journalled calls.

End-of-case verification walks the registry. A Mock entry that never matched a call is an unmet expectation and fails the case. times plays no part in that judgement: it is a maximum-call budget, so an entry declared times: 3 that matched once or twice is satisfied, and only an entry that matched zero times is unmet. Nothing fails merely because a budget went unspent. Doubles with zero journal entries raise the unnecessary-double warning unless lenient.

Matcher evaluation is a closed enum (Exact(Value), Any, IsA(TypeName), Regex(compiled), Contains(Value), StartsWith(String), Not(Box<ArgMatcher>)) compiled at parse time so an invalid regex is a suite error, not a mid-run surprise. Exact backs both the bare-argument form and the eq: escape hatch; the parser lowers both to it.

8. Fixture engine

src/testing/fixtures.rs resolves the case's requested fixtures into a dependency graph (uses edges), topologically sorts it — a cycle is a suite error naming the cycle — and executes setup actions in order. A topological sort leaves independent fixtures mutually unordered, so the sort breaks ties deterministically rather than by hash iteration order. The tie-break applies only among ready fixtures — those whose dependencies are already satisfied — so it never reorders a fixture ahead of something it uses: dependency precedence decides first, and the tie-break only chooses between candidates that are equally eligible. Among those, fixtures the step requested come first in request order, then fixtures pulled in solely as uses dependencies in declaration order within their file. Two fixtures that depend on nothing therefore always set up in the same sequence, and reverse-order teardown follows from the resulting setup order. A test with several independent fixtures asserts both the setup and the teardown sequence. Each case owns one sandbox: a temporary directory opened as a cap-std Dir, within which tmpdir, mkdir, write, copy, and remove operate by relative path. Absolute paths and .. traversal are rejected at action-evaluation time, keeping fixtures inside the capability boundary that ADR-0010 established for globbing.

Subject-manifest paths pass through the same boundary before the loader sees them. open_manifest_workspace accepts any path and opens its parent with ambient authority, which is right for netsuke build -f <path> but too wide for a test: it would let a case read anything the invoking user can read. The test runner therefore resolves and validates each author-supplied subject path — the action's manifest argument, given.subject, and the case's subject — after template evaluation and before opening the workspace, rejecting absolute paths and any path escaping the case sandbox, including through symlinked components that already exist. The enclosing project's Netsukefile is the one approved path outside the sandbox, admitted read-only. This is a test-mode restriction layered above the shared loader, not a change to the build path's behaviour. Fixture env actions write into the case-level environment map owned by TestContext, before given.env is applied over them.

All case sandboxes live under one per-run root named netsuke-test-<pid>-<nonce>. The runner installs an interrupt handler that stops scheduling, terminates and reaps live children, tears down completed fixtures, removes the run root unless --keep, and exits with the interrupted code. Every selected case still reaches the report exactly once (I9), which requires assigning a status to two groups the normal path never produces: a case whose child the parent terminated is errored, with an interruption diagnostic and whatever journal arrived before the signal; a case that never started is skipped. The scheduler owner applies the same sorted file and declaration ordering it uses for a completed run before rendering, so an interrupted run's report is deterministic rather than ordered by how far the run happened to get. An interruption report test covers a run containing all three groups — finished, terminated, and never started. A SIGKILL of the parent still a SIGKILL still leaks, so the recognizable naming scheme plus age-based reaping of stale run roots at the start of the next run makes leaks self-healing. A case whose sandbox cannot be provisioned is errored and isolated; only failure to create the run root itself aborts the run.

Teardown obligations (UX design §9) are implemented with a completion stack: each fixture pushes onto the stack only after its setup finishes, and case cleanup pops the stack unconditionally — after assertion failures, action errors, and fixture-setup failures alike. A teardown error does not stop the unwind: remaining entries still pop, the errors aggregate into the report, and the sandbox is retained. --keep skips sandbox deletion for failing cases and prints the retained path.

Fixture exports are Jinja templates evaluated against the fixture's local bindings (for example the tmpdir name) and exposed to let and assertions as fixtures.<name>.<field>.

9. Actions and the case runner

src/testing/actions.rs implements the three pipeline actions as thin compositions of public library functions:

  • load_manifest → manifest::from_str_named-equivalent entry with ManifestLoadOptions (§4.3);
  • build_graph → BuildGraph::from_manifest (src/ir/from_manifest/mod.rs:49) over the loaded manifest;
  • generate_ninja → ninja_gen::generate over the built graph.

BuildGraph::from_manifest lowers path placeholders for RecipeShell::host_default(), so quoting in the resulting command text differs between a POSIX host and a Windows one. The test runner keeps that default rather than pinning a shell: invariant I4 requires a case to lower exactly as netsuke build would on the same machine, and pinning would break that on Windows. The consequence belongs in the dialect's contract rather than in a footnote — an assertion over raw result.ninja text containing quoted paths is host-sensitive, whereas the graph view's structural helpers are not. Authors testing recipe text across platforms should assert through the view, and a future dialect addition may expose from_manifest_for_shell so a case can pin a shell deliberately.

Within a step, the actions share one pipeline pass: build_graph and generate_ninja extend the step's memoized artefacts rather than re-running the loader, which keeps a three-action when at one template evaluation and makes journal counts independent of the action list (the UX design §10 makes this the observable contract). A later step's action starts a fresh pass.

Each action produces an ActionResult { action, ok, views, error }. The case runner keeps them in a results: Vec<ActionResult> that accumulates across the whole case in execution order, never resetting between steps. result is sugar for the last element. Assertions index the history positionally — results[0], results | length — so a step that runs load_manifest then generate_ninja can compare the two stages, and a later step can still read an earlier step's outcome. Indices are stable because actions only ever append.

An action failure with expect_failure in the following then is a normal comparison; without it, the failure fails the case at the point of the first assertion that needs a missing view (or immediately when the step has no then).

The scheduler runs cases in parallel up to --jobs (defaulting to available parallelism), one case per worker. Every piece of mutable scheduling state has exactly one owner, the scheduler owner: the pending-case queue, fail-fast state, which cases are claimed, and the conversion of unclaimed cases into skipped results. It is also the sole writer of the report. Nothing else in the run may read or modify that state.

Workers own no scheduling state. A worker executes only the case the scheduler owner assigns it, supervises one child at a time (§9.1), and sends back a finished, immutable CaseResult — whether the child produced it or the supervisor synthesized it after a timeout. Workers never test fail-fast state and never claim a case for themselves.

That single ownership is what makes the concurrency tractable. Results arrive from many workers at once, but the scheduler owner processes each one in a single ordered state transition:

  1. Receive a CaseResult from a worker.
  2. Classify it as passed, failed, or errored.
  3. If --fail-fast is in force and this is the first failed or errored result, activate fail-fast.
  4. If fail-fast is not active, assign the next pending case to the now-idle worker.
  5. Otherwise mark every remaining unclaimed case as skipped.

Because steps 3 and 4 happen inside one transition, no assignment can slip between observing a failure and acting on it: the ordering is a property of the transition, not of timing. Cases already in flight are untouched and run to completion, so their teardown and journal handling are unaffected; only unclaimed cases become skipped, which keeps the report totalling the full selection (I9).

Sole ownership of the report has the same effect on output. The scheduler owner buffers results and restores sorted file order, then declaration order within each file, before rendering, so cases may finish in any order while human and JSON output stay byte-stable. A test that completes cases deliberately out of order and diffs both renderings guards this.

Case execution runs under catch_unwind inside the child; a panic that escapes it becomes an abnormal child exit, which the supervisor records as an errored case. Either way the worker survives and every selected case reaches the report (invariant I9). Process isolation strengthens this: a child that aborts outright can no longer take the run down with it.

9.1. Enforcing the per-case timeout

--timeout is a hard per-case wall-clock bound, not a best-effort one. Making it hard requires a cancellation boundary, because MiniJinja evaluation is not preemptible: a single large loop inside one target field can run indefinitely inside one render_template call, yielding to no checkpoint the runner controls. Cooperative deadline checks alone cannot bound that, so each case executes in an independently killable child process.

The split is deliberately narrow. The parent keeps discovery, parsing, scheduling, timeout enforcement, child reaping, and all report rendering. The child executes exactly one case — fixtures, overlays, pipeline actions, assertions — and returns a CaseResult. Nothing about the compiler pipeline changes: the child runs the same loader, IR builder, and generator as before (C1), so this is an execution boundary, not a second evaluator.

Timeout behaviour in the parent:

  1. Start the deadline before spawning, so spawn cost counts against the case rather than being free.
  2. Wait with wait_timeout, exactly as src/stdlib/command/execution.rs already bounds stdlib command helpers.
  3. On expiry, kill the child and reap it. std::process::Child::kill maps to SIGKILL on Unix and TerminateProcess on Windows, so termination needs no platform-specific code; CI covers both through the Namespace Ubuntu and Windows profiles.
  4. Collect a partial result if the protocol delivered one complete frame before termination; otherwise synthesize an errored CaseResult carrying a timeout diagnostic.
  5. Attach whatever mock journal arrived, so a timed-out case still shows which doubles it reached.

The child streams to the parent over its stdout pipe using length-prefixed serde_json frames, versioned like the existing json_envelope (SCHEMA_VERSION) so parent and child cannot silently disagree. serde_json is already a dependency; no IPC crate, socket, or named pipe is introduced. Frames are bounded — a journal ceiling breach truncates rather than streaming without limit — and the parent treats a truncated final frame as "no complete result", falling to step 4.

The stream carries more than one final result, because a terminated case would otherwise report an empty journal however much it had done. The child emits an incremental journal frame as calls accumulate, so the parent holds a checkpoint of everything recorded before the signal arrived. Step 5's "whatever mock journal arrived" is exactly this: the last checkpoint, not a best guess. Checkpoint frames are the same versioned envelope as the result frame and are equally bounded, and the parent discards them once a complete CaseResult supersedes them. A deterministic test kills a case after a known journal entry and asserts the parent's report contains that entry. The child's stderr is captured and folded into the case's diagnostics rather than leaking into the parent's stream, preserving stream purity (I8).

Cooperative checkpoints remain, and are now the graceful path rather than the only one. The deadline is still checked at overlay dispatch, loader stage callbacks, each fixture setup and teardown action, between pipeline actions, and between assertions; macro depth and foreach expansion ceilings still apply. A case that reaches a checkpoint reports itself cleanly with a full journal and completes its own teardown. Termination is the backstop for the case that never reaches one. The design does not claim that a blocked in-process action is interrupted where it stands: it claims the process running it is killed.

Cleanup ownership follows the same split:

Situation Teardown performed by
Normal completion child, before sending its result
Cooperative timeout child, after marking the case errored
Forced termination parent, over the case sandbox
Child panic parent, after observing abnormal exit
Interruption (Ctrl-C) parent, for every live child and the run root

Table 2: Fixture teardown ownership.

The parent does not replay per-fixture teardown for a child it killed, and so needs no hand-off of the completed-fixture list. It does not need one because every effect a fixture has is either inside the case sandbox or inside the child: filesystem actions write within the sandbox, and env actions mutate only the child's in-process map, which dies with it. Removing the sandbox therefore is complete teardown for a terminated case, and it is idempotent — safe whether the child had torn down nothing, some, or everything before it died.

This scopes I2 precisely. Reverse-order, exactly-once teardown is a guarantee about teardown the child performs; parent-side cleanup after forced termination is sandbox-level and makes no ordering claim, because there is no surviving ordered state to unwind. Termination-during-setup tests cover both hazards this creates: a fixture killed mid-setup, whose partial artefacts must still disappear, and a fixture whose teardown the child had already completed, where the parent's removal must not double- apply or error.

Case sandboxes stay under the existing per-run root, so the parent can always finish cleanup a dead child left undone. A timed-out case retains its sandbox for inspection, on the same terms as --keep, and the path is printed. The parent reaps every child it spawns, including on the interrupt path, so no zombies survive the run.

10. CLI integration

src/cli/parser/mod.rs gains Commands::Test(TestArgs) with the flags from the UX design §12. Like GraphArgs, the purely per-invocation flags are #[serde(skip)]ed out of OrthoConfig layering; candidates for config-file defaults (jobs, display policy) follow the existing precedence rules. src/runner/dispatch.rs routes the variant to testing::run, which owns discovery, scheduling, and process exit-code mapping (0, 1, 2, 3, and 130 per the UX design). Interruption keeps its own exit result and is not folded into the internal-runner-error class.

New user-facing strings — report lines, diagnostics, warnings — get keys in src/localization/keys.rs and Fluent messages. The build-time completeness audit requires the keys in every registered locale (34 catalogues beyond en-US), so the string surface is a real delivery cost: keys are defined early in the phasing, not at the end, so translation lands in batches rather than as a release-blocking cliff. Two artefacts are deliberately locale-invariant machine output, not localized prose: the suggested YAML stanza for unmatched calls and the expression-with-values rendering in failure reports.

11. Reporting

src/testing/report.rs renders both formats from one SuiteReport structure. Human rendering streams per case through the design-token/display-policy machinery like other commands; only JSON buffers the whole run, emitting exactly one document carrying the format_version field (C5, UX design §13). failed and errored are distinct case states throughout, and each failure record carries the rendered expression-with-values text — truncated per the UX design's elision rule — so CI consumers get the same diagnostic a terminal user sees without unbounded report growth.

12. Verification obligations

Named invariants the implementation must discharge, with their verification methods. These are design commitments, not a test-type list.

  • I1 — case isolation. No double, journal entry, environment binding, fixture export, or sandbox file from one case is observable from another, including under --jobs parallelism. Method: concurrent integration tests that deliberately reuse double and fixture names across cases and assert disjoint journals.
  • I2 — teardown exactly once, reverse order. Every fixture whose setup completed tears down exactly once, in reverse setup order, on every exit path the child controls: normal completion, assertion failure, action error, fixture-setup failure, and cooperative timeout. Forced termination is excluded by construction, because the child is gone and no ordered state survives it; there the guarantee is weaker and stated separately — parent-side cleanup deletes the case sandbox, which is idempotent and makes no ordering claim (§9.1). Method: proptest over randomly generated fixture dependency graphs of at most 16 fixtures, with injected failures at each lifecycle point, asserting the teardown sequence property; case counts are bounded in the nextest profile so this suite cannot become the slowest gate. Termination-during-setup tests cover the excluded path separately.
  • I3 — strict mock determinism. An unmatched call on a Mock fails the action at the call site; the journal preserves call order, arguments, and responses. Method: unit tests per matcher and dispatch rule; rstest parameterized cases over the matcher vocabulary.
  • I4 — semantic fidelity. For any manifest with no doubles declared whose file observations are confined to the sandbox (fixture-provided files) or fully doubled, load_manifest/build_graph/generate_ninja under netsuke test produce results identical to the build path run over the same tree. The scoping is forced by §5.5: the sandbox root means a manifest observing the project tree legitimately differs under test. Method: differential tests that run both paths over the example manifests inside one tree and compare serialized outputs; insta snapshots of the generated Ninja.
  • I5 — no build execution, no network, no ambient environment. Under test, no build command, Ninja invocation, or fixture shell command runs; no socket is opened; and no host environment variable is read outside an explicit opt-in. The per-case child process (§9.1) is the runner supervising itself, not the manifest executing anything, and it inherits every restriction in this list. Method: the seams make these unrepresentable (impure helpers registered as refusing stubs, deny-all policy, closed EnvReader); negative tests assert every refusal diagnostic.
  • I6 — schema strictness. Unknown keys anywhere in the test dialect fail with a located diagnostic. Method: table-driven negative parser tests covering each structure.
  • I7 — build-path neutrality. A manifest containing a tests block behaves identically under build, graph, generate, and clean to the same manifest without it. Method: differential snapshot tests.
  • I8 — report stream purity. --json emits exactly one report document on stdout with empty stderr whenever the run completes — whether every case passed, some failed or errored (exit 1), or the run was interrupted (exit 130). Only a command failure — invalid suite or selector, zero selected cases without --allow-empty (exit 2), or an internal runner error before a report can be assembled (exit 3) — suppresses the stdout document and emits one diagnostic document on stderr instead. The distinction matters because a completed run with failing cases is the primary thing automation reads from stdout; emptying stdout there would defeat --json. Method: the existing stream-purity behavioural test pattern extended to test, with cases for each exit class.
  • I9 — conservation of cases. Every selected case appears in the report exactly once, as passed, failed, errored, or skipped — including under child panic, forced termination, and interruption. Method: scheduler tests with injected panics and deadline breaches, asserting report totals against the selection count. A deterministic scheduling test additionally drives several results into the scheduler owner concurrently, including the first failed result, and attempts a next-case assignment at the same moment. It asserts that no case is assigned after the transition that recorded the first fail-fast-triggering result, and that every unassigned case is reported as skipped. Driving the transitions rather than sleeping keeps it reproducible.
  • I10 — the timeout is enforced. No case exceeds its deadline by more than the termination and reaping window, whatever the manifest does. Method: a case whose manifest contains a deliberately non-cooperative template expression — one large enough to run indefinitely inside a single render with no checkpoint — asserting that the run terminates, the case is errored with a timeout diagnostic, its partial journal survives, its sandbox is retained, its fixtures are torn down, no child process outlives the run, and --json still emits exactly one document. Cooperative expiry is covered separately and deterministically through an injected clock: a fixture setup action that passes a checkpoint after the deadline must error the case, keep the partial journal, and tear down every fixture whose setup completed; a teardown action that does the same must continue unwinding the remaining stack, aggregate its errors, retain the sandbox, and report the case as errored. Neither test depends on wall-clock delays.

The combinatorial surface that carries the highest interaction risk is double kind × ordering × times × matcher type. I3's parameterized suite enumerates kind, ordering, and times exhaustively and pairs them with each matcher type individually. Full four-way enumeration is not run, but structural separation is not offered as the reason: matching and consumption meet in entry selection, so the interaction is real and the suite covers it directly with named cases —

  • a first entry whose times budget is exhausted, so a later entry with a broader matcher must take the call;
  • an ordered double whose next entry rejects the arguments, pinning whether selection falls through or fails;
  • a catch-all entry after a specific one, in both declaration orders, confirming first-match-wins rather than best-match;
  • a times-bounded entry that is never exhausted, confirming a maximum does not become a minimum (UX design §8.2).

These are the cases where a bug would otherwise hide behind the independence claim.

New tests/*.rs files land as real Cargo targets; the existing integration-test wiring contract test enforces this automatically.

13. Module layout

src/testing/
  mod.rs          — public run() entry, suite orchestration
  ast.rs          — test-suite AST
  discovery.rs    — tests root resolution, include/exclude, imports
  parser.rs       — YAML parsing, test_* partitioning, validation
  eval.rs         — expression evaluation, expression/template split
  context.rs      — TestContext, sandbox, result views
  fixtures.rs     — fixture graph, setup/teardown
  actions.rs      — pipeline actions
  supervisor.rs   — child spawn, deadline, kill, reap
  protocol.rs     — versioned length-prefixed CaseResult frames
  mocks.rs        — DoubleRegistry, matchers, journal
  assertions.rs   — assertion normalization and evaluation
  report.rs       — SuiteReport, human and JSON rendering
  errors.rs       — thiserror diagnostics for the subsystem

Existing modules touched: src/manifest/mod.rs (options entry point, StdlibRegistration::Test, overlay registration), src/manifest/query.rs (test-mode loader entry beside the query entry), src/stdlib/register.rs (test-mode registration), src/stdlib/time/ (clock seam), src/stdlib/config/ (clock in StdlibConfig), src/ast/mod.rs (optional tests field), src/cli/parser/mod.rs and src/runner/dispatch.rs (command wiring), src/localization/keys.rs (strings). Errors are semantic thiserror enums per module, composed into the runner's reporting. The supervisor reuses the wait_timeout-then-kill-then-reap pattern already proven in src/stdlib/command/execution.rs, and protocol.rs follows the src/json_envelope.rs versioning convention rather than inventing its own. The subsystem follows whichever diagnostic direction (miette versus anyhow) the in-flight migration settles on, and must not add new dependencies on the deprecated path.

14. Phasing

The minimum viable implementation, in dependency order:

  1. Overlay spike, clock seam, and ManifestLoadOptions refactor (no behaviour change; I4/I7 differential tests land here). The spike comes first because it gates the overlay architecture: it pins MiniJinja add_function replacement semantics for shadowing, and the runner-side handle capture that spies depend on (§7). If shadowing fails, the fallback is filtering the macro out of register_manifest_macros via TemplateOverlays, which the options structure already permits. Roadmap 7.1.2 settled both questions: add_function replaces a registration, and the displaced function is reachable by enumerating Environment::globals before replacement (§4.3, §7).
  2. Test-suite AST, parser, and discovery (I6). Localization keys for the dialect's diagnostics are defined from this phase onwards (§10).
  3. Mock engine and overlays for functions and macro substitution (I1, I3).
  4. Fixture engine and sandbox (I2).
  5. Actions, result views, and the case supervisor with its frame protocol (I9, I10).
  6. Assertion evaluation and the failure taxonomy.
  7. CLI wiring, remaining localization, and reporting (I5, I8).
  8. Author-facing documentation: a users' guide chapter on writing and running manifest tests, indexed from contents.md.

Deferred work is enumerated in the UX design §15; nothing in this architecture forecloses it. Roadmap phase 7 tracks these deliverables as numbered tasks.

15. Synchronization

This document must be kept in step with the decisions and documents that govern it. When any of the following change, this document is updated in the same change set or the divergence is called out explicitly here until it is reconciled:

  • The UX design, which is normative for dialect semantics; implementation detail here must not contradict it.
  • RFC 0007, which positions and scopes the feature.
  • ADR-0008, which governs the environment injection seams §5 relies on.
  • ADR-0010, which governs the glob capability scoping the mock engine and sandbox rely on.
  • ADR-0070, which records the deny-by-default test stdlib surface, its refusal mechanics, and the which/expanduser deviations §5.5 describes.
  • Roadmap phase 7, which tracks the phasing above (§14) as numbered deliverables.

If an accepted ADR changes, the ADR wins: this document is either updated to match or the divergence is recorded here until it is.