Skip to content

Commit 55217b6

Browse files
committed
fix(cli): fall back to the environment when a relay flag is blank
A whitespace-only --relay-key or --relay-origin trimmed to an empty string, which the nullish fallback still treated as a value, so a configured environment variable was never read.
1 parent bf2a16c commit 55217b6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

apps/pythinker-code/src/cli/sub/web/remote-control.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function resolveRelayOrigin(
2828
explicit?: string,
2929
env: Readonly<Record<string, string | undefined>> = process.env,
3030
): string {
31-
const candidate = explicit?.trim() ?? env[REMOTE_CONTROL_RELAY_ENV]?.trim() ?? '';
31+
const candidate = explicit?.trim() || env[REMOTE_CONTROL_RELAY_ENV]?.trim() || '';
3232
if (candidate.length === 0) return REMOTE_CONTROL_RELAY_ORIGIN;
3333
const url = new URL(candidate);
3434
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
@@ -46,7 +46,7 @@ export function resolveRelayKey(
4646
explicit?: string,
4747
env: Readonly<Record<string, string | undefined>> = process.env,
4848
): string {
49-
const candidate = explicit?.trim() ?? env[REMOTE_CONTROL_RELAY_KEY_ENV]?.trim() ?? '';
49+
const candidate = explicit?.trim() || env[REMOTE_CONTROL_RELAY_KEY_ENV]?.trim() || '';
5050
if (candidate.length === 0) {
5151
throw new Error(
5252
`Remote Control needs a relay key. Pass --relay-key or set ${REMOTE_CONTROL_RELAY_KEY_ENV}.`,

apps/pythinker-code/test/cli/web/remote-control.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ describe('resolveRelayOrigin', () => {
205205
expect(resolveRelayOrigin(' ', { PYTHINKER_CODE_REMOTE_CONTROL_RELAY: ' ' })).toBe(
206206
REMOTE_CONTROL_RELAY_ORIGIN,
207207
);
208+
expect(
209+
resolveRelayOrigin(' ', {
210+
PYTHINKER_CODE_REMOTE_CONTROL_RELAY: 'https://env.example.test',
211+
}),
212+
).toBe('https://env.example.test');
208213
});
209214

210215
it('rejects a relay that is not http(s)', async () => {
@@ -224,6 +229,9 @@ describe('resolveRelayKey', () => {
224229
resolveRelayKey(undefined, { PYTHINKER_CODE_REMOTE_CONTROL_RELAY_KEY: 'env-key' }),
225230
).toBe('env-key');
226231
expect(resolveRelayKey(' spaced-key ', {})).toBe('spaced-key');
232+
expect(
233+
resolveRelayKey(' ', { PYTHINKER_CODE_REMOTE_CONTROL_RELAY_KEY: 'env-key' }),
234+
).toBe('env-key');
227235
});
228236

229237
it('refuses to fall back to another credential when no key is given', async () => {

0 commit comments

Comments
 (0)