feat(config): effective config via ArcSwap + DB overlay at boot (Stage 2)

Wire the settings overlay into the live config path:
- AppState.config: Config -> Arc<ArcSwap<Config>> (hot-swappable effective config) +
  config_base: Arc<Config> (immutable env-only). New AppState::cfg() accessor; every
  config read goes through it (state.cfg().field), so a runtime-safe operator edit is
  seen on the next request. One Config type, no parallel path.
- Boot (main.rs): load_settings_overlay -> Config::apply_overlay(validate) -> build
  every client/worker/router from the EFFECTIVE config. A persisted overlay that no
  longer validates is ignored (boot env-only + loud log), never bricks. Env-only when
  ADMIN_KEY_INTEGRITY_SECRET is unset.
- Migrated ~59 state.config.X reads to state.cfg().X across api/*; bound guards where a
  reference outlives the statement; integrity_secret returns owned String.
- Test harness builds AppState with ArcSwap + config_base (arc-swap dev-dep).

Behavior-preserving: with no operator_settings rows, effective == env config.
cargo check --all-targets clean; lib tests 256/0.
This commit is contained in:
jwinterm
2026-07-18 06:00:16 -04:00
parent 00968a9c05
commit 4c83e53839
24 changed files with 153 additions and 101 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ async fn admin_login_guard_refresh_logout_flow() {
let app = require_app!();
let admin = app.admin_router();
let secret = app.state.config.admin.key_integrity_secret.clone();
let secret = app.state.cfg().admin.key_integrity_secret.clone();
// Seed a PENDING admin key for our signer.
let sk = random_signer();
+3 -2
View File
@@ -89,7 +89,8 @@ pub async fn try_app_with(mutate: impl FnOnce(&mut Config)) -> Option<TestApp> {
.enabled
.then(|| AdminSessionManager::new(&config.admin.jwt_secret));
let state = Arc::new(AppState {
config,
config: Arc::new(arc_swap::ArcSwap::from_pointee(config.clone())),
config_base: Arc::new(config),
db,
sessions,
chains,
@@ -258,7 +259,7 @@ impl TestApp {
.expect("mint token pair");
let hash = hash_refresh_token(
&pair.refresh_token,
&self.state.config.secrets.refresh_token_pepper,
&self.state.cfg().secrets.refresh_token_pepper,
);
self.state
.db
+2 -2
View File
@@ -89,7 +89,7 @@ async fn erasure_request_confirm_execute_flow() {
let app = require_app!();
let base = app
.state
.config
.cfg()
.identity
.public_api_url
.clone()
@@ -221,7 +221,7 @@ async fn erasure_request_confirm_execute_flow() {
assert!(body["erasure_id"].as_str().is_some());
assert_eq!(body["status"], "pending");
let secret = app.state.config.admin.key_integrity_secret.clone();
let secret = app.state.cfg().admin.key_integrity_secret.clone();
// [HIGH regression] a request CANCELLED after confirmation is NOT executed:
// execute claims `WHERE status='confirmed'`, so a cancelled row is skipped.
+1 -1
View File
@@ -78,7 +78,7 @@ async fn link_challenge_then_link_resolves_and_rejects_replay_and_wrong_user() {
let app = require_app!();
let base = app
.state
.config
.cfg()
.identity
.public_api_url
.clone()
+3 -3
View File
@@ -88,7 +88,7 @@ async fn register_creates_user_by_npub_and_is_idempotent() {
let app = require_app!();
let base = app
.state
.config
.cfg()
.identity
.public_api_url
.clone()
@@ -120,7 +120,7 @@ async fn register_replays_are_rejected() {
let app = require_app!();
let base = app
.state
.config
.cfg()
.identity
.public_api_url
.clone()
@@ -160,7 +160,7 @@ async fn register_refuses_to_bind_npub_onto_existing_seed_fingerprint_row_withou
let app = require_app!();
let base = app
.state
.config
.cfg()
.identity
.public_api_url
.clone()
+1 -1
View File
@@ -88,7 +88,7 @@ async fn is_registered_npub_membership() {
#[tokio::test]
async fn admission_inbox_outbox_end_to_end() {
let app = require_app!();
let svc = AdmissionService::new(inbox_outbox_relay(&app.state.config), app.state.db.clone());
let svc = AdmissionService::new(inbox_outbox_relay(&app.state.cfg()), app.state.db.clone());
let author = hex64("b1"); // registered author (outbox)
let recipient = hex64("b2"); // registered recipient (inbox)