Skip to content

refactor(e2e): centralize timeout/gtimeout handling into e2e-timeout.sh - #2368

Merged
jyaunches merged 1 commit into
mainfrom
fix/reduce-timeout-boilerplate
Apr 23, 2026
Merged

jyaunches merged 1 commit into
mainfrom
fix/reduce-timeout-boilerplate

Conversation

@brandonpelfrey

@brandonpelfrey brandonpelfrey commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Centralize the duplicated timeout/gtimeout detection, self-wrap, and run_with_timeout() code from 10 E2E test scripts into a single shared helper (test/e2e/e2e-timeout.sh). PR #2162 introduced ~31 identical lines in every script;
this extracts them into one place and replaces each copy with a 4-line source stanza, removing ~210 lines of boilerplate with no behavioral changes.

Related Issue

Follow-up to #2162.

Changes

  • New file test/e2e/e2e-timeout.sh — shared helper containing:
    • timeout / gtimeout binary detection
    • Self-wrap logic (exec $TIMEOUT_CMD -s TERM … "$0" "$@") gated on NEMOCLAW_E2E_TIMEOUT_WRAPPED
    • Fail-fast with exit 127 and remediation guidance when neither binary is found
    • run_with_timeout() per-command helper
  • Updated 10 E2E scripts to source the helper instead of inlining the block:
    • test-deployment-services.sh (default 3600s)
    • test-double-onboard.sh (900s)
    • test-inference-routing.sh (1200s)
    • test-network-policy.sh (3600s)
    • test-onboard-resume.sh (600s)
    • test-sandbox-operations.sh (1800s)
    • test-sandbox-survival.sh (900s)
    • test-shields-config.sh (900s)
    • test-skip-permissions-policy.sh (900s)
    • test-token-rotation.sh (2400s)
  • Each script sets export NEMOCLAW_E2E_DEFAULT_TIMEOUT= before sourcing, preserving per-script defaults
  • All environment knobs unchanged: NEMOCLAW_E2E_NO_TIMEOUT, NEMOCLAW_E2E_TIMEOUT_SECONDS, NEMOCLAW_E2E_TIMEOUT_WRAPPED
  • Used SCRIPT_DIR_TIMEOUT to avoid collisions with existing SCRIPT_DIR variables

Type of Change

  • Code change (feature, bug fix, or refactor)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed

AI Disclosure

  • AI-assisted — tool: Claude Code

────────────────────────────────────────────────────────────────────────────────

Signed-off-by: Brandon Pelfrey [email protected]

Summary by CodeRabbit

  • Refactor
    • Extracted timeout management logic from multiple end-to-end test scripts into a centralized shared utility module. This consolidates platform-specific timeout command detection, configuration handling, and helper utility functions to eliminate code duplication and ensure consistent, reliable timeout behavior across all test suites and environments.

Extract the duplicated timeout detection, self-wrap, and run_with_timeout()
code from 10 E2E test scripts into a single shared helper (e2e-timeout.sh).

Each script now sets NEMOCLAW_E2E_DEFAULT_TIMEOUT and sources the helper,
preserving the per-script default while eliminating ~270 lines of identical
boilerplate introduced in PR #2162.

No behavioral changes — the timeout detection order, self-wrap logic, error
message, and run_with_timeout() semantics are identical to the inlined
versions they replace.
@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request consolidates duplicate timeout handling logic from 10 E2E test scripts into a new shared utility module. Each test script previously contained its own timeout detection, wrapping, and command execution logic. The refactor extracts these common patterns to a centralized e2e-timeout.sh helper, reducing code duplication across the test suite.

Changes

Cohort / File(s) Summary
New Timeout Utility
test/e2e/e2e-timeout.sh
Introduces shared timeout module that detects available timeout binary (timeout or gtimeout), handles script re-execution with timeout wrapping, and exports run_with_timeout function for conditional command execution under timeout constraints.
E2E Test Scripts
test/e2e/test-deployment-services.sh, test/e2e/test-double-onboard.sh, test/e2e/test-inference-routing.sh, test/e2e/test-network-policy.sh, test/e2e/test-onboard-resume.sh, test/e2e/test-sandbox-operations.sh, test/e2e/test-sandbox-survival.sh, test/e2e/test-shields-config.sh, test/e2e/test-skip-permissions-policy.sh, test/e2e/test-token-rotation.sh
Removes duplicate inline timeout detection logic and local run_with_timeout implementations. Each script now sets a default timeout value via NEMOCLAW_E2E_DEFAULT_TIMEOUT and sources the shared e2e-timeout.sh module for timeout handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Ten scripts once duplicated code so long,
Now hopping to one timeout song,
The rabbit bundles logic clean and tight,
Making E2E tests run just right! ✨
No more repetition, one source to keep—
A refactored victory, deep! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main refactoring objective: centralizing duplicated timeout/gtimeout handling from 10 E2E scripts into a new shared helper module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/reduce-timeout-boilerplate

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.

🧹 Nitpick comments (1)
test/e2e/e2e-timeout.sh (1)

35-41: Hardening re-exec against CWD/PATH assumptions — optional but recommended.

Line 41 re-execs "$0" directly. While all scripts are executable (100755) and invoked with bash, explicitly using bash "$0" is more defensive and matches the pattern already present elsewhere in the codebase (e.g., test/e2e/e2e-cloud-experimental/expect-interactive-install.sh).

🔧 Suggested hardening
-    exec "$TIMEOUT_CMD" -s TERM "$TIMEOUT_SECONDS" "$0" "$@"
+    exec "$TIMEOUT_CMD" -s TERM "$TIMEOUT_SECONDS" bash "$0" "$@"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/e2e-timeout.sh` around lines 35 - 41, The re-exec line using "$0"
assumes the caller is directly executable; to harden against CWD/PATH
assumptions, change the exec invocation so it explicitly runs the script via
bash rather than relying on "$0" being executable — update the exec that uses
TIMEOUT_CMD, NEMOCLAW_E2E_TIMEOUT_WRAPPED, TIMEOUT_SECONDS and "$@" to invoke
bash with the script ("$0") as the interpreter (e.g., call bash with the script
path) so the timeout wrapper runs the caller under an explicit shell
interpreter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/e2e/e2e-timeout.sh`:
- Around line 35-41: The re-exec line using "$0" assumes the caller is directly
executable; to harden against CWD/PATH assumptions, change the exec invocation
so it explicitly runs the script via bash rather than relying on "$0" being
executable — update the exec that uses TIMEOUT_CMD,
NEMOCLAW_E2E_TIMEOUT_WRAPPED, TIMEOUT_SECONDS and "$@" to invoke bash with the
script ("$0") as the interpreter (e.g., call bash with the script path) so the
timeout wrapper runs the caller under an explicit shell interpreter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 310583bd-67f3-4009-9565-5ff43a43ca25

📥 Commits

Reviewing files that changed from the base of the PR and between 89a3ebe and 19876b5.

📒 Files selected for processing (11)
  • test/e2e/e2e-timeout.sh
  • test/e2e/test-deployment-services.sh
  • test/e2e/test-double-onboard.sh
  • test/e2e/test-inference-routing.sh
  • test/e2e/test-network-policy.sh
  • test/e2e/test-onboard-resume.sh
  • test/e2e/test-sandbox-operations.sh
  • test/e2e/test-sandbox-survival.sh
  • test/e2e/test-shields-config.sh
  • test/e2e/test-skip-permissions-policy.sh
  • test/e2e/test-token-rotation.sh

@jyaunches
jyaunches self-requested a review April 23, 2026 16:59
@jyaunches
jyaunches merged commit f7f610d into main Apr 23, 2026
22 checks passed
@wscurran wscurran added the refactor PR restructures code without intended behavior change label Jun 8, 2026
@cv
cv deleted the fix/reduce-timeout-boilerplate branch June 28, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants