mirror of
https://github.com/nexu-io/open-design.git
synced 2026-09-20 06:15:06 +08:00
0688faaec3
* reland(sidecar): converge product clients after weekly release
Restore the sidecar convergence from #7244 after the release-scheduling revert in #7634. This tree matches the previously reviewed and cross-platform QA-accepted implementation at d83d4e032f.
* fix(sidecar): clarify identity and cache witnesses
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(packaged): probe cross-source desktop owners
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(sidecar): preserve cross-source launch ownership
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* test(pack): assert cross-source Windows launch ownership
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(sidecar): align HyperFrames with client boundary
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(e2e): keep HyperFrames fixture in helper lane
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* docs(sidecar): restore review and handoff contracts
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(sidecar): restore cache and daemon boundaries
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(pack): restore sourcemaps and Linux smoke discovery
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(sidecar): make payload handoff generation-atomic
* fix(sidecar): preserve packaged action and mode parity
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* test(pack): align Linux cleanup resource count
Generated-By: looper 0.11.2 (runner=fixer, agent=codex)
* fix(packaged): preserve headless sidecar mode
* test: normalize source line endings
* fix(daemon): launch Codex cmd shims on Windows
---------
Co-authored-by: Looper <looper@noreply.github.com>
275 lines
9.3 KiB
TypeScript
275 lines
9.3 KiB
TypeScript
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { build } from "esbuild";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
MAC_DAEMON_PREBUNDLE_ESM_REQUIRE_BANNER,
|
|
MAC_PREBUNDLE_COPIED_RUNTIME_DEPENDENCIES,
|
|
MAC_PREBUNDLE_ESBUILD_TARGET,
|
|
MAC_PREBUNDLE_POLICIES,
|
|
MAC_PREBUNDLE_RUNTIME_DEPENDENCIES,
|
|
MAC_PREBUNDLED_DAEMON_CLI_RELATIVE_PATH,
|
|
MAC_PREBUNDLED_DAEMON_SIDECAR_RELATIVE_PATH,
|
|
MAC_PREBUNDLED_WEB_SIDECAR_RELATIVE_PATH,
|
|
assertMacPrebundleMetafile,
|
|
findForbiddenMacPrebundleInputs,
|
|
renderMacPackagedMainEntry,
|
|
shouldInstallInternalPackageForMacPrebundle,
|
|
shouldUseMacStandalonePrebundle,
|
|
} from "@/mac/prebundle.js";
|
|
|
|
describe("mac standalone prebundle policy", () => {
|
|
it("is enabled only for standalone web output", () => {
|
|
expect(shouldUseMacStandalonePrebundle("standalone")).toBe(true);
|
|
expect(shouldUseMacStandalonePrebundle("server")).toBe(false);
|
|
});
|
|
|
|
it("keeps server-mode package topology unchanged", () => {
|
|
expect(
|
|
shouldInstallInternalPackageForMacPrebundle({
|
|
packageName: "@open-design/web",
|
|
webOutputMode: "server",
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldInstallInternalPackageForMacPrebundle({
|
|
packageName: "@open-design/packaged",
|
|
webOutputMode: "server",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("excludes internal packages replaced by mac standalone prebundles", () => {
|
|
for (const packageName of [
|
|
"@open-design/daemon",
|
|
"@open-design/desktop",
|
|
"@open-design/packaged",
|
|
"@open-design/sidecar-proto",
|
|
"@open-design/web",
|
|
]) {
|
|
expect(
|
|
shouldInstallInternalPackageForMacPrebundle({
|
|
packageName,
|
|
webOutputMode: "standalone",
|
|
}),
|
|
).toBe(false);
|
|
}
|
|
for (const packageName of [
|
|
"@open-design/contracts",
|
|
"@open-design/platform",
|
|
"@open-design/sidecar",
|
|
]) {
|
|
expect(
|
|
shouldInstallInternalPackageForMacPrebundle({ packageName, webOutputMode: "standalone" }),
|
|
).toBe(true);
|
|
}
|
|
});
|
|
|
|
it("documents the explicit code-level bundle boundaries", () => {
|
|
expect(MAC_PREBUNDLE_ESBUILD_TARGET).toBe("node24");
|
|
expect(MAC_PREBUNDLE_POLICIES.packagedMain.externals).toEqual(["@open-design/sidecar", "electron"]);
|
|
expect(MAC_PREBUNDLE_POLICIES.daemonCli.externals).toEqual([
|
|
"@ffmpeg-installer/ffmpeg",
|
|
"@open-design/sidecar",
|
|
"better-sqlite3",
|
|
"blake3-wasm",
|
|
"fsevents",
|
|
"hyperframes",
|
|
"node-pty",
|
|
]);
|
|
expect(MAC_PREBUNDLE_POLICIES.daemonSidecar.externals).toEqual([
|
|
"@ffmpeg-installer/ffmpeg",
|
|
"@open-design/sidecar",
|
|
"better-sqlite3",
|
|
"blake3-wasm",
|
|
"fsevents",
|
|
"hyperframes",
|
|
"node-pty",
|
|
]);
|
|
expect(MAC_PREBUNDLE_POLICIES.webSidecar.externals).toEqual(["@open-design/sidecar"]);
|
|
expect(MAC_DAEMON_PREBUNDLE_ESM_REQUIRE_BANNER).toContain("createRequire");
|
|
// Must match apps/daemon/package.json / the pnpm lockfile, or
|
|
// electron-builder's collector drops the module from the shipped app and
|
|
// the daemon dies at boot with ERR_MODULE_NOT_FOUND (issue #4638).
|
|
expect(MAC_PREBUNDLE_RUNTIME_DEPENDENCIES).toEqual({
|
|
"@ffmpeg-installer/ffmpeg": "1.1.0",
|
|
"better-sqlite3": "12.10.0",
|
|
"blake3-wasm": "2.1.5",
|
|
"hyperframes": "0.8.1",
|
|
"node-pty": "1.1.0",
|
|
"sharp": "0.35.3",
|
|
});
|
|
expect(MAC_PREBUNDLE_COPIED_RUNTIME_DEPENDENCIES).toEqual({ "fsevents": "2.3.3" });
|
|
expect(MAC_PREBUNDLED_DAEMON_CLI_RELATIVE_PATH).toBe("app/prebundled/daemon/daemon-cli.mjs");
|
|
expect(MAC_PREBUNDLED_DAEMON_SIDECAR_RELATIVE_PATH).toBe("app/prebundled/daemon/daemon-sidecar.mjs");
|
|
expect(MAC_PREBUNDLED_WEB_SIDECAR_RELATIVE_PATH).toBe("app/prebundled/web-sidecar.mjs");
|
|
});
|
|
|
|
it.skipIf(process.platform !== "darwin")(
|
|
"keeps chokidar's native fsevents binding outside daemon bundles",
|
|
async () => {
|
|
const workspaceRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../../..");
|
|
const result = await build({
|
|
banner: { js: MAC_DAEMON_PREBUNDLE_ESM_REQUIRE_BANNER },
|
|
bundle: true,
|
|
external: [...MAC_PREBUNDLE_POLICIES.daemonSidecar.externals],
|
|
format: "esm",
|
|
logLevel: "silent",
|
|
metafile: true,
|
|
platform: "node",
|
|
stdin: {
|
|
contents: 'import "chokidar";',
|
|
loader: "js",
|
|
resolveDir: join(workspaceRoot, "apps", "daemon"),
|
|
},
|
|
target: MAC_PREBUNDLE_ESBUILD_TARGET,
|
|
write: false,
|
|
});
|
|
|
|
expect(Object.keys(result.metafile.inputs).some((input) => input.includes("/node_modules/fsevents/"))).toBe(
|
|
false,
|
|
);
|
|
},
|
|
);
|
|
|
|
it(
|
|
"keeps node-pty's native runtime outside daemon bundles",
|
|
async () => {
|
|
const workspaceRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../../..");
|
|
const result = await build({
|
|
banner: { js: MAC_DAEMON_PREBUNDLE_ESM_REQUIRE_BANNER },
|
|
bundle: true,
|
|
external: [...MAC_PREBUNDLE_POLICIES.daemonSidecar.externals],
|
|
format: "esm",
|
|
logLevel: "silent",
|
|
metafile: true,
|
|
platform: "node",
|
|
entryPoints: [join(workspaceRoot, "apps", "daemon", "src", "terminals.ts")],
|
|
target: MAC_PREBUNDLE_ESBUILD_TARGET,
|
|
write: false,
|
|
});
|
|
|
|
expect(
|
|
Object.keys(result.metafile.inputs).some((input) => input.includes("/node_modules/node-pty/")),
|
|
).toBe(false);
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("findForbiddenMacPrebundleInputs", () => {
|
|
it("matches forbidden dependency roots after path normalization", () => {
|
|
expect(
|
|
findForbiddenMacPrebundleInputs({
|
|
forbiddenInputs: MAC_PREBUNDLE_POLICIES.webSidecar.forbiddenInputs,
|
|
inputs: [
|
|
"src/index.ts",
|
|
"C:\\repo\\node_modules\\next\\dist\\server.js",
|
|
"/repo/node_modules/openai/index.mjs",
|
|
],
|
|
}),
|
|
).toEqual([
|
|
"C:/repo/node_modules/next/dist/server.js",
|
|
"/repo/node_modules/openai/index.mjs",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("assertMacPrebundleMetafile", () => {
|
|
it("accepts a safe web sidecar metafile", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "open-design-mac-prebundle-"));
|
|
const metafilePath = join(root, "safe.json");
|
|
|
|
try {
|
|
await writeFile(
|
|
metafilePath,
|
|
JSON.stringify({ inputs: { "/repo/apps/web/sidecar/index.ts": {} } }),
|
|
"utf8",
|
|
);
|
|
|
|
await expect(
|
|
assertMacPrebundleMetafile({ metafilePath, policyName: "webSidecar" }),
|
|
).resolves.toBeUndefined();
|
|
} finally {
|
|
await rm(root, { force: true, recursive: true });
|
|
}
|
|
});
|
|
|
|
it("rejects a packaged main metafile that pulled in web runtime closure", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "open-design-mac-prebundle-"));
|
|
const metafilePath = join(root, "unsafe.json");
|
|
|
|
try {
|
|
await writeFile(
|
|
metafilePath,
|
|
JSON.stringify({ inputs: { "/repo/node_modules/@open-design/web/dist/sidecar/index.js": {} } }),
|
|
"utf8",
|
|
);
|
|
|
|
await expect(
|
|
assertMacPrebundleMetafile({ metafilePath, policyName: "packagedMain" }),
|
|
).rejects.toThrow(/packaged main prebundle included forbidden inputs/);
|
|
} finally {
|
|
await rm(root, { force: true, recursive: true });
|
|
}
|
|
});
|
|
|
|
it("rejects a daemon metafile that bundled wasm-backed runtime dependencies", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "open-design-mac-prebundle-"));
|
|
const metafilePath = join(root, "unsafe-daemon.json");
|
|
|
|
try {
|
|
await writeFile(
|
|
metafilePath,
|
|
JSON.stringify({ inputs: { "/repo/node_modules/blake3-wasm/dist/node/index.js": {} } }),
|
|
"utf8",
|
|
);
|
|
|
|
await expect(
|
|
assertMacPrebundleMetafile({ metafilePath, policyName: "daemonSidecar" }),
|
|
).rejects.toThrow(/daemon sidecar prebundle included forbidden inputs/);
|
|
} finally {
|
|
await rm(root, { force: true, recursive: true });
|
|
}
|
|
});
|
|
|
|
it("rejects a daemon metafile that bundled native runtime dependencies", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "open-design-mac-prebundle-"));
|
|
const metafilePath = join(root, "unsafe-native-daemon.json");
|
|
|
|
try {
|
|
await writeFile(
|
|
metafilePath,
|
|
JSON.stringify({
|
|
inputs: {
|
|
"/repo/node_modules/fsevents/fsevents.js": {},
|
|
"/repo/node_modules/node-pty/lib/index.js": {},
|
|
},
|
|
}),
|
|
"utf8",
|
|
);
|
|
|
|
await expect(
|
|
assertMacPrebundleMetafile({ metafilePath, policyName: "daemonSidecar" }),
|
|
).rejects.toThrow(/daemon sidecar prebundle included forbidden inputs/);
|
|
} finally {
|
|
await rm(root, { force: true, recursive: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("renderMacPackagedMainEntry", () => {
|
|
it("renders the prebundled runtime entry shim", () => {
|
|
expect(renderMacPackagedMainEntry(true)).toContain("./prebundled/packaged-main.mjs");
|
|
expect(renderMacPackagedMainEntry(true)).not.toContain("@open-design/packaged");
|
|
});
|
|
|
|
it("renders the package entry shim for non-prebundled mode", () => {
|
|
expect(renderMacPackagedMainEntry(false)).toContain("@open-design/packaged");
|
|
expect(renderMacPackagedMainEntry(false)).not.toContain("./prebundled/packaged-main.mjs");
|
|
});
|
|
});
|