forge
Explore
Log in

Don't you dare go Hollow

E2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies

Browse files at this commit

128691aa9732cd2b8a89e9d08746b404b9f781b0Ahmet Kaan GümüşParent: 76d78e3
All checks have passed
Show checks
  • refactor
    • e2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies
    • docs drop references to removed files
Show full message
♻️ refactor: e2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies; docs drop references to removed files
crates/forge-e2e/tests/e2e/account_mail_e2e.rsmodified+2 -21
@@ -2,37 +2,18 @@
22 //! tests, this starts the real `forge` binary. The log transport writes each mail to
33 //! `<data_dir>/mail-log/`, which is where the tests read the reset link from.
44
5-use crate::common::{Http, Resp, launch_with, pick_ports};
5+use crate::common::{Http, Resp, cookie_named, input_value, launch_with, pick_ports};
66 use std::fs;
77 use std::path::{Path, PathBuf};
88 use std::time::Duration;
99
1010 use forge_core::Store;
1111 use forge_core::password::hash_password;
12-use reqwest::header::SET_COOKIE;
1312
1413 const LOG_TRANSPORT: &str = "\n[mail]\ntransport = \"log\"\n";
1514 const OLD_PW: &str = "tahinli-old-password-1";
1615 const NEW_PW: &str = "tahinli-new-password-2";
1716
18-/// The `name=value` pair of the Set-Cookie header whose name starts with `prefix`.
19-fn cookie_named(resp: &Resp, prefix: &str) -> Option<String> {
20- resp.headers
21- .get_all(SET_COOKIE)
22- .iter()
23- .filter_map(|v| v.to_str().ok())
24- .find(|raw| raw.starts_with(prefix))
25- .map(|raw| raw.split(';').next().unwrap().to_owned())
26-}
27-
28-/// The value of a hidden `<input name=... value=...>` field.
29-fn input_value(html: &str, name: &str) -> String {
30- let marker = format!("name=\"{name}\" value=\"");
31- let start = html.find(&marker).unwrap_or_else(|| panic!("{name} field")) + marker.len();
32- let end = html[start..].find('"').unwrap() + start;
33- html[start..end].to_owned()
34-}
35-
3617 /// Creates tahinli with a verified address. Bob has an address that is not verified. Runs before
3718 /// the server starts, like the other e2e tests.
3819 async fn seed(dir: &Path) {
@@ -169,7 +150,7 @@ async fn reset_link_sets_a_new_password_once() {
169150 assert!(page.body.contains("Set a new password"));
170151
171152 let cookie = cookie_named(&page, "__Host-forge_precsrf").expect("precsrf cookie");
172- let precsrf = cookie.split_once('=').unwrap().1.to_owned();
153+ let precsrf = input_value(&page.body, "precsrf");
173154 let form = [
174155 ("precsrf", precsrf.as_str()),
175156 ("password", NEW_PW),
crates/forge-e2e/tests/e2e/advisories_e2e.rsmodified+1 -17
@@ -9,7 +9,7 @@
99 //! - a reader without Write gets a 404 on the page.
1010
1111 use crate::common::{
12- Http, Resp, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path,
12+ Http, Resp, Server, input_value, launch_with, login, pick_ports, run_admin, tool_on_path,
1313 write_config_with,
1414 };
1515 use std::fs;
@@ -121,22 +121,6 @@ async fn boot() -> Booted {
121121 }
122122 }
123123
124-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
125- let out = Command::new(bin())
126- .arg("--config")
127- .arg(config)
128- .args(["admin", "create-user", username])
129- .args(extra)
130- .env("FORGE_PASSWORD", password)
131- .output()
132- .expect("run admin create-user");
133- assert!(
134- out.status.success(),
135- "create-user {username} failed:\n{}",
136- String::from_utf8_lossy(&out.stderr)
137- );
138-}
139-
140124 async fn create_token(http: &Http, session: &str) -> String {
141125 let page = http.get_cookie("/settings/keys", session).await;
142126 assert_eq!(page.status, 200, "GET /settings/keys");
crates/forge-e2e/tests/e2e/branch_protection_e2e.rsmodified+2 -15
@@ -3,7 +3,7 @@
33 //! while the server runs. Helpers mirror `git_e2e.rs`.
44
55 use crate::common::{
6- Http, Ports, Server, bin, describe, input_value, launch, login, pick_ports, relaunch,
6+ Http, Ports, Server, describe, input_value, launch, login, pick_ports, relaunch, run_admin,
77 tool_on_path, write_config,
88 };
99 use std::fs;
@@ -14,18 +14,6 @@ use forge_core::Store;
1414
1515 const TAHINLI_PW: &str = "tahinli-password-123";
1616
17-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
18- let out = Command::new(bin())
19- .arg("--config")
20- .arg(config)
21- .args(["admin", "create-user", username])
22- .args(extra)
23- .env("FORGE_PASSWORD", password)
24- .output()
25- .expect("run admin create-user");
26- ok(&out, &format!("create-user {username}"));
27-}
28-
2917 fn ok(out: &Output, what: &str) {
3018 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
3119 }
@@ -233,10 +221,9 @@ async fn branch_protection_end_to_end() {
233221 };
234222 let mut server = start_server(&ctx).await;
235223
236- // Seed main, feature/x and release/1 with two commits on main.
237224 let url = format!(
238225 "http://tahinli:{token}@127.0.0.1:{}/tahinli/bp.git",
239- ctx.http.base.rsplit(':').next().expect("port")
226+ ctx.ports.http
240227 );
241228 let work = ctx.dir.join("work");
242229 ok(&git(&ctx.dir, &["clone", &url, path_str(&work)]), "clone");
crates/forge-e2e/tests/e2e/browse_e2e.rsmodified+9 -88
@@ -5,7 +5,7 @@
55 //! Cookies are handled by hand, as in `git_e2e.rs`: the session cookie is `__Host-forge_session`
66 //! with `Secure`, so a cookie jar would not send it over plain http.
77
8-use crate::common::{bin, describe, input_value, launch, pick_ports, tool_on_path, write_config};
8+use crate::common::{boot_admin, describe, input_value, tool_on_path};
99 use std::fs;
1010 use std::path::Path;
1111 use std::process::{Command, Output};
@@ -147,18 +147,6 @@ fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &s
147147 );
148148 }
149149
150-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
151- let out = Command::new(bin())
152- .arg("--config")
153- .arg(config)
154- .args(["admin", "create-user", username])
155- .args(extra)
156- .env("FORGE_PASSWORD", password)
157- .output()
158- .expect("run admin create-user");
159- ok(&out, &format!("create-user {username}"));
160-}
161-
162150 fn ok(out: &Output, what: &str) {
163151 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
164152 }
@@ -200,7 +188,6 @@ fn write_fixtures(work: &Path) {
200188 fs::write(work.join("src/main.rs"), "fn main() {}\n").expect("write main.rs");
201189 fs::write(work.join("img.png"), PNG).expect("write img.png");
202190 fs::write(work.join("evil.html"), "<script>alert(1)</script>\n").expect("write evil.html");
203- // A Git LFS pointer whose object is not stored, so the blob page says so.
204191 fs::write(
205192 work.join("weights.bin"),
206193 "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n",
@@ -334,30 +321,17 @@ async fn browse_end_to_end() {
334321 return;
335322 }
336323
337- // Keep the path short, as in git_e2e.rs.
338- let root = tempfile::Builder::new()
339- .prefix("fbrw")
340- .tempdir_in("/tmp")
341- .expect("temp dir");
324+ let (root, _server, ports) = boot_admin("fbrw", TAHINLI_PW).await;
342325 let dir = root.path().to_path_buf();
343-
344- let ports = pick_ports();
345- let config = write_config(&dir, ports);
346-
347- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
348-
349- let (_server, ports) = launch(&dir, ports).await;
350326 let http = Http::new(ports.http);
351327 let raw = Http::new(ports.content);
352328 let raw_base = raw.base.clone();
353329
354- // Setup: tahinli logs in, makes a token and creates one public and one private repo.
355330 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
356331 let token = create_token(&http, &tahinli, "browse-token").await;
357332 create_repo(&http, &tahinli, "pub", "public").await;
358333 create_repo(&http, &tahinli, "priv", "private").await;
359334
360- // Push the same fixtures to both repos over HTTPS with the token.
361335 let pub_url = format!(
362336 "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git",
363337 ports.http
@@ -369,7 +343,6 @@ async fn browse_end_to_end() {
369343 let pub_main = push_fixtures(&dir, &pub_url, &dir.join("pub-work"));
370344 push_fixtures(&dir, &priv_url, &dir.join("priv-work"));
371345
372- // A branch named `media` in the public repo, with its own README.md.
373346 let pub_work = dir.join("pub-work");
374347 ok(
375348 &git(
@@ -382,7 +355,6 @@ async fn browse_end_to_end() {
382355 commit_all(&pub_work, "media branch");
383356 ok(&git(&pub_work, &["push", "origin", "media"]), "push media");
384357
385- // App origin, anonymous, public repo.
386358 let home = http.get("/tahinli/pub", None).await;
387359 assert_eq!(home.status, 200, "anonymous home of public repo");
388360 let csp = home
@@ -420,7 +392,6 @@ async fn browse_end_to_end() {
420392 "README image must point at the raw origin: {image_srcs:?}"
421393 );
422394
423- // Latest commit bar: the root has one commit on main, so its subject, short sha and count.
424395 assert_latest_bar(
425396 &home_body,
426397 "repo home",
@@ -494,7 +465,6 @@ async fn browse_end_to_end() {
494465 feature_tree.body().contains("feature.txt"),
495466 "feature/x tree must list feature.txt"
496467 );
497- // The feature commit is the newest on feature/x, on top of the two-commit history.
498468 assert_latest_bar(
499469 &feature_tree.body(),
500470 "tree of feature/x",
@@ -510,7 +480,6 @@ async fn browse_end_to_end() {
510480 "archive must start with gzip magic bytes"
511481 );
512482
513- // App origin, private repo: anonymous gets 404 everywhere.
514483 for path in [
515484 "/tahinli/priv",
516485 "/tahinli/priv/tree/main/src",
@@ -520,7 +489,6 @@ async fn browse_end_to_end() {
520489 assert_eq!(res.status, 404, "anonymous {path} on private repo");
521490 }
522491
523- // Logged in, the image blob page carries a signed raw URL.
524492 let priv_img = http
525493 .get("/tahinli/priv/blob/main/img.png", Some(&tahinli))
526494 .await;
@@ -534,11 +502,9 @@ async fn browse_end_to_end() {
534502 "signed raw URL shape: {priv_img_src}"
535503 );
536504
537- // Raw origin: the media route 404s when the repo does not link the object.
538505 let media = raw.get("/tahinli/pub/-/media/main/weights.bin", None).await;
539506 assert_eq!(media.status, 404, "media of an unstored LFS object");
540507
541- // Raw origin: a branch named `media` is an ordinary raw path, not the media route.
542508 let media_branch = raw.get("/tahinli/pub/media/README.md", None).await;
543509 assert_eq!(
544510 media_branch.status, 200,
@@ -546,11 +512,9 @@ async fn browse_end_to_end() {
546512 );
547513 assert_eq!(media_branch.body(), "# On a media branch\n");
548514
549- // Raw origin: `-` is never a ref name, so it is a 404 and not resolved.
550515 let dash = raw.get("/tahinli/pub/-/README.md", None).await;
551516 assert_eq!(dash.status, 404, "raw path with a `-` ref");
552517
553- // Raw origin: public file.
554518 let main_rs = raw.get("/tahinli/pub/main/src/main.rs", None).await;
555519 assert_eq!(main_rs.status, 200, "raw public main.rs");
556520 assert_eq!(
@@ -570,7 +534,6 @@ async fn browse_end_to_end() {
570534 );
571535 assert_no_cookie(&main_rs, "raw public main.rs");
572536
573- // Raw origin: HTML is served as a download, never inline.
574537 let evil = raw.get("/tahinli/pub/main/evil.html", None).await;
575538 assert_eq!(evil.status, 200, "raw evil.html");
576539 assert!(
@@ -580,13 +543,11 @@ async fn browse_end_to_end() {
580543 );
581544 assert_no_cookie(&evil, "raw evil.html");
582545
583- // Raw origin: images keep their image type.
584546 let img = raw.get("/tahinli/pub/main/img.png", None).await;
585547 assert_eq!(img.status, 200, "raw img.png");
586548 assert_eq!(img.header(CONTENT_TYPE).as_deref(), Some("image/png"));
587549 assert_no_cookie(&img, "raw img.png");
588550
589- // Raw origin: private repo needs a valid token.
590551 let priv_no_token = raw.get("/tahinli/priv/main/img.png", None).await;
591552 assert_eq!(priv_no_token.status, 404, "private raw without token");
592553 assert_no_cookie(&priv_no_token, "raw private without token");
@@ -598,8 +559,6 @@ async fn browse_end_to_end() {
598559 assert_eq!(priv_ok.status, 200, "private raw with the scraped token");
599560 assert_no_cookie(&priv_ok, "raw private with token");
600561
601- // Tampering with the signature (its first character) must fail. The first base64 character
602- // carries six significant bits, so flipping it always changes the signature.
603562 let (file_part, query) = priv_path.split_once("?token=").expect("token query");
604563 let (expires, sig) = query.split_once('.').expect("token shape");
605564 let flipped = if sig.starts_with('A') { 'B' } else { 'A' };
@@ -607,10 +566,12 @@ async fn browse_end_to_end() {
607566 let tampered = raw
608567 .get(&format!("{file_part}?token={expires}.{tampered_sig}"), None)
609568 .await;
610- assert_eq!(tampered.status, 404, "tampered token must be rejected");
569+ assert_eq!(
570+ tampered.status, 404,
571+ "tampered token must be rejected: the first base64 char carries six bits, so the flip always changes the signature"
572+ );
611573 assert_no_cookie(&tampered, "raw tampered token");
612574
613- // Raw origin has no app routes.
614575 let login_page = raw.get("/login", None).await;
615576 assert_eq!(
616577 login_page.status, 404,
@@ -626,7 +587,6 @@ async fn open_stream(http: &Http, path: &str, cookie: Option<&str>) -> reqwest::
626587 req = req.header(COOKIE, cookie);
627588 }
628589 let mut res = req.send().await.expect("stream request");
629- // A stream that opens sends its `retry` field first. It is not an event, so it is read here.
630590 if res.status().is_success() {
631591 let retry = next_chunk(&mut res).await.expect("the retry field");
632592 assert!(retry.contains("retry: 1000"), "{retry}");
@@ -650,15 +610,8 @@ async fn code_view_stream_follows_pushes() {
650610 return;
651611 }
652612
653- let root = tempfile::Builder::new()
654- .prefix("fliv")
655- .tempdir_in("/tmp")
656- .expect("temp dir");
613+ let (root, _server, ports) = boot_admin("fliv", TAHINLI_PW).await;
657614 let dir = root.path().to_path_buf();
658- let ports = pick_ports();
659- let config = write_config(&dir, ports);
660- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
661- let (_server, ports) = launch(&dir, ports).await;
662615 let http = Http::new(ports.http);
663616
664617 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
@@ -677,7 +630,6 @@ async fn code_view_stream_follows_pushes() {
677630 push_fixtures(&dir, &priv_url, &dir.join("priv-live"));
678631 let work = dir.join("pub-live");
679632
680- // The branch page follows its branch. A commit page does not, since a commit never moves.
681633 let branch_page = http.get("/tahinli/pub/tree/main/", None).await;
682634 assert_eq!(branch_page.status, 200);
683635 assert!(
@@ -701,7 +653,6 @@ async fn code_view_stream_follows_pushes() {
701653 "a commit page does not follow a branch"
702654 );
703655
704- // Anyone can follow a public branch.
705656 let mut stream = open_stream(&http, "/tahinli/pub/events?ref_name=main", None).await;
706657 assert_eq!(stream.status().as_u16(), 200);
707658 assert_eq!(
@@ -709,7 +660,6 @@ async fn code_view_stream_follows_pushes() {
709660 "text/event-stream"
710661 );
711662
712- // A push to another branch sends nothing: main did not move and no ref was created.
713663 ok(
714664 &git(&work, &["checkout", "-q", "feature/x"]),
715665 "checkout feature/x",
@@ -722,7 +672,6 @@ async fn code_view_stream_follows_pushes() {
722672 );
723673 assert!(next_chunk(&mut stream).await.is_none(), "other branch sent");
724674
725- // A push to main sends one `changed` event.
726675 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");
727676 fs::write(work.join("README.md"), "# Live\n\nChanged by a push.\n").expect("write README");
728677 commit_all(&work, "change the README");
@@ -730,7 +679,6 @@ async fn code_view_stream_follows_pushes() {
730679 let event = next_chunk(&mut stream).await.expect("event for main");
731680 assert!(event.contains("event: changed"), "{event}");
732681
733- // Creating and deleting a branch changes the branch list, so the page follows it too.
734682 ok(
735683 &git(&work, &["checkout", "-q", "-b", "topic"]),
736684 "create topic",
@@ -752,7 +700,6 @@ async fn code_view_stream_follows_pushes() {
752700 .expect("event for a deleted branch");
753701 assert!(deleted.contains("event: changed"), "{deleted}");
754702
755- // A private repo streams only to a viewer who can read it.
756703 let private = "/tahinli/priv/events?ref_name=main";
757704 let anonymous = open_stream(&http, private, None).await;
758705 assert_eq!(
@@ -789,22 +736,13 @@ async fn issue_streams_follow_writes() {
789736 return;
790737 }
791738
792- let root = tempfile::Builder::new()
793- .prefix("filive")
794- .tempdir_in("/tmp")
795- .expect("temp dir");
796- let dir = root.path().to_path_buf();
797- let ports = pick_ports();
798- let config = write_config(&dir, ports);
799- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
800- let (_server, ports) = launch(&dir, ports).await;
739+ let (_root, _server, ports) = boot_admin("filive", TAHINLI_PW).await;
801740 let http = Http::new(ports.http);
802741
803742 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
804743 create_repo(&http, &tahinli, "pub", "public").await;
805744 create_repo(&http, &tahinli, "priv", "private").await;
806745
807- // The list follows the repo's issues. Anyone can follow a public repo.
808746 let list_page = http.get("/tahinli/pub/issues", None).await;
809747 assert!(
810748 list_page
@@ -815,7 +753,6 @@ async fn issue_streams_follow_writes() {
815753 let mut list = open_stream(&http, "/tahinli/pub/issues/live", None).await;
816754 assert_eq!(list.status().as_u16(), 200);
817755
818- // Creating an issue wakes the list.
819756 let new_page = http.get("/tahinli/pub/issues/new", Some(&tahinli)).await;
820757 let csrf = input_value(&new_page.body(), "csrf");
821758 post_redirect(
@@ -827,7 +764,6 @@ async fn issue_streams_follow_writes() {
827764 .await;
828765 assert_changed(&mut list, "creating an issue").await;
829766
830- // The issue page follows the issue, and the list stays subscribed to the repo's issues.
831767 let mut issue = open_stream(&http, "/tahinli/pub/issues/1/live", None).await;
832768 assert_eq!(issue.status().as_u16(), 200);
833769 let view = http.get("/tahinli/pub/issues/1", Some(&tahinli)).await;
@@ -900,7 +836,6 @@ async fn issue_streams_follow_writes() {
900836 assert_changed(&mut issue, what).await;
901837 }
902838
903- // A private repo streams only to a viewer who can read it.
904839 let anonymous = open_stream(&http, "/tahinli/priv/issues/live", None).await;
905840 assert_eq!(
906841 anonymous.status().as_u16(),
@@ -924,15 +859,8 @@ async fn browsing_pages_stream_their_changes() {
924859 return;
925860 }
926861
927- let root = tempfile::Builder::new()
928- .prefix("flive")
929- .tempdir_in("/tmp")
930- .expect("temp dir");
862+ let (root, _server, ports) = boot_admin("flive", TAHINLI_PW).await;
931863 let dir = root.path().to_path_buf();
932- let ports = pick_ports();
933- let config = write_config(&dir, ports);
934- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
935- let (_server, ports) = launch(&dir, ports).await;
936864 let http = Http::new(ports.http);
937865
938866 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
@@ -944,8 +872,6 @@ async fn browsing_pages_stream_their_changes() {
944872 );
945873 let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages"));
946874
947- // The inbox needs a session. Without one it refuses, and no URL names another user's inbox:
948- // the viewer always comes from the session.
949875 for path in [
950876 "/notifications/events",
951877 "/notifications/events?all=1&user=tahinli",
@@ -956,7 +882,6 @@ async fn browsing_pages_stream_their_changes() {
956882 let inbox = open_stream(&http, "/notifications/events", Some(tahinli.as_str())).await;
957883 assert_eq!(inbox.status().as_u16(), 200, "inbox stream for its owner");
958884
959- // The header of a public repo streams to anyone. A star moves its count for every viewer.
960885 let mut header = open_stream(&http, "/tahinli/pub/events", None).await;
961886 assert_eq!(header.status().as_u16(), 200);
962887 let page = http.get("/tahinli/pub", Some(&tahinli)).await;
@@ -973,16 +898,13 @@ async fn browsing_pages_stream_their_changes() {
973898 "the header shows the star"
974899 );
975900
976- // A second push moves main.
977901 let work = dir.join("pub-pages");
978- // push_fixtures leaves the clone on feature/x, so the new commit must go on main.
979902 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");
980903 fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt");
981904 commit_all(&work, "a second push");
982905 ok(&git(&work, &["push", "-q", "origin", "main"]), "push main");
983906 assert_ne!(pushed, head_sha(&work), "the second push moved main");
984907
985- // The explore listing streams to anyone, and a new public repo changes it.
986908 let mut explore = open_stream(&http, "/explore/events", None).await;
987909 assert_eq!(explore.status().as_u16(), 200);
988910 create_repo(&http, &tahinli, "lib", "public").await;
@@ -991,7 +913,6 @@ async fn browsing_pages_stream_their_changes() {
991913 .expect("event for a new public repo");
992914 assert!(listed.contains("event: changed"), "{listed}");
993915
994- // The profile streams to anyone, and an unknown name is not found.
995916 let mut profile = open_stream(&http, "/users/tahinli/events", None).await;
996917 assert_eq!(profile.status().as_u16(), 200);
997918 create_repo(&http, &tahinli, "tools", "public").await;
crates/forge-e2e/tests/e2e/ci_e2e.rsmodified+2 -22
@@ -11,7 +11,7 @@
1111 //! - a live log: `log.txt` streams while a job runs and ends when the job finishes.
1212
1313 use crate::common::{
14- FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, write_config,
14+ FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, run_admin, write_config,
1515 };
1616 use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest};
1717 use forge_runner::client::ForgeClient;
@@ -21,7 +21,7 @@ use forge_runner::runner::{RunOptions, Runner};
2121 use std::collections::BTreeMap;
2222 use std::fs;
2323 use std::path::{Path, PathBuf};
24-use std::process::{Command, Output};
24+use std::process::Command;
2525 use std::sync::Arc;
2626 use std::time::{Duration, Instant};
2727 use tokio_util::sync::CancellationToken;
@@ -103,26 +103,6 @@ fn first_text(body: &str, selector: &str) -> String {
103103 .to_owned()
104104 }
105105
106-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
107- let out = Command::new(bin())
108- .arg("--config")
109- .arg(config)
110- .args(["admin", "create-user", username])
111- .args(extra)
112- .env("FORGE_PASSWORD", password)
113- .output()
114- .expect("run admin create-user");
115- ok(&out, &format!("create-user {username}"));
116-}
117-
118-fn ok(out: &Output, what: &str) {
119- assert!(
120- out.status.success(),
121- "{what} failed:\n{}",
122- String::from_utf8_lossy(&out.stderr)
123- );
124-}
125-
126106 /// Runs git in `cwd` with `env` applied on top of the inherited environment. Returns stdout.
127107 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
128108 let mut cmd = Command::new("git");
crates/forge-e2e/tests/e2e/common/http.rsmodified+5 -0
@@ -153,6 +153,11 @@ pub fn cookie_named(resp: &Resp, suffix: &str) -> Option<String> {
153153 })
154154 }
155155
156+pub fn with_cookie(session: &str, res: &Resp, notice: &str) -> String {
157+ let cookie = cookie_named(res, notice).expect("notice cookie");
158+ format!("{session}; {cookie}")
159+}
160+
156161 /// Signs in as `username` through the `/login` form and returns the session cookie.
157162 pub async fn login(http: &Http, username: &str, password: &str) -> String {
158163 let page = http.get("/login", None).await;
crates/forge-e2e/tests/e2e/common/mod.rsmodified+144 -5
@@ -1,14 +1,11 @@
11 //! Helpers shared by the forge-web e2e tests. `main.rs` declares this module once, and each test
2-//! module imports what it needs from `crate::common`. Items a given test does not use are allowed
3-//! to be dead code.
2+//! module imports what it needs from `crate::common`.
43 //!
54 //! The server is started with `launch`, which waits for the three listeners (HTTP, user content
65 //! and SSH) with backoff. A connection that is refused just means "not yet". If the child exits
76 //! first, the panic carries its captured log. A port picked with `pick_ports` is only free until
87 //! the server binds it, so `launch` retries on fresh ports when the server reports a bind conflict.
98
10-#![allow(dead_code)]
11-
129 use std::fs;
1310 use std::net::TcpStream;
1411 use std::path::{Path, PathBuf};
@@ -16,9 +13,11 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio};
1613 use std::sync::OnceLock;
1714 use std::time::{Duration, Instant};
1815
16+use tempfile::TempDir;
17+
1918 mod http;
2019
21-pub use http::{Http, Resp, cookie_named, login};
20+pub use http::{Http, Resp, cookie_named, login, with_cookie};
2221
2322 /// The forge binary the tests start. `env!("CARGO_BIN_EXE_forge")` would only work in the package
2423 /// that owns the binary, and these tests live in `forge-e2e`, which does not depend on forge-web.
@@ -97,6 +96,13 @@ pub fn input_value(body: &str, name: &str) -> String {
9796 .to_owned()
9897 }
9998
99+pub fn temp_dir(prefix: &str) -> tempfile::TempDir {
100+ tempfile::Builder::new()
101+ .prefix(prefix)
102+ .tempdir_in("/tmp")
103+ .expect("temp dir")
104+}
105+
100106 /// A port the kernel handed out for a moment. It is free only until something binds it.
101107 pub fn free_port() -> u16 {
102108 std::net::TcpListener::bind("127.0.0.1:0")
@@ -167,6 +173,98 @@ pub fn write_config_with(dir: &Path, ports: Ports, extra: &str) -> PathBuf {
167173 /// before it answers 204, and the production default is 25 s, so the test server answers at once.
168174 pub const FAST_CLAIMS: &str = "[ci]\nclaim_wait_ms = 50\n";
169175
176+pub fn git(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
177+ let mut cmd = Command::new("git");
178+ cmd.current_dir(cwd)
179+ .args(["-c", "credential.helper="])
180+ .args(args)
181+ .env("GIT_TERMINAL_PROMPT", "0");
182+ for (key, value) in env {
183+ cmd.env(key, value);
184+ }
185+ cmd.output().expect("run git")
186+}
187+
188+/// Creates an access token through `/settings/tokens` and returns the token shown once.
189+pub async fn create_token(http: &Http, session: &str, name: &str) -> String {
190+ let page = http.get_cookie("/settings/keys", session).await;
191+ assert_eq!(page.status, 200, "GET /settings/keys");
192+ let csrf = input_value(&page.body, "csrf");
193+ let res = http
194+ .post_form(
195+ "/settings/tokens",
196+ &[("csrf", &csrf), ("name", name), ("expires", "30")],
197+ Some(session),
198+ )
199+ .await;
200+ assert_eq!(res.status, 200, "create token: {}", res.body);
201+ let doc = scraper::Html::parse_document(&res.body);
202+ let selector = scraper::Selector::parse("pre.code code").expect("selector");
203+ let token: String = doc
204+ .select(&selector)
205+ .next()
206+ .expect("token shown after creation")
207+ .text()
208+ .collect();
209+ let token = token.trim().to_owned();
210+ assert!(token.starts_with("forge_"), "unexpected token shape");
211+ token
212+}
213+
214+/// Creates a repo through `/new`.
215+pub async fn create_repo(http: &Http, session: &str, name: &str, visibility: &str) {
216+ let page = http.get_cookie("/new", session).await;
217+ assert_eq!(page.status, 200, "GET /new");
218+ let csrf = input_value(&page.body, "csrf");
219+ let res = http
220+ .post_form(
221+ "/new",
222+ &[
223+ ("csrf", &csrf),
224+ ("name", name),
225+ ("description", ""),
226+ ("visibility", visibility),
227+ ("default_branch", "main"),
228+ ],
229+ Some(session),
230+ )
231+ .await;
232+ assert_eq!(res.status, 303, "create repo {name}: {}", res.body);
233+ assert_eq!(
234+ res.location().as_deref(),
235+ Some(format!("/tahinli/{name}").as_str())
236+ );
237+}
238+
239+pub const PW: &str = "tahinli-password-123";
240+
241+pub fn admin(config: &Path, args: &[&str]) {
242+ let out = Command::new(bin())
243+ .arg("--config")
244+ .arg(config)
245+ .arg("admin")
246+ .args(args)
247+ .env("FORGE_PASSWORD", PW)
248+ .output()
249+ .expect("run admin command");
250+ assert!(
251+ out.status.success(),
252+ "admin {args:?} failed:\n{}",
253+ describe(&out)
254+ );
255+}
256+
257+pub fn init_bare(data_dir: &Path, repo_id: &str) {
258+ let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
259+ fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
260+ let out = Command::new("git")
261+ .args(["init", "--bare", "--quiet", "--initial-branch=main"])
262+ .arg(&path)
263+ .output()
264+ .expect("run git init");
265+ assert!(out.status.success(), "git init --bare: {}", describe(&out));
266+}
267+
170268 pub fn describe(out: &Output) -> String {
171269 format!(
172270 "status: {}\nstdout: {}\nstderr: {}",
@@ -176,6 +274,47 @@ pub fn describe(out: &Output) -> String {
176274 )
177275 }
178276
277+/// Waits for the next event of a stream, which must be `changed`.
278+pub async fn next_changed(res: &mut reqwest::Response, what: &str) {
279+ let chunk = tokio::time::timeout(Duration::from_secs(5), res.chunk())
280+ .await
281+ .unwrap_or_else(|_| panic!("no event after {what}"))
282+ .expect("stream chunk")
283+ .expect("stream still open");
284+ let text = String::from_utf8_lossy(&chunk);
285+ assert!(text.contains("event: changed"), "{what}: {text}");
286+}
287+
288+pub fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
289+ let out = Command::new(bin())
290+ .arg("--config")
291+ .arg(config)
292+ .args(["admin", "create-user", username])
293+ .args(extra)
294+ .env("FORGE_PASSWORD", password)
295+ .output()
296+ .expect("run admin create-user");
297+ assert!(
298+ out.status.success(),
299+ "create-user {username} failed:\n{}",
300+ describe(&out)
301+ );
302+}
303+
304+/// A fresh server with `tahinli` as its only user, an admin. The temp dir is under `/tmp` so the
305+/// socket paths stay under the 108-byte unix limit. Returns the dir, the server and its ports.
306+pub async fn boot_admin(prefix: &str, password: &str) -> (TempDir, Server, Ports) {
307+ let root = tempfile::Builder::new()
308+ .prefix(prefix)
309+ .tempdir_in("/tmp")
310+ .expect("temp dir");
311+ let ports = pick_ports();
312+ let config = write_config(root.path(), ports);
313+ run_admin(&config, "tahinli", &["--admin"], password);
314+ let (server, ports) = launch(root.path(), ports).await;
315+ (root, server, ports)
316+}
317+
179318 /// Starts `forge serve` on `ports` and returns once all three listeners answer. The config is
180319 /// written to `dir/forge.toml` and the log to `dir/serve.log`.
181320 ///
crates/forge-e2e/tests/e2e/discussions_e2e.rsmodified+1 -19
@@ -4,30 +4,12 @@
44 //! owner can still write.
55
66 use crate::common::{
7- Http, bin, input_value, launch, login, pick_ports, tool_on_path, write_config,
7+ Http, input_value, launch, login, pick_ports, run_admin, tool_on_path, write_config,
88 };
9-use std::path::Path;
10-use std::process::Command;
119
1210 const TAHINLI_PW: &str = "tahinli-password-123";
1311 const BOB_PW: &str = "bob-password-4567";
1412
15-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
16- let out = Command::new(bin())
17- .arg("--config")
18- .arg(config)
19- .args(["admin", "create-user", username])
20- .args(extra)
21- .env("FORGE_PASSWORD", password)
22- .output()
23- .expect("run admin create-user");
24- assert!(
25- out.status.success(),
26- "create-user {username} failed:\n{}",
27- String::from_utf8_lossy(&out.stderr)
28- );
29-}
30-
3113 /// Creates a public repo through `/new`.
3214 async fn create_repo(http: &Http, session: &str, name: &str) {
3315 let page = http.get("/new", Some(session)).await;
crates/forge-e2e/tests/e2e/git_e2e.rsmodified+2 -76
@@ -5,7 +5,8 @@
55 //! cookie jar would not send it over plain http. The test parses `Set-Cookie` and sends `Cookie`.
66
77 use crate::common::{
8- Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config,
8+ Http, create_repo, create_token, describe, git, input_value, launch, login, pick_ports,
9+ run_admin, tool_on_path, write_config,
910 };
1011 use std::fs;
1112 use std::path::{Path, PathBuf};
@@ -16,18 +17,6 @@ use reqwest::header::WWW_AUTHENTICATE;
1617 const TAHINLI_PW: &str = "tahinli-password-123";
1718 const BOB_PW: &str = "bob-password-4567";
1819
19-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
20- let out = Command::new(bin())
21- .arg("--config")
22- .arg(config)
23- .args(["admin", "create-user", username])
24- .args(extra)
25- .env("FORGE_PASSWORD", password)
26- .output()
27- .expect("run admin create-user");
28- ok(&out, &format!("create-user {username}"));
29-}
30-
3120 fn ok(out: &Output, what: &str) {
3221 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
3322 }
@@ -42,18 +31,6 @@ fn rejected(out: &Output, what: &str) -> String {
4231 describe(out)
4332 }
4433
45-fn git(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
46- let mut cmd = Command::new("git");
47- cmd.current_dir(cwd)
48- .args(["-c", "credential.helper="])
49- .args(args)
50- .env("GIT_TERMINAL_PROMPT", "0");
51- for (key, value) in env {
52- cmd.env(key, value);
53- }
54- cmd.output().expect("run git")
55-}
56-
5734 fn path_str(path: &Path) -> &str {
5835 path.to_str().expect("utf-8 path")
5936 }
@@ -140,32 +117,6 @@ fn read(path: PathBuf) -> String {
140117 fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
141118 }
142119
143-/// Creates an access token through `/settings/tokens` and returns the token shown once.
144-async fn create_token(http: &Http, session: &str, name: &str) -> String {
145- let page = http.get_cookie("/settings/keys", session).await;
146- assert_eq!(page.status, 200, "GET /settings/keys");
147- let csrf = input_value(&page.body, "csrf");
148- let res = http
149- .post_form(
150- "/settings/tokens",
151- &[("csrf", &csrf), ("name", name), ("expires", "30")],
152- Some(session),
153- )
154- .await;
155- assert_eq!(res.status, 200, "create token: {}", res.body);
156- let doc = scraper::Html::parse_document(&res.body);
157- let selector = scraper::Selector::parse("pre.code code").expect("selector");
158- let token: String = doc
159- .select(&selector)
160- .next()
161- .expect("token shown after creation")
162- .text()
163- .collect();
164- let token = token.trim().to_owned();
165- assert!(token.starts_with("forge_"), "unexpected token shape");
166- token
167-}
168-
169120 /// Adds a public key through `/settings/keys`.
170121 async fn add_key(http: &Http, session: &str, public_key: &str) {
171122 let page = http.get_cookie("/settings/keys", session).await;
@@ -185,31 +136,6 @@ async fn add_key(http: &Http, session: &str, public_key: &str) {
185136 assert_eq!(res.status, 303, "add SSH key: {}", res.body);
186137 }
187138
188-/// Creates a repo through `/new`.
189-async fn create_repo(http: &Http, session: &str, name: &str, visibility: &str) {
190- let page = http.get_cookie("/new", session).await;
191- assert_eq!(page.status, 200, "GET /new");
192- let csrf = input_value(&page.body, "csrf");
193- let res = http
194- .post_form(
195- "/new",
196- &[
197- ("csrf", &csrf),
198- ("name", name),
199- ("description", ""),
200- ("visibility", visibility),
201- ("default_branch", "main"),
202- ],
203- Some(session),
204- )
205- .await;
206- assert_eq!(res.status, 303, "create repo {name}: {}", res.body);
207- assert_eq!(
208- res.location().as_deref(),
209- Some(format!("/tahinli/{name}").as_str())
210- );
211-}
212-
213139 #[tokio::test]
214140 async fn git_end_to_end() {
215141 for tool in ["git", "ssh", "ssh-keygen"] {
crates/forge-e2e/tests/e2e/i18n_e2e.rsmodified+6 -6
@@ -1,7 +1,7 @@
11 //! End-to-end checks for the interface language. Anonymous pages follow `Accept-Language`; a
22 //! signed-in user's stored language beats the browser; `<html lang>` matches the language used.
33
4-use std::path::{Path, PathBuf};
4+use std::path::Path;
55 use std::process::Command;
66
77 use crate::common::{
@@ -38,7 +38,7 @@ struct Env {
3838 /// Creates tahinli, then runs `seed` against the store before the server starts.
3939 async fn start<F, Fut>(seed: F) -> Env
4040 where
41- F: FnOnce(PathBuf, Store) -> Fut,
41+ F: FnOnce(Store) -> Fut,
4242 Fut: std::future::Future<Output = ()>,
4343 {
4444 let root = tempfile::tempdir().expect("temp dir");
@@ -49,7 +49,7 @@ where
4949 let store = Store::open(&dir.join("forge.db"))
5050 .await
5151 .expect("open store");
52- seed(dir.clone(), store).await;
52+ seed(store).await;
5353 let (server, ports) = launch(&dir, ports).await;
5454 let http = Http::new(ports.http);
5555 Env {
@@ -61,7 +61,7 @@ where
6161
6262 #[tokio::test]
6363 async fn anonymous_pages_follow_the_browser_language() {
64- let env = start(|_, _| async {}).await;
64+ let env = start(|_| async {}).await;
6565
6666 let turkish = env
6767 .http
@@ -101,7 +101,7 @@ async fn anonymous_pages_follow_the_browser_language() {
101101
102102 #[tokio::test]
103103 async fn stored_language_beats_the_browser_for_a_signed_in_user() {
104- let env = start(|_, store| async move {
104+ let env = start(|store| async move {
105105 let tahinli = store
106106 .user_by_username("tahinli")
107107 .await
@@ -128,7 +128,7 @@ async fn stored_language_beats_the_browser_for_a_signed_in_user() {
128128
129129 #[tokio::test]
130130 async fn releases_page_follows_the_stored_turkish_language() {
131- let env = start(|_, store| async move {
131+ let env = start(|store| async move {
132132 let tahinli = store
133133 .user_by_username("tahinli")
134134 .await
crates/forge-e2e/tests/e2e/issue_close_e2e.rsmodified+2 -17
@@ -4,7 +4,8 @@
44 //! file, and every push is a real `git push` through the git HTTP endpoints.
55
66 use crate::common::{
7- Http, bin, input_value, launch, login, pick_ports, relaunch, tool_on_path, write_config,
7+ Http, input_value, launch, login, pick_ports, relaunch, run_admin, tool_on_path,
8+ write_config,
89 };
910 use std::fs;
1011 use std::future::Future;
@@ -17,22 +18,6 @@ use forge_core::Store;
1718 const TAHINLI_PW: &str = "tahinli-password-123";
1819 const BOB_PW: &str = "bob-password-4567";
1920
20-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
21- let out = Command::new(bin())
22- .arg("--config")
23- .arg(config)
24- .args(["admin", "create-user", username])
25- .args(extra)
26- .env("FORGE_PASSWORD", password)
27- .output()
28- .expect("run admin create-user");
29- assert!(
30- out.status.success(),
31- "create-user {username} failed:\n{}",
32- String::from_utf8_lossy(&out.stderr)
33- );
34-}
35-
3621 /// Runs git with credential helpers disabled and returns stdout, trimmed. Panics on failure.
3722 fn git(cwd: &Path, args: &[&str]) -> String {
3823 let out = git_output(cwd, args, &[]);
crates/forge-e2e/tests/e2e/lfs_e2e.rsmodified+1 -13
@@ -5,7 +5,7 @@
55 //! Git config is isolated from the developer's machine: `HOME` and `GIT_CONFIG_GLOBAL` point into
66 //! the test's temp dir.
77
8-use crate::common::{Http, bin, describe, input_value, launch, login, pick_ports, write_config};
8+use crate::common::{Http, describe, input_value, launch, login, pick_ports, run_admin, write_config};
99 use std::fs;
1010 use std::path::Path;
1111 use std::process::{Command, Output};
@@ -13,18 +13,6 @@ use std::process::{Command, Output};
1313 const TAHINLI_PW: &str = "tahinli-password-123";
1414 const FILE_SIZE: usize = 100 * 1024;
1515
16-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
17- let out = Command::new(bin())
18- .arg("--config")
19- .arg(config)
20- .args(["admin", "create-user", username])
21- .args(extra)
22- .env("FORGE_PASSWORD", password)
23- .output()
24- .expect("run admin create-user");
25- ok(&out, &format!("create-user {username}"));
26-}
27-
2816 fn ok(out: &Output, what: &str) {
2917 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
3018 }
crates/forge-e2e/tests/e2e/merge_queue_e2e.rsmodified+3 -133
@@ -1,17 +1,6 @@
1-//! End-to-end: the merge queue on a protected branch, against the real `forge` binary and the
2-//! real `forge-runner` library (see `ci_e2e.rs` for the harness).
3-//!
4-//! Scenarios:
5-//! - two pull requests queue; the first lands on a tested candidate, the second is removed with
6-//! a comment linking its failing run, and `main` only ever holds the tested commit;
7-//! - a new commit on a queued pull request's head removes it from the queue.
8-
9-// The harness helpers are the same ones `ci_e2e.rs` uses. This file uses a subset of them.
10-#![allow(dead_code)]
11-
121 use crate::common::{
13- FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path,
14- write_config,
2+ FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, run_admin,
3+ tool_on_path, write_config,
154 };
165 use forge_ci::proto::{JobAssignment, RegisterRequest};
176 use forge_runner::client::ForgeClient;
@@ -21,18 +10,15 @@ use forge_runner::runner::{RunOptions, Runner};
2110 use std::collections::BTreeMap;
2211 use std::fs;
2312 use std::path::{Path, PathBuf};
24-use std::process::{Command, Output};
13+use std::process::Command;
2514 use std::sync::Arc;
26-use std::time::{Duration, Instant};
2715 use tokio_util::sync::CancellationToken;
2816
2917 const TAHINLI_PW: &str = "tahinli-password-123";
3018 const BOB_PW: &str = "bob-password-4567";
31-const BOB_EMAIL: &str = "bob@users.noreply.127.0.0.1";
3219 const REPO_PATH: &str = "/tahinli/r";
3320 const LABELS: &[&str] = &["linux"];
3421
35-/// The text of the first element matching `selector`.
3622 fn first_text(body: &str, selector: &str) -> String {
3723 let doc = scraper::Html::parse_document(body);
3824 let selector = scraper::Selector::parse(selector).expect("selector");
@@ -45,27 +31,6 @@ fn first_text(body: &str, selector: &str) -> String {
4531 .to_owned()
4632 }
4733
48-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
49- let out = Command::new(bin())
50- .arg("--config")
51- .arg(config)
52- .args(["admin", "create-user", username])
53- .args(extra)
54- .env("FORGE_PASSWORD", password)
55- .output()
56- .expect("run admin create-user");
57- ok(&out, &format!("create-user {username}"));
58-}
59-
60-fn ok(out: &Output, what: &str) {
61- assert!(
62- out.status.success(),
63- "{what} failed:\n{}",
64- String::from_utf8_lossy(&out.stderr)
65- );
66-}
67-
68-/// Runs git in `cwd` with `env` applied on top of the inherited environment. Returns stdout.
6934 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
7035 let mut cmd = Command::new("git");
7136 cmd.current_dir(cwd)
@@ -88,8 +53,6 @@ fn git(cwd: &Path, args: &[&str]) -> String {
8853 git_env(cwd, args, &[])
8954 }
9055
91-/// Writes `file` (creating its directory), commits it with `who` as author and committer, and
92-/// returns the new HEAD.
9356 fn commit(
9457 repo: &Path,
9558 file: &str,
@@ -117,7 +80,6 @@ fn commit(
11780 git(repo, &["rev-parse", "HEAD"])
11881 }
11982
120-/// Clones `url` into `into` (a path that does not exist yet) and returns it.
12183 fn clone(url: &str, into: &Path) -> PathBuf {
12284 let parent = into.parent().expect("clone target has a parent");
12385 git(
@@ -127,19 +89,16 @@ fn clone(url: &str, into: &Path) -> PathBuf {
12789 into.to_path_buf()
12890 }
12991
130-/// The HTTPS remote for `owner/repo`, authenticated with a token.
13192 fn remote(port: u16, user: &str, token: &str, owner: &str, repo: &str) -> String {
13293 format!("http://{user}:{token}@127.0.0.1:{port}/{owner}/{repo}.git")
13394 }
13495
135-/// The CSRF token shown on any settings page of the signed-in user.
13696 async fn csrf_from(http: &Http, path: &str, session: &str) -> String {
13797 let page = http.get(path, Some(session)).await;
13898 assert_eq!(page.status, 200, "GET {path}");
13999 input_value(&page.body, "csrf")
140100 }
141101
142-/// Creates an access token through `/settings/tokens` and returns the token shown once.
143102 async fn create_token(http: &Http, session: &str, name: &str) -> String {
144103 let csrf = csrf_from(http, "/settings/keys", session).await;
145104 let res = http
@@ -155,7 +114,6 @@ async fn create_token(http: &Http, session: &str, name: &str) -> String {
155114 token
156115 }
157116
158-/// Creates a public repo `name` owned by tahinli through `/new`.
159117 async fn create_repo(http: &Http, session: &str, name: &str) {
160118 let page = http.get("/new", Some(session)).await;
161119 assert_eq!(page.status, 200, "GET /new");
@@ -180,21 +138,6 @@ async fn create_repo(http: &Http, session: &str, name: &str) {
180138 );
181139 }
182140
183-/// Adds or replaces a repo secret through the settings form.
184-async fn set_secret(http: &Http, session: &str, name: &str, value: &str) {
185- let csrf = csrf_from(http, &format!("{REPO_PATH}/settings/secrets"), session).await;
186- let res = http
187- .post_form(
188- &format!("{REPO_PATH}/settings/secrets"),
189- &[("csrf", &csrf), ("name", name), ("value", value)],
190- Some(session),
191- )
192- .await;
193- assert_eq!(res.status, 303, "set secret {name}: {}", res.body);
194-}
195-
196-/// A running server with its own temp data dir. Field order matters: the server is dropped (and
197-/// killed) before the temp dir is removed.
198141 struct Booted {
199142 _server: Server,
200143 _root: tempfile::TempDir,
@@ -204,14 +147,11 @@ struct Booted {
204147 port: u16,
205148 }
206149
207-/// The server's log, for assertion messages.
208150 fn server_log(b: &Booted) -> String {
209151 fs::read_to_string(b.dir.join("serve.log")).unwrap_or_default()
210152 }
211153
212-/// Creates tahinli (admin) and bob, then boots the server on fresh ports.
213154 async fn boot() -> Booted {
214- // Keep the path short: the internal unix socket path is limited to 108 bytes.
215155 let root = tempfile::Builder::new()
216156 .prefix("ci2e")
217157 .tempdir_in("/tmp")
@@ -233,7 +173,6 @@ async fn boot() -> Booted {
233173 }
234174 }
235175
236-/// A registered runner and the secret it claims with.
237176 struct Worker {
238177 runner: Runner,
239178 secret: String,
@@ -241,7 +180,6 @@ struct Worker {
241180 }
242181
243182 impl Worker {
244- /// One claim. `None` means the forge had nothing for this runner (after its long poll).
245183 async fn claim(&self) -> Option<JobAssignment> {
246184 self.runner
247185 .client()
@@ -251,7 +189,6 @@ impl Worker {
251189 .job
252190 }
253191
254- /// Claims and runs jobs until the forge has nothing left. Returns how many ran.
255192 async fn drain(&self) -> usize {
256193 let mut ran = 0;
257194 while let Some(job) = self.claim().await {
@@ -262,7 +199,6 @@ impl Worker {
262199 }
263200 }
264201
265-/// Registers a runner through the admin page and the runner API. The admin is `admin_session`.
266202 async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker {
267203 let page = b.http.get("/admin/runners", Some(admin_session)).await;
268204 assert_eq!(page.status, 200, "GET /admin/runners");
@@ -300,7 +236,6 @@ async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker
300236 images: forge_runner::config::ImagesConfig::default(),
301237 sandbox: forge_runner::config::SandboxConfig::default(),
302238 registries: Vec::new(),
303- // The e2e runner must not replace the test binary under itself.
304239 auto_update: false,
305240 cache_max_gib: 0,
306241 };
@@ -313,15 +248,11 @@ async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker
313248 }
314249 }
315250
316-/// One commit status as the status API reports it.
317251 #[derive(Debug, Clone)]
318252 struct Status {
319253 state: String,
320- description: String,
321- target_url: String,
322254 }
323255
324-/// The statuses on `sha` of tahinli/r, keyed by context.
325256 async fn statuses(http: &Http, token: &str, sha: &str) -> BTreeMap<String, Status> {
326257 let res = http
327258 .get_bearer(
@@ -341,62 +272,12 @@ async fn statuses(http: &Http, token: &str, sha: &str) -> BTreeMap<String, Statu
341272 field("context"),
342273 Status {
343274 state: field("state"),
344- description: field("description"),
345- target_url: field("target_url"),
346275 },
347276 )
348277 })
349278 .collect()
350279 }
351280
352-/// Polls the statuses until every context in `contexts` is present, then returns them.
353-async fn wait_statuses(
354- http: &Http,
355- token: &str,
356- sha: &str,
357- contexts: &[&str],
358-) -> BTreeMap<String, Status> {
359- let deadline = Instant::now() + Duration::from_secs(20);
360- loop {
361- let found = statuses(http, token, sha).await;
362- if contexts.iter().all(|c| found.contains_key(*c)) {
363- return found;
364- }
365- assert!(
366- Instant::now() < deadline,
367- "statuses never showed {contexts:?}; got {found:?}"
368- );
369- tokio::time::sleep(Duration::from_millis(100)).await;
370- }
371-}
372-
373-/// The job id at the end of a status `target_url` (`.../ci/jobs/<id>`).
374-fn job_id_of(status: &Status) -> String {
375- status
376- .target_url
377- .rsplit('/')
378- .next()
379- .filter(|id| !id.is_empty())
380- .unwrap_or_else(|| panic!("no job id in {:?}", status.target_url))
381- .to_owned()
382-}
383-
384-/// Pushes `.forge/ci.toml` (with `contents`) to `main` as tahinli. Returns the pushed commit.
385-fn push_ci_config(work: &Path, contents: &str) -> String {
386- let sha = commit(
387- work,
388- ".forge/ci.toml",
389- contents,
390- "add ci",
391- "tahinli",
392- "tahinli@example.test",
393- );
394- git(work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
395- sha
396-}
397-
398-/// The queue's workflow. Only the queue runs it (`merge_queue = true`), never the push to main.
399-/// The job fails when a candidate holds both files, which is what a semantic conflict looks like.
400281 const CI_TOML_QUEUE: &str = r#"[on]
401282 merge_queue = true
402283
@@ -405,7 +286,6 @@ image = "docker.io/library/alpine:3"
405286 run = "if [ -f a.txt ] && [ -f b.txt ]; then echo both files present; exit 1; fi"
406287 "#;
407288
408-/// Turns the merge queue on for `main` through the branch rule form.
409289 async fn require_merge_queue(http: &Http, session: &str) {
410290 let csrf = csrf_from(http, &format!("{REPO_PATH}/settings"), session).await;
411291 let res = http
@@ -428,8 +308,6 @@ async fn require_merge_queue(http: &Http, session: &str) {
428308 );
429309 }
430310
431-/// Pushes one new file on a branch cut from `origin/main`, opens a pull request for it and
432-/// returns the pull request number.
433311 async fn open_pull(http: &Http, session: &str, work: &Path, branch: &str, file: &str) -> i64 {
434312 git(work, &["fetch", "-q", "origin"]);
435313 let start = "origin/main";
@@ -469,7 +347,6 @@ async fn open_pull(http: &Http, session: &str, work: &Path, branch: &str, file:
469347 .expect("pull number in location")
470348 }
471349
472-/// Queues a pull request with the merge style `merge`.
473350 async fn enqueue(http: &Http, session: &str, number: i64) {
474351 let csrf = csrf_from(http, &format!("{REPO_PATH}/pulls/{number}"), session).await;
475352 let res = http
@@ -482,7 +359,6 @@ async fn enqueue(http: &Http, session: &str, number: i64) {
482359 assert_eq!(res.status, 303, "enqueue #{number}: {}", res.body);
483360 }
484361
485-/// The body of a pull request page, lowercased for loose text checks.
486362 async fn pull_page(http: &Http, session: &str, number: i64) -> String {
487363 let res = http
488364 .get(&format!("{REPO_PATH}/pulls/{number}"), Some(session))
@@ -491,8 +367,6 @@ async fn pull_page(http: &Http, session: &str, number: i64) -> String {
491367 res.body
492368 }
493369
494-/// Pushes the queue workflow to `main` and runs its push-less base state to completion, so the
495-/// only runs from here on are queue candidates.
496370 async fn setup_queue_repo(b: &Booted, tahinli: &str, token: &str) -> (Worker, PathBuf) {
497371 create_repo(&b.http, tahinli, "r").await;
498372 require_merge_queue(&b.http, tahinli).await;
@@ -537,8 +411,6 @@ async fn merge_queue_lands_the_first_pull_and_kicks_out_the_conflicting_second()
537411 server_log(&b)
538412 );
539413
540- // The first candidate passes and lands. The second candidate is then built on the new tip,
541- // holds both files, and fails.
542414 let ran = worker.drain().await;
543415 assert_eq!(ran, 2, "one candidate run each: {}", server_log(&b));
544416
@@ -551,7 +423,6 @@ async fn merge_queue_lands_the_first_pull_and_kicks_out_the_conflicting_second()
551423 "second pull did not land: {files}"
552424 );
553425
554- // The target only points at a tested commit: the candidate carries its passing run.
555426 let found = statuses(&b.http, &token, &main_tip).await;
556427 assert_eq!(
557428 found["ci/test"].state, "success",
@@ -602,7 +473,6 @@ async fn pushing_to_a_queued_pull_removes_it_from_the_queue() {
602473 let queued = pull_page(&b.http, &tahinli, number).await;
603474 assert!(queued.contains("Position 1 in the merge queue"), "queued");
604475
605- // A new commit on the pull request head: the entry no longer tests what it was queued for.
606476 commit(
607477 &work,
608478 "c.txt",
crates/forge-e2e/tests/e2e/mirrors_e2e.rsmodified+2 -17
@@ -10,7 +10,8 @@
1010 //! - the mirror pages and the server log never contain the access token.
1111
1212 use crate::common::{
13- Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path, write_config_with,
13+ Http, Server, input_value, launch_with, login, pick_ports, run_admin, tool_on_path,
14+ write_config_with,
1415 };
1516 use std::collections::BTreeSet;
1617 use std::fs;
@@ -36,22 +37,6 @@ fn form_actions(body: &str, suffix: &str) -> Vec<String> {
3637 .collect()
3738 }
3839
39-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
40- let out = Command::new(bin())
41- .arg("--config")
42- .arg(config)
43- .args(["admin", "create-user", username])
44- .args(extra)
45- .env("FORGE_PASSWORD", password)
46- .output()
47- .expect("run admin create-user");
48- assert!(
49- out.status.success(),
50- "create-user {username} failed:\n{}",
51- String::from_utf8_lossy(&out.stderr)
52- );
53-}
54-
5540 /// Fixed identity and config isolation for every git this file spawns, so the result does not
5641 /// depend on the machine's global git config (a clean CI container has none).
5742 const GIT_HERMETIC_ENV: &[(&str, &str)] = &[
crates/forge-e2e/tests/e2e/oci_e2e.rsmodified+37 -78
@@ -186,10 +186,25 @@ async fn user(store: &Store, name: &str) -> User {
186186 .expect("user exists")
187187 }
188188
189+async fn start_with_packages_token() -> (Env, String) {
190+ let token = generate_token();
191+ let seeded = token.clone();
192+ let env = start(move |store| async move {
193+ let tahinli = user(&store, "tahinli").await;
194+ grant(&store, &tahinli, &["packages"], &seeded).await;
195+ })
196+ .await;
197+ (env, token)
198+}
199+
189200 fn sha256_digest(bytes: &[u8]) -> String {
190201 format!("sha256:{}", hex::encode(Sha256::digest(bytes)))
191202 }
192203
204+fn blob_path(bytes: &[u8]) -> String {
205+ format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes))
206+}
207+
193208 /// The bearer header a client gets from the token endpoint with Basic `tahinli:<token>`.
194209 async fn bearer_for(http: &Http, token: &str) -> String {
195210 let res = http
@@ -298,13 +313,7 @@ async fn put_manifest(http: &Http, repo: &str, reference: &str, auth: &str, body
298313
299314 #[tokio::test]
300315 async fn probe_challenges_and_the_token_endpoint_issues_a_bearer_token() {
301- let token = generate_token();
302- let seeded = token.clone();
303- let env = start(move |store| async move {
304- let tahinli = user(&store, "tahinli").await;
305- grant(&store, &tahinli, &["packages"], &seeded).await;
306- })
307- .await;
316+ let (env, token) = start_with_packages_token().await;
308317 let port = env.port;
309318
310319 let probe = env.http.get("/v2/", None).await;
@@ -334,13 +343,7 @@ async fn probe_challenges_and_the_token_endpoint_issues_a_bearer_token() {
334343
335344 #[tokio::test]
336345 async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
337- let token = generate_token();
338- let seeded = token.clone();
339- let env = start(move |store| async move {
340- let tahinli = user(&store, "tahinli").await;
341- grant(&store, &tahinli, &["packages"], &seeded).await;
342- })
343- .await;
346+ let (env, token) = start_with_packages_token().await;
344347 let http = &env.http;
345348 let auth = bearer_for(http, &token).await;
346349
@@ -364,13 +367,13 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
364367 assert_eq!(res.status, 201, "{}", res.text());
365368 assert_eq!(
366369 res.header("location"),
367- Some(format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)).as_str())
370+ Some(blob_path(&layer_two).as_str())
368371 );
369372
370373 let head = http
371374 .send(
372375 reqwest::Method::HEAD,
373- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)),
376+ &blob_path(&layer_two),
374377 Some(&auth),
375378 &[],
376379 None,
@@ -380,7 +383,7 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
380383 assert_eq!(head.header("content-length"), Some("3000"));
381384 let blob = http
382385 .get(
383- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)),
386+ &blob_path(&layer_two),
384387 Some(&auth),
385388 )
386389 .await;
@@ -421,13 +424,7 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
421424
422425 #[tokio::test]
423426 async fn the_tag_list_pages_with_n_and_last() {
424- let token = generate_token();
425- let seeded = token.clone();
426- let env = start(move |store| async move {
427- let tahinli = user(&store, "tahinli").await;
428- grant(&store, &tahinli, &["packages"], &seeded).await;
429- })
430- .await;
427+ let (env, token) = start_with_packages_token().await;
431428 let http = &env.http;
432429 let auth = bearer_for(http, &token).await;
433430 let config = b"{}".to_vec();
@@ -467,13 +464,7 @@ async fn the_tag_list_pages_with_n_and_last() {
467464
468465 #[tokio::test]
469466 async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
470- let token = generate_token();
471- let seeded = token.clone();
472- let env = start(move |store| async move {
473- let tahinli = user(&store, "tahinli").await;
474- grant(&store, &tahinli, &["packages"], &seeded).await;
475- })
476- .await;
467+ let (env, token) = start_with_packages_token().await;
477468 let http = &env.http;
478469 let auth = bearer_for(http, &token).await;
479470 let config = b"{}".to_vec();
@@ -516,7 +507,7 @@ async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
516507
517508 let res = http
518509 .get(
519- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(b"absent")),
510+ &blob_path(b"absent"),
520511 Some(&auth),
521512 )
522513 .await;
@@ -526,13 +517,7 @@ async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
526517
527518 #[tokio::test]
528519 async fn an_aborted_chunked_upload_is_gone_after_a_bad_digest() {
529- let token = generate_token();
530- let seeded = token.clone();
531- let env = start(move |store| async move {
532- let tahinli = user(&store, "tahinli").await;
533- grant(&store, &tahinli, &["packages"], &seeded).await;
534- })
535- .await;
520+ let (env, token) = start_with_packages_token().await;
536521 let http = &env.http;
537522 let auth = bearer_for(http, &token).await;
538523
@@ -621,7 +606,7 @@ async fn a_public_image_pulls_anonymously_and_a_private_one_does_not() {
621606 assert_eq!(anon.body, image);
622607 let anon_blob = http
623608 .get(
624- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&config)),
609+ &blob_path(&config),
625610 None,
626611 )
627612 .await;
@@ -710,13 +695,7 @@ async fn bearer_for_as(http: &Http, who: &str, token: &str) -> String {
710695
711696 #[tokio::test]
712697 async fn mount_copies_a_blob_across_repositories() {
713- let token = generate_token();
714- let seeded = token.clone();
715- let env = start(move |store| async move {
716- let tahinli = user(&store, "tahinli").await;
717- grant(&store, &tahinli, &["packages"], &seeded).await;
718- })
719- .await;
698+ let (env, token) = start_with_packages_token().await;
720699 let http = &env.http;
721700 let auth = bearer_for(http, &token).await;
722701 let layer = b"shared layer bytes".to_vec();
@@ -757,13 +736,7 @@ async fn mount_copies_a_blob_across_repositories() {
757736
758737 #[tokio::test]
759738 async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
760- let token = generate_token();
761- let seeded = token.clone();
762- let env = start(move |store| async move {
763- let tahinli = user(&store, "tahinli").await;
764- grant(&store, &tahinli, &["packages"], &seeded).await;
765- })
766- .await;
739+ let (env, token) = start_with_packages_token().await;
767740 let http = &env.http;
768741 let auth = bearer_for(http, &token).await;
769742 let config = b"{\"shared\":true}".to_vec();
@@ -790,7 +763,6 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
790763 201
791764 );
792765
793- let blob_url = |bytes: &[u8]| format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes));
794766 let res = http
795767 .send(
796768 reqwest::Method::DELETE,
@@ -809,9 +781,9 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
809781 );
810782 // The blobs were pushed just now: the sweep keeps a link newer than the grace period, since a
811783 // push can still be on its way to a manifest. The store test covers the sweep after it.
812- assert_eq!(http.get(&blob_url(&layer_b), Some(&auth)).await.status, 200);
813- assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);
814- assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);
784+ assert_eq!(http.get(&blob_path(&layer_b), Some(&auth)).await.status, 200);
785+ assert_eq!(http.get(&blob_path(&layer_a), Some(&auth)).await.status, 200);
786+ assert_eq!(http.get(&blob_path(&config), Some(&auth)).await.status, 200);
815787
816788 let v1_digest = sha256_digest(&v1);
817789 let res = http
@@ -824,21 +796,15 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
824796 )
825797 .await;
826798 assert_eq!(res.status, 202);
827- assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);
828- assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);
799+ assert_eq!(http.get(&blob_path(&layer_a), Some(&auth)).await.status, 200);
800+ assert_eq!(http.get(&blob_path(&config), Some(&auth)).await.status, 200);
829801 let tags = http.get("/v2/tahinli/app/tags/list", Some(&auth)).await;
830802 assert_eq!(tags.json()["tags"], serde_json::json!([]));
831803 }
832804
833805 #[tokio::test]
834806 async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
835- let token = generate_token();
836- let seeded = token.clone();
837- let env = start(move |store| async move {
838- let tahinli = user(&store, "tahinli").await;
839- grant(&store, &tahinli, &["packages"], &seeded).await;
840- })
841- .await;
807+ let (env, token) = start_with_packages_token().await;
842808 let http = &env.http;
843809 let auth = bearer_for(http, &token).await;
844810 let config = b"{}".to_vec();
@@ -869,11 +835,10 @@ async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
869835 201
870836 );
871837
872- let delete = |bytes: &[u8]| format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes));
873838 let refused = http
874839 .send(
875840 reqwest::Method::DELETE,
876- &delete(&layer),
841+ &blob_path(&layer),
877842 Some(&auth),
878843 &[],
879844 None,
@@ -885,14 +850,14 @@ async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
885850 let gone = http
886851 .send(
887852 reqwest::Method::DELETE,
888- &delete(&spare),
853+ &blob_path(&spare),
889854 Some(&auth),
890855 &[],
891856 None,
892857 )
893858 .await;
894859 assert_eq!(gone.status, 202);
895- assert_eq!(http.get(&delete(&spare), Some(&auth)).await.status, 404);
860+ assert_eq!(http.get(&blob_path(&spare), Some(&auth)).await.status, 404);
896861 }
897862
898863 #[tokio::test]
@@ -902,13 +867,7 @@ async fn podman_logs_in_pushes_and_pulls_an_image() {
902867 eprintln!("podman is not installed; skipping");
903868 return;
904869 }
905- let token = generate_token();
906- let seeded = token.clone();
907- let env = start(move |store| async move {
908- let tahinli = user(&store, "tahinli").await;
909- grant(&store, &tahinli, &["packages"], &seeded).await;
910- })
911- .await;
870+ let (env, token) = start_with_packages_token().await;
912871 let host = format!("127.0.0.1:{}", env.port);
913872 let work = tempfile::tempdir().expect("work dir");
914873 let dir = work.path();
crates/forge-e2e/tests/e2e/orgs_core_e2e.rsmodified+6 -21
@@ -7,7 +7,7 @@ use crate::common::{
77 Http, Resp, Server, bin, cookie_named, describe, input_value, launch, pick_ports, write_config,
88 };
99 use std::future::Future;
10-use std::path::{Path, PathBuf};
10+use std::path::Path;
1111 use std::process::Command;
1212 use std::time::Duration;
1313
@@ -69,7 +69,7 @@ struct Env {
6969 /// the store before the server starts.
7070 async fn start<F, Fut>(seed: F) -> Env
7171 where
72- F: FnOnce(PathBuf, Store) -> Fut,
72+ F: FnOnce(Store) -> Fut,
7373 Fut: Future<Output = ()>,
7474 {
7575 let root = tempfile::tempdir().expect("temp dir");
@@ -82,7 +82,7 @@ where
8282 let store = Store::open(&dir.join("forge.db"))
8383 .await
8484 .expect("open store");
85- seed(dir.clone(), store).await;
85+ seed(store).await;
8686 let (server, ports) = launch(&dir, ports).await;
8787 Env {
8888 _root: root,
@@ -93,7 +93,7 @@ where
9393
9494 /// `acme` is an org owned by tahinli, with a public repo, a session row, and an API token. None of
9595 /// them may authenticate.
96-async fn seed_org(_dir: PathBuf, store: Store) {
96+async fn seed_org(store: Store) {
9797 let tahinli = store
9898 .user_by_username("tahinli")
9999 .await
@@ -129,20 +129,15 @@ async fn seed_org(_dir: PathBuf, store: Store) {
129129 }
130130
131131 #[tokio::test]
132-async fn an_org_cannot_sign_in_with_a_password() {
132+async fn org_credentials_never_authenticate() {
133133 let _guard = SERIAL.lock().await;
134134 let env = start(seed_org).await;
135+
135136 let res = try_login(&env.http, "acme").await;
136137 assert_ne!(res.status, 303, "org login must not redirect: {}", res.body);
137138 assert!(cookie_named(&res, "forge_session").is_none());
138-}
139139
140-#[tokio::test]
141-async fn an_org_session_signs_nobody_in() {
142- let _guard = SERIAL.lock().await;
143- let env = start(seed_org).await;
144140 let cookie = format!("__Host-forge_session={ORG_SESSION}");
145- // A page that needs a person answers the same with the org session as with no cookie.
146141 let with_org = env.http.get("/new", Some(&cookie)).await;
147142 let without = env.http.get("/new", None).await;
148143 assert_eq!(with_org.status, without.status);
@@ -152,12 +147,7 @@ async fn an_org_session_signs_nobody_in() {
152147 "a person is required: {}",
153148 with_org.body
154149 );
155-}
156150
157-#[tokio::test]
158-async fn an_org_api_token_is_refused() {
159- let _guard = SERIAL.lock().await;
160- let env = start(seed_org).await;
161151 let res = env
162152 .http
163153 .client
@@ -171,12 +161,7 @@ async fn an_org_api_token_is_refused() {
171161 .await
172162 .expect("api request");
173163 assert_eq!(res.status().as_u16(), 401, "org API token must be refused");
174-}
175164
176-#[tokio::test]
177-async fn an_org_token_cannot_use_git_over_http_basic() {
178- let _guard = SERIAL.lock().await;
179- let env = start(seed_org).await;
180165 let res = env
181166 .http
182167 .client
crates/forge-e2e/tests/e2e/orgs_ui_e2e.rsmodified+6 -14
@@ -4,8 +4,8 @@
44 //! handled by hand, as in `repo_collaborators_e2e.rs`.
55
66 use crate::common::{
7- Http, Resp, bin, describe, input_value, launch, launch_with, login, pick_ports, tool_on_path,
8- write_config,
7+ Http, Resp, bin, describe, input_value, launch, launch_with, login, pick_ports, temp_dir,
8+ tool_on_path, write_config,
99 };
1010 use std::fs;
1111 use std::path::Path;
@@ -84,14 +84,6 @@ fn notice_location(redirect: &Resp) -> String {
8484 redirect.header(LOCATION).expect("notice redirect")
8585 }
8686
87-/// A temp dir short enough for the unix socket path limit.
88-fn short_temp_dir() -> tempfile::TempDir {
89- tempfile::Builder::new()
90- .prefix("forg")
91- .tempdir_in("/tmp")
92- .expect("temp dir")
93-}
94-
9587 #[tokio::test]
9688 async fn org_members_teams_and_access_end_to_end() {
9789 let _guard = SERIAL.lock().await;
@@ -99,7 +91,7 @@ async fn org_members_teams_and_access_end_to_end() {
9991 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
10092 return;
10193 }
102- let root = short_temp_dir();
94+ let root = temp_dir("forg");
10395 let dir = root.path().to_path_buf();
10496 let ports = pick_ports();
10597 let config = write_config(&dir, ports);
@@ -329,7 +321,7 @@ async fn org_settings_delete_and_audit_end_to_end() {
329321 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
330322 return;
331323 }
332- let root = short_temp_dir();
324+ let root = temp_dir("forg");
333325 let dir = root.path().to_path_buf();
334326 let ports = pick_ports();
335327 let config = write_config(&dir, ports);
@@ -484,7 +476,7 @@ async fn org_settings_delete_and_audit_end_to_end() {
484476 #[tokio::test]
485477 async fn org_creation_can_be_limited_to_admins() {
486478 let _guard = SERIAL.lock().await;
487- let root = short_temp_dir();
479+ let root = temp_dir("forg");
488480 let dir = root.path().to_path_buf();
489481 let ports = pick_ports();
490482 let config = write_config(&dir, ports);
@@ -630,7 +622,7 @@ async fn org_member_pushes_over_https_through_a_write_team() {
630622 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
631623 return;
632624 }
633- let root = short_temp_dir();
625+ let root = temp_dir("forg");
634626 let dir = root.path().to_path_buf();
635627 let ports = pick_ports();
636628 let config = write_config(&dir, ports);
crates/forge-e2e/tests/e2e/pulls_e2e.rsmodified+17 -69
@@ -6,7 +6,8 @@
66 //! a fork pull merged by squash, and a conflict that blocks the merge.
77
88 use crate::common::{
9- Http, Resp, Server, bin, input_value, launch, login, pick_ports, tool_on_path, write_config,
9+ Http, Resp, Server, create_token, input_value, launch, login, pick_ports, run_admin,
10+ tool_on_path, write_config,
1011 };
1112 use std::fs;
1213 use std::path::{Path, PathBuf};
@@ -19,6 +20,8 @@ const TAHINLI_PW: &str = "tahinli-password-123";
1920 const BOB_PW: &str = "bob-password-4567";
2021 const BOB_EMAIL: &str = "bob@users.noreply.127.0.0.1";
2122 const REPO_PATH: &str = "/tahinli/r";
23+const TAHINLI: (&str, &str) = ("tahinli", "tahinli@example.test");
24+const BOB: (&str, &str) = ("bob", BOB_EMAIL);
2225
2326 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.
2427 fn state_badge(body: &str) -> String {
@@ -31,22 +34,6 @@ fn state_badge(body: &str) -> String {
3134 .unwrap_or_default()
3235 }
3336
34-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
35- let out = Command::new(bin())
36- .arg("--config")
37- .arg(config)
38- .args(["admin", "create-user", username])
39- .args(extra)
40- .env("FORGE_PASSWORD", password)
41- .output()
42- .expect("run admin create-user");
43- assert!(
44- out.status.success(),
45- "create-user {username} failed:\n{}",
46- String::from_utf8_lossy(&out.stderr)
47- );
48-}
49-
5037 /// Runs git with credential helpers disabled and extra env, returning stdout trimmed. Panics on
5138 /// failure.
5239 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
@@ -72,23 +59,17 @@ fn git(cwd: &Path, args: &[&str]) -> String {
7259 }
7360
7461 /// Writes `file`, commits it with `who` as author and committer, and returns the new HEAD.
75-fn commit(
76- repo: &Path,
77- file: &str,
78- contents: &str,
79- message: &str,
80- who: &str,
81- email: &str,
82-) -> String {
62+fn commit(repo: &Path, file: &str, contents: &str, message: &str, who: (&str, &str)) -> String {
63+ let (name, email) = who;
8364 fs::write(repo.join(file), contents).expect("write file");
8465 git(repo, &["add", file]);
8566 git_env(
8667 repo,
8768 &["-c", "commit.gpgsign=false", "commit", "-q", "-m", message],
8869 &[
89- ("GIT_AUTHOR_NAME", who),
70+ ("GIT_AUTHOR_NAME", name),
9071 ("GIT_AUTHOR_EMAIL", email),
91- ("GIT_COMMITTER_NAME", who),
72+ ("GIT_COMMITTER_NAME", name),
9273 ("GIT_COMMITTER_EMAIL", email),
9374 ],
9475 );
@@ -132,30 +113,6 @@ async fn csrf_token(http: &Http, session: &str) -> String {
132113 input_value(&page.body, "csrf")
133114 }
134115
135-/// Creates an access token through `/settings/tokens` and returns the token shown once.
136-async fn create_token(http: &Http, session: &str, name: &str) -> String {
137- let csrf = csrf_token(http, session).await;
138- let res = http
139- .post_form(
140- "/settings/tokens",
141- &[("csrf", &csrf), ("name", name), ("expires", "30")],
142- Some(session),
143- )
144- .await;
145- assert_eq!(res.status, 200, "create token: {}", res.body);
146- let doc = scraper::Html::parse_document(&res.body);
147- let selector = scraper::Selector::parse("pre.code code").expect("selector");
148- let token: String = doc
149- .select(&selector)
150- .next()
151- .expect("token shown after creation")
152- .text()
153- .collect();
154- let token = token.trim().to_owned();
155- assert!(token.starts_with("forge_"), "unexpected token shape");
156- token
157-}
158-
159116 /// Creates a public repo `name` owned by tahinli through `/new`.
160117 async fn create_repo(http: &Http, session: &str, name: &str) {
161118 let page = http.get_cookie("/new", session).await;
@@ -236,8 +193,7 @@ async fn tahinli_repo_with_main(b: &Booted) -> (String, String, PathBuf) {
236193 "base.txt",
237194 "base\n",
238195 "base commit",
239- "tahinli",
240- "tahinli@example.test",
196+ TAHINLI,
241197 );
242198 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
243199 (tahinli, token, work)
@@ -343,8 +299,7 @@ async fn same_repo_pull_merges_and_closes_issue() {
343299 "x.txt",
344300 "x\n",
345301 "Add x\n\nFixes #1",
346- "tahinli",
347- "tahinli@example.test",
302+ TAHINLI,
348303 );
349304 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature"]);
350305
@@ -410,8 +365,7 @@ async fn push_to_head_branch_updates_open_pull() {
410365 "one.txt",
411366 "1\n",
412367 "first on feature2",
413- "tahinli",
414- "tahinli@example.test",
368+ TAHINLI,
415369 );
416370 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);
417371 let number = open_pull(&b.http, &tahinli, "main", "feature2", "Feature two").await;
@@ -421,8 +375,7 @@ async fn push_to_head_branch_updates_open_pull() {
421375 "two.txt",
422376 "2\n",
423377 "second on feature2",
424- "tahinli",
425- "tahinli@example.test",
378+ TAHINLI,
426379 );
427380 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);
428381
@@ -496,8 +449,7 @@ async fn pull_pages_follow_writes_live() {
496449 "live.txt",
497450 "live\n",
498451 "first on live",
499- "tahinli",
500- "tahinli@example.test",
452+ TAHINLI,
501453 );
502454 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);
503455 let number = open_pull(&b.http, &tahinli, "main", "live", "Live pull").await;
@@ -567,8 +519,7 @@ async fn pull_pages_follow_writes_live() {
567519 "second.txt",
568520 "2\n",
569521 "second on live",
570- "tahinli",
571- "tahinli@example.test",
522+ TAHINLI,
572523 );
573524 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);
574525 next_changed(&mut pull_events, "a push to the head").await;
@@ -647,8 +598,7 @@ async fn fork_pull_squash_merge_credits_contributor() {
647598 "bob.txt",
648599 "bob\n",
649600 "Bob change",
650- "bob",
651- BOB_EMAIL,
601+ BOB,
652602 );
653603 git(
654604 &bob_work,
@@ -688,8 +638,7 @@ async fn conflicting_pull_cannot_merge() {
688638 "shared.txt",
689639 "branch side\n",
690640 "branch edit",
691- "tahinli",
692- "tahinli@example.test",
641+ TAHINLI,
693642 );
694643 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/conflict"]);
695644 let number = open_pull(&b.http, &tahinli, "main", "conflict", "Conflicting").await;
@@ -700,8 +649,7 @@ async fn conflicting_pull_cannot_merge() {
700649 "shared.txt",
701650 "main side\n",
702651 "main edit",
703- "tahinli",
704- "tahinli@example.test",
652+ TAHINLI,
705653 );
706654 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
707655
crates/forge-e2e/tests/e2e/repo_collaborators_e2e.rsmodified+7 -9
@@ -3,7 +3,7 @@
33 //! its POST forms over HTTP. Cookies are handled by hand (see `repo_settings_e2e.rs`).
44
55 use crate::common::{
6- Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,
6+ Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, with_cookie,
77 write_config,
88 };
99 use std::fs;
@@ -69,12 +69,6 @@ async fn shown_role(http: &Http, session: &str, username: &str) -> Option<String
6969 .map(str::to_owned)
7070 }
7171
72-/// The one-shot notice cookie from a redirect, joined with the session cookie for the next GET.
73-fn with_notice(session: &str, redirect: &Resp) -> String {
74- let notice = cookie_named(redirect, "forge_collab_notice").expect("notice cookie");
75- format!("{session}; {notice}")
76-}
77-
7872 #[tokio::test]
7973 async fn repo_collaborators_end_to_end() {
8074 if !tool_on_path("git") {
@@ -249,7 +243,9 @@ async fn repo_collaborators_end_to_end() {
249243 )
250244 .await;
251245 assert_eq!(res.status, 303, "unknown user redirects with a notice");
252- let notice_page = http.get(page, Some(&with_notice(&olivia, &res))).await;
246+ let notice_page = http
247+ .get(page, Some(&with_cookie(&olivia, &res, "forge_collab_notice")))
248+ .await;
253249 assert!(
254250 notice_page.body.contains("No user has that username."),
255251 "unknown user notice missing"
@@ -261,7 +257,9 @@ async fn repo_collaborators_end_to_end() {
261257 Some(&olivia),
262258 )
263259 .await;
264- let notice_page = http.get(page, Some(&with_notice(&olivia, &res))).await;
260+ let notice_page = http
261+ .get(page, Some(&with_cookie(&olivia, &res, "forge_collab_notice")))
262+ .await;
265263 assert!(
266264 notice_page
267265 .body
crates/forge-e2e/tests/e2e/repo_settings_e2e.rsmodified+4 -69
@@ -1,12 +1,6 @@
1-//! Black-box test for repo deletion. It starts the real `forge` binary, seeds repos through the
2-//! store before the server starts, and then drives the settings page and the delete form over HTTP.
3-//!
4-//! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`,
5-//! which a cookie jar would not send over plain http.
6-
71 use crate::common::{
8- Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,
9- write_config,
2+ Http, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,
3+ with_cookie, write_config,
104 };
115 use std::fs;
126 use std::path::{Path, PathBuf};
@@ -17,7 +11,6 @@ use reqwest::header::LOCATION;
1711
1812 const PW: &str = "tahinli-password-123";
1913
20-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
2114 fn admin(config: &Path, args: &[&str]) -> Output {
2215 let out = Command::new(bin())
2316 .arg("--config")
@@ -35,14 +28,12 @@ fn admin(config: &Path, args: &[&str]) -> Output {
3528 out
3629 }
3730
38-/// The session's CSRF token, read from a page every signed-in user can open.
3931 async fn csrf_for(http: &Http, session: &str) -> String {
4032 let page = http.get("/settings/keys", Some(session)).await;
4133 assert_eq!(page.status, 200, "GET /settings/keys");
4234 input_value(&page.body, "csrf")
4335 }
4436
45-/// Creates a bare git repo for `repo_id` at its data-dir location, as the create-repo page does.
4637 fn init_bare(data_dir: &Path, repo_id: &str) {
4738 let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
4839 fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
@@ -54,7 +45,6 @@ fn init_bare(data_dir: &Path, repo_id: &str) {
5445 assert!(out.status.success(), "git init --bare: {}", describe(&out));
5546 }
5647
57-/// Directories in `data_dir/trash` for the repo `id` (lowercase, as the trash names them).
5848 fn trash_entries(data_dir: &Path, repo_id: &str) -> Vec<PathBuf> {
5949 let prefix = format!("{}-", repo_id.to_ascii_lowercase());
6050 let Ok(read) = fs::read_dir(data_dir.join(forge_git::repo::TRASH_DIR)) else {
@@ -77,7 +67,6 @@ async fn repo_settings_end_to_end() {
7767 return;
7868 }
7969
80- // Keep the path short: the data dir holds a unix socket with a length limit.
8170 let root = tempfile::Builder::new()
8271 .prefix("frs")
8372 .tempdir_in("/tmp")
@@ -87,8 +76,6 @@ async fn repo_settings_end_to_end() {
8776 let ports = pick_ports();
8877 let config = write_config(&dir, ports);
8978
90- // The first user is an admin. Bob owns the repos, carol is an admin collaborator on the private
91- // one, and tahinli (admin) must still be able to delete bob's repo.
9279 admin(&config, &["create-user", "tahinli", "--admin"]);
9380 admin(&config, &["create-user", "bob"]);
9481 admin(&config, &["create-user", "carol"]);
@@ -127,12 +114,9 @@ async fn repo_settings_end_to_end() {
127114 let carol = login(&http, "carol", PW).await;
128115 let tahinli = login(&http, "tahinli", PW).await;
129116
130- // Anonymous on a private repo: 404, the same as a missing repo.
131117 let anon = http.get("/bob/priv/settings", None).await;
132118 assert_eq!(anon.status, 404, "anonymous settings on private repo");
133119
134- // A collaborator with the Admin role gets the settings page (branch rules) but no danger zone,
135- // and a POST to the delete form is 403. The repo stays.
136120 let carol_page = http
137121 .get("/bob/priv/settings?section=danger", Some(&carol))
138122 .await;
@@ -152,7 +136,6 @@ async fn repo_settings_end_to_end() {
152136 assert_eq!(carol_delete.status, 403, "collaborator delete");
153137 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 200);
154138
155- // The owner sees the danger zone, and the Settings tab appears on the repo header.
156139 let owner_page = http
157140 .get("/bob/pub/settings?section=danger", Some(&bob))
158141 .await;
@@ -173,7 +156,6 @@ async fn repo_settings_end_to_end() {
173156 "Settings tab shows to an Admin collaborator"
174157 );
175158
176- // A wrong confirmation is an error and keeps the repo.
177159 let owner_csrf = csrf_for(&http, &bob).await;
178160 let wrong = http
179161 .post_form(
@@ -197,7 +179,6 @@ async fn repo_settings_end_to_end() {
197179 "nothing trashed on mismatch"
198180 );
199181
200- // No CSRF token is rejected, even with the right confirmation.
201182 let no_csrf = http
202183 .post_form(
203184 "/bob/pub/settings/delete",
@@ -212,7 +193,6 @@ async fn repo_settings_end_to_end() {
212193 "repo kept without CSRF"
213194 );
214195
215- // The owner deletes: redirect home with a notice, the repo is gone, the directory is trashed.
216196 let deleted = http
217197 .post_form(
218198 "/bob/pub/settings/delete",
@@ -246,7 +226,6 @@ async fn repo_settings_end_to_end() {
246226 "trash entry is a bare repo"
247227 );
248228
249- // The home page is the signed-in viewer's own page, not a redirect.
250229 let home = http.get("/", Some(&bob)).await;
251230 assert_eq!(home.status, 200, "home page for a signed-in viewer");
252231 assert!(
@@ -254,7 +233,6 @@ async fn repo_settings_end_to_end() {
254233 "home lists their repositories"
255234 );
256235
257- // An admin who does not own the repo can delete it.
258236 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;
259237 assert_eq!(admin_page.status, 200, "admin settings page");
260238 let admin_csrf = csrf_for(&http, &tahinli).await;
@@ -277,7 +255,6 @@ async fn repo_settings_end_to_end() {
277255 "admin delete is trashed"
278256 );
279257
280- // The admin CLI lists both trash entries, then purges them.
281258 let listed = String::from_utf8_lossy(&admin(&config, &["trash-list"]).stdout).into_owned();
282259 assert!(
283260 listed.contains(&public_id.to_ascii_lowercase()),
@@ -298,8 +275,6 @@ async fn repo_settings_end_to_end() {
298275 drop(server);
299276 }
300277
301-/// A repo whose bare directory was removed by hand can still be deleted from the UI: the DB rows
302-/// go, nothing is trashed, and the request succeeds.
303278 #[tokio::test]
304279 async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
305280 if !tool_on_path("git") {
@@ -327,7 +302,6 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
327302 .expect("repo");
328303 init_bare(&dir, &repo.id);
329304 let bare = forge_git::repo::repo_path(&dir, &repo.id).expect("repo path");
330- // Simulate the broken state: the DB row exists but the bare directory is gone.
331305 fs::remove_dir_all(&bare).expect("remove bare dir by hand");
332306 (repo.id, bare)
333307 };
@@ -362,7 +336,6 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
362336 trash_entries(&dir, &repo_id).is_empty(),
363337 "nothing to trash when the dir is missing"
364338 );
365- // Stop the server first: the database file is locked while it runs.
366339 drop(server);
367340 let store = Store::open(&dir.join("forge.db"))
368341 .await
@@ -378,12 +351,8 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
378351 );
379352 }
380353
381-/// The rule rows of the branch rules list in page order, each as its pattern followed by the texts
382-/// of its summary pills. The built-in default-branch row has no rule behind it, so it is skipped.
383354 fn branch_rows(body: &str) -> Vec<Vec<String>> {
384355 let doc = scraper::Html::parse_document(body);
385- // Every rule row is a `details` with the pattern in its summary's name; the "Add rule" row
386- // has no pattern there, so it drops out.
387356 let cards = scraper::Selector::parse("details.row-open").expect("selector");
388357 let pattern = scraper::Selector::parse("summary .name code").expect("selector");
389358 let pills = scraper::Selector::parse("summary .rule-pills span").expect("selector");
@@ -398,15 +367,12 @@ fn branch_rows(body: &str) -> Vec<Vec<String>> {
398367 .collect()
399368 }
400369
401-/// The row for `pattern` as its cells (see `branch_rows`), if the list has one.
402370 fn rule_row(body: &str, pattern: &str) -> Option<Vec<String>> {
403371 branch_rows(body)
404372 .into_iter()
405373 .find(|cells| cells.first().is_some_and(|c| c == pattern))
406374 }
407375
408-/// Owner adds, updates, invalidates and removes branch rules. A Write collaborator and an Admin
409-/// collaborator get the right access: the Admin can manage rules but sees no danger zone.
410376 #[tokio::test]
411377 async fn branch_protection_end_to_end() {
412378 if !tool_on_path("git") {
@@ -422,7 +388,6 @@ async fn branch_protection_end_to_end() {
422388 let ports = pick_ports();
423389 let config = write_config(&dir, ports);
424390
425- // The first user is an instance admin, so bob (the owner) is an ordinary user.
426391 admin(&config, &["create-user", "tahinli", "--admin"]);
427392 admin(&config, &["create-user", "bob"]);
428393 admin(&config, &["create-user", "carol"]);
@@ -460,7 +425,6 @@ async fn branch_protection_end_to_end() {
460425 let carol = login(&http, "carol", PW).await;
461426 let dan = login(&http, "dan", PW).await;
462427
463- // Owner: the built-in row is there before any rule, and the danger zone is shown.
464428 let page = http
465429 .get("/bob/app/settings?section=branches", Some(&bob))
466430 .await;
@@ -484,7 +448,6 @@ async fn branch_protection_end_to_end() {
484448 );
485449 let owner_csrf = csrf_for(&http, &bob).await;
486450
487- // Adding main with force push allowed: it appears, and the built-in row disappears.
488451 let added = http
489452 .post_form(
490453 "/bob/app/settings/branches",
@@ -522,7 +485,6 @@ async fn branch_protection_end_to_end() {
522485 "built-in row must disappear once a rule matches"
523486 );
524487
525- // Updating the same pattern toggles the value and does not add a second row.
526488 let updated = http
527489 .post_form(
528490 "/bob/app/settings/branches",
@@ -536,7 +498,6 @@ async fn branch_protection_end_to_end() {
536498 .await;
537499 assert_eq!(updated.status, 303, "update rule: {}", updated.body);
538500
539- // Adding a new rule for a pattern that has one is refused instead of overwriting it.
540501 let duplicate = http
541502 .post_form(
542503 "/bob/app/settings/branches",
@@ -563,7 +524,6 @@ async fn branch_protection_end_to_end() {
563524 "update must not add a row"
564525 );
565526
566- // An invalid pattern is refused inline and nothing is saved.
567527 let invalid = http
568528 .post_form(
569529 "/bob/app/settings/branches",
@@ -592,7 +552,6 @@ async fn branch_protection_end_to_end() {
592552 "invalid rule must not be saved"
593553 );
594554
595- // No CSRF token is rejected.
596555 let no_csrf = http
597556 .post_form(
598557 "/bob/app/settings/branches",
@@ -621,7 +580,6 @@ async fn branch_protection_end_to_end() {
621580 "main kept without CSRF"
622581 );
623582
624- // Remove works: the row goes and the built-in row comes back.
625583 let rule_id = input_value(&page.body, "rule_id");
626584 let removed = http
627585 .post_form(
@@ -640,7 +598,6 @@ async fn branch_protection_end_to_end() {
640598 "built-in row back after remove"
641599 );
642600
643- // A Write collaborator cannot open the settings or post rules.
644601 let dan_page = http
645602 .get("/bob/app/settings?section=branches", Some(&dan))
646603 .await;
@@ -662,7 +619,6 @@ async fn branch_protection_end_to_end() {
662619 "write collaborator must not change rules"
663620 );
664621
665- // An Admin collaborator manages rules, sees no danger zone and cannot delete the repo.
666622 let carol_page = http
667623 .get("/bob/app/settings?section=branches", Some(&carol))
668624 .await;
@@ -744,7 +700,6 @@ async fn branch_protection_end_to_end() {
744700 drop(server);
745701 }
746702
747-/// Creates commits in a scratch work tree and pushes them as `branches` into the bare repo.
748703 fn seed_branches(dir: &Path, repo_id: &str, branches: &[&str]) {
749704 let bare = forge_git::repo::repo_path(dir, repo_id).expect("repo path");
750705 let work = dir.join(format!("seed-{repo_id}"));
@@ -778,7 +733,6 @@ fn seed_branches(dir: &Path, repo_id: &str, branches: &[&str]) {
778733 run(&push);
779734 }
780735
781-/// The symbolic target of HEAD in the bare repo, e.g. `refs/heads/dev`.
782736 fn git_head(data_dir: &Path, repo_id: &str) -> String {
783737 let bare = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
784738 let out = Command::new("git")
@@ -791,7 +745,6 @@ fn git_head(data_dir: &Path, repo_id: &str) -> String {
791745 String::from_utf8_lossy(&out.stdout).trim().to_owned()
792746 }
793747
794-/// The value of the `selected` option of the default-branch select, if the page has one.
795748 fn selected_branch(body: &str) -> Option<String> {
796749 let doc = scraper::Html::parse_document(body);
797750 let selector =
@@ -802,14 +755,6 @@ fn selected_branch(body: &str) -> Option<String> {
802755 .map(str::to_owned)
803756 }
804757
805-/// Cookie header with the session plus a one-shot settings notice set by the previous response.
806-fn with_notice(session: &str, res: &Resp) -> String {
807- match cookie_named(res, "forge_settings_notice") {
808- Some(notice) => format!("{session}; {notice}"),
809- None => session.to_owned(),
810- }
811-}
812-
813758 #[tokio::test]
814759 async fn general_settings_end_to_end() {
815760 if !tool_on_path("git") {
@@ -862,7 +807,6 @@ async fn general_settings_end_to_end() {
862807 let bob = login(&http, "bob", PW).await;
863808 let carol = login(&http, "carol", PW).await;
864809
865- // The General section is the first card on the page, with the sub-navigation above it.
866810 let page = http.get("/bob/gen/settings", Some(&bob)).await;
867811 assert_eq!(page.status, 200, "owner settings page");
868812 assert!(
@@ -879,7 +823,6 @@ async fn general_settings_end_to_end() {
879823 .contains("href=\"/bob/gen/settings?section=danger\"")
880824 );
881825
882- // Description: control characters are stripped and it shows on the repo header.
883826 let csrf = csrf_for(&http, &bob).await;
884827 let saved = http
885828 .post_form(
@@ -899,7 +842,6 @@ async fn general_settings_end_to_end() {
899842 "description not on header"
900843 );
901844
902- // Default branch: an existing branch updates the DB value and git HEAD.
903845 let switched = http
904846 .post_form(
905847 "/bob/gen/settings/general",
@@ -916,7 +858,6 @@ async fn general_settings_end_to_end() {
916858 let after = http.get("/bob/gen/settings", Some(&bob)).await;
917859 assert_eq!(selected_branch(&after.body).as_deref(), Some("dev"));
918860
919- // A nonexistent branch is rejected: HEAD and the DB keep dev.
920861 let missing = http
921862 .post_form(
922863 "/bob/gen/settings/general",
@@ -930,7 +871,7 @@ async fn general_settings_end_to_end() {
930871 .await;
931872 assert_eq!(missing.status, 303);
932873 let notice_page = http
933- .get("/bob/gen/settings", Some(&with_notice(&bob, &missing)))
874+ .get("/bob/gen/settings", Some(&with_cookie(&bob, &missing, "forge_settings_notice")))
934875 .await;
935876 assert!(
936877 notice_page.body.contains("That branch does not exist"),
@@ -942,7 +883,6 @@ async fn general_settings_end_to_end() {
942883 Some("dev")
943884 );
944885
945- // Over-long description is rejected.
946886 let long = "x".repeat(351);
947887 let too_long = http
948888 .post_form(
@@ -957,11 +897,10 @@ async fn general_settings_end_to_end() {
957897 .await;
958898 assert_eq!(too_long.status, 303);
959899 let long_page = http
960- .get("/bob/gen/settings", Some(&with_notice(&bob, &too_long)))
900+ .get("/bob/gen/settings", Some(&with_cookie(&bob, &too_long, "forge_settings_notice")))
961901 .await;
962902 assert!(long_page.body.contains("at most 350 characters"));
963903
964- // Visibility: changing to private needs "I understand"; then anonymous gets 404.
965904 let vis_csrf = csrf_for(&http, &bob).await;
966905 let no_ack = http
967906 .post_form(
@@ -1016,7 +955,6 @@ async fn general_settings_end_to_end() {
1016955 "anonymous on public"
1017956 );
1018957
1019- // Archive, then unarchive. The banner shows only while archived.
1020958 let arch_csrf = csrf_for(&http, &bob).await;
1021959 let archive = http
1022960 .post_form(
@@ -1050,7 +988,6 @@ async fn general_settings_end_to_end() {
1050988 "banner after unarchive"
1051989 );
1052990
1053- // A Write collaborator cannot reach the settings: GET and every POST are 403.
1054991 let carol_page = http.get("/bob/gen/settings", Some(&carol)).await;
1055992 assert_eq!(carol_page.status, 403, "write collaborator settings page");
1056993 let carol_csrf = csrf_for(&http, &carol).await;
@@ -1080,7 +1017,6 @@ async fn general_settings_end_to_end() {
10801017 "HEAD untouched by carol"
10811018 );
10821019
1083- // No CSRF token, or a wrong one, is rejected on every General POST.
10841020 let no_csrf = http
10851021 .post_form(
10861022 "/bob/gen/settings/general",
@@ -1107,7 +1043,6 @@ async fn general_settings_end_to_end() {
11071043 "visibility unchanged"
11081044 );
11091045
1110- // An empty repo says so and keeps the current value.
11111046 let empty_page = http.get("/bob/empty/settings", Some(&bob)).await;
11121047 assert!(
11131048 empty_page.body.contains("No branches yet"),
crates/forge-e2e/tests/e2e/section_nav_e2e.rsmodified+0 -97
@@ -1,97 +1,9 @@
1-//! Black-box tests for the admin and settings section tabs: every page under `/admin` and
2-//! `/settings` shows the section's own tab row above the page, marks the current tab with
3-//! `aria-current="page"`, and has no " · "-joined link row.
4-
5-#![allow(dead_code)]
6-
71 use crate::common::{Http, Server, bin, describe, launch, login, pick_ports, write_config};
82 use std::path::Path;
93 use std::process::Command;
104
115 const PW: &str = "tahinli-password-123";
126
13-/// The `data-theme` attribute of `<html>`, if the page sets one.
14-fn html_theme(body: &str) -> Option<String> {
15- let doc = scraper::Html::parse_document(body);
16- doc.root_element().attr("data-theme").map(str::to_owned)
17-}
18-
19-/// The value of attribute `name` on `<html>`, if the page sets it.
20-fn html_attr(body: &str, name: &str) -> Option<String> {
21- let doc = scraper::Html::parse_document(body);
22- doc.root_element().attr(name).map(str::to_owned)
23-}
24-
25-/// The four colour attributes of `<html>`, in the order light accent, dark accent, light base,
26-/// dark base.
27-fn html_colours(body: &str) -> [Option<String>; 4] {
28- [
29- html_attr(body, "data-accent-light"),
30- html_attr(body, "data-accent-dark"),
31- html_attr(body, "data-base-light"),
32- html_attr(body, "data-base-dark"),
33- ]
34-}
35-
36-/// The checked radio of each colour group, in the same order as `html_colours`.
37-fn checked_colours(body: &str) -> [Option<String>; 4] {
38- [
39- checked_radio(body, "accent_light"),
40- checked_radio(body, "accent_dark"),
41- checked_radio(body, "base_light"),
42- checked_radio(body, "base_dark"),
43- ]
44-}
45-
46-/// The value of the checked radio button in the group `name` on a page.
47-fn checked_radio(body: &str, name: &str) -> Option<String> {
48- let doc = scraper::Html::parse_document(body);
49- let selector =
50- scraper::Selector::parse(&format!("input[type=\"radio\"][name=\"{name}\"][checked]"))
51- .expect("selector");
52- doc.select(&selector)
53- .next()
54- .and_then(|el| el.value().attr("value"))
55- .map(str::to_owned)
56-}
57-
58-/// The option value that is selected in the `<select name="...">` on a page.
59-fn selected_option(body: &str, select: &str) -> Option<String> {
60- let doc = scraper::Html::parse_document(body);
61- let selector = scraper::Selector::parse(&format!("select[name=\"{select}\"] option[selected]"))
62- .expect("selector");
63- doc.select(&selector)
64- .next()
65- .and_then(|el| el.value().attr("value"))
66- .map(str::to_owned)
67-}
68-
69-/// The top-bar theme button: the value it posts and its accessible label.
70-fn theme_button(body: &str) -> (String, String) {
71- let doc = scraper::Html::parse_document(body);
72- let form = scraper::Selector::parse("form.theme-form").expect("selector");
73- let form = doc
74- .select(&form)
75- .next()
76- .unwrap_or_else(|| panic!("no theme button on page"));
77- let value = scraper::Selector::parse("input[name=\"theme\"]").expect("selector");
78- let value = form
79- .select(&value)
80- .next()
81- .and_then(|el| el.value().attr("value"))
82- .expect("theme value")
83- .to_owned();
84- let button = scraper::Selector::parse("button").expect("selector");
85- let label = form
86- .select(&button)
87- .next()
88- .and_then(|el| el.value().attr("aria-label"))
89- .expect("aria-label")
90- .to_owned();
91- (value, label)
92-}
93-
94-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
957 fn admin(config: &Path, args: &[&str]) {
968 let out = Command::new(bin())
979 .arg("--config")
@@ -108,7 +20,6 @@ fn admin(config: &Path, args: &[&str]) {
10820 );
10921 }
11022
111-/// A running server with user `tahinli`. The temp dir lives as long as the test.
11223 struct Env {
11324 _root: tempfile::TempDir,
11425 _server: Server,
@@ -130,8 +41,6 @@ async fn start() -> Env {
13041 }
13142 }
13243
133-/// The section's tab row as (href, aria-current) pairs. The row is the first `nav.tabs` in `main`,
134-/// which the shell puts before the page's own content, so a page's own tabs are not read here.
13544 fn tab_links(body: &str) -> Vec<(String, Option<String>)> {
13645 let doc = scraper::Html::parse_document(body);
13746 let row = scraper::Selector::parse("main nav.tabs").expect("selector");
@@ -147,8 +56,6 @@ fn tab_links(body: &str) -> Vec<(String, Option<String>)> {
14756 .collect()
14857 }
14958
150-/// Checks the section's tab row: its first tab is the section's first, every tab in `hrefs` is
151-/// there, and exactly one tab, the one at `current`, is marked.
15259 fn assert_tabs(body: &str, current: &str, hrefs: &[&str]) {
15360 let links = tab_links(body);
15461 assert_eq!(links[0].0, hrefs[0], "first tab is the section's first");
@@ -176,7 +83,6 @@ async fn admin_pages_get_the_admin_tabs() {
17683 "/admin/backups",
17784 "/admin/audit",
17885 ];
179- // Invites live under Users and replication under Backups: their own tab is the one marked.
18086 for (path, current) in [
18187 ("/admin/users", "/admin/users"),
18288 ("/admin/invites", "/admin/users"),
@@ -209,8 +115,6 @@ async fn settings_pages_get_the_settings_tabs() {
209115 "/settings/keys",
210116 "/settings/export",
211117 ];
212- // A page folded into another tab marks that tab: GPG keys and
213- // tokens under keys.
214118 let pages = [
215119 ("/settings/profile", "/settings/profile"),
216120 ("/settings/keys", "/settings/keys"),
@@ -223,7 +127,6 @@ async fn settings_pages_get_the_settings_tabs() {
223127 assert_eq!(page.status, 200, "GET {path}");
224128 assert_tabs(&page.body, current, &tabs);
225129 }
226- // GPG keys and tokens are kinds of the Keys tab, each at its own address.
227130 for path in ["/settings/gpg", "/settings/tokens"] {
228131 let page = env.http.get(path, Some(&session)).await;
229132 assert_eq!(page.status, 200, "GET {path}");
crates/forge-e2e/tests/e2e/snippets_e2e.rsmodified+13 -45
@@ -3,13 +3,12 @@
33 //! `Secure`. Files are fetched from the user-content listener, as a browser would.
44
55 use crate::common::{
6- Http, Server, bin, describe, input_value, launch, login, pick_ports, write_config,
6+ Http, Server, bin, describe, input_value, launch, login, next_changed, pick_ports, write_config,
77 };
88 use std::path::{Path, PathBuf};
99 use std::process::Command;
10-use std::time::Duration;
1110
12-use reqwest::header::{CONTENT_TYPE, COOKIE, LOCATION};
11+use reqwest::header::{CONTENT_TYPE, LOCATION};
1312
1413 const PW: &str = "tahinli-password-123";
1514
@@ -107,36 +106,6 @@ async fn create(
107106 .to_owned()
108107 }
109108
110-/// Opens a live stream as `cookie` (or anonymously) and reads its `retry` field. Returns the
111-/// status with the response, so a refused stream can be checked too.
112-async fn open_stream(http: &Http, path: &str, cookie: Option<&str>) -> reqwest::Response {
113- let mut req = http.client.get(format!("{}{path}", http.base));
114- if let Some(cookie) = cookie {
115- req = req.header(COOKIE, cookie);
116- }
117- let mut res = req.send().await.expect("stream request");
118- if res.status().is_success() {
119- let retry = tokio::time::timeout(Duration::from_secs(5), res.chunk())
120- .await
121- .expect("the retry field")
122- .expect("stream chunk")
123- .expect("stream still open");
124- assert!(String::from_utf8_lossy(&retry).contains("retry: 1000"));
125- }
126- res
127-}
128-
129-/// Waits for the next event of a stream, which must be `changed`.
130-async fn next_change(res: &mut reqwest::Response, what: &str) {
131- let chunk = tokio::time::timeout(Duration::from_secs(5), res.chunk())
132- .await
133- .unwrap_or_else(|_| panic!("no event after {what}"))
134- .expect("stream chunk")
135- .expect("stream still open");
136- let text = String::from_utf8_lossy(&chunk);
137- assert!(text.contains("event: changed"), "{what}: {text}");
138-}
139-
140109 /// The list and the snippet page follow their streams. A create, an edit and a delete each wake
141110 /// them, and a private snippet's stream answers 404 to everyone but its owner.
142111 #[tokio::test]
@@ -170,9 +139,9 @@ async fn snippet_streams_follow_writes() {
170139 "snippet page follows its stream"
171140 );
172141
173- let mut list_events = open_stream(&env.app, "/snippets/events", Some(&tahinli)).await;
142+ let mut list_events = env.app.stream("/snippets/events", Some(&tahinli)).await;
174143 assert_eq!(list_events.status().as_u16(), 200, "list stream");
175- let mut item_events = open_stream(&env.app, &item, Some(&tahinli)).await;
144+ let mut item_events = env.app.stream(&item, Some(&tahinli)).await;
176145 assert_eq!(item_events.status().as_u16(), 200, "snippet stream");
177146
178147 // An edit wakes both.
@@ -194,8 +163,8 @@ async fn snippet_streams_follow_writes() {
194163 )
195164 .await;
196165 assert_eq!(saved.status, 303, "edit: {}", saved.body);
197- next_change(&mut list_events, "an edit").await;
198- next_change(&mut item_events, "an edit").await;
166+ next_changed(&mut list_events, "an edit").await;
167+ next_changed(&mut item_events, "an edit").await;
199168
200169 // A create wakes the list only.
201170 let other = create(
@@ -206,7 +175,7 @@ async fn snippet_streams_follow_writes() {
206175 &[("two.txt", "2\n")],
207176 )
208177 .await;
209- next_change(&mut list_events, "a create").await;
178+ next_changed(&mut list_events, "a create").await;
210179
211180 // A delete wakes the list, and the snippet's stream sends `changed` too: its page now 404s.
212181 let csrf = input_value(
@@ -225,7 +194,7 @@ async fn snippet_streams_follow_writes() {
225194 )
226195 .await;
227196 assert_eq!(deleted.status, 303, "delete: {}", deleted.body);
228- next_change(&mut list_events, "a delete").await;
197+ next_changed(&mut list_events, "a delete").await;
229198
230199 // A private snippet: the owner's stream opens, everyone else gets 404 (anonymous too).
231200 let secret = create(
@@ -238,7 +207,8 @@ async fn snippet_streams_follow_writes() {
238207 .await;
239208 let secret_item = format!("/snippets/{secret}/events");
240209 assert_eq!(
241- open_stream(&env.app, &secret_item, Some(&tahinli))
210+ env.app
211+ .stream(&secret_item, Some(&tahinli))
242212 .await
243213 .status()
244214 .as_u16(),
@@ -246,7 +216,8 @@ async fn snippet_streams_follow_writes() {
246216 "owner opens the private stream"
247217 );
248218 assert_eq!(
249- open_stream(&env.app, &secret_item, Some(&bob))
219+ env.app
220+ .stream(&secret_item, Some(&bob))
250221 .await
251222 .status()
252223 .as_u16(),
@@ -254,10 +225,7 @@ async fn snippet_streams_follow_writes() {
254225 "others get 404"
255226 );
256227 assert_eq!(
257- open_stream(&env.app, &secret_item, None)
258- .await
259- .status()
260- .as_u16(),
228+ env.app.stream(&secret_item, None).await.status().as_u16(),
261229 404,
262230 "anonymous gets 404"
263231 );
crates/forge-e2e/tests/e2e/stars_e2e.rsmodified+2 -34
@@ -3,47 +3,15 @@
33 //! HTTP. Cookies are set by hand because the session cookie is `__Host-` and `Secure`.
44
55 use crate::common::{
6- Http, Resp, Server, bin, describe, input_value, launch, login, pick_ports, tool_on_path,
7- write_config,
6+ Http, PW, Resp, Server, admin, describe, init_bare, input_value, launch, login, pick_ports,
7+ tool_on_path, write_config,
88 };
9-use std::fs;
109 use std::path::{Path, PathBuf};
1110 use std::process::{Command, Stdio};
1211
1312 use forge_core::{Store, Visibility};
1413 use reqwest::header::LOCATION;
1514
16-const PW: &str = "tahinli-password-123";
17-
18-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
19-fn admin(config: &Path, args: &[&str]) {
20- let out = Command::new(bin())
21- .arg("--config")
22- .arg(config)
23- .arg("admin")
24- .args(args)
25- .env("FORGE_PASSWORD", PW)
26- .output()
27- .expect("run admin command");
28- assert!(
29- out.status.success(),
30- "admin {args:?} failed:\n{}",
31- describe(&out)
32- );
33-}
34-
35-/// Creates a bare git repo for `repo_id` at its data-dir location, as the create-repo page does.
36-fn init_bare(data_dir: &Path, repo_id: &str) {
37- let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
38- fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
39- let out = Command::new("git")
40- .args(["init", "--bare", "--quiet", "--initial-branch=main"])
41- .arg(&path)
42- .output()
43- .expect("run git init");
44- assert!(out.status.success(), "git init --bare: {}", describe(&out));
45-}
46-
4715 /// A running server plus the data it was seeded with. The temp dir lives as long as the test.
4816 struct Env {
4917 _root: tempfile::TempDir,
crates/forge-e2e/tests/e2e/user_delete_e2e.rsmodified+0 -7
@@ -15,10 +15,6 @@ use std::process::Command;
1515 use forge_core::{Store, Visibility};
1616 use reqwest::header::LOCATION;
1717
18-/// Each test starts a server on ports picked just before, so the tests run one at a time.
19-static SERIAL: std::sync::LazyLock<tokio::sync::Mutex<()>> =
20- std::sync::LazyLock::new(|| tokio::sync::Mutex::new(()));
21-
2218 const PW: &str = "tahinli-password-123";
2319
2420 /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
@@ -122,7 +118,6 @@ async fn seed_issue_by_tahinli(dir: PathBuf, store: Store) {
122118
123119 #[tokio::test]
124120 async fn admin_delete_moves_content_to_ghost_and_pages_still_render() {
125- let _serial = SERIAL.lock().await;
126121 let env = start(seed_issue_by_tahinli).await;
127122 let http = &env.http;
128123 let dana = login(http, "dana", PW).await;
@@ -173,7 +168,6 @@ async fn admin_delete_moves_content_to_ghost_and_pages_still_render() {
173168
174169 #[tokio::test]
175170 async fn self_delete_refuses_wrong_password_and_owned_repos() {
176- let _serial = SERIAL.lock().await;
177171 let env = start(seed_issue_by_tahinli).await;
178172 let http = &env.http;
179173
@@ -236,7 +230,6 @@ async fn self_delete_refuses_wrong_password_and_owned_repos() {
236230
237231 #[tokio::test]
238232 async fn self_delete_with_correct_password_signs_out_and_removes_login() {
239- let _serial = SERIAL.lock().await;
240233 let env = start(seed_issue_by_tahinli).await;
241234 let http = &env.http;
242235 let tahinli = login(http, "tahinli", PW).await;
crates/forge-e2e/tests/e2e/wiki_e2e.rsmodified+11 -22
@@ -6,7 +6,7 @@
66 //! which a cookie jar would not send over plain http.
77
88 use crate::common::{
9- Http, Resp, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config,
9+ Http, Resp, bin, describe, input_value, launch, login, pick_ports, write_config,
1010 };
1111 use std::fs;
1212 use std::path::Path;
@@ -116,8 +116,7 @@ fn commit_file(repo: &Path, name: &str, content: &str, message: &str) {
116116 );
117117 }
118118
119-/// Reads the wiki page `name` as the viewer, returns its body.
120-async fn page_body(http: &Http, path: &str, session: Option<&str>) -> Resp {
119+async fn get_ok(http: &Http, path: &str, session: Option<&str>) -> Resp {
121120 let res = http.get(path, session).await;
122121 assert_eq!(res.status, 200, "GET {path}: {}", res.body);
123122 res
@@ -125,11 +124,6 @@ async fn page_body(http: &Http, path: &str, session: Option<&str>) -> Resp {
125124
126125 #[tokio::test]
127126 async fn wiki_end_to_end() {
128- if !tool_on_path("git") {
129- eprintln!("SKIP wiki_e2e: `git` was not found on PATH");
130- return;
131- }
132-
133127 // Keep the path short: the data dir holds a unix socket with a length limit.
134128 let root = tempfile::Builder::new()
135129 .prefix("fwk")
@@ -172,7 +166,7 @@ async fn wiki_end_to_end() {
172166 let dave = login(&http, "dave", PW).await;
173167
174168 // The wiki starts empty, and the tab is there.
175- let empty = page_body(&http, "/bob/proj/wiki", Some(&bob)).await;
169+ let empty = get_ok(&http, "/bob/proj/wiki", Some(&bob)).await;
176170 assert!(empty.body.contains("no pages yet"), "{}", empty.body);
177171
178172 // Bob creates Home on the web. The save redirects to the page.
@@ -198,7 +192,7 @@ async fn wiki_end_to_end() {
198192 saved.header(LOCATION).as_deref(),
199193 Some("/bob/proj/wiki/Home")
200194 );
201- let home = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
195+ let home = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
202196 assert!(home.body.contains("Welcome"), "{}", home.body);
203197 assert!(
204198 home.body.contains("/bob/proj/wiki/Getting-Started"),
@@ -207,7 +201,7 @@ async fn wiki_end_to_end() {
207201 );
208202
209203 // Dave can read the page but not edit it.
210- page_body(&http, "/bob/proj/wiki/Home", Some(&dave)).await;
204+ get_ok(&http, "/bob/proj/wiki/Home", Some(&dave)).await;
211205 let refused = http.get("/bob/proj/wiki/Home/edit", Some(&dave)).await;
212206 assert_eq!(refused.status, 403, "read-only user must not edit");
213207
@@ -229,7 +223,7 @@ async fn wiki_end_to_end() {
229223 &git(&work, &["push", "-q", "origin", "HEAD:main"]),
230224 "push wiki change over HTTPS",
231225 );
232- let after_push = page_body(&http, "/bob/proj/wiki/Home", Some(&carol)).await;
226+ let after_push = get_ok(&http, "/bob/proj/wiki/Home", Some(&carol)).await;
233227 assert!(
234228 after_push.body.contains("Welcome again"),
235229 "{}",
@@ -275,11 +269,11 @@ async fn wiki_end_to_end() {
275269 "{}",
276270 stale.body
277271 );
278- let still = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
272+ let still = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
279273 assert!(still.body.contains("Welcome again"), "{}", still.body);
280274
281275 // The history lists both edits.
282- let history = page_body(&http, "/bob/proj/wiki/Home/history", Some(&bob)).await;
276+ let history = get_ok(&http, "/bob/proj/wiki/Home/history", Some(&bob)).await;
283277 assert!(history.body.contains("first page"), "{}", history.body);
284278 assert!(history.body.contains("edit from git"), "{}", history.body);
285279
@@ -299,7 +293,7 @@ async fn wiki_end_to_end() {
299293 assert!(!denied.status.success(), "read-only push must fail");
300294
301295 // Bob turns the wiki off on the settings page. Carol, who is not an admin, cannot.
302- let settings = page_body(&http, "/bob/proj/settings", Some(&bob)).await;
296+ let settings = get_ok(&http, "/bob/proj/settings", Some(&bob)).await;
303297 assert!(
304298 settings.body.contains("action=\"/bob/proj/settings/wiki\""),
305299 "{}",
@@ -362,11 +356,6 @@ async fn next_wiki_change(res: &mut reqwest::Response, what: &str) {
362356 /// wake the wiki streams, and a viewer who cannot read the repo gets 404 from them.
363357 #[tokio::test]
364358 async fn wiki_streams_follow_saves_and_pushes() {
365- if !tool_on_path("git") {
366- eprintln!("SKIP wiki live: `git` was not found on PATH");
367- return;
368- }
369-
370359 let root = tempfile::Builder::new()
371360 .prefix("fwl")
372361 .tempdir_in("/tmp")
@@ -402,7 +391,7 @@ async fn wiki_streams_follow_saves_and_pushes() {
402391 let dave = login(&http, "dave", PW).await;
403392
404393 // The page list follows the wiki stream.
405- let listing = page_body(&http, "/bob/proj/wiki/-/pages", Some(&bob)).await;
394+ let listing = get_ok(&http, "/bob/proj/wiki/-/pages", Some(&bob)).await;
406395 assert!(
407396 listing
408397 .body
@@ -433,7 +422,7 @@ async fn wiki_streams_follow_saves_and_pushes() {
433422 next_wiki_change(&mut wiki_events, "a web save").await;
434423
435424 // The page's own stream follows Home, and a push from git wakes it.
436- let home = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
425+ let home = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
437426 assert!(
438427 home.body
439428 .contains(r#"data-live="/bob/proj/wiki/Home/events""#),
docs/architecture.mdmodified+1 -1
@@ -61,7 +61,7 @@ Module ownership (from the contract):
6161 - `error.rs`, `time.rs` (`now_stamp()`, `stamp_after()`), `model.rs` (domain types)
6262 - `config.rs` (`Config::load`), `secret.rs` (`load_or_create_key`, `seal`, `open`)
6363 - `names.rs` (`normalize_name`, `validate_name`, `RESERVED`), `password.rs` (argon2id)
64- - `token.rs` (`generate_token`, `hash_token`, `constant_time_eq`), `session.rs`
64+ - `token.rs` (`generate_token`, `hash_token`, `constant_time_eq`)
6565 - `authz.rs` (`Action`, `Denied`, `authorize`)
6666 - `store/mod.rs` (`Store`), `store/migrate.rs` (migration runner)
6767 - `migrations/0001_init.sql`
docs/backlog.mdmodified+1 -1
@@ -51,7 +51,7 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done.
5151
5252 ## Tech debt
5353 - [x] A shared test fixture `test_support::app(dir) -> (AppState, Router)`: Config and AppState literals are copied into about 8 test modules, and every new field breaks them all
54-- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/integration/read_pool.rs`)
54+- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers
5555 - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`)
5656
5757 ## Later