Skip to content

Commit bf2a16c

Browse files
committed
fix(cli): keep /rc in the terminal UI when no relay key is set
1 parent 7338ebf commit bf2a16c

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

apps/pythinker-code/src/tui/commands/web.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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();

apps/pythinker-code/test/tui/commands/web.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ describe('handleWebCommand', () => {
147147
});
148148

149149
describe('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');

0 commit comments

Comments
 (0)