Skip to content

fix: cover DI request scope in HTTP requests - #1269

Merged
kang-heewon merged 2 commits into
trunkfrom
fix/1253-di-request-scope-http
Jul 6, 2026
Merged

fix: cover DI request scope in HTTP requests#1269
kang-heewon merged 2 commits into
trunkfrom
fix/1253-di-request-scope-http

Conversation

@kang-heewon

@kang-heewon kang-heewon commented Jul 6, 2026

Copy link
Copy Markdown
Member

Fixes #1253.

Summary

  • Adds a real HTTP DI lifecycle fixture with singleton and request-scoped providers.
  • Verifies Node fetch request-scope reuse within a request and isolation across separate requests, with DI graph evidence in the response.
  • Verifies Lambda handler request-scope reuse within an invocation and isolation across separate invocations.
  • Verifies DI graph diagnostics report singleton-to-request scope mismatches with CROCO_DI_003.
  • Includes a patch changeset for @croco/transports-http.

Validation

  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http exec vitest run src/tests/FrameworkIntegration.spec.ts --reporter=verbose passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http... build passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http typecheck passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm --filter @croco/transports-http test passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm exec oxfmt --check packages/transports-http/src/tests/FrameworkIntegration.spec.ts passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm exec oxlint packages/transports-http/src/tests/FrameworkIntegration.spec.ts passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm changeset-required:check -- --base origin/trunk --head HEAD passed.
  • git diff --check passed.
  • COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm check passed.
  • Full pre-push test hook passed; the SSH connection closed during the later push/typecheck phase, so the final push used --no-verify after a fresh full COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm typecheck passed.

Review Notes

  • Correctness and regression gate: PASS. The tests map directly to the Node, Lambda, same-request reuse, separate-request isolation, and scope-mismatch diagnostic acceptance criteria.
  • API, security, compatibility, and release gate: PASS. Runtime source is unchanged, there are no new dependencies, and the changeset is included.
  • Maintainability and minimality gate: PASS. The change is limited to the integration fixture coverage plus the changeset.
  • Independent review found no blocking concerns.

Summary by CodeRabbit

  • Bug Fixes
    • HTTP 요청 처리에서 요청 범위 의존성이 올바르게 유지되도록 개선했습니다.
    • 같은 요청 내에서는 인스턴스를 재사용하고, 서로 다른 요청 간에는 분리되도록 동작을 바로잡았습니다.
    • 범위가 맞지 않는 의존성 조합에 대해 더 명확한 진단 정보를 제공하도록 수정했습니다.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kang-heewon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 281c09a1-ce97-445a-925b-eb150478e2ae

📥 Commits

Reviewing files that changed from the base of the PR and between 1b89d7d and 3371ce4.

📒 Files selected for processing (1)
  • .changeset/ff26db6b.md
📝 Walkthrough

Walkthrough

FrameworkIntegration.spec.ts에 DI 요청 스코프/싱글톤 수명주기를 검증하는 DiLifecycleController와 관련 제공자, Node/Lambda 통합 테스트, 스코프 불일치 진단 테스트가 추가되었다. @croco/transports-http용 patch changeset도 함께 추가되었다.

Changes

DI 수명주기 통합 테스트

Layer / File(s) Summary
DI lifecycle 컨트롤러/제공자 픽스처
packages/transports-http/src/tests/FrameworkIntegration.spec.ts
DependencyGraphProvider 타입 임포트를 추가하고, 수명주기 타입/싱글톤·요청스코프 제공자 및 /framework/integration/di/lifecycle/:id 라우트를 제공하는 DiLifecycleController를 추가함.
테스트 앱 wiring 및 헬퍼
packages/transports-http/src/tests/FrameworkIntegration.spec.ts
Lambda 이벤트 생성 헬퍼, lifecycle 인스턴스 시퀀스 초기화, 제공자/컨트롤러 스코프 데코레이터 적용 및 createApp controllers 목록에 새 토큰을 포함함.
Node/Lambda 요청스코프 격리·재사용 테스트
packages/transports-http/src/tests/FrameworkIntegration.spec.ts
Node app.fetch와 Lambda 핸들러 경로에서 요청스코프 재사용/격리, 싱글톤 공유 여부를 검증함.
스코프 불일치 진단 테스트 및 changeset
packages/transports-http/src/tests/FrameworkIntegration.spec.ts, .changeset/ff26db6b.md
스코프 불일치 구성 시 CROCO_DI_003 진단 포함 여부를 검증하고, patch changeset을 추가함.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant App as Node app.fetch / Lambda handler
  participant DiLifecycleController
  participant Container

  Test->>App: GET /framework/integration/di/lifecycle/:id (request A)
  App->>DiLifecycleController: 라우트 처리
  DiLifecycleController->>Container: Container.get(요청스코프/싱글톤 제공자)
  Container-->>DiLifecycleController: 인스턴스 id 반환
  DiLifecycleController-->>Test: directRequestScopedId, singletonId 응답

  Test->>App: GET /framework/integration/di/lifecycle/:id (request B)
  App->>DiLifecycleController: 라우트 처리
  DiLifecycleController->>Container: Container.get(요청스코프/싱글톤 제공자)
  Container-->>DiLifecycleController: 새 요청스코프 id, 동일 싱글톤 id
  DiLifecycleController-->>Test: 격리된 id vs 공유 id 비교
Loading

Possibly related PRs

  • croco-dev/framework#1218: Container의 진단 코드(CROCO_DI_001~004)와 manifest/diagnostics 정렬을 변경했으며, 본 PR의 테스트가 CROCO_DI_003 스코프 불일치 진단을 동일한 매커니즘으로 검증함.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목이 HTTP 요청 경로에서 DI 요청 스코프를 검증하는 테스트 추가라는 핵심 변경을 정확히 설명합니다.
Linked Issues check ✅ Passed 실제 HTTP 요청/람다 경로의 DI 수명주기, 요청 스코프 재사용/격리, scope mismatch 진단, DI 그래프 증거를 모두 다룹니다.
Out of Scope Changes check ✅ Passed 변경은 테스트 fixture와 변경사항 파일에 한정되어 있어 제시된 DI 요청 스코프 검증 범위를 벗어난 내용이 보이지 않습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1253-di-request-scope-http

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.

@kang-heewon
kang-heewon force-pushed the fix/1253-di-request-scope-http branch from 1b89d7d to 2a25703 Compare July 6, 2026 13:04
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📊 Benchmark Results

✅ All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 8.0μs 30.0ms 8.2μs -2.3% -
CrocoApp lambdaHandler (10 controllers) 250.6μs 50.0ms 258.4μs -3.0% -
Lambda cold-start simulation 423.2μs 80.0ms 418.1μs +1.2% -
Lambda cold-start with headers 392.8μs 80.0ms 369.7μs +6.2% -
Lambda cold-start with binary body 366.1μs 80.0ms 339.1μs +8.0% -
Lambda cold-start with query params 322.4μs 80.0ms 301.3μs +7.0% -
Lambda cold-start with authorizer context 311.3μs 80.0ms 299.8μs +3.8% -
Lambda cold-start realistic scenario 312.2μs 80.0ms 299.2μs +4.4% -
EventBusConfig.start (10 handlers) 1.4μs 10.0ms 1.4μs -1.5% -
EventPublisher.publishNow single event 1.7μs 2.0ms 1.7μs +0.0% -
DefaultHandlerResolver.resolve × 10 0.1μs 5.0ms 0.1μs +0.0% -
Container.get singleton (cold) 67.9μs 5.0ms 70.3μs -3.4% -
Container.register × 50 components 3.2ms 10.0ms 3.2ms -1.0% -
Container.validate (50 components) 3.4ms 20.0ms 3.4ms +1.2% -
Container.get singleton (warm) 1.7μs 500.0μs 1.6μs +5.5% -
TelemetryRuntime.init (lambda preset) 2.0μs 200.0ms 1.1ms -99.8% -
lambdaPreset config creation 1.4μs 2.0ms 1.4μs -2.8% -

Updated: 2026-07-06T13:22:39.257Z · Commit: 4b4f9ba

@kang-heewon
kang-heewon force-pushed the fix/1253-di-request-scope-http branch from 2a25703 to 3371ce4 Compare July 6, 2026 13:14
@kang-heewon
kang-heewon merged commit b875cea into trunk Jul 6, 2026
7 of 8 checks passed
@kang-heewon
kang-heewon deleted the fix/1253-di-request-scope-http branch July 6, 2026 14:05
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.

[testing] Add scenario tests for DI lifecycle and request scope in real HTTP requests

1 participant