✓
Passing This code compiles and runs correctly.
Code
// Pins: the test block std/compiler's own test lowering generates must reach
// the emitted program.
//
// processTestFlow (koru_std/compiler.kz:1423) parses a test body, substitutes
// each mocked event by writing `const __mock_result_N = <mocked branch>` plus
// the binding extraction for the branch the mock forces
// (compiler.kz:1722-1773), and hands the finished `test "..." { ... }` back as
// an inline_code item that replaces the test flow.
//
// That pass only ever sees a live test flow when the coordinator puts
// test-generation ahead of elaborate: std/testing's test transform
// (koru_std/testing.kz:225) runs inside elaborate's run-pre-transforms
// (compiler.kz:1249) and consumes every test invocation, so under the default
// order (compiler.kz:757) test-generation finds nothing to do. The coordinator
// override below is the shape 430_COORDINATION/8401_custom_coordinator_bug and
// 430_008_pipeline_profiling already pin.
//
// post.sh reads output_emitted.zig with the variant-coverage checker's own
// bare-token predicate and requires a __mock_result_N token in bare code.
// See BUG.md.
import std/compiler
import std/optimizer
import std/testing
import std/io
std/compiler:coordinate = std/compiler:context-create(program_ast, allocator): c0 |> std/compiler:test-generation(ctx: c0): c1 |> std/compiler:elaborate(ctx: c1): c2 |> std/compiler:transform-taps(ctx: c2): c3 |> std/compiler:analysis(ctx: c3)
| ctx c4 |> std/optimizer:optimize(ctx: c4): c5 |> std/compiler:emission(ctx: c5): c6 => coordinated {
c6.ctx.ast,
c6.code,
metrics: "test-generation ran before elaborate"
}
| failed f => error f.message
tor withdraw { amount: u32 }
| success u32
| insufficient-funds
test(mock substitution binds the mocked branch) {
withdraw => success 50
withdraw(amount: 100)
| success s |> _
}
std/io:print.ln("test-generation pass ran")
Flows
subflow ~coordinate click a branch to expand · @labels scroll to their anchor
context-create (program_ast, allocator)
flow ~test click a branch to expand · @labels scroll to their anchor
test (mock substitution binds the mocked branch, source: withdraw => success 50
withdraw(amount: 100)
| success s |> _)
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "test-generation pass ran")
Test Configuration
Post-validation Script:
#!/bin/bash
# The generated test block must reach output_emitted.zig. Decided with the
# variant-coverage checker's own bare-token predicate, not a plain grep: the
# whole point is bare code versus a string literal, which grep cannot tell
# apart.
cd "$(dirname "$0")"
ROOT="$(cd ../../../../.. && pwd)"
python3 - "$ROOT" <<'PY'
import sys
from pathlib import Path
root = Path(sys.argv[1])
sys.path.insert(0, str(root / "invariants" / "checks"))
from check_variant_coverage import bare_tokens, marker_pattern
artifact = Path("output_emitted.zig")
if not artifact.exists():
print("FAIL: no output_emitted.zig — the backend never emitted the program")
sys.exit(1)
pattern = marker_pattern("__mock_result_{}")
hits = sorted(t for t in bare_tokens(artifact) if pattern.match(t))
if hits:
print("PASS: emitted program carries the mock substitution:", ", ".join(hits))
sys.exit(0)
print("FAIL: no bare __mock_result_N token in output_emitted.zig.")
print(" processTestFlow generated the test block (it panics from inside itself")
print(" on a bad mock, and on an unmocked impure event), but the block never")
print(" reached the AST — see BUG.md.")
sys.exit(1)
PY