F: F2 promote the peers VM test and the module eval test into checks
The test nodes declare peers through the first-class module options, so LoadCredential and RefreshOnReload come from the module. Every node binds :: because the test network resolves node names to IPv6 first. poll() raises with the last observed status JSON.
This commit is contained in:
1 parent
4f5fa589ac
commit
ca000d973f
4 files changed
+167
-70
No files matched your search
@@ -313,14 +313,16 @@ services.skyg-linux-tracker.peers = {
|
||||
|
||||
Rendering: one `[[peers.peer]]` per enabled peer with `token_file = "/run/credentials/skyg-linux-tracker.service/peer-<name>"`, `LoadCredential=peer-<name>:<tokenFile>`, `RefreshOnReload=credentials`, `ExecReload` = SIGHUP, assertions as in F1.
|
||||
|
||||
## 10. Test config contract (assumed by `nix/tests/peers.nix`, WS-T)
|
||||
## 10. Test config contract (`nix/tests/peers.nix`)
|
||||
|
||||
The VM test is written against the pre-F1 configuration style, so the TOML contract above must stay compatible with it:
|
||||
The VM test declares its peers with the module's first-class options (F2), so the TOML contract above must stay compatible with what they render:
|
||||
|
||||
- Hosts: `alpha` (peers `beta` over plain HTTP, `gamma` over HTTPS with `ca_file`), `beta` (peer `alpha`), `gamma` (TLS-only, no peers). Port 1984, bind `0.0.0.0`.
|
||||
- Config comes through the module's freeform `settings.peers = { enabled = true; tcp_interval_secs = 2; tcp_timeout_secs = 1; api_interval_secs = 3; api_timeout_secs = 2; fail_threshold = 2; request_timeout_secs = 4; peer = [ ... ]; }`, i.e. `[peers]` scalars plus `[[peers.peer]]` with keys `name`, `url`, `token_file`, `allow_plain_http`, optional `ca_file`.
|
||||
- `token_file = /run/credentials/skyg-linux-tracker.service/peer-<name>` (via `LoadCredential=peer-<name>:/var/lib/peer-tokens/<name>`); the file holds the placeholder `pending` until the test installs a real token, so the placeholder must pass A3 loading (non-empty, under `$CREDENTIALS_DIRECTORY` so the permission check is skipped) and be reported as `auth = "rejected"`, not as a config error.
|
||||
- Hosts: `alpha` (peers `beta` over plain HTTP, `gamma` over HTTPS with `ca_file`), `beta` (peer `alpha`), `gamma` (TLS-only, no peers). Port 1984, bind `::` (dual stack, see the address note below).
|
||||
- Config comes through the module: `peers.enable = true`, `peers.settings = { tcp_interval_secs = 2; tcp_timeout_secs = 1; api_interval_secs = 3; api_timeout_secs = 2; fail_threshold = 2; request_timeout_secs = 4; }` and `peers.peers.<name> = { url; tokenFile; caFile ? null; allowPlainHttp }`. The module renders `[peers]` plus one `[[peers.peer]]` per enabled peer with keys `name`, `url`, `token_file`, `allow_plain_http`, optional `ca_file`.
|
||||
- `token_file = /run/credentials/skyg-linux-tracker.service/peer-<name>` (the module adds `LoadCredential=peer-<name>:/var/lib/peer-tokens/<name>` and `RefreshOnReload=credentials`); the file holds the placeholder `pending` until the test installs a real token, so the placeholder must pass A3 loading (non-empty, under `$CREDENTIALS_DIRECTORY` so the permission check is skipped) and be reported as `auth = "rejected"`, not as a config error.
|
||||
- Address note: a test node's name resolves to both its IPv4 and its IPv6 address, and resolution returns the IPv6 one first, so each node binds `::` and the peer URLs keep the hostnames. A peer reachable only on IPv4 is reported as `unreachable` (the transport connects to the first resolved address); see the ws-f Log.
|
||||
- Token rotation = `mv` a new file into place and `systemctl reload skyg-linux-tracker.service` (SIGHUP with `RefreshOnReload=credentials`); status must recover without a restart. SIGHUP must therefore re-read token files and keep the registry (B4).
|
||||
- Timeouts (1 s / 2 s) are below intervals (2 s / 3 s), as validation requires; `request_timeout_secs = 4` and the test's `elapsed < 15` bound the proxy call when a peer VM is down.
|
||||
- Assertions the contract must satisfy: `GET /api/v1/peers/<p>` JSON has `server.up`, `api.up`, `api.auth` in {`ok`,`rejected`}; `GET /api/v1/peers` body contains each peer name; proxied `GET /api/v1/peers/<p>/systemd/units[/<unit>.service]` returns the peer's data with response header `x-slinuxm-peer: <p>`; `POST`/`DELETE` on a proxy path -> 405; `x-slinuxm-hop: 1` -> 4xx; unknown peer -> 404; peer rejected/down -> 503 with the peer name in the body and the caller's own token still valid; MCP `list_peers` output contains the peer names; MCP `list_systemd_units` with `{"peer": "<p>"}` returns the peer's units.
|
||||
- The peer's `/api/v1/ping` must return 401 for a bad token (placeholder case) and 200 for a good one; the test relies on `api.up = true` with `auth = "rejected"` for the 401 case (D4).
|
||||
- Removal: the test replaces the rendered `/etc/skyg-linux-tracker.toml` symlink with an edited copy (one `[[peers.peer]]` block dropped), sends SIGHUP, and expects the peer to disappear from `GET /api/v1/peers` and to 404 on `GET /api/v1/peers/<p>`, with the service's `MainPID` unchanged. Rotation and revocation likewise leave `MainPID` alone.
|
||||
@@ -64,3 +64,15 @@ Shippable, documented, verified.
|
||||
- Eval cases: 40, the new ones proving a peer `url` change and an `api_interval_secs` change move only `reloadTriggers` while `port`, `auth`, `deny_cidrs` and `max_concurrent_total` changes move `restartTriggers`, plus the new assertions and both enabled-conflict directions.
|
||||
- Recorded for F2: `nix/tests/module-peers.nix` is now in the Owned files row, and F2 must add it as `checks.module-peers` so `nix flake check` and `dev-test ci` run it.
|
||||
- Still open: the two VM tests, see the "Not run" note above.
|
||||
- 2026-10-20: rebased `ws/F` onto `main` (9e4fb38, D merged). D's MCP peer tools (`list_peers`, the `peer` argument) were not on the branch, so the test's MCP subtest could not pass; the rebase is mechanical, F1's commits are unchanged.
|
||||
- 2026-10-20: **F2 done** (commit `F: F2 promote the peers VM test and the module eval test into checks`).
|
||||
- **Root cause of the known failure** (the first peers subtest timing out while `/api/v1/peers/beta` answered 200): not the JSON shape. `contracts.md` section 3 and the real binary agree (`server.up`, `api.up`, and `api.auth` = `"rejected"` with a 401). It was address selection: the test network writes **both** an IPv4 and an IPv6 address for every node into `/etc/hosts` (`nixos/lib/testing/network.nix`), name resolution returns the IPv6 one first, and the nodes bound `0.0.0.0`. `ReqwestTransport::resolve_target` takes `addrs.first()` (the IPv6 address), so both probes failed with `unreachable` (`server.up` false, `api.up` false, `api.auth` `"unknown"`) while curl reached the IPv4 address. Reproduced locally with `url = "http://localhost:1985"` against a peer bound to `127.0.0.1`: `/api/v1/peers/beta` reported `server.up: false, api.up: false, api.last_error: "unreachable"`. With the peer bound to `::` the same setup reports `up: true, up: true, auth: "rejected"`.
|
||||
- Test fix (the binary is unchanged): every node binds `::` (dual stack; Linux accepts IPv4-mapped connections, verified against the release binary on both `127.0.0.1` and `::1`) and the peer URLs keep their hostnames, so the TLS peer still verifies its `DNS:gamma` SAN. Reported to WS-B in the Handoff: a peer that listens on IPv4 only is reported as `unreachable` when its name also resolves to IPv6, because the transport connects to the first resolved address only. A candidate fix (WS-B, `src/peers/client.rs`) is to try the resolved addresses in order, or to prefer the family the peer actually answers on.
|
||||
- `poll()` now raises with the **last observed value**: `wait_status` hands it the status JSON of every attempt, so a timeout prints e.g. `last observed: {"api": {"auth": "unknown", ...}}` instead of `(last error: None)`. New `wait_gone` for the removal case.
|
||||
- Switched to the first-class options: `peers.enable`, `peers.settings` (intervals/timeouts only), `peers.peers.<name> = { url; tokenFile; caFile; allowPlainHttp }`. The test's hand-written `LoadCredential` and `RefreshOnReload` override are gone; the module renders `token_file = /run/credentials/skyg-linux-tracker.service/peer-<name>`, one `LoadCredential=peer-<name>:/var/lib/peer-tokens/<name>` per enabled peer and `RefreshOnReload=credentials`. Token stand-ins stay root-only 0400 files under `/var/lib/peer-tokens` (agenix stand-ins). gamma keeps `peers` off (a peer-less node), since `peers.enable` requires a peer.
|
||||
- New assertions: fan-in (alpha's `GET /api/v1/peers` lists exactly beta and gamma, both with `server.up`, `api.up`, `auth == "ok"` and a `peer_version`; gamma's display URL is `https://`); proxied unit names equal a **direct** call to the peer's own API (and differ from alpha's own); placeholder-token rejection also covers the TLS peer; token install, revoke and rotation leave `MainPID` unchanged; **removing a peer** (the rendered `/etc/skyg-linux-tracker.toml` symlink is replaced by an edited copy with gamma's `[[peers.peer]]` block dropped, then SIGHUP) makes gamma 404 on `GET /api/v1/peers/gamma`, drop out of `GET /api/v1/peers`, leaves beta healthy, leaves gamma's token file at 0400 and leaves `MainPID` unchanged. The outage subtests run last, because gamma is no longer configured after the removal.
|
||||
- `flake.nix`: `tests.${system}.peers` is gone; `checks.${system}` now has `package`, `vm`, `vm-peers` (the same VM test) and `module-peers`. `module-peers` wraps the eval test in `pkgs.runCommand` whose interpolation forces the returned list, so a failing case throws during **evaluation** of the derivation and `nix flake check` fails without a VM (a bare list is not a derivation and `nix flake check` rejects it).
|
||||
- `contracts.md` section 10 updated (first-class options, dual-stack bind and the address note, the removal scenario). That file is outside the Owned files row but the F2 task text assigns section 10 to F2; no other section changed.
|
||||
- Verified here (no nix **builds** in this worktree, per AGENTS.md): `nix eval` of `nix/tests/module-peers.nix` after the rebase, 40/40 cases; `nix eval` of `checks.x86_64-linux.{module-peers,vm-peers}.drvPath` (both instantiate, so the test nodes, the module assertions and the first-class rendering are all evaluated); `nix-instantiate --parse` on `flake.nix`, `nix/tests/peers.nix`; `python3 -m py_compile` on the assembled `testScript`.
|
||||
- **For the orchestrator to run** (the nix gate): `nix flake check -L` (now includes `checks.vm-peers` and `checks.module-peers`), or `nix build .#checks.x86_64-linux.vm-peers -L` on its own.
|
||||
- **Seam, blocking for `dev-test vm peers` (WS-T owns `dev/dev-test.nu`)**: `vm-steps` builds `.#($attr).($system).($name)` with `"peers" => "tests"`, so after the move it must build `.#checks.($system).vm-peers`. Suggested change: keep `let attr = "checks"` and map the build name (`"peers" => "vm-peers"`, `_ => $name`). `dev-test ci` is unaffected (it runs `vm`), as is `nix flake check`.
|
||||
Reference in new issue
Block a user