From 9f1b579a840018bb81dd77f8160fcc9e49447c83 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 18:52:58 +1300 Subject: [PATCH 1/5] app tests: one test binary instead of 53 Each file in app/tests was its own test binary: every run linked the whole app 53 times, then cargo ran the binaries one after another. They're now modules of tests/all.rs, linked once, with every test running in parallel (Laravel Rust gives each test its own application and database). live_limits, mcp_hosts and proxies say they need a process of their own, so they stay separate [[test]] targets. A test fails if a file in tests/ is in neither list, since autotests is off. --- app/Cargo.toml | 18 +++++++++ app/tests/all.rs | 84 +++++++++++++++++++++++++++++++++++++++ app/tests/api_builds.rs | 2 +- app/tests/live_streams.rs | 2 +- app/tests/mcp.rs | 2 +- app/tests/mcp_admin.rs | 4 +- 6 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 app/tests/all.rs diff --git a/app/Cargo.toml b/app/Cargo.toml index 37896d43..6e0ed512 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -9,6 +9,8 @@ edition = "2024" rust-version = "1.99" license = "Apache-2.0" publish = false +# The integration tests are one binary (tests/all.rs), linked once: see that file. +autotests = false # Laravel Rust's convention: the library is `app`. [lib] @@ -18,6 +20,22 @@ name = "app" name = "visualci-app" path = "src/main.rs" +[[test]] +name = "app" +path = "tests/all.rs" + +[[test]] +name = "live_limits" +path = "tests/live_limits.rs" + +[[test]] +name = "mcp_hosts" +path = "tests/mcp_hosts.rs" + +[[test]] +name = "proxies" +path = "tests/proxies.rs" + [dependencies] # Pinned exactly: each 0.x minor of Laravel Rust may break, and upgrades are deliberate. laravel-rust = { version = "=0.1.4", features = ["database-postgres", "minijinja"] } diff --git a/app/tests/all.rs b/app/tests/all.rs new file mode 100644 index 00000000..6b04249f --- /dev/null +++ b/app/tests/all.rs @@ -0,0 +1,84 @@ +//! Every integration test of the app, in one test binary. +//! +//! Each file in `tests/` used to be its own binary: 53 links of the whole app on every run, then Cargo ran them one +//! after another. Here they're modules of one crate, linked once, and their tests all run in parallel, which Laravel +//! Rust's tests support (each gets its own application and, with `refresh_database`, its own database). +//! +//! A file whose tests need a process of their own (a per-process counter or service built from the first test's +//! settings) stays its own binary, as a `[[test]]` in Cargo.toml: live_limits, mcp_hosts and proxies. +//! +//! A new test file goes in the list below or in Cargo.toml; `every_test_file_is_listed` fails if it's in neither, +//! since Cargo no longer finds them by itself (`autotests = false`). `cargo test -p visualci-app ::` runs one. + +mod golden; +mod oauth_client; + +mod api_builds; +mod app_shell; +mod auth; +mod baselines; +mod billing; +mod branches; +mod credit_overrides; +mod credits; +mod demo; +mod device; +mod downloads; +mod emails; +mod fingerprints; +mod forge_events; +mod forge_reports; +mod forge_sync; +mod gallery; +mod groups; +mod hosts; +mod installations; +mod invitations; +mod link; +mod live; +mod live_streams; +mod load; +mod masks; +mod mcp; +mod mcp_admin; +mod mcp_uploads; +mod me; +mod memberships; +mod oauth; +mod organizations; +mod orgs; +mod processing; +mod processing_lock; +mod renderer; +mod retention; +mod scaffold; +mod screenshots_seed; +mod setup; +mod sign_in; +mod staff; +mod staff_commands; +mod storage; +mod storage_blobs; +mod sweep; +mod tokens; +mod ui; +mod webhooks; + +#[test] +fn every_test_file_is_listed() { + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"); + let listed = include_str!("all.rs"); + let own_binaries = include_str!("../Cargo.toml"); + let mut missing = Vec::new(); + for entry in std::fs::read_dir(&dir).unwrap() { + let path = entry.unwrap().path(); + let is_module = path.extension().is_some_and(|e| e == "rs") || path.join("mod.rs").is_file(); + let Some(module) = path.file_stem().and_then(|s| s.to_str()).filter(|_| is_module) else { continue }; + let in_all = listed.lines().any(|line| line == format!("mod {module};")); + let own_binary = own_binaries.lines().any(|line| line == format!("path = \"tests/{module}.rs\"")); + if module != "all" && !in_all && !own_binary { + missing.push(module.to_owned()); + } + } + assert!(missing.is_empty(), "add these to tests/all.rs (or Cargo.toml): {missing:?}"); +} diff --git a/app/tests/api_builds.rs b/app/tests/api_builds.rs index 44b7a662..bbfab133 100644 --- a/app/tests/api_builds.rs +++ b/app/tests/api_builds.rs @@ -1,6 +1,6 @@ //! The CI API's builds: today's answers (tests/golden/api) for the same requests. -mod golden; +use crate::golden; use app::testing::fixtures; use laravel::db; diff --git a/app/tests/live_streams.rs b/app/tests/live_streams.rs index e7924546..f045c18b 100644 --- a/app/tests/live_streams.rs +++ b/app/tests/live_streams.rs @@ -3,7 +3,7 @@ //! arrives inside a test's rolled-back transaction, so what a stream sends after its snapshot is tested on its own //! channel. -mod oauth_client; +use crate::oauth_client; use std::time::Duration; diff --git a/app/tests/mcp.rs b/app/tests/mcp.rs index be512177..f8b40fac 100644 --- a/app/tests/mcp.rs +++ b/app/tests/mcp.rs @@ -1,7 +1,7 @@ //! The public MCP server's tools: today's answers (tests/golden/mcp) for the same calls. `whoami`'s `via` and //! `list_builds`' compact lines are deliberate changes from today's answers. -mod golden; +use crate::golden; use std::collections::HashMap; use std::sync::Mutex; diff --git a/app/tests/mcp_admin.rs b/app/tests/mcp_admin.rs index f793ec62..e45eb3db 100644 --- a/app/tests/mcp_admin.rs +++ b/app/tests/mcp_admin.rs @@ -2,8 +2,8 @@ //! admin token gets in, the regular `/mcp` never shows admin tools, writes need a reason, and every call is audited. //! Each tool's answer is checked against tests/golden/mcp_admin. -mod golden; -mod oauth_client; +use crate::golden; +use crate::oauth_client; use std::collections::HashMap; use std::sync::Mutex; From 2685153918ddc0d9bd3e00e161cbe1ef3502ebe9 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 19:05:51 +1300 Subject: [PATCH 2/5] app tests: list abuse, github_calls and reruns; live.rs gets its own binary; guard requires exactly one listing From the review: main gained three test files; live.rs must start the live-updates listener on its own runtime, which only alphabetical order guaranteed in the shared binary; and a file listed in both places would run twice. --- app/Cargo.toml | 4 ++++ app/tests/all.rs | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/Cargo.toml b/app/Cargo.toml index 6e0ed512..a8e7989a 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -24,6 +24,10 @@ path = "src/main.rs" name = "app" path = "tests/all.rs" +[[test]] +name = "live" +path = "tests/live.rs" + [[test]] name = "live_limits" path = "tests/live_limits.rs" diff --git a/app/tests/all.rs b/app/tests/all.rs index 6b04249f..c1a08a31 100644 --- a/app/tests/all.rs +++ b/app/tests/all.rs @@ -5,14 +5,18 @@ //! Rust's tests support (each gets its own application and, with `refresh_database`, its own database). //! //! A file whose tests need a process of their own (a per-process counter or service built from the first test's -//! settings) stays its own binary, as a `[[test]]` in Cargo.toml: live_limits, mcp_hosts and proxies. +//! settings, the live-updates listener started on the first caller's runtime) stays its own binary, as a `[[test]]` in +//! Cargo.toml: live, live_limits, mcp_hosts and proxies. The MCP services here take their allowed hosts from the first +//! test that reaches them, so a test that needs other hosts (`mcp.visualci.test`, `VISUALCI_MCP_HOSTS`) goes there too. //! -//! A new test file goes in the list below or in Cargo.toml; `every_test_file_is_listed` fails if it's in neither, -//! since Cargo no longer finds them by itself (`autotests = false`). `cargo test -p visualci-app ::` runs one. +//! A new test file goes in the list below or in Cargo.toml: `every_test_file_is_listed` fails unless it's in exactly +//! one, since Cargo no longer finds test files by itself (`autotests = false`). +//! `cargo test -p visualci-app ::` runs one file's tests. mod golden; mod oauth_client; +mod abuse; mod api_builds; mod app_shell; mod auth; @@ -30,12 +34,12 @@ mod forge_events; mod forge_reports; mod forge_sync; mod gallery; +mod github_calls; mod groups; mod hosts; mod installations; mod invitations; mod link; -mod live; mod live_streams; mod load; mod masks; @@ -50,6 +54,7 @@ mod orgs; mod processing; mod processing_lock; mod renderer; +mod reruns; mod retention; mod scaffold; mod screenshots_seed; @@ -69,16 +74,16 @@ fn every_test_file_is_listed() { let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"); let listed = include_str!("all.rs"); let own_binaries = include_str!("../Cargo.toml"); - let mut missing = Vec::new(); + let mut wrong = Vec::new(); for entry in std::fs::read_dir(&dir).unwrap() { let path = entry.unwrap().path(); let is_module = path.extension().is_some_and(|e| e == "rs") || path.join("mod.rs").is_file(); let Some(module) = path.file_stem().and_then(|s| s.to_str()).filter(|_| is_module) else { continue }; let in_all = listed.lines().any(|line| line == format!("mod {module};")); let own_binary = own_binaries.lines().any(|line| line == format!("path = \"tests/{module}.rs\"")); - if module != "all" && !in_all && !own_binary { - missing.push(module.to_owned()); + if module != "all" && in_all == own_binary { + wrong.push(module.to_owned()); } } - assert!(missing.is_empty(), "add these to tests/all.rs (or Cargo.toml): {missing:?}"); + assert!(wrong.is_empty(), "list each of these once, in tests/all.rs or as a [[test]] in Cargo.toml: {wrong:?}"); } From 861419fef8cfef627d528e133420d0865ec39e84 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 19:32:15 +1300 Subject: [PATCH 3/5] CI app job: 12 test threads (the app tests wait on Postgres more than on the 4 cores) --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef1da708..031e2579 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,6 +103,9 @@ jobs: - run: cargo test --locked -p visualci-app env: VISUALCI_EMAIL_SNAPSHOTS: ${{ github.workspace }}/tmp/email-snapshots + # The tests mostly wait on Postgres, not the CPU: more threads than the runner's 4 cores. Each running test + # takes its own numbered copy of the database (Laravel Rust's refresh_database), so this many copies at most. + RUST_TEST_THREADS: "12" - uses: actions/upload-artifact@v4 with: name: email-snapshots From 2538f842db8d0a53c1e5207f87ba772013c62449 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 19:42:43 +1300 Subject: [PATCH 4/5] Revert the 12 test threads: no gain (tests 73 s against 75 s with 4) The tests are bound by the runner after all, so more threads only meant more database copies. --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 031e2579..ef1da708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,9 +103,6 @@ jobs: - run: cargo test --locked -p visualci-app env: VISUALCI_EMAIL_SNAPSHOTS: ${{ github.workspace }}/tmp/email-snapshots - # The tests mostly wait on Postgres, not the CPU: more threads than the runner's 4 cores. Each running test - # takes its own numbered copy of the database (Laravel Rust's refresh_database), so this many copies at most. - RUST_TEST_THREADS: "12" - uses: actions/upload-artifact@v4 with: name: email-snapshots From fcf6656a31a1e859bf4527ccbd22ee5df26b78a4 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 20:13:14 +1300 Subject: [PATCH 5/5] app tests: list org_settings (new on main) --- app/tests/all.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/tests/all.rs b/app/tests/all.rs index c1a08a31..b3f8fc23 100644 --- a/app/tests/all.rs +++ b/app/tests/all.rs @@ -49,6 +49,7 @@ mod mcp_uploads; mod me; mod memberships; mod oauth; +mod org_settings; mod organizations; mod orgs; mod processing;