|
| 1 | +/** |
| 2 | + * MIT No Attribution |
| 3 | + * |
| 4 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 7 | + * the Software without restriction, including without limitation the rights to |
| 8 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 9 | + * the Software, and to permit persons to whom the Software is furnished to do so. |
| 10 | + * |
| 11 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 12 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 14 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 15 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 16 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 17 | + * SOFTWARE. |
| 18 | + */ |
| 19 | + |
| 20 | +// Disable Lambda asset bundling during unit-test synthesis. |
| 21 | +// |
| 22 | +// `Template.fromStack()` triggers a full CDK synth, which bundles every |
| 23 | +// NodejsFunction via esbuild — ~28s for the AgentStack (413 resources). Unit |
| 24 | +// tests assert on CloudFormation structure/properties, not bundled Lambda code, |
| 25 | +// so bundling is pure overhead here: skipping it cuts a single synth ~15× |
| 26 | +// (~28.7s -> ~1.9s). See #366 and docs/design/CI_BUILD_PERFORMANCE.md. |
| 27 | +// |
| 28 | +// `aws:cdk:bundling-stacks: []` tells the CLI/synth to bundle no stacks. CDK |
| 29 | +// reads CDK_CONTEXT_JSON when an `App` is constructed, so a bare `new App()` |
| 30 | +// (the overwhelming-majority pattern in our tests) picks this up with no |
| 31 | +// call-site changes. Tests that pass their own `{ context }` still merge on top. |
| 32 | +// |
| 33 | +// If a test ever needs real bundled assets (e.g. asserting on an asset hash / |
| 34 | +// S3 key), it must opt out by constructing its `App` with |
| 35 | +// `aws:cdk:bundling-stacks: ['**']` (or the specific stack id) in its context. |
| 36 | +const BUNDLING_DISABLED_CONTEXT = { 'aws:cdk:bundling-stacks': [] as string[] }; |
| 37 | + |
| 38 | +const existing = process.env.CDK_CONTEXT_JSON; |
| 39 | +if (existing) { |
| 40 | + // Preserve any context already provided; our key wins only if unset. |
| 41 | + const merged = { ...BUNDLING_DISABLED_CONTEXT, ...JSON.parse(existing) }; |
| 42 | + process.env.CDK_CONTEXT_JSON = JSON.stringify(merged); |
| 43 | +} else { |
| 44 | + process.env.CDK_CONTEXT_JSON = JSON.stringify(BUNDLING_DISABLED_CONTEXT); |
| 45 | +} |
0 commit comments