1
//! Plan 0011 Phase 3 slice 1 acceptance rows R3 and E, exercised end to end
2
//! (compile AND run) through the Session.
3

            
4
use super::*;
5

            
6
/// Row R3: a 5000-clause `COND`, every clause a genuine runtime test
7
/// (`RPC-PROTOCOL-VERSION` is a runtime host import, so none of them fold
8
/// at compile time), compiles and gives its value with no native stack
9
/// overflow — surviving this test at all is part of the proof, the
10
/// returned value pins that the runtime chain (a flat sequence of
11
/// `if`/`br 1`s, never nested) actually falls all the way through to the
12
/// tail (the protocol version never exceeds any of these thresholds).
13
#[tokio::test]
14
1
async fn a_five_thousand_clause_runtime_cond_compiles_and_gives_its_value() {
15
1
    let clauses: String = (0..4_999u32)
16
4999
        .map(|i| format!("((> (rpc-protocol-version) {}) {i})", i + 1_000_000))
17
        .collect::<Vec<_>>()
18
1
        .join(" ");
19
1
    let form = format!("(cond {clauses} (t 4999))");
20
1
    let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
21
1
    let outcome = session.handle_request(&form).await;
22
1
    assert_eq!(
23
1
        outcome.payload,
24
1
        ResponsePayload::Value(Value::Number(Number::Index(4999))),
25
1
        "got: {:?}",
26
1
        outcome.payload
27
1
    );
28
1
}
29

            
30
/// Row E: `C_30` (`C0 = t`, `Ck = (cond (Ck-1 t))`) gives `t` inside the work
31
/// budget, which `eval_value`'s classify-then-apply doubling (`E(k) =
32
/// 2*E(k-1)`) once exhausted; the compile-time half of the row lives in
33
/// `nomiscript`'s `codegen::budget_limits::c30_cond_chain_compiles_within_the_work_budget`.
34
#[tokio::test]
35
1
async fn c30_cond_chain_gives_t_within_the_work_budget() {
36
1
    let mut src = "T".to_string();
37
1
    for _ in 0..30 {
38
30
        src = format!("(cond ({src} T))");
39
1
    }
40
1
    assert_values(&[(&src, "t")]).await;
41
1
}