Skip to content

refactor(cli): extract sandbox logs helpers#2965

Merged
cv merged 69 commits intomainfrom
refactor/retry-sandbox-logs-helpers
May 5, 2026
Merged

refactor(cli): extract sandbox logs helpers#2965
cv merged 69 commits intomainfrom
refactor/retry-sandbox-logs-helpers

Conversation

@cv
Copy link
Copy Markdown
Contributor

@cv cv commented May 4, 2026

Summary

Extract pure sandbox log option and argv helpers from the log streaming action module.

Stack Navigation

Changes

  • Added sandbox-logs-helpers.ts for option normalization, timeout parsing, probe descriptions, signal exit codes, and OpenShell argv builders.
  • Updated sandbox-logs-action.ts to import the helper logic and focus on subprocess orchestration.
  • Moved helper tests to target the extracted helper module directly.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

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
  • Docs updated for user-facing behavior changes
  • make docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Carlos Villela [email protected]

Summary by CodeRabbit

  • Refactor

    • Reorganized sandbox logging utilities into a shared helpers module for improved maintainability.
    • Updated the return type for sandbox gateway logging operations.
    • Consolidated log probe result handling and error description logic.
  • Tests

    • Enhanced test coverage for sandbox logging helper functions, including signal-to-exit-code mapping.

cv added 30 commits May 2, 2026 13:36
@cv cv self-assigned this May 4, 2026
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 4, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 45cbcd84-62da-4901-bfa5-07022402a79b

📥 Commits

Reviewing files that changed from the base of the PR and between 6943547 and 940b70d.

📒 Files selected for processing (3)
  • src/lib/sandbox-logs-action.ts
  • src/lib/sandbox-logs-helpers.test.ts
  • src/lib/sandbox-logs-helpers.ts

📝 Walkthrough

Walkthrough

Core sandbox logs utilities are extracted from sandbox-logs-action.ts into a new shared helpers module. The public return type of runOpenclawGatewayLogs changes from SpawnLikeResult to LogProbeResult. Helper functions, constants, and types migrate to the new module; the action file now orchestrates via imports.

Changes

Sandbox Logs Extraction & Refactoring

Layer / File(s) Summary
Types & Constants
src/lib/sandbox-logs-helpers.ts
New module exports LogProbeResult type with status, stdout, stderr, error, and signal fields. Constants DEFAULT_LOGS_PROBE_TIMEOUT_MS and LOGS_PROBE_TIMEOUT_ENV defined.
Utility Functions
src/lib/sandbox-logs-helpers.ts
Functions extracted: getLogsProbeTimeoutMs() (parses timeout from env), describeLogProbeResult() (formats results), exitCodeFromSignal() (maps signals to exit codes), normalizeSandboxLogsOptions() (normalizes boolean/object options), and three CLI argument builders (buildEnableSandboxAuditLogsArgs, buildSandboxOpenclawGatewayLogsArgs, buildSandboxLogsArgs).
Action Wiring & Integration
src/lib/sandbox-logs-action.ts
Imports all helpers from new module; runOpenclawGatewayLogs return type changed to LogProbeResult; signal handling refactored to use exitCodeFromSignal; local helper definitions removed; warnSandboxAuditLogsUnavailable now accepts LogProbeResult.
Tests
src/lib/sandbox-logs-helpers.test.ts
Test suite refactored to import from sandbox-logs-helpers; getLogsProbeTimeoutMs tests updated to accept option objects; new tests for exitCodeFromSignal validate exit code mapping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit refactors with care and delight,
Extracting the helpers to helpers so right!
From action to shared, the logic takes flight—
Cleaner, reusable, and tested just right! ✨

✨ 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 refactor/retry-sandbox-logs-helpers

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

@cv cv added the v0.0.34 Release target label May 4, 2026
@wscurran wscurran added NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. labels May 4, 2026
@cv cv requested a review from cjagwani May 5, 2026 00:27
@cv cv added v0.0.35 Release target and removed v0.0.34 Release target labels May 5, 2026
@prekshivyas prekshivyas self-assigned this May 5, 2026
@cv cv requested a review from prekshivyas May 5, 2026 22:43
cv added a commit that referenced this pull request May 5, 2026
## Summary
Extract pure sandbox destroy decision helpers from the destructive
destroy action module.

## Stack Navigation
- Position: 49 of 60
- Previous PR: [#2963 — refactor(cli): extract upgrade sandbox
helpers](#2963)
- Next PR: [#2965 — refactor(cli): extract sandbox logs
helpers](#2965)

## Changes
- Added `sandbox-destroy-helpers.ts` for delete outcome parsing and
cleanup decision helpers.
- Updated destroy and rebuild actions to import delete outcome parsing
from the helper module.
- Moved/added helper tests for missing-sandbox output, delete outcomes,
host-service cleanup decisions, and gateway cleanup decisions.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <[email protected]>

---------

Signed-off-by: Carlos Villela <[email protected]>
Base automatically changed from refactor/retry-sandbox-destroy-helpers to main May 5, 2026 23:19
@cv cv marked this pull request as ready for review May 5, 2026 23:20
@cv cv enabled auto-merge (squash) May 5, 2026 23:20
Copy link
Copy Markdown
Contributor

@prekshivyas prekshivyas left a comment

Choose a reason for hiding this comment

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

LGTM. Same extraction pattern as #2962/#2963/#2964 — 3 files / +116 / -105.

Six helpers moved verbatim into sandbox-logs-helpers.ts plus one new shared utility, exitCodeFromSignal, that de-duplicates the same signal-to-exit-code logic that was previously inlined in two places (exitWithSpawnResult + the streamSandboxFollowLogs::exitFromSignal lambda). sandbox-logs-action.ts shrinks -86/+15 by importing.

SpawnLikeResultLogProbeResult (internal rename). getLogsProbeTimeoutMs now takes env as a parameter (default process.env) — testability improvement, production unchanged.

Test file renamed (73% similarity, not deleted). Restructure drops vi.mock boilerplate (no longer needed since helpers are pure) and switches the timeout test from vi.stubEnv to explicit env passing — cleaner, no global mutation. +1 new test for exitCodeFromSignal.

CI: pr.yaml mostly green (lint/dco/check-hash/legacy-path-guard/changes PASS); macos-e2e/checks + pr-self-hosted builds still in flight at review time. No failures.

@cv cv merged commit 8704d84 into main May 5, 2026
11 checks passed
@prekshivyas prekshivyas deleted the refactor/retry-sandbox-logs-helpers branch May 5, 2026 23:24
cv added a commit that referenced this pull request May 5, 2026
## Summary
Extract pure policy-add argument parsing helpers from the policy/channel
action module.

## Stack Navigation
- Position: 51 of 60
- Previous PR: [#2965 — refactor(cli): extract sandbox logs
helpers](#2965)
- Next PR: [#2967 — refactor(cli): group oclif core
modules](#2967)

## Changes
- Added `policy-channel-helpers.ts` for custom policy source parsing,
confirmation bypass detection, and policy-add argument normalization.
- Updated `addSandboxPolicy` to use the extracted parser helpers while
keeping filesystem and policy application logic in the action module.
- Added direct helper coverage for `--from-file`, `--from-dir`, mutual
exclusion, missing values, confirmation aliases, and preset argument
parsing.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <[email protected]>

---------

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

Labels

NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. v0.0.35 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants