File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,14 +61,23 @@ export async function handleRemoteControlCommand(host: SlashCommandHost): Promis
6161 return ;
6262 }
6363
64+ // Before the takeover: a missing relay key is a configuration problem the
65+ // user can still fix, so it must not cost them the terminal UI.
66+ let relayKey : string ;
67+ try {
68+ relayKey = resolveRelayKey ( ) ;
69+ } catch ( error ) {
70+ host . showError ( formatErrorMessage ( error ) ) ;
71+ return ;
72+ }
73+
6474 host . setExitForegroundTask ( async ( ) => {
6575 const options = parseServerOptions ( { } ) ;
6676 let remoteControl : Awaited < ReturnType < typeof startRemoteControl > > | undefined ;
6777 try {
6878 // Inside the try: a malformed relay setting throws here, and the user
6979 // should see it through the same handler as any other startup failure.
7080 const relayOrigin = resolveRelayOrigin ( ) ;
71- const relayKey = resolveRelayKey ( ) ;
7281 await startServerForeground ( options , {
7382 onReady : async ( origin ) => {
7483 const dataDir = getDataDir ( ) ;
Original file line number Diff line number Diff line change @@ -147,6 +147,21 @@ describe('handleWebCommand', () => {
147147} ) ;
148148
149149describe ( 'handleRemoteControlCommand' , ( ) => {
150+ beforeEach ( ( ) => {
151+ vi . stubEnv ( 'PYTHINKER_CODE_REMOTE_CONTROL_RELAY_KEY' , 'relay-key-1' ) ;
152+ } ) ;
153+
154+ it ( 'stays in the TUI with a readable error when no relay key is configured' , async ( ) => {
155+ vi . clearAllMocks ( ) ;
156+ vi . stubEnv ( 'PYTHINKER_CODE_REMOTE_CONTROL_RELAY_KEY' , '' ) ;
157+ const host = makeHost ( ) ;
158+
159+ await handleRemoteControlCommand ( host ) ;
160+
161+ expect ( host . showError ) . toHaveBeenCalledWith ( expect . stringContaining ( 'relay key' ) ) ;
162+ expect ( host . setExitForegroundTask ) . not . toHaveBeenCalled ( ) ;
163+ } ) ;
164+
150165 it ( 'stays in the TUI with a readable error when another instance holds Remote Control' , async ( ) => {
151166 vi . clearAllMocks ( ) ;
152167 const { mkdtempSync, mkdirSync, rmSync, writeFileSync } = await import ( 'node:fs' ) ;
You can’t perform that action at this time.
0 commit comments