Skip to content

wip#3

Merged
klagrida merged 24 commits intomainfrom
fix-2
Nov 16, 2025
Merged

wip#3
klagrida merged 24 commits intomainfrom
fix-2

Conversation

@klagrida
Copy link
Copy Markdown
Contributor

@klagrida klagrida commented Nov 9, 2025

No description provided.

klagrida and others added 24 commits November 9, 2025 13:32
This commit fixes multiple issues causing CI failures:

1. Fixed API key extraction - Supabase CLI changed from "anon key" to "Publishable key"
2. Added apikey headers to all test functions and database health checks
3. Simplified Edge Functions startup - now auto-served by supabase start
4. Enhanced test error handling and diagnostics
5. Added pre-flight checks to validate environment and connectivity

Changes:
- .github/workflows/ci.yml: Updated API key extraction, added headers to curl
- supabase/functions/test-functions.ts: Added apikey headers, better error handling
- supabase/functions/{TEST,README}.md: Updated documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added error handling and ON CONFLICT to the trigger that creates
profiles when users sign up. This prevents database errors during
login when the trigger encounters issues.

Changes:
- Added ON CONFLICT (id) DO NOTHING to handle duplicate inserts
- Added EXCEPTION handler to catch and log errors without failing
- Prevents "Database error querying schema" during auth operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replaced non-existent 'supabase logs' command with proper Docker logs.
Updated CI workflow to show container logs on failure without failing
the workflow itself.

Changes:
- package.json: Updated logs script to use docker logs
- .github/workflows/ci.yml: Improved failure logging with fallbacks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Created a new migration to update the handle_new_user trigger with
proper error handling. This prevents "Database error querying schema"
during auth operations.

The new migration:
- Adds ON CONFLICT (id) DO NOTHING to prevent duplicate insert errors
- Adds EXCEPTION handler to catch errors without failing auth
- Ensures login/signup operations succeed even if profile creation has issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The handle_new_user trigger was causing issues during seeding because
it tried to create profiles when users were inserted, but the seed
script also explicitly creates profiles with more data.

Now the seed:
1. Disables the trigger before inserting users
2. Inserts users into auth.users
3. Explicitly creates profiles with all fields
4. Re-enables the trigger

This prevents the "Database error querying schema" during login.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The ALTER TABLE auth.users commands were causing permission errors
during seed. The improved trigger from migration 00005 already handles
conflicts with ON CONFLICT and EXCEPTION blocks, so disabling the
trigger is not necessary.

This fixes the "Process completed with exit code 1" error during npm run dev.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
When admin login fails, the test now queries the profiles table
to verify that users were seeded correctly. This will help diagnose
whether the issue is with authentication or data seeding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added is_sso_user and is_super_admin fields to the auth.users insert
statements. These fields are required by Supabase Auth and their absence
was causing "Database error querying schema" during login attempts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added extensive logging to diagnose the auth login failure:
- Check seeded users and profiles before tests
- Show auth.users table contents
- Capture full test output
- Show database state on failure
- Include auth service logs (GoTrue)
- Display last 100 lines of DB logs

This will help identify the root cause of "Database error querying schema".

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Enhanced the CI workflow with better diagnostics and reliability:

- Added 5-second wait time for Edge Functions initialization
- Added manual login test to verify auth before full test suite
- Enhanced seeded data debugging with password verification
- Improved Edge Functions verification:
  - Test actual admin-create-user function instead of generic health check
  - Increased retries from 5 to 10 attempts
  - Increased wait time from 2 to 3 seconds between attempts
  - Fail fast if Edge Functions don't respond after 10 attempts

These changes will help identify whether the CI failure is due to:
1. Authentication issues (login test)
2. Edge Functions not being ready/accessible
3. Timing issues with service startup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses multiple issues in the CI workflow:

1. **Better Edge Functions verification:**
   - Check for edge-runtime Docker container
   - Increased wait time to 10 seconds for initialization
   - Added full Supabase status output for debugging

2. **Improved environment variable extraction:**
   - More robust parsing of `supabase status` output
   - Case-insensitive grep patterns
   - Uses `$NF` (last field) instead of hardcoded field position
   - Added fallback URL for reliability
   - Validates ANON_KEY has minimum length

3. **Enhanced error diagnostics:**
   - Show full status output when parsing fails
   - Added auth service logs on failure
   - Added edge-runtime logs on failure
   - Limited log output to last 50 lines for readability

4. **Added import map:**
   - Created import_map.json for Deno module resolution
   - Ensures @supabase/supabase-js imports work correctly

These changes make the CI more resilient to:
- Different `supabase status` output formats
- Timing issues with service startup
- Edge Functions runtime problems

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The CI was failing because of a race condition after `npm run seed`
(which calls `supabase db reset`). The database reset restarts all
services including the auth service, but tests were running before
the auth service was fully ready.

Changes:
- Added comprehensive health checks after seeding
- Wait 15 seconds for services to stabilize
- Verify database is responding
- Verify auth service health endpoint (with 10 retries)
- Verify seeded users are actually in the database
- Show auth logs if health check fails

This ensures that when the Edge Functions tests run, all services
are fully operational and the auth service can properly handle
login requests.

Fixes the error:
"Database error querying schema" during login attempts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The docker/setup-docker-action@v3 doesn't exist and causes CI to fail
with a 404 error. Docker is already pre-installed on ubuntu-latest
GitHub Actions runners, so this step is unnecessary.

Removed the "Set up Docker" step as:
- ubuntu-latest has Docker pre-installed
- docker/setup-docker-action@v3 returns 404 (doesn't exist)
- Supabase CLI will use the existing Docker installation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
GoTrue was failing to query users with error:
"sql: Scan error on column index 8, name 'email_change': converting NULL to string is unsupported"

The seed.sql was missing required columns that GoTrue expects:
- email_change (empty string, not NULL)
- email_change_token_new (empty string)
- email_change_token_current (empty string)
- email_change_confirm_status (0)

Added these columns to all three test users (alice, bob, carol) with
proper default values to prevent NULL scan errors during login.

This fixes the 500 error during authentication that was preventing
the Edge Functions tests from running.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…e, etc)

GoTrue continued to fail with schema errors due to more missing columns:
"sql: Scan error on column index 31, name 'recovery_token': converting NULL to string is unsupported"

Added all remaining required auth.users columns with empty string defaults:
- recovery_token (for password recovery)
- phone_change (for phone number changes)
- phone_change_token (token for phone verification)
- reauthentication_token (for sensitive operations)

All columns now have proper non-NULL defaults as expected by GoTrue v2.182.1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The hardcoded bcrypt hash was not matching "password123", causing
login failures with "Invalid login credentials" error.

Changes:
- Use PostgreSQL's crypt(password, gen_salt('bf')) to generate
  bcrypt hashes at insert time
- This ensures hashes are compatible with GoTrue's password
  verification system
- Enabled pgcrypto extension in seed.sql
- Added explanatory migration 00006

Benefits:
- Hashes are generated fresh each time seed runs
- Guaranteed compatibility with GoTrue v2.182.1
- Passwords will now authenticate successfully

Password for all test users remains: "password123"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@klagrida klagrida merged commit c0769d6 into main Nov 16, 2025
1 check passed
@klagrida klagrida deleted the fix-2 branch November 16, 2025 15:22
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