Skip to content

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

Open
lunarwhite wants to merge 1 commit into
NVIDIA:mainfrom
lunarwhite:refactor-sandbox-create
Open

refactor(cli): replace sandbox_create positional args with SandboxCreateConfig struct#1997
lunarwhite wants to merge 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)

…ateConfig struct

Signed-off-by: Yuedong Wu <dwcn22@outlook.com>
@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

let tls = test_tls(&server);
install_fake_ssh(&fake_ssh_dir);

let cmd = vec!["echo".into(), "OK".into()];

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.

Not that it's too important, but can one specify this inline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't have a preference. Looking at the broader codebase style, not-inline seems to be the more adopted pattern. If you don't have a strong preference on this either, I'll leave it as-is for now. 🙂

@elezar elezar Jun 25, 2026

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.

Actually, looking at this again. I think specifying this inline if possible will be preferred as it aligns better with how all other options are handled.

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.

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