Skip to content

fix(test): repair main Test Suite (pg_net + service + seed + retire validator)#359

Merged
glassBead-tc merged 8 commits into
mainfrom
fix/test-suite-green
Jun 8, 2026
Merged

fix(test): repair main Test Suite (pg_net + service + seed + retire validator)#359
glassBead-tc merged 8 commits into
mainfrom
fix/test-suite-green

Conversation

@glassBead-tc

Copy link
Copy Markdown
Member

Goal

main's required Test Suite check is red from pre-existing breakage (30 failing tests), blocking every queued PR. This branch repairs it.

Fixes in this PR

Failure cluster Count Fix
supabase start dies on pg_net 3F000 (blocks all) pg_net WITH SCHEMA extensions
supabase-storage.test.ts FK violations 17 seed ensureTestWorkspace() in beforeEach (matches knowledge test)
peer-notebook tests (no Storage/edge svc) 7 re-include storage-api + edge-runtime in supabase start
validate-pr-description.test.ts 6 retire the validator gate (workflow + script + test + validate:pr) per decision
architecture.test.ts 1 record branch/handlers.ts as known SupabaseClient debt

Still under investigation (draft)

  • otel-storage.test.ts (4) — query failures
  • branch-workers.test.ts (1) — signed-token
  • intelligence-pipeline.test.ts (1)

Notes

🤖 Generated with Claude Code

glassBead-tc and others added 4 commits June 8, 2026 02:07
Migration 20260408033928 created pg_net with no target schema. On a
fresh database (CI `supabase start` replay), where pg_net is not
pre-provisioned, `CREATE EXTENSION IF NOT EXISTS pg_net` fails with
3F000 "no schema has been selected to create in" — breaking the Schema
Drift Check and Test Suite on every migration PR. Pin it to the
extensions schema, matching the convention already used in
20260409232440.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
thoughtbox-web-two Ready Ready Preview, Comment Jun 8, 2026 7:53am

@supabase

supabase Bot commented Jun 8, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project akjccuoncxlvrrtkvtno due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@glassBead-tc
glassBead-tc marked this pull request as ready for review June 8, 2026 07:41
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR repairs the main branch test suite, which had 30 failing tests blocking all queued PRs, by addressing five distinct failure clusters across CI configuration, test infrastructure, and the migration.

  • pg_net schema fix: Changes CREATE EXTENSION IF NOT EXISTS pg_net to WITH SCHEMA extensions in the migration to resolve the 3F000 startup error; the invoke_process_thought_queue_from_vault function's net.http_post call and search_path (previously flagged) remain a concern for environments where this migration was already applied.
  • Test isolation fixes: supabase-storage.test.ts gains ensureTestWorkspace() in beforeEach to satisfy FK constraints; otel-storage.test.ts introduces seedSessionWithOtel to build the real sessions → runs binding that querySessionTimeline/querySessionCost require; intelligence-pipeline.test.ts drains stale queue messages in beforeEach.
  • Infra/validator cleanup: storage-api and edge-runtime are re-added to supabase start, the PR-description validator workflow and script are retired, branch/handlers.ts is recorded as known SupabaseClient debt, and the tb-branch edge function is registered in config.toml.

Confidence Score: 4/5

Safe to merge for CI unblocking; the net.http_post / search_path mismatch in the migration function (flagged in a previous review) may silently break the cron worker on any instance where the April migration was already applied.

The test infrastructure changes are well-reasoned and the workspace-seeding and otel session-binding fixes are correct. The one outstanding concern — net.http_post referenced under search_path = public, vault, net while pg_net now lives in the extensions schema — was flagged in the prior review and is not addressed here. That cron-worker regression would not surface during pnpm test, making it easy to miss in production.

supabase/migrations/20260408033928_add_hub_tables_vectors_pgmq_realtime.sql — the pg_net schema move and the cron function's search_path/net.http_post call need to be reconciled.

Important Files Changed

Filename Overview
.github/workflows/ci.yml Re-includes storage-api and edge-runtime in supabase start so peer-notebook and edge-function tests have the services they need.
src/persistence/tests/supabase-storage.test.ts Adds ensureTestWorkspace() in beforeEach after truncateAllTables(), fixing FK violations that broke 17 tests.
src/otel/tests/otel-storage.test.ts Adds seedSessionWithOtel helper to create a real sessions+runs binding before each query test, resolving the sessions→runs join path. beforeEach still only truncates otel_events so sessions/runs accumulate across runs — each test's fresh DB-generated UUID keeps isolation correct in practice.
src/tests/intelligence-pipeline.test.ts Adds a beforeEach queue drain to clear stale thought_processing messages left by earlier test files; drain errors are silently swallowed which could mask isolation failures.
supabase/migrations/20260408033928_add_hub_tables_vectors_pgmq_realtime.sql Adds WITH SCHEMA extensions to pg_net install to fix the 3F000 startup error. The invoke_process_thought_queue_from_vault function still references net.http_post but its search_path only lists public, vault, net — whether the extensions schema is reachable under that alias depends on the local Supabase build.
supabase/config.toml Adds tb-branch edge function config with verify_jwt = false; referenced deno.json and index.ts files exist in supabase/functions/tb-branch/.
src/tests/architecture.test.ts Records branch/handlers.ts as known SupabaseClient debt to unblock the architecture constraint test.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[supabase start] -->|pg_net WITH SCHEMA extensions| B[Extensions load correctly]
    B --> C[Test Suite: pnpm test]

    C --> D[supabase-storage.test.ts]
    D -->|beforeEach: truncateAllTables + ensureTestWorkspace| D1[FK constraints satisfied ✓]

    C --> E[otel-storage.test.ts]
    E -->|storage.ingest payload with otel_session_id| E1[otel_events populated]
    E -->|seedSessionWithOtel creates sessions + runs row| E2[DB session UUID returned]
    E1 & E2 --> E3[querySessionTimeline / querySessionCost joins runs → otel_events ✓]

    C --> F[intelligence-pipeline.test.ts]
    F -->|beforeEach drain: pgmq_read_queue vt=0 + archive loop| F1[Stale thought_processing messages cleared]
    F1 --> F2[thought insert enqueue assertion isolated ✓]

    C --> G[architecture.test.ts]
    G -->|branch/handlers.ts added to known-debt list| G1[SupabaseClient constraint passes ✓]

    C --> H[validate-pr-description.test.ts]
    H -->|File deleted — validator retired| H1[6 tests removed ✓]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/__tests__/intelligence-pipeline.test.ts:112-122
**Silent errors in queue drain may leave stale messages**

Both the `pgmq_read_queue` call and each `pgmq_archive_queue_message` call discard their `error` fields. If the read RPC fails, `stale` is `null` and the drain silently does nothing, leaving stale messages in the queue and potentially causing the immediately-following assertion tests to flake. Destructure and throw (or at minimum `console.warn`) on non-null error so a drain failure is visible rather than masked.

Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/test-suite-..." | Re-trigger Greptile


await storage.ingest(parseLogsPayload(logsPayload, TEST_WORKSPACE_ID));

const sessionId = await seedSessionWithOtel('timeline-session');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Static otelSessionId strings make these three tests fragile on repeated runs. The beforeEach only clears otel_events — it does not truncate sessions or runs. If the runs table has a uniqueness constraint on otel_session_id, or if querySessionTimeline/querySessionCost join through the runs table and pick up stale rows from a previous run, tests can give wrong counts or duplicate-key errors the second time pnpm test is run against the same database. randomUUID() is already imported in this file and used in the "no cost events" test directly below — apply the same pattern here.

Suggested change
const sessionId = await seedSessionWithOtel('timeline-session');
const sessionId = await seedSessionWithOtel(randomUUID());
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/otel/__tests__/otel-storage.test.ts
Line: 197

Comment:
Static otelSessionId strings make these three tests fragile on repeated runs. The `beforeEach` only clears `otel_events` — it does not truncate `sessions` or `runs`. If the `runs` table has a uniqueness constraint on `otel_session_id`, or if `querySessionTimeline`/`querySessionCost` join through the runs table and pick up stale rows from a previous run, tests can give wrong counts or duplicate-key errors the second time `pnpm test` is run against the same database. `randomUUID()` is already imported in this file and used in the "no cost events" test directly below — apply the same pattern here.

```suggestion
    const sessionId = await seedSessionWithOtel(randomUUID());
```

How can I resolve this? If you propose a fix, please make it concise.


await storage.ingest(parseLogsPayload(logsPayload, TEST_WORKSPACE_ID));

const sessionId = await seedSessionWithOtel('limit-session');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Same static-string issue as the timeline test above — use randomUUID() for isolation.

Suggested change
const sessionId = await seedSessionWithOtel('limit-session');
const sessionId = await seedSessionWithOtel(randomUUID());
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/otel/__tests__/otel-storage.test.ts
Line: 231

Comment:
Same static-string issue as the timeline test above — use `randomUUID()` for isolation.

```suggestion
    const sessionId = await seedSessionWithOtel(randomUUID());
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


const cost = await storage.querySessionCost(TEST_WORKSPACE_ID, 'cost-session');
expect(cost.session_id).toBe('cost-session');
const sessionId = await seedSessionWithOtel('cost-session');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Same static-string issue — use randomUUID() for isolation.

Suggested change
const sessionId = await seedSessionWithOtel('cost-session');
const sessionId = await seedSessionWithOtel(randomUUID());
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/otel/__tests__/otel-storage.test.ts
Line: 272

Comment:
Same static-string issue — use `randomUUID()` for isolation.

```suggestion
    const sessionId = await seedSessionWithOtel(randomUUID());
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

CREATE EXTENSION IF NOT EXISTS pgmq;
CREATE EXTENSION IF NOT EXISTS pg_cron;
CREATE EXTENSION IF NOT EXISTS pg_net;
CREATE EXTENSION IF NOT EXISTS pg_net WITH SCHEMA extensions;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Modifying an applied migration vs. adding a new one

This migration was timestamped April 2026, two months ago. Editing it in place is correct for environments that always reset from scratch (CI, supabase start), but any Supabase instance where this migration was already applied won't receive the WITH SCHEMA extensions fix — it would need a follow-up migration (ALTER EXTENSION pg_net SET SCHEMA extensions). If there is a remote/production instance, the pg_net schema fix won't land there until one is added.

Prompt To Fix With AI
This is a comment left during a code review.
Path: supabase/migrations/20260408033928_add_hub_tables_vectors_pgmq_realtime.sql
Line: 7

Comment:
**Modifying an applied migration vs. adding a new one**

This migration was timestamped April 2026, two months ago. Editing it in place is correct for environments that always reset from scratch (CI, `supabase start`), but any Supabase instance where this migration was already applied won't receive the `WITH SCHEMA extensions` fix — it would need a follow-up migration (`ALTER EXTENSION pg_net SET SCHEMA extensions`). If there is a remote/production instance, the pg_net schema fix won't land there until one is added.

How can I resolve this? If you propose a fix, please make it concise.

@glassBead-tc
glassBead-tc merged commit a0deb9e into main Jun 8, 2026
13 of 16 checks passed
@glassBead-tc
glassBead-tc deleted the fix/test-suite-green branch June 8, 2026 13:52
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