Files
supabase/apps/studio/lib/ai/assistant-context.test.ts
barcofourie 7e56800992 fix(assistant): update support assistant messaging for clarity and consistency (#54112)
## Problem

The AI Assistant follow-up on support requests (behind the
`supportAssistantFollowUp` flag) told users with service restrictions to
ask Support for an exception. In almost every restriction ticket we
reviewed during the production test, the Assistant suggested this, and
Support then declined.

## Solution

Rather than a rule for each ticket type, this adds one general rule to
the server-side support-mode context and removes the "a human will
reply" framing.

`escalate_to_human` is unchanged, so users who ask for a person can
still be escalated.

## Review instructions

Read the diff to `assistant-context.ts` and `SupportAssistant.utils.ts`,
and check that the rule is general and doesn't name a particular ticket
type.


## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-12-03 06:23:54 +02:00

94 lines
3.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildAssistantContextMessages, NO_SCHEMA_ACCESS_MESSAGE } from '@/lib/ai/assistant-context'
const SCHEMAS = 'The available database schema names are: ["public"]'
describe('buildAssistantContextMessages', () => {
it('describes the project when there is project context', () => {
const messages = buildAssistantContextMessages({
projectRef: 'abcdefghijklmnopqrst',
chatName: 'Slow queries',
schemasString: SCHEMAS,
now: new Date('2026-08-20T06:53:00.000Z'),
})
expect(messages).toHaveLength(1)
expect(messages[0].role).toBe('assistant')
expect(messages[0].content).toContain('abcdefghijklmnopqrst')
expect(messages[0].content).toContain(SCHEMAS)
expect(messages[0].content).toContain('Slow queries')
expect(messages[0].content).toContain('2026-08-20T06:53:00.000Z')
expect(messages[0].content).toContain('iso_timestamp_start')
})
it('omits the project message when there is nothing to say', () => {
const messages = buildAssistantContextMessages({
schemasString: NO_SCHEMA_ACCESS_MESSAGE,
})
expect(messages).toEqual([])
})
it('tells the model the current opt-in level so it does not ask for access it has', () => {
const messages = buildAssistantContextMessages({
schemasString: NO_SCHEMA_ACCESS_MESSAGE,
aiOptInLevel: 'schema_and_log_and_data',
})
expect(messages).toHaveLength(1)
expect(messages[0].content).toContain('schema_and_log_and_data')
})
it('adds the support instructions in support mode', () => {
const messages = buildAssistantContextMessages({
schemasString: NO_SCHEMA_ACCESS_MESSAGE,
supportMode: true,
})
expect(messages).toHaveLength(1)
expect(messages[0].content).toContain('active support chat')
expect(messages[0].content).toContain('only Supabase staff can take')
expect(messages[0].content).not.toContain('wait for a human')
})
it('leaves the staff-only actions rule out of non-support chats', () => {
const messages = buildAssistantContextMessages({
projectRef: 'abcdefghijklmnopqrst',
schemasString: SCHEMAS,
})
expect(messages.map((message) => message.content).join('\n')).not.toContain(
'only Supabase staff can take'
)
})
it('adds ClickHouse instructions when the conversation attached a logs query', () => {
const messages = buildAssistantContextMessages({
projectRef: 'abcdefghijklmnopqrst',
schemasString: SCHEMAS,
includesLogsSnippets: true,
})
expect(messages).toHaveLength(2)
const logsContext = messages[1].content
// The dialect rules, so it doesn't answer in Postgres...
expect(logsContext).toContain('ClickHouse')
// ...and the table reference, so it doesn't invent BigQuery-style unnests.
expect(logsContext).toContain('log_attributes')
expect(logsContext).toContain("where source = 'edge_logs'")
expect(logsContext).not.toContain('cannot run')
})
it('adds nothing extra for a database-only conversation', () => {
const messages = buildAssistantContextMessages({
projectRef: 'abcdefghijklmnopqrst',
schemasString: SCHEMAS,
includesLogsSnippets: false,
})
expect(messages).toHaveLength(1)
expect(messages[0].content).not.toContain('ClickHouse')
})
})