diff --git a/src/v3/compiler/tests/integration/v4_workflow_ci_runner_dag_smoke_test.rs b/src/v3/compiler/tests/integration/v4_workflow_ci_runner_dag_smoke_test.rs index 04f20ce17e0..7fdfdac336b 100644 --- a/src/v3/compiler/tests/integration/v4_workflow_ci_runner_dag_smoke_test.rs +++ b/src/v3/compiler/tests/integration/v4_workflow_ci_runner_dag_smoke_test.rs @@ -1120,6 +1120,205 @@ fn v4_workflow_ci_bootstrap_gate_skip_policy_is_modeled() { ); } +/// Wave 2 — §11.7.5 temporary shell exception table (first executable slice). Authority: #4137 +/// §11.7.5. Models the Class-A shell-owned floor steps allowed to stay REQUIRED pending their +/// `CiUpsertStep` runtime-authority migration (bootstrap viability + M1 rust emit), and the +/// no-new-shell ratchet (§11.7.1 #5): every REQUIRED ci-floor shell invocation in ci.yml must +/// carry a row here. Dissolve-on: ci.yml emits these steps FROM their `CiUpsertStep` (T-24), +/// at which point the rows delete and this slice retires. +/// +/// **P5 receipt (T-PB-B same-path SG-0 expansion):** this is a +0-new-path addition to the +/// existing `v4_workflow_ci_runner_dag_smoke_test` harness (already carried by one SG-0 +/// hand-authored-test census entry), NOT a new hand-Rust test path/authority surface — same +/// posture as the T-38/T-38B expansions documented in this file's header. Explicit P5 deferral: +/// ROADMAP.md § "Nine lanes" row **T-PB-B** / `pb_rust_tests_outside_residual_zero`. Dissolution: +/// generated `.dag` `TestClaim` execution covers the §11.7.5 shell-exception table + no-new-shell +/// ratchet (and A15 Shape-B emitted `ci.yml`), retiring this hand-Rust parse/string harness. +/// +/// **Required-CI wiring:** the `v4_workflow_ci_wave1_` name prefix places this under the required +/// `ci_floor` "M1 v4 workflow CI model/YAML binding smoke" step's `::v4_workflow_ci_wave1_` filter +/// (`.github/workflows/ci.yml`), so the no-new-shell ratchet — §11.7.1 item #5, a safety-floor +/// gate — is enforced on every PR, not just locally. The §11.7.5 table it asserts is Wave 2 work, +/// but the ratchet it enforces is Wave 1 floor, which is why it joins the `wave1_` floor-binding group. +#[test] +fn v4_workflow_ci_wave1_class_a_shell_exception_table_first_slice() { + let module = parse_module(CI_DAG, CI_DAG_PATH); + + // Type substrate: the exception-row record + the §11.7.1 safety-floor enum it cites. + assert!( + module.items.iter().any(|item| matches!( + item, + SurfaceItem::TypeRecord { name, .. } if name == "CiShellExceptionRow" + )), + "{CI_DAG_PATH}: §11.7.5 must model CiShellExceptionRow" + ); + assert!( + module.items.iter().any(|item| matches!( + item, + SurfaceItem::TypeSum { name, .. } if name == "CiSafetyFloorItem" + )), + "{CI_DAG_PATH}: §11.7.5 must model the §11.7.1 safety-floor item enum" + ); + + // Isolate the table body so per-row assertions can't accidentally match elsewhere. + let table = CI_DAG + .split("data ci_class_a_shell_exceptions:") + .nth(1) + .unwrap_or_else(|| panic!("{CI_DAG_PATH}: missing data ci_class_a_shell_exceptions")) + .split("\n]") + .next() + .expect("ci_class_a_shell_exceptions table must terminate with `]`"); + + // Exactly the two Class-A shell-owned floor steps carry an exception: bootstrap + M1. + assert_eq!( + table.matches("CiShellExceptionRow {").count(), + 2, + "{CI_DAG_PATH}: §11.7.5 carries exactly two Class-A shell exceptions (bootstrap + M1)" + ); + for needle in [ + // bootstrap-viability.sh is the v2→v4 full compile over src/v4 — its live step + retiring + // authority are `v2_compile_src_v4`, not the lighter `v2_bootstrap_smoke_execution`. + "job: v2_compile_src_v4", + ".github/ci-floor/v4-bootstrap-viability.sh", + "protects_floor: BootstrapMinimalViability", + "job: m1_rust_emit_probe_execution", + ".github/ci-floor/v4-m1-rust-emit-probe.sh", + "protects_floor: OneRustEmitProbe", + ] { + assert!( + table.contains(needle), + "{CI_DAG_PATH}: shell exception table must carry `{needle}`" + ); + } + + // P2 single-authority: `replacement_upsert` binds the canonical `CiUpsertStepSymbol` data + // declared elsewhere in this module — NOT a parallel `Symbol` alias that could drift or name + // a non-existent upsert. Assert both the table reference and the authority declaration exist. + for upsert in [ + "ci_upsert_v2_compile_src_v4", + "ci_upsert_m1_rust_emit_probe_execution", + ] { + assert!( + table.contains(&format!("replacement_upsert: {upsert}")), + "{CI_DAG_PATH}: shell exception must point `replacement_upsert` at the canonical \ + upsert authority `{upsert}` (P2 single-authority — no parallel `_step` Symbol alias)" + ); + assert!( + CI_DAG.contains(&format!("data {upsert}: CiUpsertStepSymbol")), + "{CI_DAG_PATH}: `replacement_upsert` authority `{upsert}` must be a declared \ + `CiUpsertStepSymbol` (proves the named upsert exists)" + ); + } + + // §11.7.5 cond 4 — every row names a structural dissolution path (no calendar/owner carrier). + assert_eq!( + table + .matches("dissolution_target: ModelMissingSubstrate") + .count(), + 2, + "{CI_DAG_PATH}: each shell exception must name a structural dissolution_target" + ); + + // no-new-shell ratchet (§11.7.1 #5) — bidirectional bijection between the REQUIRED + // `.github/ci-floor/*.sh` invocations in ci.yml and the table's rows. + // + // Build the live invocation set FIRST, comment-safe, and reuse it for BOTH the row-liveness + // (cond 1) and the bijection — never raw `CI_YML.contains(...)`, which a comment could satisfy. + // Scan EVERY non-comment line (not just lines beginning `run: bash …`) so a block-scalar + // `run: |` body such as ` bash .github/ci-floor/foo.sh` cannot evade the gate by its + // YAML spelling, while a commented-out `# bash .github/ci-floor/foo.sh` is NOT counted as live + // (openai-pro #4284: skip comment-only lines + strip inline ` # …` trailers). + let mut ci_floor_scripts: Vec = Vec::new(); + for raw in CI_YML.lines() { + let line = raw.trim_start(); + if line.starts_with('#') { + continue; + } + // Drop any inline YAML comment (a ` #` trailer) before looking for an invocation. + let line = line.split_once(" #").map_or(line, |(code, _)| code); + // Key on the `.github/ci-floor/` PATH, not on a `bash ` prefix — a required floor step can + // be spelled `sh …`, `./…`, `source …`, etc. Filtering on `bash ` first would let those + // non-`bash` spellings escape the live set (openai-pro #4284). Any non-comment reference to + // a ci-floor path is treated as a live invocation and must canonicalize to a modeled `.sh`. + if let Some(idx) = line.find(".github/ci-floor/") { + // Canonicalize the path token: read from the path start until whitespace OR a shell / + // YAML separator/quote (`"' ; & | ) ``), so quoted/punctuated spellings like + // `".github/ci-floor/x.sh"` or `.github/ci-floor/x.sh; echo` canonicalize to + // the bare `.sh` path rather than being silently dropped. + let token: String = line[idx..] + .chars() + .take_while(|&c| { + !c.is_whitespace() && !matches!(c, '"' | '\'' | ';' | '&' | '|' | ')' | '`') + }) + .collect(); + // Fail CLOSED on any ci-floor reference we cannot canonicalize to a `*.sh` script: + // a non-comment line referencing `.github/ci-floor/` that does not yield a `.sh` path + // is treated as an unrecognized live shell the ratchet must not silently ignore + // (openai-pro #4284 — a new required shell in an unhandled spelling must trip the gate). + assert!( + token.ends_with(".sh"), + "{CI_YML_PATH}: ci-floor invocation `{}` did not canonicalize to a `*.sh` script — \ + the no-new-shell ratchet fails CLOSED on unrecognized live shell spellings; \ + normalize the invocation or extend the canonicalizer", + line.trim() + ); + ci_floor_scripts.push(token); + } + } + ci_floor_scripts.sort(); + ci_floor_scripts.dedup(); + assert!( + !ci_floor_scripts.is_empty(), + "{CI_YML_PATH}: expected at least one required ci-floor shell invocation to ratchet" + ); + + // §11.7.5 cond 1 — each modeled shell_owner is a live REQUIRED ci.yml floor invocation, + // checked against the SAME comment-safe parsed live set (not raw `CI_YML.contains`, which a + // comment could satisfy). No phantom exception for a script that does not actually run on PRs. + for script in [ + ".github/ci-floor/v4-bootstrap-viability.sh", + ".github/ci-floor/v4-m1-rust-emit-probe.sh", + ] { + assert!( + ci_floor_scripts.iter().any(|s| s == script), + "{CI_YML_PATH}: shell exception owner `{script}` must be a live (non-comment) floor invocation" + ); + } + + // Forward — every required ci-floor shell must have an exception row, matched at the + // `shell_owner` FIELD (`shell_owner: ""`), NOT bare path containment over the slice. + // A path can also appear in a row comment (e.g. the bootstrap row documents what the script + // does), so containment would pass even with a stale/wrong `shell_owner` field — i.e. fail + // OPEN. Pinning to the field spelling keeps it fail-CLOSED (openai-pro #4284). + for script in &ci_floor_scripts { + assert!( + table.contains(&format!("shell_owner: \"{script}\"")), + "{CI_YML_PATH}: required ci-floor shell `{script}` has no §11.7.5 \ + `CiShellExceptionRow.shell_owner` field (no-new-shell ratchet — the path appearing \ + only in a comment does not count; add/repair the `shell_owner` field or model it)" + ); + } + // Bijection — distinct required scripts must equal the row count, so a NEW ci-floor shell (or + // a duplicate/extra row) breaks the 1:1 correspondence and fails the gate rather than passing + // open on mere string containment. + assert_eq!( + ci_floor_scripts.len(), + table.matches("CiShellExceptionRow {").count(), + "{CI_DAG_PATH}: §11.7.5 table must be 1:1 with the required ci-floor invocations \ + in {CI_YML_PATH} (count {} scripts vs rows) — a new required shell or an extra/stale \ + row breaks the no-new-shell bijection", + ci_floor_scripts.len() + ); + + // RESIDUAL (tracked, openai-pro #4284): this gate keys on the script PATH, not the modeled + // `(job, step)` `CiStepId`, because ci.yml's step→`CiStepId` mapping is not yet available in a + // string-checkable form here. A *second* required step reusing an already-listed ci-floor + // script would not yet be distinguished by its own `step_id`. Dissolves on the same trigger as + // this harness's overall retirement: the generated `.dag` CI step model lets the ratchet + // compare live `(job, step, script)` against `step_id + shell_owner` directly. Until then the + // bijection above (path-keyed, block-form-safe, count-exact) is the enforced contract. +} + #[test] fn v4_workflow_affected_set_ci_runner_claim_dag_tokenizes_and_parses() { let _module = parse_module(CLAIM_DAG, CLAIM_PATH); diff --git a/src/v4/workflow/ci.dag b/src/v4/workflow/ci.dag index 1ec6d85f5bc..d0334946b98 100644 --- a/src/v4/workflow/ci.dag +++ b/src/v4/workflow/ci.dag @@ -383,6 +383,86 @@ data ci_always_run_carveouts: List = [ } ] +// ── Wave 2 — §11.7.5 temporary shell exception table (Class A safety floor) ────────────────── +// Authority: #4137 §11.7.5 "The temporary CI cut rule (codified)". A shell-owned check may remain +// REQUIRED on every PR only if it (1) protects a named §11.7.1 safety-floor item, (2) has no +// runtime-authoritative `CiUpsertStep` replacement yet, (3) is listed in THIS table, (4) names a +// structural dissolution path. Conditions (2)+(3) are definitional: a row exists here iff the step +// is still shell-owned and not yet emitted FROM its `CiUpsertStep` as ci.yml runtime authority. +// This is the first executable slice of Wave 2 (shell→`CiUpsertStep` migration, §11.7.7 lane 6): +// it models the exception registry the no-new-shell ratchet (§11.7.1 #5) consumes. INTENDED +// contract: the set of REQUIRED shell-owned ci-floor steps equals these rows' `step_id`s. +// ENFORCED today (`v4_workflow_ci_wave1_class_a_shell_exception_table_first_slice`): a bijection +// between the required `.github/ci-floor/*.sh` invocations in ci.yml and these rows, matched at the +// `shell_owner` FIELD (not bare path containment, which a row comment could satisfy fail-open), +// reading ci.yml invocations from a comment-safe, block-form-safe, count-exact live set (a +// commented-out `# bash …` is not counted; keyed on the ci-floor PATH not a `bash ` prefix, so +// `sh`/`./`/`source` spellings are caught too; quoted/punctuated paths are canonicalized and an +// unrecognizable ci-floor spelling trips the gate) — a new unlisted required shell fails CLOSED. RESIDUAL (tracked, +// openai-pro #4284): the gate keys on script path, not the modeled `(job, step)` `CiStepId`, since +// ci.yml's step→`CiStepId` mapping is not yet string-checkable; a *second* step reusing a listed +// script is not yet distinguished by `step_id`. Dissolves when the generated `.dag` CI step model +// lets the ratchet compare live `(job, step, script)` against `step_id + shell_owner` directly. +// Reuses `CiStepId` + `DissolutionTarget` (no parallel exception genus); sibling to +// `ci_always_run_carveouts` (run-policy carveout) — distinct concept (shell retirement vs +// always-run), shared leaf substrate. + +// 🟡 coproduct dissolution — feature:wave2-class-a-shell-exception-table — bind #4137 §11.7.1 — dissolve-on-arrival: this closed enumeration mirrors the §11.7.1 bare-minimum floor; it is DELETED when the dynamic affected-set + testgen safety net (§11.7.7 end state) replaces the static floor list and `protects_floor` no longer needs a fixed-arm carrier; forbidden: an open `Symbol`/`String` floor key, or an arm with no §11.7.1 row. +type CiSafetyFloorItem + = FmtCheck + | BootstrapMinimalViability + | OneRustEmitProbe + | CiDagStructuralReceipt + | NoNewShellRatchet + +// 🟡 coproduct dissolution — feature:wave2-class-a-shell-exception-table — bind #4137 §11.7.5 — dissolve-on-arrival: a row is DELETED when ci.yml emits its `step_id` FROM `replacement_upsert` as runtime authority (T-24), not when the shadow `CiUpsertStep` row merely exists; forbidden: a row without a named `dissolution_target`, or a Class-B/C/D (non-floor) step carried as a shell exception. +type CiShellExceptionRow { + step_id: CiStepId + // Repo-relative path of the `.github/ci-floor/*.sh` script owning this Class-A floor step. + // Canonical `RepoPath` carrier (v4.lens.edit_locus) — NOT a parallel path-as-String authority. + shell_owner: RepoPath + protects_floor: CiSafetyFloorItem + // The existing shadow `CiUpsertStep` AUTHORITY that retires this row once it becomes ci.yml + // runtime authority. Binds to the canonical `CiUpsertStepSymbol` data (single-authority, P2) — + // NOT a parallel `Symbol` alias that could drift or name a non-existent upsert. + replacement_upsert: CiUpsertStepSymbol + dissolution_target: DissolutionTarget +} + +// Dissolution `what` atoms — the runtime-authority emission substrate whose arrival deletes the +// row (does NOT yet exist; standard `ModelMissingSubstrate` naming, like `ci_gate_run_policy_*`). +data ci_bootstrap_step_emitted_from_upsert_runtime_authority: Symbol = ci_bootstrap_step_emitted_from_upsert_runtime_authority +data ci_m1_rust_emit_step_emitted_from_upsert_runtime_authority: Symbol = ci_m1_rust_emit_step_emitted_from_upsert_runtime_authority + +data ci_class_a_shell_exceptions: List = [ + CiShellExceptionRow { + // `.github/ci-floor/v4-bootstrap-viability.sh` is the v2→v4 FULL COMPILE over src/v4 (script + // header: "v2-compiler full compile over src/v4"; ci.yml step "v2 -> v4 bootstrap compile"), + // so the live step + its retiring authority are `v2_compile_src_v4` / `ci_upsert_v2_compile_src_v4` + // (verify `BootstrapStageCompile { produces: v4_stage0_binary }`) — NOT the lighter + // `v2_bootstrap_smoke_execution`. Bound by what the script DOES, not by name resemblance (P1/P2). + step_id: JobStep { job: v2_compile_src_v4, step: v2_compile_src_v4 }, + shell_owner: ".github/ci-floor/v4-bootstrap-viability.sh", + protects_floor: BootstrapMinimalViability, + replacement_upsert: ci_upsert_v2_compile_src_v4, + dissolution_target: ModelMissingSubstrate { + what: ci_bootstrap_step_emitted_from_upsert_runtime_authority + } + }, + CiShellExceptionRow { + step_id: JobStep { + job: m1_rust_emit_probe_execution, + step: m1_rust_emit_probe_execution + }, + shell_owner: ".github/ci-floor/v4-m1-rust-emit-probe.sh", + protects_floor: OneRustEmitProbe, + replacement_upsert: ci_upsert_m1_rust_emit_probe_execution, + dissolution_target: ModelMissingSubstrate { + what: ci_m1_rust_emit_step_emitted_from_upsert_runtime_authority + } + } +] + // Wave 3 §11.7.4 — extend existing receipt (arbiter §8 2026-06-01); no parallel shadow receipt type. // 🟡 coproduct dissolution — feature:wave3-shadow-selection-receipt — bind Wave 4 active-skip — dissolve-on-arrival: `CiActiveFloorSkipEvidence` is populated from cached TestClaimRun verdict partition; forbidden: bare `Active` tag without skip evidence (illegal floor-skip state). type CiActiveFloorSkipEvidence {