A0: contract stubs types, transport, fake and registry seams

Land the shared peer contracts: types, error mapping, transport trait,
fake transport and fixtures, registry/proxy/health skeletons, the
AppState.peers and Config.peers seams, the ping and peers route stubs,
and unit plus integration tests. No loops, no network, feature off by
default.
This commit is contained in:
ari committed 2026-10-19 20:02:17 -04:00
1 parent 746b389a2b
commit 4bfb097be6
22 files changed
+1781 -1

No files matched your search

+11 -1
View File
@@ -9,6 +9,8 @@
mod behaviour_tests;
pub mod docker;
pub mod journal;
pub mod peers;
pub mod ping;
pub mod systemd;
use std::convert::Infallible;
@@ -29,10 +31,18 @@ use crate::state::AppState;
/// Routes under `/api/v1`, already bound to `state`.
pub fn router(state: AppState) -> Router {
Router::new()
let router = Router::new()
.merge(systemd::routes())
.merge(journal::routes())
.merge(docker::routes())
.merge(ping::routes());
// Peer routes are absent entirely when the feature is off.
let router = if state.peers.is_some() {
router.merge(peers::routes())
} else {
router
};
router
.fallback(not_found)
.method_not_allowed_fallback(method_not_allowed)
.with_state(state)
+12
View File
@@ -0,0 +1,12 @@
//! Peer status and GET-only pass-through routes.
//!
//! Handlers are added here; the module is merged only when `state.peers` is
//! set, so a peer-less instance has no peers routes at all.
use axum::Router;
use crate::state::AppState;
pub fn routes() -> Router<AppState> {
Router::new()
}
+41
View File
@@ -0,0 +1,41 @@
//! GET /api/v1/ping: cheap authenticated liveness.
//!
//! `/healthz` does not validate a token, so a consolidator cannot use it to
//! prove "API running with our credentials". This route sits behind the same
//! auth layer as every other `/api/v1` route.
use axum::routing::get;
use axum::{Json, Router};
use crate::state::AppState;
pub fn routes() -> Router<AppState> {
Router::new().route("/ping", get(ping))
}
async fn ping() -> Json<serde_json::Value> {
Json(serde_json::json!({
"status": "ok",
"version": env!("CARGO_PKG_VERSION"),
}))
}
#[cfg(test)]
mod tests {
use axum::http::StatusCode;
use crate::api::router;
use crate::api::testutil::{get, json};
use crate::config::Config;
use crate::sources::fake::fake_state;
#[tokio::test]
async fn ping_reports_version() {
let app = router(fake_state(Config::default()));
let (status, body) = get(&app, "/ping").await;
assert_eq!(status, StatusCode::OK);
let v = json(&body);
assert_eq!(v["status"], "ok");
assert_eq!(v["version"], env!("CARGO_PKG_VERSION"));
}
}