Skip to content

refactor(cli): replace sandbox_create positional args with SandboxCreateConfig struct#1997

Merged
elezar merged 1 commit into
NVIDIA:mainfrom
lunarwhite:refactor-sandbox-create
Jun 26, 2026
Merged

refactor(cli): replace sandbox_create positional args with SandboxCreateConfig struct#1997
elezar merged 1 commit into
NVIDIA:mainfrom
lunarwhite:refactor-sandbox-create

Conversation

@lunarwhite

@lunarwhite lunarwhite commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the 21-parameter positional signature of run::sandbox_create with a SandboxCreateConfig struct, following the ProviderRefreshConfigInput precedent established in PR #1349. This removes the clippy::too_many_arguments suppression and makes call sites self-documenting via named fields and struct update syntax.

Related Issue

Closes #1408

Notes for reviewers:

The original issue suggested a builder pattern (SandboxCreateBuilder::new(...).name(...).create().await?).
This PR proposes to use a plain config struct with Default instead, for two reasons:

  1. Precedent: ProviderRefreshConfigInput (PR feat(providers): add credential refresh foundation #1349, merged after the issue was filed) established a config-struct convention in the CLI crate, while no builder pattern exists in crates/openshell-cli/.
  2. Fit: sandbox_create is an async side-effecting operation, not an inert value construction. A builder would require ~18 setter methods for the same named-field ergonomics that SandboxCreateConfig { ..Default::default() } provides for free. The struct approach solves the stated problem (positional args, readability, fragility) while
    staying consistent with the codebase.

Changes

  • Introduce SandboxCreateConfig<'a> struct with Default impl (safe production defaults: keep: false, approval_mode: "manual")
  • Refactor sandbox_create() to accept (server, gateway_name, config, tls), keeping infrastructure params positional per existing convention
  • Update the CLI dispatch in main.rs to construct the config struct
  • Add test_config() helper in integration tests with test-appropriate defaults (keep: true, tty_override: Some(false)) and migrate all 14 call sites
  • Net reduction of ~90 lines through struct update syntax

Testing

  • mise run pre-commit passes
  • Unit tests added/updated
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@copy-pr-bot

copy-pr-bot Bot commented Jun 25, 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.

Comment thread crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs
@elezar

elezar commented Jun 25, 2026

Copy link
Copy Markdown
Member

/ok-to-test 83637ad

Comment thread crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs Outdated
elezar
elezar previously approved these changes Jun 25, 2026

@elezar elezar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Are there other places where a similar cleanup (as follow-ups) would make sense?

@lunarwhite

Copy link
Copy Markdown
Contributor Author

Are there other places where a similar cleanup (as follow-ups) would make sense?

Good question @elezar. I just tried to create a spike with help of AI agent: #2003. But its scope looks too broad.

Most remaining items have 8 params (barely above clippy's default threshold of 7) and 1-2 call sites. Only two functions approach #1408's severity:

  • provider_create: 30 call sites, 8 params (sandbox_create has 21 params and 14 test call sites)
  • sandbox_policy_update: 13 params, 2 call sites

IMHO neither individually justifies the same urgency this PR.

Please feel free to modify or close it in favor of your deep review.

…ateConfig struct

Signed-off-by: Yuedong Wu <dwcn22@outlook.com>
@lunarwhite lunarwhite force-pushed the refactor-sandbox-create branch from 83637ad to 507940d Compare June 26, 2026 06:04
@elezar

elezar commented Jun 26, 2026

Copy link
Copy Markdown
Member

/ok-to-test 507940d

@elezar elezar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good now. Thanks!

@elezar elezar enabled auto-merge (squash) June 26, 2026 07:21
@elezar elezar merged commit f2ecadf into NVIDIA:main Jun 26, 2026
29 checks passed
@lunarwhite lunarwhite deleted the refactor-sandbox-create branch June 26, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: refactor sandbox_create to use a builder pattern

2 participants