test(cdk): スナップショットシリアライザのデッドパターン削除と軽微な堅牢化

Open Beginner friendly
#274 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
aws, node.js, typescript

Research direction

Start with apps/cdk/test/snapshot-plugin.ts and compare its serializer patterns with the generated cdk.out/*.template.json output. Run the apps/cdk test:unit command (vitest run) after removing the identified dead patterns; if hardening is included, regenerate snapshots with -u and inspect the diff. Done means the tests pass without unintended snapshot changes.

Written by the indexing model from the issue text.

Description

needs-triage

背景

apps/cdk/test/snapshot-plugin.ts は、cdk synth が出力する非決定的トークン(アセットハッシュ、Lambda Version 論理 ID 末尾のハッシュ等)を redact して CloudFormation スナップショットを安定させるシリアライザです。現在の合成テンプレートに照らすと、実際には何もマッチしていない置換パターン(デッド)が複数あり、加えて軽微な堅牢化の余地があります。

現状パターンと合成出力の突き合わせ

.replace(/([A-Fa-f0-9]{64}.zip)/, 'REDACTED')
.replace(/([A-Fa-f0-9]{64}.mjs)/, 'REDACTED')
.replace(/.*cdk-hnb659fds-container-assets-.*/, 'REDACTED')
.replace(/webapp-starter-[0-9a-z]*/, 'REDACTED')
.replace(/(.*CurrentVersion).*/, '$1REDACTED')

合成テンプレート(cdk.out/*.template.json)を確認した結果:

削除候補(デッド)
  • webapp-starter-[0-9a-z]*: 合成出力に webapp-starter-<suffix> 形の文字列は出現しない。[0-9a-z]* は 0 文字にマッチするため実質何も redact していない。削除してよい。
  • .*cdk-hnb659fds-container-assets-.*: 合成テンプレートに cdk-hnb659fds-container-assets- を含む文字列が存在しない(この構成のコンテナイメージはデプロイ時ビルドで作成される ECR リポジトリを参照し、bootstrap の container-assets リポジトリを参照しないため)。デッド。削除を検討。
維持(誤って削除しないこと)
  • .zip / .mjs: Lambda バンドルアセットの S3 キーのハッシュを redact。LIVE。
  • (.*CurrentVersion).*: Lambda Version 論理 ID 末尾のハッシュを redact。アプリ/依存の変更で変わる値のため維持が必要。LIVE。
軽微な堅牢化(任意)
  • .zip / .mjs パターンの . が未エスケープで任意 1 文字にマッチする → \. へ。
  • 同パターンに /g が無く、1 つの文字列値に 64hex が 2 つ以上現れると 2 個目以降が漏れる(現状は該当文字列 0 件のため実害はなく、保険)。
  • (.*CurrentVersion).* は貪欲マッチ。意図を明確化するなら CurrentVersion[A-Za-z0-9]*$ 等へアンカー。

受け入れ条件

  • デッドパターン削除後、apps/cdktest:unit(vitest run)でスナップショット差分が発生しない(=当該パターンが何も変えていなかったことの確認)。
  • 堅牢化を入れる場合はスナップショットを -u で再生成し、diff が意図どおりであることを確認。
Dominant language
TypeScript
Stars
229
Forks
45
Avg merge
1m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws-samples/serverless-full-stack-webapp-starter-kit

All issues in aws-samples/serverless-full-stack-webapp-starter-kit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.