Repository navigation
test(import): undo monkeypatches before cleanup deletes buckets - #186
Conversation
Fixtures tear down in reverse setup order. The two rollback tests list monkeypatch before cleanup, so cleanup ran while delete_bucket was still patched to fail, and leaked test-import-rb-a/-rb-b/-rb-c into the session's testing DB. test_server.py::test_buckets then saw 4 buckets instead of 1, failing the bundle's integration tests on every Qt build.
|
@greptileai review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Reviewing this now: I’ll check the fixture dependency/teardown ordering and rerun the import → server test sequence in an isolated HOME, including a base-versus-head comparison. |
TimeToBuildBob
left a comment
There was a problem hiding this comment.
Reviewed 1d891cc07052d22b11bda000cb8b729049f2c2cf: no blocking findings.
Independently reproduced the exact import → server ordering in separate scratch HOME/XDG directories (Python 3.11; benchmarks disabled):
- Parent commit: 30 passed, 1 failed, with
test_bucketsreportingassert 4 == 1and the three leaked rollback buckets (test-import-rb-a,-rb-b,-rb-c). - PR head: 31 passed.
The explicit cleanup → monkeypatch dependency keeps the fixture available through cleanup, and monkeypatch.undo() restores the real delete method before cleanup issues DELETE requests. The rollback assertions still run against the patched method during the test; monkeypatch's subsequent teardown safely has nothing left to undo. This is a scoped test-fixture fix, with no production behavior change.
GitHub CI was queued at the initial check; these results verify the affected local sequence, not the full live-server suite or the platform matrix. Recommend merging once required CI passes.
🤖 AI code reviewModifies the Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No findings. The diff looks correct to me on this pass. Files changed (1) — the diff as I read it
Reviewed Maintainer commands
|
Fixes the bundle's integration tests (aw-server/tests/test_server.py::test_buckets) on every Qt build: ActivityWatch/aw-server#186 stops the import tests leaking buckets.
|
Reviewed. Fix is correct. The teardown order issue: pytest tears down fixtures in reverse dependency order, so a test that lists
5/5 AI review + macOS/Windows/format/lint all green. LGTM. |
Fixes the bundle's integration tests, which fail on every Qt build since aw-server was bumped to 1780f2a (ActivityWatch/activitywatch@bc96b3d):
tests/test_server.py::test_bucketsgetsassert 4 == 1.Cause: fixtures tear down in reverse setup order.
test_import_rollback_failure_is_reported_as_server_errorandtest_import_rollback_failure_does_not_abort_other_deletes(from #176) listmonkeypatchbeforecleanup, socleanupruns whileapp.api.delete_bucketis still patched to fail. The deletes fail silently and leaktest-import-rb-a,-rb-band-rb-cinto the session-scoped testing DB. The bundle runstest_import.pybeforetest_server.py, which then counts 4 buckets. This repo's CI only runs an import check, so nothing caught it here.Fix:
cleanuptakesmonkeypatchand callsmonkeypatch.undo()before deleting, so it works whatever the argument order.undo()is idempotent, so monkeypatch's own teardown is unaffected.Verified (scratch HOME):
pytest tests/test_import.py tests/test_server.py: 1 failed → 31 passed.tests/without a running server: the only difference istest_bucketsnow passing; the other 16 need a live server (Connection refused) and fail the same with or without this change.