fix(browser-files): report exhausted object URL leases as retryable (02-04)

Preview and download share one lease registry and download leases stay for a
30 s grace, so running out of slots clears on its own. Only a Blob above the
single-lease ceiling stays LIMIT_EXCEEDED without retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-26 00:08:33 +09:00
co-authored by Claude Opus 5.5
parent c8e4794860
commit 0b41cb38af
5 changed files with 142 additions and 9 deletions
+66
View File
@@ -176,6 +176,72 @@ describe("browser file runtime hard limits and disposal", () => {
expect(revoked).toEqual(["blob:runtime-download"]);
});
it("reports exhausted object URL leases as retryable until the grace ends (02-04)", async () => {
const scheduled: Array<() => void> = [];
let urlSequence = 0;
const runtime = createBrowserFileRuntime({
input: fileInput(),
policies,
limits: {
hardMaxPreviewBytes: 8,
hardMaxObjectUrlBytes: 8,
hardMaxTransferBytes: 16,
hardMaxActiveObjectUrls: 2,
},
objectUrlApi: {
createObjectURL: () => `blob:runtime-download-${urlSequence++}`,
revokeObjectURL() {},
},
download: {
host: { handoff: vi.fn() },
browserManagedCapabilities:
unusedBrowserManagedCapabilities,
scheduler: {
setTimeout(callback) {
scheduled.push(callback);
return scheduled.length;
},
},
},
});
const deliver = () =>
runtime.downloads.deliver({
policy: downloadPolicy,
source: {
kind: "GENERATED",
bytes: {
byteLength: 3,
async *stream() {
yield { ok: true, value: new Uint8Array([1, 2, 3]) };
},
},
},
suggestedFileName: "artifact",
signal: new AbortController().signal,
onProgress() {},
});
// Each handoff keeps its lease for the revoke grace, so the third
// download inside that window finds every slot in use.
expect(await deliver()).toMatchObject({ ok: true });
expect(await deliver()).toMatchObject({ ok: true });
expect(await deliver()).toMatchObject({
ok: false,
error: {
code: "LIMIT_EXCEEDED",
retryable: true,
recovery: "RETRY",
},
});
for (const release of scheduled.splice(0)) release();
expect(await deliver()).toMatchObject({
ok: true,
value: { kind: "BROWSER_HANDOFF" },
});
runtime.dispose();
});
it("aborts a pending native picker and prevents event resurrection", async () => {
const input = fileInput();
Object.defineProperty(input, "click", {