Skip to content

Commit c177eb6

Browse files
committed
fix(server): verify legacy launcher migration on current main
1 parent 90d2337 commit c177eb6

2 files changed

Lines changed: 34 additions & 27 deletions

File tree

‎apps/server/src/cloud/bootService.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,28 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
808808
}),
809809
);
810810

811+
it.effect("migrates a versioned macOS launch agent to the fixed launcher", () =>
812+
Effect.gen(function* () {
813+
const { service, makeService, fs, runtime, baseDir } = yield* makeHarness("darwin");
814+
const path = yield* Path.Path;
815+
const first = yield* service.install();
816+
const legacy = (yield* fs.readFileString(first.unitPath)).replace(
817+
path.join(baseDir, "runtime", "launcher", "t3"),
818+
runtime.entryPath,
819+
);
820+
yield* fs.writeFileString(first.unitPath, legacy);
821+
yield* fs.remove(path.join(baseDir, "runtime", "launcher"), { recursive: true, force: true });
822+
expect((yield* service.status).current).toBe(false);
823+
824+
const updated = yield* makeService(undefined, "1.2.4");
825+
const installed = yield* updated.install();
826+
expect(BootService.bootServiceProgramOf(yield* fs.readFileString(installed.unitPath))).toBe(
827+
path.join(baseDir, "runtime", "launcher", "t3"),
828+
);
829+
expect(yield* updated.status).toMatchObject({ current: true, installedVersion: "1.2.4" });
830+
}),
831+
);
832+
811833
it.effect("keeps the launch agent on one launcher path across versions on macOS", () =>
812834
Effect.gen(function* () {
813835
const { service, makeService, fs, baseDir } = yield* makeHarness("darwin");

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
572572
const statePath = path.join(input.baseDir, "runtime", SERVICE_STATE_FILE);
573573
const restartPendingPath = path.join(input.baseDir, "runtime", SERVICE_RESTART_PENDING_FILE);
574574
const runtimePaths = pinnedRuntimePaths(path, input.baseDir, input.cliVersion, platform);
575-
// macOS keys Full Disk Access and Files & Folders grants for a non-bundled
576-
// executable to its absolute path, and the launch agent's process is the
577-
// responsible process for everything it spawns. Running the launcher from
578-
// a versioned directory made every update lose those grants, so on macOS
579-
// the launch agent runs a copy of the runtime at a path no update changes.
580-
// The copy still spawns `versions/<activeVersion>/t3 serve` as before.
575+
// macOS privacy grants track the launchd parent's executable path across updates.
581576
const launcherDir = path.join(input.baseDir, "runtime", SERVICE_LAUNCHER_DIR);
582577
const launcher =
583578
platform === "darwin"
@@ -608,8 +603,6 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
608603
);
609604
}),
610605
).pipe(Effect.mapError((cause) => new BootServiceInstallError({ cause })));
611-
// The executable hosts the launcher as a hidden subcommand of itself, so
612-
// the unit runs the pinned runtime (or, on macOS, its fixed-path copy) directly.
613606
const plan: BootServicePlan = {
614607
program: [launcher?.entryPath ?? runtimePaths.entryPath, "__service-launcher"],
615608
baseDir: input.baseDir,
@@ -728,21 +721,17 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
728721
if (remaining[0]) return yield* new BootServicePrerequisiteError({ problem: remaining[0] });
729722
});
730723

731-
const launcherComplete = (directory: string) =>
732-
Effect.all([
733-
fs.exists(path.join(directory, path.basename(runtimePaths.entryPath))),
734-
fs
735-
.readFileString(path.join(directory, path.basename(runtimePaths.sentinelPath)))
736-
.pipe(
737-
Effect.catch((error) =>
738-
error.reason._tag === "NotFound" ? Effect.succeed("") : Effect.fail(error),
739-
),
740-
),
741-
]).pipe(
742-
Effect.map(
743-
([entryExists, sentinel]) => entryExists && isExactServiceVersion(sentinel.trim()),
744-
),
724+
const launcherComplete = Effect.fn("cloud.boot_service.launcher_complete")(function* (
725+
directory: string,
726+
) {
727+
const entryExists = yield* fs.exists(
728+
path.join(directory, path.basename(runtimePaths.entryPath)),
745729
);
730+
const sentinel = yield* fs
731+
.readFileString(path.join(directory, path.basename(runtimePaths.sentinelPath)))
732+
.pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed("")));
733+
return entryExists && isExactServiceVersion(sentinel.trim());
734+
});
746735
const recoverLauncher = Effect.suspend(() =>
747736
launcher === undefined
748737
? Effect.void
@@ -780,11 +769,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
780769
yield* fs.copy(runtimePaths.sentinelPath, path.join(launcher.stagingDir, sentinel));
781770
}),
782771
).pipe(Effect.mapError((cause) => new BootServiceInstallError({ cause })));
783-
// Renames, never overwrites: a launcher that is still running keeps its
784-
// open executable. The fixed path holds a complete copy except for the
785-
// moment between the two renames; a failed swap puts the previous copy
786-
// back. Once the new copy is in place, a retired copy that cannot be
787-
// removed is left for the next install to clear.
772+
// Rename instead of overwriting a running executable; keep recovery copies if rollback fails.
788773
const publishLauncher = Effect.suspend(() =>
789774
launcher === undefined
790775
? Effect.void

0 commit comments

Comments
 (0)