Skip to content

feat(tooling): SPDX --fix, hook ordering, and strict shellcheck fixes - #670

Merged
cv merged 14 commits into
NVIDIA:mainfrom
HagegeR:spdx-headers-tooling
Mar 24, 2026
Merged

cv merged 14 commits into
NVIDIA:mainfrom
HagegeR:spdx-headers-tooling

Conversation

@HagegeR

@HagegeR HagegeR commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds --fix option to scripts/check-spdx-headers.sh (with exclusions for init.py), run the corresponding hook at higher priority with the new option, and align to lint-staged in package.json.
Fill missing SPDX headers on shell scripts, align shellcheck with default pre-commit rules (no relaxed args), and updates husky-env.sh, test-inference*.sh, and e2e scripts so strict shellcheck passes.

Changes

  • scripts/check-spdx-headers.sh: --fix, exclude nemoclaw-blueprint/**/init.py.
  • .pre-commit-config.yaml: SPDX hook priority 4 with --fix; shellcheck uses default severity/rules.
  • package.json: lint-staged SPDX step uses --fix where applicable.
  • Shell scripts: SPDX headers where missing; husky-env.sh: shell=bash for shellcheck.
  • scripts/test-inference.sh, scripts/test-inference-local.sh: redirection style for shellcheck.
  • test/e2e/test-double-onboard.sh, test/e2e/test-full-e2e.sh: refactors for strict shellcheck.

Type of Change

  • Code change for a new feature, bug fix, or refactor.
  • Code change with doc updates.
  • Doc only. Prose changes without code sample modifications.
  • Doc only. Includes code sample changes.

Testing

  • make check passes.
  • npm test passes.
  • make docs builds without warnings. (for doc-only changes)

Checklist

General

Code Changes

  • make format applied (TypeScript and Python).
  • Tests added or updated for new or changed behavior.
  • No secrets, API keys, or credentials committed.
  • Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs).

Doc Changes

  • Follows the style guide. Try running the update-docs agent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docs catch up the docs for the new changes I made in this PR."
  • New pages include SPDX license header and frontmatter, if creating a new page.
  • Cross-references and links verified.

Summary by CodeRabbit

  • Chores

    • Pre-commit now auto-inserts and auto-fixes SPDX license headers and enforces header checks earlier in the workflow.
  • Bug Fixes

    • Restore flow now more reliably selects the most recent backup when no timestamp is provided.
  • Tests

    • End-to-end tests updated for clearer, deterministic pass/fail reporting and removed "skipped" result reporting for consistent outcomes.

HagegeR added 7 commits March 23, 2026 01:25
Drop --severity=warning and --exclude=SC1091 so local hooks match
strict shellcheck; script issues are fixed in-tree instead.
Add shellcheck shell=bash directive so SC2148 is satisfied without
weakening global hook rules.
Use >/path form so shellcheck does not flag spacing around redirects.
Replace SC2015 if/else chains with explicit if/else, add source
directives for dynamic sources, fix exit-status checks, and remove
unused variables so strict shellcheck passes.
@coderabbitai

coderabbitai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 975fe659-7b1b-472b-bfdb-672c1bdce315

📥 Commits

Reviewing files that changed from the base of the PR and between 2adc337 and f2541ef.

📒 Files selected for processing (3)
  • scripts/backup-workspace.sh
  • test/e2e-test.sh
  • test/e2e/test-full-e2e.sh
✅ Files skipped from review due to trivial changes (1)
  • test/e2e-test.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/e2e/test-full-e2e.sh

📝 Walkthrough

Walkthrough

Pre-commit hook ordering changed to run spdx-headers earlier with a --fix flag; the header-check script gained --fix to auto-insert NVIDIA Apache-2.0 SPDX blocks, broadened detection to the first ~16 lines and preserves shebangs; backup selection and multiple test scripts had control-flow and selection tweaks.

Changes

Cohort / File(s) Summary
Pre-commit Hook Configuration
./.pre-commit-config.yaml
Moved spdx-headers local hook to priority 4 and invoke it with --fix; removed explicit args from shellcheck; added exclude pattern for certain __init__ files.
SPDX Header Checking Script
scripts/check-spdx-headers.sh
Added --fix mode to insert NVIDIA Apache-2.0 SPDX header blocks, expanded detection to first ~16 lines, preserves shebangs, chooses comment prefix by file type, skips non-regular files, and returns accumulated exit code.
Backup Selection Logic
scripts/backup-workspace.sh
When restoring without a timestamp, enumerate direct backup subdirectories using find ... -mindepth 1 -maxdepth 1 -type d -printf '%f\n' instead of ls.
E2E Tests & Helpers
test/e2e-test.sh, test/e2e/test-double-onboard.sh, test/e2e/test-full-e2e.sh, test/e2e/...
Replaced many short-circuit `cmd && …

Sequence Diagram(s)

sequenceDiagram
  participant PreCommit as Pre-commit
  participant HookRunner as Hook runner
  participant Script as check-spdx-headers.sh
  participant FS as Repository files

  PreCommit->>HookRunner: invoke `spdx-headers` hook (priority 4, --fix)
  HookRunner->>Script: run script with file list and `--fix`
  Script->>FS: read top ~16 lines of each target file
  alt header present
    Script->>FS: leave file unchanged
    Script-->>HookRunner: report OK
  else header missing
    Script->>FS: insert SPDX block (preserve shebang, use comment style)
    Script-->>HookRunner: report Added header
  end
  HookRunner-->>PreCommit: aggregate results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble headers in the night,
I hop and check each leading line.
If SPDX is missing, I gently fix —
tuck Apache’s mark where it belongs.
Repos hum tidy, carrots bright.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding --fix to SPDX headers, adjusting hook ordering/priority, and fixing shellcheck compliance issues across the codebase.

✏️ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

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

Inline comments:
In `@package.json`:
- Around line 40-42: The lint-staged glob "nemoclaw-blueprint/**/*.py" is
including blueprint __init__.py files (e.g.
nemoclaw-blueprint/orchestrator/__init__.py) while .pre-commit-config.yaml
explicitly excludes them; update the lint-staged entry for
"nemoclaw-blueprint/**/*.py" to also exclude __init__.py files (for example by
adding a negative glob such as "nemoclaw-blueprint/**/__init__.py" prefixed with
"!" or an equivalent exclusion) so the SPDX header fixer and lint-staged
behavior match.

In `@scripts/check-spdx-headers.sh`:
- Around line 65-82: The temp-file rewrite currently creates a 0600 file and
then mv's it over the original, losing executable bits; before mv "$tmp" "$file"
set the temp file's mode to match the original (e.g. run chmod
--reference="$file" "$tmp" or use stat to get and apply the original mode)
inside the insert_spdx block that creates tmp so the original file permissions
(including +x) are preserved when moving the temp into place.

In `@test/e2e/test-double-onboard.sh`:
- Around line 125-129: The pipeline using echo "$outputN" | grep -q should be
replaced with here-strings to avoid SIGPIPE when running with set -o pipefail:
for each check that currently uses echo "$output1" | grep -q "..." (and the
similar occurrences for output2 and output3 around the other ranges), change to
using grep -q with a here-string (grep -q "pattern" <<< "$output1") so grep
reads directly from the here-string; update the three blocks that test for
"Sandbox '${SANDBOX_A}' created" and the other two sandbox/step checks (the ones
referencing output1/output2/output3 and variables like SANDBOX_A) to use this
here-string form and keep the existing pass/fail calls unchanged.

In `@test/e2e/test-full-e2e.sh`:
- Around line 207-211: Replace the pipeline-based grep checks that read from
shell variables (e.g., echo "$list_output" | grep -Fq -- "$SANDBOX_NAME", echo
"$policy_output" | grep -q ...) with here-strings to avoid pipefail/SIGPIPE
issues; locate the grep invocations that use echo of variables such as
list_output, policy_output (and similar checks around the sandbox/name
assertions) and change them to use grep -Fq -- "$SANDBOX_NAME" <<<"$list_output"
(and grep -q <<<"$policy_output" for the policy checks) so grep reads directly
from the variable without a pipe.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3f48d530-7af6-4c51-aa87-eb084f0456c9

📥 Commits

Reviewing files that changed from the base of the PR and between d37a09f and 1107926.

📒 Files selected for processing (8)
  • .pre-commit-config.yaml
  • package.json
  • scripts/check-spdx-headers.sh
  • scripts/husky-env.sh
  • scripts/test-inference-local.sh
  • scripts/test-inference.sh
  • test/e2e/test-double-onboard.sh
  • test/e2e/test-full-e2e.sh

Comment thread package.json Resolved
Comment thread scripts/check-spdx-headers.sh Resolved
Comment thread test/e2e/test-double-onboard.sh Resolved
Comment thread test/e2e/test-full-e2e.sh Resolved
@wscurran

Copy link
Copy Markdown
Contributor

Thanks for contributing to the tooling, adding SPDX fix, hook ordering, and strict shellcheck fixes will be really helpful for improving testing and code quality.

HagegeR and others added 4 commits March 24, 2026 13:21
Address CodeRabbit review feedback on PR NVIDIA#670:
- check-spdx-headers.sh: capture and restore original file mode when
  rewriting via mktemp+mv so executable bits are not lost
- test-double-onboard.sh, test-full-e2e.sh: replace echo|grep -q pipes
  with here-strings to avoid SIGPIPE under pipefail; convert A&&B||C
  patterns to proper if/then/else (SC2015); check exit codes directly
  (SC2181); remove unused skip() function (SC2329)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Convert A&&B||C patterns to proper if/then/else (SC2015) in e2e-test.sh,
and replace ls with find in backup-workspace.sh (SC2012).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
fix: address CodeRabbit review feedback

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@scripts/backup-workspace.sh`:
- Around line 83-84: In do_restore(), the unguarded find assignment for ts can
cause the script to exit under set -euo pipefail if BACKUP_BASE doesn't exist;
guard the failure by first testing the directory (e.g., if [ -d "$BACKUP_BASE"
]; then ts="$(find "$BACKUP_BASE" -mindepth 1 -maxdepth 1 -type d -printf '%f\n'
2>/dev/null | sort -r | head -n1)"; else ts=""; fi) or alternatively append ||
true to the find pipeline (ts="$(find ... 2>/dev/null | sort -r | head -n1  ||
true)") so the command won't abort the script and the subsequent [ -n "$ts" ] ||
fail "No backups found in ${BACKUP_BASE}/" path still runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91b4d809-d7ae-4965-bc5e-c478ee3c706e

📥 Commits

Reviewing files that changed from the base of the PR and between 1cf2544 and 2adc337.

📒 Files selected for processing (5)
  • scripts/backup-workspace.sh
  • scripts/check-spdx-headers.sh
  • test/e2e-test.sh
  • test/e2e/test-double-onboard.sh
  • test/e2e/test-full-e2e.sh

Comment thread scripts/backup-workspace.sh Resolved
cv and others added 3 commits March 24, 2026 09:02
Take upstream semantic changes (ncp profile, nvidia-prod provider,
wording updates) with our structural improvements (herestrings,
if/then/else).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The unguarded find pipeline in do_restore() aborts under set -euo
pipefail when BACKUP_BASE doesn't exist, before the descriptive
error on the next line can run. Append || true so the [ -n "$ts" ]
guard produces a clear "No backups found" message instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@cv
cv merged commit fd4aafc into NVIDIA:main Mar 24, 2026
1 check was pending
jessesanford pushed a commit to jessesanford/NemoClaw that referenced this pull request Mar 24, 2026
…NVIDIA#670)

* feat(scripts): add SPDX --fix and exclude blueprint __init__.py files

* chore: SPDX hook at priority 4 with --fix; lint-staged uses --fix

* chore: add SPDX headers to shell scripts missing them

* chore(pre-commit): run shellcheck with default rules

Drop --severity=warning and --exclude=SC1091 so local hooks match
strict shellcheck; script issues are fixed in-tree instead.

* fix(scripts): declare bash for shellcheck in husky-env

Add shellcheck shell=bash directive so SC2148 is satisfied without
weakening global hook rules.

* chore(scripts): normalize redirection in test-inference helpers

Use >/path form so shellcheck does not flag spacing around redirects.

* fix(e2e): satisfy shellcheck in onboard and full e2e tests

Replace SC2015 if/else chains with explicit if/else, add source
directives for dynamic sources, fix exit-status checks, and remove
unused variables so strict shellcheck passes.

* fix: preserve file permissions in SPDX fixer and harden e2e test scripts

Address CodeRabbit review feedback on PR NVIDIA#670:
- check-spdx-headers.sh: capture and restore original file mode when
  rewriting via mktemp+mv so executable bits are not lost
- test-double-onboard.sh, test-full-e2e.sh: replace echo|grep -q pipes
  with here-strings to avoid SIGPIPE under pipefail; convert A&&B||C
  patterns to proper if/then/else (SC2015); check exit codes directly
  (SC2181); remove unused skip() function (SC2329)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: resolve shellcheck warnings in e2e-test.sh and backup-workspace.sh

Convert A&&B||C patterns to proper if/then/else (SC2015) in e2e-test.sh,
and replace ls with find in backup-workspace.sh (SC2012).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: guard find in do_restore against missing backup directory

The unguarded find pipeline in do_restore() aborts under set -euo
pipefail when BACKUP_BASE doesn't exist, before the descriptive
error on the next line can run. Append || true so the [ -n "$ts" ]
guard produces a clear "No backups found" message instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
temrjan pushed a commit to temrjan/NemoClaw that referenced this pull request Mar 25, 2026
…NVIDIA#670)

* feat(scripts): add SPDX --fix and exclude blueprint __init__.py files

* chore: SPDX hook at priority 4 with --fix; lint-staged uses --fix

* chore: add SPDX headers to shell scripts missing them

* chore(pre-commit): run shellcheck with default rules

Drop --severity=warning and --exclude=SC1091 so local hooks match
strict shellcheck; script issues are fixed in-tree instead.

* fix(scripts): declare bash for shellcheck in husky-env

Add shellcheck shell=bash directive so SC2148 is satisfied without
weakening global hook rules.

* chore(scripts): normalize redirection in test-inference helpers

Use >/path form so shellcheck does not flag spacing around redirects.

* fix(e2e): satisfy shellcheck in onboard and full e2e tests

Replace SC2015 if/else chains with explicit if/else, add source
directives for dynamic sources, fix exit-status checks, and remove
unused variables so strict shellcheck passes.

* fix: preserve file permissions in SPDX fixer and harden e2e test scripts

Address CodeRabbit review feedback on PR NVIDIA#670:
- check-spdx-headers.sh: capture and restore original file mode when
  rewriting via mktemp+mv so executable bits are not lost
- test-double-onboard.sh, test-full-e2e.sh: replace echo|grep -q pipes
  with here-strings to avoid SIGPIPE under pipefail; convert A&&B||C
  patterns to proper if/then/else (SC2015); check exit codes directly
  (SC2181); remove unused skip() function (SC2329)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: resolve shellcheck warnings in e2e-test.sh and backup-workspace.sh

Convert A&&B||C patterns to proper if/then/else (SC2015) in e2e-test.sh,
and replace ls with find in backup-workspace.sh (SC2012).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: guard find in do_restore against missing backup directory

The unguarded find pipeline in do_restore() aborts under set -euo
pipefail when BACKUP_BASE doesn't exist, before the descriptive
error on the next line can run. Append || true so the [ -n "$ts" ]
guard produces a clear "No backups found" message instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
jacobtomlinson pushed a commit to jacobtomlinson/NemoClaw that referenced this pull request Apr 30, 2026
…NVIDIA#670)

* feat(scripts): add SPDX --fix and exclude blueprint __init__.py files

* chore: SPDX hook at priority 4 with --fix; lint-staged uses --fix

* chore: add SPDX headers to shell scripts missing them

* chore(pre-commit): run shellcheck with default rules

Drop --severity=warning and --exclude=SC1091 so local hooks match
strict shellcheck; script issues are fixed in-tree instead.

* fix(scripts): declare bash for shellcheck in husky-env

Add shellcheck shell=bash directive so SC2148 is satisfied without
weakening global hook rules.

* chore(scripts): normalize redirection in test-inference helpers

Use >/path form so shellcheck does not flag spacing around redirects.

* fix(e2e): satisfy shellcheck in onboard and full e2e tests

Replace SC2015 if/else chains with explicit if/else, add source
directives for dynamic sources, fix exit-status checks, and remove
unused variables so strict shellcheck passes.

* fix: preserve file permissions in SPDX fixer and harden e2e test scripts

Address CodeRabbit review feedback on PR NVIDIA#670:
- check-spdx-headers.sh: capture and restore original file mode when
  rewriting via mktemp+mv so executable bits are not lost
- test-double-onboard.sh, test-full-e2e.sh: replace echo|grep -q pipes
  with here-strings to avoid SIGPIPE under pipefail; convert A&&B||C
  patterns to proper if/then/else (SC2015); check exit codes directly
  (SC2181); remove unused skip() function (SC2329)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: resolve shellcheck warnings in e2e-test.sh and backup-workspace.sh

Convert A&&B||C patterns to proper if/then/else (SC2015) in e2e-test.sh,
and replace ls with find in backup-workspace.sh (SC2012).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: guard find in do_restore against missing backup directory

The unguarded find pipeline in do_restore() aborts under set -euo
pipefail when BACKUP_BASE doesn't exist, before the descriptive
error on the next line can run. Append || true so the [ -n "$ts" ]
guard produces a clear "No backups found" message instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
@wscurran wscurran added area: e2e End-to-end tests, nightly failures, or validation infrastructure feature PR adds or expands user-visible functionality and removed enhancement: testing labels Jun 3, 2026
cv added a commit that referenced this pull request Nov 18, 2026
)

Apply now stops a Fabric agent's failed runtime before it starts another
in the same sandbox, so an agent recovers on the next apply after
provider errors instead of failing every apply until someone stops the
runtime by hand or replaces the sandbox.

## Problem

After provider errors, such as a model endpoint that answers 500, Fabric
can mark a runtime failed while its adapter host and native processes
keep running
([NVIDIA/NeMo-Fabric#670](NVIDIA/NeMo-Fabric#670)).
Refresh then finds the runtime not running, and the plan gives
`fabric_agent` an unknown `runtime_id`.
Apply received no runtime ID, skipped `fabric-agent-ctl stop`, and
started another runtime beside the failed one, which Fabric refused:

- With `runtime.keep_state`, the failed runtime still held the agent's
state lock: `start (state_in_use)` on every apply until someone ran
`fabric-agent-ctl stop`.
- Without kept state, OpenClaw's Gateway still held its ports: `start
(start_failed)`, with unknown effects, after which Fabric refused every
start until the sandbox was replaced.

The comment in `configuration::ensure` said a stopped runtime is stopped
in Fabric first, and the provider reference and usage guide said the
same, but only the backend tests passed a runtime ID that a real plan
never carries.

## Change

- `fabric_agent`'s backend implements `update`: when the planned
`runtime_id` is unknown, it takes the prior state's ID, so `ensure`
stops that runtime before it starts another. Stopping a runtime Fabric
no longer has already counts as stopped. If the stop fails, apply keeps
the prior state, and the next apply stops the runtime again.
- The `fabric` provider's backend passes `update` through to it; before,
the trait's default dropped the prior state.
- The fake gateway can mark a runtime failed (`fail_agent_runtime`) as
Fabric at the pinned revision does: checks and invokes find it
unavailable, a stop ends it, and until then a start in its sandbox fails
with `state_in_use` when the agent keeps state, or `start_failed` with
unknown effects otherwise.
- Tests: the `failed_runtime` contract scenario applies through OpenTofu
after the runtime fails without kept state, and a backend test covers
kept state. The existing restart backend test now passes the row a real
plan produces. Each new test failed before the fix.
- Docs: the provider reference, the `state_in_use` troubleshooting row,
and the release notes.

Stopping the failed runtime is the caller's step under Fabric's current
contract; #670 asks whether Fabric should stop the host itself. This
change stays correct either way, since a stop of a runtime that's
already gone succeeds.

## Beyond CI

The provider-500 case isn't verified live with this change. #670 records
the failure live, with kept state on the pending Fabric pin bump and
without kept state at Fabric `135147a0`. A rerun on this branch, with
OpenClaw at `135147a0` and no kept state, didn't reach it: six
invocations against a model stub that answered 500 or hung each returned
a failed result, and Fabric kept the runtime active, so apply had
nothing to recover.

Signed-off-by: Carlos Villela <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: e2e End-to-end tests, nightly failures, or validation infrastructure feature PR adds or expands user-visible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants