Skip to content
Merged
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
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,27 @@ jobs:
run: uv sync --extra test

- name: Run tests
run: uv run pytest
run: uv run pytest --ignore=tests/test_strategy_postgres.py

test-postgres:
name: Postgres Integration Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6.0.2

- name: Install uv
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true

- name: Set up Python 3.12
uses: actions/setup-python@v6.2.0
with:
python-version: "3.12"

- name: Install dependencies
run: uv sync --extra test --extra test-postgres

- name: Run Postgres integration tests
run: uv run pytest tests/test_strategy_postgres.py -v
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ test = [
"langgraph-checkpoint-sqlite>=3.1.0",
"aiosqlite>=0.20",
]
test-postgres = [
"langgraph-checkpoint-postgres>=3.1.0",
"psycopg[binary]>=3.1",
"testcontainers[postgres]>=4.0",
]
benchmark = [
"langgraph-checkpoint-sqlite>=3.0.3",
"langgraph-checkpoint-postgres>=3.0.5",
Expand Down
50 changes: 50 additions & 0 deletions tests/test_policy_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,53 @@ def resolver(tid):

assert "exempt" not in result.deleted_thread_ids
assert "expired" in result.deleted_thread_ids


def test_fresh_policy_objects_per_thread_applied_correctly():
tuples = [
make_checkpoint_tuple("strict", None, iso_ts(-70)),
make_checkpoint_tuple("lenient", None, iso_ts(-70)),
]
cp = MockCP(tuples)

def resolver(tid):
if tid == "strict":
return TTLPolicy(idle_ttl_seconds=60)
return TTLPolicy(idle_ttl_seconds=3600)

sweeper = Sweeper(
cp,
TTLPolicy(idle_ttl_seconds=9999),
policy_resolver=resolver,
safe_delete=False,
_strategy=list_strategy(tuples),
)
result = sweeper.sweep()

assert "strict" in result.deleted_thread_ids
assert "lenient" not in result.deleted_thread_ids


def test_many_threads_fresh_policies_all_evaluated_correctly():
thread_ids = [f"t{i}" for i in range(50)]
tuples = [make_checkpoint_tuple(tid, None, iso_ts(-70)) for tid in thread_ids]
cp = MockCP(tuples)

strict_ids = {tid for tid in thread_ids if int(tid[1:]) % 2 == 0}

def resolver(tid):
if tid in strict_ids:
return TTLPolicy(idle_ttl_seconds=60)
return TTLPolicy(idle_ttl_seconds=3600)

sweeper = Sweeper(
cp,
TTLPolicy(idle_ttl_seconds=9999),
policy_resolver=resolver,
safe_delete=False,
_strategy=list_strategy(tuples),
)
result = sweeper.sweep()

deleted = set(result.deleted_thread_ids)
assert deleted == strict_ids
Loading