From 3b326c811ffaacbada958a4c3aa82f712a7bc445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Shixiang=20Wang=20=28=E7=8E=8B=E8=AF=97=E7=BF=94=29?= Date: Mon, 23 Nov 2026 09:35:25 +0800 Subject: [PATCH] feat: CS-15 refdb-witness scenario -- planted-R-object adjudication over the exported ms_refdb face (pillar 3) Fifteenth pillar-3 scenario. The lane freezes what the exported ms_refdb()/MsRefDb() governance container actually adjudicates over planted synthetic R objects -- a decision record, never a specification. Chain (all receipts measured, none transcribed): - probe-cs15: 58-arm observation ledger, right-reason-audited arm by arm (class + first-clause anchors), DET byte-identical across probe reruns - runner: 188 rails pass before any witness byte is written; OVERALL PASS; the five witnesses (8 specs, 46 laws, 4 precedence, 8 degenerates, 8 scalars) reproduce byte-for-byte on re-run (DET 5/5) - law file: 10 units, 273 expectations, 0 failed / 0 errors / 0 warnings / 0 skipped; TDD red witnessed before green - double-gate split committed as measured: 43 validator arms speak msuiter_error_refdb, 3 property-gate arms die as simpleError before any validator runs - precedence: four discriminators each pinned fires-anchor-present AND anti-anchor-absent (first-matrix authority, field-before-A13, matrix-before-metadata, sha-before-availability) - degenerate pairs: four asymmetries (declared vs undeclared NA build, zero-length vs NA availability, duplicate vs absent colnames, 1x1 vs zero-column space) - dual-kernel SHA-256 (canonical pure-R + digest accelerator) agree on the plant and spec canonical texts; RNG rails silent both ends - registration: weights/manifest rows added; the gen-shard-manifest DEFECT refusal (624 vs sealed 623) was witnessed verbatim before the deliberate T0 re-seal 623 -> 624 with its comment block - docs quartet: devlog decision record, paper-draft bullet + Fig. 5 roster, docs-bridge row, _pkgdown article; scenarios gets its thirteenth leg (render-verified TRUE x6) Also repaired two drifts found by this lane: the scenarios intro still said twelve drivers (fifteen now, full roster restored) and the reproduction list had missed run_segments_witness.R since CS-14; the paper-draft CS-14 bullet cited PR #124 and is corrected to #125. Local gate: GATE-RAN-CLEAN, Status 2 WARNINGs + 1 NOTE byte-same to the CS-14 baseline (top-level files, subdirectories, Rust compilation), vignette rebuild 218s OK. Co-Authored-By: Claude Code --- _pkgdown.yml | 1 + bench/scenarios/out/cs15_degenerates.tsv | 9 + bench/scenarios/out/cs15_laws.tsv | 47 + bench/scenarios/out/cs15_precedence.tsv | 5 + bench/scenarios/out/cs15_scalars.tsv | 9 + bench/scenarios/out/cs15_specs.tsv | 9 + bench/scenarios/run_refdb_witness.R | 852 +++++++++++++++++ tests/testthat/test-scenario-refdb-witness.R | 862 ++++++++++++++++++ tools/ci/pr-gate-budget.tsv | 7 +- tools/ci/shard-manifest.tsv | 117 +-- tools/ci/shard-weights.tsv | 1 + ...evlog-2026-11-23-p3-cs15-refdb-witness.qmd | 102 +++ vignettes/articles/paper-draft.qmd | 24 +- vignettes/docs-bridge.Rmd | 1 + vignettes/scenarios.Rmd | 77 +- 15 files changed, 2060 insertions(+), 63 deletions(-) create mode 100644 bench/scenarios/out/cs15_degenerates.tsv create mode 100644 bench/scenarios/out/cs15_laws.tsv create mode 100644 bench/scenarios/out/cs15_precedence.tsv create mode 100644 bench/scenarios/out/cs15_scalars.tsv create mode 100644 bench/scenarios/out/cs15_specs.tsv create mode 100644 bench/scenarios/run_refdb_witness.R create mode 100644 tests/testthat/test-scenario-refdb-witness.R create mode 100644 vignettes/articles/devlog-2026-11-23-p3-cs15-refdb-witness.qmd diff --git a/_pkgdown.yml b/_pkgdown.yml index 287170c..17017e5 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -338,3 +338,4 @@ articles: - articles/devlog-2026-11-22-p3-cs12-sparse-spec-witness - articles/devlog-2026-11-22-p3-cs13-io-interop-witness - articles/devlog-2026-11-23-p3-cs14-segments-witness + - articles/devlog-2026-11-23-p3-cs15-refdb-witness diff --git a/bench/scenarios/out/cs15_degenerates.tsv b/bench/scenarios/out/cs15_degenerates.tsv new file mode 100644 index 0000000..c68d4cc --- /dev/null +++ b/bench/scenarios/out/cs15_degenerates.tsv @@ -0,0 +1,9 @@ +edge arm cls observed +NA build: declared vs undeclared (A13) sp-na-declared accept nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=NA;indep=TRUE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +NA build: declared vs undeclared (A13) rej-a13-undeclared msuiter_error_refdb a missing build must be declared via build_independent = TRUE +availability: zero-length vs NA entry sp-availability-zero accept nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices +availability: zero-length vs NA entry rej-avail-na msuiter_error_refdb metadata field 'availability' must be a character vector without NA +colnames: duplicates ride, absence falls sp-dup-colnames accept nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +colnames: duplicates ride, absence falls rej-mat-colnames msuiter_error_refdb reference matrix 'core' must carry rownames and colnames +column space: 1x1 accepted, 0-col refused sp-1x1 accept nmat=1;names=one;nrow=1;ncol=1;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +column space: 1x1 accepted, 0-col refused obs-zero-cols-rejected msuiter_error_refdb reference matrix 'core' must carry rownames and colnames diff --git a/bench/scenarios/out/cs15_laws.tsv b/bench/scenarios/out/cs15_laws.tsv new file mode 100644 index 0000000..a7d3c06 --- /dev/null +++ b/bench/scenarios/out/cs15_laws.tsv @@ -0,0 +1,47 @@ +arm face cls mode clause +obs-zero-cols-rejected ms_refdb msuiter_error_refdb full reference matrix 'core' must carry rownames and colnames | labels are the only legal matching key (never position) | rownames missing: FALSE; colnames missing: TRUE | set the matrix dimnames +rej-mat-empty ms_refdb msuiter_error_refdb full matrices must be a non-empty named list | an MsRefDb bundles at least one reference signature matrix | received: list of length 0 | pass the reference matrices as a named list +rej-mat-notlist ms_refdb simpleError full object properties are invalid: | - @matrices must be , not +rej-mat-null ms_refdb simpleError full object properties are invalid: | - @matrices must be , not +rej-mat-unnamed ms_refdb msuiter_error_refdb full every reference matrix must be named | matrix names identify reference sets (e.g. PCAWG) | names: (none) | name every list element +rej-mat-partial-name ms_refdb msuiter_error_refdb full every reference matrix must be named | matrix names identify reference sets (e.g. PCAWG) | names: 'core', '' | name every list element +rej-mat-vector ms_refdb msuiter_error_refdb full reference matrix 'core' must be a numeric matrix | reference signatures are channel-space matrices | received: integer | pass numeric matrices with full dimnames +rej-mat-character ms_refdb msuiter_error_refdb full reference matrix 'core' must be a numeric matrix | reference signatures are channel-space matrices | received: matrix | pass numeric matrices with full dimnames +rej-mat-dataframe ms_refdb msuiter_error_refdb full reference matrix 'core' must be a numeric matrix | reference signatures are channel-space matrices | received: data.frame | pass numeric matrices with full dimnames +rej-mat-rownames ms_refdb msuiter_error_refdb full reference matrix 'core' must carry rownames and colnames | labels are the only legal matching key (never position) | rownames missing: TRUE; colnames missing: FALSE | set the matrix dimnames +rej-mat-colnames ms_refdb msuiter_error_refdb full reference matrix 'core' must carry rownames and colnames | labels are the only legal matching key (never position) | rownames missing: FALSE; colnames missing: TRUE | set the matrix dimnames +rej-mat-nodimnames ms_refdb msuiter_error_refdb full reference matrix 'core' must carry rownames and colnames | labels are the only legal matching key (never position) | rownames missing: TRUE; colnames missing: TRUE | set the matrix dimnames +rej-mat-na ms_refdb msuiter_error_refdb full reference matrix 'core' must not contain NA or non-finite values | the FFI contract rejects NA | offending cells: '2' | fix the reference matrix source +rej-mat-nan ms_refdb msuiter_error_refdb full reference matrix 'core' must not contain NA or non-finite values | the FFI contract rejects NA | offending cells: '5' | fix the reference matrix source +rej-mat-inf ms_refdb msuiter_error_refdb full reference matrix 'core' must not contain NA or non-finite values | the FFI contract rejects NA | offending cells: '8' | fix the reference matrix source +rej-mat-negative ms_refdb msuiter_error_refdb full reference matrix 'core' must be non-negative | reference signatures are non-negative by definition | offending cells: '3' | check the reference matrix source +rej-channels-disagree ms_refdb msuiter_error_refdb full reference matrices must share the same channel labels | channel labels are matched by label, element by element | matrix 'alt' disagrees; offending labels: 'X[C>X]X' | project all matrices onto one common channel space +rej-channels-subset ms_refdb msuiter_error_refdb full reference matrices must share the same channel labels | channel labels are matched by label, element by element | matrix 'small' disagrees; offending labels: (none) | project all matrices onto one common channel space +rej-meta-notlist ms_refdb simpleError full object properties are invalid: | - @metadata must be , not +rej-meta-unnamed ms_refdb msuiter_error_refdb full metadata must be a named list | governance fields: version, class, build, schema_version, sha256, license, build_independent, availability | received: list | provide the governance metadata +rej-meta-emptyname ms_refdb msuiter_error_refdb full metadata must be a named list | governance fields: version, class, build, schema_version, sha256, license, build_independent, availability | received: list | provide the governance metadata +rej-meta-absent-one ms_refdb msuiter_error_refdb full reference metadata is missing governance fields | governance fields: version, class, build, schema_version, sha256, license, build_independent, availability | missing: 'license' | record the missing field(s) in metadata +rej-meta-absent-two ms_refdb msuiter_error_refdb full reference metadata is missing governance fields | governance fields: version, class, build, schema_version, sha256, license, build_independent, availability | missing: 'build', 'sha256' | record the missing field(s) in metadata +rej-field-version-empty ms_refdb msuiter_error_refdb full metadata field 'version' must be a single non-empty string | governance fields pin the reference set identity | received: '' | record the field as a single string +rej-field-version-na ms_refdb msuiter_error_refdb full metadata field 'version' must be a single non-empty string | governance fields pin the reference set identity | received: 'NA' | record the field as a single string +rej-field-version-multi ms_refdb msuiter_error_refdb full metadata field 'version' must be a single non-empty string | governance fields pin the reference set identity | received: '1', '2' | record the field as a single string +rej-field-version-num ms_refdb msuiter_error_refdb full metadata field 'version' must be a single non-empty string | governance fields pin the reference set identity | received: '1' | record the field as a single string +rej-field-class-empty ms_refdb msuiter_error_refdb full metadata field 'class' must be a single non-empty string | governance fields pin the reference set identity | received: '' | record the field as a single string +rej-field-schema-na ms_refdb msuiter_error_refdb full metadata field 'schema_version' must be a single non-empty string | governance fields pin the reference set identity | received: 'NA' | record the field as a single string +rej-field-license-multi ms_refdb msuiter_error_refdb full metadata field 'license' must be a single non-empty string | governance fields pin the reference set identity | received: 'CC0-1.0', 'CC-BY-4.0' | record the field as a single string +rej-indep-na ms_refdb msuiter_error_refdb full metadata field 'build_independent' must be a single TRUE or FALSE | build independence is an explicit declaration (A13) | received: 'NA' | set build_independent = TRUE only for build-agnostic sets +rej-indep-num ms_refdb msuiter_error_refdb full metadata field 'build_independent' must be a single TRUE or FALSE | build independence is an explicit declaration (A13) | received: '1' | set build_independent = TRUE only for build-agnostic sets +rej-indep-str ms_refdb msuiter_error_refdb full metadata field 'build_independent' must be a single TRUE or FALSE | build independence is an explicit declaration (A13) | received: 'TRUE' | set build_independent = TRUE only for build-agnostic sets +rej-build-empty ms_refdb msuiter_error_refdb full metadata field 'build' must be a single string, or NA if build independent | NA build is legal only together with build_independent = TRUE | received: '' | record the genome build, or declare build independence +rej-build-empty-declared ms_refdb msuiter_error_refdb full metadata field 'build' must be a single string, or NA if build independent | NA build is legal only together with build_independent = TRUE | received: '' | record the genome build, or declare build independence +rej-build-num ms_refdb msuiter_error_refdb full metadata field 'build' must be a single string, or NA if build independent | NA build is legal only together with build_independent = TRUE | received: '38' | record the genome build, or declare build independence +rej-build-multi ms_refdb msuiter_error_refdb full metadata field 'build' must be a single string, or NA if build independent | NA build is legal only together with build_independent = TRUE | received: 'GRCh38', 'GRCh37' | record the genome build, or declare build independence +rej-a13-undeclared ms_refdb msuiter_error_refdb full a missing build must be declared via build_independent = TRUE | build-agnostic reference sets must say so explicitly (A13) | build = NA, build_independent = FALSE | record the build, or set build_independent = TRUE +rej-sha-upper ms_refdb msuiter_error_refdb full metadata field 'sha256' must be a sha256 hex digest | the digest pins the reference content (A13 manifest) | received: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | record the sha256 of the reference source +rej-sha-short ms_refdb msuiter_error_refdb full metadata field 'sha256' must be a sha256 hex digest | the digest pins the reference content (A13 manifest) | received: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' | record the sha256 of the reference source +rej-sha-nonhex ms_refdb msuiter_error_refdb full metadata field 'sha256' must be a sha256 hex digest | the digest pins the reference content (A13 manifest) | received: 'gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg' | record the sha256 of the reference source +rej-sha-num ms_refdb msuiter_error_refdb full metadata field 'sha256' must be a sha256 hex digest | the digest pins the reference content (A13 manifest) | received: '42' | record the sha256 of the reference source +rej-sha-na ms_refdb msuiter_error_refdb full metadata field 'sha256' must be a sha256 hex digest | the digest pins the reference content (A13 manifest) | received: 'NA' | record the sha256 of the reference source +rej-avail-na ms_refdb msuiter_error_refdb full metadata field 'availability' must be a character vector without NA | availability lists the builds with official reference sets | received: character of length 2 | list known builds, or pass character(0) +rej-avail-num ms_refdb msuiter_error_refdb full metadata field 'availability' must be a character vector without NA | availability lists the builds with official reference sets | received: integer of length 1 | list known builds, or pass character(0) +rej-avail-logical ms_refdb msuiter_error_refdb full metadata field 'availability' must be a character vector without NA | availability lists the builds with official reference sets | received: logical of length 1 | list known builds, or pass character(0) diff --git a/bench/scenarios/out/cs15_precedence.tsv b/bench/scenarios/out/cs15_precedence.tsv new file mode 100644 index 0000000..d4c9dd9 --- /dev/null +++ b/bench/scenarios/out/cs15_precedence.tsv @@ -0,0 +1,5 @@ +arm fires_cls fires_anchor anti_anchor +prec-first-matrix-authority msuiter_error_refdb reference matrices must share the same channel labels matrix 'core' disagrees +prec-field-before-a13 msuiter_error_refdb metadata field 'version' must be a single non-empty string must be declared via build_independent +prec-matrix-before-metadata msuiter_error_refdb reference matrix 'core' must be non-negative is missing governance fields +prec-sha-before-availability msuiter_error_refdb metadata field 'sha256' must be a sha256 hex digest 'availability' must be diff --git a/bench/scenarios/out/cs15_scalars.tsv b/bench/scenarios/out/cs15_scalars.tsv new file mode 100644 index 0000000..8dd1608 --- /dev/null +++ b/bench/scenarios/out/cs15_scalars.tsv @@ -0,0 +1,9 @@ +key value +governance-fields governance fields: version, class, build, schema_version, sha256, license, build_independent, availability +label-key-law labels are the only legal matching key (never position) +ffi-no-na-clause the FFI contract rejects NA +sha-pin-clause the digest pins the reference content (A13 manifest) +plant-checksum 2ee99b67b38c7238357da9033b5a4bee1e4ab7845bd138fe0487c916afc50e37 +spec-checksum 29166e1729d5191f56f449091231cef02568d9587c0f8bde787c4dc3927462b5 +rng-before FALSE +rng-after FALSE diff --git a/bench/scenarios/out/cs15_specs.tsv b/bench/scenarios/out/cs15_specs.tsv new file mode 100644 index 0000000..7be12e7 --- /dev/null +++ b/bench/scenarios/out/cs15_specs.tsv @@ -0,0 +1,9 @@ +arm face cls detail +sp-canonical ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +sp-two-matrices ms_refdb msuiter::MsRefDb nmat=2;names=core,ext;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 2 matrices +sp-na-declared ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=NA;indep=TRUE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +sp-availability-zero ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices +sp-availability-multi ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38+GRCh37;fmt= class: SBS | version: 1 | 1 matrices +sp-integer-matrix ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +sp-1x1 ms_refdb msuiter::MsRefDb nmat=1;names=one;nrow=1;ncol=1;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices +sp-dup-colnames ms_refdb msuiter::MsRefDb nmat=1;names=core;nrow=4;ncol=2;class=SBS;version=1;build=GRCh38;indep=FALSE;avail=GRCh38;fmt= class: SBS | version: 1 | 1 matrices diff --git a/bench/scenarios/run_refdb_witness.R b/bench/scenarios/run_refdb_witness.R new file mode 100644 index 0000000..8426fed --- /dev/null +++ b/bench/scenarios/run_refdb_witness.R @@ -0,0 +1,852 @@ +# run_refdb_witness.R -- the CS-15 refdb-witness scenario (pillar 3). +# +# Mandate: plant synthetic R objects (the D3 law: zero COSMIC numeric +# matrices, zero real-data bytes, zero downloads -- build and class labels +# ride only as FORMAT NAMES) and adjudicate the EXPORTED ms_refdb() face: +# the container admission laws, the governance-metadata laws, the A13 +# cross-field clause, the lowercase sha256 policy, the double-gate split +# between the S7 property gates and the container validator, the precedence +# discriminators and the degenerate boundaries. Every arm is driven through +# the exported factory alone; the accepted returns, the abort classes and +# the fired bullets are the face's own. The scenario is RNG-free, +# network-free and clock-free; the benchmark runner and the DECLINED +# calibration family are never invoked here. +# +# Framing law: DECISION RECORD only. The witnesses under out/ are the +# committed verdict of what the shipped face SAID on planted truth. Float +# posture (D11): integer, label, logical, class and clause bytes are +# byte-committed; the face produces no float payload columns, so no float +# glyph rides any witness. +# +# Rails: this runner carries the same frozen block as the law file +# (tests/testthat/test-scenario-refdb-witness.R), injected byte-identically +# from one minted source; every observed class, clause, shape and precedence +# order is rail-checked AS WE GO -- a drift fails the run before any witness +# is written. The witness bytes are written only after every payload census +# speaks; a byte-rerun must reproduce them identically. + +.script_dir <- local({ + a <- grep("^--file=(.*)$", commandArgs(FALSE), perl = TRUE, value = TRUE) + if (length(a) == 0L) return(getwd()) + f <- sub("^--file=", "", a[1L]) + if (!grepl("/", f, fixed = TRUE)) return(getwd()) + dirname(f) +}) +ROOT <- normalizePath(file.path(.script_dir, "..", ".."), mustWork = TRUE) +OUT <- file.path(ROOT, "bench", "scenarios", "out") + +if (requireNamespace("pkgload", quietly = TRUE) && + file.exists(file.path(ROOT, "DESCRIPTION"))) { + suppressWarnings(suppressMessages( + pkgload::load_all(ROOT, quiet = TRUE, export_all = TRUE))) +} else { + library(msuiter) +} + +options(cli.no_color = TRUE, width = 220L) +rng0 <- exists(".Random.seed", inherits = TRUE) + +## <> (minted mechanically from the observed ledger +## 2026-11-23; DO NOT hand-edit: regenerate via gen-frozen.cs15.R) ## +.CS15_LAW_ARMS <- c("obs-zero-cols-rejected", "rej-mat-empty", "rej-mat-notlist", "rej-mat-null", "rej-mat-unnamed", "rej-mat-partial-name", "rej-mat-vector", "rej-mat-character", "rej-mat-dataframe", "rej-mat-rownames", "rej-mat-colnames", "rej-mat-nodimnames", "rej-mat-na", "rej-mat-nan", "rej-mat-inf", "rej-mat-negative", "rej-channels-disagree", "rej-channels-subset", "rej-meta-notlist", "rej-meta-unnamed", "rej-meta-emptyname", "rej-meta-absent-one", "rej-meta-absent-two", "rej-field-version-empty", "rej-field-version-na", "rej-field-version-multi", "rej-field-version-num", "rej-field-class-empty", "rej-field-schema-na", "rej-field-license-multi", "rej-indep-na", "rej-indep-num", "rej-indep-str", "rej-build-empty", "rej-build-empty-declared", "rej-build-num", "rej-build-multi", "rej-a13-undeclared", "rej-sha-upper", "rej-sha-short", "rej-sha-nonhex", "rej-sha-num", "rej-sha-na", "rej-avail-na", "rej-avail-num", "rej-avail-logical") +.CS15_LAW_CLS <- c("msuiter_error_refdb", "msuiter_error_refdb", "simpleError", "simpleError", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "simpleError", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb") +.CS15_LAW_MODE <- c("full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full") +.CS15_LAW_CLAUSES <- list() +.CS15_LAW_CLAUSES[["obs-zero-cols-rejected"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "FALSE; colnames missing: TRUE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-empty"]] <- paste0("matrices must be a non-empty named list | an ", + "MsRefDb bundles at least one reference signat", + "ure matrix | received: list of length 0 | pas", + "s the reference matrices as a named list") +.CS15_LAW_CLAUSES[["rej-mat-notlist"]] <- paste0(" object properties are inva", + "lid: | - @matrices must be , not ") +.CS15_LAW_CLAUSES[["rej-mat-null"]] <- paste0(" object properties are inva", + "lid: | - @matrices must be , not ") +.CS15_LAW_CLAUSES[["rej-mat-unnamed"]] <- paste0("every reference matrix must be named | matrix", + " names identify reference sets (e.g. PCAWG) |", + " names: (none) | name every list element") +.CS15_LAW_CLAUSES[["rej-mat-partial-name"]] <- paste0("every reference matrix must be named | matrix", + " names identify reference sets (e.g. PCAWG) |", + " names: 'core', '' | name every list element") +.CS15_LAW_CLAUSES[["rej-mat-vector"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: integer | pass numeric m", + "atrices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-character"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: matrix | pass numeric ma", + "trices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-dataframe"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: data.frame | pass numeri", + "c matrices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-rownames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "TRUE; colnames missing: FALSE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-colnames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "FALSE; colnames missing: TRUE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-nodimnames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "TRUE; colnames missing: TRUE | set the matrix", + " dimnames") +.CS15_LAW_CLAUSES[["rej-mat-na"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '2' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-nan"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '5' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-inf"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '8' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-negative"]] <- paste0("reference matrix 'core' must be non-negative ", + "| reference signatures are non-negative by de", + "finition | offending cells: '3' | check the r", + "eference matrix source") +.CS15_LAW_CLAUSES[["rej-channels-disagree"]] <- paste0("reference matrices must share the same channe", + "l labels | channel labels are matched by labe", + "l, element by element | matrix 'alt' disagree", + "s; offending labels: 'X[C>X]X' | project all ", + "matrices onto one common channel space") +.CS15_LAW_CLAUSES[["rej-channels-subset"]] <- paste0("reference matrices must share the same channe", + "l labels | channel labels are matched by labe", + "l, element by element | matrix 'small' disagr", + "ees; offending labels: (none) | project all m", + "atrices onto one common channel space") +.CS15_LAW_CLAUSES[["rej-meta-notlist"]] <- paste0(" object properties are inva", + "lid: | - @metadata must be , not ") +.CS15_LAW_CLAUSES[["rej-meta-unnamed"]] <- paste0("metadata must be a named list | governance fi", + "elds: version, class, build, schema_version, ", + "sha256, license, build_independent, availabil", + "ity | received: list | provide the governance", + " metadata") +.CS15_LAW_CLAUSES[["rej-meta-emptyname"]] <- paste0("metadata must be a named list | governance fi", + "elds: version, class, build, schema_version, ", + "sha256, license, build_independent, availabil", + "ity | received: list | provide the governance", + " metadata") +.CS15_LAW_CLAUSES[["rej-meta-absent-one"]] <- paste0("reference metadata is missing governance fiel", + "ds | governance fields: version, class, build", + ", schema_version, sha256, license, build_inde", + "pendent, availability | missing: 'license' | ", + "record the missing field(s) in metadata") +.CS15_LAW_CLAUSES[["rej-meta-absent-two"]] <- paste0("reference metadata is missing governance fiel", + "ds | governance fields: version, class, build", + ", schema_version, sha256, license, build_inde", + "pendent, availability | missing: 'build', 'sh", + "a256' | record the missing field(s) in metada", + "ta") +.CS15_LAW_CLAUSES[["rej-field-version-empty"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '' | record t", + "he field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-na"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: 'NA' | record", + " the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-multi"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '1', '2' | re", + "cord the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-num"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '1' | record ", + "the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-class-empty"]] <- paste0("metadata field 'class' must be a single non-e", + "mpty string | governance fields pin the refer", + "ence set identity | received: '' | record the", + " field as a single string") +.CS15_LAW_CLAUSES[["rej-field-schema-na"]] <- paste0("metadata field 'schema_version' must be a sin", + "gle non-empty string | governance fields pin ", + "the reference set identity | received: 'NA' |", + " record the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-license-multi"]] <- paste0("metadata field 'license' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: 'CC0-1.0', 'C", + "C-BY-4.0' | record the field as a single stri", + "ng") +.CS15_LAW_CLAUSES[["rej-indep-na"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: 'NA", + "' | set build_independent = TRUE only for bui", + "ld-agnostic sets") +.CS15_LAW_CLAUSES[["rej-indep-num"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: '1'", + " | set build_independent = TRUE only for buil", + "d-agnostic sets") +.CS15_LAW_CLAUSES[["rej-indep-str"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: 'TR", + "UE' | set build_independent = TRUE only for b", + "uild-agnostic sets") +.CS15_LAW_CLAUSES[["rej-build-empty"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '' | record the genome build,", + " or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-empty-declared"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '' | record the genome build,", + " or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-num"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '38' | record the genome buil", + "d, or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-multi"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: 'GRCh38', 'GRCh37' | record t", + "he genome build, or declare build independenc", + "e") +.CS15_LAW_CLAUSES[["rej-a13-undeclared"]] <- paste0("a missing build must be declared via build_in", + "dependent = TRUE | build-agnostic reference s", + "ets must say so explicitly (A13) | build = NA", + ", build_independent = FALSE | record the buil", + "d, or set build_independent = TRUE") +.CS15_LAW_CLAUSES[["rej-sha-upper"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'AAAAAAAAAAAAAAA", + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "AAAA' | record the sha256 of the reference so", + "urce") +.CS15_LAW_CLAUSES[["rej-sha-short"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'aaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaa' | record the sha256 of the reference sou", + "rce") +.CS15_LAW_CLAUSES[["rej-sha-nonhex"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'ggggggggggggggg", + "ggggggggggggggggggggggggggggggggggggggggggggg", + "gggg' | record the sha256 of the reference so", + "urce") +.CS15_LAW_CLAUSES[["rej-sha-num"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: '42' | record th", + "e sha256 of the reference source") +.CS15_LAW_CLAUSES[["rej-sha-na"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'NA' | record th", + "e sha256 of the reference source") +.CS15_LAW_CLAUSES[["rej-avail-na"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: character of length 2 | list known buil", + "ds, or pass character(0)") +.CS15_LAW_CLAUSES[["rej-avail-num"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: integer of length 1 | list known builds", + ", or pass character(0)") +.CS15_LAW_CLAUSES[["rej-avail-logical"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: logical of length 1 | list known builds", + ", or pass character(0)") +.CS15_SPEC_ARMS <- c("sp-canonical", "sp-two-matrices", "sp-na-declared", "sp-availability-zero", "sp-availability-multi", "sp-integer-matrix", "sp-1x1", "sp-dup-colnames") +.CS15_SPEC_CLS <- c("msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb") +.CS15_SPEC_DETAILS <- list() +.CS15_SPEC_DETAILS[["sp-canonical"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_SPEC_DETAILS[["sp-two-matrices"]] <- paste0("nmat=2;names=core,ext;nrow=4;ncol=2;class=SBS", + ";version=1;build=GRCh38;indep=FALSE;avail=GRC", + "h38;fmt= class: SBS | version: 1 | 2", + " matrices") +.CS15_SPEC_DETAILS[["sp-na-declared"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=NA;indep=TRUE;avail=GRCh38;fmt=<", + "MsRefDb> class: SBS | version: 1 | 1 matrices") +.CS15_SPEC_DETAILS[["sp-availability-zero"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices") +.CS15_SPEC_DETAILS[["sp-availability-multi"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38+", + "GRCh37;fmt= class: SBS | version: 1 ", + "| 1 matrices") +.CS15_SPEC_DETAILS[["sp-integer-matrix"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_SPEC_DETAILS[["sp-1x1"]] <- paste0("nmat=1;names=one;nrow=1;ncol=1;class=SBS;vers", + "ion=1;build=GRCh38;indep=FALSE;avail=GRCh38;f", + "mt= class: SBS | version: 1 | 1 matr", + "ices") +.CS15_SPEC_DETAILS[["sp-dup-colnames"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_PLANT <- list() +.CS15_PLANT[["M1"]] <- c("structure(c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5), dim = c(4L, 2L), dimnames = list(c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\"), c(\"SBS1\", \"SBS5\")))") +.CS15_PLANT[["M2"]] <- c("structure(c(1, 2, 3, 4, 5, 6, 7, 8), dim = c(4L, 2L), dimnames = list(c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\"), c(\"SBS1\", \"SBS5\")))") +.CS15_PLANT[["META"]] <- c("list(version = \"1\", class = \"SBS\", build = \"GRCh38\", schema_version = \"1\", sha256 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", license = \"CC0-1.0\", build_independent = FALSE, availability = \"GRCh38\")") +.CS15_PLANT[["CH"]] <- c("c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\")") +.CS15_PLANT[["SN"]] <- c("c(\"SBS1\", \"SBS5\")") +.CS15_PLANT[["SHA64"]] <- c("\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"") +.CS15_PREC_ARMS <- c("prec-first-matrix-authority", "prec-field-before-a13", "prec-matrix-before-metadata", "prec-sha-before-availability") +.CS15_PREC_FIRES <- c("msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb") +.CS15_PREC_ANCHOR <- c(paste0("reference matrices must share the same channe", + "l labels"), paste0("metadata field 'version' must be a single non", + "-empty string"), "reference matrix 'core' must be non-negative", paste0("metadata field 'sha256' must be a sha256 hex ", + "digest")) +.CS15_PREC_ANTI <- c("matrix 'core' disagrees", "must be declared via build_independent", "is missing governance fields", "'availability' must be") +.CS15_DEGEN <- list( +list(edge = "NA build: declared vs undeclared (A13)", arm = "sp-na-declared", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=NA;indep=TRUE;avail=GRCh38;fmt=<", + "MsRefDb> class: SBS | version: 1 | 1 matrices")), + list(edge = "NA build: declared vs undeclared (A13)", arm = "rej-a13-undeclared", cls = "msuiter_error_refdb", observed = paste0("a missing build must be declared via build_in", + "dependent = TRUE")), + list(edge = "availability: zero-length vs NA entry", arm = "sp-availability-zero", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices")), + list(edge = "availability: zero-length vs NA entry", arm = "rej-avail-na", cls = "msuiter_error_refdb", observed = paste0("metadata field 'availability' must be a chara", + "cter vector without NA")), + list(edge = "colnames: duplicates ride, absence falls", arm = "sp-dup-colnames", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices")), + list(edge = "colnames: duplicates ride, absence falls", arm = "rej-mat-colnames", cls = "msuiter_error_refdb", observed = paste0("reference matrix 'core' must carry rownames a", + "nd colnames")), + list(edge = "column space: 1x1 accepted, 0-col refused", arm = "sp-1x1", cls = "accept", observed = paste0("nmat=1;names=one;nrow=1;ncol=1;class=SBS;vers", + "ion=1;build=GRCh38;indep=FALSE;avail=GRCh38;f", + "mt= class: SBS | version: 1 | 1 matr", + "ices")), + list(edge = "column space: 1x1 accepted, 0-col refused", arm = "obs-zero-cols-rejected", cls = "msuiter_error_refdb", observed = paste0("reference matrix 'core' must carry rownames a", + "nd colnames")) +) +.CS15_SCAL_KEYS <- c("governance-fields", "label-key-law", "ffi-no-na-clause", "sha-pin-clause", "plant-checksum", "spec-checksum", "rng-before", "rng-after") +.CS15_SCAL_SOURCE <- list( +list(key = "governance-fields", from_arm = "rej-meta-absent-two", seg = 2L), + list(key = "label-key-law", from_arm = "rej-mat-rownames", seg = 2L), + list(key = "ffi-no-na-clause", from_arm = "rej-mat-na", seg = 2L), + list(key = "sha-pin-clause", from_arm = "rej-sha-upper", seg = 2L) +) +## <> ######################################################## +## <> (single source: injected byte-identically into +## tests/testthat/test-scenario-refdb-witness.R and +## bench/scenarios/run_refdb_witness.R; pure code -- no testthat, no +## rails, reaches the package ONLY through the exported ms_refdb face) +.CS15_BULLET <- "ℹ" + +##' -- error surface mirror (cli bullet glyphs are RENDERING, not bytes: +##' the theme prints ℹ, the testthat context prints an ASCII "i"; both +##' strip per segment -- CS-12/13/14 precedent) +.cs15_describe <- function(e) { + m <- gsub("\n", " | ", paste(as.character(conditionMessage(e)), + collapse = " | "), fixed = TRUE) + segs <- strsplit(m, " | ", fixed = TRUE)[[1L]] + segs <- vapply(seq_along(segs), function(i) { + s <- trimws(segs[i]) + for (b in c(paste0(.CS15_BULLET, " "), "i ")) { + if (startsWith(s, b)) s <- substring(s, nchar(b) + 1L) + } + trimws(s) + }, character(1L)) + paste0(segs, collapse = " | ") +} +.cs15_try <- function(expr) tryCatch(list(v = expr), error = identity) +.cs15_cls <- function(r) if (inherits(r, "error")) class(r)[1L] else + class(r$v)[1L] +.cs15_msg <- function(r) if (inherits(r, "error")) .cs15_describe(r) else "" + +##' -- plants: the frozen deparse text IS the byte carrier. Reconstruction +##' goes through parse/eval of the committed text; the plant checksum rides +##' the frozen text and the live replays (U4/U6, runner rails) prove the +##' reconstruction is faithful -- a drifted plant reddens the lane before +##' any witness byte is written. No file writes: the refdb face is pure R. +.cs15_plants <- function(pd) { + objs <- list() + for (nm in names(.CS15_PLANT)) { + src <- paste0(.CS15_PLANT[[nm]], collapse = "\n") + if (!nzchar(src)) stop(".cs15_plants: empty plant ", nm) + ex <- parse(text = src) + if (length(ex) != 1L) { + stop(".cs15_plants: plant ", nm, " is not a single expression") + } + objs[[nm]] <- eval(ex[[1L]]) + } + objs$dir <- pd + objs +} +##' -- plant-derived builders (exact mirrors of the observed probe shapes) +.cs15_mk <- function(ch, sn, vals) { + matrix(vals, nrow = length(ch), ncol = length(sn), dimnames = list(ch, sn)) +} +.cs15_badmat <- function(P, mod) { + m <- .cs15_mk(P$CH, P$SN, c(1, 2, 3, 4, 5, 6, 7, 8)) + switch(mod, + "na" = { m[2L, 1L] <- NA_real_; m }, + "nan" = { m[1L, 2L] <- NaN; m }, + "inf" = { m[4L, 2L] <- Inf; m }, + "neg" = { m[3L, 1L] <- -1; m }, + "noname" = { rownames(m) <- NULL; m }, + "nocol" = { colnames(m) <- NULL; m }, + "nodim" = { dimnames(m) <- NULL; m }, + stop(".cs15_badmat: unknown modification")) +} +.cs15_mch2 <- function(P, alt) { + .cs15_mk(c(alt, P$CH[2L:4L]), P$SN, c(1, 2, 3, 4, 5, 6, 7, 8)) +} +##' -- the accepted-shape rendering (integers, labels and logicals only: +##' D11 posture by construction -- the float-free face of the container) +.cs15_shape <- function(r) { + paste0("nmat=", length(r@matrices), ";names=", + paste0(names(r@matrices), collapse = ","), + ";nrow=", nrow(r@matrices[[1L]]), + ";ncol=", ncol(r@matrices[[1L]]), + ";class=", r@metadata$class, ";version=", r@metadata$version, + ";build=", r@metadata$build, + ";indep=", r@metadata$build_independent, + ";avail=", paste0(r@metadata$availability, collapse = "+"), + ";fmt=", format(r)) +} +##' -- the canonical texts whose dual-kernel checksums ride the scalars +##' witness (byte-stable joins over the frozen plant deparse texts and the +##' spec roster) +.cs15_plant_text <- function() { + per <- vapply(names(.CS15_PLANT), function(nm) + paste0(nm, "=", paste0(.CS15_PLANT[[nm]], collapse = "~")), + character(1L)) + paste0(per, collapse = ";") +} +.cs15_spec_text <- function() paste0(.CS15_SPEC_ARMS, collapse = ";") + +##' -- acceptance arms: what the face RETURNS on planted truth +.cs15_specfire <- function(arm, P) { + switch(arm, + "sp-canonical" = .cs15_try(ms_refdb(list(core = P$M1), P$META)), + "sp-two-matrices" = .cs15_try(ms_refdb(list(core = P$M1, ext = P$M2), + P$META)), + "sp-na-declared" = .cs15_try({ + r <- P$META; r$build <- NA_character_ + r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "sp-availability-zero" = .cs15_try({ + r <- P$META; r$availability <- character(0L) + ms_refdb(list(core = P$M1), r) + }), + "sp-availability-multi" = .cs15_try({ + r <- P$META; r$availability <- c("GRCh38", "GRCh37") + ms_refdb(list(core = P$M1), r) + }), + "sp-integer-matrix" = .cs15_try(ms_refdb(list(core = matrix( + as.integer(seq_len(8L)), 4L, 2L, dimnames = list(P$CH, P$SN))), + P$META)), + "sp-1x1" = .cs15_try(ms_refdb(list(one = matrix(0.7, 1L, 1L, + dimnames = list(P$CH[[1L]], P$SN[[1L]]))), P$META)), + "sp-dup-colnames" = .cs15_try(ms_refdb(list(core = matrix(1, 4L, 2L, + dimnames = list(P$CH, c(P$SN[[1L]], P$SN[[1L]])))), P$META)), + NULL) +} +##' -- the committed detail rendering per acceptance arm (recomputed live; +##' rails and U4 compare against the frozen bytes) +.cs15_detail <- function(arm, P) { + r <- .cs15_specfire(arm, P) + if (inherits(r, "error")) stop(".cs15_detail: acceptance arm refused ", arm) + paste0(.cs15_shape(r$v)) +} + +##' -- law arms: what the face SAYS on planted violations +.cs15_fire <- function(arm, P) { + switch(arm, + "obs-zero-cols-rejected" = .cs15_try(ms_refdb( + list(core = matrix(numeric(0L), 4L, 0L, + dimnames = list(P$CH, character(0L)))), P$META)), + "rej-mat-empty" = .cs15_try(ms_refdb(list(), P$META)), + "rej-mat-notlist" = .cs15_try(ms_refdb(42L, P$META)), + "rej-mat-null" = .cs15_try(ms_refdb(NULL, P$META)), + "rej-mat-unnamed" = .cs15_try(ms_refdb(list(P$M1), P$META)), + "rej-mat-partial-name" = .cs15_try(ms_refdb(list(core = P$M1, P$M2), + P$META)), + "rej-mat-vector" = .cs15_try(ms_refdb(list(core = seq_len(8L)), P$META)), + "rej-mat-character" = .cs15_try(ms_refdb(list(core = matrix("x", 4L, 2L, + dimnames = list(P$CH, P$SN))), P$META)), + "rej-mat-dataframe" = .cs15_try(ms_refdb(list(core = data.frame( + SBS1 = seq_len(4L), SBS5 = seq_len(4L))), P$META)), + "rej-mat-rownames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "noname")), P$META)), + "rej-mat-colnames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "nocol")), P$META)), + "rej-mat-nodimnames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "nodim")), P$META)), + "rej-mat-na" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "na")), + P$META)), + "rej-mat-nan" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "nan")), + P$META)), + "rej-mat-inf" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "inf")), + P$META)), + "rej-mat-negative" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "neg")), P$META)), + "rej-channels-disagree" = .cs15_try(ms_refdb(list(core = P$M1, + alt = .cs15_mch2(P, "X[C>X]X")), P$META)), + "rej-channels-subset" = .cs15_try(ms_refdb(list(core = P$M1, + small = .cs15_mk(P$CH[1L:3L], P$SN, seq_len(6L))), P$META)), + "rej-meta-notlist" = .cs15_try(ms_refdb(list(core = P$M1), 42L)), + "rej-meta-unnamed" = .cs15_try({ + r <- P$META; names(r) <- NULL + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-emptyname" = .cs15_try({ + r <- P$META; names(r)[3L] <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-absent-one" = .cs15_try({ + r <- P$META; r$license <- NULL + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-absent-two" = .cs15_try({ + r <- P$META; r$build <- NULL; r$sha256 <- NULL + r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-empty" = .cs15_try({ + r <- P$META; r$version <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-na" = .cs15_try({ + r <- P$META; r$version <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-multi" = .cs15_try({ + r <- P$META; r$version <- c("1", "2") + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-num" = .cs15_try({ + r <- P$META; r$version <- 1 + ms_refdb(list(core = P$M1), r) + }), + "rej-field-class-empty" = .cs15_try({ + r <- P$META; r$class <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-field-schema-na" = .cs15_try({ + r <- P$META; r$schema_version <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-field-license-multi" = .cs15_try({ + r <- P$META; r$license <- c("CC0-1.0", "CC-BY-4.0") + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-na" = .cs15_try({ + r <- P$META; r$build_independent <- NA + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-num" = .cs15_try({ + r <- P$META; r$build_independent <- 1L + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-str" = .cs15_try({ + r <- P$META; r$build_independent <- "TRUE" + ms_refdb(list(core = P$M1), r) + }), + "rej-build-empty" = .cs15_try({ + r <- P$META; r$build <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-build-empty-declared" = .cs15_try({ + r <- P$META; r$build <- ""; r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "rej-build-num" = .cs15_try({ + r <- P$META; r$build <- 38L + ms_refdb(list(core = P$M1), r) + }), + "rej-build-multi" = .cs15_try({ + r <- P$META; r$build <- c("GRCh38", "GRCh37") + ms_refdb(list(core = P$M1), r) + }), + "rej-a13-undeclared" = .cs15_try({ + r <- P$META; r$build <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-upper" = .cs15_try({ + r <- P$META; r$sha256 <- paste0(rep_len("A", 64L), collapse = "") + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-short" = .cs15_try({ + r <- P$META; r$sha256 <- substr(P$SHA64, 1L, 63L) + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-nonhex" = .cs15_try({ + r <- P$META; r$sha256 <- paste0(rep_len("g", 64L), collapse = "") + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-num" = .cs15_try({ + r <- P$META; r$sha256 <- 42L + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-na" = .cs15_try({ + r <- P$META; r$sha256 <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-na" = .cs15_try({ + r <- P$META; r$availability <- c("GRCh38", NA_character_) + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-num" = .cs15_try({ + r <- P$META; r$availability <- 38L + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-logical" = .cs15_try({ + r <- P$META; r$availability <- TRUE + ms_refdb(list(core = P$M1), r) + }), + NULL) +} + +##' -- precedence discriminators: which law speaks when two could +.cs15_precfire <- function(arm, P) { + switch(arm, + "prec-first-matrix-authority" = .cs15_try(ms_refdb(list(core = P$M1, + alt = .cs15_mch2(P, "X[C>X]X")), P$META)), + "prec-field-before-a13" = .cs15_try({ + r <- P$META; r$version <- ""; r$build <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "prec-matrix-before-metadata" = .cs15_try({ + r <- P$META; r$license <- NULL + ms_refdb(list(core = .cs15_badmat(P, "neg")), r) + }), + "prec-sha-before-availability" = .cs15_try({ + r <- P$META; r$sha256 <- "x"; r$availability <- 38L + ms_refdb(list(core = P$M1), r) + }), + NULL) +} +##' -- the frozen-table row builders (witness shape comes from the tables; +##' the committed TSVs must mirror these byte for byte) +.cs15_lawrows <- function() { + data.frame(arm = .CS15_LAW_ARMS, face = rep("ms_refdb", length(.CS15_LAW_ARMS)), + cls = .CS15_LAW_CLS, mode = .CS15_LAW_MODE, + clause = vapply(.CS15_LAW_ARMS, function(a) .CS15_LAW_CLAUSES[[a]], + character(1L)), + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_specrows <- function() { + data.frame(arm = .CS15_SPEC_ARMS, face = rep("ms_refdb", length(.CS15_SPEC_ARMS)), + cls = .CS15_SPEC_CLS, + detail = vapply(.CS15_SPEC_ARMS, function(a) .CS15_SPEC_DETAILS[[a]], + character(1L)), + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_precrows <- function() { + data.frame(arm = .CS15_PREC_ARMS, fires_cls = .CS15_PREC_FIRES, + fires_anchor = .CS15_PREC_ANCHOR, anti_anchor = .CS15_PREC_ANTI, + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_degenrows <- function() { + row <- function(k) vapply(.CS15_DEGEN, function(d) d[[k]], character(1L)) + data.frame(edge = row("edge"), arm = row("arm"), cls = row("cls"), + observed = row("observed"), stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_scalar_kv <- function(sc, k) sc$value[match(k, sc$key)] +## <> (do not hand-edit in place: edit the source and +## re-splice both hosts) +## re-splice both hosts) +## re-splice both hosts) + +# -- rail machinery ----------------------------------------------------------- +n_rails <- 0L +n_fail <- 0L +rail <- function(name, cond) { + n_rails <<- n_rails + 1L + if (!isTRUE(cond)) { + n_fail <<- n_fail + 1L + cat("RAIL FAIL: ", name, "\n", sep = "") + } +} + +P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-run-plants")) +rail("plants-reconstructed", + is.matrix(P$M1) && identical(dim(P$M1), c(4L, 2L)) && + is.matrix(P$M2) && identical(dim(P$M2), c(4L, 2L)) && + is.numeric(P$M1) && is.list(P$META) && + !any(is.na(P$META)) && !anyDuplicated(names(P$META)) && + all(nzchar(names(P$META))) && + is.character(P$CH) && length(P$CH) == 4L && + is.character(P$SN) && length(P$SN) == 2L && + identical(nchar(P$SHA64), 64L)) + +# -- witness: laws (adjudicated reject arms) ---------------------------------- +lw_arm <- character(0L); lw_face <- character(0L); lw_cls <- character(0L) +lw_mode <- character(0L); lw_clause <- character(0L) +for (i in seq_along(.CS15_LAW_ARMS)) { + arm <- .CS15_LAW_ARMS[i] + r <- .cs15_fire(arm, P) + rail(paste0("law-", arm, "-aborts"), inherits(r, "error")) + lc <- .cs15_cls(r); lm <- .cs15_msg(r) + rail(paste0("law-", arm, "-class"), identical(lc, .CS15_LAW_CLS[i])) + if (identical(.CS15_LAW_MODE[i], "full")) { + rail(paste0("law-", arm, "-clause"), + identical(lm, .CS15_LAW_CLAUSES[[arm]])) + committed <- lm + } else { + bls <- strsplit(.CS15_LAW_CLAUSES[[arm]], " | ", fixed = TRUE)[[1L]] + rail(paste0("law-", arm, "-bullets"), + all(vapply(bls, function(b) grepl(b, lm, fixed = TRUE), logical(1L)))) + committed <- .CS15_LAW_CLAUSES[[arm]] + } + lw_arm <- c(lw_arm, arm); lw_face <- c(lw_face, "ms_refdb") + lw_cls <- c(lw_cls, lc); lw_mode <- c(lw_mode, .CS15_LAW_MODE[i]) + lw_clause <- c(lw_clause, committed) +} +laws_dat <- data.frame(arm = lw_arm, face = lw_face, cls = lw_cls, + mode = lw_mode, clause = lw_clause, + stringsAsFactors = FALSE) + +# -- witness: specs (acceptance arms) ------------------------------------------ +sp_arm <- character(0L); sp_face <- character(0L); sp_cls <- character(0L) +sp_detail <- character(0L) +for (i in seq_along(.CS15_SPEC_ARMS)) { + arm <- .CS15_SPEC_ARMS[i] + r <- .cs15_specfire(arm, P) + rail(paste0("spec-", arm, "-returns"), !inherits(r, "error")) + lc <- .cs15_cls(r) + rail(paste0("spec-", arm, "-class"), identical(lc, .CS15_SPEC_CLS[i])) + dt <- .cs15_detail(arm, P) + rail(paste0("spec-", arm, "-detail"), identical(dt, .CS15_SPEC_DETAILS[[arm]])) + sp_arm <- c(sp_arm, arm); sp_face <- c(sp_face, "ms_refdb") + sp_cls <- c(sp_cls, lc); sp_detail <- c(sp_detail, dt) +} +specs_dat <- data.frame(arm = sp_arm, face = sp_face, cls = sp_cls, + detail = sp_detail, stringsAsFactors = FALSE) + +# -- witness: precedence discriminators ----------------------------------------- +pr_arm <- character(0L); pr_fires <- character(0L) +pr_anchor <- character(0L); pr_anti <- character(0L) +for (i in seq_along(.CS15_PREC_ARMS)) { + arm <- .CS15_PREC_ARMS[i] + r <- .cs15_precfire(arm, P) + lm <- .cs15_msg(r) + rail(paste0("prec-", arm, "-fires"), + identical(.cs15_cls(r), .CS15_PREC_FIRES[i]) && + grepl(.CS15_PREC_ANCHOR[i], lm, fixed = TRUE) && + !grepl(.CS15_PREC_ANTI[i], lm, fixed = TRUE)) + pr_arm <- c(pr_arm, arm); pr_fires <- c(pr_fires, .cs15_cls(r)) + pr_anchor <- c(pr_anchor, .CS15_PREC_ANCHOR[i]) + pr_anti <- c(pr_anti, .CS15_PREC_ANTI[i]) +} +prec_dat <- data.frame(arm = pr_arm, fires_cls = pr_fires, + fires_anchor = pr_anchor, anti_anchor = pr_anti, + stringsAsFactors = FALSE) + +# -- witness: degenerate boundaries ------------------------------------------------ +dg_edge <- character(0L); dg_arm <- character(0L); dg_cls <- character(0L) +dg_obs <- character(0L) +for (d in .CS15_DEGEN) { + if (identical(d$cls, "accept")) { + r <- .cs15_specfire(d$arm, P) + rail(paste0("degen-", d$arm, "-accepts"), + !inherits(r, "error") && + identical(.cs15_detail(d$arm, P), d$observed)) + } else { + r <- .cs15_fire(d$arm, P) + rail(paste0("degen-", d$arm, "-refuses"), + inherits(r, "error") && grepl(d$observed, .cs15_msg(r), fixed = TRUE)) + } + dg_edge <- c(dg_edge, d$edge); dg_arm <- c(dg_arm, d$arm) + dg_cls <- c(dg_cls, d$cls); dg_obs <- c(dg_obs, d$observed) +} +degen_dat <- data.frame(edge = dg_edge, arm = dg_arm, cls = dg_cls, + observed = dg_obs, stringsAsFactors = FALSE) + +# -- witness: scalars ----------------------------------------------------------------- +scal_key <- character(0L); scal_val <- character(0L) +add_scal <- function(k, v) { + scal_key <<- c(scal_key, k); scal_val <<- c(scal_val, v) +} +for (s in .CS15_SCAL_SOURCE) { + msg <- .cs15_msg(.cs15_fire(s$from_arm, P)) + seg <- strsplit(msg, " | ", fixed = TRUE)[[1L]][s$seg] + froz <- strsplit(.CS15_LAW_CLAUSES[[s$from_arm]], " | ", fixed = TRUE)[[1L]][s$seg] + rail(paste0("scal-", s$key, "-verbatim"), + identical(seg, froz) && nzchar(seg)) + add_scal(s$key, seg) +} +plant_bytes <- charToRaw(.cs15_plant_text()) +ck_a <- .ms_fit_sha256(plant_bytes) +ck_b <- digest::digest(plant_bytes, algo = "sha256", serialize = FALSE) +rail("plant-checksum-kernels", + identical(ck_a, ck_b) && grepl("^[0-9a-f]{64}$", ck_a, perl = TRUE)) +add_scal("plant-checksum", ck_a) +spec_bytes <- charToRaw(.cs15_spec_text()) +sk_a <- .ms_fit_sha256(spec_bytes) +sk_b <- digest::digest(spec_bytes, algo = "sha256", serialize = FALSE) +rail("spec-checksum-kernels", identical(sk_a, sk_b)) +add_scal("spec-checksum", sk_a) +rng1 <- exists(".Random.seed", inherits = TRUE) +add_scal("rng-before", paste0(rng0)) +add_scal("rng-after", paste0(rng1)) +scal_dat <- data.frame(key = scal_key, value = scal_val, + stringsAsFactors = FALSE) +rail("scal-keys-exact", identical(scal_key, .CS15_SCAL_KEYS)) + +# -- payload censuses ------------------------------------------------------------------- +census <- function(df) { + is.data.frame(df) && nrow(df) > 0L && + all(vapply(df, is.character, logical(1L))) && + !any(vapply(df, function(cc) any(is.na(cc)), logical(1L))) +} +rail("specs-shape", nrow(specs_dat) == 8L && census(specs_dat)) +rail("laws-shape", nrow(laws_dat) == 46L && census(laws_dat)) +rail("prec-shape", nrow(prec_dat) == 4L && census(prec_dat)) +rail("degen-shape", nrow(degen_dat) == 8L && census(degen_dat)) +rail("scal-shape", nrow(scal_dat) == 8L && census(scal_dat)) +rail("rng-rails-silent", !rng0 && !rng1) + +# -- attestation face ---------------------------------------------------------------------- +cat("[attest] FACE-only adjudication: returns, classes and clauses are the\n") +cat("[attest] exported reference-container factory's own; no face internals\n") +cat("[attest] reached, no validator reach-through, no hand-rolled reading of\n") +cat("[attest] the verdicts.\n") +cat("[attest] D3: all plants are synthetic R objects; zero COSMIC numeric\n") +cat("[attest] matrices; downloads zero.\n") +cat("[attest] D11 posture: class/label/integer/logical/clause bytes are\n") +cat("[attest] byte-committed; the face produces no float payload columns, so\n") +cat("[attest] no float glyph rides any witness.\n") +cat("[attest] The plant checksum re-hashes through BOTH governed SHA-256\n") +cat("[attest] kernels (canonical pure-R and the digest accelerator).\n") +cat("[attest] RNG rails (.Random.seed presence): before = ", rng0, ", after = ", + rng1, "\n", sep = "") +cat("[attest] The benchmark runner and the DECLINED calibration family are\n") +cat("[attest] never invoked here.\n") + +# -- commit (all censuses spoke first) -------------------------------------------------------- +if (!(census(specs_dat) && census(laws_dat) && census(prec_dat) && + census(degen_dat) && census(scal_dat))) { + cat("OVERALL FAIL -- payload census refused a witness write\n") + quit(status = 1L) +} +dir.create(OUT, showWarnings = FALSE) +.wtab <- function(nm, df) { + con <- file(file.path(OUT, nm), open = "wb") + on.exit(close(con)) + write.table(df, con, sep = "\t", quote = FALSE, row.names = FALSE, na = "") +} +.wtab("cs15_specs.tsv", specs_dat) +.wtab("cs15_laws.tsv", laws_dat) +.wtab("cs15_precedence.tsv", prec_dat) +.wtab("cs15_degenerates.tsv", degen_dat) +.wtab("cs15_scalars.tsv", scal_dat) + +cat("\n", if (identical(n_fail, 0L)) "OVERALL PASS" else "OVERALL FAIL", + " (", n_rails, " adjudications, ", n_fail, " failed)\n", sep = "") +quit(status = if (identical(n_fail, 0L)) 0L else 1L) diff --git a/tests/testthat/test-scenario-refdb-witness.R b/tests/testthat/test-scenario-refdb-witness.R new file mode 100644 index 0000000..6b69d88 --- /dev/null +++ b/tests/testthat/test-scenario-refdb-witness.R @@ -0,0 +1,862 @@ +# test-scenario-refdb-witness.R -- the CS-15 refdb-witness law units +# (pillar 3). The scenario plants synthetic R objects (the D3 law: zero +# COSMIC numeric matrices, zero real-data bytes, zero downloads -- build and +# class labels ride only as FORMAT NAMES) and adjudicates the EXPORTED +# ms_refdb() face: the container admission laws (non-empty named list, the +# numeric-matrix law, the label-key dimnames law, the NA/non-finite ban, the +# non-negative law, the first-matrix channel authority), the governance- +# metadata laws (the named-list law, the required-field roster, the four +# single-non-empty-string fields, the build_independent bool, the build +# string-or-NA law, the A13 cross-field clause, the lowercase sha256 policy, +# the availability no-NA law), the double-gate split between the S7 property +# gates and the container validator, the precedence discriminators and the +# degenerate boundaries. The witness bytes under bench/scenarios/out/ +# (cs15_specs.tsv, cs15_laws.tsv, cs15_precedence.tsv, cs15_degenerates.tsv, +# cs15_scalars.tsv) are the committed verdict: a drift in a fired clause, an +# observed error class, an accepted shape or the precedence order reddens +# here before print. The plants are synthetic -- no RNG, no network, no +# COSMIC bytes; the lane NEVER calls the benchmark driver, the declined +# calibration family, or any internal of the face (banned words, grepped). +# Framing law: DECISION RECORD only. What the face says on planted truth -- +# the accepted shapes, the abort classes, the fired bullets -- is an +# OBSERVED, COMMITTED record, never a fidelity claim beyond what was +# measured. Cross-platform posture (D11): integer, label, logical, class +# and clause bytes are byte-committed; the face produces no float payload +# columns (the matrices carry cell values only through the validator, which +# is a verdict, not a print), so no float glyph rides any witness. +# The frozen block and the shared code block below are MINTED mechanically +# from the observed probe ledger (gen-frozen.cs15.R / probe-cs15.R); neither +# is ever hand-edited in place. + +.rs_out15 <- function(fname) { + file.path(.ms_root, "bench", "scenarios", "out", fname) +} + +# The committed tables are written quote-free; quote = "" keeps every +# double quote inside the clauses literal on read. +.rs_tsv15 <- function(fname) { + read.csv(.rs_out15(fname), header = TRUE, sep = "\t", + stringsAsFactors = FALSE, na.strings = "", colClasses = "character", + quote = "") +} + +## <> (minted mechanically from the observed ledger +## 2026-11-23; DO NOT hand-edit: regenerate via gen-frozen.cs15.R) ## +.CS15_LAW_ARMS <- c("obs-zero-cols-rejected", "rej-mat-empty", "rej-mat-notlist", "rej-mat-null", "rej-mat-unnamed", "rej-mat-partial-name", "rej-mat-vector", "rej-mat-character", "rej-mat-dataframe", "rej-mat-rownames", "rej-mat-colnames", "rej-mat-nodimnames", "rej-mat-na", "rej-mat-nan", "rej-mat-inf", "rej-mat-negative", "rej-channels-disagree", "rej-channels-subset", "rej-meta-notlist", "rej-meta-unnamed", "rej-meta-emptyname", "rej-meta-absent-one", "rej-meta-absent-two", "rej-field-version-empty", "rej-field-version-na", "rej-field-version-multi", "rej-field-version-num", "rej-field-class-empty", "rej-field-schema-na", "rej-field-license-multi", "rej-indep-na", "rej-indep-num", "rej-indep-str", "rej-build-empty", "rej-build-empty-declared", "rej-build-num", "rej-build-multi", "rej-a13-undeclared", "rej-sha-upper", "rej-sha-short", "rej-sha-nonhex", "rej-sha-num", "rej-sha-na", "rej-avail-na", "rej-avail-num", "rej-avail-logical") +.CS15_LAW_CLS <- c("msuiter_error_refdb", "msuiter_error_refdb", "simpleError", "simpleError", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "simpleError", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb") +.CS15_LAW_MODE <- c("full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full", "full") +.CS15_LAW_CLAUSES <- list() +.CS15_LAW_CLAUSES[["obs-zero-cols-rejected"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "FALSE; colnames missing: TRUE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-empty"]] <- paste0("matrices must be a non-empty named list | an ", + "MsRefDb bundles at least one reference signat", + "ure matrix | received: list of length 0 | pas", + "s the reference matrices as a named list") +.CS15_LAW_CLAUSES[["rej-mat-notlist"]] <- paste0(" object properties are inva", + "lid: | - @matrices must be , not ") +.CS15_LAW_CLAUSES[["rej-mat-null"]] <- paste0(" object properties are inva", + "lid: | - @matrices must be , not ") +.CS15_LAW_CLAUSES[["rej-mat-unnamed"]] <- paste0("every reference matrix must be named | matrix", + " names identify reference sets (e.g. PCAWG) |", + " names: (none) | name every list element") +.CS15_LAW_CLAUSES[["rej-mat-partial-name"]] <- paste0("every reference matrix must be named | matrix", + " names identify reference sets (e.g. PCAWG) |", + " names: 'core', '' | name every list element") +.CS15_LAW_CLAUSES[["rej-mat-vector"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: integer | pass numeric m", + "atrices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-character"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: matrix | pass numeric ma", + "trices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-dataframe"]] <- paste0("reference matrix 'core' must be a numeric mat", + "rix | reference signatures are channel-space ", + "matrices | received: data.frame | pass numeri", + "c matrices with full dimnames") +.CS15_LAW_CLAUSES[["rej-mat-rownames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "TRUE; colnames missing: FALSE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-colnames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "FALSE; colnames missing: TRUE | set the matri", + "x dimnames") +.CS15_LAW_CLAUSES[["rej-mat-nodimnames"]] <- paste0("reference matrix 'core' must carry rownames a", + "nd colnames | labels are the only legal match", + "ing key (never position) | rownames missing: ", + "TRUE; colnames missing: TRUE | set the matrix", + " dimnames") +.CS15_LAW_CLAUSES[["rej-mat-na"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '2' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-nan"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '5' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-inf"]] <- paste0("reference matrix 'core' must not contain NA o", + "r non-finite values | the FFI contract reject", + "s NA | offending cells: '8' | fix the referen", + "ce matrix source") +.CS15_LAW_CLAUSES[["rej-mat-negative"]] <- paste0("reference matrix 'core' must be non-negative ", + "| reference signatures are non-negative by de", + "finition | offending cells: '3' | check the r", + "eference matrix source") +.CS15_LAW_CLAUSES[["rej-channels-disagree"]] <- paste0("reference matrices must share the same channe", + "l labels | channel labels are matched by labe", + "l, element by element | matrix 'alt' disagree", + "s; offending labels: 'X[C>X]X' | project all ", + "matrices onto one common channel space") +.CS15_LAW_CLAUSES[["rej-channels-subset"]] <- paste0("reference matrices must share the same channe", + "l labels | channel labels are matched by labe", + "l, element by element | matrix 'small' disagr", + "ees; offending labels: (none) | project all m", + "atrices onto one common channel space") +.CS15_LAW_CLAUSES[["rej-meta-notlist"]] <- paste0(" object properties are inva", + "lid: | - @metadata must be , not ") +.CS15_LAW_CLAUSES[["rej-meta-unnamed"]] <- paste0("metadata must be a named list | governance fi", + "elds: version, class, build, schema_version, ", + "sha256, license, build_independent, availabil", + "ity | received: list | provide the governance", + " metadata") +.CS15_LAW_CLAUSES[["rej-meta-emptyname"]] <- paste0("metadata must be a named list | governance fi", + "elds: version, class, build, schema_version, ", + "sha256, license, build_independent, availabil", + "ity | received: list | provide the governance", + " metadata") +.CS15_LAW_CLAUSES[["rej-meta-absent-one"]] <- paste0("reference metadata is missing governance fiel", + "ds | governance fields: version, class, build", + ", schema_version, sha256, license, build_inde", + "pendent, availability | missing: 'license' | ", + "record the missing field(s) in metadata") +.CS15_LAW_CLAUSES[["rej-meta-absent-two"]] <- paste0("reference metadata is missing governance fiel", + "ds | governance fields: version, class, build", + ", schema_version, sha256, license, build_inde", + "pendent, availability | missing: 'build', 'sh", + "a256' | record the missing field(s) in metada", + "ta") +.CS15_LAW_CLAUSES[["rej-field-version-empty"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '' | record t", + "he field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-na"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: 'NA' | record", + " the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-multi"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '1', '2' | re", + "cord the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-version-num"]] <- paste0("metadata field 'version' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: '1' | record ", + "the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-class-empty"]] <- paste0("metadata field 'class' must be a single non-e", + "mpty string | governance fields pin the refer", + "ence set identity | received: '' | record the", + " field as a single string") +.CS15_LAW_CLAUSES[["rej-field-schema-na"]] <- paste0("metadata field 'schema_version' must be a sin", + "gle non-empty string | governance fields pin ", + "the reference set identity | received: 'NA' |", + " record the field as a single string") +.CS15_LAW_CLAUSES[["rej-field-license-multi"]] <- paste0("metadata field 'license' must be a single non", + "-empty string | governance fields pin the ref", + "erence set identity | received: 'CC0-1.0', 'C", + "C-BY-4.0' | record the field as a single stri", + "ng") +.CS15_LAW_CLAUSES[["rej-indep-na"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: 'NA", + "' | set build_independent = TRUE only for bui", + "ld-agnostic sets") +.CS15_LAW_CLAUSES[["rej-indep-num"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: '1'", + " | set build_independent = TRUE only for buil", + "d-agnostic sets") +.CS15_LAW_CLAUSES[["rej-indep-str"]] <- paste0("metadata field 'build_independent' must be a ", + "single TRUE or FALSE | build independence is ", + "an explicit declaration (A13) | received: 'TR", + "UE' | set build_independent = TRUE only for b", + "uild-agnostic sets") +.CS15_LAW_CLAUSES[["rej-build-empty"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '' | record the genome build,", + " or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-empty-declared"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '' | record the genome build,", + " or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-num"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: '38' | record the genome buil", + "d, or declare build independence") +.CS15_LAW_CLAUSES[["rej-build-multi"]] <- paste0("metadata field 'build' must be a single strin", + "g, or NA if build independent | NA build is l", + "egal only together with build_independent = T", + "RUE | received: 'GRCh38', 'GRCh37' | record t", + "he genome build, or declare build independenc", + "e") +.CS15_LAW_CLAUSES[["rej-a13-undeclared"]] <- paste0("a missing build must be declared via build_in", + "dependent = TRUE | build-agnostic reference s", + "ets must say so explicitly (A13) | build = NA", + ", build_independent = FALSE | record the buil", + "d, or set build_independent = TRUE") +.CS15_LAW_CLAUSES[["rej-sha-upper"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'AAAAAAAAAAAAAAA", + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "AAAA' | record the sha256 of the reference so", + "urce") +.CS15_LAW_CLAUSES[["rej-sha-short"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'aaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaa' | record the sha256 of the reference sou", + "rce") +.CS15_LAW_CLAUSES[["rej-sha-nonhex"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'ggggggggggggggg", + "ggggggggggggggggggggggggggggggggggggggggggggg", + "gggg' | record the sha256 of the reference so", + "urce") +.CS15_LAW_CLAUSES[["rej-sha-num"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: '42' | record th", + "e sha256 of the reference source") +.CS15_LAW_CLAUSES[["rej-sha-na"]] <- paste0("metadata field 'sha256' must be a sha256 hex ", + "digest | the digest pins the reference conten", + "t (A13 manifest) | received: 'NA' | record th", + "e sha256 of the reference source") +.CS15_LAW_CLAUSES[["rej-avail-na"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: character of length 2 | list known buil", + "ds, or pass character(0)") +.CS15_LAW_CLAUSES[["rej-avail-num"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: integer of length 1 | list known builds", + ", or pass character(0)") +.CS15_LAW_CLAUSES[["rej-avail-logical"]] <- paste0("metadata field 'availability' must be a chara", + "cter vector without NA | availability lists t", + "he builds with official reference sets | rece", + "ived: logical of length 1 | list known builds", + ", or pass character(0)") +.CS15_SPEC_ARMS <- c("sp-canonical", "sp-two-matrices", "sp-na-declared", "sp-availability-zero", "sp-availability-multi", "sp-integer-matrix", "sp-1x1", "sp-dup-colnames") +.CS15_SPEC_CLS <- c("msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb", "msuiter::MsRefDb") +.CS15_SPEC_DETAILS <- list() +.CS15_SPEC_DETAILS[["sp-canonical"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_SPEC_DETAILS[["sp-two-matrices"]] <- paste0("nmat=2;names=core,ext;nrow=4;ncol=2;class=SBS", + ";version=1;build=GRCh38;indep=FALSE;avail=GRC", + "h38;fmt= class: SBS | version: 1 | 2", + " matrices") +.CS15_SPEC_DETAILS[["sp-na-declared"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=NA;indep=TRUE;avail=GRCh38;fmt=<", + "MsRefDb> class: SBS | version: 1 | 1 matrices") +.CS15_SPEC_DETAILS[["sp-availability-zero"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices") +.CS15_SPEC_DETAILS[["sp-availability-multi"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38+", + "GRCh37;fmt= class: SBS | version: 1 ", + "| 1 matrices") +.CS15_SPEC_DETAILS[["sp-integer-matrix"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_SPEC_DETAILS[["sp-1x1"]] <- paste0("nmat=1;names=one;nrow=1;ncol=1;class=SBS;vers", + "ion=1;build=GRCh38;indep=FALSE;avail=GRCh38;f", + "mt= class: SBS | version: 1 | 1 matr", + "ices") +.CS15_SPEC_DETAILS[["sp-dup-colnames"]] <- paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices") +.CS15_PLANT <- list() +.CS15_PLANT[["M1"]] <- c("structure(c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5), dim = c(4L, 2L), dimnames = list(c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\"), c(\"SBS1\", \"SBS5\")))") +.CS15_PLANT[["M2"]] <- c("structure(c(1, 2, 3, 4, 5, 6, 7, 8), dim = c(4L, 2L), dimnames = list(c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\"), c(\"SBS1\", \"SBS5\")))") +.CS15_PLANT[["META"]] <- c("list(version = \"1\", class = \"SBS\", build = \"GRCh38\", schema_version = \"1\", sha256 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", license = \"CC0-1.0\", build_independent = FALSE, availability = \"GRCh38\")") +.CS15_PLANT[["CH"]] <- c("c(\"A[C>A]A\", \"C[C>A]A\", \"G[C>G]C\", \"T[C>T]T\")") +.CS15_PLANT[["SN"]] <- c("c(\"SBS1\", \"SBS5\")") +.CS15_PLANT[["SHA64"]] <- c("\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"") +.CS15_PREC_ARMS <- c("prec-first-matrix-authority", "prec-field-before-a13", "prec-matrix-before-metadata", "prec-sha-before-availability") +.CS15_PREC_FIRES <- c("msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb", "msuiter_error_refdb") +.CS15_PREC_ANCHOR <- c(paste0("reference matrices must share the same channe", + "l labels"), paste0("metadata field 'version' must be a single non", + "-empty string"), "reference matrix 'core' must be non-negative", paste0("metadata field 'sha256' must be a sha256 hex ", + "digest")) +.CS15_PREC_ANTI <- c("matrix 'core' disagrees", "must be declared via build_independent", "is missing governance fields", "'availability' must be") +.CS15_DEGEN <- list( +list(edge = "NA build: declared vs undeclared (A13)", arm = "sp-na-declared", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=NA;indep=TRUE;avail=GRCh38;fmt=<", + "MsRefDb> class: SBS | version: 1 | 1 matrices")), + list(edge = "NA build: declared vs undeclared (A13)", arm = "rej-a13-undeclared", cls = "msuiter_error_refdb", observed = paste0("a missing build must be declared via build_in", + "dependent = TRUE")), + list(edge = "availability: zero-length vs NA entry", arm = "sp-availability-zero", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=;fmt= class: SBS | version: 1 | 1 matrices")), + list(edge = "availability: zero-length vs NA entry", arm = "rej-avail-na", cls = "msuiter_error_refdb", observed = paste0("metadata field 'availability' must be a chara", + "cter vector without NA")), + list(edge = "colnames: duplicates ride, absence falls", arm = "sp-dup-colnames", cls = "accept", observed = paste0("nmat=1;names=core;nrow=4;ncol=2;class=SBS;ver", + "sion=1;build=GRCh38;indep=FALSE;avail=GRCh38;", + "fmt= class: SBS | version: 1 | 1 mat", + "rices")), + list(edge = "colnames: duplicates ride, absence falls", arm = "rej-mat-colnames", cls = "msuiter_error_refdb", observed = paste0("reference matrix 'core' must carry rownames a", + "nd colnames")), + list(edge = "column space: 1x1 accepted, 0-col refused", arm = "sp-1x1", cls = "accept", observed = paste0("nmat=1;names=one;nrow=1;ncol=1;class=SBS;vers", + "ion=1;build=GRCh38;indep=FALSE;avail=GRCh38;f", + "mt= class: SBS | version: 1 | 1 matr", + "ices")), + list(edge = "column space: 1x1 accepted, 0-col refused", arm = "obs-zero-cols-rejected", cls = "msuiter_error_refdb", observed = paste0("reference matrix 'core' must carry rownames a", + "nd colnames")) +) +.CS15_SCAL_KEYS <- c("governance-fields", "label-key-law", "ffi-no-na-clause", "sha-pin-clause", "plant-checksum", "spec-checksum", "rng-before", "rng-after") +.CS15_SCAL_SOURCE <- list( +list(key = "governance-fields", from_arm = "rej-meta-absent-two", seg = 2L), + list(key = "label-key-law", from_arm = "rej-mat-rownames", seg = 2L), + list(key = "ffi-no-na-clause", from_arm = "rej-mat-na", seg = 2L), + list(key = "sha-pin-clause", from_arm = "rej-sha-upper", seg = 2L) +) +## <> ######################################################## +## <> (single source: injected byte-identically into +## tests/testthat/test-scenario-refdb-witness.R and +## bench/scenarios/run_refdb_witness.R; pure code -- no testthat, no +## rails, reaches the package ONLY through the exported ms_refdb face) +.CS15_BULLET <- "ℹ" + +##' -- error surface mirror (cli bullet glyphs are RENDERING, not bytes: +##' the theme prints ℹ, the testthat context prints an ASCII "i"; both +##' strip per segment -- CS-12/13/14 precedent) +.cs15_describe <- function(e) { + m <- gsub("\n", " | ", paste(as.character(conditionMessage(e)), + collapse = " | "), fixed = TRUE) + segs <- strsplit(m, " | ", fixed = TRUE)[[1L]] + segs <- vapply(seq_along(segs), function(i) { + s <- trimws(segs[i]) + for (b in c(paste0(.CS15_BULLET, " "), "i ")) { + if (startsWith(s, b)) s <- substring(s, nchar(b) + 1L) + } + trimws(s) + }, character(1L)) + paste0(segs, collapse = " | ") +} +.cs15_try <- function(expr) tryCatch(list(v = expr), error = identity) +.cs15_cls <- function(r) if (inherits(r, "error")) class(r)[1L] else + class(r$v)[1L] +.cs15_msg <- function(r) if (inherits(r, "error")) .cs15_describe(r) else "" + +##' -- plants: the frozen deparse text IS the byte carrier. Reconstruction +##' goes through parse/eval of the committed text; the plant checksum rides +##' the frozen text and the live replays (U4/U6, runner rails) prove the +##' reconstruction is faithful -- a drifted plant reddens the lane before +##' any witness byte is written. No file writes: the refdb face is pure R. +.cs15_plants <- function(pd) { + objs <- list() + for (nm in names(.CS15_PLANT)) { + src <- paste0(.CS15_PLANT[[nm]], collapse = "\n") + if (!nzchar(src)) stop(".cs15_plants: empty plant ", nm) + ex <- parse(text = src) + if (length(ex) != 1L) { + stop(".cs15_plants: plant ", nm, " is not a single expression") + } + objs[[nm]] <- eval(ex[[1L]]) + } + objs$dir <- pd + objs +} +##' -- plant-derived builders (exact mirrors of the observed probe shapes) +.cs15_mk <- function(ch, sn, vals) { + matrix(vals, nrow = length(ch), ncol = length(sn), dimnames = list(ch, sn)) +} +.cs15_badmat <- function(P, mod) { + m <- .cs15_mk(P$CH, P$SN, c(1, 2, 3, 4, 5, 6, 7, 8)) + switch(mod, + "na" = { m[2L, 1L] <- NA_real_; m }, + "nan" = { m[1L, 2L] <- NaN; m }, + "inf" = { m[4L, 2L] <- Inf; m }, + "neg" = { m[3L, 1L] <- -1; m }, + "noname" = { rownames(m) <- NULL; m }, + "nocol" = { colnames(m) <- NULL; m }, + "nodim" = { dimnames(m) <- NULL; m }, + stop(".cs15_badmat: unknown modification")) +} +.cs15_mch2 <- function(P, alt) { + .cs15_mk(c(alt, P$CH[2L:4L]), P$SN, c(1, 2, 3, 4, 5, 6, 7, 8)) +} +##' -- the accepted-shape rendering (integers, labels and logicals only: +##' D11 posture by construction -- the float-free face of the container) +.cs15_shape <- function(r) { + paste0("nmat=", length(r@matrices), ";names=", + paste0(names(r@matrices), collapse = ","), + ";nrow=", nrow(r@matrices[[1L]]), + ";ncol=", ncol(r@matrices[[1L]]), + ";class=", r@metadata$class, ";version=", r@metadata$version, + ";build=", r@metadata$build, + ";indep=", r@metadata$build_independent, + ";avail=", paste0(r@metadata$availability, collapse = "+"), + ";fmt=", format(r)) +} +##' -- the canonical texts whose dual-kernel checksums ride the scalars +##' witness (byte-stable joins over the frozen plant deparse texts and the +##' spec roster) +.cs15_plant_text <- function() { + per <- vapply(names(.CS15_PLANT), function(nm) + paste0(nm, "=", paste0(.CS15_PLANT[[nm]], collapse = "~")), + character(1L)) + paste0(per, collapse = ";") +} +.cs15_spec_text <- function() paste0(.CS15_SPEC_ARMS, collapse = ";") + +##' -- acceptance arms: what the face RETURNS on planted truth +.cs15_specfire <- function(arm, P) { + switch(arm, + "sp-canonical" = .cs15_try(ms_refdb(list(core = P$M1), P$META)), + "sp-two-matrices" = .cs15_try(ms_refdb(list(core = P$M1, ext = P$M2), + P$META)), + "sp-na-declared" = .cs15_try({ + r <- P$META; r$build <- NA_character_ + r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "sp-availability-zero" = .cs15_try({ + r <- P$META; r$availability <- character(0L) + ms_refdb(list(core = P$M1), r) + }), + "sp-availability-multi" = .cs15_try({ + r <- P$META; r$availability <- c("GRCh38", "GRCh37") + ms_refdb(list(core = P$M1), r) + }), + "sp-integer-matrix" = .cs15_try(ms_refdb(list(core = matrix( + as.integer(seq_len(8L)), 4L, 2L, dimnames = list(P$CH, P$SN))), + P$META)), + "sp-1x1" = .cs15_try(ms_refdb(list(one = matrix(0.7, 1L, 1L, + dimnames = list(P$CH[[1L]], P$SN[[1L]]))), P$META)), + "sp-dup-colnames" = .cs15_try(ms_refdb(list(core = matrix(1, 4L, 2L, + dimnames = list(P$CH, c(P$SN[[1L]], P$SN[[1L]])))), P$META)), + NULL) +} +##' -- the committed detail rendering per acceptance arm (recomputed live; +##' rails and U4 compare against the frozen bytes) +.cs15_detail <- function(arm, P) { + r <- .cs15_specfire(arm, P) + if (inherits(r, "error")) stop(".cs15_detail: acceptance arm refused ", arm) + paste0(.cs15_shape(r$v)) +} + +##' -- law arms: what the face SAYS on planted violations +.cs15_fire <- function(arm, P) { + switch(arm, + "obs-zero-cols-rejected" = .cs15_try(ms_refdb( + list(core = matrix(numeric(0L), 4L, 0L, + dimnames = list(P$CH, character(0L)))), P$META)), + "rej-mat-empty" = .cs15_try(ms_refdb(list(), P$META)), + "rej-mat-notlist" = .cs15_try(ms_refdb(42L, P$META)), + "rej-mat-null" = .cs15_try(ms_refdb(NULL, P$META)), + "rej-mat-unnamed" = .cs15_try(ms_refdb(list(P$M1), P$META)), + "rej-mat-partial-name" = .cs15_try(ms_refdb(list(core = P$M1, P$M2), + P$META)), + "rej-mat-vector" = .cs15_try(ms_refdb(list(core = seq_len(8L)), P$META)), + "rej-mat-character" = .cs15_try(ms_refdb(list(core = matrix("x", 4L, 2L, + dimnames = list(P$CH, P$SN))), P$META)), + "rej-mat-dataframe" = .cs15_try(ms_refdb(list(core = data.frame( + SBS1 = seq_len(4L), SBS5 = seq_len(4L))), P$META)), + "rej-mat-rownames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "noname")), P$META)), + "rej-mat-colnames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "nocol")), P$META)), + "rej-mat-nodimnames" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "nodim")), P$META)), + "rej-mat-na" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "na")), + P$META)), + "rej-mat-nan" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "nan")), + P$META)), + "rej-mat-inf" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, "inf")), + P$META)), + "rej-mat-negative" = .cs15_try(ms_refdb(list(core = .cs15_badmat(P, + "neg")), P$META)), + "rej-channels-disagree" = .cs15_try(ms_refdb(list(core = P$M1, + alt = .cs15_mch2(P, "X[C>X]X")), P$META)), + "rej-channels-subset" = .cs15_try(ms_refdb(list(core = P$M1, + small = .cs15_mk(P$CH[1L:3L], P$SN, seq_len(6L))), P$META)), + "rej-meta-notlist" = .cs15_try(ms_refdb(list(core = P$M1), 42L)), + "rej-meta-unnamed" = .cs15_try({ + r <- P$META; names(r) <- NULL + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-emptyname" = .cs15_try({ + r <- P$META; names(r)[3L] <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-absent-one" = .cs15_try({ + r <- P$META; r$license <- NULL + ms_refdb(list(core = P$M1), r) + }), + "rej-meta-absent-two" = .cs15_try({ + r <- P$META; r$build <- NULL; r$sha256 <- NULL + r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-empty" = .cs15_try({ + r <- P$META; r$version <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-na" = .cs15_try({ + r <- P$META; r$version <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-multi" = .cs15_try({ + r <- P$META; r$version <- c("1", "2") + ms_refdb(list(core = P$M1), r) + }), + "rej-field-version-num" = .cs15_try({ + r <- P$META; r$version <- 1 + ms_refdb(list(core = P$M1), r) + }), + "rej-field-class-empty" = .cs15_try({ + r <- P$META; r$class <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-field-schema-na" = .cs15_try({ + r <- P$META; r$schema_version <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-field-license-multi" = .cs15_try({ + r <- P$META; r$license <- c("CC0-1.0", "CC-BY-4.0") + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-na" = .cs15_try({ + r <- P$META; r$build_independent <- NA + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-num" = .cs15_try({ + r <- P$META; r$build_independent <- 1L + ms_refdb(list(core = P$M1), r) + }), + "rej-indep-str" = .cs15_try({ + r <- P$META; r$build_independent <- "TRUE" + ms_refdb(list(core = P$M1), r) + }), + "rej-build-empty" = .cs15_try({ + r <- P$META; r$build <- "" + ms_refdb(list(core = P$M1), r) + }), + "rej-build-empty-declared" = .cs15_try({ + r <- P$META; r$build <- ""; r$build_independent <- TRUE + ms_refdb(list(core = P$M1), r) + }), + "rej-build-num" = .cs15_try({ + r <- P$META; r$build <- 38L + ms_refdb(list(core = P$M1), r) + }), + "rej-build-multi" = .cs15_try({ + r <- P$META; r$build <- c("GRCh38", "GRCh37") + ms_refdb(list(core = P$M1), r) + }), + "rej-a13-undeclared" = .cs15_try({ + r <- P$META; r$build <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-upper" = .cs15_try({ + r <- P$META; r$sha256 <- paste0(rep_len("A", 64L), collapse = "") + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-short" = .cs15_try({ + r <- P$META; r$sha256 <- substr(P$SHA64, 1L, 63L) + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-nonhex" = .cs15_try({ + r <- P$META; r$sha256 <- paste0(rep_len("g", 64L), collapse = "") + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-num" = .cs15_try({ + r <- P$META; r$sha256 <- 42L + ms_refdb(list(core = P$M1), r) + }), + "rej-sha-na" = .cs15_try({ + r <- P$META; r$sha256 <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-na" = .cs15_try({ + r <- P$META; r$availability <- c("GRCh38", NA_character_) + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-num" = .cs15_try({ + r <- P$META; r$availability <- 38L + ms_refdb(list(core = P$M1), r) + }), + "rej-avail-logical" = .cs15_try({ + r <- P$META; r$availability <- TRUE + ms_refdb(list(core = P$M1), r) + }), + NULL) +} + +##' -- precedence discriminators: which law speaks when two could +.cs15_precfire <- function(arm, P) { + switch(arm, + "prec-first-matrix-authority" = .cs15_try(ms_refdb(list(core = P$M1, + alt = .cs15_mch2(P, "X[C>X]X")), P$META)), + "prec-field-before-a13" = .cs15_try({ + r <- P$META; r$version <- ""; r$build <- NA_character_ + ms_refdb(list(core = P$M1), r) + }), + "prec-matrix-before-metadata" = .cs15_try({ + r <- P$META; r$license <- NULL + ms_refdb(list(core = .cs15_badmat(P, "neg")), r) + }), + "prec-sha-before-availability" = .cs15_try({ + r <- P$META; r$sha256 <- "x"; r$availability <- 38L + ms_refdb(list(core = P$M1), r) + }), + NULL) +} +##' -- the frozen-table row builders (witness shape comes from the tables; +##' the committed TSVs must mirror these byte for byte) +.cs15_lawrows <- function() { + data.frame(arm = .CS15_LAW_ARMS, face = rep("ms_refdb", length(.CS15_LAW_ARMS)), + cls = .CS15_LAW_CLS, mode = .CS15_LAW_MODE, + clause = vapply(.CS15_LAW_ARMS, function(a) .CS15_LAW_CLAUSES[[a]], + character(1L)), + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_specrows <- function() { + data.frame(arm = .CS15_SPEC_ARMS, face = rep("ms_refdb", length(.CS15_SPEC_ARMS)), + cls = .CS15_SPEC_CLS, + detail = vapply(.CS15_SPEC_ARMS, function(a) .CS15_SPEC_DETAILS[[a]], + character(1L)), + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_precrows <- function() { + data.frame(arm = .CS15_PREC_ARMS, fires_cls = .CS15_PREC_FIRES, + fires_anchor = .CS15_PREC_ANCHOR, anti_anchor = .CS15_PREC_ANTI, + stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_degenrows <- function() { + row <- function(k) vapply(.CS15_DEGEN, function(d) d[[k]], character(1L)) + data.frame(edge = row("edge"), arm = row("arm"), cls = row("cls"), + observed = row("observed"), stringsAsFactors = FALSE, check.names = FALSE) +} +.cs15_scalar_kv <- function(sc, k) sc$value[match(k, sc$key)] +## <> (do not hand-edit in place: edit the source and +## re-splice both hosts) +## re-splice both hosts) +## re-splice both hosts) +## re-splice both hosts) +## re-splice both hosts) + +# =========================================================================== +# U1 -- rails: the runner exists and speaks the exported face, never an +# internal (banned-word grep over its full source). +# =========================================================================== +test_that("runner speaks the exported-face rails", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + runner <- file.path(.ms_root, "bench", "scenarios", "run_refdb_witness.R") + expect_true(file.exists(runner)) + src <- paste(readLines(runner, warn = FALSE), collapse = "\n") + for (need in c("--file=", "[attest]", "OVERALL PASS", "ms_refdb(", "cs15_")) { + expect_true(grepl(need, src, fixed = TRUE), info = need) + } + for (ban in c("msuiter:::", ".ms_refdb", "msuiter_refdb_", + "msuiter_validate_", "msuiter_abort", "MsRefDb(", + "expect_", "ms_calibration_grid", "ms_fit_bootstrap", + "ms_calibration_sanity", "run_benchmark", "set.seed", + "sample(", "download.file", "http")) { + expect_false(grepl(ban, src, fixed = TRUE), info = ban) + } +}) + +# =========================================================================== +# U2 -- witness existence and shape: five committed TSVs, non-zero, with +# hard row-count gates and an all-character no-NA census (no vacuous green). +# =========================================================================== +test_that("the five witnesses exist with hard shape gates", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + for (f in c("cs15_specs.tsv", "cs15_laws.tsv", "cs15_precedence.tsv", + "cs15_degenerates.tsv", "cs15_scalars.tsv")) { + expect_true(file.exists(.rs_out15(f))) + expect_gt(file.size(.rs_out15(f)), 0) + } + sp <- .rs_tsv15("cs15_specs.tsv"); lw <- .rs_tsv15("cs15_laws.tsv") + pr <- .rs_tsv15("cs15_precedence.tsv"); dg <- .rs_tsv15("cs15_degenerates.tsv") + sc <- .rs_tsv15("cs15_scalars.tsv") + expect_identical(nrow(sp), 8L) + expect_identical(nrow(lw), 46L) + expect_identical(nrow(pr), 4L) + expect_identical(nrow(dg), 8L) + expect_true("key" %in% names(sc) && "value" %in% names(sc)) + expect_true(all(sc$key %in% .CS15_SCAL_KEYS)) + expect_identical(nrow(sc), length(.CS15_SCAL_KEYS)) + for (df in list(sp, lw, pr, dg, sc)) { + expect_true(all(vapply(df, is.character, logical(1L)))) + expect_false(any(vapply(df, function(cc) any(is.na(cc)), logical(1L)))) + } +}) + +# =========================================================================== +# U3 -- the specs witness mirrors the frozen acceptance table byte for byte. +# =========================================================================== +test_that("committed specs mirror the frozen table", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + sp <- .rs_tsv15("cs15_specs.tsv"); fr <- .cs15_specrows() + expect_identical(sp$arm, fr$arm) + expect_identical(sp$face, fr$face) + expect_identical(sp$cls, fr$cls) + expect_identical(sp$detail, fr$detail) +}) + +# =========================================================================== +# U4 -- live replay of the acceptance arms: the shipped face still RETURNS +# exactly what the witness committed (class token + accepted-shape rendering). +# =========================================================================== +test_that("acceptance arms replay live through the face", { + P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-law-plants")) + fr <- .cs15_specrows() + for (i in seq_len(nrow(fr))) { + arm <- fr$arm[i] + r <- .cs15_specfire(arm, P) + expect_false(inherits(r, "error"), info = arm) + expect_identical(.cs15_cls(r), fr$cls[i], info = arm) + expect_identical(.cs15_detail(arm, P), fr$detail[i], info = arm) + } +}) + +# =========================================================================== +# U5 -- the laws witness mirrors the frozen law table: 46 arms, classes, +# adjudication modes, verbatim clauses. +# =========================================================================== +test_that("committed laws mirror the frozen law table", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + lw <- .rs_tsv15("cs15_laws.tsv"); fr <- .cs15_lawrows() + expect_identical(lw$arm, fr$arm) + expect_identical(lw$face, fr$face) + expect_identical(lw$cls, fr$cls) + expect_identical(lw$mode, fr$mode) + expect_identical(lw$clause, fr$clause) +}) + +# =========================================================================== +# U6 -- live replay of the law arms: each fires its committed class, and its +# committed clause rides the live message verbatim (every clause is +# byte-stable: the face is pure R and the ledger was DET-proved). +# =========================================================================== +test_that("law arms replay live with their committed verdicts", { + P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-law-plants")) + fr <- .cs15_lawrows() + for (i in seq_len(nrow(fr))) { + arm <- fr$arm[i] + r <- .cs15_fire(arm, P) + expect_true(inherits(r, "error"), info = arm) + expect_identical(.cs15_cls(r), fr$cls[i], info = arm) + msg <- .cs15_msg(r) + if (identical(fr$mode[i], "full")) { + expect_identical(msg, fr$clause[i], info = arm) + } else { + for (bl in strsplit(fr$clause[i], " | ", fixed = TRUE)[[1L]]) { + expect_true(grepl(bl, msg, fixed = TRUE), info = paste0(arm, " :: ", bl)) + } + } + } +}) + +# =========================================================================== +# U7 -- precedence discriminators: the RIGHT law speaks when two could. +# =========================================================================== +test_that("precedence discriminators speak the right law", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-law-plants")) + pr <- .cs15_precrows() + cw <- .rs_tsv15("cs15_precedence.tsv") + expect_identical(cw$arm, pr$arm) + expect_identical(cw$fires_cls, pr$fires_cls) + expect_identical(cw$fires_anchor, pr$fires_anchor) + expect_identical(cw$anti_anchor, pr$anti_anchor) + for (i in seq_len(nrow(pr))) { + r <- .cs15_precfire(pr$arm[i], P) + expect_true(inherits(r, "error"), info = pr$arm[i]) + expect_identical(.cs15_cls(r), pr$fires_cls[i], info = pr$arm[i]) + msg <- .cs15_msg(r) + expect_true(grepl(pr$fires_anchor[i], msg, fixed = TRUE), info = pr$arm[i]) + expect_false(grepl(pr$anti_anchor[i], msg, fixed = TRUE), info = pr$arm[i]) + } +}) + +# =========================================================================== +# U8 -- degenerate boundaries: the asymmetry pairs the face draws on its own +# (declared vs undeclared NA build, zero-length vs NA availability, duplicate +# vs absent colnames, 1x1 vs zero-column matrix space). +# =========================================================================== +test_that("degenerate boundaries hold their committed sides", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-law-plants")) + dg <- .rs_tsv15("cs15_degenerates.tsv"); fr <- .cs15_degenrows() + expect_identical(dg$edge, fr$edge) + expect_identical(dg$arm, fr$arm) + expect_identical(dg$cls, fr$cls) + expect_identical(dg$observed, fr$observed) + for (i in seq_len(nrow(fr))) { + arm <- fr$arm[i] + if (identical(fr$cls[i], "accept")) { + r <- .cs15_specfire(arm, P) + expect_false(inherits(r, "error"), info = arm) + expect_identical(.cs15_detail(arm, P), fr$observed[i], info = arm) + } else { + r <- .cs15_fire(arm, P) + expect_true(inherits(r, "error"), info = arm) + expect_true(grepl(fr$observed[i], .cs15_msg(r), fixed = TRUE), info = arm) + } + } +}) + +# =========================================================================== +# U9 -- plant checksum: every frozen plant byte re-hashes identically under +# BOTH governed SHA-256 kernels, and the scalars witness carries that +# checksum. The reconstruction round (parse/eval of the frozen deparse text) +# is exercised LIVE by U4/U6 through the face itself. +# =========================================================================== +test_that("plant bytes re-hash under both governed kernels", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + bytes <- charToRaw(.cs15_plant_text()) + hA <- .ms_fit_sha256(bytes) + hB <- digest::digest(bytes, algo = "sha256", serialize = FALSE) + expect_identical(hA, hB) + expect_match(hA, "^[0-9a-f]{64}$") + sc <- .rs_tsv15("cs15_scalars.tsv") + expect_identical(.cs15_scalar_kv(sc, "plant-checksum"), hA) + sbytes <- charToRaw(.cs15_spec_text()) + expect_identical(.cs15_scalar_kv(sc, "spec-checksum"), + .ms_fit_sha256(sbytes)) +}) + +# =========================================================================== +# U10 -- scalars: the bytes the face speaks verbatim (cross-checked LIVE +# through its own clauses) and the silent RNG rails. +# =========================================================================== +test_that("scalars speak face bytes and RNG rails", { + if (is.na(.ms_root)) skip("repository checkout not locatable (R CMD check context)") + P <- .cs15_plants(file.path(tempdir(TRUE), "cs15-law-plants")) + sc <- .rs_tsv15("cs15_scalars.tsv") + for (s in .CS15_SCAL_SOURCE) { + msg <- .cs15_msg(.cs15_fire(s$from_arm, P)) + seg <- strsplit(msg, " | ", fixed = TRUE)[[1L]][s$seg] + froz <- strsplit(.CS15_LAW_CLAUSES[[s$from_arm]], " | ", fixed = TRUE)[[1L]][s$seg] + expect_identical(.cs15_scalar_kv(sc, s$key), seg, info = s$key) + expect_identical(seg, froz, info = s$key) + } + expect_identical(.cs15_scalar_kv(sc, "rng-before"), "FALSE") + expect_identical(.cs15_scalar_kv(sc, "rng-after"), "FALSE") +}) diff --git a/tools/ci/pr-gate-budget.tsv b/tools/ci/pr-gate-budget.tsv index 70566a6..4bf34d4 100644 --- a/tools/ci/pr-gate-budget.tsv +++ b/tools/ci/pr-gate-budget.tsv @@ -66,6 +66,11 @@ # the T0 roster; witness: local run nb=1704 failed=0 error=0 warning=0, measured # manifest sum 623 (generator refusal witnessed at the pre-seal re-mint # attempt, the verbatim DEFECT line naming 623 against the sealed 622). +# 2026-11-23 deliberate re-seal 623 -> 624: the CS-15 scenario row +# (test-scenario-refdb-witness.R, 1 s integer weight, 273 expects) joined +# the T0 roster; witness: local run nb=273 failed=0 error=0 warning=0, measured +# manifest sum 624 (generator refusal witnessed at the pre-seal re-mint +# attempt, the verbatim DEFECT line naming 624 against the sealed 623). key value note -t0-measured 623 measured 2026-11-23 (integer manifest seconds, tier T0; 2026-11-23 seal 622 superseded by the CS-14 row) +t0-measured 624 measured 2026-11-23 (integer manifest seconds, tier T0; 2026-11-23 seal 623 superseded by the CS-15 row) t0-ceiling 800 t0-measured + one drift class; re-seal deliberately with a witness diff --git a/tools/ci/shard-manifest.tsv b/tools/ci/shard-manifest.tsv index 855ab16..a89791c 100644 --- a/tools/ci/shard-manifest.tsv +++ b/tools/ci/shard-manifest.tsv @@ -3,96 +3,97 @@ shard file seconds tier 1 test-check-layout-sim-sentry.R 1250 T2 2 test-check-layout-sim-stale.R 1231 T2 3 test-xval-m2-extract.R 948 T1 +4 test-calibrate.R 0 T0 +4 test-capability-matrix-truth.R 0 T0 4 test-catalog-currency.R 1 T0 +4 test-catalog-tally.R 0 T0 +4 test-channels-reference.R 0 T0 +4 test-channels-structure.R 0 T0 +4 test-channels-sync.R 0 T0 +4 test-check-layout-sim-gen.R 0 T0 +4 test-check-layout-sim-sdkroot.R 0 T0 +4 test-classes-benchmark.R 0 T0 +4 test-classes-catalog.R 0 T0 +4 test-classes-engines.R 0 T0 +4 test-classes-fit.R 0 T0 +4 test-classes-refdb.R 0 T0 +4 test-classes-roundtrip.R 0 T0 +4 test-classes-signature.R 0 T0 +4 test-classes-utils.R 0 T0 +4 test-classes-variants.R 0 T0 4 test-docs-get-started.R 7 T0 4 test-docs-scenarios-prose.R 1 T0 +4 test-docs-sync.R 0 T0 +4 test-engines-registry.R 0 T0 +4 test-extend-contract.R 0 T0 +4 test-ffi-probes.R 0 T0 +4 test-ffi-surface-drift.R 0 T0 +4 test-ffi-tally.R 0 T0 4 test-fit-bootstrap.R 3 T0 +4 test-fit.R 0 T0 +4 test-gitignore-hygiene.R 0 T0 +4 test-hrd-reference.R 0 T0 +4 test-hrd-report.R 0 T0 +4 test-io-segments.R 0 T0 +4 test-io-sv.R 0 T0 +4 test-io-variants.R 0 T0 +4 test-islam-xval.R 0 T0 4 test-kernel-bit-identity.R 79 T0 +4 test-kernel-cli.R 0 T0 +4 test-kernel-gate-evidence.R 0 T0 +4 test-kernel-pipeline-batch.R 0 T0 +4 test-kernel-pipeline-parse.R 0 T0 +4 test-kernel-pipeline-status.R 0 T0 +4 test-ms-cluster.R 0 T0 +4 test-ms-convert.R 0 T0 +4 test-ms-exposure-test.R 0 T0 +4 test-ms-simulate.R 0 T0 +4 test-pkgdown-citation.R 0 T0 4 test-pkgdown-coherence.R 1 T0 +4 test-pkgdown-reference-map.R 0 T0 +4 test-r-floor-ops.R 0 T0 4 test-refdb.R 373 T1 +4 test-release-materials.R 0 T0 +4 test-reproduce-link.R 0 T0 +4 test-rng-hygiene.R 0 T0 4 test-scenario-cluster-witness.R 1 T0 4 test-scenario-exposure-witness.R 1 T0 -4 test-scenario-hrd.R 0 T0 +4 test-scenario-hrd-baselines.R 0 T0 4 test-scenario-reconstruction.R 1 T0 -4 test-scenario-stratify.R 1 T0 +4 test-scenario-sparse-spec-witness.R 1 T0 4 test-site-deploy-bundle.R 3 T0 +4 test-sitrep.R 0 T0 +4 test-stratify.R 0 T0 +4 test-vendor-gate-law.R 0 T0 4 test-viz-batch2.R 2 T0 +4 test-viz-bootstrap.R 0 T0 4 test-viz-first-batch.R 11 T0 +4 test-viz-kselect.R 0 T0 4 test-xval-sigminer.R 10 T0 5 test-calibrate-real.R 1 T0 -5 test-calibrate.R 0 T0 -5 test-capability-matrix-truth.R 0 T0 -5 test-catalog-tally.R 0 T0 -5 test-channels-reference.R 0 T0 -5 test-channels-structure.R 0 T0 -5 test-channels-sync.R 0 T0 -5 test-check-layout-sim-gen.R 0 T0 -5 test-check-layout-sim-sdkroot.R 0 T0 5 test-check-layout-sim.R 15 T0 -5 test-classes-benchmark.R 0 T0 -5 test-classes-catalog.R 0 T0 -5 test-classes-engines.R 0 T0 -5 test-classes-fit.R 0 T0 -5 test-classes-refdb.R 0 T0 -5 test-classes-roundtrip.R 0 T0 -5 test-classes-signature.R 0 T0 -5 test-classes-utils.R 0 T0 -5 test-classes-variants.R 0 T0 5 test-docs-extending-surface.R 1 T0 -5 test-docs-sync.R 0 T0 5 test-docs-tour-executable.R 10 T0 -5 test-engines-registry.R 0 T0 -5 test-extend-contract.R 0 T0 5 test-extract.R 16 T0 -5 test-ffi-probes.R 0 T0 -5 test-ffi-surface-drift.R 0 T0 -5 test-ffi-tally.R 0 T0 -5 test-fit.R 0 T0 -5 test-gitignore-hygiene.R 0 T0 -5 test-hrd-independent.R 0 T0 -5 test-hrd-reference.R 0 T0 -5 test-hrd-report.R 0 T0 -5 test-io-segments.R 0 T0 -5 test-io-sv.R 0 T0 -5 test-io-variants.R 0 T0 -5 test-islam-xval.R 0 T0 -5 test-kernel-cli.R 0 T0 -5 test-kernel-gate-evidence.R 0 T0 -5 test-kernel-pipeline-batch.R 0 T0 5 test-kernel-pipeline-farm.R 5 T0 -5 test-kernel-pipeline-parse.R 0 T0 -5 test-kernel-pipeline-status.R 0 T0 5 test-kernel-trace-shape.R 1 T0 -5 test-ms-cluster.R 0 T0 5 test-ms-compare.R 9 T0 -5 test-ms-convert.R 0 T0 5 test-ms-downsample-io.R 36 T0 5 test-ms-embed.R 2 T0 -5 test-ms-exposure-test.R 0 T0 5 test-ms-qc-report.R 112 T0 5 test-ms-qc-sentries.R 280 T1 -5 test-ms-simulate.R 0 T0 -5 test-pkgdown-citation.R 0 T0 -5 test-pkgdown-reference-map.R 0 T0 -5 test-r-floor-ops.R 0 T0 -5 test-release-materials.R 0 T0 -5 test-reproduce-link.R 0 T0 -5 test-rng-hygiene.R 0 T0 5 test-scenario-atlas.R 2 T0 5 test-scenario-calibration-verdict.R 1 T0 5 test-scenario-downsample.R 1 T0 -5 test-scenario-hrd-baselines.R 0 T0 +5 test-scenario-hrd.R 0 T0 5 test-scenario-qc-artifacts.R 1 T0 -5 test-scenario-sparse-spec-witness.R 1 T0 -5 test-sitrep.R 0 T0 -5 test-stratify.R 0 T0 -5 test-vendor-gate-law.R 0 T0 -5 test-viz-bootstrap.R 0 T0 -5 test-viz-kselect.R 0 T0 +5 test-scenario-segments-witness.R 1 T0 +5 test-scenarios-gallery.R 1 T0 6 test-calibrate-plot.R 1 T0 6 test-ci-shard-map.R 8 T0 6 test-cjk-census.R 9 T0 6 test-docs-bridge.R 1 T0 +6 test-hrd-independent.R 0 T0 6 test-kernel-attest-route.R 1 T0 6 test-kernel-batch-bridge.R 172 T0 6 test-kselect.R 28 T0 @@ -103,7 +104,7 @@ shard file seconds tier 6 test-pkgdown-msu-map.R 1 T0 6 test-scenario-currency-witness.R 1 T0 6 test-scenario-io-interop-witness.R 1 T0 -6 test-scenario-segments-witness.R 1 T0 -6 test-scenarios-gallery.R 1 T0 +6 test-scenario-refdb-witness.R 1 T0 +6 test-scenario-stratify.R 1 T0 6 test-site-claim-gate.R 42 T0 6 test-treatment-report.R 13 T0 diff --git a/tools/ci/shard-weights.tsv b/tools/ci/shard-weights.tsv index 08175d0..f94691e 100644 --- a/tools/ci/shard-weights.tsv +++ b/tools/ci/shard-weights.tsv @@ -121,3 +121,4 @@ test-scenario-calibration-verdict.R 1 248 T0 test-scenario-io-interop-witness.R 1 254 T0 test-scenario-sparse-spec-witness.R 1 323 T0 test-scenario-segments-witness.R 1 1704 T0 +test-scenario-refdb-witness.R 1 273 T0 diff --git a/vignettes/articles/devlog-2026-11-23-p3-cs15-refdb-witness.qmd b/vignettes/articles/devlog-2026-11-23-p3-cs15-refdb-witness.qmd new file mode 100644 index 0000000..dc72678 --- /dev/null +++ b/vignettes/articles/devlog-2026-11-23-p3-cs15-refdb-witness.qmd @@ -0,0 +1,102 @@ +--- +title: "P3-CS-15 refdb-witness: the shipped reference-container face adjudicated over planted R objects" +format: html-vignette +--- + +## Decision record: what the container face promises, and what its receipts look like + +::: {.callout .callout-note} +**Decision.** CS-15 is a witness, not a specification: it freezes what the +exported `ms_refdb()` factory actually adjudicates over planted R objects, +so future drift speaks immediately. It commits only machine-stable facts: +the error CLASS always, and the message CLAUSES verbatim -- every one of +them. The face is pure R with no path, clock or locale in its output, so +the ledger was DET-proved byte-stable across probe reruns and no arm +needed the `stable3` bullet-subset posture that CS-13/CS-14 required for +their file paths. +::: + +### The face + +`ms_refdb(matrices, metadata)` is the exported governance container for +reference signature matrices: an S7 class with TWO admission gates -- the +property gates (non-list `matrices`/`metadata` die as `simpleError` +before any validator runs) and the container validator (43 distinct +`msuiter_error_refdb` laws). CS-15 fires 58 observation arms at it over +six frozen deparse-text plants (two 4x2 channel matrices, the eight-field +governance metadata, the channel and sample labels, a 64-hex digest): +46 law arms, 8 acceptance specs, 4 precedence discriminators, 4 degenerate +boundary pairs (8 rows), 8 scalars. The committed lane replays every arm +live: the law file adjudicates 273 expectations across 10 units +(0 failed, 0 errors, 0 warnings, 0 skipped) and the runner passes +188 rails before any witness byte is written. + +### The laws the face demonstrates + +- **Admission shape.** Empty, unnamed, partly-named or non-list containers + are refused by name; vectors, character and data.frame payloads are + refused as "not a numeric matrix" -- the container holds numeric + matrices only (integer ones ride, `is.numeric` accepts them). +- **The label-key law.** Every matrix must carry BOTH rownames and + colnames: "labels are the only legal matching key (never position)". + The zero-column observation is its sharpest witness -- a matrix with a + row-name vector but an empty column roster is refused exactly there. +- **Finite, non-negative cells.** NA, NaN and Inf are refused with the + clause "the FFI contract rejects NA"; negative cells are refused as + "non-negative by definition", each with the offending cell printed. +- **Channel authority.** All matrices are projected onto the FIRST + matrix's channel labels -- the disagreement report names the offender + against the first matrix's space ("matrix 'alt' disagrees; offending + labels: 'X[C>X]X'"), and the precedence arm proves the second matrix is + never mistaken for the authority. +- **Governance metadata.** The eight required fields are rostered + verbatim ("version, class, build, schema_version, sha256, license, + build_independent, availability"); the four identity fields demand a + single non-empty string; `build_independent` demands a bare TRUE/FALSE + (an integer or string is refused); `build` is a single string or NA; + and the **A13 cross-field clause** welds them: "an NA build must be + declared via build_independent = TRUE" -- the declared NA build is + accepted, the undeclared one is refused. +- **The digest policy.** `sha256` must match `^[0-9a-f]{64}$` -- + uppercase hex is REFUSED, a deliberate lowercase-only commitment so the + same bytes hash identically on every platform. +- **Availability.** A character vector without NA entries; the zero-length + vector is legal (no availability claim), a vector containing NA is not. + +### The receipts + +| receipt | committed bytes | +|---|---| +| `cs15_specs.tsv` | 8 accepted arms: the class token `msuiter::MsRefDb` plus the shape rendering (names, dims, governance fields, the format method's own line) | +| `cs15_laws.tsv` | 46 arms: class census MEASURED 43 validator + 3 property-gate `simpleError`, every clause verbatim, every mode `full` | +| `cs15_precedence.tsv` | 4 discriminators: first-matrix authority, field-before-A13, matrix-before-metadata, sha-before-availability -- each with its fires anchor AND anti anchor | +| `cs15_degenerates.tsv` | 4 asymmetry pairs (8 rows): declared vs undeclared NA build, zero-length vs NA availability, duplicate vs absent colnames, 1x1 vs zero-column space | +| `cs15_scalars.tsv` | 8 keys: four face-spoken clauses (governance roster, label-key law, FFI no-NA, A13 digest pin), the dual-kernel plant and spec SHA-256s, both RNG rails | + +All five witnesses byte-reproduce on a re-run (DET 5/5), the plant and +spec checksums agree under BOTH governed SHA-256 kernels, and the lane +never touches the RNG, the network, the benchmark driver, the declined +calibration family, or any unexported internal (banned-word rails, +grepped). + +### What the lane-building itself caught (the honest section) + +The live replay is not decoration -- it caught three real defects before +any witness was trusted: (1) the plant reconstruction `eval(parse(x))[[1L]]` +indexes the RESULT, not the PARSED EXPRESSION -- a list plant silently +became its first element, and the rails screamed before the mint; +(2) a top-level `on.exit(close(con))` in the injector never fires on this +base, so the parse-verification read a half-written host file; (3) a +misplaced FUN.VALUE argument in the plant-text joiner. All three died in +the rails, not in the record. The gallery roster had also drifted twice +(CS-13/CS-14 never updated the driver count or the reproduction list): +this commit repairs it to fifteen drivers with the full list. The T0 seal +moved 623 -> 624 with the generator's refusal witnessed verbatim before +the deliberate re-seal, per the budget law. + +### Provenance + +The frozen block and the shared code block in both hosts are minted +mechanically from the probe ledger; neither is ever hand-edited. The +plants' canonical deparse texts hash to the committed dual-kernel +checksum; reifying the lane reproduces every witness byte for byte. diff --git a/vignettes/articles/paper-draft.qmd b/vignettes/articles/paper-draft.qmd index 718b104..269c65a 100644 --- a/vignettes/articles/paper-draft.qmd +++ b/vignettes/articles/paper-draft.qmd @@ -530,7 +530,7 @@ format-conformance claim. Zero new machinery. Authority: vignettes/articles/devlog-2026-11-22-p3-cs13-io-interop-witness.qmd. - **CS-14 segments-witness, decision record** (`bench/scenarios/run_segments_witness.R`, -#124): the shipped segment face `ms_segments()` -- the exported mutation- +#125): the shipped segment face `ms_segments()` -- the exported mutation- catalogue importer for the eight caller ecosystems plus the in-memory `synthetic` contract -- adjudicated over 34 binary-channel-planted TSV/TXT/GZ witnesses (60 adjudications: 41 law arms, 17 acceptance specs, 4 precedence @@ -554,6 +554,26 @@ face's contract behavior on planted truth -- no extraction, benchmark or caller-conformance claim. Zero new machinery. Authority: vignettes/articles/devlog-2026-11-23-p3-cs14-segments-witness.qmd. +- **CS-15 refdb-witness, decision record** (`bench/scenarios/run_refdb_witness.R`): +the shipped reference-container factory `ms_refdb()` -- the governance gate +for reference signature matrices and their eight-field metadata -- +adjudicated over six frozen deparse-text plants. The double-gate split is +committed as measured (43 validator arms speak `msuiter_error_refdb`, the +3 property-gate arms die as `simpleError` before any validator runs); the +label-key law ("labels are the only legal matching key (never position)") +with its zero-column sharpest witness; the finite-cell ban carrying the +FFI no-NA clause; the first-matrix channel authority blaming offenders +against the first matrix's space and never mistaking the second for the +authority; the A13 cross-field clause (an NA build is legal ONLY together +with a declared build_independent = TRUE); the lowercase-only digest +policy refusing uppercase hex; four precedence discriminators each pinned +fires-anchor-present/anti-anchor-absent; four degenerate boundary pairs +(273 expectations across 10 units, rerun byte-identical 5/5, zero +failures/errors/warnings/skips). Decision-record posture: the factory's +contract behavior on planted truth -- no extraction, benchmark or +reference-content claim. Zero new machinery. Authority: +vignettes/articles/devlog-2026-11-23-p3-cs15-refdb-witness.qmd. + [FILLED — three-in-one selection] Of the three editor-offered paths that turn the case studies from decorative to forceful (vignettes/articles/review-05-nature-editor.qmd §5: (a) a treatment-history cohort with real treatment-record concordance; (b) an @@ -757,7 +777,7 @@ the reference database reaches users through the governed mirror path only | Fig. 2 | Architecture block diagram (two-tier core, FFI shell, kernel CLI boundary) | to be drawn from vignettes/articles/architecture.qmd §2 by the controller's illustrator; DRY law: no new claims | | Fig. 3 | Table 1 as a visual verdict board (MEASURED-false rows shown as such) | data FILLED §3.3 | | Fig. 4 | O5 census heat strip (8 faces x 21 classes = 168 cells, color=cpu-ratio) | data FILLED §3.3 Table 2 (log banked) | -| Fig. 5 | Scenario adjudication panels (CS-1 atlas, CS-2 dual-oracle, CS-3 treatment, CS-4 artifact forensics, CS-5 stratification decision, CS-6 downsample frontier, CS-7 reconstruction witness, CS-8 cluster witness, CS-9 currency witness, CS-10 exposure witness, CS-11 calibration witness, CS-12 sparse-spec witness, CS-13 io-interop witness, CS-14 segments-witness) | data FILLED §3.4, outputs bench/scenarios/out/* | +| Fig. 5 | Scenario adjudication panels (CS-1 atlas, CS-2 dual-oracle, CS-3 treatment, CS-4 artifact forensics, CS-5 stratification decision, CS-6 downsample frontier, CS-7 reconstruction witness, CS-8 cluster witness, CS-9 currency witness, CS-10 exposure witness, CS-11 calibration witness, CS-12 sparse-spec witness, CS-13 io-interop witness, CS-14 segments-witness, CS-15 refdb-witness) | data FILLED §3.4, outputs bench/scenarios/out/* | | Suppl. | Calibration curves 198-cell; reproduction protocol; law-family inventories | committed faces cited §4.5, §3.5 | ## 9. Bibliography diff --git a/vignettes/docs-bridge.Rmd b/vignettes/docs-bridge.Rmd index 50781b4..afc4bc6 100644 --- a/vignettes/docs-bridge.Rmd +++ b/vignettes/docs-bridge.Rmd @@ -165,3 +165,4 @@ guides), start at [Get started](get-started.html) and the [tour](tour.html). | [CS-12 sparse-spec-witness — the shipped engine-spec factory adjudicated over planted scalar plants: the degenerate-default headline, the loop-before-law validator precedence, the double-gate NA split, and the measured integer windows (reified, paper-grade)](devlog-2026-11-22-p3-cs12-sparse-spec-witness.html) | `devlog-2026-11-22-p3-cs12-sparse-spec-witness` | | [CS-13 io-interop-witness — the shipped import/export face adjudicated over planted TSV plants: the WTSI deferral clause, the reader-coercion law split, the locked provenance pair, and the 17-significant-digit round-trip drill (reified, paper-grade)](devlog-2026-11-22-p3-cs13-io-interop-witness.html) | `devlog-2026-11-22-p3-cs13-io-interop-witness` | | [CS-14 segments-witness — the shipped segment face adjudicated over planted TSV bytes: the caller-routed column law, the declared-role law, the mutation_type legality law, the Battenberg block law, the Sequenza sum law, and four precedence discriminators (reified, paper-grade)](devlog-2026-11-23-p3-cs14-segments-witness.html) | `devlog-2026-11-23-p3-cs14-segments-witness` | +| [CS-15 refdb-witness — the shipped reference-container factory adjudicated over planted R objects: the label-key law, the FFI no-NA ban, the first-matrix channel authority, the A13 cross-field clause, the lowercase-only digest policy, and four precedence discriminators (reified, paper-grade)](devlog-2026-11-23-p3-cs15-refdb-witness.html) | `devlog-2026-11-23-p3-cs15-refdb-witness` | diff --git a/vignettes/scenarios.Rmd b/vignettes/scenarios.Rmd index bb6fe90..84a7d93 100644 --- a/vignettes/scenarios.Rmd +++ b/vignettes/scenarios.Rmd @@ -43,12 +43,14 @@ knitr::opts_chunk$set(collapse = TRUE, comment = "#>") msuiter's paper pillar 3 is the application-scenario layer: end-to-end workflows that adjudicate against planted truth or an independent oracle and -persist their evidence tables. The twelve executable drivers live under +persist their evidence tables. The fifteen executable drivers live under `bench/scenarios/` (`run_atlas.R`, `run_hrd.R`, `run_treatment.R`, `run_qc_artifacts.R`, `run_stratify.R`, `run_downsample.R`, `run_reconstruction.R`, `run_cluster_witness.R`, `run_currency_witness.R`, `run_exposure_witness.R`, -`run_calibration_verdict.R`, `run_sparse_spec_witness.R`; committed +`run_calibration_verdict.R`, `run_sparse_spec_witness.R`, +`run_io_interop_witness.R`, `run_segments_witness.R`, +`run_refdb_witness.R`; committed evidence under `bench/scenarios/out/`, each driver ends in its own OVERALL PASS or OVERALL FAIL verdict line). This page runs one reduced, runnable snippet of each against the same committed fixture generators the @@ -848,6 +850,75 @@ contract on the exported surface and the declined-scope rails -- are the manual pages (`?ms_segments`) and the scenario devlog under `vignettes/articles/devlog-*-p3-cs14-*.qmd`. +## The reference-container face as a governed witness + +The fourteenth scenario adjudicates the EXPORTED `ms_refdb()` factory -- +the governance container that admits reference signature matrices and their +metadata -- over synthetic R plants: the container admission laws (named +non-empty lists, numeric matrices, the label-key dimnames law, the +NA/non-finite ban, non-negativity, first-matrix channel authority), the +governance-metadata laws (the required-field roster, the four +single-string fields, the build_independent bool, the build string-or-NA +law, the A13 cross-field clause, the lowercase sha256 policy, the +availability no-NA law), the double-gate split between the property gates +and the container validator, four precedence discriminators and four +degenerate boundary pairs. + +```{r refdb-witness, message = FALSE} +out <- file.path(PKG, "bench", "scenarios", "out") +if (dir.exists(out)) { + rd <- function(f) read.table(file.path(out, f), header = TRUE, sep = "\t", + quote = "", colClasses = "character", + na.strings = "", stringsAsFactors = FALSE) + lw <- rd("cs15_laws.tsv"); sp <- rd("cs15_specs.tsv") + pc <- rd("cs15_precedence.tsv"); dg <- rd("cs15_degenerates.tsv") + sc <- rd("cs15_scalars.tsv") + sv <- setNames(as.character(sc$value), as.character(sc$key)) + cnt <- tabulate(match(lw$cls, c("msuiter_error_refdb", "simpleError"))) + split_ok <- identical(as.integer(cnt), c(43L, 3L)) && nrow(lw) == 46L + roster_ok <- grepl("build_independent", sv[["governance-fields"]], + fixed = TRUE) && + grepl("sha256", sv[["governance-fields"]], fixed = TRUE) && + grepl("only legal matching key", sv[["label-key-law"]], fixed = TRUE) && + grepl("FFI contract rejects NA", sv[["ffi-no-na-clause"]], fixed = TRUE) && + grepl("A13 manifest", sv[["sha-pin-clause"]], fixed = TRUE) + pr <- pc[pc$arm == "prec-sha-before-availability", ] + shac <- lw$clause[lw$arm == "rej-sha-upper"] + prec_ok <- nrow(pc) == 4L && length(shac) == 1L && + grepl(pr$fires_anchor, shac, fixed = TRUE) && + !grepl(pr$anti_anchor, shac, fixed = TRUE) + dg_ok <- nrow(dg) == 8L && + sum(dg$cls == "accept") == 4L && + grepl("build=NA;indep=TRUE", + dg$observed[dg$arm == "sp-na-declared"], fixed = TRUE) + canon <- sp$detail[sp$arm == "sp-canonical"] + dup <- sp$detail[sp$arm == "sp-dup-colnames"] + spec_ok <- nrow(sp) == 8L && length(canon) == 1L && length(dup) == 1L && + grepl("class: SBS | version: 1", canon, fixed = TRUE) && + grepl("ncol=2", dup, fixed = TRUE) + rng_ok <- identical(sv[["rng-before"]], "FALSE") && + identical(sv[["rng-after"]], "FALSE") && + nchar(sv[["plant-checksum"]]) == 64L && + nchar(sv[["spec-checksum"]]) == 64L + cat("the 46-arm class census splits 43/3 between the validator and the", + "property gates exactly as committed:", split_ok, + "| the governance roster, label-key, FFI and A13 clauses speak", + "verbatim:", roster_ok, "\n") + cat("the precedence pair cannot trade clauses:", prec_ok, + "| the four degenerate pairs stand (4 accepted, 4 refused):", dg_ok, + "| the canonical rendering and the duplicate-column carry hold:", + spec_ok, "| the process is RNG-free and the plants carry a 64-hex", + "dual-kernel checksum:", rng_ok, "\n") +} +``` + +The committed tables for this leg: `bench/scenarios/out/cs15_specs.tsv`, +`cs15_laws.tsv`, `cs15_precedence.tsv`, `cs15_degenerates.tsv` and +`cs15_scalars.tsv`. The certified backing -- the factory's documented +contract on the exported surface and the declined-scope rails -- are the +manual pages (`?ms_refdb`) and the scenario devlog under +`vignettes/articles/devlog-*-p3-cs15-*.qmd`. + ## Reproducing the full verdicts Each driver prints its own adjudication lines and exits zero only on @@ -867,4 +938,6 @@ Rscript bench/scenarios/run_exposure_witness.R Rscript bench/scenarios/run_calibration_verdict.R Rscript bench/scenarios/run_sparse_spec_witness.R Rscript bench/scenarios/run_io_interop_witness.R +Rscript bench/scenarios/run_segments_witness.R +Rscript bench/scenarios/run_refdb_witness.R ```