Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions evals/docs/build-docs-042-realtime-broadcast/EVAL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
buildDocsResult,
type CheckResult,
type LocalStackEvalContext,
type LocalStackScorer,
} from '@supabase-evals/core';
import {
applyPendingMigrations,
checkMigrationsWereApplied,
} from './migrations.js';
import {
checkCannotForge,
checkInstalled,
checkLoads,
checkMemberSees,
checkNeverSees,
probeRooms,
} from './probes.js';

const GUIDE_PATH = 'guides/realtime/broadcast';

const scorer: LocalStackScorer = async (ctx) => {
try {
const migrations = await applyPendingMigrations(ctx);
const outcome = await probeRooms(ctx);

const checks: CheckResult[] = [
checkMigrationsWereApplied(migrations),
checkInstalled(outcome),
checkLoads(outcome),
checkMemberSees(outcome, 'mobile'),
checkMemberSees(outcome, 'inbox'),
checkMemberSees(outcome, 'web'),
checkNeverSees(outcome, 'outsider'),
checkNeverSees(outcome, 'visitor'),
checkCannotForge(outcome),
checkGuideWasRead(ctx),
];

return { passed: checks.every((check) => check.passed), checks };
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return {
passed: false,
checks: [
{
name: 'scorer evaluated who sees new room messages',
passed: false,
notes: message,
},
],
};
}
};

export default scorer;

function checkGuideWasRead(ctx: LocalStackEvalContext): CheckResult {
const calls = buildDocsResult(ctx.toolCalls).calls.filter((call) =>
call.pages?.some((page) => page.url.includes(GUIDE_PATH))
);
const withContent = calls.filter((call) => call.hasContent);
return {
name: 'the agent read the Broadcast guide the prompt referenced',
passed: withContent.length > 0,
notes:
withContent.length > 0
? withContent.map((call) => call.source).join(', ')
: calls.length > 0
? `reached the guide via ${calls.map((call) => call.source).join(', ')} but retrieved no page content`
: 'no docs call reached the guide',
};
}
38 changes: 38 additions & 0 deletions evals/docs/build-docs-042-realtime-broadcast/PROMPT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
stage: build
interface: cli
product:
- realtime
- database
topic:
- security
- sdk
services:
- gotrue
- kong
- postgrest
- realtime
motivation: >-
A chat room needs each new message pushed to the people in the room, and
only to them. Customers and agents send from the database to a client that
never receives it, or open the room to every signed-in user so that it does.
This checks that an agent reading the Broadcast guide gets a new message to
the room's members as it lands and to nobody outside the room. The prompt
omits the guide's vocabulary on purpose, so read README.md before editing it.
---

Burrow is our team chat. Right now people only see new messages in a room when
they reload. I want a new message to show up for everyone in the room the
moment it's saved, whether it came from the web app, the mobile app or the
support inbox. ROOMS.md says where the web app's part goes.

Rooms are members only. Nobody outside a room should ever see its messages or
be able to slip a message into it, even someone who skips our app and talks to
Supabase directly. Set that up in the local project and make sure it works on
the local stack.

Read the guide below before you start and rely on it for how to set this up,
rather than on what you already know.

REFERENCE
https://supabase.com/docs/guides/realtime/broadcast.md
94 changes: 94 additions & 0 deletions evals/docs/build-docs-042-realtime-broadcast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# build-docs-042-realtime-broadcast

## What this eval measures

The subject is [Broadcast](https://supabase.com/docs/guides/realtime/broadcast), not the agent. The prompt is a product
request plus the page's url, and the checks say whether an agent that read the page gets a new room message to the right
people.

One claim: a message saved to a room reaches the room's members live, and nobody outside the room can receive it or slip
one in.

## Do not reintroduce the vocabulary

Keep all of these out of `PROMPT.md`:

realtime, broadcast, channel, private, topic, subscribe, websocket, socket, RLS, row level security, policy,
`realtime.messages`, `realtime.topic()`, extension, authorization, trigger, `realtime.send`, `broadcast_changes`,
`setAuth`, JWT, token, publication, Postgres Changes, presence, ack, self, REST, httpSend.

"Live", "members only" and "talks to Supabase directly" stay, because that is how the team would say it. `public` is
the schema name the seed already shows, so it is not stripped.

## The seed carries the contract

- `local/ROOMS.md` fixes `watchRoom(supabase, roomId, onMessage)` in `src/live.js`, and says messages arrive from three
places. Two of them write straight to `public.messages`, so sending from the poster's browser does not reach anyone.
- `public.messages`, `public.room_members` and the helper `public.is_room_member` already keep non-members out of a
room's rows. The eval measures the live path, not the table's access rules.
- `local/package.json` and `local/package-lock.json` pin `@supabase/supabase-js`.

## Scoring needs the npm registry

The scorer runs `npm ci` in the workspace so the agent's `src/live.js` can import its dependencies. It installs its own
pinned `@supabase/supabase-js` into a directory outside the workspace, so the clients it builds do not depend on what
the agent did to `package.json`. Both need network access to the npm registry. A failed install fails the eval. Read it
as a lost run, unless the note shows `npm ci` failed on a lockfile the agent changed.

## Do not drop the positive controls

The outsider, visitor and forgery checks pass for a project with no live path at all. The three member checks are what
make them mean something. The outsider and visitor checks also fail as could-not-measure when `watchRoom` joined nothing
on the client it was given, because then there is no topic to try directly. The forgery check fails as could-not-measure
in that case too, and when the scorer's own message on its control topic never arrives.

## How the checks read the end state

- A member, a poster and a person from another room are created per run, with rooms named for the run. The member
watches through the agent's `watchRoom`.
- Three messages go to the room, each with a run-scoped body: the poster inserts one through the API like the mobile app,
the superuser inserts one with no signed-in user like the support inbox, and the poster calls `postMessage` from
`src/messages.js` like the web app. Each member check needs that body at the callback within 10 seconds. The note
names the route that delivered it, `broadcast` or `postgres_changes`, so a baseline can be read by route.
- The outsider and a visitor with no session watch three ways: through `watchRoom`, and directly on every topic the
member's client joined, once as a members-only join and once as an open one. Any of the three bodies arriving fails
the check.
- The forgery check has the outsider insert a whole row into the room's messages. A refusal counts only when the
superuser then finds no such row. It also copies what the member's client received, swaps in a new body, and sends it
as the outsider on each topic, both joins, over the socket and the HTTP endpoint. An HTTP send is listed as tried only
when the request got a response. A stored row, or either body at the member's callback, fails the check.
- The shape of what the callback gets is not scored. Only that it carries the body.
- Before any of this, the scorer sends a members-only test message from the database to its own control topic, and
listens there with the service role key, which no rule on `realtime.messages` can refuse. If it never arrives, every
probe fails as could-not-measure. Either the stack is not delivering, or the agent's migration broke sending from the
database. The forgery check's control is a message the scorer sends on the same topic.
- The local stack allows open joins unless the project turns them off, as hosted projects do with "Allow public
access". An open join to the room's topic is attempted on purpose. A project that turns public channels off is
accepted: the scorer's own control does not depend on public channels, and a refused open join or send counts as no
leak and no forgery.

## Order of the scorer

The scorer applies pending migrations with `supabase migration up --local` first, which writes to the database, so score
once per stack. It installs, then one script runs the probes in order: load, the database test message, setup, watching,
posting, then forging. A failed step marks every later probe as not run with its note. The script stops itself after 200
seconds, above the sum of its own waits.

## The guide has to actually be read

`the agent read the Broadcast guide the prompt referenced` requires a docs call that reached the page with content. Read
`docs.calls` before reading a score.

## Checks expected to saturate

The migration, install and load checks, and the visitor check. The signal is expected in the member checks and the
outsider check.

## What this eval does not score

- **Which mechanism carries the message.** Any route that delivers to members and nobody else passes, including changes
read from the table instead of sent. The member checks name the route.
- **What the callback receives.** Only that it carries the message body.
- **Removing someone from a room.** Access is checked when the room is opened, and the prompt does not ask about leaving.
- **Typing indicators, presence and replay.** The prompt asks only for new messages.
- **Hosted projects.** The "Allow public access" setting and billing are out of reach locally.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
32 changes: 32 additions & 0 deletions evals/docs/build-docs-042-realtime-broadcast/local/ROOMS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Rooms

Burrow is a team chat. A room's messages are for the people in that room and nobody else. `room_members` says who is
in which room, and the database already keeps everyone else out of a room's messages.

## Where messages come from

New messages land in `public.messages` from three places:

- The web app, through `postMessage` in `src/messages.js`.
- The mobile app, which inserts into `messages` through the API as the signed-in person.
- The support inbox, a server job that inserts customer replies straight into `messages`.

## Showing new messages in the web app

The room screen calls `watchRoom` from `src/live.js` when it opens:

```js
import { watchRoom } from './live.js'

const stop = await watchRoom(supabase, roomId, (message) => {
appendToThread(message)
})
```

- `supabase` is the app's client, already signed in as the person looking at the room.
- `roomId` is `rooms.id`.
- The callback gets each new message in that room as a `messages` row: `id`, `room_id`, `author_id`, `body`,
`created_at`.
- `watchRoom` returns, or resolves to, a function that stops watching.

The room screen closes with `stop()`.
120 changes: 120 additions & 0 deletions evals/docs/build-docs-042-realtime-broadcast/local/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "burrow",
"private": true,
"type": "module",
"dependencies": {
"@supabase/supabase-js": "2.118.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export async function postMessage(supabase, roomId, body) {
const { data, error } = await supabase
.from('messages')
.insert({ room_id: roomId, body })
.select('id, room_id, author_id, body, created_at')
.single();
if (error) throw error;
return data;
}

export async function recentMessages(supabase, roomId, limit = 50) {
const { data, error } = await supabase
.from('messages')
.select('id, room_id, author_id, body, created_at')
.eq('room_id', roomId)
.order('created_at', { ascending: false })
.limit(limit);
if (error) throw error;
return data.reverse();
}
Loading