diff --git a/app/Cargo.toml b/app/Cargo.toml index 37896d43..a8e7989a 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,26 @@ name = "app" name = "visualci-app" path = "src/main.rs" +[[test]] +name = "app" +path = "tests/all.rs" + +[[test]] +name = "live" +path = "tests/live.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..36540273 --- /dev/null +++ b/app/tests/all.rs @@ -0,0 +1,92 @@ +//! 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, 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 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; +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 github_calls; +mod groups; +mod hosts; +mod installations; +mod invitations; +mod link; +mod live_streams; +mod load; +mod masks; +mod mcp; +mod mcp_admin; +mod mcp_uploads; +mod me; +mod memberships; +mod oauth; +mod org_settings; +mod organizations; +mod orgs; +mod processing; +mod processing_lock; +mod project_deletion; +mod renderer; +mod reruns; +mod retention; +mod rollouts; +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 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 { + wrong.push(module.to_owned()); + } + } + assert!(wrong.is_empty(), "list each of these once, in tests/all.rs or as a [[test]] in Cargo.toml: {wrong:?}"); +} 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;