diff --git a/docs/dev/file-budget.tsv b/docs/dev/file-budget.tsv index 17f1a7548..b11d084fe 100644 --- a/docs/dev/file-budget.tsv +++ b/docs/dev/file-budget.tsv @@ -57,7 +57,7 @@ lib/pithead/49-control-request-loop.sh 402 scripts/build-pithead-selftest.sh 416 scripts/watch/scheduled-run-watch.sh 416 scripts/watch/trivyignore-watch.sh 599 -tests/integration/e2e.sh 684 +tests/integration/e2e.sh 658 tests/integration/fakes/test_contract.py 437 tests/integration/lib.sh 686 tests/integration/lib/live-upgrade-support.sh 413 @@ -71,7 +71,7 @@ tests/integration/selftest/selftest-rigforge-writable-keys.sh 402 tests/integration/selftest/selftest-zmq-probe.sh 431 tests/integration/selftest/selftest.sh 685 tests/os/appliance-approval-verdict.sh 449 -tests/os/appliance-node-runtime-leg.sh 448 +tests/os/appliance-node-runtime-leg.sh 438 tests/os/failure-evidence.sh 567 tests/os/phases/install-restore.sh 414 tests/os/phases/rig.sh 448 diff --git a/docs/dev/integration-testing.md b/docs/dev/integration-testing.md index 6be320e7d..37d599542 100644 --- a/docs/dev/integration-testing.md +++ b/docs/dev/integration-testing.md @@ -393,6 +393,16 @@ via an `EXIT` trap): `/opt/rigforge/data/e2e-backups/` (created mode 700, owned by the SSH login user — never inside the RigForge worker build directory, which a worker upgrade archives away) and repoints it at the bench so the matrix has a real worker mining through this stack (1 worker → run with `--workers 1`). + A pool the harness inserts carries `rig-id` `pithead-e2e`. A rig whose config already names the + bench keeps that pool and its own `rig-id` unchanged, so the dashboard and the rig-control phase + still find the rig under its own name. The reload restarts the rig's `xmrig` unit (a + root-run unit may only be allowed `stop` then `start`) and fails unless the unit's MainPID changed; + there is no signal fallback, since a signal proves no reload. Every worker gate + after a borrow or re-arm waits for an online worker named after the bench pool's `rig-id`, or its + stratum `user` when that is empty (the name xmrig-proxy lists it under), so another worker on the + proxy cannot satisfy it. The gate's log lines never print that name, because a stratum `user` can + be a payout address. A bench pool with neither, or a name outside `[A-Za-z0-9._:@+-]`, falls back + to counting proxy workers, with a warning ([#3972](https://github.com/p2pool-starter-stack/pithead/issues/3972)). With `--no-miner` nothing is borrowed, and the harness runs with `--no-mining-asserts`: the workers-online and stratum-hashes assertions skip with a logged notice while every other assertion stays binding ([#905](https://github.com/p2pool-starter-stack/pithead/issues/905)). diff --git a/docs/dev/testing-strategy.md b/docs/dev/testing-strategy.md index 578071fe7..7259c6480 100644 --- a/docs/dev/testing-strategy.md +++ b/docs/dev/testing-strategy.md @@ -585,7 +585,7 @@ the failure means. | Post-provision control on the appliance (#1966): a benign energy edit applies; a disruptive operational edit is refused without typed `APPLY`, applies with it, and is restored. Doctor returns all `{status,message}` rows, including a failed result carrying the complete document when its own exit is nonzero with monerod deliberately stopped. A p2pool tail is clamped to 200 lines/65,536 bytes, records an applied result when the byte cap closes its pipe, and redacts the known payout address; wallet-rpc logs remain refused | `tests/os/appliance-diagnostics-leg.sh` + battery `--phase provision` | 1 ✅ (verdict failure controls plus control/diagnostics route and host-runner suites) · 4 (added — unverified until the combined battery) | | Dashboard backup recovery (#1965/#1966): the control request survives its own dashboard restart, returns a downloadable encrypted archive plus one-time passphrase, and leaves the stack and dashboard serving; the install phase restores a real archive to a fresh disk and checks the running payout wallet plus Tor onion identity | battery `--phase provision` + `--phase install` restore leg | Candidate tier-1 evidence only; tier 4 added and unverified until the combined battery | | RC2 hostname identity (#1957/#1966/#2223): the wizard names the appliance `fixture-box`; kernel hostname, rendered `HOST_IP`, `/api/state`'s header source, served certificate DNS+LAN-IP SANs and mDNS resolution through active Avahi must agree initially. A day-two `fixture-next` preview is pure and approval-gated; a commit without its envelope is refused, while the ordinary authenticated control route applies the host-generated preview. The new identity must survive an unaided reboot and the A/B migration update | `tests/os/appliance-hostname-leg.sh`, `tests/os/appliance-config-approval-leg.sh` + battery `--phase provision` | 1 ✅ (pure identity/prompt/consumer verdict controls) · 4 (written — unverified until the combined image battery runs) | -| RC2 sensitive-commit/node rows (#1959/#1898/#1943/#1946, retargeted by #2076): the first live config read is followed by an authenticated read of the shipped `configversion.mjs`, requiring a non-empty module with `Saving is blocked` and `_config_version_newer` but no `Config file version` (#3239); unreadable assets fail as unexercised. A sensitive day-two commit is refused without the typed confirmation envelope and leaves live identity unchanged; a confirmed one applies, audits against the signed-in actor with **no** `approver` field, and converges hostname/mDNS/certificate identity; a dashboard-password repoint commits behind typed `APPLY` and the envelope, its verdict read from the host result spool (the dashboard poll carries the login it replaces), the new login reads `/api/config`, and the fixture password is restored the same way (#2367). A snapshot taken before the first password commit is restored host-side after every exit, including lost verdicts and failed restoration previews; cleanup waits for the control spool to drain, preserves the failed assertion, and verifies authenticated `/api/config` with the original login (#2986). A standalone local Monero node username edit, then a password edit, each previews as a `CONFIRM` change, applies with typed `APPLY`, and must leave monerod's and the dashboard's container environment and p2pool's `--rpc-login` argument carrying the new login (checked against podman's inspect output, where names carry no Docker-style leading slash). The fixture sets `p2pool.clearnet` host-side first (#165). The dashboard can also commit it, behind the approval envelope, but this leg keeps its proposal to `monero.*` and `tari.*`. Reserved reachable Monero/Tari endpoints must pass the host preflight, land in rendered runtime state and the current p2pool container's narrowly extracted arguments (including each nonblank proposed login part in its live `--rpc-login`, compared without printing it), and make an endpoint-bound current-startup `uses chain_id` consumer probe pass before the original local-node config is restored; the restore also runs when the leg fails early. The guest-side fake Telegram transport is gone with the approval round-trip, so this leg now drives the ordinary authenticated control route | `tests/os/appliance-config-approval-leg.sh`, `tests/os/appliance-node-runtime-leg.sh` plus the existing `tests/integration/lib/mergemine-probe.sh` verdict | 1 ✅ (host policy suite in `tests/stack/test-confirm-approval.sh`; pure round-trip controls) · 4 (written — requires reserved node inputs and remains unverified until the combined battery) | +| RC2 sensitive-commit/node rows (#1959/#1898/#1943/#1946, retargeted by #2076): the first live config read is followed by an authenticated read of the shipped `configversion.mjs`, requiring a non-empty module with `Saving is blocked` and `_config_version_newer` but no `Config file version` (#3239); unreadable assets fail as unexercised. A sensitive day-two commit is refused without the typed confirmation envelope and leaves live identity unchanged; a confirmed one applies, audits against the signed-in actor with **no** `approver` field, and converges hostname/mDNS/certificate identity; a dashboard-password repoint commits behind typed `APPLY` and the envelope, its verdict read from the host result spool (the dashboard poll carries the login it replaces), the new login reads `/api/config`, and the fixture password is restored the same way (#2367). A snapshot taken before the first password commit is restored host-side after every exit, including lost verdicts and failed restoration previews; cleanup waits for the control spool to drain, preserves the failed assertion, and verifies authenticated `/api/config` with the original login (#2986). A standalone local Monero node username edit, then a password edit, each previews as a `CONFIRM` change, applies with typed `APPLY`, and must leave monerod's and the dashboard's container environment and p2pool's `--rpc-login` argument carrying the new login (checked against podman's inspect output, where names carry no Docker-style leading slash). The fixture sets `p2pool.clearnet` host-side first (#165): it waits for an idle control runner and a free mutation lock, retries a failed apply once, and a second failure reports the apply's exit status and an output tail passed through the appliance redactor (`tests/os/lib/redact-addr.sh`), then clipped (#3980). The dashboard can also commit it, behind the approval envelope, but this leg keeps its proposal to `monero.*` and `tari.*`. Reserved reachable Monero/Tari endpoints must pass the host preflight, land in rendered runtime state and the current p2pool container's narrowly extracted arguments (including each nonblank proposed login part in its live `--rpc-login`, compared without printing it), and make an endpoint-bound current-startup `uses chain_id` consumer probe pass before the original local-node config is restored; the restore also runs when the leg fails early. The guest-side fake Telegram transport is gone with the approval round-trip, so this leg now drives the ordinary authenticated control route | `tests/os/appliance-config-approval-leg.sh`, `tests/os/appliance-node-runtime-leg.sh` plus the existing `tests/integration/lib/mergemine-probe.sh` verdict | 1 ✅ (host policy suite in `tests/stack/test-confirm-approval.sh`; pure round-trip controls) · 4 (written — requires reserved node inputs and remains unverified until the combined battery) | | Failing appliance rows carry their evidence, not just a verdict (#2060): the hostname rows preserve empty snapshot columns, fail an unavailable dashboard state as `state=empty`, and print kernel/static hostname, rendered host, dashboard state, certificate, Avahi, mDNS, card addresses and named HTTP status want-beside-got plus what Avahi published and on which interface (the address moved between runs, the interface is the discriminator); the control-runner rows print the runner result and value read back, reporting runner completion as unknown when the requested value has already landed but no result was written; the doctor row stays total over a FLATTENED `checks`, the shape it is named after; the bundle rows print the tail of the build log, with a missing log, an empty log and a failed build each getting their own sentence | `tests/os/appliance-hostname-leg.sh`, `appliance-diagnostics-leg.sh`, `provision-browser-submit.sh` and `appliance-approval-verdict.sh` `--self-test`, plus `tests/os/selftest-row-payloads.sh` and `tests/os/bundle-build-evidence.sh --self-test` | 1 ✅ (each payload driven against the shapes the verdict refuses, and a mutation of each field reddens its own control) · 4 (the rows themselves stay red until the defects behind them are fixed — this is the evidence step the issue asks for first) | | The appliance's mDNS name resolves to a LAN address, never a container bridge (#2060): `appliance_mdns_interfaces` names every interface holding a global v4 address that is NOT a kernel bridge, and `appliance_reconcile_mdns_interfaces` writes that list as Avahi's `allow-interfaces` through the same `/etc` overlay the console login uses, reporting a change ONLY when the file actually moved so the caller restarts Avahi exactly when there is something new to announce. A positive list rather than a deny-list because the boot render reconciles identity BEFORE `up` creates either bridge, where a deny-list would come out empty. The rewrite also runs independently of the hostname label: an appliance left on the default `auto` name had no label to reconcile and returned before Avahi was ever touched | `tests/stack/appliance/test-appliance-hostname.sh` (canned `ip` output from the measured guest; a config carrying no `allow-interfaces` line must report no change, the control that catches a silent no-op rewrite), `tests/os/verify-image.sh` (the shipped config carries the line the rewrite keys on) · battery `--phase provision` | 1 ✅ · 4 (unverified until the next battery run; the mechanism itself is measured — an `avahi-daemon` + `libnss-mdns` container with one NIC and one kernel bridge resolves its own name to the bridge without the line and to the NIC with it) | | The control POST outlasts the dashboard's own answer window (#2060/#2223): `handle_control_*` holds the request open until the runner answers or `CONTROL_WAIT_S` elapses and only THEN returns 202 with the id `dashboard_control_request`'s polling loop needs. The two clients recover on deliberately different terms. The KVM harness helper polls the caller-supplied id whenever a 2xx POST response is empty OR malformed, and also on a synthetic `000` or a proxy 5xx after the request was accepted, refusing received 1xx–4xx. Preview POSTs without a usable returned id may be re-submitted at most three times after transport loss, HTTP 000 or an unstructured proxy 5xx, with each retry capped to the remaining caller deadline: they only stage intents, and only a returned, validated preview is later committed. A complete 2xx preview with a canonical server id remains usable after a trailing curl error. A connection failure before any HTTP response (curl 7 with HTTP 000 and an empty body) may reconnect for any verb, including commit, with at most three total connection attempts under the original deadline. No request reached the listener on those failed connections. Exhausted connection failures fail without polling the unchanged preview. Other commit transport failures, empty responses and proxy 5xx responses remain ambiguous and are polled without re-submitting the mutation; received refusals remain terminal. The browser client is narrower: `controlCommitResult`, shared by Configuration and Worker adoption, polls the preview id it already holds ONLY when a successful body is exactly empty, and treats a truncated body — one that parses but carries no result status — as terminal, because a half-read answer is a different failure from a lost one and must not be retried into a false success. Thus an 8s `-m` on the POST or a dropped response would otherwise discard every control operation that did real work — a commit that runs an apply, doctor on an unhealthy box — while their fast siblings answered inside it and passed, which is what made the reds read as the runner losing results. The check reads both numbers from their own sources, so neither side can move alone | `dashboard/tests/frontend/config/configview.test.mjs`, `workers/workeradopt.test.mjs`; `tests/os/appliance-config-approval-leg.sh --self-test`, `tests/os/selftest-control-admission.sh` | 1 ✅ (the cap mutated back under the server's window reddens the check; the admission regression fails without reconnecting an undelivered commit and pins single delivery after ambiguous responses) · 4 (unverified until the combined battery runs) | diff --git a/tests/integration/e2e.sh b/tests/integration/e2e.sh index 8f4a1f2f0..c8e875e5c 100755 --- a/tests/integration/e2e.sh +++ b/tests/integration/e2e.sh @@ -346,29 +346,6 @@ wait_synced() { # done } -# Nudge the miner's xmrig to reload its (rewritten) config. xmrig watches its config file and -# reloads on change; the systemctl/SIGHUP fallbacks cover builds that don't. At least one must work; -# forward paths then poll the test bench for the worker, so the exact mechanism doesn't matter. -miner_reload() { - on_miner "sudo -n systemctl restart xmrig >/dev/null 2>&1 || systemctl --user restart xmrig >/dev/null 2>&1 || pkill -HUP -x xmrig >/dev/null 2>&1" -} - -# Poll the test bench's dashboard for at least workers connected. -wait_workers() { # - local want="$1" deadline=$(($(date +%s) + ${2:-180})) got - while :; do - got="$(on_bench "curl -fsS --max-time 8 http://127.0.0.1:8000/api/state 2>/dev/null | jq -r '.proxy_workers // 0' 2>/dev/null" || echo 0)" - [ -n "$got" ] && [ "$got" -ge "$want" ] 2>/dev/null && { - ok "$got worker(s) mining through the test bench" - return 0 - } - [ "$(date +%s)" -ge "$deadline" ] && { - warn "only $got worker(s) connected after $((${2:-180}))s (wanted $want)" - return 1 - } - sleep 8 - done -} # --- Phase 0: preflight ----------------------------------------------------- preflight() { log "Preflight" @@ -575,7 +552,7 @@ borrow_miner() { on_miner "cp -a '$MINER_XMRIG_CONFIG' '$MINER_CFG_BACKUP'" || die "Failed to back up the miner config." step "miner config backed up → $MINER_CFG_BACKUP" repoint_miner || die "Failed to repoint the miner config." - wait_workers "$WORKERS" 180 || warn "proceeding, but the matrix's mining assertions may not pass with too few workers" + wait_workers "$WORKERS" 180 "$MINER_WORKER_NAME" || warn "proceeding, but the matrix's mining assertions may not pass without the borrowed rig" } # --- Phase 4: deploy the branch --------------------------------------------- diff --git a/tests/integration/lib/borrow-fixture.sh b/tests/integration/lib/borrow-fixture.sh index e17177fee..0eee81692 100644 --- a/tests/integration/lib/borrow-fixture.sh +++ b/tests/integration/lib/borrow-fixture.sh @@ -1,6 +1,7 @@ # shellcheck shell=bash FAILOVER_POOL_PORT=3399 +MINER_WORKER_NAME= # Reapply the temporary pool fixture without minting another restore anchor. RigForge correctly # regenerates xmrig's rendered config after bootstrap/control applies; e2e.sh's original backup @@ -18,6 +19,11 @@ repoint_miner() { local primary primary="$(on_miner "jq -r '.pools[0].url' '$MINER_XMRIG_CONFIG'")" [ -n "$primary" ] && step "miner primary pool is now: $primary" + MINER_WORKER_NAME="$(on_miner "jq -r '.pools[0] | [.[\"rig-id\"], .user] | map(select(type == \"string\" and . != \"\")) | first // empty' '$MINER_XMRIG_CONFIG'")" || MINER_WORKER_NAME= + [[ "$MINER_WORKER_NAME" =~ ^[A-Za-z0-9._:@+-]+$ ]] || { + MINER_WORKER_NAME= + warn "the bench pool carries no usable rig-id or user; worker gates count proxy workers instead" + } case "$primary" in "$BENCH_HOST":* | *"://$BENCH_HOST":*) ;; *) @@ -94,7 +100,7 @@ handle_borrow_rearm() { # local attempt for attempt in 1 2 3 4; do repoint_miner || return 1 - wait_workers "$WORKERS" 60 && break + wait_workers "$WORKERS" 60 "$MINER_WORKER_NAME" && break [ "$attempt" = 4 ] && return 1 warn "re-arm attempt $attempt: the borrowed rig did not reach the test bench; restarting it again" done @@ -109,5 +115,51 @@ handle_borrow_rearm() { # ;; *) return 1 ;; esac - wait_workers "$WORKERS" 180 && printf '%s' "$record" | on_bench "cat > '$ack.tmp' && mv '$ack.tmp' '$ack'" + wait_workers "$WORKERS" 180 "$MINER_WORKER_NAME" && printf '%s' "$record" | on_bench "cat > '$ack.tmp' && mv '$ack.tmp' '$ack'" +} + +# shellcheck disable=SC2016 +miner_reload() { + on_miner ' + mainpid() { systemctl "$1" show -p MainPID --value xmrig 2>/dev/null; } + moved() { + for _ in 1 2 3 4 5 6 7 8 9 10; do + now=$(mainpid "$1") + [ -n "$now" ] && [ "$now" != 0 ] && [ "$now" != "$2" ] && return 0 + sleep 1 + done + return 1 + } + reload() { + old=$(mainpid --system) + if sudo -n systemctl restart xmrig >/dev/null 2>&1; then + moved --system "$old" + return + fi + if sudo -n systemctl stop xmrig >/dev/null 2>&1; then + sudo -n systemctl start xmrig >/dev/null 2>&1 || sudo -n systemctl start xmrig >/dev/null 2>&1 && moved --system "$old" + return + fi + old=$(mainpid --user) + systemctl --user restart xmrig >/dev/null 2>&1 && moved --user "$old" + } + reload + ' +} + +wait_workers() { + local want="$1" deadline=$(($(date +%s) + ${2:-180})) name="${3:-}" got + [ -z "$name" ] || want=1 + while :; do + got="$(on_bench "curl -fsS --max-time 8 http://127.0.0.1:8000/api/state 2>/dev/null | jq -r --arg n '$name' 'if \$n == \"\" then .proxy_workers // 0 else [.workers[]? | select(.name == \$n and .status == \"online\")] | length end' 2>/dev/null" || echo 0)" + [ -n "$got" ] && [ "$got" -ge "$want" ] 2>/dev/null && { + ok "$got worker(s) mining through the test bench${name:+ (the borrowed rig)}" + return 0 + } + [ "$(date +%s)" -ge "$deadline" ] && { + warn "only $got worker(s)${name:+ for the borrowed rig} connected after $((${2:-180}))s (wanted $want)" + return 1 + } + sleep 8 + done } diff --git a/tests/integration/selftest/selftest-borrow-reload.sh b/tests/integration/selftest/selftest-borrow-reload.sh new file mode 100755 index 000000000..96eeb062e --- /dev/null +++ b/tests/integration/selftest/selftest-borrow-reload.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034 +set -uo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$HERE/../lib.sh" + +echo "== the borrow moves a root-run rig and the worker gate names it (#3972) ==" +reload_rc() { + ( + source "$HERE/../lib/borrow-fixture.sh" + pid=100 restart_ok="$1" stopstart_ok="$2" moves="$3" user_ok="$4" + on_miner() { eval "$1"; } + sleep() { :; } + systemctl() { + case "$*" in + *"show -p MainPID"*) echo "$pid" ;; + "--user restart xmrig") [ "$user_ok" = 1 ] && pid=300 ;; + esac + } + sudo() { + shift + case "$2" in + restart) [ "$restart_ok" = 1 ] ;; + stop) [ "$stopstart_ok" != 0 ] ;; + start) + [ "$stopstart_ok" = 3 ] && [ -z "${started_once:-}" ] && { + started_once=1 + return 1 + } + [ "$stopstart_ok" = 1 ] || [ "$stopstart_ok" = 3 ] && { + [ "$moves" = 1 ] && pid=200 + true + } + ;; + esac + } + pkill() { return 0; } + miner_reload + echo $? + ) +} +assert_eq "stop then start reloads a root-run xmrig when restart is refused" "$(reload_rc 0 1 1 0 0)" 0 +assert_eq "a start that leaves the same MainPID is not a reload" "$(reload_rc 0 1 0 0 0)" 1 +assert_eq "a stop that succeeds with a failed start fails loudly" "$(reload_rc 0 2 1 1 0)" 1 +assert_eq "one failed start after a stop is retried and reloads" "$(reload_rc 0 3 1 0)" 0 +assert_eq "a user unit restart that moves its MainPID is a reload" "$(reload_rc 0 0 0 1 0)" 0 +assert_eq "refused restart, refused stop and no user unit fail loudly" "$(reload_rc 0 0 0 0 0)" 1 + +worker_gate() { + ( + source "$HERE/../lib/borrow-fixture.sh" + rows="$1" + ok() { :; } + warn() { :; } + FAKE_NOW=0 + sleep() { FAKE_NOW=$((FAKE_NOW + 100)); } + date() { echo "$FAKE_NOW"; } + curl() { printf '{"proxy_workers":1,"workers":%s}' "$rows"; } + on_bench() { eval "$1"; } + wait_workers 1 5 "$2" >/dev/null + echo $? + ) +} +assert_eq "every re-arm attempt waits for the borrowed rig by name" "$( + ( + source "$HERE/../lib/borrow-fixture.sh" + seen="$(mktemp)" + cfg="$(mktemp)" + trap 'rm -f "$seen" "$cfg"' EXIT + printf '%s' '{"pools":[{"url":"bench.example:3333","rig-id":"rig7"}]}' >"$cfg" + BENCH_HOST=bench.example MINER_XMRIG_CONFIG="$cfg" + on_bench() { if [ "$1" = "cat 'req'" ]; then echo "run-1 rearm 1"; else cat >/dev/null; fi; } + on_miner() { eval "$1"; } + miner_reload() { :; } + step() { :; } + warn() { :; } + wait_workers() { + echo "$3" >>"$seen" + [ "$(wc -l <"$seen")" -ge 2 ] + } + WORKERS=1 + handle_borrow_rearm req ack run-1 >/dev/null + sort -u "$seen" | tr '\n' ' ' + wc -l <"$seen" | tr -d ' ' + ) | tr '\n' ' ' +)" "rig7 2 " +assert_eq "another online worker does not satisfy the named-rig gate" \ + "$(worker_gate '[{"name":"other","status":"online"}]' pithead-e2e)" 1 +assert_eq "an offline worker of the borrowed name does not satisfy the gate" \ + "$(worker_gate '[{"name":"pithead-e2e","status":"offline"}]' pithead-e2e)" 1 +assert_eq "the borrowed rig online satisfies the gate" \ + "$(worker_gate '[{"name":"other","status":"online"},{"name":"pithead-e2e","status":"online"}]' pithead-e2e)" 0 +repoint_existing() { + source "$HERE/../lib/borrow-fixture.sh" + d2="$(mktemp -d)" + printf '%s' "$1" >"$d2/c.json" + BENCH_HOST=bench.example MINER_XMRIG_CONFIG="$d2/c.json" + on_miner() { eval "$1"; } + step() { :; } + warn() { :; } + miner_reload() { :; } + repoint_miner + printf '%s|%s' "$(jq -r '.pools[0]["rig-id"]' "$d2/c.json")" "$MINER_WORKER_NAME" + rm -rf "$d2" +} +assert_eq "the rig's own bench pool keeps its rig-id and the gate waits for that name" \ + "$(repoint_existing '{"pools":[{"url":"bench.example:3333","user":"w","rig-id":"rig7"}]}')" "rig7|rig7" +assert_eq "an untagged own bench pool stays untagged and the gate waits for its stratum user" \ + "$(repoint_existing '{"pools":[{"url":"bench.example:3333","user":"rig7"}]}')" "null|rig7" +assert_eq "an empty rig-id gates on the stratum user" \ + "$(repoint_existing '{"pools":[{"url":"bench.example:3333","user":"rig7","rig-id":""}]}')" "|rig7" +assert_eq "a bench pool with neither rig-id nor user falls back to the count" \ + "$(repoint_existing '{"pools":[{"url":"bench.example:3333"}]}')" "null|" +assert_eq "an inserted bench pool is tagged and the gate waits for pithead-e2e" \ + "$(repoint_existing '{"pools":[{"url":"own.example:3333","user":"w","rig-id":"rig7"}]}')" "pithead-e2e|pithead-e2e" +assert_eq "an unsafe rig-id is not used as the gate name" \ + "$(repoint_existing '{"pools":[{"url":"bench.example:3333","rig-id":"a'"'"'b"}]}')" "a'b|" + +echo "selftest-borrow-reload: $IT_PASS passed, $IT_FAIL failed" +[ "$IT_FAIL" -eq 0 ] || exit 1 diff --git a/tests/os/appliance-clearnet-fixture.sh b/tests/os/appliance-clearnet-fixture.sh new file mode 100644 index 000000000..ca1f1d779 --- /dev/null +++ b/tests/os/appliance-clearnet-fixture.sh @@ -0,0 +1,87 @@ +# shellcheck shell=bash +# shellcheck disable=SC2016,SC2034 +# shellcheck source=tests/os/lib/redact-addr.sh +source "${BASH_SOURCE[0]%/*}/lib/redact-addr.sh" +CLEARNET_FIXTURE_DIAG="" + +_control_apply_idle() { + local deadline=$(($(date +%s) + ${1:-60})) SSH_TIMEOUT="${SSH_PROBE_TIMEOUT:-20}" + while :; do + _ssh 'systemctl is-active --quiet pithead-control.path && [ "$(systemctl is-active pithead-control.service)" != activating ] && flock -n /data/pithead/.pithead.lock true' && return 0 + [ "$(date +%s)" -lt "$deadline" ] || break + sleep 3 + done + CLEARNET_FIXTURE_DIAG="${CLEARNET_FIXTURE_DIAG:+$CLEARNET_FIXTURE_DIAG$'\n'}the control runner or the mutation lock stayed busy or unreachable for the whole wait" + return 1 +} + +_clearnet_apply_once() { + local dir rc=0 here nl=$'\n' + here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + dir=$(mktemp -d) || return 1 + _ssh 'set -euo pipefail +cd /data/pithead +jq ".p2pool.clearnet = true" config.json >config.json.os2333-clearnet +chmod 600 config.json.os2333-clearnet +mv config.json.os2333-clearnet config.json +./pithead apply -y +jq -e ".p2pool.clearnet == true" config.json >/dev/null' >"$dir/raw" 2>&1 || rc=$? + if [ "$rc" -ne 0 ]; then + [ ! -s "${SSH_ERR:-}" ] || cat -- "$SSH_ERR" >>"$dir/raw" + os_redact_addr <"$dir/raw" >"$dir/redacted" || echo "the apply output could not be redacted, so it is withheld" >"$dir/redacted" + CLEARNET_FIXTURE_DIAG="${CLEARNET_FIXTURE_DIAG:+$CLEARNET_FIXTURE_DIAG$nl}clearnet apply exit=$rc$nl$(bash "$here/../../scripts/sanitize-test-log.sh" --lines 12 --width 240 "$dir/redacted")" + fi + rm -rf "$dir" + return "$rc" +} + +reserved_node_clearnet_fixture() { + CLEARNET_FIXTURE_DIAG="" + for _ in 1 2; do + _control_requests_drained && _control_apply_idle || return 1 + _clearnet_apply_once && return 0 + done + return 1 +} + +_clearnet_fixture_self_test() ( + local idle_probes=0 now=0 f=0 count + count=$(mktemp) + date() { echo "$now"; } + sleep() { now=$((now + 3)); } + _ssh() { + case "$1" in *'pithead-control.path'*'pithead-control.service'*'flock -n /data/pithead/.pithead.lock true'*) ;; *) return 1 ;; esac + idle_probes=$((idle_probes + 1)) + [ "$idle_probes" -gt "$busy_probes" ] + } + busy_probes=2 + _control_apply_idle 60 || f=$((f + 1)) + busy_probes=999 idle_probes=0 now=0 + _control_apply_idle 9 && f=$((f + 1)) + _control_requests_drained() { return 0; } + _control_apply_idle() { return 0; } + _ssh() { + echo >>"$count" + [ "$(wc -l <"$count")" -gt "$fail_calls" ] && return 0 + printf 'noise\n[ERROR] failed to apply the config: conflict for 4%s\n' "$(printf '%94s' '' | tr ' ' A)" + return 7 + } + fail_calls=1 + reserved_node_clearnet_fixture || f=$((f + 1)) + [ "$(wc -l <"$count")" -eq 2 ] || f=$((f + 1)) + fail_calls=5 + : >"$count" + reserved_node_clearnet_fixture && f=$((f + 1)) + [ "$(wc -l <"$count")" -eq 2 ] || f=$((f + 1)) + case "$CLEARNET_FIXTURE_DIAG" in *'exit=7'*'failed to apply'*) ;; *) f=$((f + 1)) ;; esac + [ "$(printf '%s\n' "$CLEARNET_FIXTURE_DIAG" | grep -cx 'clearnet apply exit=7')" -eq 2 ] || f=$((f + 1)) + case "$CLEARNET_FIXTURE_DIAG" in *'[redacted-address]'*) ;; *) f=$((f + 1)) ;; esac + case "$CLEARNET_FIXTURE_DIAG" in *4AAAAAAAAAA*) f=$((f + 1)) ;; esac + fail_calls=5 + : >"$count" + _control_apply_idle() { [ "$(wc -l <"$count")" -eq 0 ]; } + reserved_node_clearnet_fixture && f=$((f + 1)) + case "$CLEARNET_FIXTURE_DIAG" in *'exit=7'*) ;; *) f=$((f + 1)) ;; esac + rm -f "$count" + [ "$f" -eq 0 ] +) diff --git a/tests/os/appliance-node-runtime-leg.sh b/tests/os/appliance-node-runtime-leg.sh index bfb2ba9b8..de6ac17ea 100644 --- a/tests/os/appliance-node-runtime-leg.sh +++ b/tests/os/appliance-node-runtime-leg.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # Confirm-gated Monero login edits and reserved-node runtime proof (#2333). Loaded by appliance-config-approval-leg.sh after the shared approval helpers. +# shellcheck source=tests/os/appliance-clearnet-fixture.sh +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/appliance-clearnet-fixture.sh" + REMOTE_NODE_RUNTIME_REASON="not-run" remote_node_proposal() { # @@ -131,18 +134,6 @@ local_node_login_edit() { #