Files
allmende/nix/test.nix
T
nilsandClaude Sonnet 5.5 e3d0c12e55 Choose even the first region in the browser; update Docker and Nix
A node now starts without any region (it only helps others connect, and
prints a hint). The owner's sign-in link leads straight to the Regions page
when none is followed, visitors get a notice instead of an empty search, and
status always lists regions as an array.

The Docker image no longer pins Bonn, the NixOS module no longer requires
regions, and the VM test now starts without any, chooses the first region
over the API and checks it survives a restart. README and the init hint
follow.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
2026-11-18 10:41:10 +01:00

69 lines
3.3 KiB
Nix

{ pkgs, module }:
pkgs.testers.runNixOSTest {
name = "allmende";
nodes.machine = {
imports = [ module ];
services.allmende = {
enable = true;
# No regions: the owner chooses the first one in the browser (see below).
openFirewall = true;
};
};
testScript = ''
machine.wait_for_unit("multi-user.target")
with subtest("the service waits for setup instead of failing"):
machine.succeed("systemctl show allmende -p ActiveState | grep -q inactive")
machine.fail("systemctl is-failed allmende")
with subtest("init creates the identity, as the service's own user"):
# The VM's shell is a terminal, where init would wait for the phrase to be
# typed back; empty input makes it skip that check, as in a script.
out = machine.succeed("allmende-admin init </dev/null")
assert "recovery phrase" in out.lower(), out
machine.succeed("test $(stat -c %U /var/lib/allmende/admin.token) = allmende")
machine.succeed("test $(stat -c %a /var/lib/allmende/admin.token) = 600")
machine.fail("allmende-admin init </dev/null") # a second init must refuse
with subtest("the node starts and serves the UI and API"):
machine.succeed("systemctl start allmende")
machine.wait_for_open_port(8080)
machine.wait_for_open_port(4001)
status = machine.succeed("curl -sf http://127.0.0.1:8080/api/v1/status")
assert '"regions":[]' in status, status
machine.succeed("curl -sf http://127.0.0.1:8080/ | grep -qi '<html'")
# (no grep -q here: it would close the pipe early and make curl fail with exit 23)
machine.succeed("curl -sf http://127.0.0.1:8080/places.tsv | grep -c '^Bonn'")
with subtest("the owner chooses the first region, and it survives a restart"):
auth = "-H \"Authorization: Bearer $(cat /var/lib/allmende/admin.token)\""
machine.succeed("test $(curl -s -o /dev/null -w '%{http_code}' -X PUT http://127.0.0.1:8080/api/v1/regions -d '{\"regions\":[\"u1j\"]}') = 401")
machine.succeed(f"curl -sf {auth} -X PUT http://127.0.0.1:8080/api/v1/regions -d '{{\"regions\":[\"u1j\"]}}'")
status = machine.succeed("curl -sf http://127.0.0.1:8080/api/v1/status")
assert '"regions":["u1j"]' in status, status
machine.succeed("systemctl restart allmende")
machine.wait_for_open_port(8080)
status = machine.succeed("curl -sf http://127.0.0.1:8080/api/v1/status")
assert '"regions":["u1j"]' in status, status
with subtest("the owner API needs the admin token"):
machine.succeed("test $(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/api/v1/mine) = 401")
machine.succeed(
"curl -sf -H \"Authorization: Bearer $(cat /var/lib/allmende/admin.token)\" http://127.0.0.1:8080/api/v1/mine"
)
with subtest("the web port stays on loopback, the peer port is open"):
machine.succeed("ss -ltn | grep -q '127.0.0.1:8080'")
machine.fail("ss -ltn | grep -q '0.0.0.0:8080'")
with subtest("it stops promptly even though the VM has no DNS, and restarts"):
# The built-in bootstrap name cannot be resolved here; stopping must not wait for it.
machine.succeed("timeout 3 systemctl stop allmende")
machine.succeed("systemctl start allmende")
machine.wait_for_open_port(8080)
'';
}