Skip to content

ci: block banned files in pull request diffs#2475

Open
WilliamK112 wants to merge 2 commits intoNVIDIA:mainfrom
WilliamK112:ci/banned-files-guard
Open

ci: block banned files in pull request diffs#2475
WilliamK112 wants to merge 2 commits intoNVIDIA:mainfrom
WilliamK112:ci/banned-files-guard

Conversation

@WilliamK112
Copy link
Copy Markdown
Contributor

@WilliamK112 WilliamK112 commented Apr 25, 2026

Summary

  • add a diff-only banned-files guard for pull requests
  • block secrets, metadata, bytecode, and node_modules paths while allowing test fixtures
  • add a focused vitest regression suite for the guard script

Testing

  • npm test -- test/banned-files-guard.test.ts
  • npx eslint scripts/check-banned-files.mjs test/banned-files-guard.test.ts

Related

Summary by CodeRabbit

  • New Features

    • Added an automated PR validation that compares the PR against its base and blocks commits containing sensitive or generated files (environment files, private keys/cert bundles, cloud/service-account credentials, secret manifests, platform metadata, and common build/artifact directories).
  • Tests

    • Added tests that create isolated commit scenarios to verify the validation permits allowed fixtures and correctly blocks disallowed files, ensuring CI behavior remains consistent.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 25, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fb0433dc-3aa0-4ea6-9f35-bbb62a12e8ce

📥 Commits

Reviewing files that changed from the base of the PR and between 45e1992 and cc0b0ab.

📒 Files selected for processing (1)
  • .github/workflows/pr.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pr.yaml

📝 Walkthrough

Walkthrough

Adds a banned-files detection flow: a Node.js CLI inspects git diffs for sensitive/generated files; GitHub Actions PR workflow runs the check using full git history; Vitest tests validate detection and allowed exceptions.

Changes

Cohort / File(s) Summary
PR Workflow Integration
\.github/workflows/pr.yaml
Workflow now checks out full git history (fetch-depth: 0), fetches the PR base commit, and runs the banned-files checker comparing base vs HEAD to fail the job on violations.
Banned Files Checker
scripts/check-banned-files.mjs
New Node.js CLI: lists changed files between two refs, normalizes paths, excludes testdata/ and test/fixtures/, applies block rules for secrets/generated artifacts, prints violations or clean message, exits 0 (clean), 1 (blocked files), 2 (usage/error). Exports rule set and helper functions.
Tests
test/banned-files-guard.test.ts
New Vitest suite that creates temporary git repos, commits candidate files, runs the checker against base...HEAD, and asserts exit codes and output for blocked and allowed cases. Temporary repos are cleaned up after tests.

Sequence Diagram

sequenceDiagram
    actor GH as GitHub Actions
    participant WF as PR Workflow
    participant Git as Git
    participant Script as check-banned-files.mjs
    participant Rules as Block Rules
    participant Out as Output/Exit

    GH->>WF: PR triggers workflow
    WF->>Git: fetch base branch (origin)
    WF->>Script: run with base ref & HEAD
    Script->>Git: git diff --name-only base...HEAD
    Git-->>Script: list of changed files
    Script->>Script: normalize & filter fixture paths
    loop per file
        Script->>Rules: evaluate file against block rules
        Rules-->>Script: match/no-match
    end
    alt blocked files found
        Script->>Out: print violations
        Script->>Out: exit 1
    else no violations
        Script->>Out: print clean message
        Script->>Out: exit 0
    end
    Out-->>WF: status reported
    WF-->>GH: job result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hop through diffs with gentle paws,

Sniffing for keys, certs, and secret flaws.
I flag the naughty, let the tidy pass—
A courteous guard in the code-lined grass. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ci: block banned files in pull request diffs' directly and accurately summarizes the main change: adding a CI check that prevents banned files from being introduced in pull requests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/banned-files-guard.test.ts (1)

27-35: Clean up temporary repos after each test run.

makeRepo() creates temp directories but never removes them. Adding afterEach cleanup keeps local/dev CI environments tidy.

Suggested patch
-import { describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it } from "vitest";
@@
 const REPO_ROOT = path.join(import.meta.dirname, "..");
 const SCRIPT = path.join(REPO_ROOT, "scripts", "check-banned-files.mjs");
+const TEMP_REPOS: string[] = [];
@@
 function makeRepo() {
   const dir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-banned-files-"));
+  TEMP_REPOS.push(dir);
   git(dir, ["init", "-b", "main"]);
@@
   return { dir, base };
 }
+
+afterEach(() => {
+  for (const dir of TEMP_REPOS.splice(0)) {
+    fs.rmSync(dir, { recursive: true, force: true });
+  }
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/banned-files-guard.test.ts` around lines 27 - 35, makeRepo() creates
temporary repositories but never deletes them; modify the test file to track
created temp dirs (from makeRepo) and add an afterEach hook that removes each
directory (use fs.rmSync or equivalent with recursive/force) to clean up after
tests; reference the makeRepo helper and ensure the afterEach cleans any dirs
pushed to the tracking array so CI/local runs don't accumulate temp repos.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/check-banned-files.mjs`:
- Around line 9-60: BLOCK_RULES currently omits several sensitive patterns
present in our .gitignore; update the BLOCK_RULES array to add rules (or extend
existing matches functions) to catch private key and credential file patterns
such as *_rsa, *_ed25519, *_ecdsa, *.jks, *.keystore, .netrc, .npmrc, *.tfvars,
and the .direnv directory; implement each as either new objects with unique ids
(e.g., "ssh-keys", "java-keystores", "netrc-npmrc", "terraform-vars", "direnv")
and a matches: (filePath) => { ... } predicate using path.posix.basename and
regexes to mirror the style of existing entries, and ensure case-insensitive
matching where appropriate so these files are rejected by the existing check
logic.

---

Nitpick comments:
In `@test/banned-files-guard.test.ts`:
- Around line 27-35: makeRepo() creates temporary repositories but never deletes
them; modify the test file to track created temp dirs (from makeRepo) and add an
afterEach hook that removes each directory (use fs.rmSync or equivalent with
recursive/force) to clean up after tests; reference the makeRepo helper and
ensure the afterEach cleans any dirs pushed to the tracking array so CI/local
runs don't accumulate temp repos.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fe20e59c-646d-449f-985f-f9a1a98038a4

📥 Commits

Reviewing files that changed from the base of the PR and between 9c5a42a and b2890c7.

📒 Files selected for processing (3)
  • .github/workflows/pr.yaml
  • scripts/check-banned-files.mjs
  • test/banned-files-guard.test.ts

Comment thread scripts/check-banned-files.mjs
@WilliamK112 WilliamK112 force-pushed the ci/banned-files-guard branch from b2890c7 to 45e1992 Compare April 25, 2026 05:43
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/pr.yaml:
- Around line 53-57: Replace the mutable github.base_ref with the immutable pull
request base SHA and fetch that commit so the PR diff is stable: change the git
fetch target from "origin/${{ github.base_ref }}" to the captured commit
"origin/${{ github.event.pull_request.base.sha }}" (or fetch that SHA
explicitly) and pass that SHA to node scripts/check-banned-files.mjs instead of
github.base_ref; ensure the fetch command fetches the referenced commit (remove
the --depth=1 shallow ref if needed) so merge-base calculation and
scripts/check-banned-files.mjs receive an immutable base.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f99371f9-4a6c-478a-8867-bbb875c4b351

📥 Commits

Reviewing files that changed from the base of the PR and between b2890c7 and 45e1992.

📒 Files selected for processing (3)
  • .github/workflows/pr.yaml
  • scripts/check-banned-files.mjs
  • test/banned-files-guard.test.ts
✅ Files skipped from review due to trivial changes (1)
  • test/banned-files-guard.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/check-banned-files.mjs

Comment thread .github/workflows/pr.yaml
@WilliamK112
Copy link
Copy Markdown
Contributor Author

Follow-up update after review:

  • expanded the banned-path coverage to match the repo's existing ignored secret / credential patterns more closely, including *_rsa, *_ed25519, *_ecdsa, *.jks, *.keystore, .netrc, .npmrc, .pypirc, *.tfvars, .direnv/, and secret manifest filenames
  • added temp repo cleanup in the Vitest suite so the guard tests do not leave local artifacts behind
  • re-ran validation:
    • npm test -- test/banned-files-guard.test.ts
    • npx eslint scripts/check-banned-files.mjs test/banned-files-guard.test.ts

@wscurran wscurran added CI/CD Use this label to identify issues with NemoClaw CI/CD pipeline or GitHub Actions. dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code labels Apr 27, 2026
@wscurran
Copy link
Copy Markdown
Contributor

✨ Thanks for submitting this pull request that proposes a way to block banned files in pull request diffs.


Related open issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD Use this label to identify issues with NemoClaw CI/CD pipeline or GitHub Actions. dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants