Skip to content
Draft
9 changes: 9 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ promoted to `main` and tagged. The steps below build the release commit on `deve
sudo bash tests/e2e-real.sh teardown # uninstall + assert a clean revert
```

The steps that need a fresh host or a reboot no longer rest on this gate alone: the
bench's `rigforge`/`tier4-kvm` job runs `make e2e-docs-replay` on a fresh Ubuntu 24.04
guest (tests/README.md › Documentation replay) — documented install, reboot-persistent
autostart, the API allowlist from a second source, control apply/revert, the
remote-upgrade chain onto the candidate, backup/restore, the uninstall revert and
appliance mode — and its green job is the gate evidence for those steps. What stays on
real hardware is what no guest can prove: real hashrate, tuning, MSR read-back, RAPL
and thermal-sensor checks — the `verify`, `watchdog` and `perf` phases above.

When a live Pithead stack is reachable, also run the worker↔stack contract gate (stack on its
latest release tag — record `pithead version` in the run log). It asserts the mining round-trip,
the `:8080` API contract, stratum auth (pass `E2E_STRATUM_PASS` if the stack uses one), dashboard
Expand Down
1 change: 1 addition & 0 deletions docs/dev/file-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# target/ceiling rationale and CONTRIBUTING.md for the gate.
# path<TAB>ceiling-in-lines. Ceilings only ever go down; a file at or below 400 lines drops its entry.
rigforge.sh 6028
tests/e2e-docs-guest.sh 571
tests/e2e-pithead.sh 562
tests/e2e-real.sh 1388
tests/run.sh 9539
Expand Down
51 changes: 37 additions & 14 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CI median/p90, failures and occupied hours; missing evidence leaves acceptance o
| **Unit + black-box suite** | [`run.sh`](run.sh) + [`test-contract-credentials.sh`](test-contract-credentials.sh) | Any host (macOS/Linux), no Docker; credential regression needs Python 3. **In CI.** | Config parsing, the XMRig-config generation matrix (every CPU/OS profile, simulated via PATH stubs), GRUB/HugePages math, the command surface, tune search, doctor: everything that doesn't need a real `/etc` or real hardware. The bulk of coverage. | `make test` (lint + suite) or `make test-suite` |
| **Linux container e2e** | [`e2e/linux.sh`](e2e/linux.sh) → [`e2e/in-container.sh`](e2e/in-container.sh) | Disposable Ubuntu container, **needs Docker**. **In CI.** | The genuine Linux deploy path against a real (throwaway) `/etc` with real GNU tools (`sed -i`, `tee`, `envsubst`) + idempotency on re-run. Only the heavy/privileged bits (compile, package install, `systemctl`/`mount`) are stubbed. A second pass re-runs the container with `RIGFORGE_APPLIANCE=1` (#348) and proves the appliance contracts on that real `/etc`: units land in `/run/systemd/system`, no package installs, no fstab/limits.conf/logrotate writes, every enable carries `--runtime`. A third script, [`e2e/isolation.sh`](e2e/isolation.sh) (#668), puts the rig on a Docker `--internal` network whose only reachable peer is a SOCKS5 proxy fronting a stand-in GitHub (a TLS git smart-HTTP server plus the releases API). With `tor_socks5` set it runs `upgrade --check`, `setup`, a local `upgrade` with an XMRig pin change and the `control-upgrade` oneshot in its own empty environment, and proves from the proxy's log that every connection named a hostname. It also proves the block is real (a direct connection and a keyless `upgrade --check` fail), that an unreachable proxy fails closed without reaching the upstream, and that the live build survives the failed upgrade. | `make test-e2e` |
| **Native macOS e2e** | [`e2e/macos.sh`](e2e/macos.sh) | A real Mac, **manual, local only. Not in CI** (macOS is best effort). | The macOS deploy path with genuine BSD tools the Linux CI can only stub: BSD `sed`, the macOS config profile, `mac_*` process control (real `nohup` + PID file), the launchd login agent, `backup`/`restore`. | `make test-e2e-macos` |
| **Docs-replay guest battery** | [`docs_replay.py`](docs_replay.py) + [`e2e-docs-guest.sh`](e2e-docs-guest.sh) | Transient Ubuntu 24.04 KVM guest on the bench's `rigforge`/`tier4-kvm` lane, **In CI via bench-ci**; by hand with `virsh`. | The install-to-uninstall battery on a fresh host: the documented install verbatim with a dry run that changes nothing, reboot-persistent autostart, accepted shares at donation zero on a throwaway endpoint, allowlist enforcement from a second source (refused, then accepted), one applied and one reverted control change, the remote-upgrade chain on real git onto the exact candidate commit, backup/restore, the uninstall revert across a reboot, and appliance mode with runtime-only units. Real hashrate, tuning, MSR read-back, RAPL and thermal checks stay with `e2e-real.sh`. | `make e2e-docs-replay` |
| **Coverage gate** | [`coverage.sh`](coverage.sh) | kcov in **Docker**. **In CI.** | Line coverage of `rigforge.sh` and its shell helpers by running `run.sh` under kcov; enforces the committed floor ([`coverage-floor.txt`](coverage-floor.txt)) plus a patch-coverage gate (diff-cover) on changed lines. | `make coverage` |
| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables only the units the package rendered, on remove only and `postrm` accepts every dpkg action and on purge deletes config, state, control state, every rendered unit, timer and path, the firewall rules and logrotate rule, and keeps an `xmrig.service` the package did not render; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` |
| **Debian package build** | [`test-build-deb.sh`](test-build-deb.sh) | Linux with `dpkg-deb`, no Docker. **In CI** (`make test-suite`). | [`../scripts/build-deb.sh`](../scripts/build-deb.sh) builds a byte-reproducible `.deb` from the release bundle with the marker where `util/package-mode.sh` reads it, the `packaging/debian` maintainer scripts and upgrade unit, the full `Depends`, and no apt keyring. | `bash tests/test-build-deb.sh` |
Expand Down Expand Up @@ -160,13 +161,17 @@ snapshots remain on disk when cleanup cannot prove the original config bytes and

### Documentation replay on a disposable VM

`make e2e-docs-replay` is the VM job entry point for the documented installation and
uninstall lifecycle. Run it on a Linux KVM controller with Python 3 and `virsh` access to
the local system libvirt instance. The job requires these environment variables:
`make e2e-docs-replay` is the VM job entry point for the install-to-uninstall
battery: the documented install, reboot-persistent autostart, allowlist enforcement
from a second source, one applied and one reverted control change, the remote-upgrade
chain onto the exact candidate commit, backup/restore, the uninstall revert and
appliance mode. It runs as the `rigforge`/`tier4-kvm` bench-ci job, and it can also be
driven by hand on a Linux KVM controller with Python 3 and `virsh` access to the
local system libvirt instance. The job requires these environment variables:

| Variable | Required value |
|---|---|
| `E2E_DOCS_DISPOSABLE` | `1`, acknowledging that setup, uninstall and two reboots will mutate the guest. |
| `E2E_DOCS_DISPOSABLE` | `1`, acknowledging that setup, uninstall, the appliance re-setup and two reboots will mutate the guest. |
| `E2E_DOCS_VM_UUID` | UUID of a running, transient, disposable Ubuntu cloud VM with AVX2 exposed. Persistent domains are refused. |
| `E2E_DOCS_CONFIG` | Path to the prepared configuration for this run, kept outside the checkout. |

Expand All @@ -182,25 +187,43 @@ do not supply a wallet, production endpoint or credential. Leave `ACCESS_TOKEN`
and control disabled and use the default worker location. Only `pools`, `DONATION`,
`api_allow_from`, `HOME_DIR` and optional `threads` are accepted; pool objects accept
only `url`, `user` and `pass`. The guest must be able
to download the documented release and its build dependencies.
to download the documented release and its build dependencies, and the candidate
commit must already be pushed, because the forward-upgrade leg fetches it from the
documented clone's origin.

The driver extracts the marked Bash blocks from the README and walkthrough,
checks their quick-start commands agree, and executes them unchanged through the
guest agent. It inserts the prepared config before the documented dry run and
setup. This deliberately tests the release pinned by the documentation; it does
not silently replace that release with the candidate branch. Marker and command
setup. The battery installs the release pinned by the documentation first — the
documented install itself is never swapped for the candidate — then moves the
guest's checkout to the exact candidate commit with `git fetch`, `git checkout`
and `rigforge.sh upgrade`, and runs the remaining legs there. Marker and command
agreement lint runs in `tests/run.sh` without Python. The host-driver regression
and guest-check negative controls run under `make test-suite`.

The job snapshots the system changes before dry run, checks autostart after a new
boot ID, donation zero, the configured pool as the only miner peer, increasing
accepted shares with no rejects, and a refused base-API write. After uninstall and
a second new boot ID it checks units, processes, listeners, pool sockets, the nft
table, 2 MiB HugePages and GRUB restoration. A stopped or unreachable guest after
reboot is a platform failure (exit 2), never an autostart failure. Other failed
assertions exit 1. The controller emits only fixed progress messages; raw guest
output stays out of public evidence. Always discard the fixture after success,
failure or timeout; the driver never deletes a caller-owned VM.
accepted shares with no rejects, and a refused base-API write. From a second source
in a temporary netns the API must be refused while the nft drop counter rises, and
after `api_allow_from` is replaced with that source (the product grammar is one
address or CIDR) and applied, only it and loopback may reach the API — the source
gets HTTP 200 while loopback keeps working through the always-present `iifname lo`
rule; the allowlist is then restored. The control
path applies one change and reverts another, with the generated config and the
running miner following both. The remote-upgrade chain runs a noop leg and a
forged-tag leg that must roll back leaving the checkout, VERSION and throttle stamp
intact, and the forward leg upgrades to the candidate commit and re-proves mining.
A backup, a deliberate config edit and a restore must return the pre-backup config
digest. After uninstall and a second new boot ID it checks units, processes,
listeners, pool sockets, the nft table, 2 MiB HugePages and GRUB restoration. A
fresh `RIGFORGE_APPLIANCE=1` setup on the same stock guest must prove appliance
mode: runtime-only units only, GRUB, fstab, limits, modules and the kernel command
line byte-identical to the fresh baseline, hugetlbfs mounted at runtime and mining
at donation zero. A stopped or unreachable guest after reboot is a platform failure
(exit 2), never an autostart failure. Other failed assertions exit 1. The
controller emits only fixed progress messages; raw guest output stays out of public
evidence. Always discard the fixture after success, failure or timeout; the driver
never deletes a caller-owned VM.

The existing worker-to-stack `network` phase also makes a bounded request from a
temporary network namespace, bracketed by successful requests from the allowed
Expand Down
68 changes: 67 additions & 1 deletion tests/docs_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from xml.etree import ElementTree


PROBE_TAG = "v99.99.99"
ALLOWED_SECOND_SOURCE = "169.254.241.3"


class ReplayError(Exception):
pass

Expand Down Expand Up @@ -103,8 +107,20 @@ def reboot(self, script, timeout=300):
raise PlatformError("guest failed to return with a new boot ID")


def candidate(root):
result = subprocess.run(["git", "-C", str(root), "rev-parse", "HEAD"],
capture_output=True, text=True)
sha = result.stdout.strip()
if result.returncode != 0 or not re.fullmatch(r"[0-9a-f]{40}", sha):
raise ReplayError("candidate commit of the driver checkout is unavailable")
return sha


def replay(root, guest, config):
commands = recipes(root)
commit = candidate(root)
allow_from = json.loads(config)["api_allow_from"]
token = uuid.uuid4().hex
info = guest.virsh("dominfo", guest.domain)
if not re.search(r"^Persistent:\s+no\s*$", info, re.MULTILINE):
raise ReplayError("docs replay requires a transient disposable domain")
Expand All @@ -116,6 +132,7 @@ def replay(root, guest, config):
if not re.fullmatch(r"/var/tmp/rigforge-docs\.[A-Za-z0-9]+", work):
raise ReplayError("invalid guest scratch directory")
quoted = shlex.quote(work)
clone = f"{quoted}/rigforge"
helper = base64.b64encode((root / "tests/e2e-docs-guest.sh").read_bytes()).decode()
prepared = base64.b64encode(config).decode()
guest.run(f"chmod 755 {quoted}\ncd {quoted}\nprintf %s {helper} | base64 -d >check.sh\n"
Expand All @@ -131,10 +148,56 @@ def replay(root, guest, config):
guest.reboot(commands["reboot"])
guest.run(f"{check} installed {args}\n", timeout=600)
print("PASS: reboot autostart, donation, pool, shares and read-only API", flush=True)
guest.run(f"E2E_ALLOWLIST_ALLOWED_SOURCE={ALLOWED_SECOND_SOURCE} {check} allowlist-refuse {args}\n", timeout=300)
guest.run("cd " + clone + "\njq --arg source " + shlex.quote(ALLOWED_SECOND_SOURCE) +
" '.api_allow_from = $source' config.json >config.tmp && mv config.tmp config.json\n"
"sudo ./rigforge.sh apply\n", timeout=300)
guest.run(f"E2E_ALLOWLIST_ALLOWED_SOURCE={ALLOWED_SECOND_SOURCE} {check} allowlist-accept {args}\n", timeout=180)
guest.run("cd " + clone + "\njq --arg original " + shlex.quote(allow_from) +
" '.api_allow_from = $original' config.json >config.tmp && mv config.tmp config.json\n"
"sudo ./rigforge.sh apply\n", timeout=300)
print("PASS: API allowlist refused a second source and accepted an allowed source", flush=True)
guest.run("cd " + clone + "\njq --arg token " + shlex.quote(token) +
" '.control = \"enabled\" | .control_upgrade = \"enabled\" | .ACCESS_TOKEN = $token'"
" config.json >config.tmp && mv config.tmp config.json\n"
"sudo ./rigforge.sh apply\n", timeout=600)
guest.run(f"E2E_CONTROL_TOKEN={token} {check} control-apply {args}\n", timeout=480)
guest.run(f"E2E_CONTROL_TOKEN={token} {check} control-revert {args}\n", timeout=480)
print("PASS: writable control path applied one change and rolled back one change", flush=True)
guest.run("cd " + clone + "\nprobe=$(git -c user.name=docs-replay -c user.email=docs-replay@localhost"
" commit-tree 'HEAD^{tree}' -p HEAD -m 'docs replay upgrade probe')\n"
"git tag " + PROBE_TAG + " \"$probe\"\n", timeout=120)
guest.run(f"E2E_CONTROL_TOKEN={token} E2E_UPGRADE_LEG=noop E2E_CONTROL_PROBE_TAG={PROBE_TAG} "
f"{check} upgrade-leg {args}\n", timeout=480)
guest.run(f"E2E_CONTROL_TOKEN={token} E2E_UPGRADE_LEG=refused E2E_CONTROL_PROBE_TAG={PROBE_TAG} "
f"{check} upgrade-leg {args}\n", timeout=900)
print("PASS: remote-upgrade chain reached noop and refused a forged tag with the checkout intact", flush=True)
guest.run(f"cd {quoted}/rigforge\ngit fetch --quiet --tags origin\n"
f"git fetch --quiet origin {commit}\ngit checkout --quiet --force FETCH_HEAD\n"
"sudo ./rigforge.sh upgrade\n", timeout=2400)
guest.run(f"E2E_CONTROL_TOKEN={token} E2E_EXPECTED_HEAD={commit} {check} upgraded {args}\n", timeout=900)
print("PASS: remote upgrade from the previous release to the candidate kept shares landing", flush=True)
digest = guest.run(f"cd {quoted}/rigforge\nsha256sum config.json | awk '{{print $1}}'\n").strip()
if not re.fullmatch(r"[0-9a-f]{64}", digest):
raise ReplayError("config digest is unreadable")
archive = guest.run(f"cd {quoted}/rigforge\nsudo ./rigforge.sh backup --yes\n"
"ls -1 backups/rigforge-backup-*.tar.gz | sort | tail -1\n",
timeout=300).strip().splitlines()[-1]
if not re.fullmatch(r"backups/rigforge-backup-[0-9]{8}-[0-9]{6}\.tar\.gz", archive):
raise ReplayError("backup archive path is invalid")
guest.run(f"cd {quoted}/rigforge\njq '.DONATION = 1' config.json >config.tmp && mv config.tmp config.json\n")
guest.run(f"cd {quoted}/rigforge\nsudo ./rigforge.sh restore --yes {shlex.quote(archive)}\n", timeout=300)
guest.run(f"E2E_RESTORED_CONFIG_SHA256={digest} {check} restored {args}\n", timeout=120)
print("PASS: backup and restore round-tripped the config", flush=True)
guest.run(f"cd {quoted}/rigforge\nsudo ./rigforge.sh uninstall --yes\n", timeout=120)
guest.reboot(commands["reboot"])
guest.run(f"{check} removed {args}\n")
print("PASS: uninstall remained complete after reboot", flush=True)
guest.run(f"cd {quoted}/rigforge\numask 077\nprintf %s {prepared} | base64 -d >config.json\n")
guest.run(f"cd {quoted}/rigforge\nsudo env RIGFORGE_APPLIANCE=1 LC_ALL=C ./rigforge.sh\n", timeout=3600)
guest.run(f"{check} appliance {args}\n", timeout=300)
print("PASS: appliance mode ran with runtime-only units on the stock systemd guest", flush=True)
guest.run(f"cd {quoted}/rigforge\nsudo env RIGFORGE_APPLIANCE=1 ./rigforge.sh uninstall --yes\n", timeout=120)


def check_config(config):
Expand All @@ -154,7 +217,10 @@ def check_config(config):
or pools[0].get("user", "docs-replay") != "docs-replay"
or pools[0].get("pass", "x") not in ("", "x")):
raise ReplayError("prepared config needs one throwaway pool, donation zero and an API allowlist")
ipaddress.ip_network(data["api_allow_from"], strict=False)
try:
ipaddress.ip_network(data["api_allow_from"], strict=False)
except ValueError:
raise ReplayError("prepared config api_allow_from must be one valid address or network") from None
endpoint = urlsplit("//" + pools[0]["url"])
if (not endpoint.hostname or not endpoint.port or endpoint.username is not None
or endpoint.password is not None or endpoint.path or endpoint.query or endpoint.fragment
Expand Down
Loading
Loading