@@ -3,7 +3,7 @@ import * as NodeCrypto from "node:crypto";
33import * as NodePath from "node:path" ;
44
55import * as NodeServices from "@effect/platform-node/NodeServices" ;
6- import { extractFile } from "@electron/asar" ;
6+ import { createPackageWithOptions , extractFile } from "@electron/asar" ;
77import { assert , it } from "@effect/vitest" ;
88import * as ConfigProvider from "effect/ConfigProvider" ;
99import * as Deferred from "effect/Deferred" ;
@@ -45,7 +45,9 @@ import {
4545 ancestorNodeModulesPaths ,
4646 copyDirectoryPreservingSymlinks ,
4747 LinuxBrowserSecretHostError ,
48+ MacPackagedAppMissingError ,
4849 stageBrowserSecret ,
50+ validateMacPackagedPayload ,
4951 validateWindowsPackagedPayload ,
5052 verifyPackagedBundleIsSelfContained ,
5153 WindowsPrimaryNativeProbeError ,
@@ -211,6 +213,26 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
211213 } as const ;
212214} ) ;
213215
216+ const makeMacPayloadFixture = Effect . fn ( "test.makeMacPayloadFixture" ) ( function * ( input : {
217+ readonly serverEntrySource ?: string ;
218+ } ) {
219+ const fs = yield * FileSystem . FileSystem ;
220+ const path = yield * Path . Path ;
221+ const tempDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-mac-payload-test-" } ) ;
222+ const sourceDir = path . join ( tempDir , "app-source" ) ;
223+ const serverEntryPath = path . join ( sourceDir , "apps/server/dist/bin.mjs" ) ;
224+ yield * fs . makeDirectory ( path . dirname ( serverEntryPath ) , { recursive : true } ) ;
225+ yield * fs . writeFileString ( serverEntryPath , input . serverEntrySource ?? "console.log('server');\n" ) ;
226+
227+ const stageDistDir = path . join ( tempDir , "dist" ) ;
228+ const resourcesDir = path . join ( stageDistDir , "mac-arm64/T3 Code.app/Contents/Resources" ) ;
229+ yield * fs . makeDirectory ( resourcesDir , { recursive : true } ) ;
230+ yield * Effect . promise ( ( ) =>
231+ createPackageWithOptions ( sourceDir , path . join ( resourcesDir , "app.asar" ) , { } ) ,
232+ ) ;
233+ return { stageDistDir } as const ;
234+ } ) ;
235+
214236it . layer ( NodeServices . layer ) ( "build-desktop-artifact" , ( it ) => {
215237 it . effect ( "rejects overlapping builds from another process until restoration finishes" , ( ) =>
216238 Effect . gen ( function * ( ) {
@@ -1283,6 +1305,58 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
12831305 ) ,
12841306 ) ;
12851307
1308+ it . effect ( "rejects a macOS app whose packaged server bundle cannot resolve" , ( ) =>
1309+ Effect . scoped (
1310+ Effect . gen ( function * ( ) {
1311+ const fixture = yield * makeMacPayloadFixture ( {
1312+ serverEntrySource : 'import "t3code-deliberately-missing-package";\n' ,
1313+ } ) ;
1314+ const error = yield * validateMacPackagedPayload ( {
1315+ stageDistDir : fixture . stageDistDir ,
1316+ } ) . pipe ( Effect . flip ) ;
1317+
1318+ assert . instanceOf ( error , BundleNotSelfContainedError ) ;
1319+ assert . include ( error . output , "t3code-deliberately-missing-package" ) ;
1320+ } ) ,
1321+ ) ,
1322+ ) ;
1323+
1324+ it . effect ( "accepts a macOS app whose packaged server bundle resolves" , ( ) =>
1325+ Effect . scoped (
1326+ Effect . gen ( function * ( ) {
1327+ const fixture = yield * makeMacPayloadFixture ( { } ) ;
1328+ yield * validateMacPackagedPayload ( { stageDistDir : fixture . stageDistDir } ) ;
1329+ } ) ,
1330+ ) ,
1331+ ) ;
1332+
1333+ it . effect ( "rejects a macOS stage without a packaged app" , ( ) =>
1334+ Effect . scoped (
1335+ Effect . gen ( function * ( ) {
1336+ const fs = yield * FileSystem . FileSystem ;
1337+ const stageDistDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-mac-payload-test-" } ) ;
1338+ const error = yield * validateMacPackagedPayload ( { stageDistDir } ) . pipe ( Effect . flip ) ;
1339+
1340+ assert . instanceOf ( error , MacPackagedAppMissingError ) ;
1341+ } ) ,
1342+ ) ,
1343+ ) ;
1344+
1345+ it . effect ( "rejects a macOS app without app.asar" , ( ) =>
1346+ Effect . scoped (
1347+ Effect . gen ( function * ( ) {
1348+ const fs = yield * FileSystem . FileSystem ;
1349+ const stageDistDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-mac-payload-test-" } ) ;
1350+ yield * fs . makeDirectory ( `${ stageDistDir } /mac-arm64/T3 Code.app/Contents/Resources` , {
1351+ recursive : true ,
1352+ } ) ;
1353+ const error = yield * validateMacPackagedPayload ( { stageDistDir } ) . pipe ( Effect . flip ) ;
1354+
1355+ assert . instanceOf ( error , BundleNotSelfContainedError ) ;
1356+ } ) ,
1357+ ) ,
1358+ ) ;
1359+
12861360 it . effect ( "leaves the bundle self-check of a cross-built payload to the verify job" , ( ) =>
12871361 Effect . scoped (
12881362 Effect . gen ( function * ( ) {
0 commit comments