@@ -25,6 +25,64 @@ it.each(["x64", "arm64"])("skips prepared bytecode generation on Linux %s", asyn
2525 expect ( result . stdout ) . toContain ( "Skipping unsupported target linux" ) ;
2626} ) ;
2727
28+ it ( "prepares macOS x64 cache on an ARM64 build host" , async ( ) => {
29+ const { spawnSync } = await import ( "node:child_process" ) ;
30+ const root = NodeFS . realpathSync (
31+ NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-rosetta-cache-" ) ) ,
32+ ) ;
33+ try {
34+ const resources = NodePath . join ( root , "Fixture.app" , "Contents" , "Resources" ) ;
35+ const archive = NodePath . join ( resources , "app.asar" ) ;
36+ const dist = NodePath . join ( archive , "apps/server/dist" ) ;
37+ const helper = NodePath . join ( archive , "apps/desktop/dist-electron/serverCompileCache.cjs" ) ;
38+ NodeFS . mkdirSync ( dist , { recursive : true } ) ;
39+ NodeFS . mkdirSync ( NodePath . dirname ( helper ) , { recursive : true } ) ;
40+ NodeFS . writeFileSync ( NodePath . join ( dist , "binCli-fixture.mjs" ) , "export const answer = 42;" ) ;
41+ NodeFS . writeFileSync (
42+ helper ,
43+ `module.exports = require(${ JSON . stringify ( NodeURL . fileURLToPath ( new URL ( "./server-compile-cache.ts" , import . meta. url ) ) ) } );` ,
44+ ) ;
45+ const hook = NodeURL . fileURLToPath (
46+ new URL ( "../prepare-server-compile-cache.cjs" , import . meta. url ) ,
47+ ) ;
48+ // The fixture uses Node for generation; the hook still sees an ARM64 macOS build host.
49+ const result = spawnSync (
50+ process . execPath ,
51+ [
52+ "-e" ,
53+ `
54+ const childProcess = require("node:child_process");
55+ const spawn = childProcess.spawnSync;
56+ childProcess.spawnSync = (executable, args, options) => spawn(process.execPath, args, options);
57+ Object.defineProperty(process, "platform", { value: "darwin" });
58+ Object.defineProperty(process, "arch", { value: "arm64" });
59+ require(${ JSON . stringify ( hook ) } )({
60+ appOutDir: ${ JSON . stringify ( root ) } , electronPlatformName: "darwin", arch: 1,
61+ packager: { appInfo: { productFilename: "Fixture" } }
62+ }).catch(error => { console.error(error); process.exitCode = 1; });
63+ ` ,
64+ ] ,
65+ { encoding : "utf8" } ,
66+ ) ;
67+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
68+ const manifest = JSON . parse (
69+ NodeFS . readFileSync ( NodePath . join ( resources , "server-compile-cache/manifest.json" ) , "utf8" ) ,
70+ ) ;
71+ expect ( manifest . entries ) . toEqual ( [
72+ {
73+ module : "app.asar/apps/server/dist/binCli-fixture.mjs" ,
74+ file : expect . stringMatching ( / ^ [ a - f 0 - 9 ] { 8 } $ / ) ,
75+ } ,
76+ ] ) ;
77+ expect (
78+ NodeFS . statSync ( NodePath . join ( resources , "server-compile-cache" , manifest . entries [ 0 ] . file ) )
79+ . size ,
80+ ) . toBeGreaterThan ( 0 ) ;
81+ } finally {
82+ NodeFS . rmSync ( root , { recursive : true , force : true } ) ;
83+ }
84+ } ) ;
85+
2886it ( "seeds relocated cache entries without allowing writes into shipped resources" , ( ) => {
2987 const root = NodeFS . realpathSync (
3088 NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-prepared-test-" ) ) ,
0 commit comments