Skip to content

fix(e2e): replace hard exits with skip-and-continue in test-token-rotation.sh - #2256

Closed
kagura-agent wants to merge 2 commits into
NVIDIA:mainfrom
kagura-agent:fix/e2e-token-rotation-hard-exit
Closed

kagura-agent wants to merge 2 commits into
NVIDIA:mainfrom
kagura-agent:fix/e2e-token-rotation-hard-exit

Conversation

@kagura-agent

@kagura-agent kagura-agent commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace exit 1 after install/onboard failures in test-token-rotation.sh with a skip-and-continue pattern so CI always prints the Summary section.

Fixes #2247

Problem

When install.sh --non-interactive fails due to environmental issues (e.g. api.telegram.org unreachable from the CI network), the test script calls exit 1 immediately:

  • No Summary is printed
  • Phases 1–3 are never run
  • CI reports a generic failure without showing which phases would have passed

The same hard-exit pattern repeats in Phases 2 and 3.

Changes

  • Add SKIP counter and skip() helper (yellow output) alongside existing pass()/fail()
  • Track Phase 0 success with a PHASE0_OK flag
  • When Phase 0 fails, Phases 1–3 are marked SKIP instead of silently not running
  • When Phase 2/3 onboard fails, record FAIL but continue to Summary
  • Summary line now includes Skip count: Total: N Pass: N Fail: N Skip: N

Testing

  • bash -n test/e2e/test-token-rotation.sh — syntax check passes
  • Verified all exit 1 calls within phase logic are replaced; only the prerequisite checks and repo-root detection retain early exits (correct behavior)
  • The final exit code still reflects failures: exit 1 if any FAILs, exit 0 if all PASS/SKIP

Summary by CodeRabbit

  • Tests
    • Improved skip tracking and summary counts for skipped tests.
    • Detect environmental/preflight/network failures and mark affected phases as skipped.
    • Initial-phase failures no longer abort the run; execution continues and subsequent phases are conditionally skipped.
    • Tool availability checks are deferred until the initial phase succeeds.
    • Phase outcomes now record skips or failures without stopping the overall test run.

@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Reworked test/e2e/test-token-rotation.sh to detect environmental/preflight failures and record SKIP states instead of hard-exiting. Introduced PHASE0_OK and PHASE2_OK gating, is_environmental_failure() detection, and skip counting; phases are conditionally executed and final Summary reports Pass/Fail/Skip counts.

Changes

Cohort / File(s) Summary
E2E test script
test/e2e/test-token-rotation.sh
Replaced INSTALL_OK-driven exits with PHASE0_OK/PHASE2_OK flags; added is_environmental_failure() and skip() behavior. Install/onboard non-zero exits now classify environmental failures as SKIP (increment SKIP) or infrastructure failures (record FAIL/hard-exit). Phase gating changed so downstream phases may be skipped instead of aborting.
Tool checks & diagnostics
test/e2e/test-token-rotation.sh (openshell/nemoclaw checks, install log handling)
Tool PATH verification no longer immediately exits on missing binaries; missing critical tools flip PHASE0_OK=false and are recorded. Install log is inspected to distinguish environmental vs infra failures; diagnostic prints and Summary now include skip counts and reasons.

Sequence Diagram(s)

sequenceDiagram
  participant Runner as "Test Runner\n(test-token-rotation.sh)"
  participant Installer as "Installer\n(install.sh)"
  participant Tools as "Local Tools\n(openshell/nemoclaw)"
  participant External as "External APIs\n(e.g., Telegram)"
  Runner->>Installer: run install.sh
  alt install exits 0
    Installer-->>Runner: success
    Runner->>Tools: verify PATH/tools
    Tools-->>Runner: tools present
    Runner->>External: run Phase 1..5 as gated by flags
    External-->>Runner: responses
  else install exits non-zero
    Installer-->>Runner: failure (logs)
    Runner->>Runner: is_environmental_failure()? 
    alt environmental failure
      Runner-->>Runner: increment SKIP, set PHASE0_OK=false
      Runner->>Runner: mark dependent phases SKIPPED
    else infrastructure failure
      Runner-->>Runner: record FAIL / hard-exit if critical
    end
  end
  Runner->>Runner: summarize results (Pass / Fail / Skip, include Skip count)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through phases, logs in paw,

If networks flub, I mark a "raw"—
A gentle skip, no bitter crash,
I tally counts and stash the cache,
Summary neat, then off I dash! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 directly and clearly describes the main change: replacing hard exits with a skip-and-continue pattern in the test-token-rotation.sh script.
Linked Issues check ✅ Passed The PR addresses all key requirements from #2247: implements skip-and-continue pattern, adds environmental failure detection via is_environmental_failure(), gates phases on prior success flags, treats environmental failures as SKIP, updates Summary to show Skip count, and preserves hard exits for infrastructure failures.
Out of Scope Changes check ✅ Passed All changes are focused on the test-token-rotation.sh file and directly address the issue objectives; no out-of-scope modifications detected.

✏️ 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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/e2e/test-token-rotation.sh (1)

131-137: ⚠️ Potential issue | 🟠 Major

Treat Phase 0 preflight/onboard failures as SKIP, not unconditional FAIL.

install.sh --non-interactive includes the first onboard, so a non-zero install_exit can still be the environmental preflight case from #2247. Recording every non-zero exit as FAIL will keep failing CI for exactly the scenario this PR is meant to downgrade to skip.

Suggested direction
+is_environmental_preflight_failure() {
+  grep -Eq 'preflight|unreachable|Telegram|Discord' "$1"
+}
+
 if [ $install_exit -eq 0 ]; then
   pass "install.sh completed (exit 0)"
 else
-  fail "install.sh failed (exit $install_exit)"
+  if is_environmental_preflight_failure "$INSTALL_LOG"; then
+    skip "Phase 0 skipped due to environmental preflight failure (exit $install_exit)"
+  else
+    fail "install.sh failed (exit $install_exit)"
+  fi
   info "Last 30 lines of install log:"
   tail -30 "$INSTALL_LOG" 2>/dev/null || true
   PHASE0_OK=false
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/test-token-rotation.sh` around lines 131 - 137, The current block
treats any non-zero install_exit as a hard FAIL; change it so a non-zero exit
from running install.sh (which may be an environment/preflight onboarding case)
is recorded as a SKIP rather than unconditional FAIL: when install_exit is 0
keep pass "install.sh completed (exit 0)"; otherwise call skip "install.sh
skipped (exit $install_exit)" (or use the existing skip helper if present),
print the last 30 lines of INSTALL_LOG as you already do, and set
PHASE0_OK=false or a PHASE0_SKIPPED flag as appropriate—update references to
install_exit, install.sh, and PHASE0_OK in this block to reflect SKIP semantics
instead of fail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/e2e/test-token-rotation.sh`:
- Around line 192-250: Phase 3 must be gated on Phase 2 success and Phase 2
preflight/environmental failures should be downgraded to SKIP: introduce a
PHASE2_OK boolean (set to true only when the Phase 2 onboarding completes with
exit 0 and the output confirms rotation and sandbox rebuild—i.e., when the
checks around "credential(s) rotated" and "Rebuilding sandbox" both pass),
change the Phase 3 guard to if [ "$PHASE0_OK" != true ] || [ "$PHASE2_OK" !=
true ] to skip when Phase 2 did not establish the rotated-token baseline, and
update Phase 2 failure branches that currently call fail for known
environmental/preflight errors (detect via onboard_exit non-zero combined with
output matching preflight/env error strings) to call skip instead of fail so
preflight failures are recorded as SKIP rather than failing downstream phases.

---

Outside diff comments:
In `@test/e2e/test-token-rotation.sh`:
- Around line 131-137: The current block treats any non-zero install_exit as a
hard FAIL; change it so a non-zero exit from running install.sh (which may be an
environment/preflight onboarding case) is recorded as a SKIP rather than
unconditional FAIL: when install_exit is 0 keep pass "install.sh completed (exit
0)"; otherwise call skip "install.sh skipped (exit $install_exit)" (or use the
existing skip helper if present), print the last 30 lines of INSTALL_LOG as you
already do, and set PHASE0_OK=false or a PHASE0_SKIPPED flag as
appropriate—update references to install_exit, install.sh, and PHASE0_OK in this
block to reflect SKIP semantics instead of fail.
🪄 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: Pro Plus

Run ID: 438333c5-f8e0-4aa4-b3fe-c1c1ab63e9e7

📥 Commits

Reviewing files that changed from the base of the PR and between 9b66b63 and 26da301.

📒 Files selected for processing (1)
  • test/e2e/test-token-rotation.sh

Comment thread test/e2e/test-token-rotation.sh
@kagura-agent

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Both suggestions addressed in 497febb:

  1. Environmental preflight → SKIP: Added is_environmental_failure() that greps the install log for network/preflight patterns. When detected, Phase 0 records SKIP instead of FAIL.
  2. Phase 3 gated on Phase 2: Added PHASE2_OK flag. Phase 3 now skips unless both Phase 0 and Phase 2 succeeded, since same-token reuse depends on the rotation baseline from Phase 2.

@wscurran

Copy link
Copy Markdown
Contributor

✨ Thanks for submitting this PR that proposes a way to improve the E2E testing process.


Related open issues:

…ation.sh (NVIDIA#2247)

Replace `exit 1` after install/onboard failures with a skip-and-continue
pattern so CI always prints the Summary section and marks dependent
phases as skipped instead of aborting silently.

Changes:
- Add SKIP counter and skip() helper (yellow output)
- Track Phase 0 success with PHASE0_OK flag
- When Phase 0 fails (e.g. Telegram API unreachable), Phases 1-3
  are marked SKIP instead of never running
- When Phase 2/3 onboard fails, record FAIL but continue to Summary
- Summary line now includes Skip count

Fixes NVIDIA#2247
… 3 on Phase 2

Address CodeRabbit feedback:
- Add is_environmental_failure() to detect network/preflight issues in
  install log and record them as SKIP instead of FAIL
- Track Phase 2 success with PHASE2_OK flag
- Gate Phase 3 on both Phase 0 and Phase 2 success, since Phase 3
  (same-token reuse) depends on Phase 2 (token rotation) completing
@kagura-agent
kagura-agent force-pushed the fix/e2e-token-rotation-hard-exit branch from 497febb to 550502c Compare April 23, 2026 12:57
@copy-pr-bot

copy-pr-bot Bot commented Apr 23, 2026

Copy link
Copy Markdown

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.

@kagura-agent

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main to resolve conflicts. All changes preserved.

@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.

♻️ Duplicate comments (2)
test/e2e/test-token-rotation.sh (2)

282-303: ⚠️ Potential issue | 🟠 Major

Only mark a rotation phase “OK” after its baseline checks pass, and mirror that for Phase 5.

PHASE2_OK flips to true before the rotation/rebuild assertions run, and Phase 5 has no Phase 4 success gate at all. That lets the “same tokens” phases run against an unverified baseline and can turn the later result into noise.

Suggested direction
 PHASE2_OK=false
+PHASE4_OK=false
 ...
-  else
-    PHASE2_OK=true
+  else
+    phase2_checks_ok=true
   fi
 ...
   if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated"; then
     pass "Credential rotation detected"
   else
     fail "Credential rotation not detected in onboard output"
+    phase2_checks_ok=false
   fi
 ...
   if echo "$ONBOARD_OUTPUT" | grep -q "Rebuilding sandbox"; then
     pass "Sandbox rebuild triggered by rotation"
   else
     fail "Sandbox rebuild not triggered"
+    phase2_checks_ok=false
   fi
 ...
+  if [ $onboard_exit -eq 0 ] && [ "$phase2_checks_ok" = true ]; then
+    PHASE2_OK=true
+  fi
 ...
-if [ "$PHASE0_OK" != true ]; then
-  skip "Phase 5 — skipped (Phase 0 failed)"
+if [ "$PHASE0_OK" != true ] || [ "$PHASE4_OK" != true ]; then
+  skip "Phase 5 — skipped (Phase 0 or Phase 4 did not succeed)"

Also applies to: 306-346, 352-353, 372-380, 385-431, 437-439

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/test-token-rotation.sh` around lines 282 - 303, The test currently
sets PHASE2_OK (and similarly other PHASEx flags) to true before performing the
rotation/rebuild assertions; change the flow so each PHASEx_OK flag (e.g.,
PHASE2_OK, PHASE5_OK) is only set to true after the baseline onboarding/check
assertions succeed (i.e., after verifying onboard_exit == 0 and any baseline
checks/expectations); additionally add a prerequisite gate for Phase 5 so it
only runs when PHASE4_OK is true; apply the same ordering/gating fix to the
other phase blocks referenced (lines for Phase 3/4/5/6 placeholders) so no phase
flips true until its baseline verification completes and later phases check the
previous PHASE*_OK before running.

299-301: ⚠️ Potential issue | 🟠 Major

Keep environmental/preflight onboard failures as SKIP in the later phases too.

These branches still unconditionally fail on non-zero nemoclaw onboard, so the same blocked-network/preflight condition you now classify as SKIP in Phase 0 is still reported as FAIL in Phases 2–5. That leaves the #2247 behavior only half-fixed.

Suggested direction
+is_environmental_failure_text() {
+  printf '%s' "$1" | grep -Eqi 'not reachable|unreachable|preflight|network reachability failure'
+}
+
   if [ $onboard_exit -ne 0 ]; then
-    fail "Phase 2 onboard failed (exit $onboard_exit)"
+    if is_environmental_failure_text "$ONBOARD_OUTPUT"; then
+      skip "Phase 2 skipped — environmental preflight failure (exit $onboard_exit)"
+    else
+      fail "Phase 2 onboard failed (exit $onboard_exit)"
+    fi
     echo "$ONBOARD_OUTPUT" | tail -30
   fi

Also applies to: 358-361, 388-391, 443-446

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/test-token-rotation.sh` around lines 299 - 301, The script currently
unconditionally calls fail when onboard_exit is non-zero (using variables
onboard_exit, ONBOARD_OUTPUT, and the fail function); update this to detect the
same preflight/blocked-network SKIP condition used in Phase 0 (reuse the Phase 0
check or helper that inspects ONBOARD_OUTPUT / exit code for the
preflight/blocked-network marker) and, if that condition matches, call the test
skip path instead of fail (e.g., emit SKIP or call the existing skip helper with
a descriptive message); otherwise keep the existing fail behavior. Apply this
conditional replacement at the shown block and the analogous blocks referenced
(around lines 358-361, 388-391, 443-446).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@test/e2e/test-token-rotation.sh`:
- Around line 282-303: The test currently sets PHASE2_OK (and similarly other
PHASEx flags) to true before performing the rotation/rebuild assertions; change
the flow so each PHASEx_OK flag (e.g., PHASE2_OK, PHASE5_OK) is only set to true
after the baseline onboarding/check assertions succeed (i.e., after verifying
onboard_exit == 0 and any baseline checks/expectations); additionally add a
prerequisite gate for Phase 5 so it only runs when PHASE4_OK is true; apply the
same ordering/gating fix to the other phase blocks referenced (lines for Phase
3/4/5/6 placeholders) so no phase flips true until its baseline verification
completes and later phases check the previous PHASE*_OK before running.
- Around line 299-301: The script currently unconditionally calls fail when
onboard_exit is non-zero (using variables onboard_exit, ONBOARD_OUTPUT, and the
fail function); update this to detect the same preflight/blocked-network SKIP
condition used in Phase 0 (reuse the Phase 0 check or helper that inspects
ONBOARD_OUTPUT / exit code for the preflight/blocked-network marker) and, if
that condition matches, call the test skip path instead of fail (e.g., emit SKIP
or call the existing skip helper with a descriptive message); otherwise keep the
existing fail behavior. Apply this conditional replacement at the shown block
and the analogous blocks referenced (around lines 358-361, 388-391, 443-446).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8101284a-92bd-43f0-b87f-897adafafcb2

📥 Commits

Reviewing files that changed from the base of the PR and between 497febb and 550502c.

📒 Files selected for processing (1)
  • test/e2e/test-token-rotation.sh

@jyaunches
jyaunches self-requested a review April 23, 2026 18:17
@jyaunches

Copy link
Copy Markdown
Contributor

Thanks for putting this together, @kagura-agent! The skip-and-continue approach and per-phase gate flags (PHASE0_OK/PHASE2_OK) were a clean design.

Heads-up: PR #2257 landed on main earlier today (commit 1b45c2a6) and it fixes the same issue (#2247) with a superset implementation — it includes the skip/continue pattern plus Discord rotation coverage, provider-isolation assertions, and CI wiring. The base file has changed significantly (+281/−107), so this PR is now stale against main.

I'd recommend closing this one since #2247 is resolved. Thanks again for the contribution! 🙏

@jyaunches jyaunches closed this Apr 23, 2026
@kagura-agent

Copy link
Copy Markdown
Contributor Author

Thanks for the kind words, @jyaunches! Glad the skip-and-continue pattern was useful. I see #2257 also added Discord rotation coverage — nice extension. Happy to contribute again on future test improvements!

@wscurran wscurran added area: e2e End-to-end tests, nightly failures, or validation infrastructure bug-fix PR fixes a bug or regression and removed fix labels Jun 3, 2026
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 bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E2E] test-token-rotation.sh exits hard when install.sh aborts on environmental preflight failure

3 participants