A line of text enters the program, and a real cat program, which repeats
what it reads, sends it back. The line leaves the App through its output.
There are two ways to run this program: the real world (App) starts cat;
the virtual world (Lab) supplies its responses from a mock. The graph stays
the same. You can test its success, filtering and timeout before starting
an external process.
The three file formats have different
jobs: .rkg is the program and its Lab, .rkc is a scenario's reference
trace, and .rkr is a recording of a real execution.
From the repository root, with rastok installed:
rastok simulate examples/echo.rkg --compare examples/traces/echoPASS smoke.roundtripPASS smoke.filteredPASS smoke.silence_expires3 scenario(s), 0 failedThis reads examples/echo.rkg and compares each scenario with its reviewed
file in examples/traces/echo/. The command starts no external process and
writes no reference trace.
To inspect the same scenario, use a binary built with hosted-ui:
rastok simulate examples/echo.rkg --compare examples/traces/echo --uiOpen the complete URL printed by the CLI and keep it private. In Terminal on macOS, hold Command and double-click the URL to open it. If your terminal does not open links, copy the complete URL into your browser instead. The debugger tour explains its controls and source view.
Read the program
Section titled “Read the program”Open examples/echo.rkg and read from top to bottom.
graph echo : App declares the application. It contains a Connector and
an Operator, with wiring between their ports.
The Connector shell : Process talks to an external program under the
Process contract.
Here mode = job starts a child for each Call, command = "cat" selects the
program, and codec = lines exchanges lines of text. timeout = duration("5s")
bounds the wait. The declarations of idempotence and deterministic behavior
describe the repetition guarantee and the expected behavior of this command.
The Operator relay does not start a process. Its on in where data != ""
handler accepts a nonempty input and emits that data on out. An empty line
produces no output.
The wiring in -> relay -> shell -> out sends the App input to relay,
then to shell, then to the App output. The two remaining outputs,
shell.err and shell.exit, go to nothing: the program explicitly
discards them. They still exist in the journal and can be checked by the Lab.
Below the App, lab smoke describes the virtual world. It contains the
shared mock and scenarios directly; no intermediate simulation block is needed.
mock shell supplies the process response. In on in { ... }, out = .
means “emit the data this mock received”: the dot is the received data, so the
mock echoes it. exit = Exited { exit_code = 0, signal = null } then ends
the simulated process successfully. See mock responses
for the other forms.
The scenarios are independent:
roundtripsends"hello";expect app.out == "hello"requires exactly one matching App output, thenexpect shell.err == nothingrequires no error output.filteredsends"";expect shell.in == nothingandexpect app.out == nothingcheck that the empty line reaches neither the process nor the App output.silence_expiresreplaces the shared mock without = nothing, providing no terminal response;advance duration("5s")moves virtual time and the final expectation checksTimeoutExpiredonshell.exit.
An expectation examines the observations since the preceding input or time advance. It does not consume them, so successive expectations can inspect the same window.
Source: examples/echo.rkg
// A nonempty line goes to cat and comes back on the App output.// The Lab tests the echo, an empty line and a child that never answers.
graph echo : App { connector shell : Process { mode = job ; command = "cat" codec = lines idempotent = true; behavior = deterministic timeout = duration("5s") }
operator relay { on in where data != "" { out = data } }
in -> relay -> shell -> out shell.err -> nothing shell.exit -> nothing}
lab smoke { mock shell { on in { out = . exit = Exited { exit_code = 0, signal = null } } }
scenario roundtrip { app.in = "hello" expect app.out == "hello" expect shell.err == nothing }
scenario filtered { app.in = "" expect shell.in == nothing expect app.out == nothing }
scenario silence_expires { mock shell { on in { out = nothing } } app.in = "hello" advance duration("5s") expect shell.exit == TimeoutExpired {} }}Expected result
Section titled “Expected result”The roundtrip scenario follows this sequence, with the Lab supplying the
response instead of starting cat.
To run in the real world, use a macOS or Linux shell with cat on PATH.
The following command starts cat and writes echo.rkr in your current
directory. A recording captures the real execution so it can be inspected
without starting that process again. Use an unused filename: existing
recordings are never overwritten.
printf 'hello\n' | rastok run examples/echo.rkg --record echo.rkrhellorecorded: 8 causal records · seal 80f1263274f3b1b7480fdb13c007459e18e1e4cf10cc9bf08b5d12b63a4b7e0eEcho has one App output, so stdout contains the value alone. The recorded:
summary goes to stderr. Now inspect the recording:
rastok replay echo.rkrreplay: 8 causal records · seal 80f1263274f3b1b7480fdb13c007459e18e1e4cf10cc9bf08b5d12b63a4b7e0e · completed recording · no Driver I/OhelloReplay needs neither the original source nor cat. Its summary goes to
stderr; the output value goes to stdout. The matching seals describe the
same recorded execution, not a new call to the outside world. The seal above
is from one run; compare your replay with the seal printed by your own run.
A Lab execution and a real run do not have equal raw seals by default: their input provenance differs, and real response timing can differ from virtual time. Here the proof is equality between the real run and its recorded replay.
Break it
Section titled “Break it”In mock shell, change exactly out = . to out = "changed".
Leave the expected value "hello" unchanged. Run:
rastok simulate examples/echo.rkg --compare examples/traces/echoFAIL smoke.roundtrip expect app.out == "hello" (echo.rkg:34) observed app.out: "changed" expected 1 matching delivery on app.out, but observed 0 golden divergence: record 6: closure(32)[1][0][1][1]; expected 82066568656c6c6f; got 8206676368616e67…(10 bytes); cause: EGRESS "shell" · emitting_id 801cfc175b8f2151…(16 bytes) · call_key absentPASS smoke.filteredPASS smoke.silence_expires3 scenario(s), 1 failedRestore the checked-in source:
git checkout -- examples/echo.rkgThat command discards your edits to this example. Then run the complete comparison again:
rastok simulate examples/echo.rkg --compare examples/traces/echoIt prints the same three PASS lines and zero-failed total shown under Run.
Read the golden difference
Section titled “Read the golden difference”The expectation names the source line, the observed "changed" value and
the failed count. The golden difference names the first differing record,
its field, the expected and actual encoded values, and the Call that produced
it. Those are two checks: the assertion checks the authored expectation;
the trace comparison checks the reviewed causal history. Do not save a new
reference merely to make the comparison pass.
Inspect the raw sealed trace (.rkc)
The versioned reference stores one hex-encoded causal record per line, with an optional final seal line. Use the chapter's comparison commands to explain a divergence.
Source: examples/traces/echo/smoke.roundtrip.rkc
a6070108a40150f3df1105112054d397a04ed0666ca4c80350f3df1105112054d397a04ed0666ca4c804010582024882066568656c6c6f09636c61620a000b000d81826c2e696e3e72656c61792e696e824982816572656c61798000a7070211601282438280800013676c3a737461727414801780181a50f3df1105112054d397a04ed0666ca4c8a80702116572656c617912824982816572656c6179800013676c3a737461727414801780181a50f3df1105112054d397a04ed0666ca4c81822824382808000a80702116572656c617912824982816572656c617980001364703a696e1481836c2e696e3e72656c61792e696e82438280800001178183636f757400a50150801cfc175b8f2151fe076d50a05c2b580250f3df1105112054d397a04ed0666ca4c80350f3df1105112054d397a04ed0666ca4c804010582024882066568656c6c6f1818818201502d4efb509bf4e072a22ea0314c1c7ee11819818350801cfc175b8f2151fe076d50a05c2b587272656c61792e6f75743e7368656c6c2e696e82498281657368656c6c8000a8070211657368656c6c1282498281657368656c6c800013676c3a737461727414801780181a50801cfc175b8f2151fe076d50a05c2b581822824382808000a60703181b50801cfc175b8f2151fe076d50a05c2b58181c657368656c6c181e58208e4c7c1b99dbfd50e7a95185fead5ee1448fa904a2fdd778eaf5f2dbfd629a99181f0118217272656c61792e6f75743e7368656c6c2e696ea70703181b50801cfc175b8f2151fe076d50a05c2b58181c657368656c6c181e58208e4c7c1b99dbfd50e7a95185fead5ee1448fa904a2fdd778eaf5f2dbfd629a99181f02182082018282636f757482024882066568656c6c6f8264657869748202582a82138266457869746564820f828269657869745f636f646582020082667369676e616c821382008207f618217272656c61792e6f75743e7368656c6c2e696ea6070211657368656c6c1282498281657368656c6c80001364703a696e1481837272656c61792e6f75743e7368656c6c2e696e824982816572656c6179800001178283636f757400a50150233ee7a209d98e59c5f7b3aa16a9345a0250801cfc175b8f2151fe076d50a05c2b580350f3df1105112054d397a04ed0666ca4c804010582024882066568656c6c6f83646578697400a501509403fe6e10f58d02bd0e61df7a9d3e760250801cfc175b8f2151fe076d50a05c2b580350f3df1105112054d397a04ed0666ca4c80401058202582a82138266457869746564820f828269657869745f636f646582020082667369676e616c821382008207f6seal 7e20cb99d172b4d2816136dfab6e60fadc99e592aa754a520059e2d4bfea5ea9Carry forward
Section titled “Carry forward”For the concepts behind this example, read A program and The Lab.
An injected fault belongs to the virtual world (Lab); the application stays the same as in the real world (App). Keep that distinction when a partner environment is not available yet.
Next: File pipeline. Replace the external program with two file operations and ask what each effect is allowed to do.
Limits
Section titled “Limits”Reference traces contain causal evidence. Recordings are bounded local diagnostics, not durable deployment journals or share-safe exports. The recorder currently refuses personal-data plans and boot-dependent deployment profiles. Diagnostic replay reconstructs recorded facts; it does not execute a Lab scenario.