-
Notifications
You must be signed in to change notification settings - Fork 35
fix(cli): retain type of context values and not convert them to string #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #595 +/- ##
==========================================
+ Coverage 79.01% 79.02% +0.01%
==========================================
Files 46 46
Lines 7085 7091 +6
Branches 791 791
==========================================
+ Hits 5598 5604 +6
Misses 1468 1468
Partials 19 19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
context[parts[0]] = parts[1]; | ||
let parsedValue: any = parts[1]; | ||
try { | ||
parsedValue = JSON.parse(parts[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to myself, we might want to limit this to booleans and numbers
try { | ||
parsedValue = JSON.parse(parts[1]); | ||
} catch { | ||
debug('Non-JSON context value for %s, leaving as string: %s', parts[0], parts[1]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to be more clever here. JSON.parse(parts[1])
will fail if the value is a regular string like test
. This will print debug logs for perfectly fine values:
cdk deploy --context foobar=bar
Discussed with the team and this is a great fix! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too soon. Team is still discussing some open questions. But the general direction is okay.
Fixes #30583
CLI’s context-passing mechanism relied on serialising every entry to a "KEY=VALUE" string, leading CLI to only allows passing string context, so even JSON booleans (true/false) and numbers became plain strings.
This resulted in losing the typed context, like boolean feature-flags are always being passed as string "true"/"false". This incorrectly passed feature flags caused certain integration tests snapshot in the aws-cdk library to be updated with incorrect values causing the integration tests to fail.
This fix retains the type of context values when passed via CLI, by correctly JSON parsing the context while building user configuration. Values that aren’t valid JSON will fall back to plain strings, so existing workflows should continue working as is. This will restore correct typing for feature flags without disrupting existing tests.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license