Files
supabase/apps/studio/lib/api/rate.test.ts
Matt Rossman ddabeac30c feat(studio): enable EU Assistant tracing (#53332)
Enables Braintrust tracing and feedback for Assistant chats on EU-region
projects. This was the final holdout that makes it so that tracing is
applied consistently across all projects.

Adds `projectRegion` metadata to root traces so the project’s region is
recorded with each chat (consistent with the existing
[isHighComplianceProject
metadata](https://github.com/supabase/supabase/blob/917dcb388939b8c54ea13c1e31b3c7285fb2ca65/apps/studio/lib/ai/generate-assistant-response.ts#L188)).

Verified in staging with a [successful Assistant trace recording
`projectRegion:
eu-central-1`](https://www.braintrust.dev/app/supabase.io/p/Assistant/logs?r=1b4a05d7a6c1414e62f532094aa39dc1&sid=4fdc76b08a4c5a43).

<img width="2656" height="1560" alt="CleanShot 2026-11-12 at 1 12 30
PM@2x"
src="https://github.com/user-attachments/assets/4e81033a-c754-46db-845d-586d1d71e035"
/>

Closes AI-1197
2026-11-13 11:02:46 -05:00

76 lines
1.8 KiB
TypeScript

import { expect, test, vi } from 'vitest'
// End of third-party imports
import { sanitizeMessagePart } from '../ai/tools/tool-sanitizer'
import { Route } from '@/routes/api/ai/feedback/rate'
import { getRouteHandler } from '@/tests/lib/server-route'
vi.mock('../ai/tools/tool-sanitizer', () => ({
sanitizeMessagePart: vi.fn((part) => part),
}))
vi.mock('@/lib/ai/ai-details', () => ({
getAIDetails: vi.fn().mockResolvedValue({
aiOptInLevel: 'schema_and_log_and_data',
hasAccessToAdvanceModel: true,
orgId: 1,
}),
}))
vi.mock('@/lib/ai/model', () => ({
getModel: vi.fn().mockResolvedValue({
modelParams: { model: {} },
}),
}))
vi.mock('ai', () => ({
generateText: vi.fn().mockResolvedValue({
output: {
category: 'sql_generation',
},
}),
Output: { object: vi.fn() },
}))
vi.mock('@/components/ui/AIAssistantPanel/Message.utils', () => ({
rateMessageResponseSchema: {},
}))
test('rate calls the tool sanitizer', async () => {
const response = await getRouteHandler(
Route,
'POST'
)({
request: new Request('http://localhost/api/ai/feedback/rate', {
method: 'POST',
headers: {
Authorization: 'Bearer test-token',
'Content-Type': 'application/json',
},
body: JSON.stringify({
rating: 'negative',
messages: [
{
role: 'assistant',
parts: [
{
type: 'tool-execute_sql',
state: 'output-available',
output: 'test output',
},
],
},
],
messageId: 'test-message-id',
projectRef: 'test-project',
orgSlug: 'test-org',
reason: 'The response was not helpful',
}),
}),
})
expect(response.status).toBe(200)
expect(sanitizeMessagePart).toHaveBeenCalled()
})