Skip to content

Conversation

@marcodejongh
Copy link
Owner

…raint

The session-persistence tests use 'user-123' as the userId for createDiscoverableSession, but the board_sessions.created_by_user_id column has a foreign key constraint referencing the users table.

This fix:

  • Truncates the users table in beforeEach to ensure clean state
  • Creates the 'user-123' test user before each test

…raint

The session-persistence tests use 'user-123' as the userId for
createDiscoverableSession, but the board_sessions.created_by_user_id
column has a foreign key constraint referencing the users table.

This fix:
- Truncates the users table in beforeEach to ensure clean state
- Creates the 'user-123' test user before each test
@vercel
Copy link

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
boardsesh Ready Ready Preview, Comment Jan 1, 2026 4:40am

@claude
Copy link

claude bot commented Dec 31, 2025

Claude Review

No issues found.

The fix correctly addresses the foreign key constraint issue by:

  1. Truncating the users table in the proper order (after dependent tables)
  2. Creating the required test user before tests that reference it

The ON CONFLICT DO NOTHING is appropriate for test setup idempotency.

The test setup was creating its own database connection, while
roomManager uses the singleton db from @boardsesh/db/client. This
caused the test user insertion to not be visible to roomManager
when it tried to create discoverable sessions.

Changes:
- Import and use sharedDb (same instance as roomManager) for all
  data operations in beforeEach
- Remove unused local db connection and related imports
- Keep raw postgres client only for initial schema creation
@claude
Copy link

claude bot commented Dec 31, 2025

Claude Review

No significant issues found.

The fix correctly addresses the foreign key constraint violation by:

  1. Truncating the users table in beforeEach
  2. Creating the 'user-123' test user before tests run
  3. Using sharedDb for consistency with roomManager

Minor note: The ON CONFLICT (id) DO NOTHING clause is unnecessary since the table is truncated immediately before, but it's harmless.

Changes:
- Add kilter_climbs, kilter_climb_stats, kilter_difficulty_grades tables
  to test setup (required for climb query tests)
- Add equivalent tension tables for tension board tests
- Fix test parameters to use valid size_id values:
  - kilter: size_id 7 (12x14 Commercial) instead of 1
  - tension: size_id 1 (Full Wall) is already valid

The climb-queries tests require these tables to exist even if empty,
as the queries need to execute against actual database tables.
@claude
Copy link

claude bot commented Dec 31, 2025

Claude Review

Issues Found

  1. Schema drift in test table definitions (packages/backend/src/__tests__/setup.ts:75-155): The kilter_climbs and tension_climbs test tables are missing columns present in the actual schema:

    • Missing angle column
    • Missing synced column

    This may cause tests to pass against an incomplete schema while failing against the real database.

  2. Weak test assertions (packages/backend/src/__tests__/climb-queries.test.ts): Several tests have assertions that always pass:

    • Line 73-78: The expect(climb).toBeDefined() inside the grade filter test doesn't actually validate the grade range
    • Line 264-265: expect(kilterResult === null || typeof kilterResult === 'object').toBe(true) - this will always be true since the result is either null or an object
  3. Tests don't verify core functionality (packages/backend/src/__tests__/climb-queries.test.ts): The climb query tests rely on external database state (synced production-like data) rather than setting up known test fixtures. If the database is empty, tests like minAscents filter (line 81-95) will pass vacuously with 0 results.

…ries

The climb query tests with userId parameter use subqueries that
reference kilter_ascents, kilter_bids, tension_ascents, and
tension_bids tables to count user's ascents and attempts.
@claude
Copy link

claude bot commented Dec 31, 2025

Claude Review

No significant issues found.

Minor observations:

  • Duplicated schema definitions: setup.ts:80-232 duplicates table schemas that exist in packages/db/src/schema/. This could drift over time - consider importing from the schema package or using migrations for test DB setup to avoid maintaining parallel definitions.

claude added 2 commits January 1, 2026 04:38
The roomManager.joinSession() requires clients to be registered first
via registerClient(). Added a registerAndJoin helper function and
updated all test calls to use it.
The queue item validation requires proper UUID format. Updated
createTestClimb() to generate valid UUIDs using uuidv4() instead
of using the label parameter as the UUID value.
@claude
Copy link

claude bot commented Jan 1, 2026

Claude Review

Issues Found:

  1. Race condition in registerAndJoin helper (session-persistence.test.ts:158-165): The helper registers and joins in sequence but doesn't handle the case where joinSession throws before returning - the client remains registered but in an inconsistent state. This mirrors a potential real-world issue but may cause test pollution.

  2. Missing client registration in concurrent join test (session-persistence.test.ts:304-307): The Promise.all calls registerAndJoin for clients 2-4 in parallel, but since registerClient is synchronous and joinSession is async, there's a subtle race where all three clients get registered before any joins complete. This works but doesn't accurately test the concurrent restoration scenario described in the test name.

  3. Schema drift risk (setup.ts:22-228): The test setup manually defines table schemas via raw SQL strings rather than importing from the shared schema package. If the production schema changes, these test tables will silently diverge, causing tests to pass against an outdated schema.

  4. Hardcoded test user ID (setup.ts:279-282): The test user 'user-123' is created with hardcoded values, but if a test modifies or deletes this user, subsequent tests in the same run could fail. Consider using unique user IDs per test or wrapping in a transaction.

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.

3 participants