Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test(e2e): adapt to main (project-parented DBs, 3-tier submit, sync allowlist) + fix stopServer race
zchpeter7b427c662780
diff --git a/frontend/tests/e2e/framework/api-client.ts b/frontend/tests/e2e/framework/api-client.tsindex 6fc8375c1b..9fa3377d2b 100644--- a/frontend/tests/e2e/framework/api-client.ts+++ b/frontend/tests/e2e/framework/api-client.ts@@ -363,6 +363,20 @@ export class BytebaseApiClient {return this.request<{ name: string; dataSources: { id: string; port: string; host: string }[] }>("GET", `/v1/${instanceName}`);}+ // Set the instance's database sync allowlist (Instance.sync_databases). A+ // project-scoped sample instance is registered with an explicit allowlist of+ // exactly its seeded database (selfhost sample manager: [hr_test]), and the+ // schema syncer SKIPS any discovered database not on that list — so a+ // database created directly in the sample Postgres is never persisted by+ // syncInstance unless the allowlist is widened first.+ async updateInstanceSyncDatabases(instanceName: string, databases: string[]) {+ return this.request<unknown>(+ "PATCH",+ `/v1/${instanceName}?updateMask=sync_databases`,+ { name: instanceName, syncDatabases: { databases } },+ );+ }+async updateInstanceDataSource(instanceName: string, dataSourceId: string, port: string) {return this.request<unknown>("PATCH",`/v1/${instanceName}:updateDataSource?updateMask=port`,diff --git a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts b/frontend/tests/e2e/framework/mode-start-new-bytebase.tsindex 1c74b0b745..d8721b0e29 100644--- a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts+++ b/frontend/tests/e2e/framework/mode-start-new-bytebase.ts@@ -307,11 +307,27 @@ export async function startServer(): Promise<{export function stopServer(): void {if (serverProcess?.pid) {+ const pid = serverProcess.pid;try {- process.kill(-serverProcess.pid, "SIGTERM");+ process.kill(-pid, "SIGTERM");} catch {/* already dead */}+ // Wait for the process group to actually exit before removing its data+ // directory. Deleting it while the embedded Postgres is still shutting down+ // makes the checkpointer PANIC ("could not fsync pg_xact/0000") and leaves+ // the metadata-Postgres socket (/tmp/.s.PGSQL.<PORT+2>) behind, which then+ // trips the next boot's port probe. Bounded so a wedged server can't block+ // teardown forever.+ const deadline = Date.now() + 15_000;+ while (Date.now() < deadline) {+ try {+ process.kill(pid, 0); // throws once the process is gone+ } catch {+ break;+ }+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);+ }serverProcess = undefined;}if (tempDir && fs.existsSync(tempDir)) {diff --git a/frontend/tests/e2e/framework/setup-project.ts b/frontend/tests/e2e/framework/setup-project.tsindex 5ea5c32d20..9c51c3a373 100644--- a/frontend/tests/e2e/framework/setup-project.ts+++ b/frontend/tests/e2e/framework/setup-project.ts@@ -22,6 +22,12 @@ function loadSampleSeedData(): string {.join("\n");}+// The secondary-database sync poll below allows 60s, plus login, discovery+// and psql seeding before it. Playwright's 30s default test timeout would+// cut that poll off before instance sync can complete on a slower machine,+// so give the setup step an explicit budget that covers its own waits.+setup.setTimeout(180_000);+setup("authenticate and discover", async ({ page }) => {const env = loadTestEnv();await env.api.login(env.adminEmail, env.adminPassword);@@ -102,6 +108,14 @@ setup("authenticate and discover", async ({ page }) => {loadSampleSeedData(),);}+ // The sample instance is registered with a sync allowlist of just hr_test;+ // the syncer skips any other discovered database. Widen it to include the+ // secondary database BEFORE syncing, or hr_prod is discovered but never+ // persisted and the poll below can never see it.+ await env.api.updateInstanceSyncDatabases(instance, [+ databaseId,+ SECONDARY_DATABASE_ID,+ ]);await env.api.syncInstance(instance);const secondaryDatabase = `${instance}/databases/${SECONDARY_DATABASE_ID}`;await expectdiff --git a/frontend/tests/e2e/framework/ui-create-plan.ts b/frontend/tests/e2e/framework/ui-create-plan.tsindex 7791c6ebb4..bf5a4cc02d 100644--- a/frontend/tests/e2e/framework/ui-create-plan.ts+++ b/frontend/tests/e2e/framework/ui-create-plan.ts@@ -102,44 +102,30 @@ export async function createMultiSpecChangePlanViaUI(return { planId };}-// Submit the current draft plan for review (draft issue → open/non-draft), the-// UI's "Ready for Review" flow. Call while on the created plan's detail page.+// Submit the current draft plan for review — the UI's "Ready for Review"+// advance. Call while on the created plan's detail page.//-// The confirm dialog runs the plan checks and has TWO terminal states, both-// handled here so the helper is correct whether or not the plan has failing-// checks (review / rollout / plan-check callers deliberately attach ERROR-level-// rules):-// - checks pass → the Confirm button enables on its own.-// - checks fail → the product gates submission behind an explicit-// "Confirm anyway" acknowledgment checkbox; Confirm stays-// disabled until it is checked.+// 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.export async function submitDraftForReviewViaUI(page: Page): Promise<void> {- await page.getByRole("button", { name: "Ready for Review" }).click();- const dialog = page.getByRole("dialog");- const confirm = dialog- .getByRole("button", { name: /Ready for Review|Submit|Confirm/ })- .first();- const confirmAnyway = dialog- .getByRole("checkbox", { name: "Confirm anyway" })- .first();-- // Wait for the checks to settle into whichever terminal state applies: the- // ack checkbox appears (failing) or Confirm becomes enabled (passing).- await expect(async () => {- const gated = await confirmAnyway.isVisible().catch(() => false);- const enabled = await confirm.isEnabled().catch(() => false);- expect(gated || enabled).toBe(true);- }).toPass({ timeout: 45_000 });-- if (await confirmAnyway.isVisible().catch(() => false)) {- await confirmAnyway.click();- }- await expect(confirm).toBeEnabled({ timeout: 10_000 });- await confirm.click();- // After submission the header advances out of the ready-for-review state.- await expect(- page.getByRole("button", { name: "Ready for Review" }),- ).toHaveCount(0, { timeout: 15_000 });+ 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 });}// Create AND submit a database-change plan through the UI — the full "start adiff --git a/frontend/tests/e2e/issue-detail/issue-detail-targets.spec.ts b/frontend/tests/e2e/issue-detail/issue-detail-targets.spec.tsindex 8739af0460..5d11652455 100644--- a/frontend/tests/e2e/issue-detail/issue-detail-targets.spec.ts+++ b/frontend/tests/e2e/issue-detail/issue-detail-targets.spec.ts@@ -56,7 +56,16 @@ test.beforeAll(async ({ browser }) => {execSql(env.databaseId, pgPort, `CREATE DATABASE ${name}`);}- // 2. Sync the instance so Bytebase discovers them, then poll until present.+ // 2. Widen the sample instance's sync allowlist to cover the new databases,+ // then sync. The project-scoped sample instance is registered with an+ // explicit `sync_databases` allowlist (just hr_test / hr_prod); the schema+ // syncer SKIPS any discovered database not on it, so without this step the+ // poll below can never see them (discovered, never persisted).+ const { databases: existing } = await env.api.listDatabases(env.instance);+ const existingShort = (existing ?? []).map((d) => d.name.split("/").pop()!);+ await env.api.updateInstanceSyncDatabases(env.instance, [+ ...new Set([...existingShort, ...dbShortNames]),+ ]);await env.api.syncInstance(env.instance);await expect.poll(diff --git a/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts b/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.tsindex aba6c68dd1..e995850d85 100644--- a/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts+++ b/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts@@ -128,6 +128,10 @@ async function expectBackRestored({}test.beforeAll(async ({ browser }) => {+ // The file-level test.setTimeout does not cover hooks: beforeAll runs under+ // Playwright's 30s default, which cannot fit ISSUE_COUNT UI create+submit+ // cycles (each submit waits for the real "Ready for Review" advance).+ test.setTimeout(240_000);env = loadTestEnv();await env.api.login(env.adminEmail, env.adminPassword);const projectId = env.project.split("/").pop()!;diff --git a/frontend/tests/e2e/sql-editor/sql-editor-access-grants.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-access-grants.spec.tsindex 29d9e755da..4fe6de5941 100644--- a/frontend/tests/e2e/sql-editor/sql-editor-access-grants.spec.ts+++ b/frontend/tests/e2e/sql-editor/sql-editor-access-grants.spec.ts@@ -521,7 +521,15 @@ test.describe("access-grant drawer picker finds a database beyond the first page}}- // 2. Sync the instance and poll until Bytebase has discovered them all.+ // 2. Widen the sample instance's sync allowlist to cover the new databases,+ // then sync. The project-scoped sample instance carries an explicit+ // `sync_databases` allowlist and the schema syncer skips any discovered+ // database not on it — without this the poll below can never see them.+ const { databases: listed } = await env.api.listDatabases(env.instance);+ const listedShort = (listed ?? []).map((d) => d.name.split("/").pop()!);+ await env.api.updateInstanceSyncDatabases(env.instance, [+ ...new Set([...listedShort, ...dbShortNames]),+ ]);await env.api.syncInstance(env.instance);await expect.poll(diff --git a/frontend/tests/e2e/sql-editor/sql-editor-batch.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-batch.spec.tsindex e90c7bdb5a..d386ff160f 100644--- a/frontend/tests/e2e/sql-editor/sql-editor-batch.spec.ts+++ b/frontend/tests/e2e/sql-editor/sql-editor-batch.spec.ts@@ -203,18 +203,19 @@ test.describe("Connection panel Database Group tab (C8/C9)", () => {await sqlEditor.runPreparedQuery("SELECT 1 AS n;");// BatchQuerySelect rendering signal: the "Batch export" button is- // present alongside one button per queried database. The DB tabs- // are plain <button name="hr_prod"> elements (the breadcrumb's- // button is "Prod Prod Sample Instance hr_prod", so exact match- // disambiguates).+ // present alongside one result tab per queried database. Each tab's+ // accessible name is the full "<instance> / <env> <db>" path (e.g.+ // "Sample Project Instance / Prod hr_prod"), so anchor on the database+ // name at the END of the name — the breadcrumb's connection button also+ // contains "hr_prod" but is not a result tab and does not end with it.await expect(page.getByRole("button", { name: /Batch export/i }).first(),).toBeVisible({ timeout: 15_000 });await expect(- page.getByRole("button", { name: "hr_prod", exact: true }).first(),+ page.getByRole("button", { name: /\bhr_prod$/ }).first(),).toBeVisible({ timeout: 5_000 });await expect(- page.getByRole("button", { name: "hr_test", exact: true }).first(),+ page.getByRole("button", { name: /\bhr_test$/ }).first(),).toBeVisible({ timeout: 5_000 });});diff --git a/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.tsindex 8dda26339b..67de2baf3d 100644--- a/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts+++ b/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts@@ -271,8 +271,13 @@ test.describe("SQL Editor entry from the database page connects the tab (BYT-961const projectId = env.project.split("/").pop()!;// Database detail page (cold load — do NOT visit /sql-editor first).+ // Navigate exactly as the product links to it (autoDatabaseRoute): the+ // `parent` query carries the project-parented instance name. Without it the+ // page falls back to the legacy `instances/<id>` parent, GetDatabase 404s,+ // and the route bounces to the landing page.+ const parent = env.database.replace(/\/databases\/[^/]+$/, "");await dbPage.goto(- `${env.baseURL}/projects/${projectId}/instances/${env.instanceId}/databases/${env.databaseId}`,+ `${env.baseURL}/projects/${projectId}/instances/${env.instanceId}/databases/${env.databaseId}?parent=${encodeURIComponent(parent)}`,);await dbPage.keyboard.press("Escape").catch(() => {});await dbPage.waitForTimeout(1500);diff --git a/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.tsindex d1ef5bd35b..91d6ed238c 100644--- a/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts+++ b/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts@@ -6,8 +6,8 @@// localStorage-persisted tab).// - H4 Clicking the gutter tabs switches the visible aside panel// (SavedQuery ↔ Schema ↔ History).-// - H5 The SQL editor's gutter logo opens in a new tab-// (target=_blank + rel=noopener noreferrer) — GutterBar.tsx:49.+// - H5 The SQL editor header logo renders as a plain image (no link) —+// SQLEditorHeader.tsx mounts <BytebaseLogo> without `redirect`.// - O1 The QueryContextSettingPopover trigger ("(limit N)") is hidden// in admin mode — EditorAction.tsx:171 wraps it in a `!isAdminMode`// block.@@ -110,24 +110,21 @@ test.describe("Gutter tab switching (H4)", () => {});});-test.describe("Header logo links to the workspace landing (H5)", () => {- test("logo is an in-app link to the landing page, not a new-tab external anchor", async () => {+test.describe("Header logo renders as a plain image (H5)", () => {+ test("the SQL editor header shows the Bytebase logo and it is not a navigation link", async () => {const projectId = env.project.split("/").pop()!;await sqlEditor.gotoWithDb(projectId, env.instanceId, env.databaseId);- // The route-ownership refactor moved the logo into the shared SQL Editor- // header (SQLEditorHeader → BytebaseLogo) and made it an in-app RouterLink- // to the workspace landing route — no longer an external new-tab anchor.- // It's the only <img alt="Bytebase"> on the page; walk up to its <a>.- const logoAnchor = page- .locator("a")- .filter({ has: page.locator('img[alt="Bytebase"]') })- .first();- await expect(logoAnchor).toBeVisible({ timeout: 10_000 });- // Internal SPA navigation: a relative href to the landing route, and NOT a- // new-tab link.- await expect(logoAnchor).toHaveAttribute("href", /\/landing/);- await expect(logoAnchor).not.toHaveAttribute("target", "_blank");+ // The SQL editor header mounts <BytebaseLogo> WITHOUT the `redirect` prop+ // (SQLEditorHeader.tsx), so the logo is a plain image — not a RouterLink to+ // the landing page and not an external new-tab anchor. (Both earlier forms+ // existed on prior mains; the current contract is "no link".) It is the+ // only <img alt="Bytebase"> on the page.+ const logo = page.locator('img[alt="Bytebase"]').first();+ await expect(logo).toBeVisible({ timeout: 10_000 });+ await expect(+ page.locator("a").filter({ has: page.locator('img[alt="Bytebase"]') }),+ ).toHaveCount(0);});});