Lines
100 %
Functions
Branches
//! Codex adversarial review, seventh pass on this slice: 4 findings.
//! IMPORTANT: Codex's shell failed to start this run, so every finding was
//! a CODE-DERIVED PREDICTION, not an observed failure — each was
//! reproduced against a bare `nms` sandbox (using `primary-entity-idx`,
//! the non-foldable runtime call available there) before any fix landed.
//! Two of the four predicted VALUES turned out to be wrong (noted below);
//! the underlying GAPS they predicted were real in both cases, and are
//! fixed here. `n` stands for `(rpc-protocol-version)`, which is 1.
use super::*;
// --- item 1: `reject_definition_under_runtime_guard` checked only
// `and_or_depth`, ignoring `cond_depth` — so a definition inside a false
// COND clause registered anyway, sidestepping round 6's fix (which only
// covered AND/OR). Fixed by switching it to
// `SymbolTable::is_under_any_runtime_guard` (AND/OR **or** COND), matching
// `reject_compile_time_setf_under_runtime_guard`'s existing scope.
//
// PREDICTION DISPROVEN (partially): Codex predicted the form below
// evaluates to 7 (buggy) and must be 9. In fact, given this slice's
// established policy (round 6 item 1: a FRESH definition under ANY runtime
// guard registers unconditionally and so is REJECTED outright, not
// silently skipped), the CORRECT fixed behavior is a compile error, not a
// clean "9" — the same as an equivalent AND/OR guard already produces. The
// underlying gap (cond_depth ignored) was real and is fixed; the specific
// predicted VALUE was not achievable without abandoning that established
// reject-outright policy, so this test asserts the compile error instead. ---
#[tokio::test]
async fn a_definition_under_a_false_cond_clause_is_rejected_not_silently_registered() {
let form = "(progn (cond ((> (rpc-protocol-version) 5) (defvar codex-r9-y 7))) \
(defvar codex-r9-y 9) codex-r9-y)";
assert_error_code(form, "compile").await;
}
async fn a_macro_emitted_definition_under_a_false_cond_clause_is_also_rejected() {
// Distinct from round 8 item 6: THIS macro EXPANDS TO a `(defvar ...)`
// form (returned as generated code, compiled for real against the
// caller's guarded table), rather than executing a `defvar` as part of
// evaluating its own body (which round 8 item 6 already covers via
// `suspend_runtime_guards` on the private expansion environment).
let form = "(progn (defmacro codex-r9-m () '(defvar codex-r9-my 7)) \
(cond ((> (rpc-protocol-version) 5) (codex-r9-m))) \
(defvar codex-r9-my 9) codex-r9-my)";
// --- item 2: `compile_setf_for_stack`'s const place branch
// never called `reject_compile_time_setf_under_runtime_guard` (unlike the
// effect handler), so a value-position SETF under a runtime guard mutated
// compile-time state unconditionally. Fixed by adding the same rejection
// there, and in the eval-only `setf` fn too (for a non-runtime-local
// place), so classification and codegen agree on what's rejected.
// PREDICTION DISPROVEN (partially): Codex predicted the buggy value "new"
// and a correct value of "old" (silently skip the write). Given this
// slice's established policy (a compile-time-only mutation under a runtime
// guard is REJECTED outright, not silently skipped — see round 4/6's SETF
// guard), the correct fixed behavior is a compile error, matching the
// existing DEFPARAMETER-initializer SETF-under-guard tests. The underlying
// gap (compile_setf_for_stack skipping the check) was real and is fixed;
// this test asserts the compile error rather than "old". ---
async fn stack_position_setf_on_a_stored_global_under_a_runtime_guard_is_a_runtime_store() {
// 0014 Stage 2: a global the unit stores to is a runtime cell, so the
// guarded store runs only when its clause is taken — never here.
let form = "(progn (defparameter codex-r9-z \"old\") \
(defparameter codex-r9-result \
(cond ((> (rpc-protocol-version) 5) (setf codex-r9-z \"new\")) (t \"ok\"))) \
codex-r9-z)";
assert_values(&[(form, "\"old\"")]).await;
// --- item 3: effect-position COND entered the guard BEFORE
// `compile_test_condition` compiled the FIRST runtime clause's own test —
// reintroducing, in effect position, the same regression round 6 fixed in
// stack/eval position (cond.rs item 3 there). Fixed by compiling the first
// runtime test before entering the guard, then holding the guard across
// its body and the remaining clauses. ---
async fn effect_position_cond_first_clauses_own_test_mutation_is_not_rejected_as_guarded() {
let form = "(progn (defparameter codex-r9-x 0) \
(cond ((progn (setf codex-r9-x 1) (> (rpc-protocol-version) -1)) 7)) \
codex-r9-x)";
assert_values(&[(form, "1")]).await;
async fn effect_position_cond_first_runtime_clause_after_a_constant_false_prefix_is_not_rejected() {
let form = "(progn (defparameter codex-r9-x2 0) \
(cond (nil 99) \
((progn (setf codex-r9-x2 1) (> (rpc-protocol-version) -1)) 7)) \
codex-r9-x2)";