@@ -40,96 +40,114 @@ vi.mock("../../state/environments", async (importOriginal) => ({
4040 } ) ,
4141} ) ) ;
4242
43- it ( "enables the chosen provider only after a successful setup and keeps its grant when editing the key" , async ( ) => {
44- const id = EnvironmentId . make ( "voice-host" ) ;
45- const target = new PrimaryConnectionTarget ( {
46- environmentId : id ,
47- label : "Laptop" ,
48- httpBaseUrl : window . location . origin ,
49- wsBaseUrl : "ws://localhost" ,
50- } ) ;
51- const prepared = Option . some ( {
52- ...target ,
53- target,
54- socketUrl : target . wsBaseUrl ,
55- httpAuthorization : null ,
56- } ) ;
57- using cleanup = new DisposableStack ( ) ;
58- cleanup . defer ( ( ) => chooseAudioDestination ( null ) ) ;
59- chooseAudioDestination ( { kind : "environment" , environmentId : id } ) ;
60- const writes : unknown [ ] = [ ] ;
61- let rejectNextWrite = true ;
62- const fetch = globalThis . fetch ;
63- using _network = vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( ( request , init ) => {
64- const url = new URL ( request instanceof Request ? request . url : request , window . location . href ) ;
65- if ( url . pathname === "/api/voice/cloud/keys" )
66- return Promise . resolve ( Response . json ( { openai : writes . length > 0 , xai : true } ) ) ;
67- if ( url . pathname === "/api/voice/cloud/openai/key" ) {
68- if ( rejectNextWrite ) {
69- rejectNextWrite = false ;
70- return Promise . resolve ( new Response ( null , { status : 403 } ) ) ;
43+ it . each ( [ "setup" , "key replacement" , "provider switch and disable" ] as const ) (
44+ "preserves cloud voice consent during %s" ,
45+ async ( flow ) => {
46+ const id = EnvironmentId . make ( "voice-host" ) ;
47+ const target = new PrimaryConnectionTarget ( {
48+ environmentId : id ,
49+ label : "Laptop" ,
50+ httpBaseUrl : window . location . origin ,
51+ wsBaseUrl : "ws://localhost" ,
52+ } ) ;
53+ const prepared = Option . some ( {
54+ ...target ,
55+ target,
56+ socketUrl : target . wsBaseUrl ,
57+ httpAuthorization : null ,
58+ } ) ;
59+ using cleanup = new DisposableStack ( ) ;
60+ cleanup . defer ( ( ) => chooseAudioDestination ( null ) ) ;
61+ chooseAudioDestination (
62+ flow === "setup"
63+ ? { kind : "environment" , environmentId : id }
64+ : { kind : "cloud" , provider : "openai" , environmentId : id } ,
65+ ) ;
66+ const writes : unknown [ ] = [ ] ;
67+ let rejectNextWrite = flow === "setup" ;
68+ const fetch = globalThis . fetch ;
69+ using _network = vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( ( request , init ) => {
70+ const url = new URL ( request instanceof Request ? request . url : request , window . location . href ) ;
71+ if ( url . pathname === "/api/voice/cloud/keys" )
72+ return Promise . resolve (
73+ Response . json ( { openai : flow !== "setup" || writes . length > 0 , xai : true } ) ,
74+ ) ;
75+ if ( url . pathname === "/api/voice/cloud/openai/key" ) {
76+ if ( rejectNextWrite ) {
77+ rejectNextWrite = false ;
78+ return Promise . resolve ( new Response ( null , { status : 403 } ) ) ;
79+ }
80+ return new Request ( request , init ) . json ( ) . then ( ( body ) => {
81+ writes . push ( body ) ;
82+ return new Response ( null , { status : 204 } ) ;
83+ } ) ;
7184 }
72- return new Request ( request , init ) . json ( ) . then ( ( body ) => {
73- writes . push ( body ) ;
74- return new Response ( null , { status : 204 } ) ;
75- } ) ;
76- }
77- return fetch ( request , init ) ;
78- } ) ;
79- await vi . mocked ( useEnvironmentScope ) . withImplementation (
80- ( ) => true ,
81- async ( ) => {
82- await vi . mocked ( usePreparedConnection ) . withImplementation (
83- ( ) => prepared ,
84- async ( ) => {
85- await using screen = await render (
86- < SettingsScopeProvider search = { { } } onChange = { ( ) => { } } >
87- < VoiceSettingsPanel />
88- </ SettingsScopeProvider > ,
89- ) ;
90- const destination = screen . getByRole ( "combobox" , { name : "Transcribe with" } ) ;
91- await expect . element ( destination ) . toHaveTextContent ( "Laptop" ) ;
92- await destination . click ( ) ;
93- await page . getByRole ( "option" , { name : "OpenAI via Laptop" } ) . click ( ) ;
94- const dialog = page . getByRole ( "dialog" ) ;
95- await dialog . getByRole ( "button" , { name : "Cancel" } ) . click ( ) ;
96- await expect . element ( destination ) . toHaveTextContent ( "Laptop" ) ;
97- expect ( writes ) . toEqual ( [ ] ) ;
98- await destination . click ( ) ;
99- await page . getByRole ( "option" , { name : "OpenAI via Laptop" } ) . click ( ) ;
100- await dialog . getByRole ( "combobox" , { name : "OpenAI API key source" } ) . click ( ) ;
101- await page . getByRole ( "option" , { name : "Work vault" } ) . click ( ) ;
102- await dialog . getByLabelText ( "OpenAI API key reference" ) . fill ( "op://Work/Voice/key" ) ;
103- await userEvent . keyboard ( "{Enter}" ) ;
104- await expect . element ( dialog . getByRole ( "alert" ) ) . toBeVisible ( ) ;
105- expect ( writes ) . toEqual ( [ ] ) ;
106- await expect
107- . element ( dialog . getByRole ( "button" , { name : "Save and enable" } ) )
108- . toBeEnabled ( ) ;
109- await dialog . getByLabelText ( "OpenAI API key reference" ) . click ( ) ;
110- await userEvent . keyboard ( "{Enter}" ) ;
111- await expect . element ( dialog ) . not . toBeInTheDocument ( ) ;
112- await expect . element ( destination ) . toHaveTextContent ( "OpenAI via Laptop" ) ;
113- expect ( writes ) . toEqual ( [ { key : { provider : "work" , reference : "op://Work/Voice/key" } } ] ) ;
114- const grant = window . localStorage . getItem ( "t3code:voice-audio-grant:v1" ) ;
115- await screen . getByRole ( "button" , { name : "Manage key" } ) . click ( ) ;
116- await dialog . getByLabelText ( "OpenAI API key" , { exact : true } ) . fill ( "replacement" ) ;
117- await userEvent . keyboard ( "{Enter}" ) ;
118- await expect . element ( dialog ) . not . toBeInTheDocument ( ) ;
119- expect ( writes . at ( - 1 ) ) . toEqual ( { key : "replacement" } ) ;
120- expect ( window . localStorage . getItem ( "t3code:voice-audio-grant:v1" ) ) . toBe ( grant ) ;
121- await destination . click ( ) ;
122- await page . getByRole ( "option" , { name : "Grok Voice Transcribe via Laptop" } ) . click ( ) ;
123- await dialog . getByRole ( "button" , { name : "Use Grok Voice Transcribe" } ) . click ( ) ;
124- await expect . element ( destination ) . toHaveTextContent ( "Grok Voice Transcribe via Laptop" ) ;
125- await destination . click ( ) ;
126- await page . getByRole ( "option" , { name : "Off" , exact : true } ) . click ( ) ;
127- await expect . element ( destination ) . toHaveTextContent ( "Off" ) ;
128- } ,
129- ) ;
130- } ,
131- ) ;
132- } ) ;
85+ return fetch ( request , init ) ;
86+ } ) ;
87+ await vi . mocked ( useEnvironmentScope ) . withImplementation (
88+ ( ) => true ,
89+ async ( ) => {
90+ await vi . mocked ( usePreparedConnection ) . withImplementation (
91+ ( ) => prepared ,
92+ async ( ) => {
93+ await using screen = await render (
94+ < SettingsScopeProvider search = { { } } onChange = { ( ) => { } } >
95+ < VoiceSettingsPanel />
96+ </ SettingsScopeProvider > ,
97+ ) ;
98+ const destination = screen . getByRole ( "combobox" , { name : "Transcribe with" } ) ;
99+ const dialog = page . getByRole ( "dialog" ) ;
100+ if ( flow === "setup" ) {
101+ await expect . element ( destination ) . toHaveTextContent ( "Laptop" ) ;
102+ await destination . click ( ) ;
103+ await page . getByRole ( "option" , { name : "OpenAI via Laptop" } ) . click ( ) ;
104+ await dialog . getByRole ( "button" , { name : "Cancel" } ) . click ( ) ;
105+ await expect . element ( destination ) . toHaveTextContent ( "Laptop" ) ;
106+ expect ( writes ) . toEqual ( [ ] ) ;
107+ await destination . click ( ) ;
108+ await page . getByRole ( "option" , { name : "OpenAI via Laptop" } ) . click ( ) ;
109+ await dialog . getByRole ( "combobox" , { name : "OpenAI API key source" } ) . click ( ) ;
110+ await page . getByRole ( "option" , { name : "Work vault" } ) . click ( ) ;
111+ await dialog . getByLabelText ( "OpenAI API key reference" ) . fill ( "op://Work/Voice/key" ) ;
112+ await userEvent . keyboard ( "{Enter}" ) ;
113+ await expect . element ( dialog . getByRole ( "alert" ) ) . toBeVisible ( ) ;
114+ expect ( writes ) . toEqual ( [ ] ) ;
115+ await expect
116+ . element ( dialog . getByRole ( "button" , { name : "Save and enable" } ) )
117+ . toBeEnabled ( ) ;
118+ await dialog . getByLabelText ( "OpenAI API key reference" ) . click ( ) ;
119+ await userEvent . keyboard ( "{Enter}" ) ;
120+ await expect . element ( dialog ) . not . toBeInTheDocument ( ) ;
121+ await expect . element ( destination ) . toHaveTextContent ( "OpenAI via Laptop" ) ;
122+ expect ( writes ) . toEqual ( [
123+ { key : { provider : "work" , reference : "op://Work/Voice/key" } } ,
124+ ] ) ;
125+ return ;
126+ }
127+ await expect . element ( destination ) . toHaveTextContent ( "OpenAI via Laptop" ) ;
128+ const grant = window . localStorage . getItem ( "t3code:voice-audio-grant:v1" ) ;
129+ if ( flow === "key replacement" ) {
130+ await screen . getByRole ( "button" , { name : "Manage key" } ) . click ( ) ;
131+ await dialog . getByLabelText ( "OpenAI API key" , { exact : true } ) . fill ( "replacement" ) ;
132+ await userEvent . keyboard ( "{Enter}" ) ;
133+ await expect . element ( dialog ) . not . toBeInTheDocument ( ) ;
134+ expect ( writes . at ( - 1 ) ) . toEqual ( { key : "replacement" } ) ;
135+ expect ( window . localStorage . getItem ( "t3code:voice-audio-grant:v1" ) ) . toBe ( grant ) ;
136+ return ;
137+ }
138+ await destination . click ( ) ;
139+ await page . getByRole ( "option" , { name : "Grok Voice Transcribe via Laptop" } ) . click ( ) ;
140+ await dialog . getByRole ( "button" , { name : "Use Grok Voice Transcribe" } ) . click ( ) ;
141+ await expect . element ( destination ) . toHaveTextContent ( "Grok Voice Transcribe via Laptop" ) ;
142+ await destination . click ( ) ;
143+ await page . getByRole ( "option" , { name : "Off" , exact : true } ) . click ( ) ;
144+ await expect . element ( destination ) . toHaveTextContent ( "Off" ) ;
145+ } ,
146+ ) ;
147+ } ,
148+ ) ;
149+ } ,
150+ ) ;
133151
134152it ( "OpenRouter needs an exact model, and changing it writes no credential" , async ( ) => {
135153 const id = EnvironmentId . make ( "voice-host" ) ;
0 commit comments