feat: Beute L3–L5 (3D-Szene, Umbauen, Durchsicht, offline) und Diktat (T7 L1)
Beute L3 Runden 2+3 und Review-Fixes: - Glas-Holo ohne warmes Leuchten, Wanderboden-Fuss, Fokusflug mit Geist-Ansicht, Inhalte im Fokus, Rähmchen mit Art-Farbe beim Anheben - Hinweis-Geometrie je Zarge nur einmal je Layout gebaut; Drehen mit Pointer-Capture, endet auch bei Loslassen ausserhalb (rig-pointer.ts) - Tiefenunschärfe ab 55 fps, Leistungsprobe bei jeder Bewegungsstufe, Context-Loss-Listener aufgeräumt, Trefferboxen als skalierte Einheitsbox Beute L4 Umbauen (/colonies/[id]/hive): Entwurf mit Basis-Schnappschuss beim ersten Schritt, Rückgängig/Wiederholen, Hinweis bei Serverstand- Änderung, Konfliktblatt. Beute L5: - Durchsicht-Abschnitt „Beute“: Aufbau-Änderungen in der Durchsicht, Blatt-Formulare stoppen das Submit-Bubbling durch Portale (sonst speicherte „Speichern“ im Blatt die ganze Durchsicht), Fokus nach Rückgängig, Folgevorschläge beim Speichern - Offline: Beute im Offline-Paket, Warteschlange pending-hive-changes (DB v5), Abarbeiten in Reihenfolge, keine Online-Änderung überholt wartende, Hinweis bei abgelehnter Änderung mit „Warteschlange öffnen“ T7 L1 Diktat: Spracherkennungs-Kapsel (Web Speech API), Einwilligung standardmässig aus, Diktat-Knopf an Freitextfeldern, Seite „Sprache & Datenschutz“; axe-core als exakte devDependency. Backend: NotificationsService liest Empfänger und schreibt in einer Transaktion mit FOR KEY SHARE (paralleles Löschen eines Benutzers führte zu P2003 und verzögerten Vorschlägen; Ursache der wackeligen Endtests). Zwei e2e-Prüfungen gegen geteilten DB-Zustand entschärft. Gates: Frontend lint, typecheck, 2740 Tests, build; Backend lint, typecheck, 4266 Unit-Tests, build; parallele e2e 3x grün (978). Browser-Prüfung 1280/390 px, Tastatur, offline, reduced motion. Refs #19 #20 #21 #22 #27 #32 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
ab45d6e24e
commit
1a57de8573
123 files changed
+7639
-355
No files matched your search
@@ -8,6 +8,7 @@ vi.mock("@/lib/inspections/api", () => ({ createInspection: vi.fn() }));
|
||||
vi.mock("@/lib/treatments/api", () => ({ createTreatment: vi.fn() }));
|
||||
vi.mock("@/lib/documents/api", () => ({ uploadDocument: vi.fn() }));
|
||||
vi.mock("@/lib/phenology/api", () => ({ createPhenologyReport: vi.fn() }));
|
||||
vi.mock("@/lib/hive/api", () => ({ postHiveChange: vi.fn() }));
|
||||
vi.mock("@/lib/apiaries/offline-pack", () => ({ refreshPacksAfterSync: vi.fn() }));
|
||||
|
||||
// What the inspection drain hands over to the photos, seen at that moment.
|
||||
@@ -668,3 +669,222 @@ describe("syncPendingEntries", () => {
|
||||
expect(photo).toMatchObject({ state: "ready", inspectionId: "srv-1" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("drainHiveTimeline", () => {
|
||||
let postHiveChange: MockedFunction<typeof import("@/lib/hive/api").postHiveChange>;
|
||||
const op = (value: string) => ({ op: "setLabel" as const, id: "b", label: value });
|
||||
const hiveEntry = (colonyId: string, value: string) => ({
|
||||
colonyId,
|
||||
occurredOn: "2026-10-15",
|
||||
source: "CARD" as const,
|
||||
ops: [op(value)],
|
||||
});
|
||||
const withHive = (colony: number, value: string) => ({
|
||||
...inspection(colony),
|
||||
hiveChange: { ops: [op(value)] },
|
||||
});
|
||||
/** Entries queued in the same millisecond would tie on queuedAt. */
|
||||
const tick = () => new Promise((resolve) => setTimeout(resolve, 3));
|
||||
const labelsSent = () =>
|
||||
postHiveChange.mock.calls.map(([, input]) => (input.ops[0] as { label: string }).label);
|
||||
|
||||
beforeEach(async () => {
|
||||
globalThis.indexedDB = new IDBFactory();
|
||||
window.localStorage.clear();
|
||||
vi.resetModules();
|
||||
db = await import("./db");
|
||||
sync = await import("./sync");
|
||||
ApiError = (await import("@/lib/auth/api-client")).ApiError;
|
||||
createInspection = vi.mocked((await import("@/lib/inspections/api")).createInspection);
|
||||
postHiveChange = vi.mocked((await import("@/lib/hive/api")).postHiveChange);
|
||||
// The describe above leaves a mock that resolves uploads: start from scratch.
|
||||
uploadDocument = vi.mocked((await import("@/lib/documents/api")).uploadDocument);
|
||||
uploadDocument.mockReset();
|
||||
// The photo store mock wraps the first module instance, which keeps its
|
||||
// own connection: photos of earlier tests are still there and would be uploaded.
|
||||
const photoStore = await import("@/lib/photos/store");
|
||||
for (const photo of await photoStore.listPendingPhotos("user-1")) {
|
||||
await photoStore.discardReadyPhoto(photo.id);
|
||||
}
|
||||
refreshPacksAfterSync = vi.mocked(
|
||||
(await import("@/lib/apiaries/offline-pack")).refreshPacksAfterSync,
|
||||
);
|
||||
createInspection.mockReset().mockResolvedValue({ id: "i" } as never);
|
||||
postHiveChange.mockReset().mockResolvedValue({} as never);
|
||||
refreshPacksAfterSync.mockReset().mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("sends hive entries and inspections with a hive change in queuedAt order across both queues", async () => {
|
||||
const order: string[] = [];
|
||||
postHiveChange.mockImplementation(async (_c, input) => {
|
||||
order.push(`hive:${(input.ops[0] as { label: string }).label}`);
|
||||
return {} as never;
|
||||
});
|
||||
createInspection.mockImplementation(async (input) => {
|
||||
order.push(`inspection:${(input.hiveChange?.ops[0] as { label: string }).label}`);
|
||||
return { id: "i" } as never;
|
||||
});
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
await tick();
|
||||
await db.queueInspection(withHive(1, "b") as never, "k2", "user-1");
|
||||
await tick();
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "c"), "k3", "user-1");
|
||||
|
||||
const result = await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(order).toEqual(["hive:a", "inspection:b", "hive:c"]);
|
||||
expect(result).toEqual({ synced: 3, failed: 0, skippedForeign: 0 });
|
||||
expect(await db.getPendingEntries("pending-hive-changes")).toEqual([]);
|
||||
expect(await db.getPendingEntries("pending-inspections")).toEqual([]);
|
||||
});
|
||||
|
||||
it("sends each entry with its own idempotency key", async () => {
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "key-hive", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(postHiveChange).toHaveBeenCalledWith(
|
||||
"colony-1",
|
||||
{ occurredOn: "2026-10-15", source: "CARD", ops: [op("a")] },
|
||||
"key-hive",
|
||||
);
|
||||
});
|
||||
|
||||
it("leaves inspections with a hive change to the timeline and sends plain ones in the normal drain", async () => {
|
||||
await db.queueInspection(inspection(1), "plain", "user-1");
|
||||
await db.queueInspection(withHive(2, "x") as never, "with-hive", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(createInspection).toHaveBeenCalledTimes(2);
|
||||
expect(createInspection.mock.calls.map(([, options]) => options?.idempotencyKey).sort()).toEqual([
|
||||
"plain",
|
||||
"with-hive",
|
||||
]);
|
||||
});
|
||||
|
||||
it("holds later hive entries of the colony after a conflict, but not other colonies", async () => {
|
||||
postHiveChange.mockImplementation(async (colonyId, input) => {
|
||||
if (colonyId === "colony-1" && (input.ops[0] as { label: string }).label === "a") {
|
||||
throw new ApiError(409, "Konflikt", { code: "HIVE_CONFLICT", opIndex: 0, reason: "MISSING_ID: x" });
|
||||
}
|
||||
return {} as never;
|
||||
});
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
await tick();
|
||||
await db.queueInspection(withHive(1, "b") as never, "k2", "user-1");
|
||||
await tick();
|
||||
await db.queueHiveChange(hiveEntry("colony-2", "c"), "k3", "user-1");
|
||||
|
||||
const result = await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(labelsSent()).toEqual(["a", "c"]);
|
||||
expect(createInspection).not.toHaveBeenCalled();
|
||||
expect(result.failed).toBe(1);
|
||||
const [held] = await db.getPendingEntries("pending-inspections");
|
||||
expect(held.lastError).toBeUndefined();
|
||||
const [rejected] = await db.getPendingEntries("pending-hive-changes");
|
||||
expect(rejected.lastError).toMatchObject({ status: 409 });
|
||||
});
|
||||
|
||||
it("keeps only the small part of a conflict body in the stored rejection", async () => {
|
||||
postHiveChange.mockRejectedValue(
|
||||
new ApiError(409, "Konflikt", {
|
||||
code: "HIVE_CONFLICT",
|
||||
opIndex: 2,
|
||||
reason: "MISSING_ID: x",
|
||||
current: { version: 7, state: { schemaVersion: 1, stack: [{ id: "big" }] } },
|
||||
}),
|
||||
);
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
const [entry] = await db.getPendingEntries("pending-hive-changes");
|
||||
expect(entry.lastError?.details).toEqual({
|
||||
code: "HIVE_CONFLICT",
|
||||
opIndex: 2,
|
||||
reason: "MISSING_ID: x",
|
||||
current: { version: 7 },
|
||||
});
|
||||
});
|
||||
|
||||
it("holds the colony after a 403 and marks the inspection with the hive change", async () => {
|
||||
createInspection.mockRejectedValue(new ApiError(403, "Forbidden"));
|
||||
await db.queueInspection(withHive(1, "a") as never, "k1", "user-1");
|
||||
await tick();
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "b"), "k2", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(postHiveChange).not.toHaveBeenCalled();
|
||||
const [entry] = await db.getPendingEntries("pending-inspections");
|
||||
expect(entry.lastError).toMatchObject({ status: 403 });
|
||||
});
|
||||
|
||||
it("stops at a network error and sends the rest in the next run, in order", async () => {
|
||||
postHiveChange.mockRejectedValueOnce(new TypeError("Failed to fetch"));
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
await tick();
|
||||
await db.queueHiveChange(hiveEntry("colony-2", "b"), "k2", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
expect(labelsSent()).toEqual(["a"]);
|
||||
expect((await db.getPendingEntries("pending-hive-changes")).map((e) => e.lastError)).toEqual([
|
||||
undefined,
|
||||
undefined,
|
||||
]);
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
expect(labelsSent()).toEqual(["a", "a", "b"]);
|
||||
});
|
||||
|
||||
it("stops at a 5xx instead of marking the entry", async () => {
|
||||
postHiveChange.mockRejectedValueOnce(new ApiError(500, "Boom"));
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
await db.queueHiveChange(hiveEntry("colony-2", "b"), "k2", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(labelsSent()).toEqual(["a"]);
|
||||
const entries = await db.getPendingEntries("pending-hive-changes");
|
||||
expect(entries.every((entry) => entry.lastError === undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it("treats a key still in progress (409) as retry later and holds the colony", async () => {
|
||||
postHiveChange.mockRejectedValueOnce(
|
||||
new ApiError(409, "Diese Anfrage wird bereits verarbeitet - bitte kurz warten"),
|
||||
);
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-1");
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "b"), "k2", "user-1");
|
||||
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(labelsSent()).toEqual(["a"]);
|
||||
expect((await db.getPendingEntries("pending-hive-changes"))[0].lastError).toBeUndefined();
|
||||
});
|
||||
|
||||
it("never sends another account's hive entries", async () => {
|
||||
await db.queueHiveChange(hiveEntry("colony-1", "a"), "k1", "user-2");
|
||||
|
||||
const result = await sync.syncPendingEntries("user-1");
|
||||
|
||||
expect(postHiveChange).not.toHaveBeenCalled();
|
||||
expect(result.skippedForeign).toBe(1);
|
||||
});
|
||||
|
||||
it("sends the inspection without its hive change after strip-and-resend, with the same key", async () => {
|
||||
createInspection.mockRejectedValueOnce(new ApiError(403, "Forbidden"));
|
||||
await db.queueInspection(withHive(1, "a") as never, "same-key", "user-1");
|
||||
await sync.syncPendingEntries("user-1");
|
||||
const [rejected] = await db.getPendingEntries("pending-inspections");
|
||||
|
||||
await db.retryInspectionWithoutHiveChange(rejected.id);
|
||||
await sync.syncPendingEntries("user-1");
|
||||
|
||||
const [input, options] = createInspection.mock.calls[1];
|
||||
expect(input).not.toHaveProperty("hiveChange");
|
||||
expect(options?.idempotencyKey).toBe("same-key");
|
||||
expect(await db.getPendingEntries("pending-inspections")).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user