Skip to content

fix(tests): the auto-dispatch test declares its psycopg dependency - #986

Merged
github-actions[bot] merged 2 commits into
mainfrom
fix/flaky-auto-dispatch-psycopg
Nov 11, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
fix/flaky-auto-dispatch-psycopg

Conversation

@cdeust

@cdeust cdeust commented Nov 11, 2026

Copy link
Copy Markdown
Owner

What was wrong

tests_py/hooks/test_entry_auto_dispatch.py::test_engine_selected_auto_backend_reaches_hook[False-wheel] and [False-launcher] fail on the documented dev install (--extra dev, with or without --extra sqlite):

E assert None is <object object at 0x…>     (assert observed["connection"] is connection)

Cause: an undeclared dependency on psycopg.

  • The test replaces db_connect.pg_connect with a fake and expects auto_recall._connect() to return it.
  • _connect first does import psycopg and returns None on ImportError, so the fake is never reached.
  • psycopg belongs to the optional [postgresql] extra, which the documented dev install does not include.
  • The other tests that need the driver declare it with pytest.importorskip("psycopg", …); this one did not, so it failed where it should have been skipped.

What

The two PostgreSQL parameters call pytest.importorskip("psycopg", reason="psycopg not installed ([postgresql] extra)") at the top of the test. The SQLite parameters and every assertion are unchanged.

In CI nothing changes: the unit command of ci.json installs --extra postgresql, so the two tests run and are not skipped there.

Checks

  • Before: 2 failed in each of 32 full runs of the hooks selection on a dev install without the extra.
  • After: 2 passed, 2 skipped, with SKIPPED [2] … psycopg not installed ([postgresql] extra). Same result with main merged in.
  • ruff check, ruff format --check: clean. scripts/check_craftsmanship.py: OK.

Not verified

The two tests with psycopg actually installed were not run locally; this pull request's CI runs them.

No CHANGELOG entry: a six-line, test-only change.


Generated by Claude Code

…needs

test_engine_selected_auto_backend_reaches_hook[False-wheel] and
[False-launcher] failed on every install without the [postgresql] extra with
"assert None is <object object>". They replace db_connect.pg_connect and
expect auto_recall._connect to return that fake connection, but _connect
imports psycopg first and returns None when the import fails, so the fake is
never reached. The dependency was not declared: the test failed instead of
being skipped, unlike the other tests that need the driver.

The two PostgreSQL parameters now call pytest.importorskip("psycopg") with the
reason the other tests give. The SQLite parameters and every assertion are
unchanged; with the driver installed, as in CI, nothing is skipped.

Here (no psycopg): 2 passed, 2 skipped, before 2 passed, 2 failed. Not
verified with psycopg installed (it cannot be installed in this container).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_018kyZYrKg46KKYpvLPXcW4M
Signed-off-by: Claude <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T11:26:13.468012Z 725c510 PR opened
🔒 Security Review ✅ Completed 2026-11-11T11:27:13.060006Z 725c510 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @cdeust's task in 1m 13s —— View job


Review of PR #986 (review 1 of 3)

There are no Blockers and one Note.

What I checked:

  • The cause is right. Without psycopg, auto_recall._connect returns None before it reaches the replaced pg_connect.
  • The CI unit command installs --extra postgresql, so CI still runs all four tests.
  • Nothing else on the PostgreSQL path of this test imports psycopg.
  • Other tests already skip on missing psycopg the same way, with the same reason text.

Note: the skip covers more than it needs to. The checks at lines 78–83 don't need psycopg; only line 84 does.

Not done: the /review-pr skill wouldn't load, so I ran the review by hand with one review agent. This job wasn't allowed to run pytest, so I didn't execute the tests; this PR's CI run is the execution check.

Verdict: approve

@claude

claude Bot commented Nov 11, 2026

Copy link
Copy Markdown

Review 1 of 3: PR #986

No Blockers.

I checked the cause. Without psycopg, mcp_server/hooks/auto_recall.py:121-124 returns None before it calls the monkeypatched pg_connect, so the check at tests_py/hooks/test_entry_auto_dispatch.py:84 can't pass on a dev install that lacks the [postgresql] extra. The unit command in ci.json installs --extra postgresql, so all four parameters still run in CI. The regression job leaves the extra out, but it only runs tests_py/integration, so this file isn't affected. Nothing else on the sqlite=False path imports psycopg: scripts/launcher_backend.py, entry.py and wiring.py don't. Other tests already declare the driver the same way, with a function-level importorskip and the same reason string (for example tests_py/infrastructure/test_standalone_commands_settle_backend.py).

I didn't run pytest locally because this job's permissions blocked it. This PR's CI run is the execution check.

Notes, no action before merge

  • The skip is broader than it needs to be. The checks at lines 78-83 (backend and URL) don't need the driver, and only line 84 does. Moving the importorskip in front of line 84 would keep those checks running without the extra.

View job run
Verdict: approve

@github-actions
github-actions Bot merged commit 54af2b0 into main Nov 11, 2026
18 checks passed
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.

2 participants