Skip to content

Commit 46f50cb

Browse files
committed
Added test-tui script, refactored unreachable code in TUI.
1 parent 8e53d1a commit 46f50cb

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

clients/tui/tui.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,16 @@ export async function runTui(args?: string[]): Promise<void> {
119119
try {
120120
url = new URL(raw);
121121
} catch (err) {
122-
program.error(
122+
throw new Error(
123123
`Invalid callback URL: ${(err as Error)?.message ?? String(err)}`,
124124
);
125-
return { hostname: "127.0.0.1", port: 0, pathname: "/oauth/callback" }; // never reached; program.error() throws
126125
}
127126
if (url.protocol !== "http:") {
128-
program.error("Callback URL must use http scheme");
129-
return { hostname: "127.0.0.1", port: 0, pathname: "/oauth/callback" }; // never reached; program.error() throws
127+
throw new Error("Callback URL must use http scheme");
130128
}
131129
const hostname = url.hostname;
132130
if (!hostname) {
133-
program.error("Callback URL must include a hostname");
134-
return { hostname: "127.0.0.1", port: 0, pathname: "/oauth/callback" }; // never reached; program.error() throws
131+
throw new Error("Callback URL must include a hostname");
135132
}
136133
const pathname = url.pathname || "/";
137134
let port: number;
@@ -145,13 +142,21 @@ export async function runTui(args?: string[]): Promise<void> {
145142
port < 0 ||
146143
port > 65535
147144
) {
148-
program.error("Callback URL port must be between 0 and 65535");
145+
throw new Error("Callback URL port must be between 0 and 65535");
149146
}
150147
}
151148
return { hostname, port, pathname };
152149
}
153150

154-
const callbackUrlConfig = parseCallbackUrl(options.callbackUrl);
151+
let callbackUrlConfig: CallbackUrlConfig;
152+
try {
153+
callbackUrlConfig = parseCallbackUrl(options.callbackUrl);
154+
} catch (err) {
155+
if (err instanceof Error) {
156+
program.error(err.message);
157+
}
158+
throw err;
159+
}
155160

156161
// Intercept stdout.write to filter out \x1b[3J (Erase Saved Lines)
157162
// This prevents Ink's clearTerminal from clearing scrollback on macOS Terminal

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"test-cli": "cd clients/cli && npm run test",
5050
"test-core": "cd core && npm run test",
5151
"test-web": "cd clients/web && npm run test",
52+
"test-tui": "cd clients/tui && npm run test",
5253
"test-web:e2e": "MCP_AUTO_OPEN_ENABLED=false npm run test:e2e --workspace=clients/web",
5354
"prettier-fix": "prettier --write .",
5455
"prettier-check": "prettier --check .",

0 commit comments

Comments
 (0)