Side B adds a substantial new browser test covering an end-to-end pool-scoped voting workflow, providing lasting regression protection and documentation of expected behavior. Side A is a small cleanup removing dead/unused parameters and code from a JS-builder function, which is useful but minor in scope and impact compared to a new test asset.
constitution · epochs · watch · epoch 3
c_7b940fef005f (tommy-mor) vs c_7ca21f5e83a8 (tommy-mor)
download prompt · raw event · cmp_2268e0cdd548c5
council reasoning
B adds a full browser integration test that seeds a pool, exercises the vote→next-pair loop, and asserts edge-history and pool membership—lasting regression protection for a core flow. A only drops unused parameters and dead preview-morph logic from vote_compare_post_success_js, a worthwhile but small cleanup with less ongoing impact.
Side B adds a new end-to-end browser test that seeds a pool, exercises the vote→next-pair workflow, and verifies both edge-history updates and that every displayed pair stays within the requested pool, providing lasting regression coverage for an important user flow. Side A mainly removes now-unused parameters and stops updating the vote-compare preview, simplifying the implementation but largely acting as cleanup with comparatively limited functional impact.
sides
A — c_7b940fef005f (tommy-mor)
message
[c3f01e01] cleanup
diff preview
diff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs
index f9912115d3c6ac18be66c952c3af445ab0f51cea..5aa6a86326ba3545d261322c010e02fe86ee1c57 100644
--- a/server/src/api/ui_html.rs
+++ b/server/src/api/ui_html.rs
@@ -254,17 +254,7 @@ async fn dispatch_ui_action(
};
n
};
- let js = vote_compare_post_success_js(
- state,
- &nav,
- &room,
- &thread_tag,
- &left_id,
- &right_id,
- &pid,
- post_index,
- )
- .await;
+ let js = vote_compare_post_success_js(state, &nav, &left_id, &right_id).await;
Response::builder()
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, "text/javascript; charset=utf-8")
diff --git a/server/src/html/garden.rs b/server/src/html/garden.rs
index 7d309a075405483971109da2f34160409dc608f7..8a46b1e92d38f2c390f88d48750d95d11388cd73 100644
--- a/server/src/html/garden.rs
+++ b/server/src/html/garden.rs
@@ -176,34 +176,14 @@ fn vote_edge_history_markup(
pub(crate) async fn vote_compare_post_success_js(
state: &AppState,
nav: &ThreadNav,
- room_wire: &str,
- thread_tag: &str,
left: &ItemId,
right: &ItemId,
- post_id: &str,
- post_idx: Option<usize>,
) -> String {
- use crate::reducer::scope_from_room_wire;
let reduced = state.reduced.read().await;
- let scope = scope_from_room_wire(room_wire.trim());
- let Some(ing) = reduced.ingests_by_id.get(post_id).cloned() else {
- drop(reduced);
- return "console.warn('vote compare: new post not found');".to_string();
- };
- let idx = match post_idx {
- Some(i) => i,
- None => reduced
- .try_thread_post_index_chronological(&scope, thread_tag, post_id)
- .unwrap_or(0),
- };
- let viewer = None::<&str>;
- let now = now_ms();
- let card = ingest_entry_markup(nav, thread_tag, idx, &ing, viewer, now, &reduced);
let content = content_for_garden_view(&reduced, &nav.scope());
let edge_history = vote_edge_history_markup(content, left, right, nav);
drop(reduced);
let mut b = JsBuilder::new();
- b = b.morph_inner_selector("#vote-compare-preview", card);
b = b.morph_inner_selector("#vote-edge-history-region", edge_history);
b.build()
}
B — c_7ca21f5e83a8 (tommy-mor)
message
[7287df45] Add browser test for pool-scoped vote sequence. Seeds ~/pool/a-j (10 letters), enters /vote?pool=~/pool, then follows the vote → next-pair loop up to 15 iterations. Asserts each vote lands in edge history and each pair shown belongs to the pool. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
diff preview
diff --git a/test/browser_vote_pool.clj b/test/browser_vote_pool.clj
new file mode 100644
index 0000000000000000000000000000000000000000..d51f05db47dc3cb013e56e65f3a1edfbbcbd96ab
--- /dev/null
+++ b/test/browser_vote_pool.clj
@@ -0,0 +1,137 @@
+(ns test.browser-vote-pool
+ "Pool-scoped voting: seed ~/pool/a-j, enter via /vote?pool=~/pool, follow
+ the vote → next-pair → vote sequence until no next pair or 15 iterations."
+ (:require [babashka.fs :as fs]
+ [cheshire.core :as json]
+ [clojure.string :as str]
+ [clojure.test :refer [deftest is]]
+ [com.blockether.spel.core :as core]
+ [com.blockether.spel.locator :as locator]
+ [com.blockether.spel.page :as page]
+ [test.common :as common]
+ [test.oauth :as oauth]))
+
+(defn- wait-for-text [pg selector expected timeout-ms]
+ (let [deadline (+ (System/currentTimeMillis) timeout-ms)]
+ (loop []
+ (let [text (locator/text-content (page/locator pg selector))]
+ (if (and (string? text) (str/includes? text expected))
+ true
+ (if (< (System/currentTimeMillis) deadline)
+ (do (Thread/sleep 200) (recur))
+ false))))))
+
+(defn- element-text [pg selector]
+ (try (locator/text-content (page/locator pg selector)) (catch Exception _ nil)))
+
+(defn- enc [^String s]
+ (java.net.URLEncoder/encode s "UTF-8"))
+
+(def letters ["a" "b" "c" "d" "e" "f" "g" "h" "i" "j"])
+
+(defn vote-pool-flow! []
+ (println "\n━━━ browser vote pool (/vote?pool= seeds + follow next-pair sequence) ━━━\n")
+
+ (common/letlocals
+ (bind build (common/run-cargo-build-release! ["slugsocial-server"]))
+ (is (zero? (:exit build)) "cargo build succeeds")
+ (bind server-bin "target/release/slugsocial-server")
+
+ (bind tmp-dir (str (fs/create-temp-dir {:prefix "slug-browser-vote-pool-"})))
+ (bind slug-port (common/pick-port))
+ (bind google-port (common/pick-port))
+ (bind base-url (str "http://127.0.0.1:" slug-port))
+ (bind google-url (str "http://127.0.0.1:" google-port))
+
+ (bind !server (atom nil))
+ (bind !google (atom nil))
+ (bind server-env (common/slug-server-env tmp-dir base-url google-url slug-port))
+ (try
+ (reset! !google (oauth/start-mock-google google-port
+ :google-users ["google-user-alice"]))
+ (reset! !server (common/start-server server-bin server-env))
+ (is (common/wait-for-server base-url 10000) "server responds to /healthz")
+
+ (let [alice-token (oauth/fetch-bearer-token! base-url :username "alice")
+ thread-tag "browser-vote-pool"
+ ;; seed ~/pool/a through ~/pool/j as items with bodies
+ item-lines (str/join "\n"
+ (map (fn [l] (str "~/pool/" l " {" l "}")) letters))
+ raw (str "# " thread-tag "\n\n~/pool {root}\n" item-lines "\n")
+ post-resp (oauth/http-post-json
+ (str base-url "/api/v0/rpc")
+ [{"Post" {"room" "public"
+ "thread_tag" thread-tag
+ "text" raw
+ "return_rank_diff" false}}]
+ :headers {"Authorization" (str "Bearer " alice-token)})
+ post-json (json/parse-string (:body post-resp) false)
+ _ (is (true? (get-in post-json ["results" 0 "ok"]))
+ "seed ~/pool/a-j items via rpc")
+ pool-url (str base-url "/vote?pool=" (enc "~/pool"))]
+
+ (core/with-playwright [pw]
+ (core/with-browser [browser (core/launch-chromium pw {:headless true :channel "chrome"})]
+ (core/with-context [ctx (core/new-context browser)]
+ (core/with-page [pg (core/new-page-from-context ctx)]
+ (page/navigate pg (str base-url "/login"))
+ (is (wait-for-text pg "body" "@alice" 15000) "alice session after login")
+
+ ;; Enter via pool URL — page picks first pair automatically.
+ (page/navigate pg pool-url)
+ (is (wait-for-text pg "body.view-vote-compare" "compare" 15000)
+ "pool entry: vote compare page loads")
+
+ ;; Verify the initial pair is within the pool.
+ (let [pair-text (element-text pg ".vote-compare-pair")]
+ (is (and (string? pair-text) (str/includes? pair-text "~/pool/"))
+ (str "initial pair is within ~/pool: " pair-text)))
+
+ ;; Follow vote → next-pair sequence up to 15 iterations.
+ (let [votes-cast
+ (loop [i 0]
+ (if (>= i 15)
+ i
+ (let [explanation (str "pool vote " i " reason")]
+ (locator/fill (page/locator pg "#vote-explain") explanation)
+ (locator/click (page/locator pg "#vote-compare-form button[type=submit]"))
+ ;; Wait for edge history morph confirming the vote landed.
+ (if-not (wait-for-text pg "ul.vote-edge-history" explanation 20000)
+ (do (println " vote" i "history morph timed out — stopping")
+ i)
+ (let [has-next (wait-for-text pg "[data-testid=\"vote-next-pair\"]"
+ "next pair" 8000)]
+ (if-not has-next
+ ;; "no next pair" — pool exhausted.
+ (do (println " no next pair after vote" i " — pool exhausted")
+ (inc i))
+ (do
+ ;; Verify the pair on this page is within the pool before advancing.
+ (let [pt (element-text pg ".vote-compare-pair")]
+ (is (and (string? pt) (str/includes? pt "~/pool/"))
+ (str "pair at vote " i " is within ~/pool: " pt)))
+ (locator/click (page/locator pg "[data-testid=\"vote-next-pair\"]"))
+ ;; Wait for next pair to load.
+ (wait-for-text pg "body.view-vote-compare" "compare" 10000)
+ (recur (inc i)))))))))]
+
+ (is (>= votes-cast 1) (str "cast at least 1 vote, got: " votes-cast))
+ (println (str " pool voting sequence complete: " votes-cast " vote(s) cast")))
+
+ ;; After the sequence, the current page is still a pool-scoped vote page.
+ (let [url (page/url pg)]
+ (is (str/includes? (or url "") "/vote")
+ (str "still on /vote after sequence: " url))))))))
+
+ (finally
+ (when-some [s @!server] (common/kill-server s))
+ (when-some [g @!google] ((:stop-fn g)))
+ (fs/delete-tree tmp-dir)))
+
+ nil))
+
+(defn vote-pool-browser-test [& _args]
+ (vote-pool-flow!))
+
+(deftest browser-vote-pool-sequence
+ (vote-pool-flow!))
Hardlinks — judgments / attempts / prompt
judgments
attempts
Prompt text is loaded only by the download route.