Skip to content

Commit 55e7b5f

Browse files
only21milclaudemaria-rcks
authored
fix(server): keep the previous preview browser version on a shared home (pingdotgg#23771)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 5e35f6e commit 55e7b5f

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎apps/server/src/preview/PreviewBrowser.test.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const browserArchive = makeZip([
7373

7474
const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
7575
options: {
76+
readonly version?: string;
7677
readonly archive?: Buffer;
7778
readonly sha256?: string;
7879
readonly body?: Stream.Stream<Uint8Array>;
@@ -93,7 +94,7 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
9394
release: options.unsupported
9495
? null
9596
: {
96-
version: "1.2.3",
97+
version: options.version ?? "1.2.3",
9798
platform: "fixture",
9899
url: "https://storage.googleapis.com/chrome-headless-shell-fixture.zip",
99100
bytes: archive.byteLength,
@@ -121,10 +122,11 @@ const makeHarness = Effect.fn("test.makePreviewBrowser")(function* (
121122
});
122123

123124
it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
124-
it.effect("installs a verified download with its file modes and then reuses it", () =>
125+
it.effect.each(["0.8.0", "1.2.3"])("retains another version when installing %s", (current) =>
125126
Effect.gen(function* () {
126-
const { browser, fs, path, installRoot, requests } = yield* makeHarness();
127-
yield* fs.makeDirectory(path.join(installRoot, "1.0.0"), { recursive: true });
127+
const { browser, fs, path, installRoot, requests } = yield* makeHarness({ version: current });
128+
yield* fs.makeDirectory(path.join(installRoot, "0.9.0"), { recursive: true });
129+
yield* fs.makeDirectory(path.join(installRoot, "0.10.0"));
128130
const active = path.join(installRoot, ".install-other");
129131
const abandoned = path.join(installRoot, ".install-abandoned");
130132
yield* fs.makeDirectory(active);
@@ -135,7 +137,7 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
135137

136138
const executable = yield* browser.executable;
137139

138-
const version = path.join(installRoot, "1.2.3");
140+
const version = path.join(installRoot, current);
139141
expect(executable).toBe(path.join(version, executableName));
140142
expect(yield* fs.readFileString(path.join(version, "locales", "en-US.pak"))).toBe("strings");
141143
if (hostPlatform !== "win32") {
@@ -145,10 +147,9 @@ it.layer(NodeServices.layer)("PreviewBrowser", (it) => {
145147
expect(yield* mode("libEGL.so")).toBe(0o755);
146148
expect(yield* mode(path.join("locales", "en-US.pak"))).toBe(0o644);
147149
}
148-
expect((yield* fs.readDirectory(installRoot)).toSorted()).toEqual([
149-
".install-other",
150-
"1.2.3",
151-
]);
150+
expect((yield* fs.readDirectory(installRoot)).toSorted()).toEqual(
151+
[".install-other", "0.10.0", current].toSorted(),
152+
);
152153
expect(yield* browser.executable).toBe(executable);
153154
expect(yield* browser.installed).toEqual(Option.some(executable));
154155
expect(requests).toHaveLength(1);

‎apps/server/src/preview/PreviewBrowser.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,14 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
321321
yield* fs.remove(destination, { recursive: true, force: true });
322322
yield* fs.rename(unpacked, destination);
323323
}).pipe(Effect.scoped);
324-
// Shared homes may have another server installing; preserve staging directories touched within the last hour.
324+
// Shared homes may still use the newest other version or staging directories touched within the last hour.
325325
const entries = yield* fs.readDirectory(installRoot);
326+
const previous = entries
327+
.filter((name) => name !== release.version && !name.startsWith("."))
328+
.toSorted((left, right) => right.localeCompare(left, "en", { numeric: true }))[0];
326329
const now = yield* Clock.currentTimeMillis;
327330
yield* Effect.forEach(
328-
entries.filter((name) => name !== release.version),
331+
entries.filter((name) => name !== release.version && name !== previous),
329332
(name) =>
330333
Effect.gen(function* () {
331334
const target = path.join(installRoot, name);

0 commit comments

Comments
 (0)