TypeScript
fix(server): keep the previous preview browser version on a shared home (#23771)
Victor Vogel55e7b5f66d6b
diff --git a/apps/server/src/preview/PreviewBrowser.test.ts b/apps/server/src/preview/PreviewBrowser.test.tsindex 0cb1665d4f3..a5c241229a3 100644--- a/apps/server/src/preview/PreviewBrowser.test.ts+++ b/apps/server/src/preview/PreviewBrowser.test.ts@@ -73,6 +73,7 @@ const browserArchive = makeZip([const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (options: {+ readonly version?: string;readonly archive?: Buffer;readonly sha256?: string;readonly body?: Stream.Stream<Uint8Array>;@@ -93,7 +94,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (release: options.unsupported? null: {- version: "1.2.3",+ version: options.version ?? "1.2.3",platform: "fixture",url: "https://storage.googleapis.com/chrome-headless-shell-fixture.zip",bytes: archive.byteLength,@@ -121,10 +122,11 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (});it.layer(NodeServices.layer)("PreviewBrowser", (it) => {- it.effect("installs a verified download with its file modes and then reuses it", () =>+ it.effect.each(["0.8.0", "1.2.3"])("retains another version when installing %s", (current) =>Effect.gen(function* () {- const { browser, fs, path, installRoot, requests } = yield* makeHarness();- yield* fs.makeDirectory(path.join(installRoot, "1.0.0"), { recursive: true });+ const { browser, fs, path, installRoot, requests } = yield* makeHarness({ version: current });+ yield* fs.makeDirectory(path.join(installRoot, "0.9.0"), { recursive: true });+ yield* fs.makeDirectory(path.join(installRoot, "0.10.0"));const active = path.join(installRoot, ".install-other");const abandoned = path.join(installRoot, ".install-abandoned");yield* fs.makeDirectory(active);@@ -135,7 +137,7 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {const executable = yield* browser.executable;- const version = path.join(installRoot, "1.2.3");+ const version = path.join(installRoot, current);expect(executable).toBe(path.join(version, executableName));expect(yield* fs.readFileString(path.join(version, "locales", "en-US.pak"))).toBe("strings");if (hostPlatform !== "win32") {@@ -145,10 +147,9 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {expect(yield* mode("libEGL.so")).toBe(0o755);expect(yield* mode(path.join("locales", "en-US.pak"))).toBe(0o644);}- expect((yield* fs.readDirectory(installRoot)).toSorted()).toEqual([- ".install-other",- "1.2.3",- ]);+ expect((yield* fs.readDirectory(installRoot)).toSorted()).toEqual(+ [".install-other", "0.10.0", current].toSorted(),+ );expect(yield* browser.executable).toBe(executable);expect(yield* browser.installed).toEqual(Option.some(executable));expect(requests).toHaveLength(1);diff --git a/apps/server/src/preview/PreviewBrowser.ts b/apps/server/src/preview/PreviewBrowser.tsindex d13b495ef5c..ea5539aad5e 100644--- a/apps/server/src/preview/PreviewBrowser.ts+++ b/apps/server/src/preview/PreviewBrowser.ts@@ -321,11 +321,14 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (yield* fs.remove(destination, { recursive: true, force: true });yield* fs.rename(unpacked, destination);}).pipe(Effect.scoped);- // Shared homes may have another server installing; preserve staging directories touched within the last hour.+ // Shared homes may still use the newest other version or staging directories touched within the last hour.const entries = yield* fs.readDirectory(installRoot);+ const previous = entries+ .filter((name) => name !== release.version && !name.startsWith("."))+ .toSorted((left, right) => right.localeCompare(left, "en", { numeric: true }))[0];const now = yield* Clock.currentTimeMillis;yield* Effect.forEach(- entries.filter((name) => name !== release.version),+ entries.filter((name) => name !== release.version && name !== previous),(name) =>Effect.gen(function* () {const target = path.join(installRoot, name);