Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

test(e2e): re-press after wait blockers; read the plan statement as a whole

zchpetera4c755094f0e
diff --git a/frontend/tests/e2e/AGENTS.md b/frontend/tests/e2e/AGENTS.md
index ec3c344be0..24c32f4454 100644
--- a/frontend/tests/e2e/AGENTS.md
+++ b/frontend/tests/e2e/AGENTS.md
@@ -87,6 +87,8 @@ const sql = `SELECT "${col}" FROM "${schema}"."${table}" WHERE "${pkColumn}" = '
Use `ControlOrMeta+a` (portable), not `Meta+a` (Mac-only) or `Control+a` (Linux/Windows-only).
+**Exception — Monaco editors:** Monaco derives its `CtrlCmd` modifier from the user agent, and Playwright's headless Chromium reports a Windows UA on every host, while Playwright resolves `ControlOrMeta` from the host OS. For Monaco's own keybindings (select-all, editor actions) use `Control+…`; `ControlOrMeta+…` is silently ignored on macOS hosts (Linux CI hosts happen to agree, so CI does not catch it). Browser-native editing commands (copy/paste) follow the host OS instead, so don't use a key for them at all — call `document.execCommand("copy")` from `page.evaluate` right after a keypress (see `SchemaEditorPage.planStatementText`).
+
### 7. Prefer `data-testid` over class-based selectors
Tailwind class substrings like `[class*='border border-gray']` break on any CSS refactor. If you need a new locator, add a `data-testid` attribute to the component. Existing class-based selectors are technical debt.
diff --git a/frontend/tests/e2e/framework/ui-create-plan.ts b/frontend/tests/e2e/framework/ui-create-plan.ts
index bf5a4cc02d..171f5a0f85 100644
--- a/frontend/tests/e2e/framework/ui-create-plan.ts
+++ b/frontend/tests/e2e/framework/ui-create-plan.ts
@@ -106,26 +106,59 @@ export async function createMultiSpecChangePlanViaUI(
// advance. Call while on the created plan's detail page.
//
// The advance is a tiered press (LifecycleAdvance.tsx / advanceState.ts), not
-// a confirm dialog: a clean press advances immediately with no UI; when checks
-// failed and the project does not enforce SQL review, a warning popover offers
-// "Submit anyway"; a hard blocker (e.g. enforceSqlReview + failed checks)
-// shows a read-only list and the press is a no-op. Success is the header state
-// machine leaving `ready-for-review` — the button disappears. ONE press, then
-// one positive wait: no re-press/Escape loop, which fires stray events into a
-// transitioning React tree on the shared page and destabilises later tests.
+// a confirm dialog. One press resolves to exactly one of:
+// advanced — nothing unresolved: the header leaves ready-for-review and the
+// button disappears.
+// decision — checks failed and the project does not enforce SQL review: a
+// popover offers "Submit anyway".
+// blocked — a read-only blockers popover (role="alert") and NO advance.
+// `wait` rows ("Clears on its own": checks queued/running) close
+// the popover by themselves once the checks finish — but closing
+// never submits, so the press must be repeated. `fix` rows
+// (title, statement, permission) never clear without the user.
+// So: press, observe which tier answered, and re-press only after a wait-only
+// popover has closed on its own. Never re-press blindly or send Escape — stray
+// events into a transitioning React tree on the shared page destabilise later
+// tests.
export async function submitDraftForReviewViaUI(page: Page): Promise<void> {
const readyButton = page.getByRole("button", { name: "Ready for Review" });
const submitAnyway = page.getByRole("button", { name: "Submit anyway" });
- await readyButton.click();
- // Tier 2: a "Submit anyway" decision popover appears only when checks failed.
- const decided = await submitAnyway
- .waitFor({ state: "visible", timeout: 3_000 })
- .then(() => true)
- .catch(() => false);
- if (decided) await submitAnyway.click();
- // The advance completes when the header leaves ready-for-review. Plan checks
- // may still be finishing (a "wait" blocker clears on its own), so allow time.
- await expect(readyButton).toHaveCount(0, { timeout: 60_000 });
+ const blockers = page.getByRole("alert").filter({ hasText: /./ });
+ // Blocker rows without the "Clears on its own" tag need the user to act.
+ const fixRows = blockers
+ .locator(":scope > div")
+ .filter({ hasNotText: "Clears on its own" });
+
+ const observe = async () => {
+ if ((await readyButton.count()) === 0) return "advanced";
+ if (await submitAnyway.isVisible()) return "decision";
+ if (await blockers.isVisible()) return "blocked";
+ return "pending";
+ };
+
+ for (let press = 1; press <= 8; press++) {
+ await readyButton.click();
+ await expect
+ .poll(observe, { timeout: 20_000 })
+ .not.toBe("pending");
+ const tier = await observe();
+ if (tier === "advanced") return;
+ if (tier === "decision") {
+ await submitAnyway.click();
+ await expect(readyButton).toHaveCount(0, { timeout: 60_000 });
+ return;
+ }
+ // Blocked: a fix-kind row cannot self-clear — fail with what the user sees.
+ if ((await fixRows.count()) > 0) {
+ throw new Error(
+ `Ready for Review is blocked by: ${(await fixRows.allInnerTexts()).join(" | ")}`,
+ );
+ }
+ // Wait-only blockers (plan checks still running) close the popover by
+ // themselves when the checks finish; then press again.
+ await expect(blockers).toBeHidden({ timeout: 120_000 });
+ }
+ throw new Error("Ready for Review kept re-blocking on running checks");
}
// Create AND submit a database-change plan through the UI — the full "start a
diff --git a/frontend/tests/e2e/schema-editor/schema-editor.page.ts b/frontend/tests/e2e/schema-editor/schema-editor.page.ts
index 780480a65b..0965fce3a6 100644
--- a/frontend/tests/e2e/schema-editor/schema-editor.page.ts
+++ b/frontend/tests/e2e/schema-editor/schema-editor.page.ts
@@ -267,29 +267,62 @@ export class SchemaEditorPage {
await expect(this.sheet).toBeHidden({ timeout: 15_000 });
}
- // Reads the plan's statement Monaco editor. That editor VIRTUALIZES and its
- // viewport is short, so only the top (rendered) lines live in the DOM. A
- // multi-statement DDL - e.g. a CREATE TABLE followed by a SEPARATE
- // `ALTER TABLE ... ADD CONSTRAINT ... PRIMARY KEY (...)` statement - puts its
- // trailing lines below the fold, and a naive `.view-lines` read silently
- // truncates them (this is why a created-table PK, emitted as that trailing
- // ALTER statement, appeared "missing"). Read the top, jump to the end so the
- // trailing lines render, then union both. Also normalize Monaco's rendered
- // non-breaking spaces to plain spaces so literal-space assertions match.
+ // Reads the plan's statement Monaco editor — the COMPLETE text, not the
+ // rendered viewport. That editor VIRTUALIZES: only the lines in view exist in
+ // the DOM, so a `.view-lines` read silently truncates a multi-statement DDL
+ // (this is why a created-table PK, emitted as a trailing separate
+ // `ALTER TABLE ... ADD CONSTRAINT ... PRIMARY KEY`, appeared "missing").
+ // `window.monaco` is not exposed on the production bundle, so the model is
+ // read the way a user copies it: select all, then copy. Monaco's own copy
+ // handler writes the full selection into the copy event's clipboardData, and
+ // a bubbling listener on window (it runs after Monaco's textarea handler)
+ // reads it from there — no OS clipboard involved, which headless Chromium
+ // does not share between a native copy and navigator.clipboard anyway. Each
+ // step waits on its observable effect; the selection is collapsed afterwards
+ // so the editor is left as it was found.
async planStatementText(): Promise<string> {
- const lines = this.page.locator(".monaco-editor .view-lines").first();
- await expect(lines).toBeVisible({ timeout: 10_000 });
- const norm = (s: string) => s.replace(/\u00a0/g, " ");
- const top = norm(await lines.innerText());
- // Focus the editor and jump to document end so the last lines render.
- await this.page.locator(".monaco-editor").first().click();
- await this.page.keyboard.press("ControlOrMeta+End");
- await this.page.waitForTimeout(300); // let the scrolled-to lines render
- const bottom = norm(await lines.innerText());
- // Union preserves order: top lines first, then newly-revealed trailing
- // lines. Substring/regex assertions then see the whole statement.
- return Array.from(
- new Set([...top.split("\n"), ...bottom.split("\n")]),
- ).join("\n");
+ const editor = this.page.locator(".monaco-editor").first();
+ await expect(editor.locator(".view-lines")).toBeVisible({ timeout: 10_000 });
+ await this.page.evaluate(() => {
+ const w = window as unknown as {
+ __bbCopied?: string;
+ __bbCopyHooked?: boolean;
+ };
+ w.__bbCopied = undefined;
+ if (w.__bbCopyHooked) return;
+ w.__bbCopyHooked = true;
+ window.addEventListener("copy", (e) => {
+ w.__bbCopied = e.clipboardData?.getData("text/plain") ?? "";
+ });
+ });
+ // Monaco takes keys through its hidden textarea, and focuses it a tick
+ // AFTER a mouse click — a select-all pressed straight after a click lands
+ // on nothing. Focus the textarea itself and wait for the focus.
+ // `Control+a`, not `ControlOrMeta+a`: select-all is Monaco's OWN keybinding
+ // and Monaco derives its CtrlCmd modifier from the user agent — Playwright's
+ // headless Chromium reports a Windows UA whatever the host is — whereas
+ // Playwright resolves ControlOrMeta from the HOST OS (Meta on macOS, which
+ // Monaco then ignores; Linux CI hosts happen to agree, hiding the mismatch).
+ const input = editor.locator("textarea.inputarea");
+ await input.focus();
+ await expect(input).toBeFocused({ timeout: 5_000 });
+ await this.page.keyboard.press("Control+a");
+ await expect(editor.locator(".selected-text").first()).toBeVisible({
+ timeout: 5_000,
+ });
+ // Copy through execCommand rather than a key: the browser-native copy
+ // shortcut follows the HOST OS (Cmd+C on macOS, Ctrl+C on Linux CI), so no
+ // single key works everywhere, while execCommand("copy") dispatches the
+ // same copy event to Monaco's handler on every host. The select-all
+ // keypress just above supplies the user activation Chromium requires.
+ await this.page.evaluate(() => document.execCommand("copy"));
+ const read = () =>
+ this.page.evaluate(
+ () => (window as unknown as { __bbCopied?: string }).__bbCopied,
+ );
+ await expect.poll(read, { timeout: 5_000 }).not.toBeUndefined();
+ const text = (await read()) ?? "";
+ await this.page.keyboard.press("ArrowRight"); // collapse the selection
+ return text.replace(/\u00a0/g, " ").replace(/\r\n/g, "\n");
}
}
diff --git a/frontend/tests/e2e/sql-editor/sql-editor.page.ts b/frontend/tests/e2e/sql-editor/sql-editor.page.ts
index 8bd7c16193..6ba14f2f28 100644
--- a/frontend/tests/e2e/sql-editor/sql-editor.page.ts
+++ b/frontend/tests/e2e/sql-editor/sql-editor.page.ts
@@ -173,7 +173,12 @@ export class SqlEditorPage {
opts.which === "last" ? this.codeEditor.last() : this.codeEditor;
await editor.click();
await this.page.waitForTimeout(150);
- await this.page.keyboard.press("ControlOrMeta+a");
+ // `Control+a`, not `ControlOrMeta+a`: Monaco reads its CtrlCmd modifier
+ // from the user agent (Playwright's headless Chromium reports Windows on
+ // every host), while Playwright resolves ControlOrMeta from the host OS —
+ // on a macOS host that sent Meta+a, which Monaco ignored, so the "clear"
+ // only ever worked on editors that were already empty.
+ await this.page.keyboard.press("Control+a");
await this.page.waitForTimeout(50);
await this.page.keyboard.press("Delete");
await this.page.waitForTimeout(50);