Skip to content

fix(sdk): apply Stricli flag defaults in SDK invoke path#1027

Merged
BYK merged 1 commit into
mainfrom
fix/sdk-invoke-flag-defaults
May 27, 2026
Merged

fix(sdk): apply Stricli flag defaults in SDK invoke path#1027
BYK merged 1 commit into
mainfrom
fix/sdk-invoke-flag-defaults

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented May 27, 2026

Problem

CLI-1W1 (3 events) and CLI-1W0 (1 event) crash at serializeTimeRange(flags.period) because flags.period is undefined.

Both issues affect users calling the CLI programmatically via createSentrySDK() (the typed SDK).

Root Cause

The typed SDK's invoke path (src/lib/sdk-invoke.ts) calls command handlers directly, bypassing Stricli's buildArgumentScanner. This means parsed flags with defaults (e.g., period: { kind: 'parsed', default: '7d', parse: parsePeriod }) never have their parse function called on the default string when the SDK caller omits them.

The generated SDK methods (sdk.generated.ts) pass period: params?.period, which evaluates to undefined when omitted. All 14+ commands with a period flag are affected.

Fix

Adds applyFlagDefaults() to the SDK invoke layer, which replicates Stricli's default application logic:

  • kind: "parsed" flags with a string default → calls flag.parse(flag.default) (same as Stricli's parseInput)
  • Boolean/enum/counter flags → uses the raw default value
  • Strips undefined values from caller-provided flags so they don't shadow defaults
  • Skips flags already set by the caller

resolveCommand() now returns both the handler function and the command's flag definitions, so buildInvoker can apply defaults before calling the command func.

This is a systemic fix — protects all flags across all SDK-invoked commands, not just period.

Testing

  • 11 new unit tests for applyFlagDefaults() covering: parsed flags with defaults, boolean defaults, enum defaults, optional flags without defaults, undefined stripping, caller value preservation, parse failure handling, and combined scenarios.

Fixes CLI-1W1, CLI-1W0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1027/

Built to branch gh-pages at 2026-05-27 09:21 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@BYK BYK force-pushed the fix/sdk-invoke-flag-defaults branch from f916773 to 083968b Compare May 27, 2026 09:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

Codecov Results 📊

✅ Patch coverage is 90.32%. Project has 4286 uncovered lines.
✅ Project coverage is 81.97%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/lib/sdk-invoke.ts 90.32% ⚠️ 3 Missing and 3 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.95%    81.97%    +0.02%
==========================================
  Files          329       329         —
  Lines        23749     23773       +24
  Branches     15502     15521       +19
==========================================
+ Hits         19463     19487       +24
- Misses        4286      4286         —
- Partials      1643      1644        +1

Generated by Codecov Action

Comment thread src/lib/sdk-invoke.ts
The typed SDK (createSentrySDK()) calls command handlers directly,
bypassing Stricli's buildArgumentScanner. This means parsed flags
with defaults (e.g., period: { kind: 'parsed', default: '7d',
parse: parsePeriod }) never have their parse function called on the
default string when the SDK caller omits them.

This caused CLI-1W1 and CLI-1W0: serializeTimeRange() received
undefined instead of a TimeRange object because flags.period was
never parsed from its '7d'/'90d' default.

The fix adds applyFlagDefaults() which replicates Stricli's default
application logic:
- For kind:'parsed' flags with string defaults, calls flag.parse()
- For boolean/enum/counter flags, uses the raw default value
- Strips undefined values from caller-provided flags

resolveCommand() now also returns the command's flag definitions
alongside the handler, so buildInvoker can apply defaults before
calling the command func.

Fixes CLI-1W1, CLI-1W0
@BYK BYK force-pushed the fix/sdk-invoke-flag-defaults branch from 083968b to 590ff7f Compare May 27, 2026 09:20
Copy link
Copy Markdown
Member Author

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Addressed warden's finding: resolveFlagDefault now re-throws if flag.parse(flag.default) fails instead of silently returning undefined. A parse function that rejects its own default string is a command definition bug that should surface immediately, not be silently absorbed.

Updated the test to verify the error propagates (expect(() => applyFlagDefaults({}, flagDefs)).toThrow("parse error")).

@BYK BYK merged commit d7440ff into main May 27, 2026
28 checks passed
@BYK BYK deleted the fix/sdk-invoke-flag-defaults branch May 27, 2026 09:28
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