fix(studio): recover uncertain imports with persistent request identities
CI / check (push) Successful in 3m12s
CI / deploy (push) Successful in 19s
CI / publish-container (push) Successful in 1m12s

This commit is contained in:
Simo committed 2026-09-13 18:33:06 +02:00
1 parent afea80708c
commit c977fe95ba
12 files changed
+365 -31

No files matched your search

@@ -1,15 +1,34 @@
import { useState } from "react";
import { FurnitureJobHistory } from "@/components/admin/studio/furniture-jobs";
import { useFurnitureJobs } from "@/components/admin/studio/use-furniture-jobs";
import { furnitureJobFixture } from "../../../src/test/furniture-jobs-fixtures";
export function FurnitureJobsHarness() {
const [completions, setCompletions] = useState(0);
const [submitted, setSubmitted] = useState<string>("");
const history = useFurnitureJobs(
() => setCompletions((value) => value + 1),
true,
7,
);
return (
<section aria-label="Import history hook">
<button
type="button"
disabled={history.busy}
onClick={async () =>
setSubmitted(
String(
await history.submit(furnitureJobFixture.items, {
translate: false,
}),
),
)
}
>
Submit import
</button>
<output aria-label="Submitted">{submitted}</output>
<button
type="button"
onClick={() => {
+43
View File
@@ -143,3 +143,46 @@ test("history shows the current phase and validated recovery source", async ({
),
).toBe(false);
});
test("uncertain import submissions keep their identity after a page reload", async ({
page,
}) => {
const ids: string[] = [];
await page.route("**/api/admin/csrf", (route) =>
route.fulfill({ json: { token: "a".repeat(64) } }),
);
await page.route("**/api/admin/studio/import-jobs**", async (route) => {
if (route.request().method() !== "POST") {
await route.fulfill({ json: { ok: true, jobs: [], nextCursor: null } });
return;
}
const body = route.request().postDataJSON();
ids.push(body.id);
if (ids.length === 1) await route.abort("failed");
else
await route.fulfill({
json: { ok: true, job: { ...furnitureJobFixture, id: body.id } },
});
});
await page.goto("/admin/jobs-harness");
await page
.getByRole("button", { name: "Submit import", exact: true })
.click();
await expect(page.getByLabel("Submitted", { exact: true })).toHaveText(
"false",
);
await page.reload();
await page
.getByRole("button", { name: "Submit import", exact: true })
.click();
await expect(page.getByLabel("Submitted", { exact: true })).toHaveText(
"true",
);
expect(ids).toHaveLength(2);
expect(ids[1]).toBe(ids[0]);
await page
.getByRole("button", { name: "Submit import", exact: true })
.click();
await expect.poll(() => ids.length).toBe(3);
expect(ids[2]).not.toBe(ids[0]);
});