Skip to content

Fix latest_output runtime bug and run DB-backed tests in CI#57

Merged
seanwevans merged 1 commit into
mainfrom
claude/project-spec-tests-rksirm
Jun 27, 2026
Merged

Fix latest_output runtime bug and run DB-backed tests in CI#57
seanwevans merged 1 commit into
mainfrom
claude/project-spec-tests-rksirm

Conversation

@seanwevans

Copy link
Copy Markdown
Owner

Summary

CI ran pytest without a PostgreSQL service, so every database-backed test
silently skipped (10 of 35). That blind spot let two real defects ship to
main. This PR makes CI actually exercise the database, then fixes everything
the now-running tests surface.

Root cause

The test job had no Postgres service and never set TEST_DATABASE_URL, so the
DB fixtures hit pytest.skip(...). Locally, running the suite against a real
Postgres 16 produced 4 failures.

Changes

Production bug

  • sql/latest_output.sql: the function failed at runtime with
    column reference "id" is ambiguous — the RETURNS TABLE output columns
    (id, command, …) collide with the selected commands columns inside the
    RETURN 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_envs
    inserted two users with the same username (violating the UNIQUE constraint)
    and compared uuid = text in its verification query. Now uses distinct
    usernames and casts the array parameter (ANY(%s::uuid[])).
  • tests/test_functions.py: test_command_indexes_query_plans never ran
    ANALYZE, so the planner chose an index from empty-table statistics
    (commands_status_completed_at_idx instead of the expected
    commands_status_submitted_at_idx). Added ANALYZE commands before
    EXPLAIN; the planner then picks the correct index.

CI

  • .github/workflows/ci.yml: added a postgres:16 service (with a
    pg_isready healthcheck) and TEST_DATABASE_URL so the database tests run on
    every push and pull request.

Verification

  • Against a live Postgres 16: 35 passed (was 4 failed / 31 passed).
  • Without a database (mirrors the old CI): 25 passed, 10 skipped — the suite
    still degrades gracefully.

🤖 Generated with Claude Code


Generated by Claude Code

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
@seanwevans
seanwevans merged commit 542d978 into main Jun 27, 2026
2 checks passed
@seanwevans
seanwevans deleted the claude/project-spec-tests-rksirm branch June 27, 2026 00:29
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