Test that a reopened library precaches a live photo with no JSON file
check / check (push) Failing after 52s

Reopening the library over a live photo's image and video in the cache
with no JSON file beside them records no original for the photo; the
precache then fetches both and writes the JSON file.

Model: opus-5-5
This commit is contained in:
2026-10-02 01:16:55 +00:00
parent 5d11889e1a
commit 02afdd6d09
+60
View File
@@ -176,6 +176,66 @@ describe("Library content wiring", () => {
await lib.close(); await lib.close();
}); });
it("does not take a live photo's image or video with no JSON file as its original when it opens, and precaches both", async () => {
const { file: live, body } = await asLivePhoto(file(1, 1));
class LiveClient extends MockClient {
override async filesSince(): Promise<FilesPage> {
return { files: [live], deleted: [], cursor: 1 };
}
}
const originals = join(root, "cache", "originals");
const open = (opts: Partial<LibraryOptions>): Promise<Library> =>
Library.open({
client: new LiveClient(),
cacheDirectory: join(root, "cache"),
contentSource: cdnSource(new Map([[1, body]])),
refreshIntervalSeconds: 3600,
precacheThumbnails: false,
precacheOriginals: false,
...opts,
});
// A first run records the library, so the next one knows that file 1
// is a live photo when it opens the cache.
await (await open({})).close();
writeFileSync(join(originals, "1.heic"), "an image");
writeFileSync(join(originals, "1.mov"), "a video");
let precached!: () => void;
const done = new Promise<void>((r) => (precached = r));
const lib = await open({
precacheOriginals: true,
onProgress: (e) => {
if (e.operation === "precacheOriginals" && e.status === "done")
precached();
},
});
expect(
lib.photos.byID({ fileID: 1 })!.record().originalPath,
).toBeUndefined();
await done;
expect(readdirSync(originals).sort()).toEqual([
"1.heic",
"1.livephoto.json",
"1.mov",
]);
expect(readFileSync(join(originals, "1.heic"))).toEqual(
Buffer.from(IMAGE),
);
expect(readFileSync(join(originals, "1.mov"))).toEqual(
Buffer.from(VIDEO),
);
expect(
JSON.parse(
readFileSync(join(originals, "1.livephoto.json"), "utf-8"),
),
).toEqual({ image: "1.heic", video: "1.mov" });
expect(lib.photos.byID({ fileID: 1 })!.record().originalPath).toBe(
join(originals, "1.heic"),
);
await lib.close();
});
it("throws from content methods when opened without a content source", async () => { it("throws from content methods when opened without a content source", async () => {
const lib = await Library.open({ const lib = await Library.open({
client: new MockClient(), client: new MockClient(),