Skip to content

fix(cli): cdk context header always claims the context was found in cdk.json - #1816

Open
go-to-k wants to merge 1 commit into
aws:mainfrom
go-to-k:fix-context-header
Open

fix(cli): cdk context header always claims the context was found in cdk.json#1816
go-to-k wants to merge 1 commit into
aws:mainfrom
go-to-k:fix-context-header

Conversation

@go-to-k

@go-to-k go-to-k commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1814

Problem

cdk context lists the merged context from cdk.json, cdk.context.json and ~/.cdk.json, but the listing header is hardcoded to Context found in cdk.json: (PROJECT_CONFIG). When cdk.json has no context key and all values come from cdk.context.json, the header points the user at the wrong file.

Fix

  • Configuration (which builds the context from its sources) now exposes contextSourceFiles: the names of the context files that currently contain at least one value, in lookup precedence order.
  • The context command renders the header from that list, e.g. Context found in cdk.context.json: or Context found in cdk.json, cdk.context.json:. When no file source is known (e.g. context passed only on the command line), it falls back to a generic Context found: header.

The change is contained in the aws-cdk package; the Context class in toolkit-lib (not part of its public API) is unchanged.

Testing

  • New unit tests in test/cli/user-config.test.ts: contextSourceFiles lists all of cdk.json / cdk.context.json / ~/.cdk.json when each contains context, and omits files without context values (e.g. a cdk.json that has settings but no context key).
  • New unit tests in test/commands/context-command.test.ts: the listing header names the provided source files, and falls back to the generic header when the sources are unknown.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@go-to-k
go-to-k deployed to automation August 11, 2026 11:50 — with GitHub Actions Active
@go-to-k
go-to-k deployed to automation August 11, 2026 11:50 — with GitHub Actions Active
@github-actions github-actions Bot added the p2 label Aug 11, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 11, 2026 11:50
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.31%. Comparing base (785506e) to head (2b194dd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1816      +/-   ##
==========================================
- Coverage   90.32%   90.31%   -0.02%     
==========================================
  Files          80       80              
  Lines       12124    12149      +25     
  Branches     1716     1723       +7     
==========================================
+ Hits        10951    10972      +21     
- Misses       1139     1143       +4     
  Partials       34       34              
Flag Coverage Δ
suite.unit 90.31% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(context): listing header always says "Context found in cdk.json:" regardless of where the context is

2 participants