Skip to content

Commit 77b0c7a

Browse files
test(cdk): cover the postCliContext bundling opt-out precedence (#366)
PR #371 review finding 2: the documented per-test opt-out (`postCliContext`) and the `loadContext` precedence this PR corrected had zero test coverage, so a future CDK version reordering context application could silently break the one supported escape hatch. Locks the contract with two assertions verified against aws-cdk-lib@2.259.0: `postCliContext: { 'aws:cdk:bundling-stacks': ['**'] }` re-enables bundling (`bundlingRequired === true`), while constructor `context` does NOT (the env var set by the global disable clobbers it). Uses a bare `Stack` rather than a heavy AgentStack since the precedence is a property of CDK context loading, not of any particular stack. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 09b1f24 commit 77b0c7a

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

cdk/test/setup/disable-bundling.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,28 @@ describe('global Lambda bundling disable', () => {
4141
expect(stack.bundlingRequired).toBe(false);
4242
});
4343
});
44+
45+
describe('per-test bundling opt-out (#366)', () => {
46+
// The documented escape hatch for a test that needs real bundled-asset output
47+
// is `postCliContext`, NOT constructor `context`. CDK's
48+
// `App.loadContext(props.context, props.postCliContext)` applies
49+
// `props.context` first, overwrites it with CDK_CONTEXT_JSON (which the global
50+
// disable sets), then applies `postCliContext` last — so only the latter wins.
51+
// These lock that precedence contract against a future CDK reordering; without
52+
// them the one supported opt-out path is unguarded.
53+
it('re-enables bundling via postCliContext (the documented opt-out)', () => {
54+
const app = new App({ postCliContext: { 'aws:cdk:bundling-stacks': ['**'] } });
55+
const stack = new Stack(app, 'OptOutProbe', {
56+
env: { account: '123456789012', region: 'us-east-1' },
57+
});
58+
expect(stack.bundlingRequired).toBe(true);
59+
});
60+
61+
it('does NOT re-enable bundling via constructor context (env var clobbers it)', () => {
62+
const app = new App({ context: { 'aws:cdk:bundling-stacks': ['**'] } });
63+
const stack = new Stack(app, 'ContextOptOutProbe', {
64+
env: { account: '123456789012', region: 'us-east-1' },
65+
});
66+
expect(stack.bundlingRequired).toBe(false);
67+
});
68+
});

0 commit comments

Comments
 (0)