fix(sdk): apply Stricli flag defaults in SDK invoke path#1027
Merged
Conversation
Contributor
|
f916773 to
083968b
Compare
Contributor
Codecov Results 📊✅ Patch coverage is 90.32%. Project has 4286 uncovered lines. Files with missing lines (1)
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 +1Generated by Codecov Action |
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
083968b to
590ff7f
Compare
BYK
commented
May 27, 2026
Member
Author
BYK
left a comment
There was a problem hiding this comment.
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")).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CLI-1W1 (3 events) and CLI-1W0 (1 event) crash at
serializeTimeRange(flags.period)becauseflags.periodisundefined.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'sbuildArgumentScanner. This means parsed flags with defaults (e.g.,period: { kind: 'parsed', default: '7d', parse: parsePeriod }) never have theirparsefunction called on the default string when the SDK caller omits them.The generated SDK methods (
sdk.generated.ts) passperiod: params?.period, which evaluates toundefinedwhen omitted. All 14+ commands with aperiodflag are affected.Fix
Adds
applyFlagDefaults()to the SDK invoke layer, which replicates Stricli's default application logic:kind: "parsed"flags with a stringdefault→ callsflag.parse(flag.default)(same as Stricli'sparseInput)undefinedvalues from caller-provided flags so they don't shadow defaultsresolveCommand()now returns both the handler function and the command's flag definitions, sobuildInvokercan apply defaults before calling the command func.This is a systemic fix — protects all flags across all SDK-invoked commands, not just
period.Testing
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