diff --git a/.agents/skills/maintain-ci/SKILL.md b/.agents/skills/maintain-ci/SKILL.md index 131b9fe7e..5890ac78e 100644 --- a/.agents/skills/maintain-ci/SKILL.md +++ b/.agents/skills/maintain-ci/SKILL.md @@ -77,6 +77,15 @@ reliability, or reproducibility. ## Validation +The pre-commit CI job audits every maintained Python project with +`just audit-python` (`uv audit --locked`, including optional and development +dependencies), and the full Rust feature graph with +`bash scripts/lint/check_cargo_dependencies.sh` (`cargo deny ... check advisories`). +Use the uv and cargo-deny versions pinned in `ci_check.yml`. Findings fail CI; +do not add suppressions merely to enable a new gate. Python/Rust license and +attribution checks remain separate in the existing `attributions-python`, +`attributions-rust`, and `license-diff` hooks. + Start with the narrowest useful checks: ```bash @@ -105,6 +114,8 @@ source instead of assuming local success proves remote success. - `.gitlab-ci.yml` - `RELEASING.md` - `Cargo.lock` +- `deny.toml` +- `scripts/lint/check_cargo_dependencies.sh` - `uv.lock` - `docs/package-lock.json` - `justfile` diff --git a/.github/workflows/ci_check.yml b/.github/workflows/ci_check.yml index 78d67baa8..6bb23bf43 100644 --- a/.github/workflows/ci_check.yml +++ b/.github/workflows/ci_check.yml @@ -32,7 +32,7 @@ jobs: - name: Set up uv uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8 with: - version: 0.9.22 + version: 0.13.4 enable-cache: true cache-dependency-glob: uv.lock @@ -48,10 +48,10 @@ jobs: toolchain: stable cache: false - - name: Install just and cargo-about + - name: Install just, cargo-about and cargo-deny uses: taiki-e/install-action@c070f87102a1c75b3183910f391c1cb887fe13c8 # v2.77.6 with: - tool: just@1.50.0,cargo-about@0.9.0 + tool: just@1.50.0,cargo-about@0.9.0,cargo-deny@0.19.1 - name: Cache pre-commit environments uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b26293dd5..5302b5178 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,6 +46,23 @@ repos: files: '(^|/)(pyproject\.toml|uv\.lock)$' pass_filenames: false + # Dependency vulnerabilities; run even when lockfiles did not change. + - repo: local + hooks: + - id: uv-audit + name: Python dependency vulnerabilities (all project lockfiles) + entry: just audit-python + language: system + always_run: true + pass_filenames: false + + - id: cargo-deny + name: Rust dependency vulnerabilities + entry: bash scripts/lint/check_cargo_dependencies.sh + language: system + always_run: true + pass_filenames: false + # Third-party software attributions - repo: local hooks: diff --git a/deny.toml b/deny.toml new file mode 100644 index 000000000..041660e51 --- /dev/null +++ b/deny.toml @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# RustSec vulnerability advisories fail CI without a severity threshold. +# No advisory exceptions are introduced by this gate. +[advisories] +ignore = [] diff --git a/justfile b/justfile index 4d783c927..bc0f80d3c 100644 --- a/justfile +++ b/justfile @@ -492,6 +492,18 @@ lock-python: uv lock --project "$project" done +# Audit every maintained Python lockfile, including optional and dev dependencies. +audit-python: + #!/usr/bin/env bash + set -euo pipefail + projects=({{ python_projects }}) + status=0 + for project in "${projects[@]}"; do + printf '\nAuditing Python dependencies: %s\n' "$project" + uv audit --locked --project "$project" || status=1 + done + exit "$status" + # Refresh the metadata-only catalog from adapter-owned descriptors. adapter-catalog: uv run --no-project python scripts/ci/generate_adapter_catalog.py diff --git a/scripts/lint/check_cargo_dependencies.sh b/scripts/lint/check_cargo_dependencies.sh new file mode 100755 index 000000000..53b079fcc --- /dev/null +++ b/scripts/lint/check_cargo_dependencies.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +# cargo-deny refreshes a separate Git checkout for its advisory database. +# Do not let a commit hook's repository-local Git environment affect it. +while IFS= read -r git_local_variable; do + unset "$git_local_variable" +done < <(git rev-parse --local-env-vars) + +# License policy and evidence remain with cargo-about and the attribution hooks. +exec cargo deny --locked --all-features check advisories diff --git a/tests/scripts/test_dependency_audits.py b/tests/scripts/test_dependency_audits.py new file mode 100644 index 000000000..408fc6949 --- /dev/null +++ b/tests/scripts/test_dependency_audits.py @@ -0,0 +1,94 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations + +import json +import os +import shutil +import subprocess +import sys +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[2] +pytestmark = pytest.mark.skipif( + os.name == "nt", reason="CI audit drivers run under POSIX bash" +) + + +@pytest.mark.skipif(shutil.which("just") is None, reason="just is required") +@pytest.mark.parametrize( + "failure_project", [None, ".", "sdk/python/nemo-fabric-runtime"] +) +def test_python_audit_covers_every_lock_and_preserves_failure( + tmp_path, failure_project +): + log = tmp_path / "calls.jsonl" + uv = tmp_path / "uv" + uv.write_text( + f"#!{sys.executable}\n" + "import json, os, sys\n" + "with open(os.environ['AUDIT_LOG'], 'a') as output:\n" + " output.write(json.dumps(sys.argv[1:]) + '\\n')\n" + "raise SystemExit(7 if sys.argv[-1] == os.environ.get('FAIL_PROJECT') else 0)\n" + ) + uv.chmod(0o755) + env = dict( + os.environ, + PATH=f"{tmp_path}{os.pathsep}{os.environ['PATH']}", + AUDIT_LOG=str(log), + ) + env.pop("FAIL_PROJECT", None) + if failure_project is not None: + env["FAIL_PROJECT"] = failure_project + result = subprocess.run( + ["just", "audit-python"], cwd=ROOT, env=env, capture_output=True, text=True + ) + assert result.returncode == (1 if failure_project else 0), result.stderr + calls = [json.loads(line) for line in log.read_text().splitlines()] + tracked = subprocess.check_output( + ["git", "ls-files", "--", "uv.lock", "*/uv.lock"], cwd=ROOT, text=True + ).splitlines() + expected = {str(Path(path).parent) for path in tracked} + assert {call[-1] for call in calls} == expected + assert len(calls) == len(expected) + assert all(call[:3] == ["audit", "--locked", "--project"] for call in calls) + + +@pytest.mark.parametrize("exit_code", [0, 7]) +def test_rust_audit_clears_git_context_and_preserves_failure(tmp_path, exit_code): + cargo = tmp_path / "cargo" + cargo.write_text( + f"#!{sys.executable}\n" + "import json, os, sys\n" + "print(json.dumps({'args': sys.argv[1:], 'git': {key: os.environ.get(key) " + "for key in ('GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE')}}))\n" + f"raise SystemExit({exit_code})\n" + ) + cargo.chmod(0o755) + env = dict( + os.environ, + PATH=f"{tmp_path}{os.pathsep}{os.environ['PATH']}", + GIT_DIR=str(tmp_path / "other.git"), + GIT_WORK_TREE=str(tmp_path), + GIT_INDEX_FILE=str(tmp_path / "other.index"), + ) + result = subprocess.run( + ["bash", "scripts/lint/check_cargo_dependencies.sh"], + cwd=ROOT, + env=env, + capture_output=True, + text=True, + ) + assert result.returncode == exit_code, result.stderr + recorded = json.loads(result.stdout) + assert recorded["args"] == [ + "deny", + "--locked", + "--all-features", + "check", + "advisories", + ] + assert all(value is None for value in recorded["git"].values())