{"messages":[{"content":"You are a constitutional council ranking individual git commits for ownership allocation.\n\nCompare these two commits. Decide which contributed more lasting value to the project.\n\nJudge substance, not spectacle:\n- Prefer correct, lasting design and real bugfixes over churn, formatting, renames, or generated noise.\n- Prefer clarity and necessity over sheer line count. A small precise change can beat a large diffuse one.\n- Do not favor a side merely because its patch is longer or noisier.\n- Weight what the change does for the project, not the contributor's name.\n\nReturn ONLY a JSON object: {\"winner\": \"A\" or \"B\", \"ratio\": \"N:M\", \"explanation\": \"...\"}\nThe explanation must cite concrete differences in the patches (1-3 sentences).\n\nSide A — contributor: tommy-mor\nSide A — commit message:\n[1531154d] dequeue -> vec\n\nSide A — unified diff (full patch):\ndiff --git a/server/src/projection_apply.rs b/server/src/projection_apply.rs\nindex 9c8990a8af927f35d3344c8d0872a516aba56b86..ad404bacb8bcdd5ae0e682cff97f974fd44528ea 100644\n--- a/server/src/projection_apply.rs\n+++ b/server/src/projection_apply.rs\n@@ -6,8 +6,6 @@\n //! batch as the (non-idempotent) edge merges guarantees exactly-once application\n //! across replay.\n \n-use std::collections::BTreeSet;\n-\n use crate::{\n event_log::EventLogError,\n events::{Event, EventRecord},\n@@ -44,7 +42,6 @@ pub fn apply_records(\n \n let db = projection_store.db();\n let mut batch = db.batch();\n- let mut vote_parents: BTreeSet = BTreeSet::new();\n let mut last_seq = 0u64;\n \n for record in records {\n@@ -70,7 +67,6 @@ pub fn apply_records(\n *ts,\n )\n .map_err(|e| EventLogError::Apply(e.to_string()))?;\n- vote_parents.insert(parent);\n }\n Event::NodeEnsured { id } => {\n let parsed = parse_event_id(id)?;\n@@ -85,11 +81,5 @@ pub fn apply_records(\n .commit_with(durable::Durability::DisableWal)\n .map_err(|e| EventLogError::Apply(e.to_string()))?;\n \n- for parent in vote_parents {\n- projection_store\n- .trim_recent_votes(&parent)\n- .map_err(|e| EventLogError::Apply(e.to_string()))?;\n- }\n-\n Ok(())\n }\ndiff --git a/server/src/projection_store.rs b/server/src/projection_store.rs\nindex 8576d671f351004426207894ac35594ddb0f70cf..9a8953d010029d3639dc3987687554bab8b7663e 100644\n--- a/server/src/projection_store.rs\n+++ b/server/src/projection_store.rs\n@@ -18,7 +18,7 @@ use crate::{\n \n const PROJECTION_CURSOR_KEY: &str = \"cursor\";\n const PROJECTION_SCHEMA_KEY: &str = \"schema_version\";\n-const PROJECTION_SCHEMA_VERSION: u64 = 3;\n+const PROJECTION_SCHEMA_VERSION: u64 = 4;\n \n #[derive(Debug, thiserror::Error)]\n pub enum ProjectionStoreError {\n@@ -142,16 +142,6 @@ impl ProjectionStore {\n Ok(tree)\n }\n \n- /// Cap a node's recent-vote window after applying votes (best-effort, blind).\n- pub(crate) fn trim_recent_votes(&self, parent: &ItemId) -> Result<(), ProjectionStoreError> {\n- node(parent).recent_votes().truncate_back(\n- &self.db,\n- crate::storage_schema::RECENT_VOTES_CAP,\n- Durability::DisableWal,\n- )?;\n- Ok(())\n- }\n-\n /// Cache Reddit display content outside the event log (must be evicted per policy).\n pub fn put_ephemeral_content(\n &self,\ndiff --git a/server/src/reducer.rs b/server/src/reducer.rs\nindex 0c75c85150bb9e5f578bbadf58b3e43f8a80be4b..759918b8c0eb8f8bf1ed0911d8877adaa55c8ea6 100644\n--- a/server/src/reducer.rs\n+++ b/server/src/reducer.rs\n@@ -1,4 +1,4 @@\n-use std::collections::{HashMap, HashSet, VecDeque};\n+use std::collections::{HashMap, HashSet};\n \n use serde::{Deserialize, Serialize};\n \n@@ -52,7 +52,7 @@ pub struct GroupState {\n pub idx_to_item: Vec,\n pub edges: HashMap<(usize, usize), f64>,\n pub voted_pairs: HashSet<(usize, usize)>,\n- pub recent_votes: VecDeque,\n+ pub recent_votes: Vec,\n }\n \n impl GroupState {\n@@ -62,7 +62,7 @@ impl GroupState {\n idx_to_item: Vec::new(),\n edges: HashMap::new(),\n voted_pairs: HashSet::new(),\n- recent_votes: VecDeque::with_capacity(200),\n+ recent_votes: Vec::new(),\n }\n }\n \n@@ -111,10 +111,7 @@ impl GroupState {\n self.add_edge_weight(b_idx, a_idx, w_a);\n self.add_edge_weight(a_idx, b_idx, w_b);\n \n- self.recent_votes.push_front(vote);\n- while self.recent_votes.len() > 200 {\n- self.recent_votes.pop_back();\n- }\n+ self.recent_votes.push(vote);\n }\n }\n \ndiff --git a/server/src/storage_dto.rs b/server/src/storage_dto.rs\nindex 9dfb13c53efe4389277625a6ab3bfc18f566a453..3fd6db5cb909ac4896bd8a3ecace796de5f08781 100644\n--- a/server/src/storage_dto.rs\n+++ b/server/src/storage_dto.rs\n@@ -39,7 +39,7 @@ pub struct StoredEntityDataV1 {\n pub link_url: Option,\n }\n \n-/// One vote stored in a node's `recent_votes` deque.\n+/// One vote stored in a node's `recent_votes` list.\n #[derive(Debug, Clone, Serialize, Deserialize)]\n pub struct StoredVoteV1 {\n pub version: u32,\ndiff --git a/server/src/storage_schema.rs b/server/src/storage_schema.rs\nindex bd26e665e084b95b10fdfff091c31e8dc84d07b8..5d2bb1d56927fb61c7c6d2d8602bd6882327f862 100644\n--- a/server/src/storage_schema.rs\n+++ b/server/src/storage_schema.rs\n@@ -2,13 +2,13 @@\n //! durable collections instead of one blob per node.\n //!\n //! A vote updates a handful of keys: a few edge-weight merges, a voted-pair flag,\n-//! a recent-vote deque push, and child-link set entries. The in-memory\n+//! a recent-vote list append, and child-link set entries. The in-memory\n //! [`crate::reducer::GroupState`] is reconstructed from these keys on read for\n //! rank-centrality.\n \n use std::collections::{BTreeSet, HashMap, HashSet};\n \n-use durable::{Batch, Db, Deque, Durable, Leaf, Map, Sum};\n+use durable::{Batch, Db, Durable, Leaf, List, Map, Sum};\n \n use crate::{\n path_types::ItemId,\n@@ -38,8 +38,8 @@ pub struct NodeSchema {\n pub edges: Map>,\n /// Voted pairs `(min, max) -> true`.\n pub voted_pairs: Map>,\n- /// Recent votes, newest at the front (capped on write).\n- pub recent_votes: Deque>,\n+ /// Recent votes, append-only oldest-first (cap applied on read).\n+ pub recent_votes: List>,\n /// When ephemeral Reddit display content was last fetched (ms); absent after eviction.\n pub fetched_at: Leaf,\n }\n@@ -55,7 +55,7 @@ pub struct Store {\n pub view_meta: Map>,\n }\n \n-/// Cap on the per-node recent-vote window (matches the in-memory reducer).\n+/// Max recent votes returned when loading a node (query-time cap only).\n pub const RECENT_VOTES_CAP: u64 = 200;\n \n fn id_key(id: &ItemId) -> String {\n@@ -148,11 +148,14 @@ fn build_group_state(\n }\n }\n \n- // Deque is front=newest; in-memory VecDeque is also front=newest.\n- let mut recent_votes = std::collections::VecDeque::new();\n- for stored in np.recent_votes().iter(db)? {\n- recent_votes.push_back(decode_vote(stored).map_err(durable::Error::Deserialize)?);\n- }\n+ // List is index order (oldest first); keep the newest RECENT_VOTES_CAP entries.\n+ let stored = np.recent_votes().iter(db)?;\n+ let cap = RECENT_VOTES_CAP as usize;\n+ let start = stored.len().saturating_sub(cap);\n+ let recent_votes = stored[start..]\n+ .iter()\n+ .map(|s| decode_vote(s.clone()).map_err(durable::Error::Deserialize))\n+ .collect::, _>>()?;\n \n Ok(GroupState {\n item_to_idx,\n@@ -248,7 +251,7 @@ pub fn vote_writes(\n };\n batch.write(pnode.voted_pairs().key(&(lo, hi)).set(&true));\n \n- // Recent votes (newest at front).\n+ // Recent votes (append-only; cap on read).\n let stored = encode_vote(&VoteData {\n ts,\n a: a_id,\n@@ -260,7 +263,7 @@ pub fn vote_writes(\n delegate: None,\n thread_tag: \"default\".to_string(),\n });\n- batch.push_front(&pnode.recent_votes(), &stored)?;\n+ batch.push(&pnode.recent_votes(), &stored)?;\n Ok(())\n }\n \n@@ -314,6 +317,35 @@ mod tests {\n assert!(load_node_state(&db, &parent).unwrap().is_none());\n }\n \n+ #[test]\n+ fn load_caps_recent_votes_at_query_time() {\n+ let dir = tempfile::tempdir().unwrap();\n+ let db = Db::open(dir.path()).unwrap();\n+ let parent = ItemId::root();\n+\n+ let mut batch = db.batch();\n+ for i in 0..RECENT_VOTES_CAP + 10 {\n+ vote_writes(&mut batch, &parent, \"alpha\", \"beta\", 1, 0, i as i64).unwrap();\n+ }\n+ batch.commit().unwrap();\n+\n+ assert_eq!(\n+ node(&parent).recent_votes().len(&db).unwrap(),\n+ RECENT_VOTES_CAP + 10\n+ );\n+\n+ let node_state = load_node_state(&db, &parent).unwrap().unwrap();\n+ assert_eq!(node_state.local_ranking.recent_votes.len(), RECENT_VOTES_CAP as usize);\n+ assert_eq!(\n+ node_state.local_ranking.recent_votes.first().map(|v| v.ts),\n+ Some(10)\n+ );\n+ assert_eq!(\n+ node_state.local_ranking.recent_votes.last().map(|v| v.ts),\n+ Some(RECENT_VOTES_CAP as i64 + 9)\n+ );\n+ }\n+\n #[test]\n fn missing_node_is_none() {\n let dir = tempfile::tempdir().unwrap();\n\n\nSide B — contributor: tommy-mor\nSide B — commit message:\n[7bb7145d] url stuff\n\nSide B — unified diff (full patch):\ndiff --git a/AGENTS.md b/AGENTS.md\nindex e60b9ba6012593361ef10e8fdd9439cd9932e09b..babb889d6fbfb1fa7176c9e6b7544ae17b61dd2e 100644\n--- a/AGENTS.md\n+++ b/AGENTS.md\n@@ -58,4 +58,4 @@ Use **tmux** for `cargo run --package sorter2-server` (dev server). Rebuild afte\n \n - First `cargo test` / `cargo build --release` is slow; Clojure smoke test always does a release build.\n - `legacy/` and `ideas/` are not part of the workspace build.\n-- **ItemId** for web URLs is a canonical full URL (`https://reddit.com/r/rust`). Rules live in [`server/src/url_rules/`](server/src/url_rules/) (composable Rust, not a config DSL). After changing canonicalization rules, rebuild the projection: `cargo run --package sorter2-server -- replay-index`.\n+- **ItemId** for web URLs is a canonical full URL (`https://reddit.com/r/rust`). Rules live in [`server/src/url_rules/graph.rs`](server/src/url_rules/graph.rs): a semantic graph (DFA on host + path, query params in `Context`) with a generic internet fallback for unknown sites. After changing rules, rebuild the projection: `cargo run --package sorter2-server -- replay-index`.\ndiff --git a/server/src/url_rules/engine.rs b/server/src/url_rules/engine.rs\ndeleted file mode 100644\nindex e29b6b48c08deb7bffe031b1e542b1e25a7bef15..0000000000000000000000000000000000000000\n--- a/server/src/url_rules/engine.rs\n+++ /dev/null\n@@ -1,187 +0,0 @@\n-//! Composable URL normalization primitives.\n-\n-use std::collections::HashMap;\n-\n-use url::Url;\n-\n-/// Mutable URL view used by rule combinators before serializing to a canonical string.\n-#[derive(Debug, Clone)]\n-pub struct ParsedUrl {\n- pub scheme: String,\n- pub host: String,\n- pub path_segments: Vec,\n- pub query: HashMap,\n- pub fragment: Option,\n-}\n-\n-impl ParsedUrl {\n- pub fn parse(raw: &str) -> Option {\n- let trimmed = raw.trim();\n- if trimmed.is_empty() {\n- return None;\n- }\n-\n- let with_scheme = if trimmed.contains(\"://\") {\n- trimmed.to_string()\n- } else if trimmed.starts_with(\"r/\") || trimmed.starts_with(\"/r/\") {\n- let rest = trimmed.trim_start_matches('/').trim_start_matches(\"r/\");\n- format!(\"https://reddit.com/r/{rest}\")\n- } else if trimmed.contains('.') && !trimmed.starts_with('/') {\n- format!(\"https://{trimmed}\")\n- } else {\n- trimmed.to_string()\n- };\n-\n- let url = Url::parse(&with_scheme).ok()?;\n- let host = url.host_str()?.to_string();\n- let path_segments: Vec = url\n- .path_segments()\n- .map(|segs| segs.filter(|s| !s.is_empty()).map(str::to_string).collect())\n- .unwrap_or_default();\n-\n- let mut query = HashMap::new();\n- for (k, v) in url.query_pairs() {\n- query.insert(k.into_owned(), v.into_owned());\n- }\n-\n- Some(Self {\n- scheme: url.scheme().to_string(),\n- path_segments,\n- query,\n- fragment: url.fragment().map(str::to_string),\n- host,\n- })\n- }\n-\n- pub fn with_path_segments(&self, segments: &[String]) -> Self {\n- let mut u = self.clone();\n- u.path_segments = segments.to_vec();\n- u\n- }\n-\n- pub fn to_url(&self) -> Option {\n- let mut url = if self.path_segments.is_empty() {\n- Url::parse(&format!(\"{}://{}\", self.scheme, self.host)).ok()?\n- } else {\n- let path = format!(\"/{}\", self.path_segments.join(\"/\"));\n- Url::parse(&format!(\"{}://{}{}\", self.scheme, self.host, path)).ok()?\n- };\n- if !self.query.is_empty() {\n- let mut pairs: Vec<_> = self.query.iter().collect();\n- pairs.sort_by(|a, b| a.0.cmp(b.0));\n- url.query_pairs_mut().clear();\n- for (k, v) in pairs {\n- url.query_pairs_mut().append_pair(k, v);\n- }\n- }\n- if let Some(ref frag) = self.fragment {\n- url.set_fragment(Some(frag));\n- }\n- Some(url)\n- }\n-\n- pub fn canonical_string(&self) -> Option {\n- let url = self.to_url()?;\n- let mut s = url.to_string();\n- if self.path_segments.is_empty() {\n- s = s.trim_end_matches('/').to_string();\n- }\n- Some(s)\n- }\n-}\n-\n-pub fn force_https(u: &mut ParsedUrl) {\n- if u.scheme == \"http\" {\n- u.scheme = \"https\".to_string();\n- }\n-}\n-\n-pub fn drop_fragment(u: &mut ParsedUrl) {\n- u.fragment = None;\n-}\n-\n-pub fn strip_www(u: &mut ParsedUrl) {\n- if u.host.starts_with(\"www.\") {\n- u.host = u.host[4..].to_string();\n- }\n-}\n-\n-pub fn lowercase_host(u: &mut ParsedUrl) {\n- u.host = u.host.to_ascii_lowercase();\n-}\n-\n-pub fn lowercase_path(u: &mut ParsedUrl) {\n- for seg in &mut u.path_segments {\n- *seg = seg.to_ascii_lowercase();\n- }\n-}\n-\n-pub fn clear_query(u: &mut ParsedUrl) {\n- u.query.clear();\n-}\n-\n-pub fn keep_only_query(u: &mut ParsedUrl, keys: &[&str]) {\n- u.query\n- .retain(|k, _| keys.iter().any(|want| want == &k.as_str()));\n-}\n-\n-pub fn strip_tracking_params(u: &mut ParsedUrl) {\n- u.query.retain(|k, _| {\n- let lower = k.to_ascii_lowercase();\n- !(lower.starts_with(\"utm_\")\n- || matches!(\n- lower.as_str(),\n- \"fbclid\" | \"gclid\" | \"ref\" | \"ref_src\" | \"ref_source\" | \"mc_cid\" | \"mc_eid\"\n- ))\n- });\n-}\n-\n-pub fn truncate_after_segment(u: &mut ParsedUrl, name: &str, keep: usize) {\n- if let Some(i) = u.path_segments.iter().position(|s| s == name) {\n- let end = (i + 1 + keep).min(u.path_segments.len());\n- u.path_segments.truncate(end);\n- }\n-}\n-\n-pub fn drop_listing_suffix(u: &mut ParsedUrl, suffixes: &[&str]) {\n- if u.path_segments.len() >= 3 && u.path_segments.first().map(String::as_str) == Some(\"r\") {\n- if let Some(last) = u.path_segments.last() {\n- if suffixes.iter().any(|s| *s == last.as_str()) {\n- u.path_segments.pop();\n- }\n- }\n- }\n-}\n-\n-pub fn normalize_reddit_host(u: &mut ParsedUrl) {\n- if matches!(\n- u.host.as_str(),\n- \"old.reddit.com\" | \"new.reddit.com\" | \"www.reddit.com\"\n- ) {\n- u.host = \"reddit.com\".to_string();\n- }\n-}\n-\n-pub fn rewrite_youtu_be(u: &mut ParsedUrl) {\n- if u.host == \"youtu.be\" && u.path_segments.len() == 1 {\n- let id = u.path_segments[0].clone();\n- u.host = \"youtube.com\".to_string();\n- u.path_segments = vec![\"watch\".to_string()];\n- u.query.insert(\"v\".to_string(), id);\n- }\n-}\n-\n-pub fn rewrite_youtube_shorts(u: &mut ParsedUrl) {\n- if u.host == \"youtube.com\" && u.path_segments.first().map(String::as_str) == Some(\"shorts\") {\n- if let Some(id) = u.path_segments.get(1).cloned() {\n- u.path_segments = vec![\"watch\".to_string()];\n- u.query.insert(\"v\".to_string(), id);\n- }\n- }\n-}\n-\n-pub fn normalize_youtube_host(u: &mut ParsedUrl) {\n- if matches!(u.host.as_str(), \"m.youtube.com\" | \"www.youtube.com\") {\n- u.host = \"youtube.com\".to_string();\n- }\n-}\ndiff --git a/server/src/url_rules/mod.rs b/server/src/url_rules/mod.rs\nindex 03d53bd3e82d704a01ba3fd8dd02b7d31422c0de..9e1445346ce77a49dd6a7e7713bf9c57aef353cc 100644\n--- a/server/src/url_rules/mod.rs\n+++ b/server/src/url_rules/mod.rs\n@@ -1,8 +1,12 @@\n-//! URL canonicalization and hierarchy rules for [`crate::path_types::ItemId`].\n+//! URL canonicalization and hierarchy via a semantic graph (DFA + generic fallback).\n \n-mod engine;\n+mod graph;\n+mod parse;\n mod registry;\n \n+#[cfg(test)]\n+mod registry_tests;\n+\n pub use registry::{\n canonicalize_raw, looks_like_url, navigable_breadcrumbs, parent_url, resolve_id, CanonicalResult,\n };\ndiff --git a/server/src/url_rules/registry.rs b/server/src/url_rules/registry.rs\nindex 14514e9af8385fb2b9b2f35eb9ee14d453d4b97c..8e6c012ea1fc74b864307bdacdf5a0f5db5259fc 100644\n--- a/server/src/url_rules/registry.rs\n+++ b/server/src/url_rules/registry.rs\n@@ -1,12 +1,7 @@\n-//! Per-domain canonicalization and hierarchy rules.\n+//! Public API: canonical identity and hierarchy via the URL graph.\n \n-use std::collections::HashSet;\n-\n-use super::engine::{\n- clear_query, drop_fragment, drop_listing_suffix, force_https, keep_only_query, lowercase_host,\n- lowercase_path, normalize_reddit_host, normalize_youtube_host, rewrite_youtu_be,\n- rewrite_youtube_shorts, strip_tracking_params, strip_www, truncate_after_segment, ParsedUrl,\n-};\n+use super::graph::graph;\n+use super::parse::UrlParts;\n \n /// Result of canonicalizing a raw URL string.\n #[derive(Debug, Clone, PartialEq, Eq)]\n@@ -16,71 +11,16 @@ pub struct CanonicalResult {\n pub alias_of: Option,\n }\n \n-fn apply_global(u: &mut ParsedUrl) {\n- force_https(u);\n- drop_fragment(u);\n- strip_www(u);\n- lowercase_host(u);\n- strip_tracking_params(u);\n-}\n-\n-fn normalize_reddit(u: &mut ParsedUrl) {\n- normalize_reddit_host(u);\n- lowercase_path(u);\n- truncate_after_segment(u, \"comments\", 1);\n- drop_listing_suffix(u, &[\"hot\", \"top\", \"new\", \"rising\", \"controversial\"]);\n- clear_query(u);\n-}\n-\n-fn normalize_youtube(u: &mut ParsedUrl) {\n- rewrite_youtu_be(u);\n- normalize_youtube_host(u);\n- rewrite_youtube_shorts(u);\n- keep_only_query(u, &[\"v\", \"list\"]);\n-}\n-\n-fn normalize_default(_u: &mut ParsedUrl) {\n- // Global rules only.\n-}\n-\n-fn domain_key(host: &str) -> &'static str {\n- if host == \"reddit.com\" || host.ends_with(\".reddit.com\") {\n- \"reddit.com\"\n- } else if host == \"youtube.com\" || host == \"youtu.be\" {\n- \"youtube.com\"\n- } else {\n- \"default\"\n- }\n-}\n-\n-fn normalize_for_host(u: &mut ParsedUrl) {\n- apply_global(u);\n- match domain_key(&u.host) {\n- \"reddit.com\" => normalize_reddit(u),\n- \"youtube.com\" => normalize_youtube(u),\n- _ => normalize_default(u),\n- }\n-}\n-\n-/// Structural path segments that must not become standalone tree nodes when more path follows.\n-fn structural_trailing(host: &str) -> &'static [&'static str] {\n- match domain_key(host) {\n- \"reddit.com\" => &[\"comments\"],\n- _ => &[],\n- }\n-}\n-\n /// Canonicalize a raw URL. Returns `None` if the input is not URL-like.\n pub fn canonicalize_raw(raw: &str) -> Option {\n let trimmed = raw.trim();\n if trimmed.is_empty() {\n return None;\n }\n- let mut u = ParsedUrl::parse(trimmed)?;\n- let input_snapshot = u.canonical_string()?;\n- normalize_for_host(&mut u);\n- let canonical = u.canonical_string()?;\n- let alias_of = if input_snapshot != canonical {\n+ let parts = UrlParts::parse(trimmed)?;\n+ let g = graph();\n+ let canonical = g.resolve_canonical(&parts)?;\n+ let alias_of = if trimmed != canonical {\n Some(trimmed.to_string())\n } else {\n None\n@@ -98,35 +38,14 @@ pub fn resolve_id(raw: &str) -> Option {\n \n /// Navigable ancestor URLs from domain root up to and including `canonical` (full URLs).\n pub fn navigable_breadcrumbs(canonical: &str) -> Vec {\n- let Some(u) = ParsedUrl::parse(canonical) else {\n- return vec![canonical.to_string()];\n+ let parts = match UrlParts::parse(canonical) {\n+ Some(p) => p,\n+ None => return vec![canonical.to_string()],\n };\n- let structural: HashSet<&str> = structural_trailing(&u.host).iter().copied().collect();\n- let n = u.path_segments.len();\n- let mut out = Vec::new();\n-\n- // Domain root (no path segments).\n- if let Some(base) = u.with_path_segments(&[]).canonical_string() {\n- out.push(base);\n- }\n-\n- for i in 0..n {\n- let segs: Vec = u.path_segments[..=i].to_vec();\n- let is_last = i == n - 1;\n- let seg = u.path_segments[i].as_str();\n- if structural.contains(seg) && !is_last {\n- continue;\n- }\n- if let Some(url) = u.with_path_segments(&segs).canonical_string() {\n- if out.last() != Some(&url) {\n- out.push(url);\n- }\n- }\n- }\n- out\n+ graph().breadcrumbs(&parts)\n }\n \n-/// Immediate parent scope URL, or `None` for tree root / opaque single-segment ids.\n+/// Immediate parent scope URL, or `None` for tree root.\n pub fn parent_url(canonical: &str) -> Option {\n let crumbs = navigable_breadcrumbs(canonical);\n if crumbs.len() <= 1 {\n@@ -148,88 +67,3 @@ pub fn looks_like_url(raw: &str) -> bool {\n || t.starts_with(\"youtu.be/\")\n }\n \n-#[cfg(test)]\n-mod tests {\n- use super::*;\n-\n- #[test]\n- fn reddit_post_drops_slug_and_normalizes_host() {\n- let r = canonicalize_raw(\n- \"https://old.reddit.com/r/AmItheAsshole/comments/1trnvdl/aita_for_cancelling/\",\n- )\n- .unwrap();\n- assert_eq!(\n- r.canonical,\n- \"https://reddit.com/r/amitheasshole/comments/1trnvdl\"\n- );\n- }\n-\n- #[test]\n- fn reddit_strips_query_and_listing() {\n- assert_eq!(\n- canonicalize_raw(\"https://www.reddit.com/r/rust/?sort=top\")\n- .unwrap()\n- .canonical,\n- \"https://reddit.com/r/rust\"\n- );\n- assert_eq!(\n- canonicalize_raw(\"https://www.reddit.com/r/programming/hot\")\n- .unwrap()\n- .canonical,\n- \"https://reddit.com/r/programming\"\n- );\n- }\n-\n- #[test]\n- fn reddit_short_path() {\n- assert_eq!(\n- canonicalize_raw(\"r/rust\").unwrap().canonical,\n- \"https://reddit.com/r/rust\"\n- );\n- }\n-\n- #[test]\n- fn reddit_breadcrumbs_skip_phantom_comments() {\n- let post = \"https://reddit.com/r/aww/comments/1trnvdl\";\n- let crumbs = navigable_breadcrumbs(post);\n- assert!(!crumbs.iter().any(|c| c.ends_with(\"/comments\")));\n- assert_eq!(\n- crumbs.last().map(String::as_str),\n- Some(post)\n- );\n- assert!(crumbs.contains(&\"https://reddit.com/r/aww\".to_string()));\n- }\n-\n- #[test]\n- fn reddit_parent_of_post_is_subreddit() {\n- assert_eq!(\n- parent_url(\"https://reddit.com/r/aww/comments/1trnvdl\").as_deref(),\n- Some(\"https://reddit.com/r/aww\")\n- );\n- }\n-\n- #[test]\n- fn youtube_youtu_be_and_watch_same_canonical() {\n- let a = canonicalize_raw(\"https://youtu.be/dQw4w9WgXcQ\").unwrap().canonical;\n- let b = canonicalize_raw(\"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=10\").unwrap();\n- assert_eq!(a, b.canonical);\n- assert_eq!(a, \"https://youtube.com/watch?v=dQw4w9WgXcQ\");\n- }\n-\n- #[test]\n- fn legacy_schemeless_upgrades() {\n- assert_eq!(\n- canonicalize_raw(\"reddit.com/r/rust/comments/aaa/announcing_rust_199\")\n- .unwrap()\n- .canonical,\n- \"https://reddit.com/r/rust/comments/aaa\"\n- );\n- }\n-\n- #[test]\n- fn alias_recorded_when_input_differs() {\n- let r = canonicalize_raw(\"https://youtu.be/abc123\").unwrap();\n- assert_eq!(r.canonical, \"https://youtube.com/watch?v=abc123\");\n- assert!(r.alias_of.is_some());\n- }\n-}\n","role":"user"}],"model":"openai/gpt-chat-latest"}