Fix latest_output runtime bug and run DB-backed tests in CI#57
Merged
Conversation
The CI workflow only ran `pytest` without a PostgreSQL service, so every database-backed test silently skipped. This hid two defects: - latest_output() failed at runtime with `column reference "id" is ambiguous` because the RETURNS TABLE output columns collide with the selected table columns. Qualify all column references with a table alias so the core read API actually works. - test_cleanup_once_resets_multiple_envs inserted two users with the same username (violating the UNIQUE constraint) and compared uuid = text in its verification query. Use distinct usernames and cast the array param. - test_command_indexes_query_plans never ran ANALYZE, so the planner chose an index from empty-table statistics. Refresh stats before EXPLAIN. Add a postgres:16 service and TEST_DATABASE_URL to CI so these tests run on every push and pull request. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BixPb34oe2Ae5cXuz9WxbP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CI ran
pytestwithout a PostgreSQL service, so every database-backed testsilently skipped (10 of 35). That blind spot let two real defects ship to
main. This PR makes CI actually exercise the database, then fixes everythingthe now-running tests surface.
Root cause
The
testjob had no Postgres service and never setTEST_DATABASE_URL, so theDB fixtures hit
pytest.skip(...). Locally, running the suite against a realPostgres 16 produced 4 failures.
Changes
Production bug
sql/latest_output.sql: the function failed at runtime withcolumn reference "id" is ambiguous— theRETURNS TABLEoutput columns(
id,command, …) collide with the selectedcommandscolumns inside theRETURN QUERY. The SPEC's core read endpoint was completely non-functional.Fixed by qualifying every column with a table alias (
c.id,c.command, …).Test correctness
tests/test_cleanup_agent.py:test_cleanup_once_resets_multiple_envsinserted two users with the same username (violating the
UNIQUEconstraint)and compared
uuid = textin its verification query. Now uses distinctusernames and casts the array parameter (
ANY(%s::uuid[])).tests/test_functions.py:test_command_indexes_query_plansnever ranANALYZE, so the planner chose an index from empty-table statistics(
commands_status_completed_at_idxinstead of the expectedcommands_status_submitted_at_idx). AddedANALYZE commandsbeforeEXPLAIN; the planner then picks the correct index.CI
.github/workflows/ci.yml: added apostgres:16service (with apg_isreadyhealthcheck) andTEST_DATABASE_URLso the database tests run onevery push and pull request.
Verification
still degrades gracefully.
🤖 Generated with Claude Code
Generated by Claude Code