Skip to content

Add proxied full-stack e2e (docker images + nginx) and fix DISTINCT sort crash - #327

Closed
felixevers wants to merge 1 commit into
mainfrom
claude/filter-sort-e2e-tests-it1uyg
Closed

felixevers wants to merge 1 commit into
mainfrom
claude/filter-sort-e2e-tests-it1uyg

Conversation

@felixevers

Copy link
Copy Markdown
Member

Full-stack e2e behind the nginx proxy + a real backend sort crash it caught

Follow-up to #319: the mock-based e2e can't see routing or database-level problems, so this adds a second e2e tier that runs against the real stack — the docker images built for the current commit, wired together exactly like production (nginx proxy in front of web, backend and Keycloak).

Proxied full-stack e2e

  • docker-compose.e2e.yml — production-like stack (proxy → web / backend / Keycloak / Postgres / Redis / InfluxDB) with parameterized image references (BACKEND_IMAGE / WEB_IMAGE / PROXY_IMAGE) so CI runs this commit's images; ephemeral volumes, restart: on-failure on the backend so migrations retry until Postgres accepts connections.
  • tests/e2e/proxy-fullstack.spec.ts (gated behind E2E_PROXY_TARGET=1, skipped in the mock-based runs):
    • proxy routing: / → web, /keycloak/... → Keycloak (issuer under the subpath), /graphql → backend (JSON, never the frontend catch-all)
    • authentication through the proxied Keycloak: password grant for API seeding and the real browser login flow (redirect → login form → /auth/callback → app)
    • seeds patients + tasks over the proxied GraphQL API, then asserts server-side filtering and sorting from the real query engine: name asc/desc, birthdate, NOT_CONTAINS, update-date sort, and sorting tasks by patient asc/desc (issue Sorting of my tasks list based on patients not possible #213)
    • UI: logs in, searches, and sorts the patient list through the whole stack
  • e2e-proxy CI job (tests.yml) — builds the backend/web/proxy images for the commit with Buildx (cache-from/to: type=gha, same scopes now written by the Docker Build workflow, so layers are shared with the images built earlier), starts the compose stack, waits for readiness through the proxy, runs the spec, and uploads the report + stack logs on failure. Added to the required CI gate.
  • E2E_TESTING.md documents how to run this locally.

Real bug the proxied tests caught (issue #213)

Sorting my tasks by patient crashed on PostgreSQL:

(sqlalchemy) for SELECT DISTINCT, ORDER BY expressions must appear in select list

The tasks/patients base queries use SELECT DISTINCT (location-scope joins), and every sort that orders by a joined or correlated expression — tasks by patient or assignee, patients by update date, ward/room/bed, clinic or position — produced an ORDER BY outside the select list and 500ed. This is invisible to the mock-based suite and to SQLite-backed tests; it reproduced immediately against the real Postgres backend through the proxy.

Fix: apply_unified_query now rewraps DISTINCT statements into a plain select over deduplicated ids before applying sorts (and clears stale join memos so sort adapters re-join the rewrapped statement). This also covers the pre-existing case where a property filter (needs_distinct) was combined with a position/clinic sort.

Verification

  • All 5 proxied tests pass locally against the compose stack built from this commit (they fail on main with the DISTINCT crash when sorting tasks by patient).
  • Backend: ruff clean; unit tests show no new failures.
  • The spec is skipped without E2E_PROXY_TARGET=1, so the existing mock-based e2e job is unaffected.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WCSmjBuS6NbcB6oRmKvQgT


Generated by Claude Code

@felixevers
felixevers force-pushed the claude/filter-sort-e2e-tests-it1uyg branch from 4ecd0c3 to ff71758 Compare July 8, 2026 13:20
…ort crash

Full-stack e2e against the real backend behind the nginx proxy:
- docker-compose.e2e.yml: production-like stack (proxy -> web/backend/
  keycloak/postgres/redis/influxdb) with parameterized image references
  so CI runs the images built for the current commit; ephemeral volumes
- tests/e2e/proxy-fullstack.spec.ts (gated by E2E_PROXY_TARGET=1):
  verifies proxy routing (/, /graphql, /keycloak), authenticates via the
  proxied keycloak (password grant + browser login flow), seeds patients
  and tasks over the proxied GraphQL API, and asserts server-side
  filtering/sorting from the real query engine, including sorting tasks
  by patient (issue #213) and the NOT_CONTAINS operator
- e2e-proxy CI job in tests.yml: builds backend/web/proxy images for the
  commit with a shared buildx layer cache (docker-build.yml now writes
  the same gha cache scopes), starts the compose stack and runs the
  proxied tests against http://localhost; required in the CI gate

Backend fix uncovered by the proxied tests:
- sorting over DISTINCT base queries crashed on PostgreSQL ("for SELECT
  DISTINCT, ORDER BY expressions must appear in select list") whenever a
  sort ordered by a joined/correlated expression - tasks by patient or
  assignee (issue #213), patients by update date, ward/room/bed, clinic
  or position. The unified query engine now rewraps DISTINCT statements
  into a plain select over deduplicated ids before applying sorts, and
  clears stale join memos so sort adapters re-join the rewrapped query.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WCSmjBuS6NbcB6oRmKvQgT
@felixevers
felixevers force-pushed the claude/filter-sort-e2e-tests-it1uyg branch from ff71758 to 1b3df33 Compare July 8, 2026 13:29
@felixevers felixevers closed this Jul 8, 2026
@felixevers
felixevers deleted the claude/filter-sort-e2e-tests-it1uyg branch July 8, 2026 13:32
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