rsaeb 0.10.0

A no_std + alloc interpreter for A=B ordered rewrite programs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
use super::budget::RuntimeBudgetState;
use super::matcher::{RuleSearch, find_next_match};
use super::once::OnceStateSet;
use super::rewrite::RewriteScratch;
use super::state::State;
use crate::bytes::Payload;
use crate::error::{
    ReturnOutputLimitError, RunStepError, RuntimeInputError, RuntimeStateLimitError, StepLimitError,
};
use crate::execution::{BorrowedFailedRun, BorrowedStepTransition};
use crate::input::{RuntimeInput, RuntimeInputSource};
use crate::limits::{
    DEFAULT_MAX_INPUT_LEN, DEFAULT_MAX_RETURN_LEN, DEFAULT_MAX_STATE_LEN, ReturnByteLimit,
    ReturnOutputByteCount, RuntimeInputByteCount, RuntimeInputByteLimit, RuntimeStateByteCount,
    RuntimeStateByteLimit, StepCount, StepLimit,
};
use crate::program::RunOutcome;
use crate::runtime::action::prepare_matched_rule;
use crate::test_support::{
    TestFailure, TestResult, TestRunPolicy, ensure_eq, ensure_matches, parse_program, run_seed,
};
use crate::trace::RuntimeStateView;
use alloc::vec::Vec;

fn runtime_view_bytes(view: RuntimeStateView<'_>) -> Vec<u8> {
    view.materialized_bytes().collect()
}

/// Returns the materialized runtime byte at `index`.
///
/// # Errors
///
/// Returns `TestFailure` if the state has no byte at `index`.
fn expect_runtime_byte(state: &State, index: usize) -> Result<u8, TestFailure> {
    state
        .view()
        .materialized_bytes()
        .nth(index)
        .ok_or(TestFailure::message("expected runtime byte"))
}

/// Returns the program payload byte at `index`.
///
/// # Errors
///
/// Returns `TestFailure` if the payload has no byte at `index`.
fn expect_payload_byte(payload: &Payload, index: usize) -> Result<u8, TestFailure> {
    payload
        .bytes()
        .nth(index)
        .ok_or(TestFailure::message("expected payload byte"))
}

/// Returns the expected step limit error.
///
/// # Errors
///
/// Returns `TestFailure` if `error` is not a step limit error.
fn expect_step_limit(error: RunStepError) -> Result<StepLimitError, TestFailure> {
    match error {
        RunStepError::StepLimit(error) => Ok(error),
        RunStepError::Allocation(_)
        | RunStepError::RewriteSize(_)
        | RunStepError::RuntimeStateLimit(_)
        | RunStepError::ReturnOutputLimit(_)
        | RunStepError::RuleRuntimeState(_) => {
            Err(TestFailure::message("expected step limit error"))
        }
    }
}

/// Returns the expected step error.
///
/// # Errors
///
/// Returns `TestFailure` if stepping succeeds.
fn expect_step_error<'program>(
    result: BorrowedStepTransition<'program>,
) -> Result<BorrowedFailedRun<'program>, TestFailure> {
    match result {
        BorrowedStepTransition::Failed(failed) => Ok(failed),
        BorrowedStepTransition::Applied(_)
        | BorrowedStepTransition::Stable(_)
        | BorrowedStepTransition::Returned(_) => Err(TestFailure::message("expected step error")),
    }
}

/// Returns the expected successful step transition.
///
/// # Errors
///
/// Returns `TestFailure` if stepping fails.
fn expect_step_transition<'program>(
    result: BorrowedStepTransition<'program>,
) -> Result<BorrowedStepTransition<'program>, TestFailure> {
    match result {
        BorrowedStepTransition::Failed(failed) => Err(TestFailure::from(failed.into_error())),
        transition => Ok(transition),
    }
}

/// Creates runtime state through the same checked input path as public runs.
///
/// # Errors
///
/// Returns `TestFailure` if input validation fails or the input exceeds runtime
/// state limits.
fn state_from_input_bytes(input: &[u8], limits: TestRunPolicy) -> Result<State, TestFailure> {
    let (input, _) = run_seed(input, limits)?.into_runtime_parts();
    Ok(State::from_input(input))
}

struct OnceRuleFailureExpectation {
    source: &'static str,
    input: &'static [u8],
    limits: TestRunPolicy,
    error: RunStepError,
    expected_match: &'static str,
    expected_availability: &'static str,
}

/// Verifies a failed `(once)` candidate does not commit the once slot.
///
/// # Errors
///
/// Returns `TestFailure` if the candidate does not fail as expected or the
/// failed candidate mutates progress, state, or once-rule availability.
fn ensure_once_rule_failure_does_not_commit_rule(
    expectation: &OnceRuleFailureExpectation,
) -> TestResult {
    let program = parse_program(expectation.source)?;
    let state = state_from_input_bytes(expectation.input, expectation.limits)?;
    let mut budget = RuntimeBudgetState::new(expectation.limits.execution());
    let mut scratch = RewriteScratch::new();
    let mut once_states = OnceStateSet::new(program.once_rule_count())?;

    let matched = match find_next_match(program.rule_slice(), &mut once_states, &state)
        .map_err(RunStepError::from)?
    {
        RuleSearch::Matched(matched) => matched,
        RuleSearch::Stable => {
            return Err(TestFailure::message(expectation.expected_match));
        }
    };

    let result = prepare_matched_rule(&mut scratch, &mut budget, state.byte_count(), matched);
    let Err(error) = result else {
        return Err(TestFailure::message(expectation.expected_match));
    };
    ensure_eq!(error, expectation.error)?;
    ensure_eq!(budget.completed_steps(), StepCount::ZERO)?;
    ensure_eq!(
        runtime_view_bytes(state.view()).as_slice(),
        expectation.input
    )?;

    ensure_matches(
        matches!(
            find_next_match(program.rule_slice(), &mut once_states, &state)
                .map_err(RunStepError::from)?,
            RuleSearch::Matched(_)
        ),
        expectation.expected_availability,
    )
}

/// # Errors
///
/// Returns `TestFailure` if a failed once-rule commit attempt mutates runtime
/// state before the commit boundary.
#[test]
fn once_rule_failure_preserves_state_before_step_commit() -> TestResult {
    let program = parse_program("(once)a=(return)ok")?;
    let limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(1),
        DEFAULT_MAX_STATE_LEN,
        ReturnByteLimit::new(1),
    );
    let input = run_seed(b"a", limits)?;
    let runtime = program.start_run(input)?;
    let error = expect_step_error(runtime.step())?;
    ensure_eq!(
        error.error(),
        &RunStepError::ReturnOutputLimit(ReturnOutputLimitError::new(
            ReturnByteLimit::new(1),
            ReturnOutputByteCount::new(2),
        )),
    )?;

    ensure_eq!(error.completed_steps(), StepCount::ZERO)?;
    ensure_eq!(
        runtime_view_bytes(error.state()).as_slice(),
        b"a".as_slice()
    )
}

/// # Errors
///
/// Returns `TestFailure` if a step-limit failure commits state or loses the
/// running execution.
#[test]
fn execution_step_limit_failure_preserves_uncommitted_state() -> TestResult {
    let program = parse_program("a=b")?;
    let limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(0),
        DEFAULT_MAX_STATE_LEN,
        DEFAULT_MAX_RETURN_LEN,
    );
    let no_match_input = run_seed(b"x", limits)?;
    let no_match = program.start_run(no_match_input)?;
    match expect_step_transition(no_match.step())? {
        BorrowedStepTransition::Stable(stable) => {
            ensure_eq!(stable.steps().get(), 0)?;
            ensure_eq!(
                runtime_view_bytes(stable.state()).as_slice(),
                b"x".as_slice()
            )?;
        }
        BorrowedStepTransition::Applied(_)
        | BorrowedStepTransition::Returned(_)
        | BorrowedStepTransition::Failed(_) => {
            return Err(TestFailure::message("expected stable completion"));
        }
    }

    let program = parse_program("a=b")?;
    let would_match_input = run_seed(b"a", limits)?;
    let would_match = program.start_run(would_match_input)?;
    let error = expect_step_error(would_match.step())?;
    ensure_eq!(
        expect_step_limit(error.into_error())?,
        StepLimitError::new(
            StepLimit::new(0),
            StepCount::ZERO,
            RuntimeStateByteCount::new(1),
        ),
    )?;
    let program = parse_program("a=b")?;
    let would_match = program.start_run(run_seed(b"a", limits)?)?;
    let error = expect_step_error(would_match.step())?;
    ensure_eq!(error.completed_steps(), StepCount::ZERO)?;
    ensure_eq!(
        runtime_view_bytes(error.state()).as_slice(),
        b"a".as_slice(),
    )?;

    ensure_eq!(
        expect_step_limit(error.into_error())?,
        StepLimitError::new(
            StepLimit::new(0),
            StepCount::ZERO,
            RuntimeStateByteCount::new(1),
        ),
    )
}

/// # Errors
///
/// Returns `TestFailure` if state or return-size limit failures commit state.
#[test]
fn execution_size_limit_failures_preserve_uncommitted_state() -> TestResult {
    let state_limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(1),
        RuntimeStateByteLimit::new(2),
        ReturnByteLimit::new(10),
    );
    let state_program = parse_program("=a")?;
    let state_input = run_seed(b"aa", state_limits)?;
    let state_limited = state_program.start_run(state_input)?;
    let state_error = expect_step_error(state_limited.step())?;
    ensure_eq!(
        state_error.error(),
        &RunStepError::RuntimeStateLimit(RuntimeStateLimitError::new(
            RuntimeStateByteLimit::new(2),
            RuntimeStateByteCount::new(3),
        )),
    )?;
    ensure_eq!(state_error.completed_steps(), StepCount::ZERO)?;
    ensure_eq!(
        runtime_view_bytes(state_error.state()).as_slice(),
        b"aa".as_slice(),
    )?;
    ensure_eq!(
        state_error.into_error(),
        RunStepError::RuntimeStateLimit(RuntimeStateLimitError::new(
            RuntimeStateByteLimit::new(2),
            RuntimeStateByteCount::new(3),
        )),
    )?;

    let return_limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(1),
        RuntimeStateByteLimit::new(10),
        ReturnByteLimit::new(1),
    );
    let return_program = parse_program("a=(return)ok")?;
    let return_input = run_seed(b"a", return_limits)?;
    let return_limited = return_program.start_run(return_input)?;
    let return_error = expect_step_error(return_limited.step())?;
    ensure_eq!(
        return_error.error(),
        &RunStepError::ReturnOutputLimit(ReturnOutputLimitError::new(
            ReturnByteLimit::new(1),
            ReturnOutputByteCount::new(2),
        )),
    )?;
    ensure_eq!(return_error.completed_steps(), StepCount::ZERO)?;
    ensure_eq!(
        runtime_view_bytes(return_error.state()).as_slice(),
        b"a".as_slice(),
    )?;
    ensure_eq!(
        return_error.into_error(),
        RunStepError::ReturnOutputLimit(ReturnOutputLimitError::new(
            ReturnByteLimit::new(1),
            ReturnOutputByteCount::new(2),
        )),
    )
}

/// # Errors
///
/// Returns `TestFailure` if a return action enters rewrite state-limit
/// accounting instead of the return-output path.
#[test]
fn return_action_bypasses_rewrite_state_mutation_path() -> TestResult {
    let program = parse_program("a=(return)ok")?;
    let limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(1),
        RuntimeStateByteLimit::new(1),
        ReturnByteLimit::new(2),
    );
    let session = program.start_run(run_seed(b"a", limits)?)?;

    match expect_step_transition(session.step())? {
        BorrowedStepTransition::Returned(returned) => {
            let result = returned.into_result();
            ensure_eq!(result.steps().get(), 1)?;
            ensure_matches(
                matches!(
                    result.outcome(),
                    RunOutcome::Return(output) if output.as_slice() == b"ok"
                ),
                "expected return output to bypass rewrite state limit",
            )
        }
        BorrowedStepTransition::Applied(_)
        | BorrowedStepTransition::Stable(_)
        | BorrowedStepTransition::Failed(_) => {
            Err(TestFailure::message("expected return transition"))
        }
    }
}

/// # Errors
///
/// Returns `TestFailure` if any failed `(once)` candidate commits its once slot.
#[test]
fn once_limit_failures_do_not_commit_rule() -> TestResult {
    let expectations = [
        OnceRuleFailureExpectation {
            source: "(once)=aa",
            input: b"a",
            limits: TestRunPolicy::new(
                DEFAULT_MAX_INPUT_LEN,
                StepLimit::new(1),
                RuntimeStateByteLimit::new(1),
                DEFAULT_MAX_RETURN_LEN,
            ),
            error: RunStepError::RuntimeStateLimit(RuntimeStateLimitError::new(
                RuntimeStateByteLimit::new(1),
                RuntimeStateByteCount::new(3),
            )),
            expected_match: "expected once rewrite limit failure",
            expected_availability: "expected failed once rewrite to remain available",
        },
        OnceRuleFailureExpectation {
            source: "(once)a=b",
            input: b"a",
            limits: TestRunPolicy::new(
                DEFAULT_MAX_INPUT_LEN,
                StepLimit::new(0),
                DEFAULT_MAX_STATE_LEN,
                DEFAULT_MAX_RETURN_LEN,
            ),
            error: RunStepError::StepLimit(StepLimitError::new(
                StepLimit::new(0),
                StepCount::ZERO,
                RuntimeStateByteCount::new(1),
            )),
            expected_match: "expected once step limit failure",
            expected_availability: "expected failed step reservation to leave once rule available",
        },
        OnceRuleFailureExpectation {
            source: "(once)a=(return)ok",
            input: b"a",
            limits: TestRunPolicy::new(
                DEFAULT_MAX_INPUT_LEN,
                StepLimit::new(1),
                DEFAULT_MAX_STATE_LEN,
                ReturnByteLimit::new(1),
            ),
            error: RunStepError::ReturnOutputLimit(ReturnOutputLimitError::new(
                ReturnByteLimit::new(1),
                ReturnOutputByteCount::new(2),
            )),
            expected_match: "expected once return limit failure",
            expected_availability: "expected failed once return to remain available",
        },
    ];

    for expectation in expectations {
        ensure_once_rule_failure_does_not_commit_rule(&expectation)?;
    }
    Ok(())
}

/// # Errors
///
/// Returns `TestFailure` if once-state construction ignores the parser-assigned
/// once-slot count.
#[test]
fn once_state_set_is_constructed_from_parser_assigned_slots() -> TestResult {
    let program = parse_program("(once)a=b")?;
    let mut once_states = OnceStateSet::new(program.once_rule_count())?;
    let state = state_from_input_bytes(
        b"a",
        TestRunPolicy::new(
            DEFAULT_MAX_INPUT_LEN,
            StepLimit::new(1),
            DEFAULT_MAX_STATE_LEN,
            DEFAULT_MAX_RETURN_LEN,
        ),
    )?;

    ensure_matches(
        matches!(
            find_next_match(program.rule_slice(), &mut once_states, &state)
                .map_err(RunStepError::from)?,
            RuleSearch::Matched(_)
        ),
        "expected parser-assigned once slot state to keep the rule available",
    )
}

/// # Errors
///
/// Returns `TestFailure` if runtime input errors lose structured boundary
/// information.
#[test]
fn runtime_input_error_is_structured_at_the_runtime_boundary() -> TestResult {
    let Err(error) = RuntimeInput::validate(
        RuntimeInputSource::from_bytes(b"abc"),
        TestRunPolicy::new(
            RuntimeInputByteLimit::new(2),
            StepLimit::new(10),
            DEFAULT_MAX_STATE_LEN,
            DEFAULT_MAX_RETURN_LEN,
        )
        .input(),
    ) else {
        return Err(TestFailure::message("expected input limit error"));
    };

    ensure_eq!(
        error,
        RuntimeInputError::InputLimit {
            limit: RuntimeInputByteLimit::new(2),
            attempted_len: RuntimeInputByteCount::new(3),
        },
    )?;

    let Err(error) = RuntimeInput::validate(
        RuntimeInputSource::from_bytes("a\u{80}".as_bytes()),
        TestRunPolicy::new(
            RuntimeInputByteLimit::new(1),
            StepLimit::new(10),
            DEFAULT_MAX_STATE_LEN,
            DEFAULT_MAX_RETURN_LEN,
        )
        .input(),
    ) else {
        return Err(TestFailure::message(
            "expected input limit before byte error",
        ));
    };

    ensure_eq!(
        error,
        RuntimeInputError::InputLimit {
            limit: RuntimeInputByteLimit::new(1),
            attempted_len: RuntimeInputByteCount::new(3),
        },
    )?;

    let Err(error) = RuntimeInput::validate(
        RuntimeInputSource::from_bytes("a\u{80}".as_bytes()),
        TestRunPolicy::default().input(),
    ) else {
        return Err(TestFailure::message("expected input error"));
    };

    ensure_matches(
        matches!(
            error,
            RuntimeInputError::NonAscii { column, .. } if column.get() == 2
        ),
        "expected non-ASCII input error at the original column",
    )
}

/// # Errors
///
/// Returns `TestFailure` if executable payload bytes and runtime-only bytes are
/// not kept in distinct domains.
#[test]
fn internal_code_and_runtime_bytes_are_distinct_domains() -> TestResult {
    let program = parse_program("a=b")?;
    let payload = program
        .rule_slice()
        .iter()
        .next()
        .ok_or(TestFailure::message("expected parsed rule"))?
        .lhs();
    let limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(10_000),
        DEFAULT_MAX_STATE_LEN,
        DEFAULT_MAX_RETURN_LEN,
    );
    let (input, _) = run_seed(b"a=()# ", limits)?.into_runtime_parts();
    let state = State::from_input(input);

    ensure_eq!(expect_payload_byte(payload, 0)?, b'a')?;
    ensure_eq!(expect_runtime_byte(&state, 0)?, b'a')?;
    ensure_eq!(expect_runtime_byte(&state, 1)?, b'=')?;
    ensure_eq!(expect_runtime_byte(&state, 2)?, b'(')?;
    ensure_eq!(expect_runtime_byte(&state, 5)?, b' ')?;

    let result = program.run(run_seed(b"a=()# ", limits)?)?;
    ensure_matches(
        matches!(
            result.outcome(),
            RunOutcome::Stable(output) if output.as_slice() == b"b=()# "
        ),
        "expected rewrite to leave runtime-only input bytes materialized but unmatched",
    )
}

/// # Errors
///
/// Returns `TestFailure` if a consumed `(once)` rule can be matched again
/// before later rules are considered.
#[test]
fn once_rule_commit_proof_allows_only_one_successful_application() -> TestResult {
    let program = parse_program("(once)a=a\na=b")?;
    let limits = TestRunPolicy::new(
        DEFAULT_MAX_INPUT_LEN,
        StepLimit::new(10),
        DEFAULT_MAX_STATE_LEN,
        DEFAULT_MAX_RETURN_LEN,
    );
    let result = program.run(run_seed(b"a", limits)?)?;

    ensure_eq!(result.steps().get(), 2)?;
    ensure_matches(
        matches!(
            result.outcome(),
            RunOutcome::Stable(output) if output.as_slice() == b"b"
        ),
        "expected consumed once rule to give the later rule a chance",
    )
}

/// # Errors
///
/// Returns `TestFailure` if rewrite action variants lose their placement
/// semantics after being prepared from matched state spans.
#[test]
fn rewrite_action_variants_preserve_runtime_placement() -> TestResult {
    for (source, input, expected) in [
        ("a=x", b"ab".as_slice(), b"xb".as_slice()),
        ("b=(start)x", b"ab".as_slice(), b"xa".as_slice()),
        ("a=(end)x", b"ab".as_slice(), b"bx".as_slice()),
    ] {
        let limits = TestRunPolicy::new(
            DEFAULT_MAX_INPUT_LEN,
            StepLimit::new(1),
            DEFAULT_MAX_STATE_LEN,
            DEFAULT_MAX_RETURN_LEN,
        );
        let result = parse_program(source)?.run(run_seed(input, limits)?)?;

        ensure_matches(
            matches!(
                result.outcome(),
                RunOutcome::Stable(output) if output.as_slice() == expected
            ),
            "expected rewrite action variant to preserve placement",
        )?;
    }

    Ok(())
}

/// # Errors
///
/// Returns `TestFailure` if empty payload matches lose their start/end span
/// placement while deriving matched length from the validated range.
#[test]
fn empty_payload_matches_keep_anchor_specific_span_placement() -> TestResult {
    for (source, expected) in [
        ("=x", b"xab".as_slice()),
        ("(start)=x", b"xab".as_slice()),
        ("(end)=x", b"abx".as_slice()),
    ] {
        let program = parse_program(source)?;
        let limits = TestRunPolicy::new(
            DEFAULT_MAX_INPUT_LEN,
            StepLimit::new(1),
            DEFAULT_MAX_STATE_LEN,
            DEFAULT_MAX_RETURN_LEN,
        );
        let session = program.start_run(run_seed(b"ab", limits)?)?;

        match expect_step_transition(session.step())? {
            BorrowedStepTransition::Applied(applied) => {
                ensure_eq!(runtime_view_bytes(applied.state()).as_slice(), expected)?;
            }
            BorrowedStepTransition::Stable(_)
            | BorrowedStepTransition::Returned(_)
            | BorrowedStepTransition::Failed(_) => {
                return Err(TestFailure::message("expected one empty-payload rewrite"));
            }
        }
    }

    Ok(())
}