Skip to content

fix(tests): repair admin_team_lookup_test fixtures (CI failures from #57)#58

Merged
alejandro-runner merged 1 commit into
synvya-stagingfrom
fix/admin-team-lookup-tests
May 6, 2026
Merged

fix(tests): repair admin_team_lookup_test fixtures (CI failures from #57)#58
alejandro-runner merged 1 commit into
synvya-stagingfrom
fix/admin-team-lookup-tests

Conversation

@alejandro-runner
Copy link
Copy Markdown
Member

Summary

Fixes the three CI failures from the post-merge deploy of #57. All three are bugs in the test file itself, not in production code. The new endpoint and repository helper are unaffected.

Failures and fixes

Test Failure Fix
test_search_matches_substring_case_insensitive "target team must be in results" — team name \"Joes Diner {uuid}\" and query \"joes {uuid[..8]}\" don't share a contiguous substring (\"Diner \" sits between them). Rename teams to \"JoesDiner-{uuid}\" so a single substring match works.
test_search_aggregates_admin_emails FK violation on team_users_user_pubkey_fkey. The unique constraint on users is on pubkey alone (users_pubkey_idx), not (pubkey, tenant_id), so the ON CONFLICT (pubkey, tenant_id) in ensure_user_with_email was a hard parse error that let _ = ... was silently swallowing. Use ON CONFLICT (pubkey) DO UPDATE.
test_search_is_tenant_scoped FK violation on users_tenant_id_fkey. The tenants table requires domain text NOT NULL, but ensure_tenant only supplied (id, name), so the insert silently failed and tenant 999_001 never existed. Add the domain column to the insert.

Also replaces the let _ = ... error-swallowing in both fixture helpers with .expect(...) so future bugs fail loudly at the call site rather than cascading into mysterious downstream FK errors.

Why this wasn't caught locally

I had no local Postgres available before pushing #57 — the new tests couldn't actually run. Compile-clean and clippy-clean, but the SQL bugs only surfaced once CI ran them against a live database. Lesson learned for future PRs touching repository tests.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy -p keycast_api --tests --features integration-tests -- -D warnings
  • cargo check -p keycast_api --tests --features integration-tests
  • CI runs the integration tests against the test database — should now pass.

🤖 Generated with Claude Code

CI on the support-staging deploy caught three bugs in
api/tests/admin_team_lookup_test.rs that were masked locally because no
Postgres was available to actually run integration tests before pushing.
All three were in the test fixtures or a single test's query string,
not in production code.

1. `test_search_matches_substring_case_insensitive`
   Team name was "Joes Diner {uuid}" and query was "joes {uuid[..8]}",
   but those substrings don't appear consecutively in the team name —
   "Diner " sits between them. Renamed teams to use a hyphen joiner
   ("JoesDiner-{uuid}") so a single contiguous substring matches.

2. `test_search_aggregates_admin_emails` — FK violation on
   `team_users_user_pubkey_fkey` when `add_member` referenced admin2 /
   member who weren't actually in `users`. The unique index on `users`
   is on `pubkey` alone (`users_pubkey_idx`), not `(pubkey, tenant_id)`,
   so the original `ON CONFLICT (pubkey, tenant_id)` was a hard parse
   error that the `let _ = ...` was silently swallowing. Use
   `ON CONFLICT (pubkey) DO UPDATE` to match the actual constraint.

3. `test_search_is_tenant_scoped` — FK violation on
   `users_tenant_id_fkey` when creating tenant B's admin. The `tenants`
   table requires `domain text NOT NULL` (along with `name`), but
   `ensure_tenant` only supplied `(id, name)`, so the insert silently
   failed and tenant 999_001 never existed. Add the `domain` column.

Also replace the `let _ = ...` error-swallowing in both `ensure_tenant`
and `ensure_user_with_email` with `.expect(...)` so future fixture
problems fail loudly at the offending call site instead of cascading
into mysterious downstream FK errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alejandro-runner alejandro-runner merged commit 5b0cb13 into synvya-staging May 6, 2026
@alejandro-runner alejandro-runner deleted the fix/admin-team-lookup-tests branch May 6, 2026 07:36
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.

1 participant