Side A eliminates ~1800 lines of an overengineered, unreliable keystroke-transition graph parser and replaces it with a much simpler, testable URL-extraction function plus a paste-and-go UI, removing significant tech debt and a whole class of race-condition bugs (also dropping the now-obsolete Playwright race test). Side B is a solid, well-tested correctness fix (enforcing vote ratio bounds across DSL/UI/reducer) but is narrower in scope and impact than A's architectural simplification.
constitution · epochs · watch · epoch 3
c_8dc1a8119370 (tommy-mor) vs c_55666fe32c48 (tommy-mor)
download prompt · raw event · cmp_dec4685294248c
council reasoning
A removes an unreliable ~1.8k-line keystroke transition graph, ParserAction surface, race-prone JS debounce path, and Playwright race test, replacing them with a small deterministic URL→subreddit parser and paste-and-Go redirect that actually ships navigation. B is a real, well-tested domain fix (reject 0:* / *:0 and >100 ratios in DSL, UI handler, and reducer) but is a narrow constraint layer versus A’s lasting simplification of a broken subsystem.
Side B adds a durable correctness constraint across the whole stack: it rejects invalid vote ratios (either side <1 or >100) in the DSL parser, UI handler, and reducer, preventing meaningless graph edges while adding regression tests for parser, reducer, integration, and browser behavior. Side A mainly replaces a complex autocomplete/transition-graph UI with a simpler paste-and-go flow, removing substantial functionality and tests while simplifying URL parsing, which is a product-direction change rather than a clear long-term correctness improvement.
sides
A — c_8dc1a8119370 (tommy-mor)
message
[529cc941] Replace autocomplete parser with paste-and-go navigate. The keystroke transition graph was unreliable; a textarea plus Go button now parses pasted Reddit URLs and redirects to the subreddit ranking scope. Co-authored-by: Cursor <cursoragent@cursor.com>
diff preview
diff --git a/AGENTS.md b/AGENTS.md
index 77f2e31d4e860a92a77255ca5106c8b6c4510ee7..36ee4c0ec700bffbe226ee775ba9cf59cf35c770 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -11,7 +11,6 @@ Single Rust web app **`sorter2-server`**: pairwise voting, rank-centrality ranki
- **Rust 1.88+** is required (some transitive crates need a recent Cargo). The image may ship older `/usr/local/cargo` (1.83); use **rustup** and `rustup default 1.88.0` before building.
- **System packages** for builds: `pkg-config`, `libssl-dev` (for `reqwest` / OpenSSL in integration tests and release builds).
- **Clojure CLI 1.12.0.1530** (optional but used in CI): install from https://clojure.org/guides/install_clojure — needed for `./scripts/clj-test.sh` / Kaocha tests.
-- **Playwright browser** for the spel browser test (`test/parser_race.clj`): install once with `clojure -M -e "(com.microsoft.playwright.CLI/main (into-array String [\"install\" \"chromium\" \"--with-deps\"]))"`. The browser binary is cached under `~/.cache/ms-playwright`.
### Commands (see also `TEST.sh`)
diff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs
index 1339048c955c0a3eb5120381aaf031424cbed540..c4ab9d65c7b3cd42a5b4d093ba429993c101e9a8 100644
--- a/server/src/api/ui_html.rs
+++ b/server/src/api/ui_html.rs
@@ -8,7 +8,7 @@ use std::collections::HashMap;
use crate::{
html::{js_string_literal, ranking_panel, JsBuilder},
parser::parse_reddit_url,
- parser_render::parser_panel_morph,
+ parser_render::navigate_panel,
state::AppState,
ui_action::{parse_html_ui_from_form, HtmlUiAction},
};
@@ -57,18 +57,23 @@ pub async fn post_ui_html(
.morph_selector("#ranking-panel", panel)
.into_response()
}
- HtmlUiAction::ParseQuery { query } => {
- let action = parse_reddit_url(&query);
- let panel = parser_panel_morph(&query, &action);
- let mut js = JsBuilder::new().morph_selector("#parser-panel", panel);
- if let Some(comp) = action.primary_completion() {
- js = js.raw(&format!(
- "var __pi=document.getElementById('parser-input'); if(__pi){{__pi.dataset.completion={};}}",
- js_string_literal(comp)
- ));
+ HtmlUiAction::ParseQuery { query } => match parse_reddit_url(&query) {
+ Ok(subreddit) => {
+ let dest = format!("/?sub={subreddit}");
+ JsBuilder::new()
+ .raw(&format!(
+ "window.location.href={};",
+ js_string_literal(&dest)
+ ))
+ .into_response()
}
- js.into_response()
- }
+ Err(message) => {
+ let panel = navigate_panel(&query, Some(&message));
+ JsBuilder::new()
+ .morph_selector("#parser-panel", panel)
+ .into_response()
+ }
+ },
}
}
diff --git a/server/src/html/mod.rs b/server/src/html/mod.rs
index 94a5cfb561d1c8464bd2782f7ffd4e0965ccf95d..9650d333d29c4ac94ceb407aee3ee00399c7f40b 100644
--- a/server/src/html/mod.rs
+++ b/server/src/html/mod.rs
@@ -11,8 +11,7 @@ use serde::Deserialize;
use crate::{
form_template::template_json_compact,
- parser_action::ParserAction,
- parser_render::parser_panel,
+ parser_render::navigate_panel,
ranking::{top_bottom, RankedItem},
reducer::GroupState,
state::{normalize_scope, AppState},
@@ -336,10 +335,9 @@ pub async fn home(
let empty = GroupState::new();
let group = groups.get(&scope).unwrap_or(&empty);
- let empty_action = ParserAction::suggest(String::new(), None);
let body = html! {
h1 { "sorter2" }
- (parser_panel("", &empty_action))
+ (navigate_panel("", None))
(vote_panel(&scope))
(ranking_panel(&scope, group))
};
diff --git a/server/src/lib.rs b/server/src/lib.rs
index fa423640d598f4ba97a5885d228e78d7b97f7a22..de8bca48cbf689cad22337883e7791966e7c4919 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -4,7 +4,6 @@ pub mod events;
pub mod form_template;
pub mod html;
pub mod parser;
-pub mod parser_action;
pub mod parser_render;
pub mod path_types;
pub mod ranking;
diff --git a/server/src/parser.rs b/server/src/parser.rs
index ea437c4434045b44cba04a2b3416df850db518e7..50571a59f0d3ece1e2538f88e00ef46ec40ea545 100644
--- a/server/src/parser.rs
+++ b/server/src/parser.rs
@@ -1,1811 +1,87 @@
-use std::collections::HashMap;
-use std::sync::OnceLock;
+//! Extract a subreddit name from a pasted Reddit URL or path.
-use crate::parser_action::{GuideOption, ParserAction, ScrollingSuggestion, Suggestion};
-
-// --- Core Abstractions ---
-
-/// Unique identifier for nodes in the graph
-type NodeId = &'static str;
-
-/// Pattern matching for edges
-#[derive(Debug, Clone)]
-pub enum EdgePattern {
- /// Matches exact literal string
- Literal(&'static str),
-
- /// Matches any prefix of a string and suggests the full string
- /// e.g., PrefixOf("reddit.com") matches "r", "re", "red", "reddit", "reddit.com"
- PrefixOf(&'static str),
-
- /// Captures a variable segment (e.g., subreddit name, username)
- Variable(&'static str),
-
- /// Matches any string (wildcard)
- Any,
-}
-
-impl EdgePattern {
- /// Try to match this pattern against input, return (consumed_chars, captured_value)
- fn matches(&self, input: &str) -> Option<(usize, Option<String>)> {
- match self {
- EdgePattern::Literal(lit) => {
- if input.starts_with(lit) {
- Some((lit.len(), None))
- } else {
- None
- }
- }
- EdgePattern::PrefixOf(target) => {
- // Check if input is a prefix of target
- if target.starts_with(input) && !input.is_empty() {
- // It's a valid prefix
- Some((input.len(), None))
- } else if input.starts_with(target) {
- // Full match
- Some((target.len(), None))
- } else {
- None
- }
- }
- EdgePattern::Variable(var_name) => {
- // Consume until next '/' or end of string
- let end = input.find('/').unwrap_or(input.len());
- if end > 0 {
- let captured = input[..end].to_string();
- // Validate based on variable type
- if is_valid_variable(var_name, &captured) {
- Some((end, Some(captured)))
- } else {
- None
- }
- } else {
- None
- }
- }
- EdgePattern::Any => {
- // Match everything until next '/' or end
- let end = input.find('/').unwrap_or(input.len());
- if end > 0 {
- Some((end, Some(input[..end].to_string())))
- } else {
- None
- }
- }
- }
- }
-
- /// Get the completion suggestion for this pattern
- fn completion(&self, partial: &str) -> Option<String> {
- match self {
- EdgePattern::PrefixOf(target) => {
- if target.starts_with(partial) && partial != *target {
- Some(target.to_string())
- } else {
- None
- }
- }
- _ => None,
- }
+pub fn parse_reddit_url(query: &str) -> Result<String, String> {
+ let q = query.trim();
+ if q.is_empty() {
+ return Err("Paste a Reddit URL or r/subreddit path".into());
}
-}
-/// Edge in the graph
-pub struct Edge {
- pattern: EdgePattern,
- target: NodeId,
- /// Optional description for autocomplete
- description: Option<&'static str>,
-}
-
-/// Handler function for generating UI actions (Send + Sync so the graph can live in `OnceLock`).
-type Handler = Box<dyn Fn(&str, &str, &HashMap<String, String>) -> ParserAction + Send + Sync>;
-
-/// Node in the graph
-pub struct Node {
- #[allow(dead_code)]
- id: NodeId,
- edges: Vec<Edge>,
- handler: Option<Handler>,
-}
-
-/// The composable parser graph (immutable after `build`).
-pub struct Graph {
- nodes: HashMap<NodeId, Node>,
- root: NodeId,
-}
-
-// --- Graph Builder (Fluent API) ---
-
-pub struct GraphBuilder {
- nodes: HashMap<NodeId, Node>,
- current_node: Option<NodeId>,
- root: NodeId,
-}
-
-impl GraphBuilder {
- pub fn new() -> Self {
- let mut nodes = HashMap::new();
- nodes.insert(
- "root",
- Node {
- id: "root",
- edges: Vec::new(),
- handler: None,
- },
- );
-
- GraphBuilder {
- nodes,
- current_node: Some("root"),
- root: "root",
- }
+ if let Some(sub) = subreddit_after_prefix(q, "r/") {
+ return Ok(sub);
}
- /// Select a node to add edges to
- pub fn at(mut self, node_id: NodeId) -> Self {
- self.nodes.entry(node_id).or_insert_with(|| Node {
- id: node_id,
- edges: Vec::new(),
- handler: None,
- });
- self.current_node = Some(node_id);
- self
+ if let Some(sub) = subreddit_from_path_segment(q, "/r/") {
+ return Ok(sub);
}
-
- /// Add an edge from the current node
- pub fn edge(self, pattern: EdgePattern, target: NodeId) -> Self {
- self.edge_with_desc(pattern, target, None)
- }
-
- /// Add an edge with description
- pub fn edge_with_desc(
- mut self,
- pattern: EdgePattern,
- target: NodeId,
- desc: Option<&'static str>,
- ) -> Self {
- let current = self.current_node.expect("No current node selected");
-
- self.nodes.entry(target).or_insert_with(|| Node {
- id: target,
- edges: Vec::new(),
- handler: None,
- });
-
- if let Some(node) = self.nodes.get_mut(current) {
- node.edges.push(Edge {
- pattern,
- target,
- description: desc,
- });
- }
- self
- }
-
- /// Set handler for current node
- pub fn handler<F>(mut self, handler: F) -> Self
- where
- F: Fn(&str, &str, &HashMap<String, String>) -> ParserAction + Send + Sync + 'static,
- {
- let current = self.current_node.expect("No current node selected");
- if let Some(node) = self.nodes.get_mut(current) {
- node.handler = Some(Box::new(handler));
- }
- self
- }
-
- /// Build the final graph
- pub fn build(self) -> Graph {
- Graph {
- nodes: self.nodes,
- root: self.root,
- }
- }
+ Err("Could not find a subreddit in that URL".into())
}
-// --- Parser Implementation ---
-
-impl Graph {
- pub fn parse(&self, input: &str) -> ParserAction {
- let normalized = input.trim().to_lowercase();
- let mut state = ParserState {
- input: &normalized,
- cursor: 0,
- current_node_id: self.root,
- context: HashMap::new(),
- original_query: input.to_string(),
- current_prefix: String::new(),
- };
-
- self.parse_recursive(&mut state)
- }
-
- fn parse_recursive(&self, state: &mut ParserState) -> ParserAction {
- let node = self
- .nodes
- .get(state.current_node_id)
- .expect("Node not found in graph");
-
- // If we've consumed all input, check for handler or suggestions
- if state.cursor >= state.input.len() {
- if let Some(handler) = &node.han
… preview truncated; 92,533 characters omittedB — c_55666fe32c48 (tommy-mor)
message
[aa0b175c] Enforce vote ratio constraints: both sides ≥ 1, max 100. Zero on either side produces no valid graph edge; ratios above 100 add no meaningful signal. Enforce in the DSL parser, browser POST handler, and reducer guard. Update browser pool test to use 99:1 instead of 100:0. Add unit and integration regression tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
diff preview
diff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs
index b79efdb4d52bd445a67f38cbfd61d3507d2b3014..bc8a0130b434cc7880a4bf16eb9237080c4aa383 100644
--- a/server/src/api/ui_html.rs
+++ b/server/src/api/ui_html.rs
@@ -243,11 +243,23 @@ async fn dispatch_ui_action(
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::<i32>().unwrap_or(0).max(0);
- let mut rr = ratio_right.trim().parse::<i32>().unwrap_or(0).max(0);
- if rl == 0 && rr == 0 {
- rl = 1;
- rr = 1;
+ let rl = ratio_left.trim().parse::<i32>().unwrap_or(0).max(0);
+ let rr = ratio_right.trim().parse::<i32>().unwrap_or(0).max(0);
+ if rl == 0 || rr == 0 {
+ return form_js_error(
+ err_tgt.as_ref(),
+ "invalid ratio",
+ "Both ratio sides must be ≥ 1.",
+ )
+ .into_response();
+ }
+ if rl > 100 || rr > 100 {
+ return form_js_error(
+ err_tgt.as_ref(),
+ "invalid ratio",
+ "Ratio sides must be ≤ 100.",
+ )
+ .into_response();
}
let text = format!(
diff --git a/server/src/dsl.rs b/server/src/dsl.rs
index faa8aac6616bc6ea2b102d08ae999c01a716ef6e..338feacc579a92bed291867cc0f2f62462737462 100644
--- a/server/src/dsl.rs
+++ b/server/src/dsl.rs
@@ -545,9 +545,14 @@ fn parse_block_prefixed_statement(
let ((ratio_left, ratio_right), k) = parse_comparison_at(s, i)
.ok_or_else(|| DslError::Parse(format!("invalid comparison near: {}", &s[i..])))?;
- if ratio_left == 0 && ratio_right == 0 {
+ if ratio_left == 0 || ratio_right == 0 {
return Err(DslError::Parse(
- "vote ratio 0:0 is invalid; use 1:1 for a tie or omit the vote".to_string(),
+ "vote ratio sides must be ≥ 1; use 1:1 for a tie or omit the vote".to_string(),
+ ));
+ }
+ if ratio_left > 100 || ratio_right > 100 {
+ return Err(DslError::Parse(
+ "vote ratio sides must be ≤ 100".to_string(),
));
}
i = skip_ws(s, k);
@@ -929,11 +934,50 @@ mod tests {
let err = parse_full("{tie placeholder}\n~/a 0:0 ~/b").unwrap_err();
let DslError::Parse(msg) = err;
assert!(
- msg.contains("0:0"),
- "expected 0:0 rejection message, got: {msg}"
+ msg.contains("≥ 1"),
+ "expected zero-side rejection message, got: {msg}"
);
}
+ #[test]
+ fn parse_vote_rejects_left_zero_ratio() {
+ let err = parse_full("{prefer b}\n~/a 0:5 ~/b").unwrap_err();
+ let DslError::Parse(msg) = err;
+ assert!(
+ msg.contains("≥ 1"),
+ "expected zero-side rejection message, got: {msg}"
+ );
+ }
+
+ #[test]
+ fn parse_vote_rejects_right_zero_ratio() {
+ let err = parse_full("{prefer a}\n~/a 5:0 ~/b").unwrap_err();
+ let DslError::Parse(msg) = err;
+ assert!(
+ msg.contains("≥ 1"),
+ "expected zero-side rejection message, got: {msg}"
+ );
+ }
+
+ #[test]
+ fn parse_vote_rejects_over_max_ratio() {
+ let err = parse_full("{prefer a strongly}\n~/a 101:1 ~/b").unwrap_err();
+ let DslError::Parse(msg) = err;
+ assert!(
+ msg.contains("≤ 100"),
+ "expected max ratio rejection message, got: {msg}"
+ );
+ }
+
+ #[test]
+ fn parse_vote_accepts_max_ratio() {
+ let doc = parse_full("{prefer a}\n~/a 100:1 ~/b").unwrap();
+ assert!(matches!(
+ doc.statements.last(),
+ Some(Stmt::Vote { ratio_left: 100, ratio_right: 1, .. })
+ ));
+ }
+
#[test]
fn parse_full_interleaves_prose() {
let input = "hello\n#tag\nworld";
diff --git a/server/src/reducer.rs b/server/src/reducer.rs
index e949e8e092297eedd5c20c131f16ef0121f329b3..6841d35cfc9de2389f340a22b8a45acb335e36c3 100644
--- a/server/src/reducer.rs
+++ b/server/src/reducer.rs
@@ -119,11 +119,11 @@ impl GroupState {
let (i, j) = if a_idx < b_idx { (a_idx, b_idx) } else { (b_idx, a_idx) };
self.voted_pairs.insert((i, j));
- let mut w_a = vote.ratio_left.max(0) as f64;
- let mut w_b = vote.ratio_right.max(0) as f64;
- if w_a == 0.0 && w_b == 0.0 {
- w_a = 1.0;
- w_b = 1.0;
+ let w_a = vote.ratio_left as f64;
+ let w_b = vote.ratio_right as f64;
+ if w_a == 0.0 || w_b == 0.0 {
+ // Zero on either side produces no valid edge; drop the vote.
+ return;
}
self.add_edge_weight(b_idx, a_idx, w_a);
diff --git a/server/tests/basic.rs b/server/tests/basic.rs
index 9d83e7a97e2c7494790db17c4b5b30c181705026..cc8c1a0d139f3722ba6ecd13dd001c65be835b67 100644
--- a/server/tests/basic.rs
+++ b/server/tests/basic.rs
@@ -175,14 +175,14 @@ fn reducer_clamps_score_bounds() {
let mut state = ReducerState::default();
state.apply_event(ingest_event(
1,
- "@00000000-0000-0000-0000-000000000000:test:local/test\n~/t/a {a}\n~/t/b {b}\n{huge}\n~/t/a 1000:1 ~/t/b\n",
+ "@00000000-0000-0000-0000-000000000000:test:local/test\n~/t/a {a}\n~/t/b {b}\n{huge}\n~/t/a 100:1 ~/t/b\n",
));
state.apply_event(ingest_event(
2,
- "@00000000-0000-0000-0000-000000000000:test:local/test\n{huge}\n~/t/a 1:1000 ~/t/b\n",
+ "@00000000-0000-0000-0000-000000000000:test:local/test\n{huge}\n~/t/a 1:100 ~/t/b\n",
));
- assert_eq!(state.public().ranking_group.idx_to_item.len(), 2); // Should still work, scores clamped internally
+ assert_eq!(state.public().ranking_group.idx_to_item.len(), 2); // Should still work, scores handled internally
}
// ============================================================================
@@ -513,8 +513,8 @@ fn dsl_parse_rejects_zero_zero_vote_ratio() {
.expect_err("0:0 vote must be rejected by the parser");
let slugsocial_server::dsl::DslError::Parse(msg) = err;
assert!(
- msg.contains("0:0"),
- "expected message about invalid 0:0 ratio, got: {msg}"
+ msg.contains("≥ 1"),
+ "expected message about invalid zero ratio, got: {msg}"
);
let mut state = ReducerState::default();
@@ -533,7 +533,7 @@ fn dsl_parse_rejects_zero_zero_vote_ratio() {
#[test]
fn reducer_negative_ratio_clamped_to_zero() {
let _state = ReducerState::default();
- // GroupState::apply_vote clamps negatives to 0, then 0:0 -> 1:1
+ // GroupState::apply_vote clamps negatives to 0; when either side is 0 the vote is dropped.
let mut group = GroupState::new();
group.apply_vote(slugsocial_server::reducer::VoteData {
ts: 1,
@@ -546,12 +546,12 @@ fn reducer_negative_ratio_clamped_to_zero() {
delegate: Some("00000000-0000-0000-0000-000000000000:test:local/test".to_string()),
thread_tag: "t".to_string(),
});
+ // Items are registered, but the zero-clamped vote produces no edges.
assert_eq!(group.idx_to_item.len(), 2);
- // Both edges should exist (negatives clamped to 0, then 0:0 -> 1:1)
let a_idx = group.item_to_idx[&item_id("https://slug.social/~/t/a")];
let b_idx = group.item_to_idx[&item_id("https://slug.social/~/t/b")];
- assert!(group.edges.contains_key(&(a_idx, b_idx)));
- assert!(group.edges.contains_key(&(b_idx, a_idx)));
+ assert!(!group.edges.contains_key(&(a_idx, b_idx)));
+ assert!(!group.edges.contains_key(&(b_idx, a_idx)));
}
diff --git a/server/tests/integration_ui.rs b/server/tests/integration_ui.rs
index 23db7b5672418d5bb0ab7529e05ef1f89e59062a..09c5481f039d59efb617a82bafcc432a186e2d30 100644
--- a/server/tests/integration_ui.rs
+++ b/server/tests/integration_ui.rs
@@ -256,3 +256,96 @@ async fn test_sse_public_thread_morph_includes_post_body_not_thread_not_found()
);
}
+fn ui_vote_compare_post_rpc(
+ room: &str,
+ thread_tag: &str,
+ left: &str,
+ right: &str,
+ ratio_left: &str,
+ ratio_right: &str,
+ explanation: &str,
+) -> String {
+ serde_json::json!({
+ "action": "vote_compare_post",
+ "room": room,
+ "thread_tag": thread_tag,
+ "left_item": left,
+ "right_item": right,
+ "ratio_left": ratio_left,
+ "ratio_right": ratio_right,
+ "explanation": explanation,
+ "next": "/vote",
+ })
+ .to_string()
+}
+
+#[tokio::test]
+async fn test_vote_compare_post_rejects_zero_left_ratio() {
+ let (addr, _tmp, _log, _handle) = create_test_server().await;
+ let client = reqwest::Client::new();
+ let bearer = test_bearer();
+
+ let rpc = ui_vote_compare_post_rpc("public", "test-vote", "~/a", "~/b", "0", "5", "prefer b");
+ let resp = client
+ .post(format!("http://{addr}/ui"))
+ .header("Authorization", format!("Bearer {bearer}"))
+ .form(&[("__rpc__", rpc.as_str())])
+ .send()
+ .await
+ .unwrap();
+
+ assert_eq!(resp.status(), reqwest::StatusCode::OK);
+ let js = resp.text().await.unwrap();
+ assert!(
+ js.contains("invalid ratio") || js.contains("≥ 1"),
+ "expected zero-ratio rejection, got: {js}"
+ );
+}
+
+#[tokio::test]
+async fn test_vote_compare_post_rejects_zero_right_ratio() {
+ let (addr, _tmp, _log, _handle) = create_test_server().await;
+ let client = reqwest::Client::new();
+ let bearer = test_bearer();
+
+ let rpc = ui_vote_compare_post_rpc("public", "test-vote", "~/a", "~/b", "5", "0", "prefer a");
+ let resp = client
+ .post(format!("http://{addr}/ui"))
+ .header("Authorization", format!("Bearer {bearer}"))
+ .form(&[("__rpc__", rpc.as_str())])
+ .send()
+ .await
+ .unwrap();
+
+ assert_eq!(resp.status(), reqwest::StatusCode::OK);
+ let js = resp.text().await.unwrap();
+ assert!(
+ js.contains("invalid ratio") || js.contains("≥ 1"),
+ "expected zero-ratio rejection, got: {js}"
+ );
+}
+
+#[tokio::test]
+async fn test_vote_compare_post_rejects_over_max_ratio() {
+ let (addr, _tmp, _log, _handle) = create_test_server().await;
+ let client = reqwest::Client::new();
+ let bearer = test_bearer();
+
+ let rpc =
+ ui_vote_compare_post_rpc("public", "test-vote", "~/a", "~/b", "101", "1", "prefer a");
+ let resp = client
+ .post(format!("http://{addr}/ui"))
+ .header("Authorization", format!("Bearer {bearer}"))
+ .form(&[("__rpc__", rpc.as_str())])
+ .send()
+ .await
+ .unwrap();
+
+ assert_eq!(resp.status(), reqwest::StatusCode::OK);
+ let js = resp.text().await.unwrap();
+ assert!(
+ js.contains("invalid ratio") || js.contains("≤ 100"),
+ "expected over-max ratio rejection, got: {js}"
+ );
+}
+
diff --git a/test/browser_vote_pool.clj b/test/browser_vote_pool.clj
index 23d0bd80b02bd8b1b48853454bed02793296550e..738608801027d1e662660b5d6c830b4ccd07c434 100644
--- a/test/browser_vote_pool.clj
+++ b/test/browser_vote_pool.clj
@@ -38,8 +38,8 @@
;; Set the hidden ratio inputs so the alphabetically-earlier item wins.
(defn- set-ratio! [pg left-text right-text]
(let [[rl rr] (if (neg? (compare (leaf left-text) (leaf right-text)))
- [100 0] ; left is earlier → prefer left
- [0 100])] ; right is earlier → prefer right
+ [99 1] ; left is earlier → prefer left
+ [1 99])] ; right is earlier → prefer right
(page/evaluate pg (str "document.getElementById('vote-ratio-left').value='" rl "'"))
(page/evaluate pg (str "document.getElementById('vote-ratio-right').value='" rr "'"))))
Hardlinks — judgments / attempts / prompt
judgments
attempts
Prompt text is loaded only by the download route.