v1.0.0 — Hexagonal architecture rewrite
All checks were successful
CI / ci (push) Successful in 7m16s
All checks were successful
CI / ci (push) Successful in 7m16s
Restructure the monolithic 252-line main.rs into a 10-crate workspace with clean hexagonal architecture, swappable adapters, and a production- ready deployment pipeline. Backend architecture: - domain: Canvas, Color/Position/PixelUpdate value objects, port traits (CanvasStore, CanvasPersistence, EventBroadcaster), BroadcastEvent - application: use cases (place_pixel, get_state, save/restore snapshot, connect/disconnect), AppState with Arc snapshot cache - config: AppConfig structs + ConfigSource trait - api-types: shared DTOs, event name constants - adapters: config-env, canvas-file, http-axum (rust-embed), socketio, websocket — all behind port traits, swappable via feature flags - server: composition root with graceful shutdown (SIGTERM/SIGINT) Frontend: - Transport abstraction: Socket.IO and native WebSocket via VITE_TRANSPORT - Canvas zoom/pan with mouse wheel, pinch-to-zoom, and +/- buttons - ImageData rendering (~50x faster than fillRect loop) - Touch support, responsive CSS scaling, mobile-friendly layout - OG/Twitter Card meta tags for rich link previews Production: - Docker: musl static build on scratch — 2.73MB image - CI workflows for Gitea and GitHub Actions (fmt, clippy, test, Docker push) - deploy.sh for private registry - 39 unit tests across domain and application - Zero unwraps, zero unsafe, graceful error handling with tracing - Periodic canvas snapshots with rotation, restored on startup - All config via environment variables with typed defaults
This commit is contained in:
75
crates/application/tests/snapshots.rs
Normal file
75
crates/application/tests/snapshots.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
mod common;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use application::AppState;
|
||||
use domain::Color;
|
||||
|
||||
fn state_with_persistence(persistence: common::FakePersistence) -> Arc<AppState> {
|
||||
let spy = common::SpyBroadcaster::new();
|
||||
let state = AppState::new(
|
||||
Box::new(application::InMemoryCanvasStore::new(10, 10)),
|
||||
Box::new(spy),
|
||||
std::time::Duration::from_secs(10),
|
||||
)
|
||||
.with_persistence(Box::new(persistence));
|
||||
Arc::new(state)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_snapshot_persists_current_canvas() {
|
||||
let persistence = common::FakePersistence::empty();
|
||||
let saved_ref = persistence.saved_ref();
|
||||
let state = state_with_persistence(persistence);
|
||||
|
||||
application::canvas::place_pixel::execute(
|
||||
&state,
|
||||
application::canvas::place_pixel::Command {
|
||||
user_id: "user",
|
||||
position: domain::Position::new(0, 0),
|
||||
color: Color::new(0xFF),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
application::canvas::save_snapshot::execute(&state).unwrap();
|
||||
|
||||
let snapshots = saved_ref.lock().unwrap();
|
||||
assert_eq!(snapshots.len(), 1);
|
||||
assert_eq!(snapshots[0][0], Color::new(0xFF));
|
||||
assert_eq!(snapshots[0].len(), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_snapshot_loads_canvas() {
|
||||
let mut snapshot = vec![Color::white(); 100];
|
||||
snapshot[0] = Color::new(0xDEAD);
|
||||
snapshot[99] = Color::new(0xBEEF);
|
||||
|
||||
let state = state_with_persistence(common::FakePersistence::with_snapshot(snapshot));
|
||||
|
||||
let restored = application::canvas::restore_snapshot::execute(&state).unwrap();
|
||||
assert!(restored);
|
||||
|
||||
let pixels = application::canvas::get_state::execute(&state);
|
||||
assert_eq!(pixels[0], Color::new(0xDEAD));
|
||||
assert_eq!(pixels[99], Color::new(0xBEEF));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_returns_false_when_no_snapshot() {
|
||||
let state = state_with_persistence(common::FakePersistence::empty());
|
||||
assert!(!application::canvas::restore_snapshot::execute(&state).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_without_persistence_is_noop() {
|
||||
let (state, _) = common::test_state();
|
||||
assert!(application::canvas::save_snapshot::execute(&state).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_without_persistence_returns_false() {
|
||||
let (state, _) = common::test_state();
|
||||
assert!(!application::canvas::restore_snapshot::execute(&state).unwrap());
|
||||
}
|
||||
Reference in New Issue
Block a user