Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ci): preserve relative symlinks when copying the app off the DMG (#3023)

Andrew Mikofalvy17f0998bfd04
diff --git a/.github/scripts/dmg-mount.mjs b/.github/scripts/dmg-mount.mjs
index 80ced0a0b..1c40331e5 100644
--- a/.github/scripts/dmg-mount.mjs
+++ b/.github/scripts/dmg-mount.mjs
@@ -158,7 +158,19 @@ export async function withMountedDmg(dmgPath, callback, deps = {}) {
const appName = apps[0];
const appCopyPath = join(appCopyRoot, appName);
- await cpImpl(join(mountRoot, appName), appCopyPath, { recursive: true });
+ // `verbatimSymlinks` is load-bearing, not a nicety. Node's default resolves
+ // every relative symlink against the SOURCE and writes an absolute path in
+ // its place, and an Electron bundle is built out of relative links
+ // (`Electron Framework -> Versions/Current/Electron Framework`). The next
+ // line detaches the very mount those rewritten links would point into, so
+ // dropping this option yields a copy whose frameworks all dangle: the app
+ // aborts at launch with `dyld: Library not loaded: @rpath/Electron
+ // Framework.framework/Electron Framework`, and every packaged smoke test
+ // fails in milliseconds — which reads as a product verdict, not a copy bug.
+ await cpImpl(join(mountRoot, appName), appCopyPath, {
+ recursive: true,
+ verbatimSymlinks: true,
+ });
await detach();
return await callback(appCopyPath);
diff --git a/.github/scripts/dmg-mount.test.mjs b/.github/scripts/dmg-mount.test.mjs
index 41a3b3234..95fd7cbc2 100644
--- a/.github/scripts/dmg-mount.test.mjs
+++ b/.github/scripts/dmg-mount.test.mjs
@@ -1,4 +1,7 @@
import { EventEmitter } from 'node:events';
+import { cp, mkdir, mkdtemp, readlink, rm, symlink, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { isAbsolute, join } from 'node:path';
import { describe, expect, test } from 'vitest';
import { DmgMountError, MOUNT_ERROR_CODES, withMountedDmg } from './dmg-mount.mjs';
@@ -71,6 +74,50 @@ describe('withMountedDmg', () => {
expect(attach).toContain('-mountpoint');
});
+ test('copies an Electron-shaped bundle without absolutizing its relative symlinks', async () => {
+ // Exercises the REAL `fs.cp` against a real symlink tree — only hdiutil is
+ // faked. A stub that records the options bag would ratify the current
+ // implementation; this pins the property that matters, so a later swap to
+ // `ditto` or `cp -R` still has to keep the links relative.
+ const scratch = await mkdtemp(join(tmpdir(), 'ok-dmg-mount-test-'));
+ const framework = join(
+ scratch,
+ 'OpenKnowledge.app/Contents/Frameworks/Electron Framework.framework',
+ );
+ await mkdir(join(framework, 'Versions/A'), { recursive: true });
+ await writeFile(join(framework, 'Versions/A/Electron Framework'), 'mach-o');
+ await symlink('A', join(framework, 'Versions/Current'));
+ await symlink('Versions/Current/Electron Framework', join(framework, 'Electron Framework'));
+
+ let linkTarget = null;
+ await withMountedDmg(
+ '/tmp/OpenKnowledge.dmg',
+ async (appPath) => {
+ linkTarget = await readlink(
+ join(appPath, 'Contents/Frameworks/Electron Framework.framework/Electron Framework'),
+ );
+ },
+ {
+ runCommand: async () => {},
+ // The mount root has to be the tree we prepared; the copy root stays a
+ // fresh directory so the copy is a genuine cross-directory one.
+ mkdtemp: async (prefix) =>
+ prefix.includes('ok-dmg-mount-') ? scratch : await mkdtemp(prefix),
+ cp,
+ rm,
+ listAppsInMount: async () => ['OpenKnowledge.app'],
+ process: new EventEmitter(),
+ },
+ );
+
+ // An absolute target here points into the mount that the driver detaches one
+ // line after the copy, so the framework is gone before the app ever launches.
+ expect(linkTarget).toBe('Versions/Current/Electron Framework');
+ expect(isAbsolute(linkTarget)).toBe(false);
+
+ await rm(scratch, { recursive: true, force: true });
+ });
+
test('detaches before the callback error propagates', async () => {
const { calls, deps } = makeDeps();