79 lines
2.8 KiB
JavaScript
79 lines
2.8 KiB
JavaScript
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const url = 'https://llnocwyqvhgwpdjcqqyw.supabase.co'
|
|
const anonKey = 'sb_publishable_0uo4UYYvUO2y-sVMFdYylA_hHv9qRt5'
|
|
const email = process.env.D3RO_PUBLIC_E2E_EMAIL?.trim() ?? ''
|
|
const password = process.env.D3RO_PUBLIC_E2E_PASSWORD ?? ''
|
|
|
|
if (!email || !password) {
|
|
throw new Error('D3RO_PUBLIC_E2E_EMAIL and D3RO_PUBLIC_E2E_PASSWORD are required')
|
|
}
|
|
|
|
const client = createClient(url, anonKey, {
|
|
auth: { persistSession: false, autoRefreshToken: false },
|
|
})
|
|
|
|
function assert(condition, message) {
|
|
if (!condition) throw new Error(message)
|
|
}
|
|
|
|
let historyId = null
|
|
|
|
try {
|
|
const login = await client.auth.signInWithPassword({ email, password })
|
|
if (login.error) throw login.error
|
|
assert(login.data.session?.user?.id, 'public test account login did not return a session')
|
|
|
|
const anon = createClient(url, anonKey, {
|
|
auth: { persistSession: false, autoRefreshToken: false },
|
|
})
|
|
const anonymousDashboard = await anon.rpc('mobile_dashboard_stats')
|
|
assert(anonymousDashboard.error !== null, 'anonymous dashboard RPC must be denied')
|
|
|
|
const historyInsert = await client.from('history').insert({
|
|
user_id: login.data.session.user.id,
|
|
title: 'Public runtime dashboard proof',
|
|
original_text: 'public runtime proof transcript',
|
|
mode: 'dictation',
|
|
status: 'completed',
|
|
duration: 42,
|
|
word_count: 4,
|
|
app_version: 'mobile-e2e',
|
|
}).select('id').single()
|
|
if (historyInsert.error) throw historyInsert.error
|
|
historyId = historyInsert.data.id
|
|
|
|
const dashboard = await client.rpc('mobile_dashboard_stats')
|
|
if (dashboard.error) throw dashboard.error
|
|
assert(Number(dashboard.data?.total_sessions) >= 1, 'dashboard did not count authenticated history')
|
|
assert(
|
|
dashboard.data?.recent_history?.some((entry) => entry?.id === historyId),
|
|
'dashboard recent history did not contain the new row',
|
|
)
|
|
|
|
const llm = await client.functions.invoke('llm-proxy', {
|
|
body: {
|
|
messages: [{ role: 'user', content: 'Reply with one short Korean greeting.' }],
|
|
max_tokens: 32,
|
|
stream: false,
|
|
},
|
|
})
|
|
if (llm.error) throw llm.error
|
|
const assistantText = Array.isArray(llm.data?.content)
|
|
? llm.data.content
|
|
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
|
|
.map((block) => block.text)
|
|
.join('')
|
|
.trim()
|
|
: ''
|
|
assert(assistantText.length > 0, 'llm-proxy returned no real assistant text')
|
|
|
|
console.log('public_mobile_runtime_ok anonymous_rpc=denied dashboard=exact llm=real')
|
|
} finally {
|
|
if (historyId) {
|
|
const cleanup = await client.from('history').delete().eq('id', historyId)
|
|
if (cleanup.error) console.error('public_history_fixture_cleanup_required')
|
|
}
|
|
await client.auth.signOut({ scope: 'local' }).catch(() => undefined)
|
|
await client.removeAllChannels()
|
|
}
|