diff --git a/.projenrc.ts b/.projenrc.ts index 9128b9dfd..fd8eda64e 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -781,6 +781,8 @@ const toolkitLib = configureProject( ], devDeps: [ '@aws-cdk/aws-service-spec', + '@jest/globals', + '@microsoft/api-extractor', '@smithy/types', '@types/fs-extra', '@types/split2', @@ -790,8 +792,9 @@ const toolkitLib = configureProject( 'dts-bundle-generator@9.3.1', // use this specific version because newer versions are much slower. This is a temporary arrangement we hope to remove soon anyway. 'esbuild', 'fast-check', + 'nock', 'typedoc', - '@microsoft/api-extractor', + 'xml-js', ], // Watch 2 directories at once releasableCommits: transitiveToolkitPackages('@aws-cdk/toolkit-lib'), @@ -806,10 +809,10 @@ const toolkitLib = configureProject( jestConfig: { coverageThreshold: { // this is very sad but we will get better - statements: 60, - branches: 70, - functions: 55, - lines: 60, + statements: 87, + branches: 83, + functions: 82, + lines: 87, }, testEnvironment: './test/_helpers/jest-bufferedconsole.ts', setupFilesAfterEnv: ['/test/_helpers/jest-setup-after-env.ts'], @@ -896,6 +899,7 @@ toolkitLib.eslint?.addOverride({ files: ['./test/**'], rules: { '@cdklabs/no-throw-default-error': 'off', + '@typescript-eslint/unbound-method': 'off', }, }); @@ -1122,10 +1126,10 @@ const cli = configureProject( // We want to improve our test coverage // DO NOT LOWER THESE VALUES! // If you need to break glass, open an issue to re-up the values with additional test coverage - statements: 82, - branches: 74, + statements: 81, + branches: 76, functions: 87, - lines: 82, + lines: 81, }, // We have many tests here that commonly time out testTimeout: 60_000, diff --git a/packages/@aws-cdk/toolkit-lib/.eslintrc.json b/packages/@aws-cdk/toolkit-lib/.eslintrc.json index 67d425f8e..bbf2ccad5 100644 --- a/packages/@aws-cdk/toolkit-lib/.eslintrc.json +++ b/packages/@aws-cdk/toolkit-lib/.eslintrc.json @@ -320,7 +320,8 @@ "./test/**" ], "rules": { - "@cdklabs/no-throw-default-error": "off" + "@cdklabs/no-throw-default-error": "off", + "@typescript-eslint/unbound-method": "off" } } ] diff --git a/packages/@aws-cdk/toolkit-lib/.projen/deps.json b/packages/@aws-cdk/toolkit-lib/.projen/deps.json index 961b3cf8b..fa1676f1b 100644 --- a/packages/@aws-cdk/toolkit-lib/.projen/deps.json +++ b/packages/@aws-cdk/toolkit-lib/.projen/deps.json @@ -8,6 +8,10 @@ "name": "@cdklabs/eslint-plugin", "type": "build" }, + { + "name": "@jest/globals", + "type": "build" + }, { "name": "@microsoft/api-extractor", "type": "build" @@ -125,6 +129,10 @@ "name": "license-checker", "type": "build" }, + { + "name": "nock", + "type": "build" + }, { "name": "prettier", "version": "^2.8", @@ -143,6 +151,10 @@ "version": "5.6", "type": "build" }, + { + "name": "xml-js", + "type": "build" + }, { "name": "@aws-cdk/cloud-assembly-schema", "type": "runtime" diff --git a/packages/@aws-cdk/toolkit-lib/.projen/tasks.json b/packages/@aws-cdk/toolkit-lib/.projen/tasks.json index 794a8e9e7..869efc49a 100644 --- a/packages/@aws-cdk/toolkit-lib/.projen/tasks.json +++ b/packages/@aws-cdk/toolkit-lib/.projen/tasks.json @@ -59,7 +59,7 @@ }, "steps": [ { - "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --no-deprecated --dep=dev,peer,prod,optional --filter=@aws-cdk/aws-service-spec,@cdklabs/eslint-plugin,@microsoft/api-extractor,@smithy/types,@types/fs-extra,@types/jest,@types/split2,aws-cdk-lib,aws-sdk-client-mock,aws-sdk-client-mock-jest,esbuild,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-jest,eslint-plugin-jsdoc,eslint-plugin-prettier,fast-check,jest,license-checker,ts-jest,typedoc,@aws-cdk/cx-api,@aws-cdk/region-info,@smithy/middleware-endpoint,@smithy/node-http-handler,@smithy/property-provider,@smithy/shared-ini-file-loader,@smithy/util-retry,@smithy/util-stream,@smithy/util-waiter,archiver,cdk-from-cfn,glob,json-diff,minimatch,promptly,proxy-agent,semver,split2,uuid" + "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --no-deprecated --dep=dev,peer,prod,optional --filter=@aws-cdk/aws-service-spec,@cdklabs/eslint-plugin,@jest/globals,@microsoft/api-extractor,@smithy/types,@types/fs-extra,@types/jest,@types/split2,aws-cdk-lib,aws-sdk-client-mock,aws-sdk-client-mock-jest,esbuild,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-jest,eslint-plugin-jsdoc,eslint-plugin-prettier,fast-check,jest,license-checker,nock,ts-jest,typedoc,xml-js,@aws-cdk/cx-api,@aws-cdk/region-info,@smithy/middleware-endpoint,@smithy/node-http-handler,@smithy/property-provider,@smithy/shared-ini-file-loader,@smithy/util-retry,@smithy/util-stream,@smithy/util-waiter,archiver,cdk-from-cfn,glob,json-diff,minimatch,promptly,proxy-agent,semver,split2,uuid" } ] }, diff --git a/packages/@aws-cdk/toolkit-lib/jest.config.json b/packages/@aws-cdk/toolkit-lib/jest.config.json index cadf73a4e..97f0fd4eb 100644 --- a/packages/@aws-cdk/toolkit-lib/jest.config.json +++ b/packages/@aws-cdk/toolkit-lib/jest.config.json @@ -8,10 +8,10 @@ "testEnvironment": "./test/_helpers/jest-bufferedconsole.ts", "coverageThreshold": { "global": { - "statements": 60, - "branches": 70, - "functions": 55, - "lines": 60 + "statements": 87, + "branches": 83, + "functions": 82, + "lines": 87 } }, "collectCoverage": true, diff --git a/packages/@aws-cdk/toolkit-lib/package.json b/packages/@aws-cdk/toolkit-lib/package.json index d1fea484e..5f0c8d2d1 100644 --- a/packages/@aws-cdk/toolkit-lib/package.json +++ b/packages/@aws-cdk/toolkit-lib/package.json @@ -37,6 +37,7 @@ "devDependencies": { "@aws-cdk/aws-service-spec": "^0.1.69", "@cdklabs/eslint-plugin": "^1.3.2", + "@jest/globals": "^29.7.0", "@microsoft/api-extractor": "^7.52.4", "@smithy/types": "^4.2.0", "@stylistic/eslint-plugin": "^3", @@ -64,10 +65,12 @@ "jest": "^29.7.0", "jest-junit": "^16", "license-checker": "^25.0.1", + "nock": "^14.0.4", "prettier": "^2.8", "ts-jest": "^29.3.2", "typedoc": "^0.28.3", - "typescript": "5.6" + "typescript": "5.6", + "xml-js": "^1.6.11" }, "dependencies": { "@aws-cdk/cloud-assembly-schema": "^0.0.0", diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-1_144_0/tree.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-1_144_0/tree.json new file mode 100644 index 000000000..a7b0c9e29 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-1_144_0/tree.json @@ -0,0 +1,21 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "@aws-cdk/core.Construct", + "version": "1.144.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "1.144.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-2_12_0/tree.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-2_12_0/tree.json new file mode 100644 index 000000000..41c11ceaf --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/built-with-2_12_0/tree.json @@ -0,0 +1,21 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.0.64" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "2.12.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json new file mode 100644 index 000000000..ecf655077 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json @@ -0,0 +1,40 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "integ-idp": { + "id": "integ-idp", + "path": "integ-idp", + "children": { + "identitypool": { + "id": "identitypool", + "path": "integ-idp/identitypool", + "constructInfo": { + "fqn": "@aws-cdk/aws-cognito-identitypool-alpha.IdentityPool", + "version": "2.175.0-alpha.0", + "metadata": ["*", "*"] + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module/tree.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module/tree.json new file mode 100644 index 000000000..bb2fa029b --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/cloud-assembly-trees/experimental-module/tree.json @@ -0,0 +1,110 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.0.66" + } + }, + "SimulationStack": { + "id": "SimulationStack", + "path": "SimulationStack", + "children": { + "HttpApi": { + "id": "HttpApi", + "path": "SimulationStack/HttpApi", + "children": { + "Resource": { + "id": "Resource", + "path": "SimulationStack/HttpApi/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Api", + "aws:cdk:cloudformation:props": { + "name": "HttpApi", + "protocolType": "HTTP" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnApi", + "version": "2.8.0" + } + }, + "DefaultStage": { + "id": "DefaultStage", + "path": "SimulationStack/HttpApi/DefaultStage", + "children": { + "Resource": { + "id": "Resource", + "path": "SimulationStack/HttpApi/DefaultStage/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Stage", + "aws:cdk:cloudformation:props": { + "apiId": { + "Ref": "HttpApiF5A9A8A7" + }, + "stageName": "$default", + "autoDeploy": true + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_apigatewayv2.CfnStage", + "version": "2.8.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-apigatewayv2-alpha.HttpStage", + "version": "2.13.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-apigatewayv2-alpha.HttpApi", + "version": "2.13.0-alpha.0" + } + }, + "CDKMetadata": { + "id": "CDKMetadata", + "path": "SimulationStack/CDKMetadata", + "children": { + "Default": { + "id": "Default", + "path": "SimulationStack/CDKMetadata/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "2.8.0" + } + }, + "Condition": { + "id": "Condition", + "path": "SimulationStack/CDKMetadata/Condition", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnCondition", + "version": "2.8.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.0.66" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.8.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "2.8.0" + } + } + } \ No newline at end of file diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json new file mode 100644 index 000000000..ad860ee1e --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json @@ -0,0 +1,52 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "referencetoChildS3BucketParam" + }, + "S3Key": { + "Ref": "referencetoChildS3KeyParam" + } + }, + "FunctionName": "my-function" + }, + "Metadata": { + "aws:asset:path": "old-path" + } + }, + "GrandChildStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.magic-url.com", + "Parameters": { + "referencetoS3BucketParam": { + "Ref": "referencetoGrandChildS3BucketParam" + }, + "referencetoS3KeyParam": { + "Ref": "referencetoGrandChildS3KeyParam" + } + } + }, + "Metadata": { + "aws:asset:path": "one-lambda-stack-with-asset-parameters.nested.template.json" + } + } + }, + "Parameters": { + "referencetoGrandChildS3BucketParam": { + "Type": "String" + }, + "referencetoGrandChildS3KeyParam": { + "Type": "String" + }, + "referencetoChildS3BucketParam": { + "Type": "String" + }, + "referencetoChildS3KeyParam": { + "Type": "String" + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json new file mode 100644 index 000000000..96515f63a --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json @@ -0,0 +1,26 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "new-bucket", + "S3Key": "current-key" + }, + "FunctionName": "child-function" + }, + "Metadata": { + "aws:asset:path": "old-path" + } + }, + "GrandChildStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.magic-url.com" + }, + "Metadata": { + "aws:asset:path": "one-lambda-stack.nested.template.json" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json new file mode 100644 index 000000000..a8897fe42 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json @@ -0,0 +1,29 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "referencetoS3BucketParam" + }, + "S3Key": { + "Ref": "referencetoS3KeyParam" + } + }, + "FunctionName": "my-function" + }, + "Metadata": { + "aws:asset:path": "old-path" + } + } + }, + "Parameters": { + "referencetoS3BucketParam": { + "Type": "String" + }, + "referencetoS3KeyParam": { + "Type": "String" + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json new file mode 100644 index 000000000..68f18403a --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json @@ -0,0 +1,30 @@ +{ + "Type": "AWS::CloudFormation::Stack", + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "referenceToS3BucketParam" + }, + "S3Key": { + "Ref": "referenceToS3StackKeyOutput" + } + }, + "FunctionName": "my-function" + }, + "Metadata": { + "aws:asset:path": "old-path" + } + } + }, + "Parameters": { + "referenceToS3BucketParam": { + "Type": "String" + }, + "referenceToS3StackKeyOutput": { + "Type": "String" + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack.nested.template.json new file mode 100644 index 000000000..5556df6eb --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-stack.nested.template.json @@ -0,0 +1,17 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "current-bucket", + "S3Key": "new-key" + }, + "FunctionName": "my-function" + }, + "Metadata": { + "aws:asset:path": "old-path" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-version-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-version-stack.nested.template.json new file mode 100644 index 000000000..f2e75a32f --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-lambda-version-stack.nested.template.json @@ -0,0 +1,20 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "current-bucket", + "S3Key": "new-key" + }, + "FunctionName": "my-function" + } + }, + "Version": { + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { "Ref": "Func" } + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-one-param-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-one-param-stack.nested.template.json new file mode 100644 index 000000000..a86df6dfe --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-one-param-stack.nested.template.json @@ -0,0 +1,20 @@ +{ + "Resources": { + "NestedResource": { + "Type": "AWS::Something", + "Properties": { + "Property": "new-value" + } + } + }, + "Parameters": { + "NestedParam": { + "Type": "Number" + } + }, + "Outputs": { + "NestedOutput": { + "Value": { "Ref": "NestedResource" } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-stack.nested.template.json new file mode 100644 index 000000000..345987597 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-output-stack.nested.template.json @@ -0,0 +1,5 @@ +{ + "Outputs": { + "NestedOutput": { "Value": "s3-key-value-from-output" } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-one-stack-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-one-stack-stack.nested.template.json new file mode 100644 index 000000000..34317afa7 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-one-stack-stack.nested.template.json @@ -0,0 +1,19 @@ +{ + "Resources": { + "SomeResource": { + "Type": "AWS::Something", + "Properties": { + "Property": "new-value" + } + }, + "NestedStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.magic-url.com" + }, + "Metadata": { + "aws:asset:path": "one-resource-stack.nested.template.json" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-stack.nested.template.json new file mode 100644 index 000000000..f288b015b --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-stack.nested.template.json @@ -0,0 +1,10 @@ +{ + "Resources": { + "SomeResource": { + "Type": "AWS::Something", + "Properties": { + "Property": "new-value" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json new file mode 100644 index 000000000..8fc77b09f --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json @@ -0,0 +1,28 @@ +{ + "Resources": { + "SomeResource": { + "Type": "AWS::Something", + "Properties": { + "Property": "new-value" + } + }, + "GrandChildStackA": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.magic-url.com" + }, + "Metadata": { + "aws:asset:path": "one-resource-stack.nested.template.json" + } + }, + "GrandChildStackB": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.magic-url.com" + }, + "Metadata": { + "aws:asset:path": "one-resource-stack.nested.template.json" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json new file mode 100644 index 000000000..e0bcd1cb3 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json @@ -0,0 +1,39 @@ +{ + "Resources": { + "NestedLambdaStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.amazon.com", + "Parameters": { + "referenceToS3BucketParam": { + "Ref": "S3BucketParam" + }, + "referenceToS3StackKeyOutput": { + "Fn::GetAtt": [ + "NestedSiblingStack", + "Outputs.NestedOutput" + ] + } + } + }, + "Metadata": { + "aws:asset:path": "one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json" + } + }, + "NestedSiblingStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.amazon.com" + }, + "Metadata": { + "aws:asset:path": "one-output-stack.nested.template.json" + } + } + }, + "Parameters": { + "S3BucketParam": { + "Type": "String", + "Description": "S3 bucket for asset" + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json new file mode 100644 index 000000000..d91d9e065 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json @@ -0,0 +1,16 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "current-bucket", + "S3Key": "new-key" + } + }, + "Metadata": { + "aws:asset:path": "old-path" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json new file mode 100644 index 000000000..a1adcd776 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_fixtures/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json @@ -0,0 +1,34 @@ +{ + "Resources": { + "Func": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "current-bucket", + "S3Key": "new-key" + } + }, + "Metadata": { + "aws:asset:path": "old-path" + } + }, + "GrandChildStackA": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.amazon.com" + }, + "Metadata": { + "aws:asset:path": "one-unnamed-lambda-stack.nested.template.json" + } + }, + "GrandChildStackB": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://www.amazon.com" + }, + "Metadata": { + "aws:asset:path": "one-unnamed-lambda-stack.nested.template.json" + } + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/as-mock.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/as-mock.ts new file mode 100644 index 000000000..5a369f585 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/as-mock.ts @@ -0,0 +1,48 @@ +/** + * Return a mocked instance of a class, given its constructor + * + * I don't understand why jest doesn't provide this by default, + * but there you go. + * + * FIXME: Currently very limited. Doesn't support inheritance, getters or + * automatic detection of properties (as those exist on instances, not + * classes). + */ +export function instanceMockFrom(ctr: new (...args: any[]) => A): jest.Mocked { + const ret: any = {}; + for (const methodName of Object.getOwnPropertyNames(ctr.prototype)) { + ret[methodName] = jest.fn(); + } + return ret; +} + +export function withMocked( + obj: A, + key: K, + block: (fn: jest.Mocked[K]) => B, +): B { + const original = obj[key]; + const mockFn = jest.fn(); + (obj as any)[key] = mockFn; + + let asyncFinally: boolean = false; + try { + const ret = block(mockFn as any); + if (!isPromise(ret)) { + return ret; + } + + asyncFinally = true; + return ret.finally(() => { + obj[key] = original; + }) as any; + } finally { + if (!asyncFinally) { + obj[key] = original; + } + } +} + +function isPromise(object: any): object is Promise { + return Promise.resolve(object) === object; +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/assembly.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/assembly.ts index b6d807db9..2598ed0ba 100644 --- a/packages/@aws-cdk/toolkit-lib/test/_helpers/assembly.ts +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/assembly.ts @@ -91,7 +91,7 @@ function addNestedStacks(templatePath: string, outdir: string, rootStackTemplate if (!template) { const templatePathWithDir = path.join('nested-stack-templates', templatePath); - template = JSON.parse(fs.readFileSync(path.join(__dirname, '..', templatePathWithDir)).toString()); + template = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '_fixtures', templatePathWithDir)).toString()); fs.writeFileSync(path.join(outdir, templatePath), JSON.stringify(template, undefined, 2)); } diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/bockfs.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/bockfs.ts new file mode 100644 index 000000000..74257e4d8 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/bockfs.ts @@ -0,0 +1,81 @@ +/* eslint-disable import/order */ +// A not-so-fake filesystem mock similar to mock-fs +// +// mock-fs is super convenient but we can't always use it: +// - When you use console.log() jest wants to load things from the filesystem (which fails). +// - When you make AWS calls the SDK wants to load things from the filesystem (which fails). +// +// Therefore, something similar which uses tempdirs on your actual disk. +// +// The big downside compared to mockfs is that you need to use bockfs.path() to translate +// fake paths to real paths. +import * as os from 'os'; +import * as path_ from 'path'; +import * as fs from 'fs-extra'; + +const bockFsRoot = fs.realpathSync(fs.mkdtempSync(path_.join(os.tmpdir(), 'bockfs'))); +let oldCwd: string | undefined; + +function bockfs(files: Record) { + oldCwd = process.cwd(); + for (const [fileName, contents] of Object.entries(files)) { + bockfs.write(fileName, contents); + } +} + +namespace bockfs { + /** + * Write contents to a fake file + */ + export function write(fakeFilename: string, contents: string) { + const fullPath = path(fakeFilename); + fs.mkdirSync(path_.dirname(fullPath), { recursive: true }); + fs.writeFileSync(fullPath, contents, { encoding: 'utf-8' }); + } + + /** + * Turn a fake path into a real path + */ + export function path(fakePath: string) { + if (fakePath.startsWith('/')) { + fakePath = fakePath.slice(1); + } // Force path to be non-absolute + return path_.join(bockFsRoot, fakePath); + } + + /** + * Change to a fake directory + * + * @returns A template literal function to turn a fake path into a real path. Relative paths are assumed to be in the working dir. + */ + export function workingDirectory(fakePath: string): (parts: TemplateStringsArray) => string { + process.chdir(path(fakePath)); + + return function (elements: TemplateStringsArray) { + const fullPath = elements.join(''); + if (!fullPath.startsWith('/')) { + return path(path_.join(fakePath, fullPath)); + } + + return path(fullPath); + }; + } + + export function executable(...fakePaths: string[]) { + for (const fakepath of fakePaths) { + fs.chmodSync(path(fakepath), '755'); + } + } + + /** + * Remove all files and restore working directory + */ + export function restore() { + if (oldCwd) { + process.chdir(oldCwd); + } + fs.removeSync(bockFsRoot); + } +} + +export default bockfs; diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/fake-io-host.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/fake-io-host.ts new file mode 100644 index 000000000..cb5114421 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/fake-io-host.ts @@ -0,0 +1,42 @@ +import type { IIoHost, IoMessage, IoMessageLevel, IoRequest } from '../../lib/api/io'; + +/** + * An implementation of `IIoHost` that records messages and lets you assert on what was logged + * + * It's like `TestIoHost`, but comes with a predefined implementation for `notify` + * that appends all messages to an in-memory array, and comes with a helper function + * `expectMessage()` to test for the existence of a function in that array. + * + * Has a public mock for `requestResponse` that you configure like any + * other mock function. + * + * # How to use + * + * Either create a new instance of this class for every test, or call `clear()` + * on it between runs. + */ +export class FakeIoHost implements IIoHost { + public messages: Array> = []; + public requestResponse!: (msg: IoRequest) => Promise; + + constructor() { + this.clear(); + } + + public clear() { + this.messages.splice(0, this.messages.length); + this.requestResponse = jest.fn().mockRejectedValue(new Error('requestResponse not mocked')); + } + + public async notify(msg: IoMessage): Promise { + this.messages.push(msg); + } + + public expectMessage(m: { containing: string; level?: IoMessageLevel }) { + expect(this.messages).toContainEqual(expect.objectContaining({ + ...m.level ? { level: m.level } : undefined, + // Can be a partial string as well + message: expect.stringContaining(m.containing), + })); + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/mock-sdk.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/mock-sdk.ts index af8e80b87..6bce2371e 100644 --- a/packages/@aws-cdk/toolkit-lib/test/_helpers/mock-sdk.ts +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/mock-sdk.ts @@ -144,14 +144,23 @@ export const setDefaultSTSMocks = () => { * clients may be used. */ export class MockSdkProvider extends SdkProvider { + private defaultAccounts: string[] = []; + constructor() { super(FAKE_CREDENTIAL_CHAIN, 'bermuda-triangle-1337', { ioHelper: new TestIoHost().asHelper('sdk'), }); } + public returnsDefaultAccounts(...accounts: string[]) { + this.defaultAccounts = accounts; + } + public defaultAccount(): Promise { - return Promise.resolve({ accountId: '123456789012', partition: 'aws' }); + const accountId = this.defaultAccounts.length === 0 + ? '123456789012' + : this.defaultAccounts.shift()!; + return Promise.resolve({ accountId, partition: 'aws' }); } } diff --git a/packages/@aws-cdk/toolkit-lib/test/actions/diff.test.ts b/packages/@aws-cdk/toolkit-lib/test/actions/diff.test.ts index b194f2c9c..09e6d917f 100644 --- a/packages/@aws-cdk/toolkit-lib/test/actions/diff.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/actions/diff.test.ts @@ -7,13 +7,15 @@ import { RequireApproval } from '../../lib/api/require-approval'; import { StackSelectionStrategy } from '../../lib/api/shared-public'; import { Toolkit } from '../../lib/toolkit'; import { builderFixture, disposableCloudAssemblySource, TestIoHost } from '../_helpers'; -import { MockSdk } from '../_helpers/mock-sdk'; +import { MockSdk, restoreSdkMocksToDefault, setDefaultSTSMocks } from '../_helpers/mock-sdk'; let ioHost: TestIoHost; let toolkit: Toolkit; beforeEach(() => { jest.restoreAllMocks(); + restoreSdkMocksToDefault(); + setDefaultSTSMocks(); ioHost = new TestIoHost(); ioHost.requireDeployApproval = RequireApproval.NEVER; diff --git a/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/fake-cloudformation-stack.ts similarity index 86% rename from packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts rename to packages/@aws-cdk/toolkit-lib/test/api/_helpers/fake-cloudformation-stack.ts index 7a5d91c44..88ce3776a 100644 --- a/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/fake-cloudformation-stack.ts @@ -1,5 +1,7 @@ -import { ICloudFormationClient } from '../../../lib/api'; -import { CloudFormationStack, Template } from '../../../lib/api/cloudformation'; + +import type { ICloudFormationClient } from '../../../lib/api/aws-auth/private'; +import type { Template } from '../../../lib/api/cloudformation'; +import { CloudFormationStack } from '../../../lib/api/cloudformation'; import { StackStatus } from '../../../lib/api/stack-events'; import { MockSdk } from '../../_helpers/mock-sdk'; diff --git a/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/hotswap-test-setup.ts similarity index 85% rename from packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts rename to packages/@aws-cdk/toolkit-lib/test/api/_helpers/hotswap-test-setup.ts index 92abbcd50..41d95af34 100644 --- a/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/hotswap-test-setup.ts @@ -1,9 +1,16 @@ -import * as cxapi from '@aws-cdk/cx-api'; -import { ListStackResourcesCommand, StackResourceSummary, StackStatus } from '@aws-sdk/client-cloudformation'; +import type * as cxapi from '@aws-cdk/cx-api'; +import type { StackResourceSummary } from '@aws-sdk/client-cloudformation'; +import { ListStackResourcesCommand, StackStatus } from '@aws-sdk/client-cloudformation'; import { GetFunctionCommand } from '@aws-sdk/client-lambda'; -import { ICloudFormationClient, SuccessfulDeployStackResult } from '../../../lib/api'; -import { HotswapMode, HotswapPropertyOverrides, tryHotswapDeployment } from '../../../lib/api/hotswap'; -import { testStack, TestStackArtifact } from '../../_helpers/assembly'; +import { FakeCloudformationStack } from './fake-cloudformation-stack'; +import type { ICloudFormationClient } from '../../../lib/api/aws-auth/private'; +import type { Template } from '../../../lib/api/cloudformation'; +import { CloudFormationStack } from '../../../lib/api/cloudformation'; +import type { SuccessfulDeployStackResult } from '../../../lib/api/deployments/deployment-result'; +import type { HotswapMode } from '../../../lib/api/hotswap'; +import { HotswapPropertyOverrides, tryHotswapDeployment } from '../../../lib/api/hotswap'; +import type { TestStackArtifact } from '../../_helpers/assembly'; +import { testStack } from '../../_helpers/assembly'; import { mockCloudFormationClient, mockLambdaClient, @@ -11,9 +18,7 @@ import { restoreSdkMocksToDefault, setDefaultSTSMocks, } from '../../_helpers/mock-sdk'; -import { FakeCloudformationStack } from './fake-cloudformation-stack'; -import { CloudFormationStack, Template } from '../../../lib/api/cloudformation'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; const STACK_NAME = 'withouterrors'; export const STACK_ID = 'stackId'; diff --git a/packages/@aws-cdk/toolkit-lib/test/api/_helpers/mock-toolkitinfo.ts b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/mock-toolkitinfo.ts new file mode 100644 index 000000000..dfab78ba1 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/api/_helpers/mock-toolkitinfo.ts @@ -0,0 +1,54 @@ +/* eslint-disable import/order */ +import { ToolkitInfo, DEFAULT_BOOTSTRAP_VARIANT } from '../../../lib/api'; +import type { CloudFormationStack } from '../../../lib/api/cloudformation'; + +export interface MockToolkitInfoProps { + readonly bucketName?: string; + readonly bucketUrl?: string; + readonly repositoryName?: string; + readonly version?: number; + readonly bootstrapStack?: CloudFormationStack; +} + +export class MockToolkitInfo extends ToolkitInfo { + public static setup(toolkitInfo?: ToolkitInfo) { + toolkitInfo = toolkitInfo ?? new MockToolkitInfo(); + const orig = ToolkitInfo.lookup; + ToolkitInfo.lookup = jest.fn().mockResolvedValue(toolkitInfo); + + return { + toolkitInfo, + dispose: () => { + ToolkitInfo.lookup = orig; + }, + }; + } + + public readonly found = true; + public readonly bucketUrl: string; + public readonly bucketName: string; + public readonly repositoryName: string; + public readonly version: number; + public readonly variant: string; + public readonly stackName = 'MockBootstrapStack'; + + private readonly _bootstrapStack?: CloudFormationStack; + + constructor(props: MockToolkitInfoProps = {}) { + super(); + + this.bucketName = props.bucketName ?? 'MockToolkitBucketName'; + this.bucketUrl = props.bucketUrl ?? `https://${this.bucketName}.s3.amazonaws.com/`; + this.repositoryName = props.repositoryName ?? 'MockToolkitRepositoryName'; + this.version = props.version ?? 1; + this.variant = DEFAULT_BOOTSTRAP_VARIANT; + this._bootstrapStack = props.bootstrapStack; + } + + public get bootstrapStack(): CloudFormationStack { + if (!this._bootstrapStack) { + throw new Error('Bootstrap stack object expected but not supplied to MockToolkitInfo'); + } + return this._bootstrapStack; + } +} diff --git a/packages/aws-cdk/test/api/aws-auth/__snapshots__/sdk-logger.test.ts.snap b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/__snapshots__/sdk-logger.test.ts.snap similarity index 100% rename from packages/aws-cdk/test/api/aws-auth/__snapshots__/sdk-logger.test.ts.snap rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/__snapshots__/sdk-logger.test.ts.snap diff --git a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/account-cache.test.ts similarity index 99% rename from packages/aws-cdk/test/api/aws-auth/account-cache.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/account-cache.test.ts index 3561b2ec0..2804fc320 100644 --- a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/account-cache.test.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import bockfs from '../../_helpers/bockfs'; import * as fs from 'fs-extra'; -import { AccountAccessKeyCache } from '../../../lib/api/aws-auth'; +import { AccountAccessKeyCache } from '../../../lib/api/aws-auth/private'; import { withMocked } from '../../_helpers/as-mock'; +import bockfs from '../../_helpers/bockfs'; const noOp = async () => { }; diff --git a/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/awscli-compatible.test.ts similarity index 98% rename from packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/awscli-compatible.test.ts index d83be5424..6811de110 100644 --- a/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/awscli-compatible.test.ts @@ -1,8 +1,8 @@ import * as os from 'os'; import * as path from 'path'; import * as fs from 'fs-extra'; -import { AwsCliCompatible } from '../../../lib/api/aws-auth'; -import { TestIoHost } from '../../_helpers/io-host'; +import { AwsCliCompatible } from '../../../lib/api/aws-auth/private'; +import { TestIoHost } from '../../_helpers/test-io-host'; const ioHost = new TestIoHost(); const ioHelper = ioHost.asHelper('sdk'); diff --git a/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/credential-plugins.test.ts similarity index 80% rename from packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/credential-plugins.test.ts index bb5a76139..e83888324 100644 --- a/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/credential-plugins.test.ts @@ -1,8 +1,7 @@ import type { PluginProviderResult, SDKv2CompatibleCredentials } from '@aws-cdk/cli-plugin-contract'; -import { CredentialPlugins } from '../../../lib/api/aws-auth'; -import { Mode } from '../../../lib/api/plugin'; -import { TestIoHost } from '../../_helpers/io-host'; -import { GLOBAL_PLUGIN_HOST } from '../../../lib/cli/singleton-plugin-host'; +import { CredentialPlugins } from '../../../lib/api/aws-auth/private'; +import { Mode, PluginHost } from '../../../lib/api/plugin'; +import { TestIoHost } from '../../_helpers/test-io-host'; const ioHost = new TestIoHost(); const ioHelper = ioHost.asHelper('deploy'); @@ -14,7 +13,7 @@ test('returns credential from plugin', async () => { secretAccessKey: 'bbb', getPromise: () => Promise.resolve(), } satisfies SDKv2CompatibleCredentials; - const host = GLOBAL_PLUGIN_HOST; + const host = new PluginHost(); host.registerCredentialProviderSource({ name: 'Fake', diff --git a/packages/aws-cdk/test/api/aws-auth/fake-sts.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/fake-sts.ts similarity index 99% rename from packages/aws-cdk/test/api/aws-auth/fake-sts.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/fake-sts.ts index 0b97f7bfe..6ed818663 100644 --- a/packages/aws-cdk/test/api/aws-auth/fake-sts.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/fake-sts.ts @@ -1,4 +1,4 @@ -import { Tag } from '@aws-sdk/client-sts'; +import type { Tag } from '@aws-sdk/client-sts'; import * as nock from 'nock'; import * as uuid from 'uuid'; import * as xmlJs from 'xml-js'; diff --git a/packages/aws-cdk/test/api/aws-auth/sdk-logger.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-logger.test.ts similarity index 98% rename from packages/aws-cdk/test/api/aws-auth/sdk-logger.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-logger.test.ts index c3593bc07..1199c230a 100644 --- a/packages/aws-cdk/test/api/aws-auth/sdk-logger.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-logger.test.ts @@ -1,4 +1,4 @@ -import { formatSdkLoggerContent, SdkToCliLogger } from '../../../lib/api/aws-auth'; +import { formatSdkLoggerContent, SdkToCliLogger } from '../../../lib/api/aws-auth/private'; describe(SdkToCliLogger, () => { const ioHost = { diff --git a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-provider.test.ts similarity index 97% rename from packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-provider.test.ts index 35ce1c462..81c38f4d8 100644 --- a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/aws-auth/sdk-provider.test.ts @@ -13,20 +13,19 @@ * calls and locally fake an STS Endpoint using the `FakeSts` class. */ import * as os from 'os'; -import bockfs from '../../_helpers/bockfs'; import * as cxapi from '@aws-cdk/cx-api'; import * as fromEnv from '@aws-sdk/credential-provider-env'; import * as promptly from 'promptly'; import * as uuid from 'uuid'; -import { FakeSts, RegisterRoleOptions, RegisterUserOptions } from './fake-sts'; -import { ConfigurationOptions, CredentialsOptions, SDK, SdkProvider } from '../../../lib/api/aws-auth'; -import { AwsCliCompatible } from '../../../lib/api/aws-auth'; -import { defaultCliUserAgent } from '../../../lib/api/aws-auth'; -import { Mode } from '../../../lib/api/plugin'; +import type { RegisterRoleOptions, RegisterUserOptions } from './fake-sts'; +import { FakeSts } from './fake-sts'; +import type { ConfigurationOptions, CredentialsOptions, SDK } from '../../../lib/api/aws-auth/private'; +import { SdkProvider, AwsCliCompatible, defaultCliUserAgent } from '../../../lib/api/aws-auth/private'; +import { PluginHost, Mode } from '../../../lib/api/plugin'; import { withMocked } from '../../_helpers/as-mock'; +import bockfs from '../../_helpers/bockfs'; import { undoAllSdkMocks } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; -import { GLOBAL_PLUGIN_HOST } from '../../../lib/cli/singleton-plugin-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; // As part of the imports above we import `mock-sdk.ts` which automatically mocks // all SDK clients. We don't want that for this test suite, so undo it. @@ -51,6 +50,7 @@ jest.mock('@aws-sdk/ec2-metadata-service', () => { let uid: string; let pluginQueried: boolean; +let pluginHost: PluginHost; const ioHost = new TestIoHost('trace'); const ioHelper = ioHost.asHelper('sdk'); @@ -67,8 +67,10 @@ beforeEach(() => { ioHost.notifySpy.mockClear(); ioHost.requestSpy.mockClear(); - GLOBAL_PLUGIN_HOST.credentialProviderSources.splice(0); - GLOBAL_PLUGIN_HOST.credentialProviderSources.push({ + pluginHost = new PluginHost(); + + pluginHost.credentialProviderSources.splice(0); + pluginHost.credentialProviderSources.push({ isAvailable() { return Promise.resolve(true); }, @@ -163,7 +165,7 @@ describe('with intercepted network calls', () => { const error = new Error('Expired Token'); error.name = 'ExpiredToken'; const identityProvider = () => Promise.reject(error); - const provider = new SdkProvider(identityProvider, 'rgn', { ioHelper, pluginHost: GLOBAL_PLUGIN_HOST }); + const provider = new SdkProvider(identityProvider, 'rgn', { ioHelper, pluginHost: pluginHost }); const creds = await provider.baseCredentialsPartition({ ...env(account), region: 'rgn' }, Mode.ForReading); expect(creds).toBeUndefined(); @@ -325,7 +327,7 @@ describe('with intercepted network calls', () => { // The profile is not passed explicitly. Should be picked from the environment variable process.env.AWS_PROFILE = 'mfa-role'; // Awaiting to make sure the environment variable is only deleted after it's used - const provider = await SdkProvider.withAwsCliCompatibleDefaults({ ioHelper, logger: console, pluginHost: GLOBAL_PLUGIN_HOST }); + const provider = await SdkProvider.withAwsCliCompatibleDefaults({ ioHelper, logger: console, pluginHost: pluginHost }); delete process.env.AWS_PROFILE; return Promise.resolve(provider); }), @@ -829,7 +831,7 @@ function isProfileRole(x: ProfileUser | ProfileRole): x is ProfileRole { } async function providerFromProfile(profile: string | undefined) { - return SdkProvider.withAwsCliCompatibleDefaults({ ioHelper, profile, logger: console, pluginHost: GLOBAL_PLUGIN_HOST }); + return SdkProvider.withAwsCliCompatibleDefaults({ ioHelper, profile, logger: console, pluginHost: pluginHost }); } async function exerciseCredentials(provider: SdkProvider, e: cxapi.Environment, mode: Mode = Mode.ForReading, diff --git a/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap.test.ts similarity index 98% rename from packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap.test.ts index fd9261f6a..d14608efb 100644 --- a/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap.test.ts @@ -10,11 +10,10 @@ import { UpdateTerminationProtectionCommand, } from '@aws-sdk/client-cloudformation'; import { parse } from 'yaml'; -import { Bootstrapper } from '../../../lib/api/bootstrap'; -import { legacyBootstrapTemplate } from '../../../lib/api/bootstrap'; +import { Bootstrapper, legacyBootstrapTemplate } from '../../../lib/api/bootstrap'; import { deserializeStructure, serializeStructure, toYAML } from '../../../lib/util'; import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; const env = { account: '123456789012', @@ -25,7 +24,7 @@ const env = { const templateBody = toYAML(deserializeStructure(serializeStructure(legacyBootstrapTemplate({}), true))); const changeSetName = 'cdk-deploy-change-set'; -jest.mock('../../../../@aws-cdk/toolkit-lib/lib/api/deployments/checks', () => ({ +jest.mock('../../../lib/api/deployments/checks', () => ({ determineAllowCrossAccountAssetPublishing: jest.fn().mockResolvedValue(true), })); let sdk: MockSdkProvider; diff --git a/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap2.test.ts similarity index 98% rename from packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap2.test.ts index 7dca18261..f995c547c 100644 --- a/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/bootstrap/bootstrap2.test.ts @@ -1,7 +1,7 @@ /* eslint-disable import/order */ -import * as deployStack from '../../../../@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack'; -import { Stack } from '@aws-sdk/client-cloudformation'; +import * as deployStack from '../../../lib/api/deployments/deploy-stack'; +import type { Stack } from '@aws-sdk/client-cloudformation'; import { CreatePolicyCommand, GetPolicyCommand } from '@aws-sdk/client-iam'; import { Bootstrapper, ToolkitInfo } from '../../../lib/api'; import { @@ -10,8 +10,8 @@ import { MockSdkProvider, restoreSdkMocksToDefault, setDefaultSTSMocks, } from '../../_helpers/mock-sdk'; -import { IIoHost } from '../../../lib/cli/io-host'; -import { asIoHelper } from '../../../../@aws-cdk/toolkit-lib/lib/api/io/private'; +import { asIoHelper } from '../../../lib/api/io/private'; +import type { IIoHost } from '../../../lib/api/io'; const mockDeployStack = jest.spyOn(deployStack, 'deployStack'); diff --git a/packages/aws-cdk/test/api/cloudformation/evaluate-cloudformation-template.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/cloudformation/evaluate-cloudformation-template.test.ts similarity index 98% rename from packages/aws-cdk/test/api/cloudformation/evaluate-cloudformation-template.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/cloudformation/evaluate-cloudformation-template.test.ts index 3496c99f1..31fe41ea5 100644 --- a/packages/aws-cdk/test/api/cloudformation/evaluate-cloudformation-template.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/cloudformation/evaluate-cloudformation-template.test.ts @@ -1,8 +1,8 @@ import { ListExportsCommand } from '@aws-sdk/client-cloudformation'; +import type { Template } from '../../../lib/api/cloudformation'; import { CfnEvaluationException, EvaluateCloudFormationTemplate, - Template, } from '../../../lib/api/cloudformation'; import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; diff --git a/packages/aws-cdk/test/api/cloudformation/lazy-list-stack-resources.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/cloudformation/lazy-list-stack-resources.test.ts similarity index 100% rename from packages/aws-cdk/test/api/cloudformation/lazy-list-stack-resources.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/cloudformation/lazy-list-stack-resources.test.ts diff --git a/packages/aws-cdk/test/api/cloudformation/lazy-lookup-export.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/cloudformation/lazy-lookup-export.test.ts similarity index 100% rename from packages/aws-cdk/test/api/cloudformation/lazy-lookup-export.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/cloudformation/lazy-lookup-export.test.ts diff --git a/packages/aws-cdk/test/api/deployments/assets.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/assets.test.ts similarity index 92% rename from packages/aws-cdk/test/api/deployments/assets.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/assets.test.ts index f5decb16a..3d666ce3c 100644 --- a/packages/aws-cdk/test/api/deployments/assets.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/assets.test.ts @@ -1,12 +1,13 @@ /* eslint-disable import/order */ -import { AssetMetadataEntry } from '@aws-cdk/cloud-assembly-schema'; -import { testStack, withMocked } from '../../_helpers'; -import { addMetadataAssetsToManifest } from '../../../lib/api/deployments'; -import { AssetManifestBuilder } from '../../../lib/api/deployments'; -import { EnvironmentResources, EnvironmentResourcesRegistry } from '../../../lib/api/environment'; +import type { AssetMetadataEntry } from '@aws-cdk/cloud-assembly-schema'; +import { addMetadataAssetsToManifest, AssetManifestBuilder } from '../../../lib/api/deployments'; +import type { EnvironmentResources } from '../../../lib/api/environment'; +import { EnvironmentResourcesRegistry } from '../../../lib/api/environment'; import { MockSdk } from '../../_helpers/mock-sdk'; -import { MockToolkitInfo } from '../../_helpers/mock-toolkitinfo'; -import { TestIoHost } from '../../_helpers/io-host'; +import { MockToolkitInfo } from '../_helpers/mock-toolkitinfo'; +import { TestIoHost } from '../../_helpers/test-io-host'; +import { withMocked } from '../../_helpers/as-mock'; +import { testStack } from '../../_helpers/assembly'; let assets: AssetManifestBuilder; let envRegistry: EnvironmentResourcesRegistry; diff --git a/packages/aws-cdk/test/api/deployments/checks.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/checks.test.ts similarity index 98% rename from packages/aws-cdk/test/api/deployments/checks.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/checks.test.ts index ade3d6f36..1ddf30a81 100644 --- a/packages/aws-cdk/test/api/deployments/checks.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/checks.test.ts @@ -1,7 +1,7 @@ import { DescribeStacksCommand, StackStatus } from '@aws-sdk/client-cloudformation'; import { determineAllowCrossAccountAssetPublishing, getBootstrapStackInfo } from '../../../lib/api/deployments'; import { mockCloudFormationClient, MockSdk } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; let ioHelper = new TestIoHost().asHelper('deploy'); diff --git a/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation-deployments.test.ts index 70287c033..56db8036d 100644 --- a/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation-deployments.test.ts @@ -12,8 +12,11 @@ import { CreateChangeSetCommand, } from '@aws-sdk/client-cloudformation'; import { GetParameterCommand } from '@aws-sdk/client-ssm'; -import { cfnApi, deployStack } from '../../../lib/api-private'; +import { CloudFormationStack } from '../../../lib/api/cloudformation'; +import { Deployments } from '../../../lib/api/deployments'; +import { deployStack } from '../../../lib/api/deployments/deploy-stack'; import { HotswapMode } from '../../../lib/api/hotswap'; +import { cfnApi } from '../../../lib/api/shared-private'; import { ToolkitInfo } from '../../../lib/api/toolkit-info'; import { testStack } from '../../_helpers/assembly'; import { @@ -25,13 +28,11 @@ import { restoreSdkMocksToDefault, setDefaultSTSMocks, } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/test-io-host'; import { FakeCloudformationStack } from '../_helpers/fake-cloudformation-stack'; -import { TestIoHost } from '../../_helpers/io-host'; -import { Deployments } from '../../../lib/api/deployments'; -import { CloudFormationStack } from '../../../lib/api/cloudformation'; -jest.mock('../../../../@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack'); -jest.mock('../../../../@aws-cdk/toolkit-lib/lib/api/deployments/asset-publishing'); +jest.mock('../../../lib/api/deployments/deploy-stack'); +jest.mock('../../../lib/api/deployments/asset-publishing'); let sdkProvider: MockSdkProvider; let sdk: MockSdk; diff --git a/packages/aws-cdk/test/api/deployments/cloudformation.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation.test.ts similarity index 98% rename from packages/aws-cdk/test/api/deployments/cloudformation.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation.test.ts index c9f9e526c..8355bc440 100644 --- a/packages/aws-cdk/test/api/deployments/cloudformation.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/cloudformation.test.ts @@ -1,9 +1,9 @@ import { SSMPARAM_NO_INVALIDATE } from '@aws-cdk/cx-api'; import { DescribeStacksCommand, GetTemplateCommand, StackStatus } from '@aws-sdk/client-cloudformation'; -import { MockSdk, mockCloudFormationClient } from '../../_helpers/mock-sdk'; -import type { ICloudFormationClient } from '../../../lib/api/aws-auth'; +import type { ICloudFormationClient } from '../../../lib/api/aws-auth/private'; import { CloudFormationStack } from '../../../lib/api/cloudformation'; -import { cfnApi } from '../../../lib/api-private'; +import * as cfnApi from '../../../lib/api/deployments/cfn-api'; +import { MockSdk, mockCloudFormationClient } from '../../_helpers/mock-sdk'; const PARAM = 'TheParameter'; const DEFAULT = 'TheDefault'; diff --git a/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts similarity index 98% rename from packages/aws-cdk/test/api/deployments/deploy-stack.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts index 476cf0acc..ef9291b60 100644 --- a/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts @@ -17,10 +17,11 @@ import { UpdateTerminationProtectionCommand, } from '@aws-sdk/client-cloudformation'; import { assertIsSuccessfulDeployStackResult } from '../../../lib/api/deployments'; -import { deployStack, DeployStackApiOptions } from '../../../lib/api-private' -import { tryHotswapDeployment } from '../../../lib/api/hotswap'; +import type { DeployStackOptions as DeployStackApiOptions } from '../../../lib/api/deployments/deploy-stack'; +import { deployStack } from '../../../lib/api/deployments/deploy-stack'; import { NoBootstrapStackEnvironmentResources } from '../../../lib/api/environment'; -import { HotswapMode } from '../../../lib/api/hotswap'; +import { HotswapMode } from '../../../lib/api/hotswap/common'; +import { tryHotswapDeployment } from '../../../lib/api/hotswap/hotswap-deployments'; import { DEFAULT_FAKE_TEMPLATE, testStack } from '../../_helpers/assembly'; import { mockCloudFormationClient, @@ -29,7 +30,7 @@ import { MockSdkProvider, restoreSdkMocksToDefault, } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; let ioHost = new TestIoHost(); let ioHelper = ioHost.asHelper('deploy'); @@ -38,8 +39,8 @@ function testDeployStack(options: DeployStackApiOptions) { return deployStack(options, ioHelper); } -jest.mock('../../../../@aws-cdk/toolkit-lib/lib/api/hotswap/hotswap-deployments'); -jest.mock('../../../../@aws-cdk/toolkit-lib/lib/api/deployments/checks', () => ({ +jest.mock('../../../lib/api/hotswap/hotswap-deployments'); +jest.mock('../../../lib/api/deployments/checks', () => ({ determineAllowCrossAccountAssetPublishing: jest.fn().mockResolvedValue(true), })); @@ -810,7 +811,8 @@ test('deploy is not skipped if stack is in a _FAILED state', async () => { await testDeployStack({ ...standardDeployStackArguments(), usePreviousParameters: true, - }).catch(() => {}); + }).catch(() => { + }); // THEN expect(mockCloudFormationClient).toHaveReceivedCommand(CreateChangeSetCommand); diff --git a/packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/hotswap-deployments.test.ts similarity index 100% rename from packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/deployments/hotswap-deployments.test.ts diff --git a/packages/aws-cdk/test/api/environment/environment-resources.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/environment/environment-resources.test.ts similarity index 94% rename from packages/aws-cdk/test/api/environment/environment-resources.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/environment/environment-resources.test.ts index 4c6c87c25..758eb0625 100644 --- a/packages/aws-cdk/test/api/environment/environment-resources.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/environment/environment-resources.test.ts @@ -2,11 +2,11 @@ import { GetParameterCommand } from '@aws-sdk/client-ssm'; import { ToolkitInfo } from '../../../lib/api'; import { Context } from '../../../lib/api/context'; import { EnvironmentResourcesRegistry } from '../../../lib/api/environment'; +import { FakeIoHost } from '../../../lib/api/io/private/testing/fake-io-host'; import { CachedDataSource, Notices, NoticesFilter } from '../../../lib/api/notices'; import { MockSdk, mockBootstrapStack, mockSSMClient } from '../../_helpers/mock-sdk'; -import { MockToolkitInfo } from '../../_helpers/mock-toolkitinfo'; -import { TestIoHost } from '../../_helpers/io-host'; -import { FakeIoHost } from '../../../../@aws-cdk/toolkit-lib/lib/api/io/private/testing/fake-io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; +import { MockToolkitInfo } from '../_helpers/mock-toolkitinfo'; let mockSdk: MockSdk; let envRegistry: EnvironmentResourcesRegistry; @@ -101,8 +101,8 @@ describe('validateversion without bootstrap stack', () => { .mockImplementation(() => Promise.resolve({ expiration: 0, notices: [] })); // THEN - const ioHost = new FakeIoHost(); - const notices = Notices.create({ context: new Context(), ioHost, cliVersion: '1.0.0' }); + const myIoHost = new FakeIoHost(); + const notices = Notices.create({ context: new Context(), ioHost: myIoHost, cliVersion: '1.0.0' }); await notices.refresh({ dataSource: { fetch: async () => [] } }); await expect(envResources().validateVersion(8, '/abc')).resolves.toBeUndefined(); diff --git a/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/garbage-collection/garbage-collection.test.ts similarity index 99% rename from packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/garbage-collection/garbage-collection.test.ts index 5515051f1..739f3cc21 100644 --- a/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/garbage-collection/garbage-collection.test.ts @@ -1,13 +1,18 @@ -/* eslint-disable import/order */ - +import type { + Stack, +} from '@aws-sdk/client-cloudformation'; import { GetTemplateCommand, GetTemplateSummaryCommand, ListStacksCommand, - Stack, } from '@aws-sdk/client-cloudformation'; -import { ECR_ISOLATED_TAG, GarbageCollector, S3_ISOLATED_TAG, ToolkitInfo } from '../../../lib/api'; -import { mockBootstrapStack, mockCloudFormationClient, mockECRClient, mockS3Client, MockSdk, MockSdkProvider } from '../../_helpers/mock-sdk'; +import { + BatchDeleteImageCommand, + BatchGetImageCommand, + DescribeImagesCommand, + ListImagesCommand, + PutImageCommand, +} from '@aws-sdk/client-ecr'; import { DeleteObjectsCommand, DeleteObjectTaggingCommand, @@ -15,20 +20,15 @@ import { ListObjectsV2Command, PutObjectTaggingCommand, } from '@aws-sdk/client-s3'; +import { ECR_ISOLATED_TAG, GarbageCollector, S3_ISOLATED_TAG, ToolkitInfo } from '../../../lib/api'; +import type { BackgroundStackRefreshProps } from '../../../lib/api/garbage-collection'; import { ActiveAssetCache, BackgroundStackRefresh, - BackgroundStackRefreshProps, + ProgressPrinter, } from '../../../lib/api/garbage-collection'; -import { ProgressPrinter } from '../../../lib/api/garbage-collection'; -import { - BatchDeleteImageCommand, - BatchGetImageCommand, - DescribeImagesCommand, - ListImagesCommand, - PutImageCommand, -} from '@aws-sdk/client-ecr'; -import { TestIoHost } from '../../_helpers/io-host'; +import { mockBootstrapStack, mockCloudFormationClient, mockECRClient, mockS3Client, MockSdk, MockSdkProvider } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/test-io-host'; let garbageCollector: GarbageCollector; diff --git a/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts index e74f1b776..5557ff18b 100644 --- a/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts @@ -9,10 +9,9 @@ import { } from '@aws-sdk/client-appsync'; import { GetObjectCommand } from '@aws-sdk/client-s3'; import { sdkStreamMixin } from '@smithy/util-stream'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockAppSyncClient, mockS3Client } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -22,7 +21,8 @@ beforeEach(() => { const getBodyStream = (input: string) => { const stream = new Readable(); - stream._read = () => {}; + stream._read = () => { + }; stream.push(input); stream.push(null); // close the stream return sdkStreamMixin(stream); @@ -972,7 +972,6 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot test( 'updateFunction() API recovers from failed update attempt through retry logic', async () => { - // GIVEN mockAppSyncClient .on(ListFunctionsCommand) diff --git a/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts index 02ced840a..2e99e7981 100644 --- a/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts @@ -1,8 +1,7 @@ import { UpdateProjectCommand } from '@aws-sdk/client-codebuild'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockCodeBuildClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; diff --git a/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/ecs-services-hotswap-deployments.test.ts similarity index 98% rename from packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/ecs-services-hotswap-deployments.test.ts index bf0f09a61..a465117a7 100644 --- a/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/ecs-services-hotswap-deployments.test.ts @@ -1,9 +1,8 @@ import { DescribeServicesCommand, RegisterTaskDefinitionCommand, UpdateServiceCommand } from '@aws-sdk/client-ecs'; -import * as setup from '../_helpers/hotswap-test-setup'; +import { Settings } from '../../../lib/api'; import { EcsHotswapProperties, HotswapMode, HotswapPropertyOverrides } from '../../../lib/api/hotswap'; -import { Configuration } from '../../../lib/cli/user-configuration'; import { mockECSClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -642,8 +641,8 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); describe.each([ - new Configuration().settings.set(['hotswap'], { ecs: { minimumHealthyPercent: 10 } }), - new Configuration().settings.set(['hotswap'], { ecs: { minimumHealthyPercent: 10, maximumHealthyPercent: 100 } }), + new Settings().set(['hotswap'], { ecs: { minimumHealthyPercent: 10 } }), + new Settings().set(['hotswap'], { ecs: { minimumHealthyPercent: 10, maximumHealthyPercent: 100 } }), ])('hotswap properties', (settings) => { test('should handle all possible hotswap properties', async () => { // GIVEN diff --git a/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/iam-policy-hotswap-deployment.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/iam-policy-hotswap-deployment.test.ts index 7a49a659c..9afdf6901 100644 --- a/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/iam-policy-hotswap-deployment.test.ts @@ -1,7 +1,6 @@ import { StackStatus } from '@aws-sdk/client-cloudformation'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts index 499184b93..e21d321e7 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts @@ -9,10 +9,9 @@ jest.mock('@aws-sdk/client-lambda', () => { }); import { UpdateFunctionCodeCommand, waitUntilFunctionUpdatedV2 } from '@aws-sdk/client-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts index 3ab754581..8308f6a5e 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts @@ -3,10 +3,9 @@ import { UpdateFunctionConfigurationCommand, waitUntilFunctionUpdatedV2, } from '@aws-sdk/client-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts index fdb6aca9b..2d43512da 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts @@ -1,9 +1,8 @@ import { UpdateFunctionCodeCommand } from '@aws-sdk/client-lambda'; import { Runtime } from 'aws-cdk-lib/aws-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); diff --git a/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts index afd3f32a6..e5917fe47 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts @@ -1,8 +1,7 @@ import { PublishVersionCommand, UpdateAliasCommand } from '@aws-sdk/client-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); diff --git a/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/nested-stacks-hotswap.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/nested-stacks-hotswap.test.ts index 5d7651f6b..3b83569ed 100644 --- a/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/nested-stacks-hotswap.test.ts @@ -1,9 +1,8 @@ import { PublishVersionCommand, UpdateFunctionCodeCommand } from '@aws-sdk/client-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { testStack } from '../../_helpers/assembly'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -746,7 +745,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot oldChildStack.template.Resources.GrandChildStackB.Properties.TemplateURL = 'https://www.amazon.com'; const newRootStack = testStack({ stackName: oldRootStack.stackName, template: oldRootStack.template }); - //testStack({ stackName: oldChildStack.stackName, template: oldChildStack.template }); + // testStack({ stackName: oldChildStack.stackName, template: oldChildStack.template }); const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, newRootStack); diff --git a/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts index da34655f0..171c281d4 100644 --- a/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts @@ -1,8 +1,7 @@ import { InvokeCommand } from '@aws-sdk/client-lambda'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockLambdaClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; diff --git a/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/state-machine-hotswap-deployments.test.ts similarity index 99% rename from packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/hotswap/state-machine-hotswap-deployments.test.ts index 436567cf3..67215d2a4 100644 --- a/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/hotswap/state-machine-hotswap-deployments.test.ts @@ -1,8 +1,7 @@ import { UpdateStateMachineCommand } from '@aws-sdk/client-sfn'; -import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap'; import { mockStepFunctionsClient } from '../../_helpers/mock-sdk'; - +import * as setup from '../_helpers/hotswap-test-setup'; let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; diff --git a/packages/aws-cdk/test/api/logs-monitor/find-cloudwatch-logs.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/find-cloudwatch-logs.test.ts similarity index 96% rename from packages/aws-cdk/test/api/logs-monitor/find-cloudwatch-logs.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/find-cloudwatch-logs.test.ts index f0d4f87ce..45be5b4e1 100644 --- a/packages/aws-cdk/test/api/logs-monitor/find-cloudwatch-logs.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/find-cloudwatch-logs.test.ts @@ -1,13 +1,16 @@ -import * as cxapi from '@aws-cdk/cx-api'; -import { - ListStackResourcesCommand, +import type * as cxapi from '@aws-cdk/cx-api'; +import type { ListStackResourcesCommandInput, StackResourceSummary, +} from '@aws-sdk/client-cloudformation'; +import { + ListStackResourcesCommand, StackStatus, } from '@aws-sdk/client-cloudformation'; -import { SdkProvider } from '../../../lib/api'; +import type { SdkProvider } from '../../../lib/api/aws-auth/private'; import { findCloudWatchLogGroups } from '../../../lib/api/logs-monitor'; -import { testStack, TestStackArtifact } from '../../_helpers/assembly'; +import type { TestStackArtifact } from '../../_helpers/assembly'; +import { testStack } from '../../_helpers/assembly'; import { mockCloudFormationClient, MockSdk, @@ -15,7 +18,7 @@ import { restoreSdkMocksToDefault, setDefaultSTSMocks, } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; let sdk: MockSdk; let logsMockSdkProvider: SdkProvider; diff --git a/packages/aws-cdk/test/api/logs-monitor/logs-monitor.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/logs-monitor.test.ts similarity index 98% rename from packages/aws-cdk/test/api/logs-monitor/logs-monitor.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/logs-monitor.test.ts index b4c3f3699..aaad6a6c0 100644 --- a/packages/aws-cdk/test/api/logs-monitor/logs-monitor.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/logs-monitor/logs-monitor.test.ts @@ -1,8 +1,8 @@ import { FilterLogEventsCommand, type FilteredLogEvent } from '@aws-sdk/client-cloudwatch-logs'; import { CloudWatchLogEventMonitor } from '../../../lib/api/logs-monitor'; -import { sleep } from '../../_helpers/sleep'; import { MockSdk, mockCloudWatchClient } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { sleep } from '../../_helpers/sleep'; +import { TestIoHost } from '../../_helpers/test-io-host'; // Helper function to strip ANSI codes const stripAnsi = (str: string): string => { diff --git a/packages/aws-cdk/test/api/notices.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/notices.test.ts similarity index 99% rename from packages/aws-cdk/test/api/notices.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/notices.test.ts index 04c87ba86..0b103f437 100644 --- a/packages/aws-cdk/test/api/notices.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/notices.test.ts @@ -4,20 +4,22 @@ import * as os from 'os'; import * as path from 'path'; import * as fs from 'fs-extra'; import * as nock from 'nock'; +import type { + Notice, + BootstrappedEnvironment, + Component, +} from '../../lib/api/notices'; import { CachedDataSource, - Notice, Notices, NoticesFilter, FilteredNotice, WebsiteNoticeDataSource, - BootstrappedEnvironment, - Component, } from '../../lib/api/notices'; import { Settings } from '../../lib/api/settings'; import { Context } from '../../lib/api/context'; -import { asIoHelper, IoDefaultMessages } from '../../../@aws-cdk/toolkit-lib/lib/api/io/private'; import { FakeIoHost } from '../_helpers/fake-io-host'; +import { asIoHelper, IoDefaultMessages } from '../../lib/api/io/private'; const BASIC_BOOTSTRAP_NOTICE = { title: 'Exccessive permissions on file asset publishing role', @@ -829,7 +831,7 @@ describe(Notices, () => { bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), }); - const notices = Notices.create({ ioHost, context, cliVersion: '1.126.0' }); + const notices = Notices.create({ ioHost, context, cliVersion: '1.126.0' }); await notices.refresh({ dataSource: { fetch: async () => [BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE] }, }); @@ -847,7 +849,7 @@ describe(Notices, () => { bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), }); - const notices = Notices.create({ ioHost, context, includeAcknowledged: true, cliVersion: '1.126.0' }); + const notices = Notices.create({ ioHost, context, includeAcknowledged: true, cliVersion: '1.126.0' }); await notices.refresh({ dataSource: { fetch: async () => [BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE] }, }); @@ -876,7 +878,7 @@ describe(Notices, () => { }); test('deduplicates notices', async () => { - const notices = Notices.create({ ioHost, context: new Context() , cliVersion: '1.0.0'}); + const notices = Notices.create({ ioHost, context: new Context(), cliVersion: '1.0.0' }); await notices.refresh({ dataSource: { fetch: async () => [BASIC_NOTICE, BASIC_NOTICE] }, }); @@ -936,7 +938,7 @@ describe(Notices, () => { bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), }); - const notices = Notices.create({ ioHost, context, cliVersion: '1.126.0' }); + const notices = Notices.create({ ioHost, context, cliVersion: '1.126.0' }); await notices.refresh({ dataSource: { fetch: async () => [BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE] }, }); diff --git a/packages/aws-cdk/test/api/refactoring/refactoring.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/refactoring/refactoring.test.ts similarity index 96% rename from packages/aws-cdk/test/api/refactoring/refactoring.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/refactoring/refactoring.test.ts index ba48a283e..14cf37639 100644 --- a/packages/aws-cdk/test/api/refactoring/refactoring.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/refactoring/refactoring.test.ts @@ -3,23 +3,27 @@ jest.mock('@aws-cdk/cloudformation-diff/lib/diff/util', () => ({ loadResourceModel: mockLoadResourceModel, })); +import type { + ResourceLocation as CfnResourceLocation, + ResourceMapping as CfnResourceMapping, +} from '@aws-sdk/client-cloudformation'; import { GetTemplateCommand, ListStacksCommand, - ResourceLocation as CfnResourceLocation, - ResourceMapping as CfnResourceMapping, } from '@aws-sdk/client-cloudformation'; +import { expect } from '@jest/globals'; +import type { + ResourceLocation, + ResourceMapping, +} from '../../../lib/api/refactoring'; import { ambiguousMovements, findResourceMovements, - ResourceLocation, - ResourceMapping, resourceMappings, resourceMovements, -} from '../../../../@aws-cdk/toolkit-lib/lib/api/refactoring'; -import { computeResourceDigests } from '../../../../@aws-cdk/toolkit-lib/lib/api/refactoring/digest'; +} from '../../../lib/api/refactoring'; +import { computeResourceDigests } from '../../../lib/api/refactoring/digest'; import { mockCloudFormationClient, MockSdkProvider } from '../../_helpers/mock-sdk'; -import { expect } from '@jest/globals'; const cloudFormationClient = mockCloudFormationClient; @@ -40,7 +44,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(1); - expect(result['MyResource']).toBeDefined(); + expect(result.MyResource).toBeDefined(); }); test('computes digest for single resource without dependencies', () => { @@ -54,7 +58,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(1); - expect(result['MyResource']).toBeDefined(); + expect(result.MyResource).toBeDefined(); }); test('order of properties does not matter', () => { @@ -72,7 +76,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(2); - expect(result['MyResource1']).toEqual(result['MyResource2']); + expect(result.MyResource1).toEqual(result.MyResource2); }); test('computes digests with multiple resources referencing each other', () => { @@ -93,8 +97,8 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(2); - expect(result['Bucket']).toBeDefined(); - expect(result['Topic']).toBeDefined(); + expect(result.Bucket).toBeDefined(); + expect(result.Topic).toBeDefined(); }); test('computes different digests if top-level properties are different', () => { @@ -115,7 +119,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Q1']).not.toBe(result['Q2']); + expect(result.Q1).not.toBe(result.Q2); }); test('computes the same digest for identical resources', () => { @@ -133,7 +137,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(2); - expect(result['Bucket1']).toBe(result['Bucket2']); + expect(result.Bucket1).toBe(result.Bucket2); }); test('identical resources up to dependency names', () => { @@ -160,7 +164,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Bucket1']).toBe(result['Bucket2']); + expect(result.Bucket1).toBe(result.Bucket2); }); test('identical resources up to dependency names - DependsOn', () => { @@ -191,7 +195,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Topic1']).toEqual(result['Topic2']); + expect(result.Topic1).toEqual(result.Topic2); }); test('different resources - DependsOn', () => { @@ -222,7 +226,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Topic1']).not.toEqual(result['Topic2']); + expect(result.Topic1).not.toEqual(result.Topic2); }); test('almost identical resources - dependency via different intrinsic functions', () => { @@ -250,7 +254,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Bucket1']).not.toBe(result['Bucket2']); + expect(result.Bucket1).not.toBe(result.Bucket2); }); test('ignores references to unknown resources', () => { @@ -269,7 +273,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); expect(Object.keys(result).length).toBe(1); - expect(result['MyResource']).toBeDefined(); + expect(result.MyResource).toBeDefined(); }); test('ignores CDK construct path', () => { @@ -296,7 +300,7 @@ describe('computeResourceDigests', () => { }, }; const result = computeResourceDigests(template); - expect(result['Q1']).toBe(result['Q2']); + expect(result.Q1).toBe(result.Q2); }); test('uses physical ID if present', () => { @@ -324,7 +328,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).toBe(result['Foo2']); + expect(result.Foo1).toBe(result.Foo2); }); test('uses physical ID if present - with dependencies', () => { @@ -360,7 +364,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Bucket1']).toBe(result['Bucket2']); + expect(result.Bucket1).toBe(result.Bucket2); }); test('different physical IDs lead to different digests', () => { @@ -388,7 +392,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).not.toBe(result['Foo2']); + expect(result.Foo1).not.toBe(result.Foo2); }); test('primaryIdentifier is a composite field - different values', () => { @@ -418,7 +422,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).not.toBe(result['Foo2']); + expect(result.Foo1).not.toBe(result.Foo2); }); test('primaryIdentifier is a composite field - same value', () => { @@ -448,7 +452,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).toBe(result['Foo2']); + expect(result.Foo1).toBe(result.Foo2); }); test('primaryIdentifier is a composite field but not all of them are set in the resource', () => { @@ -476,7 +480,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).not.toBe(result['Foo2']); + expect(result.Foo1).not.toBe(result.Foo2); }); test('resource properties does not contain primaryIdentifier - different values', () => { @@ -502,7 +506,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).not.toBe(result['Foo2']); + expect(result.Foo1).not.toBe(result.Foo2); }); test('resource properties does not contain primaryIdentifier - same value', () => { @@ -528,7 +532,7 @@ describe('computeResourceDigests', () => { }; const result = computeResourceDigests(template); - expect(result['Foo1']).toBe(result['Foo2']); + expect(result.Foo1).toBe(result.Foo2); }); }); @@ -1006,6 +1010,7 @@ describe('typed mappings', () => { }); test('stack filtering', () => { + // eslint-disable-next-line @typescript-eslint/no-shadow const environment = { name: 'prod', account: '123456789012', diff --git a/packages/aws-cdk/test/api/resource-import/import.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/resource-import/import.test.ts similarity index 98% rename from packages/aws-cdk/test/api/resource-import/import.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/resource-import/import.test.ts index 1c2e72049..dc26c4a28 100644 --- a/packages/aws-cdk/test/api/resource-import/import.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/resource-import/import.test.ts @@ -16,10 +16,11 @@ import { } from '@aws-sdk/client-cloudformation'; import * as promptly from 'promptly'; import { Deployments } from '../../../lib/api/deployments'; -import { ResourceImporter, ImportMap, ResourceImporterProps } from '../../../lib/api/resource-import'; +import type { ImportMap, ResourceImporterProps } from '../../../lib/api/resource-import'; +import { ResourceImporter } from '../../../lib/api/resource-import'; import { testStack } from '../../_helpers/assembly'; import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; -import { TestIoHost } from '../../_helpers/io-host'; +import { TestIoHost } from '../../_helpers/test-io-host'; const promptlyConfirm = promptly.confirm as jest.Mock; const promptlyPrompt = promptly.prompt as jest.Mock; diff --git a/packages/aws-cdk/test/api/rwlock.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/rwlock.test.ts similarity index 99% rename from packages/aws-cdk/test/api/rwlock.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/rwlock.test.ts index 53d18ac13..7c01c9319 100644 --- a/packages/aws-cdk/test/api/rwlock.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/rwlock.test.ts @@ -81,4 +81,4 @@ test('can release reader lock more than once, second invocation does nothing', a await r.release(); expect(unlink).toHaveBeenCalledTimes(1); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk/test/api/settings.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/settings.test.ts similarity index 100% rename from packages/aws-cdk/test/api/settings.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/settings.test.ts diff --git a/packages/aws-cdk/test/api/stack-events/progress-monitor.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/progress-monitor.test.ts similarity index 99% rename from packages/aws-cdk/test/api/stack-events/progress-monitor.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/stack-events/progress-monitor.test.ts index 252452550..4c4feeb89 100644 --- a/packages/aws-cdk/test/api/stack-events/progress-monitor.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/progress-monitor.test.ts @@ -70,7 +70,6 @@ test('prints 0/4 progress report, when addActivity is called with an "UPDATE_FAI expect(stackProgress.formatted).toStrictEqual('0/4'); }); - test('prints " 1" progress report, when number of resources is unknown and addActivity is called with an "UPDATE_COMPLETE" ResourceStatus', () => { const stackProgress = new StackProgressMonitor(); diff --git a/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-activity-monitor.test.ts similarity index 97% rename from packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-activity-monitor.test.ts index 9d73d9f40..9afb67f9a 100644 --- a/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-activity-monitor.test.ts @@ -4,18 +4,18 @@ import { type StackEvent, StackStatus, } from '@aws-sdk/client-cloudformation'; -import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; +import type { IIoHost } from '../../../lib/api/io'; +import { asIoHelper } from '../../../lib/api/io/private'; import { StackActivityMonitor } from '../../../lib/api/stack-events'; import { testStack } from '../../_helpers/assembly'; -import { asIoHelper } from '../../../../@aws-cdk/toolkit-lib/lib/api/io/private'; -import { IIoHost } from '../../../../@aws-cdk/toolkit-lib/lib/api/io'; +import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; let sdk: MockSdk; let monitor: StackActivityMonitor; let ioHost: IIoHost = { notify: jest.fn(), requestResponse: jest.fn().mockImplementation((msg) => msg.defaultResponse), -} +}; beforeEach(async () => { sdk = new MockSdk(); @@ -48,7 +48,6 @@ describe('stack monitor event ordering and pagination', () => { expect(ioHost.notify).toHaveBeenNthCalledWith(2, expectEvent(101)); expect(ioHost.notify).toHaveBeenNthCalledWith(3, expectEvent(102)); expect(ioHost.notify).toHaveBeenNthCalledWith(4, expectStop()); - }); test('do not page further if we already saw the last event', async () => { @@ -280,6 +279,6 @@ const expectStop = () => expect.objectContaining({ code: 'CDK_TOOLKIT_I5503' }); const expectEvent = (id: number) => expect.objectContaining({ code: 'CDK_TOOLKIT_I5502', data: expect.objectContaining({ - event: expect.objectContaining({ 'EventId': String(id) }) - }) + event: expect.objectContaining({ EventId: String(id) }), + }), }); diff --git a/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-event-poller.test.ts similarity index 92% rename from packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-event-poller.test.ts index def1dd977..844e589ce 100644 --- a/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/stack-events/stack-event-poller.test.ts @@ -1,4 +1,5 @@ -import { DescribeStackEventsCommand, DescribeStackEventsCommandInput, StackEvent } from '@aws-sdk/client-cloudformation'; +import type { DescribeStackEventsCommandInput, StackEvent } from '@aws-sdk/client-cloudformation'; +import { DescribeStackEventsCommand } from '@aws-sdk/client-cloudformation'; import { StackEventPoller } from '../../../lib/api/stack-events'; import { MockSdk, mockCloudFormationClient } from '../../_helpers/mock-sdk'; @@ -7,9 +8,7 @@ beforeEach(() => { }); describe('poll', () => { - test('polls all necessary pages', async () => { - const deployTime = Date.now(); const postDeployEvent1: StackEvent = { @@ -43,11 +42,9 @@ describe('poll', () => { const events = await poller.poll(); expect(events.length).toEqual(2); - }); test('does not poll unnecessary pages', async () => { - const deployTime = Date.now(); const preDeployTimeEvent: StackEvent = { @@ -59,7 +56,6 @@ describe('poll', () => { const sdk = new MockSdk(); mockCloudFormationClient.on(DescribeStackEventsCommand).callsFake((input: DescribeStackEventsCommandInput) => { - // the first event we return should stop the polling. we therefore // do not expect a second page to be polled. expect(input.NextToken).toBe(undefined); @@ -68,7 +64,6 @@ describe('poll', () => { StackEvents: [preDeployTimeEvent], NextToken: input.NextToken === 'token' ? undefined : 'token', // simulate a two page event stream. }; - }); const poller = new StackEventPoller(sdk.cloudFormation(), { @@ -77,7 +72,5 @@ describe('poll', () => { }); await poller.poll(); - }); - }); diff --git a/packages/aws-cdk/test/api/tree.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/tree.test.ts similarity index 92% rename from packages/aws-cdk/test/api/tree.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/tree.test.ts index d3b720b69..e7f85125c 100644 --- a/packages/aws-cdk/test/api/tree.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/tree.test.ts @@ -1,6 +1,7 @@ /* eslint-disable import/order */ import * as path from 'path'; -import { ConstructTreeNode, loadTreeFromDir, some } from '../../lib/api/tree'; +import type { ConstructTreeNode } from '../../lib/api/tree'; +import { loadTreeFromDir, some } from '../../lib/api/tree'; describe('some', () => { const tree: ConstructTreeNode = { @@ -104,12 +105,14 @@ describe('some', () => { describe('loadTreeFromDir', () => { test('can find tree', () => { - const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'built-with-1_144_0'), () => {}); + const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'built-with-1_144_0'), () => { + }); expect(tree?.id).toEqual('App'); }); test('cannot find tree', () => { - const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'foo'), () => {}); + const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'foo'), () => { + }); expect(tree).toEqual(undefined); }); }); diff --git a/packages/aws-cdk/test/api/work-graph/work-graph-builder.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph-builder.test.ts similarity index 94% rename from packages/aws-cdk/test/api/work-graph/work-graph-builder.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph-builder.test.ts index 3a5ab3746..92cb641ae 100644 --- a/packages/aws-cdk/test/api/work-graph/work-graph-builder.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph-builder.test.ts @@ -1,16 +1,16 @@ import * as fs from 'fs'; import * as path from 'path'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import * as cxapi from '@aws-cdk/cx-api'; +import type * as cxapi from '@aws-cdk/cx-api'; import { CloudAssemblyBuilder } from '@aws-cdk/cx-api'; // eslint-disable-next-line import/no-extraneous-dependencies import { expect } from '@jest/globals'; -import { WorkGraph, WorkGraphBuilder } from '../../../lib/api/work-graph'; -import type { AssetBuildNode, AssetPublishNode, StackNode, WorkNode } from '../../../lib/api/work-graph'; -import { TestIoHost } from '../../_helpers/io-host'; +import { WorkGraphBuilder } from '../../../lib/api/work-graph'; +import type { AssetBuildNode, AssetPublishNode, StackNode, WorkNode, WorkGraph } from '../../../lib/api/work-graph'; +import { TestIoHost } from '../../_helpers/test-io-host'; let rootBuilder: CloudAssemblyBuilder; -let mockMsg = new TestIoHost().asHelper('deploy') +let mockMsg = new TestIoHost().asHelper('deploy'); beforeEach(() => { rootBuilder = new CloudAssemblyBuilder(); @@ -109,9 +109,15 @@ test('can handle nested assemblies', async () => { const graph = new WorkGraphBuilder(mockMsg, true).build(assembly.artifacts); await graph.doParallel(10, { - deployStack: async () => { workDone += 1; }, - buildAsset: async () => { }, - publishAsset: async () => { workDone += 1; }, + deployStack: async () => { + workDone += 1; + }, + buildAsset: async () => { + + }, + publishAsset: async () => { + workDone += 1; + }, }); // The asset is shared between parent assembly and nested assembly, but the stacks will be deployed @@ -368,9 +374,15 @@ function assertableNode(x: A) { async function traverseAndRecord(graph: WorkGraph) { const ret: string[] = []; await graph.doParallel(1, { - deployStack: async (node) => { ret.push(node.id); }, - buildAsset: async (node) => { ret.push(node.id); }, - publishAsset: async (node) => { ret.push(node.id); }, + deployStack: async (node) => { + ret.push(node.id); + }, + buildAsset: async (node) => { + ret.push(node.id); + }, + publishAsset: async (node) => { + ret.push(node.id); + }, }); return ret; } diff --git a/packages/aws-cdk/test/api/work-graph/work-graph.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph.test.ts similarity index 99% rename from packages/aws-cdk/test/api/work-graph/work-graph.test.ts rename to packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph.test.ts index cd4a96150..30af50784 100644 --- a/packages/aws-cdk/test/api/work-graph/work-graph.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/work-graph/work-graph.test.ts @@ -1,6 +1,6 @@ -import { TestIoHost } from '../../_helpers/io-host'; import { WorkGraph, DeploymentState } from '../../../lib/api/work-graph'; import type { AssetBuildNode, AssetPublishNode, StackNode } from '../../../lib/api/work-graph'; +import { TestIoHost } from '../../_helpers/test-io-host'; const DUMMY: any = 'DUMMY'; diff --git a/packages/aws-cdk/test/context-providers/amis.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/amis.test.ts similarity index 87% rename from packages/aws-cdk/test/context-providers/amis.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/amis.test.ts index 8297f338b..4849c9481 100644 --- a/packages/aws-cdk/test/context-providers/amis.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/amis.test.ts @@ -1,13 +1,14 @@ import 'aws-sdk-client-mock'; import { DescribeImagesCommand } from '@aws-sdk/client-ec2'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { AmiContextProviderPlugin } from '../../lib/context-providers/ami'; import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockEC2Client } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/asymmetric-vpcs.test.ts similarity index 100% rename from packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/asymmetric-vpcs.test.ts diff --git a/packages/aws-cdk/test/context-providers/availability-zones.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/availability-zones.test.ts similarity index 84% rename from packages/aws-cdk/test/context-providers/availability-zones.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/availability-zones.test.ts index 09a4c37a6..8c39ebfb0 100644 --- a/packages/aws-cdk/test/context-providers/availability-zones.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/availability-zones.test.ts @@ -1,12 +1,13 @@ import { DescribeAvailabilityZonesCommand } from '@aws-sdk/client-ec2'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { AZContextProviderPlugin } from '../../lib/context-providers/availability-zones'; import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/cc-api-provider.test.ts similarity index 99% rename from packages/aws-cdk/test/context-providers/cc-api-provider.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/cc-api-provider.test.ts index fd1a19bcd..f4a419ab7 100644 --- a/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/cc-api-provider.test.ts @@ -558,7 +558,7 @@ function createResourceNotFoundException() { return new ResourceNotFoundException({ $metadata: {}, message: 'Resource not found', - Message: 'Resource not found' + Message: 'Resource not found', }); } @@ -566,6 +566,6 @@ function createOtherError() { return new InvalidRequestException({ $metadata: {}, message: 'Other error', - Message: 'Other error' + Message: 'Other error', }); } diff --git a/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/endpoint-service-availability-zones.test.ts similarity index 85% rename from packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/endpoint-service-availability-zones.test.ts index 80eaab8e5..402d3e6a7 100644 --- a/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/endpoint-service-availability-zones.test.ts @@ -1,14 +1,15 @@ import { DescribeVpcEndpointServicesCommand } from '@aws-sdk/client-ec2'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { EndpointServiceAZContextProviderPlugin, } from '../../lib/context-providers/endpoint-service-availability-zones'; import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/generic.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/generic.test.ts similarity index 98% rename from packages/aws-cdk/test/context-providers/generic.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/generic.test.ts index 537e87bf1..05f0bd971 100644 --- a/packages/aws-cdk/test/context-providers/generic.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/generic.test.ts @@ -3,7 +3,7 @@ import { PluginHost } from '../../lib/api/plugin'; import * as contextproviders from '../../lib/context-providers'; import { Context, TRANSIENT_CONTEXT_KEY } from '../../lib/api/context'; import { MockSdkProvider, setDefaultSTSMocks } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const ioHost = new TestIoHost(); const ioHelper = ioHost.asHelper(); diff --git a/packages/aws-cdk/test/context-providers/hosted-zones.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/hosted-zones.test.ts similarity index 92% rename from packages/aws-cdk/test/context-providers/hosted-zones.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/hosted-zones.test.ts index 539b3332f..f38a50c9b 100644 --- a/packages/aws-cdk/test/context-providers/hosted-zones.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/hosted-zones.test.ts @@ -1,12 +1,13 @@ import { GetHostedZoneCommand, ListHostedZonesByNameCommand } from '@aws-sdk/client-route-53'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { HostedZoneContextProviderPlugin } from '../../lib/context-providers/hosted-zones'; import { FAKE_CREDENTIAL_CHAIN, mockRoute53Client, MockSdkProvider } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/keys.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/keys.test.ts similarity index 100% rename from packages/aws-cdk/test/context-providers/keys.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/keys.test.ts diff --git a/packages/aws-cdk/test/context-providers/load-balancers.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/load-balancers.test.ts similarity index 99% rename from packages/aws-cdk/test/context-providers/load-balancers.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/load-balancers.test.ts index 42595d605..bcd104833 100644 --- a/packages/aws-cdk/test/context-providers/load-balancers.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/load-balancers.test.ts @@ -4,7 +4,8 @@ import { DescribeLoadBalancersCommand, DescribeTagsCommand, } from '@aws-sdk/client-elastic-load-balancing-v2'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { LoadBalancerListenerContextProviderPlugin, LoadBalancerContextProviderPlugin, @@ -15,11 +16,11 @@ import { mockElasticLoadBalancingV2Client, restoreSdkMocksToDefault, } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/ssm-parameters.test.ts similarity index 86% rename from packages/aws-cdk/test/context-providers/ssm-parameters.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/ssm-parameters.test.ts index 249bfbc97..234915158 100644 --- a/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/context-providers/ssm-parameters.test.ts @@ -1,12 +1,13 @@ import { GetParameterCommand } from '@aws-sdk/client-ssm'; -import { SDK, SdkForEnvironment } from '../../lib/api'; +import type { SdkForEnvironment } from '../../lib/api/aws-auth/private'; +import { SDK } from '../../lib/api/aws-auth/private'; import { SSMContextProviderPlugin } from '../../lib/context-providers/ssm-parameters'; import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockSSMClient, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; -import { TestIoHost } from '../_helpers/io-host'; +import { TestIoHost } from '../_helpers/test-io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { - return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper("deploy")), didAssumeRole: false }); + return Promise.resolve({ sdk: new SDK(FAKE_CREDENTIAL_CHAIN, mockSDK.defaultRegion, {}, new TestIoHost().asHelper('deploy')), didAssumeRole: false }); } })(); diff --git a/packages/aws-cdk/test/context-providers/vpcs.test.ts b/packages/@aws-cdk/toolkit-lib/test/context-providers/vpcs.test.ts similarity index 100% rename from packages/aws-cdk/test/context-providers/vpcs.test.ts rename to packages/@aws-cdk/toolkit-lib/test/context-providers/vpcs.test.ts diff --git a/packages/aws-cdk/jest.config.json b/packages/aws-cdk/jest.config.json index fd4a38800..385b75afe 100644 --- a/packages/aws-cdk/jest.config.json +++ b/packages/aws-cdk/jest.config.json @@ -8,10 +8,10 @@ "testEnvironment": "./test/_helpers/jest-bufferedconsole.ts", "coverageThreshold": { "global": { - "statements": 82, - "branches": 74, + "statements": 81, + "branches": 76, "functions": 87, - "lines": 82 + "lines": 81 } }, "collectCoverage": true, diff --git a/packages/aws-cdk/test/cxapp/assembly-versions.ts b/packages/aws-cdk/test/_helpers/assembly-versions.ts similarity index 100% rename from packages/aws-cdk/test/cxapp/assembly-versions.ts rename to packages/aws-cdk/test/_helpers/assembly-versions.ts diff --git a/packages/aws-cdk/test/_helpers/assembly.ts b/packages/aws-cdk/test/_helpers/assembly.ts index d735db589..81a7d7a0e 100644 --- a/packages/aws-cdk/test/_helpers/assembly.ts +++ b/packages/aws-cdk/test/_helpers/assembly.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { ArtifactMetadataEntryType, ArtifactType, type AssetManifest, type AssetMetadataEntry, type AwsCloudFormationStackProperties, type MetadataEntry, type MissingContext } from '@aws-cdk/cloud-assembly-schema'; import { type CloudAssembly, CloudAssemblyBuilder, type CloudFormationStackArtifact, type StackMetadata } from '@aws-cdk/cx-api'; -import { cxapiAssemblyWithForcedVersion } from '../cxapp/assembly-versions'; +import { cxapiAssemblyWithForcedVersion } from './assembly-versions'; import { MockSdkProvider } from '../_helpers/mock-sdk'; import { CloudExecutable } from '../../lib/cxapp/cloud-executable'; import { Configuration } from '../../lib/cli/user-configuration'; diff --git a/packages/aws-cdk/test/util/mock-child_process.ts b/packages/aws-cdk/test/_helpers/mock-child_process.ts similarity index 100% rename from packages/aws-cdk/test/util/mock-child_process.ts rename to packages/aws-cdk/test/_helpers/mock-child_process.ts diff --git a/packages/aws-cdk/test/cxapp/cloud-assembly.test.ts b/packages/aws-cdk/test/cxapp/cloud-assembly.test.ts index 111fda9db..3aa912c54 100644 --- a/packages/aws-cdk/test/cxapp/cloud-assembly.test.ts +++ b/packages/aws-cdk/test/cxapp/cloud-assembly.test.ts @@ -2,7 +2,7 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import { DefaultSelection } from '../../lib/cxapp/cloud-assembly'; import { MockCloudExecutable } from '../_helpers/assembly'; -import { cliAssemblyWithForcedVersion } from './assembly-versions'; +import { cliAssemblyWithForcedVersion } from '../_helpers/assembly-versions'; test('select all top level stacks in the presence of nested assemblies', async () => { // GIVEN diff --git a/packages/aws-cdk/test/cxapp/exec.test.ts b/packages/aws-cdk/test/cxapp/exec.test.ts index 9a6dc6f15..f88ed494a 100644 --- a/packages/aws-cdk/test/cxapp/exec.test.ts +++ b/packages/aws-cdk/test/cxapp/exec.test.ts @@ -8,10 +8,10 @@ import { ImportMock } from 'ts-mock-imports'; import { execProgram } from '../../lib/cxapp/exec'; import { Configuration } from '../../lib/cli/user-configuration'; import { testAssembly } from '../_helpers/assembly'; -import { mockSpawn } from '../util/mock-child_process'; +import { mockSpawn } from '../_helpers/mock-child_process'; import { MockSdkProvider } from '../_helpers/mock-sdk'; import { RWLock } from '../../lib/api/rwlock'; -import { rewriteManifestMinimumCliVersion, rewriteManifestVersion } from './assembly-versions'; +import { rewriteManifestMinimumCliVersion, rewriteManifestVersion } from '../_helpers/assembly-versions'; import { TestIoHost } from '../_helpers/io-host'; import { ToolkitError } from '../../../@aws-cdk/toolkit-lib/lib/api'; diff --git a/packages/aws-cdk/test/stage-manifest/manifest.json b/packages/aws-cdk/test/stage-manifest/manifest.json deleted file mode 100644 index 4eb5c5743..000000000 --- a/packages/aws-cdk/test/stage-manifest/manifest.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "31.0.0", - "artifacts": { - "StageA.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "StageA.assets.json" - } - }, - "NestedStageA": { - "type": "aws:cloudformation:stack", - "environment": "aws://unknown-account/unknown-region", - "properties": { - "templateFile": "StageA.template.json", - "additionalDependencies": [ - "StageA.assets" - ] - }, - "dependencies": [ - "StageA.assets" - ] - } - } -} \ No newline at end of file diff --git a/packages/cdk-assets/test/logging.test.ts b/packages/cdk-assets/test/logging.test.ts index d950b5180..2c4672870 100644 --- a/packages/cdk-assets/test/logging.test.ts +++ b/packages/cdk-assets/test/logging.test.ts @@ -8,6 +8,9 @@ import mockfs from './mock-fs'; import type { LogLevel } from '../bin/logging'; import { setLogThreshold, log } from '../bin/logging'; +// 20s - some longer running tests +jest.setTimeout(20_000); + describe('Logging System', () => { let consoleErrorSpy: jest.SpyInstance; const originalConsoleError = console.error;