feat: patch registry + wiring for per-package patching #103
1 changed files with 51 additions and 0 deletions
feat(patches): add registry validator script
commit
e3e219e095
51
local/validate-patches.R
Normal file
51
local/validate-patches.R
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#!/usr/bin/env Rscript
|
||||||
|
# Validate local/patches/registry.json: schema, referenced patch files, and
|
||||||
|
# ambiguous overlaps. Exits 1 on any problem. Used by pre-commit and CI.
|
||||||
|
|
||||||
|
dir <- "local/patches"
|
||||||
|
registry_file <- file.path(dir, "registry.json")
|
||||||
|
if (!file.exists(registry_file)) {
|
||||||
|
cat("No registry.json found; nothing to validate.\n")
|
||||||
|
quit(status = 0L)
|
||||||
|
}
|
||||||
|
|
||||||
|
reg <- jsonlite::fromJSON(registry_file, simplifyVector = FALSE)
|
||||||
|
required <- c("package", "versions", "platforms", "reason")
|
||||||
|
errs <- character(0L)
|
||||||
|
|
||||||
|
for (i in seq_along(reg)) {
|
||||||
|
e <- reg[[i]]
|
||||||
|
missing <- setdiff(required, names(e))
|
||||||
|
if (length(missing) > 0L) {
|
||||||
|
errs <- c(errs, sprintf(
|
||||||
|
"entry %d (%s): missing %s", i,
|
||||||
|
if (is.null(e$package)) "?" else e$package, toString(missing)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
if (!is.null(e$patch)) {
|
||||||
|
p <- file.path(dir, e$patch)
|
||||||
|
if (!file.exists(p)) {
|
||||||
|
errs <- c(errs, sprintf("entry %d (%s): patch file '%s' missing",
|
||||||
|
i, e$package, p))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ambiguous overlap: two entries for the same package with identical platforms
|
||||||
|
# and versions.
|
||||||
|
keys <- vapply(reg, function(e) {
|
||||||
|
sprintf("%s|%s|%s", e$package,
|
||||||
|
paste(sort(as.character(unlist(e$platforms))), collapse = ","),
|
||||||
|
e$versions)
|
||||||
|
}, character(1L))
|
||||||
|
dups <- keys[duplicated(keys)]
|
||||||
|
if (length(dups) > 0L) {
|
||||||
|
errs <- c(errs, sprintf("ambiguous duplicate entries: %s", toString(unique(dups))))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length(errs) > 0L) {
|
||||||
|
cat("Patch registry validation FAILED:\n")
|
||||||
|
cat(paste0(" - ", errs, "\n"))
|
||||||
|
quit(status = 1L)
|
||||||
|
}
|
||||||
|
cat(sprintf("Patch registry OK (%d entrie(s)).\n", length(reg)))
|
||||||
Loading…
Reference in a new issue