spa hardening, offline logging, rate limit fixes

server:
- backup exporter, auth extractors, error shapes, CONTEXT (prior work)
- spa assets served outside the rate limit via route_layer
- requests_per_second went to per_second(), which takes an interval not a
  rate: 50 meant one request per 50s once burst was spent. now converted
  properly. 15/s, burst 60

spa fixes:
- account delete cleared snake_case token keys that were never written
- refresh interceptor could retry forever
- date ranges used local day boundaries stamped +00:00
- "all" period trend plotted one page; calendar days fabricated mood 3
- chart grid invisible: hsl(var(--border)) against rgba tokens
- blob url leak, orphaned media on failed save, devtools in prod bundle
- pt-safe/safe-area-pb classes never existed

spa features:
- offline outbox: entries queue to IndexedDB, replay with backoff, only
  server refusals count against an entry
- drafts persist, quick-log sheet, diary infinite scroll + filters
- route error boundary, stale-chunk recovery, no service worker in dev

a11y + perf:
- mood picker is a radiogroup, activity picker keyboard-operable,
  text alternatives for colour/emoji, locale week start
- dark glass over the bright photo: worst case 1.4:1 -> 4.9-9.6:1
- initial payload 1095->769kB raw, 306->230kB gzip; 38 unused components
  and 5 deps dropped; fonts 218->133kB

53 tests added (43 spa, 10 server)
This commit is contained in:
2026-08-28 14:59:21 +02:00
parent 23d052278a
commit bf148902ab
395 changed files with 13972 additions and 10635 deletions

View File

@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};
use chrono::Utc;
use chrono::{Duration, Utc};
use domain::errors::DomainError;
use domain::ports::{ReminderCommandPort, ReminderSenderPort, UserCommandPort};
@@ -71,8 +71,10 @@ async fn a_failing_send_does_not_abort_the_sweep() {
let sender = Arc::new(FlakySender::new(broken.id().clone()));
let deps = process_due_reminders::Deps {
reminder_query: store.clone(),
reminder_command: store.clone(),
user_query: store.clone(),
sender: sender.clone(),
grace: Duration::minutes(30),
};
let sent = process_due_reminders::execute(&deps).await.unwrap();
@@ -85,3 +87,89 @@ async fn a_failing_send_does_not_abort_the_sweep() {
"both users should have been attempted regardless of order, got {attempts:?}"
);
}
struct CountingSender {
attempts: Mutex<Vec<UserId>>,
}
impl CountingSender {
fn new() -> Self {
Self {
attempts: Mutex::new(Vec::new()),
}
}
fn count(&self) -> usize {
self.attempts.lock().unwrap().len()
}
}
#[async_trait::async_trait]
impl ReminderSenderPort for CountingSender {
async fn send_reminder(&self, user_id: &UserId) -> Result<(), DomainError> {
self.attempts.lock().unwrap().push(user_id.clone());
Ok(())
}
}
#[tokio::test]
async fn a_reminder_is_sent_once_however_often_the_sweep_runs() {
let store = Arc::new(InMemoryStore::new());
let mut user = test_user("nadia");
user.update_timezone(Some(Timezone::new("UTC").unwrap()));
UserCommandPort::save(&*store, &user).await.unwrap();
ReminderCommandPort::save(&*store, &due_now(user.id().clone()))
.await
.unwrap();
let sender = Arc::new(CountingSender::new());
let deps = process_due_reminders::Deps {
reminder_query: store.clone(),
reminder_command: store.clone(),
user_query: store.clone(),
sender: sender.clone(),
grace: Duration::minutes(30),
};
for _ in 0..5 {
process_due_reminders::execute(&deps).await.unwrap();
}
assert_eq!(
sender.count(),
1,
"five sweeps inside one grace window must still send one reminder"
);
}
#[tokio::test]
async fn a_send_that_fails_is_retried_by_the_next_sweep() {
let store = Arc::new(InMemoryStore::new());
let mut user = test_user("broken");
user.update_timezone(Some(Timezone::new("UTC").unwrap()));
UserCommandPort::save(&*store, &user).await.unwrap();
ReminderCommandPort::save(&*store, &due_now(user.id().clone()))
.await
.unwrap();
let sender = Arc::new(FlakySender::new(user.id().clone()));
let deps = process_due_reminders::Deps {
reminder_query: store.clone(),
reminder_command: store.clone(),
user_query: store.clone(),
sender: sender.clone(),
grace: Duration::minutes(30),
};
process_due_reminders::execute(&deps).await.unwrap();
process_due_reminders::execute(&deps).await.unwrap();
assert_eq!(
sender.attempts().len(),
2,
"nothing was delivered, so the occurrence is still owed"
);
}