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.

/// tests expect persistent sandboxes) while `SandboxCreateConfig::default()`
/// sets `keep: false` (the safe production default). Tests that exercise
/// ephemeral behavior must explicitly override with `keep: false`.
fn test_config() -> run::SandboxCreateConfig<'static> {

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.

Should this be marked test-only?

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.

Thanks for reviewing this PR! The file is under tests/ subfolder, which is a separate crate that won't be compiled into the binary. So I assume it's not required.

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

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