Open History to see the last commit
1import { defineByok, memoryStorage } from '@tanstack/ai-client/byok'
2import { act, renderHook } from '@testing-library/react'
3import { describe, expect, it } from 'vitest'
4import { useByok } from '../src/use-byok'
5
6const RAW_KEY = 'sk-abcdefghij'
7
8describe('useByok', () => {
9 it('reads the snapshot, remasks after update, and never exposes the raw key', async () => {
10 const client = defineByok({ storage: memoryStorage() })
11 const { result } = renderHook(() => useByok(client))
12
13 expect(result.current.status.openai).toBeUndefined()
14 expect(JSON.stringify(result.current)).not.toContain(RAW_KEY)
15
16 await act(async () => {
17 await client.update('openai', RAW_KEY)
18 })
19
20 expect(result.current.status.openai).toEqual({
21 state: 'set',
22 masked: 'ghij',
23 })
24 expect(JSON.stringify(result.current)).not.toContain(RAW_KEY)
25 expect(JSON.stringify(result.current.status.openai)).not.toContain(RAW_KEY)
26 })
27})