diff --git a/_pkgdown.yml b/_pkgdown.yml index 96a131b..664bbcf 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -341,3 +341,4 @@ articles: - articles/devlog-2026-11-23-p3-cs15-refdb-witness - articles/devlog-2026-11-23-p3-cs16-ard-witness - articles/devlog-2026-11-23-p3-cs17-catalog-witness + - articles/devlog-2026-11-25-p3-cs18-convert-witness diff --git a/bench/scenarios/out/cs18_degenerates.tsv b/bench/scenarios/out/cs18_degenerates.tsv new file mode 100644 index 0000000..5010162 --- /dev/null +++ b/bench/scenarios/out/cs18_degenerates.tsv @@ -0,0 +1,9 @@ +pair side arm mode cls msg +zero-column-glyph hi zero-col-hi accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,0,1 +zero-column-glyph lo full-col-lo accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +onecol-vs-multicol hi onecol-matrix-hi accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +onecol-vs-multicol lo multicol-matrix-lo reject msuiter_error_input from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities +fromopt-vs-toopt hi from-bad-hi reject msuiter_error_option from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities +fromopt-vs-toopt lo to-bad-lo reject msuiter_error_option to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nada'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities +shape-vs-names hi nonmatrix-hi reject msuiter_error_input signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature) +shape-vs-names lo wrongnames-lo reject msuiter_error_input from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'Y1', 'Y2', 'Y3' | set names(opps) to the registry labels diff --git a/bench/scenarios/out/cs18_laws.tsv b/bench/scenarios/out/cs18_laws.tsv new file mode 100644 index 0000000..e3689fa --- /dev/null +++ b/bench/scenarios/out/cs18_laws.tsv @@ -0,0 +1,11 @@ +arm mode cls msg +L1-unknown-from reject msuiter_error_option from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities +L2-unknown-to reject msuiter_error_option to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities +L3-multicol-matrix reject msuiter_error_input from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities +L4-wrong-length reject msuiter_error_input from must be a frequency vector over the 96 channels | an opportunity vector is one frequency per registry channel | received length: 10 | name it by the registry labels or pass a bundled table name +L5-names-mismatch reject msuiter_error_input from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'X1', 'X2', 'X3' | set names(opps) to the registry labels +L6-nonpositive reject msuiter_error_input from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies +L7-nonfinite reject msuiter_error_input from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies +L8-nonmatrix reject msuiter_error_input signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature) +L9-wrong-rownames reject msuiter_error_input signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | first rownames: 'R1', 'R2', 'R3' | order the matrix by the registry labels +L10-no-rownames reject msuiter_error_input signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | rownames missing | order the matrix by the registry labels diff --git a/bench/scenarios/out/cs18_precedence.tsv b/bench/scenarios/out/cs18_precedence.tsv new file mode 100644 index 0000000..b6987d5 --- /dev/null +++ b/bench/scenarios/out/cs18_precedence.tsv @@ -0,0 +1,11 @@ +arm mode cls msg fires_ok anti_ok +PR1-anchor-sigshape-over-fromopt reject msuiter_error_input signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature) TRUE TRUE +PR1-anti-fromopt-alone reject msuiter_error_option from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities TRUE TRUE +PR2-anchor-rownames-over-toopt reject msuiter_error_input signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | first rownames: 'R1', 'R2', 'R3' | order the matrix by the registry labels TRUE TRUE +PR2-anti-toopt-alone reject msuiter_error_option to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities TRUE TRUE +PR3-anchor-from-over-to reject msuiter_error_option from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities TRUE TRUE +PR3-anti-to-over-from reject msuiter_error_option to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nada'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities TRUE TRUE +PR4-anchor-length-over-names reject msuiter_error_input from must be a frequency vector over the 96 channels | an opportunity vector is one frequency per registry channel | received length: 10 | name it by the registry labels or pass a bundled table name TRUE TRUE +PR4-anti-names-alone reject msuiter_error_input from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'Y1', 'Y2', 'Y3' | set names(opps) to the registry labels TRUE TRUE +PR5-anchor-multicol-over-names reject msuiter_error_input from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities TRUE TRUE +PR5-anti-names-over-multicol reject msuiter_error_input from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'W1', 'W2', 'W3' | set names(opps) to the registry labels TRUE TRUE diff --git a/bench/scenarios/out/cs18_scalars.tsv b/bench/scenarios/out/cs18_scalars.tsv new file mode 100644 index 0000000..71bf724 --- /dev/null +++ b/bench/scenarios/out/cs18_scalars.tsv @@ -0,0 +1,11 @@ +key value +abort-class msuiter_error_input +matrix-render matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +msgsig-render MsSignature|96x3|double|1,1,1|3x2 +glyph-full 1,1,1 +glyph-zero 1,0,1 +roundtrip-under-tol TRUE +same-under-tol TRUE +storage-double double +rng-before FALSE +rng-after FALSE diff --git a/bench/scenarios/out/cs18_specs.tsv b/bench/scenarios/out/cs18_specs.tsv new file mode 100644 index 0000000..a4f1816 --- /dev/null +++ b/bench/scenarios/out/cs18_specs.tsv @@ -0,0 +1,11 @@ +arm mode cls msg +A1-accept-core accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +A2-accept-conv accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +A3-accept-rev accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +S1-accept-custom-vec accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +S2-accept-custom-both accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +S3-accept-zero-col accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,0,1 +S4-accept-onecol-matrix accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +S5-accept-int-vec accept s7:matrix matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 +A6-accept-msg-signature accept s7:msuiter::MsSignature MsSignature|96x3|double|1,1,1|3x2 +sp-replay-identity accept s7:character matrix|96x3|double|TRUE|S1,S2,S3|1,1,1==matrix|96x3|double|TRUE|S1,S2,S3|1,1,1 diff --git a/bench/scenarios/run_convert_witness.R b/bench/scenarios/run_convert_witness.R new file mode 100644 index 0000000..f61b400 --- /dev/null +++ b/bench/scenarios/run_convert_witness.R @@ -0,0 +1,470 @@ +# run_convert_witness.R -- the CS-18 convert-witness scenario (pillar 3). +# +# Mandate: plant synthetic signature-and-opportunity calls (the D3 law: zero +# COSMIC numeric matrices, zero real-data bytes, zero downloads -- the +# opportunity tables ride only as named frequency vectors over the registry +# labels) and adjudicate the EXPORTED ms_convert()/MsSignature face: the +# ten-arm "option"/"input" validator split over the from/to arguments, the +# accepted re-expression shapes, the precedence discriminators with their +# anti anchors, the boundary contrast pairs and the acceptance specs. Every +# arm is driven through the exported faces alone; the accepted returns, the +# abort classes and the fired clauses are the face's own. The scenario +# consumes no RNG, no network and no clock at the adjudication core; 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): the face returns a real matrix whose kernel error is ~1e-16, +# so no float payload rides any witness -- the accepted render commits a +# DISCRETE column-sum glyph (0/1/? at a 1e-9 threshold, seven orders above +# the observed float error), which is a cross-platform label; integer, label, +# logical, class and clause bytes are byte-committed. +# +# Rails: this runner carries the same frozen block as the law file +# (tests/testthat/test-scenario-convert-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) +} +stopif <- function(cond, msg) if (isTRUE(cond)) stop(msg, call. = FALSE) +## RNG-STATE-RAIL: the adjudication core must never seed or consume RNG; +## the purity verdict rides the scalars witness (committed bytes below). +rng0 <- exists(".Random.seed", envir = globalenv(), inherits = TRUE) +## <> (minted mechanically from the audited ledger +## 2026-11-25; DO NOT hand-edit: regenerate via cs18-mint3.R) ## +.CS18_LAW_ARMS <- c("L1-unknown-from", "L2-unknown-to", "L3-multicol-matrix", "L4-wrong-length", "L5-names-mismatch", "L6-nonpositive", "L7-nonfinite", "L8-nonmatrix", "L9-wrong-rownames", "L10-no-rownames") +.CS18_LAW_CLS <- c("msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input") +.CS18_LAW_CLAUSES <- list() +.CS18_LAW_CLAUSES[["L1-unknown-from"]] <- "from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_LAW_CLAUSES[["L2-unknown-to"]] <- "to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_LAW_CLAUSES[["L3-multicol-matrix"]] <- "from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities" +.CS18_LAW_CLAUSES[["L4-wrong-length"]] <- "from must be a frequency vector over the 96 channels | an opportunity vector is one frequency per registry channel | received length: 10 | name it by the registry labels or pass a bundled table name" +.CS18_LAW_CLAUSES[["L5-names-mismatch"]] <- "from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'X1', 'X2', 'X3' | set names(opps) to the registry labels" +.CS18_LAW_CLAUSES[["L6-nonpositive"]] <- "from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies" +.CS18_LAW_CLAUSES[["L7-nonfinite"]] <- "from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies" +.CS18_LAW_CLAUSES[["L8-nonmatrix"]] <- "signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature)" +.CS18_LAW_CLAUSES[["L9-wrong-rownames"]] <- "signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | first rownames: 'R1', 'R2', 'R3' | order the matrix by the registry labels" +.CS18_LAW_CLAUSES[["L10-no-rownames"]] <- "signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | rownames missing | order the matrix by the registry labels" +.CS18_SPEC_ARMS <- c("A1-accept-core", "A2-accept-conv", "A3-accept-rev", "S1-accept-custom-vec", "S2-accept-custom-both", "S3-accept-zero-col", "S4-accept-onecol-matrix", "S5-accept-int-vec", "A6-accept-msg-signature", "sp-replay-identity") +.CS18_SPEC_CLS <- c("s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:msuiter::MsSignature", "s7:character") +.CS18_SPEC_DETAILS <- list() +.CS18_SPEC_DETAILS[["A1-accept-core"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A2-accept-conv"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A3-accept-rev"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S1-accept-custom-vec"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S2-accept-custom-both"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S3-accept-zero-col"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,0,1" +.CS18_SPEC_DETAILS[["S4-accept-onecol-matrix"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S5-accept-int-vec"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A6-accept-msg-signature"]] <- "MsSignature|96x3|double|1,1,1|3x2" +.CS18_SPEC_DETAILS[["sp-replay-identity"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1==matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_PREC_ARMS <- c("PR1-anchor-sigshape-over-fromopt", "PR1-anti-fromopt-alone", "PR2-anchor-rownames-over-toopt", "PR2-anti-toopt-alone", "PR3-anchor-from-over-to", "PR3-anti-to-over-from", "PR4-anchor-length-over-names", "PR4-anti-names-alone", "PR5-anchor-multicol-over-names", "PR5-anti-names-over-multicol") +.CS18_PREC_CLS <- c("msuiter_error_input", "msuiter_error_option", "msuiter_error_input", "msuiter_error_option", "msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input") +.CS18_PREC_FIRES <- c("signatures must be a numeric matrix", "from must be a bundled table", "signatures must carry the SBS96 registry rownames", "to must be a bundled table", "from must be a bundled table", "to must be a bundled table", "must be a frequency vector over the 96 channels", "names must equal the SBS96 registry labels", "matrix must have exactly one frequency column", "names must equal the SBS96 registry labels") +.CS18_PREC_ANTI <- c("from must be a bundled table", "signatures must be a numeric matrix", "to must be a bundled table", "signatures must carry the SBS96 registry rownames", "to must be a bundled table", "from must be a bundled table", "names must equal the SBS96 registry labels", "must be a frequency vector over the 96 channels", "names must equal the SBS96 registry labels", "matrix must have exactly one frequency column") +.CS18_DEGEN_PAIR <- c("zero-column-glyph", "zero-column-glyph", "onecol-vs-multicol", "onecol-vs-multicol", "fromopt-vs-toopt", "fromopt-vs-toopt", "shape-vs-names", "shape-vs-names") +.CS18_DEGEN_SIDE <- c("hi", "lo", "hi", "lo", "hi", "lo", "hi", "lo") +.CS18_DEGEN_ARMS <- c("zero-col-hi", "full-col-lo", "onecol-matrix-hi", "multicol-matrix-lo", "from-bad-hi", "to-bad-lo", "nonmatrix-hi", "wrongnames-lo") +.CS18_DEGEN_MODE <- c("accept", "accept", "accept", "reject", "reject", "reject", "reject", "reject") +.CS18_DEGEN_CLS <- c("s7:matrix", "s7:matrix", "s7:matrix", "msuiter_error_input", "msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input") +.CS18_DEGEN_MSG <- list() +.CS18_DEGEN_MSG[["zero-col-hi"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,0,1" +.CS18_DEGEN_MSG[["full-col-lo"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_DEGEN_MSG[["onecol-matrix-hi"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_DEGEN_MSG[["multicol-matrix-lo"]] <- "from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities" +.CS18_DEGEN_MSG[["from-bad-hi"]] <- "from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_DEGEN_MSG[["to-bad-lo"]] <- "to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nada'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_DEGEN_MSG[["nonmatrix-hi"]] <- "signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature)" +.CS18_DEGEN_MSG[["wrongnames-lo"]] <- "from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'Y1', 'Y2', 'Y3' | set names(opps) to the registry labels" +.CS18_SCAL_KEYS <- c("abort-class", "matrix-render", "msgsig-render", "glyph-full", "glyph-zero", "roundtrip-under-tol", "same-under-tol", "storage-double", "rng-before", "rng-after") +.CS18_SCAL_VALS <- list() +.CS18_SCAL_VALS[["abort-class"]] <- "msuiter_error_input" +.CS18_SCAL_VALS[["matrix-render"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SCAL_VALS[["msgsig-render"]] <- "MsSignature|96x3|double|1,1,1|3x2" +.CS18_SCAL_VALS[["glyph-full"]] <- "1,1,1" +.CS18_SCAL_VALS[["glyph-zero"]] <- "1,0,1" +.CS18_SCAL_VALS[["roundtrip-under-tol"]] <- "TRUE" +.CS18_SCAL_VALS[["same-under-tol"]] <- "TRUE" +.CS18_SCAL_VALS[["storage-double"]] <- "double" +.CS18_SCAL_VALS[["rng-before"]] <- "FALSE" +.CS18_SCAL_VALS[["rng-after"]] <- "FALSE" +.CS18_SCAL_REFIRE <- list() +.CS18_SCAL_REFIRE[["abort-class"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_SCAL_REFIRE[["matrix-render"]] <- ".cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["msgsig-render"]] <- ".cs18_render(ms_convert(.cs18_obj(), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["glyph-full"]] <- ".cs18_cs(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["glyph-zero"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; .cs18_cs(ms_convert(s, from = \"human-genome\", to = \"human-exome\")) }" +.CS18_SCAL_REFIRE[["roundtrip-under-tol"]] <- "{ o <- ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"); b <- ms_convert(o, from = \"human-exome\", to = \"human-genome\"); max(abs(b - .cs18_sig(3L))) < 1e-9 }" +.CS18_SCAL_REFIRE[["same-under-tol"]] <- "{ o <- ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\"); max(abs(o - .cs18_sig(3L))) < 1e-9 }" +.CS18_SCAL_REFIRE[["storage-double"]] <- "storage.mode(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_ARM <- list() +.CS18_ARM[["L1-unknown-from"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["L2-unknown-to"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nope\")" +.CS18_ARM[["L3-multicol-matrix"]] <- "ms_convert(.cs18_sig(3L), from = matrix(1, length(.cs18_reg()), 2L), to = \"human-exome\")" +.CS18_ARM[["L4-wrong-length"]] <- "ms_convert(.cs18_sig(3L), from = rep(1, 10L), to = \"human-exome\")" +.CS18_ARM[["L5-names-mismatch"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"X\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L6-nonpositive"]] <- "{ v <- .cs18_nv(rep(1, length(.cs18_reg()))); v[1L] <- 0; ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L7-nonfinite"]] <- "{ v <- .cs18_nv(rep(1, length(.cs18_reg()))); v[1L] <- Inf; ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L8-nonmatrix"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["L9-wrong-rownames"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- paste0(\"R\", seq_len(nrow(s))); ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["L10-no-rownames"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- NULL; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["A1-accept-core"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")" +.CS18_ARM[["A2-accept-conv"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["A3-accept-rev"]] <- "ms_convert(.cs18_sig(3L), from = \"human-exome\", to = \"human-genome\")" +.CS18_ARM[["S1-accept-custom-vec"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1, length(.cs18_reg()))), to = \"human-exome\")" +.CS18_ARM[["S2-accept-custom-both"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1, length(.cs18_reg()))), to = .cs18_nv(rep(2, length(.cs18_reg()))))" +.CS18_ARM[["S3-accept-zero-col"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["S4-accept-onecol-matrix"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L, dimnames = list(.cs18_reg(), \"S1\")); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["S5-accept-int-vec"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1L, length(.cs18_reg()))), to = \"human-exome\")" +.CS18_ARM[["A6-accept-msg-signature"]] <- "ms_convert(.cs18_obj(), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["sp-replay-identity"]] <- "paste0(.cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")), \"==\", .cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")))" +.CS18_ARM[["PR1-anchor-sigshape-over-fromopt"]] <- "ms_convert(as.character(seq_len(8L)), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["PR1-anti-fromopt-alone"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["PR2-anchor-rownames-over-toopt"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- paste0(\"R\", seq_len(nrow(s))); ms_convert(s, from = \"human-genome\", to = \"nope\") }" +.CS18_ARM[["PR2-anti-toopt-alone"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nope\")" +.CS18_ARM[["PR3-anchor-from-over-to"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"nada\")" +.CS18_ARM[["PR3-anti-to-over-from"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nada\")" +.CS18_ARM[["PR4-anchor-length-over-names"]] <- "{ v <- stats::setNames(rep(1, 10L), paste0(\"X\", seq_len(10L))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["PR4-anti-names-alone"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"Y\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["PR5-anchor-multicol-over-names"]] <- "{ m <- matrix(1, length(.cs18_reg()), 2L); rownames(m) <- paste0(\"Z\", seq_len(nrow(m))); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["PR5-anti-names-over-multicol"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L); rownames(m) <- paste0(\"W\", seq_len(nrow(m))); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["zero-col-hi"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["full-col-lo"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["onecol-matrix-hi"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L, dimnames = list(.cs18_reg(), \"S1\")); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["multicol-matrix-lo"]] <- "ms_convert(.cs18_sig(3L), from = matrix(1, length(.cs18_reg()), 2L), to = \"human-exome\")" +.CS18_ARM[["from-bad-hi"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["to-bad-lo"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nada\")" +.CS18_ARM[["nonmatrix-hi"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["wrongnames-lo"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"Y\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_CENSUS <- c("msuiter_error_input=17", "msuiter_error_option=8", "s7:character=1", "s7:matrix=11", "s7:msuiter::MsSignature=1") +## <> ## + +## <> (single source: injected byte-identically into +## the law file and the runner; edit /tmp/cs18-shared.R and re-splice -- +## never hand-edit in place) +## cs18-shared.R -- single source of the CS-18 convert-witness shared block. +## Injected byte-identically into tests/testthat/test-scenario-convert-witness.R +## and bench/scenarios/run_convert_witness.R between the SHARED markers. +## Pure, deterministic, no RNG, no clock, no network: the condition-message +## pipeline plus the exported-face verdict render and the plant builders the +## frozen ARM texts call. The render commits a discrete column-sum glyph +## (0/1/?) instead of any float payload -- the D11 posture for a face that +## returns a real matrix. +.cs18_reg <- function() { + p <- system.file("extdata", "opps_trinuc_freqs.tsv", package = "msuiter") + cand <- c(p, file.path("inst", "extdata", "opps_trinuc_freqs.tsv"), + file.path("data-raw", "opps_trinuc_freqs.tsv")) + cand <- cand[nzchar(cand) & file.exists(cand)] + if (length(cand) == 0L) stop(".cs18_reg: opportunity table not locatable") + as.character(utils::read.delim(cand[1L], sep = "\t", header = TRUE, + stringsAsFactors = FALSE)$label) +} +.cs18_sig <- function(k = 3L) { + reg <- .cs18_reg() + matrix(1 / length(reg), length(reg), k, + dimnames = list(reg, paste0("S", seq_len(k)))) +} +.cs18_nv <- function(v) stats::setNames(as.numeric(v), .cs18_reg()) +.cs18_obj <- function() { + reg <- .cs18_reg() + samp <- c("T1", "T2") + ct <- .cs18_sig(2L); colnames(ct) <- samp + cat0 <- ms_catalog(counts = ct, + channels = list(name = "SBS96", labels = reg), + samples = samp, provenance = list(genome = "GRCh38")) + ms_signature(signatures = .cs18_sig(3L), + exposures = matrix(1, 3L, 2L, + dimnames = list(paste0("S", 1:3), samp)), + catalog_summary = msuiter_catalog_summary(cat0), + engine = "synthetic", seed = 1L) +} +## Discrete column-sum glyph: 0 for an all-zero column, 1 for a normalized +## column, "?" for anything else. The float error of the kernel is ~1e-16, +## seven orders under the threshold, so the glyph is a cross-platform label. +.cs18_cs <- function(v) { + s <- colSums(v) + paste0(vapply(s, function(z) { + if (abs(z) < 1e-9) "0" else if (abs(z - 1) < 1e-9) "1" else "?" + }, character(1L)), collapse = ",") +} +.cs18_render <- function(x) { + ## S7 objects report class(x)[1L] as "msuiter::MsSignature"; inherits() + ## against the bare name is FALSE, so detect via S7_inherits (falling back + ## to a class-name grep when the S7 namespace is not attached). + is_sig <- isTRUE(tryCatch(S7::S7_inherits(x, MsSignature), + error = function(e) FALSE)) || + grepl("MsSignature", class(x)[1L], fixed = TRUE) + if (is_sig) { + return(paste0(c("MsSignature", + paste0(dim(x@signatures), collapse = "x"), + storage.mode(x@signatures), + .cs18_cs(x@signatures), + paste0(dim(x@exposures), collapse = "x")), collapse = "|")) + } + paste0(c(class(x)[1L], + paste0(dim(x), collapse = "x"), + storage.mode(x), + paste0(identical(rownames(x), .cs18_reg())), + paste0(colnames(x), collapse = ","), + .cs18_cs(x)), collapse = "|") +} +.cs18_describe <- function(e) trimws(gsub("\n", " | ", + paste(as.character(conditionMessage(e)), collapse = " | "), fixed = TRUE)) +.cs18_strip <- function(s) { + for (b in c("ℹ ", "i ")) s <- gsub(b, "", s, fixed = TRUE) + s +} +.cs18_eval1 <- function(txt, tag) { + if (is.na(txt) || !nzchar(txt)) stop(".cs18_eval1: no text for ", tag) + ex <- parse(text = txt) + if (length(ex) != 1L) { + stop(".cs18_eval1: ", tag, " is not a single expression") + } + tryCatch(list(ok = TRUE, v = eval(ex[[1L]])), error = identity) +} +.cs18_verdict <- function(arm, r) { + if (inherits(r, "error")) { + list(arm = arm, mode = "reject", cls = class(r)[1L], + msg = gsub("\t", " ", .cs18_strip(.cs18_describe(r)), fixed = TRUE)) + } else { + rendered <- if (is.character(r)) r else .cs18_render(r) + list(arm = arm, mode = "accept", cls = paste0("s7:", class(r)[1L]), + msg = gsub("\t", " ", rendered, fixed = TRUE)) + } +} +.cs18_fire <- function(arm) { + r <- .cs18_eval1(.CS18_ARM[[arm]], arm) + .cs18_verdict(arm, if (inherits(r, "error")) r else r$v) +} +.cs18_clean <- function(df) { + ## witness bytes round-trip nameless through read.csv; strip any vapply + ## residue names so identical() compares columns byte-true + for (cnm in names(df)) attr(df[[cnm]], "names") <- NULL + df +} +.cs18_rows <- function(arms) { + vs <- lapply(arms, function(a) .cs18_fire(a)) + .cs18_clean(data.frame(arm = arms, + mode = vapply(vs, function(z) z$mode, character(1L)), + cls = vapply(vs, function(z) z$cls, character(1L)), + msg = vapply(vs, function(z) z$msg, character(1L)), + stringsAsFactors = FALSE)) +} +.cs18_lawrows <- function() .cs18_rows(.CS18_LAW_ARMS) +.cs18_specrows <- function() .cs18_rows(.CS18_SPEC_ARMS) +.cs18_precrows <- function() { + base <- .cs18_rows(.CS18_PREC_ARMS) + base$fires_ok <- unname(vapply(seq_along(base$arm), function(i) { + paste0(grepl(.CS18_PREC_FIRES[i], base$msg[i], fixed = TRUE)) + }, character(1L))) + base$anti_ok <- unname(vapply(seq_along(base$arm), function(i) { + paste0(!grepl(.CS18_PREC_ANTI[i], base$msg[i], fixed = TRUE)) + }, character(1L))) + base +} +.cs18_degenrows <- function() { + vs <- lapply(.CS18_DEGEN_ARMS, function(a) .cs18_fire(a)) + .cs18_clean(data.frame(pair = .CS18_DEGEN_PAIR, side = .CS18_DEGEN_SIDE, + arm = .CS18_DEGEN_ARMS, + mode = vapply(vs, function(z) z$mode, character(1L)), + cls = vapply(vs, function(z) z$cls, character(1L)), + msg = vapply(vs, function(z) z$msg, character(1L)), + stringsAsFactors = FALSE)) +} +.cs18_scalval <- function(k) { + txt <- .CS18_SCAL_REFIRE[[k]] + if (is.null(txt)) return(NA_character_) + res <- .cs18_eval1(txt, k) + if (inherits(res, "error")) { + if (identical(k, "abort-class")) return(paste0(class(res)[1L])) + return(.cs18_strip(.cs18_describe(res))) + } + paste0(res$v) +} +.cs18_scalref_keys <- function() names(.CS18_SCAL_REFIRE) +.cs18_plant_text <- function() { + ord <- c(.CS18_LAW_ARMS, .CS18_SPEC_ARMS, .CS18_PREC_ARMS, .CS18_DEGEN_ARMS) + paste0(vapply(ord, function(a) + paste0(a, "=", .CS18_ARM[[a]]), character(1L)), collapse = ";") +} +.cs18_spec_text <- function() paste0(.CS18_SPEC_ARMS, collapse = ";") +## <> (do not hand-edit in place: edit the source and +## re-splice) ## + +## --------------------------------------------------------------------------- +## writers, census and the dual-kernel hash rail +## --------------------------------------------------------------------------- +.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 = "") + invisible(nm) +} +.census <- function(nm, df, want.rows, key.col = 1L) { + stopif(nrow(df) != want.rows, paste0("census ", nm, ": rows ", nrow(df))) + stopif(any(duplicated(df[[key.col]])), paste0("census ", nm, ": duplicate keys")) + for (cnm in names(df)) { + col <- df[[cnm]] + bad <- !is.character(col) || any(is.na(col)) || any(!nzchar(col)) || + any(grepl("\t", col, fixed = TRUE)) + stopif(bad, paste0("census ", nm, ".", cnm, ": non-character/NA/empty/tab")) + } + invisible(TRUE) +} +.ck <- function(bytes, tag) { + a <- .ms_fit_sha256(bytes) + b <- digest::digest(bytes, algo = "sha256", serialize = FALSE) + stopif(!identical(a, b), paste0("ck: kernel disagreement on ", tag)) + stopif(!grepl("^[0-9a-f]{64}$", a), paste0("ck: hex policy on ", tag)) + stopif(nchar(a) != 64L, paste0("ck: length on ", tag)) + a +} +.file.sha <- function(nm) { + p <- file.path(OUT, nm) + con <- file(p, open = "rb") + on.exit(close(con)) + bytes <- readBin(con, what = raw(), n = file.size(p)) + .ck(bytes, nm) +} + +## --------------------------------------------------------------------------- +## build the five witness tables, rail-checked against the frozen block +## --------------------------------------------------------------------------- +dir.create(OUT, showWarnings = FALSE, recursive = TRUE) + +laws <- .cs18_lawrows() +stopif(!identical(laws$arm, .CS18_LAW_ARMS), "laws: roster drift") +stopif(!identical(laws$mode, rep("reject", 10L)), "laws: a mode drift") +stopif(!identical(laws$cls, .CS18_LAW_CLS), "laws: a class drift") +stopif(!identical(laws$msg, unname(vapply(.CS18_LAW_ARMS, + function(a) .CS18_LAW_CLAUSES[[a]], character(1L)))), "laws: clause byte drift") +.census("laws", laws, 10L) + +specs <- .cs18_specrows() +stopif(!identical(specs$arm, .CS18_SPEC_ARMS), "specs: roster drift") +stopif(!identical(specs$mode, rep("accept", 10L)), "specs: a mode drift") +stopif(!identical(specs$cls, .CS18_SPEC_CLS), "specs: a class drift") +stopif(!identical(specs$msg, unname(vapply(.CS18_SPEC_ARMS, + function(a) .CS18_SPEC_DETAILS[[a]], character(1L)))), "specs: detail byte drift") +## the replay arm speaks the core render twice, joined by == +stopif(!identical(specs$msg[match("sp-replay-identity", specs$arm)], + paste0(specs$msg[match("A1-accept-core", specs$arm)], "==", + specs$msg[match("A1-accept-core", specs$arm)])), + "specs: the replay identity is not the rendered matrix twice") +## the accepted matrix render commits the canonical-rownames bit and the glyph +stopif(!grepl("|TRUE|S1,S2,S3|1,1,1", specs$msg[match("A1-accept-core", specs$arm)], + fixed = TRUE), "specs: the core render lost its shape") +.census("specs", specs, 10L) + +prec <- .cs18_precrows() +stopif(!identical(prec$arm, .CS18_PREC_ARMS), "prec: roster drift") +stopif(!identical(prec$mode, rep("reject", 10L)), "prec: a mode drift") +stopif(!identical(prec$cls, .CS18_PREC_CLS), "prec: a class drift") +stopif(!all(prec$fires_ok == "TRUE"), "prec: a fired anchor missing") +stopif(!all(prec$anti_ok == "TRUE"), "prec: an anti anchor present") +for (i in seq_len(10L)) { + stopif(!grepl(.CS18_PREC_FIRES[i], prec$msg[i], fixed = TRUE), + paste0("prec: fire anchor absent in ", .CS18_PREC_ARMS[i])) + stopif(grepl(.CS18_PREC_ANTI[i], prec$msg[i], fixed = TRUE), + paste0("prec: anti anchor present in ", .CS18_PREC_ARMS[i])) +} +.census("prec", prec, 10L) + +degen <- .cs18_degenrows() +stopif(!identical(degen$pair, .CS18_DEGEN_PAIR), "degen: pair drift") +stopif(!identical(degen$side, .CS18_DEGEN_SIDE), "degen: side drift") +stopif(!identical(degen$arm, .CS18_DEGEN_ARMS), "degen: arm drift") +stopif(!identical(degen$mode, .CS18_DEGEN_MODE), "degen: mode drift") +stopif(!identical(degen$cls, .CS18_DEGEN_CLS), "degen: class drift") +stopif(!identical(degen$msg, unname(vapply(.CS18_DEGEN_ARMS, + function(a) .CS18_DEGEN_MSG[[a]], character(1L)))), "degen: msg byte drift") +.w <- function(arm) degen$msg[match(arm, degen$arm)] +head1 <- function(txt) strsplit(txt, " | ", fixed = TRUE)[[1L]][1L] +## zero-column glyph pair: the all-zero column rides as 0 on the hi side, the +## restored full column as 1 on the lo side +stopif(!grepl("|S1,S2,S3|1,0,1", .w("zero-col-hi"), fixed = TRUE), + "degen: the zero-column glyph moved") +stopif(!grepl("|S1,S2,S3|1,1,1", .w("full-col-lo"), fixed = TRUE), + "degen: the full-column glyph moved") +## onecol-vs-multicol pair: a one-column from-matrix accepts, a two-column +## one dies at the single-column law +stopif(!grepl("exactly one frequency column", .w("multicol-matrix-lo"), fixed = TRUE), + "degen: the multicol clause went missing") +## fromopt-vs-toopt pair: two distinct option laws by their own clause heads +stopif(!identical(head1(.w("from-bad-hi")), + "from must be a bundled table or a custom frequency vector"), + "degen: the from-option head moved") +stopif(!identical(head1(.w("to-bad-lo")), + "to must be a bundled table or a custom frequency vector"), + "degen: the to-option head moved") +## shape-vs-names pair: the shape law vs the label law, distinct heads +stopif(!identical(head1(.w("nonmatrix-hi")), "signatures must be a numeric matrix"), + "degen: the shape head moved") +stopif(!grepl("first names: 'Y1'", .w("wrongnames-lo"), fixed = TRUE), + "degen: the names decoy went missing") +.census("degen", degen, 8L, key.col = 3L) + +rng1 <- exists(".Random.seed", envir = globalenv(), inherits = TRUE) +scal.vals <- vapply(.CS18_SCAL_KEYS, function(k) { + if (identical(k, "rng-before")) return(format(rng0)) + if (identical(k, "rng-after")) return(format(rng1)) + v <- .cs18_scalval(k) + stopif(is.na(v) || !nzchar(v), paste0("scalars: empty re-fire for ", k)) + stopif(!identical(v, .CS18_SCAL_VALS[[k]]), paste0("scalars: drift for ", k)) + v +}, character(1L)) +scalars <- data.frame(key = .CS18_SCAL_KEYS, value = unname(scal.vals), + stringsAsFactors = FALSE) +stopif(!identical(scalars$value[match("rng-before", .CS18_SCAL_KEYS)], + .CS18_SCAL_VALS[["rng-before"]]), "scalars: rng-before drift") +stopif(!identical(scalars$value[match("rng-after", .CS18_SCAL_KEYS)], + .CS18_SCAL_VALS[["rng-after"]]), "scalars: rng-after drift") +## the discrete glyphs are committed labels, not float payloads +stopif(!identical(scalars$value[match("glyph-full", .CS18_SCAL_KEYS)], "1,1,1"), + "scalars: the full glyph moved") +stopif(!identical(scalars$value[match("glyph-zero", .CS18_SCAL_KEYS)], "1,0,1"), + "scalars: the zero glyph moved") +.census("scalars", scalars, 10L) + +## dual-kernel hashes over the frozen corpora (written nowhere, attested) +plant.sha <- .ck(charToRaw(.cs18_plant_text()), "plant-corpus") +spec.sha <- .ck(charToRaw(.cs18_spec_text()), "spec-corpus") + +## --------------------------------------------------------------------------- +## all censuses spoke: commit the five witnesses +## --------------------------------------------------------------------------- +.wtab("cs18_laws.tsv", laws) +.wtab("cs18_specs.tsv", specs) +.wtab("cs18_precedence.tsv", prec) +.wtab("cs18_degenerates.tsv", degen) +.wtab("cs18_scalars.tsv", scalars) + +cat("[attest] at=", format(Sys.time(), "%Y-%m-%dT%H:%M:%OS3Z", tz = "UTC"), + " out=", OUT, "\n", sep = "") +for (nm in c("cs18_laws.tsv", "cs18_specs.tsv", "cs18_precedence.tsv", + "cs18_degenerates.tsv", "cs18_scalars.tsv")) { + cat("[attest] sha256 ", nm, "=", .file.sha(nm), "\n", sep = "") +} +cat("[attest] plant_sha256=", plant.sha, " spec_sha256=", spec.sha, + " files=", length(list.files(OUT, pattern = "^cs18_")), "\n", sep = "") +cat("OVERALL PASS\n") +quit(save = "no", status = 0L) diff --git a/tests/testthat/test-scenario-convert-witness.R b/tests/testthat/test-scenario-convert-witness.R new file mode 100644 index 0000000..ef85da5 --- /dev/null +++ b/tests/testthat/test-scenario-convert-witness.R @@ -0,0 +1,572 @@ +# test-scenario-convert-witness.R -- the CS-18 convert-witness law units +# (pillar 3). The scenario plants synthetic signature-and-opportunity calls +# (the D3 law: zero COSMIC numeric matrices, zero real-data bytes, zero +# downloads -- the opportunity tables ride only as named frequency vectors +# over the registry labels) and adjudicates the EXPORTED ms_convert()/ +# MsSignature face: the ten-arm "option"/"input" validator split over the +# from/to arguments, the accepted re-expression shapes, the precedence +# discriminators with their anti anchors, the boundary contrast pairs and the +# acceptance specs. The witness bytes under bench/scenarios/out/ +# (cs18_laws.tsv, cs18_specs.tsv, cs18_precedence.tsv, cs18_degenerates.tsv, +# cs18_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 consumption, no +# network, no COSMIC bytes; the lane NEVER calls the benchmark driver, the +# declined calibration family, the registry face or any validator internal +# (banned words, grepped over the runner source). +# Framing law: DECISION RECORD only. What the face says on planted truth -- +# the accepted shapes, the abort classes, the fired clauses -- 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 returns a real matrix whose +# kernel error is ~1e-16, so no float payload rides any witness -- the +# accepted render commits a DISCRETE column-sum glyph (0/1/? at a 1e-9 +# threshold, seven orders above the observed float error). +# The frozen block and the shared code block below are MINTED mechanically +# from the audited probe ledger (cs18-mint3.R / cs18-shared.R); neither is +# ever hand-edited in place. + +.rs_out18 <- 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_tsv18 <- function(fname) { + read.csv(.rs_out18(fname), header = TRUE, sep = "\t", + stringsAsFactors = FALSE, na.strings = "", colClasses = "character", + quote = "") +} + +## <> (minted mechanically from the audited ledger +## 2026-11-25; DO NOT hand-edit: regenerate via cs18-mint3.R) ## +.CS18_LAW_ARMS <- c("L1-unknown-from", "L2-unknown-to", "L3-multicol-matrix", "L4-wrong-length", "L5-names-mismatch", "L6-nonpositive", "L7-nonfinite", "L8-nonmatrix", "L9-wrong-rownames", "L10-no-rownames") +.CS18_LAW_CLS <- c("msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input") +.CS18_LAW_CLAUSES <- list() +.CS18_LAW_CLAUSES[["L1-unknown-from"]] <- "from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_LAW_CLAUSES[["L2-unknown-to"]] <- "to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_LAW_CLAUSES[["L3-multicol-matrix"]] <- "from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities" +.CS18_LAW_CLAUSES[["L4-wrong-length"]] <- "from must be a frequency vector over the 96 channels | an opportunity vector is one frequency per registry channel | received length: 10 | name it by the registry labels or pass a bundled table name" +.CS18_LAW_CLAUSES[["L5-names-mismatch"]] <- "from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'X1', 'X2', 'X3' | set names(opps) to the registry labels" +.CS18_LAW_CLAUSES[["L6-nonpositive"]] <- "from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies" +.CS18_LAW_CLAUSES[["L7-nonfinite"]] <- "from must be positive and finite | an opportunity of 0 makes the division undefined | offending entries: 1 | opportunity tables are strictly positive frequencies" +.CS18_LAW_CLAUSES[["L8-nonmatrix"]] <- "signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature)" +.CS18_LAW_CLAUSES[["L9-wrong-rownames"]] <- "signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | first rownames: 'R1', 'R2', 'R3' | order the matrix by the registry labels" +.CS18_LAW_CLAUSES[["L10-no-rownames"]] <- "signatures must carry the SBS96 registry rownames in canonical order | the opportunity tables are matched by label, never by position | rownames missing | order the matrix by the registry labels" +.CS18_SPEC_ARMS <- c("A1-accept-core", "A2-accept-conv", "A3-accept-rev", "S1-accept-custom-vec", "S2-accept-custom-both", "S3-accept-zero-col", "S4-accept-onecol-matrix", "S5-accept-int-vec", "A6-accept-msg-signature", "sp-replay-identity") +.CS18_SPEC_CLS <- c("s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:matrix", "s7:msuiter::MsSignature", "s7:character") +.CS18_SPEC_DETAILS <- list() +.CS18_SPEC_DETAILS[["A1-accept-core"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A2-accept-conv"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A3-accept-rev"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S1-accept-custom-vec"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S2-accept-custom-both"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S3-accept-zero-col"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,0,1" +.CS18_SPEC_DETAILS[["S4-accept-onecol-matrix"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["S5-accept-int-vec"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SPEC_DETAILS[["A6-accept-msg-signature"]] <- "MsSignature|96x3|double|1,1,1|3x2" +.CS18_SPEC_DETAILS[["sp-replay-identity"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1==matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_PREC_ARMS <- c("PR1-anchor-sigshape-over-fromopt", "PR1-anti-fromopt-alone", "PR2-anchor-rownames-over-toopt", "PR2-anti-toopt-alone", "PR3-anchor-from-over-to", "PR3-anti-to-over-from", "PR4-anchor-length-over-names", "PR4-anti-names-alone", "PR5-anchor-multicol-over-names", "PR5-anti-names-over-multicol") +.CS18_PREC_CLS <- c("msuiter_error_input", "msuiter_error_option", "msuiter_error_input", "msuiter_error_option", "msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input", "msuiter_error_input") +.CS18_PREC_FIRES <- c("signatures must be a numeric matrix", "from must be a bundled table", "signatures must carry the SBS96 registry rownames", "to must be a bundled table", "from must be a bundled table", "to must be a bundled table", "must be a frequency vector over the 96 channels", "names must equal the SBS96 registry labels", "matrix must have exactly one frequency column", "names must equal the SBS96 registry labels") +.CS18_PREC_ANTI <- c("from must be a bundled table", "signatures must be a numeric matrix", "to must be a bundled table", "signatures must carry the SBS96 registry rownames", "to must be a bundled table", "from must be a bundled table", "names must equal the SBS96 registry labels", "must be a frequency vector over the 96 channels", "names must equal the SBS96 registry labels", "matrix must have exactly one frequency column") +.CS18_DEGEN_PAIR <- c("zero-column-glyph", "zero-column-glyph", "onecol-vs-multicol", "onecol-vs-multicol", "fromopt-vs-toopt", "fromopt-vs-toopt", "shape-vs-names", "shape-vs-names") +.CS18_DEGEN_SIDE <- c("hi", "lo", "hi", "lo", "hi", "lo", "hi", "lo") +.CS18_DEGEN_ARMS <- c("zero-col-hi", "full-col-lo", "onecol-matrix-hi", "multicol-matrix-lo", "from-bad-hi", "to-bad-lo", "nonmatrix-hi", "wrongnames-lo") +.CS18_DEGEN_MODE <- c("accept", "accept", "accept", "reject", "reject", "reject", "reject", "reject") +.CS18_DEGEN_CLS <- c("s7:matrix", "s7:matrix", "s7:matrix", "msuiter_error_input", "msuiter_error_option", "msuiter_error_option", "msuiter_error_input", "msuiter_error_input") +.CS18_DEGEN_MSG <- list() +.CS18_DEGEN_MSG[["zero-col-hi"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,0,1" +.CS18_DEGEN_MSG[["full-col-lo"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_DEGEN_MSG[["onecol-matrix-hi"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_DEGEN_MSG[["multicol-matrix-lo"]] <- "from matrix must have exactly one frequency column | the opportunity is a single 96-vector, not per-signature | received: 2 columns | repeat the column yourself for per-signature opportunities" +.CS18_DEGEN_MSG[["from-bad-hi"]] <- "from must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nope'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_DEGEN_MSG[["to-bad-lo"]] <- "to must be a bundled table or a custom frequency vector | panel opportunities are expected as a custom 96-vector ([V] discipline: no bundled panel table) | received: 'nada'; bundled: human-genome, human-exome | pass a named numeric vector for custom opportunities" +.CS18_DEGEN_MSG[["nonmatrix-hi"]] <- "signatures must be a numeric matrix | ms_convert() re-expresses SBS96 signatures between opportunities | received: character | pass 96 x k with registry rownames (or an MsSignature)" +.CS18_DEGEN_MSG[["wrongnames-lo"]] <- "from names must equal the SBS96 registry labels | opportunities are matched by label, never by position | first names: 'Y1', 'Y2', 'Y3' | set names(opps) to the registry labels" +.CS18_SCAL_KEYS <- c("abort-class", "matrix-render", "msgsig-render", "glyph-full", "glyph-zero", "roundtrip-under-tol", "same-under-tol", "storage-double", "rng-before", "rng-after") +.CS18_SCAL_VALS <- list() +.CS18_SCAL_VALS[["abort-class"]] <- "msuiter_error_input" +.CS18_SCAL_VALS[["matrix-render"]] <- "matrix|96x3|double|TRUE|S1,S2,S3|1,1,1" +.CS18_SCAL_VALS[["msgsig-render"]] <- "MsSignature|96x3|double|1,1,1|3x2" +.CS18_SCAL_VALS[["glyph-full"]] <- "1,1,1" +.CS18_SCAL_VALS[["glyph-zero"]] <- "1,0,1" +.CS18_SCAL_VALS[["roundtrip-under-tol"]] <- "TRUE" +.CS18_SCAL_VALS[["same-under-tol"]] <- "TRUE" +.CS18_SCAL_VALS[["storage-double"]] <- "double" +.CS18_SCAL_VALS[["rng-before"]] <- "FALSE" +.CS18_SCAL_VALS[["rng-after"]] <- "FALSE" +.CS18_SCAL_REFIRE <- list() +.CS18_SCAL_REFIRE[["abort-class"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_SCAL_REFIRE[["matrix-render"]] <- ".cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["msgsig-render"]] <- ".cs18_render(ms_convert(.cs18_obj(), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["glyph-full"]] <- ".cs18_cs(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_SCAL_REFIRE[["glyph-zero"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; .cs18_cs(ms_convert(s, from = \"human-genome\", to = \"human-exome\")) }" +.CS18_SCAL_REFIRE[["roundtrip-under-tol"]] <- "{ o <- ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"); b <- ms_convert(o, from = \"human-exome\", to = \"human-genome\"); max(abs(b - .cs18_sig(3L))) < 1e-9 }" +.CS18_SCAL_REFIRE[["same-under-tol"]] <- "{ o <- ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\"); max(abs(o - .cs18_sig(3L))) < 1e-9 }" +.CS18_SCAL_REFIRE[["storage-double"]] <- "storage.mode(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\"))" +.CS18_ARM <- list() +.CS18_ARM[["L1-unknown-from"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["L2-unknown-to"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nope\")" +.CS18_ARM[["L3-multicol-matrix"]] <- "ms_convert(.cs18_sig(3L), from = matrix(1, length(.cs18_reg()), 2L), to = \"human-exome\")" +.CS18_ARM[["L4-wrong-length"]] <- "ms_convert(.cs18_sig(3L), from = rep(1, 10L), to = \"human-exome\")" +.CS18_ARM[["L5-names-mismatch"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"X\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L6-nonpositive"]] <- "{ v <- .cs18_nv(rep(1, length(.cs18_reg()))); v[1L] <- 0; ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L7-nonfinite"]] <- "{ v <- .cs18_nv(rep(1, length(.cs18_reg()))); v[1L] <- Inf; ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["L8-nonmatrix"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["L9-wrong-rownames"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- paste0(\"R\", seq_len(nrow(s))); ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["L10-no-rownames"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- NULL; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["A1-accept-core"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")" +.CS18_ARM[["A2-accept-conv"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["A3-accept-rev"]] <- "ms_convert(.cs18_sig(3L), from = \"human-exome\", to = \"human-genome\")" +.CS18_ARM[["S1-accept-custom-vec"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1, length(.cs18_reg()))), to = \"human-exome\")" +.CS18_ARM[["S2-accept-custom-both"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1, length(.cs18_reg()))), to = .cs18_nv(rep(2, length(.cs18_reg()))))" +.CS18_ARM[["S3-accept-zero-col"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["S4-accept-onecol-matrix"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L, dimnames = list(.cs18_reg(), \"S1\")); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["S5-accept-int-vec"]] <- "ms_convert(.cs18_sig(3L), from = .cs18_nv(rep(1L, length(.cs18_reg()))), to = \"human-exome\")" +.CS18_ARM[["A6-accept-msg-signature"]] <- "ms_convert(.cs18_obj(), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["sp-replay-identity"]] <- "paste0(.cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")), \"==\", .cs18_render(ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-genome\")))" +.CS18_ARM[["PR1-anchor-sigshape-over-fromopt"]] <- "ms_convert(as.character(seq_len(8L)), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["PR1-anti-fromopt-alone"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["PR2-anchor-rownames-over-toopt"]] <- "{ s <- .cs18_sig(3L); rownames(s) <- paste0(\"R\", seq_len(nrow(s))); ms_convert(s, from = \"human-genome\", to = \"nope\") }" +.CS18_ARM[["PR2-anti-toopt-alone"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nope\")" +.CS18_ARM[["PR3-anchor-from-over-to"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"nada\")" +.CS18_ARM[["PR3-anti-to-over-from"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nada\")" +.CS18_ARM[["PR4-anchor-length-over-names"]] <- "{ v <- stats::setNames(rep(1, 10L), paste0(\"X\", seq_len(10L))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["PR4-anti-names-alone"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"Y\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_ARM[["PR5-anchor-multicol-over-names"]] <- "{ m <- matrix(1, length(.cs18_reg()), 2L); rownames(m) <- paste0(\"Z\", seq_len(nrow(m))); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["PR5-anti-names-over-multicol"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L); rownames(m) <- paste0(\"W\", seq_len(nrow(m))); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["zero-col-hi"]] <- "{ s <- .cs18_sig(3L); s[, 2L] <- 0; ms_convert(s, from = \"human-genome\", to = \"human-exome\") }" +.CS18_ARM[["full-col-lo"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["onecol-matrix-hi"]] <- "{ m <- matrix(1, length(.cs18_reg()), 1L, dimnames = list(.cs18_reg(), \"S1\")); ms_convert(.cs18_sig(3L), from = m, to = \"human-exome\") }" +.CS18_ARM[["multicol-matrix-lo"]] <- "ms_convert(.cs18_sig(3L), from = matrix(1, length(.cs18_reg()), 2L), to = \"human-exome\")" +.CS18_ARM[["from-bad-hi"]] <- "ms_convert(.cs18_sig(3L), from = \"nope\", to = \"human-exome\")" +.CS18_ARM[["to-bad-lo"]] <- "ms_convert(.cs18_sig(3L), from = \"human-genome\", to = \"nada\")" +.CS18_ARM[["nonmatrix-hi"]] <- "ms_convert(as.character(seq_len(8L)), from = \"human-genome\", to = \"human-exome\")" +.CS18_ARM[["wrongnames-lo"]] <- "{ v <- stats::setNames(rep(1, length(.cs18_reg())), paste0(\"Y\", seq_along(.cs18_reg()))); ms_convert(.cs18_sig(3L), from = v, to = \"human-exome\") }" +.CS18_CENSUS <- c("msuiter_error_input=17", "msuiter_error_option=8", "s7:character=1", "s7:matrix=11", "s7:msuiter::MsSignature=1") +## <> ## + +## <> (single source: injected byte-identically into +## the law file and the runner; edit /tmp/cs18-shared.R and re-splice -- +## never hand-edit in place) +## cs18-shared.R -- single source of the CS-18 convert-witness shared block. +## Injected byte-identically into tests/testthat/test-scenario-convert-witness.R +## and bench/scenarios/run_convert_witness.R between the SHARED markers. +## Pure, deterministic, no RNG, no clock, no network: the condition-message +## pipeline plus the exported-face verdict render and the plant builders the +## frozen ARM texts call. The render commits a discrete column-sum glyph +## (0/1/?) instead of any float payload -- the D11 posture for a face that +## returns a real matrix. +.cs18_reg <- function() { + p <- system.file("extdata", "opps_trinuc_freqs.tsv", package = "msuiter") + cand <- c(p, file.path("inst", "extdata", "opps_trinuc_freqs.tsv"), + file.path("data-raw", "opps_trinuc_freqs.tsv")) + cand <- cand[nzchar(cand) & file.exists(cand)] + if (length(cand) == 0L) stop(".cs18_reg: opportunity table not locatable") + as.character(utils::read.delim(cand[1L], sep = "\t", header = TRUE, + stringsAsFactors = FALSE)$label) +} +.cs18_sig <- function(k = 3L) { + reg <- .cs18_reg() + matrix(1 / length(reg), length(reg), k, + dimnames = list(reg, paste0("S", seq_len(k)))) +} +.cs18_nv <- function(v) stats::setNames(as.numeric(v), .cs18_reg()) +.cs18_obj <- function() { + reg <- .cs18_reg() + samp <- c("T1", "T2") + ct <- .cs18_sig(2L); colnames(ct) <- samp + cat0 <- ms_catalog(counts = ct, + channels = list(name = "SBS96", labels = reg), + samples = samp, provenance = list(genome = "GRCh38")) + ms_signature(signatures = .cs18_sig(3L), + exposures = matrix(1, 3L, 2L, + dimnames = list(paste0("S", 1:3), samp)), + catalog_summary = msuiter_catalog_summary(cat0), + engine = "synthetic", seed = 1L) +} +## Discrete column-sum glyph: 0 for an all-zero column, 1 for a normalized +## column, "?" for anything else. The float error of the kernel is ~1e-16, +## seven orders under the threshold, so the glyph is a cross-platform label. +.cs18_cs <- function(v) { + s <- colSums(v) + paste0(vapply(s, function(z) { + if (abs(z) < 1e-9) "0" else if (abs(z - 1) < 1e-9) "1" else "?" + }, character(1L)), collapse = ",") +} +.cs18_render <- function(x) { + ## S7 objects report class(x)[1L] as "msuiter::MsSignature"; inherits() + ## against the bare name is FALSE, so detect via S7_inherits (falling back + ## to a class-name grep when the S7 namespace is not attached). + is_sig <- isTRUE(tryCatch(S7::S7_inherits(x, MsSignature), + error = function(e) FALSE)) || + grepl("MsSignature", class(x)[1L], fixed = TRUE) + if (is_sig) { + return(paste0(c("MsSignature", + paste0(dim(x@signatures), collapse = "x"), + storage.mode(x@signatures), + .cs18_cs(x@signatures), + paste0(dim(x@exposures), collapse = "x")), collapse = "|")) + } + paste0(c(class(x)[1L], + paste0(dim(x), collapse = "x"), + storage.mode(x), + paste0(identical(rownames(x), .cs18_reg())), + paste0(colnames(x), collapse = ","), + .cs18_cs(x)), collapse = "|") +} +.cs18_describe <- function(e) trimws(gsub("\n", " | ", + paste(as.character(conditionMessage(e)), collapse = " | "), fixed = TRUE)) +.cs18_strip <- function(s) { + for (b in c("ℹ ", "i ")) s <- gsub(b, "", s, fixed = TRUE) + s +} +.cs18_eval1 <- function(txt, tag) { + if (is.na(txt) || !nzchar(txt)) stop(".cs18_eval1: no text for ", tag) + ex <- parse(text = txt) + if (length(ex) != 1L) { + stop(".cs18_eval1: ", tag, " is not a single expression") + } + tryCatch(list(ok = TRUE, v = eval(ex[[1L]])), error = identity) +} +.cs18_verdict <- function(arm, r) { + if (inherits(r, "error")) { + list(arm = arm, mode = "reject", cls = class(r)[1L], + msg = gsub("\t", " ", .cs18_strip(.cs18_describe(r)), fixed = TRUE)) + } else { + rendered <- if (is.character(r)) r else .cs18_render(r) + list(arm = arm, mode = "accept", cls = paste0("s7:", class(r)[1L]), + msg = gsub("\t", " ", rendered, fixed = TRUE)) + } +} +.cs18_fire <- function(arm) { + r <- .cs18_eval1(.CS18_ARM[[arm]], arm) + .cs18_verdict(arm, if (inherits(r, "error")) r else r$v) +} +.cs18_clean <- function(df) { + ## witness bytes round-trip nameless through read.csv; strip any vapply + ## residue names so identical() compares columns byte-true + for (cnm in names(df)) attr(df[[cnm]], "names") <- NULL + df +} +.cs18_rows <- function(arms) { + vs <- lapply(arms, function(a) .cs18_fire(a)) + .cs18_clean(data.frame(arm = arms, + mode = vapply(vs, function(z) z$mode, character(1L)), + cls = vapply(vs, function(z) z$cls, character(1L)), + msg = vapply(vs, function(z) z$msg, character(1L)), + stringsAsFactors = FALSE)) +} +.cs18_lawrows <- function() .cs18_rows(.CS18_LAW_ARMS) +.cs18_specrows <- function() .cs18_rows(.CS18_SPEC_ARMS) +.cs18_precrows <- function() { + base <- .cs18_rows(.CS18_PREC_ARMS) + base$fires_ok <- unname(vapply(seq_along(base$arm), function(i) { + paste0(grepl(.CS18_PREC_FIRES[i], base$msg[i], fixed = TRUE)) + }, character(1L))) + base$anti_ok <- unname(vapply(seq_along(base$arm), function(i) { + paste0(!grepl(.CS18_PREC_ANTI[i], base$msg[i], fixed = TRUE)) + }, character(1L))) + base +} +.cs18_degenrows <- function() { + vs <- lapply(.CS18_DEGEN_ARMS, function(a) .cs18_fire(a)) + .cs18_clean(data.frame(pair = .CS18_DEGEN_PAIR, side = .CS18_DEGEN_SIDE, + arm = .CS18_DEGEN_ARMS, + mode = vapply(vs, function(z) z$mode, character(1L)), + cls = vapply(vs, function(z) z$cls, character(1L)), + msg = vapply(vs, function(z) z$msg, character(1L)), + stringsAsFactors = FALSE)) +} +.cs18_scalval <- function(k) { + txt <- .CS18_SCAL_REFIRE[[k]] + if (is.null(txt)) return(NA_character_) + res <- .cs18_eval1(txt, k) + if (inherits(res, "error")) { + if (identical(k, "abort-class")) return(paste0(class(res)[1L])) + return(.cs18_strip(.cs18_describe(res))) + } + paste0(res$v) +} +.cs18_scalref_keys <- function() names(.CS18_SCAL_REFIRE) +.cs18_plant_text <- function() { + ord <- c(.CS18_LAW_ARMS, .CS18_SPEC_ARMS, .CS18_PREC_ARMS, .CS18_DEGEN_ARMS) + paste0(vapply(ord, function(a) + paste0(a, "=", .CS18_ARM[[a]]), character(1L)), collapse = ";") +} +.cs18_spec_text <- function() paste0(.CS18_SPEC_ARMS, collapse = ";") +## <> (do not hand-edit in place: edit the source and +## re-splice) ## + +# =========================================================================== +# 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_convert_witness.R") + expect_true(file.exists(runner)) + src <- paste(readLines(runner, warn = FALSE), collapse = "\n") + for (need in c("--file=", "[attest]", "OVERALL PASS", "ms_convert(", "cs18_", + "commandArgs", "digest::digest", "serialize = FALSE", + "charToRaw", "open = \"wb\"", "na = \"\"", "quote = FALSE", + "row.names = FALSE", "RNG-STATE-RAIL", ".ms_fit_sha256")) { + expect_true(grepl(need, src, fixed = TRUE), info = need) + } + ## The bans govern the hand-written region: the minted frozen block is + ## OBSERVED DATA and legitimately quotes the face's own bytes (the clause + ## table quotes the S7 message bytes). Slice the two injected regions out + ## before the absence scan; marker integrity itself is rail-checked here. + lines <- strsplit(src, "\n", fixed = TRUE)[[1L]] + .region <- function(beg, end) { + b <- which(vapply(lines, function(l) grepl(beg, l, fixed = TRUE), logical(1L))) + e <- which(vapply(lines, function(l) grepl(end, l, fixed = TRUE), logical(1L))) + expect_identical(length(b), 1L, info = beg) + expect_identical(length(e), 1L, info = end) + c(b, e) + } + drop <- c(seq(.region("## < 627: the CS-18 scenario row +# (test-scenario-convert-witness.R, 1 s integer weight, 233 expects) joined +# the T0 roster; witness: local run nb=233 failed=0 error=0 skipped=0 +# warning=0, measured manifest sum 627 (generator refusal witnessed at the +# pre-seal re-mint attempt, the verbatim DEFECT line naming 627 against the +# sealed 626). key value note -t0-measured 626 measured 2026-11-24 (integer manifest seconds, tier T0; 2026-11-24 abort-contract row joins at 0 s, sum unchanged) +t0-measured 627 measured 2026-11-25 (integer manifest seconds, tier T0; 2026-11-25 CS-18 convert-witness row joins at 1 s, 626 -> 627) 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 c6601ff..e4d96e6 100644 --- a/tools/ci/shard-manifest.tsv +++ b/tools/ci/shard-manifest.tsv @@ -3,99 +3,100 @@ 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-abort-contract.R 0 T0 +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-calibration-verdict.R 1 T0 -4 test-scenario-currency-witness.R 1 T0 -4 test-scenario-hrd.R 0 T0 -4 test-scenario-io-interop-witness.R 1 T0 -4 test-scenario-refdb-witness.R 1 T0 -4 test-scenario-stratify.R 1 T0 +4 test-scenario-convert-witness.R 1 T0 +4 test-scenario-exposure-witness.R 1 T0 +4 test-scenario-hrd-baselines.R 0 T0 +4 test-scenario-reconstruction.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-abort-contract.R 0 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-ard-witness.R 1 T0 5 test-scenario-atlas.R 2 T0 5 test-scenario-cluster-witness.R 1 T0 -5 test-scenario-exposure-witness.R 1 T0 -5 test-scenario-hrd-baselines.R 0 T0 -5 test-scenario-reconstruction.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-downsample.R 1 T0 +5 test-scenario-hrd.R 0 T0 +5 test-scenario-qc-artifacts.R 1 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 @@ -105,9 +106,9 @@ shard file seconds tier 6 test-peer-evidence.R 3 T0 6 test-pkgdown-msu-map.R 1 T0 6 test-scenario-catalog-witness.R 1 T0 -6 test-scenario-downsample.R 1 T0 -6 test-scenario-qc-artifacts.R 1 T0 -6 test-scenario-segments-witness.R 1 T0 -6 test-scenarios-gallery.R 1 T0 +6 test-scenario-currency-witness.R 1 T0 +6 test-scenario-io-interop-witness.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 2123053..487ec5e 100644 --- a/tools/ci/shard-weights.tsv +++ b/tools/ci/shard-weights.tsv @@ -125,3 +125,4 @@ test-scenario-segments-witness.R 1 1704 T0 test-scenario-refdb-witness.R 1 273 T0 test-scenario-ard-witness.R 1 246 T0 test-scenario-catalog-witness.R 1 265 T0 +test-scenario-convert-witness.R 1 233 T0 diff --git a/vignettes/articles/devlog-2026-11-25-p3-cs18-convert-witness.qmd b/vignettes/articles/devlog-2026-11-25-p3-cs18-convert-witness.qmd new file mode 100644 index 0000000..2630fd0 --- /dev/null +++ b/vignettes/articles/devlog-2026-11-25-p3-cs18-convert-witness.qmd @@ -0,0 +1,200 @@ +--- +title: "P3-CS-18 convert-witness: the shipped opportunity-converter face adjudicated over planted signature calls" +format: html-vignette +--- + +## Decision record: what the converter face promises, and what its receipts look like + +::: {.callout .callout-note} +**Decision.** CS-18 is a witness, not a specification: it freezes what the +exported `ms_convert()` generic and its `MsSignature` method actually +adjudicate over planted signature-and-opportunity calls, 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 +converter is pure R over a bundled frequency table -- no file path beyond +the packaged extdata, no clock and no RNG touches its verdicts -- so the +ledger was DET-proved byte-stable across probe reruns. But the ACCEPTED +arms return a real float matrix: the face divides by the source +opportunities and multiplies by the target ones, so the return is a +`double` matrix whose kernel round-trip error measures ~1e-16. Under the +D11 cross-platform posture no float payload can ride a byte-committed +column, so the accepted renders commit a DISCRETE column-sum GLYPH +(`0`/`1`/`?` at a 1e-9 threshold, seven orders above the observed float +error) instead of the numbers themselves; integer, label, logical, class +and clause bytes are byte-committed, floats are censused finite/in-domain +only. The lane also refuses its own sketches: the census and ordering +claims below are read from the committed witnesses, not from the build +plan -- the runner's own degen rail caught a clause-head literal that had +been drafted one word short (see the honest section) before any witness +byte was burned. +::: + +### The face + +`ms_convert(signatures, from = "human-genome", to = "human-exome")` is the +exported S7 generic that re-expresses SBS96 signatures relative to a +different mutation-opportunity vector (the sigfit `convert_signatures` +semantics: divide by the source opportunities, multiply by the target +ones, re-normalize each column). It accepts a `96 x k` numeric matrix with +SBS96 registry rownames, or an `MsSignature`; the `from`/`to` arguments +each accept a bundled table name (`"human-genome"`, `"human-exome"`) or a +custom numeric vector of 96 positive finite frequencies, named by the +registry labels or matching the signature rownames. The resolver +`.ms_convert_resolve_opps()` runs TWICE -- once for `from`, once for `to` +-- so the two option arguments carry the same ten-arm validator under two +argument names, and the two abort classes split cleanly: a bad bundled +name is `msuiter_error_option`, everything else (shape, length, label +match, positivity, the signature matrix itself) is `msuiter_error_input`. +CS-18 fires 38 observation arms at it plus eight boundary-pair rows: 10 +law arms, 10 acceptance specs, 10 precedence discriminators, 8 degenerate +rows (4 pairs), 10 scalars. The committed lane replays every arm live: the +law file adjudicates 233 expectations across 10 units (0 failed, 0 errors, +0 skipped, 0 warnings) and the runner rails every row against the frozen +block before any witness byte is written. + +### The two option laws -- one validator, two argument names + +The `from`-and-`to` split is the face's signature move, and the witness +commits it as measured. The unknown-bundled-name arm fires the SAME clause +body under each name, differing only in the leading head -- "from must be +a bundled table or a custom frequency vector" against "to must be a +bundled table or a custom frequency vector" -- and both speak the shared +[V]-discipline bullet ("panel opportunities are expected as a custom +96-vector ([V] discipline: no bundled panel table)"). The degenerate +`fromopt-vs-toopt` pair pins the two by their own clause HEADS (the +boundary contrast assertion reads `head1()` of each, split on `" | "`), +so a drift that collapsed the two heads into one reddens the lane. The +precedence roster measures the resolution ORDER: `from` resolves before +`to` (PR3), and each option law is outranked by the signature-shape law +(PR1) and the rownames law (PR2) -- the signature matrix is checked before +either opportunity argument is touched. + +### The laws the face demonstrates + +- **The bundled-name law.** A character scalar that is not one of the two + bundled tables refuses as `msuiter_error_option`, naming the bundled + roster it saw ("received: 'nope'; bundled: human-genome, human-exome"). + The panel bullet carries the [V]-discipline clause verbatim: panel + opportunities must ride as a custom 96-vector, there is no bundled panel + table. +- **The single-column law.** A numeric MATRIX argument with more than one + column refuses as `msuiter_error_input` -- "from matrix must have exactly + one frequency column" / "the opportunity is a single 96-vector, not + per-signature" -- with the received column count ("received: 2 columns") + and the repeat-it-yourself remedy. A one-column matrix is dropped to a + vector and rides the acceptance path (the `onecol-vs-multicol` degen + pair). +- **The length law.** A vector whose length is not 96 refuses -- "from must + be a frequency vector over the 96 channels" -- carrying the received + length ("received length: 10") and the name-or-table remedy. +- **The label law.** Names that are present but do not equal the registry + labels refuse -- "from names must equal the SBS96 registry labels" -- + naming the first three received names and the by-label-never-by-position + bullet. Names absent entirely are ACCEPTED (the resolver aligns by + position when `names(opps)` is `NULL`). +- **The positivity law.** A non-finite or non-positive entry refuses -- + "from must be positive and finite" -- counting the offending entries + against the "an opportunity of 0 makes the division undefined" bullet. +- **The signature laws.** A non-numeric or non-matrix `signatures` + argument refuses -- "signatures must be a numeric matrix" -- naming the + received class and the `96 x k` remedy; a matrix whose rownames are + missing or out of canonical order refuses -- "signatures must carry the + SBS96 registry rownames in canonical order" -- naming the first three + rownames (or "rownames missing") and the by-label bullet. +- **Precedence.** Ten discriminators, each with its fires anchor pinned + PRESENT and its anti anchor pinned ABSENT in the same live message -- + signature-shape before the `from` option law, rownames before the `to` + option law, `from` before `to`, length before labels, and the + multi-column law before the label law. +- **The acceptance specs.** The canonical `96 x 3` matrix render commits + its full identity line (`matrix|96x3|double|TRUE|S1,S2,S3|1,1,1`) -- the + `TRUE` committing that rownames are present and canonical, the + `S1,S2,S3` the column roster, and `1,1,1` the discrete column-sum glyph + (every column still sums to 1). A zero column commits its `0` glyph + (`1,0,1`); an integer-vector plant commits the `double` storage glyph + exactly where a silent coercion would erase it; and replaying the + committed spec through `ms_convert()` reproduces it byte-for-byte -- the + replay-identity spec welds two renders with `==`. The `MsSignature` + method commits the S7 branch (`MsSignature|96x3|double|1,1,1|3x2`, the + `3x2` being the exposure shape carried through untouched). + +### The receipts + +| receipt | committed bytes | +|---|---| +| `cs18_specs.tsv` | 10 accepted arms: class token `s7:matrix` (eight matrix accepts) or `s7:msuiter::MsSignature` (the S7 branch) plus the full identity rendering (shape, storage glyph, canonical-rownames bit, column roster, discrete glyph) and the `s7:character` replay identity | +| `cs18_laws.tsv` | 10 arms: class split `msuiter_error_option` (the two bundled-name arms) and `msuiter_error_input` (the eight shape/length/label/positivity/signature arms), every clause verbatim, every mode `reject` | +| `cs18_precedence.tsv` | 10 discriminators, each with its fires anchor PRESENT and its anti anchor ABSENT in the live message | +| `cs18_degenerates.tsv` | 4 boundary pairs (8 rows): the accepted zero-column glyph against the restored full column, the accepted one-column `from` matrix against the two-column one, the `from`-option law against the `to`-option law by their own heads, the shape law against the label law -- hi and lo committed side by side | +| `cs18_scalars.tsv` | 10 keys: the abort class, both renders, both storage glyphs, the round-trip-under-tolerance and same-under-tolerance verdicts, and both RNG-purity rails (the adjudication core never seeds) | + +The 38-row class census (`msuiter_error_input=17`, `msuiter_error_option=8`, +`s7:matrix=11`, `s7:msuiter::MsSignature=1`, `s7:character=1`, over the four +committing rosters) is recomputed from the frozen vectors inside the law +file -- a silent class shift reddens the lane, not the reader. All five +witnesses byte-reproduce on consecutive runner invocations, the plant and +spec corpora hash identically under BOTH governed SHA-256 kernels +(`.ms_fit_sha256` and digest), and the lane never touches the RNG, the +network, the benchmark driver, the declined calibration family, or any +unexported internal (banned-word rails over the hand-written region, +marker-scoped and grepped). + +### The single-source build, and the audit that became the minter + +Both hosts -- law file and runner -- carry one byte-identical frozen block +and one byte-identical shared code block, each injected from a single +source between BEGIN/END markers; the splice rail demands the exact marker +counts and compares the two regions across the files byte for byte. The +minter IS the audit: every one of the 38 roster plants and the 8 +text-twins is re-fired LIVE through the canonical pipeline against the +audited probe ledger (38 rows, 20 rejects / 18 accepts, DET across two +probe runs); each of the 10 precedence-path arms carries an explicit +decision-record path whose FIRES/ANTI alignment is asserted +order-invariantly; every scalar is re-fireable and re-fired; and a final +RE-AUDIT re-sources the EMITTED block into a cleared namespace and +re-compares every committed literal against the ledger -- so emitter +drift, chunking drift and quoting drift all die at mint time, not at read +time. The committed clause bytes in this page are read from the committed +witnesses, never re-typed from plan. + +### What the lane-building itself caught (the honest section) + +The live replay killed a would-be-innocent bug before one witness byte was +trusted. The runner's degenerate rail for the `fromopt-vs-toopt` pair had +been drafted to compare `head1(.w("from-bad-hi"))` against the literal +`"from must be a bundled table"` -- one clause short. But `head1()` splits +the message on `" | "` and returns the WHOLE first clause, which is "from +must be a bundled table or a custom frequency vector". The first runner +invocation died on the rail's own `stopif` ("degen: the from-option head +moved") -- the rail caught its own draft, exactly as intended. The fix was +applied to BOTH the runner tail and the U7 unit in the assemblers (never +hand-edited in place) and the lane regenerated: the boundary contrast now +compares the true clause heads, and the runner reached `OVERALL PASS`. The +incident is why the boundary-contrast assertions are split `" | "`-aware +rather than substring-based: a substring rail would have passed the short +literal vacuously. + +### Provenance + +The frozen block and the shared code block in both hosts are minted +mechanically from the audited probe ledger (audit green: 38 arms +byte-exact on live re-fire, 8 degen twins, 10/10 fires-and-anti anchors, +10 scalars re-fired); neither is ever hand-edited in place. The plants' +canonical texts hash to the committed dual-kernel checksum +(`plant_sha256=8956916dfe9065c5...`, `spec_sha256=82469f962fbe4a3b...`); +reifying the lane reproduces every witness byte for byte. Differentiation +from CS-17 (the governance-container face): CS-17 adjudicated an in-memory +container behind S7 property gates; CS-18 adjudicates a converter whose +accepted arms return a real matrix and whose two option arguments carry +one validator under two names -- the D11 posture therefore rides a DISCRETE +column-sum glyph, the first witness class in the series that had to commit +a glyph rather than a class token for its accepting arms. + +### Gate forensics + +The scenarios leg for this lane (the seventeenth) was render-verified +before the full local burn. The T0 seal moved 626 -> 627 with the +generator's refusal witnessed verbatim (the DEFECT line naming 627 against +the sealed 626, run against a doctored budget) before the deliberate +re-seal, per the budget law; the reified manifest carries 112 files, the +new law file on shard 4, byte-deterministic on re-mint. diff --git a/vignettes/articles/paper-draft.qmd b/vignettes/articles/paper-draft.qmd index d858aa5..e08d3d5 100644 --- a/vignettes/articles/paper-draft.qmd +++ b/vignettes/articles/paper-draft.qmd @@ -624,6 +624,37 @@ contract behavior on planted truth -- no extraction, benchmark or reference-content claim. Zero new machinery. Authority: vignettes/articles/devlog-2026-11-23-p3-cs17-catalog-witness.qmd. +- **CS-18 convert-witness, decision record** (`bench/scenarios/run_convert_witness.R`): +the exported opportunity-converter face `ms_convert()` -- the S7 generic that +re-expresses SBS96 signatures between mutation-opportunity vectors (divide by +the source, multiply by the target, re-normalize), accepting a registry-named +`96 x k` numeric matrix or an `MsSignature` under the two option arguments +`from`/`to` -- adjudicated over planted signature-and-opportunity calls. One +validator serves both option names: the ten-arm resolver runs twice, so a bad +bundled name speaks `msuiter_error_option` under the leading head "from must be +a bundled table or a custom frequency vector" or its "to must be..." twin +(sharing the [V]-discipline panel bullet verbatim), and every shape, length, +label, positivity and signature-matrix law speaks `msuiter_error_input`; the +degenerate `fromopt-vs-toopt` pair pins the two heads apart by `head1()` so a +collapse reddens the lane. Ten precedence discriminators each pin +fires-anchor-present/anti-anchor-absent (signature-shape outranks both option +laws, rownames outranks the `to` law, `from` resolves before `to`, length +outranks labels, the multi-column law outranks labels); four boundary pairs +commit the accepted zero-column glyph (`1,0,1`) against the restored full +column (`1,1,1`), the accepted one-column `from` matrix against the two-column +refusal, and the two option laws by their own heads. Because the accepted arms +return a real float matrix (kernel round-trip error ~1e-16), the D11 +cross-platform posture commits a DISCRETE column-sum glyph in place of the +payload -- the first witness in the series to commit a glyph rather than a +class token for its accepting arms -- with the canonical matrix render +(`matrix|96x3|double|TRUE|S1,S2,S3|1,1,1`), the S7 branch render +(`MsSignature|96x3|double|1,1,1|3x2`) and the `s7:character` replay identity +welding two renders of the committed spec with `==` (233 expectations across 10 +units, zero failures/errors/skips/warnings). Decision-record posture: the +converter's contract behavior on planted truth -- no extraction, benchmark or +reference-content claim. Zero new machinery. Authority: +vignettes/articles/devlog-2026-11-25-p3-cs18-convert-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 diff --git a/vignettes/docs-bridge.Rmd b/vignettes/docs-bridge.Rmd index f251000..e27e694 100644 --- a/vignettes/docs-bridge.Rmd +++ b/vignettes/docs-bridge.Rmd @@ -168,3 +168,4 @@ guides), start at [Get started](get-started.html) and the [tour](tour.html). | [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` | | [CS-16 ard-witness — the shipped ARD engine descriptor adjudicated over planted constructor calls: the double-gate split as measured, the discovered abort-plumbing class, the (named)-params permissiveness, the welded seed domain, and eight precedence discriminators (reified, paper-grade)](devlog-2026-11-23-p3-cs16-ard-witness.html) | `devlog-2026-11-23-p3-cs16-ard-witness` | | [CS-17 catalog-witness — the shipped governance-container face adjudicated over planted catalog calls: the double-gate boundary measured at three, the class-any counts rail, the derived-hash law, the reversed typed-NA fixture trap, and ten precedence discriminators (reified, paper-grade)](devlog-2026-11-23-p3-cs17-catalog-witness.html) | `devlog-2026-11-23-p3-cs17-catalog-witness` | +| [CS-18 convert-witness — the shipped opportunity-converter face adjudicated over planted signature calls: one validator under two option names, the option-vs-input class split, the discrete column-sum glyph under the D11 float posture, and ten precedence discriminators (reified, paper-grade)](devlog-2026-11-25-p3-cs18-convert-witness.html) | `devlog-2026-11-25-p3-cs18-convert-witness` |