diff --git a/crates/forge-web/tests/account_mail_e2e.rs b/crates/forge-web/tests/e2e/account_mail_e2e.rs similarity index 99% rename from crates/forge-web/tests/account_mail_e2e.rs rename to crates/forge-web/tests/e2e/account_mail_e2e.rs index 921b897..c37e107 100644 --- a/crates/forge-web/tests/account_mail_e2e.rs +++ b/crates/forge-web/tests/e2e/account_mail_e2e.rs @@ -2,8 +2,7 @@ //! tests, this starts the real `forge` binary. The log transport writes each mail to //! `/mail-log/`, which is where the tests read the reset link from. -mod common; -use common::{launch_with, pick_ports}; +use crate::common::{launch_with, pick_ports}; use std::fs; use std::path::{Path, PathBuf}; use std::time::Duration; diff --git a/crates/forge-web/tests/advisories_e2e.rs b/crates/forge-web/tests/e2e/advisories_e2e.rs similarity index 96% rename from crates/forge-web/tests/advisories_e2e.rs rename to crates/forge-web/tests/e2e/advisories_e2e.rs index ad41d17..0776938 100644 --- a/crates/forge-web/tests/advisories_e2e.rs +++ b/crates/forge-web/tests/e2e/advisories_e2e.rs @@ -8,8 +8,9 @@ //! - an owner dismisses it, reopens it, and a fixing push moves it to `fixed`; //! - a reader without Write gets a 404 on the page. -mod common; -use common::{BIN, Server, launch_with, pick_ports, tool_on_path, write_config_with}; +use crate::common::{ + BIN, Server, input_value, launch_with, pick_ports, tool_on_path, write_config_with, +}; use std::fs; use std::io::{Cursor, Write}; use std::path::{Path, PathBuf}; @@ -104,16 +105,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs git with credential helpers disabled. Panics on failure and returns trimmed stdout. fn git(cwd: &Path, args: &[&str]) -> String { let out: Output = Command::new("git") diff --git a/crates/forge-web/tests/branch_protection_e2e.rs b/crates/forge-web/tests/e2e/branch_protection_e2e.rs similarity index 96% rename from crates/forge-web/tests/branch_protection_e2e.rs rename to crates/forge-web/tests/e2e/branch_protection_e2e.rs index 58e0ccd..283e7c4 100644 --- a/crates/forge-web/tests/branch_protection_e2e.rs +++ b/crates/forge-web/tests/e2e/branch_protection_e2e.rs @@ -2,9 +2,9 @@ //! binary, pushes with the real `git` client over HTTPS, and writes rules through `forge-core` //! while the server runs. Helpers mirror `git_e2e.rs`. -mod common; -use common::{ - BIN, Ports, Server, describe, launch, pick_ports, relaunch, tool_on_path, write_config, +use crate::common::{ + BIN, Ports, Server, describe, input_value, launch, pick_ports, relaunch, tool_on_path, + write_config, }; use std::fs; use std::path::{Path, PathBuf}; @@ -100,16 +100,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { let out = Command::new(BIN) .arg("--config") diff --git a/crates/forge-web/tests/browse_e2e.rs b/crates/forge-web/tests/e2e/browse_e2e.rs similarity index 98% rename from crates/forge-web/tests/browse_e2e.rs rename to crates/forge-web/tests/e2e/browse_e2e.rs index 66a8c32..b647ded 100644 --- a/crates/forge-web/tests/browse_e2e.rs +++ b/crates/forge-web/tests/e2e/browse_e2e.rs @@ -5,8 +5,7 @@ //! Cookies are handled by hand, as in `git_e2e.rs`: the session cookie is `__Host-forge_session` //! with `Secure`, so a cookie jar would not send it over plain http. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -108,16 +107,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The values of `attr` on every element matching `selector`, in document order. fn attr_values(body: &str, selector: &str, attr: &str) -> Vec { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/ci_e2e.rs b/crates/forge-web/tests/e2e/ci_e2e.rs similarity index 98% rename from crates/forge-web/tests/ci_e2e.rs rename to crates/forge-web/tests/e2e/ci_e2e.rs index 00e0dfe..d17b77f 100644 --- a/crates/forge-web/tests/ci_e2e.rs +++ b/crates/forge-web/tests/e2e/ci_e2e.rs @@ -10,8 +10,7 @@ //! - a fork pull request: it waits for approval, then runs without secrets; //! - a live log: `log.txt` streams while a job runs and ends when the job finishes. -mod common; -use common::{BIN, FAST_CLAIMS, Server, launch_with, pick_ports, write_config}; +use crate::common::{BIN, FAST_CLAIMS, Server, input_value, launch_with, pick_ports, write_config}; use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest}; use forge_runner::client::ForgeClient; use forge_runner::config::{Limits, RunnerConfig}; @@ -176,16 +175,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The text of the first element matching `selector`. fn first_text(body: &str, selector: &str) -> String { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/common/mod.rs b/crates/forge-web/tests/e2e/common/mod.rs similarity index 92% rename from crates/forge-web/tests/common/mod.rs rename to crates/forge-web/tests/e2e/common/mod.rs index 6052649..4e22707 100644 --- a/crates/forge-web/tests/common/mod.rs +++ b/crates/forge-web/tests/e2e/common/mod.rs @@ -1,5 +1,6 @@ -//! Helpers shared by the forge-web e2e tests. Every test file pulls this in with `mod common;`, so -//! items a given test binary does not use are allowed to be dead code. +//! Helpers shared by the forge-web e2e tests. `main.rs` declares this module once, and each test +//! module imports what it needs from `crate::common`. Items a given test does not use are allowed +//! to be dead code. //! //! The server is started with `launch`, which waits for the three listeners (HTTP, user content //! and SSH) with backoff. A connection that is refused just means "not yet". If the child exits @@ -39,6 +40,17 @@ pub struct Ports { pub content: u16, } +/// The value of the named `` on a page, read with an HTML parser. +pub fn input_value(body: &str, name: &str) -> String { + let doc = scraper::Html::parse_document(body); + let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); + doc.select(&selector) + .next() + .and_then(|el| el.value().attr("value")) + .unwrap_or_else(|| panic!("no input named {name} on page")) + .to_owned() +} + /// A port the kernel handed out for a moment. It is free only until something binds it. pub fn free_port() -> u16 { std::net::TcpListener::bind("127.0.0.1:0") diff --git a/crates/forge-web/tests/community_i18n_e2e.rs b/crates/forge-web/tests/e2e/community_i18n_e2e.rs similarity index 96% rename from crates/forge-web/tests/community_i18n_e2e.rs rename to crates/forge-web/tests/e2e/community_i18n_e2e.rs index 3f30e1a..316d86f 100644 --- a/crates/forge-web/tests/community_i18n_e2e.rs +++ b/crates/forge-web/tests/e2e/community_i18n_e2e.rs @@ -1,12 +1,10 @@ //! End-to-end check that a community page (snippets) follows the viewer's browser language: //! Turkish when `Accept-Language` asks for it, English otherwise. -mod common; - use std::process::Command; use std::time::Duration; -use common::{BIN, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, describe, launch, pick_ports, write_config}; use reqwest::header::ACCEPT_LANGUAGE; const PW: &str = "tahinli-password-123"; diff --git a/crates/forge-web/tests/discussions_e2e.rs b/crates/forge-web/tests/e2e/discussions_e2e.rs similarity index 96% rename from crates/forge-web/tests/discussions_e2e.rs rename to crates/forge-web/tests/e2e/discussions_e2e.rs index ab2d62f..ee608e0 100644 --- a/crates/forge-web/tests/discussions_e2e.rs +++ b/crates/forge-web/tests/e2e/discussions_e2e.rs @@ -3,8 +3,7 @@ //! an answer in Q&A, and the lock: once locked, a plain viewer's comment is refused while the //! owner can still write. -mod common; -use common::{BIN, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, input_value, launch, pick_ports, tool_on_path, write_config}; use std::path::Path; use std::process::Command; use std::time::Duration; @@ -89,16 +88,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { let out = Command::new(BIN) .arg("--config") diff --git a/crates/forge-web/tests/git_e2e.rs b/crates/forge-web/tests/e2e/git_e2e.rs similarity index 97% rename from crates/forge-web/tests/git_e2e.rs rename to crates/forge-web/tests/e2e/git_e2e.rs index 71a4657..588ec79 100644 --- a/crates/forge-web/tests/git_e2e.rs +++ b/crates/forge-web/tests/e2e/git_e2e.rs @@ -4,8 +4,7 @@ //! Cookies are handled by hand: the session cookie is `__Host-forge_session` with `Secure`, so a //! cookie jar would not send it over plain http. The test parses `Set-Cookie` and sends `Cookie`. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -127,16 +126,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { let out = Command::new(BIN) .arg("--config") diff --git a/crates/forge-web/tests/i18n_e2e.rs b/crates/forge-web/tests/e2e/i18n_e2e.rs similarity index 94% rename from crates/forge-web/tests/i18n_e2e.rs rename to crates/forge-web/tests/e2e/i18n_e2e.rs index ed66f9f..30deddc 100644 --- a/crates/forge-web/tests/i18n_e2e.rs +++ b/crates/forge-web/tests/e2e/i18n_e2e.rs @@ -1,13 +1,11 @@ //! End-to-end checks for the interface language. Anonymous pages follow `Accept-Language`; a //! signed-in user's stored language beats the browser; `` matches the language used. -mod common; - use std::path::{Path, PathBuf}; use std::process::Command; use std::time::Duration; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use forge_core::Store; use reqwest::header::{ACCEPT_LANGUAGE, COOKIE, HeaderMap, SET_COOKIE}; @@ -90,16 +88,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/issue_close_e2e.rs b/crates/forge-web/tests/e2e/issue_close_e2e.rs similarity index 96% rename from crates/forge-web/tests/issue_close_e2e.rs rename to crates/forge-web/tests/e2e/issue_close_e2e.rs index ed2a36a..e6dc711 100644 --- a/crates/forge-web/tests/issue_close_e2e.rs +++ b/crates/forge-web/tests/e2e/issue_close_e2e.rs @@ -3,8 +3,7 @@ //! The server runs as a subprocess. Issues are created through the store on the same database //! file, and every push is a real `git push` through the git HTTP endpoints. -mod common; -use common::{BIN, launch, pick_ports, relaunch, tool_on_path, write_config}; +use crate::common::{BIN, input_value, launch, pick_ports, relaunch, tool_on_path, write_config}; use std::fs; use std::future::Future; use std::path::Path; @@ -96,16 +95,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { let out = Command::new(BIN) .arg("--config") diff --git a/crates/forge-web/tests/lfs_e2e.rs b/crates/forge-web/tests/e2e/lfs_e2e.rs similarity index 95% rename from crates/forge-web/tests/lfs_e2e.rs rename to crates/forge-web/tests/e2e/lfs_e2e.rs index 96d0d10..fbb3deb 100644 --- a/crates/forge-web/tests/lfs_e2e.rs +++ b/crates/forge-web/tests/e2e/lfs_e2e.rs @@ -5,8 +5,7 @@ //! Git config is isolated from the developer's machine: `HOME` and `GIT_CONFIG_GLOBAL` point into //! the test's temp dir. -mod common; -use common::{BIN, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -94,16 +93,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { let out = Command::new(BIN) .arg("--config") diff --git a/crates/forge-web/tests/e2e/main.rs b/crates/forge-web/tests/e2e/main.rs new file mode 100644 index 0000000..27740aa --- /dev/null +++ b/crates/forge-web/tests/e2e/main.rs @@ -0,0 +1,36 @@ +//! One integration test binary for forge-web. Every file in this directory is a module of this +//! crate, so the package links one test executable instead of one per file. The shared support +//! lives in `common`. + +mod common; + +mod account_mail_e2e; +mod advisories_e2e; +mod branch_protection_e2e; +mod browse_e2e; +mod ci_e2e; +mod community_i18n_e2e; +mod discussions_e2e; +mod git_e2e; +mod i18n_e2e; +mod issue_close_e2e; +mod lfs_e2e; +mod merge_queue_e2e; +mod mirrors_e2e; +mod oci_e2e; +mod orgs_core_e2e; +mod orgs_live_e2e; +mod orgs_ui_e2e; +mod packages_e2e; +mod pulls_e2e; +mod repo_collaborators_e2e; +mod repo_rename_e2e; +mod repo_settings_e2e; +mod repo_transfer_e2e; +mod runner_subcommand; +mod section_nav_e2e; +mod snippets_e2e; +mod stars_e2e; +mod ui_prefs_e2e; +mod user_delete_e2e; +mod wiki_e2e; diff --git a/crates/forge-web/tests/merge_queue_e2e.rs b/crates/forge-web/tests/e2e/merge_queue_e2e.rs similarity index 98% rename from crates/forge-web/tests/merge_queue_e2e.rs rename to crates/forge-web/tests/e2e/merge_queue_e2e.rs index b1701db..0014a83 100644 --- a/crates/forge-web/tests/merge_queue_e2e.rs +++ b/crates/forge-web/tests/e2e/merge_queue_e2e.rs @@ -9,8 +9,9 @@ // The harness helpers are the same ones `ci_e2e.rs` uses. This file uses a subset of them. #![allow(dead_code)] -mod common; -use common::{BIN, FAST_CLAIMS, Server, launch_with, pick_ports, tool_on_path, write_config}; +use crate::common::{ + BIN, FAST_CLAIMS, Server, input_value, launch_with, pick_ports, tool_on_path, write_config, +}; use forge_ci::proto::{JobAssignment, RegisterRequest}; use forge_runner::client::ForgeClient; use forge_runner::config::{Limits, RunnerConfig}; @@ -117,16 +118,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The text of the first element matching `selector`. fn first_text(body: &str, selector: &str) -> String { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/mirrors_e2e.rs b/crates/forge-web/tests/e2e/mirrors_e2e.rs similarity index 97% rename from crates/forge-web/tests/mirrors_e2e.rs rename to crates/forge-web/tests/e2e/mirrors_e2e.rs index d09dd25..a2931d0 100644 --- a/crates/forge-web/tests/mirrors_e2e.rs +++ b/crates/forge-web/tests/e2e/mirrors_e2e.rs @@ -9,8 +9,9 @@ //! - push mirror `pm` to `tahinli/target` (created empty) after a push to `pm`; //! - the mirror pages and the server log never contain the access token. -mod common; -use common::{BIN, Server, launch_with, pick_ports, tool_on_path, write_config_with}; +use crate::common::{ + BIN, Server, input_value, launch_with, pick_ports, tool_on_path, write_config_with, +}; use std::collections::BTreeSet; use std::fs; use std::path::{Path, PathBuf}; @@ -101,16 +102,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `action` of every form whose action ends with `suffix`, in page order. fn form_actions(body: &str, suffix: &str) -> Vec { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/oci_e2e.rs b/crates/forge-web/tests/e2e/oci_e2e.rs similarity index 99% rename from crates/forge-web/tests/oci_e2e.rs rename to crates/forge-web/tests/e2e/oci_e2e.rs index 030e32c..66a365b 100644 --- a/crates/forge-web/tests/oci_e2e.rs +++ b/crates/forge-web/tests/e2e/oci_e2e.rs @@ -5,8 +5,7 @@ //! up through the store before the server starts, since the web has no way to make one private. //! The last test drives podman when it is installed; it is ignored by default. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, Server, describe, launch, pick_ports, tool_on_path, write_config}; use std::path::Path; use std::process::Command; use std::time::Duration; diff --git a/crates/forge-web/tests/orgs_core_e2e.rs b/crates/forge-web/tests/e2e/orgs_core_e2e.rs similarity index 94% rename from crates/forge-web/tests/orgs_core_e2e.rs rename to crates/forge-web/tests/e2e/orgs_core_e2e.rs index 7159a0b..0988338 100644 --- a/crates/forge-web/tests/orgs_core_e2e.rs +++ b/crates/forge-web/tests/e2e/orgs_core_e2e.rs @@ -3,8 +3,7 @@ //! this starts the real `forge` binary and drives it over HTTP. The org rows and their credentials //! are written straight into the database before the server starts. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use std::future::Future; use std::path::{Path, PathBuf}; use std::process::Command; @@ -98,16 +97,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/orgs_live_e2e.rs b/crates/forge-web/tests/e2e/orgs_live_e2e.rs similarity index 97% rename from crates/forge-web/tests/orgs_live_e2e.rs rename to crates/forge-web/tests/e2e/orgs_live_e2e.rs index 81b938b..06e0d2a 100644 --- a/crates/forge-web/tests/orgs_live_e2e.rs +++ b/crates/forge-web/tests/e2e/orgs_live_e2e.rs @@ -2,8 +2,7 @@ //! with a seeded org (owner tahinli, member bob, a team), and the test drives the writes over HTTP //! and reads each stream. It also checks that each stream refuses the viewers its page refuses. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::path::Path; use std::process::{Command, Output}; use std::time::Duration; @@ -118,16 +117,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `data-live` value of the first element that names a stream, if any. fn live_url(body: &str) -> Option { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/orgs_ui_e2e.rs b/crates/forge-web/tests/e2e/orgs_ui_e2e.rs similarity index 98% rename from crates/forge-web/tests/orgs_ui_e2e.rs rename to crates/forge-web/tests/e2e/orgs_ui_e2e.rs index 56cbfce..f76bda1 100644 --- a/crates/forge-web/tests/orgs_ui_e2e.rs +++ b/crates/forge-web/tests/e2e/orgs_ui_e2e.rs @@ -3,8 +3,9 @@ //! through the store before the server starts, and then drive the pages over HTTP. Cookies are //! handled by hand, as in `repo_collaborators_e2e.rs`. -mod common; -use common::{BIN, describe, launch, launch_with, pick_ports, tool_on_path, write_config}; +use crate::common::{ + BIN, describe, input_value, launch, launch_with, pick_ports, tool_on_path, write_config, +}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -101,16 +102,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The value of the selected option of the `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`. fn state_badge(body: &str) -> String { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/repo_collaborators_e2e.rs b/crates/forge-web/tests/e2e/repo_collaborators_e2e.rs similarity index 97% rename from crates/forge-web/tests/repo_collaborators_e2e.rs rename to crates/forge-web/tests/e2e/repo_collaborators_e2e.rs index 9997802..8be1b7d 100644 --- a/crates/forge-web/tests/repo_collaborators_e2e.rs +++ b/crates/forge-web/tests/e2e/repo_collaborators_e2e.rs @@ -2,8 +2,7 @@ //! seed users and repos through the store before the server starts, and then drive the page and //! its POST forms over HTTP. Cookies are handled by hand (see `repo_settings_e2e.rs`). -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -95,16 +94,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) -> Output { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/repo_rename_e2e.rs b/crates/forge-web/tests/e2e/repo_rename_e2e.rs similarity index 97% rename from crates/forge-web/tests/repo_rename_e2e.rs rename to crates/forge-web/tests/e2e/repo_rename_e2e.rs index 3cd7a0d..96b581d 100644 --- a/crates/forge-web/tests/repo_rename_e2e.rs +++ b/crates/forge-web/tests/e2e/repo_rename_e2e.rs @@ -5,8 +5,7 @@ //! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`, //! which a cookie jar would not send over plain http. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -98,16 +97,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `action` of the first form on a page whose action ends with `suffix`. fn form_action(body: &str, suffix: &str) -> String { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/repo_settings_e2e.rs b/crates/forge-web/tests/e2e/repo_settings_e2e.rs similarity index 98% rename from crates/forge-web/tests/repo_settings_e2e.rs rename to crates/forge-web/tests/e2e/repo_settings_e2e.rs index 035cc12..47a69f7 100644 --- a/crates/forge-web/tests/repo_settings_e2e.rs +++ b/crates/forge-web/tests/e2e/repo_settings_e2e.rs @@ -4,8 +4,7 @@ //! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`, //! which a cookie jar would not send over plain http. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -97,16 +96,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) -> Output { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/repo_transfer_e2e.rs b/crates/forge-web/tests/e2e/repo_transfer_e2e.rs similarity index 95% rename from crates/forge-web/tests/repo_transfer_e2e.rs rename to crates/forge-web/tests/e2e/repo_transfer_e2e.rs index 64af271..78c076f 100644 --- a/crates/forge-web/tests/repo_transfer_e2e.rs +++ b/crates/forge-web/tests/e2e/repo_transfer_e2e.rs @@ -5,8 +5,7 @@ //! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`, //! which a cookie jar would not send over plain http. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::process::Command; use std::time::Duration; @@ -98,16 +97,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `action` of the first form on a page whose action ends with `suffix`. Panics when none. fn form_action(body: &str, suffix: &str) -> String { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/runner_subcommand.rs b/crates/forge-web/tests/e2e/runner_subcommand.rs similarity index 100% rename from crates/forge-web/tests/runner_subcommand.rs rename to crates/forge-web/tests/e2e/runner_subcommand.rs diff --git a/crates/forge-web/tests/section_nav_e2e.rs b/crates/forge-web/tests/e2e/section_nav_e2e.rs similarity index 95% rename from crates/forge-web/tests/section_nav_e2e.rs rename to crates/forge-web/tests/e2e/section_nav_e2e.rs index 286106f..f317191 100644 --- a/crates/forge-web/tests/section_nav_e2e.rs +++ b/crates/forge-web/tests/e2e/section_nav_e2e.rs @@ -4,8 +4,7 @@ #![allow(dead_code)] -mod common; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use std::path::Path; use std::process::Command; use std::time::Duration; @@ -95,16 +94,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `data-theme` attribute of ``, if the page sets one. fn html_theme(body: &str) -> Option { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/snippets_e2e.rs b/crates/forge-web/tests/e2e/snippets_e2e.rs similarity index 97% rename from crates/forge-web/tests/snippets_e2e.rs rename to crates/forge-web/tests/e2e/snippets_e2e.rs index 31d476e..b3168f0 100644 --- a/crates/forge-web/tests/snippets_e2e.rs +++ b/crates/forge-web/tests/e2e/snippets_e2e.rs @@ -2,8 +2,7 @@ //! drives it over HTTP. Cookies are set by hand because the session cookie is `__Host-` and //! `Secure`. Files are fetched from the user-content listener, as a browser would. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use std::path::{Path, PathBuf}; use std::process::Command; use std::time::Duration; @@ -90,16 +89,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The path and query of an absolute URL, so it can be requested through a base-bound client. fn path_of(url: &str) -> String { let rest = url.split_once("//").map_or(url, |(_, r)| r); diff --git a/crates/forge-web/tests/stars_e2e.rs b/crates/forge-web/tests/e2e/stars_e2e.rs similarity index 96% rename from crates/forge-web/tests/stars_e2e.rs rename to crates/forge-web/tests/e2e/stars_e2e.rs index 4b2d619..fe534df 100644 --- a/crates/forge-web/tests/stars_e2e.rs +++ b/crates/forge-web/tests/e2e/stars_e2e.rs @@ -2,8 +2,9 @@ //! banner. Like the other e2e tests, this starts the real `forge` binary and drives it over //! HTTP. Cookies are set by hand because the session cookie is `__Host-` and `Secure`. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{ + BIN, Server, describe, input_value, launch, pick_ports, tool_on_path, write_config, +}; use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; @@ -95,16 +96,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/ui_prefs_e2e.rs b/crates/forge-web/tests/e2e/ui_prefs_e2e.rs similarity index 98% rename from crates/forge-web/tests/ui_prefs_e2e.rs rename to crates/forge-web/tests/e2e/ui_prefs_e2e.rs index b322865..120c9a9 100644 --- a/crates/forge-web/tests/ui_prefs_e2e.rs +++ b/crates/forge-web/tests/e2e/ui_prefs_e2e.rs @@ -3,8 +3,7 @@ //! tests, this starts the real `forge` binary and drives it over HTTP. Cookies are set by hand //! because the session cookie is `__Host-` and `Secure`. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use std::path::Path; use std::process::Command; use std::time::Duration; @@ -94,16 +93,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// The `data-theme` attribute of ``, if the page sets one. fn html_theme(body: &str) -> Option { let doc = scraper::Html::parse_document(body); diff --git a/crates/forge-web/tests/user_delete_e2e.rs b/crates/forge-web/tests/e2e/user_delete_e2e.rs similarity index 95% rename from crates/forge-web/tests/user_delete_e2e.rs rename to crates/forge-web/tests/e2e/user_delete_e2e.rs index fc2391d..f7c3600 100644 --- a/crates/forge-web/tests/user_delete_e2e.rs +++ b/crates/forge-web/tests/e2e/user_delete_e2e.rs @@ -3,8 +3,7 @@ //! the real `forge` binary and drives it over HTTP. Cookies are set by hand because the //! session cookie is `__Host-` and `Secure`. -mod common; -use common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{BIN, Server, describe, input_value, launch, pick_ports, write_config}; use std::fs; use std::future::Future; use std::path::{Path, PathBuf}; @@ -101,16 +100,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) { let out = Command::new(BIN) diff --git a/crates/forge-web/tests/wiki_e2e.rs b/crates/forge-web/tests/e2e/wiki_e2e.rs similarity index 97% rename from crates/forge-web/tests/wiki_e2e.rs rename to crates/forge-web/tests/e2e/wiki_e2e.rs index 0b60cf3..92da4d7 100644 --- a/crates/forge-web/tests/wiki_e2e.rs +++ b/crates/forge-web/tests/e2e/wiki_e2e.rs @@ -5,8 +5,7 @@ //! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`, //! which a cookie jar would not send over plain http. -mod common; -use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{BIN, describe, input_value, launch, pick_ports, tool_on_path, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -98,16 +97,6 @@ fn cookie_named(resp: &Resp, suffix: &str) -> Option { } /// The value of the first `` on a page. -fn input_value(body: &str, name: &str) -> String { - let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); - doc.select(&selector) - .next() - .and_then(|el| el.value().attr("value")) - .unwrap_or_else(|| panic!("no input named {name} on page")) - .to_owned() -} - /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &Path, args: &[&str]) { let out = Command::new(BIN) diff --git a/docs/architecture.md b/docs/architecture.md index 8611991..009e630 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -479,7 +479,7 @@ Don't: - Repo create with the ID-based path. Visibility, collaborators, archive flag. - Smart HTTP (`info/refs`, upload-pack, receive-pack, gzip, streaming) and SSH (exec allow-list, `GIT_PROTOCOL`, piping, exit status). - Pre-receive policy (archived, default-branch delete and force-push, bad ref names) and post-receive `push_events`. Minimal UI: setup, login, dashboard, new repo, repo page, settings, admin users, `/healthz`. -- Tests: unit tests in core and git; end-to-end `git_e2e.rs` over HTTPS and SSH, with negative cases (bad token, cross-user private 404, forced default-branch push rejected, unknown SSH command rejected, traversal rejected, POST without CSRF rejected). +- Tests: unit tests in core and git; end-to-end `tests/e2e/git_e2e.rs` over HTTPS and SSH, with negative cases (bad token, cross-user private 404, forced default-branch push rejected, unknown SSH command rejected, traversal rejected, POST without CSRF rejected). ### Repo browsing and raw files