Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore: make ci fast (#5802)

Wolf Mermelsteine3a3d2220834
diff --git a/.cargo/config.toml b/.cargo/config.toml
index dce456f5bd..4f5bce4faf 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -3,7 +3,7 @@
# `cargo x <subcommand>` runs xtask from anywhere in the repository:
# cargo x workflows [--check] # regenerate / verify .github/workflows
# cargo x deps [--check] # regenerate / verify workspace-hack + dep closures
-# cargo x nextest-filter <file> # nextest rdeps filter for changed files
+# cargo x nextest-filter <file> <base-revision> # affected packages for changed files
# cargo x doppler-bins <file> # Doppler config-validation bins affected by changed files
# cargo x graphql-soup-schema <file> # export GraphQL Soup SDL to a file
# cargo x cache-wasm [--force] # build the browser cache wasm package
diff --git a/.github/workflows/cargo_workspace_dependency_check.yml b/.github/workflows/cargo_workspace_dependency_check.yml
index 6922d0603e..aac7b46ad3 100644
--- a/.github/workflows/cargo_workspace_dependency_check.yml
+++ b/.github/workflows/cargo_workspace_dependency_check.yml
@@ -18,9 +18,10 @@ name: cargo workspace dependency check
- Cargo.lock
- '.config/hakari.toml'
- crates/workspace-hack/**
- - tooling/xtask/**
+ - tooling/xtask/src/**
+ - tooling/xtask/crates/xtask_deps/**
+ - tooling/xtask/crates/xtask_graph/**
- '.github/workspace-dep-closures.json'
- - '.github/workflows/cargo_workspace_dependency_check.yml'
jobs:
dependency-check:
runs-on: namespace-profile-linux-rust-ci;overrides.cache-tag=sccache-ci
diff --git a/.github/workflows/code_check_cloud_storage.yml b/.github/workflows/code_check_cloud_storage.yml
index 082622c968..40750b214d 100644
--- a/.github/workflows/code_check_cloud_storage.yml
+++ b/.github/workflows/code_check_cloud_storage.yml
@@ -22,15 +22,16 @@ jobs:
runs-on: namespace-profile-linux-small
outputs:
should_run: ${{ steps.filter.outputs.should_run }}
- nextest_filter: ${{ steps.nextest-filter.outputs.nextest_filter }}
+ rust_packages: ${{ steps.nextest-filter.outputs.rust_packages }}
+ skip_tests: ${{ steps.nextest-filter.outputs.skip_tests }}
doppler_config_bins: ${{ steps.doppler-bins.outputs.doppler_config_bins }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
clean: 'false'
- fetch-depth: '0'
persist-credentials: 'false'
+ fetch-depth: '2'
- name: Setup Rust
uses: './.github/actions/setup-rust'
with:
@@ -55,21 +56,23 @@ jobs:
- 'services/**'
- 'tooling/xtask/**'
- 'static_assets/**'
+ - 'nix/**'
- 'flake.nix'
- 'flake.lock'
- '.github/actions/setup-nix/**'
- '.github/actions/setup-nix-dev-shell/**'
- '.github/actions/teardown-nix/**'
- '.github/actions/setup-sccache/**'
- - '.github/services-config.json'
- - '.github/scripts/build-cloud-storage-lambdas.sh'
- - '.github/scripts/build-cloud-storage-lambdas-nix.sh'
- .github/workflows/code_check_cloud_storage.yml
- name: compute changed files
if: steps.filter.outputs.should_run == 'true'
run: |
set -euo pipefail
+ # Compare against the merge-base so a deleted file still appears. `--no-renames`
+ # turns a rename into a delete+add pair so the old path is attributed to its
+ # package (otherwise git reports only the new name).
+
if [ -z "${GITHUB_BASE_REF:-}" ]; then
compare_rev="$(git rev-parse HEAD~1)"
else
@@ -81,7 +84,8 @@ jobs:
fi
fi
- git diff --name-only "$compare_rev" "$GITHUB_SHA" > /tmp/changed-files
+ printf '%s\n' "$compare_rev" > /tmp/base-revision
+ git diff --name-only --no-renames "$compare_rev" "$GITHUB_SHA" > /tmp/changed-files
shell: bash
- id: doppler-bins
name: compute affected Doppler config bins
@@ -104,35 +108,54 @@ jobs:
run: |
set -euo pipefail
- # Root cargo/toolchain/CI changes can affect the whole workspace, so run all tests.
- # `.sqlx/` is deliberately not in this list: the test job compiles queries against
- # live Postgres (SQLX_OFFLINE is unset there), so `.sqlx` contents cannot change
- # test outcomes, and a query change always comes with a source change in the
- # owning crate, which the package filter below already maps.
- if grep -qE '^(Cargo\.(toml|lock)|rust-toolchain\.toml|Cross\.toml|clippy\.toml|deny\.toml|\.cargo/.*|\.config/.*|flake\.nix|flake\.lock|\.github/actions/(setup-rust|setup-nix|setup-nix-dev-shell|setup-sccache)/.*|\.github/workflows/code_check_cloud_storage\.yml)$' /tmp/changed-files; then
- echo "Workspace-level change detected; running all tests"
- echo "nextest_filter=" >> "$GITHUB_OUTPUT"
+ # Writes `rust_packages` for the check/test jobs:
+ # all — compile and run the whole workspace
+ # none — no Rust packages to lint/test (Nix-only, top-level JSON, docs, …)
+ # <names> — space-separated workspace packages (changed + reverse deps)
+ #
+ # `skip_tests=true` keeps clippy on a package set while the live-Postgres
+ # test job stays skipped (used for `.sqlx`-only diffs).
+ #
+ # Root Cargo/toolchain/config edits force `all`. Cargo.lock is handled by
+ # determinator's old/new graph comparison. flake.nix, the Nix shell action,
+ # and this workflow file used to live on the full-suite list and turned every
+ # dev-shell tweak into a full-suite rebuild.
+
+ echo "skip_tests=false" >> "$GITHUB_OUTPUT"
+
+ if [ ! -s /tmp/changed-files ]; then
+ echo "Unknown or empty change set; running all tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+
+ if grep -qE '^(Cargo\.toml|rust-toolchain\.toml|Cross\.toml|clippy\.toml|deny\.toml|\.cargo/.*|\.config/.*)$' /tmp/changed-files; then
+ echo "Workspace-level Cargo/toolchain change detected; running all tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
exit 0
fi
- # A diff touching only `.sqlx/` needs no tests at all — without this it would
- # fall through to the empty-filter "run everything" fallback below. `none()`
- # selects zero tests, which `--no-tests=pass` treats as success. The `-s` guard
- # keeps an empty changed-files list (unknown merge-base) on the full-suite path.
- if [ -s /tmp/changed-files ] && ! grep -qvE '^\.sqlx/' /tmp/changed-files; then
- echo "Only .sqlx changes detected; running no tests"
- echo "nextest_filter=none()" >> "$GITHUB_OUTPUT"
+ # The test job compiles queries against live Postgres (SQLX_OFFLINE is unset
+ # there), so `.sqlx` contents cannot change test outcomes. Clippy is the
+ # offline SQLx check (`SQLX_OFFLINE=true`), so a snapshot-only diff must
+ # still compile against the cache rather than skip the check job.
+ if ! grep -qvE '^\.sqlx/' /tmp/changed-files; then
+ echo "Only .sqlx changes detected; clippy all, skip live-Postgres tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
+ echo "skip_tests=true" >> "$GITHUB_OUTPUT"
exit 0
fi
- filterset="$(cargo run --manifest-path tooling/xtask/Cargo.toml -- nextest-filter /tmp/changed-files)"
+ packages="$(cargo run --manifest-path tooling/xtask/Cargo.toml -- nextest-filter /tmp/changed-files "$(< /tmp/base-revision)")"
- if [ -z "$filterset" ]; then
- echo "No package-specific Rust changes detected; running all tests"
- else
- echo "nextest filter: $filterset"
+ if [ -z "$packages" ] || [ "$packages" = "none" ]; then
+ echo "No package-specific Rust changes detected; running no tests"
+ echo "rust_packages=none" >> "$GITHUB_OUTPUT"
+ exit 0
fi
- echo "nextest_filter=$filterset" >> "$GITHUB_OUTPUT"
+
+ echo "rust packages: $packages"
+ echo "rust_packages=$packages" >> "$GITHUB_OUTPUT"
shell: bash
check:
needs:
@@ -232,14 +255,50 @@ jobs:
run: cargo fmt --check
- name: clippy
run: |
- cargo clippy --workspace --all-features \
- --exclude sync_service
- # sync-service has mutually exclusive storage features, so lint its
- # supported default feature set separately. These two existing lints
- # predate its inclusion in the root workspace.
- cargo clippy -p sync_service -- \
- -A clippy::unnecessary_map_or \
- -A clippy::collapsible_if
+ set -euo pipefail
+
+ # Mirrors run_tests.sh package selection so clippy only lints the crates this
+ # PR can actually affect. `all` keeps the historical workspace invocation,
+ # including sync_service's special-cased feature set.
+
+ packages="${RUST_PACKAGES:-}"
+
+ clippy_sync_service() {
+ cargo clippy -p sync_service -- \
+ -A clippy::unnecessary_map_or \
+ -A clippy::collapsible_if
+ }
+
+ if [ -z "$packages" ] || [ "$packages" = "all" ]; then
+ cargo clippy --workspace --all-features --exclude sync_service
+ clippy_sync_service
+ exit 0
+ fi
+
+ if [ "$packages" = "none" ]; then
+ echo "No Rust packages to lint"
+ exit 0
+ fi
+
+ sync=false
+ pkg_args=()
+ for p in $packages; do
+ if [ "$p" = "sync_service" ]; then
+ sync=true
+ else
+ pkg_args+=(-p "$p")
+ fi
+ done
+
+ if [ "${#pkg_args[@]}" -gt 0 ]; then
+ cargo clippy --all-features "${pkg_args[@]}"
+ fi
+
+ if [ "$sync" = true ]; then
+ clippy_sync_service
+ fi
+ env:
+ RUST_PACKAGES: ${{ needs.path-check.outputs.rust_packages }}
- name: show sccache stats
if: always()
run: sccache --show-stats || true
@@ -249,10 +308,10 @@ jobs:
test:
needs:
- path-check
- if: needs.path-check.outputs.should_run == 'true' && github.event.pull_request.draft == false
+ if: needs.path-check.outputs.should_run == 'true' && github.event.pull_request.draft == false && needs.path-check.outputs.rust_packages != 'none' && needs.path-check.outputs.skip_tests != 'true'
runs-on: namespace-profile-linux-rust-ci;overrides.cache-tag=sccache-ci
env:
- NEXTEST_FILTER: ${{ needs.path-check.outputs.nextest_filter }}
+ RUST_PACKAGES: ${{ needs.path-check.outputs.rust_packages }}
NEXTEST_TEST_THREADS: '32'
RUSTFLAGS: '-Dwarnings -C link-arg=-fuse-ld=mold'
services:
@@ -340,15 +399,41 @@ jobs:
run: just setup_test_envs && just initialize_dbs
- name: run tests
run: |
- # --no-tests=pass: a package filter (e.g. an xtask/tooling-only PR -> rdeps(=xtask))
- # can legitimately select zero tests; treat that as success, not nextest's default error.
- # sync-service was not part of this suite before it joined the root workspace,
- # and its storage backends are mutually exclusive under --all-features.
- args=(--workspace --exclude sync_service --all-features --lib --bins --tests --no-tests=pass --test-threads "$NEXTEST_TEST_THREADS")
- if [ -n "$NEXTEST_FILTER" ]; then
- args+=(-E "$NEXTEST_FILTER")
+ set -euo pipefail
+
+ # --no-tests=pass: a package filter can legitimately select a crate with no
+ # tests; treat that as success, not nextest's default error.
+ # sync-service is not part of this suite, and its storage backends are mutually
+ # exclusive under --all-features.
+ #
+ # Package selection uses `cargo nextest run -p`, not `--workspace -E rdeps(...)`.
+ # The filterset only decides which tests *run* after a workspace build; `-p`
+ # is what keeps an unrelated crate's test binary from being compiled.
+ #
+ # `--lib --bins --tests` is safe with `--workspace` (cargo skips packages that
+ # lack a given target type) but fails with `-p` when any selected package has
+ # no lib — xtask binaries such as xtask_nextest_filter / xtask_workflows.
+ # Unconstrained `-p` still runs that package's tests.
+
+ : "${RUST_PACKAGES:?RUST_PACKAGES is required}"
+ common=(--all-features --no-tests=pass --test-threads "$NEXTEST_TEST_THREADS")
+
+ if [ "$RUST_PACKAGES" = "all" ]; then
+ cargo nextest run --workspace --exclude sync_service --lib --bins --tests "${common[@]}"
+ exit 0
fi
- cargo nextest run "${args[@]}"
+
+ pkg_args=()
+ for package in $RUST_PACKAGES; do
+ [ "$package" = "sync_service" ] || pkg_args+=(-p "$package")
+ done
+
+ if [ "${#pkg_args[@]}" -eq 0 ]; then
+ echo "No packages in the test suite were affected"
+ exit 0
+ fi
+
+ cargo nextest run "${common[@]}" "${pkg_args[@]}"
- name: show sccache stats
if: always()
run: sccache --show-stats || true
diff --git a/.github/workflows/pulumi_preview_pr.yml b/.github/workflows/pulumi_preview_pr.yml
index 31eb3a8aa6..9ebad9544e 100644
--- a/.github/workflows/pulumi_preview_pr.yml
+++ b/.github/workflows/pulumi_preview_pr.yml
@@ -16,7 +16,6 @@ on:
- .sqlx/**
- crates/**
- services/**
- - tooling/xtask/**
- tooling/just/**
- static_assets/**
- docker/**
@@ -32,6 +31,7 @@ on:
- .github/actions/teardown-nix/**
- .github/scripts/build-cloud-storage-lambdas-nix.sh
- .github/services-config.json
+ - .github/workspace-dep-closures.json
permissions:
contents: read
pull-requests: write
@@ -61,7 +61,6 @@ jobs:
.sqlx/**
crates/**
services/**
- tooling/xtask/**
tooling/just/**
static_assets/**
docker/**
@@ -77,6 +76,7 @@ jobs:
.github/actions/teardown-nix/**
.github/scripts/build-cloud-storage-lambdas-nix.sh
.github/services-config.json
+ .github/workspace-dep-closures.json
write_output_files: 'true'
- id: detect
name: Detect affected services
@@ -91,12 +91,15 @@ jobs:
service_changed=false
# Workspace/build-system changes can affect every deployable.
+ # `.sqlx/` lives at the repo root, so a snapshot-only edit would
+ # otherwise match no service path or dependency-closure entry.
+ # A crate source edit is not in this list: those preview only the
+ # services whose deploy binaries depend on the crate.
while IFS= read -r file; do
if [[ "$file" == "Cargo.toml" || "$file" == "Cargo.lock" || \
- "$file" == "Cross.toml" || "$file" == "clippy.toml" || \
+ "$file" == "Cross.toml" || \
"$file" == "rust-toolchain.toml" || "$file" == .cargo/* || \
"$file" == .config/* || "$file" == .sqlx/* || \
- "$file" == crates/* || "$file" == tooling/xtask/* || \
"$file" == tooling/just/* || "$file" == static_assets/* || \
"$file" == docker/* || "$file" == "flake.nix" || \
"$file" == "flake.lock" || "$file" == nix/* || \
@@ -115,7 +118,8 @@ jobs:
"$file" == .github/actions/preview-cloud-storage-pulumi/* || \
"$file" == .github/actions/setup-nix/* || \
"$file" == .github/actions/teardown-nix/* || \
- "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" ]]; then
+ "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" || \
+ "$file" == ".github/workspace-dep-closures.json" ]]; then
service_changed=true
break
fi
@@ -139,6 +143,35 @@ jobs:
done < .github/outputs/all_changed_files.txt
fi
+ # Match crate/service source against each deployable's workspace
+ # dependency closure so `crates/foo` previews foo's consumers, not
+ # every stack. Binary names that are not package names are mapped
+ # onto the crate that contains them.
+ if [[ "$service_changed" != "true" ]]; then
+ crates=$(echo "$config" | jq -r --arg s "$service" '
+ [(.services[$s].deploy_binaries // [])[], (.services[$s].deploy_lambdas // [])[]]
+ | map(
+ if . == "connection_gateway_service" then "connection_gateway"
+ elif . == "service" then "scheduled_action"
+ elif . == "pubsub_workers" then "email_service"
+ else . end
+ )
+ | unique | .[]
+ ')
+ while IFS= read -r crate; do
+ [[ -z "$crate" ]] && continue
+ while IFS= read -r dir; do
+ [[ -z "$dir" ]] && continue
+ while IFS= read -r file; do
+ if [[ "$file" == "$dir" || "$file" == "$dir"/* ]]; then
+ service_changed=true
+ break 3
+ fi
+ done < .github/outputs/all_changed_files.txt
+ done < <(jq -r --arg c "$crate" '.closures[$c] // empty | .[]' .github/workspace-dep-closures.json)
+ done <<< "$crates"
+ fi
+
if [[ "$service_changed" == "true" ]]; then
services+=("$service")
fi
diff --git a/.github/workflows/web-app-check-main.yml b/.github/workflows/web-app-check-main.yml
index 83122ff172..4a822d5aec 100644
--- a/.github/workflows/web-app-check-main.yml
+++ b/.github/workflows/web-app-check-main.yml
@@ -38,22 +38,15 @@ jobs:
- 'Cargo.lock'
- 'rust-toolchain.toml'
- 'services/lexical-service/**'
- - '.github/actions/setup-nix-dev-shell/**'
- '.github/actions/setup-reqs-web/**'
- - '.github/workflows/web-app-check-main.yml'
api_changed:
- 'crates/**/*.rs'
- 'services/**/*.rs'
- - 'tooling/xtask/**/*.rs'
- 'Cargo.toml'
- 'Cargo.lock'
- - 'flake.nix'
- - 'flake.lock'
- 'apps/web/scripts/generate-api-schema.ts'
- 'apps/web/scripts/services.ts'
- - '.github/actions/setup-nix-dev-shell/**'
- '.github/actions/setup-reqs-web/**'
- - '.github/workflows/web-app-check-main.yml'
typescript:
needs:
- path-check
diff --git a/Cargo.lock b/Cargo.lock
index a7165222f3..baf2fab809 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4924,6 +4924,23 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "determinator"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf14b901cdfba3f731d01c4c184100e85f586a272d38874824175b845dbaeaf9"
+dependencies = [
+ "camino",
+ "globset",
+ "guppy",
+ "guppy-workspace-hack",
+ "once_cell",
+ "petgraph 0.6.5",
+ "rayon",
+ "serde",
+ "toml 0.5.11",
+]
+
[[package]]
name = "device-info"
version = "0.1.1"
@@ -18683,6 +18700,7 @@ dependencies = [
"dotenvy",
"indexmap 2.14.0",
"indicatif",
+ "indoc",
"libc",
"macro_aws_config",
"macro_env_var",
@@ -18703,8 +18721,11 @@ name = "xtask_nextest_filter"
version = "0.1.0"
dependencies = [
"anyhow",
+ "determinator",
"guppy",
+ "tempfile",
"xtask_graph",
+ "xtask_paths",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index ef50db2241..f6174016bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -181,6 +181,7 @@ cron = "0.16.0"
csv = "1"
dashmap = "6.1.0"
dateparser = "0.2.1"
+determinator = "0.12.0"
dotenvy = "0.15.7"
ego-tree = "0.6.2"
either = "1"
@@ -201,6 +202,7 @@ http-body-util = "0.1.2"
httpdate = "1"
image = "0.25"
indexmap = "2"
+indoc = "2"
inquire = "0.7"
itertools = "0.14"
jsonwebtoken = { git = "https://github.com/whutchinson98/jsonwebtoken", features = [
@@ -285,6 +287,7 @@ sqlx = { version = "0.8.6", features = [
] }
sqlx-core = { version = "0.8.6" }
strum = { version = "0.27.1", features = ["derive"] }
+tempfile = "3"
thiserror = "2.0.0"
time = "0.3.37"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
diff --git a/crates/client/cache-turso/Cargo.toml b/crates/client/cache-turso/Cargo.toml
index a4d1f122c4..a61dea026a 100644
--- a/crates/client/cache-turso/Cargo.toml
+++ b/crates/client/cache-turso/Cargo.toml
@@ -27,7 +27,7 @@ pollster = { workspace = true }
serde_json = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
-tempfile = "3"
+tempfile = { workspace = true }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = { workspace = true }
diff --git a/services/upload_extractor_lambda_handler/Cargo.toml b/services/upload_extractor_lambda_handler/Cargo.toml
index d31593a624..9da0580d6f 100644
--- a/services/upload_extractor_lambda_handler/Cargo.toml
+++ b/services/upload_extractor_lambda_handler/Cargo.toml
@@ -29,7 +29,7 @@ serde_json = { workspace = true }
macro_service_urls = { path = "../../crates/macro_service_urls" }
sha2 = { workspace = true }
sqs_client = { path = "../../crates/sqs_client" }
-tempfile = "3.19.1"
+tempfile = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
tokio-util = { workspace = true }
diff --git a/tooling/seed_cli/Cargo.toml b/tooling/seed_cli/Cargo.toml
index 899ee80177..9e27935fed 100644
--- a/tooling/seed_cli/Cargo.toml
+++ b/tooling/seed_cli/Cargo.toml
@@ -51,4 +51,4 @@ uuid = { workspace = true }
workspace-hack = { version = "0.1", path = "../../crates/workspace-hack" }
[dev-dependencies]
-tempfile = "3"
+tempfile = { workspace = true }
diff --git a/tooling/xtask/crates/xtask_graph/src/lib.rs b/tooling/xtask/crates/xtask_graph/src/lib.rs
index b08e98af7a..ef18660d34 100644
--- a/tooling/xtask/crates/xtask_graph/src/lib.rs
+++ b/tooling/xtask/crates/xtask_graph/src/lib.rs
@@ -8,6 +8,7 @@
use anyhow::{Context, Result};
use guppy::MetadataCommand;
use guppy::graph::PackageGraph;
+use std::path::Path;
/// Build the workspace [`PackageGraph`] via `cargo metadata`.
///
@@ -16,8 +17,13 @@ use guppy::graph::PackageGraph;
/// silently rewritten.
pub fn build_graph(locked: bool) -> Result<PackageGraph> {
let workspace_dir = xtask_paths::workspace_root();
+ build_graph_at(&workspace_dir, locked)
+}
+
+/// Build a [`PackageGraph`] for the workspace rooted at `workspace_dir`.
+pub fn build_graph_at(workspace_dir: &Path, locked: bool) -> Result<PackageGraph> {
let mut cmd = MetadataCommand::new();
- cmd.current_dir(&workspace_dir);
+ cmd.current_dir(workspace_dir);
if locked {
cmd.other_options(vec!["--locked".to_owned()]);
}
diff --git a/tooling/xtask/crates/xtask_local/Cargo.toml b/tooling/xtask/crates/xtask_local/Cargo.toml
index 3a1c9b57d6..451a9beed9 100644
--- a/tooling/xtask/crates/xtask_local/Cargo.toml
+++ b/tooling/xtask/crates/xtask_local/Cargo.toml
@@ -41,6 +41,7 @@ console = "0.15"
indicatif = "0.18.5"
docker-compose-types = { version = "0.24", features = ["indexmap"] }
indexmap = { workspace = true }
+indoc = { workspace = true }
serde_yaml = { workspace = true }
# Parse user-provided `--env-file` overlays. EnumIter derives the port list.
dotenvy = { workspace = true }
diff --git a/tooling/xtask/crates/xtask_local/src/main.rs b/tooling/xtask/crates/xtask_local/src/main.rs
index 890d9ea8f1..dfcddd051a 100644
--- a/tooling/xtask/crates/xtask_local/src/main.rs
+++ b/tooling/xtask/crates/xtask_local/src/main.rs
@@ -13,7 +13,16 @@ use anyhow::Result;
/// The repo-automation verbs handled by the launcher. Shown alongside this
/// crate's own clap usage when an unrecognized command reaches the parser.
-const LAUNCHER_USAGE: &str = "repo automation (from the repository root):\n cargo x deps [--check]\n cargo x nextest-filter <changed-files-path>\n cargo x doppler-bins <changed-files-path>\n cargo x graphql-soup-schema <output-path>\n cargo x cache-wasm [--force]\n cargo x kafka-topics [--check]\n cargo x workflows [--check]";
+const LAUNCHER_USAGE: &str = indoc::indoc! {"
+ repo automation (from the repository root):
+ cargo x deps [--check]
+ cargo x nextest-filter <changed-files-path> <base-revision>
+ cargo x doppler-bins <changed-files-path>
+ cargo x graphql-soup-schema <output-path>
+ cargo x cache-wasm [--force]
+ cargo x kafka-topics [--check]
+ cargo x workflows [--check]
+"};
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().skip(1).collect();
diff --git a/tooling/xtask/crates/xtask_nextest_filter/Cargo.toml b/tooling/xtask/crates/xtask_nextest_filter/Cargo.toml
index ffb8dc6460..aaf2508aaf 100644
--- a/tooling/xtask/crates/xtask_nextest_filter/Cargo.toml
+++ b/tooling/xtask/crates/xtask_nextest_filter/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-description = "xtask nextest-filter: nextest rdeps package filter for a set of changed files"
+description = "xtask nextest-filter: affected Cargo packages for a set of changed files"
edition = "2024"
name = "xtask_nextest_filter"
publish = false
@@ -11,5 +11,8 @@ path = "src/main.rs"
[dependencies]
anyhow = { workspace = true }
+determinator = { workspace = true }
guppy = { workspace = true }
+tempfile = { workspace = true }
xtask_graph = { path = "../xtask_graph" }
+xtask_paths = { path = "../xtask_paths" }
diff --git a/tooling/xtask/crates/xtask_nextest_filter/determinator.toml b/tooling/xtask/crates/xtask_nextest_filter/determinator.toml
new file mode 100644
index 0000000000..f47e2406ae
--- /dev/null
+++ b/tooling/xtask/crates/xtask_nextest_filter/determinator.toml
@@ -0,0 +1,12 @@
+use-default-rules = false
+
+[[path-rule]]
+globs = ["static_assets/**"]
+mark-changed = [
+ "cache-core",
+ "collab_surface",
+ "complete_graph",
+ "documents",
+ "seed_cli",
+ "xtask_workflows",
+]
diff --git a/tooling/xtask/crates/xtask_nextest_filter/src/main.rs b/tooling/xtask/crates/xtask_nextest_filter/src/main.rs
index 3e9d0ce59f..ab9fb572b1 100644
--- a/tooling/xtask/crates/xtask_nextest_filter/src/main.rs
+++ b/tooling/xtask/crates/xtask_nextest_filter/src/main.rs
@@ -1,136 +1,223 @@
-//! `cargo x nextest-filter <changed-files-path>`
+//! `cargo x nextest-filter <changed-files-path> <base-revision>`
//!
-//! Computes the cargo-nextest package filter for Rust CI.
+//! Computes the set of workspace packages cargo nextest / clippy should run
+//! for Rust CI using [`determinator`].
//!
//! Input is a newline-delimited file of paths relative to the repository root
-//! (typically `git diff --name-only ...`). For each changed path inside the
-//! Rust workspace, find the deepest workspace package containing that
-//! path using Cargo's own workspace metadata via guppy. Shared files that
-//! crates embed from outside their own directory are mapped through
-//! [`EMBEDDED_ASSET_PACKAGES`]. The resulting nextest expression runs tests
-//! for reverse dependencies of every changed package.
+//! (typically `git diff --name-only ...`) and a Git base revision. The command
+//! builds Cargo metadata for the base and current revisions, then lets
+//! determinator account for path, dependency, and feature changes. Shared
+//! inputs that Cargo does not know about are declared in `determinator.toml`.
+//!
+//! Stdout is one of:
+//! - `all` — every workspace package is affected.
+//! - `none` — no changed file mapped to a package (a top-level JSON, a Nix
+//! shell tweak, docs, …). CI must not treat this as "run everything".
+//! - space-separated package names — pass each as `cargo nextest run -p` /
+//! `cargo clippy -p`.
use std::collections::BTreeSet;
+use std::fmt;
use std::path::{Path, PathBuf};
+use std::process::{Command, Stdio};
use anyhow::{Context, Result, bail};
-use guppy::graph::PackageGraph;
+use determinator::Determinator;
+use determinator::rules::{DeterminatorRules, PathMatch};
+use guppy::graph::{DependencyDirection, PackageGraph};
+use tempfile::TempDir;
+#[cfg(test)]
use xtask_graph::build_graph;
+use xtask_graph::build_graph_at;
#[cfg(test)]
mod test;
-/// Workspace paths that crates consume at compile time from outside their own
-/// directory (`include_str!`/`include_bytes!` or `build.rs` reads), mapped to
-/// the consuming packages. Directory containment cannot attribute these, so
-/// without an entry here a change to such a file would select no tests
-/// whenever the PR also touches a package. The drift test in `test.rs` keeps
-/// this table in sync with the source tree, and every run validates the
-/// package names against the workspace so a rename fails loudly.
-const EMBEDDED_ASSET_PACKAGES: &[(&str, &[&str])] = &[(
- "static_assets",
- &[
- "cache-core",
- "collab_surface",
- "complete_graph",
- "documents",
- "seed_cli",
- "xtask_workflows",
- ],
-)];
+const DETERMINATOR_RULES: &str = include_str!("../determinator.toml");
+
+/// Which workspace packages Rust CI should compile and test.
+///
+/// Stringified only at the CLI seam (`Display`) so bash can switch on `all`,
+/// `none`, or a space-separated package list.
+#[derive(Debug, Clone, PartialEq, Eq)]
+enum PackageSelection {
+ /// Every workspace package is affected.
+ All,
+ /// No changed file mapped to a package.
+ None,
+ /// Changed packages plus reverse dependencies.
+ Packages(BTreeSet<String>),
+}
+
+impl fmt::Display for PackageSelection {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::All => f.write_str("all"),
+ Self::None => f.write_str("none"),
+ Self::Packages(packages) => {
+ let mut first = true;
+ for name in packages {
+ if !first {
+ f.write_str(" ")?;
+ }
+ first = false;
+ f.write_str(name)?;
+ }
+ Ok(())
+ }
+ }
+ }
+}
+
+#[cfg(test)]
+impl PackageSelection {
+ fn packages(&self) -> Option<&BTreeSet<String>> {
+ match self {
+ Self::Packages(packages) => Some(packages),
+ Self::All | Self::None => None,
+ }
+ }
+}
fn main() -> Result<()> {
- let args: Vec<String> = std::env::args().skip(1).collect();
- match args.iter().map(String::as_str).collect::<Vec<_>>()[..] {
- [changed_files_path] => {
- // Read-only: `--locked` so computing the filter never rewrites Cargo.lock.
- let graph = build_graph(true)?;
- run(&graph, Path::new(changed_files_path))
+ let args: Vec<_> = std::env::args_os().skip(1).collect();
+ match args.as_slice() {
+ [changed_files_path, base_revision] => {
+ let base_revision = base_revision
+ .to_str()
+ .context("base revision is not valid UTF-8")?;
+ run(Path::new(changed_files_path), base_revision)
}
- _ => bail!("usage: cargo x nextest-filter <changed-files-path>"),
+ _ => bail!("usage: cargo x nextest-filter <changed-files-path> <base-revision>"),
}
}
-fn run(graph: &PackageGraph, changed_files_path: &Path) -> Result<()> {
+fn run(changed_files_path: &Path, base_revision: &str) -> Result<()> {
let changed_files = std::fs::read_to_string(changed_files_path).with_context(|| {
format!(
"reading changed files from {}",
changed_files_path.display()
)
})?;
-
- let filter = compute_filter(graph, &changed_files)?;
- println!("{filter}");
+ let changed_files: Vec<PathBuf> = changed_files
+ .lines()
+ .filter(|line| !line.is_empty())
+ .map(PathBuf::from)
+ .collect();
+
+ let workspace_dir = xtask_paths::workspace_root();
+ let base_worktree = BaseWorktree::new(&workspace_dir, base_revision)?;
+ let (old_graph, new_graph) = build_graphs(base_worktree.path(), &workspace_dir)?;
+ let packages = compute_packages(&old_graph, &new_graph, &changed_files)?;
+ println!("{packages}");
Ok(())
}
-/// Map each changed path to its owning workspace package (or embedded-asset
-/// consumers) and combine them into one nextest filterset expression. An
-/// empty result means no changed file mapped to a package; CI treats that as
-/// "run everything".
-fn compute_filter(graph: &PackageGraph, changed_files: &str) -> Result<String> {
- let workspace = graph.workspace();
- let ws_root = workspace.root();
- let repo_root = ws_root;
-
- let packages = workspace
- .iter()
- .map(|package| {
- let dir = package
- .manifest_path()
- .parent()
- .with_context(|| format!("manifest {} has no parent", package.manifest_path()))?;
- Ok((PathBuf::from(dir.as_std_path()), package.name().to_owned()))
- })
- .collect::<Result<Vec<_>>>()?;
+fn build_graphs(base_dir: &Path, current_dir: &Path) -> Result<(PackageGraph, PackageGraph)> {
+ Ok((
+ build_graph_at(base_dir, true)?,
+ build_graph_at(current_dir, true)?,
+ ))
+}
- let package_names: BTreeSet<&str> = packages.iter().map(|(_, name)| name.as_str()).collect();
- for (prefix, names) in EMBEDDED_ASSET_PACKAGES {
- if let Some(name) = names.iter().find(|name| !package_names.contains(**name)) {
- bail!(
- "EMBEDDED_ASSET_PACKAGES maps `{prefix}` to `{name}`, which is not a \
- workspace package; update the table in {}",
- file!()
- );
+/// Use determinator to compare both Cargo graphs and return affected package
+/// names. Paths outside Cargo packages contribute nothing, preserving the CI
+/// behavior for Nix-only and other non-Rust changes.
+fn compute_packages(
+ old_graph: &PackageGraph,
+ new_graph: &PackageGraph,
+ changed_files: &[PathBuf],
+) -> Result<PackageSelection> {
+ let rules = DeterminatorRules::parse(DETERMINATOR_RULES)
+ .context("parsing nextest determinator rules")?;
+ let mut determinator = Determinator::new(old_graph, new_graph);
+ determinator
+ .set_rules(&rules)
+ .context("applying nextest determinator rules")?;
+
+ for changed_file in changed_files {
+ let changed_file = changed_file
+ .to_str()
+ .context("changed file path is not valid UTF-8")?;
+ if !matches!(
+ determinator.match_path(changed_file, |_| {}),
+ PathMatch::NoMatches
+ ) {
+ determinator.add_changed_paths([changed_file]);
}
}
- let mut changed_packages = BTreeSet::new();
- for changed_file in changed_files.lines().filter(|line| !line.is_empty()) {
- for (prefix, names) in EMBEDDED_ASSET_PACKAGES {
- if Path::new(changed_file).starts_with(prefix) {
- changed_packages.extend(names.iter().map(|name| (*name).to_owned()));
- }
- }
+ let affected = determinator.compute().affected_set;
+ let packages: BTreeSet<_> = affected
+ .packages(DependencyDirection::Forward)
+ .filter(|package| package.in_workspace())
+ .map(|package| package.name().to_owned())
+ .collect();
- let path = repo_root
- .join(changed_file)
- .canonicalize()
- .unwrap_or_else(|_| repo_root.join(changed_file).into());
- if path != ws_root.as_std_path() && !path.starts_with(ws_root.as_std_path()) {
- continue;
- }
+ if packages.is_empty() {
+ return Ok(PackageSelection::None);
+ }
- let package = packages
- .iter()
- .filter(|(dir, _)| path == *dir || path.starts_with(dir))
- .max_by_key(|(dir, _)| dir.components().count())
- .map(|(_, name)| name);
+ if packages.len() == new_graph.workspace().iter().count() {
+ return Ok(PackageSelection::All);
+ }
+
+ Ok(PackageSelection::Packages(packages))
+}
+
+struct BaseWorktree {
+ repo_root: PathBuf,
+ path: PathBuf,
+ _temp_dir: TempDir,
+}
- if let Some(name) = package {
- changed_packages.insert(name.clone());
+impl BaseWorktree {
+ fn new(repo_root: &Path, revision: &str) -> Result<Self> {
+ let temp_dir = tempfile::Builder::new()
+ .prefix("nextest-determinator-")
+ .tempdir()
+ .context("creating temporary directory for base worktree")?;
+ let path = temp_dir.path().join("base");
+ let output = Command::new("git")
+ .current_dir(repo_root)
+ .args(["worktree", "add", "--detach"])
+ .arg(&path)
+ .arg(revision)
+ .output()
+ .context("creating base Git worktree")?;
+ if !output.status.success() {
+ bail!(
+ "creating base Git worktree failed: {}",
+ String::from_utf8_lossy(&output.stderr).trim()
+ );
}
+
+ Ok(Self {
+ repo_root: repo_root.to_owned(),
+ path,
+ _temp_dir: temp_dir,
+ })
}
- Ok(changed_packages
- .into_iter()
- .map(|name| format!("rdeps(={})", escape_nextest_name(&name)))
- .collect::<Vec<_>>()
- .join("|"))
+ fn path(&self) -> &Path {
+ &self.path
+ }
}
-fn escape_nextest_name(name: &str) -> String {
- name.replace('\\', "\\\\")
- .replace(')', "\\)")
- .replace(',', "\\,")
+impl Drop for BaseWorktree {
+ fn drop(&mut self) {
+ let result = Command::new("git")
+ .current_dir(&self.repo_root)
+ .args(["worktree", "remove", "--force"])
+ .arg(&self.path)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .status();
+ if !matches!(result, Ok(status) if status.success()) {
+ eprintln!(
+ "warning: failed to unregister temporary worktree {}",
+ self.path.display()
+ );
+ }
+ }
}
diff --git a/tooling/xtask/crates/xtask_nextest_filter/src/test.rs b/tooling/xtask/crates/xtask_nextest_filter/src/test.rs
index c79e4b6f31..ded39134aa 100644
--- a/tooling/xtask/crates/xtask_nextest_filter/src/test.rs
+++ b/tooling/xtask/crates/xtask_nextest_filter/src/test.rs
@@ -1,57 +1,131 @@
use super::*;
-/// A change in a single crate selects only that crate's reverse dependencies.
+fn changed_files(paths: &[&str]) -> Vec<PathBuf> {
+ paths.iter().map(PathBuf::from).collect()
+}
+
+fn selected_packages(selection: &PackageSelection) -> &BTreeSet<String> {
+ selection
+ .packages()
+ .unwrap_or_else(|| panic!("expected targeted packages, got {selection:?}"))
+}
+
+/// The CLI prints `all` / `none` / space-separated names; bash switches on those
+/// tokens and must not see an empty string for an unmapped change.
+#[test]
+fn display_is_the_cli_seam() {
+ assert_eq!(PackageSelection::All.to_string(), "all");
+ assert_eq!(PackageSelection::None.to_string(), "none");
+ assert_eq!(
+ PackageSelection::Packages(BTreeSet::from([
+ "email_validator".to_owned(),
+ "webhook".to_owned(),
+ ]))
+ .to_string(),
+ "email_validator webhook"
+ );
+}
+
+/// A change in a single crate selects that crate and its reverse dependencies,
+/// never the whole workspace.
#[test]
fn crate_change_maps_to_rdeps_of_that_crate() {
let graph = build_graph(false).expect("cargo metadata");
- let filter = compute_filter(&graph, "crates/email_validator/src/lib.rs\n").unwrap();
- assert_eq!(filter, "rdeps(=email_validator)");
+ let selection = compute_packages(
+ &graph,
+ &graph,
+ &changed_files(&["crates/email_validator/src/lib.rs"]),
+ )
+ .unwrap();
+ assert_ne!(selection, PackageSelection::None);
+ assert_ne!(selection, PackageSelection::All);
+ assert!(
+ selected_packages(&selection).contains("email_validator"),
+ "changed crate must be selected: {selection:?}"
+ );
+}
+
+/// Top-level files that belong to no package — a JSON at the repo root, a
+/// README, a deleted misc file — must not select the full suite.
+#[test]
+fn unmapped_files_alone_yield_none() {
+ let graph = build_graph(false).expect("cargo metadata");
+ let selection = compute_packages(
+ &graph,
+ &graph,
+ &changed_files(&["random.json", "package.json", "docs/README.md", "justfile"]),
+ )
+ .unwrap();
+ assert_eq!(selection, PackageSelection::None);
}
-/// Changed files inside the workspace that belong to no package (and are not
-/// embedded assets) contribute nothing, leaving the filter empty so CI falls
-/// back to the full suite.
+/// Package-local metadata files still select their package because some are
+/// compile-time inputs (for example, webhook embeds its README).
#[test]
-fn unmapped_files_alone_yield_empty_filter() {
+fn package_readme_selects_its_package() {
let graph = build_graph(false).expect("cargo metadata");
- let filter = compute_filter(&graph, "docs/README.md\njustfile\n").unwrap();
- assert_eq!(filter, "");
+ let selection = compute_packages(
+ &graph,
+ &graph,
+ &changed_files(&["crates/webhook/README.md"]),
+ )
+ .unwrap();
+ assert!(
+ selected_packages(&selection).contains("webhook"),
+ "package README must select its owner: {selection:?}"
+ );
}
/// Shared assets embedded into crates from outside their directories select
-/// their consumers, including when the change list also contains ordinary
-/// package files (previously the asset change was silently dropped).
+/// their consumers (and those consumers' reverse deps).
#[test]
fn embedded_assets_select_their_consumers() {
let graph = build_graph(false).expect("cargo metadata");
- let filter = compute_filter(&graph, "static_assets/schema.graphql\n").unwrap();
- assert_eq!(
- filter,
- "rdeps(=cache-core)|rdeps(=collab_surface)|rdeps(=complete_graph)|rdeps(=documents)|rdeps(=seed_cli)|rdeps(=xtask_workflows)"
- );
+ let selection = compute_packages(
+ &graph,
+ &graph,
+ &changed_files(&["static_assets/schema.graphql"]),
+ )
+ .unwrap();
+ let set = selected_packages(&selection);
+ for expected in [
+ "cache-core",
+ "collab_surface",
+ "complete_graph",
+ "documents",
+ "seed_cli",
+ "xtask_workflows",
+ ] {
+ assert!(
+ set.contains(expected),
+ "embedded asset consumers must include {expected}: {selection:?}"
+ );
+ }
- let mixed = compute_filter(
+ let mixed = compute_packages(
+ &graph,
&graph,
- "crates/email_validator/src/lib.rs\nstatic_assets/markdown-golden.1.bin\n",
+ &changed_files(&[
+ "crates/email_validator/src/lib.rs",
+ "static_assets/markdown-golden.1.bin",
+ ]),
)
.unwrap();
- assert_eq!(
- mixed,
- "rdeps(=cache-core)|rdeps(=collab_surface)|rdeps(=complete_graph)|rdeps(=documents)|rdeps(=email_validator)|rdeps(=seed_cli)|rdeps(=xtask_workflows)"
- );
+ let mixed_set = selected_packages(&mixed);
+ assert!(mixed_set.contains("email_validator"));
+ assert!(mixed_set.contains("documents"));
+ assert!(mixed_set.contains("collab_surface"));
}
-/// Drift check: every workspace package whose Rust sources mention an
-/// [`EMBEDDED_ASSET_PACKAGES`] path prefix must be listed in the table (and
-/// vice versa), so new compile-time embeds of shared assets never silently
-/// escape the CI test filter. The scan is textual, so a doc-comment mention
-/// counts; listing such a package merely over-selects, which is the safe
-/// direction.
+/// Drift check: every workspace package whose Rust sources mention the shared
+/// asset path must be listed in the determinator rule (and vice versa). The
+/// scan is textual, so a doc-comment mention merely over-selects safely.
#[test]
fn embedded_asset_packages_match_source_references() {
let graph = build_graph(false).expect("cargo metadata");
let workspace = graph.workspace();
+ let prefix = "static_assets";
let packages: Vec<(PathBuf, String)> = workspace
.iter()
@@ -66,36 +140,44 @@ fn embedded_asset_packages_match_source_references() {
collect_rust_files(dir, &mut rust_files);
}
- for (prefix, expected) in EMBEDDED_ASSET_PACKAGES {
- let mut found = BTreeSet::new();
- for file in &rust_files {
- let content = std::fs::read_to_string(file).unwrap_or_default();
- if !content.contains(prefix) {
- continue;
- }
- // Attribute the file to its deepest containing package, mirroring
- // compute_filter, so nested workspaces (tooling/xtask/crates/*)
- // don't credit the parent package.
- let owner = packages
- .iter()
- .filter(|(dir, _)| file.starts_with(dir))
- .max_by_key(|(dir, _)| dir.components().count())
- .map(|(_, name)| name.clone())
- .expect("rust file collected from a package dir");
- // This crate's own sources name the prefixes it maps.
- if owner == env!("CARGO_PKG_NAME") {
- continue;
- }
+ let mut found = BTreeSet::new();
+ for file in &rust_files {
+ let content = std::fs::read_to_string(file).unwrap_or_default();
+ if !content.contains(prefix) {
+ continue;
+ }
+ // Attribute the file to its deepest containing package, mirroring
+ // determinator's nearest-package behavior for nested xtask crates.
+ let owner = packages
+ .iter()
+ .filter(|(dir, _)| file.starts_with(dir))
+ .max_by_key(|(dir, _)| dir.components().count())
+ .map(|(_, name)| name.clone())
+ .expect("rust file collected from a package dir");
+ if owner != env!("CARGO_PKG_NAME") {
found.insert(owner);
}
+ }
- let expected: BTreeSet<String> = expected.iter().map(|name| (*name).to_owned()).collect();
- assert_eq!(
- found, expected,
- "EMBEDDED_ASSET_PACKAGES entry for `{prefix}` is out of sync with the \
- packages whose Rust sources reference it; update the table in main.rs"
+ let rules = DeterminatorRules::parse(DETERMINATOR_RULES).expect("determinator rules");
+ let mut determinator = Determinator::new(&graph, &graph);
+ determinator.set_rules(&rules).expect("set rules");
+ let mut configured = BTreeSet::new();
+ determinator.match_path("static_assets/drift-check", |id| {
+ configured.insert(
+ graph
+ .metadata(id)
+ .expect("package metadata")
+ .name()
+ .to_owned(),
);
- }
+ });
+
+ assert_eq!(
+ found, configured,
+ "determinator rule for `{prefix}` is out of sync with packages whose Rust sources \
+ reference it; update determinator.toml"
+ );
}
/// Recursively collect `.rs` files under `dir`, skipping hidden and build
diff --git a/tooling/xtask/crates/xtask_workflows/Cargo.toml b/tooling/xtask/crates/xtask_workflows/Cargo.toml
index 51e13889cf..f60e36d93e 100644
--- a/tooling/xtask/crates/xtask_workflows/Cargo.toml
+++ b/tooling/xtask/crates/xtask_workflows/Cargo.toml
@@ -14,6 +14,6 @@ anyhow = { workspace = true }
serde_json = { workspace = true }
# Define GitHub Actions workflows in Rust.
gh-workflow = "0.8"
-indoc = "2"
+indoc = { workspace = true }
serde_yaml = { workspace = true }
xtask_paths = { path = "../xtask_paths" }
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
index be25f3463f..674d11438b 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
@@ -32,12 +32,18 @@ pub fn cargo_workspace_dependency_check() -> Workflow {
.add_path(xtask_paths::repo_glob!("Cargo.lock"))
.add_path(xtask_paths::repo_glob!(".config/hakari.toml"))
.add_path(xtask_paths::repo_glob!("crates/workspace-hack/**"))
- .add_path(xtask_paths::repo_glob!("tooling/xtask/**"))
+ // Source of `cargo x deps` only — not every xtask crate. A
+ // nextest-filter or workflow-generator edit cannot drift the
+ // hack crate or closure map.
+ .add_path(xtask_paths::repo_glob!("tooling/xtask/src/**"))
.add_path(xtask_paths::repo_glob!(
- ".github/workspace-dep-closures.json"
+ "tooling/xtask/crates/xtask_deps/**"
+ ))
+ .add_path(xtask_paths::repo_glob!(
+ "tooling/xtask/crates/xtask_graph/**"
))
.add_path(xtask_paths::repo_glob!(
- ".github/workflows/cargo_workspace_dependency_check.yml"
+ ".github/workspace-dep-closures.json"
)),
))
.concurrency(
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
index 24fa212a1e..b905adf0bf 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
@@ -16,6 +16,9 @@ use crate::workflows::{
vars,
};
+#[cfg(test)]
+mod test;
+
/// Build the workflow.
pub fn code_check_cloud_storage() -> Workflow {
Workflow::new("cloud storage code check")
@@ -41,14 +44,20 @@ fn path_check() -> Job {
.runs_on(runners::Runner::Small.to_string())
.add_output("should_run", "${{ steps.filter.outputs.should_run }}")
.add_output(
- "nextest_filter",
- "${{ steps.nextest-filter.outputs.nextest_filter }}",
+ "rust_packages",
+ "${{ steps.nextest-filter.outputs.rust_packages }}",
+ )
+ .add_output(
+ "skip_tests",
+ "${{ steps.nextest-filter.outputs.skip_tests }}",
)
.add_output(
"doppler_config_bins",
"${{ steps.doppler-bins.outputs.doppler_config_bins }}",
)
- .add_step(steps::checkout(true, false))
+ // PR merge commits need both parents for `git merge-base`; fetching
+ // the entire repo (every branch) is not required.
+ .add_step(steps::checkout(false, false).add_with(("fetch-depth", 2)))
.add_step(steps::setup_rust_light())
.add_step(paths_filter())
.add_step(compute_changed_files())
@@ -78,13 +87,18 @@ fn check() -> Job {
.add_step(steps::teardown_nix())
}
-/// cargo nextest against postgres + redis service containers.
+/// cargo nextest against postgres + redis service containers. Skipped when
+/// the path filter selected no Rust packages (Nix-only / unmapped files) or
+/// when `skip_tests` is set (`.sqlx`-only diffs still clippy the snapshot).
fn test() -> Job {
steps::gated_job()
+ .cond(Expression::new(
+ "needs.path-check.outputs.should_run == 'true' && github.event.pull_request.draft == false && needs.path-check.outputs.rust_packages != 'none' && needs.path-check.outputs.skip_tests != 'true'",
+ ))
.runs_on(runners::Runner::RustCi.with_cache_tag(vars::CI_CACHE_TAG))
.add_env((
- "NEXTEST_FILTER",
- "${{ needs.path-check.outputs.nextest_filter }}",
+ "RUST_PACKAGES",
+ "${{ needs.path-check.outputs.rust_packages }}",
))
.add_env(("NEXTEST_TEST_THREADS", vars::NEXTEST_TEST_THREADS))
.add_env(("RUSTFLAGS", "-Dwarnings -C link-arg=-fuse-ld=mold"))
@@ -145,15 +159,13 @@ fn paths_filter() -> Step<gh_workflow::Use> {
- 'services/**'
- 'tooling/xtask/**'
- 'static_assets/**'
+ - 'nix/**'
- 'flake.nix'
- 'flake.lock'
- '.github/actions/setup-nix/**'
- '.github/actions/setup-nix-dev-shell/**'
- '.github/actions/teardown-nix/**'
- '.github/actions/setup-sccache/**'
- - '.github/services-config.json'
- - '.github/scripts/build-cloud-storage-lambdas.sh'
- - '.github/scripts/build-cloud-storage-lambdas-nix.sh'
- .github/workflows/code_check_cloud_storage.yml
"#},
))
@@ -180,9 +192,10 @@ fn compute_doppler_bins() -> Step<Run> {
.shell("bash")
}
-/// Compute the cargo-nextest package filter from the changed files, via the
-/// `xtask nextest-filter` subcommand. Root cargo/toolchain/CI changes
-/// short-circuit to an empty filter (run the whole suite).
+/// Compute the cargo-nextest / clippy package set from the changed files, via
+/// the `xtask nextest-filter` subcommand. Root Cargo/toolchain changes
+/// short-circuit to the full suite; unmapped files (a top-level JSON, a Nix
+/// shell tweak) select no packages.
fn compute_nextest_filter() -> Step<Run> {
Step::new("compute nextest package filter")
.run(include_str!("scripts/compute_nextest_filter.sh"))
@@ -212,18 +225,14 @@ fn cargo_fmt() -> Step<Run> {
Step::new("fmt").run("cargo fmt --check")
}
-/// `cargo clippy` (no AWS credentials; sccache uses Namespace's remote cache).
+/// `cargo clippy`, scoped to the same package set as nextest.
fn cargo_clippy() -> Step<Run> {
- Step::new("clippy").run(indoc::indoc! {r#"
- cargo clippy --workspace --all-features \
- --exclude sync_service
- # sync-service has mutually exclusive storage features, so lint its
- # supported default feature set separately. These two existing lints
- # predate its inclusion in the root workspace.
- cargo clippy -p sync_service -- \
- -A clippy::unnecessary_map_or \
- -A clippy::collapsible_if
- "#})
+ Step::new("clippy")
+ .run(include_str!("scripts/cargo_clippy.sh"))
+ .add_env((
+ "RUST_PACKAGES",
+ "${{ needs.path-check.outputs.rust_packages }}",
+ ))
}
/// pgvector service container, tuned env preserved.
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage/test.rs
new file mode 100644
index 0000000000..dfb976e48f
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage/test.rs
@@ -0,0 +1,66 @@
+use super::*;
+
+#[test]
+fn package_selection_does_not_pass_lib() {
+ let script = include_str!("../scripts/run_tests.sh");
+ assert!(
+ script.contains(r#"cargo nextest run "${common[@]}" "${pkg_args[@]}""#),
+ "the -p path must use the unconstrained selected flags, not --lib: {script}"
+ );
+ assert!(
+ !script.contains(r#"--lib --bins --tests "${common[@]}" "${pkg_args[@]}""#),
+ "--lib --bins --tests with -p fails for bin-only xtask crates"
+ );
+}
+
+#[test]
+fn tests_continue_to_exclude_sync_service() {
+ let script = include_str!("../scripts/run_tests.sh");
+ assert!(
+ script.contains("--workspace --exclude sync_service"),
+ "the full suite must preserve its historical sync_service exclusion"
+ );
+ assert!(
+ script.contains(r#"[ "$package" = "sync_service" ] || pkg_args+=(-p "$package")"#),
+ "targeted test runs must also exclude sync_service"
+ );
+}
+
+#[test]
+fn sqlx_only_clippies_and_skips_live_tests() {
+ let script = include_str!("../scripts/compute_nextest_filter.sh");
+ let start = script
+ .find("if ! grep -qvE '^\\.sqlx/'")
+ .expect("sqlx-only short-circuit must remain");
+ let sqlx_block = script[start..]
+ .split("packages=\"$(cargo run")
+ .next()
+ .unwrap();
+ assert!(
+ sqlx_block.contains(r#"rust_packages=all"#),
+ "sqlx-only must emit all for clippy, not none: {sqlx_block}"
+ );
+ assert!(
+ !sqlx_block.contains(r#"rust_packages=none"#),
+ "sqlx-only must not skip clippy: {sqlx_block}"
+ );
+ assert!(
+ sqlx_block.contains(r#"skip_tests=true"#),
+ "sqlx-only diffs must not run the live-Postgres suite: {sqlx_block}"
+ );
+}
+
+#[test]
+fn test_job_honors_skip_tests() {
+ let yaml = code_check_cloud_storage()
+ .to_string()
+ .expect("workflow yaml");
+ assert!(
+ yaml.contains("needs.path-check.outputs.skip_tests != 'true'"),
+ "test job must skip when skip_tests is set: {yaml}"
+ );
+ assert!(
+ yaml.contains("skip_tests: ${{ steps.nextest-filter.outputs.skip_tests }}"),
+ "path-check must export skip_tests: {yaml}"
+ );
+}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
index e6959f38e3..9f365107de 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
@@ -11,6 +11,9 @@ use gh_workflow::{
use crate::workflows::runners;
+#[cfg(test)]
+mod test;
+
/// Build the workflow. The reusable-workflow caller job's `with:` and
/// `secrets: inherit` are filled in by [`patch`].
pub fn pulumi_preview_pr() -> Workflow {
@@ -28,7 +31,6 @@ pub fn pulumi_preview_pr() -> Workflow {
.add_path(xtask_paths::repo_glob!(".sqlx/**"))
.add_path(xtask_paths::repo_glob!("crates/**"))
.add_path(xtask_paths::repo_glob!("services/**"))
- .add_path(xtask_paths::repo_glob!("tooling/xtask/**"))
.add_path(xtask_paths::repo_glob!("tooling/just/**"))
.add_path(xtask_paths::repo_glob!("static_assets/**"))
.add_path(xtask_paths::repo_glob!("docker/**"))
@@ -51,7 +53,10 @@ pub fn pulumi_preview_pr() -> Workflow {
.add_path(xtask_paths::repo_glob!(
".github/scripts/build-cloud-storage-lambdas-nix.sh"
))
- .add_path(xtask_paths::repo_glob!(".github/services-config.json")),
+ .add_path(xtask_paths::repo_glob!(".github/services-config.json"))
+ .add_path(xtask_paths::repo_glob!(
+ ".github/workspace-dep-closures.json"
+ )),
))
.concurrency(
Concurrency::new(Expression::new(
@@ -157,7 +162,6 @@ fn changed_files() -> Step<Use> {
.sqlx/**
crates/**
services/**
- tooling/xtask/**
tooling/just/**
static_assets/**
docker/**
@@ -173,6 +177,7 @@ fn changed_files() -> Step<Use> {
.github/actions/teardown-nix/**
.github/scripts/build-cloud-storage-lambdas-nix.sh
.github/services-config.json
+ .github/workspace-dep-closures.json
"#}
.trim_end(),
))
@@ -192,12 +197,15 @@ fn detect_affected_services() -> Step<Run> {
service_changed=false
# Workspace/build-system changes can affect every deployable.
+ # `.sqlx/` lives at the repo root, so a snapshot-only edit would
+ # otherwise match no service path or dependency-closure entry.
+ # A crate source edit is not in this list: those preview only the
+ # services whose deploy binaries depend on the crate.
while IFS= read -r file; do
if [[ "$file" == "Cargo.toml" || "$file" == "Cargo.lock" || \
- "$file" == "Cross.toml" || "$file" == "clippy.toml" || \
+ "$file" == "Cross.toml" || \
"$file" == "rust-toolchain.toml" || "$file" == .cargo/* || \
"$file" == .config/* || "$file" == .sqlx/* || \
- "$file" == crates/* || "$file" == tooling/xtask/* || \
"$file" == tooling/just/* || "$file" == static_assets/* || \
"$file" == docker/* || "$file" == "flake.nix" || \
"$file" == "flake.lock" || "$file" == nix/* || \
@@ -216,7 +224,8 @@ fn detect_affected_services() -> Step<Run> {
"$file" == .github/actions/preview-cloud-storage-pulumi/* || \
"$file" == .github/actions/setup-nix/* || \
"$file" == .github/actions/teardown-nix/* || \
- "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" ]]; then
+ "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" || \
+ "$file" == ".github/workspace-dep-closures.json" ]]; then
service_changed=true
break
fi
@@ -240,6 +249,35 @@ fn detect_affected_services() -> Step<Run> {
done < .github/outputs/all_changed_files.txt
fi
+ # Match crate/service source against each deployable's workspace
+ # dependency closure so `crates/foo` previews foo's consumers, not
+ # every stack. Binary names that are not package names are mapped
+ # onto the crate that contains them.
+ if [[ "$service_changed" != "true" ]]; then
+ crates=$(echo "$config" | jq -r --arg s "$service" '
+ [(.services[$s].deploy_binaries // [])[], (.services[$s].deploy_lambdas // [])[]]
+ | map(
+ if . == "connection_gateway_service" then "connection_gateway"
+ elif . == "service" then "scheduled_action"
+ elif . == "pubsub_workers" then "email_service"
+ else . end
+ )
+ | unique | .[]
+ ')
+ while IFS= read -r crate; do
+ [[ -z "$crate" ]] && continue
+ while IFS= read -r dir; do
+ [[ -z "$dir" ]] && continue
+ while IFS= read -r file; do
+ if [[ "$file" == "$dir" || "$file" == "$dir"/* ]]; then
+ service_changed=true
+ break 3
+ fi
+ done < .github/outputs/all_changed_files.txt
+ done < <(jq -r --arg c "$crate" '.closures[$c] // empty | .[]' .github/workspace-dep-closures.json)
+ done <<< "$crates"
+ fi
+
if [[ "$service_changed" == "true" ]]; then
services+=("$service")
fi
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs
new file mode 100644
index 0000000000..19776628bd
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs
@@ -0,0 +1,14 @@
+use super::*;
+
+#[test]
+fn sqlx_changes_preview_every_service() {
+ let detect = detect_affected_services();
+ let run = detect
+ .value
+ .run
+ .expect("detect step should be a run script");
+ assert!(
+ run.contains(r#"$file" == .sqlx/*"#),
+ "a root-only .sqlx change must fan out to every stack, not services=[]: {run}"
+ );
+}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/cargo_clippy.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/cargo_clippy.sh
new file mode 100644
index 0000000000..aed182e108
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/cargo_clippy.sh
@@ -0,0 +1,42 @@
+set -euo pipefail
+
+# Mirrors run_tests.sh package selection so clippy only lints the crates this
+# PR can actually affect. `all` keeps the historical workspace invocation,
+# including sync_service's special-cased feature set.
+
+packages="${RUST_PACKAGES:-}"
+
+clippy_sync_service() {
+ cargo clippy -p sync_service -- \
+ -A clippy::unnecessary_map_or \
+ -A clippy::collapsible_if
+}
+
+if [ -z "$packages" ] || [ "$packages" = "all" ]; then
+ cargo clippy --workspace --all-features --exclude sync_service
+ clippy_sync_service
+ exit 0
+fi
+
+if [ "$packages" = "none" ]; then
+ echo "No Rust packages to lint"
+ exit 0
+fi
+
+sync=false
+pkg_args=()
+for p in $packages; do
+ if [ "$p" = "sync_service" ]; then
+ sync=true
+ else
+ pkg_args+=(-p "$p")
+ fi
+done
+
+if [ "${#pkg_args[@]}" -gt 0 ]; then
+ cargo clippy --all-features "${pkg_args[@]}"
+fi
+
+if [ "$sync" = true ]; then
+ clippy_sync_service
+fi
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_changed_files.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_changed_files.sh
index 4ad5cb0478..a8b2ec9d7a 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_changed_files.sh
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_changed_files.sh
@@ -1,5 +1,9 @@
set -euo pipefail
+# Compare against the merge-base so a deleted file still appears. `--no-renames`
+# turns a rename into a delete+add pair so the old path is attributed to its
+# package (otherwise git reports only the new name).
+
if [ -z "${GITHUB_BASE_REF:-}" ]; then
compare_rev="$(git rev-parse HEAD~1)"
else
@@ -11,4 +15,5 @@ else
fi
fi
-git diff --name-only "$compare_rev" "$GITHUB_SHA" > /tmp/changed-files
+printf '%s\n' "$compare_rev" > /tmp/base-revision
+git diff --name-only --no-renames "$compare_rev" "$GITHUB_SHA" > /tmp/changed-files
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_nextest_filter.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_nextest_filter.sh
index 0bec1c6f6b..9fdd7c72a5 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_nextest_filter.sh
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/compute_nextest_filter.sh
@@ -1,31 +1,50 @@
set -euo pipefail
-# Root cargo/toolchain/CI changes can affect the whole workspace, so run all tests.
-# `.sqlx/` is deliberately not in this list: the test job compiles queries against
-# live Postgres (SQLX_OFFLINE is unset there), so `.sqlx` contents cannot change
-# test outcomes, and a query change always comes with a source change in the
-# owning crate, which the package filter below already maps.
-if grep -qE '^(Cargo\.(toml|lock)|rust-toolchain\.toml|Cross\.toml|clippy\.toml|deny\.toml|\.cargo/.*|\.config/.*|flake\.nix|flake\.lock|\.github/actions/(setup-rust|setup-nix|setup-nix-dev-shell|setup-sccache)/.*|\.github/workflows/code_check_cloud_storage\.yml)$' /tmp/changed-files; then
- echo "Workspace-level change detected; running all tests"
- echo "nextest_filter=" >> "$GITHUB_OUTPUT"
+# Writes `rust_packages` for the check/test jobs:
+# all — compile and run the whole workspace
+# none — no Rust packages to lint/test (Nix-only, top-level JSON, docs, …)
+# <names> — space-separated workspace packages (changed + reverse deps)
+#
+# `skip_tests=true` keeps clippy on a package set while the live-Postgres
+# test job stays skipped (used for `.sqlx`-only diffs).
+#
+# Root Cargo/toolchain/config edits force `all`. Cargo.lock is handled by
+# determinator's old/new graph comparison. flake.nix, the Nix shell action,
+# and this workflow file used to live on the full-suite list and turned every
+# dev-shell tweak into a full-suite rebuild.
+
+echo "skip_tests=false" >> "$GITHUB_OUTPUT"
+
+if [ ! -s /tmp/changed-files ]; then
+ echo "Unknown or empty change set; running all tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
exit 0
fi
-# A diff touching only `.sqlx/` needs no tests at all — without this it would
-# fall through to the empty-filter "run everything" fallback below. `none()`
-# selects zero tests, which `--no-tests=pass` treats as success. The `-s` guard
-# keeps an empty changed-files list (unknown merge-base) on the full-suite path.
-if [ -s /tmp/changed-files ] && ! grep -qvE '^\.sqlx/' /tmp/changed-files; then
- echo "Only .sqlx changes detected; running no tests"
- echo "nextest_filter=none()" >> "$GITHUB_OUTPUT"
+if grep -qE '^(Cargo\.toml|rust-toolchain\.toml|Cross\.toml|clippy\.toml|deny\.toml|\.cargo/.*|\.config/.*)$' /tmp/changed-files; then
+ echo "Workspace-level Cargo/toolchain change detected; running all tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
exit 0
fi
-filterset="$(cargo run --manifest-path tooling/xtask/Cargo.toml -- nextest-filter /tmp/changed-files)"
+# The test job compiles queries against live Postgres (SQLX_OFFLINE is unset
+# there), so `.sqlx` contents cannot change test outcomes. Clippy is the
+# offline SQLx check (`SQLX_OFFLINE=true`), so a snapshot-only diff must
+# still compile against the cache rather than skip the check job.
+if ! grep -qvE '^\.sqlx/' /tmp/changed-files; then
+ echo "Only .sqlx changes detected; clippy all, skip live-Postgres tests"
+ echo "rust_packages=all" >> "$GITHUB_OUTPUT"
+ echo "skip_tests=true" >> "$GITHUB_OUTPUT"
+ exit 0
+fi
-if [ -z "$filterset" ]; then
- echo "No package-specific Rust changes detected; running all tests"
-else
- echo "nextest filter: $filterset"
+packages="$(cargo run --manifest-path tooling/xtask/Cargo.toml -- nextest-filter /tmp/changed-files "$(< /tmp/base-revision)")"
+
+if [ -z "$packages" ] || [ "$packages" = "none" ]; then
+ echo "No package-specific Rust changes detected; running no tests"
+ echo "rust_packages=none" >> "$GITHUB_OUTPUT"
+ exit 0
fi
-echo "nextest_filter=$filterset" >> "$GITHUB_OUTPUT"
+
+echo "rust packages: $packages"
+echo "rust_packages=$packages" >> "$GITHUB_OUTPUT"
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/run_tests.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/run_tests.sh
index f40f49bfed..02702d1a24 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/run_tests.sh
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/run_tests.sh
@@ -1,9 +1,35 @@
-# --no-tests=pass: a package filter (e.g. an xtask/tooling-only PR -> rdeps(=xtask))
-# can legitimately select zero tests; treat that as success, not nextest's default error.
-# sync-service was not part of this suite before it joined the root workspace,
-# and its storage backends are mutually exclusive under --all-features.
-args=(--workspace --exclude sync_service --all-features --lib --bins --tests --no-tests=pass --test-threads "$NEXTEST_TEST_THREADS")
-if [ -n "$NEXTEST_FILTER" ]; then
- args+=(-E "$NEXTEST_FILTER")
+set -euo pipefail
+
+# --no-tests=pass: a package filter can legitimately select a crate with no
+# tests; treat that as success, not nextest's default error.
+# sync-service is not part of this suite, and its storage backends are mutually
+# exclusive under --all-features.
+#
+# Package selection uses `cargo nextest run -p`, not `--workspace -E rdeps(...)`.
+# The filterset only decides which tests *run* after a workspace build; `-p`
+# is what keeps an unrelated crate's test binary from being compiled.
+#
+# `--lib --bins --tests` is safe with `--workspace` (cargo skips packages that
+# lack a given target type) but fails with `-p` when any selected package has
+# no lib — xtask binaries such as xtask_nextest_filter / xtask_workflows.
+# Unconstrained `-p` still runs that package's tests.
+
+: "${RUST_PACKAGES:?RUST_PACKAGES is required}"
+common=(--all-features --no-tests=pass --test-threads "$NEXTEST_TEST_THREADS")
+
+if [ "$RUST_PACKAGES" = "all" ]; then
+ cargo nextest run --workspace --exclude sync_service --lib --bins --tests "${common[@]}"
+ exit 0
fi
-cargo nextest run "${args[@]}"
+
+pkg_args=()
+for package in $RUST_PACKAGES; do
+ [ "$package" = "sync_service" ] || pkg_args+=(-p "$package")
+done
+
+if [ "${#pkg_args[@]}" -eq 0 ]; then
+ echo "No packages in the test suite were affected"
+ exit 0
+fi
+
+cargo nextest run "${common[@]}" "${pkg_args[@]}"
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
index 34b83671fc..aad0b317d5 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
@@ -11,6 +11,9 @@ use crate::workflows::{
vars,
};
+#[cfg(test)]
+mod test;
+
/// Frontend-only jobs share one small Namespace profile with a dedicated cache
/// tag, so their Nix/Bun state lives on its own volume.
fn web_runner() -> String {
@@ -176,6 +179,12 @@ fn checkout(name: &str, full_history: bool) -> Step<Use> {
fn paths_filter() -> Step<Use> {
let artifact_paths = crate::workflows::web_artifact_paths::yaml_list(" ");
+ // `api_changed` is only the inputs to `bun run gen-api`. xtask, flake.nix,
+ // the Nix dev-shell action, and this workflow file do not change OpenAPI
+ // output, so they must not start Typecheck (which compiles the schema
+ // binaries). The Nix dev-shell action is also omitted from `should_run`
+ // so Typecheck (which is `should_run || api_changed`) stays off for a
+ // shell-only tweak. Workflow YAML drift is `check generated workflows`.
Step::new("Filter changed paths")
.uses(
"dorny",
@@ -186,7 +195,7 @@ fn paths_filter() -> Step<Use> {
.add_with((
"filters",
format!(
- "should_run:\n{artifact_paths} - 'services/lexical-service/**'\n - '.github/actions/setup-nix-dev-shell/**'\n - '.github/actions/setup-reqs-web/**'\n - '.github/workflows/web-app-check-main.yml'\napi_changed:\n - 'crates/**/*.rs'\n - 'services/**/*.rs'\n - 'tooling/xtask/**/*.rs'\n - 'Cargo.toml'\n - 'Cargo.lock'\n - 'flake.nix'\n - 'flake.lock'\n - 'apps/web/scripts/generate-api-schema.ts'\n - 'apps/web/scripts/services.ts'\n - '.github/actions/setup-nix-dev-shell/**'\n - '.github/actions/setup-reqs-web/**'\n - '.github/workflows/web-app-check-main.yml'\n"
+ "should_run:\n{artifact_paths} - 'services/lexical-service/**'\n - '.github/actions/setup-reqs-web/**'\napi_changed:\n - 'crates/**/*.rs'\n - 'services/**/*.rs'\n - 'Cargo.toml'\n - 'Cargo.lock'\n - 'apps/web/scripts/generate-api-schema.ts'\n - 'apps/web/scripts/services.ts'\n - '.github/actions/setup-reqs-web/**'\n"
),
))
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs
new file mode 100644
index 0000000000..cb303f31ad
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs
@@ -0,0 +1,23 @@
+use super::*;
+
+#[test]
+fn nix_dev_shell_does_not_start_typecheck() {
+ let yaml = web_app_check_main().to_string().expect("workflow yaml");
+ let filters = yaml
+ .split("filters: |")
+ .nth(1)
+ .and_then(|rest| rest.split("id: filter").next())
+ .expect("path-check filters");
+ let should_run = filters
+ .split("api_changed:")
+ .next()
+ .expect("should_run block");
+ assert!(
+ !should_run.contains("setup-nix-dev-shell"),
+ "Typecheck is should_run || api_changed; nix-dev-shell must not be in should_run: {should_run}"
+ );
+ assert!(
+ should_run.contains("setup-reqs-web"),
+ "web setup action still belongs in should_run: {should_run}"
+ );
+}