constitution · epochs · watch · epoch 3

comparison

c_48fcbcde8f88 (tommy-mor) vs c_a337088f57f0 (tommy-mor)

download prompt · raw event · cmp_14d33362c76da2

council reasoning

~anthropic/claude-sonnet-latest · winner A · 6:4 · permalink

Side A is a clean, self-contained refactor that removes ~200 lines of duplicated HTTP/OAuth/test-harness boilerplate across four test files into shared `test.common`/`test.oauth` helpers, improving maintainability without touching production code. Side B improves the dev fixture script (cargo-watch, persistent data dir) but bundles in an unrelated and unexplained removal of room heading/breadcrumb markup in `server/src/html/forum.rs`, which looks like an accidental regression to production HTML mixed into a 'dev script' commit.

~x-ai/grok-latest · winner A · 3:1 · permalink

A consolidates duplicated HTTP/OAuth helpers, assert/ANSI harness, cargo-build, and server-env setup out of auth/grants/integration into shared common/oauth modules (including multi-user mock Google and complete-registration!), which is lasting test architecture across the suite. B improves one local fixture workflow (cargo-watch, persistent fixture-data/, preferred port 8080) plus a small room_page HTML trim—valuable DX, but narrower and less foundational than A’s dedup.

openai/gpt-chat-latest · winner A · 5:1 · permalink

Side A extracts duplicated test infrastructure into shared utilities (`test.common` and `test.oauth`), introducing reusable helpers such as `run-cargo-build-release!`, `slug-server-env`, `complete-registration!`, shared assertions, configurable mock OAuth users, and consistent HTTP timeouts while updating multiple test suites to use them. Side B mainly improves the local development fixture workflow (cargo-watch, persistent fixture data, preferred port) and removes a small piece of room-page UI, which is useful but has a narrower, less foundational impact on the project's long-term maintainability.

sides

A — c_48fcbcde8f88 (tommy-mor)

message

[b32c92f2] consolidated shared functions in tests (composer 2 fast)

diff preview

diff --git a/test/auth.bb b/test/auth.bb
index a67cc1de763434176d2f68e419dd37a8cd328395..78cffc875ffe83f512bca253f4a7489227311da4 100644
--- a/test/auth.bb
+++ b/test/auth.bb
@@ -3,113 +3,14 @@
   (:require [babashka.process :as p]
             [babashka.fs :as fs]
             [cheshire.core :as json]
-            [org.httpkit.server :as http]
-            [test.common :as common]))
+            [clojure.string :as str]
+            [test.common :as common]
+            [test.oauth :as oauth]))
 
-(def ^:private ansi-green "\033[32m")
-(def ^:private ansi-red   "\033[31m")
-(def ^:private ansi-reset "\033[0m")
 (def ^:private counts (atom {:pass 0 :fail 0}))
 
-(defn- pass [msg]
-  (swap! counts update :pass inc)
-  (println (str ansi-green "  ✓ " ansi-reset msg)))
-
-(defn- fail [msg]
-  (swap! counts update :fail inc)
-  (println (str ansi-red "  ✗ " ansi-reset msg)))
-
 (defn- assert! [pred msg]
-  (if pred
-    (pass msg)
-    (do (fail msg)
-        (throw (ex-info (str "FAIL: " msg) {})))))
-
-(defn- http-client []
-  (-> (java.net.http.HttpClient/newBuilder)
-      (.followRedirects java.net.http.HttpClient$Redirect/ALWAYS)
-      (.build)))
-
-(defn- http-get [url & {:keys [headers]}]
-  (let [b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (doseq [[k v] (or headers {})]
-      (.header b k v))
-    (let [req (-> b (.GET) (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- http-post-json [url data & {:keys [headers]}]
-  (let [body (json/generate-string data)
-        b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (.header b "Content-Type" "application/json")
-    (doseq [[k v] (or headers {})]
-      (.header b k v))
-    (let [req (-> b
-                  (.POST (java.net.http.HttpRequest$BodyPublishers/ofString body))
-                  (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- http-post-form [url form]
-  (let [pairs (->> form
-                   (map (fn [[k v]]
-                          (str (java.net.URLEncoder/encode (name k) "UTF-8")
-                               "="
-                               (java.net.URLEncoder/encode (str v) "UTF-8"))))
-                   (clojure.string/join "&"))
-        b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (.header b "Content-Type" "application/x-www-form-urlencoded")
-    (let [req (-> b
-                  (.POST (java.net.http.HttpRequest$BodyPublishers/ofString pairs))
-                  (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- parse-query [s]
-  (into {}
-        (for [part (clojure.string/split (or s "") #"&")
-              :when (not (clojure.string/blank? part))]
-          (let [[k v] (clojure.string/split part #"=" 2)]
-            [(keyword (java.net.URLDecoder/decode k "UTF-8"))
-             (some-> v (java.net.URLDecoder/decode "UTF-8"))]))))
-
-(defn- b64url [s]
-  (-> (java.util.Base64/getUrlEncoder)
-      (.withoutPadding)
-      (.encodeToString (.getBytes s "UTF-8"))))
-
-(defn- make-id-token [sub]
-  (str (b64url "{\"alg\":\"RS256\",\"typ\":\"JWT\"}")
-       "."
-       (b64url (json/generate-string {:sub sub}))
-       ".fakesig"))
-
-(defn- start-mock-google [port]
-  (let [google-users ["google-user-1" "google-user-2"]
-        !call-count (atom 0)
-        handler
-        (fn [req]
-          (cond
-            (and (= :get (:request-method req))
-                 (= "/o/oauth2/v2/auth" (:uri req)))
-            (let [q (parse-query (:query-string req))
-                  redirect-uri (:redirect_uri q)
-                  state (:state q)
-                  loc (str redirect-uri "?code=mockcode&state=" state)]
-              {:status 302 :headers {"Location" loc} :body ""})
-
-            (and (= :post (:request-method req))
-                 (= "/token" (:uri req)))
-            (let [n   (swap! !call-count inc)
-                  sub (nth google-users (mod (dec n) (count google-users)))]
-              {:status 200
-               :headers {"Content-Type" "application/json"}
-               :body (json/generate-string {:id_token (make-id-token sub)})})
-
-            :else
-            {:status 404 :body "not found"}))
-        stop-fn (http/run-server handler {:port port})]
-    {:stop-fn stop-fn :port port}))
+  (common/test-assert! counts pred msg))
 
 (defn auth-test [& _args]
   (println "\n━━━ auth v3 integration check ━━━\n")
@@ -117,8 +18,7 @@
 
   (println "building server + CLI binaries…")
   (common/letlocals
-   (bind build @(p/process [(common/cargo-bin) "build" "--release" "-p" "slugsocial-server" "-p" "slugsocial"]
-                           {:inherit true :env common/base-env}))
+   (bind build (common/run-cargo-build-release! ["slugsocial-server" "slugsocial"]))
    (assert! (zero? (:exit build)) "cargo build succeeds")
    (bind server-bin "target/release/slugsocial-server")
    (bind cli-bin "target/release/slugsocial")
@@ -134,19 +34,10 @@
    (bind !server (atom nil))
    (bind !google (atom nil))
 
-   (bind server-env (merge common/base-env
-                           {"SLUG_DATA_DIR" tmp-dir
-                            "SLUG_KEYS"     "test:test"
-                            "PORT"          (str slug-port)
-                            "RUST_LOG"      "warn"
-                            "SLUG_PUBLIC_URL" base-url
-                            "SLUG_GOOGLE_AUTH_URL" (str google-url "/o/oauth2/v2/auth")
-                            "SLUG_GOOGLE_TOKEN_URL" (str google-url "/token")
-                            "SLUG_GOOGLE_CLIENT_ID" "mock"
-                            "SLUG_GOOGLE_CLIENT_SECRET" "mock"}))
+   (bind server-env (common/slug-server-env tmp-dir base-url google-url slug-port))
    (try
      (println (str "\nstarting mock google on :" google-port))
-     (reset! !google (start-mock-google google-port))
+     (reset! !google (oauth/start-mock-google google-port :google-users ["google-user-1" "google-user-2"]))
      (assert! (some? (:stop-fn @!google)) "mock google started")
 
      (println (str "starting server on :" slug-port))
@@ -154,34 +45,33 @@
      (assert! (common/wait-for-server base-url 10000) "server responds to /healthz")
 
      (println "\nstarting pending session…")
-     (let [start-resp (http-post-json (str base-url "/api/v0/pending-session")
-                                      {:agent "00000000-0000-0000-0000-000000000000:bb:local/dev"})
+     (let [start-resp (oauth/http-post-json (str base-url "/api/v0/pending-session")
+                                            {:agent "00000000-0000-0000-0000-000000000000:bb:local/dev"})
            _ (assert! (= 200 (:status start-resp)) "pending-session start returns 200")
            start-json (json/parse-string (:body start-resp) true)]
-       (assert! (clojure.string/starts-with? (:session start-json) "p_") "session id has p_ prefix")
-       (assert! (clojure.string/includes? (:login_url start-json) "/auth/login") "login_url provided")
+       (assert! (str/starts-with? (:session start-json) "p_") "session id has p_ prefix")
+       (assert! (str/includes? (:login_url start-json) "/auth/login") "login_url provided")
 
        (println "\nsimulating browser oauth redirects…")
-       ;; This will follow redirects: /auth/login -> mock google -> /auth/callback -> /auth/choose-username
-       (let [login-get (http-get (:login_url start-json))]
+       (let [login-get (oauth/http-get (:login_url start-json))]
          (assert! (= 200 (:status login-get)) "choose-username page reachable after oauth callback"))
 
        (println "\nchoosing username…")
-       (let [choose (http-post-form (str base-url "/auth/choose-username")
-                                    {:session (:session start-json) :username "bbuser"})]
+       (let [choose (oauth/http-post-form (str base-url "/auth/choose-username")
+                                          {:session (:session start-json) :username "bbuser"})]
          (assert! (= 200 (:status choose)) "choose-username POST returns 200"))
 
        (println "\npolling pending session…")
-       (let [poll (http-get (str base-url "/api/v0/pending-session/" (:session start-json)))]
+       (let [poll (oauth/http-get (str base-url "/api/v0/pending-session/" (:session start-json)))]
          (assert! (= 200 (:status poll)) "pending-session poll returns 200")
          (let [poll-json (json/parse-string (:body poll) true)]
            (assert! (:complete poll-json) "pending session complete=true")
            (assert! (= "bbuser" (:user poll-json)) "poll returns stored username bbuser")
-           (assert! (clojure.string/starts-with? (:token poll-json) "slug_") "poll returns bearer token")
+           (assert! (str/starts-with? (:token poll-json) "slug_") "poll returns bearer token")
 
            (println "\nwhoami…")
-           (let [who (http-get (str base-url "/api/v0/whoami")
-                               :headers {"Authorization" (str "Bearer " (:token poll-json))})]
+           (let [who (oauth/http-get (str base-url "/api/v0/whoami")
+                                     :headers {"Authorization" (str "Bearer " (:token poll-json))})]
              (assert! (= 200 (:status who)) "whoami returns 200")
              (let [who-json (json/parse-string (:body who) true)]
                (assert! (= "bbuser" (:user who-json)) "whoami user is bbuser (stored form)"))))))
@@ -195,11 +85,11 @@
                   (str "identity start exits 0 (stderr: " (:err start-proc) ")"))
          (let [start-cli (json/parse-string (:out start-proc) true)]
            (assert! (= "present_oauth_url_to_user" (:phase start-cli)) "identity start --json phase")
-           (assert! (clojure.string/starts-with? (:session start-cli) "p_") "CLI start session id")
-           (let [login-get (http-get (:login_url start-cli))]
+           (assert! (str/starts-with? (:session start-cli) "p_") "CLI start session id")
+           (let [login-get (oauth/http-get (:login_url start-cli))]
              (assert! (= 200 (:status login-get)) "CLI login_url redirect chain succeeds"))
-           (let [choose (http-post-form (str base-url "/auth/choose-username")
-                                        {:session (:session start-cli) :username "cliuser"})]
+           (let [choose (oauth/http-post-form (str base-url "/auth/choose-username")
+                                              {:session (:session start-cli) :username "cliuser"})]
              (assert! (= 200 (:status choose)) "choose-username for cliuser"))
            (let [poll-proc @(p/process [cli-bin "identity" "poll" (:session start-cli)
                                         "--poll-interval-ms" "100" "--max-wait-secs" "30" "--json"]
@@ -209,10 +99,10 @@
              (let [poll-cli (json/parse-string (:out poll-proc) true)]
                (assert! (= "complete" (:phase poll-cli)) "identity poll --json phase")
                (assert! (= "cliuser" (:user poll-cli)) "CLI poll user (stored form)")
-               (assert! (clojure.string/starts-with? (:token poll-cli) "slug_") "CLI poll token")
+               (assert! (str/starts-with? (:token poll-cli) "slug_") "CLI poll token")
                (let [token-path (str cli-home "/.config/slugsocial/token")]
                  (assert! (fs/exists? token-path) "token written under isolated HOME")
-                 (assert! (= (clojure.string/trim (slurp token-path)) (:token poll-cli))
+                 (assert! (= (str/trim (slurp token-path)) (:token poll-cli))
                           "token file matches poll JSON"))
      

… preview truncated; 24,704 characters omitted

download full diff A

B — c_a337088f57f0 (tommy-mor)

message

[a45842df] better dev iteration script

diff preview

diff --git a/.gitignore b/.gitignore
index 9cd2eaece834481bee87639cd7cb6be77f33e302..b70cf5b97cd3556e061233d8b0aefd333568a991 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ target/
 repomix-output.xml
 psalms_kjv.txt
 dev-data/
+fixture-data/
 .worktrees/
 .specstory/
 .specstory/
diff --git a/bb.edn b/bb.edn
index 5d1d642d75d03f70879d7673e7ad95360336a8b1..4680e82d4227057d2eea6041dc5647beb759131d 100644
--- a/bb.edn
+++ b/bb.edn
@@ -47,7 +47,7 @@
                                            "RUST_LOG"      "info"})})))}
 
   fixture
-  {:doc "Run local server + mock OAuth + seeded walkthrough data for manual browser demos"
+  {:doc "Run local server via cargo-watch + mock OAuth + seeded walkthrough data (persistent ./fixture-data/, prefers PORT 8080). Requires cargo-watch."
    :requires ([test.walkthrough-fixture :as walkthrough-fixture])
    :task (walkthrough-fixture/run-fixture)}
 
diff --git a/server/src/html/forum.rs b/server/src/html/forum.rs
index e00e7110e2ad778d63b3d00b0cc4ffe20ba2e0d4..815fc6529062b103553644fc15e516334aec2b88 100644
--- a/server/src/html/forum.rs
+++ b/server/src/html/forum.rs
@@ -976,12 +976,6 @@ pub async fn room_page(
         html! {
             (strip)
             nav class="breadcrumb" { (bc_room(&nav, slug_display, None)) }
-            h2 { (slug_display) }
-            p class="muted" { (room_id) }
-            p class="muted room-links" {
-                "room garden · "
-                a href=(nav.garden_root_url()) { "~" }
-            }
             (room_members_section_markup(&reduced, &room_id, false))
             h3 { "threads" }
             (render_thread_feed(Some(&nav), "room-thread-feed", &rows, now))
diff --git a/test/common.clj b/test/common.clj
index 76a3e99fdb67c10bcb5c2f53d8bcd0917398af50..c6deba0d90995b0e3f9c4b8ad66a516ed19b870e 100644
--- a/test/common.clj
+++ b/test/common.clj
@@ -107,6 +107,16 @@
    (.close ss)
    port))
 
+(defn pick-port-prefer
+  "Use `preferred` if it can be bound, otherwise an ephemeral port (same as `pick-port`)."
+  [preferred]
+  (try
+    (let [ss (java.net.ServerSocket. preferred)]
+      (.close ss)
+      preferred)
+    (catch java.io.IOException _
+      (pick-port))))
+
 (defn wait-for-server
   "Poll /healthz until it returns 'ok', up to `timeout-ms`."
   [base-url timeout-ms]
diff --git a/test/walkthrough_fixture.clj b/test/walkthrough_fixture.clj
index 4b814822029c913e38151ca53848d1c64fb58373..a487ff1ef8548580577914fb33f321586859c9af 100644
--- a/test/walkthrough_fixture.clj
+++ b/test/walkthrough_fixture.clj
@@ -1,11 +1,18 @@
 (ns test.walkthrough-fixture
   "Launch a local slug server with mock OAuth and seed browser-friendly demo data."
   (:require [babashka.fs :as fs]
+            [babashka.process :as p]
             [cheshire.core :as json]
             [clojure.string :as str]
             [test.common :as common]
             [test.oauth :as oauth]))
 
+(def ^:private fixture-data-dir "fixture-data")
+;; Prefer the same port as `bb dev` / `bb watch`; fall back if something else is listening.
+(def ^:private preferred-slug-port 8080)
+;; First `cargo watch` compile can exceed a release-binary startup; allow several minutes.
+(def ^:private health-wait-ms 300000)
+
 (defn- assert! [pred msg]
   (when-not pred
     (throw (ex-info msg {}))))
@@ -85,49 +92,87 @@
             :thread_url (str base-url "/r/" room-short "/" room-slug "/t/walkthrough-thread")
             :garden_url (str base-url "/r/" room-short "/" room-slug "/~/secret/item")}}))
 
+(defn- rebase-fixture-summary [saved current-base-url current-google-url current-data-dir]
+  (let [inner (:summary saved)
+        room (:room inner)
+        rs (:short room)
+        lg (:slug room)]
+    (assoc saved
+           :base_url current-base-url
+           :mock_google_url current-google-url
+           :data_dir (str current-data-dir)
+           :summary (assoc inner
+                           :room (assoc room
+                                         :url (str current-base-url "/r/" rs "/" lg)
+                                         :thread_url (str current-base-url "/r/" rs "/" lg "/t/walkthrough-thread")
+                                         :garden_url (str current-base-url "/r/" rs "/" lg "/~/secret/item"))))))
+
+(defn- fixture-log-present? [data-dir]
+  (let [p (fs/path data-dir "events.jsonl")]
+    (and (fs/exists? p) (pos? (fs/size p)))))
+
+(defn- load-or-seed-summary!
+  [base-url google-url data-dir summary-path]
+  (if (and (fixture-log-present? data-dir) (fs/exists? summary-path))
+    (let [saved (json/parse-string (slurp summary-path) true)
+          rebased (rebase-fixture-summary saved base-url google-url data-dir)]
+      (spit summary-path (json/generate-string rebased {:pretty true}))
+      (println "")
+      (println "reusing fixture-data/ (delete the directory for a fresh seed)")
+      rebased)
+    (let [seeded (seed-demo! base-url)
+          s {:base_url base-url
+             :mock_google_url google-url
+             :data_dir (str data-dir)
+             :summary seeded}]
+      (spit summary-path (json/generate-string s {:pretty true}))
+      s)))
+
 (defn run-fixture [& _args]
-  (let [build (common/run-cargo-build-release! ["slugsocial-server"])
-        _ (assert! (zero? (:exit build)) "cargo build --release failed")
-        server-bin "target/release/slugsocial-server"
-        tmp-dir (str (fs/create-temp-dir {:prefix "slug-walkthrough-"}))
-        slug-port (common/pick-port)
+  (let [data-dir (str (fs/absolutize (fs/path (fs/cwd) fixture-data-dir)))
+        slug-port (common/pick-port-prefer preferred-slug-port)
         google-port (common/pick-port)
         base-url (str "http://127.0.0.1:" slug-port)
         google-url (str "http://127.0.0.1:" google-port)
-        stable-dir "/tmp/slug-walkthrough-fixture"
-        summary-path (str stable-dir "/summary.json")
+        summary-path (str (fs/path data-dir "summary.json"))
         !server (atom nil)
         !google (atom nil)
-        server-env (common/slug-server-env tmp-dir base-url google-url slug-port)]
+        server-env (merge (common/slug-server-env data-dir base-url google-url slug-port)
+                          {"RUST_LOG" "info"})
+        watch-cmd [(common/cargo-bin) "watch"
+                   "-x" "run -p slugsocial-server"
+                   "-w" "server/src"
+                   "-w" "server/static"
+                   "-w" "types/src"]]
     (try
-      (fs/create-dirs stable-dir)
+      (fs/create-dirs data-dir)
       (reset! !google
               (oauth/start-mock-google google-port
                                        :google-users ["google-user-alice" "google-user-bob"]))
-      (reset! !server (common/start-server server-bin server-env))
-      (assert! (common/wait-for-server base-url 10000) "server did not become healthy")
-      (let [seeded (seed-demo! base-url)
-            summary {:base_url base-url
-                     :mock_google_url google-url
-                     :data_dir tmp-dir
-                     :summary seeded}]
-        (spit summary-path (json/generate-string summary {:pretty true}))
+      (println "")
+      (println "starting cargo-watch (first compile may take a while)…")
+      (flush)
+      (reset! !server (p/process watch-cmd {:inherit true :env server-env}))
+      (assert! (common/wait-for-server base-url health-wait-ms) "server did not become healthy")
+      (let [summary (load-or-seed-summary! base-url google-url data-dir summary-path)]
         (println "")
         (println "walkthrough fixture ready")
         (println (str "  base url:      " base-url))
         (println (str "  room page:     " (get-in summary [:summary :room :url])))
         (println (str "  thread page:   " (get-in summary [:summary :room :thread_url])))
         (println (str "  garden page:   " (get-in summary [:summary :room :garden_url])))
+        (println (str "  data dir:      " data-dir))
         (println (str "  summary json:  " summary-path))
         (println "")
         (println "seeded users")
         (println "  alice / bob via mock OAuth")
         (println "")
+        (println "editing server/src or server/static reloads the server; data persists in fixture-data/")
+        (println "")
         (println "press Ctrl-C to stop")
         (flush)
         (while true
           (Thread/sleep 1000)))
       (finally
         (when-some [s @!server] (common/kill-server s))
-        (when-some [g @!google] ((:stop-fn g)))
-        (fs/delete-tree tmp-dir)))))
+        (when-some [g @!google] ((:stop-fn g)))))))

download full diff B

Hardlinks — judgments / attempts / prompt

prompt download

judgments

attempts

Prompt text is loaded only by the download route.