TypeScript
fix(server): keep a failed service start out of the current state (#12199)
Vitaly Iegorove1931b56896a
diff --git a/apps/server/src/cloud/bootService.test.ts b/apps/server/src/cloud/bootService.test.tsindex 6a79d22ce90..4fb6d93babd 100644--- a/apps/server/src/cloud/bootService.test.ts+++ b/apps/server/src/cloud/bootService.test.ts@@ -858,6 +858,32 @@ it.layer(NodeServices.layer)("boot service install", (it) => {}),);+ it.effect("keeps failed launch agent installs pending until activation succeeds", () =>+ Effect.gen(function* () {+ const { service, fs, statePath, commands, control } = yield* makeHarness("darwin");+ const path = yield* Path.Path;+ const plan = yield* service.install();+ const markerPath = path.join(path.dirname(statePath), SERVICE_RESTART_PENDING_FILE);+ const bootstrap = `launchctl bootstrap gui/501 ${plan.unitPath}`;+ control.failCommand = bootstrap;++ expect((yield* service.install().pipe(Effect.flip))._tag).toBe("BootServiceCommandError");+ expect(yield* service.status).toMatchObject({+ current: false,+ problems: ["restart-pending"],+ });+ expect(yield* fs.readFileString(markerPath)).toBe("1.2.3\n");++ control.failCommand = undefined;+ commands.length = 0;+ yield* service.install();++ expect(commands).toContain(bootstrap);+ expect(yield* fs.exists(markerPath)).toBe(false);+ expect((yield* service.status).current).toBe(true);+ }),+ );+it.effect("restarts without overwriting a pending remote update on macOS", () =>Effect.gen(function* () {const { service, fs, statePath, commands } = yield* makeHarness("darwin");diff --git a/apps/server/src/cloud/bootService.ts b/apps/server/src/cloud/bootService.tsindex 8da2ca2db83..8820fc9d442 100644--- a/apps/server/src/cloud/bootService.ts+++ b/apps/server/src/cloud/bootService.ts@@ -810,12 +810,8 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {yield* fs.makeDirectory(path.dirname(unitPath), { recursive: true }).pipe(Effect.mapError((cause) => new BootServiceInstallError({ cause })));- if (!start && installed) {- // Written first: once the files below name the new version, the running- // service is behind them, and a failure between the two writes must not- // leave it looking current.- yield* fs.writeFileString(restartPendingPath, `${input.cliVersion}\n`, { mode: 0o600 });- }+ // Files can match the new version even when activation fails; keep that install retryable.+ yield* fs.writeFileString(restartPendingPath, `${input.cliVersion}\n`, { mode: 0o600 });yield* writeDurably(statePath,// @effect-diagnostics-next-line preferSchemaOverJson:off - fixed launcher-owned document.