diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef2643b5a..05d944799 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -434,6 +434,6 @@ jobs: version: "0.12.13" checksum: 745765a3b6e360ad76743599ae5c42e9278c7edf8bbff9fc76d05bf2623a04dd enable-cache: false - - name: Lint docs voice, operator strings, topology classes, file budget, pithead build/trivy parity, then JS/CSS (Biome), YAML, Markdown, proto (buf), TOML (taplo) + - name: Lint docs voice, operator strings, topology classes, bench refs, file budget, pithead build/trivy parity, then JS/CSS (Biome), YAML, Markdown, proto (buf), TOML (taplo) # Single source of truth: the Makefile targets. REPO-LOCAL GATES FIRST (#1746): local checks run before network-backed surface linters. - run: make lint-docs-voice lint-path-references lint-operator-strings lint-topology lint-file-budget lint-pithead-build lint-trivy-parity lint-js lint-yaml lint-md lint-proto lint-toml + run: make lint-docs-voice lint-path-references lint-operator-strings lint-topology lint-bench-refs lint-file-budget lint-pithead-build lint-trivy-parity lint-js lint-yaml lint-md lint-proto lint-toml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 02bee0b14..ac571558e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,6 +96,19 @@ on Linux or macOS with Bash 3.2 or newer, Python 3 and jq; it does not require G `/systemd/system/` is a unit name, not an address; `tests/` and `docs/` are an accepted exemption boundary for illustrative/fixture content, and each class also carries a small, explicit allowlist — see the script's own header — never a per-file exemption comment), + `lint-bench-refs` (the shipped surface — `lib/`, `build/`, `os/`, `dashboard/`, `install.sh`, + the compose file, the CLI completion, the config templates, `README.md` and the ten user docs the + release bundle ships (`docs/{configuration,dashboard,faq,getting-started,hardware,monitoring, + operations,privacy,telegram,workers}.md`) — never names the project's private CI/runner tooling: `bench-ci`/`BENCH_CI`, `pithead-developer`, the `adversarial-review` + status, the `rig-e2e` lock, the `tier4-e2e`/`tier4-kvm` tiers, `CI_JOB_DIR`, or a "bench + job"/"bench runner" — issue #4245; the appliance image and the generated CLI carry every word + they hold to the user's box, and only this gate stops new references creeping back). + Look-alikes that are the product's own vocabulary stay clean: `os/build/stage` paths and shell + stage variables, `pithead-control` and the `X-Pithead-Control` header, generic `PITHEAD_*` + inputs, and `miner-` names in dashboard test fixtures; the bare word `bench`, job ids and + SHAs stay usable. Changelogs narrate release history and sit outside the scan, as do `tests/`, + the other `docs/` pages, CI glue and the release tooling — those talk to the bench by design, so naming it + there is the job, not the coupling), `lint-file-budget` (the file-budget ratchet, issue #1105 Phase 0 — see [File budget gate](#file-budget-gate)), `lint-pithead-build` (the generated `pithead` must build from `lib/pithead/*.sh` in a clean diff --git a/Makefile b/Makefile index f6c48d6c3..959201fbc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .DEFAULT_GOAL := pithead -.PHONY: pithead test test-dashboard test-clearnet-replay-proof test-frontend test-browser test-patch-coverage test-stack test-netwatch test-compose test-integration test-integration-selftest test-tools test-inventory test-bridge-awk test-fakes test-mini-stack test-tari-config-parse test-container lint lint-sh lint-py lint-path-references lint-js lint-yaml lint-md lint-proto lint-toml lint-topology lint-file-budget lint-pithead-build lint-trivy-parity print-shellcheck-version print-shfmt-version release release-smoke +.PHONY: pithead test test-dashboard test-clearnet-replay-proof test-frontend test-browser test-patch-coverage test-stack test-netwatch test-compose test-integration test-integration-selftest test-tools test-inventory test-bridge-awk test-fakes test-mini-stack test-tari-config-parse test-container lint lint-sh lint-py lint-path-references lint-js lint-yaml lint-md lint-proto lint-toml lint-topology lint-bench-refs lint-file-budget lint-pithead-build lint-trivy-parity print-shellcheck-version print-shfmt-version release release-smoke pithead: scripts/build-pithead.sh $(wildcard lib/pithead/*.sh) ## Build the generated CLI bash scripts/build-pithead.sh @@ -128,7 +128,7 @@ print-shellcheck-version: ## Print the pinned shellcheck version (ci.yml's insta print-shfmt-version: ## Print the pinned shfmt version (ci.yml's installer reads this) @echo $(SHFMT_VERSION) -lint: lint-sh lint-py lint-js lint-yaml lint-md lint-docs-voice lint-path-references lint-operator-strings lint-topology lint-file-budget lint-pithead-build lint-trivy-parity lint-proto lint-toml ## Lint/format-check every surface +lint: lint-sh lint-py lint-js lint-yaml lint-md lint-docs-voice lint-path-references lint-operator-strings lint-topology lint-bench-refs lint-file-budget lint-pithead-build lint-trivy-parity lint-proto lint-toml ## Lint/format-check every surface # Shellcheck runs once per file, four at a time (#2632): a single invocation over every # script accumulated memory across files (6.1 GB RSS) and used one core for ~351 s. `-x` @@ -196,6 +196,10 @@ lint-topology: ## Fail if a real-looking IPv6/IPv4/hostname/path/user@host liter bash scripts/lint/lint-topology-classes.sh --self-test bash scripts/lint/lint-topology-classes.sh +lint-bench-refs: ## Fail if a shipped file names the private CI/runner tooling; look-alike allow-list documented in CONTRIBUTING.md (#4245) + bash scripts/lint/lint-bench-refs.sh --self-test + bash scripts/lint/lint-bench-refs.sh + lint-file-budget: ## Fail if a tracked file crosses the 800-line hard ceiling, or an existing offender grows past its docs/dev/file-budget.tsv ceiling (#1105 Phase 0) bash scripts/lint/lint-file-budget.sh --self-test bash scripts/lint/selftest-file-budget-release.sh diff --git a/lib/pithead/01-lifecycle.sh b/lib/pithead/01-lifecycle.sh index 1dead7570..00dac99a6 100644 --- a/lib/pithead/01-lifecycle.sh +++ b/lib/pithead/01-lifecycle.sh @@ -126,13 +126,6 @@ remove_deactivated_profile_containers() { warn "Could not remove the deactivated container(s): ${gone[*]} — remove them manually with 'docker rm -f ${gone[*]}'." } -# #2595: compose recreates a container by creating its replacement as "_", -# removing the old one, then renaming the replacement. A pass that aborts in between (another -# service's start failing cancels the rest) leaves the replacement beside the old container, and a -# later pass removes the old one as surplus but never renames: compose finds the service by label. -# Bench job 840 ran monerod as "4556c4f42f1d_monerod" from then on, so everything that addresses it -# by name (exec, stop, the dashboard's control calls) missed it. Rename such a leftover once its -# name is free; while the old container still holds it, the next pass decides which one survives. restore_recreate_names() { local names name names=$(docker ps -a --filter label=com.docker.compose.project=pithead --format '{{.Names}}' 2>/dev/null) || return 0 diff --git a/os/KNOWN-ISSUES.md b/os/KNOWN-ISSUES.md index 470619931..ed010faaf 100644 --- a/os/KNOWN-ISSUES.md +++ b/os/KNOWN-ISSUES.md @@ -279,7 +279,7 @@ the machine pays in ordinary RAM rather than a restart loop. Only p2pool builds monerod v0.18.5.1 allocates one only when `MONERO_RANDOMX_FULL_MEM` is set or it mines, and the stack does neither (#2681). -The reduced pool's 2048 pages are MEASURED (#2685), not derived: a tier4-e2e run samples each +The reduced pool's 2048 pages are MEASURED (#2685), not derived: an e2e run samples each daemon's own `/proc//smaps_rollup` every 10 s across a synced local-node scenario, lifecycle and auth-fail-closed, and takes the peak — job 1115@701013bb1faaea1a9a337cde16dbe79fbca797d1 measured p2pool at 1305 pages and monerod at 129 (an upper bound: its per-thread verification scratchpads scale with the measuring @@ -287,7 +287,7 @@ bench's own thread count, above a reduced-tier appliance's). Combined peak 1434, processes' second-seed caches (a seed switch is roughly every 2.8 days, so a normal run does not exercise them), +10% margin, rounded up to the next 512-page step: 2048. `tests/integration/lib/hugepage-probe.sh` carries the bound `combined peak + 256 <= REDUCED_PAGES` -as a standing gate row against this same overlay file, on every tier4-e2e run, and #2486 (p2pool +as a standing gate row against this same overlay file, on every e2e run, and #2486 (p2pool `--light-mode` on this tier, which would remove the dataset) reruns the measurement when it lands. Degrades are announced on every console, journaled, and repeated by `doctor` as a WARN — never a FAIL, so the A/B commit gate still commits a degraded-but-serving slot. Running before the boot diff --git a/os/overlay/pithead-hugepages b/os/overlay/pithead-hugepages index 3e5cca385..a2c2f4bdb 100644 --- a/os/overlay/pithead-hugepages +++ b/os/overlay/pithead-hugepages @@ -15,37 +15,6 @@ # the local-miner render declares as headroom. Without the record they would re-inflate the # pool this unit just shrank, on the very same boot. # -# The tiers, and why the low one is "reduced", not "skip": -# >= 15 GiB full 3072 pages (6 GiB). The supported machine; nothing to say. -# >= 7 GiB 2048 pages (4 GiB), MEASURED (#2685, tier4-e2e job -# 1115@701013bb1faaea1a9a337cde16dbe79fbca797d1, targeted mode: the scenario, -# auth-fail-closed, lifecycle and the restore), not derived. -# Per-process peaks over the whole run, from each daemon's own -# /proc//smaps_rollup (never a HugePages_Free delta — the e2e bench's pool -# has other tenants): -# p2pool 1305 pages peak (2,672,640 KiB), up to 47 threads. Its dataset is -# the only one either process builds at the pinned versions. -# monerod 129 pages peak (264,192 KiB), up to 30 threads on the measuring -# bench — an upper bound: its per-thread verification scratchpads -# scale with thread count, and the bench's exceeds a reduced-tier -# appliance's 7-15 GiB class. -# Combined peak 1434 pages. + 256 for the two processes' second-seed caches -# (128 each), which a run this long is not guaranteed to touch (a seed switch is -# every ~2048 blocks, ~2.8 days) = 1690. + 10% margin = 1859, rounded up to the -# next 512-page (1 GiB) step = 2048. tests/integration's live harness carries the -# bound `combined peak + 256 <= REDUCED_PAGES` as a standing gate row, checked -# against this same file, on every tier4-e2e run. -# Since #2562 raised p2pool's container cap to 4g, a HugePages shortfall no -# longer restart-loops it (that was the #78 finding this tier exists to avoid): -# it now runs on ordinary memory instead, silently, which is what the gate row's -# "no instance held zero pages for 300s+" check catches. -# Sized for today's full-mode p2pool; #2486 (p2pool --light-mode on this tier) -# would remove its dataset, the largest term above, and reruns this measurement -# when it lands. -# below 0 pages: no reservation at all leaves more RAM than any reduced pool could, -# and the stack cannot run in what remains either way. Releasing it keeps the -# machine itself responsive enough to tell the operator what is wrong. -# # A degraded boot leaves a two-line marker in /run (volatile on purpose — RAM cannot change # without a reboot): the operator prose first, then "pages=N", the machine-readable record of # the decision. doctor's memory section repeats the prose as a WARN, never a FAIL: the A/B diff --git a/scripts/lint/lint-bench-refs.sh b/scripts/lint/lint-bench-refs.sh new file mode 100644 index 000000000..3f9bb445b --- /dev/null +++ b/scripts/lint/lint-bench-refs.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +set -euo pipefail + +TARGETS=(pithead lib build os dashboard install.sh docker-compose.yml pithead-completion.bash README.md docs/configuration.md docs/dashboard.md docs/faq.md docs/getting-started.md docs/hardware.md docs/monitoring.md docs/operations.md docs/privacy.md docs/telegram.md docs/workers.md config.reference.json config.minimal.json config.core-keys.json) +EXCLUDES=(':(exclude,glob)**/CHANGELOG*.md') +PATTERN='bench[-_]ci|pithead-developer|adversarial-review|rig-e2e|tier4-(e2e|kvm)|CI_JOB_DIR|bench job|bench runner' + +enumerate() { + git ls-files -z -- "${TARGETS[@]}" "${EXCLUDES[@]}" +} + +enforce_nonempty_enumeration() { + if [ -z "$(enumerate | head -c1)" ]; then + echo "FATAL: git ls-files enumerated zero shipped-surface files. Run from the repo root; a" >&2 + echo "broken enumeration and a clean tree both scan zero hits — refusing to report either as success." >&2 + return 1 + fi + return 0 +} + +scan() { + local out rc=0 + out=$(grep -HniIE -e "$PATTERN" -- "$@" 2>/dev/null) || rc=$? + if [ "$rc" -ge 2 ]; then + echo "FATAL: grep failed (exit $rc) while scanning; refusing to report a failed scan as clean." >&2 + exit 2 + fi + printf '%s' "$out" | cut -c1-200 +} + +run() { + local -a files + mapfile -d '' -t files < <(enumerate) + local hits + hits=$(scan "${files[@]}") + if [ -n "$hits" ]; then + printf 'bench-refs: a shipped file names the private CI/runner tooling. Name the behaviour, the tier role or the job id instead — the bare word "bench", job ids and SHAs are fine (allow-list rationale: CONTRIBUTING.md, lint-bench-refs):\n' + printf '%s\n' "$hits" + return 1 + fi + echo "bench refs OK — no CI/runner tooling reference among ${#files[@]} shipped files" + return 0 +} + +if [ "${1:-}" = "--self-test" ]; then + tmp=$(mktemp -d) + trap 'rm -rf "$tmp"' EXIT + st_fail=0 + expect() { + if [ "$2" = hit ] && [ -z "$3" ]; then + echo " self-test FAIL: $1 (expected a hit, got none)" + st_fail=1 + elif [ "$2" = hits ] && [ "$(printf '%s\n' "$3" | grep -c .)" -ne "$4" ]; then + echo " self-test FAIL: $1 (expected $4 flagged lines, got $(printf '%s\n' "$3" | grep -c .))" + st_fail=1 + elif [ "$2" = clean ] && [ -n "$3" ]; then + echo " self-test FAIL: $1 (expected clean, got: $3)" + st_fail=1 + else echo " self-test ok: $1"; fi + } + + printf 'bench-ci runs this job\nBENCH_CI_APP_ID gates the release\npithead-developer files the runner\nadversarial-review gates the merge\nthe rig-e2e lock serialises rigs\ntier4-e2e targeted builds the branch\ntier4-kvm boots the image\nCI_JOB_DIR names the receipt dir\nBench Job 840 reran the leg\na bench runner queued the job\nbench_ci lower underscore form\n' >"$tmp/hits.txt" + expect "every refused token and word form, in either case, is flagged" hits "$(scan "$tmp/hits.txt")" 11 + + printf 'cp os/build/stage/docker-compose.yml into the image; stage="$(mktemp -d)"; RESTORE_STAGE_DIR="$stage"; STAGE_ONLY=1\nsystemctl restart pithead-control.path pithead-control.service\nheaders["X-Pithead-Control"] = "1" # CSRF guard\nPITHEAD_OLD_IMAGE=/images/old.img PITHEAD_REGISTRY=ghcr.io\n{"name": "miner-1", "status": "online"}\nthe e2e bench ran job 1115@701013bb1faaea1a9a337cde16dbe79fbca797d1 in targeted mode and the machine benchmarks fine\n' >"$tmp/clean.txt" + expect "os/build/stage paths and stage variables, pithead-control and X-Pithead-Control, generic PITHEAD_* inputs, miner-N fixtures and the bare words are not flagged" clean "$(scan "$tmp/clean.txt")" + + SELF="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" + + sfx=".sh" + legrel="os/overlay/leg$sfx" + repo="$tmp/shiprepo" + mkdir -p "$repo/os/overlay" "$repo/tests/integration" + git -C "$repo" init -q . + printf 'image built here\n' >"$repo/os/README.md" + printf 'bench-ci #1 pins this selftest\n' >"$repo/tests/integration/selftest-x$sfx" + git -C "$repo" add -A + if (cd "$repo" && bash "$SELF") >"$tmp/scope-out.txt" 2>&1; then + echo " self-test ok: a bench-ci reference in tests/ is that file's job, not coupling, and is not flagged" + else + echo " self-test FAIL: a tests/-only tree was flagged or failed: $(cat "$tmp/scope-out.txt")" + st_fail=1 + fi + printf '# Bench job 840 reran the leg\ntier4-e2e targeted\n' >"$repo/$legrel" + git -C "$repo" add -A + if (cd "$repo" && bash "$SELF") >"$tmp/scope-out.txt" 2>&1 && grep -q "$legrel" "$tmp/scope-out.txt"; then + echo " self-test FAIL: a reference inside the shipped surface did not fail the gate" + st_fail=1 + elif grep -q "$legrel" "$tmp/scope-out.txt"; then + echo " self-test ok: a reference inside the shipped surface fails the gate and names the file" + else + echo " self-test FAIL: the gate failed without naming the shipped file: $(cat "$tmp/scope-out.txt")" + st_fail=1 + fi + + emptyrepo="$tmp/emptyrepo" + mkdir -p "$emptyrepo" + git -C "$emptyrepo" init -q . + printf 'x\n' >"$emptyrepo/Makefile" + git -C "$emptyrepo" add -A + if (cd "$emptyrepo" && bash "$SELF") >/dev/null 2>"$tmp/empty-stderr.txt"; then + echo " self-test FAIL: an empty shipped-surface enumeration did not fail loudly" + st_fail=1 + elif grep -q FATAL "$tmp/empty-stderr.txt"; then + echo " self-test ok: an empty shipped-surface enumeration fails loudly instead of reading as clean" + else + echo " self-test FAIL: the empty-enumeration run failed, but not with the FATAL guard message" + st_fail=1 + fi + + [ "$st_fail" -eq 0 ] && { + echo "lint-bench-refs self-test OK" + exit 0 + } + echo "lint-bench-refs self-test FAILED" + exit 1 +fi + +enforce_nonempty_enumeration +run