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
70 lines
1.7 KiB
Rust
70 lines
1.7 KiB
Rust
use domain::{Color, PixelUpdate, Position};
|
|
|
|
#[test]
|
|
fn color_roundtrips_through_u32() {
|
|
for value in [0, 0xFF, 0xFF0000, 0xFFFFFFFF, 0xDEADBEEF] {
|
|
assert_eq!(Color::new(value).as_u32(), value);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn color_white_is_full_alpha() {
|
|
assert_eq!(Color::white().as_u32(), 0xFFFFFFFF);
|
|
}
|
|
|
|
#[test]
|
|
fn color_equality() {
|
|
assert_eq!(Color::new(42), Color::new(42));
|
|
assert_ne!(Color::new(1), Color::new(2));
|
|
}
|
|
|
|
#[test]
|
|
fn collect_as_u32_preserves_values() {
|
|
let colors = [Color::new(1), Color::new(2), Color::new(3)];
|
|
assert_eq!(Color::collect_as_u32(&colors), vec![1, 2, 3]);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_as_bytes_length() {
|
|
let colors = vec![Color::white(); 10];
|
|
assert_eq!(Color::collect_as_bytes(&colors).len(), 40);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_as_bytes_roundtrips() {
|
|
let original = vec![Color::new(0x01020304), Color::new(0xAABBCCDD)];
|
|
let bytes = Color::collect_as_bytes(&original);
|
|
let restored: Vec<Color> = bytes
|
|
.chunks_exact(4)
|
|
.map(|c| Color::new(u32::from_ne_bytes([c[0], c[1], c[2], c[3]])))
|
|
.collect();
|
|
assert_eq!(original, restored);
|
|
}
|
|
|
|
#[test]
|
|
fn position_accessors() {
|
|
let pos = Position::new(42, 17);
|
|
assert_eq!(pos.x(), 42);
|
|
assert_eq!(pos.y(), 17);
|
|
}
|
|
|
|
#[test]
|
|
fn position_display() {
|
|
assert_eq!(Position::new(3, 7).to_string(), "(3, 7)");
|
|
}
|
|
|
|
#[test]
|
|
fn position_equality() {
|
|
assert_eq!(Position::new(1, 2), Position::new(1, 2));
|
|
assert_ne!(Position::new(1, 2), Position::new(2, 1));
|
|
}
|
|
|
|
#[test]
|
|
fn pixel_update_carries_position_and_color() {
|
|
let pos = Position::new(5, 10);
|
|
let color = Color::new(0xFF00FF);
|
|
let update = PixelUpdate::new(pos, color);
|
|
assert_eq!(update.position(), pos);
|
|
assert_eq!(update.color(), color);
|
|
}
|