Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 40/add cdk test #47

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run lint
cdk-snapshot-test:
name: 'CDK snapshot test'
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run cdk:test
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"web:build": "npm -w packages/web run build",
"web:lint": "npm -w packages/web run lint",
"cdk:deploy": "npm -w packages/cdk run cdk deploy --",
"cdk:watch": "npm -w packages/cdk run cdk watch --",
"cdk:lint": "npm -w packages/cdk run lint"
"cdk:watch": "npm -w packages/cdk run cdk watch",
"cdk:lint": "npm -w packages/cdk run lint",
"cdk:test": "npm -w packages/cdk run test"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/cdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
},
snapshotSerializers: ['<rootDir>/test/snapshot-serializer.ts']
};
4 changes: 2 additions & 2 deletions packages/cdk/lib/generative-ai-use-cases-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export class GenerativeAiUseCasesStack extends Stack {
});

new CfnOutput(this, 'SageMakerEndpointName', {
value: JSON.stringify(llm.endpointName),
value: llm.endpointName,
});

new CfnOutput(this, 'SageMakerEndpointConfigName', {
value: JSON.stringify(llm.endpointConfigName),
value: llm.endpointConfigName,
});

new CfnOutput(this, 'SageMakerModels', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ exports[`snapshot test 1`] = `
},
},
"SageMakerEndpointConfigName": {
"Value": ""llm-jp-endpoint-config-20231120155217"",
"Value": "llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
},
"SageMakerEndpointName": {
"Value": ""llm-jp-endpoint"",
"Value": "llm-jp-endpoint",
},
"SageMakerModels": {
"Value": "[{"name":"llm-jp-13b-instruct-full-jaster-dolly-oasst-v1","path":"models/llm-jp-13b-instruct-full-jaster-dolly-oasst-v1.0.tar.gz","prompt_template_name":"llmJp"},{"name":"llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1","path":"models/llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1.0.tar.gz","prompt_template_name":"llmJp"}]",
Expand Down Expand Up @@ -2394,7 +2394,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "0caa1d8af824f7f430dafafd4695dc8cc7110ec4df0381f392ff886a9f4c4ac6.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -2505,7 +2505,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "c6d740f94d4bc9b54b9f5b1a24e394a8955da2d090a59767e15b66898198b6e3.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -2616,7 +2616,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "53a78b9548c47bff5f2f89de6960dba7b34f3191fa0de8f9568e7c0879bc6be1.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -2750,7 +2750,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "94b426ba0e898f8941f047304a96c20cf4766ca3e49dcae506d497f8025d2a95.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -2857,7 +2857,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -2888,7 +2888,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "af80ccfe8ea89fc0cf935a813dcbff05de72e65af9454183991a4f5a112c086f.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3002,7 +3002,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "12d091d805a4af41db11fc3394d783c38c1a5663de8f7837ff849266dd81cc77.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3116,7 +3116,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "42f548eefa37899f7e461aa78e3cd25bf820ffe93b88601d13a06c3dc46368bc.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3256,7 +3256,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "8c9107561407eafbb311cc5aff53c31b0b7ae9efad6268c4ac64acc0048413ae.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3352,7 +3352,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -3380,7 +3380,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "2494269eec98c2557e532c8510ca7d18e08af37a3fc0c1ed3c7489217430b03f.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3476,7 +3476,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -3504,7 +3504,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b583b7211458a029b03a75fbe15afe3f17a10b8ee881890c6960f405a6791df4.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3635,7 +3635,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -3663,7 +3663,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "4aab97388187755a6a859e129b2e86110a35aca89e829347e2d9f1e2728b811b.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3781,7 +3781,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "0d0177723cb72c44d7ea9744732331d85d40274fe871bf5b7ef0dff3c641a276.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3892,7 +3892,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "6f5a7b2920a8cb0b899d8d3f5726b5d1909094240bc0855d58fc4db057f9d478.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -3984,7 +3984,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -4012,12 +4012,12 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "a54f181e777572f64a1c5651572493ec5b360f107f8dc05454b3ff2848fcb49c.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
"AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1",
"ENDPOINT_CONFIG_NAME": "llm-jp-endpoint-config-20231120155217",
"ENDPOINT_CONFIG_NAME": "llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
"ENDPOINT_NAME": "llm-jp-endpoint",
},
},
Expand Down Expand Up @@ -4105,7 +4105,7 @@ exports[`snapshot test 1`] = `
{
"Ref": "AWS::AccountId",
},
":endpoint-config/llm-jp-endpoint-config-20231120155217",
":endpoint-config/llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
],
],
},
Expand Down Expand Up @@ -4142,7 +4142,7 @@ exports[`snapshot test 1`] = `
"destinationBucketName": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"destinationObjectKey": "fc887722ed888e2b9c9d5efd66439184.zip",
"destinationObjectKey": "[HASH REMOVED].zip",
"environment": {
"VITE_APP_API_ENDPOINT": {
"Fn::Join": [
Expand Down Expand Up @@ -4181,7 +4181,7 @@ exports[`snapshot test 1`] = `
"VITE_APP_REGION": {
"Ref": "AWS::Region",
},
"VITE_APP_SAGEMAKER_ENDPOINT_CONFIG_NAME": "llm-jp-endpoint-config-20231120155217",
"VITE_APP_SAGEMAKER_ENDPOINT_CONFIG_NAME": "llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
"VITE_APP_SAGEMAKER_ENDPOINT_NAME": "llm-jp-endpoint",
"VITE_APP_SAGEMAKER_MODELS": "[{"name":"llm-jp-13b-instruct-full-jaster-dolly-oasst-v1","path":"models/llm-jp-13b-instruct-full-jaster-dolly-oasst-v1.0.tar.gz","prompt_template_name":"llmJp"},{"name":"llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1","path":"models/llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1.0.tar.gz","prompt_template_name":"llmJp"}]",
"VITE_APP_SELF_SIGN_UP_ENABLED": "false",
Expand All @@ -4199,7 +4199,7 @@ exports[`snapshot test 1`] = `
"sourceBucketName": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"sourceObjectKey": "bdd91859d458b67f0c3e0f2823055b6e545d4ad150fd579076124f59660887ca.zip",
"sourceObjectKey": "[HASH REMOVED].zip",
},
],
"type": "NodejsBuild",
Expand All @@ -4217,7 +4217,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Description": "/opt/awscli/aws",
},
Expand Down Expand Up @@ -4248,7 +4248,7 @@ exports[`snapshot test 1`] = `
},
],
"SourceObjectKeys": [
"fc887722ed888e2b9c9d5efd66439184.zip",
"[HASH REMOVED].zip",
],
},
"Type": "Custom::CDKBucketDeployment",
Expand Down Expand Up @@ -5294,7 +5294,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "9eb41a5505d37607ac419321497a4f8c21cf0ee1f9b4a6b29aa04301aea5c7fd.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -5460,7 +5460,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b7f33614a69548d6bafe224d751a7ef238cde19097415e553fe8b63a4c8fd8a6.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Description": {
"Fn::Join": [
Expand Down Expand Up @@ -5572,7 +5572,7 @@ exports[`snapshot test 1`] = `
"LLMsagemakermodelllmjp13binstructlorajasterdollyoasstv1RoleF42A9559",
],
"Properties": {
"EndpointConfigName": "llm-jp-endpoint-config-20231120155217",
"EndpointConfigName": "llm-jp-endpoint-config-[TIMESTAMP REMOVED]",
"ProductionVariants": [
{
"InitialInstanceCount": 1,
Expand Down Expand Up @@ -5614,7 +5614,7 @@ exports[`snapshot test 1`] = `
"Arn",
],
},
"ModelName": "llm-jp-13b-instruct-full-jaster-dolly-oasst-v1-20231120155217",
"ModelName": "llm-jp-13b-instruct-full-jaster-dolly-oasst-v1-[TIMESTAMP REMOVED]",
"PrimaryContainer": {
"Image": {
"Fn::Join": [
Expand Down Expand Up @@ -5787,7 +5787,7 @@ exports[`snapshot test 1`] = `
"Arn",
],
},
"ModelName": "llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1-20231120155217",
"ModelName": "llm-jp-13b-instruct-lora-jaster-dolly-oasst-v1-[TIMESTAMP REMOVED]",
"PrimaryContainer": {
"Image": {
"Fn::Join": [
Expand Down Expand Up @@ -5958,7 +5958,7 @@ exports[`snapshot test 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b49cc8147b0bf86afefc1c551a4b5cf9165167cf31a5d50e4bf169f944f6a363.zip",
"S3Key": "[HASH REMOVED].zip",
},
"Handler": "index.handler",
"Role": {
Expand Down
4 changes: 4 additions & 0 deletions packages/cdk/test/serializer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Jestのシリアライザーにて、CDKで作成されるリソース名にタイムスタンプやハッシュ値など
ランダムな値が含まれる場合、それを除去する。


19 changes: 19 additions & 0 deletions packages/cdk/test/snapshot-serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
test: (val: unknown) => typeof val === "string",
serialize: (val: string) => {

let newVal = val.replace('"', '');

newVal = val.replace(
/([A-Fa-f0-9]{32}|[A-Fa-f0-9]{64})(\.zip)/,
'[HASH REMOVED].zip');

newVal = newVal.replace(
/-\d{14}$|-\d{14}$/,
'-[TIMESTAMP REMOVED]'
);

return `"${newVal}"`;

},
}
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"vite": "^4.4.5",
"vite-plugin-svgr": "^3.2.0"
}
}
}