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: [5350388a] Add pool-scoped voting: /vote?pool= picks pairs from children. - /vote now accepts an optional `pool` param (parent item path). When provided without left/right, it picks the first unvoted pair from the pool's children. When provided alongside left/right, it constrains "next pair" navigation to siblings within the pool. - "vote on children" button appears on item pages with ≥2 children, linking to /vote?pool=. - Pool is threaded through VoteComparePost → success JS so in-page morph after voting keeps the pool context for next-pair navigation. Co-Authored-By: Claude Sonnet 4.6 Side A — unified diff (full patch): diff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs index 5faa642451d69555cb391974beb0ad22c9355c8c..b79efdb4d52bd445a67f38cbfd61d3507d2b3014 100644 --- a/server/src/api/ui_html.rs +++ b/server/src/api/ui_html.rs @@ -193,6 +193,7 @@ async fn dispatch_ui_action( ratio_right, explanation, next, + pool, form_action, } => { if form_action != "/ui" { @@ -239,6 +240,9 @@ async fn dispatch_ui_action( .into_response(); } }; + let pool_id = pool.as_deref().and_then(|p| { + crate::path_types::ItemId::parse(p.trim()).map(|i| i.normalized_storage()) + }); let mut rl = ratio_left.trim().parse::().unwrap_or(0).max(0); let mut rr = ratio_right.trim().parse::().unwrap_or(0).max(0); if rl == 0 && rr == 0 { @@ -294,6 +298,7 @@ async fn dispatch_ui_action( &thread_tag, &left_id, &right_id, + pool_id.as_ref(), pid.as_str(), post_index, ) diff --git a/server/src/html/garden/pin.rs b/server/src/html/garden/pin.rs index 5865cfdbc06aeb6555c97380e25591fae6b3d125..1820d7fe7ee167ecbf5ad5124f23b2ab92ffb01f 100644 --- a/server/src/html/garden/pin.rs +++ b/server/src/html/garden/pin.rs @@ -79,7 +79,7 @@ pub(super) fn ont_pin_vote_controls( } } } @else { - a class="ont-vote-compare-btn" href=(vote_compare_href(nav, pi, ¤t, None)) title="Compare and vote" { + a class="ont-vote-compare-btn" href=(vote_compare_href(nav, pi, ¤t, None, None)) title="Compare and vote" { span class="ont-vote-glyph" aria-hidden="true" { "⚖" } span { "vote" } } @@ -121,7 +121,7 @@ pub(super) fn child_row_pin_or_vote( if nv == 1 { "" } else { "s" }, ); @let aria = format!("Vote; {} pairwise {}", nv, if nv == 1 { "vote" } else { "votes" }); - a class="ont-garden-vote-ico" href=(vote_compare_href(nav, pi, row_item, None)) title=(tip) aria-label=(aria) { + a class="ont-garden-vote-ico" href=(vote_compare_href(nav, pi, row_item, None, None)) title=(tip) aria-label=(aria) { span class="ont-garden-vote-glyph" aria-hidden="true" { "⚖" } span class="ont-garden-vote-count" { (format!("{}", nv)) } } diff --git a/server/src/html/garden/render.rs b/server/src/html/garden/render.rs index 5c3986ca36902f6c9019a4b5590f0b3b9d2cb4ff..bd8cbce059ee789de6e8dc9b6f69f54beee2f994 100644 --- a/server/src/html/garden/render.rs +++ b/server/src/html/garden/render.rs @@ -29,6 +29,7 @@ use super::{ item::{child_depth_from_uri, item_code_label, item_display_path, item_href}, item_page::{build_item_page_view_model, sibling_nav_markup}, pin::{child_row_pin_or_vote, ont_pin_vote_controls, pinned_item_from_jar}, + vote::vote_pool_href, }; pub(super) async fn render_scope_view( @@ -186,12 +187,21 @@ pub(super) async fn render_scope_view( } section class="ont-tab-panel ont-tab-panel-children" { + @let total_children = model.child_rankings.component_rankings + .iter().map(|c| c.ranked.len()).sum::() + + model.child_rankings.unranked_items.len(); h3 { "ranked child groups" @if model.child_depth > 1 { " " span class="muted" { (format!("(depth {})", model.child_depth)) } } + @if total_children >= 2 { + " " + a class="ont-vote-children-btn" href=(vote_pool_href(&nav, &model.item)) { + "vote on children" + } + } } @if model.child_rankings.component_rankings.is_empty() { p class="muted" { "no voted pairs yet in this scope" } diff --git a/server/src/html/garden/tests.rs b/server/src/html/garden/tests.rs index 6900a6795bcde866a176722149d6378e5127b4c3..c2036fca7752aef63d260e36cfe9649f63b5c550 100644 --- a/server/src/html/garden/tests.rs +++ b/server/src/html/garden/tests.rs @@ -105,7 +105,7 @@ fn suggest_next_vote_pair_prefers_unvoted_sibling_pair() { let content = content_for_garden_view(&reduced, &ScopeId::Public); let a = ItemId::parse("~/topic/a").unwrap().normalized_storage(); let b = ItemId::parse("~/topic/b").unwrap().normalized_storage(); - let next = suggest_next_vote_pair(content, &a, &b).expect("next sibling pair"); + let next = suggest_next_vote_pair(content, &a, &b, None).expect("next sibling pair"); assert_ne!( canonical_edge_items(&next.0, &next.1), canonical_edge_items(&a, &b) diff --git a/server/src/html/garden/vote.rs b/server/src/html/garden/vote.rs index 1d7fc8aa7436bfa9c1186dfd940a8d751ab7e088..2682cfcbd2f834b56459a02831aa225cffe67c58 100644 --- a/server/src/html/garden/vote.rs +++ b/server/src/html/garden/vote.rs @@ -211,14 +211,15 @@ pub(crate) async fn vote_compare_post_success_js( _thread_tag: &str, left: &ItemId, right: &ItemId, + pool: Option<&ItemId>, _post_id: &str, _post_idx: Option, ) -> String { let reduced = state.reduced.read().await; let content = content_for_garden_view(&reduced, &nav.scope()); let edge_history = vote_edge_history_markup(content, left, right); - let next_pair = suggest_next_vote_pair(content, left, right); - let nav_markup = vote_compare_nav_markup(nav, next_pair.as_ref()); + let next_pair = suggest_next_vote_pair(content, left, right, pool); + let nav_markup = vote_compare_nav_markup(nav, next_pair.as_ref(), pool); drop(reduced); JsBuilder::new() .morph_inner_selector("#vote-edge-history-region", edge_history) @@ -231,27 +232,39 @@ pub(super) fn vote_compare_href( left: &ItemId, right: &ItemId, thread_override: Option<&str>, + pool: Option<&ItemId>, ) -> String { let left_q = urlencoding::encode(left.as_str()); let right_q = urlencoding::encode(right.as_str()); - let base = format!( + let mut base = format!( "{}/vote?left={}&right={}", nav.room_path_prefix_for_vote_compare(), left_q, right_q ); if let Some(t) = thread_override.filter(|s| !s.is_empty()) { - format!("{}&thread={}", base, urlencoding::encode(t)) - } else { - base + base = format!("{}&thread={}", base, urlencoding::encode(t)); + } + if let Some(p) = pool { + base = format!("{}&pool={}", base, urlencoding::encode(p.as_str())); } + base +} + +pub(super) fn vote_pool_href(nav: &ThreadNav, pool_item_str: &str) -> String { + format!( + "{}/vote?pool={}", + nav.room_path_prefix_for_vote_compare(), + urlencoding::encode(pool_item_str) + ) } fn vote_compare_nav_markup( nav: &ThreadNav, next_pair: Option<&(ItemId, ItemId)>, + pool: Option<&ItemId>, ) -> maud::Markup { - let next_pair_href = next_pair.map(|(nl, nr)| vote_compare_href(nav, nl, nr, None)); + let next_pair_href = next_pair.map(|(nl, nr)| vote_compare_href(nav, nl, nr, None, pool)); html! { div class="vote-compare-nav" { @if let Some(href) = &next_pair_href { @@ -267,8 +280,15 @@ pub(super) fn suggest_next_vote_pair( content: &ContentState, current_left: &ItemId, current_right: &ItemId, + pool_parent: Option<&ItemId>, ) -> Option<(ItemId, ItemId)> { - let pool: Vec = if current_left.parent().as_ref().map(|p| p.as_str()) + let pool: Vec = if let Some(parent) = pool_parent { + content + .item_children + .get(parent) + .map(|s| s.iter().cloned().collect()) + .unwrap_or_default() + } else if current_left.parent().as_ref().map(|p| p.as_str()) == current_right.parent().as_ref().map(|p| p.as_str()) { current_left @@ -322,10 +342,14 @@ pub(super) fn vote_compare_item_card( } #[derive(Debug, Deserialize)] pub struct VoteCompareQuery { - pub left: String, - pub right: String, + #[serde(default)] + pub left: Option, + #[serde(default)] + pub right: Option, #[serde(default)] pub thread: Option, + #[serde(default)] + pub pool: Option, } /// Public pairwise vote UI — `/vote?left=&right=&thread=`. @@ -376,17 +400,53 @@ async fn vote_compare_inner( jar: CookieJar, uri: Uri, ) -> axum::response::Response { - let left = match ItemId::parse(q.left.trim()) { - Some(i) => i.normalized_storage(), - None => return (StatusCode::NOT_FOUND, "bad left item").into_response(), + let pool_id: Option = match q.pool.as_deref() { + Some(p) => match ItemId::parse(p.trim()) { + Some(i) => Some(i.normalized_storage()), + None => return (StatusCode::BAD_REQUEST, "bad pool item").into_response(), + }, + None => None, }; - let right = match ItemId::parse(q.right.trim()) { - Some(i) => i.normalized_storage(), - None => return (StatusCode::NOT_FOUND, "bad right item").into_response(), + + let (left, right) = match (q.left.as_deref(), q.right.as_deref()) { + (Some(l), Some(r)) => { + let left = match ItemId::parse(l.trim()) { + Some(i) => i.normalized_storage(), + None => return (StatusCode::NOT_FOUND, "bad left item").into_response(), + }; + let right = match ItemId::parse(r.trim()) { + Some(i) => i.normalized_storage(), + None => return (StatusCode::NOT_FOUND, "bad right item").into_response(), + }; + if left == right { + return (StatusCode::BAD_REQUEST, "items must differ").into_response(); + } + (left, right) + } + (None, None) => { + let Some(pool) = pool_id.as_ref() else { + return (StatusCode::BAD_REQUEST, "provide left+right or pool").into_response(); + }; + let reduced = state.reduced.read().await; + let content = content_for_garden_view(&reduced, &nav.scope()); + let children: Vec = content + .item_children + .get(pool) + .map(|s| s.iter().cloned().collect()) + .unwrap_or_default(); + if children.len() < 2 { + drop(reduced); + return (StatusCode::BAD_REQUEST, "pool has fewer than 2 children to compare").into_response(); + } + let pair = suggest_next_pair_in_pool(&content.ranking_group, &children, None); + drop(reduced); + match pair { + Some(p) => p, + None => return (StatusCode::BAD_REQUEST, "no pairs available in pool").into_response(), + } + } + _ => return (StatusCode::BAD_REQUEST, "provide both left and right, or just pool").into_response(), }; - if left == right { - return (StatusCode::BAD_REQUEST, "items must differ").into_response(); - } let reduced = state.reduced.read().await; let content = content_for_garden_view(&reduced, &nav.scope()); @@ -409,7 +469,7 @@ async fn vote_compare_inner( let left_body = content.item_bodies.get(&left).cloned(); let right_body = content.item_bodies.get(&right).cloned(); let item_bodies_for_cards = content.item_bodies.clone(); - let next_pair = suggest_next_vote_pair(content, &left, &right); + let next_pair = suggest_next_vote_pair(content, &left, &right, pool_id.as_ref()); drop(reduced); let title = format!( @@ -432,6 +492,7 @@ async fn vote_compare_inner( "ratio_right": {"$form": "ratio_right"}, "explanation": {"$form": "explanation"}, "next": next_path, + "pool": pool_id.as_ref().map(|p| p.as_str()), "form_action": "/ui", })) .expect("vote compare rpc json"); @@ -456,7 +517,7 @@ async fn vote_compare_inner( Some(&item_bodies_for_cards), )) } - (vote_compare_nav_markup(&nav, next_pair.as_ref())) + (vote_compare_nav_markup(&nav, next_pair.as_ref(), pool_id.as_ref())) div id="vote-edge-history-region" { (edge_history) } diff --git a/server/src/html/ui_action.rs b/server/src/html/ui_action.rs index dd5294202569454acf9f41b458718700bbf96f39..2589a2cc00bb7b18cd19ebcbb938083122d6921d 100644 --- a/server/src/html/ui_action.rs +++ b/server/src/html/ui_action.rs @@ -50,6 +50,9 @@ pub enum HtmlUiAction { explanation: String, /// Same-origin path after successful post (JS redirect). next: String, + /// Pool parent item path, if the vote was initiated from a pool URL. + #[serde(default)] + pool: Option, #[serde(default = "default_ui_form_action")] form_action: String, }, Side B — contributor: tommy-mor Side B — commit message: [075d4d37] Fix OAuth test mocks so Clojure E2E auth flows work again. HttpServer handlers were crashing on query parsing and token POSTs, which broke Playwright login; also read alias/history via real CSS selectors. Co-authored-by: Cursor Side B — unified diff (full patch): diff --git a/test/auth_login.clj b/test/auth_login.clj index 6f2f00d7aa7340e63d1ac465b0a2234cec7a983f..aa63b66ccb2471b710ba3d168d0461252b39fc10 100644 --- a/test/auth_login.clj +++ b/test/auth_login.clj @@ -14,27 +14,27 @@ (defn- type-alias! [pg text] (page/evaluate pg (.replace - "(() => { const i = document.getElementById('alias-input'); const f = document.getElementById('alias-check-form'); if (!i || !f) return; + "(() => { const i = document.getElementById('alias-input'); const f = document.getElementById('alias-check-form'); if (!i || !f) return Promise.resolve('missing-form'); i.value = __TEXT__; const cf = document.getElementById('alias-claim-field'); if (cf) cf.value = i.value; return fetch(f.action, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams(new FormData(f)).toString() }) .then(function (r) { return r.text(); }) - .then(function (t) { eval(t); }); })()" + .then(function (t) { eval(t); return document.getElementById('alias-status')?.textContent || ''; }); })()" "__TEXT__" - (pr-str text))) - (Thread/sleep 400)) + (pr-str text)))) -(defn- element-text [pg test-id] +(defn- element-text [pg selector] (let [raw (page/evaluate pg - (str "document.querySelector('[data-testid=\"" test-id "\"]')?.textContent || ''"))] + (str "document.querySelector(" (pr-str selector) ")?.textContent || ''"))] (when (string? raw) (str/trim raw)))) (defn- wait-for-text [pg test-id text timeout-ms] - (let [deadline (+ (System/currentTimeMillis) timeout-ms)] + (let [deadline (+ (System/currentTimeMillis) timeout-ms) + selector (str "[data-testid=\"" test-id "\"]")] (loop [] - (let [got (or (element-text pg test-id) "")] + (let [got (or (element-text pg selector) "")] (cond (= got text) got (< (System/currentTimeMillis) deadline) (do (Thread/sleep 200) (recur)) diff --git a/test/support/mock_oauth.clj b/test/support/mock_oauth.clj index 5ba7e9be3cf6d2226648e9609a09ed45f306930f..333fe08d56cb06bac2a338cad1c73894d54c4495 100644 --- a/test/support/mock_oauth.clj +++ b/test/support/mock_oauth.clj @@ -7,7 +7,7 @@ (defn- query-param [query key] (when query (some (fn [pair] - (let [[k v] (str/split pair "=" 2)] + (let [[k v] (str/split pair #"=" 2)] (when (= k key) (URLDecoder/decode (or v "") "UTF-8")))) (str/split query #"&")))) @@ -31,11 +31,11 @@ (defn- send-redirect [^HttpExchange ex location] (.set (.getResponseHeaders ex) "Location" location) - (.sendResponseHeaders ex 302 -1) + (.sendResponseHeaders ex 302 0) (.close (.getResponseBody ex))) (defn- read-form [^HttpExchange ex] - (let [body (slurp (.getInputStream ex))] + (let [body (slurp (.getRequestBody ex))] {:code (query-param body "code") :grant (query-param body "grant_type")})) @@ -45,7 +45,7 @@ (str/replace #"^[Bb]earer " ""))) (defn- parse-token-user [token] - (when (str/starts-with? token "mock:") + (when (and token (str/starts-with? token "mock:")) (parse-mock-user (subs token 5)))) (defn- authorize-redirect [exchange query] @@ -55,7 +55,7 @@ user (parse-mock-user mock-user) code (str "mock:" (:id user) ":" (:login user)) loc (str redirect-uri "?code=" (java.net.URLEncoder/encode code "UTF-8") - "&state=" (java.net.URLEncoder/encode state "UTF-8"))] + "&state=" (java.net.URLEncoder/encode (or state "") "UTF-8"))] (send-redirect exchange loc))) (defn start-mock-oauth @@ -65,49 +65,56 @@ handler (proxy [HttpHandler] [] (handle [^HttpExchange exchange] - (let [uri (.getRequestURI exchange) - path (.getPath uri) - query (.getQuery uri) - method (.getRequestMethod exchange)] - (cond - ;; GitHub authorize - (str/ends-with? path "/login/oauth/authorize") - (authorize-redirect exchange query) + (try + (let [uri (.getRequestURI exchange) + path (.getPath uri) + query (.getQuery uri) + method (.getRequestMethod exchange)] + (cond + ;; GitHub authorize + (str/ends-with? path "/login/oauth/authorize") + (authorize-redirect exchange query) - ;; Reddit authorize - (str/ends-with? path "/api/v1/authorize") - (authorize-redirect exchange query) + ;; Reddit authorize + (str/ends-with? path "/api/v1/authorize") + (authorize-redirect exchange query) - ;; GitHub token - (and (= method "POST") (str/ends-with? path "/login/oauth/access_token")) - (let [code (or (:code (read-form exchange)) "mock:1002:newbie")] - (send-json exchange 200 (str "{\"access_token\":\"" code "\",\"token_type\":\"bearer\"}"))) + ;; GitHub token + (and (= method "POST") (str/ends-with? path "/login/oauth/access_token")) + (let [code (or (:code (read-form exchange)) "mock:1002:newbie")] + (send-json exchange 200 (str "{\"access_token\":\"" code "\",\"token_type\":\"bearer\"}"))) - ;; Reddit token (client_credentials for import + authorization_code for login) - (and (= method "POST") (str/ends-with? path "/api/v1/access_token")) - (let [form (read-form exchange) - grant (or (:grant form) "") - code (or (:code form) "mock:t2_test:redditor")] - (if (= grant "client_credentials") - (send-json exchange 200 "{\"access_token\":\"app-token\",\"token_type\":\"bearer\",\"expires_in\":3600}") - (send-json exchange 200 (str "{\"access_token\":\"" code "\",\"token_type\":\"bearer\",\"expires_in\":3600}")))) + ;; Reddit token (client_credentials for import + authorization_code for login) + (and (= method "POST") (str/ends-with? path "/api/v1/access_token")) + (let [form (read-form exchange) + grant (or (:grant form) "") + code (or (:code form) "mock:t2_test:redditor")] + (if (= grant "client_credentials") + (send-json exchange 200 "{\"access_token\":\"app-token\",\"token_type\":\"bearer\",\"expires_in\":3600}") + (send-json exchange 200 (str "{\"access_token\":\"" code "\",\"token_type\":\"bearer\",\"expires_in\":3600}")))) - ;; GitHub user - (= path "/user") - (let [token (bearer-token exchange) - user (or (parse-token-user token) {:id "1002" :login "newbie" :numeric? true})] - (send-json exchange 200 - (str "{\"id\":" (:id user) ",\"login\":\"" (:login user) "\"}"))) + ;; GitHub user + (= path "/user") + (let [token (bearer-token exchange) + user (or (parse-token-user token) {:id "1002" :login "newbie" :numeric? true})] + (send-json exchange 200 + (str "{\"id\":" (:id user) ",\"login\":\"" (:login user) "\"}"))) - ;; Reddit /api/v1/me - (str/ends-with? path "/api/v1/me") - (let [token (bearer-token exchange) - user (or (parse-token-user token) {:id "t2_test" :login "redditor"})] - (send-json exchange 200 - (str "{\"id\":\"" (:id user) "\",\"name\":\"" (:login user) "\"}"))) + ;; Reddit /api/v1/me + (str/ends-with? path "/api/v1/me") + (let [token (bearer-token exchange) + user (or (parse-token-user token) {:id "t2_test" :login "redditor"})] + (send-json exchange 200 + (str "{\"id\":\"" (:id user) "\",\"name\":\"" (:login user) "\"}"))) - :else - (send-json exchange 404 "{\"error\":\"not found\"}")))))] + :else + (send-json exchange 404 "{\"error\":\"not found\"}"))) + (catch Throwable t + (binding [*out* *err*] + (println "mock-oauth handler error:" t)) + (try + (send-json exchange 500 "{\"error\":\"mock-oauth internal\"}") + (catch Throwable _))))))] (.createContext server "/" handler) (.setExecutor server nil) (.start server) diff --git a/test/support/mock_reddit.clj b/test/support/mock_reddit.clj index a630cf0938722193e9af88382d60e777ff371be4..faa27945b6394363914c853627a0bad1e819a5f9 100644 --- a/test/support/mock_reddit.clj +++ b/test/support/mock_reddit.clj @@ -12,7 +12,7 @@ (defn- query-param [query key] (when query (some (fn [pair] - (let [[k v] (str/split pair "=" 2)] + (let [[k v] (str/split pair #"=" 2)] (when (= k key) (URLDecoder/decode (or v "") "UTF-8")))) (str/split query #"&")))) @@ -34,11 +34,11 @@ (defn- send-redirect [^HttpExchange ex location] (.set (.getResponseHeaders ex) "Location" location) - (.sendResponseHeaders ex 302 -1) + (.sendResponseHeaders ex 302 0) (.close (.getResponseBody ex))) (defn- read-form [^HttpExchange ex] - (let [body (slurp (.getInputStream ex))] + (let [body (slurp (.getRequestBody ex))] {:code (query-param body "code") :grant (query-param body "grant_type")})) @@ -48,7 +48,7 @@ (str/replace #"^[Bb]earer " ""))) (defn- parse-token-user [token] - (when (str/starts-with? token "mock:") + (when (and token (str/starts-with? token "mock:")) (parse-mock-user (subs token 5)))) (defn start-mock-reddit @@ -72,7 +72,7 @@ user (parse-mock-user (query-param query "mock_user")) code (str "mock:" (:id user) ":" (:login user)) loc (str redirect-uri "?code=" (java.net.URLEncoder/encode code "UTF-8") - "&state=" (java.net.URLEncoder/encode state "UTF-8"))] + "&state=" (java.net.URLEncoder/encode (or state "") "UTF-8"))] (send-redirect exchange loc)) (and (= method "POST") (str/ends-with? path "/api/v1/access_token"))