diff --git a/.forge/ci.toml b/.forge/ci.toml index 81c28d0..f68e1e6 100644 --- a/.forge/ci.toml +++ b/.forge/ci.toml @@ -1,13 +1,12 @@ # CI for forge itself. Format: docs/ci.md, parser: crates/forge-ci/src/config.rs. # -# The workflow has no branch condition, so the build job also runs for pull requests. -# build has `needs = ["test"]`, so it starts only after test succeeds. Only one job uses the -# runner's memory at a time, so no memory is declared. An earlier run with concurrency 4 hit a -# host-wide OOM and the kernel killed rustc mid-build. -# The build job's artifacts are still only used -# once the whole run is green: a tag push matching "v*" publishes a release with the build job's -# binaries and SHA256SUMS, and self-update deploys forge--linux, only when every job in the run, -# including test, succeeded. +# The workflow has no branch condition, so the job also runs for pull requests. +# One job does everything, so its steps run one at a time and no memory is declared. An earlier run +# with concurrency 4 hit a host-wide OOM and the kernel killed rustc mid-build. +# A tag push matching "v*" publishes a release with the job's binaries and SHA256SUMS, and +# self-update deploys forge--linux. Both happen only when the job succeeded. +# +# The job is named build because self-update's `job` setting and the release assets name it. [on] push = ["main"] @@ -15,31 +14,22 @@ pull_request = true manual = true tags = ["v*"] -[jobs.test] +[jobs.build] image = "docker.io/library/rust:1" # Build parallelism comes from the runner (CARGO_BUILD_JOBS follows its CPU limit). Drops debuginfo. # CARGO_HOME in the workspace puts the downloaded crates in the cache, so a run downloads only new ones. # That places turso_core's source inside this repo, and its build.rs then watches our .git/HEAD, which # is new in every job, so it would rebuild on every run. With SOURCE_DATE_EPOCH set it skips git. -env = { CARGO_PROFILE_DEV_DEBUG = "0", CARGO_PROFILE_TEST_DEBUG = "0", CARGO_INCREMENTAL = "0", CARGO_HOME = "/workspace/.cargo-home", SOURCE_DATE_EPOCH = "0" } -# main.rs holds the whole forge-web crate, so `cargo test` compiles it twice: the `forge` binary -# (the e2e tests run it) and its unit-test harness, ~3.4 GB of rustc each. Built in parallel they -# hit the runner's box cap and got OOM-killed now and then. The e2e build makes the binary first, -# alone; the full run reuses it and compiles only the harness. -run = """ -cargo test --workspace --no-run --test e2e -cargo test --workspace -""" -cache = ["target", ".cargo-home"] -timeout_minutes = 120 - -[jobs.build] -image = "docker.io/library/rust:1" -needs = ["test"] -# Build parallelism comes from the runner (CARGO_BUILD_JOBS follows its CPU limit). -env = { CARGO_INCREMENTAL = "0", CARGO_HOME = "/workspace/.cargo-home", SOURCE_DATE_EPOCH = "0" } +# Incremental stays on for the test builds, which `target` in the cache lets them reuse. It is on +# trial: it was turned off in 4c4575a to avoid OOM kills, so set CARGO_INCREMENTAL = "0" if they return. +# The dist profile has incremental off. +env = { CARGO_PROFILE_DEV_DEBUG = "0", CARGO_PROFILE_TEST_DEBUG = "0", CARGO_HOME = "/workspace/.cargo-home", SOURCE_DATE_EPOCH = "0" } +# Unit tests run first, so a failure shows before the release build. The e2e tests then run against +# the binary this job ships, so forge is not compiled a third time just for them. run = """ +cargo test --workspace --exclude forge-e2e cargo build --profile dist -p forge-web -p forge-runner +FORGE_BIN="$PWD/target/dist/forge" cargo test -p forge-e2e ARCH=$(uname -m) cp target/dist/forge forge-$ARCH-linux cp target/dist/forge-runner forge-runner-$ARCH-linux @@ -47,7 +37,7 @@ sha256sum forge-$ARCH-linux forge-runner-$ARCH-linux > SHA256SUMS """ artifacts = ["forge-*-linux", "SHA256SUMS"] cache = ["target", ".cargo-home"] -timeout_minutes = 120 +timeout_minutes = 240 [release] assets = ["build:forge-*-linux", "build:SHA256SUMS"] diff --git a/Cargo.lock b/Cargo.lock index 44aa383..fdb50c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1873,6 +1873,28 @@ dependencies = [ "zip", ] +[[package]] +name = "forge-e2e" +version = "0.1.0" +dependencies = [ + "base64 0.23.1", + "flate2", + "forge-ci", + "forge-core", + "forge-git", + "forge-runner", + "hex", + "reqwest", + "scraper", + "serde_json", + "sha2 0.11.1", + "tar", + "tempfile", + "tokio", + "tokio-util", + "zip", +] + [[package]] name = "forge-git" version = "0.1.0" @@ -1942,18 +1964,16 @@ name = "forge-web" version = "0.1.0" dependencies = [ "aes-gcm 0.11.1", - "ammonia", "async-compression", "base64 0.23.1", "bytes", - "comrak", - "emojis", "flate2", "forge-ci", "forge-core", "forge-git", "forge-runner", "forge-ssh", + "forge-web-base", "form_urlencoded", "futures-util", "grass", @@ -1969,7 +1989,6 @@ dependencies = [ "lettre", "multer", "nix 0.31.3", - "object_store", "p256", "rand 0.10.3", "reqwest", @@ -1980,15 +1999,12 @@ dependencies = [ "sha2 0.11.1", "similar", "subtle", - "syntect", "tar", "tempfile", "time", "tokio", "tokio-util", "topcoat", - "tower", - "tower-http 0.7.1", "tracing", "tracing-subscriber", "ulid", @@ -1998,6 +2014,33 @@ dependencies = [ "zip", ] +[[package]] +name = "forge-web-base" +version = "0.1.0" +dependencies = [ + "ammonia", + "bytes", + "comrak", + "emojis", + "forge-core", + "forge-git", + "futures-util", + "hex", + "http", + "http-body", + "object_store", + "serde_json", + "sha2 0.11.1", + "syntect", + "tempfile", + "time", + "tokio", + "topcoat", + "tower", + "tower-http 0.7.1", + "tracing", +] + [[package]] name = "form_urlencoded" version = "1.2.2" diff --git a/Cargo.toml b/Cargo.toml index b3eea19..0fa9711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,10 @@ members = [ "crates/forge-git", "crates/forge-ssh", "crates/forge-web", + "crates/forge-web-base", "crates/forge-ci", "crates/forge-runner", + "crates/forge-e2e", ] [workspace.package] @@ -31,6 +33,7 @@ forge-ci = { path = "crates/forge-ci" } forge-git = { path = "crates/forge-git" } forge-ssh = { path = "crates/forge-ssh" } forge-runner = { path = "crates/forge-runner" } +forge-web-base = { path = "crates/forge-web-base" } # async runtime and HTTP plumbing tokio = { version = "1.53.3", features = ["full"] } diff --git a/crates/forge-ci/build.rs b/crates/forge-ci/build_identity.rs similarity index 58% rename from crates/forge-ci/build.rs rename to crates/forge-ci/build_identity.rs index c73ed62..9495351 100644 --- a/crates/forge-ci/build.rs +++ b/crates/forge-ci/build_identity.rs @@ -1,11 +1,14 @@ -//! Emits the build identity: the git commit short sha, whether the tree was dirty, and the commit -//! date. It falls back to the FORGE_BUILD_COMMIT and FORGE_BUILD_DATE environment variables when -//! there is no git (a source tarball, a sandbox without the binary), and then to "unknown". -//! The dirty flag is only re-evaluated when HEAD or its ref moves. - -use std::{env, process::Command}; +// Build identity for the binary crates. Not a build script of its own: each binary's build.rs pulls +// this file in with `include!("../forge-ci/build_identity.rs");` and calls `emit_identity()`. It +// emits FORGE_GIT_SHA, FORGE_GIT_DATE and FORGE_GIT_DIRTY for that crate. +// +// Only release builds read git: the commit, its date and the dirty flag, with a rerun when HEAD +// moves. Any other profile emits "unknown" and no per-commit input, so a new commit does not +// rebuild debug or test binaries. Release falls back to the FORGE_BUILD_COMMIT and FORGE_BUILD_DATE +// environment variables when there is no git (a source tarball, a sandbox without the binary). fn git(args: &[&str]) -> Option { + use std::process::Command; let out = Command::new("git").args(args).output().ok()?; if !out.status.success() { return None; @@ -14,10 +17,18 @@ fn git(args: &[&str]) -> Option { (!text.is_empty()).then_some(text) } -fn main() { +pub fn emit_identity() { + use std::env; + + if env::var("PROFILE").as_deref() != Ok("release") { + println!("cargo:rustc-env=FORGE_GIT_SHA=unknown"); + println!("cargo:rustc-env=FORGE_GIT_DATE=unknown"); + println!("cargo:rustc-env=FORGE_GIT_DIRTY=0"); + return; + } + println!("cargo:rerun-if-env-changed=FORGE_BUILD_COMMIT"); println!("cargo:rerun-if-env-changed=FORGE_BUILD_DATE"); - println!("cargo:rerun-if-changed=build.rs"); if let Some(head) = git(&["rev-parse", "--git-path", "HEAD"]) { println!("cargo:rerun-if-changed={head}"); } diff --git a/crates/forge-ci/src/build.rs b/crates/forge-ci/src/build.rs index 743b7f3..a7cd83a 100644 --- a/crates/forge-ci/src/build.rs +++ b/crates/forge-ci/src/build.rs @@ -1,18 +1,48 @@ //! The build identity of this binary: version, git commit, commit date. Shared by the server and //! the runner, which are the same binary, so a runner can be compared to the server it talks to. +use std::sync::OnceLock; + /// The crate version. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -/// Short git sha of the commit built, or "unknown". -pub const COMMIT: &str = env!("FORGE_GIT_SHA"); -/// Commit date (YYYY-MM-DD), or "unknown". -pub const DATE: &str = env!("FORGE_GIT_DATE"); + +struct Identity { + commit: &'static str, + date: &'static str, + dirty: bool, +} + +static IDENTITY: OnceLock = OnceLock::new(); + +/// Sets the commit, commit date and dirty flag of the running binary. Each binary sets this first +/// thing in main, so this crate has no per-commit input and a new commit does not rebuild +/// everything that depends on it. A second call is ignored. +pub fn set_identity(commit: &'static str, date: &'static str, dirty: bool) { + let _ = IDENTITY.set(Identity { + commit, + date, + dirty, + }); +} + +/// Short git sha of the commit built, or "unknown" before [`set_identity`]. +pub fn commit() -> &'static str { + IDENTITY.get().map_or("unknown", |i| i.commit) +} + +/// Commit date (YYYY-MM-DD), or "unknown" before [`set_identity`]. +pub fn date() -> &'static str { + IDENTITY.get().map_or("unknown", |i| i.date) +} + /// True when the tree had uncommitted changes to tracked files at build time. -pub const DIRTY: bool = matches!(env!("FORGE_GIT_DIRTY").as_bytes(), b"1"); +pub fn dirty() -> bool { + IDENTITY.get().is_some_and(|i| i.dirty) +} /// `0.1.0 (cf8e648, 2026-10-20)`, with `cf8e648-dirty` for a dirty tree. pub fn display() -> String { - format_build(VERSION, COMMIT, DATE, DIRTY) + format_build(VERSION, commit(), date(), dirty()) } pub fn format_build(version: &str, commit: &str, date: &str, dirty: bool) -> String { diff --git a/crates/forge-e2e/Cargo.toml b/crates/forge-e2e/Cargo.toml new file mode 100644 index 0000000..64d66b2 --- /dev/null +++ b/crates/forge-e2e/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "forge-e2e" +description = "End-to-end tests for the forge binary: HTTP, git, SSH and CI over real servers" +version.workspace = true +edition.workspace = true +license.workspace = true +publish = false + +[[test]] +name = "e2e" +path = "tests/e2e/main.rs" + +[dev-dependencies] +forge-core.workspace = true +forge-ci.workspace = true +forge-git.workspace = true +forge-runner = { workspace = true, features = ["test-host-executor"] } +tokio.workspace = true +tokio-util = { workspace = true, features = ["io"] } +reqwest.workspace = true +serde_json.workspace = true +base64.workspace = true +sha2.workspace = true +hex.workspace = true +flate2.workspace = true +tar.workspace = true +zip = { workspace = true } +tempfile.workspace = true +scraper = { workspace = true } + +[lints] +workspace = true diff --git a/crates/forge-e2e/src/lib.rs b/crates/forge-e2e/src/lib.rs new file mode 100644 index 0000000..7081258 --- /dev/null +++ b/crates/forge-e2e/src/lib.rs @@ -0,0 +1 @@ +//! End-to-end tests for the forge binary. The tests live in `tests/e2e`. diff --git a/crates/forge-web/tests/e2e/account_mail_e2e.rs b/crates/forge-e2e/tests/e2e/account_mail_e2e.rs similarity index 100% rename from crates/forge-web/tests/e2e/account_mail_e2e.rs rename to crates/forge-e2e/tests/e2e/account_mail_e2e.rs diff --git a/crates/forge-web/tests/e2e/advisories_e2e.rs b/crates/forge-e2e/tests/e2e/advisories_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/advisories_e2e.rs rename to crates/forge-e2e/tests/e2e/advisories_e2e.rs index 8df4478..b6f46f7 100644 --- a/crates/forge-web/tests/e2e/advisories_e2e.rs +++ b/crates/forge-e2e/tests/e2e/advisories_e2e.rs @@ -9,7 +9,7 @@ //! - a reader without Write gets a 404 on the page. use crate::common::{ - BIN, Http, Resp, Server, input_value, launch_with, login, pick_ports, tool_on_path, + Http, Resp, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path, write_config_with, }; use std::fs; @@ -122,7 +122,7 @@ async fn boot() -> Booted { } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/branch_protection_e2e.rs b/crates/forge-e2e/tests/e2e/branch_protection_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/branch_protection_e2e.rs rename to crates/forge-e2e/tests/e2e/branch_protection_e2e.rs index d3f0908..02aad80 100644 --- a/crates/forge-web/tests/e2e/branch_protection_e2e.rs +++ b/crates/forge-e2e/tests/e2e/branch_protection_e2e.rs @@ -3,7 +3,7 @@ //! while the server runs. Helpers mirror `git_e2e.rs`. use crate::common::{ - BIN, Http, Ports, Server, describe, input_value, launch, login, pick_ports, relaunch, + Http, Ports, Server, bin, describe, input_value, launch, login, pick_ports, relaunch, tool_on_path, write_config, }; use std::fs; @@ -15,7 +15,7 @@ use forge_core::Store; const TAHINLI_PW: &str = "tahinli-password-123"; fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/browse_e2e.rs b/crates/forge-e2e/tests/e2e/browse_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/browse_e2e.rs rename to crates/forge-e2e/tests/e2e/browse_e2e.rs index f237716..8b5497f 100644 --- a/crates/forge-web/tests/e2e/browse_e2e.rs +++ b/crates/forge-e2e/tests/e2e/browse_e2e.rs @@ -5,7 +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. -use crate::common::{BIN, describe, input_value, 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}; @@ -147,7 +147,7 @@ fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &s } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/ci_e2e.rs b/crates/forge-e2e/tests/e2e/ci_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/ci_e2e.rs rename to crates/forge-e2e/tests/e2e/ci_e2e.rs index eb8f9d1..5c3e99c 100644 --- a/crates/forge-web/tests/e2e/ci_e2e.rs +++ b/crates/forge-e2e/tests/e2e/ci_e2e.rs @@ -11,7 +11,7 @@ //! - a live log: `log.txt` streams while a job runs and ends when the job finishes. use crate::common::{ - BIN, FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, write_config, + FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, write_config, }; use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest}; use forge_runner::client::ForgeClient; @@ -104,7 +104,7 @@ fn first_text(body: &str, selector: &str) -> String { } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/common/http.rs b/crates/forge-e2e/tests/e2e/common/http.rs similarity index 100% rename from crates/forge-web/tests/e2e/common/http.rs rename to crates/forge-e2e/tests/e2e/common/http.rs diff --git a/crates/forge-web/tests/e2e/common/mod.rs b/crates/forge-e2e/tests/e2e/common/mod.rs similarity index 82% rename from crates/forge-web/tests/e2e/common/mod.rs rename to crates/forge-e2e/tests/e2e/common/mod.rs index 3a42540..06e8b13 100644 --- a/crates/forge-web/tests/e2e/common/mod.rs +++ b/crates/forge-e2e/tests/e2e/common/mod.rs @@ -13,13 +13,55 @@ use std::fs; use std::net::TcpStream; use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; +use std::sync::OnceLock; use std::time::{Duration, Instant}; mod http; pub use http::{Http, Resp, cookie_named, login}; -pub const BIN: &str = env!("CARGO_BIN_EXE_forge"); +/// The forge binary the tests start. `env!("CARGO_BIN_EXE_forge")` would only work in the package +/// that owns the binary, and these tests live in `forge-e2e`, which does not depend on forge-web. +/// CI sets `FORGE_BIN` to the prebuilt release binary. Without it, the dev-profile binary is built +/// once per test run, so `cargo test --workspace` works with no extra steps. +pub fn bin() -> &'static str { + static BIN: OnceLock = OnceLock::new(); + BIN.get_or_init(|| match std::env::var("FORGE_BIN") { + Ok(path) if !path.is_empty() => path, + _ => build_forge(), + }) + .as_str() +} + +/// Builds `forge` with cargo and returns the executable path cargo reports for it. +fn build_forge() -> String { + let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned()); + let output = Command::new(&cargo) + .args([ + "build", + "-p", + "forge-web", + "--bin", + "forge", + "--message-format=json-render-diagnostics", + ]) + .current_dir(env!("CARGO_MANIFEST_DIR")) + .stderr(Stdio::inherit()) + .output() + .unwrap_or_else(|e| panic!("failed to run `{cargo} build -p forge-web --bin forge`: {e}")); + assert!( + output.status.success(), + "`{cargo} build -p forge-web --bin forge` failed ({})", + output.status + ); + let stdout = String::from_utf8(output.stdout).expect("cargo output is UTF-8"); + stdout + .lines() + .filter_map(|line| serde_json::from_str::(line).ok()) + .find(|msg| msg["reason"] == "compiler-artifact" && msg["target"]["name"] == "forge") + .and_then(|msg| msg["executable"].as_str().map(str::to_owned)) + .unwrap_or_else(|| panic!("cargo build reported no executable for the forge binary")) +} /// How long a freshly spawned server gets to answer on all three listeners. const READY_TIMEOUT: Duration = Duration::from_secs(30); @@ -180,7 +222,7 @@ pub async fn relaunch(config: &Path, log_path: &Path, ports: Ports) -> Server { fn spawn(config: &Path, log_path: &Path) -> Server { let log = fs::File::create(log_path).expect("log file"); - let child = Command::new(BIN) + let child = Command::new(bin()) .arg("--config") .arg(config) .arg("serve") diff --git a/crates/forge-web/tests/e2e/community_i18n_e2e.rs b/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs similarity index 95% rename from crates/forge-web/tests/e2e/community_i18n_e2e.rs rename to crates/forge-e2e/tests/e2e/community_i18n_e2e.rs index 316d86f..d5630d5 100644 --- a/crates/forge-web/tests/e2e/community_i18n_e2e.rs +++ b/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs @@ -4,14 +4,14 @@ use std::process::Command; use std::time::Duration; -use crate::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"; /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &std::path::Path, args: &[&str]) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/discussions_e2e.rs b/crates/forge-e2e/tests/e2e/discussions_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/discussions_e2e.rs rename to crates/forge-e2e/tests/e2e/discussions_e2e.rs index 2f91fe6..67ea2dd 100644 --- a/crates/forge-web/tests/e2e/discussions_e2e.rs +++ b/crates/forge-e2e/tests/e2e/discussions_e2e.rs @@ -4,7 +4,7 @@ //! owner can still write. use crate::common::{ - BIN, Http, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, bin, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::path::Path; use std::process::Command; @@ -13,7 +13,7 @@ const TAHINLI_PW: &str = "tahinli-password-123"; const BOB_PW: &str = "bob-password-4567"; fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/git_e2e.rs b/crates/forge-e2e/tests/e2e/git_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/git_e2e.rs rename to crates/forge-e2e/tests/e2e/git_e2e.rs index 4279ac8..2903676 100644 --- a/crates/forge-web/tests/e2e/git_e2e.rs +++ b/crates/forge-e2e/tests/e2e/git_e2e.rs @@ -5,7 +5,7 @@ //! cookie jar would not send it over plain http. The test parses `Set-Cookie` and sends `Cookie`. use crate::common::{ - BIN, Http, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; use std::path::{Path, PathBuf}; @@ -17,7 +17,7 @@ const TAHINLI_PW: &str = "tahinli-password-123"; const BOB_PW: &str = "bob-password-4567"; fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/i18n_e2e.rs b/crates/forge-e2e/tests/e2e/i18n_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/i18n_e2e.rs rename to crates/forge-e2e/tests/e2e/i18n_e2e.rs index 2457498..7e682da 100644 --- a/crates/forge-web/tests/e2e/i18n_e2e.rs +++ b/crates/forge-e2e/tests/e2e/i18n_e2e.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use crate::common::{ - BIN, Http, Server, describe, input_value, launch, login, pick_ports, write_config, + Http, Server, bin, describe, input_value, launch, login, pick_ports, write_config, }; use forge_core::Store; @@ -13,7 +13,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/issue_close_e2e.rs b/crates/forge-e2e/tests/e2e/issue_close_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/issue_close_e2e.rs rename to crates/forge-e2e/tests/e2e/issue_close_e2e.rs index 7e76eff..339070d 100644 --- a/crates/forge-web/tests/e2e/issue_close_e2e.rs +++ b/crates/forge-e2e/tests/e2e/issue_close_e2e.rs @@ -4,7 +4,7 @@ //! file, and every push is a real `git push` through the git HTTP endpoints. use crate::common::{ - BIN, Http, input_value, launch, login, pick_ports, relaunch, tool_on_path, write_config, + Http, bin, input_value, launch, login, pick_ports, relaunch, tool_on_path, write_config, }; use std::fs; use std::future::Future; @@ -18,7 +18,7 @@ const TAHINLI_PW: &str = "tahinli-password-123"; const BOB_PW: &str = "bob-password-4567"; fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/lfs_e2e.rs b/crates/forge-e2e/tests/e2e/lfs_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/lfs_e2e.rs rename to crates/forge-e2e/tests/e2e/lfs_e2e.rs index 0eefd92..894e475 100644 --- a/crates/forge-web/tests/e2e/lfs_e2e.rs +++ b/crates/forge-e2e/tests/e2e/lfs_e2e.rs @@ -5,7 +5,7 @@ //! Git config is isolated from the developer's machine: `HOME` and `GIT_CONFIG_GLOBAL` point into //! the test's temp dir. -use crate::common::{BIN, Http, describe, input_value, launch, login, pick_ports, write_config}; +use crate::common::{Http, bin, describe, input_value, launch, login, pick_ports, write_config}; use std::fs; use std::path::Path; use std::process::{Command, Output}; @@ -14,7 +14,7 @@ const TAHINLI_PW: &str = "tahinli-password-123"; const FILE_SIZE: usize = 100 * 1024; fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/main.rs b/crates/forge-e2e/tests/e2e/main.rs similarity index 100% rename from crates/forge-web/tests/e2e/main.rs rename to crates/forge-e2e/tests/e2e/main.rs diff --git a/crates/forge-web/tests/e2e/merge_queue_e2e.rs b/crates/forge-e2e/tests/e2e/merge_queue_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/merge_queue_e2e.rs rename to crates/forge-e2e/tests/e2e/merge_queue_e2e.rs index 4c71e86..9d2ac4e 100644 --- a/crates/forge-web/tests/e2e/merge_queue_e2e.rs +++ b/crates/forge-e2e/tests/e2e/merge_queue_e2e.rs @@ -10,7 +10,7 @@ #![allow(dead_code)] use crate::common::{ - BIN, FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, tool_on_path, + FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path, write_config, }; use forge_ci::proto::{JobAssignment, RegisterRequest}; @@ -46,7 +46,7 @@ fn first_text(body: &str, selector: &str) -> String { } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/mirrors_e2e.rs b/crates/forge-e2e/tests/e2e/mirrors_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/mirrors_e2e.rs rename to crates/forge-e2e/tests/e2e/mirrors_e2e.rs index 9e5f7db..ae7fd13 100644 --- a/crates/forge-web/tests/e2e/mirrors_e2e.rs +++ b/crates/forge-e2e/tests/e2e/mirrors_e2e.rs @@ -10,7 +10,7 @@ //! - the mirror pages and the server log never contain the access token. use crate::common::{ - BIN, Http, Server, input_value, launch_with, login, pick_ports, tool_on_path, write_config_with, + Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path, write_config_with, }; use std::collections::BTreeSet; use std::fs; @@ -37,7 +37,7 @@ fn form_actions(body: &str, suffix: &str) -> Vec { } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/oci_e2e.rs b/crates/forge-e2e/tests/e2e/oci_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/oci_e2e.rs rename to crates/forge-e2e/tests/e2e/oci_e2e.rs index 66a365b..efdd7e0 100644 --- a/crates/forge-web/tests/e2e/oci_e2e.rs +++ b/crates/forge-e2e/tests/e2e/oci_e2e.rs @@ -5,7 +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. -use crate::common::{BIN, Server, describe, launch, pick_ports, tool_on_path, write_config}; +use crate::common::{Server, bin, describe, launch, pick_ports, tool_on_path, write_config}; use std::path::Path; use std::process::Command; use std::time::Duration; @@ -118,7 +118,7 @@ impl Http { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/orgs_core_e2e.rs b/crates/forge-e2e/tests/e2e/orgs_core_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/orgs_core_e2e.rs rename to crates/forge-e2e/tests/e2e/orgs_core_e2e.rs index 35187c5..57e993b 100644 --- a/crates/forge-web/tests/e2e/orgs_core_e2e.rs +++ b/crates/forge-e2e/tests/e2e/orgs_core_e2e.rs @@ -4,7 +4,7 @@ //! are written straight into the database before the server starts. use crate::common::{ - BIN, Http, Resp, Server, cookie_named, describe, input_value, launch, pick_ports, write_config, + Http, Resp, Server, bin, cookie_named, describe, input_value, launch, pick_ports, write_config, }; use std::future::Future; use std::path::{Path, PathBuf}; @@ -25,7 +25,7 @@ const ORG_SESSION: &str = "org-session-token-for-tests-0123456789"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/orgs_live_e2e.rs b/crates/forge-e2e/tests/e2e/orgs_live_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/orgs_live_e2e.rs rename to crates/forge-e2e/tests/e2e/orgs_live_e2e.rs index 42386ad..52ba037 100644 --- a/crates/forge-web/tests/e2e/orgs_live_e2e.rs +++ b/crates/forge-e2e/tests/e2e/orgs_live_e2e.rs @@ -3,7 +3,7 @@ //! and reads each stream. It also checks that each stream refuses the viewers its page refuses. use crate::common::{ - BIN, Http, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::path::Path; use std::process::{Command, Output}; @@ -30,7 +30,7 @@ fn live_url(body: &str) -> Option { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/orgs_ui_e2e.rs b/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/orgs_ui_e2e.rs rename to crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs index 9860ab0..bc332f9 100644 --- a/crates/forge-web/tests/e2e/orgs_ui_e2e.rs +++ b/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs @@ -4,7 +4,7 @@ //! handled by hand, as in `repo_collaborators_e2e.rs`. use crate::common::{ - BIN, Http, Resp, describe, input_value, launch, launch_with, login, pick_ports, tool_on_path, + Http, Resp, bin, describe, input_value, launch, launch_with, login, pick_ports, tool_on_path, write_config, }; use std::fs; @@ -43,7 +43,7 @@ fn owner_options(body: &str) -> Vec { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/packages_e2e.rs b/crates/forge-e2e/tests/e2e/packages_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/packages_e2e.rs rename to crates/forge-e2e/tests/e2e/packages_e2e.rs index 585a0d5..e66bd4d 100644 --- a/crates/forge-web/tests/e2e/packages_e2e.rs +++ b/crates/forge-e2e/tests/e2e/packages_e2e.rs @@ -4,7 +4,7 @@ //! private package are seeded through the store before the server starts, since the web API has //! no way to make a package private. -use crate::common::{BIN, Server, describe, launch, pick_ports, write_config}; +use crate::common::{Server, bin, describe, launch, pick_ports, write_config}; use std::io::Write; use std::path::Path; use std::process::Command; @@ -90,7 +90,7 @@ impl Http { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/pulls_e2e.rs b/crates/forge-e2e/tests/e2e/pulls_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/pulls_e2e.rs rename to crates/forge-e2e/tests/e2e/pulls_e2e.rs index 0a3b3c9..99561c8 100644 --- a/crates/forge-web/tests/e2e/pulls_e2e.rs +++ b/crates/forge-e2e/tests/e2e/pulls_e2e.rs @@ -6,7 +6,7 @@ //! a fork pull merged by squash, and a conflict that blocks the merge. use crate::common::{ - BIN, Http, Resp, Server, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, Resp, Server, bin, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; use std::path::{Path, PathBuf}; @@ -31,7 +31,7 @@ fn state_badge(body: &str) -> String { } fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .args(["admin", "create-user", username]) diff --git a/crates/forge-web/tests/e2e/repo_collaborators_e2e.rs b/crates/forge-e2e/tests/e2e/repo_collaborators_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/repo_collaborators_e2e.rs rename to crates/forge-e2e/tests/e2e/repo_collaborators_e2e.rs index f24bda6..d3eae5a 100644 --- a/crates/forge-web/tests/e2e/repo_collaborators_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_collaborators_e2e.rs @@ -3,7 +3,7 @@ //! its POST forms over HTTP. Cookies are handled by hand (see `repo_settings_e2e.rs`). use crate::common::{ - BIN, Http, Resp, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path, + Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; @@ -17,7 +17,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/repo_rename_e2e.rs b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/repo_rename_e2e.rs rename to crates/forge-e2e/tests/e2e/repo_rename_e2e.rs index d3ad954..2a6f8c7 100644 --- a/crates/forge-web/tests/e2e/repo_rename_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs @@ -6,7 +6,7 @@ //! which a cookie jar would not send over plain http. use crate::common::{ - BIN, Http, Resp, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, Resp, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; use std::path::Path; @@ -30,7 +30,7 @@ fn form_action(body: &str, suffix: &str) -> String { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/repo_settings_e2e.rs b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/repo_settings_e2e.rs rename to crates/forge-e2e/tests/e2e/repo_settings_e2e.rs index 72ac003..10df6ef 100644 --- a/crates/forge-web/tests/e2e/repo_settings_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs @@ -5,7 +5,7 @@ //! which a cookie jar would not send over plain http. use crate::common::{ - BIN, Http, Resp, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path, + Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; @@ -19,7 +19,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/repo_transfer_e2e.rs b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/repo_transfer_e2e.rs rename to crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs index 8e9e8ab..03e0eda 100644 --- a/crates/forge-web/tests/e2e/repo_transfer_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs @@ -6,7 +6,7 @@ //! which a cookie jar would not send over plain http. use crate::common::{ - BIN, Http, Resp, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, Resp, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; use std::process::Command; @@ -30,7 +30,7 @@ fn form_action(body: &str, suffix: &str) -> String { /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &std::path::Path, args: &[&str]) { - let out = Command::new(BIN) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/runner_subcommand.rs b/crates/forge-e2e/tests/e2e/runner_subcommand.rs similarity index 98% rename from crates/forge-web/tests/e2e/runner_subcommand.rs rename to crates/forge-e2e/tests/e2e/runner_subcommand.rs index 84c17e3..7ed366d 100644 --- a/crates/forge-web/tests/e2e/runner_subcommand.rs +++ b/crates/forge-e2e/tests/e2e/runner_subcommand.rs @@ -8,8 +8,10 @@ use std::process::Command; use tempfile::TempDir; +use crate::common::bin; + fn forge() -> Command { - Command::new(env!("CARGO_BIN_EXE_forge")) + Command::new(bin()) } /// Unprivileged user namespaces, as `crates/forge-runner/tests/sandbox.rs` checks them. diff --git a/crates/forge-web/tests/e2e/section_nav_e2e.rs b/crates/forge-e2e/tests/e2e/section_nav_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/section_nav_e2e.rs rename to crates/forge-e2e/tests/e2e/section_nav_e2e.rs index 3a52f3d..58b9a8b 100644 --- a/crates/forge-web/tests/e2e/section_nav_e2e.rs +++ b/crates/forge-e2e/tests/e2e/section_nav_e2e.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] -use crate::common::{BIN, Http, Server, describe, launch, login, pick_ports, write_config}; +use crate::common::{Http, Server, bin, describe, launch, login, pick_ports, write_config}; use std::path::Path; use std::process::Command; @@ -93,7 +93,7 @@ fn theme_button(body: &str) -> (String, String) { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/snippets_e2e.rs b/crates/forge-e2e/tests/e2e/snippets_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/snippets_e2e.rs rename to crates/forge-e2e/tests/e2e/snippets_e2e.rs index d72537a..2b7c710 100644 --- a/crates/forge-web/tests/e2e/snippets_e2e.rs +++ b/crates/forge-e2e/tests/e2e/snippets_e2e.rs @@ -3,7 +3,7 @@ //! `Secure`. Files are fetched from the user-content listener, as a browser would. use crate::common::{ - BIN, Http, Server, describe, input_value, launch, login, pick_ports, write_config, + Http, Server, bin, describe, input_value, launch, login, pick_ports, write_config, }; use std::path::{Path, PathBuf}; use std::process::Command; @@ -35,7 +35,7 @@ fn link_href(body: &str, text: &str) -> String { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/stars_e2e.rs b/crates/forge-e2e/tests/e2e/stars_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/stars_e2e.rs rename to crates/forge-e2e/tests/e2e/stars_e2e.rs index f89d4a7..ad3cc62 100644 --- a/crates/forge-web/tests/e2e/stars_e2e.rs +++ b/crates/forge-e2e/tests/e2e/stars_e2e.rs @@ -3,7 +3,7 @@ //! HTTP. Cookies are set by hand because the session cookie is `__Host-` and `Secure`. use crate::common::{ - BIN, Http, Resp, Server, describe, input_value, launch, login, pick_ports, tool_on_path, + Http, Resp, Server, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; @@ -17,7 +17,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/ui_prefs_e2e.rs b/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/ui_prefs_e2e.rs rename to crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs index 462362d..559f523 100644 --- a/crates/forge-web/tests/e2e/ui_prefs_e2e.rs +++ b/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs @@ -4,7 +4,7 @@ //! because the session cookie is `__Host-` and `Secure`. use crate::common::{ - BIN, Http, Server, cookie_named, describe, input_value, launch, login, pick_ports, write_config, + Http, Server, bin, cookie_named, describe, input_value, launch, login, pick_ports, write_config, }; use std::path::Path; use std::process::Command; @@ -105,7 +105,7 @@ fn pressed_theme(body: &str) -> Option { /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/user_delete_e2e.rs b/crates/forge-e2e/tests/e2e/user_delete_e2e.rs similarity index 98% rename from crates/forge-web/tests/e2e/user_delete_e2e.rs rename to crates/forge-e2e/tests/e2e/user_delete_e2e.rs index bb4641f..e59c1d8 100644 --- a/crates/forge-web/tests/e2e/user_delete_e2e.rs +++ b/crates/forge-e2e/tests/e2e/user_delete_e2e.rs @@ -4,7 +4,7 @@ //! session cookie is `__Host-` and `Secure`. use crate::common::{ - BIN, Http, Resp, Server, cookie_named, describe, input_value, launch, login, pick_ports, + Http, Resp, Server, bin, cookie_named, describe, input_value, launch, login, pick_ports, write_config, }; use std::fs; @@ -23,7 +23,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-web/tests/e2e/wiki_e2e.rs b/crates/forge-e2e/tests/e2e/wiki_e2e.rs similarity index 99% rename from crates/forge-web/tests/e2e/wiki_e2e.rs rename to crates/forge-e2e/tests/e2e/wiki_e2e.rs index dea89ec..e6cde93 100644 --- a/crates/forge-web/tests/e2e/wiki_e2e.rs +++ b/crates/forge-e2e/tests/e2e/wiki_e2e.rs @@ -6,7 +6,7 @@ //! which a cookie jar would not send over plain http. use crate::common::{ - BIN, Http, Resp, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, + Http, Resp, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config, }; use std::fs; use std::path::Path; @@ -20,7 +20,7 @@ const PW: &str = "tahinli-password-123"; /// 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) + let out = Command::new(bin()) .arg("--config") .arg(config) .arg("admin") diff --git a/crates/forge-runner/build.rs b/crates/forge-runner/build.rs new file mode 100644 index 0000000..9fb9bad --- /dev/null +++ b/crates/forge-runner/build.rs @@ -0,0 +1,10 @@ +//! Emits the build identity (FORGE_GIT_SHA, FORGE_GIT_DATE, FORGE_GIT_DIRTY) for this binary. +//! The logic lives in forge-ci's build_identity.rs, shared with forge-web. + +include!("../forge-ci/build_identity.rs"); + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=../forge-ci/build_identity.rs"); + emit_identity(); +} diff --git a/crates/forge-runner/src/cache.rs b/crates/forge-runner/src/cache.rs index f5e46c7..e962a81 100644 --- a/crates/forge-runner/src/cache.rs +++ b/crates/forge-runner/src/cache.rs @@ -6,13 +6,16 @@ //! Layout under `work_dir/.cache`. The leading dot keeps it apart from job dirs, since job ids //! never start with one: //! - `/` is one entry. It holds `p0`, `p1`, ... for the cached -//! paths, `manifest.json` (the workspace path of each `pN`) and `meta.json`. +//! paths, `manifest.json` (the workspace path of each `pN`), `meta.json` and `stamps.json`. //! - `.new-` and `.old-` are one job's scratch dirs. A crashed job can leave them behind, //! and [`CacheStore::sweep_stale`] removes them at startup. `.inuse-` is swept too: older //! runners moved an entry there while a job used it. +//! - `.stamps-` is one job's file of tracked-file stamps, written at restore and copied into +//! the entry at save. It sits here, not in the workspace, so the job cannot change it. //! //! A restore never fails a job. A failure is logged and the job runs without the cache. +use std::collections::BTreeMap; use std::fs; use std::io; use std::path::{Component, Path, PathBuf}; @@ -37,7 +40,8 @@ const MAX_KEY_LEN: usize = 256; const MAX_STDERR: usize = 500; const MANIFEST: &str = "manifest.json"; const META: &str = "meta.json"; -const SCRATCH_PREFIXES: [&str; 3] = [".inuse-", ".new-", ".old-"]; +const STAMPS: &str = "stamps.json"; +const SCRATCH_PREFIXES: [&str; 4] = [".inuse-", ".new-", ".old-", ".stamps-"]; /// Errors from the build cache. They are logged to the job, never returned to the forge. #[derive(Debug, thiserror::Error)] @@ -52,6 +56,24 @@ pub enum CacheError { NotDir(PathBuf), #[error("cp failed: {0}")] Copy(String), + #[error("git ls-tree failed: {0}")] + Git(String), +} + +/// One tracked file's stamp: the blob it had and the mtime it was given, in Unix seconds. +#[derive(Debug, Clone, Serialize, Deserialize)] +struct Stamp { + blob: String, + mtime: i64, +} + +/// Tracked file path to its stamp. Read from `stamps.json`, and written to the job's scratch file. +type Stamps = BTreeMap; + +/// What one restored entry gave the job: its size and the stamps it recorded. +struct Restored { + size: u64, + stamps: Stamps, } /// What `meta.json` records about one entry. @@ -136,15 +158,17 @@ impl CacheStore { }; if !job.cache_key.is_empty() - && let Some(size) = self + && let Some(restored) = self .restore_from(job, &job.cache_key, workspace, &wanted, &mut lines) .await { lines.push(format!( "runner: cache hit {} ({})", job.cache_key, - human(size) + human(restored.size) )); + self.stamp_files(job, workspace, &restored.stamps, &mut lines) + .await; return lines; } @@ -152,16 +176,19 @@ impl CacheStore { if key.is_empty() || key.len() > MAX_KEY_LEN { continue; } - if self + if let Some(restored) = self .restore_from(job, key, workspace, &wanted, &mut lines) .await - .is_some() { lines.push(format!("runner: cache restored from fallback {key}")); + self.stamp_files(job, workspace, &restored.stamps, &mut lines) + .await; return lines; } } lines.push("runner: cache miss".to_owned()); + self.stamp_files(job, workspace, &Stamps::new(), &mut lines) + .await; lines } @@ -193,7 +220,7 @@ impl CacheStore { } /// Copies the entry for `key`'s wanted paths into the workspace. The entry is left as it is. - /// Returns the entry size when at least one path was restored. + /// Returns the entry size and stamps when at least one path was restored. async fn restore_from( &self, job: &JobAssignment, @@ -201,7 +228,7 @@ impl CacheStore { workspace: &Path, wanted: &[PathBuf], lines: &mut Vec, - ) -> Option { + ) -> Option { let _guard = self.lock.read().await; let source = self.entry_dir(&job.repo, &job.job_name, key); if !is_dir(&source) { @@ -214,6 +241,8 @@ impl CacheStore { return None; } }; + // Read under the lock, so the stamps belong to the entry copied here. + let stamps = read_stamps(&source); let mut restored = 0usize; for (k, rel) in selected(&manifest, wanted, lines) { let src = source.join(format!("p{k}")); @@ -229,10 +258,117 @@ impl CacheStore { if restored == 0 { return None; } - Some(match read_meta(&source) { + let size = match read_meta(&source) { Some(meta) => meta.size_bytes, None => dir_size(&source).await, + }; + Some(Restored { size, stamps }) + } + + /// Sets each tracked file's mtime to when its content last changed. A file whose blob matches + /// `previous` keeps that stamp, and any other file gets the current time. The new stamps go to + /// the job's scratch file for the save. Never fails the job. + async fn stamp_files( + &self, + job: &JobAssignment, + workspace: &Path, + previous: &Stamps, + lines: &mut Vec, + ) { + match self.try_stamp_files(job, workspace, previous).await { + Ok((kept, changed)) => { + if !previous.is_empty() { + lines.push(format!( + "runner: file times restored ({kept} unchanged, {changed} changed)" + )); + } + } + Err(e) => lines.push(format!("runner: cache stamps skipped: {e}")), + } + } + + /// The work of [`CacheStore::stamp_files`]. Returns how many files kept their stamp and how + /// many got the current time. + async fn try_stamp_files( + &self, + job: &JobAssignment, + workspace: &Path, + previous: &Stamps, + ) -> Result<(usize, usize), CacheError> { + // The checkout is at the job's commit, so HEAD lists exactly the tracked files. + let listing = Command::new("git") + .arg("-C") + .arg(workspace) + .args(["ls-tree", "-r", "-z", "HEAD"]) + .stdin(Stdio::null()) + .stderr(Stdio::piped()) + .kill_on_drop(true) + .output() + .await?; + if !listing.status.success() { + let stderr: String = String::from_utf8_lossy(&listing.stderr) + .chars() + .take(MAX_STDERR) + .collect(); + return Err(CacheError::Git(stderr.trim().to_owned())); + } + + let now = unix_secs(SystemTime::now()); + let mut stamps = Stamps::new(); + let mut files = Vec::new(); + let (mut kept, mut changed) = (0usize, 0usize); + // Records are ` \t`, NUL terminated. Only regular files count. + for record in listing.stdout.split(|b| *b == 0).filter(|r| !r.is_empty()) { + let Some(tab) = record.iter().position(|b| *b == b'\t') else { + continue; + }; + let (info, path) = (&record[..tab], &record[tab + 1..]); + let (Ok(info), Ok(path)) = (std::str::from_utf8(info), std::str::from_utf8(path)) + else { + continue; + }; + let mut fields = info.split(' '); + let mode = fields.next(); + let blob = fields.nth(1); + let (Some(mode), Some(blob)) = (mode, blob) else { + continue; + }; + if mode != "100644" && mode != "100755" { + continue; + } + let mtime = match previous.get(path) { + Some(old) if old.blob == blob => { + kept += 1; + old.mtime + } + _ => { + changed += 1; + now + } + }; + stamps.insert( + path.to_owned(), + Stamp { + blob: blob.to_owned(), + mtime, + }, + ); + files.push((workspace.join(path), mtime)); + } + + tokio::task::spawn_blocking(move || { + for (path, secs) in &files { + // A file that cannot be stamped keeps its checkout time. That is not a failure. + let _ = time_of(*secs).and_then(|time| set_mtime(path, time)); + } }) + .await + .map_err(io::Error::other)?; + + // A first job on a fresh runner gets here before any save has made the root. + tokio::fs::create_dir_all(&self.root).await?; + write_json(&self.scratch(".stamps-", &job.job_id), &stamps).await?; + Ok((kept, changed)) } /// Builds the new entry in `.new-` and installs it over the old one. Caller has checked @@ -272,6 +408,11 @@ impl CacheStore { // Measured before the metadata files are written, so the size is the cached data only. let size = dir_size(&new).await; + // The stamps the job's restore wrote. Missing when the restore did not get that far. + let stamps = self.scratch(".stamps-", &job.job_id); + if exists_no_follow(&stamps) { + tokio::fs::copy(&stamps, new.join(STAMPS)).await?; + } write_json(&new.join(MANIFEST), &manifest).await?; let meta = Meta { repo: job.repo.clone(), @@ -585,6 +726,38 @@ fn read_meta(dir: &Path) -> Option { serde_json::from_slice(&bytes).ok() } +/// The stamps an entry recorded. An entry without a readable `stamps.json` has none. +fn read_stamps(dir: &Path) -> Stamps { + fs::read(dir.join(STAMPS)) + .ok() + .and_then(|bytes| serde_json::from_slice(&bytes).ok()) + .unwrap_or_default() +} + +/// Sets a regular file's modification time. A symlink or other kind is refused, not followed. +fn set_mtime(path: &Path, time: SystemTime) -> io::Result<()> { + if !fs::symlink_metadata(path)?.is_file() { + return Err(io::Error::other("not a regular file")); + } + fs::File::open(path)?.set_modified(time) +} + +/// A stamp's Unix seconds as a time. Negative or out of range values are refused. +fn time_of(secs: i64) -> io::Result { + u64::try_from(secs) + .ok() + .and_then(|s| UNIX_EPOCH.checked_add(Duration::from_secs(s))) + .ok_or_else(|| io::Error::other("time out of range")) +} + +/// Unix seconds of `now`, or 0 before the epoch. +fn unix_secs(now: SystemTime) -> i64 { + now.duration_since(UNIX_EPOCH) + .ok() + .and_then(|d| i64::try_from(d.as_secs()).ok()) + .unwrap_or(0) +} + fn read_manifest(dir: &Path) -> Result, CacheError> { let bytes = fs::read(dir.join(MANIFEST))?; serde_json::from_slice(&bytes).map_err(|e| CacheError::Io(io::Error::other(e))) @@ -1010,4 +1183,97 @@ mod tests { } assert!(keep.is_dir(), "entries are kept"); } + + /// Runs git in `dir` with a fixed identity. Fails the test when git fails. + fn git(dir: &Path, args: &[&str]) { + let ok = std::process::Command::new("git") + .arg("-C") + .arg(dir) + .args(args) + .env("GIT_AUTHOR_NAME", "ci") + .env("GIT_AUTHOR_EMAIL", "ci@example.com") + .env("GIT_COMMITTER_NAME", "ci") + .env("GIT_COMMITTER_EMAIL", "ci@example.com") + .status() + .expect("git runs") + .success(); + assert!(ok, "git {args:?} failed"); + } + + fn mtime_secs(path: &Path) -> u64 { + fs::metadata(path) + .and_then(|m| m.modified()) + .expect("mtime") + .duration_since(UNIX_EPOCH) + .expect("after the epoch") + .as_secs() + } + + #[tokio::test] + async fn unchanged_files_keep_their_stamp_and_changed_files_get_a_new_one() { + let dir = tempfile::tempdir().expect("tempdir"); + let store = store(dir.path(), 1 << 30); + let origin = dir.path().join("origin"); + let origin_str = origin.to_str().expect("utf8 path").to_owned(); + fs::create_dir_all(&origin).expect("mkdir"); + git(&origin, &["init", "--quiet"]); + fs::write(origin.join("a.txt"), "a").expect("write"); + fs::write(origin.join("b.txt"), "b").expect("write"); + git(&origin, &["add", "."]); + git( + &origin, + &[ + "-c", + "commit.gpgsign=false", + "commit", + "--quiet", + "-m", + "one", + ], + ); + + // The first run is a miss. It saves an entry from its checkout. + git(dir.path(), &["clone", "--quiet", &origin_str, "ws1"]); + let ws1 = dir.path().join("ws1"); + let first = job("job_1", "ref:main", &[], &["target"]); + store.restore(&first, &ws1).await; + fs::create_dir_all(ws1.join("target")).expect("mkdir"); + fs::write(ws1.join("target/out.bin"), "built").expect("write"); + store.save(&first, Outcome::Success, &ws1).await; + let a_stamp = mtime_secs(&ws1.join("a.txt")); + + // The next commit changes only b.txt. The sleep makes a new stamp a later second. + fs::write(origin.join("b.txt"), "b2").expect("write"); + git(&origin, &["add", "."]); + git( + &origin, + &[ + "-c", + "commit.gpgsign=false", + "commit", + "--quiet", + "-m", + "two", + ], + ); + git(dir.path(), &["clone", "--quiet", &origin_str, "ws2"]); + tokio::time::sleep(Duration::from_millis(1100)).await; + + let ws2 = dir.path().join("ws2"); + let second = job("job_2", "ref:main", &[], &["target"]); + let lines = store.restore(&second, &ws2).await; + assert!( + lines.contains(&"runner: file times restored (1 unchanged, 1 changed)".to_owned()), + "{lines:?}" + ); + assert_eq!( + mtime_secs(&ws2.join("a.txt")), + a_stamp, + "unchanged keeps its stamp" + ); + assert!( + mtime_secs(&ws2.join("b.txt")) > a_stamp, + "a changed file is newer" + ); + } } diff --git a/crates/forge-runner/src/main.rs b/crates/forge-runner/src/main.rs index 87c5ec2..5ca0f16 100644 --- a/crates/forge-runner/src/main.rs +++ b/crates/forge-runner/src/main.rs @@ -5,6 +5,11 @@ use std::process::ExitCode; fn main() -> ExitCode { + forge_ci::build::set_identity( + env!("FORGE_GIT_SHA"), + env!("FORGE_GIT_DATE"), + matches!(env!("FORGE_GIT_DIRTY").as_bytes(), b"1"), + ); // The hidden helpers run before any runtime or subscriber exists. if forge_runner::cli::is_sandbox_invocation() { std::process::exit(forge_runner::cli::hidden_main()); diff --git a/crates/forge-web-base/Cargo.toml b/crates/forge-web-base/Cargo.toml new file mode 100644 index 0000000..be748df --- /dev/null +++ b/crates/forge-web-base/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "forge-web-base" +description = "forge web building blocks that do not depend on the pages: i18n, rendering, themes, templates, blobs and compression" +version.workspace = true +edition.workspace = true +license.workspace = true +publish = false + +[dependencies] +forge-core.workspace = true +forge-git.workspace = true +topcoat = { workspace = true, default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "compression", "multipart", "tower"] } +tokio.workspace = true +futures-util.workspace = true +bytes.workspace = true +http.workspace = true +http-body.workspace = true +serde_json.workspace = true +hex.workspace = true +sha2.workspace = true +time.workspace = true +tracing.workspace = true +tower.workspace = true +tower-http.workspace = true +object_store.workspace = true +comrak = { workspace = true } +emojis.workspace = true +ammonia = { workspace = true } +syntect = { workspace = true } + +[dev-dependencies] +tempfile.workspace = true + +[lints] +workspace = true diff --git a/crates/forge-web/src/accent.rs b/crates/forge-web-base/src/accent.rs similarity index 100% rename from crates/forge-web/src/accent.rs rename to crates/forge-web-base/src/accent.rs diff --git a/crates/forge-web/src/accent_palette.rs b/crates/forge-web-base/src/accent_palette.rs similarity index 100% rename from crates/forge-web/src/accent_palette.rs rename to crates/forge-web-base/src/accent_palette.rs diff --git a/crates/forge-web/src/blobs.rs b/crates/forge-web-base/src/blobs.rs similarity index 100% rename from crates/forge-web/src/blobs.rs rename to crates/forge-web-base/src/blobs.rs diff --git a/crates/forge-web/src/compression.rs b/crates/forge-web-base/src/compression.rs similarity index 96% rename from crates/forge-web/src/compression.rs rename to crates/forge-web-base/src/compression.rs index 9262260..b1461f6 100644 --- a/crates/forge-web/src/compression.rs +++ b/crates/forge-web-base/src/compression.rs @@ -246,17 +246,6 @@ mod tests { assert_eq!(encoding(&router, "/tahinli/demo/blob.bin").await, None); } - #[tokio::test] - async fn public_css_asset_is_gzipped() { - let dir = tempfile::tempdir().expect("tempdir"); - let state = crate::test_support::test_state(dir.path()).await; - let router = crate::test_support::app_router(state); - assert_eq!( - encoding(&router, "/assets/main.css").await.as_deref(), - Some("gzip") - ); - } - #[test] fn policy_skips_small_streamed_and_already_encoded_bodies() { let small = Response::builder() diff --git a/crates/forge-web/src/custom_colour.rs b/crates/forge-web-base/src/custom_colour.rs similarity index 100% rename from crates/forge-web/src/custom_colour.rs rename to crates/forge-web-base/src/custom_colour.rs diff --git a/crates/forge-web/src/i18n/accents.rs b/crates/forge-web-base/src/i18n/accents.rs similarity index 100% rename from crates/forge-web/src/i18n/accents.rs rename to crates/forge-web-base/src/i18n/accents.rs diff --git a/crates/forge-web/src/i18n/accounts.rs b/crates/forge-web-base/src/i18n/accounts.rs similarity index 100% rename from crates/forge-web/src/i18n/accounts.rs rename to crates/forge-web-base/src/i18n/accounts.rs diff --git a/crates/forge-web/src/i18n/admin.rs b/crates/forge-web-base/src/i18n/admin.rs similarity index 100% rename from crates/forge-web/src/i18n/admin.rs rename to crates/forge-web-base/src/i18n/admin.rs diff --git a/crates/forge-web/src/i18n/alerts.rs b/crates/forge-web-base/src/i18n/alerts.rs similarity index 100% rename from crates/forge-web/src/i18n/alerts.rs rename to crates/forge-web-base/src/i18n/alerts.rs diff --git a/crates/forge-web/src/i18n/authoring.rs b/crates/forge-web-base/src/i18n/authoring.rs similarity index 100% rename from crates/forge-web/src/i18n/authoring.rs rename to crates/forge-web-base/src/i18n/authoring.rs diff --git a/crates/forge-web/src/i18n/browse.rs b/crates/forge-web-base/src/i18n/browse.rs similarity index 100% rename from crates/forge-web/src/i18n/browse.rs rename to crates/forge-web-base/src/i18n/browse.rs diff --git a/crates/forge-web/src/i18n/code.rs b/crates/forge-web-base/src/i18n/code.rs similarity index 100% rename from crates/forge-web/src/i18n/code.rs rename to crates/forge-web-base/src/i18n/code.rs diff --git a/crates/forge-web/src/i18n/community.rs b/crates/forge-web-base/src/i18n/community.rs similarity index 100% rename from crates/forge-web/src/i18n/community.rs rename to crates/forge-web-base/src/i18n/community.rs diff --git a/crates/forge-web/src/i18n/integrations.rs b/crates/forge-web-base/src/i18n/integrations.rs similarity index 100% rename from crates/forge-web/src/i18n/integrations.rs rename to crates/forge-web-base/src/i18n/integrations.rs diff --git a/crates/forge-web/src/i18n/issues.rs b/crates/forge-web-base/src/i18n/issues.rs similarity index 100% rename from crates/forge-web/src/i18n/issues.rs rename to crates/forge-web-base/src/i18n/issues.rs diff --git a/crates/forge-web/src/i18n/link.rs b/crates/forge-web-base/src/i18n/link.rs similarity index 100% rename from crates/forge-web/src/i18n/link.rs rename to crates/forge-web-base/src/i18n/link.rs diff --git a/crates/forge-web/src/i18n/merge_queue.rs b/crates/forge-web-base/src/i18n/merge_queue.rs similarity index 100% rename from crates/forge-web/src/i18n/merge_queue.rs rename to crates/forge-web-base/src/i18n/merge_queue.rs diff --git a/crates/forge-web/src/i18n/migrate.rs b/crates/forge-web-base/src/i18n/migrate.rs similarity index 100% rename from crates/forge-web/src/i18n/migrate.rs rename to crates/forge-web-base/src/i18n/migrate.rs diff --git a/crates/forge-web/src/i18n/misc.rs b/crates/forge-web-base/src/i18n/misc.rs similarity index 100% rename from crates/forge-web/src/i18n/misc.rs rename to crates/forge-web-base/src/i18n/misc.rs diff --git a/crates/forge-web/src/i18n/mod.rs b/crates/forge-web-base/src/i18n/mod.rs similarity index 100% rename from crates/forge-web/src/i18n/mod.rs rename to crates/forge-web-base/src/i18n/mod.rs diff --git a/crates/forge-web/src/i18n/needs.rs b/crates/forge-web-base/src/i18n/needs.rs similarity index 100% rename from crates/forge-web/src/i18n/needs.rs rename to crates/forge-web-base/src/i18n/needs.rs diff --git a/crates/forge-web/src/i18n/orgs.rs b/crates/forge-web-base/src/i18n/orgs.rs similarity index 100% rename from crates/forge-web/src/i18n/orgs.rs rename to crates/forge-web-base/src/i18n/orgs.rs diff --git a/crates/forge-web/src/i18n/packages.rs b/crates/forge-web-base/src/i18n/packages.rs similarity index 100% rename from crates/forge-web/src/i18n/packages.rs rename to crates/forge-web-base/src/i18n/packages.rs diff --git a/crates/forge-web/src/i18n/pulls.rs b/crates/forge-web-base/src/i18n/pulls.rs similarity index 100% rename from crates/forge-web/src/i18n/pulls.rs rename to crates/forge-web-base/src/i18n/pulls.rs diff --git a/crates/forge-web/src/i18n/pulls_review.rs b/crates/forge-web-base/src/i18n/pulls_review.rs similarity index 100% rename from crates/forge-web/src/i18n/pulls_review.rs rename to crates/forge-web-base/src/i18n/pulls_review.rs diff --git a/crates/forge-web/src/i18n/push.rs b/crates/forge-web-base/src/i18n/push.rs similarity index 100% rename from crates/forge-web/src/i18n/push.rs rename to crates/forge-web-base/src/i18n/push.rs diff --git a/crates/forge-web/src/i18n/releases_ci.rs b/crates/forge-web-base/src/i18n/releases_ci.rs similarity index 100% rename from crates/forge-web/src/i18n/releases_ci.rs rename to crates/forge-web-base/src/i18n/releases_ci.rs diff --git a/crates/forge-web/src/i18n/repo_admin.rs b/crates/forge-web-base/src/i18n/repo_admin.rs similarity index 100% rename from crates/forge-web/src/i18n/repo_admin.rs rename to crates/forge-web-base/src/i18n/repo_admin.rs diff --git a/crates/forge-web/src/i18n/server_settings.rs b/crates/forge-web-base/src/i18n/server_settings.rs similarity index 100% rename from crates/forge-web/src/i18n/server_settings.rs rename to crates/forge-web-base/src/i18n/server_settings.rs diff --git a/crates/forge-web/src/i18n/timeline.rs b/crates/forge-web-base/src/i18n/timeline.rs similarity index 100% rename from crates/forge-web/src/i18n/timeline.rs rename to crates/forge-web-base/src/i18n/timeline.rs diff --git a/crates/forge-web-base/src/lib.rs b/crates/forge-web-base/src/lib.rs new file mode 100644 index 0000000..5db7876 --- /dev/null +++ b/crates/forge-web-base/src/lib.rs @@ -0,0 +1,14 @@ +//! Web modules that do not depend on the pages. They compile once in this crate, so a change in +//! forge-web's pages does not rebuild them. + +pub mod accent; +pub mod accent_palette; +pub mod blobs; +pub mod compression; +pub mod custom_colour; +pub mod i18n; +pub mod render; +pub mod repo_stats; +pub mod templates; +pub mod theme; +pub mod throttle; diff --git a/crates/forge-web/src/render/commit_message.rs b/crates/forge-web-base/src/render/commit_message.rs similarity index 100% rename from crates/forge-web/src/render/commit_message.rs rename to crates/forge-web-base/src/render/commit_message.rs diff --git a/crates/forge-web/src/render/emoji.rs b/crates/forge-web-base/src/render/emoji.rs similarity index 100% rename from crates/forge-web/src/render/emoji.rs rename to crates/forge-web-base/src/render/emoji.rs diff --git a/crates/forge-web/src/render/gitmojis.LICENSE b/crates/forge-web-base/src/render/gitmojis.LICENSE similarity index 100% rename from crates/forge-web/src/render/gitmojis.LICENSE rename to crates/forge-web-base/src/render/gitmojis.LICENSE diff --git a/crates/forge-web/src/render/gitmojis.json b/crates/forge-web-base/src/render/gitmojis.json similarity index 100% rename from crates/forge-web/src/render/gitmojis.json rename to crates/forge-web-base/src/render/gitmojis.json diff --git a/crates/forge-web/src/render/highlight.rs b/crates/forge-web-base/src/render/highlight.rs similarity index 100% rename from crates/forge-web/src/render/highlight.rs rename to crates/forge-web-base/src/render/highlight.rs diff --git a/crates/forge-web/src/render/markdown.rs b/crates/forge-web-base/src/render/markdown.rs similarity index 100% rename from crates/forge-web/src/render/markdown.rs rename to crates/forge-web-base/src/render/markdown.rs diff --git a/crates/forge-web/src/render/mod.rs b/crates/forge-web-base/src/render/mod.rs similarity index 100% rename from crates/forge-web/src/render/mod.rs rename to crates/forge-web-base/src/render/mod.rs diff --git a/crates/forge-web/src/repo_stats.rs b/crates/forge-web-base/src/repo_stats.rs similarity index 100% rename from crates/forge-web/src/repo_stats.rs rename to crates/forge-web-base/src/repo_stats.rs diff --git a/crates/forge-web/src/templates.rs b/crates/forge-web-base/src/templates.rs similarity index 51% rename from crates/forge-web/src/templates.rs rename to crates/forge-web-base/src/templates.rs index 4c78150..1bffbc6 100644 --- a/crates/forge-web/src/templates.rs +++ b/crates/forge-web-base/src/templates.rs @@ -262,275 +262,3 @@ mod tests { assert_eq!(t.body, "Body\r\n"); } } - -#[cfg(test)] -mod route_tests { - use forge_core::Visibility; - - use crate::pages::commits::test_support::{Fixture, git}; - use crate::pages::issues_list::test_util::{CSRF, OWNER, REPO, TOKEN, send}; - - const BUG: &str = "---\nname: Bug report\nabout: Something broke\ntitle: \"[Bug]: \"\nlabels: bug, needs triage\n---\n## Steps to reproduce\n\n1. Do the thing\n"; - const FEATURE: &str = "---\nname: Feature request\nabout: Suggest an idea\n---\n## Idea\n"; - - /// A repo whose default branch gets `files` committed on top of the fixture's history. - /// Tahinli is signed in. - async fn setup(files: &[(&str, &str)]) -> Fixture { - let fx = Fixture::new(Visibility::Public).await; - for (path, text) in files { - let full = fx.work.join(path); - std::fs::create_dir_all(full.parent().unwrap()).unwrap(); - std::fs::write(full, text).unwrap(); - } - git(&fx.work, &["add", "-A"]); - git(&fx.work, &["commit", "-q", "-m", "Add templates"]); - git( - &fx.work, - &[ - "push", - "-q", - &fx.bare.to_string_lossy(), - "HEAD:refs/heads/main", - ], - ); - let owner = fx.store.user_by_username(OWNER).await.unwrap().unwrap(); - crate::test_support::create_session(&fx.store, &owner.id, TOKEN, CSRF).await; - fx - } - - fn new_issue_uri(query: &str) -> String { - format!("/{OWNER}/{REPO}/issues/new{query}") - } - - /// The text of the tag that starts at `needle`, up to its closing `>`. - fn tag_at(html: &str, needle: &str) -> String { - let at = html.find(needle).expect("needle in page"); - let end = html[at..].find('>').expect("tag end") + at; - html[at..end].to_owned() - } - - #[tokio::test] - async fn several_templates_show_a_chooser() { - let fx = setup(&[ - (".forge/ISSUE_TEMPLATE/bug.md", BUG), - (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), - ]) - .await; - let reply = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]).await; - assert_eq!(reply.status, 200); - let html = reply.text(); - assert!(html.contains("Bug report")); - assert!(html.contains("Something broke")); - assert!(html.contains("issues/new?template=bug\"")); - assert!(html.contains("issues/new?template=feature\"")); - assert!(html.contains("Open a blank issue")); - assert!(html.contains("issues/new?blank=1\"")); - assert!(!html.contains("name=\"title\"")); - } - - #[tokio::test] - async fn chosen_template_prefills_and_preselects_existing_labels() { - let fx = setup(&[ - (".forge/ISSUE_TEMPLATE/bug.md", BUG), - (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), - ]) - .await; - let repo = fx - .store - .repo_by_owner_and_name(OWNER, REPO) - .await - .unwrap() - .unwrap(); - fx.store - .create_label(&repo.id, "bug", "#d73a4a", "") - .await - .unwrap(); - fx.store - .create_label(&repo.id, "docs", "#0075ca", "") - .await - .unwrap(); - let bug_id = fx - .store - .list_labels(&repo.id) - .await - .unwrap() - .into_iter() - .find(|l| l.name == "bug") - .unwrap() - .id; - - let reply = send( - &fx.router, - "GET", - &new_issue_uri("?template=bug"), - true, - None, - &[], - ) - .await; - assert_eq!(reply.status, 200); - let html = reply.text(); - assert!(html.contains("name=\"title\"")); - assert!(html.contains("value=\"[Bug]:\"")); - assert!(html.contains("## Steps to reproduce")); - assert!(!html.contains("Choose a template")); - assert!(tag_at(&html, &format!("value=\"{bug_id}\"")).contains("checked")); - assert!(!html.contains("value=\"needs triage\"")); - assert_eq!(html.matches("name=\"label\"").count(), 2); - let docs_id = fx - .store - .list_labels(&repo.id) - .await - .unwrap() - .into_iter() - .find(|l| l.name == "docs") - .unwrap() - .id; - assert!(!tag_at(&html, &format!("value=\"{docs_id}\"")).contains("checked")); - } - - #[tokio::test] - async fn blank_issue_from_chooser_is_empty() { - let fx = setup(&[ - (".forge/ISSUE_TEMPLATE/bug.md", BUG), - (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), - ]) - .await; - let reply = send( - &fx.router, - "GET", - &new_issue_uri("?blank=1"), - true, - None, - &[], - ) - .await; - let html = reply.text(); - assert!(html.contains("name=\"title\"")); - assert!(!html.contains("Steps to reproduce")); - assert!(!html.contains("Choose a template")); - } - - #[tokio::test] - async fn single_template_prefills_without_chooser() { - let fx = setup(&[(".forge/ISSUE_TEMPLATE/bug.md", BUG)]).await; - let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) - .await - .text(); - assert!(html.contains("value=\"[Bug]:\"")); - assert!(html.contains("## Steps to reproduce")); - assert!(!html.contains("Open a blank issue")); - } - - #[tokio::test] - async fn single_file_under_github_is_used_as_is() { - let fx = setup(&[(".github/ISSUE_TEMPLATE.md", "Plain body text\n")]).await; - let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) - .await - .text(); - assert!(html.contains("Plain body text")); - } - - #[tokio::test] - async fn chooser_lists_at_most_twenty_templates() { - let names: Vec = (0..21).map(|n| format!("t{n:02}")).collect(); - let files: Vec<(String, String)> = names - .iter() - .map(|n| { - ( - format!(".forge/ISSUE_TEMPLATE/{n}.md"), - format!("body {n}\n"), - ) - }) - .collect(); - let refs: Vec<(&str, &str)> = files - .iter() - .map(|(p, t)| (p.as_str(), t.as_str())) - .collect(); - let fx = setup(&refs).await; - let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) - .await - .text(); - assert!(html.contains("issues/new?template=t19\"")); - assert!(!html.contains("issues/new?template=t20\"")); - } - - #[tokio::test] - async fn submitting_with_a_label_applies_it_to_the_issue() { - let fx = setup(&[(".forge/ISSUE_TEMPLATE/bug.md", BUG)]).await; - let repo = fx - .store - .repo_by_owner_and_name(OWNER, REPO) - .await - .unwrap() - .unwrap(); - fx.store - .create_label(&repo.id, "bug", "#d73a4a", "") - .await - .unwrap(); - let bug_id = fx - .store - .list_labels(&repo.id) - .await - .unwrap() - .into_iter() - .next() - .unwrap() - .id; - let form = format!("csrf={CSRF}&title=Crash+on+start&body=details&label={bug_id}"); - let reply = send( - &fx.router, - "POST", - &new_issue_uri(""), - true, - Some(&form), - &[], - ) - .await; - assert_eq!(reply.status, 303); - let issue = fx - .store - .issue_by_number(&repo.id, 1) - .await - .unwrap() - .unwrap(); - let labels = fx.store.issue_labels(&issue.id).await.unwrap(); - assert_eq!(labels.len(), 1); - assert_eq!(labels[0].name, "bug"); - } - - #[tokio::test] - async fn compare_form_starts_with_the_pull_request_template() { - let fx = setup(&[( - ".forge/PULL_REQUEST_TEMPLATE.md", - "## Summary\n\nWhat changed?\n", - )]) - .await; - git(&fx.work, &["checkout", "-q", "-b", "feature"]); - std::fs::write(fx.work.join("feature.txt"), "feature\n").unwrap(); - git(&fx.work, &["add", "-A"]); - git(&fx.work, &["commit", "-q", "-m", "Add feature file"]); - git( - &fx.work, - &[ - "push", - "-q", - &fx.bare.to_string_lossy(), - "feature:refs/heads/feature", - ], - ); - git(&fx.work, &["checkout", "-q", "main"]); - - let reply = send( - &fx.router, - "GET", - &format!("/{OWNER}/{REPO}/compare/main...feature"), - true, - None, - &[], - ) - .await; - assert_eq!(reply.status, 200); - assert!(reply.text().contains("What changed?")); - } -} diff --git a/crates/forge-web/src/theme.rs b/crates/forge-web-base/src/theme.rs similarity index 100% rename from crates/forge-web/src/theme.rs rename to crates/forge-web-base/src/theme.rs diff --git a/crates/forge-web/src/throttle.rs b/crates/forge-web-base/src/throttle.rs similarity index 100% rename from crates/forge-web/src/throttle.rs rename to crates/forge-web-base/src/throttle.rs diff --git a/crates/forge-web/Cargo.toml b/crates/forge-web/Cargo.toml index 39d1df0..8ec4edc 100644 --- a/crates/forge-web/Cargo.toml +++ b/crates/forge-web/Cargo.toml @@ -16,6 +16,7 @@ ipnet.workspace = true forge-git.workspace = true forge-ssh.workspace = true forge-ci.workspace = true +forge-web-base.workspace = true topcoat = { workspace = true, default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "compression", "multipart", "tower"] } tokio.workspace = true futures-util.workspace = true @@ -39,16 +40,9 @@ hex.workspace = true nix = { workspace = true } sha2.workspace = true time.workspace = true -comrak = { workspace = true } -emojis.workspace = true -ammonia = { workspace = true } -syntect = { workspace = true } reqwest = { workspace = true } hmac.workspace = true similar = { workspace = true } -tower = { workspace = true } -tower-http = { workspace = true } -object_store.workspace = true multer.workspace = true ulid.workspace = true forge-runner = { workspace = true } @@ -69,7 +63,6 @@ sha2.workspace = true [dev-dependencies] tempfile.workspace = true -forge-runner = { workspace = true, features = ["test-host-executor"] } image = { workspace = true } scraper = { workspace = true } webauthn-authenticator-rs = { version = "0.5.5", features = ["softpasskey"] } diff --git a/crates/forge-web/build.rs b/crates/forge-web/build.rs index e1424fa..4cd00ed 100644 --- a/crates/forge-web/build.rs +++ b/crates/forge-web/build.rs @@ -2,15 +2,16 @@ //! asset also gets a content hash (FORGE_MAIN_CSS_V, FORGE_NAV_JS_V) that the page links use as //! their cache-busting query, so an unchanged file keeps its URL and a changed one gets a new one. //! -//! The accent colours and the neutral bases come from `src/accent_palette.rs`, the same data the -//! app reads. This script turns it into `_accents.scss` in OUT_DIR, which main.scss imports. +//! The accent colours and the neutral bases come from `forge-web-base/src/accent_palette.rs`, the +//! same data the app reads. This script turns it into `_accents.scss` in OUT_DIR, which main.scss +//! imports. use std::{env, fs, path::PathBuf}; use hex::encode; use sha2::{Digest, Sha256}; -#[path = "src/accent_palette.rs"] +#[path = "../forge-web-base/src/accent_palette.rs"] #[allow(dead_code)] mod accent_palette; @@ -19,6 +20,8 @@ use accent_palette::{ Tokens, }; +include!("../forge-ci/build_identity.rs"); + /// First 12 hex characters of the SHA-256 of `bytes`. fn content_version(bytes: &[u8]) -> String { encode(Sha256::digest(bytes))[..12].to_string() @@ -149,7 +152,7 @@ fn swatch_rules(css: &mut String) { /// chips. fn accents_scss() -> String { let mut css = String::from( - "/* Generated by crates/forge-web/build.rs from src/accent_palette.rs. Edit that file. */\n", + "/* Generated by crates/forge-web/build.rs from forge-web-base/src/accent_palette.rs. Edit that file. */\n", ); assert_eq!(PALETTES[0].id, DEFAULT, "the default palette comes first"); assert_eq!(BASES[0].id, BASE_DEFAULT, "the default base comes first"); @@ -166,9 +169,12 @@ fn accents_scss() -> String { fn main() { println!("cargo:rerun-if-env-changed=FORGE_BUILD_SHA"); + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=../forge-ci/build_identity.rs"); + emit_identity(); println!("cargo:rerun-if-changed=../../style"); println!("cargo:rerun-if-changed=assets/nav.js"); - println!("cargo:rerun-if-changed=src/accent_palette.rs"); + println!("cargo:rerun-if-changed=../forge-web-base/src/accent_palette.rs"); let sha = env::var("FORGE_BUILD_SHA").unwrap_or_else(|_| "dev".to_string()); println!("cargo:rustc-env=FORGE_BUILD_SHA={sha}"); diff --git a/crates/forge-web/src/compression_route_tests.rs b/crates/forge-web/src/compression_route_tests.rs new file mode 100644 index 0000000..68784d0 --- /dev/null +++ b/crates/forge-web/src/compression_route_tests.rs @@ -0,0 +1,25 @@ +//! The public router gzips its stylesheet. The response compression policy is tested in +//! forge-web-base, next to the layer; this checks it is wired into the real app router. + +use http::header::{ACCEPT_ENCODING, CONTENT_ENCODING}; +use topcoat::router::Body; + +#[tokio::test] +async fn public_css_asset_is_gzipped() { + let dir = tempfile::tempdir().expect("tempdir"); + let state = crate::test_support::test_state(dir.path()).await; + let router = crate::test_support::app_router(state); + let request = http::Request::builder() + .uri("/assets/main.css") + .header(ACCEPT_ENCODING, "gzip") + .body(Body::empty()) + .expect("request"); + let response = router.handle(request).await; + assert_eq!( + response + .headers() + .get(CONTENT_ENCODING) + .map(|v| v.to_str().expect("ascii")), + Some("gzip") + ); +} diff --git a/crates/forge-web/src/main.rs b/crates/forge-web/src/main.rs index 420689c..fa3a434 100644 --- a/crates/forge-web/src/main.rs +++ b/crates/forge-web/src/main.rs @@ -6,9 +6,12 @@ #![recursion_limit = "256"] -mod accent; -#[allow(dead_code)] // build.rs uses the whole file; the app reads only part of it. -mod accent_palette; +// Modules that moved to forge-web-base, so they compile once and are not rebuilt with the pages. +pub(crate) use forge_web_base::{ + accent, accent_palette, blobs, compression, custom_colour, i18n, render, repo_stats, templates, + theme, throttle, +}; + mod access; mod admin_cli; mod admin_client; @@ -19,17 +22,15 @@ mod audit; mod auth; mod automerge; mod backup; -mod blobs; mod boot; mod ci; mod client_ip; -mod compression; -mod custom_colour; +#[cfg(test)] +mod compression_route_tests; mod exporter; mod git_auth; mod git_http; mod hook_cmd; -mod i18n; mod importer; mod internal; mod lfs; @@ -49,18 +50,15 @@ mod prune; mod pulls_sync; mod raw; mod release_ops; -mod render; mod replication; -mod repo_stats; mod self_update; mod signatures; mod ssh_backend; mod state; -mod templates; +#[cfg(test)] +mod templates_route_tests; #[cfg(test)] mod test_support; -mod theme; -mod throttle; mod views; mod web_push; mod webhooks; @@ -154,6 +152,11 @@ fn reexec_with_allocator_env(raw: &[std::ffi::OsString]) { } fn main() -> ExitCode { + forge_ci::build::set_identity( + env!("FORGE_GIT_SHA"), + env!("FORGE_GIT_DATE"), + matches!(env!("FORGE_GIT_DIRTY").as_bytes(), b"1"), + ); // The sandbox helpers must start before any runtime or subscriber exists. if forge_runner::cli::is_sandbox_invocation() { std::process::exit(forge_runner::cli::hidden_main()); diff --git a/crates/forge-web/src/pages/admin_health.rs b/crates/forge-web/src/pages/admin_health.rs index 1940bfd..47076b0 100644 --- a/crates/forge-web/src/pages/admin_health.rs +++ b/crates/forge-web/src/pages/admin_health.rs @@ -408,15 +408,19 @@ async fn gather(state: &AppState, lang: Lang) -> Result { let uptime = uptime_secs().map_or_else(|| at(lang, A::Unavailable).to_owned(), duration_short); let build = format!( "{}{}", - forge_ci::build::COMMIT, - if forge_ci::build::DIRTY { "-dirty" } else { "" } + forge_ci::build::commit(), + if forge_ci::build::dirty() { + "-dirty" + } else { + "" + } ); let meta = meta_line( lang, &uptime, forge_ci::build::VERSION, &build, - forge_ci::build::DATE, + forge_ci::build::date(), ); let attention = usize::from(usage.as_ref().is_some_and(|u| u.bad)) diff --git a/crates/forge-web/src/templates_route_tests.rs b/crates/forge-web/src/templates_route_tests.rs new file mode 100644 index 0000000..b099ff3 --- /dev/null +++ b/crates/forge-web/src/templates_route_tests.rs @@ -0,0 +1,268 @@ +use forge_core::Visibility; + +use crate::pages::commits::test_support::{Fixture, git}; +use crate::pages::issues_list::test_util::{CSRF, OWNER, REPO, TOKEN, send}; + +const BUG: &str = "---\nname: Bug report\nabout: Something broke\ntitle: \"[Bug]: \"\nlabels: bug, needs triage\n---\n## Steps to reproduce\n\n1. Do the thing\n"; +const FEATURE: &str = "---\nname: Feature request\nabout: Suggest an idea\n---\n## Idea\n"; + +/// A repo whose default branch gets `files` committed on top of the fixture's history. +/// Tahinli is signed in. +async fn setup(files: &[(&str, &str)]) -> Fixture { + let fx = Fixture::new(Visibility::Public).await; + for (path, text) in files { + let full = fx.work.join(path); + std::fs::create_dir_all(full.parent().unwrap()).unwrap(); + std::fs::write(full, text).unwrap(); + } + git(&fx.work, &["add", "-A"]); + git(&fx.work, &["commit", "-q", "-m", "Add templates"]); + git( + &fx.work, + &[ + "push", + "-q", + &fx.bare.to_string_lossy(), + "HEAD:refs/heads/main", + ], + ); + let owner = fx.store.user_by_username(OWNER).await.unwrap().unwrap(); + crate::test_support::create_session(&fx.store, &owner.id, TOKEN, CSRF).await; + fx +} + +fn new_issue_uri(query: &str) -> String { + format!("/{OWNER}/{REPO}/issues/new{query}") +} + +/// The text of the tag that starts at `needle`, up to its closing `>`. +fn tag_at(html: &str, needle: &str) -> String { + let at = html.find(needle).expect("needle in page"); + let end = html[at..].find('>').expect("tag end") + at; + html[at..end].to_owned() +} + +#[tokio::test] +async fn several_templates_show_a_chooser() { + let fx = setup(&[ + (".forge/ISSUE_TEMPLATE/bug.md", BUG), + (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), + ]) + .await; + let reply = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]).await; + assert_eq!(reply.status, 200); + let html = reply.text(); + assert!(html.contains("Bug report")); + assert!(html.contains("Something broke")); + assert!(html.contains("issues/new?template=bug\"")); + assert!(html.contains("issues/new?template=feature\"")); + assert!(html.contains("Open a blank issue")); + assert!(html.contains("issues/new?blank=1\"")); + assert!(!html.contains("name=\"title\"")); +} + +#[tokio::test] +async fn chosen_template_prefills_and_preselects_existing_labels() { + let fx = setup(&[ + (".forge/ISSUE_TEMPLATE/bug.md", BUG), + (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), + ]) + .await; + let repo = fx + .store + .repo_by_owner_and_name(OWNER, REPO) + .await + .unwrap() + .unwrap(); + fx.store + .create_label(&repo.id, "bug", "#d73a4a", "") + .await + .unwrap(); + fx.store + .create_label(&repo.id, "docs", "#0075ca", "") + .await + .unwrap(); + let bug_id = fx + .store + .list_labels(&repo.id) + .await + .unwrap() + .into_iter() + .find(|l| l.name == "bug") + .unwrap() + .id; + + let reply = send( + &fx.router, + "GET", + &new_issue_uri("?template=bug"), + true, + None, + &[], + ) + .await; + assert_eq!(reply.status, 200); + let html = reply.text(); + assert!(html.contains("name=\"title\"")); + assert!(html.contains("value=\"[Bug]:\"")); + assert!(html.contains("## Steps to reproduce")); + assert!(!html.contains("Choose a template")); + assert!(tag_at(&html, &format!("value=\"{bug_id}\"")).contains("checked")); + assert!(!html.contains("value=\"needs triage\"")); + assert_eq!(html.matches("name=\"label\"").count(), 2); + let docs_id = fx + .store + .list_labels(&repo.id) + .await + .unwrap() + .into_iter() + .find(|l| l.name == "docs") + .unwrap() + .id; + assert!(!tag_at(&html, &format!("value=\"{docs_id}\"")).contains("checked")); +} + +#[tokio::test] +async fn blank_issue_from_chooser_is_empty() { + let fx = setup(&[ + (".forge/ISSUE_TEMPLATE/bug.md", BUG), + (".forge/ISSUE_TEMPLATE/feature.md", FEATURE), + ]) + .await; + let reply = send( + &fx.router, + "GET", + &new_issue_uri("?blank=1"), + true, + None, + &[], + ) + .await; + let html = reply.text(); + assert!(html.contains("name=\"title\"")); + assert!(!html.contains("Steps to reproduce")); + assert!(!html.contains("Choose a template")); +} + +#[tokio::test] +async fn single_template_prefills_without_chooser() { + let fx = setup(&[(".forge/ISSUE_TEMPLATE/bug.md", BUG)]).await; + let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) + .await + .text(); + assert!(html.contains("value=\"[Bug]:\"")); + assert!(html.contains("## Steps to reproduce")); + assert!(!html.contains("Open a blank issue")); +} + +#[tokio::test] +async fn single_file_under_github_is_used_as_is() { + let fx = setup(&[(".github/ISSUE_TEMPLATE.md", "Plain body text\n")]).await; + let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) + .await + .text(); + assert!(html.contains("Plain body text")); +} + +#[tokio::test] +async fn chooser_lists_at_most_twenty_templates() { + let names: Vec = (0..21).map(|n| format!("t{n:02}")).collect(); + let files: Vec<(String, String)> = names + .iter() + .map(|n| { + ( + format!(".forge/ISSUE_TEMPLATE/{n}.md"), + format!("body {n}\n"), + ) + }) + .collect(); + let refs: Vec<(&str, &str)> = files + .iter() + .map(|(p, t)| (p.as_str(), t.as_str())) + .collect(); + let fx = setup(&refs).await; + let html = send(&fx.router, "GET", &new_issue_uri(""), true, None, &[]) + .await + .text(); + assert!(html.contains("issues/new?template=t19\"")); + assert!(!html.contains("issues/new?template=t20\"")); +} + +#[tokio::test] +async fn submitting_with_a_label_applies_it_to_the_issue() { + let fx = setup(&[(".forge/ISSUE_TEMPLATE/bug.md", BUG)]).await; + let repo = fx + .store + .repo_by_owner_and_name(OWNER, REPO) + .await + .unwrap() + .unwrap(); + fx.store + .create_label(&repo.id, "bug", "#d73a4a", "") + .await + .unwrap(); + let bug_id = fx + .store + .list_labels(&repo.id) + .await + .unwrap() + .into_iter() + .next() + .unwrap() + .id; + let form = format!("csrf={CSRF}&title=Crash+on+start&body=details&label={bug_id}"); + let reply = send( + &fx.router, + "POST", + &new_issue_uri(""), + true, + Some(&form), + &[], + ) + .await; + assert_eq!(reply.status, 303); + let issue = fx + .store + .issue_by_number(&repo.id, 1) + .await + .unwrap() + .unwrap(); + let labels = fx.store.issue_labels(&issue.id).await.unwrap(); + assert_eq!(labels.len(), 1); + assert_eq!(labels[0].name, "bug"); +} + +#[tokio::test] +async fn compare_form_starts_with_the_pull_request_template() { + let fx = setup(&[( + ".forge/PULL_REQUEST_TEMPLATE.md", + "## Summary\n\nWhat changed?\n", + )]) + .await; + git(&fx.work, &["checkout", "-q", "-b", "feature"]); + std::fs::write(fx.work.join("feature.txt"), "feature\n").unwrap(); + git(&fx.work, &["add", "-A"]); + git(&fx.work, &["commit", "-q", "-m", "Add feature file"]); + git( + &fx.work, + &[ + "push", + "-q", + &fx.bare.to_string_lossy(), + "feature:refs/heads/feature", + ], + ); + git(&fx.work, &["checkout", "-q", "main"]); + + let reply = send( + &fx.router, + "GET", + &format!("/{OWNER}/{REPO}/compare/main...feature"), + true, + None, + &[], + ) + .await; + assert_eq!(reply.status, 200); + assert!(reply.text().contains("What changed?")); +} diff --git a/docs/architecture.md b/docs/architecture.md index e23e362..0fc5994 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -47,6 +47,8 @@ project_git/ forge-git/ safe git command builder, process spawn and streaming, pkt-line, repo init, managed gitconfig, version check forge-ssh/ russh server: pubkey auth, exec allow-list and parse, GIT_PROTOCOL env, piping, timeouts forge-web/ crate, builds the `forge` binary: Topcoat UI, auth, smart-HTTP routes, internal hook API, `hook` subcommand, admin CLI + forge-web-base/ forge-web modules with no routes and no dependency on pages: i18n, render, theme and accents, templates, blobs + forge-e2e/ end-to-end tests. They run `FORGE_BIN` when it is set, so CI tests the binary it ships, and otherwise build `forge` ``` Module ownership (from the contract): @@ -486,7 +488,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 `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). +- Tests: unit tests in core and git; end-to-end `crates/forge-e2e/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 diff --git a/docs/ci.md b/docs/ci.md index ba52ee8..0077a85 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -764,6 +764,12 @@ cargo test --workspace Setting `CARGO_HOME` to a path inside the workspace keeps the downloaded crates in the cache too. +Each job checks out its commit fresh, so every file would get a new modification time and tools that +compare times would rebuild everything. The runner avoids this: when it restores a cache, it sets +each tracked file's modification time to when that file's content last changed, as the restored +cache saw it. A file that did not change keeps its old time, and a changed file gets the current +time. Tools that compare times, such as cargo and make, therefore rebuild only what changed. + ## Forge limits (`[ci]`) The `[ci]` section of `forge.toml` controls CI on the forge. These are the defaults: