From 60aed91fdd247bd72e7504f9e973582ad6edf38e Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 10 Nov 2026 09:59:20 -0600 Subject: [PATCH 1/5] =?UTF-8?q?tests:=20fix=20#3972,=20#3980=20=E2=80=94?= =?UTF-8?q?=20verify=20the=20borrowed=20rig=20reload=20and=20the=20clearne?= =?UTF-8?q?t=20fixture=20apply?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/file-budget.tsv | 4 +- docs/dev/integration-testing.md | 5 ++ docs/dev/testing-strategy.md | 2 +- tests/integration/e2e.sh | 25 +------ tests/integration/lib/borrow-fixture.sh | 54 +++++++++++++-- .../selftest/selftest-borrow-rearm.sh | 65 +++++++++++++++++++ tests/os/appliance-clearnet-fixture.sh | 60 +++++++++++++++++ tests/os/appliance-node-runtime-leg.sh | 18 ++--- 8 files changed, 189 insertions(+), 44 deletions(-) create mode 100644 tests/os/appliance-clearnet-fixture.sh diff --git a/docs/dev/file-budget.tsv b/docs/dev/file-budget.tsv index ab9d963a1..09925a2b2 100644 --- a/docs/dev/file-budget.tsv +++ b/docs/dev/file-budget.tsv @@ -43,7 +43,7 @@ lib/pithead/28-parse-and-validate-config.sh 464 lib/pithead/33-render-env.sh 481 lib/pithead/36-quadlet-units.sh 406 scripts/watch/trivyignore-watch.sh 599 -tests/integration/e2e.sh 663 +tests/integration/e2e.sh 639 tests/integration/lib/run-cli.sh 410 tests/integration/fakes/test_contract.py 437 tests/integration/lib.sh 686 @@ -54,7 +54,7 @@ tests/integration/selftest/selftest-live-gates.sh 453 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 440 tests/os/failure-evidence.sh 567 tests/os/phases/install-restore.sh 414 tests/os/phases/update.sh 413 diff --git a/docs/dev/integration-testing.md b/docs/dev/integration-testing.md index 353172b91..70ef3c21a 100644 --- a/docs/dev/integration-testing.md +++ b/docs/dev/integration-testing.md @@ -410,6 +410,11 @@ via an `EXIT` trap): before mining waits. The controller uses its runner-owned recovery hold and exact config backup, then restores the borrowed config before the next scenario. Without that controller transport or recovery hold, the authenticated scenario fails before changing configuration. + The borrowed pool carries `rig-id` `pithead-e2e`. 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; + the signal fallback only reaches an `xmrig` owned by the harness's own user. Every worker gate + after a borrow or re-arm waits for an online worker named `pithead-e2e`, so another worker on the + proxy cannot satisfy it ([#3972](https://github.com/p2pool-starter-stack/pithead/issues/3972)). A failed handoff or restore stops the harness and leaves final recovery to the controller. The rig continues using cleartext on the dual-mode stratum port; the TLS handshake and fingerprint are checked separately. diff --git a/docs/dev/testing-strategy.md b/docs/dev/testing-strategy.md index 6ce015588..9837e50c6 100644 --- a/docs/dev/testing-strategy.md +++ b/docs/dev/testing-strategy.md @@ -623,7 +623,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). Shared snapshot restoration records drain, installation, apply, exact comparison and removal separately, with each operation’s exit status (#3806). Combined stdout/stderr, including SSH stderr, is projected onto fixed diagnostic phrases before reaching the retained battery log: at most the last 12 matching lines of 240 characters per operation, with separate redaction and overflow markers. Progress output cannot displace a later recognized error. Raw command output and configuration contents are not retained by this helper. A failed operation stops restoration without removing the snapshot or clearing its pending marker; a later cleanup failure leaves the earlier diagnostic intact. `selftest-approval-restore.sh` covers each boundary, unequal configurations, successful restoration/removal and output bounds; completed current-head provision evidence is still required to identify any recurring failing operation. 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). Shared snapshot restoration records drain, installation, apply, exact comparison and removal separately, with each operation’s exit status (#3806). Combined stdout/stderr, including SSH stderr, is projected onto fixed diagnostic phrases before reaching the retained battery log: at most the last 12 matching lines of 240 characters per operation, with separate redaction and overflow markers. Progress output cannot displace a later recognized error. Raw command output and configuration contents are not retained by this helper. A failed operation stops restoration without removing the snapshot or clearing its pending marker; a later cleanup failure leaves the earlier diagnostic intact. `selftest-approval-restore.sh` covers each boundary, unequal configurations, successful restoration/removal and output bounds; completed current-head provision evidence is still required to identify any recurring failing operation. 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 redacted output tail (#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 66316a78c..aed65702a 100755 --- a/tests/integration/e2e.sh +++ b/tests/integration/e2e.sh @@ -344,29 +344,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" @@ -558,7 +535,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 ec957eba9..d7c9eb98e 100644 --- a/tests/integration/lib/borrow-fixture.sh +++ b/tests/integration/lib/borrow-fixture.sh @@ -1,16 +1,16 @@ # shellcheck shell=bash +MINER_WORKER_NAME=pithead-e2e + # 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 # remains the one and only restore source (#1994). repoint_miner() { - # Inject a bench pool if needed, then keep it primary with the rig's original pools as failover. - # ponytail: :3333 is the seeded canonical stratum port the bench runs. on_miner " jq --arg b '$BENCH_HOST' ' (if any(.pools[]?; .url | ascii_downcase | contains(\$b)) then . else .pools = ([ (.pools[0]) + {url: (\$b + \":3333\"), tls: false, daemon: false, \"rig-id\": \"pithead-e2e\"} ] + .pools) end) - | .pools |= ([.[] | select(.url | ascii_downcase | contains(\$b))] + [.[] | select(.url | ascii_downcase | contains(\$b) | not)])' \ + | .pools |= ([.[] | select(.url | ascii_downcase | contains(\$b)) | . + {\"rig-id\": \"$MINER_WORKER_NAME\"}] + [.[] | select(.url | ascii_downcase | contains(\$b) | not)])' \ '$MINER_XMRIG_CONFIG' > '$MINER_XMRIG_CONFIG.e2e.tmp' \ && mv '$MINER_XMRIG_CONFIG.e2e.tmp' '$MINER_XMRIG_CONFIG' && chmod 600 '$MINER_XMRIG_CONFIG' " || return 1 @@ -87,5 +87,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 || { sudo -n systemctl stop xmrig >/dev/null 2>&1 && sudo -n systemctl start xmrig >/dev/null 2>&1; }; then + moved --system "$old" + return + fi + old=$(mainpid --user) + if systemctl --user restart xmrig >/dev/null 2>&1; then + moved --user "$old" + return + fi + pkill -HUP -u "$(id -u)" -x xmrig >/dev/null 2>&1 + } + reload + ' +} + +wait_workers() { # [worker-name] + 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:+ ($name)}" + return 0 + } + [ "$(date +%s)" -ge "$deadline" ] && { + warn "only $got worker(s)${name:+ named $name} connected after $((${2:-180}))s (wanted $want)" + return 1 + } + sleep 8 + done } diff --git a/tests/integration/selftest/selftest-borrow-rearm.sh b/tests/integration/selftest/selftest-borrow-rearm.sh index 24881af8c..fe057507b 100755 --- a/tests/integration/selftest/selftest-borrow-rearm.sh +++ b/tests/integration/selftest/selftest-borrow-rearm.sh @@ -175,5 +175,70 @@ assert_rc "rotation without a controller transport fails closed" "$( echo $? )" 1 +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" pkill_ok="$5" pkill_args="" + on_miner() { eval "$1"; } + sleep() { :; } + systemctl() { + case "$*" in + *"show -p MainPID"*) echo "$pid" ;; + "--user restart xmrig") [ "$user_ok" = 1 ] ;; + esac + } + sudo() { + shift + case "$2" in + restart) [ "$restart_ok" = 1 ] ;; + stop) [ "$stopstart_ok" = 1 ] ;; + start) [ "$stopstart_ok" = 1 ] && { [ "$moves" = 1 ] && pid=200; true; } ;; + esac + } + pkill() { pkill_args="$*"; [ "$pkill_ok" = 1 ]; } + miner_reload + rc=$? + echo "$rc $pkill_args" + ) +} +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 "refused restart, failed signal and no user unit fail loudly" "$(reload_rc 0 0 0 0 0)" "1 -HUP -u $(id -u) -x xmrig" +assert_eq "the signal fallback only targets the caller's own xmrig" "$(reload_rc 0 0 0 0 1)" "0 -HUP -u $(id -u) -x xmrig" + +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 "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 +assert_eq "the bench's own rig-id tags the pool even when the pool pre-exists" "$( + d2="$(mktemp -d)" + printf '%s' '{"pools":[{"url":"bench.example:3333","user":"w"}]}' >"$d2/c.json" + BENCH_HOST=bench.example MINER_XMRIG_CONFIG="$d2/c.json" + on_miner() { eval "$1"; } + step() { :; } + miner_reload() { :; } + repoint_miner + jq -r '.pools[0]["rig-id"]' "$d2/c.json" + rm -rf "$d2" +)" pithead-e2e + echo "selftest-borrow-rearm: $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..f15a5c323 --- /dev/null +++ b/tests/os/appliance-clearnet-fixture.sh @@ -0,0 +1,60 @@ +# shellcheck shell=bash +# shellcheck disable=SC2016,SC2034 +CLEARNET_FIXTURE_DIAG="" + +_control_apply_idle() { # [seconds] + local deadline=$(($(date +%s) + ${1:-60})) SSH_TIMEOUT="${SSH_PROBE_TIMEOUT:-20}" + while :; do + _ssh '[ "$(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="the control runner or the mutation lock stayed busy for the whole wait" + return 1 +} + +reserved_node_clearnet_fixture() { + CLEARNET_FIXTURE_DIAG="" + for _ in 1 2; do + _control_requests_drained && _control_apply_idle || return 1 + CLEARNET_FIXTURE_DIAG=$(approval_restore_step clearnet-apply _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') && return 0 + done + return 1 +} + +# The fixture waits for an idle control runner, retries one failed apply, and reports the apply's exit and tail. +_clearnet_fixture_self_test() ( + local idle_probes=0 now=0 f=0 count + count=$(mktemp) + trap 'rm -f "$count"' RETURN + date() { echo "$now"; } + sleep() { now=$((now + 3)); } + _ssh() { 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; } + approval_restore_step() { + echo >>"$count" + [ "$(wc -l <"$count")" -gt "$fail_calls" ] && return 0 + printf 'approval restore operation=clearnet-apply exit=1\n[ERROR] apply conflict\n' + return 1 + } + 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=1'*'apply conflict'*) ;; *) f=$((f + 1)) ;; esac + [ "$f" -eq 0 ] +) diff --git a/tests/os/appliance-node-runtime-leg.sh b/tests/os/appliance-node-runtime-leg.sh index d9329dcd9..114a9a4a6 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() { #