Lines
100 %
Functions
Branches
//! Plan 0011 Phase 3 slice 1 acceptance rows R3 and E, exercised end to end
//! (compile AND run) through the Session.
use super::*;
/// Row R3: a 5000-clause `COND`, every clause a genuine runtime test
/// (`RPC-PROTOCOL-VERSION` is a runtime host import, so none of them fold
/// at compile time), compiles and gives its value with no native stack
/// overflow — surviving this test at all is part of the proof, the
/// returned value pins that the runtime chain (a flat sequence of
/// `if`/`br 1`s, never nested) actually falls all the way through to the
/// tail (the protocol version never exceeds any of these thresholds).
#[tokio::test]
async fn a_five_thousand_clause_runtime_cond_compiles_and_gives_its_value() {
let clauses: String = (0..4_999u32)
.map(|i| format!("((> (rpc-protocol-version) {}) {i})", i + 1_000_000))
.collect::<Vec<_>>()
.join(" ");
let form = format!("(cond {clauses} (t 4999))");
let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
let outcome = session.handle_request(&form).await;
assert_eq!(
outcome.payload,
ResponsePayload::Value(Value::Number(Number::Index(4999))),
"got: {:?}",
outcome.payload
);
}
/// Row E: `C_30` (`C0 = t`, `Ck = (cond (Ck-1 t))`) gives `t` inside the work
/// budget, which `eval_value`'s classify-then-apply doubling (`E(k) =
/// 2*E(k-1)`) once exhausted; the compile-time half of the row lives in
/// `nomiscript`'s `codegen::budget_limits::c30_cond_chain_compiles_within_the_work_budget`.
async fn c30_cond_chain_gives_t_within_the_work_budget() {
let mut src = "T".to_string();
for _ in 0..30 {
src = format!("(cond ({src} T))");
assert_values(&[(&src, "t")]).await;