Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

test(ui): stop two flaky browser checks from ejecting merge-queue runs (#10333)

Josh Corbett024dab826568
diff --git a/invokeai/frontend/webv2/performance/README.md b/invokeai/frontend/webv2/performance/README.md
index 3d7f4df9b8..258c61213a 100644
--- a/invokeai/frontend/webv2/performance/README.md
+++ b/invokeai/frontend/webv2/performance/README.md
@@ -113,10 +113,16 @@ Use the raw `:browser` command only when the build is known current. Install eng
`pnpm exec playwright install --with-deps chromium firefox webkit`. Ports default to 4180/4181; override
`INVOKEAI_PROJECT_FILE_PORT` and `INVOKEAI_PROJECT_FILE_BACKEND_PORT` for an isolated focused run.
-The required localhost capabilities are IndexedDB and Web Locks. Each engine holds the initial fixture migration PUT before server dispatch, makes a new held prompt edit, and
-leaves for a neutral same-origin document immediately. Before any editor can reconcile it, the suite proves the
-committed journal has the new marker while the staged draft, held PUT bodies and server do not. Reopening must
-recover that marker. Each engine also verifies actual Canvas and layer-thumbnail fixture pixels, rejects an opaque
+The required localhost capabilities are IndexedDB and Web Locks. Each engine holds the initial fixture migration PUT before server dispatch and checks
+that this save staged the old document, then makes a new held prompt edit and leaves for a neutral same-origin
+document immediately. Before any editor can reconcile it, the suite checks where the edit is held and that the server
+lacks it; reopening must recover it. Chromium must hold it in the committed journal alone, with the staged draft and
+held PUT bodies still old, so its run proves journal-only recovery. In Firefox and WebKit, once unload cancels the held
+PUT, the queued `pagehide` save can continue: it stages the edit, retires its journal entry and may send it. Their runs
+prove only that the edit was durably held in the journal or the staged draft, was staged if sent, and survived the
+reload. Journal-only recovery is also covered by the scenarios in `src/workbench/projects/unloadJournal.scenarios.ts`,
+run on Chromium IndexedDB by `unloadJournal.scenarios.browser.test.ts`; that a save sends nothing until its draft
+write finishes is covered in `src/workbench/projects/durableSyncedPersistence.test.ts`. Each engine also verifies actual Canvas and layer-thumbnail fixture pixels, rejects an opaque
checker-only thumbnail and empty Canvas, holds native animation-end delivery to prove retirement waits for the owner’s exit event, defers actual owner DOM removal by 100 ms to exercise the bounded React-removal grace, and injects retained portal DOM into the real sustained-workload collector.
Engines must give duplicated tabs separate live editor sessions, release a closed tab's session lock, preserve edits
across route re-entry after Launchpad owner/media readiness (all mounted cover images finish decoding), advance keyboard focus, and disable copy controls with an explanation when clipboard is
@@ -139,7 +145,7 @@ Document-navigation cancellation expectations are shared by smoke and release jo
explicitly owned navigation through DOMContentLoaded, on the same origin's `/api/` requests or mock Socket.IO polling.
All engines may cancel old-document reads and writes; WebKit may instead emit its exact native Fetch/XMLHttpRequest
access-control-denial message. A canceled mutation is teardown evidence, never evidence of a successful save: the
-held-edit scenario separately proves journal-only recovery. HTTP 4xx/5xx responses, non-abort failures, cross-origin
+held-edit scenario separately checks where the edit was durably held and that reopening recovers it. HTTP 4xx/5xx responses, non-abort failures, cross-origin
requests, asset failures, live-document mutations and unrelated runtime/console errors remain critical. Queue reader
cancellations during route re-entry are limited to its actual read interface: status, current, next and item IDs (GET),
then bounded item hydration (`items_by_ids`, read-only POST). Queue status GET cancellation is also recognized at the
diff --git a/invokeai/frontend/webv2/scripts/run-browser-smoke.mjs b/invokeai/frontend/webv2/scripts/run-browser-smoke.mjs
index 3dbcf38df8..4366fff9a5 100644
--- a/invokeai/frontend/webv2/scripts/run-browser-smoke.mjs
+++ b/invokeai/frontend/webv2/scripts/run-browser-smoke.mjs
@@ -17,6 +17,46 @@ const initialSavePath = '/api/v1/projects/fixture-project-002';
const isInitialSaveUrl = (url) => url.origin === origin && url.pathname === initialSavePath;
const sessionKey = 'invokeai:v7:webv2:editor-session';
const lockPrefix = `${sessionKey}:`;
+/** Which committed unload-journal entries and staged drafts hold `needle`, read from IndexedDB. */
+const readHeldDocuments = (page, needle) =>
+ page.evaluate(async (needle) => {
+ const result = { journal: [], drafts: [] };
+ for (const { name } of await indexedDB.databases()) {
+ const kind = name.startsWith('invokeai:v7:webv2:unload-journal')
+ ? 'journal'
+ : name.startsWith('invokeai:v7:webv2:workbench')
+ ? 'drafts'
+ : null;
+ if (!kind) {
+ continue;
+ }
+ const db = await new Promise((resolve, reject) => {
+ const request = indexedDB.open(name);
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ });
+ try {
+ const store = kind === 'journal' ? 'entries' : 'draftBodies';
+ if (!db.objectStoreNames.contains(store)) {
+ continue;
+ }
+ const records = await new Promise((resolve, reject) => {
+ const request = db.transaction(store).objectStore(store).getAll();
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ });
+ result[kind].push(
+ ...records.map((record) => ({
+ projectId: record.projectId,
+ hasMarker: record.documentJson.includes(needle),
+ }))
+ );
+ } finally {
+ db.close();
+ }
+ }
+ return result;
+ }, needle);
await mkdir(artifacts, { recursive: true });
const reports = [];
for (const [engine, type] of Object.entries({ chromium, firefox, webkit })) {
@@ -118,58 +158,30 @@ for (const [engine, type] of Object.entries({ chromium, firefox, webkit })) {
}
await waitForRenderedMedia(page);
await expect.poll(() => heldPuts.length, { timeout: 20_000 }).toBeGreaterThan(0);
- // No blur/debounce/save wait after A: the actual unload must checkpoint the held field over B.
let marker = `smoke held prompt ${engine}`;
- await prompt.fill(marker);
- await navigate(() => page.goto(`${origin}/__browser-smoke-idle`, { waitUntil: 'domcontentloaded' }));
- const recovery = await page.evaluate(async (needle) => {
- const result = { journal: [], drafts: [] };
- for (const { name } of await indexedDB.databases()) {
- const kind = name.startsWith('invokeai:v7:webv2:unload-journal')
- ? 'journal'
- : name.startsWith('invokeai:v7:webv2:workbench')
- ? 'drafts'
- : null;
- if (!kind) {
- continue;
- }
- const db = await new Promise((resolve, reject) => {
- const request = indexedDB.open(name);
- request.onsuccess = () => resolve(request.result);
- request.onerror = () => reject(request.error);
- });
- try {
- const store = kind === 'journal' ? 'entries' : 'draftBodies';
- if (!db.objectStoreNames.contains(store)) {
- continue;
- }
- const records = await new Promise((resolve, reject) => {
- const request = db.transaction(store).objectStore(store).getAll();
- request.onsuccess = () => resolve(request.result);
- request.onerror = () => reject(request.error);
- });
- result[kind].push(
- ...records.map((record) => ({
- projectId: record.projectId,
- hasMarker: record.documentJson.includes(needle),
- }))
- );
- } finally {
- db.close();
- }
- }
- return result;
- }, marker);
- assert.ok(
- recovery.journal.some((entry) => entry.hasMarker),
- 'Committed journal must contain A'
- );
+ const initial = await readHeldDocuments(page, marker);
assert.ok(
- recovery.drafts.some((entry) => entry.projectId === 'fixture-project-002' && !entry.hasMarker),
+ initial.drafts.some((entry) => entry.projectId === 'fixture-project-002' && !entry.hasMarker),
'The initial save must have staged old B'
);
- assert.ok(!recovery.drafts.some((entry) => entry.hasMarker), 'Staged B must not explain A recovery');
- assert.ok(heldPuts.length && heldPuts.every((body) => !body.includes(marker)), 'Only old B reached PUT');
+ // No blur/debounce/save wait after A: the actual unload must checkpoint the held field over B.
+ await prompt.fill(marker);
+ await navigate(() => page.goto(`${origin}/__browser-smoke-idle`, { waitUntil: 'domcontentloaded' }));
+ const recovery = await readHeldDocuments(page, marker);
+ const journaledA = recovery.journal.some((entry) => entry.hasMarker);
+ if (engine === 'chromium') {
+ assert.ok(journaledA, 'Committed journal must contain A');
+ assert.ok(!recovery.drafts.some((entry) => entry.hasMarker), 'Staged B must not explain A recovery');
+ assert.ok(heldPuts.length && heldPuts.every((body) => !body.includes(marker)), 'Only old B reached PUT');
+ } else {
+ // Once unload cancels the held B PUT, Firefox and WebKit can run the pagehide save on: it stages A
+ // over B, retiring the journal, and may then PUT A.
+ const stagedA = recovery.drafts.some(
+ (entry) => entry.projectId === 'fixture-project-002' && entry.hasMarker
+ );
+ assert.ok(journaledA || stagedA, 'A must be held in the committed journal or the staged draft');
+ assert.ok(stagedA || heldPuts.every((body) => !body.includes(marker)), 'A sent by PUT must be staged');
+ }
const server = await fetch(
`${backend.origin}/api/v1/projects/fixture-project-002?max_canvas_schema_version=4&max_document_schema_version=4`
);
@@ -202,7 +214,7 @@ for (const [engine, type] of Object.entries({ chromium, firefox, webkit })) {
);
void initialGalleryReads.catch(() => {});
await open();
- await expect(prompt, 'Journal-only held field must survive actual unload').toHaveValue(marker);
+ await expect(prompt, 'Held field must survive actual unload').toHaveValue(marker);
await initialGalleryReads;
await waitForRenderedMedia(page, {
allImagesSelector: '[data-hotkey-widget-type-id="gallery"] [data-gallery-tile-media] img',
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx
index 50628e08f2..1f37e7eaa8 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx
@@ -4,7 +4,6 @@ import { system } from '@theme/system';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { userEvent } from 'vitest/browser';
import { ConditioningRebalanceBars } from './ConditioningRebalanceBars';
@@ -68,21 +67,6 @@ const lastPreview = (): number[] => (onPreview.mock.calls.at(-1)?.[0] as number[
const lastCommit = (): number[] => (onCommit.mock.calls.at(-1)?.[0] as number[] | undefined) ?? [];
-/** Reset real pointer and scroll state to prevent interference from synthetic events. */
-const resetPointerAndScroll = async (): Promise<void> => {
- const parking = document.createElement('div');
-
- parking.style.cssText = 'position:fixed;right:0;bottom:0;width:2px;height:2px;z-index:2147483647';
- document.body.append(parking);
-
- await act(async () => {
- await userEvent.hover(parking);
- });
-
- parking.remove();
- window.scrollTo(0, 0);
-};
-
beforeEach(() => {
host = document.createElement('div');
document.body.append(host);
@@ -97,7 +81,7 @@ afterEach(async () => {
host?.remove();
host = null;
root = null;
- await resetPointerAndScroll();
+ window.scrollTo(0, 0);
});
describe('ConditioningRebalanceBars', () => {
diff --git a/invokeai/frontend/webv2/src/features/video/ui/videoReferenceFindInGallery.browser.test.tsx b/invokeai/frontend/webv2/src/features/video/ui/videoReferenceFindInGallery.browser.test.tsx
index d52f68cd25..93ef0764df 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/videoReferenceFindInGallery.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/videoReferenceFindInGallery.browser.test.tsx
@@ -8,7 +8,6 @@ import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { I18nextProvider, initReactI18next } from 'react-i18next';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { userEvent } from 'vitest/browser';
import { VideoReferenceListField } from './VideoReferenceListField';
import { VideoUiProvider, type VideoUiAdapter } from './VideoUiContext';
@@ -98,23 +97,6 @@ const render = async (): Promise<void> => {
);
};
-/**
- * Park the pointer before mount: an origin hover would reveal the first badge, and moving afterward starts a fade that
- * invalidates resting-opacity assertions.
- */
-const parkPointer = async (): Promise<void> => {
- const parking = document.createElement('div');
-
- parking.style.cssText = 'position:fixed;right:0;bottom:0;width:2px;height:2px;z-index:2147483647';
- document.body.append(parking);
-
- await act(async () => {
- await userEvent.hover(parking);
- });
-
- parking.remove();
-};
-
const findButtons = (name: string): HTMLButtonElement[] => [
...host.querySelectorAll<HTMLButtonElement>(`button[aria-label="Find ${name} in Gallery"]`),
];
@@ -143,7 +125,6 @@ describe('video reference find-in-gallery badges', () => {
});
it('keeps the badge out of the way until its own thumbnail is hovered or focused', async () => {
- await parkPointer();
await render();
// Focus-within exercises the same thumbnail scope as hover. Assert pointer-events during focus changes because
diff --git a/invokeai/frontend/webv2/src/workbench/projects/durableSyncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/durableSyncedPersistence.test.ts
index f14d962b5a..1dbabe3264 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/durableSyncedPersistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/durableSyncedPersistence.test.ts
@@ -730,6 +730,40 @@ describe('durable project persistence', () => {
);
});
+ it('sends an edit to the server only after its draft write has finished', async () => {
+ const owner = captureAccountScope();
+ const api = createApi();
+ const project = createDraftProject([]);
+ api.records.set(project.id, toRecord(project));
+ vi.mocked(api.loadSession).mockResolvedValue({
+ account: createInitialWorkbenchState().account,
+ activeProjectId: project.id,
+ openProjectIds: [project.id],
+ });
+ const backingStore = createMemoryProjectDraftStore();
+ let held: Promise<void> | null = null;
+ let finishWrite!: () => void;
+ const stage = vi.fn(async (input: Parameters<ProjectDraftStore['stage']>[0]) => {
+ await held;
+ return backingStore.stage(input);
+ });
+ const service = createService(owner, api, { ...backingStore, stage });
+ const loaded = await service.loadWorkbench();
+ held = new Promise((resolve) => {
+ finishWrite = resolve;
+ });
+ stage.mockClear();
+
+ const saved = service.saveWorkbench(stateWith([{ ...loaded.state.projects[0]!, name: 'Renamed' }]));
+ await vi.waitFor(() => expect(stage).toHaveBeenCalledOnce());
+ expect(api.updateProject).not.toHaveBeenCalled();
+ finishWrite();
+ await saved;
+
+ expect(api.updateProject).toHaveBeenCalledOnce();
+ expect(api.records.get(project.id)?.name).toBe('Renamed');
+ });
+
it('continues the authoritative save when browser draft storage is unavailable', async () => {
const owner = captureAccountScope();
const api = createApi();