/better-supabase:better-supabase-testingfrom better-supabase
Tests Supabase RLS policies, APIs, and SQL against the local stack using better-supabase/testing, typed seeds, and pgTAP. Useful when writing or fixing tests that touch the database, policies, auth, OAuth, or agent scopes.
Ships in better-supabase. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Test against the local stack (supabase start) as real users. Don't mock
supabase-js, and don't use the service role for anything a user does.
supabase start) and write .env.local with
better-supabase dev env. In a sandbox without Docker, start it with
SUPABASE_EXPERIMENTAL_STACK=1 (the Supabase CLI's native stack).supabase/seed.ts, including one row
owned by another tenant, then supabase db reset.asUser for each role that matters.not_found or forbidden.supabase test db if the project has pgTAP tests.Done when the test fails after you drop or loosen the policy, and passes again once you restore it.
better-supabase dev env writes the URL and keys to .env.local; load it in the test setup.better-supabase dev keys creates supabase/signing_keys.json. Set signing_keys_path = "./signing_keys.json" under [auth] in supabase/config.toml, gitignore the file and restart the stack. asUser signs ES256 tokens with it.supabase/seed.ts:import { defineSeed } from "better-supabase/testing";
import { betterSupabase } from "../src/lib/supabase/index.ts";
export const seed = defineSeed(betterSupabase, {
organizations: { acme: { id: ACME, name: "Acme" } },
customers: { first: { id: FIRST, organizationId: ACME, name: "First" } },
});
better-supabase db seed renders them to SQL for supabase db reset, and
tests import the same rows (seed.rows.customers.first.id).
const alice = await asUser(
betterSupabase,
{ sub: aliceId, tenant_id: ACME },
{ postgres },
);
expect(await alice.db.customers.count().orThrow()).toBe(1);
expect(await alice.db.customers.get(OTHER_ORGANIZATION_CUSTOMER)).toMatchObject(
{ ok: false },
);
alice.sql runs the same checks over direct Postgres.result.error.kind (not_found, forbidden, conflict, validation), not on messages.Send authorization: Bearer ${alice.token} (or a token from signLocalJwt).
The adapter verifies it against the local JWKS; no test-only resolver is needed.
For a route with scopes, sign a delegated token the way the Supabase OAuth
server or an agent token exchange would, and assert both sides:
const client = await signLocalJwt({
sub: aliceId,
tenant_id: ACME,
client_id: "c1",
scope: "openid", // add "customers:read" to pass
});
const response = await app.request("/api/customers", {
headers: { authorization: `Bearer ${client}` },
});
expect(response.status).toBe(403);
expect(response.headers.get("www-authenticate")).toContain(
'error="insufficient_scope"',
);
The user's own token (no client_id, no act) must still pass, and a
malformed act claim (act: { sub: "" }) must get a 401.
With gen.codecs.timestamptz: 'instant', rows hold Temporal values. Import
temporal-polyfill/global in the test setup on Node 24, and compare with
.equals() or an equality tester, because toEqual treats any two instants
as equal:
import "temporal-polyfill/global";
import { expect } from "vitest";
expect.addEqualityTesters([
(a, b) =>
a instanceof Temporal.Instant && b instanceof Temporal.Instant
? a.equals(b)
: undefined,
]);
With the polyfill, vi.useFakeTimers({ now }) drives Temporal.Now too.
Run pnpm better-supabase doctor against the reset stack and fail the job on
a nonzero exit. --json puts the report, with each finding's code, under data,
--format github annotates the pull request, and
--format sarif --out doctor.sarif feeds code scanning.
better-supabase add pgtap installs tests.create_user,
tests.authenticate_as(user, claims), tests.clear_authentication() and
tests.rls_enabled('public') for supabase test db. Put
select tests.rls_enabled('public'); in a test so tables without RLS fail CI.
tests.import_run_fixture(source, entities, state) creates a run in pending,
running, stale or canceled. tests.age_import_run(run, interval) moves
its lease and heartbeat into the past. tests.bulk_touch_subjects(entity, n)
moves the stored import stamp of n records into the past.
tests.assert_override_dispatches_all(signature) fails when the function is
missing a when arm for an entity import_entities() returns.
testImportTarget({ entity, fixture }) from better-supabase/testing builds
the pgTAP shape for a target: the first import inserts, the second is
unchanged, a changed hash updates, a user edit conflicts, a dry run leaves no
subject rows, import mode suppresses events, and the target returns updatedAt.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
4 skills in this plugin
/better-supabaseQuery and write Supabase data with better-supabase's typed repositories, Results and codegen. Use when code imports better-supabase, when adding a table, query or mutation, when a Supabase type is out of date, or after upgrading better-supabase./better-supabase-apiBuild HTTP APIs, Edge Functions and MCP servers on Supabase with better-supabase adapters. Use when adding a route, REST resource, oRPC procedure, Edge Function, MCP tool, AI chat route, knowledge or memory, stored agent, MCP connector, eve agent, Chat SDK bot, resumable stream, third-party credential, OAuth or agent scopes, webhook, background job, cleanup cron or idempotent endpoint./better-supabase-authnpx claudepluginhub scaledockhq/better-supabase --plugin better-supabaseOther plugins' skills for the same job