Open History to see the last commit
1import * as NodeFS from "node:fs";
2import * as NodeOS from "node:os";
3import * as NodePath from "node:path";
4
5import { assert, describe, it } from "vite-plus/test";
6
7import {
8 makeDevelopmentEnvironmentScript,
9 makeDevelopmentLauncherScript,
10 resolveElectronBinaryPath,
11 resolveMacBundleInfoPlistStrings,
12 resolveMacCodeSignArguments,
13 resolveMacLauncherIconPaths,
14 resolveMacLauncherPaths,
15 writeDevelopmentLauncherScript,
16} from "./electron-launcher.mjs";
17
18describe("electron development launcher", () => {
19 it("uses captured values only as fallbacks for a live runner environment", () => {
20 const environmentScript = makeDevelopmentEnvironmentScript({
21 VITE_DEV_SERVER_URL: "http://127.0.0.1:8526",
22 T3CODE_PORT: "16566",
23 T3CODE_HOME: "/tmp/t3",
24 });
25
26 assert.include(
27 environmentScript,
28 "if [ -z \"${VITE_DEV_SERVER_URL:-}\" ]; then export VITE_DEV_SERVER_URL='http://127.0.0.1:8526'; fi",
29 );
30 assert.notInclude(environmentScript, "\nexport VITE_DEV_SERVER_URL=");
31 });
32
33 it("keeps the launcher script free of volatile environment values", () => {
34 const script = makeDevelopmentLauncherScript({
35 electronBinaryPath: "/repo/node_modules/electron/Electron",
36 mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
37 desktopRoot: "/repo/apps/desktop",
38 environmentFilePath: "/repo/apps/desktop/.electron-runtime/dev-environment.sh",
39 });
40
41 assert.include(
42 script,
43 "if [ -f '/repo/apps/desktop/.electron-runtime/dev-environment.sh' ]; then . '/repo/apps/desktop/.electron-runtime/dev-environment.sh'; fi",
44 );
45 assert.notInclude(script, "VITE_DEV_SERVER_URL");
46 assert.include(
47 script,
48 "exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",
49 );
50 });
51
52 it("repairs Electron before loading the package entrypoint", () => {
53 const calls = [];
54 const electronPath = resolveElectronBinaryPath({
55 ensureRuntime: () => {
56 calls.push("ensure");
57 },
58 createRequire: () => (specifier) => {
59 calls.push(`require:${specifier}`);
60 return "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron";
61 },
62 moduleUrl: import.meta.url,
63 });
64
65 assert.equal(
66 electronPath,
67 "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron",
68 );
69 assert.deepEqual(calls, ["ensure", "require:electron"]);
70 });
71
72 it("keeps the native Electron executable name inside the branded macOS bundle", () => {
73 const paths = resolveMacLauncherPaths(
74 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app",
75 "T3 Code (Dev)",
76 );
77
78 assert.equal(paths.launcherExecutableName, "T3 Code (Dev) Launcher");
79 assert.equal(
80 paths.launcherBinaryPath,
81 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/T3 Code (Dev) Launcher",
82 );
83 assert.equal(
84 paths.runtimeElectronBinaryPath,
85 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron",
86 );
87
88 const script = makeDevelopmentLauncherScript({
89 electronBinaryPath: paths.runtimeElectronBinaryPath,
90 mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
91 desktopRoot: "/repo/apps/desktop",
92 environmentFilePath: "/repo/apps/desktop/.electron-runtime/dev-environment.sh",
93 });
94 assert.include(
95 script,
96 "exec '/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron'",
97 );
98 assert.notInclude(script, "node_modules/electron");
99 });
100
101 it("declares why the macOS app needs protected access", () => {
102 const values = resolveMacBundleInfoPlistStrings("T3 Code (Dev) Launcher");
103
104 assert.equal(
105 values.NSScreenCaptureUsageDescription,
106 "T3 Code captures the active window when you use the snapshot shortcut.",
107 );
108 assert.equal(
109 values.NSDocumentsFolderUsageDescription,
110 "T3 Code reads project files you open in the desktop app.",
111 );
112 });
113
114 it("ad-hoc signs the complete development app bundle", () => {
115 assert.deepEqual(resolveMacCodeSignArguments("/runtime/T3 Code (Dev).app"), [
116 "--force",
117 "--deep",
118 "--sign",
119 "-",
120 "--timestamp=none",
121 "/runtime/T3 Code (Dev).app",
122 ]);
123 });
124
125 it("restores execute permissions on an unchanged launcher", () => {
126 const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-launcher-"));
127 const launcherPath = NodePath.join(directory, "launcher");
128 try {
129 writeDevelopmentLauncherScript(launcherPath, "/runtime/Electron");
130 NodeFS.chmodSync(launcherPath, 0o644);
131
132 assert.isFalse(writeDevelopmentLauncherScript(launcherPath, "/runtime/Electron"));
133 assert.equal(NodeFS.statSync(launcherPath).mode & 0o777, 0o755);
134 } finally {
135 NodeFS.rmSync(directory, { recursive: true, force: true });
136 }
137 });
138
139 it("derives launcher icons from canonical development and production assets", () => {
140 const development = resolveMacLauncherIconPaths("/runtime", true);
141 const production = resolveMacLauncherIconPaths("/runtime", false);
142
143 // The source icons are real repo paths, joined for the host.
144 assert.match(development.sourceIconPath, /assets[\\/]dev[\\/]blueprint-macos-1024\.png$/);
145 assert.equal(development.generatedIconPath, "/runtime/icon-dev.icns");
146 assert.match(production.sourceIconPath, /assets[\\/]prod[\\/]black-macos-1024\.png$/);
147 assert.equal(production.generatedIconPath, "/runtime/icon-prod.icns");
148 });
149});