Side A meaningfully deduplicates substantial test infrastructure (mock OAuth server, HTTP helpers, pass/fail harness, env builders) across three test files into shared modules, reducing maintenance burden with no behavior loss. Side B is a small, cosmetic UI tweak (removing a toggle button and simplifying placeholder text) with minimal lasting architectural value.
constitution · epochs · watch · epoch 3
c_48fcbcde8f88 (tommy-mor) vs c_19f4b8f10b98 (tommy-mor)
download prompt · raw event · cmp_d338c8213b729a
council reasoning
A consolidates duplicated test harness, HTTP/OAuth mocks, cargo build, and server-env helpers into common.bb/oauth.bb and rewires auth/grants/integration to use them, a lasting DRY improvement across the suite. B only trims a public new-thread compose toggle and tweaks labels/placeholders in forum.rs—cosmetic UI churn with little structural impact.
Side A consolidates duplicated test infrastructure into shared helpers (`test.common` and `test.oauth`), introducing reusable functions like `run-cargo-build-release!`, `slug-server-env`, `complete-registration!`, and configurable mock OAuth behavior while updating multiple test suites to use them. This reduces duplication, centralizes maintenance, and also standardizes HTTP timeouts and multi-user OAuth testing; Side B is primarily a UI cleanup that removes the form toggle and tweaks placeholders/button text without adding comparable lasting functionality.
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 omittedB — c_19f4b8f10b98 (tommy-mor)
message
[b5e9bc03] cleaner
diff preview
diff --git a/server/src/html/forum.rs b/server/src/html/forum.rs
index a173e7aea7a81c7cfab5f2f6a5549e0db560fb2b..670f5209c1e172b75156ef1b88ea382c70242062 100644
--- a/server/src/html/forum.rs
+++ b/server/src/html/forum.rs
@@ -465,41 +465,23 @@ fn new_thread_form_public(show: bool) -> Markup {
return html! {};
}
html! {
- button
- type="button"
- class="form-toggle"
- data-toggle-target="#public-new-thread-compose"
- data-open-label="new public thread"
- data-close-label="hide new public thread"
- aria-expanded="false"
- {
- "new public thread"
- }
- section class="compose" id="public-new-thread-compose" hidden {
- h3 { "new public thread" }
- p class="muted" { "Set thread tag and body. Example: start with a title line or use the CLI-shaped DSL." }
+ section class="compose" id="public-new-thread-compose" {
div id="public-new-thread-errors" {}
form id="public-new-thread-form" method="POST" action="/ui" data-check-action="/ui" data-check-rpc=(template_json_compact(&json!({
"action": "check_ingest",
"room": "public",
"thread_tag": {"$form": "thread_tag"},
"text": {"$form": "text"},
- "error_target": "public-new-thread-errors",
- "form_id": "public-new-thread-form",
})).unwrap()) {
input type="hidden" name=(UI_RPC_FIELD) value=(template_json_compact(&json!({
"action": "post_ingest",
"room": "public",
"thread_tag": {"$form": "thread_tag"},
"text": {"$form": "text"},
- "error_target": "public-new-thread-errors",
- "form_id": "public-new-thread-form",
})).unwrap());
- label for="new-thread-tag" { "thread tag" }
- input type="text" id="new-thread-tag" name="thread_tag" pattern="[a-z0-9_\\-]{1,64}" placeholder="my-topic";
- label for="new-thread-text" { "text" }
- textarea id="new-thread-text" name="text" rows="4" placeholder="#my-topic\n\nYour first post…" {}
- p { button type="submit" { "create / post" } }
+ input type="text" id="new-thread-tag" name="thread_tag" pattern="[a-z0-9_\\-]{1,64}" placeholder="thread-title-slug-here";
+ textarea id="new-thread-text" name="text" rows="4" placeholder="Hello threadgoers!! Behold my new thread!" {}
+ p { button type="submit" { "create thread / make first post" } }
}
}
}
Hardlinks — judgments / attempts / prompt
judgments
attempts
Prompt text is loaded only by the download route.