feat(supabase): publish gate on the Rust core's sheet.check, fail closed

publishSheetVersion(client, versionId, validate) takes the core's
sheet.check (the package never loads the module itself); anything but a
publishable verdict refuses publication before the RPC: invalid_shape,
not_publishable (same message as before: first error code), and
validator_unavailable when the core cannot run. Tests run on the real
Node core; the shape case now asserts the closed kind instead of any
throw. The package no longer depends on @faunosteo/domain.
This commit is contained in:
bchanot committed 2026-10-14 00:29:03 +02:00
1 parent 21906c4358
commit 6891f9ea25
6 files changed
+119 -18

No files matched your search

@@ -1,5 +1,15 @@
import { publishSheetVersion } from '../src'
import type { FaunosteoClient } from '../src'
import { nodeCoreRuntime } from '@faunosteo/core-wasm/node'
import type { CoreRuntime } from '@faunosteo/core-wasm'
import { publishSheetVersion, SheetPublishError } from '../src'
import type { FaunosteoClient, SheetCheckOutcome, SheetValidator } from '../src'
/** The real core's `sheet.check` (R2): the gate is never tested against a stub verdict. */
let core: CoreRuntime
beforeAll(async () => {
core = await nodeCoreRuntime()
})
const validate: SheetValidator = (content) =>
core.call('sheet.check', JSON.stringify(content)) as SheetCheckOutcome
/**
* Stub of the two client calls publishSheetVersion makes. The real RPC is
@@ -48,9 +58,21 @@ const publishable = {
}
describe('publishSheetVersion', () => {
it('refuses publication when the validator cannot run (fail closed)', async () => {
const { client, rpcCalls } = stubClient(publishable)
const unavailable: SheetValidator = () => ({
ok: false,
kind: 'core_unavailable',
})
await expect(
publishSheetVersion(client, 'v1', unavailable),
).rejects.toMatchObject({ kind: 'validator_unavailable' })
expect(rpcCalls).toEqual([])
})
it('calls the RPC once the document passes shape and integrity checks', async () => {
const { client, rpcCalls } = stubClient(publishable)
await expect(publishSheetVersion(client, 'v1')).resolves.toBe(
await expect(publishSheetVersion(client, 'v1', validate)).resolves.toBe(
'published-id',
)
expect(rpcCalls).toEqual([['publish_sheet_version', { version_id: 'v1' }]])
@@ -61,7 +83,7 @@ describe('publishSheetVersion', () => {
...publishable,
views: [{ ...publishable.views[0], svg_asset_id: null }],
})
await expect(publishSheetVersion(client, 'v1')).rejects.toThrow(
await expect(publishSheetVersion(client, 'v1', validate)).rejects.toThrow(
/view\.asset\.missing/,
)
expect(rpcCalls).toEqual([])
@@ -69,7 +91,12 @@ describe('publishSheetVersion', () => {
it('refuses a document that does not match the schema', async () => {
const { client, rpcCalls } = stubClient({ schema_version: 1 })
await expect(publishSheetVersion(client, 'v1')).rejects.toThrow()
await expect(
publishSheetVersion(client, 'v1', validate),
).rejects.toBeInstanceOf(SheetPublishError)
await expect(
publishSheetVersion(client, 'v1', validate),
).rejects.toMatchObject({ kind: 'invalid_shape' })
expect(rpcCalls).toEqual([])
})
})