fix: improve WSL login fallback

This commit is contained in:
Advait Paliwal
2026-04-14 09:01:44 -07:00
parent 5d10285372
commit 8de8054e4f
7 changed files with 157 additions and 18 deletions

View File

@@ -0,0 +1,51 @@
import test from "node:test";
import assert from "node:assert/strict";
import { patchAlphaHubAuthSource } from "../scripts/lib/alpha-hub-auth-patch.mjs";
test("patchAlphaHubAuthSource fixes browser open logic for WSL and Windows", () => {
const input = [
"function openBrowser(url) {",
" try {",
" const plat = platform();",
" if (plat === 'darwin') execSync(`open \"${url}\"`);",
" else if (plat === 'linux') execSync(`xdg-open \"${url}\"`);",
" else if (plat === 'win32') execSync(`start \"\" \"${url}\"`);",
" } catch {}",
"}",
].join("\n");
const patched = patchAlphaHubAuthSource(input);
assert.match(patched, /const isWsl = plat === 'linux'/);
assert.match(patched, /wslview/);
assert.match(patched, /cmd\.exe \/c start/);
assert.match(patched, /cmd \/c start/);
});
test("patchAlphaHubAuthSource includes the auth URL in login output", () => {
const input = "process.stderr.write('Opening browser for alphaXiv login...\\n');";
const patched = patchAlphaHubAuthSource(input);
assert.match(patched, /Auth URL: \$\{authUrl\.toString\(\)\}/);
});
test("patchAlphaHubAuthSource is idempotent", () => {
const input = [
"function openBrowser(url) {",
" try {",
" const plat = platform();",
" if (plat === 'darwin') execSync(`open \"${url}\"`);",
" else if (plat === 'linux') execSync(`xdg-open \"${url}\"`);",
" else if (plat === 'win32') execSync(`start \"\" \"${url}\"`);",
" } catch {}",
"}",
"process.stderr.write('Opening browser for alphaXiv login...\\n');",
].join("\n");
const once = patchAlphaHubAuthSource(input);
const twice = patchAlphaHubAuthSource(once);
assert.equal(twice, once);
});