Cycle previews through the walk

This commit is contained in:
Fisto
2026-09-17 00:20:00 +02:00
parent 0664b54241
commit 0ba51e06ba
5 changed files with 86 additions and 3 deletions
+61
View File
@@ -877,6 +877,67 @@ void (async () => {
assert.equal(existsSync(join(dir, `${poster?.hash}.webp`)), true);
});
await test("previews run in cycles during the walk", async () => {
const events: string[] = [];
const pages: Array<{ messages: CoreMessage[] }> = [
{
messages: [
message("1000", {
attachments: [attachment({ filename: "a.png", contentType: "image/png" })]
})
]
},
{
messages: [
message("999", {
attachments: [attachment({ filename: "b.png", contentType: "image/png" })]
})
]
}
];
const backend: ScrapeBackend = {
name: "puppet",
async fetchPage() {
events.push("walk");
return pages.shift() ?? { messages: [] };
}
};
const engine = new ScrapeEngine({
rootDir: root,
pageSize: 1,
pageMinMs: 0,
pageMaxMs: 0,
sleep: async () => {},
random: () => 0,
log: () => {},
previews: true,
walkCyclePages: 1,
download: {
fetchImpl: async () => {
events.push("preview");
return new Response("webp", { status: 200, headers: { "content-type": "image/webp" } });
},
minGapMs: 0,
maxGapMs: 0,
previewMinGapMs: 0,
previewMaxGapMs: 0,
previewBatchSize: 100,
sleep: async () => {}
}
});
const started = await engine.start({ channelId: "150", guildId: null, mode: "links", backend });
await engine.processQueue();
assert.equal(engine.get(started.id)?.previewed, 2);
const firstPreview = events.indexOf("preview");
const secondWalk = events.indexOf("walk", 1);
assert.ok(firstPreview !== -1, "a preview happened during the walk");
assert.ok(secondWalk > firstPreview, "the walk continued after previews");
});
await test("engine resumes a paused scrape from its cursor", async () => {
const first = new FakeBackend([
{ messages: [message("500"), message("499")] },