Skip to content

refactor: use oclif variadic args instead of strict=false#782

Draft
rexxars wants to merge 4 commits intomainfrom
rexxars/oclif-varargs
Draft

refactor: use oclif variadic args instead of strict=false#782
rexxars wants to merge 4 commits intomainfrom
rexxars/oclif-varargs

Conversation

@rexxars
Copy link
Copy Markdown
Member

@rexxars rexxars commented Mar 24, 2026

Summary

We could wait and see if oclif/core#1568 lands which will improve this further by automatically narrowing arg types.

  • Replaces strict = false + manual argv parsing with oclif's native multiple: true on Args.string() in doctor, documents delete, and install commands
  • Uses oclif's built-in validation for the doctor command's check names via options: [...] instead of manual validation
  • exec remains strict = false since it's a genuine passthrough case
  • Lockfile updated from oclif dep bumps that landed on main

Test plan

  • Existing tests updated and passing
  • doctor command validates check names via oclif's options (error message changed from custom to oclif's Expected X to be one of...)
  • Manual: sanity doctor cli studio, sanity documents delete id1 id2, sanity install pkg1 pkg2

🤖 Generated with Claude Code

Replace `strict = false` + manual argv parsing with `multiple: true` on
Args.string() in doctor, documents delete, and install commands. This
uses oclif's built-in variadic argument support (added in @oclif/core
4.10.0) for proper parsing, validation, and help output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude Bot commented Mar 24, 2026

Claude finished @rexxars's task in 1m 4s —— View job


Review

  • Read changed files
  • Analyze diff
  • Post review

doctor.ts line 147 — The comment references https://github.com/oclif/core/issues/1234 which is a placeholder issue number and not a real link. Remove or replace with an accurate reference.

doctor.ts line 148 — The as DoctorCheckName[] cast bypasses TypeScript's type narrowing. Since oclif validates the values against options: [...KNOWN_CHECKS] at runtime, the cast is safe, but it's fragile: if someone adds a new check to doctorChecks without updating KNOWN_CHECKS, or vice versa, the cast silently breaks. Consider instead: checkNames.map((name) => doctorChecks[name as DoctorCheckName]).filter(Boolean) or keep the cast but drop the comment referencing a fake issue.

Coverage drop in doctor.ts (-7.2%) — The getChecks function's happy path (running with a valid specific check like cli) has no test coverage. The existing tests only cover the no-args case and the invalid-arg rejection case. Add a test like:

test('runs only specified check when check name is provided', async () => {
  const {error, stdout} = await testCommand(DoctorCommand, ['cli'])
  expect(error).toBeUndefined()
  expect(stdout).toContain('CLI Installation')
})

delete.ts line 84notFound detection relies on results containing entries with operation === 'delete' matching by id. This logic existed before this PR so not introduced here, but worth noting it's unchanged.

No issues with install.ts or the test changes.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 24, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/commands/doctor.ts 88.9% (- 7.2%)
packages/@sanity/cli/src/commands/documents/delete.ts 100.0% (+ 2.7%)
packages/@sanity/cli/src/commands/install.ts 100.0% (±0%)

Comparing 3 changed files against main @ 56f2c0ad9debf4324b7f736ba2f19a2421f4eb7a

Overall Coverage

Metric Coverage
Statements 83.0% (- 0.0%)
Branches 72.7% (±0%)
Functions 83.1% (- 0.1%)
Lines 83.4% (- 0.0%)

rexxars and others added 2 commits March 24, 2026 12:28
The simulateOAuthCallback helper used a single 100ms delay before
connecting to the local auth server. On Windows CI, the server may not
be listening yet, causing ECONNREFUSED. Add retry logic with backoff
and use 127.0.0.1 directly to avoid IPv6 resolution delays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 30, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (c37431d6) · v6.2.1 (npm)

@sanity/cli

Metric Value vs main (c37431d) vs v6.2.1
Internal (raw) 2.1 KB - -
Internal (gzip) 799 B - -
Bundled (raw) 11.06 MB - +9.12 MB, +470.6%
Bundled (gzip) 2.07 MB - +1.60 MB, +335.8%
Import time 852ms +2ms, +0.2% +41ms, +5.1%

bin:sanity

Metric Value vs main (c37431d) vs v6.2.1
Internal (raw) 975 B - -
Internal (gzip) 460 B - -
Bundled (raw) 9.83 MB - +9.12 MB, +1286.7%
Bundled (gzip) 1.77 MB - +1.60 MB, +940.0%
Import time NaNs - NaNs, NaN%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (c37431d6) · v1.2.1 (npm)

Metric Value vs main (c37431d) vs v1.2.1
Internal (raw) 92.2 KB - +3.9 KB, +4.4%
Internal (gzip) 21.6 KB - +1.1 KB, +5.5%
Bundled (raw) 21.72 MB - +9.16 MB, +72.9%
Bundled (gzip) 3.45 MB - +1.61 MB, +87.2%
Import time 798ms +3ms, +0.3% +46ms, +6.1%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli/src/commands/doctor.ts 88.9% (- 7.2%)
packages/@sanity/cli/src/commands/documents/delete.ts 100.0% (+ 2.7%)
packages/@sanity/cli/src/commands/install.ts 100.0% (±0%)

Comparing 3 changed files against main @ c37431d667a9edccd74f2435021eed7ea0e0388f

Overall Coverage

Metric Coverage
Statements 83.0% (- 0.0%)
Branches 72.9% (±0%)
Functions 83.2% (- 0.1%)
Lines 83.5% (- 0.0%)

oclif validates args against `options` before run(), so the filter
could never reject anything. Cast directly instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (c37431d6)

@sanity/cli

Metric Value vs main (c37431d)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.95 MB -120.3 KB, -1.1%
Bundled (gzip) 2.06 MB -20.4 KB, -1.0%
Import time 823ms -21ms, -2.5%

bin:sanity

Metric Value vs main (c37431d)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 1.95s -5ms, -0.2%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (c37431d6)

Metric Value vs main (c37431d)
Internal (raw) 92.3 KB +96 B, +0.1%
Internal (gzip) 21.6 KB +18 B, +0.1%
Bundled (raw) 21.53 MB -118.6 KB, -0.5%
Bundled (gzip) 3.41 MB -20.5 KB, -0.6%
Import time 784ms +0ms, +0.1%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (c37431d6)

Metric Value vs main (c37431d)
Internal (raw) 976 B -
Internal (gzip) 507 B -
Bundled (raw) 50.7 KB -
Bundled (gzip) 12.6 KB -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/commands/doctor.ts 93.0% (- 3.0%)
packages/@sanity/cli/src/commands/documents/delete.ts 100.0% (+ 2.7%)
packages/@sanity/cli/src/commands/install.ts 100.0% (±0%)

Comparing 3 changed files against main @ ef5ed4565d33b83d67cd66c6b3c335516e5b1132

Overall Coverage

Metric Coverage
Statements 83.1% (- 0.0%)
Branches 72.9% (±0%)
Functions 83.3% (- 0.0%)
Lines 83.5% (- 0.0%)

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.

1 participant