Skip to content

Commit 7d117ee

Browse files
committed
Cover backfill cache retry behavior
Add a regression test proving failed documentLoader calls are removed from the traversal-local cache. A later strategy can retry the same IRI and yield the recovered object. Assisted-by: Codex:gpt-5.5
1 parent e7a2e69 commit 7d117ee

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

packages/backfill/src/backfill.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,53 @@ describe("backfill", () => {
429429
]);
430430
});
431431

432+
test("document cache does not keep failed dereferences", async () => {
433+
const contextId = new URL("https://example.com/contexts/1");
434+
const parentId = new URL("https://example.com/notes/1");
435+
const parent = new Note({
436+
id: parentId,
437+
content: "parent",
438+
});
439+
const note = new Note({
440+
id: new URL("https://example.com/notes/2"),
441+
contexts: [contextId],
442+
replyTarget: parentId,
443+
});
444+
const requests: URL[] = [];
445+
let parentRequests = 0;
446+
const context: BackfillContext = {
447+
documentLoader: (iri) => {
448+
requests.push(iri);
449+
if (iri.href === contextId.href) {
450+
return Promise.resolve(
451+
new Collection({
452+
id: contextId,
453+
items: [parentId],
454+
}),
455+
);
456+
}
457+
if (iri.href === parentId.href) {
458+
parentRequests++;
459+
if (parentRequests === 1) throw new Error("temporary failure");
460+
return Promise.resolve(parent);
461+
}
462+
return Promise.resolve(null);
463+
},
464+
};
465+
466+
const items = await collect(context, note, {
467+
strategies: ["context-auto", "reply-tree"],
468+
});
469+
470+
strictEqual(items.length, 1);
471+
strictEqual(items[0].object.id?.href, parentId.href);
472+
deepStrictEqual(requests.map((url) => url.href), [
473+
contextId.href,
474+
parentId.href,
475+
parentId.href,
476+
]);
477+
});
478+
432479
test("strategy order controls deduplicated item metadata", async () => {
433480
const contextId = new URL("https://example.com/contexts/1");
434481
const parentId = new URL("https://example.com/notes/1");

0 commit comments

Comments
 (0)