You are a constitutional council ranking individual git commits for ownership allocation. Compare these two commits. Decide which contributed more lasting value to the project. Judge substance, not spectacle: - Prefer correct, lasting design and real bugfixes over churn, formatting, renames, or generated noise. - Prefer clarity and necessity over sheer line count. A small precise change can beat a large diffuse one. - Do not favor a side merely because its patch is longer or noisier. - Weight what the change does for the project, not the contributor's name. Return ONLY a JSON object: {"winner": "A" or "B", "ratio": "N:M", "explanation": "..."} The explanation must cite concrete differences in the patches (1-3 sentences). Side A — contributor: tommy-mor Side A — commit message: [4cd0d15d] more seed Side A — unified diff (full patch): diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9cb07c60cb0da063f747cfbf1b3b876ecb8ba03e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# time 0.3.47+ requires Rust 1.88 (edition 2024) +FROM rust:1.88-slim as builder + +WORKDIR /build + +RUN apt-get update && \ + apt-get install -y pkg-config libssl-dev && \ + rm -rf /var/lib/apt/lists/* + +# Copy source and build. (Keep it simple to avoid remote build cache oddities.) +COPY . . +RUN cargo build --release --package slugsocial-server + +FROM debian:bookworm-slim + +RUN apt-get update && \ + apt-get install -y ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY --from=builder /build/target/release/slugsocial-server /app/slugsocial-server + +# Create data directory for persistent volume +RUN mkdir -p /data + +ENV SLUG_DATA_DIR=/data +ENV SLUG_EVENT_LOG=/data/events.jsonl +ENV PORT=8080 + +EXPOSE 8080 + +CMD ["/app/slugsocial-server"] + diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000000000000000000000000000000000000..0bf892d44f491cb2313e01ae8a942c3097c52948 --- /dev/null +++ b/deps.edn @@ -0,0 +1,10 @@ +{:paths ["." "test"] + :deps {cheshire/cheshire {:mvn/version "5.13.0"} + http-kit/http-kit {:mvn/version "2.8.0"} + babashka/fs {:mvn/version "0.5.32"} + babashka/process {:mvn/version "0.6.25"} + com.blockether/spel {:mvn/version "0.7.11"}} + :aliases + {:kaocha {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"} + lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}} + :main-opts ["-m" "kaocha.runner"]}}} diff --git a/event_log.rs b/event_log.rs new file mode 100644 index 0000000000000000000000000000000000000000..eaae0d495e43a45d6590603892265a62cc92906e --- /dev/null +++ b/event_log.rs @@ -0,0 +1,83 @@ +use std::path::{Path, PathBuf}; + +use tokio::{ + fs::{self, OpenOptions}, + io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, +}; + +use crate::events::Event; + +#[derive(Debug, thiserror::Error)] +pub enum EventLogError { + #[error("io error: {0}")] + Io(#[from] std::io::Error), + #[error("json error: {0}")] + Json(#[from] serde_json::Error), +} + +#[derive(Debug, Clone)] +pub struct EventLog { + path: PathBuf, +} + +impl EventLog { + pub fn new(path: impl Into) -> Self { + Self { path: path.into() } + } + + pub fn path(&self) -> &Path { + &self.path + } + + pub async fn ensure_parent_dir(&self) -> Result<(), EventLogError> { + if let Some(parent) = self.path.parent() { + fs::create_dir_all(parent).await?; + } + Ok(()) + } + + pub async fn append(&self, event: &Event) -> Result<(), EventLogError> { + self.ensure_parent_dir().await?; + let mut f: tokio::fs::File = OpenOptions::new() + .create(true) + .append(true) + .open(&self.path) + .await?; + + let mut line = serde_json::to_string(event)?; + line.push('\n'); + f.write_all(line.as_bytes()).await?; + f.flush().await?; + Ok(()) + } + + /// Load events from JSONL. Corrupt lines are skipped and returned as `(line_no, line)`. + pub async fn load_all(&self) -> Result<(Vec, Vec<(usize, String)>), EventLogError> { + if !fs::try_exists(&self.path).await? { + return Ok((vec![], vec![])); + } + + let f = fs::File::open(&self.path).await?; + let mut reader = BufReader::new(f).lines(); + + let mut events = Vec::new(); + let mut bad_lines = Vec::new(); + + let mut line_no: usize = 0; + while let Some(line) = reader.next_line().await? { + line_no += 1; + let trimmed = line.trim(); + if trimmed.is_empty() { + continue; + } + match serde_json::from_str::(trimmed) { + Ok(ev) => events.push(ev), + Err(_) => bad_lines.push((line_no, line)), + } + } + + Ok((events, bad_lines)) + } +} + + diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000000000000000000000000000000000000..bbb9345e527452db1d87a549213645c195eae5fc --- /dev/null +++ b/fly.toml @@ -0,0 +1,42 @@ +app = "slugsocial" +primary_region = "iad" + +[build] + dockerfile = "Dockerfile" + +[env] + SLUG_DATA_DIR = "/data" + SLUG_EVENT_LOG = "/data/events.jsonl" + PORT = "8080" + +[[services]] + internal_port = 8080 + protocol = "tcp" + + [[services.ports]] + port = 80 + handlers = ["http"] + force_https = true + + [[services.ports]] + port = 443 + handlers = ["tls", "http"] + + [services.concurrency] + type = "connections" + hard_limit = 1000 + soft_limit = 500 + + [[services.http_checks]] + interval = "10s" + timeout = "2s" + grace_period = "5s" + method = "GET" + path = "/healthz" + protocol = "http" + tls_skip_verify = false + +[[mounts]] + source = "slugsocial_data" + destination = "/data" + diff --git a/views.rs b/views.rs new file mode 100644 index 0000000000000000000000000000000000000000..d4f0ffc49475f014698b4da0de6f476884430813 --- /dev/null +++ b/views.rs @@ -0,0 +1,63 @@ +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; +use tokio::sync::mpsc; + +type CountMap = Arc>>; + +#[derive(Clone)] +pub struct ViewStore { + counts: CountMap, + flush_tx: mpsc::Sender<()>, +} + +impl ViewStore { + pub fn new(json_path: &str) -> Self { + // Load existing counts from disk on startup (best-effort) + let initial: HashMap = std::fs::read_to_string(json_path) + .ok() + .and_then(|s| serde_json::from_str(&s).ok()) + .unwrap_or_default(); + + let counts: CountMap = Arc::new(Mutex::new(initial)); + let (flush_tx, mut flush_rx) = mpsc::channel::<()>(64); + let path = json_path.to_string(); + + let counts_for_writer = counts.clone(); + tokio::spawn(async move { + while flush_rx.recv().await.is_some() { + while flush_rx.try_recv().is_ok() {} + + let snapshot: HashMap = { + counts_for_writer.lock().unwrap().clone() + }; + + let path = path.clone(); + let _ = tokio::task::spawn_blocking(move || { + if let Ok(json) = serde_json::to_string(&snapshot) { + let tmp = format!("{path}.tmp"); + if std::fs::write(&tmp, &json).is_ok() { + let _ = std::fs::rename(&tmp, &path); + } + } + }) + .await; + } + }); + + Self { counts, flush_tx } + } + + pub fn increment(&self, path: String) { + { + let mut map = self.counts.lock().unwrap(); + *map.entry(path).or_insert(0) += 1; + } + let _ = self.flush_tx.try_send(()); + } + + pub fn get_views(&self, path: &str) -> u64 { + self.counts.lock().unwrap().get(path).copied().unwrap_or(0) + } +} Side B — contributor: tommy-mor Side B — commit message: [10c9caac] Fix all workspace clippy warnings. Wire up a missing ui_action test, allow dead code in shared integration helpers, and apply small clippy cleanups across server and types. Co-authored-by: Cursor Side B — unified diff (full patch): diff --git a/server/src/dsl.rs b/server/src/dsl.rs index a45c5b33e10d0d2ea48c7313061cfa1e6430bcfc..faa8aac6616bc6ea2b102d08ae999c01a716ef6e 100644 --- a/server/src/dsl.rs +++ b/server/src/dsl.rs @@ -927,9 +927,7 @@ mod tests { #[test] fn parse_vote_rejects_zero_zero_ratio() { let err = parse_full("{tie placeholder}\n~/a 0:0 ~/b").unwrap_err(); - let msg = match err { - DslError::Parse(m) => m, - }; + let DslError::Parse(msg) = err; assert!( msg.contains("0:0"), "expected 0:0 rejection message, got: {msg}" diff --git a/server/src/html/garden/tests.rs b/server/src/html/garden/tests.rs index c2036fca7752aef63d260e36cfe9649f63b5c550..0a1be1290fdc93197ca191197a473840bb4decbc 100644 --- a/server/src/html/garden/tests.rs +++ b/server/src/html/garden/tests.rs @@ -346,7 +346,7 @@ fn vote_compare_item_card_renders_github_import_markup() { "headline": "#1 Compare card", "sublines": ["State: open"], }); - let body = format!("```slug-github-card\n{}\n```", json.to_string()); + let body = format!("```slug-github-card\n{json}\n```"); let html = vote_compare_item_card( &nav, &item, diff --git a/server/src/html/ui_action.rs b/server/src/html/ui_action.rs index 2589a2cc00bb7b18cd19ebcbb938083122d6921d..5e4131dd346a6f80bfe091a9b0cf7902721bc47f 100644 --- a/server/src/html/ui_action.rs +++ b/server/src/html/ui_action.rs @@ -246,6 +246,7 @@ mod tests { ); } + #[test] fn set_new_thread_compose_expanded_true() { let template = serde_json::json!({ "action": "set_new_thread_compose_expanded", diff --git a/server/src/offline.rs b/server/src/offline.rs index 2db6f67e22e00a24ce673d13095644dd9fa9342d..93d4d5ee55449da644f732bc0ba007ee4c2c7079 100644 --- a/server/src/offline.rs +++ b/server/src/offline.rs @@ -167,7 +167,7 @@ fn rankings_for_simulated( .iter() .map(|parent| { let scoped_content = simulated - .content_for_scope(&scope) + .content_for_scope(scope) .unwrap_or_else(|| simulated.public()); let scoped = build_children_rankings(scoped_content, parent); let components: Vec = scoped @@ -254,7 +254,9 @@ fn ingest_parse_error(raw: &str) -> Option { dsl::parse_full(raw).err().map(|e| e.to_string()) } -fn load_events_from_jsonl(path: &Path) -> Result<(usize, Vec<(usize, Event)>, Vec), std::io::Error> { +type JsonlEventsLoad = Result<(usize, Vec<(usize, Event)>, Vec), std::io::Error>; + +fn load_events_from_jsonl(path: &Path) -> JsonlEventsLoad { let text = std::fs::read_to_string(path)?; let total_lines = text.lines().count(); let mut events = Vec::new(); diff --git a/server/src/resolvers/github.rs b/server/src/resolvers/github.rs index 30dd4cdac96de0e3da4fa03fdf82f91bed73bfe0..3cec5e8b7249a4597c378890cc9e6125104e76c3 100644 --- a/server/src/resolvers/github.rs +++ b/server/src/resolvers/github.rs @@ -749,6 +749,6 @@ mod tests { GithubImportKind::Issue, ); assert!(card.sublines.iter().any(|l| l.contains("@octo"))); - assert_eq!(card.excerpt.as_deref(), Some("The issue body.").as_deref()); + assert_eq!(card.excerpt.as_deref(), Some("The issue body.")); } } diff --git a/server/tests/basic.rs b/server/tests/basic.rs index 31a35251a8abd6f4a48c1d7782b6985f621375e1..9d83e7a97e2c7494790db17c4b5b30c181705026 100644 --- a/server/tests/basic.rs +++ b/server/tests/basic.rs @@ -337,7 +337,7 @@ async fn event_log_handles_corrupt_lines() { .unwrap(); // Add empty line. - writeln!(f, "").unwrap(); + writeln!(f).unwrap(); let (loaded, bad) = log.load_all().await.unwrap(); assert_eq!(loaded.len(), 2); @@ -511,9 +511,7 @@ fn dsl_parse_rejects_zero_zero_vote_ratio() { "~/t/a {a}\n~/t/b {b}\n{zero}\n~/t/a 0:0 ~/t/b\n", ) .expect_err("0:0 vote must be rejected by the parser"); - let msg = match err { - slugsocial_server::dsl::DslError::Parse(m) => m, - }; + let slugsocial_server::dsl::DslError::Parse(msg) = err; assert!( msg.contains("0:0"), "expected message about invalid 0:0 ratio, got: {msg}" @@ -904,7 +902,7 @@ fn posts_by_actor_indexes_and_profile_visibility() { fn feed_query(state: &ReducerState, cutoff: i64, limit: usize) -> (usize, Vec) { let matching: Vec<&str> = state.ingests_ordered.iter().rev() .map(|id| id.as_str()) - .take_while(|id| state.ingests_by_id.get(*id).map_or(false, |ing| ing.ts > cutoff)) + .take_while(|id| state.ingests_by_id.get(*id).is_some_and(|ing| ing.ts > cutoff)) .filter(|id| { state.ingests_by_id.get(*id).is_some_and(|ing| { let scope = slugsocial_server::reducer::scope_from_room_wire(&ing.room_id); diff --git a/server/tests/integration_health.rs b/server/tests/integration_health.rs index 481222d8c48c44fcfb7e9ba26cf7644b5c26d5f4..351aae6b0e9738021886a076ee08fab5cf5a0001 100644 --- a/server/tests/integration_health.rs +++ b/server/tests/integration_health.rs @@ -7,7 +7,7 @@ async fn test_healthz() { let (addr, _tmp, _log, _handle) = create_test_server().await; let client = reqwest::Client::new(); let response = client - .get(&format!("http://{}/healthz", addr)) + .get(format!("http://{}/healthz", addr)) .send() .await .unwrap(); diff --git a/server/tests/integration_rpc.rs b/server/tests/integration_rpc.rs index ccd89a02594bd2a8e7047edafca04b0e54384139..ec446d94a38c8d6961d2135dd031da7ab2a39b48 100644 --- a/server/tests/integration_rpc.rs +++ b/server/tests/integration_rpc.rs @@ -440,7 +440,6 @@ async fn test_rank_history() { let bearer = test_bearer(); let ingest = |delegate: &str, text: &str| { let client = client.clone(); - let addr = addr; let bearer = bearer.clone(); let text = text.to_string(); let delegate = delegate.to_string(); diff --git a/server/tests/support/mod.rs b/server/tests/support/mod.rs index 84dc1d68b6c1e1fdfdbd0757139c06c3daf1e9a6..4a620eaa875e7a1145f2a4e82cc4ff2be21d5345 100644 --- a/server/tests/support/mod.rs +++ b/server/tests/support/mod.rs @@ -1,3 +1,6 @@ +//! Shared helpers for integration tests; each test binary uses a different subset. +#![allow(dead_code)] + use sha2::{Digest, Sha256}; use slugsocial_server::{ event_log::EventLog, diff --git a/types/src/paths.rs b/types/src/paths.rs index ebc299c5e1af456c3e4b7fa45ed9fb23313e88c4..d2e799942b98dd7342764475deb17903fb60c600 100644 --- a/types/src/paths.rs +++ b/types/src/paths.rs @@ -411,7 +411,7 @@ mod tests { #[test] fn garden_item_url_deref_to_str() { let g = GardenItemUrl::from_storage_str("https://slug.social/~/x", "public"); - let s: &str = &*g; + let s: &str = &g; assert_eq!(s, "https://slug.social/~/x"); }