Skip to content

refactor(handlers): introduce repository layer for external-id-audit-handler (#1237 pattern) - #1287

Merged
susumutomita merged 1 commit into
mainfrom
refactor/handlers-via-repository-1237
May 24, 2026
Merged

susumutomita merged 1 commit into
mainfrom
refactor/handlers-via-repository-1237

Conversation

@susumutomita

Copy link
Copy Markdown
Owner

Summary

Move every direct @aws-sdk/* import out of external-id-audit-handler/index.ts into a dedicated repository module. The handler now consumes plain JS objects from a single typed boundary; the repository owns AWS SDK Command construction + DynamoDB marshalling.

This PR demonstrates the migration pattern Issue #1237 calls for, using one representative handler as the proof-of-concept. Follow-up PRs continue the same extraction for the remaining baselined handlers (describe-stack-handler, generic-scoring-handler, portal-handler, etc).

Changes

  • new infrastructure/lib/problem-deploy/handlers/external-id-audit-handler/repository.ts (165 lines) — owns CloudWatch + DynamoDB + lib-dynamodb client construction, Command shapes, and item marshalling
  • index.ts shrinks from 167 → 118 lines and contains zero SDK imports
  • new infrastructure/test/.../external-id-audit-handler-repository.test.ts (116 lines) — 8 unit cases asserting PutItemCommand / GetItemCommand / QueryCommand / PutMetricDataCommand are built with the expected shape (PK / SK / TTL / metric dimensions)
  • existing handler test (external-id-audit-handler.test.ts) updated to mock the repository (not the SDK directly) — coverage preserved, mock boundary clearer
  • .claude/harness/baselines/handler-no-direct-sdk-import.json — 6 baselined SDK-import violations removed (external-id-audit-handler is now clean per the rule introduced in feat(#986): SOLID 強制を harness に実装 (file-too-large / handler-no-direct-sdk-import + biome complexity) #1004)

Closes #1237

Regression analysis

  • Behavior-preserving: same DDB items, same DDB schema, same TTL, same CloudWatch metric dimensions, same retry behavior, same StatusCodes.
  • Existing 8 handler tests pass against the new repository indirection.
  • New 8 repository tests assert the SDK Command shapes that the handler used to construct inline — guards against drift.
  • Risk: low — narrow scope, one handler, behavior pinned by two test suites (route + command shape).

Physical impact

  • NO-OP for CloudFormation / IAM / Lambda runtime — the Lambda still calls the same AWS APIs with the same parameters.
  • UPDATE: external-id-audit-handler Lambda bundle (separation of concerns; no runtime behavior change; minified bytes nearly identical).
  • NEW FILES: repository.ts (impl) + *-repository.test.ts (test).
  • DELETE: 6 entries removed from .claude/harness/baselines/handler-no-direct-sdk-import.json.

Migration roadmap (for follow-up PRs)

Remaining baselined handlers (each ~1 PR worth):

…handler

Move all direct @aws-sdk/* imports (CloudWatch, DynamoDB, lib-dynamodb)
out of the route handler into a dedicated repository module. The handler
now consumes plain JS objects from a single typed boundary; the
repository owns AWS SDK Command construction + marshalling.

Demonstrates the migration pattern that Issue #1237 calls for. Follow-up
PRs continue the same extraction for the remaining baselined handlers
(describe-stack-handler / generic-scoring-handler / portal-handler etc).

- new infrastructure/lib/.../external-id-audit-handler/repository.ts
- index.ts shrinks from 167 to 118 lines, no SDK imports remain
- new infrastructure/test/.../external-id-audit-handler-repository.test.ts
  asserts SDK Command shapes (PutItem / GetItem / Query / PutMetricData)
- existing handler test updated to mock the repository (not the SDK)

Closes #1237
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@susumutomita, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 38 minutes and 45 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b67ec24-ee76-4a61-abec-0d8a0c7a1e6b

📥 Commits

Reviewing files that changed from the base of the PR and between eaa6cd1 and 253b29c.

📒 Files selected for processing (5)
  • .claude/harness/baselines/handler-no-direct-sdk-import.json
  • infrastructure/lib/problem-deploy/handlers/external-id-audit-handler/index.ts
  • infrastructure/lib/problem-deploy/handlers/external-id-audit-handler/repository.ts
  • infrastructure/test/problem-deploy/external-id-audit-handler-repository.test.ts
  • infrastructure/test/problem-deploy/external-id-audit-handler.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/handlers-via-repository-1237

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@eaa6cd1). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...y/handlers/external-id-audit-handler/repository.ts 66.66% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1287   +/-   ##
=======================================
  Coverage        ?   64.28%           
=======================================
  Files           ?      253           
  Lines           ?     8476           
  Branches        ?     2673           
=======================================
  Hits            ?     5449           
  Misses          ?     2199           
  Partials        ?      828           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@susumutomita
susumutomita merged commit 883047b into main May 24, 2026
10 checks passed
@susumutomita
susumutomita deleted the refactor/handlers-via-repository-1237 branch May 24, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tech-debt] Move handler direct SDK imports behind repository layer

1 participant