Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

fix(cli): a self-update on Windows hands the rerun every argument whole, so setup --dir with a space in the path is not split

Shahriar1f0e8d0ea42a
diff --git a/src/daemon/self-update.test.ts b/src/daemon/self-update.test.ts
index 3b7f7f8..23e4806 100644
--- a/src/daemon/self-update.test.ts
+++ b/src/daemon/self-update.test.ts
@@ -26,7 +26,8 @@ let selfUpdate: typeof import('./self-update');
/** Stand-ins for npm, npx and browsentic that note how they were run, then exit with FAKE_<NAME>_EXIT. */
const bin = join(stateDir, 'fake-bin');
const ran = join(stateDir, 'ran.log');
-const commandsRun = () => (existsSync(ran) ? readFileSync(ran, 'utf8').split('\n').filter(Boolean) : []);
+const argvsRun = (): string[][] => (existsSync(ran) ? readFileSync(ran, 'utf8').split('\n').filter(Boolean).map((line) => JSON.parse(line)) : []);
+const commandsRun = () => argvsRun().map((argv) => argv.join(' '));
beforeAll(async () => {
await new Promise<void>((resolve) => registry.listen(0, '127.0.0.1', resolve));
@@ -38,7 +39,7 @@ beforeAll(async () => {
for (const name of ['npm', 'npx', 'browsentic']) {
stubCli(
join(bin, name),
- `require('node:fs').appendFileSync(${JSON.stringify(ran)}, [${JSON.stringify(name)}, ...process.argv.slice(2)].join(' ') + '\\n');
+ `require('node:fs').appendFileSync(${JSON.stringify(ran)}, JSON.stringify([${JSON.stringify(name)}, ...process.argv.slice(2)]) + '\\n');
process.exit(Number(process.env.FAKE_${name.toUpperCase()}_EXIT || 0));`,
);
}
@@ -163,6 +164,14 @@ describe('updating the command itself', () => {
]);
});
+ test('an argument with a space, an ampersand or a trailing backslash reaches the new command whole', async () => {
+ const dir = 'C:\\Users\\R&D Lab\\my ext\\';
+ expect([await selfUpdate.upgradeCli('0.6.2', ['setup', '--dir', dir]), argvsRun().at(-1)]).toEqual([
+ 0,
+ ['browsentic', 'setup', '--dir', dir, '--no-self-update'],
+ ]);
+ });
+
test('a global install npm could not replace says what to run by hand, and goes no further', async () => {
vi.stubEnv('FAKE_NPM_EXIT', '1');
expect([await selfUpdate.upgradeCli('0.6.2', ['update']), commandsRun(), stderr().includes('npm install -g [email protected]')]).toEqual([
diff --git a/src/daemon/self-update.ts b/src/daemon/self-update.ts
index 071b802..16e52d6 100644
--- a/src/daemon/self-update.ts
+++ b/src/daemon/self-update.ts
@@ -88,8 +88,16 @@ export async function upgradeCli(current: string, forward: string[]): Promise<nu
return run('browsentic', rerun);
}
+/**
+ * One argument as cmd.exe hands it on whole, so `--dir "C:\Users\Jo Doe\ext\"` is not split at its
+ * space: quoted, with the backslashes before the closing quote doubled for the program reading it.
+ */
+const forCmd = (arg: string) => (/^[\w@.:/\\=+-]+$/.test(arg) ? arg : `"${arg.replace(/(\\*)$/, '$1$1')}"`);
+
+/** npm, npx and an npm-installed browsentic are batch files on Windows, which only cmd.exe starts. */
function run(command: string, args: string[]): number {
- const result = spawnSync(command, args, { stdio: 'inherit', shell: process.platform === 'win32' });
+ const windows = process.platform === 'win32';
+ const result = spawnSync(command, windows ? args.map(forCmd) : args, { stdio: 'inherit', shell: windows });
if (result.error) {
console.error(`\n Could not run \`${command}\`: ${result.error.message}\n`);
return 1;