From ac6aec57f0eb113e9f270538b6744e8e27cc5a11 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 9 Oct 2026 13:09:26 -0700 Subject: [PATCH] ci: run the live suites on pull requests that can affect them Live / Docker and Live / Kind ran only on v1 pushes, so #12831 and #12855 merged with passing pull request checks and turned v1 red. Both now run on pull requests to v1. Each job first runs `nemoclaw-build changes live`, which uses the determinator and guppy analysis the image workflow uses with a live build: the packages whose tests run live, and the CLI and providers the bundle ships, with their dependencies. Path rules in .config/determinator-live.toml classify other files; documentation and unrelated workflows skip the suite, while examples, images, runtimes, schemas, pinned versions, the nextest profiles, and the live workflows run it. Unclassified files, dependency or feature changes, and failed analyses run it too. Superseded pull request runs are cancelled; push runs still finish. Closes #12883. --- .config/determinator-live.toml | 47 +++++++++++ .github/workflows/live-docker.yml | 32 +++++++- .github/workflows/live-kind.yml | 32 +++++++- crates/nemoclaw-build/src/changes.rs | 104 ++++++++++++++++++++----- crates/nemoclaw-build/src/main.rs | 11 ++- crates/nemoclaw-build/tests/changes.rs | 77 +++++++++++++++++- docs/contributing/testing.md | 10 ++- 7 files changed, 278 insertions(+), 35 deletions(-) create mode 100644 .config/determinator-live.toml diff --git a/.config/determinator-live.toml b/.config/determinator-live.toml new file mode 100644 index 00000000000..6a285f8b2c2 --- /dev/null +++ b/.config/determinator-live.toml @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Which changed files can affect the live suites, read by `nemoclaw-build changes live`. +# A file inside a crate marks that crate changed; the command then checks whether the +# live build uses it: the packages whose tests run live, and the CLI and providers the +# bundle ships, with their development dependencies. Any other file outside a crate runs +# the live suites unless a rule below ignores it. Rules apply in order, before +# determinator's defaults. + +# A workspace package under examples/: map it to its package. +[[path-rule]] +globs = ["examples/onboarding-tui/**"] +mark-changed = [] +post-rule = "skip-rules" + +# Inputs the live tests and the bundle read outside crates. +[[path-rule]] +globs = [ + "examples/**", + "image/**", + "runtimes/**", + "schemas/**", + "versions.json", + "rust-toolchain.toml", + ".config/nextest.toml", + ".github/actions/**", + ".github/workflows/live-*.yml", +] +mark-changed = "all" + +# Not read by the live tests, the bundle, or their workflows. +[[path-rule]] +globs = [ + "docs/**", + "fern/**", + "tools/**", + ".github/**", + ".config/**", + ".agents/**", + ".claude/**", + "deny.toml", + ".pre-commit-config.yaml", + "AGENTS.md", + "WRITING.md", +] +mark-changed = [] diff --git a/.github/workflows/live-docker.yml b/.github/workflows/live-docker.yml index 3402b791eec..e8ece9683f4 100644 --- a/.github/workflows/live-docker.yml +++ b/.github/workflows/live-docker.yml @@ -6,14 +6,18 @@ name: Live / Docker on: push: # Dispatch needs this file on the default branch; push a - # run-live-docker/ branch to run it before merging. + # run-live-docker/ branch to run it outside a pull request. branches: [v1, run-live-docker/**] + # Pull requests run the suite when they change its build or inputs; see + # docs/contributing/testing.md. + pull_request: + branches: [v1] workflow_dispatch: permissions: contents: read concurrency: - group: live-docker-${{ github.ref }} - cancel-in-progress: false + group: live-docker-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: live-docker: name: Live / Docker / ${{ matrix.platform }} @@ -37,17 +41,36 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # The second commit is a pull request merge commit's base. + fetch-depth: 2 + - name: Decide whether this change can affect the live suites + id: changes + env: + EVENT: ${{ github.event_name }} + run: | + # Pushes and manual runs always run the suite. + if [ "$EVENT" != pull_request ]; then + echo live=true >> "$GITHUB_OUTPUT" + exit 0 + fi + base=$(git rev-parse HEAD^1) + cargo run --locked --quiet -p nemoclaw-build --no-default-features --target-dir target/ci-runner -- \ + changes live --base "$base" >> "$GITHUB_OUTPUT" - uses: ./.github/actions/setup-rust + if: steps.changes.outputs.live == 'true' with: platform: ${{ matrix.platform }} save-cache: "false" - name: Build test executables + if: steps.changes.outputs.live == 'true' run: cargo ci build - name: Build and verify bundle + if: steps.changes.outputs.live == 'true' run: cargo ci bundle # The tests use local images by digest and load OCI archives, which need # Docker's containerd image store; hosted runners use the classic store. - name: Use the containerd image store + if: steps.changes.outputs.live == 'true' run: | config=/etc/docker/daemon.json if [ -s "$config" ]; then current=$(sudo cat "$config"); else current='{}'; fi @@ -55,9 +78,10 @@ jobs: sudo systemctl restart docker docker info --format '{{json .DriverStatus}}' | grep -q io.containerd.snapshotter.v1 - name: Run Docker live tests + if: steps.changes.outputs.live == 'true' run: cargo ci live-docker - name: Upload live test results - if: always() + if: always() && steps.changes.outputs.live == 'true' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: live-docker-${{ matrix.platform }}-${{ github.run_attempt }} diff --git a/.github/workflows/live-kind.yml b/.github/workflows/live-kind.yml index 6ab2e93af75..921ea160483 100644 --- a/.github/workflows/live-kind.yml +++ b/.github/workflows/live-kind.yml @@ -6,14 +6,18 @@ name: Live / Kind on: push: # Dispatch needs this file on the default branch; push a - # run-live-kind/ branch to run it before merging. + # run-live-kind/ branch to run it outside a pull request. branches: [v1, run-live-kind/**] + # Pull requests run the suite when they change its build or inputs; see + # docs/contributing/testing.md. + pull_request: + branches: [v1] workflow_dispatch: permissions: contents: read concurrency: - group: live-kind-${{ github.ref }} - cancel-in-progress: false + group: live-kind-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: live-kind: name: Live / Kind / ${{ matrix.platform }} @@ -37,17 +41,36 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # The second commit is a pull request merge commit's base. + fetch-depth: 2 + - name: Decide whether this change can affect the live suites + id: changes + env: + EVENT: ${{ github.event_name }} + run: | + # Pushes and manual runs always run the suite. + if [ "$EVENT" != pull_request ]; then + echo live=true >> "$GITHUB_OUTPUT" + exit 0 + fi + base=$(git rev-parse HEAD^1) + cargo run --locked --quiet -p nemoclaw-build --no-default-features --target-dir target/ci-runner -- \ + changes live --base "$base" >> "$GITHUB_OUTPUT" - uses: ./.github/actions/setup-rust + if: steps.changes.outputs.live == 'true' with: platform: ${{ matrix.platform }} save-cache: "false" - name: Build test executables + if: steps.changes.outputs.live == 'true' run: cargo ci build - name: Build and verify bundle + if: steps.changes.outputs.live == 'true' run: cargo ci bundle # The agent image's metadata bundle is read from an OCI index, which # Docker writes only with its containerd image store. - name: Use the containerd image store + if: steps.changes.outputs.live == 'true' run: | config=/etc/docker/daemon.json if [ -s "$config" ]; then current=$(sudo cat "$config"); else current='{}'; fi @@ -55,9 +78,10 @@ jobs: sudo systemctl restart docker docker info --format '{{json .DriverStatus}}' | grep -q io.containerd.snapshotter.v1 - name: Run Kubernetes live tests + if: steps.changes.outputs.live == 'true' run: cargo ci live-kind - name: Upload live test results - if: always() + if: always() && steps.changes.outputs.live == 'true' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: live-kind-${{ matrix.platform }}-${{ github.run_attempt }} diff --git a/crates/nemoclaw-build/src/changes.rs b/crates/nemoclaw-build/src/changes.rs index 25ef8cd3514..6151469f9e6 100644 --- a/crates/nemoclaw-build/src/changes.rs +++ b/crates/nemoclaw-build/src/changes.rs @@ -1,13 +1,15 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -//! Decide whether changes since a base revision can affect `CI / Images`. +//! Decide whether changes since a base revision can affect `CI / Images` or the +//! live suites. //! -//! determinator maps changed files to workspace packages, using the rules in -//! [`RULES`] for files outside crates. guppy then simulates the image build: -//! nemoclaw-build without default features, including the dev-dependencies its -//! `bake::` tests compile, and the Ollama proxy with its defaults and tests. -//! The images are affected when a changed package is in that build, or when -//! its third-party dependencies or enabled features differ from the base. +//! determinator maps changed files to workspace packages, using each workflow's +//! path rules for files outside crates. guppy then simulates the workflow's build. +//! The image build is nemoclaw-build without default features, including the +//! dev-dependencies its `bake::` tests compile, and the Ollama proxy with its +//! defaults and tests. The live build is [`LIVE_PACKAGES`] with their defaults and +//! tests. A workflow is affected when a changed package is in its build, or when its +//! build's third-party dependencies or enabled features differ from the base. use determinator::{Determinator, Utf8Paths0, rules::DeterminatorRules}; use guppy::{ @@ -22,6 +24,43 @@ use std::{collections::BTreeSet, fs, path::Path, process::Command}; /// Path rules for files outside crates, relative to the repository root. pub const RULES: &str = ".config/determinator-images.toml"; +/// The live suites' path rules. +pub const LIVE_RULES: &str = ".config/determinator-live.toml"; +/// Packages whose tests run in the live suites, and the CLI and providers the +/// bundle they test ships. +pub const LIVE_PACKAGES: [&str; 8] = [ + "nemoclaw-build", + "nemoclaw-cli", + "nemoclaw-e2e", + "nemoclaw-provider", + "nemoclaw-runtime", + "nemoclaw-sdk", + "openshell-provider", + "fabric-provider", +]; + +/// A CI workflow whose steps run only when a change can affect them. +#[derive(Clone, Copy)] +pub enum Workflow { + /// `CI / Images`. + Images, + /// `Live / Docker` and `Live / Kind`. + Live, +} +impl Workflow { + fn rules(self) -> &'static str { + match self { + Self::Images => RULES, + Self::Live => LIVE_RULES, + } + } + fn subject(self) -> &'static str { + match self { + Self::Images => "image", + Self::Live => "live", + } + } +} type Result = std::result::Result; @@ -35,15 +74,22 @@ pub struct Decision { /// /// Any failure to analyze the change runs the checks rather than skipping them. pub fn images(root: &Path, base: &str) -> Decision { - analyze(root, base).unwrap_or_else(|error| Decision { + decide(root, base, Workflow::Images) +} + +/// Decide for `workflow`; any failure to analyze the change runs it. +pub fn decide(root: &Path, base: &str, workflow: Workflow) -> Decision { + analyze(root, base, workflow).unwrap_or_else(|error| Decision { run: true, reason: format!( - "could not analyze changes since {base} ({error}); running the image checks" + "could not analyze changes since {base} ({error}); running the {} checks", + workflow.subject() ), }) } -fn analyze(root: &Path, base: &str) -> Result { +fn analyze(root: &Path, base: &str, workflow: Workflow) -> Result { + let rules_path = workflow.rules(); let base = String::from_utf8(git( root, &["rev-parse", "--verify", &format!("{base}^{{commit}}")], @@ -57,9 +103,10 @@ fn analyze(root: &Path, base: &str) -> Result { &["diff", "-z", "--name-only", "--no-renames", &base, "HEAD"], )?; let paths = Utf8Paths0::from_bytes(changed).map_err(|_| "a changed path is not UTF-8")?; + let rules = fs::read_to_string(root.join(rules_path)) + .map_err(|e| format!("cannot read {rules_path}: {e}"))?; let rules = - fs::read_to_string(root.join(RULES)).map_err(|e| format!("cannot read {RULES}: {e}"))?; - let rules = DeterminatorRules::parse(&rules).map_err(|e| format!("invalid {RULES}: {e}"))?; + DeterminatorRules::parse(&rules).map_err(|e| format!("invalid {rules_path}: {e}"))?; let new = graph(root)?; let base_tree = tempfile::tempdir().map_err(|e| e.to_string())?; @@ -72,11 +119,16 @@ fn analyze(root: &Path, base: &str) -> Result { let mut determinator = Determinator::new(&old, &new); determinator .set_rules(&rules) - .map_err(|e| format!("invalid {RULES}: {e}"))?; + .map_err(|e| format!("invalid {rules_path}: {e}"))?; determinator.add_changed_paths(&paths); let path_changed = determinator.compute().path_changed_set; - let build = image_build(&new)?; + let build_for = |graph| match workflow { + Workflow::Images => image_build(graph), + Workflow::Live => live_build(graph), + }; + let subject = workflow.subject(); + let build = build_for(&new)?; for package in packages(&build).packages(DependencyDirection::Forward) { if path_changed .contains(package.id()) @@ -84,19 +136,22 @@ fn analyze(root: &Path, base: &str) -> Result { { return Ok(Decision { run: true, - reason: format!("{} is part of the image build and changed", package.name()), + reason: format!( + "{} is part of the {subject} build and changed", + package.name() + ), }); } } - if summary(&build) != summary(&image_build(&old)?) { + if summary(&build) != summary(&build_for(&old)?) { return Ok(Decision { run: true, - reason: "the image build's dependencies or features changed".into(), + reason: format!("the {subject} build's dependencies or features changed"), }); } Ok(Decision { run: false, - reason: format!("no image inputs changed since {base}"), + reason: format!("no {subject} inputs changed since {base}"), }) } @@ -143,6 +198,19 @@ fn image_build(graph: &PackageGraph) -> Result> { .map_err(|e| e.to_string()) } +fn live_build(graph: &PackageGraph) -> Result> { + let initials = graph + .resolve_workspace_names(LIVE_PACKAGES) + .map_err(|e| format!("workspace lacks a live package: {e}"))? + .to_feature_set(StandardFeatures::Default); + CargoSet::new( + initials, + graph.feature_graph().resolve_none(), + &CargoOptions::new(), + ) + .map_err(|e| e.to_string()) +} + fn packages<'g>(build: &CargoSet<'g>) -> PackageSet<'g> { build .target_features() diff --git a/crates/nemoclaw-build/src/main.rs b/crates/nemoclaw-build/src/main.rs index ec8678075e7..fccfbe4ff2f 100644 --- a/crates/nemoclaw-build/src/main.rs +++ b/crates/nemoclaw-build/src/main.rs @@ -91,6 +91,8 @@ enum Action { enum ChangedWorkflow { /// `CI / Images`. Images, + /// `Live / Docker` and `Live / Kind`. + Live, } #[cfg(feature = "sdk")] #[derive(Subcommand)] @@ -476,10 +478,13 @@ async fn main() -> Result<()> { .map_err(Into::into); } if let Action::Changes { workflow, base } = &cli.command { - let ChangedWorkflow::Images = workflow; - let decision = nemoclaw_build::changes::images(Path::new("."), base); + let (workflow, name) = match workflow { + ChangedWorkflow::Images => (nemoclaw_build::changes::Workflow::Images, "images"), + ChangedWorkflow::Live => (nemoclaw_build::changes::Workflow::Live, "live"), + }; + let decision = nemoclaw_build::changes::decide(Path::new("."), base, workflow); eprintln!("{}", decision.reason); - println!("images={}", decision.run); + println!("{name}={}", decision.run); return Ok(()); } let pins: Pins = serde_json::from_slice(&fs::read("versions.json")?)?; diff --git a/crates/nemoclaw-build/tests/changes.rs b/crates/nemoclaw-build/tests/changes.rs index 13d0bcfba6a..6c968275cbb 100644 --- a/crates/nemoclaw-build/tests/changes.rs +++ b/crates/nemoclaw-build/tests/changes.rs @@ -1,11 +1,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -//! Whether a change can affect `CI / Images`, decided from a real Git history and -//! Cargo workspace without network access. +//! Whether a change can affect `CI / Images` or the live suites, decided from a real +//! Git history and Cargo workspace without network access. use std::{fs, path::Path, process::Command}; const RULES: &str = include_str!("../../../.config/determinator-images.toml"); +const LIVE_RULES: &str = include_str!("../../../.config/determinator-live.toml"); fn manifest(name: &str, dependencies: &str) -> String { format!( @@ -82,6 +83,11 @@ impl Repo { ), ), (".config/determinator-images.toml", RULES.to_owned()), + (".config/determinator-live.toml", LIVE_RULES.to_owned()), + (".config/nextest.toml", "\n".into()), + (".github/workflows/live-docker.yml", "name: live\n".into()), + ("examples/local.yaml", "kind: Deployment\n".into()), + ("versions.json", "{}\n".into()), (".dockerignore", "*\n".into()), (".github/workflows/images.yml", "name: images\n".into()), (".github/workflows/rust.yml", "name: rust\n".into()), @@ -99,6 +105,22 @@ impl Repo { for (path, contents) in files { write(dir.path(), path, &contents); } + // The rest of the live build: the CLI and providers in the bundle, and a + // package outside it. + for name in [ + "nemoclaw-cli", + "nemoclaw-provider", + "openshell-provider", + "fabric-provider", + "nemoclaw-onboarding", + ] { + write( + dir.path(), + &format!("crates/{name}/Cargo.toml"), + &manifest(name, "nemoclaw-sdk = { path = \"../nemoclaw-sdk\" }\n"), + ); + write(dir.path(), &format!("crates/{name}/src/lib.rs"), ""); + } for name in ["build", "ollama-proxy", "runtime", "sdk", "e2e"] { write( dir.path(), @@ -121,6 +143,15 @@ impl Repo { /// Commit the edits (None deletes a file), then ask about the base commit. fn decide(&self, edits: &[(&str, Option<&str>)], base: Option<&str>) -> (String, String) { + self.decide_for("images", edits, base) + } + + fn decide_for( + &self, + workflow: &str, + edits: &[(&str, Option<&str>)], + base: Option<&str>, + ) -> (String, String) { let recorded = self.base(); for (path, contents) in edits { match contents { @@ -131,7 +162,7 @@ impl Repo { succeed(self.0.path(), "git", &["add", "-A"]); succeed(self.0.path(), "git", &["commit", "-q", "-m", "change"]); let output = Command::new(env!("CARGO_BIN_EXE_nemoclaw-build")) - .args(["changes", "images", "--base", base.unwrap_or(&recorded)]) + .args(["changes", workflow, "--base", base.unwrap_or(&recorded)]) .current_dir(self.0.path()) .env("CARGO", cargo()) .env("CARGO_NET_OFFLINE", "true") @@ -234,3 +265,43 @@ fn an_unanalyzable_change_runs_the_image_checks() { assert_eq!(decision, "images=true"); assert!(stderr.contains("running the image checks"), "{stderr}"); } + +fn live(edits: &[(&str, Option<&str>)]) -> String { + let (decision, stderr) = Repo::new().decide_for("live", edits, None); + assert!(!stderr.contains("could not analyze"), "{stderr}"); + decision +} + +#[test] +fn documentation_other_workflows_and_packages_outside_the_live_build_skip_live_suites() { + let decision = live(&[ + ("docs/guide.md", Some("# Changed\n")), + (".github/workflows/images.yml", Some("name: changed\n")), + ( + "crates/nemoclaw-onboarding/src/lib.rs", + Some("pub fn changed() {}\n"), + ), + ]); + assert_eq!(decision, "live=false"); +} + +#[test] +fn live_build_packages_and_their_inputs_run_live_suites() { + for path in [ + "crates/nemoclaw-sdk/src/lib.rs", + "crates/nemoclaw-runtime/src/lib.rs", + "crates/nemoclaw-e2e/src/lib.rs", + "crates/nemoclaw-build/src/lib.rs", + "crates/nemoclaw-cli/src/lib.rs", + "crates/openshell-provider/src/lib.rs", + "runtimes/vllm/build.json", + "image/fabric/Dockerfile", + "examples/local.yaml", + "versions.json", + ".config/nextest.toml", + ".github/workflows/live-docker.yml", + "Makefile", + ] { + assert_eq!(live(&[(path, Some("# changed\n"))]), "live=true", "{path}"); + } +} diff --git a/docs/contributing/testing.md b/docs/contributing/testing.md index e43ea0c83f9..4ca2ccd5ea4 100644 --- a/docs/contributing/testing.md +++ b/docs/contributing/testing.md @@ -55,8 +55,8 @@ To build the SDK outside `cargo ci`, set `PROTOC` to `.tools/protoc-36.1/bin/pro | CI / Images | `Build / linux_arm64`, `Build / linux_amd64` | | CI / Dependencies | `Policy` | | CD / Documentation | `Validate`, then PR preview, staging, or release publication | -| Live / Docker | `Live / Docker / linux_arm64`, `Live / Docker / linux_amd64` on `v1` pushes, `run-live-docker/` branch pushes, and manual runs, through `cargo ci live-docker` | -| Live / Kind | `Live / Kind / linux_arm64`, `Live / Kind / linux_amd64` on `v1` pushes, `run-live-kind/` branch pushes, and manual runs, through `cargo ci live-kind` | +| Live / Docker | `Live / Docker / linux_arm64`, `Live / Docker / linux_amd64` on pull requests that can affect them, `v1` pushes, `run-live-docker/` branch pushes, and manual runs, through `cargo ci live-docker` | +| Live / Kind | `Live / Kind / linux_arm64`, `Live / Kind / linux_amd64` on pull requests that can affect them, `v1` pushes, `run-live-kind/` branch pushes, and manual runs, through `cargo ci live-kind` | | Live / Brev | Bundle build, image build, and VM preparation in parallel, then lifecycle qualification and verified VM deletion | The first eight checks are required by the `v1` ruleset, including documentation validation. @@ -65,7 +65,11 @@ Superseded PR runs are cancelled. The image workflow also cancels superseded pushes; its manual runs use a separate concurrency group and finish. Native push runs finish because only `v1` pushes save the shared Rust caches; a newer push still replaces an older pending run. Documentation and dependency pushes finish; newer pushes replace older pending runs. -Live runs use separate concurrency groups and are not cancelled by a newer push. +Live push runs use separate concurrency groups and are not cancelled by a newer push; superseded pull request runs are cancelled. +On a pull request, each live job first runs `nemoclaw-build changes live` and skips its remaining steps when the change cannot affect the suite. +A file inside a crate counts when that crate is in the live build: the packages whose tests run live and the CLI and providers the bundle ships, with their dependencies. +[Path rules](../../.config/determinator-live.toml) classify other files; unclassified files, dependency or feature changes in the live build, and failed analyses run the suite. +Run `cargo run -p nemoclaw-build --no-default-features -- changes live --base origin/v1` after committing to see the decision. The Brev workflow remains opt-in; see [live prerequisites and cleanup](live-tests.md#bare-brev). ## Test Runner