Files
bchanot 7bf4fb6079 feat(supabase): workspaces M1, one personal workspace per account
V1-1.1 (contract V1-1_OWNERS_ANIMALS.md §4, §8, §9). Tables workspaces and workspace_members, created with the profile by trigger through one atomic, idempotent write path; deferred invariant (a personal workspace has exactly its account as holder); backfill of existing profiles; access helpers caller_workspace_ids (active profile, confirmed email) and writable_workspace_ids; RLS select for members only; no privilege for anon or service_role. log_event keeps x-correlation-id only as a short token. pgTAP 012 (85 checks), census and types updated, config test.
2026-10-25 19:53:16 +01:00

39 lines
1.4 KiB
TypeScript

import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { supabaseDir } from './harness'
/**
* Settings the workspace access rule depends on (V1-1 contract §6.2, §9.1).
* private.caller_workspace_ids() requires auth.users.email_confirmed_at, but
* with confirmations off GoTrue stamps that column at sign-up; the helpers
* live in `private`, which must stay out of the PostgREST schemas.
*/
async function readSetting(
section: string,
key: string,
): Promise<string | undefined> {
const config = await readFile(join(supabaseDir, 'config.toml'), 'utf8')
let current = ''
for (const line of config.split('\n')) {
const header = line.match(/^\[([^\]]+)\]\s*$/)
if (header) current = header[1]
const setting = line.match(/^(\w+)\s*=\s*(.+?)\s*$/)
if (current === section && setting?.[1] === key) return setting[2]
}
return undefined
}
describe('config.toml settings the access rules rely on', () => {
it('requires email confirmation before any session', async () => {
expect(await readSetting('auth.email', 'enable_confirmations')).toBe('true')
})
it('keeps anonymous sign-ins off (no account without an email)', async () => {
expect(await readSetting('auth', 'enable_anonymous_sign_ins')).toBe('false')
})
it('exposes only the public schema through PostgREST', async () => {
expect(await readSetting('api', 'schemas')).toBe('["public"]')
})
})