Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented May 2, 2025

If a working directory is given and outdir is relative, then the CDK app synths relative to the supplied working directory, but the toolkit tries to load the assembly relative to the process' cwd and fails.

Also, the documentation of fromCdkApp falsely claimed that by default it will create a temporary directory and clean it up. It does not, by default it emits into a relative cdk.out directory which won't get cleaned up. The cdk.out directory also was not entirely consistently evaluated, so we specify that it must be evaluated against workingDirectory.

While we're at it, immediately add a flag that allows explicit directories to be cleaned up as well so that our tests (which explicitly specify temporary directories and so they don't get cleaned up) don't spam all the way into the system's tempdir.


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

@rix0rrr rix0rrr requested a review from a team May 2, 2025 08:43
@github-actions github-actions bot added the p2 label May 2, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team May 2, 2025 08:45
@rix0rrr rix0rrr changed the title chore(toolkit-lib): fromCdkApp doees not default to temporary directory fix(toolkit-lib): fromCdkApp handling of outdir is inconsistent May 2, 2025
@rix0rrr rix0rrr changed the title fix(toolkit-lib): fromCdkApp handling of outdir is inconsistent fix(toolkit-lib): fromCdkApp fails if working directory is given and outdir is relative May 2, 2025
@codecov-commenter
Copy link

codecov-commenter commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.31%. Comparing base (1d4fd87) to head (dede397).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #444      +/-   ##
==========================================
+ Coverage   79.18%   79.31%   +0.13%     
==========================================
  Files          54       54              
  Lines        6895     6895              
  Branches      772      777       +5     
==========================================
+ Hits         5460     5469       +9     
+ Misses       1417     1408       -9     
  Partials       18       18              
Flag Coverage Δ
suite.unit 79.31% <ø> (+0.13%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

// THEN - synth succeeds
expect(assembly.cloudAssembly.stacksRecursively.map(s => s.hierarchicalId)).toEqual(['Stack1', 'Stack2']);
} finally {
await fs.rm(path.join(app.workingDirectory, 'relative.dir'), { force: true, recursive: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be automatic with deleteOutdir, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

*
* @default - `true` if `outdir` is not given, `false` otherwise
*/
readonly deleteOutdir?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

…outdir is relative

The documentation of `fromCdkApp` falsely claimed that it would create a
temporary directory and clean it up. It does not, it emits into
`cdk.out` which won't get cleaned up.

Update the docs.
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue May 5, 2025
Merged via the queue into main with commit d570e65 May 5, 2025
30 of 32 checks passed
@aws-cdk-automation aws-cdk-automation deleted the huijbers/docs branch May 5, 2025 12:34
github-merge-queue bot pushed a commit that referenced this pull request May 6, 2025
Add integration tests for the toolkit library.

Introduces the toolkit library as a new "component under test". 

Because we want to promote writing integ tests against the toolkit
library the same way we would write normal production code, the setup is
like this:

- The toolkit lib is installed as a `devDependency` into the integ test
package. This will allow writing tests as if the toolkit lib is "just" a
dependency.
- At runtime, a version of the toolkit library can be selected and it
will be installed into the dependency closure by the runner before the
tests are run, so that the imports will still function properly.

To signal this, we'll mark `@aws-cdk/toolkit-lib` as an
`optionalDependency` as well.

(PR includes #444)

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

Signed-off-by: github-actions <github-actions@github.com>
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.

4 participants