Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/calibrate-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,17 @@ plot_calibration_curve <- function(calibration_df, window = NULL, se = TRUE) {
"calibration_df$pass_window must be logical without NAs",
i = "hand-built tables must pass the kernel verdict column verbatim",
j = paste0("class: ", paste(class(df$pass_window), collapse = "/"),
"; NAs: ", sum(is.na(df$pass_window)))
"; NAs: ", sum(is.na(df$pass_window))),
c = "carry the logical pass_window column through unchanged"
)
}
if (se && anyNA(df$se)) {
msuiter_abort(
"input",
"calibration_df$se must be non-missing when se = TRUE",
j = paste0("NAs: ", sum(is.na(df$se)))
i = "se = TRUE requests the standard-error ribbon",
j = paste0("NAs: ", sum(is.na(df$se))),
c = "populate the se column or pass se = FALSE"
)
}
fail <- df[!df$pass_window, , drop = FALSE]
Expand Down
8 changes: 6 additions & 2 deletions R/engines-ard.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,19 @@ ms_ard <- function(a0 = 10, b0 = 5, tol = 1e-5, max_iter = 2000, seed = 1) {
msuiter_abort(
"input",
"counts must be a numeric matrix",
i = "the ARD kernel consumes the MsCatalog counts slot (transposed to t(counts) for the FFI)"
i = "the ARD kernel consumes the MsCatalog counts slot (transposed to t(counts) for the FFI)",
j = paste0("received: ", class(counts)[1L]),
c = "pass a channels x samples numeric matrix"
)
}
if (!is.numeric(k0) || length(k0) != 1L || is.na(k0) || k0 < 1 ||
k0 != floor(k0)) {
msuiter_abort(
"input",
"`k0` must be a single positive whole number",
i = paste0("got: ", format(k0))
i = "k0 is the number of components the ARD kernel estimates",
j = paste0("got: ", format(k0)),
c = "pass a whole number k0 >= 1"
)
}
ms_ard_rust(
Expand Down
8 changes: 6 additions & 2 deletions R/engines-sparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,19 @@ ms_sparse <- function(variant = "l1", lambda = 0, mu = 0,
msuiter_abort(
"input",
"counts must be a numeric matrix",
i = "the sparse kernel consumes the MsCatalog counts slot (transposed to t(counts) for the FFI)"
i = "the sparse kernel consumes the MsCatalog counts slot (transposed to t(counts) for the FFI)",
j = paste0("received: ", class(counts)[1L]),
c = "pass a channels x samples numeric matrix"
)
}
if (!is.numeric(k) || length(k) != 1L || is.na(k) || k < 1 ||
k != floor(k)) {
msuiter_abort(
"input",
"`k` must be a single positive whole number",
i = paste0("got: ", format(k))
i = "k is the number of components the sparse kernel estimates",
j = paste0("got: ", format(k)),
c = "pass a whole number k >= 1"
)
}
ms_sparse_rust(
Expand Down
1 change: 1 addition & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ S7::method(ms_fit_bootstrap, S7::class_any) <- function(catalog, signatures,
msuiter_abort(
"input",
"bca must be a single TRUE or FALSE",
i = "bca selects the bias-corrected accelerated bootstrap interval",
j = paste0("received: ", msuiter_quote_trunc(bca)),
c = "leave the default FALSE for the percentile interval only"
)
Expand Down
1 change: 1 addition & 0 deletions R/ms-compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
msuiter_abort(
"input",
"n_draws must be a single whole number >= 200",
i = "n_draws is the Monte Carlo draw count for the null tail",
j = paste0("received: ", msuiter_quote_trunc(n_draws)),
c = "the add-one tail estimate needs a usable denominator"
)
Expand Down
1 change: 1 addition & 0 deletions R/ms-convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ms_convert <- S7::new_generic(
msuiter_abort(
"input",
sprintf("%s must be a frequency vector over the 96 channels", arg_nm),
i = "an opportunity vector is one frequency per registry channel",
j = sprintf("received length: %d", length(opps)),
c = "name it by the registry labels or pass a bundled table name"
)
Expand Down
3 changes: 2 additions & 1 deletion R/viz-bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ plot_boot_stability <- function(fit, sample = 1L) {
"input",
"sample must be an index or a column name",
i = "one sample per CI face",
j = paste0("received: ", msuiter_quote_trunc(sample))
j = paste0("received: ", msuiter_quote_trunc(sample)),
c = "pass an in-range index or an existing colname"
)
}

Expand Down
17 changes: 13 additions & 4 deletions R/viz-profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,20 @@ plot_reconstruction_panel <- function(counts, signatures, exposures,
msuiter_abort(
"input",
"counts and signatures must share the canonical channel order",
j = sprintf("rows: %d vs %d", length(pc$labels), length(ps$labels))
i = "observed and fitted profiles must share one channel axis",
j = sprintf("rows: %d vs %d", length(pc$labels), length(ps$labels)),
c = "pass counts and signatures over the same channel table"
)
}
exposures <- as.matrix(exposures)
if (nrow(exposures) != ncol(ps$matrix)) {
msuiter_abort(
"input",
"exposures rows must match the signature columns",
i = "the fitted profile multiplies signatures by exposures",
j = sprintf("exposures rows: %d; signatures: %d",
nrow(exposures), ncol(ps$matrix))
nrow(exposures), ncol(ps$matrix)),
c = "pass exposures with one row per signature column"
)
}
fitted <- as.numeric(ps$matrix %*% exposures)
Expand Down Expand Up @@ -289,6 +293,7 @@ plot_reconstruction_panel <- function(counts, signatures, exposures,
msuiter_abort(
"input",
"profile input must be a numeric matrix (or named vector, or MsSignature)",
i = "the profile faces read one numeric m x k matrix",
j = paste0("received: ", class(matrix)[1L]),
c = "pass m x k with canonical registry rownames"
)
Expand Down Expand Up @@ -355,8 +360,10 @@ plot_reconstruction_panel <- function(counts, signatures, exposures,
msuiter_abort(
"input",
"column index out of range",
i = "column selects one profile column",
j = sprintf("requested: %s; columns: %d",
msuiter_quote_trunc(idx), ncol(matrix))
msuiter_quote_trunc(idx), ncol(matrix)),
c = "pass an index in [1, ncol]"
)
}
return(idx)
Expand All @@ -367,7 +374,9 @@ plot_reconstruction_panel <- function(counts, signatures, exposures,
msuiter_abort(
"input",
"requested column names are absent",
j = paste0("missing: ", msuiter_quote_trunc(missing))
i = "columns are addressed by the matrix colnames",
j = paste0("missing: ", msuiter_quote_trunc(missing)),
c = "pass existing colnames or integer indices"
)
}
return(match(columns, cn))
Expand Down
107 changes: 107 additions & 0 deletions tests/testthat/test-abort-contract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# The abort-contract law (R/classes-utils.R docs; ARCHITECTURE section 3.5):
# every `msuiter_abort()` call passes the mandatory i/j/c three-part payload,
# so a violation raises the structured `msuiter_error_<topic>` condition (the
# `msuiter_error` payload plus the three message bullets) rather than a bare
# base-R `missingArgError`/`getvarError` whose message prints in the locale's
# language and carries no payload.
#
# A missing argument parses cleanly, so no reader that only inspects present
# tokens can see it: the 2026-11-24 sweep found 15 sites in R/ that passed two
# or three of the five names (a genuine residual -- an earlier commit fixed the
# property validators but not the counts/k0/k guards). This file is the reader
# that sees the absence.

# Census one source text: a data.frame(line, missing) over every
# msuiter_abort() call whose argument list omits any of i/j/c. getParseData
# yields byte-true line numbers and nesting, so a NESTED call's own commas are
# never read as the outer call's argument separators.
.abort_census_text <- function(text) {
empty <- data.frame(line = integer(0), missing = character(0),
stringsAsFactors = FALSE)
pd <- utils::getParseData(parse(text = text, keep.source = TRUE))
if (is.null(pd) || nrow(pd) == 0L) return(empty)
nr <- nrow(pd)
calls <- which(pd$token == "SYMBOL_FUNCTION_CALL" & pd$text == "msuiter_abort")
if (length(calls) == 0L) return(empty)
out <- lapply(calls, function(r) {
opn <- which(pd$token == "'('" & seq_len(nr) > r)[1L]
if (is.na(opn)) return(NULL)
depth <- 0L
cls <- NA_integer_
for (i in opn:nr) {
tok <- pd$token[i]
if (tok == "'('") depth <- depth + 1L
else if (tok == "')'") {
depth <- depth - 1L
if (depth == 0L) { cls <- i; break }
}
}
if (is.na(cls) || cls <= opn + 1L) return(NULL)
d <- 0L
subs <- character(0L)
for (i in (opn + 1L):(cls - 1L)) {
tok <- pd$token[i]
if (tok == "'('") d <- d + 1L
else if (tok == "')'") d <- d - 1L
else if (tok == "SYMBOL_SUB" && d == 0L) subs <- c(subs, pd$text[i])
}
data.frame(line = pd$line1[r],
missing = paste(setdiff(c("i", "j", "c"), subs), collapse = ","),
stringsAsFactors = FALSE)
})
out <- do.call(rbind, out)
if (is.null(out)) empty else out
}

.abort_root <- function(start = testthat::test_path()) {
d <- normalizePath(start)
while (nzchar(dirname(d)) != nchar(d)) {
f <- file.path(d, "DESCRIPTION")
if (file.exists(f) &&
any(grepl("^Package: msuiter", readLines(f, warn = FALSE)))) {
return(d)
}
d <- dirname(d)
}
# The simulated check layout runs the copied tests as a sibling of the
# package dir -- no DESCRIPTION ancestry there. Absent root is the
# check-context signal, spoken by the sanctioned skip, not a stop.
NA_character_
}

test_that("a census sees a missing i/j/c bullet (firing control)", {
bad <- "f <- function() { msuiter_abort('input', 'msg', i = 'x', j = 'y') }"
expect_identical(.abort_census_text(bad)$missing, "c")
good <- paste0("f <- function() { msuiter_abort('input', 'msg', i = 'x', ",
"j = 'y', c = 'z') }")
expect_false(any(nzchar(.abort_census_text(good)$missing)))
# A nested call's commas belong to the inner list, not the outer arg list.
nest <- paste0("f <- function() { msuiter_abort('input', 'msg', i = 'x', ",
"j = paste(c('a', 'b'), collapse = ','), c = 'z') }")
expect_false(any(nzchar(.abort_census_text(nest)$missing)))
})

test_that("every msuiter_abort() call carries the mandatory i/j/c payload", {
root <- .abort_root()
if (is.na(root)) {
skip(paste0("the abort census parses the R/ sources: requires the source ",
"checkout, which the check layout does not ship ",
"(R CMD check context)"))
}
files <- list.files(file.path(root, "R"), pattern = "[.]R$",
full.names = TRUE)
total <- 0L
offenders <- character()
for (f in files) {
res <- .abort_census_text(paste(readLines(f, warn = FALSE), collapse = "\n"))
total <- total + nrow(res)
bad <- res[nzchar(res$missing), , drop = FALSE]
if (nrow(bad) > 0L) {
offenders <- c(offenders, sprintf("%s:%d (missing %s)", basename(f),
bad$line, bad$missing))
}
}
# Window liveness on the real tree: a scan reading nothing would pass blind.
expect_gt(total, 100L)
expect_identical(offenders, character())
})
6 changes: 5 additions & 1 deletion tools/ci/pr-gate-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
# the T0 roster; witness: local run nb=265 failed=0 error=0 warning=0, measured
# manifest sum 626 (generator refusal witnessed at the pre-seal re-mint
# attempt, the verbatim DEFECT line naming 626 against the sealed 625).
# 2026-11-24 roster addition at constant 626: the abort-contract law row
# (test-abort-contract.R, 0 s integer weight, 5 expects) joined the T0
# roster; witness: local run nb=5 failed=0 error=0 warning=0, elapsed 0.4 s,
# so the measured manifest sum stays 626 (a zero-weight row moves no seal).
key value note
t0-measured 626 measured 2026-11-24 (integer manifest seconds, tier T0; 2026-11-24 seal 625 superseded by the CS-17 row)
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-ceiling 800 t0-measured + one drift class; re-seal deliberately with a witness
1 change: 1 addition & 0 deletions tools/ci/shard-manifest.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shard file seconds tier
4 test-viz-batch2.R 2 T0
4 test-viz-first-batch.R 11 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
Expand Down
1 change: 1 addition & 0 deletions tools/ci/shard-weights.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ test-docs-tour-executable.R 10 28 T0
test-docs-scenarios-prose.R 1 19 T0
test-docs-extending-surface.R 1 20 T0
test-rng-hygiene.R 0 13 T0
test-abort-contract.R 0 5 T0
test-scenario-stratify.R 1 91 T0
test-scenario-downsample.R 1 116 T0
test-scenario-reconstruction.R 1 92 T0
Expand Down
Loading