F: F3 end-to-end peer tests

Real registry and transport against in-process peers and hand-written
listeners: plain, TLS with an rcgen CA, a wrong CA, redirects, oversize
bodies, a silent peer, the 64-peer cap and shutdown mid-follow. Two proxy
cases are ignored: the proxied path is missing its /api/v1 prefix.
This commit is contained in:
ari committed 2026-10-20 15:04:09 -04:00
1 parent ca000d973f
commit 66ee41a672
3 files changed
+686

No files matched your search

+5
View File
@@ -68,3 +68,8 @@ Behaviour tests with the fake transport for every error mapping row in D9; 405 o
- Handoff to WS-D: `PeerRequest.query` carries decoded pairs. A `unit` argument reaches the proxy as the unit name itself (`dev-disk-by\x2did.device`, backslash included) and needs no encoding on D's side; the tool schema takes the plain name, so an already percent-encoded string such as `dev-disk-by%5Cx2did.device` is not a unit name and is `400`.
- Non-blocking 3: a `..` inside a single segment is not traversal, because segments cannot contain `/` and the forwarded path is re-encoded from them. Pinned by allowlist cases `systemd/units/foo..bar.mount` and `docker/containers/foo..bar`, plus a rejection case for an encoded `%2e%2e` inside one segment (`systemd/units/foo%2e%2ebar.mount`), which `encoding_forbidden` catches.
- `docs/api.md` states the `unit` query rule and the `%5C`/literal-backslash forms.
- 2026-10-20 (from WS-F, **blocking defect found by the F3 end-to-end test**): every proxied call to a healthy peer answers `404` and the consolidator maps it to `peer <name>: not found on peer`.
- Cause: `proxy::get` hands `PeerRequest.path` to the transport as the stripped route (`/systemd/units`), and `ReqwestTransport::request_url` builds `{peer.url.path()}/{path}`, i.e. `http://<peer>:1984/systemd/units`. An unmodified peer serves its REST routes only under `/api/v1` (`server::build_router` nests `api::router` at `/api/v1`), so the peer's own 404 comes back. Health checks are unaffected: `health::probe_api` passes `/api/v1/ping`, which is the `PeerRequest.path` form `contracts.md` section 2 specifies ("e.g. `/api/v1/systemd/units`").
- Reproduction (real transport, real peer, no VM): in the WS-F worktree, `cargo test --test peers` — the tests `a_plain_peer_serves_its_own_data_through_the_proxy` and `shutdown_ends_a_proxied_follow` are `#[ignore]`d with this reason and state the contract (proxied units equal a direct call to the peer; the proxied follow ends on shutdown). Removing the attribute is the acceptance check for this fix. It also blocks the proxy subtest of `checks.vm-peers` (`nix/tests/peers.nix`), which expects `200` from `GET /api/v1/peers/beta/systemd/units`.
- Fix, one place: prefix the path the transport sees with `/api/v1` in `proxy::get` (`path: format!("/api/v1{path}")` before building `PeerRequest`), keeping the stripped route for the allowlist and the forward form. Then the `proxy.rs` module doc ("the transport always sees one form" of the stripped path) and the unit tests asserting `forwarded(&fake) == "/systemd/units"` follow the new form. Doing it in the transport instead would leave the probes' `/api/v1/ping` double-prefixed, so the proxy side is the safer place.
- Not fixed here: `src/**` is outside WS-F's Owned files.
@@ -76,3 +76,8 @@ Shippable, documented, verified.
- 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`.
- 2026-10-20: **F3 done** (commit `F: F3 end-to-end peer tests`).
- New `tests/peers.rs`, one integration binary: a consolidator served by the real router (`server::build_router` + `server::serve_listener`) with the real `PeerRegistry`/`ReqwestTransport`, against peers that are either another in-process `slinuxm` (fake sources, real auth with a minted token) or a hand-written listener for the cases a real peer cannot produce. Token files are 0600 temporaries in `$TMPDIR`; `tests/common/mod.rs` is reused for `request`/`parse_response` and not modified (its items would be dead code in the other test binaries).
- Cases: plain peer (status `server.up`/`api.up`/`auth ok`, `peer_version`, list shape, 401 without a caller token, 404 for an unknown peer, 405 on POST, both checks flipping when the peer dies, proxy 503 naming the peer while the caller's token keeps working); TLS peer with an `rcgen` CA and a leaf for `127.0.0.1` via `ca_file` (`api.up` needs a verified handshake and our token); a peer signed by a different CA (`server.up` true, `api.up` false, `last_error = tls_error`, proxy 503 `tls_error`); a `302` (503 `http_302`, and the `Location` target sees **zero** connections); an oversize body (503 `oversize` with `max_response_bytes = 64`); a silent peer (503 `timeout`, bounded); the 64-peer cap (`Config::validate`, the path `serve` uses: 64 accepted, 65 refused); and shutdown ending a proxied follow.
- **Blocking finding, reported to WS-C's Log (2026-10-20)**: the proxy hands the transport the stripped route (`/systemd/units`) while peers serve `/api/v1/systemd/units`, so every proxied call to a healthy peer answers `peer <name>: not found on peer`. Health checks are fine (`/api/v1/ping`). Two tests (`a_plain_peer_serves_its_own_data_through_the_proxy`, `shutdown_ends_a_proxied_follow`) are `#[ignore]`d with that reason and state the contract; removing the attribute is the acceptance check once C (or B) prefixes the path. The same defect will fail the proxy subtest of `checks.vm-peers`.
- Verified: `cargo test --test peers` → 7 passed, 2 ignored.