From 6739abf1ef28aa54a952e2f3312601e980cb9895 Mon Sep 17 00:00:00 2001 From: Joseph Woolley Date: Sat, 5 Dec 2026 07:54:12 -0500 Subject: [PATCH] Start the fake server through a symlink or a path with a space. The direct-run check compared a percent-encoded URL with the path as typed, so a checkout in a folder with a space, or reached through a symlink, exited 0 and printed nothing. The helper already resolves the real path. The stand-in backend now does the same. Fixes #618 Co-Authored-By: Grok 4.7 --- test/fake-direct-run.test.mjs | 62 +++++++++++++++++++++++++++++++++++ test/fake-omarchyd.mjs | 14 +++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/fake-direct-run.test.mjs diff --git a/test/fake-direct-run.test.mjs b/test/fake-direct-run.test.mjs new file mode 100644 index 00000000..cdd410ab --- /dev/null +++ b/test/fake-direct-run.test.mjs @@ -0,0 +1,62 @@ +// The stand-in backend must start when the checkout path has a space or is reached through a symlink. +import assert from 'node:assert/strict' +import {spawn} from 'node:child_process' +import {mkdir, mkdtemp, rm, symlink} from 'node:fs/promises' +import os from 'node:os' +import {join} from 'node:path' +import {test} from 'node:test' +import {fileURLToPath} from 'node:url' + +const fakePath = fileURLToPath(new URL('./fake-omarchyd.mjs', import.meta.url)) + +function started(script) { + return new Promise((resolve, reject) => { + const child = spawn(process.execPath, [script, '0'], {stdio: ['ignore', 'pipe', 'pipe']}) + let out = '' + let err = '' + let settled = false + const timer = setTimeout(() => done(new Error(`no startup line\n${out}\n${err}`)), 15_000) + const done = (error, text) => { + if (settled) return + settled = true + clearTimeout(timer) + child.kill('SIGTERM') + const kill = setTimeout(() => child.kill('SIGKILL'), 1000) + kill.unref() + if (child.exitCode != null || child.signalCode != null) { + error ? reject(error) : resolve(text) + return + } + child.on('exit', () => (error ? reject(error) : resolve(text))) + } + child.stdout.on('data', (b) => { + out += b + if (out.includes('fake omarchyd (TEST ONLY)')) done(null, out) + }) + child.stderr.on('data', (b) => { + err += b + }) + child.on('error', (error) => done(error)) + child.on('exit', (code) => { + if (!out.includes('fake omarchyd (TEST ONLY)')) done(new Error(`exited ${code}\n${out}\n${err}`)) + }) + }) +} + +test('fake omarchyd starts through a symlink and a path with a space', async () => { + const dir = await mkdtemp(join(os.tmpdir(), 'omarchy-fake-')) + try { + const link = join(dir, 'fake-link.mjs') + await symlink(fakePath, link) + const spaced = join(dir, 'sp ace') + await mkdir(spaced) + const spacedFake = join(spaced, 'fake-omarchyd.mjs') + await symlink(fakePath, spacedFake) + for (const script of [link, spacedFake]) { + const out = await started(script) + assert.match(out, /fake omarchyd \(TEST ONLY\) at /) + } + } finally { + await rm(dir, {recursive: true, force: true}) + } +}) diff --git a/test/fake-omarchyd.mjs b/test/fake-omarchyd.mjs index d9b7a9ca..e36b5ee2 100644 --- a/test/fake-omarchyd.mjs +++ b/test/fake-omarchyd.mjs @@ -4,8 +4,10 @@ // server. It is never shipped or used by the app itself. import http from 'node:http' +import {realpathSync} from 'node:fs' import {readFile, readdir} from 'node:fs/promises' import {randomBytes} from 'node:crypto' +import {fileURLToPath} from 'node:url' import {WebSocketServer} from 'ws' export async function startFakeserverd({ @@ -1172,7 +1174,17 @@ function rfbServer(ws, keys) { } // `node test/fake-omarchyd.mjs 7781` runs it standalone for UI development. -if (import.meta.url === `file://${process.argv[1]}`) { +// import.meta.url is the real path, percent-encoded. argv is the path as typed, so a +// space or a symlink used to make this comparison fail and the process exit 0. +function ranAsMain() { + if (typeof import.meta.main === 'boolean') return import.meta.main + try { + return Boolean(process.argv[1]) && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)) + } catch { + return false + } +} +if (ranAsMain()) { const fake = await startFakeserverd({port: Number(process.argv[2] ?? 7781)}) console.log(`fake omarchyd (TEST ONLY) at ${fake.url}, password "correct horse"`) // Lets a browser test read which keys reached the fake VM.