#![allow(clippy::approx_constant)]
#![allow(non_snake_case)] // many *Ex778 test names mirror exit codes; renaming would lose link

//! Tests pinning the v0.12.2 API additions:
//!   - `ShellHost::subshell_end -> Option<i32>` (Some(N) updates vm.last_status)
//!   - `VM::request_halt()` (host-callable mid-execution halt)
//!
//! These behaviors are documented in fusevm v0.12.2 release notes and
//! zshrs's TODO.md #6. Until now no test pinned the actual contract —
//! only that the trait sig type-checks. A regression that no-ops
//! Some(status) or that ignores request_halt would slip silently.

use fusevm::{ChunkBuilder, DefaultHost, Op, ShellHost, VMResult, Value, VM};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Mutex;

/// Serializes tests that share static atomics (Rust runs #[test] in parallel).
static PIN_TEST_LOCK: Mutex<()> = Mutex::new(());

// ─── ShellHost::subshell_end Option<i32> contract ──────────────────────

struct StatusReturningHost(i32);

impl ShellHost for StatusReturningHost {
    fn subshell_end(&mut self) -> Option<i32> {
        Some(self.0)
    }
}

#[test]
fn subshell_end_some_status_updates_vm_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.set_shell_host(Box::new(StatusReturningHost(42)));
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 42,
        "Some(42) returned from subshell_end MUST propagate into vm.last_status"
    );
}

#[test]
fn subshell_end_some_zero_overwrites_nonzero_last_status() {
    // The zero case is the interesting one — early implementations
    // sometimes special-case 0 as "no change" defeating the purpose.
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 99;
    vm.set_shell_host(Box::new(StatusReturningHost(0)));
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 0,
        "Some(0) MUST overwrite prior last_status — Z does not mean 'unchanged'"
    );
}

struct NoneHost;
impl ShellHost for NoneHost {
    fn subshell_end(&mut self) -> Option<i32> {
        None
    }
}

#[test]
fn subshell_end_none_leaves_last_status_untouched() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 99;
    vm.set_shell_host(Box::new(NoneHost));
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 99,
        "None MUST leave prior last_status untouched — the no-update contract"
    );
}

#[test]
fn subshell_end_default_trait_impl_returns_none() {
    // The trait's default subshell_end returns None — a host that
    // doesn't override gets prior behavior (no last_status writes).
    struct BareHost;
    impl ShellHost for BareHost {} // takes the default impl
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 7;
    vm.set_shell_host(Box::new(BareHost));
    let _ = vm.run();
    assert_eq!(vm.last_status, 7);
}

#[test]
fn subshell_end_negative_status_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-1)));
    let _ = vm.run();
    assert_eq!(
        vm.last_status, -1,
        "negative exit codes MUST propagate verbatim — shell $? is signed i32"
    );
}

#[test]
fn subshell_end_some_does_not_push_onto_stack() {
    // SubshellEnd only updates last_status; it must not push Status onto
    // the value stack (PipelineEnd does that — different op, different contract).
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(5)));
    match vm.run() {
        VMResult::Ok(Value::Int(99)) => {}
        other => panic!(
            "SubshellEnd MUST NOT push onto stack — expected sole stack value Int(99), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 5);
}

#[test]
fn subshell_end_getstatus_sees_host_returned_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(13)));
    match vm.run() {
        VMResult::Ok(Value::Status(13)) => {}
        other => panic!(
            "GetStatus after subshell_end(Some(13)) MUST read updated last_status, got {:?}",
            other
        ),
    }
}

struct FirstSomeThenNoneHost {
    calls: u32,
    status: i32,
}

impl ShellHost for FirstSomeThenNoneHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        if self.calls == 1 {
            Some(self.status)
        } else {
            None
        }
    }
}

#[test]
fn subshell_end_none_after_some_preserves_status_from_first() {
    // Nested subshells: inner returns None → outer's prior write must stick.
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 88,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(88)) => {}
        other => panic!(
            "None on second subshell_end MUST NOT revert first Some(88), got {:?}",
            other
        ),
    }
}

struct AlternatingStatusHost {
    calls: u32,
}

impl ShellHost for AlternatingStatusHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        match self.calls {
            1 => Some(3),
            2 => Some(9),
            _ => None,
        }
    }
}

#[test]
fn subshell_end_later_some_overwrites_earlier_different_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "later Some(9) MUST replace earlier Some(3), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_some_overwrites_prior_setstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(50), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(3)));
    match vm.run() {
        VMResult::Ok(Value::Status(3)) => {}
        other => panic!(
            "subshell_end(Some(3)) MUST overwrite SetStatus(50), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_without_begin_still_updates_last_status() {
    // Orphan SubshellEnd — host may still return deferred exit status.
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(17)));
    match vm.run() {
        VMResult::Ok(Value::Status(17)) => {}
        other => panic!(
            "SubshellEnd without SubshellBegin MUST still honor host Some(17), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_with_default_host_leaves_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 44;
    vm.set_shell_host(Box::new(DefaultHost));
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 44,
        "DefaultHost::subshell_end returns None — last_status MUST stay unchanged"
    );
}

#[test]
fn subshell_end_no_host_leaves_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 66;
    match vm.run() {
        VMResult::Ok(Value::Status(66)) => {}
        other => panic!(
            "SubshellEnd without host MUST NOT touch last_status, got {:?}",
            other
        ),
    }
}

struct SubshellThenDefaultPipelineHost;

impl ShellHost for SubshellThenDefaultPipelineHost {
    fn subshell_end(&mut self) -> Option<i32> {
        Some(4)
    }
    // pipeline_end uses trait default → 0
}

#[test]
fn subshell_end_with_host_then_pipelineend_uses_host_not_last_status() {
    // When a host IS set, PipelineEnd calls host.pipeline_end() — it does
    // NOT fall back to last_status even if subshell_end just wrote 4 there.
    // A regression that "helpfully" reads last_status when pipeline_end is 0
    // would break hosts that intentionally return 0.
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenDefaultPipelineHost));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "PipelineEnd with host MUST use host.pipeline_end(), not subshell last_status(4), got {:?}",
            other
        ),
    }
    assert_eq!(
        vm.last_status, 0,
        "PipelineEnd MUST overwrite last_status with host.pipeline_end() result"
    );
}

struct NoneThenSomeHost {
    calls: u32,
}

impl ShellHost for NoneThenSomeHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        if self.calls == 1 {
            None
        } else {
            Some(42)
        }
    }
}

#[test]
fn subshell_end_none_then_some_updates_on_second() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(NoneThenSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!(
            "second subshell_end(Some(42)) MUST apply after first None, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_begin_alone_does_not_update_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 31;
    vm.set_shell_host(Box::new(StatusReturningHost(99)));
    match vm.run() {
        VMResult::Ok(Value::Status(31)) => {}
        other => panic!(
            "SubshellBegin alone MUST NOT invoke subshell_end or change last_status, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_255_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(255)));
    match vm.run() {
        VMResult::Ok(Value::Status(255)) => {}
        other => panic!(
            "shell exit 255 MUST propagate as Status(255), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_reset_clears_last_status_from_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let chunk = b.build();

    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(42)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 42);

    let mut b2 = ChunkBuilder::new();
    b2.emit(Op::GetStatus, 1);
    vm.reset(b2.build());
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset MUST zero last_status even after subshell_end(Some(42)), got {:?}",
            other
        ),
    }
}

struct CustomPipelineHost(i32);

impl ShellHost for CustomPipelineHost {
    fn subshell_end(&mut self) -> Option<i32> {
        Some(4)
    }

    fn pipeline_end(&mut self) -> i32 {
        self.0
    }
}

#[test]
fn subshell_then_custom_pipelineend_uses_host_pipeline_result() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CustomPipelineHost(127)));
    match vm.run() {
        VMResult::Ok(Value::Status(127)) => {}
        other => panic!(
            "custom host.pipeline_end(127) MUST win over subshell last_status(4), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 127);
}

static SUBSHELL_END_CALLS: AtomicU32 = AtomicU32::new(0);

struct CountingSubshellEndHost(i32);

impl ShellHost for CountingSubshellEndHost {
    fn subshell_end(&mut self) -> Option<i32> {
        SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
        Some(self.0)
    }
}

#[test]
fn subshell_end_without_host_does_not_call_host() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 5);
}

#[test]
fn subshell_end_with_host_invokes_host_once_per_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1)));
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        2,
        "each SubshellEnd op MUST invoke host.subshell_end exactly once"
    );
}

static SUBSHELL_BEGIN_CALLS: AtomicU32 = AtomicU32::new(0);

struct BeginEndCountingHost(i32);

impl ShellHost for BeginEndCountingHost {
    fn subshell_begin(&mut self) {
        SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
    }

    fn subshell_end(&mut self) -> Option<i32> {
        Some(self.0)
    }
}

#[test]
fn subshell_begin_end_pair_invokes_begin_once_per_begin_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(2)));
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        1,
        "each SubshellBegin MUST invoke host.subshell_begin exactly once"
    );
    assert_eq!(vm.last_status, 2);
}

#[test]
fn subshell_end_i32_min_status_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(i32::MIN)));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MIN)) => {}
        other => panic!(
            "i32::MIN exit status MUST propagate verbatim, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_setstatus_after_overwrites_subshell_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(19), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(5)));
    match vm.run() {
        VMResult::Ok(Value::Status(19)) => {}
        other => panic!(
            "SetStatus after subshell_end MUST overwrite subshell last_status, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_getstatus_before_and_after_reads_different_values() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(StatusReturningHost(8)));
    match vm.run() {
        VMResult::Ok(Value::Status(8)) => {}
        other => panic!("expected final stack top Status(8), got {:?}", other),
    }
    assert_eq!(vm.last_status, 8);
}

struct IncrementingSubshellHost {
    next: i32,
}

impl ShellHost for IncrementingSubshellHost {
    fn subshell_end(&mut self) -> Option<i32> {
        let s = self.next;
        self.next += 1;
        Some(s)
    }
}

#[test]
fn subshell_end_three_some_in_sequence_last_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!(
            "third subshell_end(Some(12)) MUST be visible to GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_none_after_setstatus_preserves_setstatus_value() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(23), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(23)) => {}
        other => panic!(
            "subshell_end(None) MUST leave SetStatus(23) intact, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_reset_preserves_shell_host() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let chunk = b.build();

    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(91)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 91);

    vm.reset(chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(91)) => {}
        other => panic!(
            "reset MUST preserve shell host for subshell_end on rerun, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_i32_max_status_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(i32::MAX)));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MAX)) => {}
        other => panic!(
            "i32::MAX exit status MUST propagate verbatim, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_begin_without_host_is_noop() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    match vm.run() {
        VMResult::Ok(Value::Status(5)) => {}
        other => panic!(
            "SubshellBegin without host MUST NOT change last_status, got {:?}",
            other
        ),
    }
}

struct ThirdSomeSubshellHost {
    calls: u32,
}

impl ShellHost for ThirdSomeSubshellHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        if self.calls == 3 {
            Some(30)
        } else {
            None
        }
    }
}

#[test]
fn subshell_end_some_on_third_none_before_preserves_until_some() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(ThirdSomeSubshellHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(30)) => {}
        other => panic!(
            "third subshell_end(Some(30)) MUST apply; first two None leave 1, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_double_begin_single_end_still_updates_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(6)));
    match vm.run() {
        VMResult::Ok(Value::Status(6)) => {}
        other => panic!(
            "SubshellEnd after two SubshellBegin MUST still apply Some(6), got {:?}",
            other
        ),
    }
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        2,
        "each SubshellBegin MUST invoke host even when paired with one SubshellEnd"
    );
}

static PIPELINE_END_CALLS: AtomicU32 = AtomicU32::new(0);

struct CountingPipelineHost;

impl ShellHost for CountingPipelineHost {
    fn pipeline_end(&mut self) -> i32 {
        PIPELINE_END_CALLS.fetch_add(1, Ordering::SeqCst);
        0
    }
}

// ─── VM::request_halt contract ──────────────────────────────────────────

// Static counters — BuiltinHandler is a raw fn pointer (no captures),
// so test state lives in static atomics. Tests reset before each use.
static AFTER_HALT_COUNT: AtomicU32 = AtomicU32::new(0);
static TOUCHED: AtomicU32 = AtomicU32::new(0);

fn builtin_request_halt(vm: &mut VM, _argc: u8) -> Value {
    vm.request_halt();
    Value::Int(0)
}

fn builtin_count_after_halt(_vm: &mut VM, _argc: u8) -> Value {
    AFTER_HALT_COUNT.fetch_add(1, Ordering::SeqCst);
    Value::Int(0)
}

fn builtin_touched(_vm: &mut VM, _argc: u8) -> Value {
    TOUCHED.store(1, Ordering::SeqCst);
    Value::Int(0)
}

fn builtin_triple_halt(vm: &mut VM, _argc: u8) -> Value {
    vm.request_halt();
    vm.request_halt();
    vm.request_halt();
    Value::Int(0)
}

fn builtin_halt_only(vm: &mut VM, _argc: u8) -> Value {
    vm.request_halt();
    // CallBuiltin always pushes handler return value — Undef keeps stack non-empty
    // when combined with prior pushes, but an empty pre-run stack + pre-run halt
    // is the Halted path (see request_halt_pre_run_empty_stack_returns_halted).
    Value::Undef
}

#[test]
fn request_halt_from_builtin_stops_dispatch() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    // Builtin id 100: requests halt.
    b.emit(Op::CallBuiltin(100, 0), 1);
    // Builtin id 200: increments counter — should NOT execute.
    b.emit(Op::CallBuiltin(200, 0), 1);

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let r = vm.run();
    // Builtin 100 pushed Value::Int(0) before halting → stack non-empty
    // at exit → run() returns VMResult::Ok(Value::Int(0)) not Halted.
    // VMResult::Halted only fires when the stack is empty after halt.
    // The load-bearing assertion is the side-effect counter below.
    assert!(
        !matches!(r, VMResult::Error(_)),
        "request_halt MUST cleanly exit dispatch, got error"
    );
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "the op after CallBuiltin(100) MUST NOT execute when halt is requested"
    );
}

#[test]
fn request_halt_is_idempotent() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(50, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(50, builtin_triple_halt);
    let r = vm.run();
    // 3× request_halt is just 3× set-bool-true — must not panic or error.
    assert!(
        !matches!(r, VMResult::Error(_)),
        "multiple request_halt calls must be safe"
    );
}

#[test]
fn request_halt_before_run_short_circuits_immediately() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        0,
        "pre-run request_halt MUST prevent any op execution"
    );
}

#[test]
fn request_halt_pre_run_empty_stack_returns_halted() {
    let b = ChunkBuilder::new();
    let mut vm = VM::new(b.build());
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "pre-run request_halt on empty stack MUST return VMResult::Halted, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_preserves_prior_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(60, 0), 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 55;
    vm.register_builtin(60, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 55,
        "request_halt MUST NOT clobber last_status — only stops dispatch"
    );
}

#[test]
fn request_halt_reset_clears_halt_and_allows_rerun() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);

    let mut b2 = ChunkBuilder::new();
    b2.emit(Op::LoadInt(42), 1);
    vm.reset(b2.build());
    match vm.run() {
        VMResult::Ok(Value::Int(42)) => {}
        other => panic!(
            "reset MUST clear request_halt so VM can run again, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_subsequent_ops_leave_stack_intact() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt after builtin MUST leave prior stack values + builtin result, got {:?}",
            other
        ),
    }
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "LoadInt(22) and CallBuiltin(200) MUST NOT run after halt"
    );
}

#[test]
fn request_halt_from_builtin_with_only_undef_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(61, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(61, builtin_halt_only);
    match vm.run() {
        VMResult::Ok(Value::Undef) => {}
        other => panic!(
            "halt via builtin still pushes handler result before run() pops it, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_from_extension_handler_stops_dispatch() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        vm.request_halt();
    }));
    vm.register_builtin(200, builtin_count_after_halt);
    let r = vm.run();
    assert!(
        !matches!(r, VMResult::Error(_)),
        "request_halt from extension handler MUST exit cleanly, got {:?}",
        r
    );
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "ops after Extended MUST NOT run when extension handler requests halt"
    );
}

#[test]
fn request_halt_second_run_without_reset_does_not_resume() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);

    let r = vm.run();
    assert!(
        matches!(r, VMResult::Ok(_) | VMResult::Halted),
        "second run() without reset MUST NOT error, got {:?}",
        r
    );
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "halted flag MUST persist across run() calls until reset"
    );
}

#[test]
fn request_halt_from_nested_call_stops_caller_ops() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("haltfn");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(99), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt inside callee MUST return builtin result without running caller LoadInt(99), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_preserves_shell_host() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let chunk = b.build();

    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(33)));
    vm.request_halt();
    let _ = vm.run();

    vm.reset(chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(33)) => {}
        other => panic!(
            "reset MUST preserve shell host so subshell_end still works, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_preserves_registered_builtins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    let chunk = b.build();

    let mut vm = VM::new(chunk.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);

    vm.reset(chunk);
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        1,
        "reset MUST preserve builtin table registered before halt"
    );
}

#[test]
fn request_halt_does_not_clear_setstatus_during_run() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(77), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 77,
        "request_halt MUST NOT undo SetStatus written earlier in the same run"
    );
}

#[test]
fn request_halt_from_extension_wide_handler_stops_dispatch() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(9, 0xBEEF), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        vm.request_halt();
    }));
    vm.register_builtin(200, builtin_count_after_halt);
    let r = vm.run();
    assert!(
        !matches!(r, VMResult::Error(_)),
        "request_halt from ExtendedWide handler MUST exit cleanly, got {:?}",
        r
    );
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn request_halt_stops_before_jump_target() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let jmp = b.emit(Op::Jump(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "Jump target MUST NOT execute after request_halt"
    );
}

#[test]
fn request_halt_allows_ops_before_halt_to_complete() {
    static PRE_HALT: AtomicU32 = AtomicU32::new(0);
    fn mark_then_halt(vm: &mut VM, _argc: u8) -> Value {
        PRE_HALT.store(1, Ordering::SeqCst);
        vm.request_halt();
        Value::Int(0)
    }
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PRE_HALT.store(0, Ordering::SeqCst);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);

    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(6), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, mark_then_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "ops before halt MUST complete; halt builtin MUST push its result, got {:?}",
            other
        ),
    }
    assert_eq!(PRE_HALT.load(Ordering::SeqCst), 1);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn request_halt_prevents_subshell_end_from_running() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 10;
    vm.set_shell_host(Box::new(StatusReturningHost(99)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return builtin result, got {:?}", other),
    }
    assert_eq!(
        vm.last_status, 10,
        "subshell_end MUST NOT run after request_halt — last_status stays 10 not 99"
    );
}

#[test]
fn request_halt_pre_run_skips_ops_so_stack_stays_empty() {
    // Pre-run halt fires before dispatch — LoadInt in the chunk never runs.
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(123), 1);
    let mut vm = VM::new(b.build());
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "pre-run halt MUST skip all ops including LoadInt — stack empty → Halted, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_subshell_end_preserves_subshell_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(61)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 61,
        "request_halt after subshell_end MUST preserve subshell-written last_status"
    );
}

#[test]
fn request_halt_mid_chunk_then_reset_allows_subshell_end() {
    let mut halt_chunk = ChunkBuilder::new();
    halt_chunk.emit(Op::CallBuiltin(100, 0), 1);
    let halt_chunk = halt_chunk.build();

    let mut subshell_chunk = ChunkBuilder::new();
    subshell_chunk.emit(Op::SubshellBegin, 1);
    subshell_chunk.emit(Op::SubshellEnd, 1);
    subshell_chunk.emit(Op::GetStatus, 1);
    let subshell_chunk = subshell_chunk.build();

    let mut vm = VM::new(halt_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(71)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 0);

    vm.reset(subshell_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(71)) => {}
        other => panic!(
            "after reset, subshell_end MUST work post-halt run, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_conditional_jump_target() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "JumpIfTrue target MUST NOT execute after request_halt"
    );
}

#[test]
fn request_halt_stops_before_push_frame() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "PushFrame and subsequent ops MUST NOT run after request_halt"
    );
}

fn builtin_halt_report_argc(vm: &mut VM, argc: u8) -> Value {
    vm.request_halt();
    Value::Int(argc as i64)
}

#[test]
fn request_halt_from_builtin_with_args_still_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_halt_report_argc);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(2)) => {}
        other => panic!(
            "halt builtin MUST receive argc=2 and push it before stopping, got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn request_halt_reset_preserves_extension_handler() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_TOUCHED: AtomicU32 = AtomicU32::new(0);
    let mut halt_chunk = ChunkBuilder::new();
    halt_chunk.emit(Op::CallBuiltin(100, 0), 1);
    let halt_chunk = halt_chunk.build();

    let mut ext_chunk = ChunkBuilder::new();
    ext_chunk.emit(Op::Extended(3, 7), 1);
    let ext_chunk = ext_chunk.build();

    let mut vm = VM::new(halt_chunk);
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        EXT_TOUCHED.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();

    EXT_TOUCHED.store(0, Ordering::SeqCst);
    vm.reset(ext_chunk);
    let _ = vm.run();
    assert_eq!(
        EXT_TOUCHED.load(Ordering::SeqCst),
        1,
        "reset MUST preserve extension handler registered before halt"
    );
}

#[test]
fn request_halt_multiple_ops_before_all_complete() {
    static PRE_COUNT: AtomicU32 = AtomicU32::new(0);
    fn count_then_halt(vm: &mut VM, _argc: u8) -> Value {
        PRE_COUNT.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
        Value::Int(0)
    }
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PRE_COUNT.store(0, Ordering::SeqCst);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);

    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(3), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, count_then_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(PRE_COUNT.load(Ordering::SeqCst), 1);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn request_halt_does_not_run_setstatus_after_halt_point() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 1,
        "SetStatus after halt MUST NOT run — last_status stays pre-halt value"
    );
}

#[test]
fn subshell_end_then_request_halt_getstatus_not_reached() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(45)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("expected builtin halt result Int(0), got {:?}", other),
    }
    assert_eq!(
        vm.last_status, 45,
        "subshell status MUST be set before halt; GetStatus after halt MUST NOT run"
    );
}

#[test]
fn request_halt_stops_before_jump_if_false_target() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalse(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "JumpIfFalse target MUST NOT execute after request_halt"
    );
}

#[test]
fn request_halt_stops_before_pop_frame() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "PopFrame and subsequent ops MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_prevents_subshell_begin_from_running() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(9)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        0,
        "SubshellBegin MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_prevents_pipeline_end_from_running() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_END_CALLS.load(Ordering::SeqCst),
        0,
        "PipelineEnd MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_as_first_op_returns_ok_not_halted() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        VMResult::Halted => panic!(
            "halt via first-op CallBuiltin pushes result — MUST return Ok(Int(0)), not Halted"
        ),
        other => panic!("unexpected result {:?}", other),
    }
}

#[test]
fn request_halt_reset_preserves_extension_wide_handler() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_WIDE_TOUCHED: AtomicU32 = AtomicU32::new(0);
    let mut halt_chunk = ChunkBuilder::new();
    halt_chunk.emit(Op::CallBuiltin(100, 0), 1);
    let halt_chunk = halt_chunk.build();

    let mut wide_chunk = ChunkBuilder::new();
    wide_chunk.emit(Op::ExtendedWide(5, 0xCAFE), 1);
    let wide_chunk = wide_chunk.build();

    let mut vm = VM::new(halt_chunk);
    vm.set_extension_wide_handler(Box::new(|_vm, _id, _payload| {
        EXT_WIDE_TOUCHED.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();

    EXT_WIDE_TOUCHED.store(0, Ordering::SeqCst);
    vm.reset(wide_chunk);
    let _ = vm.run();
    assert_eq!(
        EXT_WIDE_TOUCHED.load(Ordering::SeqCst),
        1,
        "reset MUST preserve extension wide handler registered before halt"
    );
}

#[test]
fn request_halt_nested_call_does_not_return_to_caller() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("inner");
    b.emit(Op::LoadInt(100), 1);
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(200), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt in callee MUST NOT ReturnValue to caller — expect builtin result, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_pre_run_then_reset_runs_chunk_normally() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    let chunk = b.build();

    let mut vm = VM::new(chunk.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!("pre-run halt expected Halted, got {:?}", other),
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);

    vm.reset(chunk);
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        1,
        "reset after pre-run halt MUST allow normal execution"
    );
}

#[test]
fn subshell_end_and_halt_in_same_chunk_subshell_runs_first() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(52)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 52);
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        1,
        "only subshell ops before halt MUST run — second SubshellBegin MUST NOT"
    );
}

#[test]
fn subshell_only_ops_empty_stack_returns_halted() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(7)));
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "subshell-only chunk MUST leave stack empty → Halted, got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 7);
}

#[test]
fn subshell_end_exit_code_128_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(128)));
    match vm.run() {
        VMResult::Ok(Value::Status(128)) => {}
        other => panic!(
            "exit code 128 MUST propagate as Status(128), got {:?}",
            other
        ),
    }
}

struct PipelineThenSubshellHost;

impl ShellHost for PipelineThenSubshellHost {
    fn pipeline_end(&mut self) -> i32 {
        3
    }

    fn subshell_end(&mut self) -> Option<i32> {
        Some(9)
    }
}

#[test]
fn subshell_end_after_pipelineend_overwrites_pipeline_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "subshell_end(Some(9)) MUST overwrite pipeline_end(3) last_status, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_manual_last_status_write_visible_to_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 14;
    match vm.run() {
        VMResult::Ok(Value::Status(14)) => {}
        other => panic!(
            "GetStatus MUST read vm.last_status field set before run(), got {:?}",
            other
        ),
    }
}

static SUBSHELL_END_NONE_CALLS: AtomicU32 = AtomicU32::new(0);

struct NoneThenStatusHost(i32);

impl ShellHost for NoneThenStatusHost {
    fn subshell_end(&mut self) -> Option<i32> {
        SUBSHELL_END_NONE_CALLS.fetch_add(1, Ordering::SeqCst);
        if SUBSHELL_END_NONE_CALLS.load(Ordering::SeqCst) == 1 {
            None
        } else {
            Some(self.0)
        }
    }
}

#[test]
fn subshell_end_orphan_end_after_none_still_applies_some() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_NONE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(NoneThenStatusHost(16)));
    match vm.run() {
        VMResult::Ok(Value::Status(16)) => {}
        other => panic!(
            "second orphan SubshellEnd(Some(16)) MUST apply after first None, got {:?}",
            other
        ),
    }
}

static PIPELINE_BEGIN_CALLS: AtomicU32 = AtomicU32::new(0);

struct CountingPipelineBeginHost;

impl ShellHost for CountingPipelineBeginHost {
    fn pipeline_begin(&mut self, _n: u8) {
        PIPELINE_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
    }
}

#[test]
fn request_halt_stops_before_top_level_return() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "top-level Return MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_stops_before_pipeline_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineBeginHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst),
        0,
        "PipelineBegin MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_run_pops_only_stack_top() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "run() MUST pop only stack top (builtin result 0), not deeper Int(22), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_skips_getstatus_after_subshell_wrote_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(37)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return builtin Int(0), not GetStatus(37) pushed after halt point, got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 37);
}

#[test]
fn request_halt_stops_before_later_callbuiltin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        0,
        "CallBuiltin after halt MUST NOT run even when registered"
    );
}

#[test]
fn request_halt_both_extension_handlers_only_first_runs() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_NARROW: AtomicU32 = AtomicU32::new(0);
    static EXT_WIDE: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::ExtendedWide(2, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        EXT_NARROW.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.set_extension_wide_handler(Box::new(|_vm, _id, _payload| {
        EXT_WIDE.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(EXT_NARROW.load(Ordering::SeqCst), 1);
    assert_eq!(
        EXT_WIDE.load(Ordering::SeqCst),
        0,
        "ExtendedWide MUST NOT run after Extended handler requests halt"
    );
}

static PIPELINE_STAGE_CALLS: AtomicU32 = AtomicU32::new(0);

struct CountingPipelineStageHost;

impl ShellHost for CountingPipelineStageHost {
    fn pipeline_stage(&mut self) {
        PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
    }
}

#[test]
fn request_halt_stops_before_pipeline_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineStageHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_STAGE_CALLS.load(Ordering::SeqCst),
        0,
        "PipelineStage MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_1_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1)));
    match vm.run() {
        VMResult::Ok(Value::Status(1)) => {}
        other => panic!("exit code 1 MUST propagate as Status(1), got {:?}", other),
    }
}

#[test]
fn subshell_end_getstatus_leaves_prior_status_on_stack_below() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(StatusReturningHost(8)));
    match vm.run() {
        VMResult::Ok(Value::Status(8)) => {}
        other => panic!(
            "run() MUST pop top Status(8) from second GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_return_value_top_level() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(55), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return builtin Int(0), not ReturnValue(55), got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn request_halt_wide_extension_halts_before_narrow() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_N: AtomicU32 = AtomicU32::new(0);
    static EXT_W: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        EXT_W.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        EXT_N.fetch_add(1, Ordering::SeqCst);
    }));
    let _ = vm.run();
    assert_eq!(EXT_W.load(Ordering::SeqCst), 1);
    assert_eq!(
        EXT_N.load(Ordering::SeqCst),
        0,
        "Extended MUST NOT run after ExtendedWide requests halt"
    );
}

#[test]
fn subshell_end_some_overwrites_setstatus_zero() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(0), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(6)));
    match vm.run() {
        VMResult::Ok(Value::Status(6)) => {}
        other => panic!(
            "subshell_end(Some(6)) MUST overwrite SetStatus(0), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_prevents_subshell_end_host_invocation() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(4)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        0,
        "SubshellEnd MUST NOT invoke host after request_halt"
    );
}

#[test]
fn subshell_triple_begin_end_updates_to_last_some() {
    let mut b = ChunkBuilder::new();
    for _ in 0..3 {
        b.emit(Op::SubshellBegin, 1);
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!(
            "third subshell_end(Some(12)) MUST win in triple pairs, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_jump_if_true_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "JumpIfTrueKeep target MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_last_status_set_even_when_run_returns_halted() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(21)));
    assert!(matches!(vm.run(), VMResult::Halted));
    assert_eq!(vm.last_status, 21);
}

#[test]
fn request_halt_stops_second_extension_in_chain() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_A: AtomicU32 = AtomicU32::new(0);
    static EXT_B: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, id, _arg| {
        if id == 1 {
            EXT_A.fetch_add(1, Ordering::SeqCst);
            vm.request_halt();
        } else {
            EXT_B.fetch_add(1, Ordering::SeqCst);
        }
    }));
    let _ = vm.run();
    assert_eq!(EXT_A.load(Ordering::SeqCst), 1);
    assert_eq!(EXT_B.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_begin_does_not_change_status_before_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(99)));
    match vm.run() {
        VMResult::Ok(Value::Status(4)) => {}
        other => panic!(
            "SubshellBegin MUST NOT apply subshell_end status early, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_clears_setstatus_from_halted_run() {
    let mut halt_b = ChunkBuilder::new();
    halt_b.emit(Op::LoadInt(50), 1);
    halt_b.emit(Op::SetStatus, 1);
    halt_b.emit(Op::CallBuiltin(100, 0), 1);
    let halt_chunk = halt_b.build();

    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(halt_chunk);
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 50);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset MUST zero last_status from prior halted run, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_between_pipeline_ops_does_not_call_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(3)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 3);
    assert_eq!(
        PIPELINE_END_CALLS.load(Ordering::SeqCst),
        0,
        "SubshellEnd MUST NOT implicitly invoke pipeline_end"
    );
}

#[test]
fn request_halt_nested_call_with_args_still_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("fn");
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::Call(name, 2), 1);
    b.emit(Op::LoadInt(30), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "nested halt with args MUST return builtin result, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_without_host_orphan_leaves_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 18;
    match vm.run() {
        VMResult::Ok(Value::Status(18)) => {}
        other => panic!(
            "orphan SubshellEnd without host MUST leave last_status(18), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_three_consecutive_runs_never_resume() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    let _ = vm.run();
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        0,
        "three run() calls without reset MUST NOT resume dispatch"
    );
}

#[test]
fn subshell_end_getstatus_then_loadint_returns_loadint() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::LoadInt(44), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(5)));
    match vm.run() {
        VMResult::Ok(Value::Int(44)) => {}
        other => panic!(
            "final stack top MUST be LoadInt(44) not Status(5), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_subshell_getstatus_lifecycle() {
    let mut halt_b = ChunkBuilder::new();
    halt_b.emit(Op::CallBuiltin(100, 0), 1);
    let halt_chunk = halt_b.build();

    let mut sub_b = ChunkBuilder::new();
    sub_b.emit(Op::SubshellBegin, 1);
    sub_b.emit(Op::SubshellEnd, 1);
    sub_b.emit(Op::GetStatus, 1);
    let sub_chunk = sub_b.build();

    let mut vm = VM::new(halt_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(93)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();

    vm.reset(sub_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(93)) => {}
        other => panic!(
            "full lifecycle: halt → reset → subshell_end(Some(93)) → GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_halt_reset_subshell_preserves_host_and_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);

    let mut chunk_a = ChunkBuilder::new();
    chunk_a.emit(Op::SubshellBegin, 1);
    chunk_a.emit(Op::SubshellEnd, 1);
    chunk_a.emit(Op::CallBuiltin(100, 0), 1);
    let chunk_a = chunk_a.build();

    let mut chunk_b = ChunkBuilder::new();
    chunk_b.emit(Op::SubshellBegin, 1);
    chunk_b.emit(Op::SubshellEnd, 1);
    chunk_b.emit(Op::GetStatus, 1);
    let chunk_b = chunk_b.build();

    let mut vm = VM::new(chunk_a);
    vm.set_shell_host(Box::new(BeginEndCountingHost(64)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 64);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);

    vm.reset(chunk_b);
    match vm.run() {
        VMResult::Ok(Value::Status(64)) => {}
        other => panic!(
            "after halt+reset, host MUST still drive subshell_end(Some(64)), got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn request_halt_stops_before_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "JumpIfFalseKeep target MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_2_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2)));
    match vm.run() {
        VMResult::Ok(Value::Status(2)) => {}
        other => panic!("exit code 2 MUST propagate as Status(2), got {:?}", other),
    }
}

#[test]
fn request_halt_after_pushframe_popframe_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "PopFrame after halt MUST NOT run"
    );
}

#[test]
fn subshell_end_with_loadint_only_on_stack_returns_int() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(77), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(15)));
    match vm.run() {
        VMResult::Ok(Value::Int(77)) => {}
        other => panic!(
            "SubshellEnd MUST NOT push — sole stack value stays Int(77), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 15);
}

#[test]
fn request_halt_stops_before_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(999), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return Int(0) not LoadInt(999), got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_getstatus_twice_reflects_updated_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(StatusReturningHost(8)));
    match vm.run() {
        VMResult::Ok(Value::Status(8)) => {}
        other => panic!(
            "second GetStatus MUST read subshell-updated last_status(8), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_four_end_ops_incrementing_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..4 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 20 }));
    match vm.run() {
        VMResult::Ok(Value::Status(23)) => {}
        other => panic!("fourth subshell_end(Some(23)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_begin_before_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_END_CALLS.load(Ordering::SeqCst),
        0,
        "PipelineEnd MUST NOT run after halt even when PipelineBegin already ran"
    );
}

#[test]
fn subshell_setstatus_then_end_getstatus_chain() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(20)));
    match vm.run() {
        VMResult::Ok(Value::Status(20)) => {}
        other => panic!(
            "subshell_end(Some(20)) MUST override prior SetStatus(10), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_subshell_begin_after_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(1)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        0,
        "SubshellBegin after halt MUST NOT run even when prior LoadInt completed"
    );
}

#[test]
fn request_halt_only_wide_handler_no_narrow() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static ONLY_WIDE: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(3, 1), 1);
    b.emit(Op::Extended(4, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        ONLY_WIDE.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(ONLY_WIDE.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_some_zero_after_some_negative() {
    struct NegThenZeroHost {
        calls: u32,
    }
    impl ShellHost for NegThenZeroHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            match self.calls {
                1 => Some(-1),
                2 => Some(0),
                _ => None,
            }
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegThenZeroHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST overwrite Some(-1), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_double_pre_run_reset_then_executes() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new();
    let noop_chunk = noop.build();
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::CallBuiltin(7, 0), 1);
    let run_chunk = run_b.build();

    let mut vm = VM::new(noop_chunk.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    assert!(matches!(vm.run(), VMResult::Halted));
    vm.reset(noop_chunk);
    vm.request_halt();
    assert!(matches!(vm.run(), VMResult::Halted));
    vm.reset(run_chunk);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_some_max_then_none_preserves_max() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: i32::MAX,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MAX)) => {}
        other => panic!(
            "None after Some(MAX) MUST preserve last_status, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_callee_return_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("f");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(300), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("callee Return MUST NOT run after halt, got {:?}", other),
    }
}

#[test]
fn subshell_one_begin_two_end_second_status_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(11)) => {}
        other => panic!(
            "second SubshellEnd(Some(11)) MUST win over first Some(10), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_extension_handler_runs_on_new_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_RUNS: AtomicU32 = AtomicU32::new(0);
    let halt_chunk = ChunkBuilder::new().build();
    let mut ext_b = ChunkBuilder::new();
    ext_b.emit(Op::Extended(8, 1), 1);
    let ext_chunk = ext_b.build();

    let mut vm = VM::new(halt_chunk);
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        EXT_RUNS.fetch_add(1, Ordering::SeqCst);
    }));
    vm.request_halt();
    let _ = vm.run();
    EXT_RUNS.store(0, Ordering::SeqCst);
    vm.reset(ext_chunk);
    let _ = vm.run();
    assert_eq!(EXT_RUNS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_after_pipelineend_getstatus_reads_subshell_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "GetStatus after subshell MUST read 9 not pipeline 3, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_halt_reset_getstatus_full_chain() {
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::LoadInt(50), 1);
    run_b.emit(Op::SetStatus, 1);
    run_b.emit(Op::SubshellBegin, 1);
    run_b.emit(Op::SubshellEnd, 1);
    run_b.emit(Op::CallBuiltin(100, 0), 1);
    let run_chunk = run_b.build();

    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(run_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(60)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 60);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset after subshell+halt MUST zero last_status before GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_two_begin_end_pairs_last_status_wins() {
    let mut b = ChunkBuilder::new();
    for _ in 0..2 {
        b.emit(Op::SubshellBegin, 1);
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "second pair subshell_end(Some(9)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_setstatus_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(88), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 1,
        "SetStatus MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_127_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(127)));
    match vm.run() {
        VMResult::Ok(Value::Status(127)) => {}
        other => panic!("exit code 127 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_getstatus_before_second_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(55), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return builtin Int(0) not second GetStatus(55), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 55);
}

#[test]
fn subshell_end_two_loadints_top_value_returned() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(4)));
    match vm.run() {
        VMResult::Ok(Value::Int(2)) => {}
        other => panic!(
            "SubshellEnd MUST NOT push — run() pops top Int(2), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_pipeline_begin_and_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineStageHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_STAGE_CALLS.load(Ordering::SeqCst),
        0,
        "PipelineStage MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_invokes_host_every_time_regardless_of_value() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(5)));
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        2,
        "each SubshellEnd MUST call host even when returning same status"
    );
    assert_eq!(vm.last_status, 5);
}

#[test]
fn request_halt_extension_handler_reads_subshell_last_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN_STATUS: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::Extended(5, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(42)));
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        SEEN_STATUS.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(
        SEEN_STATUS.load(Ordering::SeqCst),
        42,
        "extension handler MUST see subshell-updated last_status before halt"
    );
}

#[test]
fn subshell_end_exit_code_126_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(126)));
    match vm.run() {
        VMResult::Ok(Value::Status(126)) => {}
        other => panic!("exit code 126 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_setstatus_after_end_overwrites_subshell_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(8)));
    match vm.run() {
        VMResult::Ok(Value::Status(3)) => {}
        other => panic!(
            "SetStatus(3) after subshell MUST overwrite last_status(8), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_call_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("fn");
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Call(name, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(7, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        0,
        "Call op MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_double_reset_then_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::CallBuiltin(7, 0), 1);
    let run_chunk = run_b.build();

    let mut vm = VM::new(noop.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop.clone());
    vm.reset(run_chunk);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_after_begin_only_pair_updates_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.set_shell_host(Box::new(StatusReturningHost(33)));
    match vm.run() {
        VMResult::Ok(Value::Status(33)) => {}
        other => panic!(
            "SubshellEnd MUST update status even with trailing SubshellBegin, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_getstatus_subshell_getstatus_two_updates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "final GetStatus MUST read second subshell Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_nested_two_level_call_stops_at_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let inner = b.add_name("inner");
    let outer = b.add_name("outer");
    b.emit(Op::Call(outer, 0), 1);
    b.emit(Op::LoadInt(500), 1);
    let skip_outer = b.emit(Op::Jump(0), 1);
    let outer_entry = b.current_pos();
    b.add_sub_entry(outer, outer_entry);
    b.emit(Op::Call(inner, 0), 1);
    b.emit(Op::ReturnValue, 1);
    let skip_inner = b.emit(Op::Jump(0), 1);
    let inner_entry = b.current_pos();
    b.add_sub_entry(inner, inner_entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip_inner, b.current_pos());
    b.patch_jump(skip_outer, b.current_pos());

    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "two-level nested halt MUST return builtin result, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_five_end_incrementing_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(5)) => {}
        other => panic!("fifth subshell_end(Some(5)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_many_ops_none_execute() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(99)));
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn request_halt_after_getstatus_on_stack_returns_builtin_not_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(55), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return Int(0) not Status(55) from stack below, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_begin_end_halt_begin_count_is_one() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(70)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 70);
}

#[test]
fn subshell_halt_reset_subshell_halt_reset_getstatus() {
    let mut sub_b = ChunkBuilder::new();
    sub_b.emit(Op::SubshellBegin, 1);
    sub_b.emit(Op::SubshellEnd, 1);
    sub_b.emit(Op::CallBuiltin(100, 0), 1);
    let sub_chunk = sub_b.build();

    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(sub_chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(81)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 81);

    vm.reset(sub_chunk);
    let _ = vm.run();
    assert_eq!(vm.last_status, 81);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "final reset MUST clear last_status before GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_none_none_some_via_third_host() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.set_shell_host(Box::new(ThirdSomeSubshellHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(30)) => {}
        other => panic!(
            "ThirdSomeSubshellHost MUST apply Some(30) on third end, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_subshell_begin_before_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.set_shell_host(Box::new(BeginEndCountingHost(11)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        0,
        "SubshellEnd MUST NOT run after halt even when SubshellBegin already ran"
    );
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_end_exit_code_124_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(124)));
    match vm.run() {
        VMResult::Ok(Value::Status(124)) => {}
        other => panic!("exit code 124 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_six_end_incrementing_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..6 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(15)) => {}
        other => panic!("sixth subshell_end(Some(15)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_backward_jump_target() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let fwd = b.emit(Op::Jump(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(fwd, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "backward Jump target MUST NOT run after request_halt"
    );
}

#[test]
fn request_halt_wide_handler_reads_setstatus_last_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static WIDE_SEEN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(37), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::ExtendedWide(1, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        WIDE_SEEN.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(
        WIDE_SEEN.load(Ordering::SeqCst),
        37,
        "ExtendedWide handler MUST see SetStatus-written last_status"
    );
}

#[test]
fn subshell_replaced_host_none_on_second_reset_chunk() {
    let mut b1 = ChunkBuilder::new();
    b1.emit(Op::SubshellEnd, 1);
    let chunk1 = b1.build();
    let mut b2 = ChunkBuilder::new();
    b2.emit(Op::SubshellEnd, 1);
    b2.emit(Op::GetStatus, 1);
    let chunk2 = b2.build();

    let mut vm = VM::new(chunk1);
    vm.set_shell_host(Box::new(StatusReturningHost(5)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 5);

    vm.set_shell_host(Box::new(NoneHost));
    vm.reset(chunk2);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "NoneHost after reset MUST leave last_status(0) not prior 5, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_top_level_return_value() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(88), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("ReturnValue(88) MUST NOT run after halt, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-2)));
    match vm.run() {
        VMResult::Ok(Value::Status(-2)) => {}
        other => panic!("status -2 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_triple_reset_then_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::CallBuiltin(7, 0), 1);
    let run_chunk = run_b.build();

    let mut vm = VM::new(noop.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop.clone());
    vm.reset(noop.clone());
    vm.reset(run_chunk);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_three_begins_one_end_still_applies_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(44)));
    match vm.run() {
        VMResult::Ok(Value::Status(44)) => {}
        other => panic!(
            "single SubshellEnd MUST apply after triple SubshellBegin, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 3);
}

#[test]
fn subshell_getstatus_loadint_getstatus_final_is_loadint() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(7)));
    match vm.run() {
        VMResult::Ok(Value::Status(7)) => {}
        other => panic!(
            "top GetStatus(7) MUST be below LoadInt(9) — run pops Status(7), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_two_subshell_begins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(55)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        1,
        "second SubshellBegin MUST NOT run after halt"
    );
    assert_eq!(vm.last_status, 0);
}

struct MaxThenMinHost {
    calls: u32,
}

impl ShellHost for MaxThenMinHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        match self.calls {
            1 => Some(i32::MAX),
            2 => Some(i32::MIN),
            _ => None,
        }
    }
}

#[test]
fn subshell_max_then_min_second_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(MaxThenMinHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MIN)) => {}
        other => panic!(
            "second subshell_end(MIN) MUST overwrite first MAX, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_halt_flag_persists_after_ok_return() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    assert!(matches!(vm.run(), VMResult::Ok(Value::Int(0))));
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        0,
        "halted flag MUST persist after Ok return from first run()"
    );
}

#[test]
fn subshell_incrementing_from_100_to_104() {
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 100 }));
    match vm.run() {
        VMResult::Ok(Value::Status(104)) => {}
        other => panic!("fifth Some(104) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_pipeline_end_without_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_halt_subshell_getstatus_same_vm_no_reset() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(92)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 92);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) | VMResult::Halted => {}
        other => panic!("second run without reset unexpected {:?}", other),
    }
}

#[test]
fn request_halt_extension_handler_receives_id_and_arg() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN_ID: AtomicU32 = AtomicU32::new(0);
    static SEEN_ARG: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(42, 7), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, id, arg| {
        SEEN_ID.store(id as u32, Ordering::SeqCst);
        SEEN_ARG.store(arg as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SEEN_ID.load(Ordering::SeqCst), 42);
    assert_eq!(SEEN_ARG.load(Ordering::SeqCst), 7);
}

#[test]
fn full_lifecycle_setstatus_subshell_halt_reset_getstatus() {
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::LoadInt(41), 1);
    run_b.emit(Op::SetStatus, 1);
    run_b.emit(Op::SubshellEnd, 1);
    run_b.emit(Op::CallBuiltin(100, 0), 1);
    let run_chunk = run_b.build();

    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(run_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(83)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 83);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!("reset MUST clear subshell+setstatus state, got {:?}", other),
    }
}

#[test]
fn subshell_ten_end_incrementing_from_zero() {
    let mut b = ChunkBuilder::new();
    for _ in 0..10 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!("tenth subshell_end(Some(9)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_125_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(125)));
    match vm.run() {
        VMResult::Ok(Value::Status(125)) => {}
        other => panic!("exit code 125 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_subshell_ends() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(3)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        1,
        "second SubshellEnd MUST NOT run after request_halt"
    );
    assert_eq!(vm.last_status, 3);
}

#[test]
fn request_halt_three_builtins_before_halt_all_run() {
    static PRE: AtomicU32 = AtomicU32::new(0);
    fn pre(_vm: &mut VM, _argc: u8) -> Value {
        PRE.fetch_add(1, Ordering::SeqCst);
        Value::Int(0)
    }
    fn halt(vm: &mut VM, _argc: u8) -> Value {
        PRE.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
        Value::Int(0)
    }
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PRE.store(0, Ordering::SeqCst);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(10, 0), 1);
    b.emit(Op::CallBuiltin(11, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(10, pre);
    vm.register_builtin(11, pre);
    vm.register_builtin(100, halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(PRE.load(Ordering::SeqCst), 3);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_seven_end_incrementing_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..7 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(6)) => {}
        other => panic!("seventh subshell_end(Some(6)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_wide_extension_receives_id_and_payload() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN_ID: AtomicU32 = AtomicU32::new(0);
    static SEEN_PAYLOAD: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(99, 0xABCD), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, id, payload| {
        SEEN_ID.store(id as u32, Ordering::SeqCst);
        SEEN_PAYLOAD.store(payload as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SEEN_ID.load(Ordering::SeqCst), 99);
    assert_eq!(SEEN_PAYLOAD.load(Ordering::SeqCst), 0xABCD);
}

#[test]
fn subshell_pipeline_stage_does_not_change_last_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::GetStatus, 1);
    struct StageAndSubshellHost;
    impl ShellHost for StageAndSubshellHost {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(12)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StageAndSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!(
            "PipelineStage MUST NOT overwrite subshell last_status(12), got {:?}",
            other
        ),
    }
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn request_halt_stops_before_second_push_frame() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_130_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(130)));
    match vm.run() {
        VMResult::Ok(Value::Status(130)) => {}
        other => panic!("exit code 130 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_mid_subshell_chunk_allows_end() {
    let mut partial = ChunkBuilder::new();
    partial.emit(Op::SubshellBegin, 1);
    partial.emit(Op::CallBuiltin(100, 0), 1);
    let partial = partial.build();

    let mut full = ChunkBuilder::new();
    full.emit(Op::SubshellBegin, 1);
    full.emit(Op::SubshellEnd, 1);
    full.emit(Op::GetStatus, 1);
    let full = full.build();

    let mut vm = VM::new(partial);
    vm.set_shell_host(Box::new(StatusReturningHost(47)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 0);

    vm.reset(full);
    match vm.run() {
        VMResult::Ok(Value::Status(47)) => {}
        other => panic!(
            "reset MUST allow subshell_end after halted partial chunk, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_getstatus_twice_without_intervening_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(19)));
    match vm.run() {
        VMResult::Ok(Value::Status(19)) => {}
        other => panic!(
            "both GetStatus MUST read subshell-updated 19, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_subshell_begin_end_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(25)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        1,
        "only first SubshellEnd MUST run — second pair blocked by halt"
    );
    assert_eq!(vm.last_status, 25);
}

#[test]
fn subshell_end_loadint_getstatus_stack_order() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(66), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(4)));
    match vm.run() {
        VMResult::Ok(Value::Status(4)) => {}
        other => panic!(
            "GetStatus(4) MUST be stack top over LoadInt(66), got {:?}",
            other
        ),
    }
}

struct MinThenMaxHost {
    calls: u32,
}

impl ShellHost for MinThenMaxHost {
    fn subshell_end(&mut self) -> Option<i32> {
        self.calls += 1;
        match self.calls {
            1 => Some(i32::MIN),
            2 => Some(i32::MAX),
            _ => None,
        }
    }
}

#[test]
fn subshell_min_then_max_second_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(MinThenMaxHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MAX)) => {}
        other => panic!(
            "second subshell_end(MAX) MUST overwrite MIN, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_four_consecutive_runs_never_resume() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..4 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twelve_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..12 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!("twelfth subshell_end(Some(12)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_extended_without_handler_continues() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(
        TOUCHED.load(Ordering::SeqCst),
        1,
        "CallBuiltin MUST run when Extended has no handler registered"
    );
}

#[test]
fn subshell_after_pipeline_begin_stage_without_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct StageSubshellHost;
    impl ShellHost for StageSubshellHost {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(28)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StageSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(28)) => {}
        other => panic!(
            "subshell_end(Some(28)) MUST apply without PipelineEnd, got {:?}",
            other
        ),
    }
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn request_halt_with_host_set_builtin_still_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(99)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn full_lifecycle_halt_reset_subshell_getstatus_twice() {
    let halt_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let status_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::GetStatus, 1);
        b.build()
    };

    let mut vm = VM::new(halt_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(95)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();

    vm.reset(sub_chunk.clone());
    match vm.run() {
        VMResult::Ok(Value::Status(95)) => {}
        other => panic!(
            "subshell after reset MUST use preserved host, got {:?}",
            other
        ),
    }

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!("final reset MUST zero last_status, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_end_incrementing_from_zero() {
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(19)) => {}
        other => panic!("twentieth subshell_end(Some(19)) MUST win, got {:?}", other),
    }
}

// ─── Additional pin tests (handwritten) ───────────────────────────────────

#[test]
fn subshell_end_exit_code_3_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(3)));
    match vm.run() {
        VMResult::Ok(Value::Status(3)) => {}
        other => panic!("exit code 3 MUST propagate as Status(3), got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ne_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumNe, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "NumNe/JumpIfTrue target MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_4_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(4)));
    match vm.run() {
        VMResult::Ok(Value::Status(4)) => {}
        other => panic!("exit code 4 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_triple_halt_still_blocks_following_builtin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(50, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(50, builtin_triple_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(
        AFTER_HALT_COUNT.load(Ordering::SeqCst),
        0,
        "triple request_halt MUST still stop dispatch before next op"
    );
}

#[test]
fn subshell_end_exit_code_5_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(5)));
    match vm.run() {
        VMResult::Ok(Value::Status(5)) => {}
        other => panic!("exit code 5 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_halt_only_pushes_undef_and_blocks_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(61, 0), 1);
    b.emit(Op::LoadInt(777), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(61, builtin_halt_only);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Undef) => {}
        other => panic!(
            "halt_only MUST return Undef on stack top, not LoadInt(777), got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_7_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(7)));
    match vm.run() {
        VMResult::Ok(Value::Status(7)) => {}
        other => panic!("exit code 7 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_subshell_chunk_skips_host_until_reset() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let chunk = b.build();
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(31)));
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "pre-run halt on subshell chunk MUST return Halted, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
    vm.reset(chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(31)) => {}
        other => panic!("after reset subshell_end MUST run, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_9_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(9)));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!("exit code 9 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_true_after_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_11_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(11)));
    match vm.run() {
        VMResult::Ok(Value::Status(11)) => {}
        other => panic!("exit code 11 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_false_after_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_12_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(12)));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!("exit code 12 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_pipeline_stages_blocks_second_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(3), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineStageHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_STAGE_CALLS.load(Ordering::SeqCst),
        1,
        "second PipelineStage MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_13_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(13)));
    match vm.run() {
        VMResult::Ok(Value::Status(13)) => {}
        other => panic!("exit code 13 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_first_pipeline_end_blocks_second_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_END_CALLS.load(Ordering::SeqCst),
        1,
        "second PipelineEnd MUST NOT run after request_halt"
    );
}

#[test]
fn subshell_end_exit_code_14_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(14)));
    match vm.run() {
        VMResult::Ok(Value::Status(14)) => {}
        other => panic!("exit code 14 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_with_two_args_halts_before_caller_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("halt_callee");
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::Call(name, 2), 1);
    b.emit(Op::LoadInt(999), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt in 2-arg callee MUST NOT run caller LoadInt(999), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_15_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(15)));
    match vm.run() {
        VMResult::Ok(Value::Status(15)) => {}
        other => panic!("exit code 15 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_narrow_extension_blocks_following_wide_on_same_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static NARROW_RAN: AtomicU32 = AtomicU32::new(0);
    static WIDE_RAN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::ExtendedWide(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        NARROW_RAN.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.set_extension_wide_handler(Box::new(|_vm, _id, _payload| {
        WIDE_RAN.fetch_add(1, Ordering::SeqCst);
    }));
    let _ = vm.run();
    assert_eq!(NARROW_RAN.load(Ordering::SeqCst), 1);
    assert_eq!(WIDE_RAN.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_16_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(16)));
    match vm.run() {
        VMResult::Ok(Value::Status(16)) => {}
        other => panic!("exit code 16 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_wide_extension_blocks_following_narrow_on_same_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static NARROW_RAN: AtomicU32 = AtomicU32::new(0);
    static WIDE_RAN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(3, 0), 1);
    b.emit(Op::Extended(4, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        WIDE_RAN.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        NARROW_RAN.fetch_add(1, Ordering::SeqCst);
    }));
    let _ = vm.run();
    assert_eq!(WIDE_RAN.load(Ordering::SeqCst), 1);
    assert_eq!(NARROW_RAN.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_17_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(17)));
    match vm.run() {
        VMResult::Ok(Value::Status(17)) => {}
        other => panic!("exit code 17 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_after_halted_subshell_chunk_allows_fresh_getstatus_zero() {
    let mut run_b = ChunkBuilder::new();
    run_b.emit(Op::SubshellEnd, 1);
    run_b.emit(Op::CallBuiltin(100, 0), 1);
    let run_chunk = run_b.build();
    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(run_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(52)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 52);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset MUST clear last_status from halted subshell run, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_18_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(18)));
    match vm.run() {
        VMResult::Ok(Value::Status(18)) => {}
        other => panic!("exit code 18 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_double_reset_then_subshell_end_runs() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let mut sub_b = ChunkBuilder::new();
    sub_b.emit(Op::SubshellEnd, 1);
    let sub_chunk = sub_b.build();

    let mut vm = VM::new(noop.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(64)));
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop);
    vm.reset(sub_chunk);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 64);
}

#[test]
fn subshell_end_exit_code_19_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(19)));
    match vm.run() {
        VMResult::Ok(Value::Status(19)) => {}
        other => panic!("exit code 19 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_top_level_return_on_nonempty_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(44), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("Return MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_20_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(20)));
    match vm.run() {
        VMResult::Ok(Value::Status(20)) => {}
        other => panic!("exit code 20 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_with_two_ints_on_stack_returns_builtin_not_deeper_int() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(100), 1);
    b.emit(Op::LoadInt(200), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "run() MUST pop only halt builtin result, not deeper Int(100), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_21_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(21)));
    match vm.run() {
        VMResult::Ok(Value::Status(21)) => {}
        other => panic!("exit code 21 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callbuiltin_three_args_reports_argc_before_stop() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 3), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_halt_report_argc);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(3)) => {}
        other => panic!("halt MUST push argc=3 before stopping, got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_22_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(22)));
    match vm.run() {
        VMResult::Ok(Value::Status(22)) => {}
        other => panic!("exit code 22 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_second_subshell_begin_in_same_chunk_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(0)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst),
        1,
        "second SubshellBegin MUST NOT run after halt"
    );
}

#[test]
fn subshell_end_exit_code_129_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(129)));
    match vm.run() {
        VMResult::Ok(Value::Status(129)) => {}
        other => panic!("exit code 129 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_subshell_end_and_getstatus_leaves_status_set() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(73)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("GetStatus MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 73);
}

#[test]
fn subshell_end_exit_code_131_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(131)));
    match vm.run() {
        VMResult::Ok(Value::Status(131)) => {}
        other => panic!("exit code 131 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_consecutive_runs_never_advance_past_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..5 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_132_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(132)));
    match vm.run() {
        VMResult::Ok(Value::Status(132)) => {}
        other => panic!("exit code 132 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_begin_only_one_begin_call() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(3), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineBeginHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst),
        1,
        "second PipelineBegin MUST NOT run after halt"
    );
}

#[test]
fn subshell_end_exit_code_133_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(133)));
    match vm.run() {
        VMResult::Ok(Value::Status(133)) => {}
        other => panic!("exit code 133 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_blocks_loadint_between_two_subshell_ends() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(555), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(8)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        SUBSHELL_END_CALLS.load(Ordering::SeqCst),
        1,
        "second SubshellEnd MUST NOT run after halt"
    );
    assert_eq!(vm.last_status, 8);
}

#[test]
fn subshell_end_exit_code_134_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(134)));
    match vm.run() {
        VMResult::Ok(Value::Status(134)) => {}
        other => panic!("exit code 134 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_extended_without_handler_still_blocks_following_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(9, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(123), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-3)));
    match vm.run() {
        VMResult::Ok(Value::Status(-3)) => {}
        other => panic!("status -3 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_jump_if_true_keep_with_true_condition_not_taken_before_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-4)));
    match vm.run() {
        VMResult::Ok(Value::Status(-4)) => {}
        other => panic!("status -4 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_jump_if_false_keep_with_false_condition_not_taken_before_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_eight_end_incrementing_from_thirty() {
    let mut b = ChunkBuilder::new();
    for _ in 0..8 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 30 }));
    match vm.run() {
        VMResult::Ok(Value::Status(37)) => {}
        other => panic!("eighth subshell_end(Some(37)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_between_subshell_end_and_setstatus_preserves_subshell_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(46)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 46,
        "SetStatus MUST NOT run after halt — subshell status MUST stick"
    );
}

#[test]
fn subshell_nine_end_incrementing_from_forty() {
    let mut b = ChunkBuilder::new();
    for _ in 0..9 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 40 }));
    match vm.run() {
        VMResult::Ok(Value::Status(48)) => {}
        other => panic!("ninth subshell_end(Some(48)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_then_wide_handler_runs_on_fresh_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static WIDE_TOUCHED: AtomicU32 = AtomicU32::new(0);
    let halt_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let wide_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::ExtendedWide(8, 0xBEEF), 1);
        b.build()
    };
    let mut vm = VM::new(halt_chunk);
    vm.set_extension_wide_handler(Box::new(|_vm, _id, _payload| {
        WIDE_TOUCHED.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    WIDE_TOUCHED.store(0, Ordering::SeqCst);
    vm.reset(wide_chunk);
    let _ = vm.run();
    assert_eq!(WIDE_TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_eleven_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..11 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(12)) => {}
        other => panic!("eleventh subshell_end(Some(12)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_begin_end_halt_reset_subshell_getstatus() {
    let mut sub_b = ChunkBuilder::new();
    sub_b.emit(Op::SubshellBegin, 1);
    sub_b.emit(Op::SubshellEnd, 1);
    sub_b.emit(Op::CallBuiltin(100, 0), 1);
    let sub_chunk = sub_b.build();
    let mut status_b = ChunkBuilder::new();
    status_b.emit(Op::GetStatus, 1);
    let status_chunk = status_b.build();

    let mut vm = VM::new(sub_chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(58)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 58);

    vm.reset(status_chunk);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset after subshell+halt MUST zero last_status, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_thirteen_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..13 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(19)) => {}
        other => panic!(
            "thirteenth subshell_end(Some(19)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_callee_return_not_reached_when_halt_before_return_value() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("inner_ret");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(500), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::LoadInt(77), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "ReturnValue(77) MUST NOT run after halt in callee, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_fifteen_end_incrementing_from_twelve() {
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(26)) => {}
        other => panic!("fifteenth subshell_end(Some(26)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_host_subshell_end_count_one_when_halt_after_first() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(14)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_alternating_fourth_none_keeps_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..4 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost fourth None MUST keep prior Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_getstatus_leaves_prior_status_on_stack_unpopped() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(33), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(44), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return builtin Int(0), not LoadInt(44), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 33);
}

#[test]
fn subshell_none_then_some_second_end_updates_from_eleven() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(NoneThenSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!(
            "NoneThenSomeHost second Some(42) MUST overwrite 11, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_two_getstatus_ops_second_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(25), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("second GetStatus MUST NOT run after halt, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_twice_preserves_eighty_eight() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 88,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(88)) => {}
        other => panic!(
            "FirstSomeThenNoneHost MUST preserve Some(88) through later None, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_pipeline_end_after_subshell_end_both_ran_status_from_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        vm.last_status, 9,
        "subshell_end(Some(9)) MUST run before halt; PipelineEnd MUST NOT run after"
    );
}

#[test]
fn subshell_pipeline_end_before_subshell_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "GetStatus MUST read subshell_end(9) not pipeline_end(3), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_open_pipeline_begin_blocks_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_setstatus_between_two_ends_second_end_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(50), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 100 }));
    match vm.run() {
        VMResult::Ok(Value::Status(101)) => {}
        other => panic!(
            "second subshell_end(Some(101)) MUST beat SetStatus(50), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_three_level_nested_call_stops_at_innermost_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let outer = b.add_name("outer");
    let mid = b.add_name("mid");
    let inner = b.add_name("inner");
    b.emit(Op::Call(outer, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let outer_e = b.current_pos();
    b.add_sub_entry(outer, outer_e);
    b.emit(Op::Call(mid, 0), 1);
    b.emit(Op::Return, 1);
    let mid_e = b.current_pos();
    b.add_sub_entry(mid, mid_e);
    b.emit(Op::Call(inner, 0), 1);
    b.emit(Op::Return, 1);
    let inner_e = b.current_pos();
    b.add_sub_entry(inner, inner_e);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_three_begins_two_ends_last_end_status_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(6)) => {}
        other => panic!(
            "second SubshellEnd(Some(6)) MUST win over first Some(5), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_as_only_op_on_empty_chunk_returns_ok_from_builtin() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "sole halt builtin MUST return Ok(Int(0)) on empty pre-stack, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_host_swap_none_then_status_on_second_reset_chunk() {
    let chunk1 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let chunk2 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk1);
    vm.set_shell_host(Box::new(NoneHost));
    let _ = vm.run();
    assert_eq!(vm.last_status, 0);
    vm.set_shell_host(Box::new(StatusReturningHost(67)));
    vm.reset(chunk2);
    match vm.run() {
        VMResult::Ok(Value::Status(67)) => {}
        other => panic!(
            "StatusReturningHost after swap MUST apply Some(67), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_subshell_begin_before_end_leaves_status_zero() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(29)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_loadint_between_two_getstatus_second_on_top() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::LoadInt(77), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(6)));
    match vm.run() {
        VMResult::Ok(Value::Status(6)) => {}
        other => panic!(
            "top GetStatus(6) MUST be returned; LoadInt(77) below it, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_clears_halt_allows_subshell_on_same_vm_instance() {
    let mut sub_b = ChunkBuilder::new();
    sub_b.emit(Op::SubshellEnd, 1);
    sub_b.emit(Op::CallBuiltin(100, 0), 1);
    let sub_chunk = sub_b.build();
    let mut vm = VM::new(sub_chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(84)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub_chunk);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "second run after reset MUST reach halt builtin again, got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 84);
}

#[test]
fn subshell_custom_pipeline_negative_exit_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CustomPipelineHost(-7)));
    match vm.run() {
        VMResult::Ok(Value::Status(-7)) => {}
        other => panic!(
            "CustomPipelineHost(-7) MUST push negative pipeline status, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_extension_handler_can_read_vm_last_status_before_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(41), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::Extended(6, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        SEEN.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SEEN.load(Ordering::SeqCst), 41);
}

#[test]
fn subshell_zero_after_max_on_single_vm_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct MaxThenZeroHost {
        calls: u32,
    }
    impl ShellHost for MaxThenZeroHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(i32::MAX)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(MaxThenZeroHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!("Some(0) MUST overwrite i32::MAX, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_nonempty_stack_still_halts_before_first_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(7, builtin_touched);
    vm.stack.push(Value::Int(1));
    vm.request_halt();
    match vm.run() {
        VMResult::Ok(Value::Int(1)) => {}
        other => panic!(
            "pre-run halt with pre-seeded stack MUST pop stack top without running ops, got {:?}",
            other
        ),
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_negative_after_zero_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct ZeroThenNegativeHost {
        calls: u32,
    }
    impl ShellHost for ZeroThenNegativeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(0)
            } else {
                Some(-9)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(ZeroThenNegativeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(-9)) => {}
        other => panic!("Some(-9) MUST overwrite Some(0), got {:?}", other),
    }
}

#[test]
fn request_halt_between_pushframe_and_popframe_pop_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_fourteen_end_incrementing_from_eighteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..14 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 18 }));
    match vm.run() {
        VMResult::Ok(Value::Status(31)) => {}
        other => panic!(
            "fourteenth subshell_end(Some(31)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_full_pipeline_begin_stage_end_then_halt_before_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_default_host_on_second_chunk_after_status_host_first() {
    let chunk1 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let chunk2 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk1);
    vm.set_shell_host(Box::new(StatusReturningHost(23)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 23);
    vm.set_shell_host(Box::new(DefaultHost));
    vm.reset(chunk2);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "DefaultHost subshell_end(None) after reset MUST leave last_status(0), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_subshell_status_visible_to_extension_after_end_before_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::Extended(11, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(96)));
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        SEEN.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SEEN.load(Ordering::SeqCst), 96);
}

#[test]
fn subshell_end_exit_code_135_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(135)));
    match vm.run() {
        VMResult::Ok(Value::Status(135)) => {}
        other => panic!("exit code 135 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_undef_after_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadUndef, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_136_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(136)));
    match vm.run() {
        VMResult::Ok(Value::Status(136)) => {}
        other => panic!("exit code 136 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_on_nonempty_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_sixteen_end_incrementing_from_twenty_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 22 }));
    match vm.run() {
        VMResult::Ok(Value::Status(37)) => {}
        other => panic!("sixteenth subshell_end(Some(37)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_after_callee_returnvalue_before_second_builtin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("ret_one");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt builtin result MUST be stack top over callee ReturnValue(1), got {:?}",
            other
        ),
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_third_some_host_on_fifth_end_applies_fifty() {
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FifthSomeSubshellHost {
        calls: u32,
    }
    impl ShellHost for FifthSomeSubshellHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 5 {
                Some(50)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FifthSomeSubshellHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(50)) => {}
        other => panic!("fifth subshell_end(Some(50)) MUST apply, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_extended_ops_second_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static FIRST: AtomicU32 = AtomicU32::new(0);
    static SECOND: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, id, _arg| {
        if id == 1 {
            FIRST.fetch_add(1, Ordering::SeqCst);
            vm.request_halt();
        } else {
            SECOND.fetch_add(1, Ordering::SeqCst);
        }
    }));
    let _ = vm.run();
    assert_eq!(FIRST.load(Ordering::SeqCst), 1);
    assert_eq!(SECOND.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_getstatus_after_begin_without_end_reads_prior_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 38;
    vm.set_shell_host(Box::new(BeginEndCountingHost(99)));
    match vm.run() {
        VMResult::Ok(Value::Status(38)) => {}
        other => panic!(
            "GetStatus before SubshellEnd MUST read prior last_status(38), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_then_extension_handler_runs_extended_op() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_RAN: AtomicU32 = AtomicU32::new(0);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let ext = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::Extended(20, 5), 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_extension_handler(Box::new(|_vm, id, arg| {
        assert_eq!(id, 20);
        assert_eq!(arg, 5);
        EXT_RAN.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    EXT_RAN.store(0, Ordering::SeqCst);
    vm.reset(ext);
    let _ = vm.run();
    assert_eq!(EXT_RAN.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_after_two_pipeline_stages_without_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(3), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct StageSubshellHost2;
    impl ShellHost for StageSubshellHost2 {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(62)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StageSubshellHost2));
    match vm.run() {
        VMResult::Ok(Value::Status(62)) => {}
        other => panic!(
            "subshell_end(Some(62)) MUST apply mid-pipeline without PipelineEnd, got {:?}",
            other
        ),
    }
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn request_halt_after_subshell_end_and_before_pipeline_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineBeginHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_end_status_minus_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-5)));
    match vm.run() {
        VMResult::Ok(Value::Status(-5)) => {}
        other => panic!("status -5 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_halt_flag_survives_ok_return_from_empty_halt_only_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(61, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(61, builtin_halt_only);
    vm.register_builtin(7, builtin_touched);
    assert!(matches!(vm.run(), VMResult::Ok(Value::Undef)));
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_orphan_end_counting_host_invoked_without_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(16)));
    match vm.run() {
        VMResult::Ok(Value::Status(16)) => {}
        other => panic!(
            "orphan SubshellEnd MUST invoke host and apply Some(16), got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn request_halt_between_subshell_begin_and_subshell_end_no_status_change() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 14;
    vm.set_shell_host(Box::new(CountingSubshellEndHost(55)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 14);
}

// ─── Pin tests batch A (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_23_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(23)));
    match vm.run() {
        VMResult::Ok(Value::Status(23)) => {}
        other => panic!("exit code 23 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_lt_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumLt, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_24_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(24)));
    match vm.run() {
        VMResult::Ok(Value::Status(24)) => {}
        other => panic!("exit code 24 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_gt_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::NumGt, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_25_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(25)));
    match vm.run() {
        VMResult::Ok(Value::Status(25)) => {}
        other => panic!("exit code 25 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(42), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_26_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(26)));
    match vm.run() {
        VMResult::Ok(Value::Status(26)) => {}
        other => panic!("exit code 26 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_swap_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Swap, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_27_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(27)));
    match vm.run() {
        VMResult::Ok(Value::Status(27)) => {}
        other => panic!("exit code 27 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_const() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let c = b.add_constant(Value::Int(99));
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadConst(c), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_28_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(28)));
    match vm.run() {
        VMResult::Ok(Value::Status(28)) => {}
        other => panic!("exit code 28 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_in_open_pipeline_before_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    struct SubshellStageHost39;
    impl ShellHost for SubshellStageHost39 {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(39)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellStageHost39));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 39);
}

#[test]
fn subshell_end_exit_code_29_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(29)));
    match vm.run() {
        VMResult::Ok(Value::Status(29)) => {}
        other => panic!("exit code 29 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_quadruple_reset_then_touched_builtin_runs() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let run = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(7, 0), 1);
        b.build()
    };
    let mut vm = VM::new(noop.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop.clone());
    vm.reset(noop.clone());
    vm.reset(noop.clone());
    vm.reset(run);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_exit_code_30_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(30)));
    match vm.run() {
        VMResult::Ok(Value::Status(30)) => {}
        other => panic!("exit code 30 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_callbuiltin_and_loadint_blocks_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(808), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_137_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(137)));
    match vm.run() {
        VMResult::Ok(Value::Status(137)) => {}
        other => panic!("exit code 137 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_top_level_returnvalue_after_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(63), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("ReturnValue MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_138_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(138)));
    match vm.run() {
        VMResult::Ok(Value::Status(138)) => {}
        other => panic!("exit code 138 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_extension_wide_reads_subshell_status_in_handler() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::ExtendedWide(10, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(77)));
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        SEEN.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SEEN.load(Ordering::SeqCst), 77);
}

#[test]
fn subshell_end_exit_code_139_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(139)));
    match vm.run() {
        VMResult::Ok(Value::Status(139)) => {}
        other => panic!("exit code 139 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_halt_reset_pre_run_halt_reset_then_runs() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(7, 0), 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    let _ = vm.run();
    vm.reset(chunk.clone());
    vm.request_halt();
    let _ = vm.run();
    vm.reset(chunk);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_status_minus_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-6)));
    match vm.run() {
        VMResult::Ok(Value::Status(-6)) => {}
        other => panic!("status -6 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-7)));
    match vm.run() {
        VMResult::Ok(Value::Status(-7)) => {}
        other => panic!("status -7 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_pipeline_end_and_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("GetStatus MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_seventeen_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(25)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(25)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_three_stage_pipeline_halt_before_second_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(3), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineStageHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_STAGE_CALLS.load(Ordering::SeqCst),
        1,
        "only first PipelineStage MUST run before halt"
    );
}

#[test]
fn subshell_eighteen_end_incrementing_from_eleven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(28)) => {}
        other => panic!(
            "eighteenth subshell_end(Some(28)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_nested_call_depth_four_halts_at_level_two() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let l1 = b.add_name("l1");
    let l2 = b.add_name("l2");
    let l3 = b.add_name("l3");
    b.emit(Op::Call(l1, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let e1 = b.current_pos();
    b.add_sub_entry(l1, e1);
    b.emit(Op::Call(l2, 0), 1);
    b.emit(Op::Return, 1);
    let e2 = b.current_pos();
    b.add_sub_entry(l2, e2);
    b.emit(Op::Call(l3, 0), 1);
    b.emit(Op::Return, 1);
    let e3 = b.current_pos();
    b.add_sub_entry(l3, e3);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_nineteen_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(22)) => {}
        other => panic!(
            "nineteenth subshell_end(Some(22)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_callbuiltin_argc_one_reports_one() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::CallBuiltin(100, 1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_halt_report_argc);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(1)) => {}
        other => panic!("halt MUST report argc=1, got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_getstatus_before_end_stays_on_stack_below_updated_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 10;
    vm.set_shell_host(Box::new(StatusReturningHost(32)));
    match vm.run() {
        VMResult::Ok(Value::Status(32)) => {}
        other => panic!("top GetStatus(32) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_chain_of_three_extended_no_handler_then_halt_builtin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    b.emit(Op::Extended(3, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_loadint_deep_stack_unaffected_by_subshell_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(100), 1);
    b.emit(Op::LoadInt(200), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(33)));
    match vm.run() {
        VMResult::Ok(Value::Int(200)) => {}
        other => panic!(
            "SubshellEnd MUST NOT pop stack — top MUST stay Int(200), got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 33);
}

#[test]
fn request_halt_after_setstatus_before_getstatus_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(48), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("GetStatus MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 48);
}

#[test]
fn subshell_begin_end_begin_end_alternating_status_second_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "second Some(9) MUST win over first Some(3), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_subshell_end_then_pipeline_begin_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineBeginHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_setstatus_before_begin_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(55), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(34)));
    match vm.run() {
        VMResult::Ok(Value::Status(34)) => {}
        other => panic!(
            "subshell_end(Some(34)) MUST beat prior SetStatus(55), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_after_halt_allows_second_subshell_end_on_new_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let halt_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt_chunk);
    vm.set_shell_host(Box::new(CountingSubshellEndHost(35)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    vm.reset(end_chunk);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 35);
}

#[test]
fn subshell_end_after_loadtrue_stack_top_is_true() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadTrue, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(36)));
    match vm.run() {
        VMResult::Ok(Value::Bool(true)) => {}
        other => panic!(
            "LoadTrue MUST be stack top after subshell_end, got {:?}",
            other
        ),
    }
    assert_eq!(vm.last_status, 36);
}

#[test]
fn request_halt_halt_between_two_return_ops_in_flat_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_after_loadfalse_stack_top_is_false() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(37)));
    match vm.run() {
        VMResult::Ok(Value::Bool(false)) => {}
        other => panic!(
            "LoadFalse MUST be stack top after subshell_end, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_six_consecutive_runs_without_reset_never_resume() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..6 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_two_setstatus_between_ends_last_end_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 40 }));
    match vm.run() {
        VMResult::Ok(Value::Status(41)) => {}
        other => panic!(
            "second subshell_end(Some(41)) MUST beat SetStatus(10), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_subshell_end_and_pipeline_stage_in_open_pipeline() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    struct SubshellStageHost;
    impl ShellHost for SubshellStageHost {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(43)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellStageHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 43);
}

// ─── Pin tests batch B (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_140_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(140)));
    match vm.run() {
        VMResult::Ok(Value::Status(140)) => {}
        other => panic!("exit code 140 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_add_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Add, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_141_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(141)));
    match vm.run() {
        VMResult::Ok(Value::Status(141)) => {}
        other => panic!("exit code 141 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_sub_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Sub, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_142_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(142)));
    match vm.run() {
        VMResult::Ok(Value::Status(142)) => {}
        other => panic!("exit code 142 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_stage_before_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_143_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(143)));
    match vm.run() {
        VMResult::Ok(Value::Status(143)) => {}
        other => panic!("exit code 143 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_mid_chunk_subshell_end_runs_before_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(44)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 44);
}

#[test]
fn subshell_end_exit_code_144_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(144)));
    match vm.run() {
        VMResult::Ok(Value::Status(144)) => {}
        other => panic!("exit code 144 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_inc_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Inc, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_145_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(145)));
    match vm.run() {
        VMResult::Ok(Value::Status(145)) => {}
        other => panic!("exit code 145 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dec_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dec, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_one_end_incrementing_from_zero() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(20)) => {}
        other => panic!(
            "twenty-first subshell_end(Some(20)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_callee_returns_before_halt_in_caller_second_builtin_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("add_one");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt builtin MUST be stack top over callee ReturnValue(2), got {:?}",
            other
        ),
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_two_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(27)) => {}
        other => panic!(
            "twenty-second subshell_end(Some(27)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_extension_handler_on_reset_chunk_sees_zero_last_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN: AtomicU32 = AtomicU32::new(0);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::LoadInt(99), 1);
        b.emit(Op::SetStatus, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let ext = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::Extended(15, 0), 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        SEEN.store(vm.last_status as u32, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(ext);
    let _ = vm.run();
    assert_eq!(SEEN.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_three_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(30)) => {}
        other => panic!(
            "twenty-third subshell_end(Some(30)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_two_subshell_begins_without_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(0)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_twenty_four_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..24 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(24)) => {}
        other => panic!(
            "twenty-fourth subshell_end(Some(24)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_forward_jump_over_halt_target() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let fwd = b.emit(Op::Jump(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(fwd, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_five_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..25 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(26)) => {}
        other => panic!(
            "twenty-fifth subshell_end(Some(26)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_getstatus_leaves_status_on_stack_when_halt_follows() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(51), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST return builtin Int(0), not Status(51), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_sixth_none_then_some_on_seventh_applies_sixty_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..7 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct SeventhSomeHost {
        calls: u32,
    }
    impl ShellHost for SeventhSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 7 {
                Some(63)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(SeventhSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(63)) => {}
        other => panic!("seventh subshell_end(Some(63)) MUST apply, got {:?}", other),
    }
}

#[test]
fn request_halt_two_subshell_ends_then_halt_third_end_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(45)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
    assert_eq!(vm.last_status, 45);
}

#[test]
fn subshell_pipeline_begin_without_end_subshell_end_status_persists() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct BeginSubshellHost;
    impl ShellHost for BeginSubshellHost {
        fn pipeline_begin(&mut self, _n: u8) {
            PIPELINE_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(46)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(46)) => {}
        other => panic!(
            "subshell_end(Some(46)) MUST apply without PipelineEnd, got {:?}",
            other
        ),
    }
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn request_halt_stops_before_mul_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mul, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-8)));
    match vm.run() {
        VMResult::Ok(Value::Status(-8)) => {}
        other => panic!("status -8 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_div_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Div, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_getstatus_with_zero_last_status_before_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.set_shell_host(Box::new(StatusReturningHost(47)));
    match vm.run() {
        VMResult::Ok(Value::Status(47)) => {}
        other => panic!("final GetStatus MUST read Some(47), got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_preserves_stack_loadint_below_halt_result() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(88), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(48)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST pop builtin Int(0) as top, got {:?}", other),
    }
    assert_eq!(vm.last_status, 48);
}

#[test]
fn subshell_custom_pipeline_zero_after_subshell_four_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CustomPipelineHost(0)));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "PipelineEnd MUST push host.pipeline_end(0), not subshell last_status(4), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_clears_halt_three_subshell_ends_on_fresh_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let ends = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(CountingSubshellEndHost(49)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(ends);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 3);
    assert_eq!(vm.last_status, 49);
}

#[test]
fn subshell_end_after_manual_last_status_ninety_one() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 91;
    vm.set_shell_host(Box::new(StatusReturningHost(52)));
    match vm.run() {
        VMResult::Ok(Value::Status(52)) => {}
        other => panic!(
            "Some(52) MUST overwrite manual last_status(91), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_mod_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mod, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_none_host_first_chunk_status_host_second_after_reset() {
    let c1 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let c2 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(c1);
    vm.last_status = 20;
    vm.set_shell_host(Box::new(NoneHost));
    let _ = vm.run();
    assert_eq!(vm.last_status, 20);
    vm.set_shell_host(Box::new(StatusReturningHost(53)));
    vm.reset(c2);
    match vm.run() {
        VMResult::Ok(Value::Status(53)) => {}
        other => panic!(
            "StatusReturningHost MUST apply Some(53) on reset chunk, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_subshell_end_and_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(54)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 54);
}

#[test]
fn subshell_halt_reset_subshell_end_twice_same_host() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(56)));
    match vm.run() {
        VMResult::Ok(Value::Status(56)) => {}
        other => panic!("first run MUST get Status(56), got {:?}", other),
    }
    vm.reset(chunk.clone());
    match vm.run() {
        VMResult::Ok(Value::Status(56)) => {}
        other => panic!(
            "second run after reset MUST get Status(56), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_num_le_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::NumLe, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_150_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(150)));
    match vm.run() {
        VMResult::Ok(Value::Status(150)) => {}
        other => panic!("exit code 150 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumGe, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_begin_end_halt_reset_begin_end_runs_again() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellBegin, 1);
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(BeginEndCountingHost(57)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    vm.reset(chunk);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 57);
}

#[test]
fn request_halt_with_pipeline_host_and_builtin_in_same_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_max_alone_on_single_end_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(i32::MAX)));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MAX)) => {}
        other => panic!(
            "i32::MAX MUST propagate on orphan SubshellEnd, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_seventh_consecutive_run_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..7 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_min_alone_on_single_end_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(i32::MIN)));
    match vm.run() {
        VMResult::Ok(Value::Status(i32::MIN)) => {}
        other => panic!(
            "i32::MIN MUST propagate on orphan SubshellEnd, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_subshell_then_halt_then_reset_getstatus_zero() {
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let status = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(sub);
    vm.set_shell_host(Box::new(StatusReturningHost(58)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 58);
    vm.reset(status);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "reset MUST zero last_status before GetStatus, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_between_two_loadints_top_is_second_int() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(22), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(59)));
    match vm.run() {
        VMResult::Ok(Value::Int(22)) => {}
        other => panic!("LoadInt(22) MUST be stack top, got {:?}", other),
    }
}

#[test]
fn request_halt_from_builtin_mid_chunk_leaves_earlier_loadint_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(33), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return builtin on top, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_31_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(31)));
    match vm.run() {
        VMResult::Ok(Value::Status(31)) => {}
        other => panic!("exit code 31 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_undef_between_two_loadints() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadUndef, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_32_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(32)));
    match vm.run() {
        VMResult::Ok(Value::Status(32)) => {}
        other => panic!("exit code 32 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_two_push_frames_before_third_push() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_33_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(33)));
    match vm.run() {
        VMResult::Ok(Value::Status(33)) => {}
        other => panic!("exit code 33 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..8 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

// ─── Pin tests batch C (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_34_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(34)));
    match vm.run() {
        VMResult::Ok(Value::Status(34)) => {}
        other => panic!("exit code 34 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup2_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup2, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_35_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(35)));
    match vm.run() {
        VMResult::Ok(Value::Status(35)) => {}
        other => panic!("exit code 35 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_rot_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Rot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_36_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(36)));
    match vm.run() {
        VMResult::Ok(Value::Status(36)) => {}
        other => panic!("exit code 36 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pow_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pow, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_37_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(37)));
    match vm.run() {
        VMResult::Ok(Value::Status(37)) => {}
        other => panic!("exit code 37 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_spaceship_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Spaceship, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_38_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(38)));
    match vm.run() {
        VMResult::Ok(Value::Status(38)) => {}
        other => panic!("exit code 38 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(3.14), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_39_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(39)));
    match vm.run() {
        VMResult::Ok(Value::Status(39)) => {}
        other => panic!("exit code 39 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_eq_on_string_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("a"));
    let bidx = b.add_constant(Value::str("b"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrEq, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_40_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(40)));
    match vm.run() {
        VMResult::Ok(Value::Status(40)) => {}
        other => panic!("exit code 40 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..9 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_41_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(41)));
    match vm.run() {
        VMResult::Ok(Value::Status(41)) => {}
        other => panic!("exit code 41 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ten_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..10 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_42_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(42)));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!("exit code 42 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_eq_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_43_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(43)));
    match vm.run() {
        VMResult::Ok(Value::Status(43)) => {}
        other => panic!("exit code 43 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_eq_jump_if_true_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_44_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(44)));
    match vm.run() {
        VMResult::Ok(Value::Status(44)) => {}
        other => panic!("exit code 44 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_second_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(60)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("second GetStatus MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 60);
}

#[test]
fn subshell_end_exit_code_45_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(45)));
    match vm.run() {
        VMResult::Ok(Value::Status(45)) => {}
        other => panic!("exit code 45 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_loadint_and_setstatus() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(70), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 0;
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 0, "SetStatus MUST NOT run after halt");
}

#[test]
fn subshell_end_exit_code_46_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(46)));
    match vm.run() {
        VMResult::Ok(Value::Status(46)) => {}
        other => panic!("exit code 46 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_twice_then_subshell_end_on_third_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(noop.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(61)));
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop.clone());
    vm.reset(sub);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 61);
}

#[test]
fn subshell_end_exit_code_47_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(47)));
    match vm.run() {
        VMResult::Ok(Value::Status(47)) => {}
        other => panic!("exit code 47 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_halt_before_return_caller_gets_builtin_result() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("halt_fn");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(500), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "caller MUST get halt builtin Int(0), not LoadInt(500), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_48_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(48)));
    match vm.run() {
        VMResult::Ok(Value::Status(48)) => {}
        other => panic!("exit code 48 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_begin_end_then_halt_before_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(62)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 62);
}

#[test]
fn subshell_end_exit_code_49_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(49)));
    match vm.run() {
        VMResult::Ok(Value::Status(49)) => {}
        other => panic!("exit code 49 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_extended_handlers_first_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static COUNTS: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    b.emit(Op::Extended(3, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, id, _arg| {
        COUNTS.fetch_add(1, Ordering::SeqCst);
        if id == 1 {
            vm.request_halt();
        }
    }));
    let _ = vm.run();
    assert_eq!(COUNTS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_exit_code_50_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(50)));
    match vm.run() {
        VMResult::Ok(Value::Status(50)) => {}
        other => panic!("exit code 50 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pipeline_begin_stage_halt_before_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_146_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(146)));
    match vm.run() {
        VMResult::Ok(Value::Status(146)) => {}
        other => panic!("exit code 146 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_open_pipeline_subshell_end_before_stage() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    struct SubshellStageHost60;
    impl ShellHost for SubshellStageHost60 {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(60)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellStageHost60));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 60);
}

#[test]
fn subshell_end_exit_code_147_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(147)));
    match vm.run() {
        VMResult::Ok(Value::Status(147)) => {}
        other => panic!("exit code 147 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_first_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(63)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_exit_code_148_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(148)));
    match vm.run() {
        VMResult::Ok(Value::Status(148)) => {}
        other => panic!("exit code 148 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_wide_handler_halts_before_subsequent_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(5, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(64)));
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_149_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(149)));
    match vm.run() {
        VMResult::Ok(Value::Status(149)) => {}
        other => panic!("exit code 149 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_then_reset_subshell_getstatus_lifecycle() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(65)));
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!("pre-run halt MUST return Halted, got {:?}", other),
    }
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(65)) => {}
        other => panic!("after reset subshell MUST apply Some(65), got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-9)));
    match vm.run() {
        VMResult::Ok(Value::Status(-9)) => {}
        other => panic!("status -9 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_third_push_frame() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_ten_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-10)));
    match vm.run() {
        VMResult::Ok(Value::Status(-10)) => {}
        other => panic!("status -10 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_pipeline_end_ops_in_flat_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(
        PIPELINE_END_CALLS.load(Ordering::SeqCst),
        1,
        "first PipelineEnd MUST run; second MUST NOT after halt"
    );
}

#[test]
fn subshell_twenty_six_end_incrementing_from_ten() {
    let mut b = ChunkBuilder::new();
    for _ in 0..26 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(35)) => {}
        other => panic!(
            "twenty-sixth subshell_end(Some(35)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_extension_reads_subshell_status_then_halts_before_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static SEEN: AtomicU32 = AtomicU32::new(0);
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::Extended(8, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(66)));
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        SEEN.store(vm.last_status as u32, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(SEEN.load(Ordering::SeqCst), 66);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_seven_end_incrementing_from_thirteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..27 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 13 }));
    match vm.run() {
        VMResult::Ok(Value::Status(39)) => {}
        other => panic!(
            "twenty-seventh subshell_end(Some(39)) MUST win, got {:?}",
            other
        ),
    }
}

// ─── Pin tests batch D (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_151_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(151)));
    match vm.run() {
        VMResult::Ok(Value::Status(151)) => {}
        other => panic!("exit code 151 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ne_keep_conditional_jump() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumNe, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_152_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(152)));
    match vm.run() {
        VMResult::Ok(Value::Status(152)) => {}
        other => panic!("exit code 152 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_backward_jump_if_true() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    let fwd = b.emit(Op::Jump(0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let back = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    b.patch_jump(back, b.current_pos());
    b.patch_jump(fwd, back);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_153_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(153)));
    match vm.run() {
        VMResult::Ok(Value::Status(153)) => {}
        other => panic!("exit code 153 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_first_of_three_subshell_ends() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(67)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 67);
}

#[test]
fn subshell_end_exit_code_154_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(154)));
    match vm.run() {
        VMResult::Ok(Value::Status(154)) => {}
        other => panic!("exit code 154 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_status_persists_when_getstatus_on_stack_before_halt() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(68)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return builtin, not Status(68), got {:?}", other),
    }
    assert_eq!(vm.last_status, 68);
}

#[test]
fn subshell_end_exit_code_155_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(155)));
    match vm.run() {
        VMResult::Ok(Value::Status(155)) => {}
        other => panic!("exit code 155 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_push_frames_halt_before_pop_frame() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::PushFrame, 1);
    }
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_eight_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..28 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(32)) => {}
        other => panic!(
            "twenty-eighth subshell_end(Some(32)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_call_op_in_caller_blocked_after_callee_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let inner = b.add_name("inner_h");
    let outer = b.add_name("outer_h");
    b.emit(Op::Call(outer, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let oe = b.current_pos();
    b.add_sub_entry(outer, oe);
    b.emit(Op::Call(inner, 0), 1);
    b.emit(Op::Return, 1);
    let ie = b.current_pos();
    b.add_sub_entry(inner, ie);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twenty_nine_end_incrementing_from_seventeen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..29 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 17 }));
    match vm.run() {
        VMResult::Ok(Value::Status(45)) => {}
        other => panic!(
            "twenty-ninth subshell_end(Some(45)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_reset_preserves_counting_subshell_host_across_three_chunks() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(CountingSubshellEndHost(69)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(end.clone());
    let _ = vm.run();
    vm.reset(end);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
    assert_eq!(vm.last_status, 69);
}

#[test]
fn subshell_thirty_end_incrementing_from_nineteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..30 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 19 }));
    match vm.run() {
        VMResult::Ok(Value::Status(48)) => {}
        other => panic!("thirtieth subshell_end(Some(48)) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_between_getstatus_and_loadint_blocks_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(71), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(72), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_eleven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-11)));
    match vm.run() {
        VMResult::Ok(Value::Status(-11)) => {}
        other => panic!("status -11 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_halt_only_after_loadint_returns_undef_not_int() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::CallBuiltin(61, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(61, builtin_halt_only);
    match vm.run() {
        VMResult::Ok(Value::Undef) => {}
        other => panic!(
            "halt_only MUST return Undef over LoadInt(99), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_eighth_some_on_eighth_end_applies_seventy() {
    let mut b = ChunkBuilder::new();
    for _ in 0..8 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct EighthSomeHost {
        calls: u32,
    }
    impl ShellHost for EighthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 8 {
                Some(70)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(EighthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(70)) => {}
        other => panic!("eighth subshell_end(Some(70)) MUST apply, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_call_in_caller_after_callee_returns() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static OUTER_CALLS: AtomicU32 = AtomicU32::new(0);
    fn outer_fn(_vm: &mut VM, _argc: u8) -> Value {
        OUTER_CALLS.fetch_add(1, Ordering::SeqCst);
        Value::Int(0)
    }
    let mut b = ChunkBuilder::new();
    let name = b.add_name("ret5");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::CallBuiltin(300, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(300, outer_fn);
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST be stack top after callee+outer builtin, got {:?}",
            other
        ),
    }
    assert_eq!(OUTER_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_pipeline_end_then_subshell_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "GetStatus MUST read subshell(9) not pipeline(3), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_subshell_end_in_nested_begin_end_pair() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(71)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 71);
}

#[test]
fn subshell_setstatus_after_begin_before_end_overwritten_by_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::LoadInt(80), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(72)));
    match vm.run() {
        VMResult::Ok(Value::Status(72)) => {}
        other => panic!(
            "subshell_end(Some(72)) MUST beat in-pair SetStatus(80), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_load_true_between_two_loadints() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_two_orphan_ends_none_then_some_host() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 15;
    vm.set_shell_host(Box::new(NoneThenSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!("NoneThenSomeHost second Some(42) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_end_subshell_end_both_complete_before_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    struct BothCountingHost;
    impl ShellHost for BothCountingHost {
        fn pipeline_end(&mut self) -> i32 {
            PIPELINE_END_CALLS.fetch_add(1, Ordering::SeqCst);
            2
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(73)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BothCountingHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 73);
}

#[test]
fn subshell_getstatus_after_end_without_begin_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(74)));
    match vm.run() {
        VMResult::Ok(Value::Status(74)) => {}
        other => panic!("orphan SubshellEnd MUST update GetStatus, got {:?}", other),
    }
}

#[test]
fn request_halt_mid_chunk_setstatus_before_halt_not_reached() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(75), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 1);
}

#[test]
fn subshell_four_begin_two_end_incrementing_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..4 {
        b.emit(Op::SubshellBegin, 1);
    }
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 20 }));
    match vm.run() {
        VMResult::Ok(Value::Status(21)) => {}
        other => panic!("second end Some(21) MUST win, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_extended_wide() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static WIDE1: AtomicU32 = AtomicU32::new(0);
    static WIDE2: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(1, 0), 1);
    b.emit(Op::ExtendedWide(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, id, _payload| {
        if id == 1 {
            WIDE1.fetch_add(1, Ordering::SeqCst);
            vm.request_halt();
        } else {
            WIDE2.fetch_add(1, Ordering::SeqCst);
        }
    }));
    let _ = vm.run();
    assert_eq!(WIDE1.load(Ordering::SeqCst), 1);
    assert_eq!(WIDE2.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_halt_reset_halt_reset_subshell_end_third_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(76)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 3);
    assert_eq!(vm.last_status, 76);
}

#[test]
fn request_halt_empty_chunk_after_reset_on_pre_run_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let empty = ChunkBuilder::new().build();
    let run = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(7, 0), 1);
        b.build()
    };
    let mut vm = VM::new(empty.clone());
    vm.register_builtin(7, builtin_touched);
    vm.request_halt();
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "pre-run halt on empty chunk MUST return Halted, got {:?}",
            other
        ),
    }
    vm.reset(run);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_none_host_reset_then_status_host_on_same_chunk_type() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(NoneHost));
    vm.last_status = 8;
    match vm.run() {
        VMResult::Ok(Value::Status(8)) => {}
        other => panic!("NoneHost MUST preserve last_status(8), got {:?}", other),
    }
    vm.reset(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(77)));
    match vm.run() {
        VMResult::Ok(Value::Status(77)) => {}
        other => panic!("StatusReturningHost MUST apply Some(77), got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_call_with_one_arg_in_caller() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("noop");
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Call(name, 1), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_between_two_setstatus_second_end_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 30 }));
    match vm.run() {
        VMResult::Ok(Value::Status(31)) => {}
        other => panic!(
            "second end Some(31) MUST beat SetStatus(20), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_subshell_begin_count_one_when_halt_after_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(78)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_triple_getstatus_after_single_end_all_read_same() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(79)));
    match vm.run() {
        VMResult::Ok(Value::Status(79)) => {}
        other => panic!(
            "top GetStatus(79) MUST win over deeper copies, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_eleven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..11 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_156_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(156)));
    match vm.run() {
        VMResult::Ok(Value::Status(156)) => {}
        other => panic!("exit code 156 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twelve_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..12 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_157_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(157)));
    match vm.run() {
        VMResult::Ok(Value::Status(157)) => {}
        other => panic!("exit code 157 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_preserves_deeper_loadint_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(100), 1);
    b.emit(Op::LoadInt(200), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(80)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return builtin on top, got {:?}", other),
    }
    assert_eq!(vm.last_status, 80);
}

#[test]
fn subshell_end_exit_code_158_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(158)));
    match vm.run() {
        VMResult::Ok(Value::Status(158)) => {}
        other => panic!("exit code 158 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_full_lifecycle_host_swap_reset_getstatus() {
    let c1 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let c2 = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(c1);
    vm.set_shell_host(Box::new(StatusReturningHost(81)));
    let _ = vm.run();
    vm.set_shell_host(Box::new(DefaultHost));
    vm.reset(c2);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "DefaultHost after reset MUST leave last_status(0), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_after_halt_reset_on_same_vm_reads_new_host_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let run = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(run);
    vm.set_shell_host(Box::new(StatusReturningHost(82)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.set_shell_host(Box::new(StatusReturningHost(83)));
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(83)) => {}
        other => panic!(
            "swapped host MUST apply Some(83) after reset, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_subshell_end_and_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_loadint_getstatus_subshell_end_final_getstatus_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(44), 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(StatusReturningHost(84)));
    match vm.run() {
        VMResult::Ok(Value::Status(84)) => {}
        other => panic!("final GetStatus(84) MUST be stack top, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_end_after_first_updates_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(85)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 85);
}

#[test]
fn subshell_end_exit_code_159_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(159)));
    match vm.run() {
        VMResult::Ok(Value::Status(159)) => {}
        other => panic!("exit code 159 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_triple_halt_from_builtin_still_single_clean_stop() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(50, 0), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(50, builtin_triple_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_160_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(160)));
    match vm.run() {
        VMResult::Ok(Value::Status(160)) => {}
        other => panic!("exit code 160 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_clears_halt_subshell_end_then_getstatus_on_fresh_chunk() {
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(StatusReturningHost(86)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(86)) => {}
        other => panic!("subshell+GetStatus MUST work after reset, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_on_second_end_preserves_first() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 87,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(87)) => {}
        other => panic!(
            "FirstSomeThenNoneHost MUST preserve Some(87), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_after_getstatus_does_not_pop_status_before_halt_builtin() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(88), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "run MUST return halt builtin, not Status(88), got {:?}",
            other
        ),
    }
}

// ─── Pin tests batch E (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_51_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(51)));
    match vm.run() {
        VMResult::Ok(Value::Status(51)) => {}
        other => panic!("exit code 51 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_on_string_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("foo"));
    let bidx = b.add_constant(Value::str("bar"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Concat, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_52_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(52)));
    match vm.run() {
        VMResult::Ok(Value::Status(52)) => {}
        other => panic!("exit code 52 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_len() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let s = b.add_constant(Value::str("hello"));
    b.emit(Op::LoadConst(s), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StringLen, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_53_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(53)));
    match vm.run() {
        VMResult::Ok(Value::Status(53)) => {}
        other => panic!("exit code 53 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_repeat() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let s = b.add_constant(Value::str("x"));
    b.emit(Op::LoadConst(s), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StringRepeat, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_54_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(54)));
    match vm.run() {
        VMResult::Ok(Value::Status(54)) => {}
        other => panic!("exit code 54 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..13 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_55_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(55)));
    match vm.run() {
        VMResult::Ok(Value::Status(55)) => {}
        other => panic!("exit code 55 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fourteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..14 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_56_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(56)));
    match vm.run() {
        VMResult::Ok(Value::Status(56)) => {}
        other => panic!("exit code 56 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ne_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("a"));
    let bidx = b.add_constant(Value::str("b"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrNe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_57_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(57)));
    match vm.run() {
        VMResult::Ok(Value::Status(57)) => {}
        other => panic!("exit code 57 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_pipeline_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    struct SubshellBeginHost88;
    impl ShellHost for SubshellBeginHost88 {
        fn pipeline_begin(&mut self, _n: u8) {
            PIPELINE_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(88)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellBeginHost88));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 88);
}

#[test]
fn subshell_end_exit_code_58_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(58)));
    match vm.run() {
        VMResult::Ok(Value::Status(58)) => {}
        other => panic!("exit code 58 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_59_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(59)));
    match vm.run() {
        VMResult::Ok(Value::Status(59)) => {}
        other => panic!("exit code 59 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_then_subshell_begin_end_on_fresh_chunk() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let pair = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellBegin, 1);
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(BeginEndCountingHost(90)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(pair);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 90);
}

#[test]
fn subshell_end_exit_code_60_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(60)));
    match vm.run() {
        VMResult::Ok(Value::Status(60)) => {}
        other => panic!("exit code 60 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_load_const_ops() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let c1 = b.add_constant(Value::Int(1));
    let c2 = b.add_constant(Value::Int(2));
    b.emit(Op::LoadConst(c1), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadConst(c2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_61_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(61)));
    match vm.run() {
        VMResult::Ok(Value::Status(61)) => {}
        other => panic!("exit code 61 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_returnvalue_before_halt_in_caller_stack_top_is_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("rv3");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST be stack top over ReturnValue(3), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_62_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(62)));
    match vm.run() {
        VMResult::Ok(Value::Status(62)) => {}
        other => panic!("exit code 62 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_stage_before_pipeline_end_in_open_pipeline() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_63_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(63)));
    match vm.run() {
        VMResult::Ok(Value::Status(63)) => {}
        other => panic!("exit code 63 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_extended_after_first_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static FIRST: AtomicU32 = AtomicU32::new(0);
    static SECOND: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(10, 0), 1);
    b.emit(Op::Extended(11, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_handler(Box::new(|vm, id, _arg| {
        if id == 10 {
            FIRST.fetch_add(1, Ordering::SeqCst);
            vm.request_halt();
        } else {
            SECOND.fetch_add(1, Ordering::SeqCst);
        }
    }));
    let _ = vm.run();
    assert_eq!(FIRST.load(Ordering::SeqCst), 1);
    assert_eq!(SECOND.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_64_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(64)));
    match vm.run() {
        VMResult::Ok(Value::Status(64)) => {}
        other => panic!("exit code 64 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_halt_reset_halt_reset_then_subshell_runs() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let noop = ChunkBuilder::new().build();
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(noop.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(91)));
    vm.request_halt();
    let _ = vm.run();
    vm.reset(noop.clone());
    vm.request_halt();
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 91);
}

#[test]
fn subshell_end_exit_code_65_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(65)));
    match vm.run() {
        VMResult::Ok(Value::Status(65)) => {}
        other => panic!("exit code 65 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_false_after_load_true() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_twelve_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-12)));
    match vm.run() {
        VMResult::Ok(Value::Status(-12)) => {}
        other => panic!("status -12 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_subshell_end_and_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(92), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(92)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 92);
}

#[test]
fn subshell_end_status_minus_thirteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-13)));
    match vm.run() {
        VMResult::Ok(Value::Status(-13)) => {}
        other => panic!("status -13 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..15 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_thirty_one_end_incrementing_from_twenty_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..31 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 21 }));
    match vm.run() {
        VMResult::Ok(Value::Status(51)) => {}
        other => panic!(
            "thirty-first subshell_end(Some(51)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_num_lt_keep_when_condition_true() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumLt, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_thirty_two_end_incrementing_from_fourteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..32 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 14 }));
    match vm.run() {
        VMResult::Ok(Value::Status(45)) => {}
        other => panic!(
            "thirty-second subshell_end(Some(45)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_num_gt_keep_when_condition_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumGt, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_ninth_some_on_ninth_end_applies_ninety_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..9 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct NinthSomeHost {
        calls: u32,
    }
    impl ShellHost for NinthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 9 {
                Some(93)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 4;
    vm.set_shell_host(Box::new(NinthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(93)) => {}
        other => panic!("ninth subshell_end(Some(93)) MUST apply, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_end_then_setstatus_blocked() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(94), 1);
    b.emit(Op::SetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(94)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 94);
}

#[test]
fn subshell_end_exit_code_66_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(66)));
    match vm.run() {
        VMResult::Ok(Value::Status(66)) => {}
        other => panic!("exit code 66 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_subshell_begins_halt_before_any_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(95)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_67_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(67)));
    match vm.run() {
        VMResult::Ok(Value::Status(67)) => {}
        other => panic!("exit code 67 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_wide_then_narrow_extension_first_halts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static WIDE: AtomicU32 = AtomicU32::new(0);
    static NARROW: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(1, 0), 1);
    b.emit(Op::Extended(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|vm, _id, _payload| {
        WIDE.fetch_add(1, Ordering::SeqCst);
        vm.request_halt();
    }));
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        NARROW.fetch_add(1, Ordering::SeqCst);
    }));
    let _ = vm.run();
    assert_eq!(WIDE.load(Ordering::SeqCst), 1);
    assert_eq!(NARROW.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_68_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(68)));
    match vm.run() {
        VMResult::Ok(Value::Status(68)) => {}
        other => panic!("exit code 68 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(96)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 96);
}

#[test]
fn subshell_end_exit_code_69_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(69)));
    match vm.run() {
        VMResult::Ok(Value::Status(69)) => {}
        other => panic!("exit code 69 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_clears_halt_four_subshell_ends_on_two_resets() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let two_ends = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(CountingSubshellEndHost(97)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(two_ends.clone());
    let _ = vm.run();
    vm.reset(two_ends);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 4);
    assert_eq!(vm.last_status, 97);
}

#[test]
fn subshell_end_exit_code_70_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(70)));
    match vm.run() {
        VMResult::Ok(Value::Status(70)) => {}
        other => panic!("exit code 70 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_after_dup_on_stack() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::Dup, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

// ─── Pin tests batch F (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_161_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(161)));
    match vm.run() {
        VMResult::Ok(Value::Status(161)) => {}
        other => panic!("exit code 161 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..16 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_162_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(162)));
    match vm.run() {
        VMResult::Ok(Value::Status(162)) => {}
        other => panic!("exit code 162 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_keep_when_condition_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::NumLe, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_163_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(163)));
    match vm.run() {
        VMResult::Ok(Value::Status(163)) => {}
        other => panic!("exit code 163 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_keep_when_condition_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::NumGe, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_164_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(164)));
    match vm.run() {
        VMResult::Ok(Value::Status(164)) => {}
        other => panic!("exit code 164 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_subshell_ends_with_loadint_between() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(98), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(98)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 98);
}

#[test]
fn subshell_end_exit_code_165_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(165)));
    match vm.run() {
        VMResult::Ok(Value::Status(165)) => {}
        other => panic!("exit code 165 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventeen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..17 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_fourteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-14)));
    match vm.run() {
        VMResult::Ok(Value::Status(-14)) => {}
        other => panic!("status -14 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_swap_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Swap, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(99)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_fifteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-15)));
    match vm.run() {
        VMResult::Ok(Value::Status(-15)) => {}
        other => panic!("status -15 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_first_getstatus_before_subshell_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(100), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(101)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("SubshellEnd MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 100);
}

#[test]
fn subshell_thirty_three_end_incrementing_from_sixteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..33 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 16 }));
    match vm.run() {
        VMResult::Ok(Value::Status(48)) => {}
        other => panic!(
            "thirty-third subshell_end(Some(48)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_loadint_after_full_subshell_begin_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(102), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(102)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 102);
}

#[test]
fn subshell_thirty_four_end_incrementing_from_nineteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..34 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 19 }));
    match vm.run() {
        VMResult::Ok(Value::Status(52)) => {}
        other => panic!(
            "thirty-fourth subshell_end(Some(52)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_nested_callee_halt_caller_never_reaches_loadint() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("inner_h2");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::LoadInt(777), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "caller LoadInt MUST NOT run after callee halt, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_thirty_five_end_incrementing_from_twenty_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..35 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 23 }));
    match vm.run() {
        VMResult::Ok(Value::Status(57)) => {}
        other => panic!(
            "thirty-fifth subshell_end(Some(57)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_extension_handler_halts_before_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::Extended(20, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(103)));
    vm.set_extension_handler(Box::new(|vm, _id, _arg| {
        vm.request_halt();
    }));
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_166_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(166)));
    match vm.run() {
        VMResult::Ok(Value::Status(166)) => {}
        other => panic!("exit code 166 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_pipeline_stage_in_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    struct StageAfterSubshellHost;
    impl ShellHost for StageAfterSubshellHost {
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(104)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StageAfterSubshellHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 104);
}

#[test]
fn subshell_end_exit_code_167_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(167)));
    match vm.run() {
        VMResult::Ok(Value::Status(167)) => {}
        other => panic!("exit code 167 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_halt_only_on_empty_stack_returns_halted() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(61, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(61, builtin_halt_only);
    match vm.run() {
        VMResult::Ok(Value::Undef) => {}
        other => panic!(
            "halt_only pushes Undef before run() pops stack top, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_168_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(168)));
    match vm.run() {
        VMResult::Ok(Value::Status(168)) => {}
        other => panic!("exit code 168 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_double_subshell_end_then_halt_third_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(105)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
    assert_eq!(vm.last_status, 105);
}

#[test]
fn subshell_end_exit_code_169_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(169)));
    match vm.run() {
        VMResult::Ok(Value::Status(169)) => {}
        other => panic!("exit code 169 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_after_subshell_halt_allows_getstatus_zero() {
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let status = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(sub);
    vm.set_shell_host(Box::new(StatusReturningHost(106)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 106);
    vm.reset(status);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!("reset MUST clear last_status, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_170_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(170)));
    match vm.run() {
        VMResult::Ok(Value::Status(170)) => {}
        other => panic!("exit code 170 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..18 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_tenth_some_on_tenth_end_applies_one_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..10 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TenthSomeHost {
        calls: u32,
    }
    impl ShellHost for TenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 10 {
                Some(107)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(TenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(107)) => {}
        other => panic!("tenth subshell_end(Some(107)) MUST apply, got {:?}", other),
    }
}

#[test]
fn request_halt_between_pipeline_begin_and_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(108)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_setstatus_after_end_before_getstatus_reads_setstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(109), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(50)));
    match vm.run() {
        VMResult::Ok(Value::Status(109)) => {}
        other => panic!(
            "SetStatus(109) MUST beat subshell Some(50), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(110)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_two_pipeline_ends_subshell_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!("GetStatus MUST read subshell(9), got {:?}", other),
    }
}

#[test]
fn request_halt_callee_with_one_arg_before_halt_in_caller() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let mut b = ChunkBuilder::new();
    let name = b.add_name("take1");
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::Call(name, 1), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST be stack top after callee, got {:?}", other),
    }
}

#[test]
fn subshell_begin_end_reset_begin_end_same_host_twice() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellBegin, 1);
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(BeginEndCountingHost(111)));
    let _ = vm.run();
    vm.reset(chunk.clone());
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 2);
    assert_eq!(vm.last_status, 111);
}

#[test]
fn request_halt_stops_before_add_after_subshell_wrote_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Add, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(112)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_loadint_subshell_end_getstatus_order_final_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(55), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(113)));
    match vm.run() {
        VMResult::Ok(Value::Status(113)) => {}
        other => panic!("GetStatus(113) MUST be stack top, got {:?}", other),
    }
}

#[test]
fn request_halt_nineteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..19 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_alternating_host_fifth_end_none_keeps_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost fifth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_twenty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..20 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_none_then_some_on_orphan_ends_only() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 6;
    vm.set_shell_host(Box::new(NoneThenSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!("NoneThenSomeHost MUST apply Some(42), got {:?}", other),
    }
}

#[test]
fn request_halt_full_reset_lifecycle_halt_subshell_halt_getstatus() {
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let status = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(114)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 114);
    vm.reset(sub);
    let _ = vm.run();
    vm.reset(status);
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!("final GetStatus MUST read 0 after reset, got {:?}", other),
    }
}

#[test]
fn subshell_custom_pipeline_positive_after_subshell_on_stack() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CustomPipelineHost(115)));
    match vm.run() {
        VMResult::Ok(Value::Status(115)) => {}
        other => panic!("PipelineEnd MUST push host 115, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_getstatus_after_subshell_end() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(116)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("second GetStatus MUST NOT run, got {:?}", other),
    }
    assert_eq!(vm.last_status, 116);
}

#[test]
fn subshell_end_exit_code_171_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(171)));
    match vm.run() {
        VMResult::Ok(Value::Status(171)) => {}
        other => panic!("exit code 171 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_preserves_shell_host_after_reset_on_halt_chunk() {
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(halt);
    vm.set_shell_host(Box::new(StatusReturningHost(117)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(117)) => {}
        other => panic!("preserved host MUST apply Some(117), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_172_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(172)));
    match vm.run() {
        VMResult::Ok(Value::Status(172)) => {}
        other => panic!("exit code 172 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_frame_after_three_push_frames() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_triple_begin_single_end_applies_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(118)));
    match vm.run() {
        VMResult::Ok(Value::Status(118)) => {}
        other => panic!("SubshellEnd MUST apply Some(118), got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 3);
}

#[test]
fn request_halt_after_subshell_end_extension_handler_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_RAN: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Extended(30, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(119)));
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        EXT_RAN.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(EXT_RAN.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 119);
}

#[test]
fn subshell_end_exit_code_173_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(173)));
    match vm.run() {
        VMResult::Ok(Value::Status(173)) => {}
        other => panic!("exit code 173 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_and_halt_same_chunk_last_status_from_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(120)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 120);
}
// ─── Pin tests batch G (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_174_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(174)));
    match vm.run() {
        VMResult::Ok(Value::Status(174)) => {}
        other => panic!("exit code 174 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_lt_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("a"));
    let bidx = b.add_constant(Value::str("z"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrLt, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_175_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(175)));
    match vm.run() {
        VMResult::Ok(Value::Status(175)) => {}
        other => panic!("exit code 175 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_gt_jump_if_true_keep_when_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("a"));
    let bidx = b.add_constant(Value::str("z"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrGt, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_176_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(176)));
    match vm.run() {
        VMResult::Ok(Value::Status(176)) => {}
        other => panic!("exit code 176 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_le_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("mid"));
    let bidx = b.add_constant(Value::str("mid"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrLe, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_177_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(177)));
    match vm.run() {
        VMResult::Ok(Value::Status(177)) => {}
        other => panic!("exit code 177 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ge_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("z"));
    let bidx = b.add_constant(Value::str("a"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrGe, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_178_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(178)));
    match vm.run() {
        VMResult::Ok(Value::Status(178)) => {}
        other => panic!("exit code 178 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ne_jump_if_false_keep_when_true() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::NumNe, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_179_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(179)));
    match vm.run() {
        VMResult::Ok(Value::Status(179)) => {}
        other => panic!("exit code 179 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..21 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_180_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(180)));
    match vm.run() {
        VMResult::Ok(Value::Status(180)) => {}
        other => panic!("exit code 180 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..22 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_181_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(181)));
    match vm.run() {
        VMResult::Ok(Value::Status(181)) => {}
        other => panic!("exit code 181 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..23 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_182_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(182)));
    match vm.run() {
        VMResult::Ok(Value::Status(182)) => {}
        other => panic!("exit code 182 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..24 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_183_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(183)));
    match vm.run() {
        VMResult::Ok(Value::Status(183)) => {}
        other => panic!("exit code 183 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..25 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_184_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(184)));
    match vm.run() {
        VMResult::Ok(Value::Status(184)) => {}
        other => panic!("exit code 184 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_six_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..36 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(39)) => {}
        other => panic!(
            "thirty-sixth subshell_end(Some(39)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_185_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(185)));
    match vm.run() {
        VMResult::Ok(Value::Status(185)) => {}
        other => panic!("exit code 185 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_seven_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..37 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(45)) => {}
        other => panic!(
            "thirty-seventh subshell_end(Some(45)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_186_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(186)));
    match vm.run() {
        VMResult::Ok(Value::Status(186)) => {}
        other => panic!("exit code 186 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_eight_end_incrementing_from_twelve() {
    let mut b = ChunkBuilder::new();
    for _ in 0..38 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(49)) => {}
        other => panic!(
            "thirty-eighth subshell_end(Some(49)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_187_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(187)));
    match vm.run() {
        VMResult::Ok(Value::Status(187)) => {}
        other => panic!("exit code 187 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_nine_end_incrementing_from_fifteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..39 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 15 }));
    match vm.run() {
        VMResult::Ok(Value::Status(53)) => {}
        other => panic!(
            "thirty-ninth subshell_end(Some(53)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_188_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(188)));
    match vm.run() {
        VMResult::Ok(Value::Status(188)) => {}
        other => panic!("exit code 188 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..40 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(40)) => {}
        other => panic!("fortieth subshell_end(Some(40)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_189_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(189)));
    match vm.run() {
        VMResult::Ok(Value::Status(189)) => {}
        other => panic!("exit code 189 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-16)));
    match vm.run() {
        VMResult::Ok(Value::Status(-16)) => {}
        other => panic!("status -16 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_190_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(190)));
    match vm.run() {
        VMResult::Ok(Value::Status(190)) => {}
        other => panic!("exit code 190 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventeen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-17)));
    match vm.run() {
        VMResult::Ok(Value::Status(-17)) => {}
        other => panic!("status -17 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_191_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(191)));
    match vm.run() {
        VMResult::Ok(Value::Status(191)) => {}
        other => panic!("exit code 191 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-18)));
    match vm.run() {
        VMResult::Ok(Value::Status(-18)) => {}
        other => panic!("status -18 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_192_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(192)));
    match vm.run() {
        VMResult::Ok(Value::Status(192)) => {}
        other => panic!("exit code 192 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_nineteen_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-19)));
    match vm.run() {
        VMResult::Ok(Value::Status(-19)) => {}
        other => panic!("status -19 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_193_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(193)));
    match vm.run() {
        VMResult::Ok(Value::Status(193)) => {}
        other => panic!("exit code 193 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-20)));
    match vm.run() {
        VMResult::Ok(Value::Status(-20)) => {}
        other => panic!("status -20 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_194_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(194)));
    match vm.run() {
        VMResult::Ok(Value::Status(194)) => {}
        other => panic!("exit code 194 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eleventh_some_host_applies_on_eleventh_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..11 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct EleventhSomeHost {
        calls: u32,
    }
    impl ShellHost for EleventhSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 11 {
                Some(121)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(EleventhSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(121)) => {}
        other => panic!(
            "eleventh subshell_end(Some(121)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_195_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(195)));
    match vm.run() {
        VMResult::Ok(Value::Status(195)) => {}
        other => panic!("exit code 195 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_wrote_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.71), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(196)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 196);
}

#[test]
fn subshell_end_exit_code_196_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(196)));
    match vm.run() {
        VMResult::Ok(Value::Status(196)) => {}
        other => panic!("exit code 196 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_str_eq_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    let a = b.add_constant(Value::str("x"));
    let bidx = b.add_constant(Value::str("x"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrEq, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(197)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 197);
}

#[test]
fn subshell_end_exit_code_197_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(197)));
    match vm.run() {
        VMResult::Ok(Value::Status(197)) => {}
        other => panic!("exit code 197 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_halt_reset_subshell_end_fourth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(198)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 4);
    assert_eq!(vm.last_status, 198);
}

#[test]
fn subshell_end_exit_code_198_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(198)));
    match vm.run() {
        VMResult::Ok(Value::Status(198)) => {}
        other => panic!("exit code 198 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_subshell_end_and_second_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(BeginEndCountingHost(199)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 199);
}
// ─── Pin tests batch H (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_199_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(199)));
    match vm.run() {
        VMResult::Ok(Value::Status(199)) => {}
        other => panic!("exit code 199 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_backward_jump_if_false_keep() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::NumEq, 1);
    let back = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(back, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_200_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(200)));
    match vm.run() {
        VMResult::Ok(Value::Status(200)) => {}
        other => panic!("exit code 200 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixth_some_host_applies_on_sixth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..6 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct SixthSomeHost {
        calls: u32,
    }
    impl ShellHost for SixthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 6 {
                Some(201)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(SixthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(201)) => {}
        other => panic!("sixth subshell_end(Some(201)) MUST apply, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_201_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(201)));
    match vm.run() {
        VMResult::Ok(Value::Status(201)) => {}
        other => panic!("exit code 201 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_pipeline_begin_before_subshell_end_host() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    struct PipelineBeginSubshellEndHost202;
    impl ShellHost for PipelineBeginSubshellEndHost202 {
        fn pipeline_begin(&mut self, _n: u8) {
            PIPELINE_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(202)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineBeginSubshellEndHost202));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_exit_code_202_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(202)));
    match vm.run() {
        VMResult::Ok(Value::Status(202)) => {}
        other => panic!("exit code 202 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_setstatus_before_end_some_host_overwrites_setstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(203), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(203)));
    match vm.run() {
        VMResult::Ok(Value::Status(203)) => {}
        other => panic!(
            "subshell Some(203) MUST beat SetStatus(203), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_203_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(203)));
    match vm.run() {
        VMResult::Ok(Value::Status(203)) => {}
        other => panic!("exit code 203 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_four_begins_three_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost204;
    impl ShellHost for CountingBeginEndHost204 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(204)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost204));
    match vm.run() {
        VMResult::Ok(Value::Status(204)) => {}
        other => panic!("third subshell_end(Some(204)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 4);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 3);
}

#[test]
fn subshell_end_exit_code_204_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(204)));
    match vm.run() {
        VMResult::Ok(Value::Status(204)) => {}
        other => panic!("exit code 204 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_then_subshell_chunk_after_reset_runs_host() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let empty = ChunkBuilder::new().build();
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(empty);
    vm.set_shell_host(Box::new(CountingSubshellEndHost(205)));
    vm.request_halt();
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 205);
}

#[test]
fn subshell_end_exit_code_205_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(205)));
    match vm.run() {
        VMResult::Ok(Value::Status(205)) => {}
        other => panic!("exit code 205 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_sixth_none_keeps_fifth_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..6 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost sixth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_206_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(206)));
    match vm.run() {
        VMResult::Ok(Value::Status(206)) => {}
        other => panic!("exit code 206 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_after_two_push_frames() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PushFrame, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_207_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(207)));
    match vm.run() {
        VMResult::Ok(Value::Status(207)) => {}
        other => panic!("exit code 207 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_counting_end_host_two_ends_same_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(208)));
    match vm.run() {
        VMResult::Ok(Value::Status(208)) => {}
        other => panic!(
            "second subshell_end MUST still apply Some(208), got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn subshell_end_exit_code_208_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(208)));
    match vm.run() {
        VMResult::Ok(Value::Status(208)) => {}
        other => panic!("exit code 208 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_extension_no_handler_after_subshell_end_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_TOUCHED: AtomicU32 = AtomicU32::new(0);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Extended(44, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(209)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(EXT_TOUCHED.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 209);
}

#[test]
fn subshell_end_exit_code_209_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(209)));
    match vm.run() {
        VMResult::Ok(Value::Status(209)) => {}
        other => panic!("exit code 209 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_setstatus_zero_before_end_some_overwrites_zero() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(0), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(210)));
    match vm.run() {
        VMResult::Ok(Value::Status(210)) => {}
        other => panic!(
            "subshell Some(210) MUST overwrite SetStatus(0), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_210_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(210)));
    match vm.run() {
        VMResult::Ok(Value::Status(210)) => {}
        other => panic!("exit code 210 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_two_args_return_before_caller_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("pair");
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::Call(name, 2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST be stack top after callee return, got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_211_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(211)));
    match vm.run() {
        VMResult::Ok(Value::Status(211)) => {}
        other => panic!("exit code 211 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_replace_host_between_runs_second_host_wins() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(212)));
    let _ = vm.run();
    vm.reset(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(213)));
    match vm.run() {
        VMResult::Ok(Value::Status(213)) => {}
        other => panic!("replaced host MUST apply Some(213), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_212_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(212)));
    match vm.run() {
        VMResult::Ok(Value::Status(212)) => {}
        other => panic!("exit code 212 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_after_getstatus_read() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(214), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(999), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("halt MUST return before LoadInt(999), got {:?}", other),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_213_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(213)));
    match vm.run() {
        VMResult::Ok(Value::Status(213)) => {}
        other => panic!("exit code 213 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_end_subshell_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!("GetStatus MUST read subshell Some(9), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_214_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(214)));
    match vm.run() {
        VMResult::Ok(Value::Status(214)) => {}
        other => panic!("exit code 214 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_extension_wide_handlers_second_not_reached() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static WIDE_A: AtomicU32 = AtomicU32::new(0);
    static WIDE_B: AtomicU32 = AtomicU32::new(0);
    WIDE_A.store(0, Ordering::SeqCst);
    WIDE_B.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::ExtendedWide(1, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ExtendedWide(2, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_extension_wide_handler(Box::new(|_vm, id, _payload| {
        if id == 1 {
            WIDE_A.fetch_add(1, Ordering::SeqCst);
        } else if id == 2 {
            WIDE_B.fetch_add(1, Ordering::SeqCst);
        }
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(WIDE_A.load(Ordering::SeqCst), 1);
    assert_eq!(WIDE_B.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_215_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(215)));
    match vm.run() {
        VMResult::Ok(Value::Status(215)) => {}
        other => panic!("exit code 215 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_double_getstatus_after_end_same_value() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(216)));
    match vm.run() {
        VMResult::Ok(Value::Status(216)) => {}
        other => panic!(
            "second GetStatus MUST still read Status(216), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_216_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(216)));
    match vm.run() {
        VMResult::Ok(Value::Status(216)) => {}
        other => panic!("exit code 216 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_eq_jump_if_true_when_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_217_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(217)));
    match vm.run() {
        VMResult::Ok(Value::Status(217)) => {}
        other => panic!("exit code 217 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_orphan_after_none_host_leaves_prior_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 218;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(218)) => {}
        other => panic!(
            "NoneHost orphan end MUST preserve last_status 218, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_218_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(218)));
    match vm.run() {
        VMResult::Ok(Value::Status(218)) => {}
        other => panic!("exit code 218 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_reset_twice_then_subshell_end_runs_host() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(halt.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(219)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(halt.clone());
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 219);
}

#[test]
fn subshell_end_exit_code_219_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(219)));
    match vm.run() {
        VMResult::Ok(Value::Status(219)) => {}
        other => panic!("exit code 219 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_begin_counting_host_without_matching_end_leaves_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 220;
    vm.set_shell_host(Box::new(BeginEndCountingHost(220)));
    match vm.run() {
        VMResult::Ok(Value::Status(220)) => {}
        other => panic!(
            "SubshellBegin alone MUST NOT change last_status, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn subshell_end_exit_code_220_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(220)));
    match vm.run() {
        VMResult::Ok(Value::Status(220)) => {}
        other => panic!("exit code 220 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_first_of_three_callbuiltins_blocks_rest() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(7, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(7, builtin_touched);
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 1);
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_221_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(221)));
    match vm.run() {
        VMResult::Ok(Value::Status(221)) => {}
        other => panic!("exit code 221 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_same_vm_second_subshell_end_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(222)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 222);
}

#[test]
fn subshell_end_exit_code_222_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(222)));
    match vm.run() {
        VMResult::Ok(Value::Status(222)) => {}
        other => panic!("exit code 222 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..26 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_223_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(223)));
    match vm.run() {
        VMResult::Ok(Value::Status(223)) => {}
        other => panic!("exit code 223 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_one_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..41 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(42)) => {}
        other => panic!(
            "forty-first subshell_end(Some(42)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_str_ne_jump_if_true_keep_when_false() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("same"));
    let bidx = b.add_constant(Value::str("same"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::StrNe, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_twenty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-21)));
    match vm.run() {
        VMResult::Ok(Value::Status(-21)) => {}
        other => panic!("status -21 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_twelfth_some_host_applies_on_twelfth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..12 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwelfthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwelfthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 12 {
                Some(224)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(TwelfthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(224)) => {}
        other => panic!(
            "twelfth subshell_end(Some(224)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_between_subshell_end_and_getstatus_preserves_last_status() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(225)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(vm.last_status, 225);
}
// ─── Pin tests batch I (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_224_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(224)));
    match vm.run() {
        VMResult::Ok(Value::Status(224)) => {}
        other => panic!("exit code 224 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..27 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_225_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(225)));
    match vm.run() {
        VMResult::Ok(Value::Status(225)) => {}
        other => panic!("exit code 225 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_lt_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("alpha"));
    let bidx = b.add_constant(Value::str("omega"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrLt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_226_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(226)));
    match vm.run() {
        VMResult::Ok(Value::Status(226)) => {}
        other => panic!("exit code 226 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..28 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_227_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(227)));
    match vm.run() {
        VMResult::Ok(Value::Status(227)) => {}
        other => panic!("exit code 227 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_hash_after_halt_point() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let k = b.add_constant(Value::str("k"));
    let v = b.add_constant(Value::str("v"));
    b.emit(Op::LoadConst(k), 1);
    b.emit(Op::LoadConst(v), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeHash(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_228_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(228)));
    match vm.run() {
        VMResult::Ok(Value::Status(228)) => {}
        other => panic!("exit code 228 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_twenty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..29 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_229_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(229)));
    match vm.run() {
        VMResult::Ok(Value::Status(229)) => {}
        other => panic!("exit code 229 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_status230_blocks_following_pipeline_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    struct SubshellThenPipelineEndHost230;
    impl ShellHost for SubshellThenPipelineEndHost230 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(230)
        }
        fn pipeline_end(&mut self) -> i32 {
            PIPELINE_END_CALLS.fetch_add(1, Ordering::SeqCst);
            0
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineEndHost230));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 230);
}

#[test]
fn subshell_end_exit_code_230_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(230)));
    match vm.run() {
        VMResult::Ok(Value::Status(230)) => {}
        other => panic!("exit code 230 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..30 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_231_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(231)));
    match vm.run() {
        VMResult::Ok(Value::Status(231)) => {}
        other => panic!("exit code 231 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_two_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..42 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(44)) => {}
        other => panic!(
            "forty-second subshell_end(Some(44)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_232_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(232)));
    match vm.run() {
        VMResult::Ok(Value::Status(232)) => {}
        other => panic!("exit code 232 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..31 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_233_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(233)));
    match vm.run() {
        VMResult::Ok(Value::Status(233)) => {}
        other => panic!("exit code 233 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-22)));
    match vm.run() {
        VMResult::Ok(Value::Status(-22)) => {}
        other => panic!("status -22 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_234_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(234)));
    match vm.run() {
        VMResult::Ok(Value::Status(234)) => {}
        other => panic!("exit code 234 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_three_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..43 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(47)) => {}
        other => panic!(
            "forty-third subshell_end(Some(47)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_235_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(235)));
    match vm.run() {
        VMResult::Ok(Value::Status(235)) => {}
        other => panic!("exit code 235 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-23)));
    match vm.run() {
        VMResult::Ok(Value::Status(-23)) => {}
        other => panic!("status -23 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_236_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(236)));
    match vm.run() {
        VMResult::Ok(Value::Status(236)) => {}
        other => panic!("exit code 236 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirteenth_some_host_applies_on_thirteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..13 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 13 {
                Some(237)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 4;
    vm.set_shell_host(Box::new(ThirteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(237)) => {}
        other => panic!(
            "thirteenth subshell_end(Some(237)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_237_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(237)));
    match vm.run() {
        VMResult::Ok(Value::Status(237)) => {}
        other => panic!("exit code 237 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-24)));
    match vm.run() {
        VMResult::Ok(Value::Status(-24)) => {}
        other => panic!("status -24 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_238_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(238)));
    match vm.run() {
        VMResult::Ok(Value::Status(238)) => {}
        other => panic!("exit code 238 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ge_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("zeta"));
    let bidx = b.add_constant(Value::str("alpha"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_239_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(239)));
    match vm.run() {
        VMResult::Ok(Value::Status(239)) => {}
        other => panic!("exit code 239 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-25)));
    match vm.run() {
        VMResult::Ok(Value::Status(-25)) => {}
        other => panic!("status -25 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_240_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(240)));
    match vm.run() {
        VMResult::Ok(Value::Status(240)) => {}
        other => panic!("exit code 240 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_four_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..44 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(51)) => {}
        other => panic!(
            "forty-fourth subshell_end(Some(51)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_241_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(241)));
    match vm.run() {
        VMResult::Ok(Value::Status(241)) => {}
        other => panic!("exit code 241 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-26)));
    match vm.run() {
        VMResult::Ok(Value::Status(-26)) => {}
        other => panic!("status -26 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_242_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(242)));
    match vm.run() {
        VMResult::Ok(Value::Status(242)) => {}
        other => panic!("exit code 242 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_halt_reset_subshell_end_fifth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(243)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 5);
    assert_eq!(vm.last_status, 243);
}

#[test]
fn subshell_end_exit_code_243_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(243)));
    match vm.run() {
        VMResult::Ok(Value::Status(243)) => {}
        other => panic!("exit code 243 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_five_end_incrementing_from_eleven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..45 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(55)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(55)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_244_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(244)));
    match vm.run() {
        VMResult::Ok(Value::Status(244)) => {}
        other => panic!("exit code 244 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_triple_reset_same_host_same_status_each_run() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(245)));
    for _ in 0..3 {
        match vm.run() {
            VMResult::Ok(Value::Status(245)) => {}
            other => panic!("each reset run MUST return Status(245), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_245_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(245)));
    match vm.run() {
        VMResult::Ok(Value::Status(245)) => {}
        other => panic!("exit code 245 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_pipeline_stage_and_pipeline_end_after_subshell() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_STAGE_CALLS.store(0, Ordering::SeqCst);
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    struct SubshellStagePipelineHost246;
    impl ShellHost for SubshellStagePipelineHost246 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(246)
        }
        fn pipeline_stage(&mut self) {
            PIPELINE_STAGE_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn pipeline_end(&mut self) -> i32 {
            PIPELINE_END_CALLS.fetch_add(1, Ordering::SeqCst);
            0
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellStagePipelineHost246));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_STAGE_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 246);
}

#[test]
fn subshell_end_exit_code_246_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(246)));
    match vm.run() {
        VMResult::Ok(Value::Status(246)) => {}
        other => panic!("exit code 246 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_four_end_alternating_host_last_some_wins() {
    let mut b = ChunkBuilder::new();
    for _ in 0..4 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "fourth AlternatingStatusHost end MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_247_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(247)));
    match vm.run() {
        VMResult::Ok(Value::Status(247)) => {}
        other => panic!("exit code 247 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_load_true() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(248)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 248);
}

#[test]
fn subshell_end_exit_code_248_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(248)));
    match vm.run() {
        VMResult::Ok(Value::Status(248)) => {}
        other => panic!("exit code 248 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_undef_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadUndef, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(249)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 249);
}
// ─── Pin tests batch J (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_249_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(249)));
    match vm.run() {
        VMResult::Ok(Value::Status(249)) => {}
        other => panic!("exit code 249 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..32 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_250_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(250)));
    match vm.run() {
        VMResult::Ok(Value::Status(250)) => {}
        other => panic!("exit code 250 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..33 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_251_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(251)));
    match vm.run() {
        VMResult::Ok(Value::Status(251)) => {}
        other => panic!("exit code 251 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..34 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_252_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(252)));
    match vm.run() {
        VMResult::Ok(Value::Status(252)) => {}
        other => panic!("exit code 252 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..35 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_253_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(253)));
    match vm.run() {
        VMResult::Ok(Value::Status(253)) => {}
        other => panic!("exit code 253 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_six_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..46 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(47)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(47)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_254_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(254)));
    match vm.run() {
        VMResult::Ok(Value::Status(254)) => {}
        other => panic!("exit code 254 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-27)));
    match vm.run() {
        VMResult::Ok(Value::Status(-27)) => {}
        other => panic!("status -27 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_256_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(256)));
    match vm.run() {
        VMResult::Ok(Value::Status(256)) => {}
        other => panic!("exit code 256 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seven_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..47 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(52)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(52)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_257_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(257)));
    match vm.run() {
        VMResult::Ok(Value::Status(257)) => {}
        other => panic!("exit code 257 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-28)));
    match vm.run() {
        VMResult::Ok(Value::Status(-28)) => {}
        other => panic!("status -28 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_258_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(258)));
    match vm.run() {
        VMResult::Ok(Value::Status(258)) => {}
        other => panic!("exit code 258 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fourteenth_some_host_applies_on_fourteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..14 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FourteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for FourteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 14 {
                Some(259)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 6;
    vm.set_shell_host(Box::new(FourteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(259)) => {}
        other => panic!(
            "fourteenth subshell_end(Some(259)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_259_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(259)));
    match vm.run() {
        VMResult::Ok(Value::Status(259)) => {}
        other => panic!("exit code 259 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_twenty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-29)));
    match vm.run() {
        VMResult::Ok(Value::Status(-29)) => {}
        other => panic!("status -29 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_260_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(260)));
    match vm.run() {
        VMResult::Ok(Value::Status(260)) => {}
        other => panic!("exit code 260 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eight_end_incrementing_from_ten() {
    let mut b = ChunkBuilder::new();
    for _ in 0..48 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(57)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(57)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_261_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(261)));
    match vm.run() {
        VMResult::Ok(Value::Status(261)) => {}
        other => panic!("exit code 261 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-30)));
    match vm.run() {
        VMResult::Ok(Value::Status(-30)) => {}
        other => panic!("status -30 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_262_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(262)));
    match vm.run() {
        VMResult::Ok(Value::Status(262)) => {}
        other => panic!("exit code 262 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_zero_args_return_before_caller_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("noop");
    b.emit(Op::Call(name, 0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST be stack top after zero-arg callee, got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_263_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(263)));
    match vm.run() {
        VMResult::Ok(Value::Status(263)) => {}
        other => panic!("exit code 263 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_first_getstatus_blocks_second_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(264)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("second GetStatus MUST NOT run after halt, got {:?}", other),
    }
    assert_eq!(vm.last_status, 264);
}

#[test]
fn subshell_end_exit_code_264_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(264)));
    match vm.run() {
        VMResult::Ok(Value::Status(264)) => {}
        other => panic!("exit code 264 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pow_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pow, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(264)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 264);
}

#[test]
fn subshell_end_exit_code_265_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(265)));
    match vm.run() {
        VMResult::Ok(Value::Status(265)) => {}
        other => panic!("exit code 265 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_subshell_ends_second_host_not_called() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(266)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 266);
}

#[test]
fn subshell_end_exit_code_266_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(266)));
    match vm.run() {
        VMResult::Ok(Value::Status(266)) => {}
        other => panic!("exit code 266 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_le_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("abc"));
    let bidx = b.add_constant(Value::str("abd"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_267_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(267)));
    match vm.run() {
        VMResult::Ok(Value::Status(267)) => {}
        other => panic!("exit code 267 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_end_before_narrow_extension() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    static EXT_RAN: AtomicU32 = AtomicU32::new(0);
    EXT_RAN.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Extended(55, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(268)));
    vm.set_extension_handler(Box::new(|_vm, _id, _arg| {
        EXT_RAN.fetch_add(1, Ordering::SeqCst);
    }));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(EXT_RAN.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 268);
}

#[test]
fn subshell_end_exit_code_268_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(268)));
    match vm.run() {
        VMResult::Ok(Value::Status(268)) => {}
        other => panic!("exit code 268 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_after_setstatus_before_getstatus_reads_setstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::LoadInt(269), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(269)) => {}
        other => panic!(
            "NoneHost after SubshellBegin MUST preserve SetStatus(269), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_269_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(269)));
    match vm.run() {
        VMResult::Ok(Value::Status(269)) => {}
        other => panic!("exit code 269 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_subshell_status270_blocks_following_pipeline_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_BEGIN_CALLS.store(0, Ordering::SeqCst);
    struct SubshellPipelineBeginHost270;
    impl ShellHost for SubshellPipelineBeginHost270 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(270)
        }
        fn pipeline_begin(&mut self, _n: u8) {
            PIPELINE_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellPipelineBeginHost270));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 270);
}

#[test]
fn subshell_end_exit_code_270_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(270)));
    match vm.run() {
        VMResult::Ok(Value::Status(270)) => {}
        other => panic!("exit code 270 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..36 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_271_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(271)));
    match vm.run() {
        VMResult::Ok(Value::Status(271)) => {}
        other => panic!("exit code 271 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_max_then_zero_second_end_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct MaxThenZeroHost {
        calls: u32,
    }
    impl ShellHost for MaxThenZeroHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(i32::MAX)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(MaxThenZeroHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST overwrite MAX, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_272_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(272)));
    match vm.run() {
        VMResult::Ok(Value::Status(272)) => {}
        other => panic!("exit code 272 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_loadints_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(273)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 273);
}

#[test]
fn subshell_end_exit_code_273_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(273)));
    match vm.run() {
        VMResult::Ok(Value::Status(273)) => {}
        other => panic!("exit code 273 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_two_pipeline_ends_blocks_second() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    PIPELINE_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingPipelineHost));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(PIPELINE_END_CALLS.load(Ordering::SeqCst), 1);
}

#[test]
fn subshell_end_exit_code_274_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(274)));
    match vm.run() {
        VMResult::Ok(Value::Status(274)) => {}
        other => panic!("exit code 274 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifteenth_some_host_applies_on_fifteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FifteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for FifteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 15 {
                Some(275)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FifteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(275)) => {}
        other => panic!(
            "fifteenth subshell_end(Some(275)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_stops_before_str_gt_on_consts() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let a = b.add_constant(Value::str("longer"));
    let bidx = b.add_constant(Value::str("short"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrGt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_276_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(276)));
    match vm.run() {
        VMResult::Ok(Value::Status(276)) => {}
        other => panic!("exit code 276 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_nine_end_incrementing_from_thirteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..49 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 13 }));
    match vm.run() {
        VMResult::Ok(Value::Status(61)) => {}
        other => panic!(
            "forty-ninth subshell_end(Some(61)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn request_halt_thirty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..37 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_status_minus_thirty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-31)));
    match vm.run() {
        VMResult::Ok(Value::Status(-31)) => {}
        other => panic!("status -31 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_getstatus_on_fourth_reset_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(halt.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(277)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(halt);
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(277)) => {}
        other => panic!("fourth run MUST return Status(277), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_277_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(277)));
    match vm.run() {
        VMResult::Ok(Value::Status(277)) => {}
        other => panic!("exit code 277 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_false_after_subshell_wrote_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(278)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 278);
}

#[test]
fn subshell_end_exit_code_278_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(278)));
    match vm.run() {
        VMResult::Ok(Value::Status(278)) => {}
        other => panic!("exit code 278 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch K (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_279_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(279)));
    match vm.run() {
        VMResult::Ok(Value::Status(279)) => {}
        other => panic!("exit code 279 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..38 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_280_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(280)));
    match vm.run() {
        VMResult::Ok(Value::Status(280)) => {}
        other => panic!("exit code 280 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_thirty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..39 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_281_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(281)));
    match vm.run() {
        VMResult::Ok(Value::Status(281)) => {}
        other => panic!("exit code 281 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..40 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_282_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(282)));
    match vm.run() {
        VMResult::Ok(Value::Status(282)) => {}
        other => panic!("exit code 282 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..50 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(53)) => {}
        other => panic!("fiftieth subshell_end(Some(53)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_283_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(283)));
    match vm.run() {
        VMResult::Ok(Value::Status(283)) => {}
        other => panic!("exit code 283 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-32)));
    match vm.run() {
        VMResult::Ok(Value::Status(-32)) => {}
        other => panic!("status -32 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_284_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(284)));
    match vm.run() {
        VMResult::Ok(Value::Status(284)) => {}
        other => panic!("exit code 284 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-33)));
    match vm.run() {
        VMResult::Ok(Value::Status(-33)) => {}
        other => panic!("status -33 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_285_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(285)));
    match vm.run() {
        VMResult::Ok(Value::Status(285)) => {}
        other => panic!("exit code 285 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_one_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..51 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(57)) => {}
        other => panic!(
            "fifty-first subshell_end(Some(57)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_286_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(286)));
    match vm.run() {
        VMResult::Ok(Value::Status(286)) => {}
        other => panic!("exit code 286 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-34)));
    match vm.run() {
        VMResult::Ok(Value::Status(-34)) => {}
        other => panic!("status -34 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_287_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(287)));
    match vm.run() {
        VMResult::Ok(Value::Status(287)) => {}
        other => panic!("exit code 287 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-35)));
    match vm.run() {
        VMResult::Ok(Value::Status(-35)) => {}
        other => panic!("status -35 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_288_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(288)));
    match vm.run() {
        VMResult::Ok(Value::Status(288)) => {}
        other => panic!("exit code 288 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-36)));
    match vm.run() {
        VMResult::Ok(Value::Status(-36)) => {}
        other => panic!("status -36 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_289_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(289)));
    match vm.run() {
        VMResult::Ok(Value::Status(289)) => {}
        other => panic!("exit code 289 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixteenth_some_host_applies_on_sixteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct SixteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for SixteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 16 {
                Some(290)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(SixteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(290)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(290)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_290_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(290)));
    match vm.run() {
        VMResult::Ok(Value::Status(290)) => {}
        other => panic!("exit code 290 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_mod_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mod, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(291)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 291);
}

#[test]
fn subshell_end_exit_code_291_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(291)));
    match vm.run() {
        VMResult::Ok(Value::Status(291)) => {}
        other => panic!("exit code 291 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_div_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Div, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(292)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 292);
}

#[test]
fn subshell_end_exit_code_292_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(292)));
    match vm.run() {
        VMResult::Ok(Value::Status(292)) => {}
        other => panic!("exit code 292 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_sixth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(293)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only.clone());
    let _ = vm.run();
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 6);
    assert_eq!(vm.last_status, 293);
}

#[test]
fn subshell_end_exit_code_293_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(293)));
    match vm.run() {
        VMResult::Ok(Value::Status(293)) => {}
        other => panic!("exit code 293 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_wrote_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(294)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 294);
}

#[test]
fn subshell_end_exit_code_294_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(294)));
    match vm.run() {
        VMResult::Ok(Value::Status(294)) => {}
        other => panic!("exit code 294 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_five_begins_two_ends_applies_last_end_status() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellBegin, 1);
    }
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost295;
    impl ShellHost for CountingBeginEndHost295 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(295)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost295));
    match vm.run() {
        VMResult::Ok(Value::Status(295)) => {}
        other => panic!("second subshell_end(Some(295)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 5);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 2);
}

#[test]
fn subshell_end_exit_code_295_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(295)));
    match vm.run() {
        VMResult::Ok(Value::Status(295)) => {}
        other => panic!("exit code 295 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_second_subshell_begin_and_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(296)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 296);
}

#[test]
fn subshell_end_exit_code_296_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(296)));
    match vm.run() {
        VMResult::Ok(Value::Status(296)) => {}
        other => panic!("exit code 296 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_eighth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..8 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost eighth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_297_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(297)));
    match vm.run() {
        VMResult::Ok(Value::Status(297)) => {}
        other => panic!("exit code 297 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_double_reset_then_subshell_end_runs_host298() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let empty = ChunkBuilder::new().build();
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(empty.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(298)));
    vm.request_halt();
    let _ = vm.run();
    vm.reset(empty);
    vm.request_halt();
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 298);
}

#[test]
fn subshell_end_exit_code_298_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(298)));
    match vm.run() {
        VMResult::Ok(Value::Status(298)) => {}
        other => panic!("exit code 298 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup2_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup2, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(299)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 299);
}

#[test]
fn subshell_end_exit_code_299_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(299)));
    match vm.run() {
        VMResult::Ok(Value::Status(299)) => {}
        other => panic!("exit code 299 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_four_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(300)));
    for _ in 0..4 {
        match vm.run() {
            VMResult::Ok(Value::Status(300)) => {}
            other => panic!("reset run MUST return Status(300), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_300_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(300)));
    match vm.run() {
        VMResult::Ok(Value::Status(300)) => {}
        other => panic!("exit code 300 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_spaceship_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Spaceship, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(301)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 301);
}

#[test]
fn subshell_end_exit_code_301_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(301)));
    match vm.run() {
        VMResult::Ok(Value::Status(301)) => {}
        other => panic!("exit code 301 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_stage_subshell_end_getstatus_reads_subshell() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!("GetStatus MUST read subshell Some(9), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_302_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(302)));
    match vm.run() {
        VMResult::Ok(Value::Status(302)) => {}
        other => panic!("exit code 302 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(303)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 303);
}

#[test]
fn subshell_end_exit_code_303_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(303)));
    match vm.run() {
        VMResult::Ok(Value::Status(303)) => {}
        other => panic!("exit code 303 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch L (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_304_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(304)));
    match vm.run() {
        VMResult::Ok(Value::Status(304)) => {}
        other => panic!("exit code 304 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..41 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_305_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(305)));
    match vm.run() {
        VMResult::Ok(Value::Status(305)) => {}
        other => panic!("exit code 305 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..42 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_306_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(306)));
    match vm.run() {
        VMResult::Ok(Value::Status(306)) => {}
        other => panic!("exit code 306 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..43 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_307_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(307)));
    match vm.run() {
        VMResult::Ok(Value::Status(307)) => {}
        other => panic!("exit code 307 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_two_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..52 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(53)) => {}
        other => panic!(
            "fifty-second subshell_end(Some(53)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_308_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(308)));
    match vm.run() {
        VMResult::Ok(Value::Status(308)) => {}
        other => panic!("exit code 308 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-37)));
    match vm.run() {
        VMResult::Ok(Value::Status(-37)) => {}
        other => panic!("status -37 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_309_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(309)));
    match vm.run() {
        VMResult::Ok(Value::Status(309)) => {}
        other => panic!("exit code 309 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_three_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..53 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(61)) => {}
        other => panic!(
            "fifty-third subshell_end(Some(61)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_310_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(310)));
    match vm.run() {
        VMResult::Ok(Value::Status(310)) => {}
        other => panic!("exit code 310 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-38)));
    match vm.run() {
        VMResult::Ok(Value::Status(-38)) => {}
        other => panic!("status -38 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_311_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(311)));
    match vm.run() {
        VMResult::Ok(Value::Status(311)) => {}
        other => panic!("exit code 311 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_thirty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-39)));
    match vm.run() {
        VMResult::Ok(Value::Status(-39)) => {}
        other => panic!("status -39 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_312_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(312)));
    match vm.run() {
        VMResult::Ok(Value::Status(312)) => {}
        other => panic!("exit code 312 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-40)));
    match vm.run() {
        VMResult::Ok(Value::Status(-40)) => {}
        other => panic!("status -40 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_313_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(313)));
    match vm.run() {
        VMResult::Ok(Value::Status(313)) => {}
        other => panic!("exit code 313 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-41)));
    match vm.run() {
        VMResult::Ok(Value::Status(-41)) => {}
        other => panic!("status -41 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_314_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(314)));
    match vm.run() {
        VMResult::Ok(Value::Status(314)) => {}
        other => panic!("exit code 314 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventeenth_some_host_applies_on_seventeenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct SeventeenthSomeHost {
        calls: u32,
    }
    impl ShellHost for SeventeenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 17 {
                Some(315)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(SeventeenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(315)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(315)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_315_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(315)));
    match vm.run() {
        VMResult::Ok(Value::Status(315)) => {}
        other => panic!("exit code 315 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighteenth_some_host_applies_on_eighteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct EighteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for EighteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 18 {
                Some(316)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(EighteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(316)) => {}
        other => panic!(
            "eighteenth subshell_end(Some(316)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_316_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(316)));
    match vm.run() {
        VMResult::Ok(Value::Status(316)) => {}
        other => panic!("exit code 316 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_mul_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mul, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(317)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 317);
}

#[test]
fn subshell_end_exit_code_317_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(317)));
    match vm.run() {
        VMResult::Ok(Value::Status(317)) => {}
        other => panic!("exit code 317 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_after_subshell_getstatus_blocks_second_getstatus() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(318)));
    vm.register_builtin(100, builtin_request_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!("second GetStatus MUST NOT run, got {:?}", other),
    }
    assert_eq!(vm.last_status, 318);
}

#[test]
fn subshell_end_exit_code_318_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(318)));
    match vm.run() {
        VMResult::Ok(Value::Status(318)) => {}
        other => panic!("exit code 318 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_seventh_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(319)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    for _ in 0..4 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 7);
    assert_eq!(vm.last_status, 319);
}

#[test]
fn subshell_end_exit_code_319_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(319)));
    match vm.run() {
        VMResult::Ok(Value::Status(319)) => {}
        other => panic!("exit code 319 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_callee_one_arg_before_caller_halt() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    let name = b.add_name("take1");
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::Call(name, 1), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let skip = b.emit(Op::Jump(0), 1);
    let entry = b.current_pos();
    b.add_sub_entry(name, entry);
    b.emit(Op::ReturnValue, 1);
    b.patch_jump(skip, b.current_pos());
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    match vm.run() {
        VMResult::Ok(Value::Int(0)) => {}
        other => panic!(
            "halt MUST be stack top after one-arg callee, got {:?}",
            other
        ),
    }
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_320_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(320)));
    match vm.run() {
        VMResult::Ok(Value::Status(320)) => {}
        other => panic!("exit code 320 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_none_some_none_some_host_pattern() {
    let mut b = ChunkBuilder::new();
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct NoneNoneSomeNoneSomeHost {
        calls: u32,
    }
    impl ShellHost for NoneNoneSomeNoneSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            match self.calls {
                3 => Some(321),
                5 => Some(322),
                _ => None,
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 10;
    vm.set_shell_host(Box::new(NoneNoneSomeNoneSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(322)) => {}
        other => panic!(
            "fifth end Some(322) MUST beat third Some(321), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_321_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(321)));
    match vm.run() {
        VMResult::Ok(Value::Status(321)) => {}
        other => panic!("exit code 321 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_false_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalse(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(322)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 322);
}

#[test]
fn subshell_end_exit_code_322_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(322)));
    match vm.run() {
        VMResult::Ok(Value::Status(322)) => {}
        other => panic!("exit code 322 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_end_then_pipeline_end_getstatus_reads_pipeline() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineThenSubshellHost));
    match vm.run() {
        VMResult::Ok(Value::Status(3)) => {}
        other => panic!(
            "GetStatus MUST read pipeline_end(3) after subshell Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_323_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(323)));
    match vm.run() {
        VMResult::Ok(Value::Status(323)) => {}
        other => panic!("exit code 323 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..44 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_324_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(324)));
    match vm.run() {
        VMResult::Ok(Value::Status(324)) => {}
        other => panic!("exit code 324 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_min_then_zero_second_end_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct MinThenZeroHost {
        calls: u32,
    }
    impl ShellHost for MinThenZeroHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(i32::MIN)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(MinThenZeroHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST overwrite MIN, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_325_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(325)));
    match vm.run() {
        VMResult::Ok(Value::Status(325)) => {}
        other => panic!("exit code 325 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(326)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 326);
}

#[test]
fn subshell_end_exit_code_326_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(326)));
    match vm.run() {
        VMResult::Ok(Value::Status(326)) => {}
        other => panic!("exit code 326 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_sub_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Sub, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(327)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 327);
}

#[test]
fn subshell_end_exit_code_327_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(327)));
    match vm.run() {
        VMResult::Ok(Value::Status(327)) => {}
        other => panic!("exit code 327 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_four_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..54 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(58)) => {}
        other => panic!(
            "fifty-fourth subshell_end(Some(58)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_328_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(328)));
    match vm.run() {
        VMResult::Ok(Value::Status(328)) => {}
        other => panic!("exit code 328 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_rot_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Rot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(329)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 329);
}

#[test]
fn subshell_end_exit_code_329_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(329)));
    match vm.run() {
        VMResult::Ok(Value::Status(329)) => {}
        other => panic!("exit code 329 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteenth_some_host_applies_on_nineteenth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct NineteenthSomeHost {
        calls: u32,
    }
    impl ShellHost for NineteenthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 19 {
                Some(330)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(NineteenthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(330)) => {}
        other => panic!(
            "nineteenth subshell_end(Some(330)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_330_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(330)));
    match vm.run() {
        VMResult::Ok(Value::Status(330)) => {}
        other => panic!("exit code 330 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_inc_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Inc, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(331)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 331);
}

#[test]
fn subshell_end_exit_code_331_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(331)));
    match vm.run() {
        VMResult::Ok(Value::Status(331)) => {}
        other => panic!("exit code 331 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..45 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_332_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(332)));
    match vm.run() {
        VMResult::Ok(Value::Status(332)) => {}
        other => panic!("exit code 332 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-42)));
    match vm.run() {
        VMResult::Ok(Value::Status(-42)) => {}
        other => panic!("status -42 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dec_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dec, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(333)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 333);
}

#[test]
fn subshell_end_exit_code_333_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(333)));
    match vm.run() {
        VMResult::Ok(Value::Status(333)) => {}
        other => panic!("exit code 333 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch M (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_334_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(334)));
    match vm.run() {
        VMResult::Ok(Value::Status(334)) => {}
        other => panic!("exit code 334 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..46 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_335_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(335)));
    match vm.run() {
        VMResult::Ok(Value::Status(335)) => {}
        other => panic!("exit code 335 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..47 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_336_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(336)));
    match vm.run() {
        VMResult::Ok(Value::Status(336)) => {}
        other => panic!("exit code 336 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..48 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_337_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(337)));
    match vm.run() {
        VMResult::Ok(Value::Status(337)) => {}
        other => panic!("exit code 337 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_forty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..49 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_338_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(338)));
    match vm.run() {
        VMResult::Ok(Value::Status(338)) => {}
        other => panic!("exit code 338 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..50 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_339_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(339)));
    match vm.run() {
        VMResult::Ok(Value::Status(339)) => {}
        other => panic!("exit code 339 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_five_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..55 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(60)) => {}
        other => panic!(
            "fifty-fifth subshell_end(Some(60)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_340_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(340)));
    match vm.run() {
        VMResult::Ok(Value::Status(340)) => {}
        other => panic!("exit code 340 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-43)));
    match vm.run() {
        VMResult::Ok(Value::Status(-43)) => {}
        other => panic!("status -43 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_341_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(341)));
    match vm.run() {
        VMResult::Ok(Value::Status(341)) => {}
        other => panic!("exit code 341 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_six_end_incrementing_from_eleven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..56 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(66)) => {}
        other => panic!(
            "fifty-sixth subshell_end(Some(66)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_342_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(342)));
    match vm.run() {
        VMResult::Ok(Value::Status(342)) => {}
        other => panic!("exit code 342 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-44)));
    match vm.run() {
        VMResult::Ok(Value::Status(-44)) => {}
        other => panic!("status -44 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_343_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(343)));
    match vm.run() {
        VMResult::Ok(Value::Status(343)) => {}
        other => panic!("exit code 343 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-45)));
    match vm.run() {
        VMResult::Ok(Value::Status(-45)) => {}
        other => panic!("status -45 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_344_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(344)));
    match vm.run() {
        VMResult::Ok(Value::Status(344)) => {}
        other => panic!("exit code 344 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-46)));
    match vm.run() {
        VMResult::Ok(Value::Status(-46)) => {}
        other => panic!("status -46 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_345_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(345)));
    match vm.run() {
        VMResult::Ok(Value::Status(345)) => {}
        other => panic!("exit code 345 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-47)));
    match vm.run() {
        VMResult::Ok(Value::Status(-47)) => {}
        other => panic!("status -47 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_346_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(346)));
    match vm.run() {
        VMResult::Ok(Value::Status(346)) => {}
        other => panic!("exit code 346 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twentieth_some_host_applies_on_twentieth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentiethSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentiethSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 20 {
                Some(347)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 7;
    vm.set_shell_host(Box::new(TwentiethSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(347)) => {}
        other => panic!(
            "twentieth subshell_end(Some(347)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_347_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(347)));
    match vm.run() {
        VMResult::Ok(Value::Status(347)) => {}
        other => panic!("exit code 347 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("foo"));
    let bidx = b.add_constant(Value::str("bar"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Concat, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(348)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 348);
}

#[test]
fn subshell_end_exit_code_348_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(348)));
    match vm.run() {
        VMResult::Ok(Value::Status(348)) => {}
        other => panic!("exit code 348 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_repeat_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let s = b.add_constant(Value::str("x"));
    b.emit(Op::LoadConst(s), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StringRepeat, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(349)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 349);
}

#[test]
fn subshell_end_exit_code_349_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(349)));
    match vm.run() {
        VMResult::Ok(Value::Status(349)) => {}
        other => panic!("exit code 349 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_eighth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(350)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..5 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 8);
    assert_eq!(vm.last_status, 350);
}

#[test]
fn subshell_end_exit_code_350_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(350)));
    match vm.run() {
        VMResult::Ok(Value::Status(350)) => {}
        other => panic!("exit code 350 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status351() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(1.41), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(351)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 351);
}

#[test]
fn subshell_end_exit_code_351_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(351)));
    match vm.run() {
        VMResult::Ok(Value::Status(351)) => {}
        other => panic!("exit code 351 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_six_begins_three_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..6 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..3 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost352;
    impl ShellHost for CountingBeginEndHost352 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(352)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost352));
    match vm.run() {
        VMResult::Ok(Value::Status(352)) => {}
        other => panic!("third subshell_end(Some(352)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 6);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 3);
}

#[test]
fn subshell_end_exit_code_352_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(352)));
    match vm.run() {
        VMResult::Ok(Value::Status(352)) => {}
        other => panic!("exit code 352 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ne_on_consts_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("left"));
    let bidx = b.add_constant(Value::str("right"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrNe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(353)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 353);
}

#[test]
fn subshell_end_exit_code_353_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(353)));
    match vm.run() {
        VMResult::Ok(Value::Status(353)) => {}
        other => panic!("exit code 353 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_five_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(354)));
    for _ in 0..5 {
        match vm.run() {
            VMResult::Ok(Value::Status(354)) => {}
            other => panic!("reset run MUST return Status(354), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_354_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(354)));
    match vm.run() {
        VMResult::Ok(Value::Status(354)) => {}
        other => panic!("exit code 354 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_add_after_subshell_end_status355() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Add, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(355)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 355);
}

#[test]
fn subshell_end_exit_code_355_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(355)));
    match vm.run() {
        VMResult::Ok(Value::Status(355)) => {}
        other => panic!("exit code 355 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_tenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..10 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost tenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_356_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(356)));
    match vm.run() {
        VMResult::Ok(Value::Status(356)) => {}
        other => panic!("exit code 356 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_len_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let s = b.add_constant(Value::str("halt"));
    b.emit(Op::LoadConst(s), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StringLen, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(357)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 357);
}

#[test]
fn subshell_end_exit_code_357_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(357)));
    match vm.run() {
        VMResult::Ok(Value::Status(357)) => {}
        other => panic!("exit code 357 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_seven_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..57 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(59)) => {}
        other => panic!(
            "fifty-seventh subshell_end(Some(59)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_358_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(358)));
    match vm.run() {
        VMResult::Ok(Value::Status(358)) => {}
        other => panic!("exit code 358 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch N (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_359_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(359)));
    match vm.run() {
        VMResult::Ok(Value::Status(359)) => {}
        other => panic!("exit code 359 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..51 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_360_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(360)));
    match vm.run() {
        VMResult::Ok(Value::Status(360)) => {}
        other => panic!("exit code 360 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..52 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_361_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(361)));
    match vm.run() {
        VMResult::Ok(Value::Status(361)) => {}
        other => panic!("exit code 361 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..53 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_362_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(362)));
    match vm.run() {
        VMResult::Ok(Value::Status(362)) => {}
        other => panic!("exit code 362 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_eight_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..58 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(65)) => {}
        other => panic!(
            "fifty-eighth subshell_end(Some(65)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_363_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(363)));
    match vm.run() {
        VMResult::Ok(Value::Status(363)) => {}
        other => panic!("exit code 363 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-48)));
    match vm.run() {
        VMResult::Ok(Value::Status(-48)) => {}
        other => panic!("status -48 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_364_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(364)));
    match vm.run() {
        VMResult::Ok(Value::Status(364)) => {}
        other => panic!("exit code 364 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_forty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-49)));
    match vm.run() {
        VMResult::Ok(Value::Status(-49)) => {}
        other => panic!("status -49 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_365_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(365)));
    match vm.run() {
        VMResult::Ok(Value::Status(365)) => {}
        other => panic!("exit code 365 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-50)));
    match vm.run() {
        VMResult::Ok(Value::Status(-50)) => {}
        other => panic!("status -50 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_366_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(366)));
    match vm.run() {
        VMResult::Ok(Value::Status(366)) => {}
        other => panic!("exit code 366 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_first_some_host_applies_on_twenty_first_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyFirstSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyFirstSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 21 {
                Some(367)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 4;
    vm.set_shell_host(Box::new(TwentyFirstSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(367)) => {}
        other => panic!(
            "twenty-first subshell_end(Some(367)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_367_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(367)));
    match vm.run() {
        VMResult::Ok(Value::Status(367)) => {}
        other => panic!("exit code 367 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_second_some_host_applies_on_twenty_second_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentySecondSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentySecondSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 22 {
                Some(368)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(TwentySecondSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(368)) => {}
        other => panic!(
            "twenty-second subshell_end(Some(368)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_368_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(368)));
    match vm.run() {
        VMResult::Ok(Value::Status(368)) => {}
        other => panic!("exit code 368 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_hash_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let k = b.add_constant(Value::str("a"));
    let v = b.add_constant(Value::str("b"));
    b.emit(Op::LoadConst(k), 1);
    b.emit(Op::LoadConst(v), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeHash(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(369)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 369);
}

#[test]
fn subshell_end_exit_code_369_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(369)));
    match vm.run() {
        VMResult::Ok(Value::Status(369)) => {}
        other => panic!("exit code 369 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_spaceship_after_subshell_end_status370() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Spaceship, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(370)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 370);
}

#[test]
fn subshell_end_exit_code_370_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(370)));
    match vm.run() {
        VMResult::Ok(Value::Status(370)) => {}
        other => panic!("exit code 370 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_ninth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(371)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..6 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 9);
    assert_eq!(vm.last_status, 371);
}

#[test]
fn subshell_end_exit_code_371_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(371)));
    match vm.run() {
        VMResult::Ok(Value::Status(371)) => {}
        other => panic!("exit code 371 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_true_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(372)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 372);
}

#[test]
fn subshell_end_exit_code_372_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(372)));
    match vm.run() {
        VMResult::Ok(Value::Status(372)) => {}
        other => panic!("exit code 372 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_zero_then_negative_second_end_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct ZeroThenNegativeHost {
        calls: u32,
    }
    impl ShellHost for ZeroThenNegativeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(0)
            } else {
                Some(-51)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(ZeroThenNegativeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(-51)) => {}
        other => panic!(
            "second subshell_end(Some(-51)) MUST overwrite zero, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_373_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(373)));
    match vm.run() {
        VMResult::Ok(Value::Status(373)) => {}
        other => panic!("exit code 373 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..54 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_374_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(374)));
    match vm.run() {
        VMResult::Ok(Value::Status(374)) => {}
        other => panic!("exit code 374 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_nine_end_incrementing_from_twelve() {
    let mut b = ChunkBuilder::new();
    for _ in 0..59 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(70)) => {}
        other => panic!(
            "fifty-ninth subshell_end(Some(70)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_375_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(375)));
    match vm.run() {
        VMResult::Ok(Value::Status(375)) => {}
        other => panic!("exit code 375 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_third_subshell_end_and_fourth_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    struct CountingBeginEndHost376;
    impl ShellHost for CountingBeginEndHost376 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(376)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost376));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 3);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 376);
}

#[test]
fn subshell_end_exit_code_376_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(376)));
    match vm.run() {
        VMResult::Ok(Value::Status(376)) => {}
        other => panic!("exit code 376 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_eq_on_consts_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("eq"));
    let bidx = b.add_constant(Value::str("eq"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrEq, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(377)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 377);
}

#[test]
fn subshell_end_exit_code_377_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(377)));
    match vm.run() {
        VMResult::Ok(Value::Status(377)) => {}
        other => panic!("exit code 377 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_six_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(378)));
    for _ in 0..6 {
        match vm.run() {
            VMResult::Ok(Value::Status(378)) => {}
            other => panic!("reset run MUST return Status(378), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_378_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(378)));
    match vm.run() {
        VMResult::Ok(Value::Status(378)) => {}
        other => panic!("exit code 378 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(379)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 379);
}

#[test]
fn subshell_end_exit_code_379_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(379)));
    match vm.run() {
        VMResult::Ok(Value::Status(379)) => {}
        other => panic!("exit code 379 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-51)));
    match vm.run() {
        VMResult::Ok(Value::Status(-51)) => {}
        other => panic!("status -51 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_380_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(380)));
    match vm.run() {
        VMResult::Ok(Value::Status(380)) => {}
        other => panic!("exit code 380 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..55 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_381_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(381)));
    match vm.run() {
        VMResult::Ok(Value::Status(381)) => {}
        other => panic!("exit code 381 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..60 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(60)) => {}
        other => panic!("sixtieth subshell_end(Some(60)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_382_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(382)));
    match vm.run() {
        VMResult::Ok(Value::Status(382)) => {}
        other => panic!("exit code 382 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_swap_after_subshell_end_status383() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Swap, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(383)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 383);
}

#[test]
fn subshell_end_exit_code_383_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(383)));
    match vm.run() {
        VMResult::Ok(Value::Status(383)) => {}
        other => panic!("exit code 383 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-52)));
    match vm.run() {
        VMResult::Ok(Value::Status(-52)) => {}
        other => panic!("status -52 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(42), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(384)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 384);
}

#[test]
fn subshell_end_exit_code_384_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(384)));
    match vm.run() {
        VMResult::Ok(Value::Status(384)) => {}
        other => panic!("exit code 384 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_third_some_host_applies_on_twenty_third_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyThirdSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyThirdSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 23 {
                Some(385)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 9;
    vm.set_shell_host(Box::new(TwentyThirdSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(385)) => {}
        other => panic!(
            "twenty-third subshell_end(Some(385)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_385_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(385)));
    match vm.run() {
        VMResult::Ok(Value::Status(385)) => {}
        other => panic!("exit code 385 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..56 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_386_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(386)));
    match vm.run() {
        VMResult::Ok(Value::Status(386)) => {}
        other => panic!("exit code 386 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_getstatus_on_fifth_reset_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(halt.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(387)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(halt);
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(387)) => {}
        other => panic!("fifth reset run MUST return Status(387), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_387_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(387)));
    match vm.run() {
        VMResult::Ok(Value::Status(387)) => {}
        other => panic!("exit code 387 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_undef_after_subshell_end_status388() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadUndef, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(388)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 388);
}

#[test]
fn subshell_end_exit_code_388_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(388)));
    match vm.run() {
        VMResult::Ok(Value::Status(388)) => {}
        other => panic!("exit code 388 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch O (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_389_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(389)));
    match vm.run() {
        VMResult::Ok(Value::Status(389)) => {}
        other => panic!("exit code 389 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..57 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_390_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(390)));
    match vm.run() {
        VMResult::Ok(Value::Status(390)) => {}
        other => panic!("exit code 390 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..58 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_391_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(391)));
    match vm.run() {
        VMResult::Ok(Value::Status(391)) => {}
        other => panic!("exit code 391 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_fifty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..59 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_392_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(392)));
    match vm.run() {
        VMResult::Ok(Value::Status(392)) => {}
        other => panic!("exit code 392 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..60 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_393_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(393)));
    match vm.run() {
        VMResult::Ok(Value::Status(393)) => {}
        other => panic!("exit code 393 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..61 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_394_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(394)));
    match vm.run() {
        VMResult::Ok(Value::Status(394)) => {}
        other => panic!("exit code 394 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_one_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..61 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(65)) => {}
        other => panic!(
            "sixty-first subshell_end(Some(65)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_395_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(395)));
    match vm.run() {
        VMResult::Ok(Value::Status(395)) => {}
        other => panic!("exit code 395 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-53)));
    match vm.run() {
        VMResult::Ok(Value::Status(-53)) => {}
        other => panic!("status -53 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_396_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(396)));
    match vm.run() {
        VMResult::Ok(Value::Status(396)) => {}
        other => panic!("exit code 396 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_two_end_incrementing_from_ten() {
    let mut b = ChunkBuilder::new();
    for _ in 0..62 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(71)) => {}
        other => panic!(
            "sixty-second subshell_end(Some(71)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_397_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(397)));
    match vm.run() {
        VMResult::Ok(Value::Status(397)) => {}
        other => panic!("exit code 397 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-54)));
    match vm.run() {
        VMResult::Ok(Value::Status(-54)) => {}
        other => panic!("status -54 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_398_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(398)));
    match vm.run() {
        VMResult::Ok(Value::Status(398)) => {}
        other => panic!("exit code 398 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-55)));
    match vm.run() {
        VMResult::Ok(Value::Status(-55)) => {}
        other => panic!("status -55 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_399_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(399)));
    match vm.run() {
        VMResult::Ok(Value::Status(399)) => {}
        other => panic!("exit code 399 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-56)));
    match vm.run() {
        VMResult::Ok(Value::Status(-56)) => {}
        other => panic!("status -56 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_400_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(400)));
    match vm.run() {
        VMResult::Ok(Value::Status(400)) => {}
        other => panic!("exit code 400 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-57)));
    match vm.run() {
        VMResult::Ok(Value::Status(-57)) => {}
        other => panic!("status -57 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_401_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(401)));
    match vm.run() {
        VMResult::Ok(Value::Status(401)) => {}
        other => panic!("exit code 401 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_fourth_some_host_applies_on_twenty_fourth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..24 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyFourthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyFourthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 24 {
                Some(402)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 6;
    vm.set_shell_host(Box::new(TwentyFourthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(402)) => {}
        other => panic!(
            "twenty-fourth subshell_end(Some(402)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_402_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(402)));
    match vm.run() {
        VMResult::Ok(Value::Status(402)) => {}
        other => panic!("exit code 402 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_tenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(403)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..7 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 10);
    assert_eq!(vm.last_status, 403);
}

#[test]
fn subshell_end_exit_code_403_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(403)));
    match vm.run() {
        VMResult::Ok(Value::Status(403)) => {}
        other => panic!("exit code 403 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_lt_on_consts_after_subshell_end_status404() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("a"));
    let bidx = b.add_constant(Value::str("z"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrLt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(404)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 404);
}

#[test]
fn subshell_end_exit_code_404_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(404)));
    match vm.run() {
        VMResult::Ok(Value::Status(404)) => {}
        other => panic!("exit code 404 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seven_begins_four_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..7 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..4 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost405;
    impl ShellHost for CountingBeginEndHost405 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(405)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost405));
    match vm.run() {
        VMResult::Ok(Value::Status(405)) => {}
        other => panic!("fourth subshell_end(Some(405)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 7);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 4);
}

#[test]
fn subshell_end_exit_code_405_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(405)));
    match vm.run() {
        VMResult::Ok(Value::Status(405)) => {}
        other => panic!("exit code 405 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_pipeline_end_and_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    struct PipelineEndSubshellBeginHost406;
    impl ShellHost for PipelineEndSubshellBeginHost406 {
        fn pipeline_end(&mut self) -> i32 {
            0
        }
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(406)
        }
    }
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineEndSubshellBeginHost406));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 0);
}

#[test]
fn subshell_end_exit_code_406_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(406)));
    match vm.run() {
        VMResult::Ok(Value::Status(406)) => {}
        other => panic!("exit code 406 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seven_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(407)));
    for _ in 0..7 {
        match vm.run() {
            VMResult::Ok(Value::Status(407)) => {}
            other => panic!("reset run MUST return Status(407), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_407_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(407)));
    match vm.run() {
        VMResult::Ok(Value::Status(407)) => {}
        other => panic!("exit code 407 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_gt_on_consts_after_subshell_end_status408() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("z"));
    let bidx = b.add_constant(Value::str("a"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrGt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(408)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 408);
}

#[test]
fn subshell_end_exit_code_408_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(408)));
    match vm.run() {
        VMResult::Ok(Value::Status(408)) => {}
        other => panic!("exit code 408 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twelfth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..12 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twelfth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_409_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(409)));
    match vm.run() {
        VMResult::Ok(Value::Status(409)) => {}
        other => panic!("exit code 409 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pow_after_subshell_end_status410() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pow, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(410)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 410);
}

#[test]
fn subshell_end_exit_code_410_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(410)));
    match vm.run() {
        VMResult::Ok(Value::Status(410)) => {}
        other => panic!("exit code 410 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_three_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..63 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(64)) => {}
        other => panic!(
            "sixty-third subshell_end(Some(64)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_411_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(411)));
    match vm.run() {
        VMResult::Ok(Value::Status(411)) => {}
        other => panic!("exit code 411 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_false_after_subshell_end_status412() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(412)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 412);
}

#[test]
fn subshell_end_exit_code_412_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(412)));
    match vm.run() {
        VMResult::Ok(Value::Status(412)) => {}
        other => panic!("exit code 412 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_rot_after_subshell_end_status413() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Rot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(413)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 413);
}

#[test]
fn subshell_end_exit_code_413_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(413)));
    match vm.run() {
        VMResult::Ok(Value::Status(413)) => {}
        other => panic!("exit code 413 MUST propagate, got {:?}", other),
    }
}
// ─── Pin tests batch P (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_414_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(414)));
    match vm.run() {
        VMResult::Ok(Value::Status(414)) => {}
        other => panic!("exit code 414 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..62 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_415_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(415)));
    match vm.run() {
        VMResult::Ok(Value::Status(415)) => {}
        other => panic!("exit code 415 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..63 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_416_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(416)));
    match vm.run() {
        VMResult::Ok(Value::Status(416)) => {}
        other => panic!("exit code 416 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..64 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_417_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(417)));
    match vm.run() {
        VMResult::Ok(Value::Status(417)) => {}
        other => panic!("exit code 417 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..65 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_418_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(418)));
    match vm.run() {
        VMResult::Ok(Value::Status(418)) => {}
        other => panic!("exit code 418 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..66 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_419_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(419)));
    match vm.run() {
        VMResult::Ok(Value::Status(419)) => {}
        other => panic!("exit code 419 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_four_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..64 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(70)) => {}
        other => panic!(
            "sixty-fourth subshell_end(Some(70)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_420_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(420)));
    match vm.run() {
        VMResult::Ok(Value::Status(420)) => {}
        other => panic!("exit code 420 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-58)));
    match vm.run() {
        VMResult::Ok(Value::Status(-58)) => {}
        other => panic!("status -58 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_421_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(421)));
    match vm.run() {
        VMResult::Ok(Value::Status(421)) => {}
        other => panic!("exit code 421 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_fifty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-59)));
    match vm.run() {
        VMResult::Ok(Value::Status(-59)) => {}
        other => panic!("status -59 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_422_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(422)));
    match vm.run() {
        VMResult::Ok(Value::Status(422)) => {}
        other => panic!("exit code 422 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-60)));
    match vm.run() {
        VMResult::Ok(Value::Status(-60)) => {}
        other => panic!("status -60 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_423_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(423)));
    match vm.run() {
        VMResult::Ok(Value::Status(423)) => {}
        other => panic!("exit code 423 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_fifth_some_host_applies_on_twenty_fifth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..25 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyFifthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyFifthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 25 {
                Some(424)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(TwentyFifthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(424)) => {}
        other => panic!(
            "twenty-fifth subshell_end(Some(424)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_424_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(424)));
    match vm.run() {
        VMResult::Ok(Value::Status(424)) => {}
        other => panic!("exit code 424 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_sixth_some_host_applies_on_twenty_sixth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..26 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentySixthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentySixthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 26 {
                Some(425)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(TwentySixthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(425)) => {}
        other => panic!(
            "twenty-sixth subshell_end(Some(425)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_425_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(425)));
    match vm.run() {
        VMResult::Ok(Value::Status(425)) => {}
        other => panic!("exit code 425 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_eleventh_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(426)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..8 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 11);
    assert_eq!(vm.last_status, 426);
}

#[test]
fn subshell_end_exit_code_426_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(426)));
    match vm.run() {
        VMResult::Ok(Value::Status(426)) => {}
        other => panic!("exit code 426 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_true_after_subshell_end() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumLt, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(427)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 427);
}

#[test]
fn subshell_end_exit_code_427_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(427)));
    match vm.run() {
        VMResult::Ok(Value::Status(427)) => {}
        other => panic!("exit code 427 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_second_end_overwrites() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-61)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST overwrite -61, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_428_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(428)));
    match vm.run() {
        VMResult::Ok(Value::Status(428)) => {}
        other => panic!("exit code 428 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..67 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_429_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(429)));
    match vm.run() {
        VMResult::Ok(Value::Status(429)) => {}
        other => panic!("exit code 429 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_five_end_incrementing_from_fourteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..65 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 14 }));
    match vm.run() {
        VMResult::Ok(Value::Status(78)) => {}
        other => panic!(
            "sixty-fifth subshell_end(Some(78)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_430_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(430)));
    match vm.run() {
        VMResult::Ok(Value::Status(430)) => {}
        other => panic!("exit code 430 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_between_fourth_subshell_end_and_fifth_subshell_begin() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    struct CountingBeginEndHost431;
    impl ShellHost for CountingBeginEndHost431 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(431)
        }
    }
    let mut b = ChunkBuilder::new();
    for _ in 0..4 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost431));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 4);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 431);
}

#[test]
fn subshell_end_exit_code_431_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(431)));
    match vm.run() {
        VMResult::Ok(Value::Status(431)) => {}
        other => panic!("exit code 431 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_le_on_consts_after_subshell_end_status432() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let a = b.add_constant(Value::str("abc"));
    let bidx = b.add_constant(Value::str("abd"));
    b.emit(Op::LoadConst(a), 1);
    b.emit(Op::LoadConst(bidx), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::StrLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(432)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 432);
}

#[test]
fn subshell_end_exit_code_432_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(432)));
    match vm.run() {
        VMResult::Ok(Value::Status(432)) => {}
        other => panic!("exit code 432 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eight_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(433)));
    for _ in 0..8 {
        match vm.run() {
            VMResult::Ok(Value::Status(433)) => {}
            other => panic!("reset run MUST return Status(433), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_433_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(433)));
    match vm.run() {
        VMResult::Ok(Value::Status(433)) => {}
        other => panic!("exit code 433 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_inc_after_subshell_end_status434() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Inc, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(434)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 434);
}

#[test]
fn subshell_end_exit_code_434_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(434)));
    match vm.run() {
        VMResult::Ok(Value::Status(434)) => {}
        other => panic!("exit code 434 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-61)));
    match vm.run() {
        VMResult::Ok(Value::Status(-61)) => {}
        other => panic!("status -61 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_435_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(435)));
    match vm.run() {
        VMResult::Ok(Value::Status(435)) => {}
        other => panic!("exit code 435 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..68 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_436_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(436)));
    match vm.run() {
        VMResult::Ok(Value::Status(436)) => {}
        other => panic!("exit code 436 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_six_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..66 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(68)) => {}
        other => panic!(
            "sixty-sixth subshell_end(Some(68)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_437_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(437)));
    match vm.run() {
        VMResult::Ok(Value::Status(437)) => {}
        other => panic!("exit code 437 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dec_after_subshell_end_status438() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dec, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(438)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 438);
}

#[test]
fn subshell_end_exit_code_438_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(438)));
    match vm.run() {
        VMResult::Ok(Value::Status(438)) => {}
        other => panic!("exit code 438 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_seventh_some_host_applies_on_twenty_seventh_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..27 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentySeventhSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentySeventhSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 27 {
                Some(439)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(TwentySeventhSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(439)) => {}
        other => panic!(
            "twenty-seventh subshell_end(Some(439)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_439_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(439)));
    match vm.run() {
        VMResult::Ok(Value::Status(439)) => {}
        other => panic!("exit code 439 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_hash_after_subshell_end_status440() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    let k = b.add_constant(Value::str("x"));
    let v = b.add_constant(Value::str("y"));
    b.emit(Op::LoadConst(k), 1);
    b.emit(Op::LoadConst(v), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeHash(1), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(440)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 440);
}

#[test]
fn subshell_end_exit_code_440_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(440)));
    match vm.run() {
        VMResult::Ok(Value::Status(440)) => {}
        other => panic!("exit code 440 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_getstatus_on_sixth_reset_run() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    let halt = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(halt.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(441)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(halt);
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub.clone());
    let _ = vm.run();
    vm.reset(sub);
    match vm.run() {
        VMResult::Ok(Value::Status(441)) => {}
        other => panic!("sixth reset run MUST return Status(441), got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_441_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(441)));
    match vm.run() {
        VMResult::Ok(Value::Status(441)) => {}
        other => panic!("exit code 441 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_sixty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..69 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_442_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(442)));
    match vm.run() {
        VMResult::Ok(Value::Status(442)) => {}
        other => panic!("exit code 442 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-62)));
    match vm.run() {
        VMResult::Ok(Value::Status(-62)) => {}
        other => panic!("status -62 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup2_after_subshell_end_status443() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup2, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(443)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 443);
}

#[test]
fn subshell_end_exit_code_443_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(443)));
    match vm.run() {
        VMResult::Ok(Value::Status(443)) => {}
        other => panic!("exit code 443 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch Q (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_444_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(444)));
    match vm.run() {
        VMResult::Ok(Value::Status(444)) => {}
        other => panic!("exit code 444 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..70 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_445_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(445)));
    match vm.run() {
        VMResult::Ok(Value::Status(445)) => {}
        other => panic!("exit code 445 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..71 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_446_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(446)));
    match vm.run() {
        VMResult::Ok(Value::Status(446)) => {}
        other => panic!("exit code 446 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..72 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_447_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(447)));
    match vm.run() {
        VMResult::Ok(Value::Status(447)) => {}
        other => panic!("exit code 447 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..73 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_448_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(448)));
    match vm.run() {
        VMResult::Ok(Value::Status(448)) => {}
        other => panic!("exit code 448 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..74 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_449_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(449)));
    match vm.run() {
        VMResult::Ok(Value::Status(449)) => {}
        other => panic!("exit code 449 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_seven_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..67 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(72)) => {}
        other => panic!(
            "sixty-seventh subshell_end(Some(72)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_450_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(450)));
    match vm.run() {
        VMResult::Ok(Value::Status(450)) => {}
        other => panic!("exit code 450 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-63)));
    match vm.run() {
        VMResult::Ok(Value::Status(-63)) => {}
        other => panic!("status -63 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_451_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(451)));
    match vm.run() {
        VMResult::Ok(Value::Status(451)) => {}
        other => panic!("exit code 451 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_eight_end_incrementing_from_eleven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..68 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(78)) => {}
        other => panic!(
            "sixty-eighth subshell_end(Some(78)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_452_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(452)));
    match vm.run() {
        VMResult::Ok(Value::Status(452)) => {}
        other => panic!("exit code 452 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-64)));
    match vm.run() {
        VMResult::Ok(Value::Status(-64)) => {}
        other => panic!("status -64 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_453_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(453)));
    match vm.run() {
        VMResult::Ok(Value::Status(453)) => {}
        other => panic!("exit code 453 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-65)));
    match vm.run() {
        VMResult::Ok(Value::Status(-65)) => {}
        other => panic!("status -65 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_454_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(454)));
    match vm.run() {
        VMResult::Ok(Value::Status(454)) => {}
        other => panic!("exit code 454 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-66)));
    match vm.run() {
        VMResult::Ok(Value::Status(-66)) => {}
        other => panic!("status -66 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_455_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(455)));
    match vm.run() {
        VMResult::Ok(Value::Status(455)) => {}
        other => panic!("exit code 455 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-67)));
    match vm.run() {
        VMResult::Ok(Value::Status(-67)) => {}
        other => panic!("status -67 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_456_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(456)));
    match vm.run() {
        VMResult::Ok(Value::Status(456)) => {}
        other => panic!("exit code 456 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_eighth_some_host_applies_on_twenty_eighth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..28 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyEighthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyEighthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 28 {
                Some(457)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(TwentyEighthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(457)) => {}
        other => panic!(
            "twenty-eighth subshell_end(Some(457)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_457_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(457)));
    match vm.run() {
        VMResult::Ok(Value::Status(457)) => {}
        other => panic!("exit code 457 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twelfth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(458)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..9 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 12);
    assert_eq!(vm.last_status, 458);
}

#[test]
fn subshell_end_exit_code_458_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(458)));
    match vm.run() {
        VMResult::Ok(Value::Status(458)) => {}
        other => panic!("exit code 458 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_mod_after_subshell_end_status459() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(17), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mod, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(459)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 459);
}

#[test]
fn subshell_end_exit_code_459_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(459)));
    match vm.run() {
        VMResult::Ok(Value::Status(459)) => {}
        other => panic!("exit code 459 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eight_begins_five_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..8 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..5 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost460;
    impl ShellHost for CountingBeginEndHost460 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(460)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost460));
    match vm.run() {
        VMResult::Ok(Value::Status(460)) => {}
        other => panic!("fifth subshell_end(Some(460)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 8);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 5);
}

#[test]
fn subshell_end_exit_code_460_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(460)));
    match vm.run() {
        VMResult::Ok(Value::Status(460)) => {}
        other => panic!("exit code 460 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_div_after_subshell_end_status461() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(24), 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Div, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(461)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 461);
}

#[test]
fn subshell_end_exit_code_461_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(461)));
    match vm.run() {
        VMResult::Ok(Value::Status(461)) => {}
        other => panic!("exit code 461 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nine_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(462)));
    for _ in 0..9 {
        match vm.run() {
            VMResult::Ok(Value::Status(462)) => {}
            other => panic!("reset run MUST return Status(462), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_462_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(462)));
    match vm.run() {
        VMResult::Ok(Value::Status(462)) => {}
        other => panic!("exit code 462 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_fourteenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..14 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost fourteenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_463_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(463)));
    match vm.run() {
        VMResult::Ok(Value::Status(463)) => {}
        other => panic!("exit code 463 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_mul_after_subshell_end_status464() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Mul, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(464)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 464);
}

#[test]
fn subshell_end_exit_code_464_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(464)));
    match vm.run() {
        VMResult::Ok(Value::Status(464)) => {}
        other => panic!("exit code 464 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_nine_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..69 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(72)) => {}
        other => panic!(
            "sixty-ninth subshell_end(Some(72)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_465_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(465)));
    match vm.run() {
        VMResult::Ok(Value::Status(465)) => {}
        other => panic!("exit code 465 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_sub_after_subshell_end_status466() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Sub, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(466)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 466);
}

#[test]
fn subshell_end_exit_code_466_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(466)));
    match vm.run() {
        VMResult::Ok(Value::Status(466)) => {}
        other => panic!("exit code 466 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status467() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(467)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 467);
}

#[test]
fn subshell_end_exit_code_467_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(467)));
    match vm.run() {
        VMResult::Ok(Value::Status(467)) => {}
        other => panic!("exit code 467 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..75 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_468_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(468)));
    match vm.run() {
        VMResult::Ok(Value::Status(468)) => {}
        other => panic!("exit code 468 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch R (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_469_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(469)));
    match vm.run() {
        VMResult::Ok(Value::Status(469)) => {}
        other => panic!("exit code 469 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..76 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_470_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(470)));
    match vm.run() {
        VMResult::Ok(Value::Status(470)) => {}
        other => panic!("exit code 470 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..77 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_471_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(471)));
    match vm.run() {
        VMResult::Ok(Value::Status(471)) => {}
        other => panic!("exit code 471 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..78 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_472_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(472)));
    match vm.run() {
        VMResult::Ok(Value::Status(472)) => {}
        other => panic!("exit code 472 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_seventy_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..79 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_473_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(473)));
    match vm.run() {
        VMResult::Ok(Value::Status(473)) => {}
        other => panic!("exit code 473 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..80 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_474_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(474)));
    match vm.run() {
        VMResult::Ok(Value::Status(474)) => {}
        other => panic!("exit code 474 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..70 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(70)) => {}
        other => panic!(
            "seventieth subshell_end(Some(70)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_475_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(475)));
    match vm.run() {
        VMResult::Ok(Value::Status(475)) => {}
        other => panic!("exit code 475 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-68)));
    match vm.run() {
        VMResult::Ok(Value::Status(-68)) => {}
        other => panic!("status -68 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_476_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(476)));
    match vm.run() {
        VMResult::Ok(Value::Status(476)) => {}
        other => panic!("exit code 476 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_sixty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-69)));
    match vm.run() {
        VMResult::Ok(Value::Status(-69)) => {}
        other => panic!("status -69 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_477_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(477)));
    match vm.run() {
        VMResult::Ok(Value::Status(477)) => {}
        other => panic!("exit code 477 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-70)));
    match vm.run() {
        VMResult::Ok(Value::Status(-70)) => {}
        other => panic!("status -70 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_478_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(478)));
    match vm.run() {
        VMResult::Ok(Value::Status(478)) => {}
        other => panic!("exit code 478 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-71)));
    match vm.run() {
        VMResult::Ok(Value::Status(-71)) => {}
        other => panic!("status -71 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_479_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(479)));
    match vm.run() {
        VMResult::Ok(Value::Status(479)) => {}
        other => panic!("exit code 479 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-72)));
    match vm.run() {
        VMResult::Ok(Value::Status(-72)) => {}
        other => panic!("status -72 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_ninth_some_host_applies_on_twenty_ninth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..29 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct TwentyNinthSomeHost {
        calls: u32,
    }
    impl ShellHost for TwentyNinthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 29 {
                Some(480)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(TwentyNinthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(480)) => {}
        other => panic!(
            "twenty-ninth subshell_end(Some(480)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_480_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(480)));
    match vm.run() {
        VMResult::Ok(Value::Status(480)) => {}
        other => panic!("exit code 480 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_thirteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(481)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..10 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 13);
    assert_eq!(vm.last_status, 481);
}

#[test]
fn subshell_end_exit_code_481_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(481)));
    match vm.run() {
        VMResult::Ok(Value::Status(481)) => {}
        other => panic!("exit code 481 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_add_after_subshell_end_status482() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(13), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Add, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(482)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 482);
}

#[test]
fn subshell_end_exit_code_482_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(482)));
    match vm.run() {
        VMResult::Ok(Value::Status(482)) => {}
        other => panic!("exit code 482 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nine_begins_six_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..9 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..6 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost483;
    impl ShellHost for CountingBeginEndHost483 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(483)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost483));
    match vm.run() {
        VMResult::Ok(Value::Status(483)) => {}
        other => panic!("sixth subshell_end(Some(483)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 9);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 6);
}

#[test]
fn subshell_end_exit_code_483_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(483)));
    match vm.run() {
        VMResult::Ok(Value::Status(483)) => {}
        other => panic!("exit code 483 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_neg_after_subshell_end_status484() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(484)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 484);
}

#[test]
fn subshell_end_exit_code_484_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(484)));
    match vm.run() {
        VMResult::Ok(Value::Status(484)) => {}
        other => panic!("exit code 484 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ten_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(485)));
    for _ in 0..10 {
        match vm.run() {
            VMResult::Ok(Value::Status(485)) => {}
            other => panic!("reset run MUST return Status(485), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_485_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(485)));
    match vm.run() {
        VMResult::Ok(Value::Status(485)) => {}
        other => panic!("exit code 485 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_fifteenth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 486,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(486)) => {}
        other => panic!(
            "FirstSomeThenNoneHost fifteenth None MUST keep first Some(486), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_486_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(486)));
    match vm.run() {
        VMResult::Ok(Value::Status(486)) => {}
        other => panic!("exit code 486 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_not_after_subshell_end_status487() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(487)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 487);
}

#[test]
fn subshell_end_exit_code_487_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(487)));
    match vm.run() {
        VMResult::Ok(Value::Status(487)) => {}
        other => panic!("exit code 487 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_one_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..71 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(72)) => {}
        other => panic!(
            "seventy-first subshell_end(Some(72)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_488_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(488)));
    match vm.run() {
        VMResult::Ok(Value::Status(488)) => {}
        other => panic!("exit code 488 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_eq_after_subshell_end_status489() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumEq, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(489)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 489);
}

#[test]
fn subshell_end_exit_code_489_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(489)));
    match vm.run() {
        VMResult::Ok(Value::Status(489)) => {}
        other => panic!("exit code 489 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_lt_after_subshell_end_status490() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(490)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 490);
}

#[test]
fn subshell_end_exit_code_490_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(490)));
    match vm.run() {
        VMResult::Ok(Value::Status(490)) => {}
        other => panic!("exit code 490 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_gt_after_subshell_end_status491() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGt, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(491)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 491);
}

#[test]
fn subshell_end_exit_code_491_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(491)));
    match vm.run() {
        VMResult::Ok(Value::Status(491)) => {}
        other => panic!("exit code 491 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..81 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_492_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(492)));
    match vm.run() {
        VMResult::Ok(Value::Status(492)) => {}
        other => panic!("exit code 492 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirtieth_some_host_applies_on_thirtieth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..30 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtiethSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtiethSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 30 {
                Some(493)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(ThirtiethSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(493)) => {}
        other => panic!(
            "thirtieth subshell_end(Some(493)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_493_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(493)));
    match vm.run() {
        VMResult::Ok(Value::Status(493)) => {}
        other => panic!("exit code 493 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_494() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    struct PipelineSubshellHost494;
    impl ShellHost for PipelineSubshellHost494 {
        fn pipeline_end(&mut self) -> i32 {
            2
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(494)
        }
    }
    vm.set_shell_host(Box::new(PipelineSubshellHost494));
    match vm.run() {
        VMResult::Ok(Value::Status(494)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 494, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_494_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(494)));
    match vm.run() {
        VMResult::Ok(Value::Status(494)) => {}
        other => panic!("exit code 494 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_fifteen_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 495;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(495)) => {}
        other => panic!(
            "NoneHost fifteen ends MUST leave last_status 495, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_495_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(495)));
    match vm.run() {
        VMResult::Ok(Value::Status(495)) => {}
        other => panic!("exit code 495 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_pre_run_empty_stack_then_subshell_end_status496() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.request_halt();
    vm.set_shell_host(Box::new(StatusReturningHost(496)));
    match vm.run() {
        VMResult::Halted => {}
        other => panic!(
            "pre-run halt empty stack MUST Halted before subshell_end, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_496_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(496)));
    match vm.run() {
        VMResult::Ok(Value::Status(496)) => {}
        other => panic!("exit code 496 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost496 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost496 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-73)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost496 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -73, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_497_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(497)));
    match vm.run() {
        VMResult::Ok(Value::Status(497)) => {}
        other => panic!("exit code 497 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..82 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_498_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(498)));
    match vm.run() {
        VMResult::Ok(Value::Status(498)) => {}
        other => panic!("exit code 498 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch S (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_499_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(499)));
    match vm.run() {
        VMResult::Ok(Value::Status(499)) => {}
        other => panic!("exit code 499 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..83 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_500_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(500)));
    match vm.run() {
        VMResult::Ok(Value::Status(500)) => {}
        other => panic!("exit code 500 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..84 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_501_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(501)));
    match vm.run() {
        VMResult::Ok(Value::Status(501)) => {}
        other => panic!("exit code 501 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..85 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_502_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(502)));
    match vm.run() {
        VMResult::Ok(Value::Status(502)) => {}
        other => panic!("exit code 502 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_two_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..72 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(74)) => {}
        other => panic!(
            "seventy-second subshell_end(Some(74)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_503_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(503)));
    match vm.run() {
        VMResult::Ok(Value::Status(503)) => {}
        other => panic!("exit code 503 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-74)));
    match vm.run() {
        VMResult::Ok(Value::Status(-74)) => {}
        other => panic!("status -74 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_504_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(504)));
    match vm.run() {
        VMResult::Ok(Value::Status(504)) => {}
        other => panic!("exit code 504 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-75)));
    match vm.run() {
        VMResult::Ok(Value::Status(-75)) => {}
        other => panic!("status -75 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_505_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(505)));
    match vm.run() {
        VMResult::Ok(Value::Status(505)) => {}
        other => panic!("exit code 505 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_first_some_host_applies_on_thirty_first_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..31 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyFirstSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyFirstSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 31 {
                Some(506)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(ThirtyFirstSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(506)) => {}
        other => panic!(
            "thirty-first subshell_end(Some(506)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_506_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(506)));
    match vm.run() {
        VMResult::Ok(Value::Status(506)) => {}
        other => panic!("exit code 506 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_fourteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(507)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..11 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 14);
    assert_eq!(vm.last_status, 507);
}

#[test]
fn subshell_end_exit_code_507_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(507)));
    match vm.run() {
        VMResult::Ok(Value::Status(507)) => {}
        other => panic!("exit code 507 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ne_after_subshell_end_status508() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumNe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(508)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 508);
}

#[test]
fn subshell_end_exit_code_508_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(508)));
    match vm.run() {
        VMResult::Ok(Value::Status(508)) => {}
        other => panic!("exit code 508 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ten_begins_seven_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..10 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..7 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost509;
    impl ShellHost for CountingBeginEndHost509 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(509)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost509));
    match vm.run() {
        VMResult::Ok(Value::Status(509)) => {}
        other => panic!("seventh subshell_end(Some(509)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 10);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 7);
}

#[test]
fn subshell_end_exit_code_509_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(509)));
    match vm.run() {
        VMResult::Ok(Value::Status(509)) => {}
        other => panic!("exit code 509 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_spaceship_after_subshell_end_status510() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Spaceship, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(510)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 510);
}

#[test]
fn subshell_end_exit_code_510_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(510)));
    match vm.run() {
        VMResult::Ok(Value::Status(510)) => {}
        other => panic!("exit code 510 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eleven_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(511)));
    for _ in 0..11 {
        match vm.run() {
            VMResult::Ok(Value::Status(511)) => {}
            other => panic!("reset run MUST return Status(511), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_511_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(511)));
    match vm.run() {
        VMResult::Ok(Value::Status(511)) => {}
        other => panic!("exit code 511 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_fifteenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost fifteenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_512_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(512)));
    match vm.run() {
        VMResult::Ok(Value::Status(512)) => {}
        other => panic!("exit code 512 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_and_after_subshell_end_status513() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitAnd, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(513)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 513);
}

#[test]
fn subshell_end_exit_code_513_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(513)));
    match vm.run() {
        VMResult::Ok(Value::Status(513)) => {}
        other => panic!("exit code 513 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_three_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..73 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(77)) => {}
        other => panic!(
            "seventy-third subshell_end(Some(77)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_514_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(514)));
    match vm.run() {
        VMResult::Ok(Value::Status(514)) => {}
        other => panic!("exit code 514 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_true_after_subshell_end_status515() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(515)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 515);
}

#[test]
fn subshell_end_exit_code_515_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(515)));
    match vm.run() {
        VMResult::Ok(Value::Status(515)) => {}
        other => panic!("exit code 515 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_false_after_subshell_end_status516() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(516)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 516);
}

#[test]
fn subshell_end_exit_code_516_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(516)));
    match vm.run() {
        VMResult::Ok(Value::Status(516)) => {}
        other => panic!("exit code 516 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..86 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_517_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(517)));
    match vm.run() {
        VMResult::Ok(Value::Status(517)) => {}
        other => panic!("exit code 517 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..87 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_518_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(518)));
    match vm.run() {
        VMResult::Ok(Value::Status(518)) => {}
        other => panic!("exit code 518 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup_after_subshell_end_status519() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(12), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(519)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 519);
}

#[test]
fn subshell_end_exit_code_519_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(519)));
    match vm.run() {
        VMResult::Ok(Value::Status(519)) => {}
        other => panic!("exit code 519 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_swap_after_subshell_end_status520() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Swap, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(520)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 520);
}

#[test]
fn subshell_end_exit_code_520_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(520)));
    match vm.run() {
        VMResult::Ok(Value::Status(520)) => {}
        other => panic!("exit code 520 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nine_begins_eight_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..9 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..8 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost521;
    impl ShellHost for CountingBeginEndHost521 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(521)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost521));
    match vm.run() {
        VMResult::Ok(Value::Status(521)) => {}
        other => panic!("eighth subshell_end(Some(521)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 9);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 8);
}

#[test]
fn subshell_end_exit_code_521_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(521)));
    match vm.run() {
        VMResult::Ok(Value::Status(521)) => {}
        other => panic!("exit code 521 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_four_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..74 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(81)) => {}
        other => panic!(
            "seventy-fourth subshell_end(Some(81)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_522_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(522)));
    match vm.run() {
        VMResult::Ok(Value::Status(522)) => {}
        other => panic!("exit code 522 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_undef_after_subshell_end_status523() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadUndef, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(523)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 523);
}

#[test]
fn subshell_end_exit_code_523_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(523)));
    match vm.run() {
        VMResult::Ok(Value::Status(523)) => {}
        other => panic!("exit code 523 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch T (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_524_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(524)));
    match vm.run() {
        VMResult::Ok(Value::Status(524)) => {}
        other => panic!("exit code 524 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..88 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_525_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(525)));
    match vm.run() {
        VMResult::Ok(Value::Status(525)) => {}
        other => panic!("exit code 525 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_eighty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..89 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_526_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(526)));
    match vm.run() {
        VMResult::Ok(Value::Status(526)) => {}
        other => panic!("exit code 526 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..90 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_527_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(527)));
    match vm.run() {
        VMResult::Ok(Value::Status(527)) => {}
        other => panic!("exit code 527 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_five_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..75 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(83)) => {}
        other => panic!(
            "seventy-fifth subshell_end(Some(83)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_528_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(528)));
    match vm.run() {
        VMResult::Ok(Value::Status(528)) => {}
        other => panic!("exit code 528 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-76)));
    match vm.run() {
        VMResult::Ok(Value::Status(-76)) => {}
        other => panic!("status -76 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_529_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(529)));
    match vm.run() {
        VMResult::Ok(Value::Status(529)) => {}
        other => panic!("exit code 529 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-77)));
    match vm.run() {
        VMResult::Ok(Value::Status(-77)) => {}
        other => panic!("status -77 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_530_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(530)));
    match vm.run() {
        VMResult::Ok(Value::Status(530)) => {}
        other => panic!("exit code 530 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_seventy_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-78)));
    match vm.run() {
        VMResult::Ok(Value::Status(-78)) => {}
        other => panic!("status -78 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_531_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(531)));
    match vm.run() {
        VMResult::Ok(Value::Status(531)) => {}
        other => panic!("exit code 531 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_second_some_host_applies_on_thirty_second_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..32 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtySecondSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtySecondSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 32 {
                Some(532)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 4;
    vm.set_shell_host(Box::new(ThirtySecondSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(532)) => {}
        other => panic!(
            "thirty-second subshell_end(Some(532)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_532_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(532)));
    match vm.run() {
        VMResult::Ok(Value::Status(532)) => {}
        other => panic!("exit code 532 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_fifteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(533)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..12 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 15);
    assert_eq!(vm.last_status, 533);
}

#[test]
fn subshell_end_exit_code_533_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(533)));
    match vm.run() {
        VMResult::Ok(Value::Status(533)) => {}
        other => panic!("exit code 533 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_or_after_subshell_end_status534() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitOr, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(534)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 534);
}

#[test]
fn subshell_end_exit_code_534_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(534)));
    match vm.run() {
        VMResult::Ok(Value::Status(534)) => {}
        other => panic!("exit code 534 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eleven_begins_nine_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..11 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..9 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost535;
    impl ShellHost for CountingBeginEndHost535 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(535)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost535));
    match vm.run() {
        VMResult::Ok(Value::Status(535)) => {}
        other => panic!("ninth subshell_end(Some(535)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 11);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 9);
}

#[test]
fn subshell_end_exit_code_535_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(535)));
    match vm.run() {
        VMResult::Ok(Value::Status(535)) => {}
        other => panic!("exit code 535 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status536() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(536)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 536);
}

#[test]
fn subshell_end_exit_code_536_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(536)));
    match vm.run() {
        VMResult::Ok(Value::Status(536)) => {}
        other => panic!("exit code 536 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twelve_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(537)));
    for _ in 0..12 {
        match vm.run() {
            VMResult::Ok(Value::Status(537)) => {}
            other => panic!("reset run MUST return Status(537), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_537_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(537)));
    match vm.run() {
        VMResult::Ok(Value::Status(537)) => {}
        other => panic!("exit code 537 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status538() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(538)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 538);
}

#[test]
fn subshell_end_exit_code_538_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(538)));
    match vm.run() {
        VMResult::Ok(Value::Status(538)) => {}
        other => panic!("exit code 538 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_six_end_incrementing_from_twelve() {
    let mut b = ChunkBuilder::new();
    for _ in 0..76 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(87)) => {}
        other => panic!(
            "seventy-sixth subshell_end(Some(87)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_539_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(539)));
    match vm.run() {
        VMResult::Ok(Value::Status(539)) => {}
        other => panic!("exit code 539 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_inc_after_subshell_end_status540() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(14), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Inc, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(540)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 540);
}

#[test]
fn subshell_end_exit_code_540_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(540)));
    match vm.run() {
        VMResult::Ok(Value::Status(540)) => {}
        other => panic!("exit code 540 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dec_after_subshell_end_status541() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dec, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(541)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 541);
}

#[test]
fn subshell_end_exit_code_541_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(541)));
    match vm.run() {
        VMResult::Ok(Value::Status(541)) => {}
        other => panic!("exit code 541 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..91 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_542_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(542)));
    match vm.run() {
        VMResult::Ok(Value::Status(542)) => {}
        other => panic!("exit code 542 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_third_some_host_applies_on_thirty_third_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..33 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyThirdSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyThirdSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 33 {
                Some(543)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 6;
    vm.set_shell_host(Box::new(ThirtyThirdSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(543)) => {}
        other => panic!(
            "thirty-third subshell_end(Some(543)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_543_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(543)));
    match vm.run() {
        VMResult::Ok(Value::Status(543)) => {}
        other => panic!("exit code 543 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_sixteenth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 544,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(544)) => {}
        other => panic!(
            "FirstSomeThenNoneHost sixteenth None MUST keep first Some(544), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_544_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(544)));
    match vm.run() {
        VMResult::Ok(Value::Status(544)) => {}
        other => panic!("exit code 544 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pow_after_subshell_end_status545() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pow, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(545)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 545);
}

#[test]
fn subshell_end_exit_code_545_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(545)));
    match vm.run() {
        VMResult::Ok(Value::Status(545)) => {}
        other => panic!("exit code 545 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_sixteen_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 546;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(546)) => {}
        other => panic!(
            "NoneHost sixteen ends MUST leave last_status 546, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_546_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(546)));
    match vm.run() {
        VMResult::Ok(Value::Status(546)) => {}
        other => panic!("exit code 546 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status547() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost547 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost547 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-79)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost547 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -79, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_547_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(547)));
    match vm.run() {
        VMResult::Ok(Value::Status(547)) => {}
        other => panic!("exit code 547 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_rot_after_subshell_end_status548() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Rot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(548)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 548);
}

#[test]
fn subshell_end_exit_code_548_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(548)));
    match vm.run() {
        VMResult::Ok(Value::Status(548)) => {}
        other => panic!("exit code 548 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..92 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_549() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost549;
    impl ShellHost for SubshellThenPipelineHost549 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(11)
        }
        fn pipeline_end(&mut self) -> i32 {
            549
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost549));
    match vm.run() {
        VMResult::Ok(Value::Status(549)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 549, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_549_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(549)));
    match vm.run() {
        VMResult::Ok(Value::Status(549)) => {}
        other => panic!("exit code 549 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_seven_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..77 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(77)) => {}
        other => panic!(
            "seventy-seventh subshell_end(Some(77)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_550_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(550)));
    match vm.run() {
        VMResult::Ok(Value::Status(550)) => {}
        other => panic!("exit code 550 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_dup2_after_subshell_end_status551() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(10), 1);
    b.emit(Op::LoadInt(20), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Dup2, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(551)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 551);
}

#[test]
fn subshell_end_exit_code_551_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(551)));
    match vm.run() {
        VMResult::Ok(Value::Status(551)) => {}
        other => panic!("exit code 551 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..93 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_552_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(552)));
    match vm.run() {
        VMResult::Ok(Value::Status(552)) => {}
        other => panic!("exit code 552 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_sixteenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost sixteenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_553_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(553)));
    match vm.run() {
        VMResult::Ok(Value::Status(553)) => {}
        other => panic!("exit code 553 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch U (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_554_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(554)));
    match vm.run() {
        VMResult::Ok(Value::Status(554)) => {}
        other => panic!("exit code 554 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..94 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_555_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(555)));
    match vm.run() {
        VMResult::Ok(Value::Status(555)) => {}
        other => panic!("exit code 555 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..95 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_556_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(556)));
    match vm.run() {
        VMResult::Ok(Value::Status(556)) => {}
        other => panic!("exit code 556 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..96 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_557_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(557)));
    match vm.run() {
        VMResult::Ok(Value::Status(557)) => {}
        other => panic!("exit code 557 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_eight_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..78 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(79)) => {}
        other => panic!(
            "seventy-eighth subshell_end(Some(79)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_558_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(558)));
    match vm.run() {
        VMResult::Ok(Value::Status(558)) => {}
        other => panic!("exit code 558 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-80)));
    match vm.run() {
        VMResult::Ok(Value::Status(-80)) => {}
        other => panic!("status -80 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_559_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(559)));
    match vm.run() {
        VMResult::Ok(Value::Status(559)) => {}
        other => panic!("exit code 559 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-81)));
    match vm.run() {
        VMResult::Ok(Value::Status(-81)) => {}
        other => panic!("status -81 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_560_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(560)));
    match vm.run() {
        VMResult::Ok(Value::Status(560)) => {}
        other => panic!("exit code 560 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_fourth_some_host_applies_on_thirty_fourth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..34 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyFourthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyFourthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 34 {
                Some(561)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 7;
    vm.set_shell_host(Box::new(ThirtyFourthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(561)) => {}
        other => panic!(
            "thirty-fourth subshell_end(Some(561)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_561_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(561)));
    match vm.run() {
        VMResult::Ok(Value::Status(561)) => {}
        other => panic!("exit code 561 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_sixteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(562)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..13 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 16);
    assert_eq!(vm.last_status, 562);
}

#[test]
fn subshell_end_exit_code_562_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(562)));
    match vm.run() {
        VMResult::Ok(Value::Status(562)) => {}
        other => panic!("exit code 562 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status563() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(12), 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(563)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 563);
}

#[test]
fn subshell_end_exit_code_563_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(563)));
    match vm.run() {
        VMResult::Ok(Value::Status(563)) => {}
        other => panic!("exit code 563 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twelve_begins_ten_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..12 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..10 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost564;
    impl ShellHost for CountingBeginEndHost564 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(564)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost564));
    match vm.run() {
        VMResult::Ok(Value::Status(564)) => {}
        other => panic!("tenth subshell_end(Some(564)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 12);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 10);
}

#[test]
fn subshell_end_exit_code_564_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(564)));
    match vm.run() {
        VMResult::Ok(Value::Status(564)) => {}
        other => panic!("exit code 564 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_not_after_subshell_end_status565() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(565)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 565);
}

#[test]
fn subshell_end_exit_code_565_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(565)));
    match vm.run() {
        VMResult::Ok(Value::Status(565)) => {}
        other => panic!("exit code 565 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(566)));
    for _ in 0..13 {
        match vm.run() {
            VMResult::Ok(Value::Status(566)) => {}
            other => panic!("reset run MUST return Status(566), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_566_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(566)));
    match vm.run() {
        VMResult::Ok(Value::Status(566)) => {}
        other => panic!("exit code 566 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_shl_after_subshell_end_status567() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Shl, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(567)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 567);
}

#[test]
fn subshell_end_exit_code_567_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(567)));
    match vm.run() {
        VMResult::Ok(Value::Status(567)) => {}
        other => panic!("exit code 567 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_nine_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..79 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(84)) => {}
        other => panic!(
            "seventy-ninth subshell_end(Some(84)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_568_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(568)));
    match vm.run() {
        VMResult::Ok(Value::Status(568)) => {}
        other => panic!("exit code 568 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_shr_after_subshell_end_status569() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(16), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Shr, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(569)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 569);
}

#[test]
fn subshell_end_exit_code_569_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(569)));
    match vm.run() {
        VMResult::Ok(Value::Status(569)) => {}
        other => panic!("exit code 569 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..97 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_570_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(570)));
    match vm.run() {
        VMResult::Ok(Value::Status(570)) => {}
        other => panic!("exit code 570 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..98 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_571_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(571)));
    match vm.run() {
        VMResult::Ok(Value::Status(571)) => {}
        other => panic!("exit code 571 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_after_subshell_end_status572() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Pop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(572)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 572);
}

#[test]
fn subshell_end_exit_code_572_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(572)));
    match vm.run() {
        VMResult::Ok(Value::Status(572)) => {}
        other => panic!("exit code 572 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..80 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(80)) => {}
        other => panic!("eightieth subshell_end(Some(80)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_573_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(573)));
    match vm.run() {
        VMResult::Ok(Value::Status(573)) => {}
        other => panic!("exit code 573 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_and_after_subshell_end_status574() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogAnd, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(574)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 574);
}

#[test]
fn subshell_end_exit_code_574_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(574)));
    match vm.run() {
        VMResult::Ok(Value::Status(574)) => {}
        other => panic!("exit code 574 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-82)));
    match vm.run() {
        VMResult::Ok(Value::Status(-82)) => {}
        other => panic!("status -82 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_575_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(575)));
    match vm.run() {
        VMResult::Ok(Value::Status(575)) => {}
        other => panic!("exit code 575 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_or_after_subshell_end_status576() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::LoadTrue, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogOr, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(576)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 576);
}

#[test]
fn subshell_end_exit_code_576_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(576)));
    match vm.run() {
        VMResult::Ok(Value::Status(576)) => {}
        other => panic!("exit code 576 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_seventeen_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 577;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(577)) => {}
        other => panic!(
            "NoneHost seventeen ends MUST leave last_status 577, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_577_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(577)));
    match vm.run() {
        VMResult::Ok(Value::Status(577)) => {}
        other => panic!("exit code 577 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_seventeenth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 578,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(578)) => {}
        other => panic!(
            "FirstSomeThenNoneHost seventeenth None MUST keep first Some(578), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_578_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(578)));
    match vm.run() {
        VMResult::Ok(Value::Status(578)) => {}
        other => panic!("exit code 578 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch V (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_579_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(579)));
    match vm.run() {
        VMResult::Ok(Value::Status(579)) => {}
        other => panic!("exit code 579 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_ninety_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..99 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_580_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(580)));
    match vm.run() {
        VMResult::Ok(Value::Status(580)) => {}
        other => panic!("exit code 580 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..100 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_581_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(581)));
    match vm.run() {
        VMResult::Ok(Value::Status(581)) => {}
        other => panic!("exit code 581 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..101 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_582_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(582)));
    match vm.run() {
        VMResult::Ok(Value::Status(582)) => {}
        other => panic!("exit code 582 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_one_end_incrementing_from_fifteen() {
    let mut b = ChunkBuilder::new();
    for _ in 0..81 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 15 }));
    match vm.run() {
        VMResult::Ok(Value::Status(95)) => {}
        other => panic!(
            "eighty-first subshell_end(Some(95)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_583_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(583)));
    match vm.run() {
        VMResult::Ok(Value::Status(583)) => {}
        other => panic!("exit code 583 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-83)));
    match vm.run() {
        VMResult::Ok(Value::Status(-83)) => {}
        other => panic!("status -83 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_584_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(584)));
    match vm.run() {
        VMResult::Ok(Value::Status(584)) => {}
        other => panic!("exit code 584 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-84)));
    match vm.run() {
        VMResult::Ok(Value::Status(-84)) => {}
        other => panic!("status -84 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_585_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(585)));
    match vm.run() {
        VMResult::Ok(Value::Status(585)) => {}
        other => panic!("exit code 585 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_fifth_some_host_applies_on_thirty_fifth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..35 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyFifthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyFifthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 35 {
                Some(586)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(ThirtyFifthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(586)) => {}
        other => panic!(
            "thirty-fifth subshell_end(Some(586)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_586_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(586)));
    match vm.run() {
        VMResult::Ok(Value::Status(586)) => {}
        other => panic!("exit code 586 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_seventeenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(587)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..14 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 17);
    assert_eq!(vm.last_status, 587);
}

#[test]
fn subshell_end_exit_code_587_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(587)));
    match vm.run() {
        VMResult::Ok(Value::Status(587)) => {}
        other => panic!("exit code 587 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status588() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(3.14), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(588)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 588);
}

#[test]
fn subshell_end_exit_code_588_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(588)));
    match vm.run() {
        VMResult::Ok(Value::Status(588)) => {}
        other => panic!("exit code 588 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirteen_begins_eleven_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..13 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..11 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost589;
    impl ShellHost for CountingBeginEndHost589 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(589)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost589));
    match vm.run() {
        VMResult::Ok(Value::Status(589)) => {}
        other => panic!("eleventh subshell_end(Some(589)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 13);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 11);
}

#[test]
fn subshell_end_exit_code_589_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(589)));
    match vm.run() {
        VMResult::Ok(Value::Status(589)) => {}
        other => panic!("exit code 589 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status590() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("a"));
        let bidx = cb.add_constant(Value::str("b"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(590)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 590);
}

#[test]
fn subshell_end_exit_code_590_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(590)));
    match vm.run() {
        VMResult::Ok(Value::Status(590)) => {}
        other => panic!("exit code 590 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fourteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(591)));
    for _ in 0..14 {
        match vm.run() {
            VMResult::Ok(Value::Status(591)) => {}
            other => panic!("reset run MUST return Status(591), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_591_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(591)));
    match vm.run() {
        VMResult::Ok(Value::Status(591)) => {}
        other => panic!("exit code 591 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_eq_after_subshell_end_status592() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("x"));
        let bidx = cb.add_constant(Value::str("x"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrEq, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(592)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 592);
}

#[test]
fn subshell_end_exit_code_592_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(592)));
    match vm.run() {
        VMResult::Ok(Value::Status(592)) => {}
        other => panic!("exit code 592 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_two_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..82 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(85)) => {}
        other => panic!(
            "eighty-second subshell_end(Some(85)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_593_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(593)));
    match vm.run() {
        VMResult::Ok(Value::Status(593)) => {}
        other => panic!("exit code 593 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ne_after_subshell_end_status594() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("a"));
        let bidx = cb.add_constant(Value::str("b"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrNe, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(594)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 594);
}

#[test]
fn subshell_end_exit_code_594_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(594)));
    match vm.run() {
        VMResult::Ok(Value::Status(594)) => {}
        other => panic!("exit code 594 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost595 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost595 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-85)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost595 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -85, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_595_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(595)));
    match vm.run() {
        VMResult::Ok(Value::Status(595)) => {}
        other => panic!("exit code 595 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..102 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_596_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(596)));
    match vm.run() {
        VMResult::Ok(Value::Status(596)) => {}
        other => panic!("exit code 596 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_sixth_some_host_applies_on_thirty_sixth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..36 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtySixthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtySixthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 36 {
                Some(597)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(ThirtySixthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(597)) => {}
        other => panic!(
            "thirty-sixth subshell_end(Some(597)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_597_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(597)));
    match vm.run() {
        VMResult::Ok(Value::Status(597)) => {}
        other => panic!("exit code 597 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_seventeenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost seventeenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_598_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(598)));
    match vm.run() {
        VMResult::Ok(Value::Status(598)) => {}
        other => panic!("exit code 598 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_lt_after_subshell_end_status599() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("a"));
        let bidx = cb.add_constant(Value::str("z"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrLt, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(599)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 599);
}

#[test]
fn subshell_end_exit_code_599_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(599)));
    match vm.run() {
        VMResult::Ok(Value::Status(599)) => {}
        other => panic!("exit code 599 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_600() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost600;
    impl ShellHost for PipelineSubshellHost600 {
        fn pipeline_end(&mut self) -> i32 {
            4
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(600)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost600));
    match vm.run() {
        VMResult::Ok(Value::Status(600)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 600, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_600_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(600)));
    match vm.run() {
        VMResult::Ok(Value::Status(600)) => {}
        other => panic!("exit code 600 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_gt_after_subshell_end_status601() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("z"));
        let bidx = cb.add_constant(Value::str("a"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrGt, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(601)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 601);
}

#[test]
fn subshell_end_exit_code_601_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(601)));
    match vm.run() {
        VMResult::Ok(Value::Status(601)) => {}
        other => panic!("exit code 601 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_three_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..83 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(89)) => {}
        other => panic!(
            "eighty-third subshell_end(Some(89)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_602_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(602)));
    match vm.run() {
        VMResult::Ok(Value::Status(602)) => {}
        other => panic!("exit code 602 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_le_after_subshell_end_status603() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("a"));
        let bidx = cb.add_constant(Value::str("a"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrLe, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(603)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 603);
}

#[test]
fn subshell_end_exit_code_603_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(603)));
    match vm.run() {
        VMResult::Ok(Value::Status(603)) => {}
        other => panic!("exit code 603 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..103 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_604_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(604)));
    match vm.run() {
        VMResult::Ok(Value::Status(604)) => {}
        other => panic!("exit code 604 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_ge_after_subshell_end_status605() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("z"));
        let bidx = cb.add_constant(Value::str("a"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrGe, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(605)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 605);
}

#[test]
fn subshell_end_exit_code_605_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(605)));
    match vm.run() {
        VMResult::Ok(Value::Status(605)) => {}
        other => panic!("exit code 605 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-86)));
    match vm.run() {
        VMResult::Ok(Value::Status(-86)) => {}
        other => panic!("status -86 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_606_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(606)));
    match vm.run() {
        VMResult::Ok(Value::Status(606)) => {}
        other => panic!("exit code 606 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_607() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost607;
    impl ShellHost for SubshellThenPipelineHost607 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(13)
        }
        fn pipeline_end(&mut self) -> i32 {
            607
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost607));
    match vm.run() {
        VMResult::Ok(Value::Status(607)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 607, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_607_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(607)));
    match vm.run() {
        VMResult::Ok(Value::Status(607)) => {}
        other => panic!("exit code 607 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_four_end_incrementing_from_ten() {
    let mut b = ChunkBuilder::new();
    for _ in 0..84 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(93)) => {}
        other => panic!(
            "eighty-fourth subshell_end(Some(93)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_608_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(608)));
    match vm.run() {
        VMResult::Ok(Value::Status(608)) => {}
        other => panic!("exit code 608 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..104 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_609_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(609)));
    match vm.run() {
        VMResult::Ok(Value::Status(609)) => {}
        other => panic!("exit code 609 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch W (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_610_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(610)));
    match vm.run() {
        VMResult::Ok(Value::Status(610)) => {}
        other => panic!("exit code 610 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..105 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_611_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(611)));
    match vm.run() {
        VMResult::Ok(Value::Status(611)) => {}
        other => panic!("exit code 611 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..106 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_612_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(612)));
    match vm.run() {
        VMResult::Ok(Value::Status(612)) => {}
        other => panic!("exit code 612 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..107 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_613_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(613)));
    match vm.run() {
        VMResult::Ok(Value::Status(613)) => {}
        other => panic!("exit code 613 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_five_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..85 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(86)) => {}
        other => panic!(
            "eighty-fifth subshell_end(Some(86)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_614_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(614)));
    match vm.run() {
        VMResult::Ok(Value::Status(614)) => {}
        other => panic!("exit code 614 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_seven_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-87)));
    match vm.run() {
        VMResult::Ok(Value::Status(-87)) => {}
        other => panic!("status -87 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_615_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(615)));
    match vm.run() {
        VMResult::Ok(Value::Status(615)) => {}
        other => panic!("exit code 615 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-88)));
    match vm.run() {
        VMResult::Ok(Value::Status(-88)) => {}
        other => panic!("status -88 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_616_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(616)));
    match vm.run() {
        VMResult::Ok(Value::Status(616)) => {}
        other => panic!("exit code 616 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_seventh_some_host_applies_on_thirty_seventh_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..37 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtySeventhSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtySeventhSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 37 {
                Some(617)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(ThirtySeventhSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(617)) => {}
        other => panic!(
            "thirty-seventh subshell_end(Some(617)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_617_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(617)));
    match vm.run() {
        VMResult::Ok(Value::Status(617)) => {}
        other => panic!("exit code 617 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_eighteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(618)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..15 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 18);
    assert_eq!(vm.last_status, 618);
}

#[test]
fn subshell_end_exit_code_618_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(618)));
    match vm.run() {
        VMResult::Ok(Value::Status(618)) => {}
        other => panic!("exit code 618 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_len_after_subshell_end_status619() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let s = cb.add_constant(Value::str("abc"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(s), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StringLen, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(619)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 619);
}

#[test]
fn subshell_end_exit_code_619_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(619)));
    match vm.run() {
        VMResult::Ok(Value::Status(619)) => {}
        other => panic!("exit code 619 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fourteen_begins_twelve_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..14 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..12 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost620;
    impl ShellHost for CountingBeginEndHost620 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(620)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost620));
    match vm.run() {
        VMResult::Ok(Value::Status(620)) => {}
        other => panic!("twelfth subshell_end(Some(620)) MUST win, got {:?}", other),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 14);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 12);
}

#[test]
fn subshell_end_exit_code_620_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(620)));
    match vm.run() {
        VMResult::Ok(Value::Status(620)) => {}
        other => panic!("exit code 620 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_string_repeat_after_subshell_end_status621() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let s = cb.add_constant(Value::str("x"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(s), 1);
        cb.emit(Op::LoadInt(3), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StringRepeat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(621)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 621);
}

#[test]
fn subshell_end_exit_code_621_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(621)));
    match vm.run() {
        VMResult::Ok(Value::Status(621)) => {}
        other => panic!("exit code 621 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(622)));
    for _ in 0..15 {
        match vm.run() {
            VMResult::Ok(Value::Status(622)) => {}
            other => panic!("reset run MUST return Status(622), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_622_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(622)));
    match vm.run() {
        VMResult::Ok(Value::Status(622)) => {}
        other => panic!("exit code 622 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_range_after_subshell_end_status623() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Range, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(623)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 623);
}

#[test]
fn subshell_end_exit_code_623_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(623)));
    match vm.run() {
        VMResult::Ok(Value::Status(623)) => {}
        other => panic!("exit code 623 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_six_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..86 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(94)) => {}
        other => panic!(
            "eighty-sixth subshell_end(Some(94)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_624_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(624)));
    match vm.run() {
        VMResult::Ok(Value::Status(624)) => {}
        other => panic!("exit code 624 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_range_step_after_subshell_end_status625() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(0), 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::RangeStep, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(625)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 625);
}

#[test]
fn subshell_end_exit_code_625_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(625)));
    match vm.run() {
        VMResult::Ok(Value::Status(625)) => {}
        other => panic!("exit code 625 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..108 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_626_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(626)));
    match vm.run() {
        VMResult::Ok(Value::Status(626)) => {}
        other => panic!("exit code 626 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..109 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_627_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(627)));
    match vm.run() {
        VMResult::Ok(Value::Status(627)) => {}
        other => panic!("exit code 627 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_hash_after_subshell_end_status628() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let k = cb.add_constant(Value::str("a"));
        let v = cb.add_constant(Value::str("b"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(k), 1);
        cb.emit(Op::LoadConst(v), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::MakeHash(1), 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(628)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 628);
}

#[test]
fn subshell_end_exit_code_628_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(628)));
    match vm.run() {
        VMResult::Ok(Value::Status(628)) => {}
        other => panic!("exit code 628 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_eighteenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost eighteenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_629_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(629)));
    match vm.run() {
        VMResult::Ok(Value::Status(629)) => {}
        other => panic!("exit code 629 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_eighteen_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 630;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(630)) => {}
        other => panic!(
            "NoneHost eighteen ends MUST leave last_status 630, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_630_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(630)));
    match vm.run() {
        VMResult::Ok(Value::Status(630)) => {}
        other => panic!("exit code 630 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_eighteenth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 631,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(631)) => {}
        other => panic!(
            "FirstSomeThenNoneHost eighteenth None MUST keep first Some(631), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_631_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(631)));
    match vm.run() {
        VMResult::Ok(Value::Status(631)) => {}
        other => panic!("exit code 631 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_eighty_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-89)));
    match vm.run() {
        VMResult::Ok(Value::Status(-89)) => {}
        other => panic!("status -89 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_632_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(632)));
    match vm.run() {
        VMResult::Ok(Value::Status(632)) => {}
        other => panic!("exit code 632 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_setstatus_after_subshell_end_status633() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(99), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SetStatus, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(633)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 633);
}

#[test]
fn subshell_end_exit_code_633_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(633)));
    match vm.run() {
        VMResult::Ok(Value::Status(633)) => {}
        other => panic!("exit code 633 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_seven_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..87 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(90)) => {}
        other => panic!(
            "eighty-seventh subshell_end(Some(90)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_634_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(634)));
    match vm.run() {
        VMResult::Ok(Value::Status(634)) => {}
        other => panic!("exit code 634 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch X (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_635_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(635)));
    match vm.run() {
        VMResult::Ok(Value::Status(635)) => {}
        other => panic!("exit code 635 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ten_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..110 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_636_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(636)));
    match vm.run() {
        VMResult::Ok(Value::Status(636)) => {}
        other => panic!("exit code 636 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eleven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..111 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_637_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(637)));
    match vm.run() {
        VMResult::Ok(Value::Status(637)) => {}
        other => panic!("exit code 637 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twelve_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..112 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_638_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(638)));
    match vm.run() {
        VMResult::Ok(Value::Status(638)) => {}
        other => panic!("exit code 638 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_eight_end_incrementing_from_eleven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..88 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(98)) => {}
        other => panic!(
            "eighty-eighth subshell_end(Some(98)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_639_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(639)));
    match vm.run() {
        VMResult::Ok(Value::Status(639)) => {}
        other => panic!("exit code 639 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-90)));
    match vm.run() {
        VMResult::Ok(Value::Status(-90)) => {}
        other => panic!("status -90 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_640_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(640)));
    match vm.run() {
        VMResult::Ok(Value::Status(640)) => {}
        other => panic!("exit code 640 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-91)));
    match vm.run() {
        VMResult::Ok(Value::Status(-91)) => {}
        other => panic!("status -91 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_641_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(641)));
    match vm.run() {
        VMResult::Ok(Value::Status(641)) => {}
        other => panic!("exit code 641 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_eighth_some_host_applies_on_thirty_eighth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..38 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyEighthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyEighthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 38 {
                Some(642)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 1;
    vm.set_shell_host(Box::new(ThirtyEighthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(642)) => {}
        other => panic!(
            "thirty-eighth subshell_end(Some(642)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_642_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(642)));
    match vm.run() {
        VMResult::Ok(Value::Status(642)) => {}
        other => panic!("exit code 642 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_nineteenth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(643)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..16 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 19);
    assert_eq!(vm.last_status, 643);
}

#[test]
fn subshell_end_exit_code_643_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(643)));
    match vm.run() {
        VMResult::Ok(Value::Status(643)) => {}
        other => panic!("exit code 643 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_push_frame_after_subshell_end_status644() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(644)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 644);
}

#[test]
fn subshell_end_exit_code_644_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(644)));
    match vm.run() {
        VMResult::Ok(Value::Status(644)) => {}
        other => panic!("exit code 644 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifteen_begins_thirteen_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..15 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..13 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost645;
    impl ShellHost for CountingBeginEndHost645 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(645)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost645));
    match vm.run() {
        VMResult::Ok(Value::Status(645)) => {}
        other => panic!(
            "thirteenth subshell_end(Some(645)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 15);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 13);
}

#[test]
fn subshell_end_exit_code_645_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(645)));
    match vm.run() {
        VMResult::Ok(Value::Status(645)) => {}
        other => panic!("exit code 645 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pop_frame_after_subshell_end_status646() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PushFrame, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PopFrame, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(646)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 646);
}

#[test]
fn subshell_end_exit_code_646_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(646)));
    match vm.run() {
        VMResult::Ok(Value::Status(646)) => {}
        other => panic!("exit code 646 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(647)));
    for _ in 0..16 {
        match vm.run() {
            VMResult::Ok(Value::Status(647)) => {}
            other => panic!("reset run MUST return Status(647), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_647_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(647)));
    match vm.run() {
        VMResult::Ok(Value::Status(647)) => {}
        other => panic!("exit code 647 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_return_after_subshell_end_status648() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Return, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(648)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 648);
}

#[test]
fn subshell_end_exit_code_648_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(648)));
    match vm.run() {
        VMResult::Ok(Value::Status(648)) => {}
        other => panic!("exit code 648 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_nine_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..89 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(91)) => {}
        other => panic!(
            "eighty-ninth subshell_end(Some(91)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_649_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(649)));
    match vm.run() {
        VMResult::Ok(Value::Status(649)) => {}
        other => panic!("exit code 649 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_return_value_after_subshell_end_status650() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(42), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::ReturnValue, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(650)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 650);
}

#[test]
fn subshell_end_exit_code_650_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(650)));
    match vm.run() {
        VMResult::Ok(Value::Status(650)) => {}
        other => panic!("exit code 650 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost651 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost651 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-92)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost651 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -92, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_651_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(651)));
    match vm.run() {
        VMResult::Ok(Value::Status(651)) => {}
        other => panic!("exit code 651 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..113 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_652_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(652)));
    match vm.run() {
        VMResult::Ok(Value::Status(652)) => {}
        other => panic!("exit code 652 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_ninth_some_host_applies_on_thirty_ninth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..39 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct ThirtyNinthSomeHost {
        calls: u32,
    }
    impl ShellHost for ThirtyNinthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 39 {
                Some(653)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 9;
    vm.set_shell_host(Box::new(ThirtyNinthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(653)) => {}
        other => panic!(
            "thirty-ninth subshell_end(Some(653)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_653_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(653)));
    match vm.run() {
        VMResult::Ok(Value::Status(653)) => {}
        other => panic!("exit code 653 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_nineteenth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost nineteenth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_654_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(654)));
    match vm.run() {
        VMResult::Ok(Value::Status(654)) => {}
        other => panic!("exit code 654 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pipeline_begin_after_subshell_end_status655() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(655)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 655);
}

#[test]
fn subshell_end_exit_code_655_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(655)));
    match vm.run() {
        VMResult::Ok(Value::Status(655)) => {}
        other => panic!("exit code 655 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pipeline_stage_after_subshell_end_status656() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineStage, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(656)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 656);
}

#[test]
fn subshell_end_exit_code_656_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(656)));
    match vm.run() {
        VMResult::Ok(Value::Status(656)) => {}
        other => panic!("exit code 656 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..90 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(94)) => {}
        other => panic!("ninetieth subshell_end(Some(94)) MUST win, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_657_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(657)));
    match vm.run() {
        VMResult::Ok(Value::Status(657)) => {}
        other => panic!("exit code 657 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_pipeline_end_after_subshell_end_status658() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(658)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 658);
}

#[test]
fn subshell_end_exit_code_658_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(658)));
    match vm.run() {
        VMResult::Ok(Value::Status(658)) => {}
        other => panic!("exit code 658 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fourteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..114 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_659_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(659)));
    match vm.run() {
        VMResult::Ok(Value::Status(659)) => {}
        other => panic!("exit code 659 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fortieth_some_host_applies_on_fortieth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..40 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortiethSomeHost {
        calls: u32,
    }
    impl ShellHost for FortiethSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 40 {
                Some(660)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortiethSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(660)) => {}
        other => panic!(
            "fortieth subshell_end(Some(660)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_660_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(660)));
    match vm.run() {
        VMResult::Ok(Value::Status(660)) => {}
        other => panic!("exit code 660 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_661() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost661;
    impl ShellHost for PipelineSubshellHost661 {
        fn pipeline_end(&mut self) -> i32 {
            5
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(661)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost661));
    match vm.run() {
        VMResult::Ok(Value::Status(661)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 661, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_661_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(661)));
    match vm.run() {
        VMResult::Ok(Value::Status(661)) => {}
        other => panic!("exit code 661 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_662() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost662;
    impl ShellHost for SubshellThenPipelineHost662 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(14)
        }
        fn pipeline_end(&mut self) -> i32 {
            662
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost662));
    match vm.run() {
        VMResult::Ok(Value::Status(662)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 662, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_662_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(662)));
    match vm.run() {
        VMResult::Ok(Value::Status(662)) => {}
        other => panic!("exit code 662 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-93)));
    match vm.run() {
        VMResult::Ok(Value::Status(-93)) => {}
        other => panic!("status -93 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_663_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(663)));
    match vm.run() {
        VMResult::Ok(Value::Status(663)) => {}
        other => panic!("exit code 663 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_one_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..91 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(96)) => {}
        other => panic!(
            "ninety-first subshell_end(Some(96)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_664_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(664)));
    match vm.run() {
        VMResult::Ok(Value::Status(664)) => {}
        other => panic!("exit code 664 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..115 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_665_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(665)));
    match vm.run() {
        VMResult::Ok(Value::Status(665)) => {}
        other => panic!("exit code 665 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch Y (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_666_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(666)));
    match vm.run() {
        VMResult::Ok(Value::Status(666)) => {}
        other => panic!("exit code 666 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..116 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_667_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(667)));
    match vm.run() {
        VMResult::Ok(Value::Status(667)) => {}
        other => panic!("exit code 667 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventeen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..117 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_668_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(668)));
    match vm.run() {
        VMResult::Ok(Value::Status(668)) => {}
        other => panic!("exit code 668 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..118 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_669_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(669)));
    match vm.run() {
        VMResult::Ok(Value::Status(669)) => {}
        other => panic!("exit code 669 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_two_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..92 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(98)) => {}
        other => panic!(
            "ninety-second subshell_end(Some(98)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_670_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(670)));
    match vm.run() {
        VMResult::Ok(Value::Status(670)) => {}
        other => panic!("exit code 670 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-94)));
    match vm.run() {
        VMResult::Ok(Value::Status(-94)) => {}
        other => panic!("status -94 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_671_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(671)));
    match vm.run() {
        VMResult::Ok(Value::Status(671)) => {}
        other => panic!("exit code 671 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-95)));
    match vm.run() {
        VMResult::Ok(Value::Status(-95)) => {}
        other => panic!("status -95 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_672_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(672)));
    match vm.run() {
        VMResult::Ok(Value::Status(672)) => {}
        other => panic!("exit code 672 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_first_some_host_applies_on_forty_first_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..41 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFirstSomeHost {
        calls: u32,
    }
    impl ShellHost for FortyFirstSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 41 {
                Some(673)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 4;
    vm.set_shell_host(Box::new(FortyFirstSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(673)) => {}
        other => panic!(
            "forty-first subshell_end(Some(673)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_673_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(673)));
    match vm.run() {
        VMResult::Ok(Value::Status(673)) => {}
        other => panic!("exit code 673 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twentieth_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(674)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..17 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 20);
    assert_eq!(vm.last_status, 674);
}

#[test]
fn subshell_end_exit_code_674_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(674)));
    match vm.run() {
        VMResult::Ok(Value::Status(674)) => {}
        other => panic!("exit code 674 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_subshell_begin_after_subshell_end_status675() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(675)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 675);
}

#[test]
fn subshell_end_exit_code_675_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(675)));
    match vm.run() {
        VMResult::Ok(Value::Status(675)) => {}
        other => panic!("exit code 675 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixteen_begins_fourteen_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..16 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..14 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost676;
    impl ShellHost for CountingBeginEndHost676 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(676)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost676));
    match vm.run() {
        VMResult::Ok(Value::Status(676)) => {}
        other => panic!(
            "fourteenth subshell_end(Some(676)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 16);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 14);
}

#[test]
fn subshell_end_exit_code_676_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(676)));
    match vm.run() {
        VMResult::Ok(Value::Status(676)) => {}
        other => panic!("exit code 676 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_nop_after_subshell_end_status677() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Nop, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(677)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 677);
}

#[test]
fn subshell_end_exit_code_677_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(677)));
    match vm.run() {
        VMResult::Ok(Value::Status(677)) => {}
        other => panic!("exit code 677 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventeen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(678)));
    for _ in 0..17 {
        match vm.run() {
            VMResult::Ok(Value::Status(678)) => {}
            other => panic!("reset run MUST return Status(678), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_678_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(678)));
    match vm.run() {
        VMResult::Ok(Value::Status(678)) => {}
        other => panic!("exit code 678 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_str_cmp_after_subshell_end_status679() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("cat"));
        let bidx = cb.add_constant(Value::str("dog"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::StrCmp, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(679)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 679);
}

#[test]
fn subshell_end_exit_code_679_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(679)));
    match vm.run() {
        VMResult::Ok(Value::Status(679)) => {}
        other => panic!("exit code 679 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_three_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..93 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(100)) => {}
        other => panic!(
            "ninety-third subshell_end(Some(100)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_680_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(680)));
    match vm.run() {
        VMResult::Ok(Value::Status(680)) => {}
        other => panic!("exit code 680 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_getstatus_after_subshell_end_status681() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::GetStatus, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(681)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 681);
}

#[test]
fn subshell_end_exit_code_681_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(681)));
    match vm.run() {
        VMResult::Ok(Value::Status(681)) => {}
        other => panic!("exit code 681 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_nineteen_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..119 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_682_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(682)));
    match vm.run() {
        VMResult::Ok(Value::Status(682)) => {}
        other => panic!("exit code 682 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..120 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_683_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(683)));
    match vm.run() {
        VMResult::Ok(Value::Status(683)) => {}
        other => panic!("exit code 683 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twentieth_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twentieth None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_684_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(684)));
    match vm.run() {
        VMResult::Ok(Value::Status(684)) => {}
        other => panic!("exit code 684 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_nineteen_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 685;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(685)) => {}
        other => panic!(
            "NoneHost nineteen ends MUST leave last_status 685, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_685_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(685)));
    match vm.run() {
        VMResult::Ok(Value::Status(685)) => {}
        other => panic!("exit code 685 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_nineteenth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 686,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(686)) => {}
        other => panic!(
            "FirstSomeThenNoneHost nineteenth None MUST keep first Some(686), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_686_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(686)));
    match vm.run() {
        VMResult::Ok(Value::Status(686)) => {}
        other => panic!("exit code 686 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-96)));
    match vm.run() {
        VMResult::Ok(Value::Status(-96)) => {}
        other => panic!("status -96 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_687_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(687)));
    match vm.run() {
        VMResult::Ok(Value::Status(687)) => {}
        other => panic!("exit code 687 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_four_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..94 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(94)) => {}
        other => panic!(
            "ninety-fourth subshell_end(Some(94)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_688_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(688)));
    match vm.run() {
        VMResult::Ok(Value::Status(688)) => {}
        other => panic!("exit code 688 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_const_after_subshell_end_status689() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let c = cb.add_constant(Value::Int(55));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::LoadConst(c), 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(689)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 689);
}

#[test]
fn subshell_end_exit_code_689_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(689)));
    match vm.run() {
        VMResult::Ok(Value::Status(689)) => {}
        other => panic!("exit code 689 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status690() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost690 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost690 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-97)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost690 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -97, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_690_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(690)));
    match vm.run() {
        VMResult::Ok(Value::Status(690)) => {}
        other => panic!("exit code 690 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch Z (handwritten) ──────────────────────────────────────

#[test]
fn subshell_end_exit_code_691_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(691)));
    match vm.run() {
        VMResult::Ok(Value::Status(691)) => {}
        other => panic!("exit code 691 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..121 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_692_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(692)));
    match vm.run() {
        VMResult::Ok(Value::Status(692)) => {}
        other => panic!("exit code 692 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..122 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_693_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(693)));
    match vm.run() {
        VMResult::Ok(Value::Status(693)) => {}
        other => panic!("exit code 693 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..123 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_694_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(694)));
    match vm.run() {
        VMResult::Ok(Value::Status(694)) => {}
        other => panic!("exit code 694 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_five_end_incrementing_from_twelve() {
    let mut b = ChunkBuilder::new();
    for _ in 0..95 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(106)) => {}
        other => panic!(
            "ninety-fifth subshell_end(Some(106)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_695_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(695)));
    match vm.run() {
        VMResult::Ok(Value::Status(695)) => {}
        other => panic!("exit code 695 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_eight_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-98)));
    match vm.run() {
        VMResult::Ok(Value::Status(-98)) => {}
        other => panic!("status -98 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_696_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(696)));
    match vm.run() {
        VMResult::Ok(Value::Status(696)) => {}
        other => panic!("exit code 696 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_ninety_nine_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-99)));
    match vm.run() {
        VMResult::Ok(Value::Status(-99)) => {}
        other => panic!("status -99 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_697_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(697)));
    match vm.run() {
        VMResult::Ok(Value::Status(697)) => {}
        other => panic!("exit code 697 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_second_some_host_applies_on_forty_second_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..42 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySecondSomeHost {
        calls: u32,
    }
    impl ShellHost for FortySecondSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 42 {
                Some(698)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 6;
    vm.set_shell_host(Box::new(FortySecondSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(698)) => {}
        other => panic!(
            "forty-second subshell_end(Some(698)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_698_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(698)));
    match vm.run() {
        VMResult::Ok(Value::Status(698)) => {}
        other => panic!("exit code 698 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_first_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(699)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..18 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 21);
    assert_eq!(vm.last_status, 699);
}

#[test]
fn subshell_end_exit_code_699_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(699)));
    match vm.run() {
        VMResult::Ok(Value::Status(699)) => {}
        other => panic!("exit code 699 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_true_after_subshell_end_status700() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(5), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::NumLt, 1);
    let jmp = b.emit(Op::JumpIfTrue(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(700)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 700);
}

#[test]
fn subshell_end_exit_code_700_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(700)));
    match vm.run() {
        VMResult::Ok(Value::Status(700)) => {}
        other => panic!("exit code 700 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventeen_begins_fifteen_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..17 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..15 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost701;
    impl ShellHost for CountingBeginEndHost701 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(701)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost701));
    match vm.run() {
        VMResult::Ok(Value::Status(701)) => {}
        other => panic!(
            "fifteenth subshell_end(Some(701)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 17);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 15);
}

#[test]
fn subshell_end_exit_code_701_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(701)));
    match vm.run() {
        VMResult::Ok(Value::Status(701)) => {}
        other => panic!("exit code 701 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_false_after_subshell_end_status702() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::LoadInt(4), 1);
    b.emit(Op::NumEq, 1);
    let jmp = b.emit(Op::JumpIfFalse(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(702)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 702);
}

#[test]
fn subshell_end_exit_code_702_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(702)));
    match vm.run() {
        VMResult::Ok(Value::Status(702)) => {}
        other => panic!("exit code 702 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(703)));
    for _ in 0..18 {
        match vm.run() {
            VMResult::Ok(Value::Status(703)) => {}
            other => panic!("reset run MUST return Status(703), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_703_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(703)));
    match vm.run() {
        VMResult::Ok(Value::Status(703)) => {}
        other => panic!("exit code 703 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_true_keep_after_subshell_end_status704() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    let jmp = b.emit(Op::JumpIfTrueKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(704)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 704);
}

#[test]
fn subshell_end_exit_code_704_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(704)));
    match vm.run() {
        VMResult::Ok(Value::Status(704)) => {}
        other => panic!("exit code 704 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_six_end_incrementing_from_nine() {
    let mut b = ChunkBuilder::new();
    for _ in 0..96 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(104)) => {}
        other => panic!(
            "ninety-sixth subshell_end(Some(104)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_705_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(705)));
    match vm.run() {
        VMResult::Ok(Value::Status(705)) => {}
        other => panic!("exit code 705 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_jump_if_false_keep_after_subshell_end_status706() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadTrue, 1);
    let jmp = b.emit(Op::JumpIfFalseKeep(0), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.patch_jump(jmp, b.current_pos());
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(706)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 706);
}

#[test]
fn subshell_end_exit_code_706_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(706)));
    match vm.run() {
        VMResult::Ok(Value::Status(706)) => {}
        other => panic!("exit code 706 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..124 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_707_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(707)));
    match vm.run() {
        VMResult::Ok(Value::Status(707)) => {}
        other => panic!("exit code 707 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_third_some_host_applies_on_forty_third_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..43 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyThirdSomeHost {
        calls: u32,
    }
    impl ShellHost for FortyThirdSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 43 {
                Some(708)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 3;
    vm.set_shell_host(Box::new(FortyThirdSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(708)) => {}
        other => panic!(
            "forty-third subshell_end(Some(708)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_708_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(708)));
    match vm.run() {
        VMResult::Ok(Value::Status(708)) => {}
        other => panic!("exit code 708 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_first_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-first None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_709_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(709)));
    match vm.run() {
        VMResult::Ok(Value::Status(709)) => {}
        other => panic!("exit code 709 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_end_after_subshell_end_status710() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(710)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 1);
    assert_eq!(vm.last_status, 710);
}

#[test]
fn subshell_end_exit_code_710_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(710)));
    match vm.run() {
        VMResult::Ok(Value::Status(710)) => {}
        other => panic!("exit code 710 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_seven_end_incrementing_from_four() {
    let mut b = ChunkBuilder::new();
    for _ in 0..97 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(100)) => {}
        other => panic!(
            "ninety-seventh subshell_end(Some(100)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_711_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(711)));
    match vm.run() {
        VMResult::Ok(Value::Status(711)) => {}
        other => panic!("exit code 711 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_spaceship_after_subshell_end_status712() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Spaceship, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(712)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 712);
}

#[test]
fn subshell_end_exit_code_712_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(712)));
    match vm.run() {
        VMResult::Ok(Value::Status(712)) => {}
        other => panic!("exit code 712 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 713;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(713)) => {}
        other => panic!(
            "NoneHost twenty ends MUST leave last_status 713, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_713_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(713)));
    match vm.run() {
        VMResult::Ok(Value::Status(713)) => {}
        other => panic!("exit code 713 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twentieth_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 714,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(714)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twentieth None MUST keep first Some(714), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_714_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(714)));
    match vm.run() {
        VMResult::Ok(Value::Status(714)) => {}
        other => panic!("exit code 714 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..125 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_715_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(715)));
    match vm.run() {
        VMResult::Ok(Value::Status(715)) => {}
        other => panic!("exit code 715 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fourth_some_host_applies_on_forty_fourth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..44 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFourthSomeHost {
        calls: u32,
    }
    impl ShellHost for FortyFourthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 44 {
                Some(716)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 10;
    vm.set_shell_host(Box::new(FortyFourthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(716)) => {}
        other => panic!(
            "forty-fourth subshell_end(Some(716)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_716_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(716)));
    match vm.run() {
        VMResult::Ok(Value::Status(716)) => {}
        other => panic!("exit code 716 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_717() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost717;
    impl ShellHost for PipelineSubshellHost717 {
        fn pipeline_end(&mut self) -> i32 {
            6
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(717)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost717));
    match vm.run() {
        VMResult::Ok(Value::Status(717)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 717, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_717_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(717)));
    match vm.run() {
        VMResult::Ok(Value::Status(717)) => {}
        other => panic!("exit code 717 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_718() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost718;
    impl ShellHost for SubshellThenPipelineHost718 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(15)
        }
        fn pipeline_end(&mut self) -> i32 {
            718
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost718));
    match vm.run() {
        VMResult::Ok(Value::Status(718)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 718, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_718_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(718)));
    match vm.run() {
        VMResult::Ok(Value::Status(718)) => {}
        other => panic!("exit code 718 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-100)));
    match vm.run() {
        VMResult::Ok(Value::Status(-100)) => {}
        other => panic!("status -100 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_719_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(719)));
    match vm.run() {
        VMResult::Ok(Value::Status(719)) => {}
        other => panic!("exit code 719 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_eight_end_incrementing_from_two() {
    let mut b = ChunkBuilder::new();
    for _ in 0..98 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 2 }));
    match vm.run() {
        VMResult::Ok(Value::Status(99)) => {}
        other => panic!(
            "ninety-eighth subshell_end(Some(99)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_720_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(720)));
    match vm.run() {
        VMResult::Ok(Value::Status(720)) => {}
        other => panic!("exit code 720 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..126 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_721_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(721)));
    match vm.run() {
        VMResult::Ok(Value::Status(721)) => {}
        other => panic!("exit code 721 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AA (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_722_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(722)));
    match vm.run() {
        VMResult::Ok(Value::Status(722)) => {}
        other => panic!("exit code 722 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..127 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_723_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(723)));
    match vm.run() {
        VMResult::Ok(Value::Status(723)) => {}
        other => panic!("exit code 723 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_eight_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..128 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_724_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(724)));
    match vm.run() {
        VMResult::Ok(Value::Status(724)) => {}
        other => panic!("exit code 724 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_twenty_nine_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..129 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_725_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(725)));
    match vm.run() {
        VMResult::Ok(Value::Status(725)) => {}
        other => panic!("exit code 725 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_ten() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_726_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(726)));
    match vm.run() {
        VMResult::Ok(Value::Status(726)) => {}
        other => panic!("exit code 726 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-101)));
    match vm.run() {
        VMResult::Ok(Value::Status(-101)) => {}
        other => panic!("status -101 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_727_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(727)));
    match vm.run() {
        VMResult::Ok(Value::Status(727)) => {}
        other => panic!("exit code 727 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-102)));
    match vm.run() {
        VMResult::Ok(Value::Status(-102)) => {}
        other => panic!("status -102 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_728_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(728)));
    match vm.run() {
        VMResult::Ok(Value::Status(728)) => {}
        other => panic!("exit code 728 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..45 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHost {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 45 {
                Some(729)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(729)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(729)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_729_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(729)));
    match vm.run() {
        VMResult::Ok(Value::Status(729)) => {}
        other => panic!("exit code 729 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(730)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..19 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 22);
    assert_eq!(vm.last_status, 730);
}

#[test]
fn subshell_end_exit_code_730_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(730)));
    match vm.run() {
        VMResult::Ok(Value::Status(730)) => {}
        other => panic!("exit code 730 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status731() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(731)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 731);
}

#[test]
fn subshell_end_exit_code_731_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(731)));
    match vm.run() {
        VMResult::Ok(Value::Status(731)) => {}
        other => panic!("exit code 731 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighteen_begins_sixteen_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..18 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..16 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost732;
    impl ShellHost for CountingBeginEndHost732 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(732)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost732));
    match vm.run() {
        VMResult::Ok(Value::Status(732)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(732)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 18);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 16);
}

#[test]
fn subshell_end_exit_code_732_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(732)));
    match vm.run() {
        VMResult::Ok(Value::Status(732)) => {}
        other => panic!("exit code 732 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status733() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733;
    impl ShellHost for CountingBeginHost733 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(733)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 733);
}

#[test]
fn subshell_end_exit_code_733_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(733)));
    match vm.run() {
        VMResult::Ok(Value::Status(733)) => {}
        other => panic!("exit code 733 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(734)));
    for _ in 0..19 {
        match vm.run() {
            VMResult::Ok(Value::Status(734)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_734_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(734)));
    match vm.run() {
        VMResult::Ok(Value::Status(734)) => {}
        other => panic!("exit code 734 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status735() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(735)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 735);
}

#[test]
fn subshell_end_exit_code_735_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(735)));
    match vm.run() {
        VMResult::Ok(Value::Status(735)) => {}
        other => panic!("exit code 735 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_three() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_736_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(736)));
    match vm.run() {
        VMResult::Ok(Value::Status(736)) => {}
        other => panic!("exit code 736 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status737() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(737)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 737);
}

#[test]
fn subshell_end_exit_code_737_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(737)));
    match vm.run() {
        VMResult::Ok(Value::Status(737)) => {}
        other => panic!("exit code 737 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..130 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_738_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(738)));
    match vm.run() {
        VMResult::Ok(Value::Status(738)) => {}
        other => panic!("exit code 738 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_one_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..131 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_739_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(739)));
    match vm.run() {
        VMResult::Ok(Value::Status(739)) => {}
        other => panic!("exit code 739 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_740_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(740)));
    match vm.run() {
        VMResult::Ok(Value::Status(740)) => {}
        other => panic!("exit code 740 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 741;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(741)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 741, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_741_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(741)));
    match vm.run() {
        VMResult::Ok(Value::Status(741)) => {}
        other => panic!("exit code 741 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 742,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(742)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(742), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_742_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(742)));
    match vm.run() {
        VMResult::Ok(Value::Status(742)) => {}
        other => panic!("exit code 742 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-103)));
    match vm.run() {
        VMResult::Ok(Value::Status(-103)) => {}
        other => panic!("status -103 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_743_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(743)));
    match vm.run() {
        VMResult::Ok(Value::Status(743)) => {}
        other => panic!("exit code 743 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_end_incrementing_from_five() {
    let mut b = ChunkBuilder::new();
    for _ in 0..101 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 5 }));
    match vm.run() {
        VMResult::Ok(Value::Status(105)) => {}
        other => panic!(
            "one-hundred-first subshell_end(Some(105)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_744_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(744)));
    match vm.run() {
        VMResult::Ok(Value::Status(744)) => {}
        other => panic!("exit code 744 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status745() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost745 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost745 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost745 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_745_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(745)));
    match vm.run() {
        VMResult::Ok(Value::Status(745)) => {}
        other => panic!("exit code 745 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status746() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(746)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 746);
}

#[test]
fn subshell_end_exit_code_746_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(746)));
    match vm.run() {
        VMResult::Ok(Value::Status(746)) => {}
        other => panic!("exit code 746 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AB (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_747_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(747)));
    match vm.run() {
        VMResult::Ok(Value::Status(747)) => {}
        other => panic!("exit code 747 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_two_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..132 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_748_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(748)));
    match vm.run() {
        VMResult::Ok(Value::Status(748)) => {}
        other => panic!("exit code 748 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_three_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..133 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_749_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(749)));
    match vm.run() {
        VMResult::Ok(Value::Status(749)) => {}
        other => panic!("exit code 749 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_four_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..134 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_750_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(750)));
    match vm.run() {
        VMResult::Ok(Value::Status(750)) => {}
        other => panic!("exit code 750 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_end_incrementing_from_six() {
    let mut b = ChunkBuilder::new();
    for _ in 0..102 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 6 }));
    match vm.run() {
        VMResult::Ok(Value::Status(107)) => {}
        other => panic!(
            "one-hundred-second subshell_end(Some(107)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_751_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(751)));
    match vm.run() {
        VMResult::Ok(Value::Status(751)) => {}
        other => panic!("exit code 751 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-104)));
    match vm.run() {
        VMResult::Ok(Value::Status(-104)) => {}
        other => panic!("status -104 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_752_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(752)));
    match vm.run() {
        VMResult::Ok(Value::Status(752)) => {}
        other => panic!("exit code 752 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-105)));
    match vm.run() {
        VMResult::Ok(Value::Status(-105)) => {}
        other => panic!("status -105 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_753_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(753)));
    match vm.run() {
        VMResult::Ok(Value::Status(753)) => {}
        other => panic!("exit code 753 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..46 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHost {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 46 {
                Some(754)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(754)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(754)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_754_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(754)));
    match vm.run() {
        VMResult::Ok(Value::Status(754)) => {}
        other => panic!("exit code 754 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_applies() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(755)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..20 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 23);
    assert_eq!(vm.last_status, 755);
}

#[test]
fn subshell_end_exit_code_755_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(755)));
    match vm.run() {
        VMResult::Ok(Value::Status(755)) => {}
        other => panic!("exit code 755 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status756() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(756)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 756);
}

#[test]
fn subshell_end_exit_code_756_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(756)));
    match vm.run() {
        VMResult::Ok(Value::Status(756)) => {}
        other => panic!("exit code 756 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_begins_seventeen_ends_last_end_status_wins() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..19 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..17 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost757;
    impl ShellHost for CountingBeginEndHost757 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(757)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost757));
    match vm.run() {
        VMResult::Ok(Value::Status(757)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(757)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 19);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 17);
}

#[test]
fn subshell_end_exit_code_757_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(757)));
    match vm.run() {
        VMResult::Ok(Value::Status(757)) => {}
        other => panic!("exit code 757 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status758() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(758)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 758);
}

#[test]
fn subshell_end_exit_code_758_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(758)));
    match vm.run() {
        VMResult::Ok(Value::Status(758)) => {}
        other => panic!("exit code 758 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_status() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(759)));
    for _ in 0..20 {
        match vm.run() {
            VMResult::Ok(Value::Status(759)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_759_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(759)));
    match vm.run() {
        VMResult::Ok(Value::Status(759)) => {}
        other => panic!("exit code 759 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status760() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(760)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 760);
}

#[test]
fn subshell_end_exit_code_760_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(760)));
    match vm.run() {
        VMResult::Ok(Value::Status(760)) => {}
        other => panic!("exit code 760 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_end_incrementing_from_seven() {
    let mut b = ChunkBuilder::new();
    for _ in 0..103 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(109)) => {}
        other => panic!(
            "one-hundred-third subshell_end(Some(109)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_761_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(761)));
    match vm.run() {
        VMResult::Ok(Value::Status(761)) => {}
        other => panic!("exit code 761 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status762() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(762)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 762);
}

#[test]
fn subshell_end_exit_code_762_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(762)));
    match vm.run() {
        VMResult::Ok(Value::Status(762)) => {}
        other => panic!("exit code 762 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_five_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..135 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_763_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(763)));
    match vm.run() {
        VMResult::Ok(Value::Status(763)) => {}
        other => panic!("exit code 763 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..47 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHost {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 47 {
                Some(764)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(764)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(764)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_764_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(764)));
    match vm.run() {
        VMResult::Ok(Value::Status(764)) => {}
        other => panic!("exit code 764 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninth() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_765_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(765)));
    match vm.run() {
        VMResult::Ok(Value::Status(765)) => {}
        other => panic!("exit code 765 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status766() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(766)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 766);
}

#[test]
fn subshell_end_exit_code_766_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(766)));
    match vm.run() {
        VMResult::Ok(Value::Status(766)) => {}
        other => panic!("exit code 766 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_four_end_incrementing_from_one() {
    let mut b = ChunkBuilder::new();
    for _ in 0..104 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 1 }));
    match vm.run() {
        VMResult::Ok(Value::Status(104)) => {}
        other => panic!(
            "one-hundred-fourth subshell_end(Some(104)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_767_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(767)));
    match vm.run() {
        VMResult::Ok(Value::Status(767)) => {}
        other => panic!("exit code 767 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_status() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 768;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(768)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 768, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_768_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(768)));
    match vm.run() {
        VMResult::Ok(Value::Status(768)) => {}
        other => panic!("exit code 768 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_first() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 769,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(769)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(769), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_769_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(769)));
    match vm.run() {
        VMResult::Ok(Value::Status(769)) => {}
        other => panic!("exit code 769 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_six_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..136 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_770_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(770)));
    match vm.run() {
        VMResult::Ok(Value::Status(770)) => {}
        other => panic!("exit code 770 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_end() {
    let mut b = ChunkBuilder::new();
    for _ in 0..48 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHost {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHost {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 48 {
                Some(771)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(771)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(771)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_771_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(771)));
    match vm.run() {
        VMResult::Ok(Value::Status(771)) => {}
        other => panic!("exit code 771 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_772() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost772;
    impl ShellHost for PipelineSubshellHost772 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(772)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost772));
    match vm.run() {
        VMResult::Ok(Value::Status(772)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_772_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(772)));
    match vm.run() {
        VMResult::Ok(Value::Status(772)) => {}
        other => panic!("exit code 772 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_773() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost773;
    impl ShellHost for SubshellThenPipelineHost773 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            773
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost773));
    match vm.run() {
        VMResult::Ok(Value::Status(773)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_773_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(773)));
    match vm.run() {
        VMResult::Ok(Value::Status(773)) => {}
        other => panic!("exit code 773 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-106)));
    match vm.run() {
        VMResult::Ok(Value::Status(-106)) => {}
        other => panic!("status -106 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_774_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(774)));
    match vm.run() {
        VMResult::Ok(Value::Status(774)) => {}
        other => panic!("exit code 774 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_five_end_incrementing_from_eight() {
    let mut b = ChunkBuilder::new();
    for _ in 0..105 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(112)) => {}
        other => panic!(
            "one-hundred-fifth subshell_end(Some(112)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_775_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(775)));
    match vm.run() {
        VMResult::Ok(Value::Status(775)) => {}
        other => panic!("exit code 775 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_seven_consecutive_runs_without_reset_still_blocked() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..137 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_776_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(776)));
    match vm.run() {
        VMResult::Ok(Value::Status(776)) => {}
        other => panic!("exit code 776 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status777() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost777 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost777 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost777 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_777_propagates() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(777)));
    match vm.run() {
        VMResult::Ok(Value::Status(777)) => {}
        other => panic!("exit code 777 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AC (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_778_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(778)));
    match vm.run() {
        VMResult::Ok(Value::Status(778)) => {}
        other => panic!("exit code 778 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_eight_consecutive_runs_without_reset_still_blockedEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..138 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_779_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(779)));
    match vm.run() {
        VMResult::Ok(Value::Status(779)) => {}
        other => panic!("exit code 779 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_thirty_nine_consecutive_runs_without_reset_still_blockedEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..139 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_780_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(780)));
    match vm.run() {
        VMResult::Ok(Value::Status(780)) => {}
        other => panic!("exit code 780 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_consecutive_runs_without_reset_still_blockedEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..140 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_781_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(781)));
    match vm.run() {
        VMResult::Ok(Value::Status(781)) => {}
        other => panic!("exit code 781 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_782_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(782)));
    match vm.run() {
        VMResult::Ok(Value::Status(782)) => {}
        other => panic!("exit code 782 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-108)));
    match vm.run() {
        VMResult::Ok(Value::Status(-108)) => {}
        other => panic!("status -108 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_783_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(783)));
    match vm.run() {
        VMResult::Ok(Value::Status(783)) => {}
        other => panic!("exit code 783 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-109)));
    match vm.run() {
        VMResult::Ok(Value::Status(-109)) => {}
        other => panic!("status -109 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_784_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(784)));
    match vm.run() {
        VMResult::Ok(Value::Status(784)) => {}
        other => panic!("exit code 784 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..49 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx778 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx778 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 49 {
                Some(785)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx778 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(785)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(785)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_785_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(785)));
    match vm.run() {
        VMResult::Ok(Value::Status(785)) => {}
        other => panic!("exit code 785 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(786)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..21 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 24);
    assert_eq!(vm.last_status, 786);
}

#[test]
fn subshell_end_exit_code_786_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(786)));
    match vm.run() {
        VMResult::Ok(Value::Status(786)) => {}
        other => panic!("exit code 786 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status787Ex778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(787)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 787);
}

#[test]
fn subshell_end_exit_code_787_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(787)));
    match vm.run() {
        VMResult::Ok(Value::Status(787)) => {}
        other => panic!("exit code 787 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_begins_eighteen_ends_last_end_status_winsEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..20 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..18 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost788Ex778;
    impl ShellHost for CountingBeginEndHost788Ex778 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(788)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost788Ex778));
    match vm.run() {
        VMResult::Ok(Value::Status(788)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(788)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 20);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 18);
}

#[test]
fn subshell_end_exit_code_788_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(788)));
    match vm.run() {
        VMResult::Ok(Value::Status(788)) => {}
        other => panic!("exit code 788 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status789Ex778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex778;
    impl ShellHost for CountingBeginHost733Ex778 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(789)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex778));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 789);
}

#[test]
fn subshell_end_exit_code_789_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(789)));
    match vm.run() {
        VMResult::Ok(Value::Status(789)) => {}
        other => panic!("exit code 789 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx778() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(790)));
    for _ in 0..21 {
        match vm.run() {
            VMResult::Ok(Value::Status(790)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_790_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(790)));
    match vm.run() {
        VMResult::Ok(Value::Status(790)) => {}
        other => panic!("exit code 790 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status791Ex778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(791)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 791);
}

#[test]
fn subshell_end_exit_code_791_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(791)));
    match vm.run() {
        VMResult::Ok(Value::Status(791)) => {}
        other => panic!("exit code 791 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_792_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(792)));
    match vm.run() {
        VMResult::Ok(Value::Status(792)) => {}
        other => panic!("exit code 792 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status793Ex778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(793)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 793);
}

#[test]
fn subshell_end_exit_code_793_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(793)));
    match vm.run() {
        VMResult::Ok(Value::Status(793)) => {}
        other => panic!("exit code 793 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_one_consecutive_runs_without_reset_still_blockedEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..141 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_794_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(794)));
    match vm.run() {
        VMResult::Ok(Value::Status(794)) => {}
        other => panic!("exit code 794 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_two_consecutive_runs_without_reset_still_blockedEx778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..142 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_795_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(795)));
    match vm.run() {
        VMResult::Ok(Value::Status(795)) => {}
        other => panic!("exit code 795 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_796_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(796)));
    match vm.run() {
        VMResult::Ok(Value::Status(796)) => {}
        other => panic!("exit code 796 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 797;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(797)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 797, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_797_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(797)));
    match vm.run() {
        VMResult::Ok(Value::Status(797)) => {}
        other => panic!("exit code 797 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 798,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(798)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(798), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_798_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(798)));
    match vm.run() {
        VMResult::Ok(Value::Status(798)) => {}
        other => panic!("exit code 798 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-110)));
    match vm.run() {
        VMResult::Ok(Value::Status(-110)) => {}
        other => panic!("status -110 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_799_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(799)));
    match vm.run() {
        VMResult::Ok(Value::Status(799)) => {}
        other => panic!("exit code 799 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eight_end_incrementing_from_fiveEx778() {
    let mut b = ChunkBuilder::new();
    for _ in 0..108 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 8 }));
    match vm.run() {
        VMResult::Ok(Value::Status(115)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(115)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_800_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(800)));
    match vm.run() {
        VMResult::Ok(Value::Status(800)) => {}
        other => panic!("exit code 800 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status801Ex778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost801Ex778 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost801Ex778 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost801Ex778 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_801_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(801)));
    match vm.run() {
        VMResult::Ok(Value::Status(801)) => {}
        other => panic!("exit code 801 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status802Ex778() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(802)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 802);
}

#[test]
fn subshell_end_exit_code_802_propagatesEx778() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(802)));
    match vm.run() {
        VMResult::Ok(Value::Status(802)) => {}
        other => panic!("exit code 802 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AD (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_803_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(803)));
    match vm.run() {
        VMResult::Ok(Value::Status(803)) => {}
        other => panic!("exit code 803 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_three_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..143 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_804_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(804)));
    match vm.run() {
        VMResult::Ok(Value::Status(804)) => {}
        other => panic!("exit code 804 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_four_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..144 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_805_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(805)));
    match vm.run() {
        VMResult::Ok(Value::Status(805)) => {}
        other => panic!("exit code 805 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_five_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..145 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_806_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(806)));
    match vm.run() {
        VMResult::Ok(Value::Status(806)) => {}
        other => panic!("exit code 806 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_nine_end_incrementing_from_sixEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..109 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 9 }));
    match vm.run() {
        VMResult::Ok(Value::Status(117)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(117)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_807_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(807)));
    match vm.run() {
        VMResult::Ok(Value::Status(807)) => {}
        other => panic!("exit code 807 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-111)));
    match vm.run() {
        VMResult::Ok(Value::Status(-111)) => {}
        other => panic!("status -111 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_808_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(808)));
    match vm.run() {
        VMResult::Ok(Value::Status(808)) => {}
        other => panic!("exit code 808 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-112)));
    match vm.run() {
        VMResult::Ok(Value::Status(-112)) => {}
        other => panic!("status -112 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_809_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(809)));
    match vm.run() {
        VMResult::Ok(Value::Status(809)) => {}
        other => panic!("exit code 809 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..50 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx803 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx803 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 50 {
                Some(810)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx803 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(810)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(810)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_810_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(810)));
    match vm.run() {
        VMResult::Ok(Value::Status(810)) => {}
        other => panic!("exit code 810 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(811)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..22 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 25);
    assert_eq!(vm.last_status, 811);
}

#[test]
fn subshell_end_exit_code_811_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(811)));
    match vm.run() {
        VMResult::Ok(Value::Status(811)) => {}
        other => panic!("exit code 811 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status812Ex803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(812)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 812);
}

#[test]
fn subshell_end_exit_code_812_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(812)));
    match vm.run() {
        VMResult::Ok(Value::Status(812)) => {}
        other => panic!("exit code 812 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_one_begins_nineteen_ends_last_end_status_winsEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..19 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost813Ex803;
    impl ShellHost for CountingBeginEndHost813Ex803 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(813)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost813Ex803));
    match vm.run() {
        VMResult::Ok(Value::Status(813)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(813)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 21);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 19);
}

#[test]
fn subshell_end_exit_code_813_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(813)));
    match vm.run() {
        VMResult::Ok(Value::Status(813)) => {}
        other => panic!("exit code 813 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status814Ex803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(814)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 814);
}

#[test]
fn subshell_end_exit_code_814_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(814)));
    match vm.run() {
        VMResult::Ok(Value::Status(814)) => {}
        other => panic!("exit code 814 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx803() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(815)));
    for _ in 0..22 {
        match vm.run() {
            VMResult::Ok(Value::Status(815)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_815_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(815)));
    match vm.run() {
        VMResult::Ok(Value::Status(815)) => {}
        other => panic!("exit code 815 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status816Ex803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(816)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 816);
}

#[test]
fn subshell_end_exit_code_816_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(816)));
    match vm.run() {
        VMResult::Ok(Value::Status(816)) => {}
        other => panic!("exit code 816 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ten_end_incrementing_from_sevenEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..110 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(119)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(119)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_817_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(817)));
    match vm.run() {
        VMResult::Ok(Value::Status(817)) => {}
        other => panic!("exit code 817 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status818Ex803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(818)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 818);
}

#[test]
fn subshell_end_exit_code_818_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(818)));
    match vm.run() {
        VMResult::Ok(Value::Status(818)) => {}
        other => panic!("exit code 818 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_six_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..146 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_819_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(819)));
    match vm.run() {
        VMResult::Ok(Value::Status(819)) => {}
        other => panic!("exit code 819 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..51 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx803 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx803 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 51 {
                Some(820)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx803 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(820)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(820)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_820_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(820)));
    match vm.run() {
        VMResult::Ok(Value::Status(820)) => {}
        other => panic!("exit code 820 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_821_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(821)));
    match vm.run() {
        VMResult::Ok(Value::Status(821)) => {}
        other => panic!("exit code 821 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status822Ex803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(822)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 822);
}

#[test]
fn subshell_end_exit_code_822_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(822)));
    match vm.run() {
        VMResult::Ok(Value::Status(822)) => {}
        other => panic!("exit code 822 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eleven_end_incrementing_from_oneEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..111 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 4 }));
    match vm.run() {
        VMResult::Ok(Value::Status(114)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(114)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_823_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(823)));
    match vm.run() {
        VMResult::Ok(Value::Status(823)) => {}
        other => panic!("exit code 823 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 824;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(824)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 824, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_824_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(824)));
    match vm.run() {
        VMResult::Ok(Value::Status(824)) => {}
        other => panic!("exit code 824 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 825,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(825)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(825), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_825_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(825)));
    match vm.run() {
        VMResult::Ok(Value::Status(825)) => {}
        other => panic!("exit code 825 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_seven_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..147 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_826_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(826)));
    match vm.run() {
        VMResult::Ok(Value::Status(826)) => {}
        other => panic!("exit code 826 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..52 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx803 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx803 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 52 {
                Some(827)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx803 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(827)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(827)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_827_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(827)));
    match vm.run() {
        VMResult::Ok(Value::Status(827)) => {}
        other => panic!("exit code 827 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_828Ex803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost828Ex803;
    impl ShellHost for PipelineSubshellHost828Ex803 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(828)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost828Ex803));
    match vm.run() {
        VMResult::Ok(Value::Status(828)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_828_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(828)));
    match vm.run() {
        VMResult::Ok(Value::Status(828)) => {}
        other => panic!("exit code 828 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_829Ex803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost829Ex803;
    impl ShellHost for SubshellThenPipelineHost829Ex803 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            829
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost829Ex803));
    match vm.run() {
        VMResult::Ok(Value::Status(829)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_829_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(829)));
    match vm.run() {
        VMResult::Ok(Value::Status(829)) => {}
        other => panic!("exit code 829 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-113)));
    match vm.run() {
        VMResult::Ok(Value::Status(-113)) => {}
        other => panic!("status -113 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_830_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(830)));
    match vm.run() {
        VMResult::Ok(Value::Status(830)) => {}
        other => panic!("exit code 830 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twelve_end_incrementing_from_eightEx803() {
    let mut b = ChunkBuilder::new();
    for _ in 0..112 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(122)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(122)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_831_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(831)));
    match vm.run() {
        VMResult::Ok(Value::Status(831)) => {}
        other => panic!("exit code 831 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_eight_consecutive_runs_without_reset_still_blockedEx803() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..148 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_832_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(832)));
    match vm.run() {
        VMResult::Ok(Value::Status(832)) => {}
        other => panic!("exit code 832 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status833Ex803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost833Ex803 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost833Ex803 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost833Ex803 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_833_propagatesEx803() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(833)));
    match vm.run() {
        VMResult::Ok(Value::Status(833)) => {}
        other => panic!("exit code 833 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AE (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_834_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(834)));
    match vm.run() {
        VMResult::Ok(Value::Status(834)) => {}
        other => panic!("exit code 834 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_forty_nine_consecutive_runs_without_reset_still_blockedEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..149 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_835_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(835)));
    match vm.run() {
        VMResult::Ok(Value::Status(835)) => {}
        other => panic!("exit code 835 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_consecutive_runs_without_reset_still_blockedEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..150 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_836_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(836)));
    match vm.run() {
        VMResult::Ok(Value::Status(836)) => {}
        other => panic!("exit code 836 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_one_consecutive_runs_without_reset_still_blockedEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..151 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_837_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(837)));
    match vm.run() {
        VMResult::Ok(Value::Status(837)) => {}
        other => panic!("exit code 837 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_838_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(838)));
    match vm.run() {
        VMResult::Ok(Value::Status(838)) => {}
        other => panic!("exit code 838 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-115)));
    match vm.run() {
        VMResult::Ok(Value::Status(-115)) => {}
        other => panic!("status -115 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_839_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(839)));
    match vm.run() {
        VMResult::Ok(Value::Status(839)) => {}
        other => panic!("exit code 839 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-116)));
    match vm.run() {
        VMResult::Ok(Value::Status(-116)) => {}
        other => panic!("status -116 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_840_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(840)));
    match vm.run() {
        VMResult::Ok(Value::Status(840)) => {}
        other => panic!("exit code 840 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..53 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx834 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx834 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 53 {
                Some(841)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx834 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(841)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(841)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_841_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(841)));
    match vm.run() {
        VMResult::Ok(Value::Status(841)) => {}
        other => panic!("exit code 841 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(842)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..23 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 26);
    assert_eq!(vm.last_status, 842);
}

#[test]
fn subshell_end_exit_code_842_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(842)));
    match vm.run() {
        VMResult::Ok(Value::Status(842)) => {}
        other => panic!("exit code 842 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status843Ex834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(843)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 843);
}

#[test]
fn subshell_end_exit_code_843_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(843)));
    match vm.run() {
        VMResult::Ok(Value::Status(843)) => {}
        other => panic!("exit code 843 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_two_begins_twenty_ends_last_end_status_winsEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..20 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost844Ex834;
    impl ShellHost for CountingBeginEndHost844Ex834 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(844)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost844Ex834));
    match vm.run() {
        VMResult::Ok(Value::Status(844)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(844)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 22);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 20);
}

#[test]
fn subshell_end_exit_code_844_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(844)));
    match vm.run() {
        VMResult::Ok(Value::Status(844)) => {}
        other => panic!("exit code 844 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status845Ex834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex834;
    impl ShellHost for CountingBeginHost733Ex834 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(845)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex834));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 845);
}

#[test]
fn subshell_end_exit_code_845_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(845)));
    match vm.run() {
        VMResult::Ok(Value::Status(845)) => {}
        other => panic!("exit code 845 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx834() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(846)));
    for _ in 0..23 {
        match vm.run() {
            VMResult::Ok(Value::Status(846)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_846_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(846)));
    match vm.run() {
        VMResult::Ok(Value::Status(846)) => {}
        other => panic!("exit code 846 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status847Ex834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(847)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 847);
}

#[test]
fn subshell_end_exit_code_847_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(847)));
    match vm.run() {
        VMResult::Ok(Value::Status(847)) => {}
        other => panic!("exit code 847 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_848_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(848)));
    match vm.run() {
        VMResult::Ok(Value::Status(848)) => {}
        other => panic!("exit code 848 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status849Ex834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(849)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 849);
}

#[test]
fn subshell_end_exit_code_849_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(849)));
    match vm.run() {
        VMResult::Ok(Value::Status(849)) => {}
        other => panic!("exit code 849 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_two_consecutive_runs_without_reset_still_blockedEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..152 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_850_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(850)));
    match vm.run() {
        VMResult::Ok(Value::Status(850)) => {}
        other => panic!("exit code 850 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_three_consecutive_runs_without_reset_still_blockedEx834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..153 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_851_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(851)));
    match vm.run() {
        VMResult::Ok(Value::Status(851)) => {}
        other => panic!("exit code 851 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_852_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(852)));
    match vm.run() {
        VMResult::Ok(Value::Status(852)) => {}
        other => panic!("exit code 852 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 853;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(853)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 853, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_853_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(853)));
    match vm.run() {
        VMResult::Ok(Value::Status(853)) => {}
        other => panic!("exit code 853 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 854,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(854)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(854), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_854_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(854)));
    match vm.run() {
        VMResult::Ok(Value::Status(854)) => {}
        other => panic!("exit code 854 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-117)));
    match vm.run() {
        VMResult::Ok(Value::Status(-117)) => {}
        other => panic!("status -117 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_855_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(855)));
    match vm.run() {
        VMResult::Ok(Value::Status(855)) => {}
        other => panic!("exit code 855 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifteen_end_incrementing_from_fiveEx834() {
    let mut b = ChunkBuilder::new();
    for _ in 0..115 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 11 }));
    match vm.run() {
        VMResult::Ok(Value::Status(125)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(125)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_856_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(856)));
    match vm.run() {
        VMResult::Ok(Value::Status(856)) => {}
        other => panic!("exit code 856 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status857Ex834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost857Ex834 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost857Ex834 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost857Ex834 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_857_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(857)));
    match vm.run() {
        VMResult::Ok(Value::Status(857)) => {}
        other => panic!("exit code 857 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status858Ex834() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(858)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 858);
}

#[test]
fn subshell_end_exit_code_858_propagatesEx834() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(858)));
    match vm.run() {
        VMResult::Ok(Value::Status(858)) => {}
        other => panic!("exit code 858 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AF (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_859_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(859)));
    match vm.run() {
        VMResult::Ok(Value::Status(859)) => {}
        other => panic!("exit code 859 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_four_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..154 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_860_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(860)));
    match vm.run() {
        VMResult::Ok(Value::Status(860)) => {}
        other => panic!("exit code 860 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_five_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..155 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_861_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(861)));
    match vm.run() {
        VMResult::Ok(Value::Status(861)) => {}
        other => panic!("exit code 861 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_six_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..156 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_862_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(862)));
    match vm.run() {
        VMResult::Ok(Value::Status(862)) => {}
        other => panic!("exit code 862 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixteen_end_incrementing_from_sixEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..116 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 12 }));
    match vm.run() {
        VMResult::Ok(Value::Status(127)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(127)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_863_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(863)));
    match vm.run() {
        VMResult::Ok(Value::Status(863)) => {}
        other => panic!("exit code 863 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-118)));
    match vm.run() {
        VMResult::Ok(Value::Status(-118)) => {}
        other => panic!("status -118 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_864_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(864)));
    match vm.run() {
        VMResult::Ok(Value::Status(864)) => {}
        other => panic!("exit code 864 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-119)));
    match vm.run() {
        VMResult::Ok(Value::Status(-119)) => {}
        other => panic!("status -119 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_865_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(865)));
    match vm.run() {
        VMResult::Ok(Value::Status(865)) => {}
        other => panic!("exit code 865 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..54 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx859 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx859 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 54 {
                Some(866)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx859 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(866)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(866)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_866_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(866)));
    match vm.run() {
        VMResult::Ok(Value::Status(866)) => {}
        other => panic!("exit code 866 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(867)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..24 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 27);
    assert_eq!(vm.last_status, 867);
}

#[test]
fn subshell_end_exit_code_867_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(867)));
    match vm.run() {
        VMResult::Ok(Value::Status(867)) => {}
        other => panic!("exit code 867 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status868Ex859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(868)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 868);
}

#[test]
fn subshell_end_exit_code_868_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(868)));
    match vm.run() {
        VMResult::Ok(Value::Status(868)) => {}
        other => panic!("exit code 868 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_three_begins_twenty_one_ends_last_end_status_winsEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost869Ex859;
    impl ShellHost for CountingBeginEndHost869Ex859 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(869)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost869Ex859));
    match vm.run() {
        VMResult::Ok(Value::Status(869)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(869)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 23);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 21);
}

#[test]
fn subshell_end_exit_code_869_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(869)));
    match vm.run() {
        VMResult::Ok(Value::Status(869)) => {}
        other => panic!("exit code 869 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status870Ex859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(870)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 870);
}

#[test]
fn subshell_end_exit_code_870_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(870)));
    match vm.run() {
        VMResult::Ok(Value::Status(870)) => {}
        other => panic!("exit code 870 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx859() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(871)));
    for _ in 0..24 {
        match vm.run() {
            VMResult::Ok(Value::Status(871)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_871_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(871)));
    match vm.run() {
        VMResult::Ok(Value::Status(871)) => {}
        other => panic!("exit code 871 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status872Ex859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(872)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 872);
}

#[test]
fn subshell_end_exit_code_872_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(872)));
    match vm.run() {
        VMResult::Ok(Value::Status(872)) => {}
        other => panic!("exit code 872 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventeen_end_incrementing_from_sevenEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..117 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 13 }));
    match vm.run() {
        VMResult::Ok(Value::Status(129)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(129)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_873_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(873)));
    match vm.run() {
        VMResult::Ok(Value::Status(873)) => {}
        other => panic!("exit code 873 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status874Ex859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(874)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 874);
}

#[test]
fn subshell_end_exit_code_874_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(874)));
    match vm.run() {
        VMResult::Ok(Value::Status(874)) => {}
        other => panic!("exit code 874 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_seven_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..157 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_875_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(875)));
    match vm.run() {
        VMResult::Ok(Value::Status(875)) => {}
        other => panic!("exit code 875 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..55 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx859 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx859 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 55 {
                Some(876)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx859 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(876)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(876)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_876_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(876)));
    match vm.run() {
        VMResult::Ok(Value::Status(876)) => {}
        other => panic!("exit code 876 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_877_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(877)));
    match vm.run() {
        VMResult::Ok(Value::Status(877)) => {}
        other => panic!("exit code 877 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status878Ex859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(878)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 878);
}

#[test]
fn subshell_end_exit_code_878_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(878)));
    match vm.run() {
        VMResult::Ok(Value::Status(878)) => {}
        other => panic!("exit code 878 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighteen_end_incrementing_from_oneEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..118 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 7 }));
    match vm.run() {
        VMResult::Ok(Value::Status(124)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(124)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_879_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(879)));
    match vm.run() {
        VMResult::Ok(Value::Status(879)) => {}
        other => panic!("exit code 879 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 880;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(880)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 880, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_880_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(880)));
    match vm.run() {
        VMResult::Ok(Value::Status(880)) => {}
        other => panic!("exit code 880 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 881,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(881)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(881), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_881_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(881)));
    match vm.run() {
        VMResult::Ok(Value::Status(881)) => {}
        other => panic!("exit code 881 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_eight_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..158 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_882_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(882)));
    match vm.run() {
        VMResult::Ok(Value::Status(882)) => {}
        other => panic!("exit code 882 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..56 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx859 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx859 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 56 {
                Some(883)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx859 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(883)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(883)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_883_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(883)));
    match vm.run() {
        VMResult::Ok(Value::Status(883)) => {}
        other => panic!("exit code 883 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_884Ex859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost884Ex859;
    impl ShellHost for PipelineSubshellHost884Ex859 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(884)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost884Ex859));
    match vm.run() {
        VMResult::Ok(Value::Status(884)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_884_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(884)));
    match vm.run() {
        VMResult::Ok(Value::Status(884)) => {}
        other => panic!("exit code 884 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_885Ex859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost885Ex859;
    impl ShellHost for SubshellThenPipelineHost885Ex859 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            885
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost885Ex859));
    match vm.run() {
        VMResult::Ok(Value::Status(885)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_885_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(885)));
    match vm.run() {
        VMResult::Ok(Value::Status(885)) => {}
        other => panic!("exit code 885 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-120)));
    match vm.run() {
        VMResult::Ok(Value::Status(-120)) => {}
        other => panic!("status -120 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_886_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(886)));
    match vm.run() {
        VMResult::Ok(Value::Status(886)) => {}
        other => panic!("exit code 886 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_nineteen_end_incrementing_from_eightEx859() {
    let mut b = ChunkBuilder::new();
    for _ in 0..119 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 14 }));
    match vm.run() {
        VMResult::Ok(Value::Status(132)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(132)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_887_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(887)));
    match vm.run() {
        VMResult::Ok(Value::Status(887)) => {}
        other => panic!("exit code 887 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_fifty_nine_consecutive_runs_without_reset_still_blockedEx859() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..159 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_888_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(888)));
    match vm.run() {
        VMResult::Ok(Value::Status(888)) => {}
        other => panic!("exit code 888 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status889Ex859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost889Ex859 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost889Ex859 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost889Ex859 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_889_propagatesEx859() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(889)));
    match vm.run() {
        VMResult::Ok(Value::Status(889)) => {}
        other => panic!("exit code 889 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AG (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_890_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(890)));
    match vm.run() {
        VMResult::Ok(Value::Status(890)) => {}
        other => panic!("exit code 890 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_consecutive_runs_without_reset_still_blockedEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..160 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_891_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(891)));
    match vm.run() {
        VMResult::Ok(Value::Status(891)) => {}
        other => panic!("exit code 891 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_one_consecutive_runs_without_reset_still_blockedEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..161 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_892_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(892)));
    match vm.run() {
        VMResult::Ok(Value::Status(892)) => {}
        other => panic!("exit code 892 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_two_consecutive_runs_without_reset_still_blockedEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..162 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_893_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(893)));
    match vm.run() {
        VMResult::Ok(Value::Status(893)) => {}
        other => panic!("exit code 893 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_894_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(894)));
    match vm.run() {
        VMResult::Ok(Value::Status(894)) => {}
        other => panic!("exit code 894 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-122)));
    match vm.run() {
        VMResult::Ok(Value::Status(-122)) => {}
        other => panic!("status -122 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_895_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(895)));
    match vm.run() {
        VMResult::Ok(Value::Status(895)) => {}
        other => panic!("exit code 895 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-123)));
    match vm.run() {
        VMResult::Ok(Value::Status(-123)) => {}
        other => panic!("status -123 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_896_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(896)));
    match vm.run() {
        VMResult::Ok(Value::Status(896)) => {}
        other => panic!("exit code 896 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..57 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx890 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx890 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 57 {
                Some(897)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx890 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(897)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(897)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_897_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(897)));
    match vm.run() {
        VMResult::Ok(Value::Status(897)) => {}
        other => panic!("exit code 897 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(898)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..25 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 28);
    assert_eq!(vm.last_status, 898);
}

#[test]
fn subshell_end_exit_code_898_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(898)));
    match vm.run() {
        VMResult::Ok(Value::Status(898)) => {}
        other => panic!("exit code 898 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status899Ex890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(899)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 899);
}

#[test]
fn subshell_end_exit_code_899_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(899)));
    match vm.run() {
        VMResult::Ok(Value::Status(899)) => {}
        other => panic!("exit code 899 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_four_begins_twenty_two_ends_last_end_status_winsEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..24 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost900Ex890;
    impl ShellHost for CountingBeginEndHost900Ex890 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(900)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost900Ex890));
    match vm.run() {
        VMResult::Ok(Value::Status(900)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(900)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 24);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 22);
}

#[test]
fn subshell_end_exit_code_900_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(900)));
    match vm.run() {
        VMResult::Ok(Value::Status(900)) => {}
        other => panic!("exit code 900 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status901Ex890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex890;
    impl ShellHost for CountingBeginHost733Ex890 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(901)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex890));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 901);
}

#[test]
fn subshell_end_exit_code_901_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(901)));
    match vm.run() {
        VMResult::Ok(Value::Status(901)) => {}
        other => panic!("exit code 901 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx890() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(902)));
    for _ in 0..25 {
        match vm.run() {
            VMResult::Ok(Value::Status(902)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_902_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(902)));
    match vm.run() {
        VMResult::Ok(Value::Status(902)) => {}
        other => panic!("exit code 902 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status903Ex890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(903)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 903);
}

#[test]
fn subshell_end_exit_code_903_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(903)));
    match vm.run() {
        VMResult::Ok(Value::Status(903)) => {}
        other => panic!("exit code 903 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_904_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(904)));
    match vm.run() {
        VMResult::Ok(Value::Status(904)) => {}
        other => panic!("exit code 904 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status905Ex890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(905)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 905);
}

#[test]
fn subshell_end_exit_code_905_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(905)));
    match vm.run() {
        VMResult::Ok(Value::Status(905)) => {}
        other => panic!("exit code 905 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_three_consecutive_runs_without_reset_still_blockedEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..163 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_906_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(906)));
    match vm.run() {
        VMResult::Ok(Value::Status(906)) => {}
        other => panic!("exit code 906 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_four_consecutive_runs_without_reset_still_blockedEx890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..164 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_907_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(907)));
    match vm.run() {
        VMResult::Ok(Value::Status(907)) => {}
        other => panic!("exit code 907 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_908_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(908)));
    match vm.run() {
        VMResult::Ok(Value::Status(908)) => {}
        other => panic!("exit code 908 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 909;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(909)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 909, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_909_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(909)));
    match vm.run() {
        VMResult::Ok(Value::Status(909)) => {}
        other => panic!("exit code 909 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 910,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(910)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(910), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_910_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(910)));
    match vm.run() {
        VMResult::Ok(Value::Status(910)) => {}
        other => panic!("exit code 910 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-124)));
    match vm.run() {
        VMResult::Ok(Value::Status(-124)) => {}
        other => panic!("status -124 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_911_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(911)));
    match vm.run() {
        VMResult::Ok(Value::Status(911)) => {}
        other => panic!("exit code 911 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_two_end_incrementing_from_fiveEx890() {
    let mut b = ChunkBuilder::new();
    for _ in 0..122 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 14 }));
    match vm.run() {
        VMResult::Ok(Value::Status(135)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(135)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_912_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(912)));
    match vm.run() {
        VMResult::Ok(Value::Status(912)) => {}
        other => panic!("exit code 912 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status913Ex890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost913Ex890 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost913Ex890 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost913Ex890 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_913_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(913)));
    match vm.run() {
        VMResult::Ok(Value::Status(913)) => {}
        other => panic!("exit code 913 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status914Ex890() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(914)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 914);
}

#[test]
fn subshell_end_exit_code_914_propagatesEx890() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(914)));
    match vm.run() {
        VMResult::Ok(Value::Status(914)) => {}
        other => panic!("exit code 914 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AH (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_915_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(915)));
    match vm.run() {
        VMResult::Ok(Value::Status(915)) => {}
        other => panic!("exit code 915 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_five_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..165 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_916_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(916)));
    match vm.run() {
        VMResult::Ok(Value::Status(916)) => {}
        other => panic!("exit code 916 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_six_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..166 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_917_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(917)));
    match vm.run() {
        VMResult::Ok(Value::Status(917)) => {}
        other => panic!("exit code 917 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_seven_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..167 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_918_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(918)));
    match vm.run() {
        VMResult::Ok(Value::Status(918)) => {}
        other => panic!("exit code 918 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_three_end_incrementing_from_sixEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..123 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 15 }));
    match vm.run() {
        VMResult::Ok(Value::Status(137)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(137)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_919_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(919)));
    match vm.run() {
        VMResult::Ok(Value::Status(919)) => {}
        other => panic!("exit code 919 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-125)));
    match vm.run() {
        VMResult::Ok(Value::Status(-125)) => {}
        other => panic!("status -125 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_920_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(920)));
    match vm.run() {
        VMResult::Ok(Value::Status(920)) => {}
        other => panic!("exit code 920 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-126)));
    match vm.run() {
        VMResult::Ok(Value::Status(-126)) => {}
        other => panic!("status -126 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_921_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(921)));
    match vm.run() {
        VMResult::Ok(Value::Status(921)) => {}
        other => panic!("exit code 921 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..58 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx915 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx915 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 58 {
                Some(922)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx915 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(922)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(922)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_922_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(922)));
    match vm.run() {
        VMResult::Ok(Value::Status(922)) => {}
        other => panic!("exit code 922 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(923)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..26 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 29);
    assert_eq!(vm.last_status, 923);
}

#[test]
fn subshell_end_exit_code_923_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(923)));
    match vm.run() {
        VMResult::Ok(Value::Status(923)) => {}
        other => panic!("exit code 923 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status924Ex915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(924)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 924);
}

#[test]
fn subshell_end_exit_code_924_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(924)));
    match vm.run() {
        VMResult::Ok(Value::Status(924)) => {}
        other => panic!("exit code 924 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_five_begins_twenty_three_ends_last_end_status_winsEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..25 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost925Ex915;
    impl ShellHost for CountingBeginEndHost925Ex915 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(925)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost925Ex915));
    match vm.run() {
        VMResult::Ok(Value::Status(925)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(925)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 25);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 23);
}

#[test]
fn subshell_end_exit_code_925_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(925)));
    match vm.run() {
        VMResult::Ok(Value::Status(925)) => {}
        other => panic!("exit code 925 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status926Ex915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(926)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 926);
}

#[test]
fn subshell_end_exit_code_926_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(926)));
    match vm.run() {
        VMResult::Ok(Value::Status(926)) => {}
        other => panic!("exit code 926 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx915() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(927)));
    for _ in 0..26 {
        match vm.run() {
            VMResult::Ok(Value::Status(927)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_927_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(927)));
    match vm.run() {
        VMResult::Ok(Value::Status(927)) => {}
        other => panic!("exit code 927 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status928Ex915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(928)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 928);
}

#[test]
fn subshell_end_exit_code_928_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(928)));
    match vm.run() {
        VMResult::Ok(Value::Status(928)) => {}
        other => panic!("exit code 928 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_four_end_incrementing_from_sevenEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..124 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 16 }));
    match vm.run() {
        VMResult::Ok(Value::Status(139)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(139)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_929_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(929)));
    match vm.run() {
        VMResult::Ok(Value::Status(929)) => {}
        other => panic!("exit code 929 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status930Ex915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(930)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 930);
}

#[test]
fn subshell_end_exit_code_930_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(930)));
    match vm.run() {
        VMResult::Ok(Value::Status(930)) => {}
        other => panic!("exit code 930 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_eight_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..168 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_931_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(931)));
    match vm.run() {
        VMResult::Ok(Value::Status(931)) => {}
        other => panic!("exit code 931 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..59 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx915 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx915 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 59 {
                Some(932)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx915 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(932)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(932)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_932_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(932)));
    match vm.run() {
        VMResult::Ok(Value::Status(932)) => {}
        other => panic!("exit code 932 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_933_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(933)));
    match vm.run() {
        VMResult::Ok(Value::Status(933)) => {}
        other => panic!("exit code 933 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status934Ex915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(934)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 934);
}

#[test]
fn subshell_end_exit_code_934_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(934)));
    match vm.run() {
        VMResult::Ok(Value::Status(934)) => {}
        other => panic!("exit code 934 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_five_end_incrementing_from_oneEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..125 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(134)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(134)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_935_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(935)));
    match vm.run() {
        VMResult::Ok(Value::Status(935)) => {}
        other => panic!("exit code 935 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 936;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(936)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 936, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_936_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(936)));
    match vm.run() {
        VMResult::Ok(Value::Status(936)) => {}
        other => panic!("exit code 936 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 937,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(937)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(937), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_937_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(937)));
    match vm.run() {
        VMResult::Ok(Value::Status(937)) => {}
        other => panic!("exit code 937 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_sixty_nine_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..169 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_938_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(938)));
    match vm.run() {
        VMResult::Ok(Value::Status(938)) => {}
        other => panic!("exit code 938 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..60 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx915 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx915 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 60 {
                Some(939)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx915 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(939)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(939)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_939_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(939)));
    match vm.run() {
        VMResult::Ok(Value::Status(939)) => {}
        other => panic!("exit code 939 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_940Ex915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost940Ex915;
    impl ShellHost for PipelineSubshellHost940Ex915 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(940)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost940Ex915));
    match vm.run() {
        VMResult::Ok(Value::Status(940)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_940_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(940)));
    match vm.run() {
        VMResult::Ok(Value::Status(940)) => {}
        other => panic!("exit code 940 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_941Ex915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost941Ex915;
    impl ShellHost for SubshellThenPipelineHost941Ex915 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            941
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost941Ex915));
    match vm.run() {
        VMResult::Ok(Value::Status(941)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_941_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(941)));
    match vm.run() {
        VMResult::Ok(Value::Status(941)) => {}
        other => panic!("exit code 941 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-127)));
    match vm.run() {
        VMResult::Ok(Value::Status(-127)) => {}
        other => panic!("status -127 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_942_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(942)));
    match vm.run() {
        VMResult::Ok(Value::Status(942)) => {}
        other => panic!("exit code 942 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_six_end_incrementing_from_eightEx915() {
    let mut b = ChunkBuilder::new();
    for _ in 0..126 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 17 }));
    match vm.run() {
        VMResult::Ok(Value::Status(142)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(142)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_943_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(943)));
    match vm.run() {
        VMResult::Ok(Value::Status(943)) => {}
        other => panic!("exit code 943 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_consecutive_runs_without_reset_still_blockedEx915() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..170 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_944_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(944)));
    match vm.run() {
        VMResult::Ok(Value::Status(944)) => {}
        other => panic!("exit code 944 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status945Ex915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost945Ex915 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost945Ex915 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost945Ex915 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_945_propagatesEx915() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(945)));
    match vm.run() {
        VMResult::Ok(Value::Status(945)) => {}
        other => panic!("exit code 945 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AI (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_946_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(946)));
    match vm.run() {
        VMResult::Ok(Value::Status(946)) => {}
        other => panic!("exit code 946 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_one_consecutive_runs_without_reset_still_blockedEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..171 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_947_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(947)));
    match vm.run() {
        VMResult::Ok(Value::Status(947)) => {}
        other => panic!("exit code 947 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_two_consecutive_runs_without_reset_still_blockedEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..172 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_948_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(948)));
    match vm.run() {
        VMResult::Ok(Value::Status(948)) => {}
        other => panic!("exit code 948 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_three_consecutive_runs_without_reset_still_blockedEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..173 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_949_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(949)));
    match vm.run() {
        VMResult::Ok(Value::Status(949)) => {}
        other => panic!("exit code 949 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_950_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(950)));
    match vm.run() {
        VMResult::Ok(Value::Status(950)) => {}
        other => panic!("exit code 950 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-129)));
    match vm.run() {
        VMResult::Ok(Value::Status(-129)) => {}
        other => panic!("status -129 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_951_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(951)));
    match vm.run() {
        VMResult::Ok(Value::Status(951)) => {}
        other => panic!("exit code 951 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-130)));
    match vm.run() {
        VMResult::Ok(Value::Status(-130)) => {}
        other => panic!("status -130 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_952_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(952)));
    match vm.run() {
        VMResult::Ok(Value::Status(952)) => {}
        other => panic!("exit code 952 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..61 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx946 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx946 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 61 {
                Some(953)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx946 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(953)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(953)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_953_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(953)));
    match vm.run() {
        VMResult::Ok(Value::Status(953)) => {}
        other => panic!("exit code 953 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(954)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..27 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 30);
    assert_eq!(vm.last_status, 954);
}

#[test]
fn subshell_end_exit_code_954_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(954)));
    match vm.run() {
        VMResult::Ok(Value::Status(954)) => {}
        other => panic!("exit code 954 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status955Ex946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(955)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 955);
}

#[test]
fn subshell_end_exit_code_955_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(955)));
    match vm.run() {
        VMResult::Ok(Value::Status(955)) => {}
        other => panic!("exit code 955 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_six_begins_twenty_four_ends_last_end_status_winsEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..26 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..24 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost956Ex946;
    impl ShellHost for CountingBeginEndHost956Ex946 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(956)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost956Ex946));
    match vm.run() {
        VMResult::Ok(Value::Status(956)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(956)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 26);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 24);
}

#[test]
fn subshell_end_exit_code_956_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(956)));
    match vm.run() {
        VMResult::Ok(Value::Status(956)) => {}
        other => panic!("exit code 956 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status957Ex946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex946;
    impl ShellHost for CountingBeginHost733Ex946 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(957)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex946));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 957);
}

#[test]
fn subshell_end_exit_code_957_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(957)));
    match vm.run() {
        VMResult::Ok(Value::Status(957)) => {}
        other => panic!("exit code 957 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx946() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(958)));
    for _ in 0..27 {
        match vm.run() {
            VMResult::Ok(Value::Status(958)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_958_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(958)));
    match vm.run() {
        VMResult::Ok(Value::Status(958)) => {}
        other => panic!("exit code 958 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status959Ex946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(959)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 959);
}

#[test]
fn subshell_end_exit_code_959_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(959)));
    match vm.run() {
        VMResult::Ok(Value::Status(959)) => {}
        other => panic!("exit code 959 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_960_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(960)));
    match vm.run() {
        VMResult::Ok(Value::Status(960)) => {}
        other => panic!("exit code 960 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status961Ex946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(961)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 961);
}

#[test]
fn subshell_end_exit_code_961_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(961)));
    match vm.run() {
        VMResult::Ok(Value::Status(961)) => {}
        other => panic!("exit code 961 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_four_consecutive_runs_without_reset_still_blockedEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..174 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_962_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(962)));
    match vm.run() {
        VMResult::Ok(Value::Status(962)) => {}
        other => panic!("exit code 962 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_five_consecutive_runs_without_reset_still_blockedEx946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..175 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_963_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(963)));
    match vm.run() {
        VMResult::Ok(Value::Status(963)) => {}
        other => panic!("exit code 963 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_964_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(964)));
    match vm.run() {
        VMResult::Ok(Value::Status(964)) => {}
        other => panic!("exit code 964 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 965;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(965)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 965, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_965_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(965)));
    match vm.run() {
        VMResult::Ok(Value::Status(965)) => {}
        other => panic!("exit code 965 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 966,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(966)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(966), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_966_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(966)));
    match vm.run() {
        VMResult::Ok(Value::Status(966)) => {}
        other => panic!("exit code 966 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-131)));
    match vm.run() {
        VMResult::Ok(Value::Status(-131)) => {}
        other => panic!("status -131 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_967_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(967)));
    match vm.run() {
        VMResult::Ok(Value::Status(967)) => {}
        other => panic!("exit code 967 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_twenty_nine_end_incrementing_from_fiveEx946() {
    let mut b = ChunkBuilder::new();
    for _ in 0..129 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 17 }));
    match vm.run() {
        VMResult::Ok(Value::Status(145)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(145)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_968_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(968)));
    match vm.run() {
        VMResult::Ok(Value::Status(968)) => {}
        other => panic!("exit code 968 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status969Ex946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost969Ex946 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost969Ex946 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost969Ex946 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_969_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(969)));
    match vm.run() {
        VMResult::Ok(Value::Status(969)) => {}
        other => panic!("exit code 969 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status970Ex946() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(970)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 970);
}

#[test]
fn subshell_end_exit_code_970_propagatesEx946() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(970)));
    match vm.run() {
        VMResult::Ok(Value::Status(970)) => {}
        other => panic!("exit code 970 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AJ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_971_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(971)));
    match vm.run() {
        VMResult::Ok(Value::Status(971)) => {}
        other => panic!("exit code 971 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_six_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..176 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_972_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(972)));
    match vm.run() {
        VMResult::Ok(Value::Status(972)) => {}
        other => panic!("exit code 972 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_seven_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..177 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_973_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(973)));
    match vm.run() {
        VMResult::Ok(Value::Status(973)) => {}
        other => panic!("exit code 973 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_eight_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..178 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_974_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(974)));
    match vm.run() {
        VMResult::Ok(Value::Status(974)) => {}
        other => panic!("exit code 974 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_end_incrementing_from_sixEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..130 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 18 }));
    match vm.run() {
        VMResult::Ok(Value::Status(147)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(147)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_975_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(975)));
    match vm.run() {
        VMResult::Ok(Value::Status(975)) => {}
        other => panic!("exit code 975 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-132)));
    match vm.run() {
        VMResult::Ok(Value::Status(-132)) => {}
        other => panic!("status -132 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_976_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(976)));
    match vm.run() {
        VMResult::Ok(Value::Status(976)) => {}
        other => panic!("exit code 976 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-133)));
    match vm.run() {
        VMResult::Ok(Value::Status(-133)) => {}
        other => panic!("status -133 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_977_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(977)));
    match vm.run() {
        VMResult::Ok(Value::Status(977)) => {}
        other => panic!("exit code 977 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..62 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx971 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx971 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 62 {
                Some(978)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx971 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(978)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(978)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_978_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(978)));
    match vm.run() {
        VMResult::Ok(Value::Status(978)) => {}
        other => panic!("exit code 978 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(979)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..28 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 31);
    assert_eq!(vm.last_status, 979);
}

#[test]
fn subshell_end_exit_code_979_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(979)));
    match vm.run() {
        VMResult::Ok(Value::Status(979)) => {}
        other => panic!("exit code 979 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status980Ex971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(980)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 980);
}

#[test]
fn subshell_end_exit_code_980_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(980)));
    match vm.run() {
        VMResult::Ok(Value::Status(980)) => {}
        other => panic!("exit code 980 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_seven_begins_twenty_five_ends_last_end_status_winsEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..27 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..25 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost981Ex971;
    impl ShellHost for CountingBeginEndHost981Ex971 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(981)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost981Ex971));
    match vm.run() {
        VMResult::Ok(Value::Status(981)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(981)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 27);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 25);
}

#[test]
fn subshell_end_exit_code_981_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(981)));
    match vm.run() {
        VMResult::Ok(Value::Status(981)) => {}
        other => panic!("exit code 981 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status982Ex971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(982)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 982);
}

#[test]
fn subshell_end_exit_code_982_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(982)));
    match vm.run() {
        VMResult::Ok(Value::Status(982)) => {}
        other => panic!("exit code 982 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx971() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(983)));
    for _ in 0..28 {
        match vm.run() {
            VMResult::Ok(Value::Status(983)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_983_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(983)));
    match vm.run() {
        VMResult::Ok(Value::Status(983)) => {}
        other => panic!("exit code 983 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status984Ex971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(984)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 984);
}

#[test]
fn subshell_end_exit_code_984_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(984)));
    match vm.run() {
        VMResult::Ok(Value::Status(984)) => {}
        other => panic!("exit code 984 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_one_end_incrementing_from_sevenEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..131 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 19 }));
    match vm.run() {
        VMResult::Ok(Value::Status(149)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(149)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_985_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(985)));
    match vm.run() {
        VMResult::Ok(Value::Status(985)) => {}
        other => panic!("exit code 985 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status986Ex971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(986)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 986);
}

#[test]
fn subshell_end_exit_code_986_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(986)));
    match vm.run() {
        VMResult::Ok(Value::Status(986)) => {}
        other => panic!("exit code 986 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_seventy_nine_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..179 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_987_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(987)));
    match vm.run() {
        VMResult::Ok(Value::Status(987)) => {}
        other => panic!("exit code 987 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..63 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx971 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx971 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 63 {
                Some(988)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx971 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(988)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(988)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_988_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(988)));
    match vm.run() {
        VMResult::Ok(Value::Status(988)) => {}
        other => panic!("exit code 988 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_989_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(989)));
    match vm.run() {
        VMResult::Ok(Value::Status(989)) => {}
        other => panic!("exit code 989 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status990Ex971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(990)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 990);
}

#[test]
fn subshell_end_exit_code_990_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(990)));
    match vm.run() {
        VMResult::Ok(Value::Status(990)) => {}
        other => panic!("exit code 990 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_two_end_incrementing_from_oneEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..132 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 13 }));
    match vm.run() {
        VMResult::Ok(Value::Status(144)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(144)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_991_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(991)));
    match vm.run() {
        VMResult::Ok(Value::Status(991)) => {}
        other => panic!("exit code 991 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 992;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(992)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 992, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_992_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(992)));
    match vm.run() {
        VMResult::Ok(Value::Status(992)) => {}
        other => panic!("exit code 992 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 993,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(993)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(993), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_993_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(993)));
    match vm.run() {
        VMResult::Ok(Value::Status(993)) => {}
        other => panic!("exit code 993 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..180 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_994_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(994)));
    match vm.run() {
        VMResult::Ok(Value::Status(994)) => {}
        other => panic!("exit code 994 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..64 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx971 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx971 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 64 {
                Some(995)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx971 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(995)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(995)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_995_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(995)));
    match vm.run() {
        VMResult::Ok(Value::Status(995)) => {}
        other => panic!("exit code 995 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_996Ex971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost996Ex971;
    impl ShellHost for PipelineSubshellHost996Ex971 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(996)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost996Ex971));
    match vm.run() {
        VMResult::Ok(Value::Status(996)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_996_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(996)));
    match vm.run() {
        VMResult::Ok(Value::Status(996)) => {}
        other => panic!("exit code 996 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_997Ex971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost997Ex971;
    impl ShellHost for SubshellThenPipelineHost997Ex971 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            997
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost997Ex971));
    match vm.run() {
        VMResult::Ok(Value::Status(997)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_997_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(997)));
    match vm.run() {
        VMResult::Ok(Value::Status(997)) => {}
        other => panic!("exit code 997 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-134)));
    match vm.run() {
        VMResult::Ok(Value::Status(-134)) => {}
        other => panic!("status -134 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_998_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(998)));
    match vm.run() {
        VMResult::Ok(Value::Status(998)) => {}
        other => panic!("exit code 998 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_three_end_incrementing_from_eightEx971() {
    let mut b = ChunkBuilder::new();
    for _ in 0..133 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 20 }));
    match vm.run() {
        VMResult::Ok(Value::Status(152)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(152)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_999_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(999)));
    match vm.run() {
        VMResult::Ok(Value::Status(999)) => {}
        other => panic!("exit code 999 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_one_consecutive_runs_without_reset_still_blockedEx971() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..181 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1000_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1000)));
    match vm.run() {
        VMResult::Ok(Value::Status(1000)) => {}
        other => panic!("exit code 1000 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1001Ex971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1001Ex971 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1001Ex971 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1001Ex971 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1001_propagatesEx971() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1001)));
    match vm.run() {
        VMResult::Ok(Value::Status(1001)) => {}
        other => panic!("exit code 1001 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AK (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1002_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1002)));
    match vm.run() {
        VMResult::Ok(Value::Status(1002)) => {}
        other => panic!("exit code 1002 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_two_consecutive_runs_without_reset_still_blockedEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..182 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1003_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1003)));
    match vm.run() {
        VMResult::Ok(Value::Status(1003)) => {}
        other => panic!("exit code 1003 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_three_consecutive_runs_without_reset_still_blockedEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..183 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1004_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1004)));
    match vm.run() {
        VMResult::Ok(Value::Status(1004)) => {}
        other => panic!("exit code 1004 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_four_consecutive_runs_without_reset_still_blockedEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..184 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1005_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1005)));
    match vm.run() {
        VMResult::Ok(Value::Status(1005)) => {}
        other => panic!("exit code 1005 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1006_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1006)));
    match vm.run() {
        VMResult::Ok(Value::Status(1006)) => {}
        other => panic!("exit code 1006 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-136)));
    match vm.run() {
        VMResult::Ok(Value::Status(-136)) => {}
        other => panic!("status -136 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1007_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1007)));
    match vm.run() {
        VMResult::Ok(Value::Status(1007)) => {}
        other => panic!("exit code 1007 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-137)));
    match vm.run() {
        VMResult::Ok(Value::Status(-137)) => {}
        other => panic!("status -137 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1008_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1008)));
    match vm.run() {
        VMResult::Ok(Value::Status(1008)) => {}
        other => panic!("exit code 1008 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..65 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1002 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1002 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 65 {
                Some(1009)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1002 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1009)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1009)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1009_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1009)));
    match vm.run() {
        VMResult::Ok(Value::Status(1009)) => {}
        other => panic!("exit code 1009 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1010)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..29 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 32);
    assert_eq!(vm.last_status, 1010);
}

#[test]
fn subshell_end_exit_code_1010_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1010)));
    match vm.run() {
        VMResult::Ok(Value::Status(1010)) => {}
        other => panic!("exit code 1010 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1011Ex1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1011)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1011);
}

#[test]
fn subshell_end_exit_code_1011_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1011)));
    match vm.run() {
        VMResult::Ok(Value::Status(1011)) => {}
        other => panic!("exit code 1011 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_eight_begins_twenty_six_ends_last_end_status_winsEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..28 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..26 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1012Ex1002;
    impl ShellHost for CountingBeginEndHost1012Ex1002 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1012)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1012Ex1002));
    match vm.run() {
        VMResult::Ok(Value::Status(1012)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1012)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 28);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 26);
}

#[test]
fn subshell_end_exit_code_1012_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1012)));
    match vm.run() {
        VMResult::Ok(Value::Status(1012)) => {}
        other => panic!("exit code 1012 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1013Ex1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1002;
    impl ShellHost for CountingBeginHost733Ex1002 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1013)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1002));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1013);
}

#[test]
fn subshell_end_exit_code_1013_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1013)));
    match vm.run() {
        VMResult::Ok(Value::Status(1013)) => {}
        other => panic!("exit code 1013 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1002() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1014)));
    for _ in 0..29 {
        match vm.run() {
            VMResult::Ok(Value::Status(1014)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1014_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1014)));
    match vm.run() {
        VMResult::Ok(Value::Status(1014)) => {}
        other => panic!("exit code 1014 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1015Ex1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1015)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1015);
}

#[test]
fn subshell_end_exit_code_1015_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1015)));
    match vm.run() {
        VMResult::Ok(Value::Status(1015)) => {}
        other => panic!("exit code 1015 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1016_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1016)));
    match vm.run() {
        VMResult::Ok(Value::Status(1016)) => {}
        other => panic!("exit code 1016 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1017Ex1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1017)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1017);
}

#[test]
fn subshell_end_exit_code_1017_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1017)));
    match vm.run() {
        VMResult::Ok(Value::Status(1017)) => {}
        other => panic!("exit code 1017 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_five_consecutive_runs_without_reset_still_blockedEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..185 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1018_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1018)));
    match vm.run() {
        VMResult::Ok(Value::Status(1018)) => {}
        other => panic!("exit code 1018 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_six_consecutive_runs_without_reset_still_blockedEx1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..186 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1019_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1019)));
    match vm.run() {
        VMResult::Ok(Value::Status(1019)) => {}
        other => panic!("exit code 1019 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1020_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1020)));
    match vm.run() {
        VMResult::Ok(Value::Status(1020)) => {}
        other => panic!("exit code 1020 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1021;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1021)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1021, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1021_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1021)));
    match vm.run() {
        VMResult::Ok(Value::Status(1021)) => {}
        other => panic!("exit code 1021 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1022,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1022)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1022), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1022_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1022)));
    match vm.run() {
        VMResult::Ok(Value::Status(1022)) => {}
        other => panic!("exit code 1022 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-138)));
    match vm.run() {
        VMResult::Ok(Value::Status(-138)) => {}
        other => panic!("status -138 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1023_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1023)));
    match vm.run() {
        VMResult::Ok(Value::Status(1023)) => {}
        other => panic!("exit code 1023 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_six_end_incrementing_from_fiveEx1002() {
    let mut b = ChunkBuilder::new();
    for _ in 0..136 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 20 }));
    match vm.run() {
        VMResult::Ok(Value::Status(155)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(155)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1024_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1024)));
    match vm.run() {
        VMResult::Ok(Value::Status(1024)) => {}
        other => panic!("exit code 1024 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1025Ex1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1025Ex1002 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1025Ex1002 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1025Ex1002 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1025_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1025)));
    match vm.run() {
        VMResult::Ok(Value::Status(1025)) => {}
        other => panic!("exit code 1025 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1026Ex1002() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1026)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1026);
}

#[test]
fn subshell_end_exit_code_1026_propagatesEx1002() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1026)));
    match vm.run() {
        VMResult::Ok(Value::Status(1026)) => {}
        other => panic!("exit code 1026 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AL (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1027_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1027)));
    match vm.run() {
        VMResult::Ok(Value::Status(1027)) => {}
        other => panic!("exit code 1027 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_seven_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..187 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1028_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1028)));
    match vm.run() {
        VMResult::Ok(Value::Status(1028)) => {}
        other => panic!("exit code 1028 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_eight_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..188 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1029_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1029)));
    match vm.run() {
        VMResult::Ok(Value::Status(1029)) => {}
        other => panic!("exit code 1029 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_eighty_nine_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..189 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1030_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1030)));
    match vm.run() {
        VMResult::Ok(Value::Status(1030)) => {}
        other => panic!("exit code 1030 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_seven_end_incrementing_from_sixEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..137 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 21 }));
    match vm.run() {
        VMResult::Ok(Value::Status(157)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(157)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1031_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1031)));
    match vm.run() {
        VMResult::Ok(Value::Status(1031)) => {}
        other => panic!("exit code 1031 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-139)));
    match vm.run() {
        VMResult::Ok(Value::Status(-139)) => {}
        other => panic!("status -139 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1032_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1032)));
    match vm.run() {
        VMResult::Ok(Value::Status(1032)) => {}
        other => panic!("exit code 1032 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-140)));
    match vm.run() {
        VMResult::Ok(Value::Status(-140)) => {}
        other => panic!("status -140 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1033_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1033)));
    match vm.run() {
        VMResult::Ok(Value::Status(1033)) => {}
        other => panic!("exit code 1033 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..66 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1027 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1027 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 66 {
                Some(1034)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1027 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1034)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1034)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1034_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1034)));
    match vm.run() {
        VMResult::Ok(Value::Status(1034)) => {}
        other => panic!("exit code 1034 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1035)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..30 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 33);
    assert_eq!(vm.last_status, 1035);
}

#[test]
fn subshell_end_exit_code_1035_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1035)));
    match vm.run() {
        VMResult::Ok(Value::Status(1035)) => {}
        other => panic!("exit code 1035 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1036Ex1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1036)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1036);
}

#[test]
fn subshell_end_exit_code_1036_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1036)));
    match vm.run() {
        VMResult::Ok(Value::Status(1036)) => {}
        other => panic!("exit code 1036 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_nine_begins_twenty_seven_ends_last_end_status_winsEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..29 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..27 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1037Ex1027;
    impl ShellHost for CountingBeginEndHost1037Ex1027 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1037)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1037Ex1027));
    match vm.run() {
        VMResult::Ok(Value::Status(1037)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1037)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 29);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 27);
}

#[test]
fn subshell_end_exit_code_1037_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1037)));
    match vm.run() {
        VMResult::Ok(Value::Status(1037)) => {}
        other => panic!("exit code 1037 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1038Ex1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1038)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1038);
}

#[test]
fn subshell_end_exit_code_1038_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1038)));
    match vm.run() {
        VMResult::Ok(Value::Status(1038)) => {}
        other => panic!("exit code 1038 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1027() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1039)));
    for _ in 0..30 {
        match vm.run() {
            VMResult::Ok(Value::Status(1039)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1039_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1039)));
    match vm.run() {
        VMResult::Ok(Value::Status(1039)) => {}
        other => panic!("exit code 1039 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1040Ex1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1040)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1040);
}

#[test]
fn subshell_end_exit_code_1040_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1040)));
    match vm.run() {
        VMResult::Ok(Value::Status(1040)) => {}
        other => panic!("exit code 1040 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_eight_end_incrementing_from_sevenEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..138 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 22 }));
    match vm.run() {
        VMResult::Ok(Value::Status(159)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(159)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1041_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1041)));
    match vm.run() {
        VMResult::Ok(Value::Status(1041)) => {}
        other => panic!("exit code 1041 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1042Ex1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1042)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1042);
}

#[test]
fn subshell_end_exit_code_1042_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1042)));
    match vm.run() {
        VMResult::Ok(Value::Status(1042)) => {}
        other => panic!("exit code 1042 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..190 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1043_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1043)));
    match vm.run() {
        VMResult::Ok(Value::Status(1043)) => {}
        other => panic!("exit code 1043 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..67 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1027 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1027 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 67 {
                Some(1044)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1027 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1044)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1044)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1044_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1044)));
    match vm.run() {
        VMResult::Ok(Value::Status(1044)) => {}
        other => panic!("exit code 1044 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1045_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1045)));
    match vm.run() {
        VMResult::Ok(Value::Status(1045)) => {}
        other => panic!("exit code 1045 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1046Ex1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1046)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1046);
}

#[test]
fn subshell_end_exit_code_1046_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1046)));
    match vm.run() {
        VMResult::Ok(Value::Status(1046)) => {}
        other => panic!("exit code 1046 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_thirty_nine_end_incrementing_from_oneEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..139 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 16 }));
    match vm.run() {
        VMResult::Ok(Value::Status(154)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(154)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1047_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1047)));
    match vm.run() {
        VMResult::Ok(Value::Status(1047)) => {}
        other => panic!("exit code 1047 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1048;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1048)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1048, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1048_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1048)));
    match vm.run() {
        VMResult::Ok(Value::Status(1048)) => {}
        other => panic!("exit code 1048 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1049,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1049)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1049), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1049_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1049)));
    match vm.run() {
        VMResult::Ok(Value::Status(1049)) => {}
        other => panic!("exit code 1049 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_one_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..191 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1050_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1050)));
    match vm.run() {
        VMResult::Ok(Value::Status(1050)) => {}
        other => panic!("exit code 1050 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..68 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1027 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1027 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 68 {
                Some(1051)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1027 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1051)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1051)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1051_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1051)));
    match vm.run() {
        VMResult::Ok(Value::Status(1051)) => {}
        other => panic!("exit code 1051 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1052Ex1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1052Ex1027;
    impl ShellHost for PipelineSubshellHost1052Ex1027 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1052)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1052Ex1027));
    match vm.run() {
        VMResult::Ok(Value::Status(1052)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1052_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1052)));
    match vm.run() {
        VMResult::Ok(Value::Status(1052)) => {}
        other => panic!("exit code 1052 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1053Ex1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1053Ex1027;
    impl ShellHost for SubshellThenPipelineHost1053Ex1027 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1053
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1053Ex1027));
    match vm.run() {
        VMResult::Ok(Value::Status(1053)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1053_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1053)));
    match vm.run() {
        VMResult::Ok(Value::Status(1053)) => {}
        other => panic!("exit code 1053 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-141)));
    match vm.run() {
        VMResult::Ok(Value::Status(-141)) => {}
        other => panic!("status -141 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1054_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1054)));
    match vm.run() {
        VMResult::Ok(Value::Status(1054)) => {}
        other => panic!("exit code 1054 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_end_incrementing_from_eightEx1027() {
    let mut b = ChunkBuilder::new();
    for _ in 0..140 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 23 }));
    match vm.run() {
        VMResult::Ok(Value::Status(162)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(162)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1055_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1055)));
    match vm.run() {
        VMResult::Ok(Value::Status(1055)) => {}
        other => panic!("exit code 1055 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_two_consecutive_runs_without_reset_still_blockedEx1027() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..192 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1056_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1056)));
    match vm.run() {
        VMResult::Ok(Value::Status(1056)) => {}
        other => panic!("exit code 1056 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1057Ex1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1057Ex1027 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1057Ex1027 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1057Ex1027 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1057_propagatesEx1027() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1057)));
    match vm.run() {
        VMResult::Ok(Value::Status(1057)) => {}
        other => panic!("exit code 1057 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AM (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1058_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1058)));
    match vm.run() {
        VMResult::Ok(Value::Status(1058)) => {}
        other => panic!("exit code 1058 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_three_consecutive_runs_without_reset_still_blockedEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..193 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1059_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1059)));
    match vm.run() {
        VMResult::Ok(Value::Status(1059)) => {}
        other => panic!("exit code 1059 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_four_consecutive_runs_without_reset_still_blockedEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..194 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1060_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1060)));
    match vm.run() {
        VMResult::Ok(Value::Status(1060)) => {}
        other => panic!("exit code 1060 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_five_consecutive_runs_without_reset_still_blockedEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..195 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1061_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1061)));
    match vm.run() {
        VMResult::Ok(Value::Status(1061)) => {}
        other => panic!("exit code 1061 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1062_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1062)));
    match vm.run() {
        VMResult::Ok(Value::Status(1062)) => {}
        other => panic!("exit code 1062 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-143)));
    match vm.run() {
        VMResult::Ok(Value::Status(-143)) => {}
        other => panic!("status -143 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1063_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1063)));
    match vm.run() {
        VMResult::Ok(Value::Status(1063)) => {}
        other => panic!("exit code 1063 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-144)));
    match vm.run() {
        VMResult::Ok(Value::Status(-144)) => {}
        other => panic!("status -144 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1064_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1064)));
    match vm.run() {
        VMResult::Ok(Value::Status(1064)) => {}
        other => panic!("exit code 1064 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..69 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1058 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1058 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 69 {
                Some(1065)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1058 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1065)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1065)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1065_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1065)));
    match vm.run() {
        VMResult::Ok(Value::Status(1065)) => {}
        other => panic!("exit code 1065 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1066)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..31 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 34);
    assert_eq!(vm.last_status, 1066);
}

#[test]
fn subshell_end_exit_code_1066_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1066)));
    match vm.run() {
        VMResult::Ok(Value::Status(1066)) => {}
        other => panic!("exit code 1066 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1067Ex1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1067)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1067);
}

#[test]
fn subshell_end_exit_code_1067_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1067)));
    match vm.run() {
        VMResult::Ok(Value::Status(1067)) => {}
        other => panic!("exit code 1067 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_begins_twenty_eight_ends_last_end_status_winsEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..30 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..28 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1068Ex1058;
    impl ShellHost for CountingBeginEndHost1068Ex1058 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1068)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1068Ex1058));
    match vm.run() {
        VMResult::Ok(Value::Status(1068)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1068)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 30);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 28);
}

#[test]
fn subshell_end_exit_code_1068_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1068)));
    match vm.run() {
        VMResult::Ok(Value::Status(1068)) => {}
        other => panic!("exit code 1068 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1069Ex1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1058;
    impl ShellHost for CountingBeginHost733Ex1058 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1069)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1058));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1069);
}

#[test]
fn subshell_end_exit_code_1069_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1069)));
    match vm.run() {
        VMResult::Ok(Value::Status(1069)) => {}
        other => panic!("exit code 1069 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1058() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1070)));
    for _ in 0..31 {
        match vm.run() {
            VMResult::Ok(Value::Status(1070)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1070_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1070)));
    match vm.run() {
        VMResult::Ok(Value::Status(1070)) => {}
        other => panic!("exit code 1070 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1071Ex1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1071)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1071);
}

#[test]
fn subshell_end_exit_code_1071_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1071)));
    match vm.run() {
        VMResult::Ok(Value::Status(1071)) => {}
        other => panic!("exit code 1071 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1072_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1072)));
    match vm.run() {
        VMResult::Ok(Value::Status(1072)) => {}
        other => panic!("exit code 1072 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1073Ex1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1073)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1073);
}

#[test]
fn subshell_end_exit_code_1073_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1073)));
    match vm.run() {
        VMResult::Ok(Value::Status(1073)) => {}
        other => panic!("exit code 1073 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_six_consecutive_runs_without_reset_still_blockedEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..196 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1074_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1074)));
    match vm.run() {
        VMResult::Ok(Value::Status(1074)) => {}
        other => panic!("exit code 1074 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_seven_consecutive_runs_without_reset_still_blockedEx1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..197 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1075_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1075)));
    match vm.run() {
        VMResult::Ok(Value::Status(1075)) => {}
        other => panic!("exit code 1075 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1076_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1076)));
    match vm.run() {
        VMResult::Ok(Value::Status(1076)) => {}
        other => panic!("exit code 1076 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1077;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1077)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1077, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1077_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1077)));
    match vm.run() {
        VMResult::Ok(Value::Status(1077)) => {}
        other => panic!("exit code 1077 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1078,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1078)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1078), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1078_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1078)));
    match vm.run() {
        VMResult::Ok(Value::Status(1078)) => {}
        other => panic!("exit code 1078 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-145)));
    match vm.run() {
        VMResult::Ok(Value::Status(-145)) => {}
        other => panic!("status -145 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1079_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1079)));
    match vm.run() {
        VMResult::Ok(Value::Status(1079)) => {}
        other => panic!("exit code 1079 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_three_end_incrementing_from_fiveEx1058() {
    let mut b = ChunkBuilder::new();
    for _ in 0..143 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 23 }));
    match vm.run() {
        VMResult::Ok(Value::Status(165)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(165)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1080_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1080)));
    match vm.run() {
        VMResult::Ok(Value::Status(1080)) => {}
        other => panic!("exit code 1080 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1081Ex1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1081Ex1058 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1081Ex1058 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1081Ex1058 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1081_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1081)));
    match vm.run() {
        VMResult::Ok(Value::Status(1081)) => {}
        other => panic!("exit code 1081 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1082Ex1058() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1082)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1082);
}

#[test]
fn subshell_end_exit_code_1082_propagatesEx1058() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1082)));
    match vm.run() {
        VMResult::Ok(Value::Status(1082)) => {}
        other => panic!("exit code 1082 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AN (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1083_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1083)));
    match vm.run() {
        VMResult::Ok(Value::Status(1083)) => {}
        other => panic!("exit code 1083 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_eight_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..198 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1084_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1084)));
    match vm.run() {
        VMResult::Ok(Value::Status(1084)) => {}
        other => panic!("exit code 1084 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_one_hundred_ninety_nine_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..199 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1085_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1085)));
    match vm.run() {
        VMResult::Ok(Value::Status(1085)) => {}
        other => panic!("exit code 1085 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..200 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1086_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1086)));
    match vm.run() {
        VMResult::Ok(Value::Status(1086)) => {}
        other => panic!("exit code 1086 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_four_end_incrementing_from_sixEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..144 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 24 }));
    match vm.run() {
        VMResult::Ok(Value::Status(167)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(167)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1087_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1087)));
    match vm.run() {
        VMResult::Ok(Value::Status(1087)) => {}
        other => panic!("exit code 1087 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-146)));
    match vm.run() {
        VMResult::Ok(Value::Status(-146)) => {}
        other => panic!("status -146 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1088_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1088)));
    match vm.run() {
        VMResult::Ok(Value::Status(1088)) => {}
        other => panic!("exit code 1088 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-147)));
    match vm.run() {
        VMResult::Ok(Value::Status(-147)) => {}
        other => panic!("status -147 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1089_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1089)));
    match vm.run() {
        VMResult::Ok(Value::Status(1089)) => {}
        other => panic!("exit code 1089 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..70 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1083 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1083 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 70 {
                Some(1090)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1083 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1090)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1090)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1090_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1090)));
    match vm.run() {
        VMResult::Ok(Value::Status(1090)) => {}
        other => panic!("exit code 1090 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1091)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..32 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 35);
    assert_eq!(vm.last_status, 1091);
}

#[test]
fn subshell_end_exit_code_1091_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1091)));
    match vm.run() {
        VMResult::Ok(Value::Status(1091)) => {}
        other => panic!("exit code 1091 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1092Ex1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1092)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1092);
}

#[test]
fn subshell_end_exit_code_1092_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1092)));
    match vm.run() {
        VMResult::Ok(Value::Status(1092)) => {}
        other => panic!("exit code 1092 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_one_begins_twenty_nine_ends_last_end_status_winsEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..31 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..29 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1093Ex1083;
    impl ShellHost for CountingBeginEndHost1093Ex1083 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1093)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1093Ex1083));
    match vm.run() {
        VMResult::Ok(Value::Status(1093)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1093)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 31);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 29);
}

#[test]
fn subshell_end_exit_code_1093_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1093)));
    match vm.run() {
        VMResult::Ok(Value::Status(1093)) => {}
        other => panic!("exit code 1093 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1094Ex1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1094)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1094);
}

#[test]
fn subshell_end_exit_code_1094_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1094)));
    match vm.run() {
        VMResult::Ok(Value::Status(1094)) => {}
        other => panic!("exit code 1094 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1083() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1095)));
    for _ in 0..32 {
        match vm.run() {
            VMResult::Ok(Value::Status(1095)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1095_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1095)));
    match vm.run() {
        VMResult::Ok(Value::Status(1095)) => {}
        other => panic!("exit code 1095 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1096Ex1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1096)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1096);
}

#[test]
fn subshell_end_exit_code_1096_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1096)));
    match vm.run() {
        VMResult::Ok(Value::Status(1096)) => {}
        other => panic!("exit code 1096 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_five_end_incrementing_from_sevenEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..145 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 25 }));
    match vm.run() {
        VMResult::Ok(Value::Status(169)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(169)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1097_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1097)));
    match vm.run() {
        VMResult::Ok(Value::Status(1097)) => {}
        other => panic!("exit code 1097 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1098Ex1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1098)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1098);
}

#[test]
fn subshell_end_exit_code_1098_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1098)));
    match vm.run() {
        VMResult::Ok(Value::Status(1098)) => {}
        other => panic!("exit code 1098 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_one_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..201 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1099_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1099)));
    match vm.run() {
        VMResult::Ok(Value::Status(1099)) => {}
        other => panic!("exit code 1099 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..71 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1083 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1083 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 71 {
                Some(1100)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1083 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1100)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1100)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1100_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1100)));
    match vm.run() {
        VMResult::Ok(Value::Status(1100)) => {}
        other => panic!("exit code 1100 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1101_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1101)));
    match vm.run() {
        VMResult::Ok(Value::Status(1101)) => {}
        other => panic!("exit code 1101 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1102Ex1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1102)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1102);
}

#[test]
fn subshell_end_exit_code_1102_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1102)));
    match vm.run() {
        VMResult::Ok(Value::Status(1102)) => {}
        other => panic!("exit code 1102 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_six_end_incrementing_from_oneEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..146 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 19 }));
    match vm.run() {
        VMResult::Ok(Value::Status(164)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(164)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1103_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1103)));
    match vm.run() {
        VMResult::Ok(Value::Status(1103)) => {}
        other => panic!("exit code 1103 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1104;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1104)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1104_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1104)));
    match vm.run() {
        VMResult::Ok(Value::Status(1104)) => {}
        other => panic!("exit code 1104 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1105,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1105)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1105), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1105_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1105)));
    match vm.run() {
        VMResult::Ok(Value::Status(1105)) => {}
        other => panic!("exit code 1105 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_two_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..202 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1106_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1106)));
    match vm.run() {
        VMResult::Ok(Value::Status(1106)) => {}
        other => panic!("exit code 1106 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..72 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1083 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1083 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 72 {
                Some(1107)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1083 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1107)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1107)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1107_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1107)));
    match vm.run() {
        VMResult::Ok(Value::Status(1107)) => {}
        other => panic!("exit code 1107 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1108Ex1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1108Ex1083;
    impl ShellHost for PipelineSubshellHost1108Ex1083 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1108)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1108Ex1083));
    match vm.run() {
        VMResult::Ok(Value::Status(1108)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1108_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1108)));
    match vm.run() {
        VMResult::Ok(Value::Status(1108)) => {}
        other => panic!("exit code 1108 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1109Ex1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1109Ex1083;
    impl ShellHost for SubshellThenPipelineHost1109Ex1083 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1109
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1109Ex1083));
    match vm.run() {
        VMResult::Ok(Value::Status(1109)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1109_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1109)));
    match vm.run() {
        VMResult::Ok(Value::Status(1109)) => {}
        other => panic!("exit code 1109 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-148)));
    match vm.run() {
        VMResult::Ok(Value::Status(-148)) => {}
        other => panic!("status -148 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1110_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1110)));
    match vm.run() {
        VMResult::Ok(Value::Status(1110)) => {}
        other => panic!("exit code 1110 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_forty_seven_end_incrementing_from_eightEx1083() {
    let mut b = ChunkBuilder::new();
    for _ in 0..147 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 26 }));
    match vm.run() {
        VMResult::Ok(Value::Status(172)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(172)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1111_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1111)));
    match vm.run() {
        VMResult::Ok(Value::Status(1111)) => {}
        other => panic!("exit code 1111 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_three_consecutive_runs_without_reset_still_blockedEx1083() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..203 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1112_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1112)));
    match vm.run() {
        VMResult::Ok(Value::Status(1112)) => {}
        other => panic!("exit code 1112 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1113Ex1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1113Ex1083 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1113Ex1083 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1113Ex1083 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1113_propagatesEx1083() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1113)));
    match vm.run() {
        VMResult::Ok(Value::Status(1113)) => {}
        other => panic!("exit code 1113 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AO (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1114_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1114)));
    match vm.run() {
        VMResult::Ok(Value::Status(1114)) => {}
        other => panic!("exit code 1114 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_four_consecutive_runs_without_reset_still_blockedEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..204 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1115_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1115)));
    match vm.run() {
        VMResult::Ok(Value::Status(1115)) => {}
        other => panic!("exit code 1115 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_five_consecutive_runs_without_reset_still_blockedEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..205 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1116_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1116)));
    match vm.run() {
        VMResult::Ok(Value::Status(1116)) => {}
        other => panic!("exit code 1116 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_six_consecutive_runs_without_reset_still_blockedEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..206 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1117_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1117)));
    match vm.run() {
        VMResult::Ok(Value::Status(1117)) => {}
        other => panic!("exit code 1117 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1118_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1118)));
    match vm.run() {
        VMResult::Ok(Value::Status(1118)) => {}
        other => panic!("exit code 1118 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-150)));
    match vm.run() {
        VMResult::Ok(Value::Status(-150)) => {}
        other => panic!("status -150 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1119_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1119)));
    match vm.run() {
        VMResult::Ok(Value::Status(1119)) => {}
        other => panic!("exit code 1119 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-151)));
    match vm.run() {
        VMResult::Ok(Value::Status(-151)) => {}
        other => panic!("status -151 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1120_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1120)));
    match vm.run() {
        VMResult::Ok(Value::Status(1120)) => {}
        other => panic!("exit code 1120 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..73 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1114 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1114 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 73 {
                Some(1121)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1114 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1121)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1121)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1121_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1121)));
    match vm.run() {
        VMResult::Ok(Value::Status(1121)) => {}
        other => panic!("exit code 1121 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1122)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..33 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 36);
    assert_eq!(vm.last_status, 1122);
}

#[test]
fn subshell_end_exit_code_1122_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1122)));
    match vm.run() {
        VMResult::Ok(Value::Status(1122)) => {}
        other => panic!("exit code 1122 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1123Ex1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1123)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1123);
}

#[test]
fn subshell_end_exit_code_1123_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1123)));
    match vm.run() {
        VMResult::Ok(Value::Status(1123)) => {}
        other => panic!("exit code 1123 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_two_begins_thirty_ends_last_end_status_winsEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..32 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..30 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1124Ex1114;
    impl ShellHost for CountingBeginEndHost1124Ex1114 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1124)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1124Ex1114));
    match vm.run() {
        VMResult::Ok(Value::Status(1124)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1124)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 32);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 30);
}

#[test]
fn subshell_end_exit_code_1124_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1124)));
    match vm.run() {
        VMResult::Ok(Value::Status(1124)) => {}
        other => panic!("exit code 1124 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1125Ex1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1114;
    impl ShellHost for CountingBeginHost733Ex1114 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1125)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1114));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1125);
}

#[test]
fn subshell_end_exit_code_1125_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1125)));
    match vm.run() {
        VMResult::Ok(Value::Status(1125)) => {}
        other => panic!("exit code 1125 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1114() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1126)));
    for _ in 0..33 {
        match vm.run() {
            VMResult::Ok(Value::Status(1126)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1126_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1126)));
    match vm.run() {
        VMResult::Ok(Value::Status(1126)) => {}
        other => panic!("exit code 1126 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1127Ex1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1127)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1127);
}

#[test]
fn subshell_end_exit_code_1127_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1127)));
    match vm.run() {
        VMResult::Ok(Value::Status(1127)) => {}
        other => panic!("exit code 1127 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1128_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1128)));
    match vm.run() {
        VMResult::Ok(Value::Status(1128)) => {}
        other => panic!("exit code 1128 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1129Ex1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1129)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1129);
}

#[test]
fn subshell_end_exit_code_1129_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1129)));
    match vm.run() {
        VMResult::Ok(Value::Status(1129)) => {}
        other => panic!("exit code 1129 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seven_consecutive_runs_without_reset_still_blockedEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..207 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1130_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1130)));
    match vm.run() {
        VMResult::Ok(Value::Status(1130)) => {}
        other => panic!("exit code 1130 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eight_consecutive_runs_without_reset_still_blockedEx1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..208 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1131_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1131)));
    match vm.run() {
        VMResult::Ok(Value::Status(1131)) => {}
        other => panic!("exit code 1131 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1132_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1132)));
    match vm.run() {
        VMResult::Ok(Value::Status(1132)) => {}
        other => panic!("exit code 1132 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1133;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1133)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1133, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1133_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1133)));
    match vm.run() {
        VMResult::Ok(Value::Status(1133)) => {}
        other => panic!("exit code 1133 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1134,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1134)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1134), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1134_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1134)));
    match vm.run() {
        VMResult::Ok(Value::Status(1134)) => {}
        other => panic!("exit code 1134 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-152)));
    match vm.run() {
        VMResult::Ok(Value::Status(-152)) => {}
        other => panic!("status -152 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1135_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1135)));
    match vm.run() {
        VMResult::Ok(Value::Status(1135)) => {}
        other => panic!("exit code 1135 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_end_incrementing_from_fiveEx1114() {
    let mut b = ChunkBuilder::new();
    for _ in 0..150 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 26 }));
    match vm.run() {
        VMResult::Ok(Value::Status(175)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(175)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1136_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1136)));
    match vm.run() {
        VMResult::Ok(Value::Status(1136)) => {}
        other => panic!("exit code 1136 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1137Ex1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1137Ex1114 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1137Ex1114 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1137Ex1114 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1137_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1137)));
    match vm.run() {
        VMResult::Ok(Value::Status(1137)) => {}
        other => panic!("exit code 1137 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1138Ex1114() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1138)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1138);
}

#[test]
fn subshell_end_exit_code_1138_propagatesEx1114() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1138)));
    match vm.run() {
        VMResult::Ok(Value::Status(1138)) => {}
        other => panic!("exit code 1138 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AP (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1139_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1139)));
    match vm.run() {
        VMResult::Ok(Value::Status(1139)) => {}
        other => panic!("exit code 1139 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_nine_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..209 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1140_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1140)));
    match vm.run() {
        VMResult::Ok(Value::Status(1140)) => {}
        other => panic!("exit code 1140 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ten_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..210 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1141_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1141)));
    match vm.run() {
        VMResult::Ok(Value::Status(1141)) => {}
        other => panic!("exit code 1141 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eleven_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..211 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1142_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1142)));
    match vm.run() {
        VMResult::Ok(Value::Status(1142)) => {}
        other => panic!("exit code 1142 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_one_end_incrementing_from_sixEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..151 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 27 }));
    match vm.run() {
        VMResult::Ok(Value::Status(177)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(177)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1143_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1143)));
    match vm.run() {
        VMResult::Ok(Value::Status(1143)) => {}
        other => panic!("exit code 1143 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-153)));
    match vm.run() {
        VMResult::Ok(Value::Status(-153)) => {}
        other => panic!("status -153 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1144_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1144)));
    match vm.run() {
        VMResult::Ok(Value::Status(1144)) => {}
        other => panic!("exit code 1144 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-154)));
    match vm.run() {
        VMResult::Ok(Value::Status(-154)) => {}
        other => panic!("status -154 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1145_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1145)));
    match vm.run() {
        VMResult::Ok(Value::Status(1145)) => {}
        other => panic!("exit code 1145 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..74 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1139 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1139 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 74 {
                Some(1146)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1139 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1146)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1146)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1146_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1146)));
    match vm.run() {
        VMResult::Ok(Value::Status(1146)) => {}
        other => panic!("exit code 1146 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1147)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..34 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 37);
    assert_eq!(vm.last_status, 1147);
}

#[test]
fn subshell_end_exit_code_1147_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1147)));
    match vm.run() {
        VMResult::Ok(Value::Status(1147)) => {}
        other => panic!("exit code 1147 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1148Ex1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1148)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1148);
}

#[test]
fn subshell_end_exit_code_1148_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1148)));
    match vm.run() {
        VMResult::Ok(Value::Status(1148)) => {}
        other => panic!("exit code 1148 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_three_begins_thirty_one_ends_last_end_status_winsEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..33 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..31 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1149Ex1139;
    impl ShellHost for CountingBeginEndHost1149Ex1139 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1149)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1149Ex1139));
    match vm.run() {
        VMResult::Ok(Value::Status(1149)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1149)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 33);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 31);
}

#[test]
fn subshell_end_exit_code_1149_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1149)));
    match vm.run() {
        VMResult::Ok(Value::Status(1149)) => {}
        other => panic!("exit code 1149 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1150Ex1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1150)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1150);
}

#[test]
fn subshell_end_exit_code_1150_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1150)));
    match vm.run() {
        VMResult::Ok(Value::Status(1150)) => {}
        other => panic!("exit code 1150 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1139() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1151)));
    for _ in 0..34 {
        match vm.run() {
            VMResult::Ok(Value::Status(1151)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1151_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1151)));
    match vm.run() {
        VMResult::Ok(Value::Status(1151)) => {}
        other => panic!("exit code 1151 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1152Ex1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1152)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1152);
}

#[test]
fn subshell_end_exit_code_1152_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1152)));
    match vm.run() {
        VMResult::Ok(Value::Status(1152)) => {}
        other => panic!("exit code 1152 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_two_end_incrementing_from_sevenEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..152 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 28 }));
    match vm.run() {
        VMResult::Ok(Value::Status(179)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(179)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1153_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1153)));
    match vm.run() {
        VMResult::Ok(Value::Status(1153)) => {}
        other => panic!("exit code 1153 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1154Ex1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1154)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1154);
}

#[test]
fn subshell_end_exit_code_1154_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1154)));
    match vm.run() {
        VMResult::Ok(Value::Status(1154)) => {}
        other => panic!("exit code 1154 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twelve_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..212 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1155_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1155)));
    match vm.run() {
        VMResult::Ok(Value::Status(1155)) => {}
        other => panic!("exit code 1155 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..75 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1139 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1139 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 75 {
                Some(1156)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1139 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1156)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1156)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1156_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1156)));
    match vm.run() {
        VMResult::Ok(Value::Status(1156)) => {}
        other => panic!("exit code 1156 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1157_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1157)));
    match vm.run() {
        VMResult::Ok(Value::Status(1157)) => {}
        other => panic!("exit code 1157 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1158Ex1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1158)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1158);
}

#[test]
fn subshell_end_exit_code_1158_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1158)));
    match vm.run() {
        VMResult::Ok(Value::Status(1158)) => {}
        other => panic!("exit code 1158 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_three_end_incrementing_from_oneEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..153 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 22 }));
    match vm.run() {
        VMResult::Ok(Value::Status(174)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(174)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1159_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1159)));
    match vm.run() {
        VMResult::Ok(Value::Status(1159)) => {}
        other => panic!("exit code 1159 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1160;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1160)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1160, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1160_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1160)));
    match vm.run() {
        VMResult::Ok(Value::Status(1160)) => {}
        other => panic!("exit code 1160 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1161,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1161)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1161), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1161_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1161)));
    match vm.run() {
        VMResult::Ok(Value::Status(1161)) => {}
        other => panic!("exit code 1161 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirteen_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..213 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1162_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1162)));
    match vm.run() {
        VMResult::Ok(Value::Status(1162)) => {}
        other => panic!("exit code 1162 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..76 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1139 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1139 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 76 {
                Some(1163)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1139 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1163)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1163)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1163_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1163)));
    match vm.run() {
        VMResult::Ok(Value::Status(1163)) => {}
        other => panic!("exit code 1163 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1164Ex1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1164Ex1139;
    impl ShellHost for PipelineSubshellHost1164Ex1139 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1164)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1164Ex1139));
    match vm.run() {
        VMResult::Ok(Value::Status(1164)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1164_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1164)));
    match vm.run() {
        VMResult::Ok(Value::Status(1164)) => {}
        other => panic!("exit code 1164 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1165Ex1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1165Ex1139;
    impl ShellHost for SubshellThenPipelineHost1165Ex1139 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1165
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1165Ex1139));
    match vm.run() {
        VMResult::Ok(Value::Status(1165)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1165_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1165)));
    match vm.run() {
        VMResult::Ok(Value::Status(1165)) => {}
        other => panic!("exit code 1165 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-155)));
    match vm.run() {
        VMResult::Ok(Value::Status(-155)) => {}
        other => panic!("status -155 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1166_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1166)));
    match vm.run() {
        VMResult::Ok(Value::Status(1166)) => {}
        other => panic!("exit code 1166 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_four_end_incrementing_from_eightEx1139() {
    let mut b = ChunkBuilder::new();
    for _ in 0..154 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 29 }));
    match vm.run() {
        VMResult::Ok(Value::Status(182)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(182)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1167_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1167)));
    match vm.run() {
        VMResult::Ok(Value::Status(1167)) => {}
        other => panic!("exit code 1167 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fourteen_consecutive_runs_without_reset_still_blockedEx1139() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..214 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1168_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1168)));
    match vm.run() {
        VMResult::Ok(Value::Status(1168)) => {}
        other => panic!("exit code 1168 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1169Ex1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1169Ex1139 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1169Ex1139 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1169Ex1139 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1169_propagatesEx1139() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1169)));
    match vm.run() {
        VMResult::Ok(Value::Status(1169)) => {}
        other => panic!("exit code 1169 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AQ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1170_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1170)));
    match vm.run() {
        VMResult::Ok(Value::Status(1170)) => {}
        other => panic!("exit code 1170 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifteen_consecutive_runs_without_reset_still_blockedEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..215 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1171_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1171)));
    match vm.run() {
        VMResult::Ok(Value::Status(1171)) => {}
        other => panic!("exit code 1171 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixteen_consecutive_runs_without_reset_still_blockedEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..216 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1172_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1172)));
    match vm.run() {
        VMResult::Ok(Value::Status(1172)) => {}
        other => panic!("exit code 1172 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventeen_consecutive_runs_without_reset_still_blockedEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..217 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1173_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1173)));
    match vm.run() {
        VMResult::Ok(Value::Status(1173)) => {}
        other => panic!("exit code 1173 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1174_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1174)));
    match vm.run() {
        VMResult::Ok(Value::Status(1174)) => {}
        other => panic!("exit code 1174 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-157)));
    match vm.run() {
        VMResult::Ok(Value::Status(-157)) => {}
        other => panic!("status -157 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1175_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1175)));
    match vm.run() {
        VMResult::Ok(Value::Status(1175)) => {}
        other => panic!("exit code 1175 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-158)));
    match vm.run() {
        VMResult::Ok(Value::Status(-158)) => {}
        other => panic!("status -158 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1176_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1176)));
    match vm.run() {
        VMResult::Ok(Value::Status(1176)) => {}
        other => panic!("exit code 1176 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..77 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1170 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1170 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 77 {
                Some(1177)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1170 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1177)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1177)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1177_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1177)));
    match vm.run() {
        VMResult::Ok(Value::Status(1177)) => {}
        other => panic!("exit code 1177 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1178)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..35 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 38);
    assert_eq!(vm.last_status, 1178);
}

#[test]
fn subshell_end_exit_code_1178_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1178)));
    match vm.run() {
        VMResult::Ok(Value::Status(1178)) => {}
        other => panic!("exit code 1178 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1179Ex1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1179)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1179);
}

#[test]
fn subshell_end_exit_code_1179_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1179)));
    match vm.run() {
        VMResult::Ok(Value::Status(1179)) => {}
        other => panic!("exit code 1179 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_four_begins_thirty_two_ends_last_end_status_winsEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..34 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..32 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1180Ex1170;
    impl ShellHost for CountingBeginEndHost1180Ex1170 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1180)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1180Ex1170));
    match vm.run() {
        VMResult::Ok(Value::Status(1180)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1180)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 34);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 32);
}

#[test]
fn subshell_end_exit_code_1180_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1180)));
    match vm.run() {
        VMResult::Ok(Value::Status(1180)) => {}
        other => panic!("exit code 1180 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1181Ex1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1170;
    impl ShellHost for CountingBeginHost733Ex1170 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1181)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1170));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1181);
}

#[test]
fn subshell_end_exit_code_1181_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1181)));
    match vm.run() {
        VMResult::Ok(Value::Status(1181)) => {}
        other => panic!("exit code 1181 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1170() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1182)));
    for _ in 0..35 {
        match vm.run() {
            VMResult::Ok(Value::Status(1182)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1182_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1182)));
    match vm.run() {
        VMResult::Ok(Value::Status(1182)) => {}
        other => panic!("exit code 1182 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1183Ex1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1183)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1183);
}

#[test]
fn subshell_end_exit_code_1183_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1183)));
    match vm.run() {
        VMResult::Ok(Value::Status(1183)) => {}
        other => panic!("exit code 1183 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1184_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1184)));
    match vm.run() {
        VMResult::Ok(Value::Status(1184)) => {}
        other => panic!("exit code 1184 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1185Ex1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1185)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1185);
}

#[test]
fn subshell_end_exit_code_1185_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1185)));
    match vm.run() {
        VMResult::Ok(Value::Status(1185)) => {}
        other => panic!("exit code 1185 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighteen_consecutive_runs_without_reset_still_blockedEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..218 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1186_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1186)));
    match vm.run() {
        VMResult::Ok(Value::Status(1186)) => {}
        other => panic!("exit code 1186 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_nineteen_consecutive_runs_without_reset_still_blockedEx1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..219 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1187_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1187)));
    match vm.run() {
        VMResult::Ok(Value::Status(1187)) => {}
        other => panic!("exit code 1187 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1188_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1188)));
    match vm.run() {
        VMResult::Ok(Value::Status(1188)) => {}
        other => panic!("exit code 1188 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1189;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1189)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1189, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1189_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1189)));
    match vm.run() {
        VMResult::Ok(Value::Status(1189)) => {}
        other => panic!("exit code 1189 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1190,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1190)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1190), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1190_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1190)));
    match vm.run() {
        VMResult::Ok(Value::Status(1190)) => {}
        other => panic!("exit code 1190 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-159)));
    match vm.run() {
        VMResult::Ok(Value::Status(-159)) => {}
        other => panic!("status -159 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1191_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1191)));
    match vm.run() {
        VMResult::Ok(Value::Status(1191)) => {}
        other => panic!("exit code 1191 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_seven_end_incrementing_from_fiveEx1170() {
    let mut b = ChunkBuilder::new();
    for _ in 0..157 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 29 }));
    match vm.run() {
        VMResult::Ok(Value::Status(185)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(185)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1192_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1192)));
    match vm.run() {
        VMResult::Ok(Value::Status(1192)) => {}
        other => panic!("exit code 1192 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1193Ex1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1193Ex1170 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1193Ex1170 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1193Ex1170 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1193_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1193)));
    match vm.run() {
        VMResult::Ok(Value::Status(1193)) => {}
        other => panic!("exit code 1193 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1194Ex1170() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1194)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1194);
}

#[test]
fn subshell_end_exit_code_1194_propagatesEx1170() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1194)));
    match vm.run() {
        VMResult::Ok(Value::Status(1194)) => {}
        other => panic!("exit code 1194 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AR (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1195_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1195)));
    match vm.run() {
        VMResult::Ok(Value::Status(1195)) => {}
        other => panic!("exit code 1195 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..220 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1196_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1196)));
    match vm.run() {
        VMResult::Ok(Value::Status(1196)) => {}
        other => panic!("exit code 1196 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_one_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..221 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1197_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1197)));
    match vm.run() {
        VMResult::Ok(Value::Status(1197)) => {}
        other => panic!("exit code 1197 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_two_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..222 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1198_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1198)));
    match vm.run() {
        VMResult::Ok(Value::Status(1198)) => {}
        other => panic!("exit code 1198 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_eight_end_incrementing_from_sixEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..158 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 30 }));
    match vm.run() {
        VMResult::Ok(Value::Status(187)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(187)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1199_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1199)));
    match vm.run() {
        VMResult::Ok(Value::Status(1199)) => {}
        other => panic!("exit code 1199 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-160)));
    match vm.run() {
        VMResult::Ok(Value::Status(-160)) => {}
        other => panic!("status -160 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1200_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1200)));
    match vm.run() {
        VMResult::Ok(Value::Status(1200)) => {}
        other => panic!("exit code 1200 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-161)));
    match vm.run() {
        VMResult::Ok(Value::Status(-161)) => {}
        other => panic!("status -161 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1201_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1201)));
    match vm.run() {
        VMResult::Ok(Value::Status(1201)) => {}
        other => panic!("exit code 1201 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..78 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1195 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1195 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 78 {
                Some(1202)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1195 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1202)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1202)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1202_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1202)));
    match vm.run() {
        VMResult::Ok(Value::Status(1202)) => {}
        other => panic!("exit code 1202 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1203)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..36 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 39);
    assert_eq!(vm.last_status, 1203);
}

#[test]
fn subshell_end_exit_code_1203_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1203)));
    match vm.run() {
        VMResult::Ok(Value::Status(1203)) => {}
        other => panic!("exit code 1203 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1204Ex1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1204)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1204);
}

#[test]
fn subshell_end_exit_code_1204_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1204)));
    match vm.run() {
        VMResult::Ok(Value::Status(1204)) => {}
        other => panic!("exit code 1204 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_five_begins_thirty_three_ends_last_end_status_winsEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..35 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..33 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1205Ex1195;
    impl ShellHost for CountingBeginEndHost1205Ex1195 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1205)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1205Ex1195));
    match vm.run() {
        VMResult::Ok(Value::Status(1205)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1205)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 35);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 33);
}

#[test]
fn subshell_end_exit_code_1205_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1205)));
    match vm.run() {
        VMResult::Ok(Value::Status(1205)) => {}
        other => panic!("exit code 1205 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1206Ex1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1206)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1206);
}

#[test]
fn subshell_end_exit_code_1206_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1206)));
    match vm.run() {
        VMResult::Ok(Value::Status(1206)) => {}
        other => panic!("exit code 1206 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1195() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1207)));
    for _ in 0..36 {
        match vm.run() {
            VMResult::Ok(Value::Status(1207)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1207_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1207)));
    match vm.run() {
        VMResult::Ok(Value::Status(1207)) => {}
        other => panic!("exit code 1207 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1208Ex1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1208)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1208);
}

#[test]
fn subshell_end_exit_code_1208_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1208)));
    match vm.run() {
        VMResult::Ok(Value::Status(1208)) => {}
        other => panic!("exit code 1208 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_fifty_nine_end_incrementing_from_sevenEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..159 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 31 }));
    match vm.run() {
        VMResult::Ok(Value::Status(189)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(189)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1209_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1209)));
    match vm.run() {
        VMResult::Ok(Value::Status(1209)) => {}
        other => panic!("exit code 1209 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1210Ex1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1210)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1210);
}

#[test]
fn subshell_end_exit_code_1210_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1210)));
    match vm.run() {
        VMResult::Ok(Value::Status(1210)) => {}
        other => panic!("exit code 1210 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_three_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..223 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1211_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1211)));
    match vm.run() {
        VMResult::Ok(Value::Status(1211)) => {}
        other => panic!("exit code 1211 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..79 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1195 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1195 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 79 {
                Some(1212)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1195 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1212)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1212)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1212_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1212)));
    match vm.run() {
        VMResult::Ok(Value::Status(1212)) => {}
        other => panic!("exit code 1212 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1213_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1213)));
    match vm.run() {
        VMResult::Ok(Value::Status(1213)) => {}
        other => panic!("exit code 1213 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1214Ex1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1214)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1214);
}

#[test]
fn subshell_end_exit_code_1214_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1214)));
    match vm.run() {
        VMResult::Ok(Value::Status(1214)) => {}
        other => panic!("exit code 1214 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_end_incrementing_from_oneEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..160 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 25 }));
    match vm.run() {
        VMResult::Ok(Value::Status(184)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(184)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1215_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1215)));
    match vm.run() {
        VMResult::Ok(Value::Status(1215)) => {}
        other => panic!("exit code 1215 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1216;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1216)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1216, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1216_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1216)));
    match vm.run() {
        VMResult::Ok(Value::Status(1216)) => {}
        other => panic!("exit code 1216 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1217,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1217)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1217), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1217_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1217)));
    match vm.run() {
        VMResult::Ok(Value::Status(1217)) => {}
        other => panic!("exit code 1217 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_four_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..224 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1218_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1218)));
    match vm.run() {
        VMResult::Ok(Value::Status(1218)) => {}
        other => panic!("exit code 1218 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..80 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1195 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1195 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 80 {
                Some(1219)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1195 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1219)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1219)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1219_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1219)));
    match vm.run() {
        VMResult::Ok(Value::Status(1219)) => {}
        other => panic!("exit code 1219 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1220Ex1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1220Ex1195;
    impl ShellHost for PipelineSubshellHost1220Ex1195 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1220)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1220Ex1195));
    match vm.run() {
        VMResult::Ok(Value::Status(1220)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1220_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1220)));
    match vm.run() {
        VMResult::Ok(Value::Status(1220)) => {}
        other => panic!("exit code 1220 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1221Ex1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1221Ex1195;
    impl ShellHost for SubshellThenPipelineHost1221Ex1195 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1221
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1221Ex1195));
    match vm.run() {
        VMResult::Ok(Value::Status(1221)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1221_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1221)));
    match vm.run() {
        VMResult::Ok(Value::Status(1221)) => {}
        other => panic!("exit code 1221 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-162)));
    match vm.run() {
        VMResult::Ok(Value::Status(-162)) => {}
        other => panic!("status -162 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1222_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1222)));
    match vm.run() {
        VMResult::Ok(Value::Status(1222)) => {}
        other => panic!("exit code 1222 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_one_end_incrementing_from_eightEx1195() {
    let mut b = ChunkBuilder::new();
    for _ in 0..161 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 32 }));
    match vm.run() {
        VMResult::Ok(Value::Status(192)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(192)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1223_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1223)));
    match vm.run() {
        VMResult::Ok(Value::Status(1223)) => {}
        other => panic!("exit code 1223 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_five_consecutive_runs_without_reset_still_blockedEx1195() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..225 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1224_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1224)));
    match vm.run() {
        VMResult::Ok(Value::Status(1224)) => {}
        other => panic!("exit code 1224 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1225Ex1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1225Ex1195 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1225Ex1195 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1225Ex1195 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1225_propagatesEx1195() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1225)));
    match vm.run() {
        VMResult::Ok(Value::Status(1225)) => {}
        other => panic!("exit code 1225 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AS (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1226_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1226)));
    match vm.run() {
        VMResult::Ok(Value::Status(1226)) => {}
        other => panic!("exit code 1226 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_six_consecutive_runs_without_reset_still_blockedEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..226 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1227_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1227)));
    match vm.run() {
        VMResult::Ok(Value::Status(1227)) => {}
        other => panic!("exit code 1227 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_seven_consecutive_runs_without_reset_still_blockedEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..227 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1228_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1228)));
    match vm.run() {
        VMResult::Ok(Value::Status(1228)) => {}
        other => panic!("exit code 1228 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_eight_consecutive_runs_without_reset_still_blockedEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..228 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1229_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1229)));
    match vm.run() {
        VMResult::Ok(Value::Status(1229)) => {}
        other => panic!("exit code 1229 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1230_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1230)));
    match vm.run() {
        VMResult::Ok(Value::Status(1230)) => {}
        other => panic!("exit code 1230 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-164)));
    match vm.run() {
        VMResult::Ok(Value::Status(-164)) => {}
        other => panic!("status -164 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1231_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1231)));
    match vm.run() {
        VMResult::Ok(Value::Status(1231)) => {}
        other => panic!("exit code 1231 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-165)));
    match vm.run() {
        VMResult::Ok(Value::Status(-165)) => {}
        other => panic!("status -165 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1232_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1232)));
    match vm.run() {
        VMResult::Ok(Value::Status(1232)) => {}
        other => panic!("exit code 1232 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..81 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1226 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1226 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 81 {
                Some(1233)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1226 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1233)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1233)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1233_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1233)));
    match vm.run() {
        VMResult::Ok(Value::Status(1233)) => {}
        other => panic!("exit code 1233 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1234)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..37 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 40);
    assert_eq!(vm.last_status, 1234);
}

#[test]
fn subshell_end_exit_code_1234_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1234)));
    match vm.run() {
        VMResult::Ok(Value::Status(1234)) => {}
        other => panic!("exit code 1234 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1235Ex1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1235)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1235);
}

#[test]
fn subshell_end_exit_code_1235_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1235)));
    match vm.run() {
        VMResult::Ok(Value::Status(1235)) => {}
        other => panic!("exit code 1235 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_six_begins_thirty_four_ends_last_end_status_winsEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..36 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..34 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1236Ex1226;
    impl ShellHost for CountingBeginEndHost1236Ex1226 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1236)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1236Ex1226));
    match vm.run() {
        VMResult::Ok(Value::Status(1236)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1236)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 36);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 34);
}

#[test]
fn subshell_end_exit_code_1236_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1236)));
    match vm.run() {
        VMResult::Ok(Value::Status(1236)) => {}
        other => panic!("exit code 1236 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1237Ex1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1226;
    impl ShellHost for CountingBeginHost733Ex1226 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1237)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1226));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1237);
}

#[test]
fn subshell_end_exit_code_1237_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1237)));
    match vm.run() {
        VMResult::Ok(Value::Status(1237)) => {}
        other => panic!("exit code 1237 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1226() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1238)));
    for _ in 0..37 {
        match vm.run() {
            VMResult::Ok(Value::Status(1238)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1238_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1238)));
    match vm.run() {
        VMResult::Ok(Value::Status(1238)) => {}
        other => panic!("exit code 1238 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1239Ex1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1239)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1239);
}

#[test]
fn subshell_end_exit_code_1239_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1239)));
    match vm.run() {
        VMResult::Ok(Value::Status(1239)) => {}
        other => panic!("exit code 1239 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1240_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1240)));
    match vm.run() {
        VMResult::Ok(Value::Status(1240)) => {}
        other => panic!("exit code 1240 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1241Ex1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1241)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1241);
}

#[test]
fn subshell_end_exit_code_1241_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1241)));
    match vm.run() {
        VMResult::Ok(Value::Status(1241)) => {}
        other => panic!("exit code 1241 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_twenty_nine_consecutive_runs_without_reset_still_blockedEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..229 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1242_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1242)));
    match vm.run() {
        VMResult::Ok(Value::Status(1242)) => {}
        other => panic!("exit code 1242 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_consecutive_runs_without_reset_still_blockedEx1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..230 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1243_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1243)));
    match vm.run() {
        VMResult::Ok(Value::Status(1243)) => {}
        other => panic!("exit code 1243 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1244_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1244)));
    match vm.run() {
        VMResult::Ok(Value::Status(1244)) => {}
        other => panic!("exit code 1244 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1245;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1245)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1245, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1245_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1245)));
    match vm.run() {
        VMResult::Ok(Value::Status(1245)) => {}
        other => panic!("exit code 1245 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1246,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1246)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1246), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1246_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1246)));
    match vm.run() {
        VMResult::Ok(Value::Status(1246)) => {}
        other => panic!("exit code 1246 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-166)));
    match vm.run() {
        VMResult::Ok(Value::Status(-166)) => {}
        other => panic!("status -166 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1247_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1247)));
    match vm.run() {
        VMResult::Ok(Value::Status(1247)) => {}
        other => panic!("exit code 1247 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_four_end_incrementing_from_fiveEx1226() {
    let mut b = ChunkBuilder::new();
    for _ in 0..164 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 32 }));
    match vm.run() {
        VMResult::Ok(Value::Status(195)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(195)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1248_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1248)));
    match vm.run() {
        VMResult::Ok(Value::Status(1248)) => {}
        other => panic!("exit code 1248 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1249Ex1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1249Ex1226 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1249Ex1226 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1249Ex1226 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1249_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1249)));
    match vm.run() {
        VMResult::Ok(Value::Status(1249)) => {}
        other => panic!("exit code 1249 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1250Ex1226() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1250)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1250);
}

#[test]
fn subshell_end_exit_code_1250_propagatesEx1226() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1250)));
    match vm.run() {
        VMResult::Ok(Value::Status(1250)) => {}
        other => panic!("exit code 1250 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AT (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1251_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1251)));
    match vm.run() {
        VMResult::Ok(Value::Status(1251)) => {}
        other => panic!("exit code 1251 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_one_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..231 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1252_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1252)));
    match vm.run() {
        VMResult::Ok(Value::Status(1252)) => {}
        other => panic!("exit code 1252 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_two_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..232 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1253_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1253)));
    match vm.run() {
        VMResult::Ok(Value::Status(1253)) => {}
        other => panic!("exit code 1253 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_three_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..233 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1254_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1254)));
    match vm.run() {
        VMResult::Ok(Value::Status(1254)) => {}
        other => panic!("exit code 1254 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_five_end_incrementing_from_sixEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..165 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 33 }));
    match vm.run() {
        VMResult::Ok(Value::Status(197)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(197)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1255_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1255)));
    match vm.run() {
        VMResult::Ok(Value::Status(1255)) => {}
        other => panic!("exit code 1255 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-167)));
    match vm.run() {
        VMResult::Ok(Value::Status(-167)) => {}
        other => panic!("status -167 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1256_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1256)));
    match vm.run() {
        VMResult::Ok(Value::Status(1256)) => {}
        other => panic!("exit code 1256 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-168)));
    match vm.run() {
        VMResult::Ok(Value::Status(-168)) => {}
        other => panic!("status -168 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1257_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1257)));
    match vm.run() {
        VMResult::Ok(Value::Status(1257)) => {}
        other => panic!("exit code 1257 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..82 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1251 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1251 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 82 {
                Some(1258)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1251 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1258)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1258)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1258_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1258)));
    match vm.run() {
        VMResult::Ok(Value::Status(1258)) => {}
        other => panic!("exit code 1258 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1259)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..38 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 41);
    assert_eq!(vm.last_status, 1259);
}

#[test]
fn subshell_end_exit_code_1259_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1259)));
    match vm.run() {
        VMResult::Ok(Value::Status(1259)) => {}
        other => panic!("exit code 1259 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1260Ex1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1260)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1260);
}

#[test]
fn subshell_end_exit_code_1260_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1260)));
    match vm.run() {
        VMResult::Ok(Value::Status(1260)) => {}
        other => panic!("exit code 1260 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_seven_begins_thirty_five_ends_last_end_status_winsEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..37 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..35 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1261Ex1251;
    impl ShellHost for CountingBeginEndHost1261Ex1251 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1261)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1261Ex1251));
    match vm.run() {
        VMResult::Ok(Value::Status(1261)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1261)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 37);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 35);
}

#[test]
fn subshell_end_exit_code_1261_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1261)));
    match vm.run() {
        VMResult::Ok(Value::Status(1261)) => {}
        other => panic!("exit code 1261 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1262Ex1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1262)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1262);
}

#[test]
fn subshell_end_exit_code_1262_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1262)));
    match vm.run() {
        VMResult::Ok(Value::Status(1262)) => {}
        other => panic!("exit code 1262 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1251() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1263)));
    for _ in 0..38 {
        match vm.run() {
            VMResult::Ok(Value::Status(1263)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1263_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1263)));
    match vm.run() {
        VMResult::Ok(Value::Status(1263)) => {}
        other => panic!("exit code 1263 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1264Ex1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1264)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1264);
}

#[test]
fn subshell_end_exit_code_1264_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1264)));
    match vm.run() {
        VMResult::Ok(Value::Status(1264)) => {}
        other => panic!("exit code 1264 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_six_end_incrementing_from_sevenEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..166 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 34 }));
    match vm.run() {
        VMResult::Ok(Value::Status(199)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(199)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1265_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1265)));
    match vm.run() {
        VMResult::Ok(Value::Status(1265)) => {}
        other => panic!("exit code 1265 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1266Ex1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1266)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1266);
}

#[test]
fn subshell_end_exit_code_1266_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1266)));
    match vm.run() {
        VMResult::Ok(Value::Status(1266)) => {}
        other => panic!("exit code 1266 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_four_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..234 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1267_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1267)));
    match vm.run() {
        VMResult::Ok(Value::Status(1267)) => {}
        other => panic!("exit code 1267 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..83 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1251 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1251 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 83 {
                Some(1268)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1251 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1268)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1268)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1268_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1268)));
    match vm.run() {
        VMResult::Ok(Value::Status(1268)) => {}
        other => panic!("exit code 1268 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1269_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1269)));
    match vm.run() {
        VMResult::Ok(Value::Status(1269)) => {}
        other => panic!("exit code 1269 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1270Ex1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1270)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1270);
}

#[test]
fn subshell_end_exit_code_1270_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1270)));
    match vm.run() {
        VMResult::Ok(Value::Status(1270)) => {}
        other => panic!("exit code 1270 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_seven_end_incrementing_from_oneEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..167 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 28 }));
    match vm.run() {
        VMResult::Ok(Value::Status(194)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(194)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1271_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1271)));
    match vm.run() {
        VMResult::Ok(Value::Status(1271)) => {}
        other => panic!("exit code 1271 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1272;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1272)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1272, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1272_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1272)));
    match vm.run() {
        VMResult::Ok(Value::Status(1272)) => {}
        other => panic!("exit code 1272 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1273,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1273)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1273), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1273_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1273)));
    match vm.run() {
        VMResult::Ok(Value::Status(1273)) => {}
        other => panic!("exit code 1273 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_five_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..235 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1274_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1274)));
    match vm.run() {
        VMResult::Ok(Value::Status(1274)) => {}
        other => panic!("exit code 1274 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..84 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1251 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1251 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 84 {
                Some(1275)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1251 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1275)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1275)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1275_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1275)));
    match vm.run() {
        VMResult::Ok(Value::Status(1275)) => {}
        other => panic!("exit code 1275 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1276Ex1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1276Ex1251;
    impl ShellHost for PipelineSubshellHost1276Ex1251 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1276)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1276Ex1251));
    match vm.run() {
        VMResult::Ok(Value::Status(1276)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1276_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1276)));
    match vm.run() {
        VMResult::Ok(Value::Status(1276)) => {}
        other => panic!("exit code 1276 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1277Ex1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1277Ex1251;
    impl ShellHost for SubshellThenPipelineHost1277Ex1251 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1277
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1277Ex1251));
    match vm.run() {
        VMResult::Ok(Value::Status(1277)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1277_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1277)));
    match vm.run() {
        VMResult::Ok(Value::Status(1277)) => {}
        other => panic!("exit code 1277 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-169)));
    match vm.run() {
        VMResult::Ok(Value::Status(-169)) => {}
        other => panic!("status -169 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1278_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1278)));
    match vm.run() {
        VMResult::Ok(Value::Status(1278)) => {}
        other => panic!("exit code 1278 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_sixty_eight_end_incrementing_from_eightEx1251() {
    let mut b = ChunkBuilder::new();
    for _ in 0..168 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 35 }));
    match vm.run() {
        VMResult::Ok(Value::Status(202)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(202)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1279_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1279)));
    match vm.run() {
        VMResult::Ok(Value::Status(1279)) => {}
        other => panic!("exit code 1279 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_six_consecutive_runs_without_reset_still_blockedEx1251() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..236 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1280_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1280)));
    match vm.run() {
        VMResult::Ok(Value::Status(1280)) => {}
        other => panic!("exit code 1280 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1281Ex1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1281Ex1251 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1281Ex1251 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1281Ex1251 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1281_propagatesEx1251() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1281)));
    match vm.run() {
        VMResult::Ok(Value::Status(1281)) => {}
        other => panic!("exit code 1281 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AU (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1282_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1282)));
    match vm.run() {
        VMResult::Ok(Value::Status(1282)) => {}
        other => panic!("exit code 1282 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_seven_consecutive_runs_without_reset_still_blockedEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..237 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1283_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1283)));
    match vm.run() {
        VMResult::Ok(Value::Status(1283)) => {}
        other => panic!("exit code 1283 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_eight_consecutive_runs_without_reset_still_blockedEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..238 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1284_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1284)));
    match vm.run() {
        VMResult::Ok(Value::Status(1284)) => {}
        other => panic!("exit code 1284 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_thirty_nine_consecutive_runs_without_reset_still_blockedEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..239 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1285_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1285)));
    match vm.run() {
        VMResult::Ok(Value::Status(1285)) => {}
        other => panic!("exit code 1285 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1286_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1286)));
    match vm.run() {
        VMResult::Ok(Value::Status(1286)) => {}
        other => panic!("exit code 1286 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-171)));
    match vm.run() {
        VMResult::Ok(Value::Status(-171)) => {}
        other => panic!("status -171 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1287_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1287)));
    match vm.run() {
        VMResult::Ok(Value::Status(1287)) => {}
        other => panic!("exit code 1287 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-172)));
    match vm.run() {
        VMResult::Ok(Value::Status(-172)) => {}
        other => panic!("status -172 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1288_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1288)));
    match vm.run() {
        VMResult::Ok(Value::Status(1288)) => {}
        other => panic!("exit code 1288 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..85 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1282 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1282 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 85 {
                Some(1289)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1282 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1289)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1289)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1289_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1289)));
    match vm.run() {
        VMResult::Ok(Value::Status(1289)) => {}
        other => panic!("exit code 1289 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1290)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..39 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 42);
    assert_eq!(vm.last_status, 1290);
}

#[test]
fn subshell_end_exit_code_1290_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1290)));
    match vm.run() {
        VMResult::Ok(Value::Status(1290)) => {}
        other => panic!("exit code 1290 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1291Ex1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1291)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1291);
}

#[test]
fn subshell_end_exit_code_1291_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1291)));
    match vm.run() {
        VMResult::Ok(Value::Status(1291)) => {}
        other => panic!("exit code 1291 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_eight_begins_thirty_six_ends_last_end_status_winsEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..38 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..36 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1292Ex1282;
    impl ShellHost for CountingBeginEndHost1292Ex1282 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1292)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1292Ex1282));
    match vm.run() {
        VMResult::Ok(Value::Status(1292)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1292)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 38);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 36);
}

#[test]
fn subshell_end_exit_code_1292_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1292)));
    match vm.run() {
        VMResult::Ok(Value::Status(1292)) => {}
        other => panic!("exit code 1292 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1293Ex1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1282;
    impl ShellHost for CountingBeginHost733Ex1282 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1293)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1282));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1293);
}

#[test]
fn subshell_end_exit_code_1293_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1293)));
    match vm.run() {
        VMResult::Ok(Value::Status(1293)) => {}
        other => panic!("exit code 1293 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1282() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1294)));
    for _ in 0..39 {
        match vm.run() {
            VMResult::Ok(Value::Status(1294)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1294_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1294)));
    match vm.run() {
        VMResult::Ok(Value::Status(1294)) => {}
        other => panic!("exit code 1294 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1295Ex1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1295)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1295);
}

#[test]
fn subshell_end_exit_code_1295_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1295)));
    match vm.run() {
        VMResult::Ok(Value::Status(1295)) => {}
        other => panic!("exit code 1295 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1296_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1296)));
    match vm.run() {
        VMResult::Ok(Value::Status(1296)) => {}
        other => panic!("exit code 1296 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1297Ex1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1297)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1297);
}

#[test]
fn subshell_end_exit_code_1297_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1297)));
    match vm.run() {
        VMResult::Ok(Value::Status(1297)) => {}
        other => panic!("exit code 1297 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_consecutive_runs_without_reset_still_blockedEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..240 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1298_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1298)));
    match vm.run() {
        VMResult::Ok(Value::Status(1298)) => {}
        other => panic!("exit code 1298 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_one_consecutive_runs_without_reset_still_blockedEx1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..241 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1299_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1299)));
    match vm.run() {
        VMResult::Ok(Value::Status(1299)) => {}
        other => panic!("exit code 1299 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1300_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1300)));
    match vm.run() {
        VMResult::Ok(Value::Status(1300)) => {}
        other => panic!("exit code 1300 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1301;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1301)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1301, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1301_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1301)));
    match vm.run() {
        VMResult::Ok(Value::Status(1301)) => {}
        other => panic!("exit code 1301 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1302,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1302)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1302), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1302_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1302)));
    match vm.run() {
        VMResult::Ok(Value::Status(1302)) => {}
        other => panic!("exit code 1302 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-173)));
    match vm.run() {
        VMResult::Ok(Value::Status(-173)) => {}
        other => panic!("status -173 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1303_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1303)));
    match vm.run() {
        VMResult::Ok(Value::Status(1303)) => {}
        other => panic!("exit code 1303 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_one_end_incrementing_from_fiveEx1282() {
    let mut b = ChunkBuilder::new();
    for _ in 0..171 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 35 }));
    match vm.run() {
        VMResult::Ok(Value::Status(205)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(205)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1304_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1304)));
    match vm.run() {
        VMResult::Ok(Value::Status(1304)) => {}
        other => panic!("exit code 1304 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1305Ex1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1305Ex1282 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1305Ex1282 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1305Ex1282 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1305_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1305)));
    match vm.run() {
        VMResult::Ok(Value::Status(1305)) => {}
        other => panic!("exit code 1305 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1306Ex1282() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1306)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1306);
}

#[test]
fn subshell_end_exit_code_1306_propagatesEx1282() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1306)));
    match vm.run() {
        VMResult::Ok(Value::Status(1306)) => {}
        other => panic!("exit code 1306 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AV (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1307_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1307)));
    match vm.run() {
        VMResult::Ok(Value::Status(1307)) => {}
        other => panic!("exit code 1307 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_two_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..242 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1308_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1308)));
    match vm.run() {
        VMResult::Ok(Value::Status(1308)) => {}
        other => panic!("exit code 1308 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_three_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..243 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1309_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1309)));
    match vm.run() {
        VMResult::Ok(Value::Status(1309)) => {}
        other => panic!("exit code 1309 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_four_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..244 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1310_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1310)));
    match vm.run() {
        VMResult::Ok(Value::Status(1310)) => {}
        other => panic!("exit code 1310 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_two_end_incrementing_from_sixEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..172 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 36 }));
    match vm.run() {
        VMResult::Ok(Value::Status(207)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(207)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1311_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1311)));
    match vm.run() {
        VMResult::Ok(Value::Status(1311)) => {}
        other => panic!("exit code 1311 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-174)));
    match vm.run() {
        VMResult::Ok(Value::Status(-174)) => {}
        other => panic!("status -174 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1312_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1312)));
    match vm.run() {
        VMResult::Ok(Value::Status(1312)) => {}
        other => panic!("exit code 1312 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-175)));
    match vm.run() {
        VMResult::Ok(Value::Status(-175)) => {}
        other => panic!("status -175 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1313_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1313)));
    match vm.run() {
        VMResult::Ok(Value::Status(1313)) => {}
        other => panic!("exit code 1313 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..86 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1307 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1307 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 86 {
                Some(1314)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1307 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1314)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1314)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1314_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1314)));
    match vm.run() {
        VMResult::Ok(Value::Status(1314)) => {}
        other => panic!("exit code 1314 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1315)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..40 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 43);
    assert_eq!(vm.last_status, 1315);
}

#[test]
fn subshell_end_exit_code_1315_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1315)));
    match vm.run() {
        VMResult::Ok(Value::Status(1315)) => {}
        other => panic!("exit code 1315 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1316Ex1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1316)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1316);
}

#[test]
fn subshell_end_exit_code_1316_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1316)));
    match vm.run() {
        VMResult::Ok(Value::Status(1316)) => {}
        other => panic!("exit code 1316 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_thirty_nine_begins_thirty_seven_ends_last_end_status_winsEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..39 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..37 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1317Ex1307;
    impl ShellHost for CountingBeginEndHost1317Ex1307 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1317)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1317Ex1307));
    match vm.run() {
        VMResult::Ok(Value::Status(1317)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1317)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 39);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 37);
}

#[test]
fn subshell_end_exit_code_1317_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1317)));
    match vm.run() {
        VMResult::Ok(Value::Status(1317)) => {}
        other => panic!("exit code 1317 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1318Ex1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1318)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1318);
}

#[test]
fn subshell_end_exit_code_1318_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1318)));
    match vm.run() {
        VMResult::Ok(Value::Status(1318)) => {}
        other => panic!("exit code 1318 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1307() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1319)));
    for _ in 0..40 {
        match vm.run() {
            VMResult::Ok(Value::Status(1319)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1319_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1319)));
    match vm.run() {
        VMResult::Ok(Value::Status(1319)) => {}
        other => panic!("exit code 1319 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1320Ex1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1320)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1320);
}

#[test]
fn subshell_end_exit_code_1320_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1320)));
    match vm.run() {
        VMResult::Ok(Value::Status(1320)) => {}
        other => panic!("exit code 1320 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_three_end_incrementing_from_sevenEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..173 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 37 }));
    match vm.run() {
        VMResult::Ok(Value::Status(209)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(209)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1321_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1321)));
    match vm.run() {
        VMResult::Ok(Value::Status(1321)) => {}
        other => panic!("exit code 1321 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1322Ex1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1322)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1322);
}

#[test]
fn subshell_end_exit_code_1322_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1322)));
    match vm.run() {
        VMResult::Ok(Value::Status(1322)) => {}
        other => panic!("exit code 1322 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_five_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..245 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1323_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1323)));
    match vm.run() {
        VMResult::Ok(Value::Status(1323)) => {}
        other => panic!("exit code 1323 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..87 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1307 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1307 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 87 {
                Some(1324)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1307 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1324)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1324)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1324_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1324)));
    match vm.run() {
        VMResult::Ok(Value::Status(1324)) => {}
        other => panic!("exit code 1324 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1325_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1325)));
    match vm.run() {
        VMResult::Ok(Value::Status(1325)) => {}
        other => panic!("exit code 1325 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1326Ex1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1326)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1326);
}

#[test]
fn subshell_end_exit_code_1326_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1326)));
    match vm.run() {
        VMResult::Ok(Value::Status(1326)) => {}
        other => panic!("exit code 1326 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_four_end_incrementing_from_oneEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..174 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 31 }));
    match vm.run() {
        VMResult::Ok(Value::Status(204)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(204)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1327_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1327)));
    match vm.run() {
        VMResult::Ok(Value::Status(1327)) => {}
        other => panic!("exit code 1327 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1328;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1328)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1328, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1328_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1328)));
    match vm.run() {
        VMResult::Ok(Value::Status(1328)) => {}
        other => panic!("exit code 1328 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1329,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1329)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1329), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1329_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1329)));
    match vm.run() {
        VMResult::Ok(Value::Status(1329)) => {}
        other => panic!("exit code 1329 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_six_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..246 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1330_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1330)));
    match vm.run() {
        VMResult::Ok(Value::Status(1330)) => {}
        other => panic!("exit code 1330 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..88 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1307 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1307 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 88 {
                Some(1331)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1307 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1331)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1331)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1331_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1331)));
    match vm.run() {
        VMResult::Ok(Value::Status(1331)) => {}
        other => panic!("exit code 1331 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1332Ex1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1332Ex1307;
    impl ShellHost for PipelineSubshellHost1332Ex1307 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1332)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1332Ex1307));
    match vm.run() {
        VMResult::Ok(Value::Status(1332)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1332_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1332)));
    match vm.run() {
        VMResult::Ok(Value::Status(1332)) => {}
        other => panic!("exit code 1332 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1333Ex1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1333Ex1307;
    impl ShellHost for SubshellThenPipelineHost1333Ex1307 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1333
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1333Ex1307));
    match vm.run() {
        VMResult::Ok(Value::Status(1333)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1333_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1333)));
    match vm.run() {
        VMResult::Ok(Value::Status(1333)) => {}
        other => panic!("exit code 1333 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-176)));
    match vm.run() {
        VMResult::Ok(Value::Status(-176)) => {}
        other => panic!("status -176 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1334_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1334)));
    match vm.run() {
        VMResult::Ok(Value::Status(1334)) => {}
        other => panic!("exit code 1334 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_five_end_incrementing_from_eightEx1307() {
    let mut b = ChunkBuilder::new();
    for _ in 0..175 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 38 }));
    match vm.run() {
        VMResult::Ok(Value::Status(212)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(212)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1335_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1335)));
    match vm.run() {
        VMResult::Ok(Value::Status(1335)) => {}
        other => panic!("exit code 1335 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_seven_consecutive_runs_without_reset_still_blockedEx1307() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..247 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1336_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1336)));
    match vm.run() {
        VMResult::Ok(Value::Status(1336)) => {}
        other => panic!("exit code 1336 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1337Ex1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1337Ex1307 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1337Ex1307 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1337Ex1307 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1337_propagatesEx1307() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1337)));
    match vm.run() {
        VMResult::Ok(Value::Status(1337)) => {}
        other => panic!("exit code 1337 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AW (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1338_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1338)));
    match vm.run() {
        VMResult::Ok(Value::Status(1338)) => {}
        other => panic!("exit code 1338 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_eight_consecutive_runs_without_reset_still_blockedEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..248 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1339_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1339)));
    match vm.run() {
        VMResult::Ok(Value::Status(1339)) => {}
        other => panic!("exit code 1339 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_forty_nine_consecutive_runs_without_reset_still_blockedEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..249 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1340_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1340)));
    match vm.run() {
        VMResult::Ok(Value::Status(1340)) => {}
        other => panic!("exit code 1340 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_consecutive_runs_without_reset_still_blockedEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..250 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1341_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1341)));
    match vm.run() {
        VMResult::Ok(Value::Status(1341)) => {}
        other => panic!("exit code 1341 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1342_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1342)));
    match vm.run() {
        VMResult::Ok(Value::Status(1342)) => {}
        other => panic!("exit code 1342 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-178)));
    match vm.run() {
        VMResult::Ok(Value::Status(-178)) => {}
        other => panic!("status -178 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1343_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1343)));
    match vm.run() {
        VMResult::Ok(Value::Status(1343)) => {}
        other => panic!("exit code 1343 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-179)));
    match vm.run() {
        VMResult::Ok(Value::Status(-179)) => {}
        other => panic!("status -179 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1344_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1344)));
    match vm.run() {
        VMResult::Ok(Value::Status(1344)) => {}
        other => panic!("exit code 1344 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..89 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1338 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1338 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 89 {
                Some(1345)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1338 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1345)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1345)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1345_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1345)));
    match vm.run() {
        VMResult::Ok(Value::Status(1345)) => {}
        other => panic!("exit code 1345 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1346)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..41 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 44);
    assert_eq!(vm.last_status, 1346);
}

#[test]
fn subshell_end_exit_code_1346_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1346)));
    match vm.run() {
        VMResult::Ok(Value::Status(1346)) => {}
        other => panic!("exit code 1346 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1347Ex1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1347)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1347);
}

#[test]
fn subshell_end_exit_code_1347_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1347)));
    match vm.run() {
        VMResult::Ok(Value::Status(1347)) => {}
        other => panic!("exit code 1347 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_begins_thirty_eight_ends_last_end_status_winsEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..40 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..38 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1348Ex1338;
    impl ShellHost for CountingBeginEndHost1348Ex1338 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1348)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1348Ex1338));
    match vm.run() {
        VMResult::Ok(Value::Status(1348)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1348)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 40);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 38);
}

#[test]
fn subshell_end_exit_code_1348_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1348)));
    match vm.run() {
        VMResult::Ok(Value::Status(1348)) => {}
        other => panic!("exit code 1348 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1349Ex1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1338;
    impl ShellHost for CountingBeginHost733Ex1338 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1349)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1338));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1349);
}

#[test]
fn subshell_end_exit_code_1349_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1349)));
    match vm.run() {
        VMResult::Ok(Value::Status(1349)) => {}
        other => panic!("exit code 1349 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1338() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1350)));
    for _ in 0..41 {
        match vm.run() {
            VMResult::Ok(Value::Status(1350)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1350_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1350)));
    match vm.run() {
        VMResult::Ok(Value::Status(1350)) => {}
        other => panic!("exit code 1350 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1351Ex1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1351)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1351);
}

#[test]
fn subshell_end_exit_code_1351_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1351)));
    match vm.run() {
        VMResult::Ok(Value::Status(1351)) => {}
        other => panic!("exit code 1351 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1352_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1352)));
    match vm.run() {
        VMResult::Ok(Value::Status(1352)) => {}
        other => panic!("exit code 1352 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1353Ex1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1353)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1353);
}

#[test]
fn subshell_end_exit_code_1353_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1353)));
    match vm.run() {
        VMResult::Ok(Value::Status(1353)) => {}
        other => panic!("exit code 1353 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_one_consecutive_runs_without_reset_still_blockedEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..251 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1354_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1354)));
    match vm.run() {
        VMResult::Ok(Value::Status(1354)) => {}
        other => panic!("exit code 1354 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_two_consecutive_runs_without_reset_still_blockedEx1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..252 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1355_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1355)));
    match vm.run() {
        VMResult::Ok(Value::Status(1355)) => {}
        other => panic!("exit code 1355 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1356_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1356)));
    match vm.run() {
        VMResult::Ok(Value::Status(1356)) => {}
        other => panic!("exit code 1356 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1357;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1357)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1357, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1357_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1357)));
    match vm.run() {
        VMResult::Ok(Value::Status(1357)) => {}
        other => panic!("exit code 1357 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1358,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1358)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1358), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1358_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1358)));
    match vm.run() {
        VMResult::Ok(Value::Status(1358)) => {}
        other => panic!("exit code 1358 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-180)));
    match vm.run() {
        VMResult::Ok(Value::Status(-180)) => {}
        other => panic!("status -180 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1359_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1359)));
    match vm.run() {
        VMResult::Ok(Value::Status(1359)) => {}
        other => panic!("exit code 1359 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_eight_end_incrementing_from_fiveEx1338() {
    let mut b = ChunkBuilder::new();
    for _ in 0..178 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 38 }));
    match vm.run() {
        VMResult::Ok(Value::Status(215)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(215)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1360_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1360)));
    match vm.run() {
        VMResult::Ok(Value::Status(1360)) => {}
        other => panic!("exit code 1360 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1361Ex1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1361Ex1338 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1361Ex1338 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1361Ex1338 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1361_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1361)));
    match vm.run() {
        VMResult::Ok(Value::Status(1361)) => {}
        other => panic!("exit code 1361 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1362Ex1338() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1362)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1362);
}

#[test]
fn subshell_end_exit_code_1362_propagatesEx1338() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1362)));
    match vm.run() {
        VMResult::Ok(Value::Status(1362)) => {}
        other => panic!("exit code 1362 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AX (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1363_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1363)));
    match vm.run() {
        VMResult::Ok(Value::Status(1363)) => {}
        other => panic!("exit code 1363 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_three_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..253 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1364_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1364)));
    match vm.run() {
        VMResult::Ok(Value::Status(1364)) => {}
        other => panic!("exit code 1364 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_four_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..254 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1365_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1365)));
    match vm.run() {
        VMResult::Ok(Value::Status(1365)) => {}
        other => panic!("exit code 1365 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_five_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..255 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1366_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1366)));
    match vm.run() {
        VMResult::Ok(Value::Status(1366)) => {}
        other => panic!("exit code 1366 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_seventy_nine_end_incrementing_from_sixEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..179 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 39 }));
    match vm.run() {
        VMResult::Ok(Value::Status(217)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(217)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1367_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1367)));
    match vm.run() {
        VMResult::Ok(Value::Status(1367)) => {}
        other => panic!("exit code 1367 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-181)));
    match vm.run() {
        VMResult::Ok(Value::Status(-181)) => {}
        other => panic!("status -181 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1368_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1368)));
    match vm.run() {
        VMResult::Ok(Value::Status(1368)) => {}
        other => panic!("exit code 1368 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-182)));
    match vm.run() {
        VMResult::Ok(Value::Status(-182)) => {}
        other => panic!("status -182 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1369_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1369)));
    match vm.run() {
        VMResult::Ok(Value::Status(1369)) => {}
        other => panic!("exit code 1369 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..90 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1363 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1363 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 90 {
                Some(1370)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1363 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1370)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1370)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1370_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1370)));
    match vm.run() {
        VMResult::Ok(Value::Status(1370)) => {}
        other => panic!("exit code 1370 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1371)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..42 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 45);
    assert_eq!(vm.last_status, 1371);
}

#[test]
fn subshell_end_exit_code_1371_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1371)));
    match vm.run() {
        VMResult::Ok(Value::Status(1371)) => {}
        other => panic!("exit code 1371 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1372Ex1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1372)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1372);
}

#[test]
fn subshell_end_exit_code_1372_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1372)));
    match vm.run() {
        VMResult::Ok(Value::Status(1372)) => {}
        other => panic!("exit code 1372 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_one_begins_thirty_nine_ends_last_end_status_winsEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..41 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..39 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1373Ex1363;
    impl ShellHost for CountingBeginEndHost1373Ex1363 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1373)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1373Ex1363));
    match vm.run() {
        VMResult::Ok(Value::Status(1373)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1373)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 41);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 39);
}

#[test]
fn subshell_end_exit_code_1373_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1373)));
    match vm.run() {
        VMResult::Ok(Value::Status(1373)) => {}
        other => panic!("exit code 1373 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1374Ex1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1374)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1374);
}

#[test]
fn subshell_end_exit_code_1374_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1374)));
    match vm.run() {
        VMResult::Ok(Value::Status(1374)) => {}
        other => panic!("exit code 1374 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1363() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1375)));
    for _ in 0..42 {
        match vm.run() {
            VMResult::Ok(Value::Status(1375)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1375_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1375)));
    match vm.run() {
        VMResult::Ok(Value::Status(1375)) => {}
        other => panic!("exit code 1375 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1376Ex1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1376)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1376);
}

#[test]
fn subshell_end_exit_code_1376_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1376)));
    match vm.run() {
        VMResult::Ok(Value::Status(1376)) => {}
        other => panic!("exit code 1376 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_end_incrementing_from_sevenEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..180 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 40 }));
    match vm.run() {
        VMResult::Ok(Value::Status(219)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(219)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1377_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1377)));
    match vm.run() {
        VMResult::Ok(Value::Status(1377)) => {}
        other => panic!("exit code 1377 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1378Ex1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1378)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1378);
}

#[test]
fn subshell_end_exit_code_1378_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1378)));
    match vm.run() {
        VMResult::Ok(Value::Status(1378)) => {}
        other => panic!("exit code 1378 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_six_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..256 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1379_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1379)));
    match vm.run() {
        VMResult::Ok(Value::Status(1379)) => {}
        other => panic!("exit code 1379 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..91 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1363 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1363 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 91 {
                Some(1380)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1363 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1380)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1380)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1380_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1380)));
    match vm.run() {
        VMResult::Ok(Value::Status(1380)) => {}
        other => panic!("exit code 1380 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1381_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1381)));
    match vm.run() {
        VMResult::Ok(Value::Status(1381)) => {}
        other => panic!("exit code 1381 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1382Ex1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1382)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1382);
}

#[test]
fn subshell_end_exit_code_1382_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1382)));
    match vm.run() {
        VMResult::Ok(Value::Status(1382)) => {}
        other => panic!("exit code 1382 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_one_end_incrementing_from_oneEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..181 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 34 }));
    match vm.run() {
        VMResult::Ok(Value::Status(214)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(214)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1383_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1383)));
    match vm.run() {
        VMResult::Ok(Value::Status(1383)) => {}
        other => panic!("exit code 1383 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1384;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1384)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1384, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1384_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1384)));
    match vm.run() {
        VMResult::Ok(Value::Status(1384)) => {}
        other => panic!("exit code 1384 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1385,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1385)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1385), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1385_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1385)));
    match vm.run() {
        VMResult::Ok(Value::Status(1385)) => {}
        other => panic!("exit code 1385 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_seven_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..257 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1386_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1386)));
    match vm.run() {
        VMResult::Ok(Value::Status(1386)) => {}
        other => panic!("exit code 1386 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..92 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1363 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1363 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 92 {
                Some(1387)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1363 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1387)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1387)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1387_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1387)));
    match vm.run() {
        VMResult::Ok(Value::Status(1387)) => {}
        other => panic!("exit code 1387 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1388Ex1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1388Ex1363;
    impl ShellHost for PipelineSubshellHost1388Ex1363 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1388)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1388Ex1363));
    match vm.run() {
        VMResult::Ok(Value::Status(1388)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1388_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1388)));
    match vm.run() {
        VMResult::Ok(Value::Status(1388)) => {}
        other => panic!("exit code 1388 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1389Ex1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1389Ex1363;
    impl ShellHost for SubshellThenPipelineHost1389Ex1363 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1389
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1389Ex1363));
    match vm.run() {
        VMResult::Ok(Value::Status(1389)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1389_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1389)));
    match vm.run() {
        VMResult::Ok(Value::Status(1389)) => {}
        other => panic!("exit code 1389 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-183)));
    match vm.run() {
        VMResult::Ok(Value::Status(-183)) => {}
        other => panic!("status -183 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1390_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1390)));
    match vm.run() {
        VMResult::Ok(Value::Status(1390)) => {}
        other => panic!("exit code 1390 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_two_end_incrementing_from_eightEx1363() {
    let mut b = ChunkBuilder::new();
    for _ in 0..182 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 41 }));
    match vm.run() {
        VMResult::Ok(Value::Status(222)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(222)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1391_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1391)));
    match vm.run() {
        VMResult::Ok(Value::Status(1391)) => {}
        other => panic!("exit code 1391 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_eight_consecutive_runs_without_reset_still_blockedEx1363() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..258 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1392_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1392)));
    match vm.run() {
        VMResult::Ok(Value::Status(1392)) => {}
        other => panic!("exit code 1392 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1393Ex1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1393Ex1363 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1393Ex1363 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1393Ex1363 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1393_propagatesEx1363() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1393)));
    match vm.run() {
        VMResult::Ok(Value::Status(1393)) => {}
        other => panic!("exit code 1393 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AY (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1394_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1394)));
    match vm.run() {
        VMResult::Ok(Value::Status(1394)) => {}
        other => panic!("exit code 1394 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_fifty_nine_consecutive_runs_without_reset_still_blockedEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..259 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1395_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1395)));
    match vm.run() {
        VMResult::Ok(Value::Status(1395)) => {}
        other => panic!("exit code 1395 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_consecutive_runs_without_reset_still_blockedEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..260 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1396_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1396)));
    match vm.run() {
        VMResult::Ok(Value::Status(1396)) => {}
        other => panic!("exit code 1396 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_one_consecutive_runs_without_reset_still_blockedEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..261 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1397_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1397)));
    match vm.run() {
        VMResult::Ok(Value::Status(1397)) => {}
        other => panic!("exit code 1397 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1398_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1398)));
    match vm.run() {
        VMResult::Ok(Value::Status(1398)) => {}
        other => panic!("exit code 1398 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-185)));
    match vm.run() {
        VMResult::Ok(Value::Status(-185)) => {}
        other => panic!("status -185 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1399_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1399)));
    match vm.run() {
        VMResult::Ok(Value::Status(1399)) => {}
        other => panic!("exit code 1399 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-186)));
    match vm.run() {
        VMResult::Ok(Value::Status(-186)) => {}
        other => panic!("status -186 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1400_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1400)));
    match vm.run() {
        VMResult::Ok(Value::Status(1400)) => {}
        other => panic!("exit code 1400 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..93 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1394 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1394 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 93 {
                Some(1401)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1394 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1401)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1401)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1401_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1401)));
    match vm.run() {
        VMResult::Ok(Value::Status(1401)) => {}
        other => panic!("exit code 1401 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1402)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..43 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 46);
    assert_eq!(vm.last_status, 1402);
}

#[test]
fn subshell_end_exit_code_1402_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1402)));
    match vm.run() {
        VMResult::Ok(Value::Status(1402)) => {}
        other => panic!("exit code 1402 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1403Ex1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1403)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1403);
}

#[test]
fn subshell_end_exit_code_1403_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1403)));
    match vm.run() {
        VMResult::Ok(Value::Status(1403)) => {}
        other => panic!("exit code 1403 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_two_begins_forty_ends_last_end_status_winsEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..42 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..40 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1404Ex1394;
    impl ShellHost for CountingBeginEndHost1404Ex1394 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1404)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1404Ex1394));
    match vm.run() {
        VMResult::Ok(Value::Status(1404)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1404)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 42);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 40);
}

#[test]
fn subshell_end_exit_code_1404_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1404)));
    match vm.run() {
        VMResult::Ok(Value::Status(1404)) => {}
        other => panic!("exit code 1404 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1405Ex1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1394;
    impl ShellHost for CountingBeginHost733Ex1394 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1405)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1394));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1405);
}

#[test]
fn subshell_end_exit_code_1405_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1405)));
    match vm.run() {
        VMResult::Ok(Value::Status(1405)) => {}
        other => panic!("exit code 1405 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1394() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1406)));
    for _ in 0..43 {
        match vm.run() {
            VMResult::Ok(Value::Status(1406)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1406_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1406)));
    match vm.run() {
        VMResult::Ok(Value::Status(1406)) => {}
        other => panic!("exit code 1406 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1407Ex1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1407)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1407);
}

#[test]
fn subshell_end_exit_code_1407_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1407)));
    match vm.run() {
        VMResult::Ok(Value::Status(1407)) => {}
        other => panic!("exit code 1407 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1408_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1408)));
    match vm.run() {
        VMResult::Ok(Value::Status(1408)) => {}
        other => panic!("exit code 1408 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1409Ex1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1409)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1409);
}

#[test]
fn subshell_end_exit_code_1409_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1409)));
    match vm.run() {
        VMResult::Ok(Value::Status(1409)) => {}
        other => panic!("exit code 1409 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_two_consecutive_runs_without_reset_still_blockedEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..262 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1410_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1410)));
    match vm.run() {
        VMResult::Ok(Value::Status(1410)) => {}
        other => panic!("exit code 1410 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_three_consecutive_runs_without_reset_still_blockedEx1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..263 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1411_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1411)));
    match vm.run() {
        VMResult::Ok(Value::Status(1411)) => {}
        other => panic!("exit code 1411 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1412_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1412)));
    match vm.run() {
        VMResult::Ok(Value::Status(1412)) => {}
        other => panic!("exit code 1412 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1413;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1413)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1413, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1413_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1413)));
    match vm.run() {
        VMResult::Ok(Value::Status(1413)) => {}
        other => panic!("exit code 1413 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1414,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1414)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1414), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1414_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1414)));
    match vm.run() {
        VMResult::Ok(Value::Status(1414)) => {}
        other => panic!("exit code 1414 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-187)));
    match vm.run() {
        VMResult::Ok(Value::Status(-187)) => {}
        other => panic!("status -187 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1415_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1415)));
    match vm.run() {
        VMResult::Ok(Value::Status(1415)) => {}
        other => panic!("exit code 1415 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_five_end_incrementing_from_fiveEx1394() {
    let mut b = ChunkBuilder::new();
    for _ in 0..185 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 41 }));
    match vm.run() {
        VMResult::Ok(Value::Status(225)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(225)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1416_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1416)));
    match vm.run() {
        VMResult::Ok(Value::Status(1416)) => {}
        other => panic!("exit code 1416 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1417Ex1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1417Ex1394 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1417Ex1394 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1417Ex1394 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1417_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1417)));
    match vm.run() {
        VMResult::Ok(Value::Status(1417)) => {}
        other => panic!("exit code 1417 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1418Ex1394() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1418)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1418);
}

#[test]
fn subshell_end_exit_code_1418_propagatesEx1394() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1418)));
    match vm.run() {
        VMResult::Ok(Value::Status(1418)) => {}
        other => panic!("exit code 1418 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch AZ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1419_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1419)));
    match vm.run() {
        VMResult::Ok(Value::Status(1419)) => {}
        other => panic!("exit code 1419 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_four_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..264 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1420_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1420)));
    match vm.run() {
        VMResult::Ok(Value::Status(1420)) => {}
        other => panic!("exit code 1420 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_five_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..265 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1421_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1421)));
    match vm.run() {
        VMResult::Ok(Value::Status(1421)) => {}
        other => panic!("exit code 1421 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_six_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..266 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1422_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1422)));
    match vm.run() {
        VMResult::Ok(Value::Status(1422)) => {}
        other => panic!("exit code 1422 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_six_end_incrementing_from_sixEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..186 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 42 }));
    match vm.run() {
        VMResult::Ok(Value::Status(227)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(227)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1423_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1423)));
    match vm.run() {
        VMResult::Ok(Value::Status(1423)) => {}
        other => panic!("exit code 1423 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-188)));
    match vm.run() {
        VMResult::Ok(Value::Status(-188)) => {}
        other => panic!("status -188 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1424_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1424)));
    match vm.run() {
        VMResult::Ok(Value::Status(1424)) => {}
        other => panic!("exit code 1424 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-189)));
    match vm.run() {
        VMResult::Ok(Value::Status(-189)) => {}
        other => panic!("status -189 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1425_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1425)));
    match vm.run() {
        VMResult::Ok(Value::Status(1425)) => {}
        other => panic!("exit code 1425 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..94 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1419 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1419 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 94 {
                Some(1426)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1419 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1426)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1426)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1426_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1426)));
    match vm.run() {
        VMResult::Ok(Value::Status(1426)) => {}
        other => panic!("exit code 1426 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1427)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..44 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 47);
    assert_eq!(vm.last_status, 1427);
}

#[test]
fn subshell_end_exit_code_1427_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1427)));
    match vm.run() {
        VMResult::Ok(Value::Status(1427)) => {}
        other => panic!("exit code 1427 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1428Ex1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1428)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1428);
}

#[test]
fn subshell_end_exit_code_1428_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1428)));
    match vm.run() {
        VMResult::Ok(Value::Status(1428)) => {}
        other => panic!("exit code 1428 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_three_begins_forty_one_ends_last_end_status_winsEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..43 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..41 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1429Ex1419;
    impl ShellHost for CountingBeginEndHost1429Ex1419 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1429)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1429Ex1419));
    match vm.run() {
        VMResult::Ok(Value::Status(1429)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1429)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 43);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 41);
}

#[test]
fn subshell_end_exit_code_1429_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1429)));
    match vm.run() {
        VMResult::Ok(Value::Status(1429)) => {}
        other => panic!("exit code 1429 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1430Ex1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1430)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1430);
}

#[test]
fn subshell_end_exit_code_1430_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1430)));
    match vm.run() {
        VMResult::Ok(Value::Status(1430)) => {}
        other => panic!("exit code 1430 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1419() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1431)));
    for _ in 0..44 {
        match vm.run() {
            VMResult::Ok(Value::Status(1431)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1431_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1431)));
    match vm.run() {
        VMResult::Ok(Value::Status(1431)) => {}
        other => panic!("exit code 1431 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1432Ex1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1432)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1432);
}

#[test]
fn subshell_end_exit_code_1432_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1432)));
    match vm.run() {
        VMResult::Ok(Value::Status(1432)) => {}
        other => panic!("exit code 1432 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_seven_end_incrementing_from_sevenEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..187 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 43 }));
    match vm.run() {
        VMResult::Ok(Value::Status(229)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(229)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1433_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1433)));
    match vm.run() {
        VMResult::Ok(Value::Status(1433)) => {}
        other => panic!("exit code 1433 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1434Ex1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1434)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1434);
}

#[test]
fn subshell_end_exit_code_1434_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1434)));
    match vm.run() {
        VMResult::Ok(Value::Status(1434)) => {}
        other => panic!("exit code 1434 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_seven_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..267 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1435_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1435)));
    match vm.run() {
        VMResult::Ok(Value::Status(1435)) => {}
        other => panic!("exit code 1435 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..95 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1419 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1419 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 95 {
                Some(1436)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1419 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1436)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1436)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1436_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1436)));
    match vm.run() {
        VMResult::Ok(Value::Status(1436)) => {}
        other => panic!("exit code 1436 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1437_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1437)));
    match vm.run() {
        VMResult::Ok(Value::Status(1437)) => {}
        other => panic!("exit code 1437 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1438Ex1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1438)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1438);
}

#[test]
fn subshell_end_exit_code_1438_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1438)));
    match vm.run() {
        VMResult::Ok(Value::Status(1438)) => {}
        other => panic!("exit code 1438 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_eight_end_incrementing_from_oneEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..188 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 37 }));
    match vm.run() {
        VMResult::Ok(Value::Status(224)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(224)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1439_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1439)));
    match vm.run() {
        VMResult::Ok(Value::Status(1439)) => {}
        other => panic!("exit code 1439 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1440;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1440)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1440, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1440_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1440)));
    match vm.run() {
        VMResult::Ok(Value::Status(1440)) => {}
        other => panic!("exit code 1440 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1441,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1441)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1441), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1441_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1441)));
    match vm.run() {
        VMResult::Ok(Value::Status(1441)) => {}
        other => panic!("exit code 1441 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_eight_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..268 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1442_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1442)));
    match vm.run() {
        VMResult::Ok(Value::Status(1442)) => {}
        other => panic!("exit code 1442 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..96 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1419 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1419 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 96 {
                Some(1443)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1419 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1443)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1443)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1443_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1443)));
    match vm.run() {
        VMResult::Ok(Value::Status(1443)) => {}
        other => panic!("exit code 1443 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1444Ex1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1444Ex1419;
    impl ShellHost for PipelineSubshellHost1444Ex1419 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1444)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1444Ex1419));
    match vm.run() {
        VMResult::Ok(Value::Status(1444)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1444_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1444)));
    match vm.run() {
        VMResult::Ok(Value::Status(1444)) => {}
        other => panic!("exit code 1444 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1445Ex1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1445Ex1419;
    impl ShellHost for SubshellThenPipelineHost1445Ex1419 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1445
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1445Ex1419));
    match vm.run() {
        VMResult::Ok(Value::Status(1445)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1445_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1445)));
    match vm.run() {
        VMResult::Ok(Value::Status(1445)) => {}
        other => panic!("exit code 1445 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-190)));
    match vm.run() {
        VMResult::Ok(Value::Status(-190)) => {}
        other => panic!("status -190 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1446_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1446)));
    match vm.run() {
        VMResult::Ok(Value::Status(1446)) => {}
        other => panic!("exit code 1446 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_eighty_nine_end_incrementing_from_eightEx1419() {
    let mut b = ChunkBuilder::new();
    for _ in 0..189 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 44 }));
    match vm.run() {
        VMResult::Ok(Value::Status(232)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(232)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1447_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1447)));
    match vm.run() {
        VMResult::Ok(Value::Status(1447)) => {}
        other => panic!("exit code 1447 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_sixty_nine_consecutive_runs_without_reset_still_blockedEx1419() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..269 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1448_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1448)));
    match vm.run() {
        VMResult::Ok(Value::Status(1448)) => {}
        other => panic!("exit code 1448 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1449Ex1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1449Ex1419 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1449Ex1419 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1449Ex1419 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1449_propagatesEx1419() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1449)));
    match vm.run() {
        VMResult::Ok(Value::Status(1449)) => {}
        other => panic!("exit code 1449 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BA (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1450_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1450)));
    match vm.run() {
        VMResult::Ok(Value::Status(1450)) => {}
        other => panic!("exit code 1450 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_consecutive_runs_without_reset_still_blockedEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..270 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1451_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1451)));
    match vm.run() {
        VMResult::Ok(Value::Status(1451)) => {}
        other => panic!("exit code 1451 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_one_consecutive_runs_without_reset_still_blockedEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..271 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1452_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1452)));
    match vm.run() {
        VMResult::Ok(Value::Status(1452)) => {}
        other => panic!("exit code 1452 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_two_consecutive_runs_without_reset_still_blockedEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..272 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1453_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1453)));
    match vm.run() {
        VMResult::Ok(Value::Status(1453)) => {}
        other => panic!("exit code 1453 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1454_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1454)));
    match vm.run() {
        VMResult::Ok(Value::Status(1454)) => {}
        other => panic!("exit code 1454 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-192)));
    match vm.run() {
        VMResult::Ok(Value::Status(-192)) => {}
        other => panic!("status -192 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1455_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1455)));
    match vm.run() {
        VMResult::Ok(Value::Status(1455)) => {}
        other => panic!("exit code 1455 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-193)));
    match vm.run() {
        VMResult::Ok(Value::Status(-193)) => {}
        other => panic!("status -193 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1456_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1456)));
    match vm.run() {
        VMResult::Ok(Value::Status(1456)) => {}
        other => panic!("exit code 1456 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..97 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1450 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1450 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 97 {
                Some(1457)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1450 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1457)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1457)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1457_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1457)));
    match vm.run() {
        VMResult::Ok(Value::Status(1457)) => {}
        other => panic!("exit code 1457 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1458)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..45 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 48);
    assert_eq!(vm.last_status, 1458);
}

#[test]
fn subshell_end_exit_code_1458_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1458)));
    match vm.run() {
        VMResult::Ok(Value::Status(1458)) => {}
        other => panic!("exit code 1458 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1459Ex1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1459)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1459);
}

#[test]
fn subshell_end_exit_code_1459_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1459)));
    match vm.run() {
        VMResult::Ok(Value::Status(1459)) => {}
        other => panic!("exit code 1459 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_four_begins_forty_two_ends_last_end_status_winsEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..44 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..42 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1460Ex1450;
    impl ShellHost for CountingBeginEndHost1460Ex1450 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1460)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1460Ex1450));
    match vm.run() {
        VMResult::Ok(Value::Status(1460)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1460)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 44);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 42);
}

#[test]
fn subshell_end_exit_code_1460_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1460)));
    match vm.run() {
        VMResult::Ok(Value::Status(1460)) => {}
        other => panic!("exit code 1460 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1461Ex1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1450;
    impl ShellHost for CountingBeginHost733Ex1450 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1461)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1450));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1461);
}

#[test]
fn subshell_end_exit_code_1461_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1461)));
    match vm.run() {
        VMResult::Ok(Value::Status(1461)) => {}
        other => panic!("exit code 1461 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1450() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1462)));
    for _ in 0..45 {
        match vm.run() {
            VMResult::Ok(Value::Status(1462)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1462_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1462)));
    match vm.run() {
        VMResult::Ok(Value::Status(1462)) => {}
        other => panic!("exit code 1462 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1463Ex1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1463)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1463);
}

#[test]
fn subshell_end_exit_code_1463_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1463)));
    match vm.run() {
        VMResult::Ok(Value::Status(1463)) => {}
        other => panic!("exit code 1463 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1464_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1464)));
    match vm.run() {
        VMResult::Ok(Value::Status(1464)) => {}
        other => panic!("exit code 1464 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1465Ex1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1465)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1465);
}

#[test]
fn subshell_end_exit_code_1465_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1465)));
    match vm.run() {
        VMResult::Ok(Value::Status(1465)) => {}
        other => panic!("exit code 1465 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_three_consecutive_runs_without_reset_still_blockedEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..273 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1466_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1466)));
    match vm.run() {
        VMResult::Ok(Value::Status(1466)) => {}
        other => panic!("exit code 1466 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_four_consecutive_runs_without_reset_still_blockedEx1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..274 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1467_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1467)));
    match vm.run() {
        VMResult::Ok(Value::Status(1467)) => {}
        other => panic!("exit code 1467 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1468_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1468)));
    match vm.run() {
        VMResult::Ok(Value::Status(1468)) => {}
        other => panic!("exit code 1468 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1469;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1469)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1469, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1469_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1469)));
    match vm.run() {
        VMResult::Ok(Value::Status(1469)) => {}
        other => panic!("exit code 1469 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1470,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1470)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1470), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1470_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1470)));
    match vm.run() {
        VMResult::Ok(Value::Status(1470)) => {}
        other => panic!("exit code 1470 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-194)));
    match vm.run() {
        VMResult::Ok(Value::Status(-194)) => {}
        other => panic!("status -194 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1471_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1471)));
    match vm.run() {
        VMResult::Ok(Value::Status(1471)) => {}
        other => panic!("exit code 1471 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_two_end_incrementing_from_fiveEx1450() {
    let mut b = ChunkBuilder::new();
    for _ in 0..192 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 44 }));
    match vm.run() {
        VMResult::Ok(Value::Status(235)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(235)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1472_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1472)));
    match vm.run() {
        VMResult::Ok(Value::Status(1472)) => {}
        other => panic!("exit code 1472 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1473Ex1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1473Ex1450 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1473Ex1450 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1473Ex1450 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1473_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1473)));
    match vm.run() {
        VMResult::Ok(Value::Status(1473)) => {}
        other => panic!("exit code 1473 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1474Ex1450() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1474)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1474);
}

#[test]
fn subshell_end_exit_code_1474_propagatesEx1450() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1474)));
    match vm.run() {
        VMResult::Ok(Value::Status(1474)) => {}
        other => panic!("exit code 1474 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BB (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1475_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1475)));
    match vm.run() {
        VMResult::Ok(Value::Status(1475)) => {}
        other => panic!("exit code 1475 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_five_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..275 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1476_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1476)));
    match vm.run() {
        VMResult::Ok(Value::Status(1476)) => {}
        other => panic!("exit code 1476 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_six_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..276 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1477_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1477)));
    match vm.run() {
        VMResult::Ok(Value::Status(1477)) => {}
        other => panic!("exit code 1477 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_seven_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..277 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1478_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1478)));
    match vm.run() {
        VMResult::Ok(Value::Status(1478)) => {}
        other => panic!("exit code 1478 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_three_end_incrementing_from_sixEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..193 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 45 }));
    match vm.run() {
        VMResult::Ok(Value::Status(237)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(237)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1479_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1479)));
    match vm.run() {
        VMResult::Ok(Value::Status(1479)) => {}
        other => panic!("exit code 1479 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-195)));
    match vm.run() {
        VMResult::Ok(Value::Status(-195)) => {}
        other => panic!("status -195 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1480_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1480)));
    match vm.run() {
        VMResult::Ok(Value::Status(1480)) => {}
        other => panic!("exit code 1480 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-196)));
    match vm.run() {
        VMResult::Ok(Value::Status(-196)) => {}
        other => panic!("status -196 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1481_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1481)));
    match vm.run() {
        VMResult::Ok(Value::Status(1481)) => {}
        other => panic!("exit code 1481 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..98 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1475 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1475 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 98 {
                Some(1482)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1475 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1482)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1482)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1482_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1482)));
    match vm.run() {
        VMResult::Ok(Value::Status(1482)) => {}
        other => panic!("exit code 1482 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1483)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..46 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 49);
    assert_eq!(vm.last_status, 1483);
}

#[test]
fn subshell_end_exit_code_1483_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1483)));
    match vm.run() {
        VMResult::Ok(Value::Status(1483)) => {}
        other => panic!("exit code 1483 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1484Ex1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1484)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1484);
}

#[test]
fn subshell_end_exit_code_1484_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1484)));
    match vm.run() {
        VMResult::Ok(Value::Status(1484)) => {}
        other => panic!("exit code 1484 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_five_begins_forty_three_ends_last_end_status_winsEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..45 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..43 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1485Ex1475;
    impl ShellHost for CountingBeginEndHost1485Ex1475 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1485)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1485Ex1475));
    match vm.run() {
        VMResult::Ok(Value::Status(1485)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1485)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 45);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 43);
}

#[test]
fn subshell_end_exit_code_1485_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1485)));
    match vm.run() {
        VMResult::Ok(Value::Status(1485)) => {}
        other => panic!("exit code 1485 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1486Ex1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1486)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1486);
}

#[test]
fn subshell_end_exit_code_1486_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1486)));
    match vm.run() {
        VMResult::Ok(Value::Status(1486)) => {}
        other => panic!("exit code 1486 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1475() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1487)));
    for _ in 0..46 {
        match vm.run() {
            VMResult::Ok(Value::Status(1487)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1487_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1487)));
    match vm.run() {
        VMResult::Ok(Value::Status(1487)) => {}
        other => panic!("exit code 1487 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1488Ex1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1488)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1488);
}

#[test]
fn subshell_end_exit_code_1488_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1488)));
    match vm.run() {
        VMResult::Ok(Value::Status(1488)) => {}
        other => panic!("exit code 1488 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_four_end_incrementing_from_sevenEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..194 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 46 }));
    match vm.run() {
        VMResult::Ok(Value::Status(239)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(239)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1489_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1489)));
    match vm.run() {
        VMResult::Ok(Value::Status(1489)) => {}
        other => panic!("exit code 1489 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1490Ex1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1490)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1490);
}

#[test]
fn subshell_end_exit_code_1490_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1490)));
    match vm.run() {
        VMResult::Ok(Value::Status(1490)) => {}
        other => panic!("exit code 1490 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_eight_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..278 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1491_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1491)));
    match vm.run() {
        VMResult::Ok(Value::Status(1491)) => {}
        other => panic!("exit code 1491 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1475 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1475 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 99 {
                Some(1492)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1475 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1492)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1492)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1492_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1492)));
    match vm.run() {
        VMResult::Ok(Value::Status(1492)) => {}
        other => panic!("exit code 1492 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1493_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1493)));
    match vm.run() {
        VMResult::Ok(Value::Status(1493)) => {}
        other => panic!("exit code 1493 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1494Ex1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1494)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1494);
}

#[test]
fn subshell_end_exit_code_1494_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1494)));
    match vm.run() {
        VMResult::Ok(Value::Status(1494)) => {}
        other => panic!("exit code 1494 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_five_end_incrementing_from_oneEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..195 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 40 }));
    match vm.run() {
        VMResult::Ok(Value::Status(234)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(234)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1495_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1495)));
    match vm.run() {
        VMResult::Ok(Value::Status(1495)) => {}
        other => panic!("exit code 1495 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1496;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1496)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1496, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1496_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1496)));
    match vm.run() {
        VMResult::Ok(Value::Status(1496)) => {}
        other => panic!("exit code 1496 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1497,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1497)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1497), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1497_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1497)));
    match vm.run() {
        VMResult::Ok(Value::Status(1497)) => {}
        other => panic!("exit code 1497 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_seventy_nine_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..279 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1498_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1498)));
    match vm.run() {
        VMResult::Ok(Value::Status(1498)) => {}
        other => panic!("exit code 1498 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1475 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1475 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 100 {
                Some(1499)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1475 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1499)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1499)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1499_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1499)));
    match vm.run() {
        VMResult::Ok(Value::Status(1499)) => {}
        other => panic!("exit code 1499 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1500Ex1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1500Ex1475;
    impl ShellHost for PipelineSubshellHost1500Ex1475 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1500)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1500Ex1475));
    match vm.run() {
        VMResult::Ok(Value::Status(1500)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1500_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1500)));
    match vm.run() {
        VMResult::Ok(Value::Status(1500)) => {}
        other => panic!("exit code 1500 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1501Ex1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1501Ex1475;
    impl ShellHost for SubshellThenPipelineHost1501Ex1475 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1501
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1501Ex1475));
    match vm.run() {
        VMResult::Ok(Value::Status(1501)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1501_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1501)));
    match vm.run() {
        VMResult::Ok(Value::Status(1501)) => {}
        other => panic!("exit code 1501 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-197)));
    match vm.run() {
        VMResult::Ok(Value::Status(-197)) => {}
        other => panic!("status -197 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1502_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1502)));
    match vm.run() {
        VMResult::Ok(Value::Status(1502)) => {}
        other => panic!("exit code 1502 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_six_end_incrementing_from_eightEx1475() {
    let mut b = ChunkBuilder::new();
    for _ in 0..196 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 47 }));
    match vm.run() {
        VMResult::Ok(Value::Status(242)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(242)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1503_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1503)));
    match vm.run() {
        VMResult::Ok(Value::Status(1503)) => {}
        other => panic!("exit code 1503 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_consecutive_runs_without_reset_still_blockedEx1475() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..280 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1504_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1504)));
    match vm.run() {
        VMResult::Ok(Value::Status(1504)) => {}
        other => panic!("exit code 1504 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1505Ex1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1505Ex1475 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1505Ex1475 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1505Ex1475 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1505_propagatesEx1475() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1505)));
    match vm.run() {
        VMResult::Ok(Value::Status(1505)) => {}
        other => panic!("exit code 1505 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BC (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1506_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1506)));
    match vm.run() {
        VMResult::Ok(Value::Status(1506)) => {}
        other => panic!("exit code 1506 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_one_consecutive_runs_without_reset_still_blockedEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..281 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1507_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1507)));
    match vm.run() {
        VMResult::Ok(Value::Status(1507)) => {}
        other => panic!("exit code 1507 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_two_consecutive_runs_without_reset_still_blockedEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..282 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1508_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1508)));
    match vm.run() {
        VMResult::Ok(Value::Status(1508)) => {}
        other => panic!("exit code 1508 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_three_consecutive_runs_without_reset_still_blockedEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..283 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1509_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1509)));
    match vm.run() {
        VMResult::Ok(Value::Status(1509)) => {}
        other => panic!("exit code 1509 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1510_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1510)));
    match vm.run() {
        VMResult::Ok(Value::Status(1510)) => {}
        other => panic!("exit code 1510 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-199)));
    match vm.run() {
        VMResult::Ok(Value::Status(-199)) => {}
        other => panic!("status -199 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1511_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1511)));
    match vm.run() {
        VMResult::Ok(Value::Status(1511)) => {}
        other => panic!("exit code 1511 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-200)));
    match vm.run() {
        VMResult::Ok(Value::Status(-200)) => {}
        other => panic!("status -200 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1512_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1512)));
    match vm.run() {
        VMResult::Ok(Value::Status(1512)) => {}
        other => panic!("exit code 1512 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..101 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1506 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1506 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 101 {
                Some(1513)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1506 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1513)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1513)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1513_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1513)));
    match vm.run() {
        VMResult::Ok(Value::Status(1513)) => {}
        other => panic!("exit code 1513 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1514)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..47 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 50);
    assert_eq!(vm.last_status, 1514);
}

#[test]
fn subshell_end_exit_code_1514_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1514)));
    match vm.run() {
        VMResult::Ok(Value::Status(1514)) => {}
        other => panic!("exit code 1514 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1515Ex1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1515)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1515);
}

#[test]
fn subshell_end_exit_code_1515_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1515)));
    match vm.run() {
        VMResult::Ok(Value::Status(1515)) => {}
        other => panic!("exit code 1515 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_six_begins_forty_four_ends_last_end_status_winsEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..46 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..44 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1516Ex1506;
    impl ShellHost for CountingBeginEndHost1516Ex1506 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1516)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1516Ex1506));
    match vm.run() {
        VMResult::Ok(Value::Status(1516)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1516)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 46);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 44);
}

#[test]
fn subshell_end_exit_code_1516_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1516)));
    match vm.run() {
        VMResult::Ok(Value::Status(1516)) => {}
        other => panic!("exit code 1516 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1517Ex1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1506;
    impl ShellHost for CountingBeginHost733Ex1506 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1517)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1506));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1517);
}

#[test]
fn subshell_end_exit_code_1517_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1517)));
    match vm.run() {
        VMResult::Ok(Value::Status(1517)) => {}
        other => panic!("exit code 1517 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1506() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1518)));
    for _ in 0..47 {
        match vm.run() {
            VMResult::Ok(Value::Status(1518)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1518_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1518)));
    match vm.run() {
        VMResult::Ok(Value::Status(1518)) => {}
        other => panic!("exit code 1518 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1519Ex1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1519)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1519);
}

#[test]
fn subshell_end_exit_code_1519_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1519)));
    match vm.run() {
        VMResult::Ok(Value::Status(1519)) => {}
        other => panic!("exit code 1519 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1520_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1520)));
    match vm.run() {
        VMResult::Ok(Value::Status(1520)) => {}
        other => panic!("exit code 1520 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1521Ex1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1521)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1521);
}

#[test]
fn subshell_end_exit_code_1521_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1521)));
    match vm.run() {
        VMResult::Ok(Value::Status(1521)) => {}
        other => panic!("exit code 1521 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_four_consecutive_runs_without_reset_still_blockedEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..284 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1522_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1522)));
    match vm.run() {
        VMResult::Ok(Value::Status(1522)) => {}
        other => panic!("exit code 1522 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_five_consecutive_runs_without_reset_still_blockedEx1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..285 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1523_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1523)));
    match vm.run() {
        VMResult::Ok(Value::Status(1523)) => {}
        other => panic!("exit code 1523 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1524_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1524)));
    match vm.run() {
        VMResult::Ok(Value::Status(1524)) => {}
        other => panic!("exit code 1524 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1525;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1525)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1525, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1525_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1525)));
    match vm.run() {
        VMResult::Ok(Value::Status(1525)) => {}
        other => panic!("exit code 1525 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1526,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1526)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1526), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1526_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1526)));
    match vm.run() {
        VMResult::Ok(Value::Status(1526)) => {}
        other => panic!("exit code 1526 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-201)));
    match vm.run() {
        VMResult::Ok(Value::Status(-201)) => {}
        other => panic!("status -201 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1527_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1527)));
    match vm.run() {
        VMResult::Ok(Value::Status(1527)) => {}
        other => panic!("exit code 1527 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_one_hundred_ninety_nine_end_incrementing_from_fiveEx1506() {
    let mut b = ChunkBuilder::new();
    for _ in 0..199 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 47 }));
    match vm.run() {
        VMResult::Ok(Value::Status(245)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(245)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1528_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1528)));
    match vm.run() {
        VMResult::Ok(Value::Status(1528)) => {}
        other => panic!("exit code 1528 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1529Ex1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1529Ex1506 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1529Ex1506 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1529Ex1506 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1529_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1529)));
    match vm.run() {
        VMResult::Ok(Value::Status(1529)) => {}
        other => panic!("exit code 1529 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1530Ex1506() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1530)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1530);
}

#[test]
fn subshell_end_exit_code_1530_propagatesEx1506() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1530)));
    match vm.run() {
        VMResult::Ok(Value::Status(1530)) => {}
        other => panic!("exit code 1530 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BD (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1531_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1531)));
    match vm.run() {
        VMResult::Ok(Value::Status(1531)) => {}
        other => panic!("exit code 1531 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_six_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..286 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1532_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1532)));
    match vm.run() {
        VMResult::Ok(Value::Status(1532)) => {}
        other => panic!("exit code 1532 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_seven_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..287 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1533_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1533)));
    match vm.run() {
        VMResult::Ok(Value::Status(1533)) => {}
        other => panic!("exit code 1533 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_eight_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..288 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1534_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1534)));
    match vm.run() {
        VMResult::Ok(Value::Status(1534)) => {}
        other => panic!("exit code 1534 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_end_incrementing_from_sixEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..200 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 48 }));
    match vm.run() {
        VMResult::Ok(Value::Status(247)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(247)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1535_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1535)));
    match vm.run() {
        VMResult::Ok(Value::Status(1535)) => {}
        other => panic!("exit code 1535 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-202)));
    match vm.run() {
        VMResult::Ok(Value::Status(-202)) => {}
        other => panic!("status -202 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1536_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1536)));
    match vm.run() {
        VMResult::Ok(Value::Status(1536)) => {}
        other => panic!("exit code 1536 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-203)));
    match vm.run() {
        VMResult::Ok(Value::Status(-203)) => {}
        other => panic!("status -203 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1537_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1537)));
    match vm.run() {
        VMResult::Ok(Value::Status(1537)) => {}
        other => panic!("exit code 1537 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..102 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1531 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1531 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 102 {
                Some(1538)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1531 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1538)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1538)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1538_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1538)));
    match vm.run() {
        VMResult::Ok(Value::Status(1538)) => {}
        other => panic!("exit code 1538 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1539)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..48 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 51);
    assert_eq!(vm.last_status, 1539);
}

#[test]
fn subshell_end_exit_code_1539_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1539)));
    match vm.run() {
        VMResult::Ok(Value::Status(1539)) => {}
        other => panic!("exit code 1539 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1540Ex1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1540)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1540);
}

#[test]
fn subshell_end_exit_code_1540_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1540)));
    match vm.run() {
        VMResult::Ok(Value::Status(1540)) => {}
        other => panic!("exit code 1540 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seven_begins_forty_five_ends_last_end_status_winsEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..47 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..45 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1541Ex1531;
    impl ShellHost for CountingBeginEndHost1541Ex1531 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1541)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1541Ex1531));
    match vm.run() {
        VMResult::Ok(Value::Status(1541)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1541)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 47);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 45);
}

#[test]
fn subshell_end_exit_code_1541_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1541)));
    match vm.run() {
        VMResult::Ok(Value::Status(1541)) => {}
        other => panic!("exit code 1541 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1542Ex1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1542)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1542);
}

#[test]
fn subshell_end_exit_code_1542_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1542)));
    match vm.run() {
        VMResult::Ok(Value::Status(1542)) => {}
        other => panic!("exit code 1542 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1531() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1543)));
    for _ in 0..48 {
        match vm.run() {
            VMResult::Ok(Value::Status(1543)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1543_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1543)));
    match vm.run() {
        VMResult::Ok(Value::Status(1543)) => {}
        other => panic!("exit code 1543 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1544Ex1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1544)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1544);
}

#[test]
fn subshell_end_exit_code_1544_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1544)));
    match vm.run() {
        VMResult::Ok(Value::Status(1544)) => {}
        other => panic!("exit code 1544 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_one_end_incrementing_from_sevenEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..201 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 49 }));
    match vm.run() {
        VMResult::Ok(Value::Status(249)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(249)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1545_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1545)));
    match vm.run() {
        VMResult::Ok(Value::Status(1545)) => {}
        other => panic!("exit code 1545 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1546Ex1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1546)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1546);
}

#[test]
fn subshell_end_exit_code_1546_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1546)));
    match vm.run() {
        VMResult::Ok(Value::Status(1546)) => {}
        other => panic!("exit code 1546 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_eighty_nine_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..289 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1547_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1547)));
    match vm.run() {
        VMResult::Ok(Value::Status(1547)) => {}
        other => panic!("exit code 1547 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..103 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1531 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1531 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 103 {
                Some(1548)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1531 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1548)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1548)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1548_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1548)));
    match vm.run() {
        VMResult::Ok(Value::Status(1548)) => {}
        other => panic!("exit code 1548 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1549_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1549)));
    match vm.run() {
        VMResult::Ok(Value::Status(1549)) => {}
        other => panic!("exit code 1549 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1550Ex1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1550)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1550);
}

#[test]
fn subshell_end_exit_code_1550_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1550)));
    match vm.run() {
        VMResult::Ok(Value::Status(1550)) => {}
        other => panic!("exit code 1550 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_two_end_incrementing_from_oneEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..202 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 43 }));
    match vm.run() {
        VMResult::Ok(Value::Status(244)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(244)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1551_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1551)));
    match vm.run() {
        VMResult::Ok(Value::Status(1551)) => {}
        other => panic!("exit code 1551 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1552;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1552)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1552, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1552_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1552)));
    match vm.run() {
        VMResult::Ok(Value::Status(1552)) => {}
        other => panic!("exit code 1552 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1553,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1553)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1553), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1553_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1553)));
    match vm.run() {
        VMResult::Ok(Value::Status(1553)) => {}
        other => panic!("exit code 1553 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..290 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1554_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1554)));
    match vm.run() {
        VMResult::Ok(Value::Status(1554)) => {}
        other => panic!("exit code 1554 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..104 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1531 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1531 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 104 {
                Some(1555)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1531 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1555)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1555)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1555_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1555)));
    match vm.run() {
        VMResult::Ok(Value::Status(1555)) => {}
        other => panic!("exit code 1555 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1556Ex1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1556Ex1531;
    impl ShellHost for PipelineSubshellHost1556Ex1531 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1556)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1556Ex1531));
    match vm.run() {
        VMResult::Ok(Value::Status(1556)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1556_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1556)));
    match vm.run() {
        VMResult::Ok(Value::Status(1556)) => {}
        other => panic!("exit code 1556 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1557Ex1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1557Ex1531;
    impl ShellHost for SubshellThenPipelineHost1557Ex1531 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1557
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1557Ex1531));
    match vm.run() {
        VMResult::Ok(Value::Status(1557)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1557_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1557)));
    match vm.run() {
        VMResult::Ok(Value::Status(1557)) => {}
        other => panic!("exit code 1557 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-204)));
    match vm.run() {
        VMResult::Ok(Value::Status(-204)) => {}
        other => panic!("status -204 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1558_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1558)));
    match vm.run() {
        VMResult::Ok(Value::Status(1558)) => {}
        other => panic!("exit code 1558 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_three_end_incrementing_from_eightEx1531() {
    let mut b = ChunkBuilder::new();
    for _ in 0..203 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 50 }));
    match vm.run() {
        VMResult::Ok(Value::Status(252)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(252)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1559_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1559)));
    match vm.run() {
        VMResult::Ok(Value::Status(1559)) => {}
        other => panic!("exit code 1559 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_one_consecutive_runs_without_reset_still_blockedEx1531() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..291 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1560_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1560)));
    match vm.run() {
        VMResult::Ok(Value::Status(1560)) => {}
        other => panic!("exit code 1560 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1561Ex1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1561Ex1531 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1561Ex1531 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1561Ex1531 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1561_propagatesEx1531() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1561)));
    match vm.run() {
        VMResult::Ok(Value::Status(1561)) => {}
        other => panic!("exit code 1561 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BE (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1562_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1562)));
    match vm.run() {
        VMResult::Ok(Value::Status(1562)) => {}
        other => panic!("exit code 1562 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_two_consecutive_runs_without_reset_still_blockedEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..292 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1563_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1563)));
    match vm.run() {
        VMResult::Ok(Value::Status(1563)) => {}
        other => panic!("exit code 1563 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_three_consecutive_runs_without_reset_still_blockedEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..293 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1564_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1564)));
    match vm.run() {
        VMResult::Ok(Value::Status(1564)) => {}
        other => panic!("exit code 1564 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_four_consecutive_runs_without_reset_still_blockedEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..294 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1565_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1565)));
    match vm.run() {
        VMResult::Ok(Value::Status(1565)) => {}
        other => panic!("exit code 1565 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1566_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1566)));
    match vm.run() {
        VMResult::Ok(Value::Status(1566)) => {}
        other => panic!("exit code 1566 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-206)));
    match vm.run() {
        VMResult::Ok(Value::Status(-206)) => {}
        other => panic!("status -206 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1567_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1567)));
    match vm.run() {
        VMResult::Ok(Value::Status(1567)) => {}
        other => panic!("exit code 1567 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-207)));
    match vm.run() {
        VMResult::Ok(Value::Status(-207)) => {}
        other => panic!("status -207 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1568_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1568)));
    match vm.run() {
        VMResult::Ok(Value::Status(1568)) => {}
        other => panic!("exit code 1568 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..105 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1562 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1562 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 105 {
                Some(1569)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1562 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1569)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1569)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1569_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1569)));
    match vm.run() {
        VMResult::Ok(Value::Status(1569)) => {}
        other => panic!("exit code 1569 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1570)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..49 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 52);
    assert_eq!(vm.last_status, 1570);
}

#[test]
fn subshell_end_exit_code_1570_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1570)));
    match vm.run() {
        VMResult::Ok(Value::Status(1570)) => {}
        other => panic!("exit code 1570 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1571Ex1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1571)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1571);
}

#[test]
fn subshell_end_exit_code_1571_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1571)));
    match vm.run() {
        VMResult::Ok(Value::Status(1571)) => {}
        other => panic!("exit code 1571 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eight_begins_forty_six_ends_last_end_status_winsEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..48 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..46 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1572Ex1562;
    impl ShellHost for CountingBeginEndHost1572Ex1562 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1572)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1572Ex1562));
    match vm.run() {
        VMResult::Ok(Value::Status(1572)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1572)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 48);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 46);
}

#[test]
fn subshell_end_exit_code_1572_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1572)));
    match vm.run() {
        VMResult::Ok(Value::Status(1572)) => {}
        other => panic!("exit code 1572 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1573Ex1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1562;
    impl ShellHost for CountingBeginHost733Ex1562 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1573)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1562));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1573);
}

#[test]
fn subshell_end_exit_code_1573_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1573)));
    match vm.run() {
        VMResult::Ok(Value::Status(1573)) => {}
        other => panic!("exit code 1573 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1562() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1574)));
    for _ in 0..49 {
        match vm.run() {
            VMResult::Ok(Value::Status(1574)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1574_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1574)));
    match vm.run() {
        VMResult::Ok(Value::Status(1574)) => {}
        other => panic!("exit code 1574 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1575Ex1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1575)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1575);
}

#[test]
fn subshell_end_exit_code_1575_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1575)));
    match vm.run() {
        VMResult::Ok(Value::Status(1575)) => {}
        other => panic!("exit code 1575 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1576_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1576)));
    match vm.run() {
        VMResult::Ok(Value::Status(1576)) => {}
        other => panic!("exit code 1576 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1577Ex1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1577)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1577);
}

#[test]
fn subshell_end_exit_code_1577_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1577)));
    match vm.run() {
        VMResult::Ok(Value::Status(1577)) => {}
        other => panic!("exit code 1577 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_five_consecutive_runs_without_reset_still_blockedEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..295 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1578_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1578)));
    match vm.run() {
        VMResult::Ok(Value::Status(1578)) => {}
        other => panic!("exit code 1578 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_six_consecutive_runs_without_reset_still_blockedEx1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..296 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1579_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1579)));
    match vm.run() {
        VMResult::Ok(Value::Status(1579)) => {}
        other => panic!("exit code 1579 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1580_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1580)));
    match vm.run() {
        VMResult::Ok(Value::Status(1580)) => {}
        other => panic!("exit code 1580 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1581;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1581)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1581, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1581_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1581)));
    match vm.run() {
        VMResult::Ok(Value::Status(1581)) => {}
        other => panic!("exit code 1581 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1582,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1582)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1582), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1582_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1582)));
    match vm.run() {
        VMResult::Ok(Value::Status(1582)) => {}
        other => panic!("exit code 1582 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-208)));
    match vm.run() {
        VMResult::Ok(Value::Status(-208)) => {}
        other => panic!("status -208 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1583_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1583)));
    match vm.run() {
        VMResult::Ok(Value::Status(1583)) => {}
        other => panic!("exit code 1583 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_six_end_incrementing_from_fiveEx1562() {
    let mut b = ChunkBuilder::new();
    for _ in 0..206 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 50 }));
    match vm.run() {
        VMResult::Ok(Value::Status(255)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(255)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1584_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1584)));
    match vm.run() {
        VMResult::Ok(Value::Status(1584)) => {}
        other => panic!("exit code 1584 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1585Ex1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1585Ex1562 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1585Ex1562 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1585Ex1562 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1585_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1585)));
    match vm.run() {
        VMResult::Ok(Value::Status(1585)) => {}
        other => panic!("exit code 1585 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1586Ex1562() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1586)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1586);
}

#[test]
fn subshell_end_exit_code_1586_propagatesEx1562() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1586)));
    match vm.run() {
        VMResult::Ok(Value::Status(1586)) => {}
        other => panic!("exit code 1586 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BF (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1587_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1587)));
    match vm.run() {
        VMResult::Ok(Value::Status(1587)) => {}
        other => panic!("exit code 1587 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_seven_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..297 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1588_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1588)));
    match vm.run() {
        VMResult::Ok(Value::Status(1588)) => {}
        other => panic!("exit code 1588 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_eight_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..298 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1589_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1589)));
    match vm.run() {
        VMResult::Ok(Value::Status(1589)) => {}
        other => panic!("exit code 1589 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_two_hundred_ninety_nine_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..299 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1590_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1590)));
    match vm.run() {
        VMResult::Ok(Value::Status(1590)) => {}
        other => panic!("exit code 1590 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seven_end_incrementing_from_sixEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..207 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 51 }));
    match vm.run() {
        VMResult::Ok(Value::Status(257)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(257)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1591_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1591)));
    match vm.run() {
        VMResult::Ok(Value::Status(1591)) => {}
        other => panic!("exit code 1591 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-209)));
    match vm.run() {
        VMResult::Ok(Value::Status(-209)) => {}
        other => panic!("status -209 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1592_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1592)));
    match vm.run() {
        VMResult::Ok(Value::Status(1592)) => {}
        other => panic!("exit code 1592 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-210)));
    match vm.run() {
        VMResult::Ok(Value::Status(-210)) => {}
        other => panic!("status -210 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1593_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1593)));
    match vm.run() {
        VMResult::Ok(Value::Status(1593)) => {}
        other => panic!("exit code 1593 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..106 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1587 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1587 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 106 {
                Some(1594)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1587 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1594)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1594)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1594_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1594)));
    match vm.run() {
        VMResult::Ok(Value::Status(1594)) => {}
        other => panic!("exit code 1594 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1595)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..50 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 53);
    assert_eq!(vm.last_status, 1595);
}

#[test]
fn subshell_end_exit_code_1595_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1595)));
    match vm.run() {
        VMResult::Ok(Value::Status(1595)) => {}
        other => panic!("exit code 1595 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1596Ex1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1596)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1596);
}

#[test]
fn subshell_end_exit_code_1596_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1596)));
    match vm.run() {
        VMResult::Ok(Value::Status(1596)) => {}
        other => panic!("exit code 1596 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_nine_begins_forty_seven_ends_last_end_status_winsEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..49 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..47 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1597Ex1587;
    impl ShellHost for CountingBeginEndHost1597Ex1587 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1597)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1597Ex1587));
    match vm.run() {
        VMResult::Ok(Value::Status(1597)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1597)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 49);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 47);
}

#[test]
fn subshell_end_exit_code_1597_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1597)));
    match vm.run() {
        VMResult::Ok(Value::Status(1597)) => {}
        other => panic!("exit code 1597 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1598Ex1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1598)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1598);
}

#[test]
fn subshell_end_exit_code_1598_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1598)));
    match vm.run() {
        VMResult::Ok(Value::Status(1598)) => {}
        other => panic!("exit code 1598 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1587() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1599)));
    for _ in 0..50 {
        match vm.run() {
            VMResult::Ok(Value::Status(1599)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1599_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1599)));
    match vm.run() {
        VMResult::Ok(Value::Status(1599)) => {}
        other => panic!("exit code 1599 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1600Ex1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1600)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1600);
}

#[test]
fn subshell_end_exit_code_1600_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1600)));
    match vm.run() {
        VMResult::Ok(Value::Status(1600)) => {}
        other => panic!("exit code 1600 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eight_end_incrementing_from_sevenEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..208 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 52 }));
    match vm.run() {
        VMResult::Ok(Value::Status(259)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(259)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1601_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1601)));
    match vm.run() {
        VMResult::Ok(Value::Status(1601)) => {}
        other => panic!("exit code 1601 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1602Ex1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1602)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1602);
}

#[test]
fn subshell_end_exit_code_1602_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1602)));
    match vm.run() {
        VMResult::Ok(Value::Status(1602)) => {}
        other => panic!("exit code 1602 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..300 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1603_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1603)));
    match vm.run() {
        VMResult::Ok(Value::Status(1603)) => {}
        other => panic!("exit code 1603 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..107 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1587 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1587 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 107 {
                Some(1604)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1587 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1604)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1604)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1604_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1604)));
    match vm.run() {
        VMResult::Ok(Value::Status(1604)) => {}
        other => panic!("exit code 1604 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1605_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1605)));
    match vm.run() {
        VMResult::Ok(Value::Status(1605)) => {}
        other => panic!("exit code 1605 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1606Ex1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1606)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1606);
}

#[test]
fn subshell_end_exit_code_1606_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1606)));
    match vm.run() {
        VMResult::Ok(Value::Status(1606)) => {}
        other => panic!("exit code 1606 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_nine_end_incrementing_from_oneEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..209 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 46 }));
    match vm.run() {
        VMResult::Ok(Value::Status(254)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(254)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1607_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1607)));
    match vm.run() {
        VMResult::Ok(Value::Status(1607)) => {}
        other => panic!("exit code 1607 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1608;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1608)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1608, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1608_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1608)));
    match vm.run() {
        VMResult::Ok(Value::Status(1608)) => {}
        other => panic!("exit code 1608 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1609,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1609)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1609), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1609_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1609)));
    match vm.run() {
        VMResult::Ok(Value::Status(1609)) => {}
        other => panic!("exit code 1609 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_one_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..301 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1610_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1610)));
    match vm.run() {
        VMResult::Ok(Value::Status(1610)) => {}
        other => panic!("exit code 1610 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..108 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1587 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1587 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 108 {
                Some(1611)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1587 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1611)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1611)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1611_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1611)));
    match vm.run() {
        VMResult::Ok(Value::Status(1611)) => {}
        other => panic!("exit code 1611 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1612Ex1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1612Ex1587;
    impl ShellHost for PipelineSubshellHost1612Ex1587 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1612)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1612Ex1587));
    match vm.run() {
        VMResult::Ok(Value::Status(1612)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1612_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1612)));
    match vm.run() {
        VMResult::Ok(Value::Status(1612)) => {}
        other => panic!("exit code 1612 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1613Ex1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1613Ex1587;
    impl ShellHost for SubshellThenPipelineHost1613Ex1587 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1613
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1613Ex1587));
    match vm.run() {
        VMResult::Ok(Value::Status(1613)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1613_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1613)));
    match vm.run() {
        VMResult::Ok(Value::Status(1613)) => {}
        other => panic!("exit code 1613 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-211)));
    match vm.run() {
        VMResult::Ok(Value::Status(-211)) => {}
        other => panic!("status -211 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1614_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1614)));
    match vm.run() {
        VMResult::Ok(Value::Status(1614)) => {}
        other => panic!("exit code 1614 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ten_end_incrementing_from_eightEx1587() {
    let mut b = ChunkBuilder::new();
    for _ in 0..210 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 53 }));
    match vm.run() {
        VMResult::Ok(Value::Status(262)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(262)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1615_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1615)));
    match vm.run() {
        VMResult::Ok(Value::Status(1615)) => {}
        other => panic!("exit code 1615 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_two_consecutive_runs_without_reset_still_blockedEx1587() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..302 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1616_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1616)));
    match vm.run() {
        VMResult::Ok(Value::Status(1616)) => {}
        other => panic!("exit code 1616 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1617Ex1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1617Ex1587 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1617Ex1587 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1617Ex1587 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1617_propagatesEx1587() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1617)));
    match vm.run() {
        VMResult::Ok(Value::Status(1617)) => {}
        other => panic!("exit code 1617 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BG (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1618_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1618)));
    match vm.run() {
        VMResult::Ok(Value::Status(1618)) => {}
        other => panic!("exit code 1618 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_three_consecutive_runs_without_reset_still_blockedEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..303 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1619_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1619)));
    match vm.run() {
        VMResult::Ok(Value::Status(1619)) => {}
        other => panic!("exit code 1619 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_four_consecutive_runs_without_reset_still_blockedEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..304 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1620_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1620)));
    match vm.run() {
        VMResult::Ok(Value::Status(1620)) => {}
        other => panic!("exit code 1620 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_five_consecutive_runs_without_reset_still_blockedEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..305 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1621_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1621)));
    match vm.run() {
        VMResult::Ok(Value::Status(1621)) => {}
        other => panic!("exit code 1621 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1622_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1622)));
    match vm.run() {
        VMResult::Ok(Value::Status(1622)) => {}
        other => panic!("exit code 1622 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-213)));
    match vm.run() {
        VMResult::Ok(Value::Status(-213)) => {}
        other => panic!("status -213 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1623_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1623)));
    match vm.run() {
        VMResult::Ok(Value::Status(1623)) => {}
        other => panic!("exit code 1623 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-214)));
    match vm.run() {
        VMResult::Ok(Value::Status(-214)) => {}
        other => panic!("status -214 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1624_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1624)));
    match vm.run() {
        VMResult::Ok(Value::Status(1624)) => {}
        other => panic!("exit code 1624 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..109 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1618 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1618 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 109 {
                Some(1625)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1618 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1625)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1625)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1625_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1625)));
    match vm.run() {
        VMResult::Ok(Value::Status(1625)) => {}
        other => panic!("exit code 1625 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1626)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..51 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 54);
    assert_eq!(vm.last_status, 1626);
}

#[test]
fn subshell_end_exit_code_1626_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1626)));
    match vm.run() {
        VMResult::Ok(Value::Status(1626)) => {}
        other => panic!("exit code 1626 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1627Ex1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1627)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1627);
}

#[test]
fn subshell_end_exit_code_1627_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1627)));
    match vm.run() {
        VMResult::Ok(Value::Status(1627)) => {}
        other => panic!("exit code 1627 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_begins_forty_eight_ends_last_end_status_winsEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..50 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..48 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1628Ex1618;
    impl ShellHost for CountingBeginEndHost1628Ex1618 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1628)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1628Ex1618));
    match vm.run() {
        VMResult::Ok(Value::Status(1628)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1628)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 50);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 48);
}

#[test]
fn subshell_end_exit_code_1628_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1628)));
    match vm.run() {
        VMResult::Ok(Value::Status(1628)) => {}
        other => panic!("exit code 1628 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1629Ex1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1618;
    impl ShellHost for CountingBeginHost733Ex1618 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1629)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1618));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1629);
}

#[test]
fn subshell_end_exit_code_1629_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1629)));
    match vm.run() {
        VMResult::Ok(Value::Status(1629)) => {}
        other => panic!("exit code 1629 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1618() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1630)));
    for _ in 0..51 {
        match vm.run() {
            VMResult::Ok(Value::Status(1630)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1630_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1630)));
    match vm.run() {
        VMResult::Ok(Value::Status(1630)) => {}
        other => panic!("exit code 1630 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1631Ex1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1631)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1631);
}

#[test]
fn subshell_end_exit_code_1631_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1631)));
    match vm.run() {
        VMResult::Ok(Value::Status(1631)) => {}
        other => panic!("exit code 1631 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1632_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1632)));
    match vm.run() {
        VMResult::Ok(Value::Status(1632)) => {}
        other => panic!("exit code 1632 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1633Ex1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1633)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1633);
}

#[test]
fn subshell_end_exit_code_1633_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1633)));
    match vm.run() {
        VMResult::Ok(Value::Status(1633)) => {}
        other => panic!("exit code 1633 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_six_consecutive_runs_without_reset_still_blockedEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..306 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1634_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1634)));
    match vm.run() {
        VMResult::Ok(Value::Status(1634)) => {}
        other => panic!("exit code 1634 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seven_consecutive_runs_without_reset_still_blockedEx1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..307 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1635_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1635)));
    match vm.run() {
        VMResult::Ok(Value::Status(1635)) => {}
        other => panic!("exit code 1635 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1636_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1636)));
    match vm.run() {
        VMResult::Ok(Value::Status(1636)) => {}
        other => panic!("exit code 1636 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1637;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1637)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1637, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1637_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1637)));
    match vm.run() {
        VMResult::Ok(Value::Status(1637)) => {}
        other => panic!("exit code 1637 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1638,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1638)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1638), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1638_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1638)));
    match vm.run() {
        VMResult::Ok(Value::Status(1638)) => {}
        other => panic!("exit code 1638 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-215)));
    match vm.run() {
        VMResult::Ok(Value::Status(-215)) => {}
        other => panic!("status -215 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1639_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1639)));
    match vm.run() {
        VMResult::Ok(Value::Status(1639)) => {}
        other => panic!("exit code 1639 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirteen_end_incrementing_from_fiveEx1618() {
    let mut b = ChunkBuilder::new();
    for _ in 0..213 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 53 }));
    match vm.run() {
        VMResult::Ok(Value::Status(265)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(265)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1640_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1640)));
    match vm.run() {
        VMResult::Ok(Value::Status(1640)) => {}
        other => panic!("exit code 1640 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1641Ex1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1641Ex1618 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1641Ex1618 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1641Ex1618 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1641_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1641)));
    match vm.run() {
        VMResult::Ok(Value::Status(1641)) => {}
        other => panic!("exit code 1641 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1642Ex1618() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1642)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1642);
}

#[test]
fn subshell_end_exit_code_1642_propagatesEx1618() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1642)));
    match vm.run() {
        VMResult::Ok(Value::Status(1642)) => {}
        other => panic!("exit code 1642 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BH (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1643_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1643)));
    match vm.run() {
        VMResult::Ok(Value::Status(1643)) => {}
        other => panic!("exit code 1643 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eight_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..308 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1644_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1644)));
    match vm.run() {
        VMResult::Ok(Value::Status(1644)) => {}
        other => panic!("exit code 1644 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_nine_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..309 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1645_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1645)));
    match vm.run() {
        VMResult::Ok(Value::Status(1645)) => {}
        other => panic!("exit code 1645 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ten_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..310 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1646_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1646)));
    match vm.run() {
        VMResult::Ok(Value::Status(1646)) => {}
        other => panic!("exit code 1646 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fourteen_end_incrementing_from_sixEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..214 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 54 }));
    match vm.run() {
        VMResult::Ok(Value::Status(267)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(267)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1647_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1647)));
    match vm.run() {
        VMResult::Ok(Value::Status(1647)) => {}
        other => panic!("exit code 1647 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-216)));
    match vm.run() {
        VMResult::Ok(Value::Status(-216)) => {}
        other => panic!("status -216 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1648_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1648)));
    match vm.run() {
        VMResult::Ok(Value::Status(1648)) => {}
        other => panic!("exit code 1648 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-217)));
    match vm.run() {
        VMResult::Ok(Value::Status(-217)) => {}
        other => panic!("status -217 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1649_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1649)));
    match vm.run() {
        VMResult::Ok(Value::Status(1649)) => {}
        other => panic!("exit code 1649 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..110 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1643 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1643 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 110 {
                Some(1650)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1643 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1650)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1650)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1650_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1650)));
    match vm.run() {
        VMResult::Ok(Value::Status(1650)) => {}
        other => panic!("exit code 1650 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1651)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..52 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 55);
    assert_eq!(vm.last_status, 1651);
}

#[test]
fn subshell_end_exit_code_1651_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1651)));
    match vm.run() {
        VMResult::Ok(Value::Status(1651)) => {}
        other => panic!("exit code 1651 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1652Ex1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1652)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1652);
}

#[test]
fn subshell_end_exit_code_1652_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1652)));
    match vm.run() {
        VMResult::Ok(Value::Status(1652)) => {}
        other => panic!("exit code 1652 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_one_begins_forty_nine_ends_last_end_status_winsEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..51 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..49 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1653Ex1643;
    impl ShellHost for CountingBeginEndHost1653Ex1643 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1653)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1653Ex1643));
    match vm.run() {
        VMResult::Ok(Value::Status(1653)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1653)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 51);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 49);
}

#[test]
fn subshell_end_exit_code_1653_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1653)));
    match vm.run() {
        VMResult::Ok(Value::Status(1653)) => {}
        other => panic!("exit code 1653 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1654Ex1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1654)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1654);
}

#[test]
fn subshell_end_exit_code_1654_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1654)));
    match vm.run() {
        VMResult::Ok(Value::Status(1654)) => {}
        other => panic!("exit code 1654 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1643() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1655)));
    for _ in 0..52 {
        match vm.run() {
            VMResult::Ok(Value::Status(1655)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1655_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1655)));
    match vm.run() {
        VMResult::Ok(Value::Status(1655)) => {}
        other => panic!("exit code 1655 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1656Ex1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1656)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1656);
}

#[test]
fn subshell_end_exit_code_1656_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1656)));
    match vm.run() {
        VMResult::Ok(Value::Status(1656)) => {}
        other => panic!("exit code 1656 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifteen_end_incrementing_from_sevenEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..215 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 55 }));
    match vm.run() {
        VMResult::Ok(Value::Status(269)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(269)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1657_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1657)));
    match vm.run() {
        VMResult::Ok(Value::Status(1657)) => {}
        other => panic!("exit code 1657 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1658Ex1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1658)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1658);
}

#[test]
fn subshell_end_exit_code_1658_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1658)));
    match vm.run() {
        VMResult::Ok(Value::Status(1658)) => {}
        other => panic!("exit code 1658 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eleven_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..311 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1659_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1659)));
    match vm.run() {
        VMResult::Ok(Value::Status(1659)) => {}
        other => panic!("exit code 1659 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..111 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1643 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1643 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 111 {
                Some(1660)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1643 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1660)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1660)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1660_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1660)));
    match vm.run() {
        VMResult::Ok(Value::Status(1660)) => {}
        other => panic!("exit code 1660 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1661_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1661)));
    match vm.run() {
        VMResult::Ok(Value::Status(1661)) => {}
        other => panic!("exit code 1661 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1662Ex1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1662)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1662);
}

#[test]
fn subshell_end_exit_code_1662_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1662)));
    match vm.run() {
        VMResult::Ok(Value::Status(1662)) => {}
        other => panic!("exit code 1662 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixteen_end_incrementing_from_oneEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..216 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 49 }));
    match vm.run() {
        VMResult::Ok(Value::Status(264)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(264)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1663_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1663)));
    match vm.run() {
        VMResult::Ok(Value::Status(1663)) => {}
        other => panic!("exit code 1663 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1664;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1664)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1664, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1664_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1664)));
    match vm.run() {
        VMResult::Ok(Value::Status(1664)) => {}
        other => panic!("exit code 1664 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1665,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1665)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1665), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1665_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1665)));
    match vm.run() {
        VMResult::Ok(Value::Status(1665)) => {}
        other => panic!("exit code 1665 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twelve_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..312 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1666_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1666)));
    match vm.run() {
        VMResult::Ok(Value::Status(1666)) => {}
        other => panic!("exit code 1666 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..112 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1643 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1643 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 112 {
                Some(1667)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1643 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1667)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1667)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1667_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1667)));
    match vm.run() {
        VMResult::Ok(Value::Status(1667)) => {}
        other => panic!("exit code 1667 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1668Ex1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1668Ex1643;
    impl ShellHost for PipelineSubshellHost1668Ex1643 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1668)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1668Ex1643));
    match vm.run() {
        VMResult::Ok(Value::Status(1668)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1668_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1668)));
    match vm.run() {
        VMResult::Ok(Value::Status(1668)) => {}
        other => panic!("exit code 1668 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1669Ex1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1669Ex1643;
    impl ShellHost for SubshellThenPipelineHost1669Ex1643 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1669
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1669Ex1643));
    match vm.run() {
        VMResult::Ok(Value::Status(1669)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1669_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1669)));
    match vm.run() {
        VMResult::Ok(Value::Status(1669)) => {}
        other => panic!("exit code 1669 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-218)));
    match vm.run() {
        VMResult::Ok(Value::Status(-218)) => {}
        other => panic!("status -218 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1670_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1670)));
    match vm.run() {
        VMResult::Ok(Value::Status(1670)) => {}
        other => panic!("exit code 1670 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventeen_end_incrementing_from_eightEx1643() {
    let mut b = ChunkBuilder::new();
    for _ in 0..217 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 56 }));
    match vm.run() {
        VMResult::Ok(Value::Status(272)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(272)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1671_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1671)));
    match vm.run() {
        VMResult::Ok(Value::Status(1671)) => {}
        other => panic!("exit code 1671 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirteen_consecutive_runs_without_reset_still_blockedEx1643() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..313 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1672_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1672)));
    match vm.run() {
        VMResult::Ok(Value::Status(1672)) => {}
        other => panic!("exit code 1672 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1673Ex1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1673Ex1643 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1673Ex1643 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1673Ex1643 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1673_propagatesEx1643() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1673)));
    match vm.run() {
        VMResult::Ok(Value::Status(1673)) => {}
        other => panic!("exit code 1673 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BI (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1674_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1674)));
    match vm.run() {
        VMResult::Ok(Value::Status(1674)) => {}
        other => panic!("exit code 1674 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fourteen_consecutive_runs_without_reset_still_blockedEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..314 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1675_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1675)));
    match vm.run() {
        VMResult::Ok(Value::Status(1675)) => {}
        other => panic!("exit code 1675 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifteen_consecutive_runs_without_reset_still_blockedEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..315 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1676_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1676)));
    match vm.run() {
        VMResult::Ok(Value::Status(1676)) => {}
        other => panic!("exit code 1676 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixteen_consecutive_runs_without_reset_still_blockedEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..316 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1677_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1677)));
    match vm.run() {
        VMResult::Ok(Value::Status(1677)) => {}
        other => panic!("exit code 1677 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1678_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1678)));
    match vm.run() {
        VMResult::Ok(Value::Status(1678)) => {}
        other => panic!("exit code 1678 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-220)));
    match vm.run() {
        VMResult::Ok(Value::Status(-220)) => {}
        other => panic!("status -220 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1679_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1679)));
    match vm.run() {
        VMResult::Ok(Value::Status(1679)) => {}
        other => panic!("exit code 1679 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-221)));
    match vm.run() {
        VMResult::Ok(Value::Status(-221)) => {}
        other => panic!("status -221 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1680_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1680)));
    match vm.run() {
        VMResult::Ok(Value::Status(1680)) => {}
        other => panic!("exit code 1680 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..113 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1674 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1674 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 113 {
                Some(1681)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1674 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1681)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1681)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1681_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1681)));
    match vm.run() {
        VMResult::Ok(Value::Status(1681)) => {}
        other => panic!("exit code 1681 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1682)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..53 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 56);
    assert_eq!(vm.last_status, 1682);
}

#[test]
fn subshell_end_exit_code_1682_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1682)));
    match vm.run() {
        VMResult::Ok(Value::Status(1682)) => {}
        other => panic!("exit code 1682 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1683Ex1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1683)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1683);
}

#[test]
fn subshell_end_exit_code_1683_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1683)));
    match vm.run() {
        VMResult::Ok(Value::Status(1683)) => {}
        other => panic!("exit code 1683 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_two_begins_fifty_ends_last_end_status_winsEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..52 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..50 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1684Ex1674;
    impl ShellHost for CountingBeginEndHost1684Ex1674 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1684)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1684Ex1674));
    match vm.run() {
        VMResult::Ok(Value::Status(1684)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1684)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 52);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 50);
}

#[test]
fn subshell_end_exit_code_1684_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1684)));
    match vm.run() {
        VMResult::Ok(Value::Status(1684)) => {}
        other => panic!("exit code 1684 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1685Ex1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1674;
    impl ShellHost for CountingBeginHost733Ex1674 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1685)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1674));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1685);
}

#[test]
fn subshell_end_exit_code_1685_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1685)));
    match vm.run() {
        VMResult::Ok(Value::Status(1685)) => {}
        other => panic!("exit code 1685 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1674() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1686)));
    for _ in 0..53 {
        match vm.run() {
            VMResult::Ok(Value::Status(1686)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1686_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1686)));
    match vm.run() {
        VMResult::Ok(Value::Status(1686)) => {}
        other => panic!("exit code 1686 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1687Ex1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1687)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1687);
}

#[test]
fn subshell_end_exit_code_1687_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1687)));
    match vm.run() {
        VMResult::Ok(Value::Status(1687)) => {}
        other => panic!("exit code 1687 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1688_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1688)));
    match vm.run() {
        VMResult::Ok(Value::Status(1688)) => {}
        other => panic!("exit code 1688 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1689Ex1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1689)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1689);
}

#[test]
fn subshell_end_exit_code_1689_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1689)));
    match vm.run() {
        VMResult::Ok(Value::Status(1689)) => {}
        other => panic!("exit code 1689 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventeen_consecutive_runs_without_reset_still_blockedEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..317 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1690_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1690)));
    match vm.run() {
        VMResult::Ok(Value::Status(1690)) => {}
        other => panic!("exit code 1690 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighteen_consecutive_runs_without_reset_still_blockedEx1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..318 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1691_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1691)));
    match vm.run() {
        VMResult::Ok(Value::Status(1691)) => {}
        other => panic!("exit code 1691 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1692_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1692)));
    match vm.run() {
        VMResult::Ok(Value::Status(1692)) => {}
        other => panic!("exit code 1692 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1693;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1693)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1693, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1693_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1693)));
    match vm.run() {
        VMResult::Ok(Value::Status(1693)) => {}
        other => panic!("exit code 1693 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1694,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1694)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1694), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1694_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1694)));
    match vm.run() {
        VMResult::Ok(Value::Status(1694)) => {}
        other => panic!("exit code 1694 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-222)));
    match vm.run() {
        VMResult::Ok(Value::Status(-222)) => {}
        other => panic!("status -222 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1695_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1695)));
    match vm.run() {
        VMResult::Ok(Value::Status(1695)) => {}
        other => panic!("exit code 1695 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_end_incrementing_from_fiveEx1674() {
    let mut b = ChunkBuilder::new();
    for _ in 0..220 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 56 }));
    match vm.run() {
        VMResult::Ok(Value::Status(275)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(275)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1696_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1696)));
    match vm.run() {
        VMResult::Ok(Value::Status(1696)) => {}
        other => panic!("exit code 1696 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1697Ex1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1697Ex1674 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1697Ex1674 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1697Ex1674 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1697_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1697)));
    match vm.run() {
        VMResult::Ok(Value::Status(1697)) => {}
        other => panic!("exit code 1697 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1698Ex1674() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1698)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1698);
}

#[test]
fn subshell_end_exit_code_1698_propagatesEx1674() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1698)));
    match vm.run() {
        VMResult::Ok(Value::Status(1698)) => {}
        other => panic!("exit code 1698 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BJ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1699_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1699)));
    match vm.run() {
        VMResult::Ok(Value::Status(1699)) => {}
        other => panic!("exit code 1699 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_nineteen_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..319 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1700_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1700)));
    match vm.run() {
        VMResult::Ok(Value::Status(1700)) => {}
        other => panic!("exit code 1700 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..320 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1701_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1701)));
    match vm.run() {
        VMResult::Ok(Value::Status(1701)) => {}
        other => panic!("exit code 1701 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_one_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..321 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1702_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1702)));
    match vm.run() {
        VMResult::Ok(Value::Status(1702)) => {}
        other => panic!("exit code 1702 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_one_end_incrementing_from_sixEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..221 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 57 }));
    match vm.run() {
        VMResult::Ok(Value::Status(277)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(277)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1703_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1703)));
    match vm.run() {
        VMResult::Ok(Value::Status(1703)) => {}
        other => panic!("exit code 1703 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-223)));
    match vm.run() {
        VMResult::Ok(Value::Status(-223)) => {}
        other => panic!("status -223 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1704_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1704)));
    match vm.run() {
        VMResult::Ok(Value::Status(1704)) => {}
        other => panic!("exit code 1704 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-224)));
    match vm.run() {
        VMResult::Ok(Value::Status(-224)) => {}
        other => panic!("status -224 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1705_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1705)));
    match vm.run() {
        VMResult::Ok(Value::Status(1705)) => {}
        other => panic!("exit code 1705 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..114 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1699 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1699 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 114 {
                Some(1706)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1699 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1706)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1706)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1706_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1706)));
    match vm.run() {
        VMResult::Ok(Value::Status(1706)) => {}
        other => panic!("exit code 1706 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1707)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..54 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 57);
    assert_eq!(vm.last_status, 1707);
}

#[test]
fn subshell_end_exit_code_1707_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1707)));
    match vm.run() {
        VMResult::Ok(Value::Status(1707)) => {}
        other => panic!("exit code 1707 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1708Ex1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1708)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1708);
}

#[test]
fn subshell_end_exit_code_1708_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1708)));
    match vm.run() {
        VMResult::Ok(Value::Status(1708)) => {}
        other => panic!("exit code 1708 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_three_begins_fifty_one_ends_last_end_status_winsEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..53 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..51 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1709Ex1699;
    impl ShellHost for CountingBeginEndHost1709Ex1699 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1709)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1709Ex1699));
    match vm.run() {
        VMResult::Ok(Value::Status(1709)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1709)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 53);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 51);
}

#[test]
fn subshell_end_exit_code_1709_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1709)));
    match vm.run() {
        VMResult::Ok(Value::Status(1709)) => {}
        other => panic!("exit code 1709 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1710Ex1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1710)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1710);
}

#[test]
fn subshell_end_exit_code_1710_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1710)));
    match vm.run() {
        VMResult::Ok(Value::Status(1710)) => {}
        other => panic!("exit code 1710 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1699() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1711)));
    for _ in 0..54 {
        match vm.run() {
            VMResult::Ok(Value::Status(1711)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1711_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1711)));
    match vm.run() {
        VMResult::Ok(Value::Status(1711)) => {}
        other => panic!("exit code 1711 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1712Ex1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1712)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1712);
}

#[test]
fn subshell_end_exit_code_1712_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1712)));
    match vm.run() {
        VMResult::Ok(Value::Status(1712)) => {}
        other => panic!("exit code 1712 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_two_end_incrementing_from_sevenEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..222 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 58 }));
    match vm.run() {
        VMResult::Ok(Value::Status(279)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(279)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1713_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1713)));
    match vm.run() {
        VMResult::Ok(Value::Status(1713)) => {}
        other => panic!("exit code 1713 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1714Ex1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1714)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1714);
}

#[test]
fn subshell_end_exit_code_1714_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1714)));
    match vm.run() {
        VMResult::Ok(Value::Status(1714)) => {}
        other => panic!("exit code 1714 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_two_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..322 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1715_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1715)));
    match vm.run() {
        VMResult::Ok(Value::Status(1715)) => {}
        other => panic!("exit code 1715 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..115 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1699 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1699 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 115 {
                Some(1716)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1699 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1716)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1716)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1716_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1716)));
    match vm.run() {
        VMResult::Ok(Value::Status(1716)) => {}
        other => panic!("exit code 1716 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1717_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1717)));
    match vm.run() {
        VMResult::Ok(Value::Status(1717)) => {}
        other => panic!("exit code 1717 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1718Ex1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1718)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1718);
}

#[test]
fn subshell_end_exit_code_1718_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1718)));
    match vm.run() {
        VMResult::Ok(Value::Status(1718)) => {}
        other => panic!("exit code 1718 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_three_end_incrementing_from_oneEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..223 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 52 }));
    match vm.run() {
        VMResult::Ok(Value::Status(274)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(274)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1719_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1719)));
    match vm.run() {
        VMResult::Ok(Value::Status(1719)) => {}
        other => panic!("exit code 1719 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1720;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1720)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1720, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1720_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1720)));
    match vm.run() {
        VMResult::Ok(Value::Status(1720)) => {}
        other => panic!("exit code 1720 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1721,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1721)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1721), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1721_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1721)));
    match vm.run() {
        VMResult::Ok(Value::Status(1721)) => {}
        other => panic!("exit code 1721 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_three_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..323 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1722_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1722)));
    match vm.run() {
        VMResult::Ok(Value::Status(1722)) => {}
        other => panic!("exit code 1722 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..116 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1699 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1699 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 116 {
                Some(1723)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1699 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1723)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1723)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1723_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1723)));
    match vm.run() {
        VMResult::Ok(Value::Status(1723)) => {}
        other => panic!("exit code 1723 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1724Ex1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1724Ex1699;
    impl ShellHost for PipelineSubshellHost1724Ex1699 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1724)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1724Ex1699));
    match vm.run() {
        VMResult::Ok(Value::Status(1724)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1724_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1724)));
    match vm.run() {
        VMResult::Ok(Value::Status(1724)) => {}
        other => panic!("exit code 1724 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1725Ex1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1725Ex1699;
    impl ShellHost for SubshellThenPipelineHost1725Ex1699 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1725
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1725Ex1699));
    match vm.run() {
        VMResult::Ok(Value::Status(1725)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1725_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1725)));
    match vm.run() {
        VMResult::Ok(Value::Status(1725)) => {}
        other => panic!("exit code 1725 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-225)));
    match vm.run() {
        VMResult::Ok(Value::Status(-225)) => {}
        other => panic!("status -225 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1726_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1726)));
    match vm.run() {
        VMResult::Ok(Value::Status(1726)) => {}
        other => panic!("exit code 1726 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_four_end_incrementing_from_eightEx1699() {
    let mut b = ChunkBuilder::new();
    for _ in 0..224 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 59 }));
    match vm.run() {
        VMResult::Ok(Value::Status(282)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(282)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1727_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1727)));
    match vm.run() {
        VMResult::Ok(Value::Status(1727)) => {}
        other => panic!("exit code 1727 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_four_consecutive_runs_without_reset_still_blockedEx1699() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..324 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1728_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1728)));
    match vm.run() {
        VMResult::Ok(Value::Status(1728)) => {}
        other => panic!("exit code 1728 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1729Ex1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1729Ex1699 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1729Ex1699 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1729Ex1699 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1729_propagatesEx1699() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1729)));
    match vm.run() {
        VMResult::Ok(Value::Status(1729)) => {}
        other => panic!("exit code 1729 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BK (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1730_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1730)));
    match vm.run() {
        VMResult::Ok(Value::Status(1730)) => {}
        other => panic!("exit code 1730 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_five_consecutive_runs_without_reset_still_blockedEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..325 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1731_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1731)));
    match vm.run() {
        VMResult::Ok(Value::Status(1731)) => {}
        other => panic!("exit code 1731 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_six_consecutive_runs_without_reset_still_blockedEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..326 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1732_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1732)));
    match vm.run() {
        VMResult::Ok(Value::Status(1732)) => {}
        other => panic!("exit code 1732 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_seven_consecutive_runs_without_reset_still_blockedEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..327 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1733_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1733)));
    match vm.run() {
        VMResult::Ok(Value::Status(1733)) => {}
        other => panic!("exit code 1733 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1734_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1734)));
    match vm.run() {
        VMResult::Ok(Value::Status(1734)) => {}
        other => panic!("exit code 1734 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-227)));
    match vm.run() {
        VMResult::Ok(Value::Status(-227)) => {}
        other => panic!("status -227 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1735_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1735)));
    match vm.run() {
        VMResult::Ok(Value::Status(1735)) => {}
        other => panic!("exit code 1735 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-228)));
    match vm.run() {
        VMResult::Ok(Value::Status(-228)) => {}
        other => panic!("status -228 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1736_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1736)));
    match vm.run() {
        VMResult::Ok(Value::Status(1736)) => {}
        other => panic!("exit code 1736 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..117 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1730 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1730 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 117 {
                Some(1737)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1730 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1737)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1737)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1737_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1737)));
    match vm.run() {
        VMResult::Ok(Value::Status(1737)) => {}
        other => panic!("exit code 1737 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1738)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..55 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 58);
    assert_eq!(vm.last_status, 1738);
}

#[test]
fn subshell_end_exit_code_1738_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1738)));
    match vm.run() {
        VMResult::Ok(Value::Status(1738)) => {}
        other => panic!("exit code 1738 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1739Ex1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1739)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1739);
}

#[test]
fn subshell_end_exit_code_1739_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1739)));
    match vm.run() {
        VMResult::Ok(Value::Status(1739)) => {}
        other => panic!("exit code 1739 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_four_begins_fifty_two_ends_last_end_status_winsEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..54 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..52 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1740Ex1730;
    impl ShellHost for CountingBeginEndHost1740Ex1730 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1740)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1740Ex1730));
    match vm.run() {
        VMResult::Ok(Value::Status(1740)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1740)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 54);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 52);
}

#[test]
fn subshell_end_exit_code_1740_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1740)));
    match vm.run() {
        VMResult::Ok(Value::Status(1740)) => {}
        other => panic!("exit code 1740 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1741Ex1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1730;
    impl ShellHost for CountingBeginHost733Ex1730 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1741)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1730));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1741);
}

#[test]
fn subshell_end_exit_code_1741_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1741)));
    match vm.run() {
        VMResult::Ok(Value::Status(1741)) => {}
        other => panic!("exit code 1741 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1730() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1742)));
    for _ in 0..55 {
        match vm.run() {
            VMResult::Ok(Value::Status(1742)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1742_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1742)));
    match vm.run() {
        VMResult::Ok(Value::Status(1742)) => {}
        other => panic!("exit code 1742 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1743Ex1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1743)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1743);
}

#[test]
fn subshell_end_exit_code_1743_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1743)));
    match vm.run() {
        VMResult::Ok(Value::Status(1743)) => {}
        other => panic!("exit code 1743 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1744_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1744)));
    match vm.run() {
        VMResult::Ok(Value::Status(1744)) => {}
        other => panic!("exit code 1744 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1745Ex1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1745)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1745);
}

#[test]
fn subshell_end_exit_code_1745_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1745)));
    match vm.run() {
        VMResult::Ok(Value::Status(1745)) => {}
        other => panic!("exit code 1745 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_eight_consecutive_runs_without_reset_still_blockedEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..328 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1746_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1746)));
    match vm.run() {
        VMResult::Ok(Value::Status(1746)) => {}
        other => panic!("exit code 1746 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_twenty_nine_consecutive_runs_without_reset_still_blockedEx1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..329 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1747_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1747)));
    match vm.run() {
        VMResult::Ok(Value::Status(1747)) => {}
        other => panic!("exit code 1747 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1748_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1748)));
    match vm.run() {
        VMResult::Ok(Value::Status(1748)) => {}
        other => panic!("exit code 1748 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1749;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1749)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1749, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1749_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1749)));
    match vm.run() {
        VMResult::Ok(Value::Status(1749)) => {}
        other => panic!("exit code 1749 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1750,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1750)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1750), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1750_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1750)));
    match vm.run() {
        VMResult::Ok(Value::Status(1750)) => {}
        other => panic!("exit code 1750 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-229)));
    match vm.run() {
        VMResult::Ok(Value::Status(-229)) => {}
        other => panic!("status -229 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1751_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1751)));
    match vm.run() {
        VMResult::Ok(Value::Status(1751)) => {}
        other => panic!("exit code 1751 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_seven_end_incrementing_from_fiveEx1730() {
    let mut b = ChunkBuilder::new();
    for _ in 0..227 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 59 }));
    match vm.run() {
        VMResult::Ok(Value::Status(285)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(285)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1752_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1752)));
    match vm.run() {
        VMResult::Ok(Value::Status(1752)) => {}
        other => panic!("exit code 1752 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1753Ex1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1753Ex1730 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1753Ex1730 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1753Ex1730 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1753_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1753)));
    match vm.run() {
        VMResult::Ok(Value::Status(1753)) => {}
        other => panic!("exit code 1753 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1754Ex1730() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1754)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1754);
}

#[test]
fn subshell_end_exit_code_1754_propagatesEx1730() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1754)));
    match vm.run() {
        VMResult::Ok(Value::Status(1754)) => {}
        other => panic!("exit code 1754 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BL (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1755_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1755)));
    match vm.run() {
        VMResult::Ok(Value::Status(1755)) => {}
        other => panic!("exit code 1755 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..330 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1756_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1756)));
    match vm.run() {
        VMResult::Ok(Value::Status(1756)) => {}
        other => panic!("exit code 1756 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_one_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..331 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1757_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1757)));
    match vm.run() {
        VMResult::Ok(Value::Status(1757)) => {}
        other => panic!("exit code 1757 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_two_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..332 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1758_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1758)));
    match vm.run() {
        VMResult::Ok(Value::Status(1758)) => {}
        other => panic!("exit code 1758 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_eight_end_incrementing_from_sixEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..228 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 60 }));
    match vm.run() {
        VMResult::Ok(Value::Status(287)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(287)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1759_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1759)));
    match vm.run() {
        VMResult::Ok(Value::Status(1759)) => {}
        other => panic!("exit code 1759 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-230)));
    match vm.run() {
        VMResult::Ok(Value::Status(-230)) => {}
        other => panic!("status -230 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1760_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1760)));
    match vm.run() {
        VMResult::Ok(Value::Status(1760)) => {}
        other => panic!("exit code 1760 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-231)));
    match vm.run() {
        VMResult::Ok(Value::Status(-231)) => {}
        other => panic!("status -231 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1761_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1761)));
    match vm.run() {
        VMResult::Ok(Value::Status(1761)) => {}
        other => panic!("exit code 1761 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..118 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1755 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1755 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 118 {
                Some(1762)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1755 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1762)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1762)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1762_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1762)));
    match vm.run() {
        VMResult::Ok(Value::Status(1762)) => {}
        other => panic!("exit code 1762 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1763)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..56 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 59);
    assert_eq!(vm.last_status, 1763);
}

#[test]
fn subshell_end_exit_code_1763_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1763)));
    match vm.run() {
        VMResult::Ok(Value::Status(1763)) => {}
        other => panic!("exit code 1763 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1764Ex1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1764)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1764);
}

#[test]
fn subshell_end_exit_code_1764_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1764)));
    match vm.run() {
        VMResult::Ok(Value::Status(1764)) => {}
        other => panic!("exit code 1764 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_five_begins_fifty_three_ends_last_end_status_winsEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..55 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..53 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1765Ex1755;
    impl ShellHost for CountingBeginEndHost1765Ex1755 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1765)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1765Ex1755));
    match vm.run() {
        VMResult::Ok(Value::Status(1765)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1765)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 55);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 53);
}

#[test]
fn subshell_end_exit_code_1765_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1765)));
    match vm.run() {
        VMResult::Ok(Value::Status(1765)) => {}
        other => panic!("exit code 1765 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1766Ex1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1766)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1766);
}

#[test]
fn subshell_end_exit_code_1766_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1766)));
    match vm.run() {
        VMResult::Ok(Value::Status(1766)) => {}
        other => panic!("exit code 1766 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1755() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1767)));
    for _ in 0..56 {
        match vm.run() {
            VMResult::Ok(Value::Status(1767)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1767_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1767)));
    match vm.run() {
        VMResult::Ok(Value::Status(1767)) => {}
        other => panic!("exit code 1767 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1768Ex1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1768)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1768);
}

#[test]
fn subshell_end_exit_code_1768_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1768)));
    match vm.run() {
        VMResult::Ok(Value::Status(1768)) => {}
        other => panic!("exit code 1768 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_twenty_nine_end_incrementing_from_sevenEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..229 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 61 }));
    match vm.run() {
        VMResult::Ok(Value::Status(289)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(289)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1769_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1769)));
    match vm.run() {
        VMResult::Ok(Value::Status(1769)) => {}
        other => panic!("exit code 1769 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1770Ex1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1770)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1770);
}

#[test]
fn subshell_end_exit_code_1770_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1770)));
    match vm.run() {
        VMResult::Ok(Value::Status(1770)) => {}
        other => panic!("exit code 1770 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_three_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..333 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1771_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1771)));
    match vm.run() {
        VMResult::Ok(Value::Status(1771)) => {}
        other => panic!("exit code 1771 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..119 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1755 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1755 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 119 {
                Some(1772)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1755 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1772)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1772)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1772_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1772)));
    match vm.run() {
        VMResult::Ok(Value::Status(1772)) => {}
        other => panic!("exit code 1772 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1773_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1773)));
    match vm.run() {
        VMResult::Ok(Value::Status(1773)) => {}
        other => panic!("exit code 1773 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1774Ex1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1774)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1774);
}

#[test]
fn subshell_end_exit_code_1774_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1774)));
    match vm.run() {
        VMResult::Ok(Value::Status(1774)) => {}
        other => panic!("exit code 1774 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_end_incrementing_from_oneEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..230 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 55 }));
    match vm.run() {
        VMResult::Ok(Value::Status(284)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(284)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1775_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1775)));
    match vm.run() {
        VMResult::Ok(Value::Status(1775)) => {}
        other => panic!("exit code 1775 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1776;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1776)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1776, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1776_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1776)));
    match vm.run() {
        VMResult::Ok(Value::Status(1776)) => {}
        other => panic!("exit code 1776 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1777,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1777)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1777), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1777_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1777)));
    match vm.run() {
        VMResult::Ok(Value::Status(1777)) => {}
        other => panic!("exit code 1777 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_four_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..334 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1778_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1778)));
    match vm.run() {
        VMResult::Ok(Value::Status(1778)) => {}
        other => panic!("exit code 1778 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..120 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1755 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1755 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 120 {
                Some(1779)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1755 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1779)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1779)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1779_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1779)));
    match vm.run() {
        VMResult::Ok(Value::Status(1779)) => {}
        other => panic!("exit code 1779 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1780Ex1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1780Ex1755;
    impl ShellHost for PipelineSubshellHost1780Ex1755 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1780)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1780Ex1755));
    match vm.run() {
        VMResult::Ok(Value::Status(1780)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1780_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1780)));
    match vm.run() {
        VMResult::Ok(Value::Status(1780)) => {}
        other => panic!("exit code 1780 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1781Ex1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1781Ex1755;
    impl ShellHost for SubshellThenPipelineHost1781Ex1755 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1781
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1781Ex1755));
    match vm.run() {
        VMResult::Ok(Value::Status(1781)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1781_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1781)));
    match vm.run() {
        VMResult::Ok(Value::Status(1781)) => {}
        other => panic!("exit code 1781 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-232)));
    match vm.run() {
        VMResult::Ok(Value::Status(-232)) => {}
        other => panic!("status -232 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1782_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1782)));
    match vm.run() {
        VMResult::Ok(Value::Status(1782)) => {}
        other => panic!("exit code 1782 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_one_end_incrementing_from_eightEx1755() {
    let mut b = ChunkBuilder::new();
    for _ in 0..231 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 62 }));
    match vm.run() {
        VMResult::Ok(Value::Status(292)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(292)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1783_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1783)));
    match vm.run() {
        VMResult::Ok(Value::Status(1783)) => {}
        other => panic!("exit code 1783 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_five_consecutive_runs_without_reset_still_blockedEx1755() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..335 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1784_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1784)));
    match vm.run() {
        VMResult::Ok(Value::Status(1784)) => {}
        other => panic!("exit code 1784 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1785Ex1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1785Ex1755 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1785Ex1755 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1785Ex1755 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1785_propagatesEx1755() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1785)));
    match vm.run() {
        VMResult::Ok(Value::Status(1785)) => {}
        other => panic!("exit code 1785 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BM (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1786_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1786)));
    match vm.run() {
        VMResult::Ok(Value::Status(1786)) => {}
        other => panic!("exit code 1786 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_six_consecutive_runs_without_reset_still_blockedEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..336 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1787_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1787)));
    match vm.run() {
        VMResult::Ok(Value::Status(1787)) => {}
        other => panic!("exit code 1787 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_seven_consecutive_runs_without_reset_still_blockedEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..337 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1788_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1788)));
    match vm.run() {
        VMResult::Ok(Value::Status(1788)) => {}
        other => panic!("exit code 1788 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_eight_consecutive_runs_without_reset_still_blockedEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..338 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1789_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1789)));
    match vm.run() {
        VMResult::Ok(Value::Status(1789)) => {}
        other => panic!("exit code 1789 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1790_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1790)));
    match vm.run() {
        VMResult::Ok(Value::Status(1790)) => {}
        other => panic!("exit code 1790 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-234)));
    match vm.run() {
        VMResult::Ok(Value::Status(-234)) => {}
        other => panic!("status -234 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1791_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1791)));
    match vm.run() {
        VMResult::Ok(Value::Status(1791)) => {}
        other => panic!("exit code 1791 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-235)));
    match vm.run() {
        VMResult::Ok(Value::Status(-235)) => {}
        other => panic!("status -235 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1792_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1792)));
    match vm.run() {
        VMResult::Ok(Value::Status(1792)) => {}
        other => panic!("exit code 1792 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..121 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1786 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1786 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 121 {
                Some(1793)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1786 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1793)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1793)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1793_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1793)));
    match vm.run() {
        VMResult::Ok(Value::Status(1793)) => {}
        other => panic!("exit code 1793 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1794)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..57 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 60);
    assert_eq!(vm.last_status, 1794);
}

#[test]
fn subshell_end_exit_code_1794_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1794)));
    match vm.run() {
        VMResult::Ok(Value::Status(1794)) => {}
        other => panic!("exit code 1794 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1795Ex1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1795)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1795);
}

#[test]
fn subshell_end_exit_code_1795_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1795)));
    match vm.run() {
        VMResult::Ok(Value::Status(1795)) => {}
        other => panic!("exit code 1795 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_six_begins_fifty_four_ends_last_end_status_winsEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..56 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..54 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1796Ex1786;
    impl ShellHost for CountingBeginEndHost1796Ex1786 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1796)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1796Ex1786));
    match vm.run() {
        VMResult::Ok(Value::Status(1796)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1796)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 56);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 54);
}

#[test]
fn subshell_end_exit_code_1796_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1796)));
    match vm.run() {
        VMResult::Ok(Value::Status(1796)) => {}
        other => panic!("exit code 1796 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1797Ex1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1786;
    impl ShellHost for CountingBeginHost733Ex1786 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1797)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1786));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1797);
}

#[test]
fn subshell_end_exit_code_1797_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1797)));
    match vm.run() {
        VMResult::Ok(Value::Status(1797)) => {}
        other => panic!("exit code 1797 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1786() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1798)));
    for _ in 0..57 {
        match vm.run() {
            VMResult::Ok(Value::Status(1798)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1798_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1798)));
    match vm.run() {
        VMResult::Ok(Value::Status(1798)) => {}
        other => panic!("exit code 1798 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1799Ex1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1799)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1799);
}

#[test]
fn subshell_end_exit_code_1799_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1799)));
    match vm.run() {
        VMResult::Ok(Value::Status(1799)) => {}
        other => panic!("exit code 1799 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1800_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1800)));
    match vm.run() {
        VMResult::Ok(Value::Status(1800)) => {}
        other => panic!("exit code 1800 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1801Ex1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1801)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1801);
}

#[test]
fn subshell_end_exit_code_1801_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1801)));
    match vm.run() {
        VMResult::Ok(Value::Status(1801)) => {}
        other => panic!("exit code 1801 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_thirty_nine_consecutive_runs_without_reset_still_blockedEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..339 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1802_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1802)));
    match vm.run() {
        VMResult::Ok(Value::Status(1802)) => {}
        other => panic!("exit code 1802 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_consecutive_runs_without_reset_still_blockedEx1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..340 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1803_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1803)));
    match vm.run() {
        VMResult::Ok(Value::Status(1803)) => {}
        other => panic!("exit code 1803 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1804_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1804)));
    match vm.run() {
        VMResult::Ok(Value::Status(1804)) => {}
        other => panic!("exit code 1804 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1805;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1805)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1805, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1805_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1805)));
    match vm.run() {
        VMResult::Ok(Value::Status(1805)) => {}
        other => panic!("exit code 1805 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1806,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1806)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1806), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1806_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1806)));
    match vm.run() {
        VMResult::Ok(Value::Status(1806)) => {}
        other => panic!("exit code 1806 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-236)));
    match vm.run() {
        VMResult::Ok(Value::Status(-236)) => {}
        other => panic!("status -236 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1807_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1807)));
    match vm.run() {
        VMResult::Ok(Value::Status(1807)) => {}
        other => panic!("exit code 1807 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_four_end_incrementing_from_fiveEx1786() {
    let mut b = ChunkBuilder::new();
    for _ in 0..234 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 62 }));
    match vm.run() {
        VMResult::Ok(Value::Status(295)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(295)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1808_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1808)));
    match vm.run() {
        VMResult::Ok(Value::Status(1808)) => {}
        other => panic!("exit code 1808 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1809Ex1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1809Ex1786 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1809Ex1786 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1809Ex1786 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1809_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1809)));
    match vm.run() {
        VMResult::Ok(Value::Status(1809)) => {}
        other => panic!("exit code 1809 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1810Ex1786() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1810)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1810);
}

#[test]
fn subshell_end_exit_code_1810_propagatesEx1786() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1810)));
    match vm.run() {
        VMResult::Ok(Value::Status(1810)) => {}
        other => panic!("exit code 1810 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BN (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1811_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1811)));
    match vm.run() {
        VMResult::Ok(Value::Status(1811)) => {}
        other => panic!("exit code 1811 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_one_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..341 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1812_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1812)));
    match vm.run() {
        VMResult::Ok(Value::Status(1812)) => {}
        other => panic!("exit code 1812 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_two_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..342 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1813_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1813)));
    match vm.run() {
        VMResult::Ok(Value::Status(1813)) => {}
        other => panic!("exit code 1813 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_three_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..343 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1814_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1814)));
    match vm.run() {
        VMResult::Ok(Value::Status(1814)) => {}
        other => panic!("exit code 1814 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_five_end_incrementing_from_sixEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..235 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 63 }));
    match vm.run() {
        VMResult::Ok(Value::Status(297)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(297)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1815_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1815)));
    match vm.run() {
        VMResult::Ok(Value::Status(1815)) => {}
        other => panic!("exit code 1815 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-237)));
    match vm.run() {
        VMResult::Ok(Value::Status(-237)) => {}
        other => panic!("status -237 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1816_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1816)));
    match vm.run() {
        VMResult::Ok(Value::Status(1816)) => {}
        other => panic!("exit code 1816 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-238)));
    match vm.run() {
        VMResult::Ok(Value::Status(-238)) => {}
        other => panic!("status -238 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1817_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1817)));
    match vm.run() {
        VMResult::Ok(Value::Status(1817)) => {}
        other => panic!("exit code 1817 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..122 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1811 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1811 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 122 {
                Some(1818)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1811 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1818)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1818)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1818_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1818)));
    match vm.run() {
        VMResult::Ok(Value::Status(1818)) => {}
        other => panic!("exit code 1818 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1819)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..58 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 61);
    assert_eq!(vm.last_status, 1819);
}

#[test]
fn subshell_end_exit_code_1819_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1819)));
    match vm.run() {
        VMResult::Ok(Value::Status(1819)) => {}
        other => panic!("exit code 1819 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1820Ex1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1820)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1820);
}

#[test]
fn subshell_end_exit_code_1820_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1820)));
    match vm.run() {
        VMResult::Ok(Value::Status(1820)) => {}
        other => panic!("exit code 1820 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_seven_begins_fifty_five_ends_last_end_status_winsEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..57 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..55 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1821Ex1811;
    impl ShellHost for CountingBeginEndHost1821Ex1811 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1821)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1821Ex1811));
    match vm.run() {
        VMResult::Ok(Value::Status(1821)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1821)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 57);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 55);
}

#[test]
fn subshell_end_exit_code_1821_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1821)));
    match vm.run() {
        VMResult::Ok(Value::Status(1821)) => {}
        other => panic!("exit code 1821 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1822Ex1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1822)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1822);
}

#[test]
fn subshell_end_exit_code_1822_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1822)));
    match vm.run() {
        VMResult::Ok(Value::Status(1822)) => {}
        other => panic!("exit code 1822 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1811() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1823)));
    for _ in 0..58 {
        match vm.run() {
            VMResult::Ok(Value::Status(1823)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1823_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1823)));
    match vm.run() {
        VMResult::Ok(Value::Status(1823)) => {}
        other => panic!("exit code 1823 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1824Ex1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1824)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1824);
}

#[test]
fn subshell_end_exit_code_1824_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1824)));
    match vm.run() {
        VMResult::Ok(Value::Status(1824)) => {}
        other => panic!("exit code 1824 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_six_end_incrementing_from_sevenEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..236 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 64 }));
    match vm.run() {
        VMResult::Ok(Value::Status(299)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(299)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1825_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1825)));
    match vm.run() {
        VMResult::Ok(Value::Status(1825)) => {}
        other => panic!("exit code 1825 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1826Ex1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1826)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1826);
}

#[test]
fn subshell_end_exit_code_1826_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1826)));
    match vm.run() {
        VMResult::Ok(Value::Status(1826)) => {}
        other => panic!("exit code 1826 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_four_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..344 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1827_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1827)));
    match vm.run() {
        VMResult::Ok(Value::Status(1827)) => {}
        other => panic!("exit code 1827 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..123 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1811 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1811 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 123 {
                Some(1828)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1811 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1828)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1828)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1828_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1828)));
    match vm.run() {
        VMResult::Ok(Value::Status(1828)) => {}
        other => panic!("exit code 1828 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1829_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1829)));
    match vm.run() {
        VMResult::Ok(Value::Status(1829)) => {}
        other => panic!("exit code 1829 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1830Ex1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1830)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1830);
}

#[test]
fn subshell_end_exit_code_1830_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1830)));
    match vm.run() {
        VMResult::Ok(Value::Status(1830)) => {}
        other => panic!("exit code 1830 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_seven_end_incrementing_from_oneEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..237 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 58 }));
    match vm.run() {
        VMResult::Ok(Value::Status(294)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(294)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1831_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1831)));
    match vm.run() {
        VMResult::Ok(Value::Status(1831)) => {}
        other => panic!("exit code 1831 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1832;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1832)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1832, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1832_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1832)));
    match vm.run() {
        VMResult::Ok(Value::Status(1832)) => {}
        other => panic!("exit code 1832 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1833,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1833)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1833), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1833_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1833)));
    match vm.run() {
        VMResult::Ok(Value::Status(1833)) => {}
        other => panic!("exit code 1833 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_five_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..345 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1834_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1834)));
    match vm.run() {
        VMResult::Ok(Value::Status(1834)) => {}
        other => panic!("exit code 1834 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..124 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1811 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1811 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 124 {
                Some(1835)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1811 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1835)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1835)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1835_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1835)));
    match vm.run() {
        VMResult::Ok(Value::Status(1835)) => {}
        other => panic!("exit code 1835 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1836Ex1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1836Ex1811;
    impl ShellHost for PipelineSubshellHost1836Ex1811 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1836)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1836Ex1811));
    match vm.run() {
        VMResult::Ok(Value::Status(1836)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1836_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1836)));
    match vm.run() {
        VMResult::Ok(Value::Status(1836)) => {}
        other => panic!("exit code 1836 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1837Ex1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1837Ex1811;
    impl ShellHost for SubshellThenPipelineHost1837Ex1811 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1837
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1837Ex1811));
    match vm.run() {
        VMResult::Ok(Value::Status(1837)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1837_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1837)));
    match vm.run() {
        VMResult::Ok(Value::Status(1837)) => {}
        other => panic!("exit code 1837 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-239)));
    match vm.run() {
        VMResult::Ok(Value::Status(-239)) => {}
        other => panic!("status -239 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1838_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1838)));
    match vm.run() {
        VMResult::Ok(Value::Status(1838)) => {}
        other => panic!("exit code 1838 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_thirty_eight_end_incrementing_from_eightEx1811() {
    let mut b = ChunkBuilder::new();
    for _ in 0..238 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 65 }));
    match vm.run() {
        VMResult::Ok(Value::Status(302)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(302)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1839_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1839)));
    match vm.run() {
        VMResult::Ok(Value::Status(1839)) => {}
        other => panic!("exit code 1839 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_six_consecutive_runs_without_reset_still_blockedEx1811() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..346 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1840_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1840)));
    match vm.run() {
        VMResult::Ok(Value::Status(1840)) => {}
        other => panic!("exit code 1840 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1841Ex1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1841Ex1811 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1841Ex1811 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1841Ex1811 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1841_propagatesEx1811() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1841)));
    match vm.run() {
        VMResult::Ok(Value::Status(1841)) => {}
        other => panic!("exit code 1841 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BO (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1842_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1842)));
    match vm.run() {
        VMResult::Ok(Value::Status(1842)) => {}
        other => panic!("exit code 1842 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_seven_consecutive_runs_without_reset_still_blockedEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..347 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1843_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1843)));
    match vm.run() {
        VMResult::Ok(Value::Status(1843)) => {}
        other => panic!("exit code 1843 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_eight_consecutive_runs_without_reset_still_blockedEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..348 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1844_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1844)));
    match vm.run() {
        VMResult::Ok(Value::Status(1844)) => {}
        other => panic!("exit code 1844 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_forty_nine_consecutive_runs_without_reset_still_blockedEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..349 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1845_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1845)));
    match vm.run() {
        VMResult::Ok(Value::Status(1845)) => {}
        other => panic!("exit code 1845 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1846_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1846)));
    match vm.run() {
        VMResult::Ok(Value::Status(1846)) => {}
        other => panic!("exit code 1846 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-241)));
    match vm.run() {
        VMResult::Ok(Value::Status(-241)) => {}
        other => panic!("status -241 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1847_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1847)));
    match vm.run() {
        VMResult::Ok(Value::Status(1847)) => {}
        other => panic!("exit code 1847 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-242)));
    match vm.run() {
        VMResult::Ok(Value::Status(-242)) => {}
        other => panic!("status -242 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1848_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1848)));
    match vm.run() {
        VMResult::Ok(Value::Status(1848)) => {}
        other => panic!("exit code 1848 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..125 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1842 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1842 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 125 {
                Some(1849)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1842 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1849)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1849)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1849_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1849)));
    match vm.run() {
        VMResult::Ok(Value::Status(1849)) => {}
        other => panic!("exit code 1849 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1850)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..59 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 62);
    assert_eq!(vm.last_status, 1850);
}

#[test]
fn subshell_end_exit_code_1850_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1850)));
    match vm.run() {
        VMResult::Ok(Value::Status(1850)) => {}
        other => panic!("exit code 1850 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1851Ex1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1851)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1851);
}

#[test]
fn subshell_end_exit_code_1851_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1851)));
    match vm.run() {
        VMResult::Ok(Value::Status(1851)) => {}
        other => panic!("exit code 1851 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_eight_begins_fifty_six_ends_last_end_status_winsEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..58 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..56 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1852Ex1842;
    impl ShellHost for CountingBeginEndHost1852Ex1842 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1852)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1852Ex1842));
    match vm.run() {
        VMResult::Ok(Value::Status(1852)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1852)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 58);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 56);
}

#[test]
fn subshell_end_exit_code_1852_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1852)));
    match vm.run() {
        VMResult::Ok(Value::Status(1852)) => {}
        other => panic!("exit code 1852 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1853Ex1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1842;
    impl ShellHost for CountingBeginHost733Ex1842 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1853)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1842));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1853);
}

#[test]
fn subshell_end_exit_code_1853_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1853)));
    match vm.run() {
        VMResult::Ok(Value::Status(1853)) => {}
        other => panic!("exit code 1853 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1842() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1854)));
    for _ in 0..59 {
        match vm.run() {
            VMResult::Ok(Value::Status(1854)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1854_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1854)));
    match vm.run() {
        VMResult::Ok(Value::Status(1854)) => {}
        other => panic!("exit code 1854 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1855Ex1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1855)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1855);
}

#[test]
fn subshell_end_exit_code_1855_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1855)));
    match vm.run() {
        VMResult::Ok(Value::Status(1855)) => {}
        other => panic!("exit code 1855 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1856_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1856)));
    match vm.run() {
        VMResult::Ok(Value::Status(1856)) => {}
        other => panic!("exit code 1856 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1857Ex1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1857)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1857);
}

#[test]
fn subshell_end_exit_code_1857_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1857)));
    match vm.run() {
        VMResult::Ok(Value::Status(1857)) => {}
        other => panic!("exit code 1857 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_consecutive_runs_without_reset_still_blockedEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..350 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1858_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1858)));
    match vm.run() {
        VMResult::Ok(Value::Status(1858)) => {}
        other => panic!("exit code 1858 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_one_consecutive_runs_without_reset_still_blockedEx1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..351 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1859_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1859)));
    match vm.run() {
        VMResult::Ok(Value::Status(1859)) => {}
        other => panic!("exit code 1859 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1860_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1860)));
    match vm.run() {
        VMResult::Ok(Value::Status(1860)) => {}
        other => panic!("exit code 1860 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1861;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1861)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1861, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1861_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1861)));
    match vm.run() {
        VMResult::Ok(Value::Status(1861)) => {}
        other => panic!("exit code 1861 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1862,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1862)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1862), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1862_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1862)));
    match vm.run() {
        VMResult::Ok(Value::Status(1862)) => {}
        other => panic!("exit code 1862 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-243)));
    match vm.run() {
        VMResult::Ok(Value::Status(-243)) => {}
        other => panic!("status -243 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1863_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1863)));
    match vm.run() {
        VMResult::Ok(Value::Status(1863)) => {}
        other => panic!("exit code 1863 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_one_end_incrementing_from_fiveEx1842() {
    let mut b = ChunkBuilder::new();
    for _ in 0..241 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 65 }));
    match vm.run() {
        VMResult::Ok(Value::Status(305)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(305)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1864_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1864)));
    match vm.run() {
        VMResult::Ok(Value::Status(1864)) => {}
        other => panic!("exit code 1864 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1865Ex1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1865Ex1842 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1865Ex1842 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1865Ex1842 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1865_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1865)));
    match vm.run() {
        VMResult::Ok(Value::Status(1865)) => {}
        other => panic!("exit code 1865 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1866Ex1842() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1866)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1866);
}

#[test]
fn subshell_end_exit_code_1866_propagatesEx1842() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1866)));
    match vm.run() {
        VMResult::Ok(Value::Status(1866)) => {}
        other => panic!("exit code 1866 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BP (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1867_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1867)));
    match vm.run() {
        VMResult::Ok(Value::Status(1867)) => {}
        other => panic!("exit code 1867 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_two_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..352 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1868_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1868)));
    match vm.run() {
        VMResult::Ok(Value::Status(1868)) => {}
        other => panic!("exit code 1868 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_three_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..353 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1869_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1869)));
    match vm.run() {
        VMResult::Ok(Value::Status(1869)) => {}
        other => panic!("exit code 1869 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_four_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..354 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1870_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1870)));
    match vm.run() {
        VMResult::Ok(Value::Status(1870)) => {}
        other => panic!("exit code 1870 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_two_end_incrementing_from_sixEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..242 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 66 }));
    match vm.run() {
        VMResult::Ok(Value::Status(307)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(307)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1871_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1871)));
    match vm.run() {
        VMResult::Ok(Value::Status(1871)) => {}
        other => panic!("exit code 1871 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-244)));
    match vm.run() {
        VMResult::Ok(Value::Status(-244)) => {}
        other => panic!("status -244 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1872_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1872)));
    match vm.run() {
        VMResult::Ok(Value::Status(1872)) => {}
        other => panic!("exit code 1872 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-245)));
    match vm.run() {
        VMResult::Ok(Value::Status(-245)) => {}
        other => panic!("status -245 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1873_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1873)));
    match vm.run() {
        VMResult::Ok(Value::Status(1873)) => {}
        other => panic!("exit code 1873 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..126 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1867 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1867 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 126 {
                Some(1874)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1867 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1874)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1874)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1874_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1874)));
    match vm.run() {
        VMResult::Ok(Value::Status(1874)) => {}
        other => panic!("exit code 1874 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1875)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..60 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 63);
    assert_eq!(vm.last_status, 1875);
}

#[test]
fn subshell_end_exit_code_1875_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1875)));
    match vm.run() {
        VMResult::Ok(Value::Status(1875)) => {}
        other => panic!("exit code 1875 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1876Ex1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1876)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1876);
}

#[test]
fn subshell_end_exit_code_1876_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1876)));
    match vm.run() {
        VMResult::Ok(Value::Status(1876)) => {}
        other => panic!("exit code 1876 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_fifty_nine_begins_fifty_seven_ends_last_end_status_winsEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..59 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..57 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1877Ex1867;
    impl ShellHost for CountingBeginEndHost1877Ex1867 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1877)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1877Ex1867));
    match vm.run() {
        VMResult::Ok(Value::Status(1877)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1877)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 59);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 57);
}

#[test]
fn subshell_end_exit_code_1877_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1877)));
    match vm.run() {
        VMResult::Ok(Value::Status(1877)) => {}
        other => panic!("exit code 1877 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1878Ex1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1878)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1878);
}

#[test]
fn subshell_end_exit_code_1878_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1878)));
    match vm.run() {
        VMResult::Ok(Value::Status(1878)) => {}
        other => panic!("exit code 1878 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1867() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1879)));
    for _ in 0..60 {
        match vm.run() {
            VMResult::Ok(Value::Status(1879)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1879_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1879)));
    match vm.run() {
        VMResult::Ok(Value::Status(1879)) => {}
        other => panic!("exit code 1879 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1880Ex1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1880)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1880);
}

#[test]
fn subshell_end_exit_code_1880_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1880)));
    match vm.run() {
        VMResult::Ok(Value::Status(1880)) => {}
        other => panic!("exit code 1880 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_three_end_incrementing_from_sevenEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..243 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 67 }));
    match vm.run() {
        VMResult::Ok(Value::Status(309)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(309)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1881_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1881)));
    match vm.run() {
        VMResult::Ok(Value::Status(1881)) => {}
        other => panic!("exit code 1881 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1882Ex1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1882)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1882);
}

#[test]
fn subshell_end_exit_code_1882_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1882)));
    match vm.run() {
        VMResult::Ok(Value::Status(1882)) => {}
        other => panic!("exit code 1882 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_five_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..355 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1883_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1883)));
    match vm.run() {
        VMResult::Ok(Value::Status(1883)) => {}
        other => panic!("exit code 1883 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..127 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1867 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1867 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 127 {
                Some(1884)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1867 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1884)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1884)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1884_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1884)));
    match vm.run() {
        VMResult::Ok(Value::Status(1884)) => {}
        other => panic!("exit code 1884 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1885_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1885)));
    match vm.run() {
        VMResult::Ok(Value::Status(1885)) => {}
        other => panic!("exit code 1885 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1886Ex1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1886)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1886);
}

#[test]
fn subshell_end_exit_code_1886_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1886)));
    match vm.run() {
        VMResult::Ok(Value::Status(1886)) => {}
        other => panic!("exit code 1886 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_four_end_incrementing_from_oneEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..244 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 61 }));
    match vm.run() {
        VMResult::Ok(Value::Status(304)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(304)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1887_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1887)));
    match vm.run() {
        VMResult::Ok(Value::Status(1887)) => {}
        other => panic!("exit code 1887 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1888;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1888)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1888, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1888_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1888)));
    match vm.run() {
        VMResult::Ok(Value::Status(1888)) => {}
        other => panic!("exit code 1888 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1889,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1889)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1889), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1889_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1889)));
    match vm.run() {
        VMResult::Ok(Value::Status(1889)) => {}
        other => panic!("exit code 1889 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_six_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..356 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1890_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1890)));
    match vm.run() {
        VMResult::Ok(Value::Status(1890)) => {}
        other => panic!("exit code 1890 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..128 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1867 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1867 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 128 {
                Some(1891)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1867 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1891)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1891)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1891_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1891)));
    match vm.run() {
        VMResult::Ok(Value::Status(1891)) => {}
        other => panic!("exit code 1891 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1892Ex1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1892Ex1867;
    impl ShellHost for PipelineSubshellHost1892Ex1867 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1892)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1892Ex1867));
    match vm.run() {
        VMResult::Ok(Value::Status(1892)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1892_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1892)));
    match vm.run() {
        VMResult::Ok(Value::Status(1892)) => {}
        other => panic!("exit code 1892 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1893Ex1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1893Ex1867;
    impl ShellHost for SubshellThenPipelineHost1893Ex1867 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1893
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1893Ex1867));
    match vm.run() {
        VMResult::Ok(Value::Status(1893)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1893_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1893)));
    match vm.run() {
        VMResult::Ok(Value::Status(1893)) => {}
        other => panic!("exit code 1893 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-246)));
    match vm.run() {
        VMResult::Ok(Value::Status(-246)) => {}
        other => panic!("status -246 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1894_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1894)));
    match vm.run() {
        VMResult::Ok(Value::Status(1894)) => {}
        other => panic!("exit code 1894 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_five_end_incrementing_from_eightEx1867() {
    let mut b = ChunkBuilder::new();
    for _ in 0..245 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 68 }));
    match vm.run() {
        VMResult::Ok(Value::Status(312)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(312)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1895_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1895)));
    match vm.run() {
        VMResult::Ok(Value::Status(1895)) => {}
        other => panic!("exit code 1895 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_seven_consecutive_runs_without_reset_still_blockedEx1867() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..357 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1896_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1896)));
    match vm.run() {
        VMResult::Ok(Value::Status(1896)) => {}
        other => panic!("exit code 1896 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1897Ex1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1897Ex1867 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1897Ex1867 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1897Ex1867 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1897_propagatesEx1867() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1897)));
    match vm.run() {
        VMResult::Ok(Value::Status(1897)) => {}
        other => panic!("exit code 1897 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BQ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1898_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1898)));
    match vm.run() {
        VMResult::Ok(Value::Status(1898)) => {}
        other => panic!("exit code 1898 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_eight_consecutive_runs_without_reset_still_blockedEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..358 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1899_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1899)));
    match vm.run() {
        VMResult::Ok(Value::Status(1899)) => {}
        other => panic!("exit code 1899 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_fifty_nine_consecutive_runs_without_reset_still_blockedEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..359 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1900_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1900)));
    match vm.run() {
        VMResult::Ok(Value::Status(1900)) => {}
        other => panic!("exit code 1900 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_consecutive_runs_without_reset_still_blockedEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..360 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1901_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1901)));
    match vm.run() {
        VMResult::Ok(Value::Status(1901)) => {}
        other => panic!("exit code 1901 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1902_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1902)));
    match vm.run() {
        VMResult::Ok(Value::Status(1902)) => {}
        other => panic!("exit code 1902 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-248)));
    match vm.run() {
        VMResult::Ok(Value::Status(-248)) => {}
        other => panic!("status -248 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1903_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1903)));
    match vm.run() {
        VMResult::Ok(Value::Status(1903)) => {}
        other => panic!("exit code 1903 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-249)));
    match vm.run() {
        VMResult::Ok(Value::Status(-249)) => {}
        other => panic!("status -249 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1904_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1904)));
    match vm.run() {
        VMResult::Ok(Value::Status(1904)) => {}
        other => panic!("exit code 1904 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..129 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1898 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1898 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 129 {
                Some(1905)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1898 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1905)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1905)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1905_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1905)));
    match vm.run() {
        VMResult::Ok(Value::Status(1905)) => {}
        other => panic!("exit code 1905 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1906)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..61 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 64);
    assert_eq!(vm.last_status, 1906);
}

#[test]
fn subshell_end_exit_code_1906_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1906)));
    match vm.run() {
        VMResult::Ok(Value::Status(1906)) => {}
        other => panic!("exit code 1906 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1907Ex1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1907)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1907);
}

#[test]
fn subshell_end_exit_code_1907_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1907)));
    match vm.run() {
        VMResult::Ok(Value::Status(1907)) => {}
        other => panic!("exit code 1907 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_begins_fifty_eight_ends_last_end_status_winsEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..60 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..58 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1908Ex1898;
    impl ShellHost for CountingBeginEndHost1908Ex1898 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1908)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1908Ex1898));
    match vm.run() {
        VMResult::Ok(Value::Status(1908)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1908)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 60);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 58);
}

#[test]
fn subshell_end_exit_code_1908_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1908)));
    match vm.run() {
        VMResult::Ok(Value::Status(1908)) => {}
        other => panic!("exit code 1908 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1909Ex1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1898;
    impl ShellHost for CountingBeginHost733Ex1898 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1909)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1898));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1909);
}

#[test]
fn subshell_end_exit_code_1909_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1909)));
    match vm.run() {
        VMResult::Ok(Value::Status(1909)) => {}
        other => panic!("exit code 1909 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1898() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1910)));
    for _ in 0..61 {
        match vm.run() {
            VMResult::Ok(Value::Status(1910)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1910_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1910)));
    match vm.run() {
        VMResult::Ok(Value::Status(1910)) => {}
        other => panic!("exit code 1910 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1911Ex1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1911)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1911);
}

#[test]
fn subshell_end_exit_code_1911_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1911)));
    match vm.run() {
        VMResult::Ok(Value::Status(1911)) => {}
        other => panic!("exit code 1911 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1912_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1912)));
    match vm.run() {
        VMResult::Ok(Value::Status(1912)) => {}
        other => panic!("exit code 1912 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1913Ex1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1913)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1913);
}

#[test]
fn subshell_end_exit_code_1913_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1913)));
    match vm.run() {
        VMResult::Ok(Value::Status(1913)) => {}
        other => panic!("exit code 1913 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_one_consecutive_runs_without_reset_still_blockedEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..361 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1914_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1914)));
    match vm.run() {
        VMResult::Ok(Value::Status(1914)) => {}
        other => panic!("exit code 1914 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_two_consecutive_runs_without_reset_still_blockedEx1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..362 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1915_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1915)));
    match vm.run() {
        VMResult::Ok(Value::Status(1915)) => {}
        other => panic!("exit code 1915 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1916_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1916)));
    match vm.run() {
        VMResult::Ok(Value::Status(1916)) => {}
        other => panic!("exit code 1916 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1917;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1917)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1917, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1917_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1917)));
    match vm.run() {
        VMResult::Ok(Value::Status(1917)) => {}
        other => panic!("exit code 1917 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1918,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1918)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1918), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1918_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1918)));
    match vm.run() {
        VMResult::Ok(Value::Status(1918)) => {}
        other => panic!("exit code 1918 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-250)));
    match vm.run() {
        VMResult::Ok(Value::Status(-250)) => {}
        other => panic!("status -250 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1919_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1919)));
    match vm.run() {
        VMResult::Ok(Value::Status(1919)) => {}
        other => panic!("exit code 1919 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_eight_end_incrementing_from_fiveEx1898() {
    let mut b = ChunkBuilder::new();
    for _ in 0..248 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 68 }));
    match vm.run() {
        VMResult::Ok(Value::Status(315)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(315)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1920_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1920)));
    match vm.run() {
        VMResult::Ok(Value::Status(1920)) => {}
        other => panic!("exit code 1920 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1921Ex1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1921Ex1898 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1921Ex1898 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1921Ex1898 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1921_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1921)));
    match vm.run() {
        VMResult::Ok(Value::Status(1921)) => {}
        other => panic!("exit code 1921 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1922Ex1898() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1922)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1922);
}

#[test]
fn subshell_end_exit_code_1922_propagatesEx1898() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1922)));
    match vm.run() {
        VMResult::Ok(Value::Status(1922)) => {}
        other => panic!("exit code 1922 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BR (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1923_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1923)));
    match vm.run() {
        VMResult::Ok(Value::Status(1923)) => {}
        other => panic!("exit code 1923 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_three_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..363 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1924_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1924)));
    match vm.run() {
        VMResult::Ok(Value::Status(1924)) => {}
        other => panic!("exit code 1924 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_four_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..364 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1925_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1925)));
    match vm.run() {
        VMResult::Ok(Value::Status(1925)) => {}
        other => panic!("exit code 1925 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_five_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..365 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1926_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1926)));
    match vm.run() {
        VMResult::Ok(Value::Status(1926)) => {}
        other => panic!("exit code 1926 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_forty_nine_end_incrementing_from_sixEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..249 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 69 }));
    match vm.run() {
        VMResult::Ok(Value::Status(317)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(317)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1927_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1927)));
    match vm.run() {
        VMResult::Ok(Value::Status(1927)) => {}
        other => panic!("exit code 1927 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-251)));
    match vm.run() {
        VMResult::Ok(Value::Status(-251)) => {}
        other => panic!("status -251 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1928_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1928)));
    match vm.run() {
        VMResult::Ok(Value::Status(1928)) => {}
        other => panic!("exit code 1928 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-252)));
    match vm.run() {
        VMResult::Ok(Value::Status(-252)) => {}
        other => panic!("status -252 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1929_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1929)));
    match vm.run() {
        VMResult::Ok(Value::Status(1929)) => {}
        other => panic!("exit code 1929 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..130 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1923 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1923 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 130 {
                Some(1930)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1923 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1930)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1930)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1930_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1930)));
    match vm.run() {
        VMResult::Ok(Value::Status(1930)) => {}
        other => panic!("exit code 1930 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1931)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..62 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 65);
    assert_eq!(vm.last_status, 1931);
}

#[test]
fn subshell_end_exit_code_1931_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1931)));
    match vm.run() {
        VMResult::Ok(Value::Status(1931)) => {}
        other => panic!("exit code 1931 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1932Ex1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1932)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1932);
}

#[test]
fn subshell_end_exit_code_1932_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1932)));
    match vm.run() {
        VMResult::Ok(Value::Status(1932)) => {}
        other => panic!("exit code 1932 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_one_begins_fifty_nine_ends_last_end_status_winsEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..61 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..59 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1933Ex1923;
    impl ShellHost for CountingBeginEndHost1933Ex1923 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1933)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1933Ex1923));
    match vm.run() {
        VMResult::Ok(Value::Status(1933)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1933)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 61);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 59);
}

#[test]
fn subshell_end_exit_code_1933_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1933)));
    match vm.run() {
        VMResult::Ok(Value::Status(1933)) => {}
        other => panic!("exit code 1933 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1934Ex1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1934)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1934);
}

#[test]
fn subshell_end_exit_code_1934_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1934)));
    match vm.run() {
        VMResult::Ok(Value::Status(1934)) => {}
        other => panic!("exit code 1934 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1923() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1935)));
    for _ in 0..62 {
        match vm.run() {
            VMResult::Ok(Value::Status(1935)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1935_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1935)));
    match vm.run() {
        VMResult::Ok(Value::Status(1935)) => {}
        other => panic!("exit code 1935 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1936Ex1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1936)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1936);
}

#[test]
fn subshell_end_exit_code_1936_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1936)));
    match vm.run() {
        VMResult::Ok(Value::Status(1936)) => {}
        other => panic!("exit code 1936 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_end_incrementing_from_sevenEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..250 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 70 }));
    match vm.run() {
        VMResult::Ok(Value::Status(319)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(319)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1937_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1937)));
    match vm.run() {
        VMResult::Ok(Value::Status(1937)) => {}
        other => panic!("exit code 1937 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1938Ex1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1938)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1938);
}

#[test]
fn subshell_end_exit_code_1938_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1938)));
    match vm.run() {
        VMResult::Ok(Value::Status(1938)) => {}
        other => panic!("exit code 1938 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_six_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..366 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1939_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1939)));
    match vm.run() {
        VMResult::Ok(Value::Status(1939)) => {}
        other => panic!("exit code 1939 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..131 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1923 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1923 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 131 {
                Some(1940)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1923 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1940)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1940)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1940_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1940)));
    match vm.run() {
        VMResult::Ok(Value::Status(1940)) => {}
        other => panic!("exit code 1940 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1941_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1941)));
    match vm.run() {
        VMResult::Ok(Value::Status(1941)) => {}
        other => panic!("exit code 1941 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1942Ex1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1942)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1942);
}

#[test]
fn subshell_end_exit_code_1942_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1942)));
    match vm.run() {
        VMResult::Ok(Value::Status(1942)) => {}
        other => panic!("exit code 1942 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_one_end_incrementing_from_oneEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..251 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 64 }));
    match vm.run() {
        VMResult::Ok(Value::Status(314)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(314)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1943_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1943)));
    match vm.run() {
        VMResult::Ok(Value::Status(1943)) => {}
        other => panic!("exit code 1943 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1944;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1944)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 1944, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1944_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1944)));
    match vm.run() {
        VMResult::Ok(Value::Status(1944)) => {}
        other => panic!("exit code 1944 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1945,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1945)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(1945), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1945_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1945)));
    match vm.run() {
        VMResult::Ok(Value::Status(1945)) => {}
        other => panic!("exit code 1945 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_seven_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..367 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1946_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1946)));
    match vm.run() {
        VMResult::Ok(Value::Status(1946)) => {}
        other => panic!("exit code 1946 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..132 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1923 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1923 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 132 {
                Some(1947)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1923 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1947)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(1947)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1947_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1947)));
    match vm.run() {
        VMResult::Ok(Value::Status(1947)) => {}
        other => panic!("exit code 1947 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_1948Ex1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost1948Ex1923;
    impl ShellHost for PipelineSubshellHost1948Ex1923 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1948)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost1948Ex1923));
    match vm.run() {
        VMResult::Ok(Value::Status(1948)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1948_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1948)));
    match vm.run() {
        VMResult::Ok(Value::Status(1948)) => {}
        other => panic!("exit code 1948 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_1949Ex1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost1949Ex1923;
    impl ShellHost for SubshellThenPipelineHost1949Ex1923 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            1949
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost1949Ex1923));
    match vm.run() {
        VMResult::Ok(Value::Status(1949)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1949_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1949)));
    match vm.run() {
        VMResult::Ok(Value::Status(1949)) => {}
        other => panic!("exit code 1949 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-253)));
    match vm.run() {
        VMResult::Ok(Value::Status(-253)) => {}
        other => panic!("status -253 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1950_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1950)));
    match vm.run() {
        VMResult::Ok(Value::Status(1950)) => {}
        other => panic!("exit code 1950 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_two_end_incrementing_from_eightEx1923() {
    let mut b = ChunkBuilder::new();
    for _ in 0..252 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 71 }));
    match vm.run() {
        VMResult::Ok(Value::Status(322)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(322)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1951_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1951)));
    match vm.run() {
        VMResult::Ok(Value::Status(1951)) => {}
        other => panic!("exit code 1951 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_eight_consecutive_runs_without_reset_still_blockedEx1923() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..368 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1952_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1952)));
    match vm.run() {
        VMResult::Ok(Value::Status(1952)) => {}
        other => panic!("exit code 1952 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1953Ex1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1953Ex1923 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1953Ex1923 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1953Ex1923 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1953_propagatesEx1923() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1953)));
    match vm.run() {
        VMResult::Ok(Value::Status(1953)) => {}
        other => panic!("exit code 1953 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BS (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1954_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1954)));
    match vm.run() {
        VMResult::Ok(Value::Status(1954)) => {}
        other => panic!("exit code 1954 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_sixty_nine_consecutive_runs_without_reset_still_blockedEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..369 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1955_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1955)));
    match vm.run() {
        VMResult::Ok(Value::Status(1955)) => {}
        other => panic!("exit code 1955 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_consecutive_runs_without_reset_still_blockedEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..370 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1956_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1956)));
    match vm.run() {
        VMResult::Ok(Value::Status(1956)) => {}
        other => panic!("exit code 1956 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_one_consecutive_runs_without_reset_still_blockedEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..371 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1957_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1957)));
    match vm.run() {
        VMResult::Ok(Value::Status(1957)) => {}
        other => panic!("exit code 1957 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1958_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1958)));
    match vm.run() {
        VMResult::Ok(Value::Status(1958)) => {}
        other => panic!("exit code 1958 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-255)));
    match vm.run() {
        VMResult::Ok(Value::Status(-255)) => {}
        other => panic!("status -255 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1959_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1959)));
    match vm.run() {
        VMResult::Ok(Value::Status(1959)) => {}
        other => panic!("exit code 1959 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-256)));
    match vm.run() {
        VMResult::Ok(Value::Status(-256)) => {}
        other => panic!("status -256 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1960_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1960)));
    match vm.run() {
        VMResult::Ok(Value::Status(1960)) => {}
        other => panic!("exit code 1960 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..133 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx1954 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx1954 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 133 {
                Some(1961)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx1954 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1961)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(1961)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1961_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1961)));
    match vm.run() {
        VMResult::Ok(Value::Status(1961)) => {}
        other => panic!("exit code 1961 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1962)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..63 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 66);
    assert_eq!(vm.last_status, 1962);
}

#[test]
fn subshell_end_exit_code_1962_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1962)));
    match vm.run() {
        VMResult::Ok(Value::Status(1962)) => {}
        other => panic!("exit code 1962 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status1963Ex1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1963)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1963);
}

#[test]
fn subshell_end_exit_code_1963_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1963)));
    match vm.run() {
        VMResult::Ok(Value::Status(1963)) => {}
        other => panic!("exit code 1963 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_two_begins_sixty_ends_last_end_status_winsEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..62 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..60 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1964Ex1954;
    impl ShellHost for CountingBeginEndHost1964Ex1954 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1964)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1964Ex1954));
    match vm.run() {
        VMResult::Ok(Value::Status(1964)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(1964)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 62);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 60);
}

#[test]
fn subshell_end_exit_code_1964_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1964)));
    match vm.run() {
        VMResult::Ok(Value::Status(1964)) => {}
        other => panic!("exit code 1964 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status1965Ex1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex1954;
    impl ShellHost for CountingBeginHost733Ex1954 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(1965)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex1954));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1965);
}

#[test]
fn subshell_end_exit_code_1965_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1965)));
    match vm.run() {
        VMResult::Ok(Value::Status(1965)) => {}
        other => panic!("exit code 1965 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx1954() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1966)));
    for _ in 0..63 {
        match vm.run() {
            VMResult::Ok(Value::Status(1966)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1966_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1966)));
    match vm.run() {
        VMResult::Ok(Value::Status(1966)) => {}
        other => panic!("exit code 1966 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status1967Ex1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1967)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1967);
}

#[test]
fn subshell_end_exit_code_1967_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1967)));
    match vm.run() {
        VMResult::Ok(Value::Status(1967)) => {}
        other => panic!("exit code 1967 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1968_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1968)));
    match vm.run() {
        VMResult::Ok(Value::Status(1968)) => {}
        other => panic!("exit code 1968 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status1969Ex1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1969)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1969);
}

#[test]
fn subshell_end_exit_code_1969_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1969)));
    match vm.run() {
        VMResult::Ok(Value::Status(1969)) => {}
        other => panic!("exit code 1969 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_two_consecutive_runs_without_reset_still_blockedEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..372 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1970_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1970)));
    match vm.run() {
        VMResult::Ok(Value::Status(1970)) => {}
        other => panic!("exit code 1970 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_three_consecutive_runs_without_reset_still_blockedEx1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..373 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1971_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1971)));
    match vm.run() {
        VMResult::Ok(Value::Status(1971)) => {}
        other => panic!("exit code 1971 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1972_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1972)));
    match vm.run() {
        VMResult::Ok(Value::Status(1972)) => {}
        other => panic!("exit code 1972 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 1973;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(1973)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 1973, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1973_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1973)));
    match vm.run() {
        VMResult::Ok(Value::Status(1973)) => {}
        other => panic!("exit code 1973 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 1974,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(1974)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(1974), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1974_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1974)));
    match vm.run() {
        VMResult::Ok(Value::Status(1974)) => {}
        other => panic!("exit code 1974 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-257)));
    match vm.run() {
        VMResult::Ok(Value::Status(-257)) => {}
        other => panic!("status -257 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1975_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1975)));
    match vm.run() {
        VMResult::Ok(Value::Status(1975)) => {}
        other => panic!("exit code 1975 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_five_end_incrementing_from_fiveEx1954() {
    let mut b = ChunkBuilder::new();
    for _ in 0..255 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 71 }));
    match vm.run() {
        VMResult::Ok(Value::Status(325)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(325)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1976_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1976)));
    match vm.run() {
        VMResult::Ok(Value::Status(1976)) => {}
        other => panic!("exit code 1976 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status1977Ex1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost1977Ex1954 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost1977Ex1954 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost1977Ex1954 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1977_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1977)));
    match vm.run() {
        VMResult::Ok(Value::Status(1977)) => {}
        other => panic!("exit code 1977 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status1978Ex1954() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1978)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1978);
}

#[test]
fn subshell_end_exit_code_1978_propagatesEx1954() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1978)));
    match vm.run() {
        VMResult::Ok(Value::Status(1978)) => {}
        other => panic!("exit code 1978 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BT (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_1979_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1979)));
    match vm.run() {
        VMResult::Ok(Value::Status(1979)) => {}
        other => panic!("exit code 1979 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_four_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..374 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1980_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1980)));
    match vm.run() {
        VMResult::Ok(Value::Status(1980)) => {}
        other => panic!("exit code 1980 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_five_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..375 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1981_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1981)));
    match vm.run() {
        VMResult::Ok(Value::Status(1981)) => {}
        other => panic!("exit code 1981 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_six_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..376 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1982_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1982)));
    match vm.run() {
        VMResult::Ok(Value::Status(1982)) => {}
        other => panic!("exit code 1982 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_six_end_incrementing_from_sixEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..256 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 72 }));
    match vm.run() {
        VMResult::Ok(Value::Status(327)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(327)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1983_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1983)));
    match vm.run() {
        VMResult::Ok(Value::Status(1983)) => {}
        other => panic!("exit code 1983 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-258)));
    match vm.run() {
        VMResult::Ok(Value::Status(-258)) => {}
        other => panic!("status -258 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1984_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1984)));
    match vm.run() {
        VMResult::Ok(Value::Status(1984)) => {}
        other => panic!("exit code 1984 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-259)));
    match vm.run() {
        VMResult::Ok(Value::Status(-259)) => {}
        other => panic!("status -259 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_1985_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1985)));
    match vm.run() {
        VMResult::Ok(Value::Status(1985)) => {}
        other => panic!("exit code 1985 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..134 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx1979 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx1979 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 134 {
                Some(1986)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx1979 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1986)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(1986)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1986_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1986)));
    match vm.run() {
        VMResult::Ok(Value::Status(1986)) => {}
        other => panic!("exit code 1986 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(1987)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..64 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 67);
    assert_eq!(vm.last_status, 1987);
}

#[test]
fn subshell_end_exit_code_1987_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1987)));
    match vm.run() {
        VMResult::Ok(Value::Status(1987)) => {}
        other => panic!("exit code 1987 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status1988Ex1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1988)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1988);
}

#[test]
fn subshell_end_exit_code_1988_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1988)));
    match vm.run() {
        VMResult::Ok(Value::Status(1988)) => {}
        other => panic!("exit code 1988 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_three_begins_sixty_one_ends_last_end_status_winsEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..63 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..61 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost1989Ex1979;
    impl ShellHost for CountingBeginEndHost1989Ex1979 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(1989)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost1989Ex1979));
    match vm.run() {
        VMResult::Ok(Value::Status(1989)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(1989)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 63);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 61);
}

#[test]
fn subshell_end_exit_code_1989_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1989)));
    match vm.run() {
        VMResult::Ok(Value::Status(1989)) => {}
        other => panic!("exit code 1989 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status1990Ex1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1990)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1990);
}

#[test]
fn subshell_end_exit_code_1990_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1990)));
    match vm.run() {
        VMResult::Ok(Value::Status(1990)) => {}
        other => panic!("exit code 1990 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx1979() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(1991)));
    for _ in 0..64 {
        match vm.run() {
            VMResult::Ok(Value::Status(1991)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_1991_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1991)));
    match vm.run() {
        VMResult::Ok(Value::Status(1991)) => {}
        other => panic!("exit code 1991 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status1992Ex1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1992)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1992);
}

#[test]
fn subshell_end_exit_code_1992_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1992)));
    match vm.run() {
        VMResult::Ok(Value::Status(1992)) => {}
        other => panic!("exit code 1992 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_seven_end_incrementing_from_sevenEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..257 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 73 }));
    match vm.run() {
        VMResult::Ok(Value::Status(329)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(329)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1993_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1993)));
    match vm.run() {
        VMResult::Ok(Value::Status(1993)) => {}
        other => panic!("exit code 1993 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status1994Ex1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(1994)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1994);
}

#[test]
fn subshell_end_exit_code_1994_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1994)));
    match vm.run() {
        VMResult::Ok(Value::Status(1994)) => {}
        other => panic!("exit code 1994 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_seven_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..377 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_1995_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1995)));
    match vm.run() {
        VMResult::Ok(Value::Status(1995)) => {}
        other => panic!("exit code 1995 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..135 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx1979 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx1979 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 135 {
                Some(1996)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx1979 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(1996)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(1996)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1996_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1996)));
    match vm.run() {
        VMResult::Ok(Value::Status(1996)) => {}
        other => panic!("exit code 1996 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1997_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1997)));
    match vm.run() {
        VMResult::Ok(Value::Status(1997)) => {}
        other => panic!("exit code 1997 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status1998Ex1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1998)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 1998);
}

#[test]
fn subshell_end_exit_code_1998_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1998)));
    match vm.run() {
        VMResult::Ok(Value::Status(1998)) => {}
        other => panic!("exit code 1998 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_eight_end_incrementing_from_oneEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..258 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 67 }));
    match vm.run() {
        VMResult::Ok(Value::Status(324)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(324)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_1999_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(1999)));
    match vm.run() {
        VMResult::Ok(Value::Status(1999)) => {}
        other => panic!("exit code 1999 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2000;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2000)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2000, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2000_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2000)));
    match vm.run() {
        VMResult::Ok(Value::Status(2000)) => {}
        other => panic!("exit code 2000 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2001,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2001)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2001), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2001_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2001)));
    match vm.run() {
        VMResult::Ok(Value::Status(2001)) => {}
        other => panic!("exit code 2001 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_eight_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..378 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2002_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2002)));
    match vm.run() {
        VMResult::Ok(Value::Status(2002)) => {}
        other => panic!("exit code 2002 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..136 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx1979 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx1979 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 136 {
                Some(2003)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx1979 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2003)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2003)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2003_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2003)));
    match vm.run() {
        VMResult::Ok(Value::Status(2003)) => {}
        other => panic!("exit code 2003 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2004Ex1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2004Ex1979;
    impl ShellHost for PipelineSubshellHost2004Ex1979 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2004)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2004Ex1979));
    match vm.run() {
        VMResult::Ok(Value::Status(2004)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2004_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2004)));
    match vm.run() {
        VMResult::Ok(Value::Status(2004)) => {}
        other => panic!("exit code 2004 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2005Ex1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2005Ex1979;
    impl ShellHost for SubshellThenPipelineHost2005Ex1979 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2005
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2005Ex1979));
    match vm.run() {
        VMResult::Ok(Value::Status(2005)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2005_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2005)));
    match vm.run() {
        VMResult::Ok(Value::Status(2005)) => {}
        other => panic!("exit code 2005 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-260)));
    match vm.run() {
        VMResult::Ok(Value::Status(-260)) => {}
        other => panic!("status -260 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2006_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2006)));
    match vm.run() {
        VMResult::Ok(Value::Status(2006)) => {}
        other => panic!("exit code 2006 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_fifty_nine_end_incrementing_from_eightEx1979() {
    let mut b = ChunkBuilder::new();
    for _ in 0..259 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 74 }));
    match vm.run() {
        VMResult::Ok(Value::Status(332)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(332)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2007_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2007)));
    match vm.run() {
        VMResult::Ok(Value::Status(2007)) => {}
        other => panic!("exit code 2007 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_seventy_nine_consecutive_runs_without_reset_still_blockedEx1979() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..379 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2008_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2008)));
    match vm.run() {
        VMResult::Ok(Value::Status(2008)) => {}
        other => panic!("exit code 2008 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2009Ex1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2009Ex1979 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2009Ex1979 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2009Ex1979 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2009_propagatesEx1979() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2009)));
    match vm.run() {
        VMResult::Ok(Value::Status(2009)) => {}
        other => panic!("exit code 2009 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BU (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2010_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2010)));
    match vm.run() {
        VMResult::Ok(Value::Status(2010)) => {}
        other => panic!("exit code 2010 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_consecutive_runs_without_reset_still_blockedEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..380 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2011_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2011)));
    match vm.run() {
        VMResult::Ok(Value::Status(2011)) => {}
        other => panic!("exit code 2011 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_one_consecutive_runs_without_reset_still_blockedEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..381 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2012_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2012)));
    match vm.run() {
        VMResult::Ok(Value::Status(2012)) => {}
        other => panic!("exit code 2012 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_two_consecutive_runs_without_reset_still_blockedEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..382 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2013_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2013)));
    match vm.run() {
        VMResult::Ok(Value::Status(2013)) => {}
        other => panic!("exit code 2013 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2014_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2014)));
    match vm.run() {
        VMResult::Ok(Value::Status(2014)) => {}
        other => panic!("exit code 2014 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-262)));
    match vm.run() {
        VMResult::Ok(Value::Status(-262)) => {}
        other => panic!("status -262 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2015_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2015)));
    match vm.run() {
        VMResult::Ok(Value::Status(2015)) => {}
        other => panic!("exit code 2015 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-263)));
    match vm.run() {
        VMResult::Ok(Value::Status(-263)) => {}
        other => panic!("status -263 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2016_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2016)));
    match vm.run() {
        VMResult::Ok(Value::Status(2016)) => {}
        other => panic!("exit code 2016 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..137 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2010 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2010 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 137 {
                Some(2017)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2010 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2017)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2017)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2017_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2017)));
    match vm.run() {
        VMResult::Ok(Value::Status(2017)) => {}
        other => panic!("exit code 2017 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2018)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..65 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 68);
    assert_eq!(vm.last_status, 2018);
}

#[test]
fn subshell_end_exit_code_2018_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2018)));
    match vm.run() {
        VMResult::Ok(Value::Status(2018)) => {}
        other => panic!("exit code 2018 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2019Ex2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2019)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2019);
}

#[test]
fn subshell_end_exit_code_2019_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2019)));
    match vm.run() {
        VMResult::Ok(Value::Status(2019)) => {}
        other => panic!("exit code 2019 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_four_begins_sixty_two_ends_last_end_status_winsEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..64 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..62 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2020Ex2010;
    impl ShellHost for CountingBeginEndHost2020Ex2010 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2020)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2020Ex2010));
    match vm.run() {
        VMResult::Ok(Value::Status(2020)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2020)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 64);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 62);
}

#[test]
fn subshell_end_exit_code_2020_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2020)));
    match vm.run() {
        VMResult::Ok(Value::Status(2020)) => {}
        other => panic!("exit code 2020 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2021Ex2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2010;
    impl ShellHost for CountingBeginHost733Ex2010 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2021)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2010));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2021);
}

#[test]
fn subshell_end_exit_code_2021_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2021)));
    match vm.run() {
        VMResult::Ok(Value::Status(2021)) => {}
        other => panic!("exit code 2021 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2010() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2022)));
    for _ in 0..65 {
        match vm.run() {
            VMResult::Ok(Value::Status(2022)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2022_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2022)));
    match vm.run() {
        VMResult::Ok(Value::Status(2022)) => {}
        other => panic!("exit code 2022 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2023Ex2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2023)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2023);
}

#[test]
fn subshell_end_exit_code_2023_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2023)));
    match vm.run() {
        VMResult::Ok(Value::Status(2023)) => {}
        other => panic!("exit code 2023 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2024_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2024)));
    match vm.run() {
        VMResult::Ok(Value::Status(2024)) => {}
        other => panic!("exit code 2024 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2025Ex2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2025)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2025);
}

#[test]
fn subshell_end_exit_code_2025_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2025)));
    match vm.run() {
        VMResult::Ok(Value::Status(2025)) => {}
        other => panic!("exit code 2025 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_three_consecutive_runs_without_reset_still_blockedEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..383 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2026_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2026)));
    match vm.run() {
        VMResult::Ok(Value::Status(2026)) => {}
        other => panic!("exit code 2026 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_four_consecutive_runs_without_reset_still_blockedEx2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..384 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2027_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2027)));
    match vm.run() {
        VMResult::Ok(Value::Status(2027)) => {}
        other => panic!("exit code 2027 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2028_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2028)));
    match vm.run() {
        VMResult::Ok(Value::Status(2028)) => {}
        other => panic!("exit code 2028 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2029;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2029)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2029, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2029_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2029)));
    match vm.run() {
        VMResult::Ok(Value::Status(2029)) => {}
        other => panic!("exit code 2029 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2030,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2030)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2030), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2030_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2030)));
    match vm.run() {
        VMResult::Ok(Value::Status(2030)) => {}
        other => panic!("exit code 2030 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-264)));
    match vm.run() {
        VMResult::Ok(Value::Status(-264)) => {}
        other => panic!("status -264 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2031_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2031)));
    match vm.run() {
        VMResult::Ok(Value::Status(2031)) => {}
        other => panic!("exit code 2031 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_two_end_incrementing_from_fiveEx2010() {
    let mut b = ChunkBuilder::new();
    for _ in 0..262 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 74 }));
    match vm.run() {
        VMResult::Ok(Value::Status(335)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(335)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2032_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2032)));
    match vm.run() {
        VMResult::Ok(Value::Status(2032)) => {}
        other => panic!("exit code 2032 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2033Ex2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2033Ex2010 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2033Ex2010 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2033Ex2010 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2033_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2033)));
    match vm.run() {
        VMResult::Ok(Value::Status(2033)) => {}
        other => panic!("exit code 2033 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2034Ex2010() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2034)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2034);
}

#[test]
fn subshell_end_exit_code_2034_propagatesEx2010() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2034)));
    match vm.run() {
        VMResult::Ok(Value::Status(2034)) => {}
        other => panic!("exit code 2034 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BV (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2035_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2035)));
    match vm.run() {
        VMResult::Ok(Value::Status(2035)) => {}
        other => panic!("exit code 2035 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_five_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..385 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2036_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2036)));
    match vm.run() {
        VMResult::Ok(Value::Status(2036)) => {}
        other => panic!("exit code 2036 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_six_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..386 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2037_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2037)));
    match vm.run() {
        VMResult::Ok(Value::Status(2037)) => {}
        other => panic!("exit code 2037 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_seven_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..387 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2038_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2038)));
    match vm.run() {
        VMResult::Ok(Value::Status(2038)) => {}
        other => panic!("exit code 2038 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_three_end_incrementing_from_sixEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..263 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 75 }));
    match vm.run() {
        VMResult::Ok(Value::Status(337)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(337)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2039_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2039)));
    match vm.run() {
        VMResult::Ok(Value::Status(2039)) => {}
        other => panic!("exit code 2039 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-265)));
    match vm.run() {
        VMResult::Ok(Value::Status(-265)) => {}
        other => panic!("status -265 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2040_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2040)));
    match vm.run() {
        VMResult::Ok(Value::Status(2040)) => {}
        other => panic!("exit code 2040 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-266)));
    match vm.run() {
        VMResult::Ok(Value::Status(-266)) => {}
        other => panic!("status -266 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2041_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2041)));
    match vm.run() {
        VMResult::Ok(Value::Status(2041)) => {}
        other => panic!("exit code 2041 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..138 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2035 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2035 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 138 {
                Some(2042)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2035 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2042)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2042)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2042_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2042)));
    match vm.run() {
        VMResult::Ok(Value::Status(2042)) => {}
        other => panic!("exit code 2042 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2043)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..66 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 69);
    assert_eq!(vm.last_status, 2043);
}

#[test]
fn subshell_end_exit_code_2043_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2043)));
    match vm.run() {
        VMResult::Ok(Value::Status(2043)) => {}
        other => panic!("exit code 2043 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2044Ex2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2044)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2044);
}

#[test]
fn subshell_end_exit_code_2044_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2044)));
    match vm.run() {
        VMResult::Ok(Value::Status(2044)) => {}
        other => panic!("exit code 2044 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_five_begins_sixty_three_ends_last_end_status_winsEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..65 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..63 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2045Ex2035;
    impl ShellHost for CountingBeginEndHost2045Ex2035 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2045)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2045Ex2035));
    match vm.run() {
        VMResult::Ok(Value::Status(2045)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2045)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 65);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 63);
}

#[test]
fn subshell_end_exit_code_2045_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2045)));
    match vm.run() {
        VMResult::Ok(Value::Status(2045)) => {}
        other => panic!("exit code 2045 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2046Ex2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2046)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2046);
}

#[test]
fn subshell_end_exit_code_2046_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2046)));
    match vm.run() {
        VMResult::Ok(Value::Status(2046)) => {}
        other => panic!("exit code 2046 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2035() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2047)));
    for _ in 0..66 {
        match vm.run() {
            VMResult::Ok(Value::Status(2047)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2047_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2047)));
    match vm.run() {
        VMResult::Ok(Value::Status(2047)) => {}
        other => panic!("exit code 2047 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2048Ex2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2048)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2048);
}

#[test]
fn subshell_end_exit_code_2048_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2048)));
    match vm.run() {
        VMResult::Ok(Value::Status(2048)) => {}
        other => panic!("exit code 2048 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_four_end_incrementing_from_sevenEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..264 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 76 }));
    match vm.run() {
        VMResult::Ok(Value::Status(339)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(339)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2049_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2049)));
    match vm.run() {
        VMResult::Ok(Value::Status(2049)) => {}
        other => panic!("exit code 2049 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2050Ex2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2050)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2050);
}

#[test]
fn subshell_end_exit_code_2050_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2050)));
    match vm.run() {
        VMResult::Ok(Value::Status(2050)) => {}
        other => panic!("exit code 2050 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_eight_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..388 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2051_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2051)));
    match vm.run() {
        VMResult::Ok(Value::Status(2051)) => {}
        other => panic!("exit code 2051 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..139 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2035 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2035 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 139 {
                Some(2052)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2035 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2052)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2052)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2052_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2052)));
    match vm.run() {
        VMResult::Ok(Value::Status(2052)) => {}
        other => panic!("exit code 2052 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2053_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2053)));
    match vm.run() {
        VMResult::Ok(Value::Status(2053)) => {}
        other => panic!("exit code 2053 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2054Ex2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2054)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2054);
}

#[test]
fn subshell_end_exit_code_2054_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2054)));
    match vm.run() {
        VMResult::Ok(Value::Status(2054)) => {}
        other => panic!("exit code 2054 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_five_end_incrementing_from_oneEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..265 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 70 }));
    match vm.run() {
        VMResult::Ok(Value::Status(334)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(334)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2055_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2055)));
    match vm.run() {
        VMResult::Ok(Value::Status(2055)) => {}
        other => panic!("exit code 2055 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2056;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2056)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2056, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2056_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2056)));
    match vm.run() {
        VMResult::Ok(Value::Status(2056)) => {}
        other => panic!("exit code 2056 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2057,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2057)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2057), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2057_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2057)));
    match vm.run() {
        VMResult::Ok(Value::Status(2057)) => {}
        other => panic!("exit code 2057 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_eighty_nine_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..389 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2058_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2058)));
    match vm.run() {
        VMResult::Ok(Value::Status(2058)) => {}
        other => panic!("exit code 2058 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..140 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2035 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2035 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 140 {
                Some(2059)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2035 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2059)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2059)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2059_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2059)));
    match vm.run() {
        VMResult::Ok(Value::Status(2059)) => {}
        other => panic!("exit code 2059 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2060Ex2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2060Ex2035;
    impl ShellHost for PipelineSubshellHost2060Ex2035 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2060)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2060Ex2035));
    match vm.run() {
        VMResult::Ok(Value::Status(2060)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2060_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2060)));
    match vm.run() {
        VMResult::Ok(Value::Status(2060)) => {}
        other => panic!("exit code 2060 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2061Ex2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2061Ex2035;
    impl ShellHost for SubshellThenPipelineHost2061Ex2035 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2061
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2061Ex2035));
    match vm.run() {
        VMResult::Ok(Value::Status(2061)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2061_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2061)));
    match vm.run() {
        VMResult::Ok(Value::Status(2061)) => {}
        other => panic!("exit code 2061 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-267)));
    match vm.run() {
        VMResult::Ok(Value::Status(-267)) => {}
        other => panic!("status -267 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2062_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2062)));
    match vm.run() {
        VMResult::Ok(Value::Status(2062)) => {}
        other => panic!("exit code 2062 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_six_end_incrementing_from_eightEx2035() {
    let mut b = ChunkBuilder::new();
    for _ in 0..266 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 77 }));
    match vm.run() {
        VMResult::Ok(Value::Status(342)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(342)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2063_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2063)));
    match vm.run() {
        VMResult::Ok(Value::Status(2063)) => {}
        other => panic!("exit code 2063 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_consecutive_runs_without_reset_still_blockedEx2035() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..390 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2064_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2064)));
    match vm.run() {
        VMResult::Ok(Value::Status(2064)) => {}
        other => panic!("exit code 2064 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2065Ex2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2065Ex2035 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2065Ex2035 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2065Ex2035 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2065_propagatesEx2035() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2065)));
    match vm.run() {
        VMResult::Ok(Value::Status(2065)) => {}
        other => panic!("exit code 2065 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BW (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2066_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2066)));
    match vm.run() {
        VMResult::Ok(Value::Status(2066)) => {}
        other => panic!("exit code 2066 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_one_consecutive_runs_without_reset_still_blockedEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..391 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2067_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2067)));
    match vm.run() {
        VMResult::Ok(Value::Status(2067)) => {}
        other => panic!("exit code 2067 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_two_consecutive_runs_without_reset_still_blockedEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..392 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2068_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2068)));
    match vm.run() {
        VMResult::Ok(Value::Status(2068)) => {}
        other => panic!("exit code 2068 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_three_consecutive_runs_without_reset_still_blockedEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..393 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2069_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2069)));
    match vm.run() {
        VMResult::Ok(Value::Status(2069)) => {}
        other => panic!("exit code 2069 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2070_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2070)));
    match vm.run() {
        VMResult::Ok(Value::Status(2070)) => {}
        other => panic!("exit code 2070 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-269)));
    match vm.run() {
        VMResult::Ok(Value::Status(-269)) => {}
        other => panic!("status -269 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2071_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2071)));
    match vm.run() {
        VMResult::Ok(Value::Status(2071)) => {}
        other => panic!("exit code 2071 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-270)));
    match vm.run() {
        VMResult::Ok(Value::Status(-270)) => {}
        other => panic!("status -270 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2072_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2072)));
    match vm.run() {
        VMResult::Ok(Value::Status(2072)) => {}
        other => panic!("exit code 2072 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..141 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2066 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2066 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 141 {
                Some(2073)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2066 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2073)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2073)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2073_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2073)));
    match vm.run() {
        VMResult::Ok(Value::Status(2073)) => {}
        other => panic!("exit code 2073 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2074)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..67 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 70);
    assert_eq!(vm.last_status, 2074);
}

#[test]
fn subshell_end_exit_code_2074_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2074)));
    match vm.run() {
        VMResult::Ok(Value::Status(2074)) => {}
        other => panic!("exit code 2074 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2075Ex2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2075)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2075);
}

#[test]
fn subshell_end_exit_code_2075_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2075)));
    match vm.run() {
        VMResult::Ok(Value::Status(2075)) => {}
        other => panic!("exit code 2075 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_six_begins_sixty_four_ends_last_end_status_winsEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..66 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..64 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2076Ex2066;
    impl ShellHost for CountingBeginEndHost2076Ex2066 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2076)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2076Ex2066));
    match vm.run() {
        VMResult::Ok(Value::Status(2076)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2076)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 66);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 64);
}

#[test]
fn subshell_end_exit_code_2076_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2076)));
    match vm.run() {
        VMResult::Ok(Value::Status(2076)) => {}
        other => panic!("exit code 2076 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2077Ex2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2066;
    impl ShellHost for CountingBeginHost733Ex2066 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2077)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2066));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2077);
}

#[test]
fn subshell_end_exit_code_2077_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2077)));
    match vm.run() {
        VMResult::Ok(Value::Status(2077)) => {}
        other => panic!("exit code 2077 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2066() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2078)));
    for _ in 0..67 {
        match vm.run() {
            VMResult::Ok(Value::Status(2078)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2078_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2078)));
    match vm.run() {
        VMResult::Ok(Value::Status(2078)) => {}
        other => panic!("exit code 2078 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2079Ex2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2079)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2079);
}

#[test]
fn subshell_end_exit_code_2079_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2079)));
    match vm.run() {
        VMResult::Ok(Value::Status(2079)) => {}
        other => panic!("exit code 2079 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2080_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2080)));
    match vm.run() {
        VMResult::Ok(Value::Status(2080)) => {}
        other => panic!("exit code 2080 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2081Ex2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2081)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2081);
}

#[test]
fn subshell_end_exit_code_2081_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2081)));
    match vm.run() {
        VMResult::Ok(Value::Status(2081)) => {}
        other => panic!("exit code 2081 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_four_consecutive_runs_without_reset_still_blockedEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..394 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2082_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2082)));
    match vm.run() {
        VMResult::Ok(Value::Status(2082)) => {}
        other => panic!("exit code 2082 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_five_consecutive_runs_without_reset_still_blockedEx2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..395 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2083_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2083)));
    match vm.run() {
        VMResult::Ok(Value::Status(2083)) => {}
        other => panic!("exit code 2083 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2084_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2084)));
    match vm.run() {
        VMResult::Ok(Value::Status(2084)) => {}
        other => panic!("exit code 2084 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2085;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2085)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2085, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2085_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2085)));
    match vm.run() {
        VMResult::Ok(Value::Status(2085)) => {}
        other => panic!("exit code 2085 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2086,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2086)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2086), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2086_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2086)));
    match vm.run() {
        VMResult::Ok(Value::Status(2086)) => {}
        other => panic!("exit code 2086 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-271)));
    match vm.run() {
        VMResult::Ok(Value::Status(-271)) => {}
        other => panic!("status -271 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2087_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2087)));
    match vm.run() {
        VMResult::Ok(Value::Status(2087)) => {}
        other => panic!("exit code 2087 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_sixty_nine_end_incrementing_from_fiveEx2066() {
    let mut b = ChunkBuilder::new();
    for _ in 0..269 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 77 }));
    match vm.run() {
        VMResult::Ok(Value::Status(345)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(345)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2088_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2088)));
    match vm.run() {
        VMResult::Ok(Value::Status(2088)) => {}
        other => panic!("exit code 2088 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2089Ex2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2089Ex2066 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2089Ex2066 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2089Ex2066 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2089_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2089)));
    match vm.run() {
        VMResult::Ok(Value::Status(2089)) => {}
        other => panic!("exit code 2089 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2090Ex2066() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2090)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2090);
}

#[test]
fn subshell_end_exit_code_2090_propagatesEx2066() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2090)));
    match vm.run() {
        VMResult::Ok(Value::Status(2090)) => {}
        other => panic!("exit code 2090 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BX (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2091_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2091)));
    match vm.run() {
        VMResult::Ok(Value::Status(2091)) => {}
        other => panic!("exit code 2091 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_six_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..396 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2092_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2092)));
    match vm.run() {
        VMResult::Ok(Value::Status(2092)) => {}
        other => panic!("exit code 2092 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_seven_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..397 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2093_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2093)));
    match vm.run() {
        VMResult::Ok(Value::Status(2093)) => {}
        other => panic!("exit code 2093 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_eight_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..398 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2094_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2094)));
    match vm.run() {
        VMResult::Ok(Value::Status(2094)) => {}
        other => panic!("exit code 2094 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_end_incrementing_from_sixEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..270 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 78 }));
    match vm.run() {
        VMResult::Ok(Value::Status(347)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(347)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2095_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2095)));
    match vm.run() {
        VMResult::Ok(Value::Status(2095)) => {}
        other => panic!("exit code 2095 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-272)));
    match vm.run() {
        VMResult::Ok(Value::Status(-272)) => {}
        other => panic!("status -272 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2096_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2096)));
    match vm.run() {
        VMResult::Ok(Value::Status(2096)) => {}
        other => panic!("exit code 2096 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-273)));
    match vm.run() {
        VMResult::Ok(Value::Status(-273)) => {}
        other => panic!("status -273 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2097_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2097)));
    match vm.run() {
        VMResult::Ok(Value::Status(2097)) => {}
        other => panic!("exit code 2097 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..142 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2091 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2091 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 142 {
                Some(2098)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2091 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2098)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2098)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2098_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2098)));
    match vm.run() {
        VMResult::Ok(Value::Status(2098)) => {}
        other => panic!("exit code 2098 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2099)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..68 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 71);
    assert_eq!(vm.last_status, 2099);
}

#[test]
fn subshell_end_exit_code_2099_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2099)));
    match vm.run() {
        VMResult::Ok(Value::Status(2099)) => {}
        other => panic!("exit code 2099 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2100Ex2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2100)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2100);
}

#[test]
fn subshell_end_exit_code_2100_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2100)));
    match vm.run() {
        VMResult::Ok(Value::Status(2100)) => {}
        other => panic!("exit code 2100 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_seven_begins_sixty_five_ends_last_end_status_winsEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..67 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..65 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2101Ex2091;
    impl ShellHost for CountingBeginEndHost2101Ex2091 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2101)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2101Ex2091));
    match vm.run() {
        VMResult::Ok(Value::Status(2101)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2101)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 67);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 65);
}

#[test]
fn subshell_end_exit_code_2101_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2101)));
    match vm.run() {
        VMResult::Ok(Value::Status(2101)) => {}
        other => panic!("exit code 2101 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2102Ex2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2102)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2102);
}

#[test]
fn subshell_end_exit_code_2102_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2102)));
    match vm.run() {
        VMResult::Ok(Value::Status(2102)) => {}
        other => panic!("exit code 2102 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2091() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2103)));
    for _ in 0..68 {
        match vm.run() {
            VMResult::Ok(Value::Status(2103)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2103_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2103)));
    match vm.run() {
        VMResult::Ok(Value::Status(2103)) => {}
        other => panic!("exit code 2103 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2104Ex2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2104)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2104);
}

#[test]
fn subshell_end_exit_code_2104_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2104)));
    match vm.run() {
        VMResult::Ok(Value::Status(2104)) => {}
        other => panic!("exit code 2104 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_one_end_incrementing_from_sevenEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..271 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 79 }));
    match vm.run() {
        VMResult::Ok(Value::Status(349)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(349)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2105_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2105)));
    match vm.run() {
        VMResult::Ok(Value::Status(2105)) => {}
        other => panic!("exit code 2105 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2106Ex2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2106)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2106);
}

#[test]
fn subshell_end_exit_code_2106_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2106)));
    match vm.run() {
        VMResult::Ok(Value::Status(2106)) => {}
        other => panic!("exit code 2106 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_three_hundred_ninety_nine_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..399 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2107_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2107)));
    match vm.run() {
        VMResult::Ok(Value::Status(2107)) => {}
        other => panic!("exit code 2107 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..143 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2091 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2091 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 143 {
                Some(2108)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2091 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2108)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2108)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2108_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2108)));
    match vm.run() {
        VMResult::Ok(Value::Status(2108)) => {}
        other => panic!("exit code 2108 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2109_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2109)));
    match vm.run() {
        VMResult::Ok(Value::Status(2109)) => {}
        other => panic!("exit code 2109 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2110Ex2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2110)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2110);
}

#[test]
fn subshell_end_exit_code_2110_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2110)));
    match vm.run() {
        VMResult::Ok(Value::Status(2110)) => {}
        other => panic!("exit code 2110 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_two_end_incrementing_from_oneEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..272 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 73 }));
    match vm.run() {
        VMResult::Ok(Value::Status(344)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(344)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2111_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2111)));
    match vm.run() {
        VMResult::Ok(Value::Status(2111)) => {}
        other => panic!("exit code 2111 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2112;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2112)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2112, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2112_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2112)));
    match vm.run() {
        VMResult::Ok(Value::Status(2112)) => {}
        other => panic!("exit code 2112 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2113,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2113)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2113), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2113_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2113)));
    match vm.run() {
        VMResult::Ok(Value::Status(2113)) => {}
        other => panic!("exit code 2113 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..400 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2114_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2114)));
    match vm.run() {
        VMResult::Ok(Value::Status(2114)) => {}
        other => panic!("exit code 2114 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..144 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2091 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2091 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 144 {
                Some(2115)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2091 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2115)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2115)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2115_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2115)));
    match vm.run() {
        VMResult::Ok(Value::Status(2115)) => {}
        other => panic!("exit code 2115 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2116Ex2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2116Ex2091;
    impl ShellHost for PipelineSubshellHost2116Ex2091 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2116)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2116Ex2091));
    match vm.run() {
        VMResult::Ok(Value::Status(2116)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2116_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2116)));
    match vm.run() {
        VMResult::Ok(Value::Status(2116)) => {}
        other => panic!("exit code 2116 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2117Ex2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2117Ex2091;
    impl ShellHost for SubshellThenPipelineHost2117Ex2091 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2117
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2117Ex2091));
    match vm.run() {
        VMResult::Ok(Value::Status(2117)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2117_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2117)));
    match vm.run() {
        VMResult::Ok(Value::Status(2117)) => {}
        other => panic!("exit code 2117 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-274)));
    match vm.run() {
        VMResult::Ok(Value::Status(-274)) => {}
        other => panic!("status -274 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2118_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2118)));
    match vm.run() {
        VMResult::Ok(Value::Status(2118)) => {}
        other => panic!("exit code 2118 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_three_end_incrementing_from_eightEx2091() {
    let mut b = ChunkBuilder::new();
    for _ in 0..273 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 80 }));
    match vm.run() {
        VMResult::Ok(Value::Status(352)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(352)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2119_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2119)));
    match vm.run() {
        VMResult::Ok(Value::Status(2119)) => {}
        other => panic!("exit code 2119 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_one_consecutive_runs_without_reset_still_blockedEx2091() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..401 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2120_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2120)));
    match vm.run() {
        VMResult::Ok(Value::Status(2120)) => {}
        other => panic!("exit code 2120 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2121Ex2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2121Ex2091 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2121Ex2091 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2121Ex2091 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2121_propagatesEx2091() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2121)));
    match vm.run() {
        VMResult::Ok(Value::Status(2121)) => {}
        other => panic!("exit code 2121 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BY (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2122_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2122)));
    match vm.run() {
        VMResult::Ok(Value::Status(2122)) => {}
        other => panic!("exit code 2122 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_two_consecutive_runs_without_reset_still_blockedEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..402 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2123_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2123)));
    match vm.run() {
        VMResult::Ok(Value::Status(2123)) => {}
        other => panic!("exit code 2123 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_three_consecutive_runs_without_reset_still_blockedEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..403 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2124_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2124)));
    match vm.run() {
        VMResult::Ok(Value::Status(2124)) => {}
        other => panic!("exit code 2124 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_four_consecutive_runs_without_reset_still_blockedEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..404 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2125_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2125)));
    match vm.run() {
        VMResult::Ok(Value::Status(2125)) => {}
        other => panic!("exit code 2125 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2126_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2126)));
    match vm.run() {
        VMResult::Ok(Value::Status(2126)) => {}
        other => panic!("exit code 2126 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-276)));
    match vm.run() {
        VMResult::Ok(Value::Status(-276)) => {}
        other => panic!("status -276 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2127_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2127)));
    match vm.run() {
        VMResult::Ok(Value::Status(2127)) => {}
        other => panic!("exit code 2127 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-277)));
    match vm.run() {
        VMResult::Ok(Value::Status(-277)) => {}
        other => panic!("status -277 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2128_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2128)));
    match vm.run() {
        VMResult::Ok(Value::Status(2128)) => {}
        other => panic!("exit code 2128 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..145 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2122 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2122 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 145 {
                Some(2129)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2122 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2129)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2129)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2129_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2129)));
    match vm.run() {
        VMResult::Ok(Value::Status(2129)) => {}
        other => panic!("exit code 2129 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2130)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..69 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 72);
    assert_eq!(vm.last_status, 2130);
}

#[test]
fn subshell_end_exit_code_2130_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2130)));
    match vm.run() {
        VMResult::Ok(Value::Status(2130)) => {}
        other => panic!("exit code 2130 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2131Ex2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2131)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2131);
}

#[test]
fn subshell_end_exit_code_2131_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2131)));
    match vm.run() {
        VMResult::Ok(Value::Status(2131)) => {}
        other => panic!("exit code 2131 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_eight_begins_sixty_six_ends_last_end_status_winsEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..68 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..66 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2132Ex2122;
    impl ShellHost for CountingBeginEndHost2132Ex2122 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2132)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2132Ex2122));
    match vm.run() {
        VMResult::Ok(Value::Status(2132)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2132)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 68);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 66);
}

#[test]
fn subshell_end_exit_code_2132_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2132)));
    match vm.run() {
        VMResult::Ok(Value::Status(2132)) => {}
        other => panic!("exit code 2132 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2133Ex2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2122;
    impl ShellHost for CountingBeginHost733Ex2122 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2133)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2122));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2133);
}

#[test]
fn subshell_end_exit_code_2133_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2133)));
    match vm.run() {
        VMResult::Ok(Value::Status(2133)) => {}
        other => panic!("exit code 2133 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2122() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2134)));
    for _ in 0..69 {
        match vm.run() {
            VMResult::Ok(Value::Status(2134)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2134_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2134)));
    match vm.run() {
        VMResult::Ok(Value::Status(2134)) => {}
        other => panic!("exit code 2134 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2135Ex2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2135)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2135);
}

#[test]
fn subshell_end_exit_code_2135_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2135)));
    match vm.run() {
        VMResult::Ok(Value::Status(2135)) => {}
        other => panic!("exit code 2135 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2136_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2136)));
    match vm.run() {
        VMResult::Ok(Value::Status(2136)) => {}
        other => panic!("exit code 2136 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2137Ex2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2137)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2137);
}

#[test]
fn subshell_end_exit_code_2137_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2137)));
    match vm.run() {
        VMResult::Ok(Value::Status(2137)) => {}
        other => panic!("exit code 2137 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_five_consecutive_runs_without_reset_still_blockedEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..405 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2138_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2138)));
    match vm.run() {
        VMResult::Ok(Value::Status(2138)) => {}
        other => panic!("exit code 2138 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_six_consecutive_runs_without_reset_still_blockedEx2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..406 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2139_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2139)));
    match vm.run() {
        VMResult::Ok(Value::Status(2139)) => {}
        other => panic!("exit code 2139 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2140_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2140)));
    match vm.run() {
        VMResult::Ok(Value::Status(2140)) => {}
        other => panic!("exit code 2140 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2141;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2141)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2141, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2141_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2141)));
    match vm.run() {
        VMResult::Ok(Value::Status(2141)) => {}
        other => panic!("exit code 2141 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2142,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2142)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2142), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2142_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2142)));
    match vm.run() {
        VMResult::Ok(Value::Status(2142)) => {}
        other => panic!("exit code 2142 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-278)));
    match vm.run() {
        VMResult::Ok(Value::Status(-278)) => {}
        other => panic!("status -278 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2143_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2143)));
    match vm.run() {
        VMResult::Ok(Value::Status(2143)) => {}
        other => panic!("exit code 2143 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_six_end_incrementing_from_fiveEx2122() {
    let mut b = ChunkBuilder::new();
    for _ in 0..276 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 80 }));
    match vm.run() {
        VMResult::Ok(Value::Status(355)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(355)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2144_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2144)));
    match vm.run() {
        VMResult::Ok(Value::Status(2144)) => {}
        other => panic!("exit code 2144 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2145Ex2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2145Ex2122 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2145Ex2122 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2145Ex2122 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2145_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2145)));
    match vm.run() {
        VMResult::Ok(Value::Status(2145)) => {}
        other => panic!("exit code 2145 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2146Ex2122() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2146)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2146);
}

#[test]
fn subshell_end_exit_code_2146_propagatesEx2122() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2146)));
    match vm.run() {
        VMResult::Ok(Value::Status(2146)) => {}
        other => panic!("exit code 2146 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch BZ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2147_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2147)));
    match vm.run() {
        VMResult::Ok(Value::Status(2147)) => {}
        other => panic!("exit code 2147 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seven_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..407 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2148_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2148)));
    match vm.run() {
        VMResult::Ok(Value::Status(2148)) => {}
        other => panic!("exit code 2148 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eight_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..408 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2149_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2149)));
    match vm.run() {
        VMResult::Ok(Value::Status(2149)) => {}
        other => panic!("exit code 2149 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_nine_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..409 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2150_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2150)));
    match vm.run() {
        VMResult::Ok(Value::Status(2150)) => {}
        other => panic!("exit code 2150 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_seven_end_incrementing_from_sixEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..277 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 81 }));
    match vm.run() {
        VMResult::Ok(Value::Status(357)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(357)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2151_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2151)));
    match vm.run() {
        VMResult::Ok(Value::Status(2151)) => {}
        other => panic!("exit code 2151 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-279)));
    match vm.run() {
        VMResult::Ok(Value::Status(-279)) => {}
        other => panic!("status -279 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2152_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2152)));
    match vm.run() {
        VMResult::Ok(Value::Status(2152)) => {}
        other => panic!("exit code 2152 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-280)));
    match vm.run() {
        VMResult::Ok(Value::Status(-280)) => {}
        other => panic!("status -280 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2153_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2153)));
    match vm.run() {
        VMResult::Ok(Value::Status(2153)) => {}
        other => panic!("exit code 2153 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..146 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2147 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2147 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 146 {
                Some(2154)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2147 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2154)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2154)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2154_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2154)));
    match vm.run() {
        VMResult::Ok(Value::Status(2154)) => {}
        other => panic!("exit code 2154 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2155)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..70 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 73);
    assert_eq!(vm.last_status, 2155);
}

#[test]
fn subshell_end_exit_code_2155_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2155)));
    match vm.run() {
        VMResult::Ok(Value::Status(2155)) => {}
        other => panic!("exit code 2155 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2156Ex2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2156)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2156);
}

#[test]
fn subshell_end_exit_code_2156_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2156)));
    match vm.run() {
        VMResult::Ok(Value::Status(2156)) => {}
        other => panic!("exit code 2156 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_sixty_nine_begins_sixty_seven_ends_last_end_status_winsEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..69 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..67 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2157Ex2147;
    impl ShellHost for CountingBeginEndHost2157Ex2147 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2157)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2157Ex2147));
    match vm.run() {
        VMResult::Ok(Value::Status(2157)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2157)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 69);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 67);
}

#[test]
fn subshell_end_exit_code_2157_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2157)));
    match vm.run() {
        VMResult::Ok(Value::Status(2157)) => {}
        other => panic!("exit code 2157 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2158Ex2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2158)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2158);
}

#[test]
fn subshell_end_exit_code_2158_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2158)));
    match vm.run() {
        VMResult::Ok(Value::Status(2158)) => {}
        other => panic!("exit code 2158 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2147() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2159)));
    for _ in 0..70 {
        match vm.run() {
            VMResult::Ok(Value::Status(2159)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2159_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2159)));
    match vm.run() {
        VMResult::Ok(Value::Status(2159)) => {}
        other => panic!("exit code 2159 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2160Ex2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2160)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2160);
}

#[test]
fn subshell_end_exit_code_2160_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2160)));
    match vm.run() {
        VMResult::Ok(Value::Status(2160)) => {}
        other => panic!("exit code 2160 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_eight_end_incrementing_from_sevenEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..278 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 82 }));
    match vm.run() {
        VMResult::Ok(Value::Status(359)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(359)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2161_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2161)));
    match vm.run() {
        VMResult::Ok(Value::Status(2161)) => {}
        other => panic!("exit code 2161 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2162Ex2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2162)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2162);
}

#[test]
fn subshell_end_exit_code_2162_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2162)));
    match vm.run() {
        VMResult::Ok(Value::Status(2162)) => {}
        other => panic!("exit code 2162 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ten_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..410 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2163_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2163)));
    match vm.run() {
        VMResult::Ok(Value::Status(2163)) => {}
        other => panic!("exit code 2163 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..147 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2147 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2147 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 147 {
                Some(2164)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2147 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2164)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2164)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2164_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2164)));
    match vm.run() {
        VMResult::Ok(Value::Status(2164)) => {}
        other => panic!("exit code 2164 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2165_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2165)));
    match vm.run() {
        VMResult::Ok(Value::Status(2165)) => {}
        other => panic!("exit code 2165 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2166Ex2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2166)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2166);
}

#[test]
fn subshell_end_exit_code_2166_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2166)));
    match vm.run() {
        VMResult::Ok(Value::Status(2166)) => {}
        other => panic!("exit code 2166 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_seventy_nine_end_incrementing_from_oneEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..279 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 76 }));
    match vm.run() {
        VMResult::Ok(Value::Status(354)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(354)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2167_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2167)));
    match vm.run() {
        VMResult::Ok(Value::Status(2167)) => {}
        other => panic!("exit code 2167 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2168;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2168)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2168, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2168_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2168)));
    match vm.run() {
        VMResult::Ok(Value::Status(2168)) => {}
        other => panic!("exit code 2168 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2169,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2169)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2169), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2169_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2169)));
    match vm.run() {
        VMResult::Ok(Value::Status(2169)) => {}
        other => panic!("exit code 2169 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eleven_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..411 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2170_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2170)));
    match vm.run() {
        VMResult::Ok(Value::Status(2170)) => {}
        other => panic!("exit code 2170 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..148 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2147 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2147 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 148 {
                Some(2171)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2147 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2171)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2171)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2171_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2171)));
    match vm.run() {
        VMResult::Ok(Value::Status(2171)) => {}
        other => panic!("exit code 2171 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2172Ex2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2172Ex2147;
    impl ShellHost for PipelineSubshellHost2172Ex2147 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2172)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2172Ex2147));
    match vm.run() {
        VMResult::Ok(Value::Status(2172)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2172_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2172)));
    match vm.run() {
        VMResult::Ok(Value::Status(2172)) => {}
        other => panic!("exit code 2172 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2173Ex2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2173Ex2147;
    impl ShellHost for SubshellThenPipelineHost2173Ex2147 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2173
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2173Ex2147));
    match vm.run() {
        VMResult::Ok(Value::Status(2173)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2173_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2173)));
    match vm.run() {
        VMResult::Ok(Value::Status(2173)) => {}
        other => panic!("exit code 2173 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-281)));
    match vm.run() {
        VMResult::Ok(Value::Status(-281)) => {}
        other => panic!("status -281 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2174_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2174)));
    match vm.run() {
        VMResult::Ok(Value::Status(2174)) => {}
        other => panic!("exit code 2174 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_end_incrementing_from_eightEx2147() {
    let mut b = ChunkBuilder::new();
    for _ in 0..280 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 83 }));
    match vm.run() {
        VMResult::Ok(Value::Status(362)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(362)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2175_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2175)));
    match vm.run() {
        VMResult::Ok(Value::Status(2175)) => {}
        other => panic!("exit code 2175 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twelve_consecutive_runs_without_reset_still_blockedEx2147() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..412 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2176_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2176)));
    match vm.run() {
        VMResult::Ok(Value::Status(2176)) => {}
        other => panic!("exit code 2176 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2177Ex2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2177Ex2147 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2177Ex2147 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2177Ex2147 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2177_propagatesEx2147() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2177)));
    match vm.run() {
        VMResult::Ok(Value::Status(2177)) => {}
        other => panic!("exit code 2177 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CA (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2178_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2178)));
    match vm.run() {
        VMResult::Ok(Value::Status(2178)) => {}
        other => panic!("exit code 2178 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirteen_consecutive_runs_without_reset_still_blockedEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..413 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2179_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2179)));
    match vm.run() {
        VMResult::Ok(Value::Status(2179)) => {}
        other => panic!("exit code 2179 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fourteen_consecutive_runs_without_reset_still_blockedEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..414 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2180_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2180)));
    match vm.run() {
        VMResult::Ok(Value::Status(2180)) => {}
        other => panic!("exit code 2180 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifteen_consecutive_runs_without_reset_still_blockedEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..415 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2181_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2181)));
    match vm.run() {
        VMResult::Ok(Value::Status(2181)) => {}
        other => panic!("exit code 2181 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2182_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2182)));
    match vm.run() {
        VMResult::Ok(Value::Status(2182)) => {}
        other => panic!("exit code 2182 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-283)));
    match vm.run() {
        VMResult::Ok(Value::Status(-283)) => {}
        other => panic!("status -283 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2183_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2183)));
    match vm.run() {
        VMResult::Ok(Value::Status(2183)) => {}
        other => panic!("exit code 2183 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-284)));
    match vm.run() {
        VMResult::Ok(Value::Status(-284)) => {}
        other => panic!("status -284 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2184_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2184)));
    match vm.run() {
        VMResult::Ok(Value::Status(2184)) => {}
        other => panic!("exit code 2184 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..149 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2178 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2178 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 149 {
                Some(2185)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2178 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2185)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2185)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2185_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2185)));
    match vm.run() {
        VMResult::Ok(Value::Status(2185)) => {}
        other => panic!("exit code 2185 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2186)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..71 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 74);
    assert_eq!(vm.last_status, 2186);
}

#[test]
fn subshell_end_exit_code_2186_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2186)));
    match vm.run() {
        VMResult::Ok(Value::Status(2186)) => {}
        other => panic!("exit code 2186 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2187Ex2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2187)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2187);
}

#[test]
fn subshell_end_exit_code_2187_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2187)));
    match vm.run() {
        VMResult::Ok(Value::Status(2187)) => {}
        other => panic!("exit code 2187 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_begins_sixty_eight_ends_last_end_status_winsEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..70 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..68 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2188Ex2178;
    impl ShellHost for CountingBeginEndHost2188Ex2178 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2188)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2188Ex2178));
    match vm.run() {
        VMResult::Ok(Value::Status(2188)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2188)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 70);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 68);
}

#[test]
fn subshell_end_exit_code_2188_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2188)));
    match vm.run() {
        VMResult::Ok(Value::Status(2188)) => {}
        other => panic!("exit code 2188 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2189Ex2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2178;
    impl ShellHost for CountingBeginHost733Ex2178 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2189)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2178));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2189);
}

#[test]
fn subshell_end_exit_code_2189_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2189)));
    match vm.run() {
        VMResult::Ok(Value::Status(2189)) => {}
        other => panic!("exit code 2189 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2178() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2190)));
    for _ in 0..71 {
        match vm.run() {
            VMResult::Ok(Value::Status(2190)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2190_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2190)));
    match vm.run() {
        VMResult::Ok(Value::Status(2190)) => {}
        other => panic!("exit code 2190 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2191Ex2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2191)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2191);
}

#[test]
fn subshell_end_exit_code_2191_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2191)));
    match vm.run() {
        VMResult::Ok(Value::Status(2191)) => {}
        other => panic!("exit code 2191 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2192_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2192)));
    match vm.run() {
        VMResult::Ok(Value::Status(2192)) => {}
        other => panic!("exit code 2192 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2193Ex2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2193)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2193);
}

#[test]
fn subshell_end_exit_code_2193_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2193)));
    match vm.run() {
        VMResult::Ok(Value::Status(2193)) => {}
        other => panic!("exit code 2193 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixteen_consecutive_runs_without_reset_still_blockedEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..416 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2194_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2194)));
    match vm.run() {
        VMResult::Ok(Value::Status(2194)) => {}
        other => panic!("exit code 2194 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventeen_consecutive_runs_without_reset_still_blockedEx2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..417 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2195_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2195)));
    match vm.run() {
        VMResult::Ok(Value::Status(2195)) => {}
        other => panic!("exit code 2195 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2196_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2196)));
    match vm.run() {
        VMResult::Ok(Value::Status(2196)) => {}
        other => panic!("exit code 2196 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2197;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2197)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2197, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2197_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2197)));
    match vm.run() {
        VMResult::Ok(Value::Status(2197)) => {}
        other => panic!("exit code 2197 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2198,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2198)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2198), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2198_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2198)));
    match vm.run() {
        VMResult::Ok(Value::Status(2198)) => {}
        other => panic!("exit code 2198 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-285)));
    match vm.run() {
        VMResult::Ok(Value::Status(-285)) => {}
        other => panic!("status -285 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2199_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2199)));
    match vm.run() {
        VMResult::Ok(Value::Status(2199)) => {}
        other => panic!("exit code 2199 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_three_end_incrementing_from_fiveEx2178() {
    let mut b = ChunkBuilder::new();
    for _ in 0..283 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 83 }));
    match vm.run() {
        VMResult::Ok(Value::Status(365)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(365)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2200_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2200)));
    match vm.run() {
        VMResult::Ok(Value::Status(2200)) => {}
        other => panic!("exit code 2200 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2201Ex2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2201Ex2178 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2201Ex2178 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2201Ex2178 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2201_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2201)));
    match vm.run() {
        VMResult::Ok(Value::Status(2201)) => {}
        other => panic!("exit code 2201 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2202Ex2178() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2202)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2202);
}

#[test]
fn subshell_end_exit_code_2202_propagatesEx2178() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2202)));
    match vm.run() {
        VMResult::Ok(Value::Status(2202)) => {}
        other => panic!("exit code 2202 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CB (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2203_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2203)));
    match vm.run() {
        VMResult::Ok(Value::Status(2203)) => {}
        other => panic!("exit code 2203 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighteen_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..418 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2204_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2204)));
    match vm.run() {
        VMResult::Ok(Value::Status(2204)) => {}
        other => panic!("exit code 2204 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_nineteen_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..419 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2205_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2205)));
    match vm.run() {
        VMResult::Ok(Value::Status(2205)) => {}
        other => panic!("exit code 2205 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..420 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2206_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2206)));
    match vm.run() {
        VMResult::Ok(Value::Status(2206)) => {}
        other => panic!("exit code 2206 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_four_end_incrementing_from_sixEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..284 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 84 }));
    match vm.run() {
        VMResult::Ok(Value::Status(367)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(367)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2207_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2207)));
    match vm.run() {
        VMResult::Ok(Value::Status(2207)) => {}
        other => panic!("exit code 2207 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-286)));
    match vm.run() {
        VMResult::Ok(Value::Status(-286)) => {}
        other => panic!("status -286 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2208_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2208)));
    match vm.run() {
        VMResult::Ok(Value::Status(2208)) => {}
        other => panic!("exit code 2208 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-287)));
    match vm.run() {
        VMResult::Ok(Value::Status(-287)) => {}
        other => panic!("status -287 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2209_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2209)));
    match vm.run() {
        VMResult::Ok(Value::Status(2209)) => {}
        other => panic!("exit code 2209 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..150 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2203 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2203 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 150 {
                Some(2210)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2203 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2210)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2210)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2210_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2210)));
    match vm.run() {
        VMResult::Ok(Value::Status(2210)) => {}
        other => panic!("exit code 2210 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2211)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..72 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 75);
    assert_eq!(vm.last_status, 2211);
}

#[test]
fn subshell_end_exit_code_2211_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2211)));
    match vm.run() {
        VMResult::Ok(Value::Status(2211)) => {}
        other => panic!("exit code 2211 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2212Ex2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2212)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2212);
}

#[test]
fn subshell_end_exit_code_2212_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2212)));
    match vm.run() {
        VMResult::Ok(Value::Status(2212)) => {}
        other => panic!("exit code 2212 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_one_begins_sixty_nine_ends_last_end_status_winsEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..71 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..69 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2213Ex2203;
    impl ShellHost for CountingBeginEndHost2213Ex2203 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2213)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2213Ex2203));
    match vm.run() {
        VMResult::Ok(Value::Status(2213)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2213)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 71);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 69);
}

#[test]
fn subshell_end_exit_code_2213_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2213)));
    match vm.run() {
        VMResult::Ok(Value::Status(2213)) => {}
        other => panic!("exit code 2213 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2214Ex2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2214)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2214);
}

#[test]
fn subshell_end_exit_code_2214_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2214)));
    match vm.run() {
        VMResult::Ok(Value::Status(2214)) => {}
        other => panic!("exit code 2214 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2203() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2215)));
    for _ in 0..72 {
        match vm.run() {
            VMResult::Ok(Value::Status(2215)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2215_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2215)));
    match vm.run() {
        VMResult::Ok(Value::Status(2215)) => {}
        other => panic!("exit code 2215 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2216Ex2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2216)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2216);
}

#[test]
fn subshell_end_exit_code_2216_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2216)));
    match vm.run() {
        VMResult::Ok(Value::Status(2216)) => {}
        other => panic!("exit code 2216 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_five_end_incrementing_from_sevenEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..285 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 85 }));
    match vm.run() {
        VMResult::Ok(Value::Status(369)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(369)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2217_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2217)));
    match vm.run() {
        VMResult::Ok(Value::Status(2217)) => {}
        other => panic!("exit code 2217 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2218Ex2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2218)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2218);
}

#[test]
fn subshell_end_exit_code_2218_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2218)));
    match vm.run() {
        VMResult::Ok(Value::Status(2218)) => {}
        other => panic!("exit code 2218 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_one_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..421 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2219_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2219)));
    match vm.run() {
        VMResult::Ok(Value::Status(2219)) => {}
        other => panic!("exit code 2219 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..151 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2203 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2203 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 151 {
                Some(2220)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2203 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2220)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2220)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2220_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2220)));
    match vm.run() {
        VMResult::Ok(Value::Status(2220)) => {}
        other => panic!("exit code 2220 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2221_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2221)));
    match vm.run() {
        VMResult::Ok(Value::Status(2221)) => {}
        other => panic!("exit code 2221 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2222Ex2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2222)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2222);
}

#[test]
fn subshell_end_exit_code_2222_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2222)));
    match vm.run() {
        VMResult::Ok(Value::Status(2222)) => {}
        other => panic!("exit code 2222 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_six_end_incrementing_from_oneEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..286 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 79 }));
    match vm.run() {
        VMResult::Ok(Value::Status(364)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(364)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2223_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2223)));
    match vm.run() {
        VMResult::Ok(Value::Status(2223)) => {}
        other => panic!("exit code 2223 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2224;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2224)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2224, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2224_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2224)));
    match vm.run() {
        VMResult::Ok(Value::Status(2224)) => {}
        other => panic!("exit code 2224 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2225,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2225)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2225), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2225_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2225)));
    match vm.run() {
        VMResult::Ok(Value::Status(2225)) => {}
        other => panic!("exit code 2225 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_two_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..422 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2226_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2226)));
    match vm.run() {
        VMResult::Ok(Value::Status(2226)) => {}
        other => panic!("exit code 2226 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..152 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2203 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2203 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 152 {
                Some(2227)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2203 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2227)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2227)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2227_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2227)));
    match vm.run() {
        VMResult::Ok(Value::Status(2227)) => {}
        other => panic!("exit code 2227 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2228Ex2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2228Ex2203;
    impl ShellHost for PipelineSubshellHost2228Ex2203 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2228)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2228Ex2203));
    match vm.run() {
        VMResult::Ok(Value::Status(2228)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2228_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2228)));
    match vm.run() {
        VMResult::Ok(Value::Status(2228)) => {}
        other => panic!("exit code 2228 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2229Ex2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2229Ex2203;
    impl ShellHost for SubshellThenPipelineHost2229Ex2203 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2229
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2229Ex2203));
    match vm.run() {
        VMResult::Ok(Value::Status(2229)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2229_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2229)));
    match vm.run() {
        VMResult::Ok(Value::Status(2229)) => {}
        other => panic!("exit code 2229 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-288)));
    match vm.run() {
        VMResult::Ok(Value::Status(-288)) => {}
        other => panic!("status -288 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2230_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2230)));
    match vm.run() {
        VMResult::Ok(Value::Status(2230)) => {}
        other => panic!("exit code 2230 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_eighty_seven_end_incrementing_from_eightEx2203() {
    let mut b = ChunkBuilder::new();
    for _ in 0..287 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 86 }));
    match vm.run() {
        VMResult::Ok(Value::Status(372)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(372)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2231_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2231)));
    match vm.run() {
        VMResult::Ok(Value::Status(2231)) => {}
        other => panic!("exit code 2231 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_three_consecutive_runs_without_reset_still_blockedEx2203() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..423 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2232_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2232)));
    match vm.run() {
        VMResult::Ok(Value::Status(2232)) => {}
        other => panic!("exit code 2232 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2233Ex2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2233Ex2203 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2233Ex2203 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2233Ex2203 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2233_propagatesEx2203() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2233)));
    match vm.run() {
        VMResult::Ok(Value::Status(2233)) => {}
        other => panic!("exit code 2233 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CC (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2234_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2234)));
    match vm.run() {
        VMResult::Ok(Value::Status(2234)) => {}
        other => panic!("exit code 2234 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_four_consecutive_runs_without_reset_still_blockedEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..424 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2235_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2235)));
    match vm.run() {
        VMResult::Ok(Value::Status(2235)) => {}
        other => panic!("exit code 2235 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_five_consecutive_runs_without_reset_still_blockedEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..425 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2236_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2236)));
    match vm.run() {
        VMResult::Ok(Value::Status(2236)) => {}
        other => panic!("exit code 2236 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_six_consecutive_runs_without_reset_still_blockedEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..426 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2237_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2237)));
    match vm.run() {
        VMResult::Ok(Value::Status(2237)) => {}
        other => panic!("exit code 2237 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2238_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2238)));
    match vm.run() {
        VMResult::Ok(Value::Status(2238)) => {}
        other => panic!("exit code 2238 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-290)));
    match vm.run() {
        VMResult::Ok(Value::Status(-290)) => {}
        other => panic!("status -290 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2239_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2239)));
    match vm.run() {
        VMResult::Ok(Value::Status(2239)) => {}
        other => panic!("exit code 2239 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-291)));
    match vm.run() {
        VMResult::Ok(Value::Status(-291)) => {}
        other => panic!("status -291 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2240_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2240)));
    match vm.run() {
        VMResult::Ok(Value::Status(2240)) => {}
        other => panic!("exit code 2240 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..153 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2234 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2234 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 153 {
                Some(2241)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2234 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2241)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2241)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2241_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2241)));
    match vm.run() {
        VMResult::Ok(Value::Status(2241)) => {}
        other => panic!("exit code 2241 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2242)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..73 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 76);
    assert_eq!(vm.last_status, 2242);
}

#[test]
fn subshell_end_exit_code_2242_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2242)));
    match vm.run() {
        VMResult::Ok(Value::Status(2242)) => {}
        other => panic!("exit code 2242 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2243Ex2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2243)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2243);
}

#[test]
fn subshell_end_exit_code_2243_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2243)));
    match vm.run() {
        VMResult::Ok(Value::Status(2243)) => {}
        other => panic!("exit code 2243 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_two_begins_seventy_ends_last_end_status_winsEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..72 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..70 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2244Ex2234;
    impl ShellHost for CountingBeginEndHost2244Ex2234 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2244)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2244Ex2234));
    match vm.run() {
        VMResult::Ok(Value::Status(2244)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2244)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 72);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 70);
}

#[test]
fn subshell_end_exit_code_2244_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2244)));
    match vm.run() {
        VMResult::Ok(Value::Status(2244)) => {}
        other => panic!("exit code 2244 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2245Ex2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2234;
    impl ShellHost for CountingBeginHost733Ex2234 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2245)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2234));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2245);
}

#[test]
fn subshell_end_exit_code_2245_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2245)));
    match vm.run() {
        VMResult::Ok(Value::Status(2245)) => {}
        other => panic!("exit code 2245 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2234() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2246)));
    for _ in 0..73 {
        match vm.run() {
            VMResult::Ok(Value::Status(2246)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2246_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2246)));
    match vm.run() {
        VMResult::Ok(Value::Status(2246)) => {}
        other => panic!("exit code 2246 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2247Ex2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2247)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2247);
}

#[test]
fn subshell_end_exit_code_2247_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2247)));
    match vm.run() {
        VMResult::Ok(Value::Status(2247)) => {}
        other => panic!("exit code 2247 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2248_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2248)));
    match vm.run() {
        VMResult::Ok(Value::Status(2248)) => {}
        other => panic!("exit code 2248 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2249Ex2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2249)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2249);
}

#[test]
fn subshell_end_exit_code_2249_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2249)));
    match vm.run() {
        VMResult::Ok(Value::Status(2249)) => {}
        other => panic!("exit code 2249 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_seven_consecutive_runs_without_reset_still_blockedEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..427 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2250_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2250)));
    match vm.run() {
        VMResult::Ok(Value::Status(2250)) => {}
        other => panic!("exit code 2250 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_eight_consecutive_runs_without_reset_still_blockedEx2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..428 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2251_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2251)));
    match vm.run() {
        VMResult::Ok(Value::Status(2251)) => {}
        other => panic!("exit code 2251 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2252_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2252)));
    match vm.run() {
        VMResult::Ok(Value::Status(2252)) => {}
        other => panic!("exit code 2252 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2253;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2253)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2253, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2253_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2253)));
    match vm.run() {
        VMResult::Ok(Value::Status(2253)) => {}
        other => panic!("exit code 2253 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2254,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2254)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2254), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2254_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2254)));
    match vm.run() {
        VMResult::Ok(Value::Status(2254)) => {}
        other => panic!("exit code 2254 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-292)));
    match vm.run() {
        VMResult::Ok(Value::Status(-292)) => {}
        other => panic!("status -292 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2255_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2255)));
    match vm.run() {
        VMResult::Ok(Value::Status(2255)) => {}
        other => panic!("exit code 2255 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_end_incrementing_from_fiveEx2234() {
    let mut b = ChunkBuilder::new();
    for _ in 0..290 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 86 }));
    match vm.run() {
        VMResult::Ok(Value::Status(375)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(375)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2256_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2256)));
    match vm.run() {
        VMResult::Ok(Value::Status(2256)) => {}
        other => panic!("exit code 2256 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2257Ex2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2257Ex2234 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2257Ex2234 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2257Ex2234 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2257_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2257)));
    match vm.run() {
        VMResult::Ok(Value::Status(2257)) => {}
        other => panic!("exit code 2257 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2258Ex2234() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2258)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2258);
}

#[test]
fn subshell_end_exit_code_2258_propagatesEx2234() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2258)));
    match vm.run() {
        VMResult::Ok(Value::Status(2258)) => {}
        other => panic!("exit code 2258 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CD (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2259_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2259)));
    match vm.run() {
        VMResult::Ok(Value::Status(2259)) => {}
        other => panic!("exit code 2259 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_twenty_nine_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..429 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2260_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2260)));
    match vm.run() {
        VMResult::Ok(Value::Status(2260)) => {}
        other => panic!("exit code 2260 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..430 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2261_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2261)));
    match vm.run() {
        VMResult::Ok(Value::Status(2261)) => {}
        other => panic!("exit code 2261 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_one_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..431 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2262_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2262)));
    match vm.run() {
        VMResult::Ok(Value::Status(2262)) => {}
        other => panic!("exit code 2262 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_one_end_incrementing_from_sixEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..291 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 87 }));
    match vm.run() {
        VMResult::Ok(Value::Status(377)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(377)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2263_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2263)));
    match vm.run() {
        VMResult::Ok(Value::Status(2263)) => {}
        other => panic!("exit code 2263 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-293)));
    match vm.run() {
        VMResult::Ok(Value::Status(-293)) => {}
        other => panic!("status -293 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2264_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2264)));
    match vm.run() {
        VMResult::Ok(Value::Status(2264)) => {}
        other => panic!("exit code 2264 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-294)));
    match vm.run() {
        VMResult::Ok(Value::Status(-294)) => {}
        other => panic!("status -294 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2265_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2265)));
    match vm.run() {
        VMResult::Ok(Value::Status(2265)) => {}
        other => panic!("exit code 2265 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..154 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2259 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2259 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 154 {
                Some(2266)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2259 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2266)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2266)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2266_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2266)));
    match vm.run() {
        VMResult::Ok(Value::Status(2266)) => {}
        other => panic!("exit code 2266 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2267)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..74 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 77);
    assert_eq!(vm.last_status, 2267);
}

#[test]
fn subshell_end_exit_code_2267_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2267)));
    match vm.run() {
        VMResult::Ok(Value::Status(2267)) => {}
        other => panic!("exit code 2267 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2268Ex2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2268)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2268);
}

#[test]
fn subshell_end_exit_code_2268_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2268)));
    match vm.run() {
        VMResult::Ok(Value::Status(2268)) => {}
        other => panic!("exit code 2268 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_three_begins_seventy_one_ends_last_end_status_winsEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..73 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..71 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2269Ex2259;
    impl ShellHost for CountingBeginEndHost2269Ex2259 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2269)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2269Ex2259));
    match vm.run() {
        VMResult::Ok(Value::Status(2269)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2269)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 73);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 71);
}

#[test]
fn subshell_end_exit_code_2269_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2269)));
    match vm.run() {
        VMResult::Ok(Value::Status(2269)) => {}
        other => panic!("exit code 2269 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2270Ex2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2270)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2270);
}

#[test]
fn subshell_end_exit_code_2270_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2270)));
    match vm.run() {
        VMResult::Ok(Value::Status(2270)) => {}
        other => panic!("exit code 2270 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2259() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2271)));
    for _ in 0..74 {
        match vm.run() {
            VMResult::Ok(Value::Status(2271)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2271_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2271)));
    match vm.run() {
        VMResult::Ok(Value::Status(2271)) => {}
        other => panic!("exit code 2271 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2272Ex2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2272)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2272);
}

#[test]
fn subshell_end_exit_code_2272_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2272)));
    match vm.run() {
        VMResult::Ok(Value::Status(2272)) => {}
        other => panic!("exit code 2272 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_two_end_incrementing_from_sevenEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..292 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 88 }));
    match vm.run() {
        VMResult::Ok(Value::Status(379)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(379)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2273_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2273)));
    match vm.run() {
        VMResult::Ok(Value::Status(2273)) => {}
        other => panic!("exit code 2273 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2274Ex2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2274)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2274);
}

#[test]
fn subshell_end_exit_code_2274_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2274)));
    match vm.run() {
        VMResult::Ok(Value::Status(2274)) => {}
        other => panic!("exit code 2274 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_two_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..432 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2275_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2275)));
    match vm.run() {
        VMResult::Ok(Value::Status(2275)) => {}
        other => panic!("exit code 2275 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..155 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2259 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2259 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 155 {
                Some(2276)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2259 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2276)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2276)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2276_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2276)));
    match vm.run() {
        VMResult::Ok(Value::Status(2276)) => {}
        other => panic!("exit code 2276 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2277_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2277)));
    match vm.run() {
        VMResult::Ok(Value::Status(2277)) => {}
        other => panic!("exit code 2277 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2278Ex2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2278)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2278);
}

#[test]
fn subshell_end_exit_code_2278_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2278)));
    match vm.run() {
        VMResult::Ok(Value::Status(2278)) => {}
        other => panic!("exit code 2278 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_three_end_incrementing_from_oneEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..293 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 82 }));
    match vm.run() {
        VMResult::Ok(Value::Status(374)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(374)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2279_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2279)));
    match vm.run() {
        VMResult::Ok(Value::Status(2279)) => {}
        other => panic!("exit code 2279 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2280;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2280)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2280, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2280_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2280)));
    match vm.run() {
        VMResult::Ok(Value::Status(2280)) => {}
        other => panic!("exit code 2280 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2281,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2281)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2281), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2281_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2281)));
    match vm.run() {
        VMResult::Ok(Value::Status(2281)) => {}
        other => panic!("exit code 2281 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_three_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..433 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2282_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2282)));
    match vm.run() {
        VMResult::Ok(Value::Status(2282)) => {}
        other => panic!("exit code 2282 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..156 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2259 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2259 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 156 {
                Some(2283)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2259 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2283)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2283)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2283_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2283)));
    match vm.run() {
        VMResult::Ok(Value::Status(2283)) => {}
        other => panic!("exit code 2283 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2284Ex2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2284Ex2259;
    impl ShellHost for PipelineSubshellHost2284Ex2259 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2284)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2284Ex2259));
    match vm.run() {
        VMResult::Ok(Value::Status(2284)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2284_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2284)));
    match vm.run() {
        VMResult::Ok(Value::Status(2284)) => {}
        other => panic!("exit code 2284 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2285Ex2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2285Ex2259;
    impl ShellHost for SubshellThenPipelineHost2285Ex2259 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2285
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2285Ex2259));
    match vm.run() {
        VMResult::Ok(Value::Status(2285)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2285_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2285)));
    match vm.run() {
        VMResult::Ok(Value::Status(2285)) => {}
        other => panic!("exit code 2285 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-295)));
    match vm.run() {
        VMResult::Ok(Value::Status(-295)) => {}
        other => panic!("status -295 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2286_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2286)));
    match vm.run() {
        VMResult::Ok(Value::Status(2286)) => {}
        other => panic!("exit code 2286 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_four_end_incrementing_from_eightEx2259() {
    let mut b = ChunkBuilder::new();
    for _ in 0..294 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 89 }));
    match vm.run() {
        VMResult::Ok(Value::Status(382)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(382)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2287_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2287)));
    match vm.run() {
        VMResult::Ok(Value::Status(2287)) => {}
        other => panic!("exit code 2287 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_four_consecutive_runs_without_reset_still_blockedEx2259() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..434 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2288_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2288)));
    match vm.run() {
        VMResult::Ok(Value::Status(2288)) => {}
        other => panic!("exit code 2288 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2289Ex2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2289Ex2259 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2289Ex2259 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2289Ex2259 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2289_propagatesEx2259() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2289)));
    match vm.run() {
        VMResult::Ok(Value::Status(2289)) => {}
        other => panic!("exit code 2289 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CE (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2290_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2290)));
    match vm.run() {
        VMResult::Ok(Value::Status(2290)) => {}
        other => panic!("exit code 2290 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_five_consecutive_runs_without_reset_still_blockedEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..435 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2291_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2291)));
    match vm.run() {
        VMResult::Ok(Value::Status(2291)) => {}
        other => panic!("exit code 2291 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_six_consecutive_runs_without_reset_still_blockedEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..436 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2292_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2292)));
    match vm.run() {
        VMResult::Ok(Value::Status(2292)) => {}
        other => panic!("exit code 2292 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_seven_consecutive_runs_without_reset_still_blockedEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..437 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2293_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2293)));
    match vm.run() {
        VMResult::Ok(Value::Status(2293)) => {}
        other => panic!("exit code 2293 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2294_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2294)));
    match vm.run() {
        VMResult::Ok(Value::Status(2294)) => {}
        other => panic!("exit code 2294 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-297)));
    match vm.run() {
        VMResult::Ok(Value::Status(-297)) => {}
        other => panic!("status -297 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2295_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2295)));
    match vm.run() {
        VMResult::Ok(Value::Status(2295)) => {}
        other => panic!("exit code 2295 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-298)));
    match vm.run() {
        VMResult::Ok(Value::Status(-298)) => {}
        other => panic!("status -298 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2296_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2296)));
    match vm.run() {
        VMResult::Ok(Value::Status(2296)) => {}
        other => panic!("exit code 2296 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..157 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2290 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2290 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 157 {
                Some(2297)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2290 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2297)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2297)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2297_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2297)));
    match vm.run() {
        VMResult::Ok(Value::Status(2297)) => {}
        other => panic!("exit code 2297 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2298)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..75 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 78);
    assert_eq!(vm.last_status, 2298);
}

#[test]
fn subshell_end_exit_code_2298_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2298)));
    match vm.run() {
        VMResult::Ok(Value::Status(2298)) => {}
        other => panic!("exit code 2298 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2299Ex2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2299)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2299);
}

#[test]
fn subshell_end_exit_code_2299_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2299)));
    match vm.run() {
        VMResult::Ok(Value::Status(2299)) => {}
        other => panic!("exit code 2299 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_four_begins_seventy_two_ends_last_end_status_winsEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..74 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..72 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2300Ex2290;
    impl ShellHost for CountingBeginEndHost2300Ex2290 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2300)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2300Ex2290));
    match vm.run() {
        VMResult::Ok(Value::Status(2300)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2300)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 74);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 72);
}

#[test]
fn subshell_end_exit_code_2300_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2300)));
    match vm.run() {
        VMResult::Ok(Value::Status(2300)) => {}
        other => panic!("exit code 2300 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2301Ex2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2290;
    impl ShellHost for CountingBeginHost733Ex2290 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2301)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2290));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2301);
}

#[test]
fn subshell_end_exit_code_2301_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2301)));
    match vm.run() {
        VMResult::Ok(Value::Status(2301)) => {}
        other => panic!("exit code 2301 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2290() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2302)));
    for _ in 0..75 {
        match vm.run() {
            VMResult::Ok(Value::Status(2302)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2302_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2302)));
    match vm.run() {
        VMResult::Ok(Value::Status(2302)) => {}
        other => panic!("exit code 2302 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2303Ex2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2303)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2303);
}

#[test]
fn subshell_end_exit_code_2303_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2303)));
    match vm.run() {
        VMResult::Ok(Value::Status(2303)) => {}
        other => panic!("exit code 2303 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2304_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2304)));
    match vm.run() {
        VMResult::Ok(Value::Status(2304)) => {}
        other => panic!("exit code 2304 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2305Ex2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2305)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2305);
}

#[test]
fn subshell_end_exit_code_2305_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2305)));
    match vm.run() {
        VMResult::Ok(Value::Status(2305)) => {}
        other => panic!("exit code 2305 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_eight_consecutive_runs_without_reset_still_blockedEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..438 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2306_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2306)));
    match vm.run() {
        VMResult::Ok(Value::Status(2306)) => {}
        other => panic!("exit code 2306 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_thirty_nine_consecutive_runs_without_reset_still_blockedEx2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..439 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2307_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2307)));
    match vm.run() {
        VMResult::Ok(Value::Status(2307)) => {}
        other => panic!("exit code 2307 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2308_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2308)));
    match vm.run() {
        VMResult::Ok(Value::Status(2308)) => {}
        other => panic!("exit code 2308 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2309;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2309)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2309, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2309_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2309)));
    match vm.run() {
        VMResult::Ok(Value::Status(2309)) => {}
        other => panic!("exit code 2309 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2310,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2310)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2310), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2310_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2310)));
    match vm.run() {
        VMResult::Ok(Value::Status(2310)) => {}
        other => panic!("exit code 2310 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-299)));
    match vm.run() {
        VMResult::Ok(Value::Status(-299)) => {}
        other => panic!("status -299 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2311_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2311)));
    match vm.run() {
        VMResult::Ok(Value::Status(2311)) => {}
        other => panic!("exit code 2311 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_seven_end_incrementing_from_fiveEx2290() {
    let mut b = ChunkBuilder::new();
    for _ in 0..297 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 89 }));
    match vm.run() {
        VMResult::Ok(Value::Status(385)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(385)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2312_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2312)));
    match vm.run() {
        VMResult::Ok(Value::Status(2312)) => {}
        other => panic!("exit code 2312 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2313Ex2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2313Ex2290 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2313Ex2290 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2313Ex2290 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2313_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2313)));
    match vm.run() {
        VMResult::Ok(Value::Status(2313)) => {}
        other => panic!("exit code 2313 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2314Ex2290() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2314)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2314);
}

#[test]
fn subshell_end_exit_code_2314_propagatesEx2290() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2314)));
    match vm.run() {
        VMResult::Ok(Value::Status(2314)) => {}
        other => panic!("exit code 2314 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CF (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2315_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2315)));
    match vm.run() {
        VMResult::Ok(Value::Status(2315)) => {}
        other => panic!("exit code 2315 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..440 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2316_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2316)));
    match vm.run() {
        VMResult::Ok(Value::Status(2316)) => {}
        other => panic!("exit code 2316 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_one_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..441 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2317_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2317)));
    match vm.run() {
        VMResult::Ok(Value::Status(2317)) => {}
        other => panic!("exit code 2317 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_two_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..442 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2318_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2318)));
    match vm.run() {
        VMResult::Ok(Value::Status(2318)) => {}
        other => panic!("exit code 2318 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_eight_end_incrementing_from_sixEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..298 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 90 }));
    match vm.run() {
        VMResult::Ok(Value::Status(387)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(387)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2319_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2319)));
    match vm.run() {
        VMResult::Ok(Value::Status(2319)) => {}
        other => panic!("exit code 2319 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-300)));
    match vm.run() {
        VMResult::Ok(Value::Status(-300)) => {}
        other => panic!("status -300 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2320_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2320)));
    match vm.run() {
        VMResult::Ok(Value::Status(2320)) => {}
        other => panic!("exit code 2320 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-301)));
    match vm.run() {
        VMResult::Ok(Value::Status(-301)) => {}
        other => panic!("status -301 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2321_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2321)));
    match vm.run() {
        VMResult::Ok(Value::Status(2321)) => {}
        other => panic!("exit code 2321 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..158 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2315 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2315 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 158 {
                Some(2322)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2315 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2322)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2322)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2322_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2322)));
    match vm.run() {
        VMResult::Ok(Value::Status(2322)) => {}
        other => panic!("exit code 2322 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2323)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..76 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 79);
    assert_eq!(vm.last_status, 2323);
}

#[test]
fn subshell_end_exit_code_2323_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2323)));
    match vm.run() {
        VMResult::Ok(Value::Status(2323)) => {}
        other => panic!("exit code 2323 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2324Ex2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2324)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2324);
}

#[test]
fn subshell_end_exit_code_2324_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2324)));
    match vm.run() {
        VMResult::Ok(Value::Status(2324)) => {}
        other => panic!("exit code 2324 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_five_begins_seventy_three_ends_last_end_status_winsEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..75 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..73 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2325Ex2315;
    impl ShellHost for CountingBeginEndHost2325Ex2315 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2325)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2325Ex2315));
    match vm.run() {
        VMResult::Ok(Value::Status(2325)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2325)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 75);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 73);
}

#[test]
fn subshell_end_exit_code_2325_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2325)));
    match vm.run() {
        VMResult::Ok(Value::Status(2325)) => {}
        other => panic!("exit code 2325 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2326Ex2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2326)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2326);
}

#[test]
fn subshell_end_exit_code_2326_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2326)));
    match vm.run() {
        VMResult::Ok(Value::Status(2326)) => {}
        other => panic!("exit code 2326 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2315() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2327)));
    for _ in 0..76 {
        match vm.run() {
            VMResult::Ok(Value::Status(2327)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2327_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2327)));
    match vm.run() {
        VMResult::Ok(Value::Status(2327)) => {}
        other => panic!("exit code 2327 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2328Ex2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2328)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2328);
}

#[test]
fn subshell_end_exit_code_2328_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2328)));
    match vm.run() {
        VMResult::Ok(Value::Status(2328)) => {}
        other => panic!("exit code 2328 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_two_hundred_ninety_nine_end_incrementing_from_sevenEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..299 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 91 }));
    match vm.run() {
        VMResult::Ok(Value::Status(389)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(389)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2329_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2329)));
    match vm.run() {
        VMResult::Ok(Value::Status(2329)) => {}
        other => panic!("exit code 2329 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2330Ex2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2330)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2330);
}

#[test]
fn subshell_end_exit_code_2330_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2330)));
    match vm.run() {
        VMResult::Ok(Value::Status(2330)) => {}
        other => panic!("exit code 2330 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_three_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..443 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2331_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2331)));
    match vm.run() {
        VMResult::Ok(Value::Status(2331)) => {}
        other => panic!("exit code 2331 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..159 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2315 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2315 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 159 {
                Some(2332)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2315 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2332)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2332)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2332_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2332)));
    match vm.run() {
        VMResult::Ok(Value::Status(2332)) => {}
        other => panic!("exit code 2332 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2333_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2333)));
    match vm.run() {
        VMResult::Ok(Value::Status(2333)) => {}
        other => panic!("exit code 2333 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2334Ex2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2334)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2334);
}

#[test]
fn subshell_end_exit_code_2334_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2334)));
    match vm.run() {
        VMResult::Ok(Value::Status(2334)) => {}
        other => panic!("exit code 2334 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_end_incrementing_from_oneEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..300 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 85 }));
    match vm.run() {
        VMResult::Ok(Value::Status(384)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(384)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2335_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2335)));
    match vm.run() {
        VMResult::Ok(Value::Status(2335)) => {}
        other => panic!("exit code 2335 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2336;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2336)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2336, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2336_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2336)));
    match vm.run() {
        VMResult::Ok(Value::Status(2336)) => {}
        other => panic!("exit code 2336 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2337,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2337)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2337), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2337_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2337)));
    match vm.run() {
        VMResult::Ok(Value::Status(2337)) => {}
        other => panic!("exit code 2337 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_four_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..444 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2338_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2338)));
    match vm.run() {
        VMResult::Ok(Value::Status(2338)) => {}
        other => panic!("exit code 2338 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..160 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2315 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2315 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 160 {
                Some(2339)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2315 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2339)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2339)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2339_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2339)));
    match vm.run() {
        VMResult::Ok(Value::Status(2339)) => {}
        other => panic!("exit code 2339 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2340Ex2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2340Ex2315;
    impl ShellHost for PipelineSubshellHost2340Ex2315 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2340)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2340Ex2315));
    match vm.run() {
        VMResult::Ok(Value::Status(2340)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2340_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2340)));
    match vm.run() {
        VMResult::Ok(Value::Status(2340)) => {}
        other => panic!("exit code 2340 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2341Ex2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2341Ex2315;
    impl ShellHost for SubshellThenPipelineHost2341Ex2315 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2341
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2341Ex2315));
    match vm.run() {
        VMResult::Ok(Value::Status(2341)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2341_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2341)));
    match vm.run() {
        VMResult::Ok(Value::Status(2341)) => {}
        other => panic!("exit code 2341 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-302)));
    match vm.run() {
        VMResult::Ok(Value::Status(-302)) => {}
        other => panic!("status -302 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2342_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2342)));
    match vm.run() {
        VMResult::Ok(Value::Status(2342)) => {}
        other => panic!("exit code 2342 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_one_end_incrementing_from_eightEx2315() {
    let mut b = ChunkBuilder::new();
    for _ in 0..301 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 92 }));
    match vm.run() {
        VMResult::Ok(Value::Status(392)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(392)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2343_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2343)));
    match vm.run() {
        VMResult::Ok(Value::Status(2343)) => {}
        other => panic!("exit code 2343 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_five_consecutive_runs_without_reset_still_blockedEx2315() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..445 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2344_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2344)));
    match vm.run() {
        VMResult::Ok(Value::Status(2344)) => {}
        other => panic!("exit code 2344 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2345Ex2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2345Ex2315 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2345Ex2315 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2345Ex2315 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2345_propagatesEx2315() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2345)));
    match vm.run() {
        VMResult::Ok(Value::Status(2345)) => {}
        other => panic!("exit code 2345 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CG (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2346_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2346)));
    match vm.run() {
        VMResult::Ok(Value::Status(2346)) => {}
        other => panic!("exit code 2346 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_six_consecutive_runs_without_reset_still_blockedEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..446 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2347_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2347)));
    match vm.run() {
        VMResult::Ok(Value::Status(2347)) => {}
        other => panic!("exit code 2347 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_seven_consecutive_runs_without_reset_still_blockedEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..447 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2348_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2348)));
    match vm.run() {
        VMResult::Ok(Value::Status(2348)) => {}
        other => panic!("exit code 2348 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_eight_consecutive_runs_without_reset_still_blockedEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..448 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2349_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2349)));
    match vm.run() {
        VMResult::Ok(Value::Status(2349)) => {}
        other => panic!("exit code 2349 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2350_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2350)));
    match vm.run() {
        VMResult::Ok(Value::Status(2350)) => {}
        other => panic!("exit code 2350 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-304)));
    match vm.run() {
        VMResult::Ok(Value::Status(-304)) => {}
        other => panic!("status -304 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2351_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2351)));
    match vm.run() {
        VMResult::Ok(Value::Status(2351)) => {}
        other => panic!("exit code 2351 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-305)));
    match vm.run() {
        VMResult::Ok(Value::Status(-305)) => {}
        other => panic!("status -305 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2352_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2352)));
    match vm.run() {
        VMResult::Ok(Value::Status(2352)) => {}
        other => panic!("exit code 2352 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..161 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2346 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2346 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 161 {
                Some(2353)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2346 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2353)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2353)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2353_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2353)));
    match vm.run() {
        VMResult::Ok(Value::Status(2353)) => {}
        other => panic!("exit code 2353 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2354)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..77 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 80);
    assert_eq!(vm.last_status, 2354);
}

#[test]
fn subshell_end_exit_code_2354_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2354)));
    match vm.run() {
        VMResult::Ok(Value::Status(2354)) => {}
        other => panic!("exit code 2354 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2355Ex2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2355)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2355);
}

#[test]
fn subshell_end_exit_code_2355_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2355)));
    match vm.run() {
        VMResult::Ok(Value::Status(2355)) => {}
        other => panic!("exit code 2355 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_six_begins_seventy_four_ends_last_end_status_winsEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..76 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..74 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2356Ex2346;
    impl ShellHost for CountingBeginEndHost2356Ex2346 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2356)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2356Ex2346));
    match vm.run() {
        VMResult::Ok(Value::Status(2356)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2356)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 76);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 74);
}

#[test]
fn subshell_end_exit_code_2356_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2356)));
    match vm.run() {
        VMResult::Ok(Value::Status(2356)) => {}
        other => panic!("exit code 2356 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2357Ex2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2346;
    impl ShellHost for CountingBeginHost733Ex2346 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2357)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2346));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2357);
}

#[test]
fn subshell_end_exit_code_2357_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2357)));
    match vm.run() {
        VMResult::Ok(Value::Status(2357)) => {}
        other => panic!("exit code 2357 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2346() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2358)));
    for _ in 0..77 {
        match vm.run() {
            VMResult::Ok(Value::Status(2358)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2358_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2358)));
    match vm.run() {
        VMResult::Ok(Value::Status(2358)) => {}
        other => panic!("exit code 2358 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2359Ex2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2359)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2359);
}

#[test]
fn subshell_end_exit_code_2359_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2359)));
    match vm.run() {
        VMResult::Ok(Value::Status(2359)) => {}
        other => panic!("exit code 2359 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2360_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2360)));
    match vm.run() {
        VMResult::Ok(Value::Status(2360)) => {}
        other => panic!("exit code 2360 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2361Ex2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2361)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2361);
}

#[test]
fn subshell_end_exit_code_2361_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2361)));
    match vm.run() {
        VMResult::Ok(Value::Status(2361)) => {}
        other => panic!("exit code 2361 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_forty_nine_consecutive_runs_without_reset_still_blockedEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..449 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2362_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2362)));
    match vm.run() {
        VMResult::Ok(Value::Status(2362)) => {}
        other => panic!("exit code 2362 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_consecutive_runs_without_reset_still_blockedEx2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..450 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2363_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2363)));
    match vm.run() {
        VMResult::Ok(Value::Status(2363)) => {}
        other => panic!("exit code 2363 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2364_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2364)));
    match vm.run() {
        VMResult::Ok(Value::Status(2364)) => {}
        other => panic!("exit code 2364 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2365;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2365)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2365, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2365_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2365)));
    match vm.run() {
        VMResult::Ok(Value::Status(2365)) => {}
        other => panic!("exit code 2365 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2366,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2366)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2366), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2366_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2366)));
    match vm.run() {
        VMResult::Ok(Value::Status(2366)) => {}
        other => panic!("exit code 2366 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-306)));
    match vm.run() {
        VMResult::Ok(Value::Status(-306)) => {}
        other => panic!("status -306 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2367_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2367)));
    match vm.run() {
        VMResult::Ok(Value::Status(2367)) => {}
        other => panic!("exit code 2367 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_four_end_incrementing_from_fiveEx2346() {
    let mut b = ChunkBuilder::new();
    for _ in 0..304 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 92 }));
    match vm.run() {
        VMResult::Ok(Value::Status(395)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(395)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2368_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2368)));
    match vm.run() {
        VMResult::Ok(Value::Status(2368)) => {}
        other => panic!("exit code 2368 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2369Ex2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2369Ex2346 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2369Ex2346 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2369Ex2346 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2369_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2369)));
    match vm.run() {
        VMResult::Ok(Value::Status(2369)) => {}
        other => panic!("exit code 2369 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2370Ex2346() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2370)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2370);
}

#[test]
fn subshell_end_exit_code_2370_propagatesEx2346() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2370)));
    match vm.run() {
        VMResult::Ok(Value::Status(2370)) => {}
        other => panic!("exit code 2370 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CH (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2371_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2371)));
    match vm.run() {
        VMResult::Ok(Value::Status(2371)) => {}
        other => panic!("exit code 2371 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_one_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..451 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2372_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2372)));
    match vm.run() {
        VMResult::Ok(Value::Status(2372)) => {}
        other => panic!("exit code 2372 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_two_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..452 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2373_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2373)));
    match vm.run() {
        VMResult::Ok(Value::Status(2373)) => {}
        other => panic!("exit code 2373 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_three_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..453 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2374_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2374)));
    match vm.run() {
        VMResult::Ok(Value::Status(2374)) => {}
        other => panic!("exit code 2374 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_five_end_incrementing_from_sixEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..305 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 93 }));
    match vm.run() {
        VMResult::Ok(Value::Status(397)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(397)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2375_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2375)));
    match vm.run() {
        VMResult::Ok(Value::Status(2375)) => {}
        other => panic!("exit code 2375 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-307)));
    match vm.run() {
        VMResult::Ok(Value::Status(-307)) => {}
        other => panic!("status -307 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2376_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2376)));
    match vm.run() {
        VMResult::Ok(Value::Status(2376)) => {}
        other => panic!("exit code 2376 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-308)));
    match vm.run() {
        VMResult::Ok(Value::Status(-308)) => {}
        other => panic!("status -308 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2377_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2377)));
    match vm.run() {
        VMResult::Ok(Value::Status(2377)) => {}
        other => panic!("exit code 2377 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..162 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2371 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2371 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 162 {
                Some(2378)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2371 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2378)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2378)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2378_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2378)));
    match vm.run() {
        VMResult::Ok(Value::Status(2378)) => {}
        other => panic!("exit code 2378 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2379)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..78 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 81);
    assert_eq!(vm.last_status, 2379);
}

#[test]
fn subshell_end_exit_code_2379_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2379)));
    match vm.run() {
        VMResult::Ok(Value::Status(2379)) => {}
        other => panic!("exit code 2379 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2380Ex2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2380)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2380);
}

#[test]
fn subshell_end_exit_code_2380_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2380)));
    match vm.run() {
        VMResult::Ok(Value::Status(2380)) => {}
        other => panic!("exit code 2380 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_seven_begins_seventy_five_ends_last_end_status_winsEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..77 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..75 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2381Ex2371;
    impl ShellHost for CountingBeginEndHost2381Ex2371 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2381)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2381Ex2371));
    match vm.run() {
        VMResult::Ok(Value::Status(2381)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2381)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 77);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 75);
}

#[test]
fn subshell_end_exit_code_2381_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2381)));
    match vm.run() {
        VMResult::Ok(Value::Status(2381)) => {}
        other => panic!("exit code 2381 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2382Ex2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2382)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2382);
}

#[test]
fn subshell_end_exit_code_2382_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2382)));
    match vm.run() {
        VMResult::Ok(Value::Status(2382)) => {}
        other => panic!("exit code 2382 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2371() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2383)));
    for _ in 0..78 {
        match vm.run() {
            VMResult::Ok(Value::Status(2383)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2383_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2383)));
    match vm.run() {
        VMResult::Ok(Value::Status(2383)) => {}
        other => panic!("exit code 2383 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2384Ex2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2384)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2384);
}

#[test]
fn subshell_end_exit_code_2384_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2384)));
    match vm.run() {
        VMResult::Ok(Value::Status(2384)) => {}
        other => panic!("exit code 2384 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_six_end_incrementing_from_sevenEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..306 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 94 }));
    match vm.run() {
        VMResult::Ok(Value::Status(399)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(399)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2385_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2385)));
    match vm.run() {
        VMResult::Ok(Value::Status(2385)) => {}
        other => panic!("exit code 2385 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2386Ex2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2386)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2386);
}

#[test]
fn subshell_end_exit_code_2386_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2386)));
    match vm.run() {
        VMResult::Ok(Value::Status(2386)) => {}
        other => panic!("exit code 2386 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_four_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..454 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2387_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2387)));
    match vm.run() {
        VMResult::Ok(Value::Status(2387)) => {}
        other => panic!("exit code 2387 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..163 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2371 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2371 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 163 {
                Some(2388)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2371 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2388)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2388)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2388_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2388)));
    match vm.run() {
        VMResult::Ok(Value::Status(2388)) => {}
        other => panic!("exit code 2388 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2389_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2389)));
    match vm.run() {
        VMResult::Ok(Value::Status(2389)) => {}
        other => panic!("exit code 2389 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2390Ex2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2390)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2390);
}

#[test]
fn subshell_end_exit_code_2390_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2390)));
    match vm.run() {
        VMResult::Ok(Value::Status(2390)) => {}
        other => panic!("exit code 2390 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_seven_end_incrementing_from_oneEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..307 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 88 }));
    match vm.run() {
        VMResult::Ok(Value::Status(394)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(394)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2391_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2391)));
    match vm.run() {
        VMResult::Ok(Value::Status(2391)) => {}
        other => panic!("exit code 2391 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2392;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2392)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2392, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2392_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2392)));
    match vm.run() {
        VMResult::Ok(Value::Status(2392)) => {}
        other => panic!("exit code 2392 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2393,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2393)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2393), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2393_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2393)));
    match vm.run() {
        VMResult::Ok(Value::Status(2393)) => {}
        other => panic!("exit code 2393 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_five_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..455 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2394_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2394)));
    match vm.run() {
        VMResult::Ok(Value::Status(2394)) => {}
        other => panic!("exit code 2394 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..164 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2371 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2371 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 164 {
                Some(2395)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2371 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2395)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2395)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2395_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2395)));
    match vm.run() {
        VMResult::Ok(Value::Status(2395)) => {}
        other => panic!("exit code 2395 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2396Ex2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2396Ex2371;
    impl ShellHost for PipelineSubshellHost2396Ex2371 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2396)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2396Ex2371));
    match vm.run() {
        VMResult::Ok(Value::Status(2396)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2396_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2396)));
    match vm.run() {
        VMResult::Ok(Value::Status(2396)) => {}
        other => panic!("exit code 2396 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2397Ex2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2397Ex2371;
    impl ShellHost for SubshellThenPipelineHost2397Ex2371 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2397
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2397Ex2371));
    match vm.run() {
        VMResult::Ok(Value::Status(2397)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2397_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2397)));
    match vm.run() {
        VMResult::Ok(Value::Status(2397)) => {}
        other => panic!("exit code 2397 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-309)));
    match vm.run() {
        VMResult::Ok(Value::Status(-309)) => {}
        other => panic!("status -309 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2398_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2398)));
    match vm.run() {
        VMResult::Ok(Value::Status(2398)) => {}
        other => panic!("exit code 2398 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_eight_end_incrementing_from_eightEx2371() {
    let mut b = ChunkBuilder::new();
    for _ in 0..308 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 95 }));
    match vm.run() {
        VMResult::Ok(Value::Status(402)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(402)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2399_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2399)));
    match vm.run() {
        VMResult::Ok(Value::Status(2399)) => {}
        other => panic!("exit code 2399 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_six_consecutive_runs_without_reset_still_blockedEx2371() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..456 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2400_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2400)));
    match vm.run() {
        VMResult::Ok(Value::Status(2400)) => {}
        other => panic!("exit code 2400 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2401Ex2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2401Ex2371 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2401Ex2371 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2401Ex2371 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2401_propagatesEx2371() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2401)));
    match vm.run() {
        VMResult::Ok(Value::Status(2401)) => {}
        other => panic!("exit code 2401 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CI (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2402_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2402)));
    match vm.run() {
        VMResult::Ok(Value::Status(2402)) => {}
        other => panic!("exit code 2402 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_seven_consecutive_runs_without_reset_still_blockedEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..457 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2403_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2403)));
    match vm.run() {
        VMResult::Ok(Value::Status(2403)) => {}
        other => panic!("exit code 2403 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_eight_consecutive_runs_without_reset_still_blockedEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..458 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2404_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2404)));
    match vm.run() {
        VMResult::Ok(Value::Status(2404)) => {}
        other => panic!("exit code 2404 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_fifty_nine_consecutive_runs_without_reset_still_blockedEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..459 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2405_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2405)));
    match vm.run() {
        VMResult::Ok(Value::Status(2405)) => {}
        other => panic!("exit code 2405 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2406_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2406)));
    match vm.run() {
        VMResult::Ok(Value::Status(2406)) => {}
        other => panic!("exit code 2406 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-311)));
    match vm.run() {
        VMResult::Ok(Value::Status(-311)) => {}
        other => panic!("status -311 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2407_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2407)));
    match vm.run() {
        VMResult::Ok(Value::Status(2407)) => {}
        other => panic!("exit code 2407 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-312)));
    match vm.run() {
        VMResult::Ok(Value::Status(-312)) => {}
        other => panic!("status -312 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2408_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2408)));
    match vm.run() {
        VMResult::Ok(Value::Status(2408)) => {}
        other => panic!("exit code 2408 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..165 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2402 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2402 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 165 {
                Some(2409)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2402 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2409)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2409)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2409_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2409)));
    match vm.run() {
        VMResult::Ok(Value::Status(2409)) => {}
        other => panic!("exit code 2409 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2410)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..79 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 82);
    assert_eq!(vm.last_status, 2410);
}

#[test]
fn subshell_end_exit_code_2410_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2410)));
    match vm.run() {
        VMResult::Ok(Value::Status(2410)) => {}
        other => panic!("exit code 2410 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2411Ex2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2411)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2411);
}

#[test]
fn subshell_end_exit_code_2411_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2411)));
    match vm.run() {
        VMResult::Ok(Value::Status(2411)) => {}
        other => panic!("exit code 2411 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_eight_begins_seventy_six_ends_last_end_status_winsEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..78 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..76 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2412Ex2402;
    impl ShellHost for CountingBeginEndHost2412Ex2402 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2412)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2412Ex2402));
    match vm.run() {
        VMResult::Ok(Value::Status(2412)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2412)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 78);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 76);
}

#[test]
fn subshell_end_exit_code_2412_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2412)));
    match vm.run() {
        VMResult::Ok(Value::Status(2412)) => {}
        other => panic!("exit code 2412 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2413Ex2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2402;
    impl ShellHost for CountingBeginHost733Ex2402 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2413)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2402));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2413);
}

#[test]
fn subshell_end_exit_code_2413_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2413)));
    match vm.run() {
        VMResult::Ok(Value::Status(2413)) => {}
        other => panic!("exit code 2413 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2402() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2414)));
    for _ in 0..79 {
        match vm.run() {
            VMResult::Ok(Value::Status(2414)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2414_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2414)));
    match vm.run() {
        VMResult::Ok(Value::Status(2414)) => {}
        other => panic!("exit code 2414 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2415Ex2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2415)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2415);
}

#[test]
fn subshell_end_exit_code_2415_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2415)));
    match vm.run() {
        VMResult::Ok(Value::Status(2415)) => {}
        other => panic!("exit code 2415 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2416_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2416)));
    match vm.run() {
        VMResult::Ok(Value::Status(2416)) => {}
        other => panic!("exit code 2416 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2417Ex2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2417)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2417);
}

#[test]
fn subshell_end_exit_code_2417_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2417)));
    match vm.run() {
        VMResult::Ok(Value::Status(2417)) => {}
        other => panic!("exit code 2417 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_consecutive_runs_without_reset_still_blockedEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..460 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2418_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2418)));
    match vm.run() {
        VMResult::Ok(Value::Status(2418)) => {}
        other => panic!("exit code 2418 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_one_consecutive_runs_without_reset_still_blockedEx2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..461 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2419_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2419)));
    match vm.run() {
        VMResult::Ok(Value::Status(2419)) => {}
        other => panic!("exit code 2419 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2420_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2420)));
    match vm.run() {
        VMResult::Ok(Value::Status(2420)) => {}
        other => panic!("exit code 2420 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2421;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2421)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2421, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2421_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2421)));
    match vm.run() {
        VMResult::Ok(Value::Status(2421)) => {}
        other => panic!("exit code 2421 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2422,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2422)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2422), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2422_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2422)));
    match vm.run() {
        VMResult::Ok(Value::Status(2422)) => {}
        other => panic!("exit code 2422 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-313)));
    match vm.run() {
        VMResult::Ok(Value::Status(-313)) => {}
        other => panic!("status -313 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2423_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2423)));
    match vm.run() {
        VMResult::Ok(Value::Status(2423)) => {}
        other => panic!("exit code 2423 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_eleven_end_incrementing_from_fiveEx2402() {
    let mut b = ChunkBuilder::new();
    for _ in 0..311 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 95 }));
    match vm.run() {
        VMResult::Ok(Value::Status(405)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(405)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2424_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2424)));
    match vm.run() {
        VMResult::Ok(Value::Status(2424)) => {}
        other => panic!("exit code 2424 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2425Ex2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2425Ex2402 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2425Ex2402 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2425Ex2402 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2425_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2425)));
    match vm.run() {
        VMResult::Ok(Value::Status(2425)) => {}
        other => panic!("exit code 2425 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2426Ex2402() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2426)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2426);
}

#[test]
fn subshell_end_exit_code_2426_propagatesEx2402() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2426)));
    match vm.run() {
        VMResult::Ok(Value::Status(2426)) => {}
        other => panic!("exit code 2426 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CJ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2427_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2427)));
    match vm.run() {
        VMResult::Ok(Value::Status(2427)) => {}
        other => panic!("exit code 2427 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_two_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..462 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2428_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2428)));
    match vm.run() {
        VMResult::Ok(Value::Status(2428)) => {}
        other => panic!("exit code 2428 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_three_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..463 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2429_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2429)));
    match vm.run() {
        VMResult::Ok(Value::Status(2429)) => {}
        other => panic!("exit code 2429 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_four_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..464 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2430_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2430)));
    match vm.run() {
        VMResult::Ok(Value::Status(2430)) => {}
        other => panic!("exit code 2430 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twelve_end_incrementing_from_sixEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..312 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 96 }));
    match vm.run() {
        VMResult::Ok(Value::Status(407)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(407)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2431_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2431)));
    match vm.run() {
        VMResult::Ok(Value::Status(2431)) => {}
        other => panic!("exit code 2431 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-314)));
    match vm.run() {
        VMResult::Ok(Value::Status(-314)) => {}
        other => panic!("status -314 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2432_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2432)));
    match vm.run() {
        VMResult::Ok(Value::Status(2432)) => {}
        other => panic!("exit code 2432 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-315)));
    match vm.run() {
        VMResult::Ok(Value::Status(-315)) => {}
        other => panic!("status -315 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2433_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2433)));
    match vm.run() {
        VMResult::Ok(Value::Status(2433)) => {}
        other => panic!("exit code 2433 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..166 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2427 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2427 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 166 {
                Some(2434)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2427 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2434)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2434)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2434_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2434)));
    match vm.run() {
        VMResult::Ok(Value::Status(2434)) => {}
        other => panic!("exit code 2434 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2435)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..80 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 83);
    assert_eq!(vm.last_status, 2435);
}

#[test]
fn subshell_end_exit_code_2435_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2435)));
    match vm.run() {
        VMResult::Ok(Value::Status(2435)) => {}
        other => panic!("exit code 2435 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2436Ex2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2436)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2436);
}

#[test]
fn subshell_end_exit_code_2436_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2436)));
    match vm.run() {
        VMResult::Ok(Value::Status(2436)) => {}
        other => panic!("exit code 2436 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_seventy_nine_begins_seventy_seven_ends_last_end_status_winsEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..79 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..77 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2437Ex2427;
    impl ShellHost for CountingBeginEndHost2437Ex2427 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2437)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2437Ex2427));
    match vm.run() {
        VMResult::Ok(Value::Status(2437)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2437)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 79);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 77);
}

#[test]
fn subshell_end_exit_code_2437_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2437)));
    match vm.run() {
        VMResult::Ok(Value::Status(2437)) => {}
        other => panic!("exit code 2437 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2438Ex2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2438)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2438);
}

#[test]
fn subshell_end_exit_code_2438_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2438)));
    match vm.run() {
        VMResult::Ok(Value::Status(2438)) => {}
        other => panic!("exit code 2438 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2427() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2439)));
    for _ in 0..80 {
        match vm.run() {
            VMResult::Ok(Value::Status(2439)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2439_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2439)));
    match vm.run() {
        VMResult::Ok(Value::Status(2439)) => {}
        other => panic!("exit code 2439 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2440Ex2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2440)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2440);
}

#[test]
fn subshell_end_exit_code_2440_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2440)));
    match vm.run() {
        VMResult::Ok(Value::Status(2440)) => {}
        other => panic!("exit code 2440 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirteen_end_incrementing_from_sevenEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..313 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 97 }));
    match vm.run() {
        VMResult::Ok(Value::Status(409)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(409)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2441_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2441)));
    match vm.run() {
        VMResult::Ok(Value::Status(2441)) => {}
        other => panic!("exit code 2441 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2442Ex2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2442)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2442);
}

#[test]
fn subshell_end_exit_code_2442_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2442)));
    match vm.run() {
        VMResult::Ok(Value::Status(2442)) => {}
        other => panic!("exit code 2442 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_five_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..465 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2443_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2443)));
    match vm.run() {
        VMResult::Ok(Value::Status(2443)) => {}
        other => panic!("exit code 2443 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..167 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2427 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2427 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 167 {
                Some(2444)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2427 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2444)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2444)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2444_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2444)));
    match vm.run() {
        VMResult::Ok(Value::Status(2444)) => {}
        other => panic!("exit code 2444 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2445_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2445)));
    match vm.run() {
        VMResult::Ok(Value::Status(2445)) => {}
        other => panic!("exit code 2445 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2446Ex2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2446)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2446);
}

#[test]
fn subshell_end_exit_code_2446_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2446)));
    match vm.run() {
        VMResult::Ok(Value::Status(2446)) => {}
        other => panic!("exit code 2446 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fourteen_end_incrementing_from_oneEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..314 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 91 }));
    match vm.run() {
        VMResult::Ok(Value::Status(404)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(404)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2447_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2447)));
    match vm.run() {
        VMResult::Ok(Value::Status(2447)) => {}
        other => panic!("exit code 2447 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2448;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2448)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2448, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2448_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2448)));
    match vm.run() {
        VMResult::Ok(Value::Status(2448)) => {}
        other => panic!("exit code 2448 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2449,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2449)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2449), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2449_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2449)));
    match vm.run() {
        VMResult::Ok(Value::Status(2449)) => {}
        other => panic!("exit code 2449 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_six_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..466 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2450_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2450)));
    match vm.run() {
        VMResult::Ok(Value::Status(2450)) => {}
        other => panic!("exit code 2450 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..168 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2427 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2427 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 168 {
                Some(2451)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2427 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2451)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2451)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2451_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2451)));
    match vm.run() {
        VMResult::Ok(Value::Status(2451)) => {}
        other => panic!("exit code 2451 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2452Ex2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2452Ex2427;
    impl ShellHost for PipelineSubshellHost2452Ex2427 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2452)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2452Ex2427));
    match vm.run() {
        VMResult::Ok(Value::Status(2452)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2452_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2452)));
    match vm.run() {
        VMResult::Ok(Value::Status(2452)) => {}
        other => panic!("exit code 2452 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2453Ex2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2453Ex2427;
    impl ShellHost for SubshellThenPipelineHost2453Ex2427 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2453
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2453Ex2427));
    match vm.run() {
        VMResult::Ok(Value::Status(2453)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2453_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2453)));
    match vm.run() {
        VMResult::Ok(Value::Status(2453)) => {}
        other => panic!("exit code 2453 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-316)));
    match vm.run() {
        VMResult::Ok(Value::Status(-316)) => {}
        other => panic!("status -316 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2454_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2454)));
    match vm.run() {
        VMResult::Ok(Value::Status(2454)) => {}
        other => panic!("exit code 2454 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifteen_end_incrementing_from_eightEx2427() {
    let mut b = ChunkBuilder::new();
    for _ in 0..315 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 98 }));
    match vm.run() {
        VMResult::Ok(Value::Status(412)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(412)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2455_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2455)));
    match vm.run() {
        VMResult::Ok(Value::Status(2455)) => {}
        other => panic!("exit code 2455 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_seven_consecutive_runs_without_reset_still_blockedEx2427() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..467 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2456_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2456)));
    match vm.run() {
        VMResult::Ok(Value::Status(2456)) => {}
        other => panic!("exit code 2456 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2457Ex2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2457Ex2427 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2457Ex2427 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2457Ex2427 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2457_propagatesEx2427() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2457)));
    match vm.run() {
        VMResult::Ok(Value::Status(2457)) => {}
        other => panic!("exit code 2457 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CK (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2458_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2458)));
    match vm.run() {
        VMResult::Ok(Value::Status(2458)) => {}
        other => panic!("exit code 2458 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_eight_consecutive_runs_without_reset_still_blockedEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..468 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2459_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2459)));
    match vm.run() {
        VMResult::Ok(Value::Status(2459)) => {}
        other => panic!("exit code 2459 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_sixty_nine_consecutive_runs_without_reset_still_blockedEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..469 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2460_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2460)));
    match vm.run() {
        VMResult::Ok(Value::Status(2460)) => {}
        other => panic!("exit code 2460 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_consecutive_runs_without_reset_still_blockedEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..470 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2461_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2461)));
    match vm.run() {
        VMResult::Ok(Value::Status(2461)) => {}
        other => panic!("exit code 2461 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2462_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2462)));
    match vm.run() {
        VMResult::Ok(Value::Status(2462)) => {}
        other => panic!("exit code 2462 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-318)));
    match vm.run() {
        VMResult::Ok(Value::Status(-318)) => {}
        other => panic!("status -318 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2463_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2463)));
    match vm.run() {
        VMResult::Ok(Value::Status(2463)) => {}
        other => panic!("exit code 2463 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-319)));
    match vm.run() {
        VMResult::Ok(Value::Status(-319)) => {}
        other => panic!("status -319 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2464_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2464)));
    match vm.run() {
        VMResult::Ok(Value::Status(2464)) => {}
        other => panic!("exit code 2464 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..169 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2458 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2458 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 169 {
                Some(2465)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2458 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2465)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2465)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2465_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2465)));
    match vm.run() {
        VMResult::Ok(Value::Status(2465)) => {}
        other => panic!("exit code 2465 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2466)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..81 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 84);
    assert_eq!(vm.last_status, 2466);
}

#[test]
fn subshell_end_exit_code_2466_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2466)));
    match vm.run() {
        VMResult::Ok(Value::Status(2466)) => {}
        other => panic!("exit code 2466 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2467Ex2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2467)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2467);
}

#[test]
fn subshell_end_exit_code_2467_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2467)));
    match vm.run() {
        VMResult::Ok(Value::Status(2467)) => {}
        other => panic!("exit code 2467 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_begins_seventy_eight_ends_last_end_status_winsEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..80 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..78 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2468Ex2458;
    impl ShellHost for CountingBeginEndHost2468Ex2458 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2468)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2468Ex2458));
    match vm.run() {
        VMResult::Ok(Value::Status(2468)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2468)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 80);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 78);
}

#[test]
fn subshell_end_exit_code_2468_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2468)));
    match vm.run() {
        VMResult::Ok(Value::Status(2468)) => {}
        other => panic!("exit code 2468 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2469Ex2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2458;
    impl ShellHost for CountingBeginHost733Ex2458 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2469)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2458));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2469);
}

#[test]
fn subshell_end_exit_code_2469_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2469)));
    match vm.run() {
        VMResult::Ok(Value::Status(2469)) => {}
        other => panic!("exit code 2469 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2458() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2470)));
    for _ in 0..81 {
        match vm.run() {
            VMResult::Ok(Value::Status(2470)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2470_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2470)));
    match vm.run() {
        VMResult::Ok(Value::Status(2470)) => {}
        other => panic!("exit code 2470 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2471Ex2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2471)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2471);
}

#[test]
fn subshell_end_exit_code_2471_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2471)));
    match vm.run() {
        VMResult::Ok(Value::Status(2471)) => {}
        other => panic!("exit code 2471 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2472_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2472)));
    match vm.run() {
        VMResult::Ok(Value::Status(2472)) => {}
        other => panic!("exit code 2472 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2473Ex2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2473)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2473);
}

#[test]
fn subshell_end_exit_code_2473_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2473)));
    match vm.run() {
        VMResult::Ok(Value::Status(2473)) => {}
        other => panic!("exit code 2473 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_one_consecutive_runs_without_reset_still_blockedEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..471 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2474_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2474)));
    match vm.run() {
        VMResult::Ok(Value::Status(2474)) => {}
        other => panic!("exit code 2474 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_two_consecutive_runs_without_reset_still_blockedEx2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..472 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2475_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2475)));
    match vm.run() {
        VMResult::Ok(Value::Status(2475)) => {}
        other => panic!("exit code 2475 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2476_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2476)));
    match vm.run() {
        VMResult::Ok(Value::Status(2476)) => {}
        other => panic!("exit code 2476 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2477;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2477)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2477, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2477_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2477)));
    match vm.run() {
        VMResult::Ok(Value::Status(2477)) => {}
        other => panic!("exit code 2477 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2478,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2478)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2478), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2478_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2478)));
    match vm.run() {
        VMResult::Ok(Value::Status(2478)) => {}
        other => panic!("exit code 2478 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-320)));
    match vm.run() {
        VMResult::Ok(Value::Status(-320)) => {}
        other => panic!("status -320 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2479_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2479)));
    match vm.run() {
        VMResult::Ok(Value::Status(2479)) => {}
        other => panic!("exit code 2479 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_eighteen_end_incrementing_from_fiveEx2458() {
    let mut b = ChunkBuilder::new();
    for _ in 0..318 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 98 }));
    match vm.run() {
        VMResult::Ok(Value::Status(415)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(415)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2480_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2480)));
    match vm.run() {
        VMResult::Ok(Value::Status(2480)) => {}
        other => panic!("exit code 2480 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2481Ex2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2481Ex2458 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2481Ex2458 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2481Ex2458 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2481_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2481)));
    match vm.run() {
        VMResult::Ok(Value::Status(2481)) => {}
        other => panic!("exit code 2481 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2482Ex2458() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2482)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2482);
}

#[test]
fn subshell_end_exit_code_2482_propagatesEx2458() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2482)));
    match vm.run() {
        VMResult::Ok(Value::Status(2482)) => {}
        other => panic!("exit code 2482 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CL (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2483_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2483)));
    match vm.run() {
        VMResult::Ok(Value::Status(2483)) => {}
        other => panic!("exit code 2483 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_three_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..473 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2484_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2484)));
    match vm.run() {
        VMResult::Ok(Value::Status(2484)) => {}
        other => panic!("exit code 2484 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_four_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..474 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2485_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2485)));
    match vm.run() {
        VMResult::Ok(Value::Status(2485)) => {}
        other => panic!("exit code 2485 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_five_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..475 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2486_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2486)));
    match vm.run() {
        VMResult::Ok(Value::Status(2486)) => {}
        other => panic!("exit code 2486 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_nineteen_end_incrementing_from_sixEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..319 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 99 }));
    match vm.run() {
        VMResult::Ok(Value::Status(417)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(417)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2487_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2487)));
    match vm.run() {
        VMResult::Ok(Value::Status(2487)) => {}
        other => panic!("exit code 2487 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-321)));
    match vm.run() {
        VMResult::Ok(Value::Status(-321)) => {}
        other => panic!("status -321 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2488_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2488)));
    match vm.run() {
        VMResult::Ok(Value::Status(2488)) => {}
        other => panic!("exit code 2488 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-322)));
    match vm.run() {
        VMResult::Ok(Value::Status(-322)) => {}
        other => panic!("status -322 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2489_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2489)));
    match vm.run() {
        VMResult::Ok(Value::Status(2489)) => {}
        other => panic!("exit code 2489 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..170 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2483 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2483 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 170 {
                Some(2490)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2483 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2490)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2490)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2490_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2490)));
    match vm.run() {
        VMResult::Ok(Value::Status(2490)) => {}
        other => panic!("exit code 2490 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2491)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..82 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 85);
    assert_eq!(vm.last_status, 2491);
}

#[test]
fn subshell_end_exit_code_2491_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2491)));
    match vm.run() {
        VMResult::Ok(Value::Status(2491)) => {}
        other => panic!("exit code 2491 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2492Ex2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2492)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2492);
}

#[test]
fn subshell_end_exit_code_2492_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2492)));
    match vm.run() {
        VMResult::Ok(Value::Status(2492)) => {}
        other => panic!("exit code 2492 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_one_begins_seventy_nine_ends_last_end_status_winsEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..81 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..79 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2493Ex2483;
    impl ShellHost for CountingBeginEndHost2493Ex2483 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2493)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2493Ex2483));
    match vm.run() {
        VMResult::Ok(Value::Status(2493)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2493)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 81);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 79);
}

#[test]
fn subshell_end_exit_code_2493_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2493)));
    match vm.run() {
        VMResult::Ok(Value::Status(2493)) => {}
        other => panic!("exit code 2493 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2494Ex2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2494)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2494);
}

#[test]
fn subshell_end_exit_code_2494_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2494)));
    match vm.run() {
        VMResult::Ok(Value::Status(2494)) => {}
        other => panic!("exit code 2494 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2483() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2495)));
    for _ in 0..82 {
        match vm.run() {
            VMResult::Ok(Value::Status(2495)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2495_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2495)));
    match vm.run() {
        VMResult::Ok(Value::Status(2495)) => {}
        other => panic!("exit code 2495 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2496Ex2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2496)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2496);
}

#[test]
fn subshell_end_exit_code_2496_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2496)));
    match vm.run() {
        VMResult::Ok(Value::Status(2496)) => {}
        other => panic!("exit code 2496 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_end_incrementing_from_sevenEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..320 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 100 }));
    match vm.run() {
        VMResult::Ok(Value::Status(419)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(419)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2497_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2497)));
    match vm.run() {
        VMResult::Ok(Value::Status(2497)) => {}
        other => panic!("exit code 2497 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2498Ex2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2498)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2498);
}

#[test]
fn subshell_end_exit_code_2498_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2498)));
    match vm.run() {
        VMResult::Ok(Value::Status(2498)) => {}
        other => panic!("exit code 2498 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_six_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..476 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2499_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2499)));
    match vm.run() {
        VMResult::Ok(Value::Status(2499)) => {}
        other => panic!("exit code 2499 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..171 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2483 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2483 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 171 {
                Some(2500)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2483 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2500)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2500)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2500_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2500)));
    match vm.run() {
        VMResult::Ok(Value::Status(2500)) => {}
        other => panic!("exit code 2500 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2501_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2501)));
    match vm.run() {
        VMResult::Ok(Value::Status(2501)) => {}
        other => panic!("exit code 2501 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2502Ex2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2502)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2502);
}

#[test]
fn subshell_end_exit_code_2502_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2502)));
    match vm.run() {
        VMResult::Ok(Value::Status(2502)) => {}
        other => panic!("exit code 2502 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_one_end_incrementing_from_oneEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..321 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 94 }));
    match vm.run() {
        VMResult::Ok(Value::Status(414)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(414)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2503_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2503)));
    match vm.run() {
        VMResult::Ok(Value::Status(2503)) => {}
        other => panic!("exit code 2503 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2504;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2504)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2504, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2504_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2504)));
    match vm.run() {
        VMResult::Ok(Value::Status(2504)) => {}
        other => panic!("exit code 2504 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2505,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2505)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2505), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2505_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2505)));
    match vm.run() {
        VMResult::Ok(Value::Status(2505)) => {}
        other => panic!("exit code 2505 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_seven_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..477 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2506_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2506)));
    match vm.run() {
        VMResult::Ok(Value::Status(2506)) => {}
        other => panic!("exit code 2506 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..172 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2483 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2483 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 172 {
                Some(2507)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2483 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2507)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2507)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2507_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2507)));
    match vm.run() {
        VMResult::Ok(Value::Status(2507)) => {}
        other => panic!("exit code 2507 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2508Ex2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2508Ex2483;
    impl ShellHost for PipelineSubshellHost2508Ex2483 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2508)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2508Ex2483));
    match vm.run() {
        VMResult::Ok(Value::Status(2508)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2508_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2508)));
    match vm.run() {
        VMResult::Ok(Value::Status(2508)) => {}
        other => panic!("exit code 2508 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2509Ex2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2509Ex2483;
    impl ShellHost for SubshellThenPipelineHost2509Ex2483 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2509
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2509Ex2483));
    match vm.run() {
        VMResult::Ok(Value::Status(2509)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2509_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2509)));
    match vm.run() {
        VMResult::Ok(Value::Status(2509)) => {}
        other => panic!("exit code 2509 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-323)));
    match vm.run() {
        VMResult::Ok(Value::Status(-323)) => {}
        other => panic!("status -323 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2510_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2510)));
    match vm.run() {
        VMResult::Ok(Value::Status(2510)) => {}
        other => panic!("exit code 2510 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_two_end_incrementing_from_eightEx2483() {
    let mut b = ChunkBuilder::new();
    for _ in 0..322 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 101 }));
    match vm.run() {
        VMResult::Ok(Value::Status(422)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(422)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2511_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2511)));
    match vm.run() {
        VMResult::Ok(Value::Status(2511)) => {}
        other => panic!("exit code 2511 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_eight_consecutive_runs_without_reset_still_blockedEx2483() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..478 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2512_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2512)));
    match vm.run() {
        VMResult::Ok(Value::Status(2512)) => {}
        other => panic!("exit code 2512 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2513Ex2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2513Ex2483 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2513Ex2483 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2513Ex2483 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2513_propagatesEx2483() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2513)));
    match vm.run() {
        VMResult::Ok(Value::Status(2513)) => {}
        other => panic!("exit code 2513 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CM (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2514_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2514)));
    match vm.run() {
        VMResult::Ok(Value::Status(2514)) => {}
        other => panic!("exit code 2514 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_seventy_nine_consecutive_runs_without_reset_still_blockedEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..479 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2515_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2515)));
    match vm.run() {
        VMResult::Ok(Value::Status(2515)) => {}
        other => panic!("exit code 2515 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_consecutive_runs_without_reset_still_blockedEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..480 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2516_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2516)));
    match vm.run() {
        VMResult::Ok(Value::Status(2516)) => {}
        other => panic!("exit code 2516 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_one_consecutive_runs_without_reset_still_blockedEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..481 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2517_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2517)));
    match vm.run() {
        VMResult::Ok(Value::Status(2517)) => {}
        other => panic!("exit code 2517 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2518_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2518)));
    match vm.run() {
        VMResult::Ok(Value::Status(2518)) => {}
        other => panic!("exit code 2518 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-325)));
    match vm.run() {
        VMResult::Ok(Value::Status(-325)) => {}
        other => panic!("status -325 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2519_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2519)));
    match vm.run() {
        VMResult::Ok(Value::Status(2519)) => {}
        other => panic!("exit code 2519 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-326)));
    match vm.run() {
        VMResult::Ok(Value::Status(-326)) => {}
        other => panic!("status -326 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2520_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2520)));
    match vm.run() {
        VMResult::Ok(Value::Status(2520)) => {}
        other => panic!("exit code 2520 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..173 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2514 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2514 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 173 {
                Some(2521)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2514 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2521)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2521)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2521_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2521)));
    match vm.run() {
        VMResult::Ok(Value::Status(2521)) => {}
        other => panic!("exit code 2521 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2522)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..83 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 86);
    assert_eq!(vm.last_status, 2522);
}

#[test]
fn subshell_end_exit_code_2522_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2522)));
    match vm.run() {
        VMResult::Ok(Value::Status(2522)) => {}
        other => panic!("exit code 2522 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2523Ex2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2523)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2523);
}

#[test]
fn subshell_end_exit_code_2523_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2523)));
    match vm.run() {
        VMResult::Ok(Value::Status(2523)) => {}
        other => panic!("exit code 2523 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_two_begins_eighty_ends_last_end_status_winsEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..82 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..80 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2524Ex2514;
    impl ShellHost for CountingBeginEndHost2524Ex2514 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2524)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2524Ex2514));
    match vm.run() {
        VMResult::Ok(Value::Status(2524)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2524)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 82);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 80);
}

#[test]
fn subshell_end_exit_code_2524_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2524)));
    match vm.run() {
        VMResult::Ok(Value::Status(2524)) => {}
        other => panic!("exit code 2524 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2525Ex2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2514;
    impl ShellHost for CountingBeginHost733Ex2514 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2525)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2514));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2525);
}

#[test]
fn subshell_end_exit_code_2525_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2525)));
    match vm.run() {
        VMResult::Ok(Value::Status(2525)) => {}
        other => panic!("exit code 2525 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2514() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2526)));
    for _ in 0..83 {
        match vm.run() {
            VMResult::Ok(Value::Status(2526)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2526_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2526)));
    match vm.run() {
        VMResult::Ok(Value::Status(2526)) => {}
        other => panic!("exit code 2526 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2527Ex2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2527)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2527);
}

#[test]
fn subshell_end_exit_code_2527_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2527)));
    match vm.run() {
        VMResult::Ok(Value::Status(2527)) => {}
        other => panic!("exit code 2527 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2528_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2528)));
    match vm.run() {
        VMResult::Ok(Value::Status(2528)) => {}
        other => panic!("exit code 2528 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2529Ex2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2529)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2529);
}

#[test]
fn subshell_end_exit_code_2529_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2529)));
    match vm.run() {
        VMResult::Ok(Value::Status(2529)) => {}
        other => panic!("exit code 2529 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_two_consecutive_runs_without_reset_still_blockedEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..482 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2530_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2530)));
    match vm.run() {
        VMResult::Ok(Value::Status(2530)) => {}
        other => panic!("exit code 2530 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_three_consecutive_runs_without_reset_still_blockedEx2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..483 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2531_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2531)));
    match vm.run() {
        VMResult::Ok(Value::Status(2531)) => {}
        other => panic!("exit code 2531 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2532_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2532)));
    match vm.run() {
        VMResult::Ok(Value::Status(2532)) => {}
        other => panic!("exit code 2532 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2533;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2533)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2533, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2533_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2533)));
    match vm.run() {
        VMResult::Ok(Value::Status(2533)) => {}
        other => panic!("exit code 2533 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2534,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2534)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2534), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2534_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2534)));
    match vm.run() {
        VMResult::Ok(Value::Status(2534)) => {}
        other => panic!("exit code 2534 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-327)));
    match vm.run() {
        VMResult::Ok(Value::Status(-327)) => {}
        other => panic!("status -327 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2535_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2535)));
    match vm.run() {
        VMResult::Ok(Value::Status(2535)) => {}
        other => panic!("exit code 2535 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_five_end_incrementing_from_fiveEx2514() {
    let mut b = ChunkBuilder::new();
    for _ in 0..325 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 101 }));
    match vm.run() {
        VMResult::Ok(Value::Status(425)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(425)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2536_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2536)));
    match vm.run() {
        VMResult::Ok(Value::Status(2536)) => {}
        other => panic!("exit code 2536 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2537Ex2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2537Ex2514 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2537Ex2514 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2537Ex2514 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2537_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2537)));
    match vm.run() {
        VMResult::Ok(Value::Status(2537)) => {}
        other => panic!("exit code 2537 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2538Ex2514() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2538)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2538);
}

#[test]
fn subshell_end_exit_code_2538_propagatesEx2514() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2538)));
    match vm.run() {
        VMResult::Ok(Value::Status(2538)) => {}
        other => panic!("exit code 2538 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CN (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2539_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2539)));
    match vm.run() {
        VMResult::Ok(Value::Status(2539)) => {}
        other => panic!("exit code 2539 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_four_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..484 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2540_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2540)));
    match vm.run() {
        VMResult::Ok(Value::Status(2540)) => {}
        other => panic!("exit code 2540 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_five_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..485 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2541_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2541)));
    match vm.run() {
        VMResult::Ok(Value::Status(2541)) => {}
        other => panic!("exit code 2541 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_six_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..486 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2542_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2542)));
    match vm.run() {
        VMResult::Ok(Value::Status(2542)) => {}
        other => panic!("exit code 2542 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_six_end_incrementing_from_sixEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..326 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 102 }));
    match vm.run() {
        VMResult::Ok(Value::Status(427)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(427)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2543_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2543)));
    match vm.run() {
        VMResult::Ok(Value::Status(2543)) => {}
        other => panic!("exit code 2543 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-328)));
    match vm.run() {
        VMResult::Ok(Value::Status(-328)) => {}
        other => panic!("status -328 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2544_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2544)));
    match vm.run() {
        VMResult::Ok(Value::Status(2544)) => {}
        other => panic!("exit code 2544 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-329)));
    match vm.run() {
        VMResult::Ok(Value::Status(-329)) => {}
        other => panic!("status -329 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2545_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2545)));
    match vm.run() {
        VMResult::Ok(Value::Status(2545)) => {}
        other => panic!("exit code 2545 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..174 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2539 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2539 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 174 {
                Some(2546)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2539 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2546)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2546)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2546_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2546)));
    match vm.run() {
        VMResult::Ok(Value::Status(2546)) => {}
        other => panic!("exit code 2546 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2547)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..84 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 87);
    assert_eq!(vm.last_status, 2547);
}

#[test]
fn subshell_end_exit_code_2547_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2547)));
    match vm.run() {
        VMResult::Ok(Value::Status(2547)) => {}
        other => panic!("exit code 2547 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2548Ex2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2548)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2548);
}

#[test]
fn subshell_end_exit_code_2548_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2548)));
    match vm.run() {
        VMResult::Ok(Value::Status(2548)) => {}
        other => panic!("exit code 2548 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_three_begins_eighty_one_ends_last_end_status_winsEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..83 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..81 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2549Ex2539;
    impl ShellHost for CountingBeginEndHost2549Ex2539 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2549)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2549Ex2539));
    match vm.run() {
        VMResult::Ok(Value::Status(2549)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2549)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 83);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 81);
}

#[test]
fn subshell_end_exit_code_2549_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2549)));
    match vm.run() {
        VMResult::Ok(Value::Status(2549)) => {}
        other => panic!("exit code 2549 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2550Ex2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2550)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2550);
}

#[test]
fn subshell_end_exit_code_2550_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2550)));
    match vm.run() {
        VMResult::Ok(Value::Status(2550)) => {}
        other => panic!("exit code 2550 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2539() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2551)));
    for _ in 0..84 {
        match vm.run() {
            VMResult::Ok(Value::Status(2551)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2551_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2551)));
    match vm.run() {
        VMResult::Ok(Value::Status(2551)) => {}
        other => panic!("exit code 2551 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2552Ex2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2552)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2552);
}

#[test]
fn subshell_end_exit_code_2552_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2552)));
    match vm.run() {
        VMResult::Ok(Value::Status(2552)) => {}
        other => panic!("exit code 2552 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_seven_end_incrementing_from_sevenEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..327 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 103 }));
    match vm.run() {
        VMResult::Ok(Value::Status(429)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(429)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2553_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2553)));
    match vm.run() {
        VMResult::Ok(Value::Status(2553)) => {}
        other => panic!("exit code 2553 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2554Ex2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2554)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2554);
}

#[test]
fn subshell_end_exit_code_2554_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2554)));
    match vm.run() {
        VMResult::Ok(Value::Status(2554)) => {}
        other => panic!("exit code 2554 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_seven_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..487 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2555_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2555)));
    match vm.run() {
        VMResult::Ok(Value::Status(2555)) => {}
        other => panic!("exit code 2555 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..175 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2539 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2539 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 175 {
                Some(2556)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2539 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2556)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2556)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2556_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2556)));
    match vm.run() {
        VMResult::Ok(Value::Status(2556)) => {}
        other => panic!("exit code 2556 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2557_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2557)));
    match vm.run() {
        VMResult::Ok(Value::Status(2557)) => {}
        other => panic!("exit code 2557 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2558Ex2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2558)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2558);
}

#[test]
fn subshell_end_exit_code_2558_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2558)));
    match vm.run() {
        VMResult::Ok(Value::Status(2558)) => {}
        other => panic!("exit code 2558 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_eight_end_incrementing_from_oneEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..328 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 97 }));
    match vm.run() {
        VMResult::Ok(Value::Status(424)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(424)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2559_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2559)));
    match vm.run() {
        VMResult::Ok(Value::Status(2559)) => {}
        other => panic!("exit code 2559 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2560;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2560)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2560, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2560_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2560)));
    match vm.run() {
        VMResult::Ok(Value::Status(2560)) => {}
        other => panic!("exit code 2560 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2561,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2561)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2561), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2561_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2561)));
    match vm.run() {
        VMResult::Ok(Value::Status(2561)) => {}
        other => panic!("exit code 2561 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_eight_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..488 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2562_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2562)));
    match vm.run() {
        VMResult::Ok(Value::Status(2562)) => {}
        other => panic!("exit code 2562 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..176 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2539 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2539 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 176 {
                Some(2563)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2539 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2563)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2563)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2563_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2563)));
    match vm.run() {
        VMResult::Ok(Value::Status(2563)) => {}
        other => panic!("exit code 2563 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2564Ex2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2564Ex2539;
    impl ShellHost for PipelineSubshellHost2564Ex2539 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2564)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2564Ex2539));
    match vm.run() {
        VMResult::Ok(Value::Status(2564)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2564_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2564)));
    match vm.run() {
        VMResult::Ok(Value::Status(2564)) => {}
        other => panic!("exit code 2564 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2565Ex2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2565Ex2539;
    impl ShellHost for SubshellThenPipelineHost2565Ex2539 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2565
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2565Ex2539));
    match vm.run() {
        VMResult::Ok(Value::Status(2565)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2565_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2565)));
    match vm.run() {
        VMResult::Ok(Value::Status(2565)) => {}
        other => panic!("exit code 2565 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-330)));
    match vm.run() {
        VMResult::Ok(Value::Status(-330)) => {}
        other => panic!("status -330 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2566_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2566)));
    match vm.run() {
        VMResult::Ok(Value::Status(2566)) => {}
        other => panic!("exit code 2566 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_twenty_nine_end_incrementing_from_eightEx2539() {
    let mut b = ChunkBuilder::new();
    for _ in 0..329 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 104 }));
    match vm.run() {
        VMResult::Ok(Value::Status(432)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(432)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2567_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2567)));
    match vm.run() {
        VMResult::Ok(Value::Status(2567)) => {}
        other => panic!("exit code 2567 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_eighty_nine_consecutive_runs_without_reset_still_blockedEx2539() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..489 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2568_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2568)));
    match vm.run() {
        VMResult::Ok(Value::Status(2568)) => {}
        other => panic!("exit code 2568 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2569Ex2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2569Ex2539 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2569Ex2539 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2569Ex2539 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2569_propagatesEx2539() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2569)));
    match vm.run() {
        VMResult::Ok(Value::Status(2569)) => {}
        other => panic!("exit code 2569 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CO (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2570_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2570)));
    match vm.run() {
        VMResult::Ok(Value::Status(2570)) => {}
        other => panic!("exit code 2570 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_consecutive_runs_without_reset_still_blockedEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..490 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2571_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2571)));
    match vm.run() {
        VMResult::Ok(Value::Status(2571)) => {}
        other => panic!("exit code 2571 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_one_consecutive_runs_without_reset_still_blockedEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..491 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2572_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2572)));
    match vm.run() {
        VMResult::Ok(Value::Status(2572)) => {}
        other => panic!("exit code 2572 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_two_consecutive_runs_without_reset_still_blockedEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..492 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2573_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2573)));
    match vm.run() {
        VMResult::Ok(Value::Status(2573)) => {}
        other => panic!("exit code 2573 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2574_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2574)));
    match vm.run() {
        VMResult::Ok(Value::Status(2574)) => {}
        other => panic!("exit code 2574 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-332)));
    match vm.run() {
        VMResult::Ok(Value::Status(-332)) => {}
        other => panic!("status -332 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2575_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2575)));
    match vm.run() {
        VMResult::Ok(Value::Status(2575)) => {}
        other => panic!("exit code 2575 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-333)));
    match vm.run() {
        VMResult::Ok(Value::Status(-333)) => {}
        other => panic!("status -333 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2576_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2576)));
    match vm.run() {
        VMResult::Ok(Value::Status(2576)) => {}
        other => panic!("exit code 2576 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..177 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2570 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2570 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 177 {
                Some(2577)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2570 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2577)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2577)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2577_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2577)));
    match vm.run() {
        VMResult::Ok(Value::Status(2577)) => {}
        other => panic!("exit code 2577 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2578)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..85 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 88);
    assert_eq!(vm.last_status, 2578);
}

#[test]
fn subshell_end_exit_code_2578_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2578)));
    match vm.run() {
        VMResult::Ok(Value::Status(2578)) => {}
        other => panic!("exit code 2578 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2579Ex2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2579)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2579);
}

#[test]
fn subshell_end_exit_code_2579_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2579)));
    match vm.run() {
        VMResult::Ok(Value::Status(2579)) => {}
        other => panic!("exit code 2579 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_four_begins_eighty_two_ends_last_end_status_winsEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..84 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..82 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2580Ex2570;
    impl ShellHost for CountingBeginEndHost2580Ex2570 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2580)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2580Ex2570));
    match vm.run() {
        VMResult::Ok(Value::Status(2580)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2580)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 84);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 82);
}

#[test]
fn subshell_end_exit_code_2580_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2580)));
    match vm.run() {
        VMResult::Ok(Value::Status(2580)) => {}
        other => panic!("exit code 2580 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2581Ex2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2570;
    impl ShellHost for CountingBeginHost733Ex2570 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2581)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2570));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2581);
}

#[test]
fn subshell_end_exit_code_2581_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2581)));
    match vm.run() {
        VMResult::Ok(Value::Status(2581)) => {}
        other => panic!("exit code 2581 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2570() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2582)));
    for _ in 0..85 {
        match vm.run() {
            VMResult::Ok(Value::Status(2582)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2582_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2582)));
    match vm.run() {
        VMResult::Ok(Value::Status(2582)) => {}
        other => panic!("exit code 2582 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2583Ex2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2583)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2583);
}

#[test]
fn subshell_end_exit_code_2583_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2583)));
    match vm.run() {
        VMResult::Ok(Value::Status(2583)) => {}
        other => panic!("exit code 2583 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2584_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2584)));
    match vm.run() {
        VMResult::Ok(Value::Status(2584)) => {}
        other => panic!("exit code 2584 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2585Ex2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2585)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2585);
}

#[test]
fn subshell_end_exit_code_2585_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2585)));
    match vm.run() {
        VMResult::Ok(Value::Status(2585)) => {}
        other => panic!("exit code 2585 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_three_consecutive_runs_without_reset_still_blockedEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..493 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2586_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2586)));
    match vm.run() {
        VMResult::Ok(Value::Status(2586)) => {}
        other => panic!("exit code 2586 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_four_consecutive_runs_without_reset_still_blockedEx2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..494 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2587_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2587)));
    match vm.run() {
        VMResult::Ok(Value::Status(2587)) => {}
        other => panic!("exit code 2587 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2588_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2588)));
    match vm.run() {
        VMResult::Ok(Value::Status(2588)) => {}
        other => panic!("exit code 2588 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2589;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2589)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2589, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2589_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2589)));
    match vm.run() {
        VMResult::Ok(Value::Status(2589)) => {}
        other => panic!("exit code 2589 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2590,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2590)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2590), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2590_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2590)));
    match vm.run() {
        VMResult::Ok(Value::Status(2590)) => {}
        other => panic!("exit code 2590 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-334)));
    match vm.run() {
        VMResult::Ok(Value::Status(-334)) => {}
        other => panic!("status -334 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2591_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2591)));
    match vm.run() {
        VMResult::Ok(Value::Status(2591)) => {}
        other => panic!("exit code 2591 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_two_end_incrementing_from_fiveEx2570() {
    let mut b = ChunkBuilder::new();
    for _ in 0..332 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 104 }));
    match vm.run() {
        VMResult::Ok(Value::Status(435)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(435)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2592_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2592)));
    match vm.run() {
        VMResult::Ok(Value::Status(2592)) => {}
        other => panic!("exit code 2592 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2593Ex2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2593Ex2570 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2593Ex2570 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2593Ex2570 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2593_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2593)));
    match vm.run() {
        VMResult::Ok(Value::Status(2593)) => {}
        other => panic!("exit code 2593 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2594Ex2570() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2594)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2594);
}

#[test]
fn subshell_end_exit_code_2594_propagatesEx2570() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2594)));
    match vm.run() {
        VMResult::Ok(Value::Status(2594)) => {}
        other => panic!("exit code 2594 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CP (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2595_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2595)));
    match vm.run() {
        VMResult::Ok(Value::Status(2595)) => {}
        other => panic!("exit code 2595 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_five_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..495 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2596_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2596)));
    match vm.run() {
        VMResult::Ok(Value::Status(2596)) => {}
        other => panic!("exit code 2596 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_six_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..496 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2597_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2597)));
    match vm.run() {
        VMResult::Ok(Value::Status(2597)) => {}
        other => panic!("exit code 2597 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_seven_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..497 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2598_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2598)));
    match vm.run() {
        VMResult::Ok(Value::Status(2598)) => {}
        other => panic!("exit code 2598 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_three_end_incrementing_from_sixEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..333 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 105 }));
    match vm.run() {
        VMResult::Ok(Value::Status(437)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(437)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2599_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2599)));
    match vm.run() {
        VMResult::Ok(Value::Status(2599)) => {}
        other => panic!("exit code 2599 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-335)));
    match vm.run() {
        VMResult::Ok(Value::Status(-335)) => {}
        other => panic!("status -335 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2600_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2600)));
    match vm.run() {
        VMResult::Ok(Value::Status(2600)) => {}
        other => panic!("exit code 2600 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-336)));
    match vm.run() {
        VMResult::Ok(Value::Status(-336)) => {}
        other => panic!("status -336 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2601_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2601)));
    match vm.run() {
        VMResult::Ok(Value::Status(2601)) => {}
        other => panic!("exit code 2601 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..178 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2595 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2595 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 178 {
                Some(2602)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2595 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2602)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2602)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2602_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2602)));
    match vm.run() {
        VMResult::Ok(Value::Status(2602)) => {}
        other => panic!("exit code 2602 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2603)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..86 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 89);
    assert_eq!(vm.last_status, 2603);
}

#[test]
fn subshell_end_exit_code_2603_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2603)));
    match vm.run() {
        VMResult::Ok(Value::Status(2603)) => {}
        other => panic!("exit code 2603 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2604Ex2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2604)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2604);
}

#[test]
fn subshell_end_exit_code_2604_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2604)));
    match vm.run() {
        VMResult::Ok(Value::Status(2604)) => {}
        other => panic!("exit code 2604 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_five_begins_eighty_three_ends_last_end_status_winsEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..85 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..83 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2605Ex2595;
    impl ShellHost for CountingBeginEndHost2605Ex2595 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2605)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2605Ex2595));
    match vm.run() {
        VMResult::Ok(Value::Status(2605)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2605)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 85);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 83);
}

#[test]
fn subshell_end_exit_code_2605_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2605)));
    match vm.run() {
        VMResult::Ok(Value::Status(2605)) => {}
        other => panic!("exit code 2605 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2606Ex2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2606)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2606);
}

#[test]
fn subshell_end_exit_code_2606_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2606)));
    match vm.run() {
        VMResult::Ok(Value::Status(2606)) => {}
        other => panic!("exit code 2606 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2595() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2607)));
    for _ in 0..86 {
        match vm.run() {
            VMResult::Ok(Value::Status(2607)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2607_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2607)));
    match vm.run() {
        VMResult::Ok(Value::Status(2607)) => {}
        other => panic!("exit code 2607 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2608Ex2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2608)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2608);
}

#[test]
fn subshell_end_exit_code_2608_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2608)));
    match vm.run() {
        VMResult::Ok(Value::Status(2608)) => {}
        other => panic!("exit code 2608 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_four_end_incrementing_from_sevenEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..334 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 106 }));
    match vm.run() {
        VMResult::Ok(Value::Status(439)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(439)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2609_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2609)));
    match vm.run() {
        VMResult::Ok(Value::Status(2609)) => {}
        other => panic!("exit code 2609 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2610Ex2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2610)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2610);
}

#[test]
fn subshell_end_exit_code_2610_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2610)));
    match vm.run() {
        VMResult::Ok(Value::Status(2610)) => {}
        other => panic!("exit code 2610 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_eight_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..498 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2611_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2611)));
    match vm.run() {
        VMResult::Ok(Value::Status(2611)) => {}
        other => panic!("exit code 2611 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..179 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2595 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2595 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 179 {
                Some(2612)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2595 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2612)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2612)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2612_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2612)));
    match vm.run() {
        VMResult::Ok(Value::Status(2612)) => {}
        other => panic!("exit code 2612 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2613_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2613)));
    match vm.run() {
        VMResult::Ok(Value::Status(2613)) => {}
        other => panic!("exit code 2613 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2614Ex2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2614)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2614);
}

#[test]
fn subshell_end_exit_code_2614_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2614)));
    match vm.run() {
        VMResult::Ok(Value::Status(2614)) => {}
        other => panic!("exit code 2614 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_five_end_incrementing_from_oneEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..335 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 100 }));
    match vm.run() {
        VMResult::Ok(Value::Status(434)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(434)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2615_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2615)));
    match vm.run() {
        VMResult::Ok(Value::Status(2615)) => {}
        other => panic!("exit code 2615 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2616;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2616)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2616, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2616_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2616)));
    match vm.run() {
        VMResult::Ok(Value::Status(2616)) => {}
        other => panic!("exit code 2616 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2617,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2617)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2617), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2617_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2617)));
    match vm.run() {
        VMResult::Ok(Value::Status(2617)) => {}
        other => panic!("exit code 2617 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_four_hundred_ninety_nine_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..499 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2618_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2618)));
    match vm.run() {
        VMResult::Ok(Value::Status(2618)) => {}
        other => panic!("exit code 2618 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..180 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2595 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2595 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 180 {
                Some(2619)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2595 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2619)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2619)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2619_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2619)));
    match vm.run() {
        VMResult::Ok(Value::Status(2619)) => {}
        other => panic!("exit code 2619 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2620Ex2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2620Ex2595;
    impl ShellHost for PipelineSubshellHost2620Ex2595 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2620)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2620Ex2595));
    match vm.run() {
        VMResult::Ok(Value::Status(2620)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2620_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2620)));
    match vm.run() {
        VMResult::Ok(Value::Status(2620)) => {}
        other => panic!("exit code 2620 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2621Ex2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2621Ex2595;
    impl ShellHost for SubshellThenPipelineHost2621Ex2595 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2621
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2621Ex2595));
    match vm.run() {
        VMResult::Ok(Value::Status(2621)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2621_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2621)));
    match vm.run() {
        VMResult::Ok(Value::Status(2621)) => {}
        other => panic!("exit code 2621 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-337)));
    match vm.run() {
        VMResult::Ok(Value::Status(-337)) => {}
        other => panic!("status -337 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2622_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2622)));
    match vm.run() {
        VMResult::Ok(Value::Status(2622)) => {}
        other => panic!("exit code 2622 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_six_end_incrementing_from_eightEx2595() {
    let mut b = ChunkBuilder::new();
    for _ in 0..336 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 107 }));
    match vm.run() {
        VMResult::Ok(Value::Status(442)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(442)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2623_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2623)));
    match vm.run() {
        VMResult::Ok(Value::Status(2623)) => {}
        other => panic!("exit code 2623 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_consecutive_runs_without_reset_still_blockedEx2595() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..500 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2624_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2624)));
    match vm.run() {
        VMResult::Ok(Value::Status(2624)) => {}
        other => panic!("exit code 2624 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2625Ex2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2625Ex2595 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2625Ex2595 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2625Ex2595 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2625_propagatesEx2595() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2625)));
    match vm.run() {
        VMResult::Ok(Value::Status(2625)) => {}
        other => panic!("exit code 2625 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CQ (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2626_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2626)));
    match vm.run() {
        VMResult::Ok(Value::Status(2626)) => {}
        other => panic!("exit code 2626 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_one_consecutive_runs_without_reset_still_blockedEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..501 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2627_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2627)));
    match vm.run() {
        VMResult::Ok(Value::Status(2627)) => {}
        other => panic!("exit code 2627 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_two_consecutive_runs_without_reset_still_blockedEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..502 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2628_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2628)));
    match vm.run() {
        VMResult::Ok(Value::Status(2628)) => {}
        other => panic!("exit code 2628 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_three_consecutive_runs_without_reset_still_blockedEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..503 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2629_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2629)));
    match vm.run() {
        VMResult::Ok(Value::Status(2629)) => {}
        other => panic!("exit code 2629 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2630_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2630)));
    match vm.run() {
        VMResult::Ok(Value::Status(2630)) => {}
        other => panic!("exit code 2630 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-339)));
    match vm.run() {
        VMResult::Ok(Value::Status(-339)) => {}
        other => panic!("status -339 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2631_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2631)));
    match vm.run() {
        VMResult::Ok(Value::Status(2631)) => {}
        other => panic!("exit code 2631 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-340)));
    match vm.run() {
        VMResult::Ok(Value::Status(-340)) => {}
        other => panic!("status -340 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2632_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2632)));
    match vm.run() {
        VMResult::Ok(Value::Status(2632)) => {}
        other => panic!("exit code 2632 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..181 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2626 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2626 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 181 {
                Some(2633)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2626 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2633)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2633)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2633_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2633)));
    match vm.run() {
        VMResult::Ok(Value::Status(2633)) => {}
        other => panic!("exit code 2633 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2634)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..87 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 90);
    assert_eq!(vm.last_status, 2634);
}

#[test]
fn subshell_end_exit_code_2634_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2634)));
    match vm.run() {
        VMResult::Ok(Value::Status(2634)) => {}
        other => panic!("exit code 2634 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2635Ex2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2635)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2635);
}

#[test]
fn subshell_end_exit_code_2635_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2635)));
    match vm.run() {
        VMResult::Ok(Value::Status(2635)) => {}
        other => panic!("exit code 2635 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_six_begins_eighty_four_ends_last_end_status_winsEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..86 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..84 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2636Ex2626;
    impl ShellHost for CountingBeginEndHost2636Ex2626 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2636)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2636Ex2626));
    match vm.run() {
        VMResult::Ok(Value::Status(2636)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2636)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 86);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 84);
}

#[test]
fn subshell_end_exit_code_2636_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2636)));
    match vm.run() {
        VMResult::Ok(Value::Status(2636)) => {}
        other => panic!("exit code 2636 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2637Ex2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2626;
    impl ShellHost for CountingBeginHost733Ex2626 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2637)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2626));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2637);
}

#[test]
fn subshell_end_exit_code_2637_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2637)));
    match vm.run() {
        VMResult::Ok(Value::Status(2637)) => {}
        other => panic!("exit code 2637 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2626() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2638)));
    for _ in 0..87 {
        match vm.run() {
            VMResult::Ok(Value::Status(2638)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2638_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2638)));
    match vm.run() {
        VMResult::Ok(Value::Status(2638)) => {}
        other => panic!("exit code 2638 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2639Ex2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2639)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2639);
}

#[test]
fn subshell_end_exit_code_2639_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2639)));
    match vm.run() {
        VMResult::Ok(Value::Status(2639)) => {}
        other => panic!("exit code 2639 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2640_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2640)));
    match vm.run() {
        VMResult::Ok(Value::Status(2640)) => {}
        other => panic!("exit code 2640 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2641Ex2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2641)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2641);
}

#[test]
fn subshell_end_exit_code_2641_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2641)));
    match vm.run() {
        VMResult::Ok(Value::Status(2641)) => {}
        other => panic!("exit code 2641 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_four_consecutive_runs_without_reset_still_blockedEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..504 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2642_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2642)));
    match vm.run() {
        VMResult::Ok(Value::Status(2642)) => {}
        other => panic!("exit code 2642 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_five_consecutive_runs_without_reset_still_blockedEx2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..505 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2643_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2643)));
    match vm.run() {
        VMResult::Ok(Value::Status(2643)) => {}
        other => panic!("exit code 2643 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2644_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2644)));
    match vm.run() {
        VMResult::Ok(Value::Status(2644)) => {}
        other => panic!("exit code 2644 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2645;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2645)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2645, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2645_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2645)));
    match vm.run() {
        VMResult::Ok(Value::Status(2645)) => {}
        other => panic!("exit code 2645 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2646,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2646)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2646), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2646_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2646)));
    match vm.run() {
        VMResult::Ok(Value::Status(2646)) => {}
        other => panic!("exit code 2646 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-341)));
    match vm.run() {
        VMResult::Ok(Value::Status(-341)) => {}
        other => panic!("status -341 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2647_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2647)));
    match vm.run() {
        VMResult::Ok(Value::Status(2647)) => {}
        other => panic!("exit code 2647 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_thirty_nine_end_incrementing_from_fiveEx2626() {
    let mut b = ChunkBuilder::new();
    for _ in 0..339 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 107 }));
    match vm.run() {
        VMResult::Ok(Value::Status(445)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(445)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2648_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2648)));
    match vm.run() {
        VMResult::Ok(Value::Status(2648)) => {}
        other => panic!("exit code 2648 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2649Ex2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2649Ex2626 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2649Ex2626 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2649Ex2626 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2649_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2649)));
    match vm.run() {
        VMResult::Ok(Value::Status(2649)) => {}
        other => panic!("exit code 2649 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2650Ex2626() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2650)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2650);
}

#[test]
fn subshell_end_exit_code_2650_propagatesEx2626() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2650)));
    match vm.run() {
        VMResult::Ok(Value::Status(2650)) => {}
        other => panic!("exit code 2650 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CR (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2651_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2651)));
    match vm.run() {
        VMResult::Ok(Value::Status(2651)) => {}
        other => panic!("exit code 2651 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_six_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..506 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2652_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2652)));
    match vm.run() {
        VMResult::Ok(Value::Status(2652)) => {}
        other => panic!("exit code 2652 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_seven_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..507 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2653_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2653)));
    match vm.run() {
        VMResult::Ok(Value::Status(2653)) => {}
        other => panic!("exit code 2653 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_eight_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..508 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2654_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2654)));
    match vm.run() {
        VMResult::Ok(Value::Status(2654)) => {}
        other => panic!("exit code 2654 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_end_incrementing_from_sixEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..340 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 108 }));
    match vm.run() {
        VMResult::Ok(Value::Status(447)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(447)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2655_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2655)));
    match vm.run() {
        VMResult::Ok(Value::Status(2655)) => {}
        other => panic!("exit code 2655 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-342)));
    match vm.run() {
        VMResult::Ok(Value::Status(-342)) => {}
        other => panic!("status -342 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2656_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2656)));
    match vm.run() {
        VMResult::Ok(Value::Status(2656)) => {}
        other => panic!("exit code 2656 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-343)));
    match vm.run() {
        VMResult::Ok(Value::Status(-343)) => {}
        other => panic!("status -343 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2657_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2657)));
    match vm.run() {
        VMResult::Ok(Value::Status(2657)) => {}
        other => panic!("exit code 2657 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..182 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2651 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2651 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 182 {
                Some(2658)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2651 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2658)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2658)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2658_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2658)));
    match vm.run() {
        VMResult::Ok(Value::Status(2658)) => {}
        other => panic!("exit code 2658 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2659)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..88 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 91);
    assert_eq!(vm.last_status, 2659);
}

#[test]
fn subshell_end_exit_code_2659_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2659)));
    match vm.run() {
        VMResult::Ok(Value::Status(2659)) => {}
        other => panic!("exit code 2659 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2660Ex2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2660)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2660);
}

#[test]
fn subshell_end_exit_code_2660_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2660)));
    match vm.run() {
        VMResult::Ok(Value::Status(2660)) => {}
        other => panic!("exit code 2660 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_seven_begins_eighty_five_ends_last_end_status_winsEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..87 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..85 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2661Ex2651;
    impl ShellHost for CountingBeginEndHost2661Ex2651 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2661)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2661Ex2651));
    match vm.run() {
        VMResult::Ok(Value::Status(2661)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2661)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 87);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 85);
}

#[test]
fn subshell_end_exit_code_2661_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2661)));
    match vm.run() {
        VMResult::Ok(Value::Status(2661)) => {}
        other => panic!("exit code 2661 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2662Ex2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2662)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2662);
}

#[test]
fn subshell_end_exit_code_2662_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2662)));
    match vm.run() {
        VMResult::Ok(Value::Status(2662)) => {}
        other => panic!("exit code 2662 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2651() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2663)));
    for _ in 0..88 {
        match vm.run() {
            VMResult::Ok(Value::Status(2663)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2663_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2663)));
    match vm.run() {
        VMResult::Ok(Value::Status(2663)) => {}
        other => panic!("exit code 2663 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2664Ex2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2664)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2664);
}

#[test]
fn subshell_end_exit_code_2664_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2664)));
    match vm.run() {
        VMResult::Ok(Value::Status(2664)) => {}
        other => panic!("exit code 2664 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_one_end_incrementing_from_sevenEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..341 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 109 }));
    match vm.run() {
        VMResult::Ok(Value::Status(449)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(449)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2665_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2665)));
    match vm.run() {
        VMResult::Ok(Value::Status(2665)) => {}
        other => panic!("exit code 2665 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2666Ex2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2666)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2666);
}

#[test]
fn subshell_end_exit_code_2666_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2666)));
    match vm.run() {
        VMResult::Ok(Value::Status(2666)) => {}
        other => panic!("exit code 2666 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_nine_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..509 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2667_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2667)));
    match vm.run() {
        VMResult::Ok(Value::Status(2667)) => {}
        other => panic!("exit code 2667 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..183 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2651 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2651 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 183 {
                Some(2668)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2651 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2668)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2668)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2668_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2668)));
    match vm.run() {
        VMResult::Ok(Value::Status(2668)) => {}
        other => panic!("exit code 2668 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2669_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2669)));
    match vm.run() {
        VMResult::Ok(Value::Status(2669)) => {}
        other => panic!("exit code 2669 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2670Ex2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2670)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2670);
}

#[test]
fn subshell_end_exit_code_2670_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2670)));
    match vm.run() {
        VMResult::Ok(Value::Status(2670)) => {}
        other => panic!("exit code 2670 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_two_end_incrementing_from_oneEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..342 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 103 }));
    match vm.run() {
        VMResult::Ok(Value::Status(444)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(444)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2671_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2671)));
    match vm.run() {
        VMResult::Ok(Value::Status(2671)) => {}
        other => panic!("exit code 2671 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2672;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2672)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2672, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2672_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2672)));
    match vm.run() {
        VMResult::Ok(Value::Status(2672)) => {}
        other => panic!("exit code 2672 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2673,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2673)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2673), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2673_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2673)));
    match vm.run() {
        VMResult::Ok(Value::Status(2673)) => {}
        other => panic!("exit code 2673 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_ten_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..510 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2674_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2674)));
    match vm.run() {
        VMResult::Ok(Value::Status(2674)) => {}
        other => panic!("exit code 2674 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..184 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2651 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2651 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 184 {
                Some(2675)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2651 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2675)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2675)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2675_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2675)));
    match vm.run() {
        VMResult::Ok(Value::Status(2675)) => {}
        other => panic!("exit code 2675 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2676Ex2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2676Ex2651;
    impl ShellHost for PipelineSubshellHost2676Ex2651 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2676)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2676Ex2651));
    match vm.run() {
        VMResult::Ok(Value::Status(2676)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2676_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2676)));
    match vm.run() {
        VMResult::Ok(Value::Status(2676)) => {}
        other => panic!("exit code 2676 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2677Ex2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2677Ex2651;
    impl ShellHost for SubshellThenPipelineHost2677Ex2651 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2677
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2677Ex2651));
    match vm.run() {
        VMResult::Ok(Value::Status(2677)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2677_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2677)));
    match vm.run() {
        VMResult::Ok(Value::Status(2677)) => {}
        other => panic!("exit code 2677 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-344)));
    match vm.run() {
        VMResult::Ok(Value::Status(-344)) => {}
        other => panic!("status -344 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2678_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2678)));
    match vm.run() {
        VMResult::Ok(Value::Status(2678)) => {}
        other => panic!("exit code 2678 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_three_end_incrementing_from_eightEx2651() {
    let mut b = ChunkBuilder::new();
    for _ in 0..343 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 110 }));
    match vm.run() {
        VMResult::Ok(Value::Status(452)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(452)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2679_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2679)));
    match vm.run() {
        VMResult::Ok(Value::Status(2679)) => {}
        other => panic!("exit code 2679 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_eleven_consecutive_runs_without_reset_still_blockedEx2651() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..511 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2680_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2680)));
    match vm.run() {
        VMResult::Ok(Value::Status(2680)) => {}
        other => panic!("exit code 2680 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2681Ex2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2681Ex2651 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2681Ex2651 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2681Ex2651 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2681_propagatesEx2651() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2681)));
    match vm.run() {
        VMResult::Ok(Value::Status(2681)) => {}
        other => panic!("exit code 2681 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CS (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2682_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2682)));
    match vm.run() {
        VMResult::Ok(Value::Status(2682)) => {}
        other => panic!("exit code 2682 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twelve_consecutive_runs_without_reset_still_blockedEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..512 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2683_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2683)));
    match vm.run() {
        VMResult::Ok(Value::Status(2683)) => {}
        other => panic!("exit code 2683 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_thirteen_consecutive_runs_without_reset_still_blockedEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..513 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2684_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2684)));
    match vm.run() {
        VMResult::Ok(Value::Status(2684)) => {}
        other => panic!("exit code 2684 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_fourteen_consecutive_runs_without_reset_still_blockedEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..514 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2685_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2685)));
    match vm.run() {
        VMResult::Ok(Value::Status(2685)) => {}
        other => panic!("exit code 2685 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2686_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2686)));
    match vm.run() {
        VMResult::Ok(Value::Status(2686)) => {}
        other => panic!("exit code 2686 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-346)));
    match vm.run() {
        VMResult::Ok(Value::Status(-346)) => {}
        other => panic!("status -346 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2687_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2687)));
    match vm.run() {
        VMResult::Ok(Value::Status(2687)) => {}
        other => panic!("exit code 2687 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-347)));
    match vm.run() {
        VMResult::Ok(Value::Status(-347)) => {}
        other => panic!("status -347 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2688_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2688)));
    match vm.run() {
        VMResult::Ok(Value::Status(2688)) => {}
        other => panic!("exit code 2688 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..185 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2682 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2682 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 185 {
                Some(2689)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2682 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2689)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2689)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2689_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2689)));
    match vm.run() {
        VMResult::Ok(Value::Status(2689)) => {}
        other => panic!("exit code 2689 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2690)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..89 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 92);
    assert_eq!(vm.last_status, 2690);
}

#[test]
fn subshell_end_exit_code_2690_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2690)));
    match vm.run() {
        VMResult::Ok(Value::Status(2690)) => {}
        other => panic!("exit code 2690 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2691Ex2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2691)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2691);
}

#[test]
fn subshell_end_exit_code_2691_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2691)));
    match vm.run() {
        VMResult::Ok(Value::Status(2691)) => {}
        other => panic!("exit code 2691 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_eight_begins_eighty_six_ends_last_end_status_winsEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..88 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..86 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2692Ex2682;
    impl ShellHost for CountingBeginEndHost2692Ex2682 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2692)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2692Ex2682));
    match vm.run() {
        VMResult::Ok(Value::Status(2692)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2692)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 88);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 86);
}

#[test]
fn subshell_end_exit_code_2692_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2692)));
    match vm.run() {
        VMResult::Ok(Value::Status(2692)) => {}
        other => panic!("exit code 2692 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2693Ex2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2682;
    impl ShellHost for CountingBeginHost733Ex2682 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2693)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2682));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2693);
}

#[test]
fn subshell_end_exit_code_2693_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2693)));
    match vm.run() {
        VMResult::Ok(Value::Status(2693)) => {}
        other => panic!("exit code 2693 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2682() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2694)));
    for _ in 0..89 {
        match vm.run() {
            VMResult::Ok(Value::Status(2694)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2694_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2694)));
    match vm.run() {
        VMResult::Ok(Value::Status(2694)) => {}
        other => panic!("exit code 2694 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2695Ex2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2695)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2695);
}

#[test]
fn subshell_end_exit_code_2695_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2695)));
    match vm.run() {
        VMResult::Ok(Value::Status(2695)) => {}
        other => panic!("exit code 2695 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2696_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2696)));
    match vm.run() {
        VMResult::Ok(Value::Status(2696)) => {}
        other => panic!("exit code 2696 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2697Ex2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2697)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2697);
}

#[test]
fn subshell_end_exit_code_2697_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2697)));
    match vm.run() {
        VMResult::Ok(Value::Status(2697)) => {}
        other => panic!("exit code 2697 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_fifteen_consecutive_runs_without_reset_still_blockedEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..515 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2698_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2698)));
    match vm.run() {
        VMResult::Ok(Value::Status(2698)) => {}
        other => panic!("exit code 2698 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_sixteen_consecutive_runs_without_reset_still_blockedEx2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..516 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2699_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2699)));
    match vm.run() {
        VMResult::Ok(Value::Status(2699)) => {}
        other => panic!("exit code 2699 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2700_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2700)));
    match vm.run() {
        VMResult::Ok(Value::Status(2700)) => {}
        other => panic!("exit code 2700 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2701;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2701)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2701, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2701_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2701)));
    match vm.run() {
        VMResult::Ok(Value::Status(2701)) => {}
        other => panic!("exit code 2701 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2702,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2702)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2702), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2702_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2702)));
    match vm.run() {
        VMResult::Ok(Value::Status(2702)) => {}
        other => panic!("exit code 2702 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-348)));
    match vm.run() {
        VMResult::Ok(Value::Status(-348)) => {}
        other => panic!("status -348 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2703_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2703)));
    match vm.run() {
        VMResult::Ok(Value::Status(2703)) => {}
        other => panic!("exit code 2703 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_six_end_incrementing_from_fiveEx2682() {
    let mut b = ChunkBuilder::new();
    for _ in 0..346 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 110 }));
    match vm.run() {
        VMResult::Ok(Value::Status(455)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(455)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2704_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2704)));
    match vm.run() {
        VMResult::Ok(Value::Status(2704)) => {}
        other => panic!("exit code 2704 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2705Ex2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2705Ex2682 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2705Ex2682 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2705Ex2682 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2705_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2705)));
    match vm.run() {
        VMResult::Ok(Value::Status(2705)) => {}
        other => panic!("exit code 2705 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2706Ex2682() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2706)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2706);
}

#[test]
fn subshell_end_exit_code_2706_propagatesEx2682() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2706)));
    match vm.run() {
        VMResult::Ok(Value::Status(2706)) => {}
        other => panic!("exit code 2706 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CT (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2707_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2707)));
    match vm.run() {
        VMResult::Ok(Value::Status(2707)) => {}
        other => panic!("exit code 2707 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_seventeen_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..517 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2708_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2708)));
    match vm.run() {
        VMResult::Ok(Value::Status(2708)) => {}
        other => panic!("exit code 2708 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_eighteen_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..518 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2709_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2709)));
    match vm.run() {
        VMResult::Ok(Value::Status(2709)) => {}
        other => panic!("exit code 2709 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_nineteen_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..519 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2710_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2710)));
    match vm.run() {
        VMResult::Ok(Value::Status(2710)) => {}
        other => panic!("exit code 2710 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_seven_end_incrementing_from_sixEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..347 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 111 }));
    match vm.run() {
        VMResult::Ok(Value::Status(457)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(457)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2711_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2711)));
    match vm.run() {
        VMResult::Ok(Value::Status(2711)) => {}
        other => panic!("exit code 2711 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-349)));
    match vm.run() {
        VMResult::Ok(Value::Status(-349)) => {}
        other => panic!("status -349 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2712_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2712)));
    match vm.run() {
        VMResult::Ok(Value::Status(2712)) => {}
        other => panic!("exit code 2712 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-350)));
    match vm.run() {
        VMResult::Ok(Value::Status(-350)) => {}
        other => panic!("status -350 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2713_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2713)));
    match vm.run() {
        VMResult::Ok(Value::Status(2713)) => {}
        other => panic!("exit code 2713 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..186 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2707 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2707 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 186 {
                Some(2714)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2707 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2714)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2714)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2714_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2714)));
    match vm.run() {
        VMResult::Ok(Value::Status(2714)) => {}
        other => panic!("exit code 2714 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2715)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..90 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 93);
    assert_eq!(vm.last_status, 2715);
}

#[test]
fn subshell_end_exit_code_2715_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2715)));
    match vm.run() {
        VMResult::Ok(Value::Status(2715)) => {}
        other => panic!("exit code 2715 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2716Ex2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2716)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2716);
}

#[test]
fn subshell_end_exit_code_2716_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2716)));
    match vm.run() {
        VMResult::Ok(Value::Status(2716)) => {}
        other => panic!("exit code 2716 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_eighty_nine_begins_eighty_seven_ends_last_end_status_winsEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..89 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..87 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2717Ex2707;
    impl ShellHost for CountingBeginEndHost2717Ex2707 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2717)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2717Ex2707));
    match vm.run() {
        VMResult::Ok(Value::Status(2717)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2717)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 89);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 87);
}

#[test]
fn subshell_end_exit_code_2717_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2717)));
    match vm.run() {
        VMResult::Ok(Value::Status(2717)) => {}
        other => panic!("exit code 2717 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2718Ex2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2718)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2718);
}

#[test]
fn subshell_end_exit_code_2718_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2718)));
    match vm.run() {
        VMResult::Ok(Value::Status(2718)) => {}
        other => panic!("exit code 2718 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2707() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2719)));
    for _ in 0..90 {
        match vm.run() {
            VMResult::Ok(Value::Status(2719)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2719_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2719)));
    match vm.run() {
        VMResult::Ok(Value::Status(2719)) => {}
        other => panic!("exit code 2719 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2720Ex2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2720)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2720);
}

#[test]
fn subshell_end_exit_code_2720_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2720)));
    match vm.run() {
        VMResult::Ok(Value::Status(2720)) => {}
        other => panic!("exit code 2720 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_eight_end_incrementing_from_sevenEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..348 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 112 }));
    match vm.run() {
        VMResult::Ok(Value::Status(459)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(459)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2721_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2721)));
    match vm.run() {
        VMResult::Ok(Value::Status(2721)) => {}
        other => panic!("exit code 2721 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2722Ex2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2722)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2722);
}

#[test]
fn subshell_end_exit_code_2722_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2722)));
    match vm.run() {
        VMResult::Ok(Value::Status(2722)) => {}
        other => panic!("exit code 2722 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..520 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2723_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2723)));
    match vm.run() {
        VMResult::Ok(Value::Status(2723)) => {}
        other => panic!("exit code 2723 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..187 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2707 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2707 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 187 {
                Some(2724)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2707 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2724)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2724)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2724_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2724)));
    match vm.run() {
        VMResult::Ok(Value::Status(2724)) => {}
        other => panic!("exit code 2724 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2725_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2725)));
    match vm.run() {
        VMResult::Ok(Value::Status(2725)) => {}
        other => panic!("exit code 2725 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2726Ex2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2726)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2726);
}

#[test]
fn subshell_end_exit_code_2726_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2726)));
    match vm.run() {
        VMResult::Ok(Value::Status(2726)) => {}
        other => panic!("exit code 2726 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_forty_nine_end_incrementing_from_oneEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..349 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 106 }));
    match vm.run() {
        VMResult::Ok(Value::Status(454)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(454)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2727_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2727)));
    match vm.run() {
        VMResult::Ok(Value::Status(2727)) => {}
        other => panic!("exit code 2727 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2728;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2728)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2728, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2728_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2728)));
    match vm.run() {
        VMResult::Ok(Value::Status(2728)) => {}
        other => panic!("exit code 2728 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2729,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2729)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2729), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2729_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2729)));
    match vm.run() {
        VMResult::Ok(Value::Status(2729)) => {}
        other => panic!("exit code 2729 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_one_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..521 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2730_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2730)));
    match vm.run() {
        VMResult::Ok(Value::Status(2730)) => {}
        other => panic!("exit code 2730 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..188 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2707 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2707 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 188 {
                Some(2731)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2707 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2731)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2731)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2731_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2731)));
    match vm.run() {
        VMResult::Ok(Value::Status(2731)) => {}
        other => panic!("exit code 2731 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2732Ex2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2732Ex2707;
    impl ShellHost for PipelineSubshellHost2732Ex2707 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2732)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2732Ex2707));
    match vm.run() {
        VMResult::Ok(Value::Status(2732)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2732_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2732)));
    match vm.run() {
        VMResult::Ok(Value::Status(2732)) => {}
        other => panic!("exit code 2732 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2733Ex2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2733Ex2707;
    impl ShellHost for SubshellThenPipelineHost2733Ex2707 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2733
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2733Ex2707));
    match vm.run() {
        VMResult::Ok(Value::Status(2733)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2733_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2733)));
    match vm.run() {
        VMResult::Ok(Value::Status(2733)) => {}
        other => panic!("exit code 2733 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-351)));
    match vm.run() {
        VMResult::Ok(Value::Status(-351)) => {}
        other => panic!("status -351 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2734_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2734)));
    match vm.run() {
        VMResult::Ok(Value::Status(2734)) => {}
        other => panic!("exit code 2734 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_end_incrementing_from_eightEx2707() {
    let mut b = ChunkBuilder::new();
    for _ in 0..350 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 113 }));
    match vm.run() {
        VMResult::Ok(Value::Status(462)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(462)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2735_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2735)));
    match vm.run() {
        VMResult::Ok(Value::Status(2735)) => {}
        other => panic!("exit code 2735 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_two_consecutive_runs_without_reset_still_blockedEx2707() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..522 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2736_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2736)));
    match vm.run() {
        VMResult::Ok(Value::Status(2736)) => {}
        other => panic!("exit code 2736 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2737Ex2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2737Ex2707 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2737Ex2707 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2737Ex2707 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2737_propagatesEx2707() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2737)));
    match vm.run() {
        VMResult::Ok(Value::Status(2737)) => {}
        other => panic!("exit code 2737 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CU (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2738_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2738)));
    match vm.run() {
        VMResult::Ok(Value::Status(2738)) => {}
        other => panic!("exit code 2738 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_three_consecutive_runs_without_reset_still_blockedEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..523 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2739_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2739)));
    match vm.run() {
        VMResult::Ok(Value::Status(2739)) => {}
        other => panic!("exit code 2739 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_four_consecutive_runs_without_reset_still_blockedEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..524 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2740_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2740)));
    match vm.run() {
        VMResult::Ok(Value::Status(2740)) => {}
        other => panic!("exit code 2740 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_five_consecutive_runs_without_reset_still_blockedEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..525 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2741_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2741)));
    match vm.run() {
        VMResult::Ok(Value::Status(2741)) => {}
        other => panic!("exit code 2741 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_nine_end_incrementing_from_tenEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..99 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 10 }));
    match vm.run() {
        VMResult::Ok(Value::Status(108)) => {}
        other => panic!(
            "ninety-ninth subshell_end(Some(108)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2742_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2742)));
    match vm.run() {
        VMResult::Ok(Value::Status(2742)) => {}
        other => panic!("exit code 2742 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_one_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-353)));
    match vm.run() {
        VMResult::Ok(Value::Status(-353)) => {}
        other => panic!("status -353 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2743_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2743)));
    match vm.run() {
        VMResult::Ok(Value::Status(2743)) => {}
        other => panic!("exit code 2743 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_two_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-354)));
    match vm.run() {
        VMResult::Ok(Value::Status(-354)) => {}
        other => panic!("status -354 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2744_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2744)));
    match vm.run() {
        VMResult::Ok(Value::Status(2744)) => {}
        other => panic!("exit code 2744 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_fifth_some_host_applies_on_forty_fifth_endEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..189 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyFifthSomeHostEx2738 {
        calls: u32,
    }
    impl ShellHost for FortyFifthSomeHostEx2738 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 189 {
                Some(2745)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 5;
    vm.set_shell_host(Box::new(FortyFifthSomeHostEx2738 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2745)) => {}
        other => panic!(
            "forty-fifth subshell_end(Some(2745)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2745_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2745)));
    match vm.run() {
        VMResult::Ok(Value::Status(2745)) => {}
        other => panic!("exit code 2745 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_second_run_appliesEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2746)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..91 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 94);
    assert_eq!(vm.last_status, 2746);
}

#[test]
fn subshell_end_exit_code_2746_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2746)));
    match vm.run() {
        VMResult::Ok(Value::Status(2746)) => {}
        other => panic!("exit code 2746 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_int_pair_after_subshell_end_status2747Ex2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadInt(11), 1);
    b.emit(Op::LoadInt(22), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2747)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2747);
}

#[test]
fn subshell_end_exit_code_2747_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2747)));
    match vm.run() {
        VMResult::Ok(Value::Status(2747)) => {}
        other => panic!("exit code 2747 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_begins_eighty_eight_ends_last_end_status_winsEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..90 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..88 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2748Ex2738;
    impl ShellHost for CountingBeginEndHost2748Ex2738 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2748)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2748Ex2738));
    match vm.run() {
        VMResult::Ok(Value::Status(2748)) => {}
        other => panic!(
            "sixteenth subshell_end(Some(2748)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 90);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 88);
}

#[test]
fn subshell_end_exit_code_2748_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2748)));
    match vm.run() {
        VMResult::Ok(Value::Status(2748)) => {}
        other => panic!("exit code 2748 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_second_subshell_begin_after_subshell_end_status2749Ex2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    struct CountingBeginHost733Ex2738;
    impl ShellHost for CountingBeginHost733Ex2738 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2749)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginHost733Ex2738));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2749);
}

#[test]
fn subshell_end_exit_code_2749_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2749)));
    match vm.run() {
        VMResult::Ok(Value::Status(2749)) => {}
        other => panic!("exit code 2749 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_nineteen_reset_runs_same_host_same_statusEx2738() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2750)));
    for _ in 0..91 {
        match vm.run() {
            VMResult::Ok(Value::Status(2750)) => {}
            other => panic!("reset run MUST return Status(734), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2750_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2750)));
    match vm.run() {
        VMResult::Ok(Value::Status(2750)) => {}
        other => panic!("exit code 2750 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_le_after_subshell_end_status2751Ex2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::LoadInt(8), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumLe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2751)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2751);
}

#[test]
fn subshell_end_exit_code_2751_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2751)));
    match vm.run() {
        VMResult::Ok(Value::Status(2751)) => {}
        other => panic!("exit code 2751 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_end_incrementing_from_threeEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..100 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 3 }));
    match vm.run() {
        VMResult::Ok(Value::Status(102)) => {}
        other => panic!(
            "one-hundredth subshell_end(Some(102)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2752_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2752)));
    match vm.run() {
        VMResult::Ok(Value::Status(2752)) => {}
        other => panic!("exit code 2752 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_num_ge_after_subshell_end_status2753Ex2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(9), 1);
    b.emit(Op::LoadInt(3), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::NumGe, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2753)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2753);
}

#[test]
fn subshell_end_exit_code_2753_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2753)));
    match vm.run() {
        VMResult::Ok(Value::Status(2753)) => {}
        other => panic!("exit code 2753 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_six_consecutive_runs_without_reset_still_blockedEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..526 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2754_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2754)));
    match vm.run() {
        VMResult::Ok(Value::Status(2754)) => {}
        other => panic!("exit code 2754 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_seven_consecutive_runs_without_reset_still_blockedEx2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..527 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2755_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2755)));
    match vm.run() {
        VMResult::Ok(Value::Status(2755)) => {}
        other => panic!("exit code 2755 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_second_none_keeps_ninthEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-second None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2756_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2756)));
    match vm.run() {
        VMResult::Ok(Value::Status(2756)) => {}
        other => panic!("exit code 2756 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_one_ends_leaves_initial_statusEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2757;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2757)) => {}
        other => panic!(
            "NoneHost twenty-one ends MUST leave last_status 2757, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2757_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2757)));
    match vm.run() {
        VMResult::Ok(Value::Status(2757)) => {}
        other => panic!("exit code 2757 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_first_none_keeps_firstEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..21 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2758,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2758)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-first None MUST keep first Some(2758), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2758_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2758)));
    match vm.run() {
        VMResult::Ok(Value::Status(2758)) => {}
        other => panic!("exit code 2758 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_three_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-355)));
    match vm.run() {
        VMResult::Ok(Value::Status(-355)) => {}
        other => panic!("status -355 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2759_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2759)));
    match vm.run() {
        VMResult::Ok(Value::Status(2759)) => {}
        other => panic!("exit code 2759 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_three_end_incrementing_from_fiveEx2738() {
    let mut b = ChunkBuilder::new();
    for _ in 0..353 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 113 }));
    match vm.run() {
        VMResult::Ok(Value::Status(465)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(465)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2760_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2760)));
    match vm.run() {
        VMResult::Ok(Value::Status(2760)) => {}
        other => panic!("exit code 2760 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2761Ex2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2761Ex2738 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2761Ex2738 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-104)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2761Ex2738 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -104, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2761_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2761)));
    match vm.run() {
        VMResult::Ok(Value::Status(2761)) => {}
        other => panic!("exit code 2761 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_bit_xor_after_subshell_end_status2762Ex2738() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(15), 1);
    b.emit(Op::LoadInt(7), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::BitXor, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2762)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2762);
}

#[test]
fn subshell_end_exit_code_2762_propagatesEx2738() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2762)));
    match vm.run() {
        VMResult::Ok(Value::Status(2762)) => {}
        other => panic!("exit code 2762 MUST propagate, got {:?}", other),
    }
}

// ─── Pin tests batch CV (handwritten) ─────────────────────────────────────

#[test]
fn subshell_end_exit_code_2763_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2763)));
    match vm.run() {
        VMResult::Ok(Value::Status(2763)) => {}
        other => panic!("exit code 2763 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_eight_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..528 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2764_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2764)));
    match vm.run() {
        VMResult::Ok(Value::Status(2764)) => {}
        other => panic!("exit code 2764 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_twenty_nine_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..529 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2765_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2765)));
    match vm.run() {
        VMResult::Ok(Value::Status(2765)) => {}
        other => panic!("exit code 2765 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_thirty_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..530 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2766_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2766)));
    match vm.run() {
        VMResult::Ok(Value::Status(2766)) => {}
        other => panic!("exit code 2766 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_four_end_incrementing_from_sixEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..354 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 114 }));
    match vm.run() {
        VMResult::Ok(Value::Status(467)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(467)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2767_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2767)));
    match vm.run() {
        VMResult::Ok(Value::Status(2767)) => {}
        other => panic!("exit code 2767 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_four_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-356)));
    match vm.run() {
        VMResult::Ok(Value::Status(-356)) => {}
        other => panic!("status -356 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2768_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2768)));
    match vm.run() {
        VMResult::Ok(Value::Status(2768)) => {}
        other => panic!("exit code 2768 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_five_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-357)));
    match vm.run() {
        VMResult::Ok(Value::Status(-357)) => {}
        other => panic!("status -357 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2769_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2769)));
    match vm.run() {
        VMResult::Ok(Value::Status(2769)) => {}
        other => panic!("exit code 2769 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_sixth_some_host_applies_on_forty_sixth_endEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..190 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySixthSomeHostEx2763 {
        calls: u32,
    }
    impl ShellHost for FortySixthSomeHostEx2763 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 190 {
                Some(2770)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 8;
    vm.set_shell_host(Box::new(FortySixthSomeHostEx2763 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2770)) => {}
        other => panic!(
            "forty-sixth subshell_end(Some(2770)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2770_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2770)));
    match vm.run() {
        VMResult::Ok(Value::Status(2770)) => {}
        other => panic!("exit code 2770 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_halt_reset_subshell_end_twenty_third_run_appliesEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let sub = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::CallBuiltin(100, 0), 1);
        b.build()
    };
    let end_only = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.build()
    };
    let mut vm = VM::new(sub.clone());
    vm.set_shell_host(Box::new(CountingSubshellEndHost(2771)));
    vm.register_builtin(100, builtin_request_halt);
    let _ = vm.run();
    vm.reset(sub);
    let _ = vm.run();
    for _ in 0..92 {
        vm.reset(end_only.clone());
        let _ = vm.run();
    }
    vm.reset(end_only);
    let _ = vm.run();
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 95);
    assert_eq!(vm.last_status, 2771);
}

#[test]
fn subshell_end_exit_code_2771_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2771)));
    match vm.run() {
        VMResult::Ok(Value::Status(2771)) => {}
        other => panic!("exit code 2771 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_log_not_after_subshell_end_status2772Ex2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadFalse, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LogNot, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2772)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2772);
}

#[test]
fn subshell_end_exit_code_2772_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2772)));
    match vm.run() {
        VMResult::Ok(Value::Status(2772)) => {}
        other => panic!("exit code 2772 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_ninety_one_begins_eighty_nine_ends_last_end_status_winsEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    SUBSHELL_BEGIN_CALLS.store(0, Ordering::SeqCst);
    SUBSHELL_END_CALLS.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    for _ in 0..91 {
        b.emit(Op::SubshellBegin, 1);
    }
    for _ in 0..89 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct CountingBeginEndHost2773Ex2763;
    impl ShellHost for CountingBeginEndHost2773Ex2763 {
        fn subshell_begin(&mut self) {
            SUBSHELL_BEGIN_CALLS.fetch_add(1, Ordering::SeqCst);
        }
        fn subshell_end(&mut self) -> Option<i32> {
            SUBSHELL_END_CALLS.fetch_add(1, Ordering::SeqCst);
            Some(2773)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(CountingBeginEndHost2773Ex2763));
    match vm.run() {
        VMResult::Ok(Value::Status(2773)) => {}
        other => panic!(
            "seventeenth subshell_end(Some(2773)) MUST win, got {:?}",
            other
        ),
    }
    assert_eq!(SUBSHELL_BEGIN_CALLS.load(Ordering::SeqCst), 91);
    assert_eq!(SUBSHELL_END_CALLS.load(Ordering::SeqCst), 89);
}

#[test]
fn subshell_end_exit_code_2773_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2773)));
    match vm.run() {
        VMResult::Ok(Value::Status(2773)) => {}
        other => panic!("exit code 2773 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_negate_after_subshell_end_status2774Ex2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(6), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::Negate, 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2774)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2774);
}

#[test]
fn subshell_end_exit_code_2774_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2774)));
    match vm.run() {
        VMResult::Ok(Value::Status(2774)) => {}
        other => panic!("exit code 2774 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_twenty_reset_runs_same_host_same_statusEx2763() {
    let chunk = {
        let mut b = ChunkBuilder::new();
        b.emit(Op::SubshellEnd, 1);
        b.emit(Op::GetStatus, 1);
        b.build()
    };
    let mut vm = VM::new(chunk.clone());
    vm.set_shell_host(Box::new(StatusReturningHost(2775)));
    for _ in 0..92 {
        match vm.run() {
            VMResult::Ok(Value::Status(2775)) => {}
            other => panic!("reset run MUST return Status(759), got {:?}", other),
        }
        vm.reset(chunk.clone());
    }
}

#[test]
fn subshell_end_exit_code_2775_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2775)));
    match vm.run() {
        VMResult::Ok(Value::Status(2775)) => {}
        other => panic!("exit code 2775 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_make_array_after_subshell_end_status2776Ex2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::LoadInt(1), 1);
    b.emit(Op::LoadInt(2), 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::MakeArray(2), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2776)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2776);
}

#[test]
fn subshell_end_exit_code_2776_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2776)));
    match vm.run() {
        VMResult::Ok(Value::Status(2776)) => {}
        other => panic!("exit code 2776 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_five_end_incrementing_from_sevenEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..355 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 115 }));
    match vm.run() {
        VMResult::Ok(Value::Status(469)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(469)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2777_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2777)));
    match vm.run() {
        VMResult::Ok(Value::Status(2777)) => {}
        other => panic!("exit code 2777 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_concat_after_subshell_end_status2778Ex2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let chunk = {
        let mut cb = ChunkBuilder::new();
        let a = cb.add_constant(Value::str("p"));
        let bidx = cb.add_constant(Value::str("q"));
        cb.emit(Op::SubshellEnd, 1);
        cb.emit(Op::LoadConst(a), 1);
        cb.emit(Op::LoadConst(bidx), 1);
        cb.emit(Op::CallBuiltin(100, 0), 1);
        cb.emit(Op::Concat, 1);
        cb.emit(Op::CallBuiltin(200, 0), 1);
        cb.build()
    };
    let mut vm = VM::new(chunk);
    vm.set_shell_host(Box::new(StatusReturningHost(2778)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2778);
}

#[test]
fn subshell_end_exit_code_2778_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2778)));
    match vm.run() {
        VMResult::Ok(Value::Status(2778)) => {}
        other => panic!("exit code 2778 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_thirty_one_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..531 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2779_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2779)));
    match vm.run() {
        VMResult::Ok(Value::Status(2779)) => {}
        other => panic!("exit code 2779 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_seventh_some_host_applies_on_forty_seventh_endEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..191 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortySeventhSomeHostEx2763 {
        calls: u32,
    }
    impl ShellHost for FortySeventhSomeHostEx2763 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 191 {
                Some(2780)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 11;
    vm.set_shell_host(Box::new(FortySeventhSomeHostEx2763 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2780)) => {}
        other => panic!(
            "forty-seventh subshell_end(Some(2780)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2780_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2780)));
    match vm.run() {
        VMResult::Ok(Value::Status(2780)) => {}
        other => panic!("exit code 2780 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_alternating_status_twenty_third_none_keeps_ninthEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..23 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(AlternatingStatusHost { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(9)) => {}
        other => panic!(
            "AlternatingStatusHost twenty-third None MUST keep Some(9), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2781_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2781)));
    match vm.run() {
        VMResult::Ok(Value::Status(2781)) => {}
        other => panic!("exit code 2781 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_stops_before_load_float_after_subshell_end_status2782Ex2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    AFTER_HALT_COUNT.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::LoadFloat(2.5), 1);
    b.emit(Op::CallBuiltin(200, 0), 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2782)));
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(200, builtin_count_after_halt);
    let _ = vm.run();
    assert_eq!(AFTER_HALT_COUNT.load(Ordering::SeqCst), 0);
    assert_eq!(vm.last_status, 2782);
}

#[test]
fn subshell_end_exit_code_2782_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2782)));
    match vm.run() {
        VMResult::Ok(Value::Status(2782)) => {}
        other => panic!("exit code 2782 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_six_end_incrementing_from_oneEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..356 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 109 }));
    match vm.run() {
        VMResult::Ok(Value::Status(464)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(464)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2783_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2783)));
    match vm.run() {
        VMResult::Ok(Value::Status(2783)) => {}
        other => panic!("exit code 2783 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_none_host_twenty_two_ends_leaves_initial_statusEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.last_status = 2784;
    vm.set_shell_host(Box::new(NoneHost));
    match vm.run() {
        VMResult::Ok(Value::Status(2784)) => {}
        other => panic!(
            "NoneHost twenty-two ends MUST leave last_status 2784, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2784_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2784)));
    match vm.run() {
        VMResult::Ok(Value::Status(2784)) => {}
        other => panic!("exit code 2784 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_first_some_then_none_host_twenty_second_none_keeps_firstEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..22 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(FirstSomeThenNoneHost {
        calls: 0,
        status: 2785,
    }));
    match vm.run() {
        VMResult::Ok(Value::Status(2785)) => {}
        other => panic!(
            "FirstSomeThenNoneHost twenty-second None MUST keep first Some(2785), got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2785_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2785)));
    match vm.run() {
        VMResult::Ok(Value::Status(2785)) => {}
        other => panic!("exit code 2785 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_thirty_two_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..532 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2786_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2786)));
    match vm.run() {
        VMResult::Ok(Value::Status(2786)) => {}
        other => panic!("exit code 2786 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_forty_eighth_some_host_applies_on_forty_eighth_endEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..192 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    struct FortyEighthSomeHostEx2763 {
        calls: u32,
    }
    impl ShellHost for FortyEighthSomeHostEx2763 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 192 {
                Some(2787)
            } else {
                None
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.last_status = 2;
    vm.set_shell_host(Box::new(FortyEighthSomeHostEx2763 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(2787)) => {}
        other => panic!(
            "forty-eighth subshell_end(Some(2787)) MUST apply, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2787_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2787)));
    match vm.run() {
        VMResult::Ok(Value::Status(2787)) => {}
        other => panic!("exit code 2787 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_pipeline_then_subshell_getstatus_reads_subshell_2788Ex2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct PipelineSubshellHost2788Ex2763;
    impl ShellHost for PipelineSubshellHost2788Ex2763 {
        fn pipeline_end(&mut self) -> i32 {
            7
        }
        fn subshell_end(&mut self) -> Option<i32> {
            Some(2788)
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(PipelineSubshellHost2788Ex2763));
    match vm.run() {
        VMResult::Ok(Value::Status(2788)) => {}
        other => panic!(
            "GetStatus after pipeline+subshell MUST read subshell 772, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2788_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2788)));
    match vm.run() {
        VMResult::Ok(Value::Status(2788)) => {}
        other => panic!("exit code 2788 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_subshell_then_pipeline_getstatus_reads_pipeline_2789Ex2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::PipelineBegin(2), 1);
    b.emit(Op::PipelineEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct SubshellThenPipelineHost2789Ex2763;
    impl ShellHost for SubshellThenPipelineHost2789Ex2763 {
        fn subshell_end(&mut self) -> Option<i32> {
            Some(16)
        }
        fn pipeline_end(&mut self) -> i32 {
            2789
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(SubshellThenPipelineHost2789Ex2763));
    match vm.run() {
        VMResult::Ok(Value::Status(2789)) => {}
        other => panic!(
            "GetStatus after subshell+pipeline MUST read pipeline 773, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2789_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2789)));
    match vm.run() {
        VMResult::Ok(Value::Status(2789)) => {}
        other => panic!("exit code 2789 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_status_minus_one_hundred_six_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(-358)));
    match vm.run() {
        VMResult::Ok(Value::Status(-358)) => {}
        other => panic!("status -358 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_end_exit_code_2790_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2790)));
    match vm.run() {
        VMResult::Ok(Value::Status(2790)) => {}
        other => panic!("exit code 2790 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_one_hundred_three_hundred_fifty_seven_end_incrementing_from_eightEx2763() {
    let mut b = ChunkBuilder::new();
    for _ in 0..357 {
        b.emit(Op::SubshellEnd, 1);
    }
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(IncrementingSubshellHost { next: 116 }));
    match vm.run() {
        VMResult::Ok(Value::Status(472)) => {}
        other => panic!(
            "one-hundred-END subshell_end(Some(472)) MUST win, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2791_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2791)));
    match vm.run() {
        VMResult::Ok(Value::Status(2791)) => {}
        other => panic!("exit code 2791 MUST propagate, got {:?}", other),
    }
}

#[test]
fn request_halt_five_hundred_thirty_three_consecutive_runs_without_reset_still_blockedEx2763() {
    let _guard = PIN_TEST_LOCK.lock().unwrap();
    TOUCHED.store(0, Ordering::SeqCst);
    let mut b = ChunkBuilder::new();
    b.emit(Op::CallBuiltin(100, 0), 1);
    b.emit(Op::CallBuiltin(7, 0), 1);
    let mut vm = VM::new(b.build());
    vm.register_builtin(100, builtin_request_halt);
    vm.register_builtin(7, builtin_touched);
    for _ in 0..533 {
        let _ = vm.run();
    }
    assert_eq!(TOUCHED.load(Ordering::SeqCst), 0);
}

#[test]
fn subshell_end_exit_code_2792_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2792)));
    match vm.run() {
        VMResult::Ok(Value::Status(2792)) => {}
        other => panic!("exit code 2792 MUST propagate, got {:?}", other),
    }
}

#[test]
fn subshell_negative_then_zero_host_last_zero_wins_status2793Ex2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    struct NegativeThenZeroHost2793Ex2763 {
        calls: u32,
    }
    impl ShellHost for NegativeThenZeroHost2793Ex2763 {
        fn subshell_end(&mut self) -> Option<i32> {
            self.calls += 1;
            if self.calls == 1 {
                Some(-107)
            } else {
                Some(0)
            }
        }
    }
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(NegativeThenZeroHost2793Ex2763 { calls: 0 }));
    match vm.run() {
        VMResult::Ok(Value::Status(0)) => {}
        other => panic!(
            "second subshell_end(Some(0)) MUST win over -107, got {:?}",
            other
        ),
    }
}

#[test]
fn subshell_end_exit_code_2793_propagatesEx2763() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellEnd, 1);
    b.emit(Op::GetStatus, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(2793)));
    match vm.run() {
        VMResult::Ok(Value::Status(2793)) => {}
        other => panic!("exit code 2793 MUST propagate, got {:?}", other),
    }
}

// ─── Combined ───────────────────────────────────────────────────────────

#[test]
fn subshell_some_status_after_normal_run_matches_returned_value() {
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm = VM::new(b.build());
    vm.set_shell_host(Box::new(StatusReturningHost(7)));
    let _ = vm.run();
    assert_eq!(vm.last_status, 7);
}

#[test]
fn shell_op_runs_without_host_when_no_host_is_set() {
    // No set_shell_host → SubshellEnd op no-ops silently.
    let mut b = ChunkBuilder::new();
    b.emit(Op::SubshellBegin, 1);
    b.emit(Op::SubshellEnd, 1);
    let mut vm: VM = VM::new(b.build());
    let r = vm.run();
    assert!(matches!(r, VMResult::Ok(_) | VMResult::Halted));
}
