Skip to content

[Test] Postgres 체크포인터 통합 테스트 + docker-compose 서비스#69

Merged
haein45 merged 4 commits into
devfrom
test/postgres-checkpoint
May 29, 2026
Merged

[Test] Postgres 체크포인터 통합 테스트 + docker-compose 서비스#69
haein45 merged 4 commits into
devfrom
test/postgres-checkpoint

Conversation

@haein45

@haein45 haein45 commented May 29, 2026

Copy link
Copy Markdown
Collaborator

📌 관련 이슈

🏷️ PR 타입

  • ✨ 기능 추가 (Feature)
  • 🐛 버그 수정 (Bug Fix)
  • ♻️ 리팩토링 (Refactoring)
  • 📝 문서 수정 (Documentation)
  • 🎨 스타일 변경 (Style)
  • ✅ 테스트 추가 (Test)

📝 작업 내용

  • pyproject.toml: postgres 마커 등록 (Daytona용 integration과 분리)
  • tests/integration/test_postgres_checkpoint.py: 실제 Postgres 통합 테스트 추가
    • 매 턴 새 연결로 2턴 호출 → turn2가 Postgres에서 역직렬화로 복원
    • CreditEntry/PlanStep이 dict 아닌 정상 Pydantic 타입으로 복원 (serde allowlist 실DB 검증)
    • 멀티턴 누적 + 턴 단위 정산 + thread 격리 검증
    • DATABASE_URL 없으면 skip (기본 스위트 영향 없음)
  • docker-compose.test.yml: 격리된 postgres(healthcheck) + test-pg 러너 서비스 추가
  • Dockerfile.test / .dockerignore 빌드 수정 (E2E 과정에서 발견):
    • .venv·중첩 *.egg-info·__pycache__ 제외 — 호스트 산물 복사로 인한 uv sync 권한 충돌 해소
    • Dockerfile.testchownCOPY 이후로 이동 — 복사 파일을 appuser 소유로 만들어 editable 빌드 가능

📸 스크린샷

Docker E2E (docker compose -f docker-compose.test.yml run --rm --build test-pg):

tests/integration/test_postgres_checkpoint.py::test_postgres_multiturn_restore_and_per_turn_settlement PASSED [ 50%]
tests/integration/test_postgres_checkpoint.py::test_postgres_threads_isolated PASSED [100%]
================= 2 passed, 112 deselected, 1 warning in 1.59s =================

✅ 체크리스트

  • 코드 리뷰를 받을 준비가 완료되었습니다
  • 테스트를 작성하고 모두 통과했습니다
  • 문서를 업데이트했습니다 (필요한 경우)
  • 코드 스타일 가이드를 준수했습니다
  • 셀프 리뷰를 완료했습니다

📎 기타 참고사항

Summary by CodeRabbit

릴리스 노트

  • Documentation

    • Postgres 체크포인터 통합 테스트 실행 방법 가이드 추가
    • pytest 실행 예시 및 테스트 설정 문서화
  • Tests

    • Postgres 체크포인터 멀티턴 복원 및 턴별 정산 통합 테스트 추가
    • 스레드 격리 동작 검증 테스트 추가
  • Chores

    • Docker 빌드 환경 구성 최적화
    • 테스트 실행 Postgres 서비스 설정 추가

Review Change Stack

haein45 added 2 commits May 29, 2026 23:21
- pyproject: postgres 마커 등록 (Daytona용 integration과 분리)
- tests/integration/test_postgres_checkpoint.py: 새 연결로 2턴 호출해 PG
  역직렬화(CreditEntry/PlanStep 타입 복원)·멀티턴 누적·턴 단위 정산 검증.
  DATABASE_URL 없으면 skip
- docker-compose.test.yml: 격리된 postgres(healthcheck) + test-pg 러너 추가
  → docker compose -f docker-compose.test.yml run --rm --build test-pg

기본 스위트(-m "not integration")는 DB 없이 통과 (postgres 테스트 skip).
로컬 Postgres로 통합 테스트 2개 통과 확인.
Postgres E2E를 Docker에서 돌리는 과정에서 발견된 Dockerfile.test 빌드 실패 수정:
- .dockerignore: 호스트 산물 .venv, 중첩 *.egg-info, __pycache__ 제외
  (이미지로 복사되면 uv sync editable 빌드가 권한 충돌)
- Dockerfile.test: chown을 COPY 이후로 이동 — 복사 파일을 appuser 소유로 만들어
  uv sync가 src/*.egg-info를 생성할 수 있게

docker compose -f docker-compose.test.yml run --rm --build test-pg → 2 passed.
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@haein45, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 12 seconds. Learn how PR review limits work.

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

⌛ How to resolve this issue?

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.

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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 875b66ee-392d-4377-8f95-c5d01f94d97c

📥 Commits

Reviewing files that changed from the base of the PR and between 9cfec41 and 04ab1a4.

📒 Files selected for processing (2)
  • docker-compose.test.yml
  • tests/integration/test_postgres_checkpoint.py
📝 Walkthrough

둘러보기

멀티턴 체크포인터의 Postgres 경로를 검증하기 위해 pytest 마커를 등록하고, Docker 빌드 환경을 정리하며, docker-compose에 격리된 Postgres 테스트 인프라를 추가하고, 상태 복원 및 타입 보존을 검증하는 통합 테스트를 구현했다.

변경 사항

Postgres 체크포인터 통합 테스트 추가

Layer / File(s) Summary
Pytest 마커 등록 및 Docker 빌드 환경 정리
pyproject.toml, .dockerignore, Dockerfile.test
[tool.pytest.ini_options].markerspostgres 마커를 등록하고, .dockerignore에 Python 가상환경(.venv/, venv/)과 빌드 산물(**/*.egg-info/, **/__pycache__/)을 추가한다. Dockerfile.test의 빌드 단계를 재정렬하여 uv 설치 후 /app 소유권을 appuser로 변경하고, USER appuser 컨텍스트에서 의존성 설치가 진행되도록 한다.
Docker Compose 테스트 서비스 정의
docker-compose.test.yml
Postgres 이미지(v15)를 사용하는 postgres 서비스를 추가하여 환경 변수, pg_isready 기반 healthcheck로 준비 상태를 관리한다. test-pg 서비스에서 postgres 서비스가 healthy 상태가 된 이후 DATABASE_URL과 PYTHONPATH를 주입받아 uv run pytest -m postgres -v를 실행하도록 구성한다.
Postgres 체크포인터 통합 테스트 구현
tests/integration/test_postgres_checkpoint.py
DATABASE_URL이 없으면 스킵하는 fixture를 제공한다. 동일한 thread_id로 두 턴을 실행하여 Postgres에서 상태 복원 시 credit_logCreditEntryplanPlanStep 타입이 보존되는지, 멀티턴 누적(total_credit_cost, settled_count)이 정확한지, 턴 단위 정산 메시지가 기대값과 일치하는지를 검증한다. 서로 다른 thread_id 간 체크포인트 격리를 검증하여 한 스레드의 상태가 다른 스레드로 누출되지 않음을 확인한다.
테스트 실행 가이드 문서
AGENTS.md
개발 명령어 섹션에 uv run pytest 예시를 추가하고, @pytest.mark.postgres 테스트의 skip 조건, docker-compose를 통한 격리된 환경 실행 방법, DATABASE_URL을 통한 로컬 실행 방법을 안내한다.

시퀀스 다이어그램

sequenceDiagram
  participant Developer
  participant docker-compose
  participant postgres_service
  participant test-pg_service
  participant pytest
  
  Developer->>docker-compose: docker-compose -f docker-compose.test.yml up
  docker-compose->>postgres_service: 서비스 시작
  postgres_service->>postgres_service: pg_isready 상태 확인
  docker-compose->>test-pg_service: 서비스 시작 (postgres 의존)
  postgres_service-->>test-pg_service: service_healthy 상태 도달
  test-pg_service->>test-pg_service: DATABASE_URL, PYTHONPATH 환경 변수 설정
  test-pg_service->>pytest: uv run pytest -m postgres 실행
  pytest->>postgres_service: 멀티턴 상태 읽기/쓰기
  pytest-->>test-pg_service: 테스트 결과
  test-pg_service-->>Developer: 테스트 완료 (통과/실패)
Loading

예상 코드 리뷰 노력

🎯 3 (보통) | ⏱️ ~20분

Docker 속 DB 서비스, 마커 붙인 테스트,
상태 복원 검증하는 터닝 로직,
Postgres 통합의 길을 닦네요. 🐇✨
격리된 환경에서 재현성 있는 검증,
멀티턴 누적과 타입 보존을 믿으면서! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 주요 변경사항(Postgres 체크포인터 통합 테스트 및 docker-compose 서비스 추가)을 명확하고 간결하게 요약합니다.
Description check ✅ Passed PR 설명이 템플릿의 주요 섹션(관련 이슈, PR 타입, 작업 내용, 스크린샷, 체크리스트)을 모두 포함하고 있습니다.
Linked Issues check ✅ Passed 모든 코드 변경사항이 이슈 #68의 요구사항을 충족합니다: postgres 마커 등록, 통합 테스트 추가, docker-compose 서비스, Dockerfile 수정, 문서화.
Out of Scope Changes check ✅ Passed 모든 변경사항이 이슈 #68의 범위 내이며, 추가 변경(Dockerfile, .dockerignore, AGENTS.md)도 통합 테스트 실행을 위한 필수 빌드 수정입니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/postgres-checkpoint

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.

@haein45 haein45 self-assigned this May 29, 2026
@haein45 haein45 added the 혜인 label May 29, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요약

Postgres 체크포인터 통합 테스트와 Docker(chown 순서, .dockerignore) 수정 방향은 적절하며, 턴마다 open_checkpointer로 새 연결을 여는 구성이 운영에서의 재연결·역직렬화 시나리오를 InMemory 테스트보다 잘 검증합니다. CreditEntry/PlanStepisinstance 검증은 serde allowlist 회귀에 실질적 가치가 있습니다. 다만 프로덕션 체크포인트 키 형식·CI 자동화·일부 assertion 강도에서 보완 여지가 있습니다.


[문제 1]

  • 심각도: Medium
  • 범주: 유지보수성
  • 근거: postgres 마커 테스트는 docker compose -f docker-compose.test.yml run test-pg로만 실행되며, .github/workflows/에는 deploy만 있고 -m postgres 실행 단계가 없습니다. README도 uv run pytest만 안내해, 로컬/CI 기본 pytest에서는 DATABASE_URL 없을 때 skip되므로 serde·PG 역직렬화 회귀가 파이프라인에서 잡히지 않을 수 있습니다.
  • 수정안: (a) PR 또는 후속으로 services: postgres + pytest -m postgres를 돌리는 GitHub Actions job 추가, 또는 (b) 최소한 README/AGENTS.md에 docker compose -f docker-compose.test.yml run --rm --build test-pg 실행 방법을 명시.

[문제 2]

  • 심각도: Low(추가 확인 필요)
  • 범주: 정확성
  • 근거: 프로덕션 solve.pyconfigurable.thread_idf"{user_id}:{thread_id}"를 사용하지만, 통합 테스트는 raw thread_id만 넘깁니다. 멀티턴·정산 로직 검증은 tests/graph/test_multiturn.py와 거의 동일하고, 이 PR의 고유 가치(재연결 + PG serde) 와는 별개로, 네임스페이스된 키·콜론 포함 thread_id에서만 발생하는 이슈는 테스트가 커버하지 않을 수 있습니다.
  • 수정안: _run_turnconfig{"configurable": {"thread_id": f"u:{thread_id}"}}처럼 프로덕션과 동일하게 맞추거나, 해당 형식 전용 케이스를 하나 추가.

[문제 3]

  • 심각도: Low
  • 범주: 정확성
  • 근거: tests/graph/test_multiturn.pytest_multiturn_credit_settled_per_turnlen(settler_msgs) == 2로 턴마다 정산 메시지가 하나씩만 쌓이는지 검증하지만, Postgres 테스트는 마지막 메시지 내용만 검사합니다. PG 복원 후 메시지가 중복·누락되는 버그는 놓칠 수 있습니다.
  • 수정안: assert len(settler_msgs) == 2test_postgres_multiturn_restore_and_per_turn_settlement에도 추가.

리스크 참고(이슈로 분류하지 않음): docker-compose.test.ymlproovy/proovy 자격 증명은 로컬 격리 테스트용으로 적절해 보입니다. tests/ 볼륨 마운트는 .dockerignore와 맞물려 test-pg에서만 테스트 코드를 주입하는 합리적 선택입니다.

Open in Web View Automation 

Sent by Cursor Automation: Chowon Reviewer

Comment thread docker-compose.test.yml
depends_on:
postgres:
condition: service_healthy
command: uv run pytest -m postgres -v

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium · 유지보수성] postgres 마커 테스트가 CI/기본 pytest 경로에 없어 serde·PG 역직렬화 회귀가 수동 docker compose ... test-pg에만 의존합니다.

수정안: GitHub Actions에 postgres 서비스 + pytest -m postgres job 추가, 또는 README/AGENTS.md에 실행 명령을 문서화해 주세요.

graph = _build(saver)
return await graph.ainvoke(
ProovyState(user_id="u", thread_id=thread_id),
config={"configurable": {"thread_id": thread_id}},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low · 정확성 · 추가 확인 필요] 프로덕션은 solve.py에서 checkpoint_thread_id = f"{user_id}:{thread_id}"를 쓰는데, 여기서는 raw thread_id만 사용합니다. 멀티턴·serde 검증 자체는 유효하지만, 네임스페이스된 키 형식에서만 나는 이슈는 커버하지 못할 수 있습니다.

수정안: configf"u:{thread_id}" 등 프로덕션과 동일한 형식으로 맞추는 것을 권장합니다.


# 턴 단위 정산 — turn2는 누적(10)이 아닌 이번 턴 비용(5)
settler_msgs = [m for m in s2["messages"] if "cr 사용" in str(m.content)]
assert settler_msgs[-1].content == "총 5.0cr 사용"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low · 정확성] test_multiturn_credit_settled_per_turnlen(settler_msgs) == 2로 턴당 정산 메시지 개수도 검증합니다. 마지막 content만 보면 PG 복원 후 메시지 중복/누락 회귀를 놓칠 수 있습니다.

수정안: assert len(settler_msgs) == 2 추가.

- 통합 테스트 체크포인트 키를 프로덕션(solve.py)과 동일하게 user_id 네임스페이스
  (f"u:{thread_id}")로 — 네임스페이스 키 경로도 검증
- PG 복원 후 정산 메시지 개수 검증(len==2) 추가 — 중복/누락 회귀 가드
- AGENTS.md에 postgres 통합 테스트 실행법 문서화 (docker compose test-pg /
  DATABASE_URL 직접 지정)

skip: CI job 추가 — full-suite는 #67(SSE) 머지 전까지 close()-drain로 red라
별도 후속(팀 CI 조율)으로 권장.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker-compose.test.yml`:
- Line 12: The pdf-test service may fail to import tests.pdf_node.test_pdf_node
because .dockerignore excludes tests/ and pdf-test doesn't mount the host tests
directory; update the pdf-test service definition (referencing the service name
"pdf-test" and its "working_dir" setting) to mount the tests directory into the
container (e.g. add a volume mapping from ./tests to /app/tests) or
alternatively remove tests/ from .dockerignore so the test files are available
at runtime.

In `@tests/integration/test_postgres_checkpoint.py`:
- Around line 40-47: The _build function lacks type hints; annotate its
signature like def _build(checkpointer: Any) -> Any (or use the actual
Checkpointer and compiled graph types if available) and add the necessary import
(e.g., from typing import Any or the concrete Checkpointer/CompiledGraph types),
ensuring the parameter type for checkpointer and the return type for the result
of builder.compile(checkpointer=checkpointer) are declared; keep the function
body unchanged and prefer concrete types if they exist in the codebase (e.g.,
Checkpointer, StateGraphCompiled).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a669b867-b072-4e8d-b33e-ea2e6bce2187

📥 Commits

Reviewing files that changed from the base of the PR and between 56c1b3b and 9cfec41.

📒 Files selected for processing (6)
  • .dockerignore
  • AGENTS.md
  • Dockerfile.test
  • docker-compose.test.yml
  • pyproject.toml
  • tests/integration/test_postgres_checkpoint.py

Comment thread docker-compose.test.yml
Comment thread tests/integration/test_postgres_checkpoint.py Outdated
- docker-compose.test.yml: pdf-test에도 ./tests:/app/tests 마운트 추가.
  tests/가 .dockerignore로 제외돼 런타임에 모듈을 못 찾던 문제 해소
  (docker compose run pdf-test → "테스트 성공!" 확인)
- test_postgres_checkpoint.py: _build에 BaseCheckpointSaver → CompiledStateGraph
  타입힌트 추가
@haein45 haein45 requested review from chowon442 and gaeunee2 May 29, 2026 16:29

@gaeunee2 gaeunee2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도커가 핑핑 잘 돌아간다니 너무 다행이다깡총.

@haein45 haein45 merged commit 3ad5ca8 into dev May 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test] Postgres 체크포인터 통합 테스트 + docker-compose 서비스

2 participants