Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
// Targets "View all" sheet (scrollability) — on Plan Detail.
//
// BYT-9558 (FIXED, #20427): on a Data Change with many targets, clicking
// "View all (N)" opened a popup that was frozen — the user could not scroll down
// to see all the targets. Root cause: the targets list rendered in a Dialog whose
// nested flex/overflow chain never produced a scrollable container, so content
// below the fold was unreachable. The fix replaced the Dialog with a Sheet whose
// body is `overflow-hidden` and whose inner list is `min-h-0 flex-1
// overflow-y-auto` — a real scroll container.
//
// SURFACE NOTE (BYT-9721, #20722): schema/data CHANGE issues now redirect off
// Issue Detail to Plan Detail, so opening this change issue lands on Plan Detail
// and this test exercises the Plan detail Changes/Targets sheet
// (PlanDetailChangesBranch.tsx) — the sibling surface that shared the same
// broken pattern + fix and was previously uncovered. The test asserts the
// redirect explicitly rather than depending on it silently.
//
// Owns its fixtures: creates >20 databases via psql, syncs + transfers them into
// the project, targets them in a single-spec plan/issue, and drops them in
// afterAll.
import { test, expect, type BrowserContext, type Page } from "@playwright/test";
import { loadTestEnv, type TestEnv } from "../framework/env";
import type { BytebaseApiClient } from "../framework/api-client";
import { execSql, getInstancePgPort } from "../framework/psql";
test.describe.configure({ mode: "serial" });
// 21 > DEFAULT_VISIBLE_TARGETS (20), so the "View all (21)" button renders.
const TARGET_COUNT = 21;
const STAMP = Date.now();
// Unique per run so a CI retry against the same disposable server doesn't collide.
const DB_PREFIX = `e2e_tgt_${STAMP}_`;
const dbShortNames = Array.from(
{ length: TARGET_COUNT },
(_, i) => `${DB_PREFIX}${String(i + 1).padStart(2, "0")}`,
);
// The last target — must require scrolling to reach inside the sheet.
const LAST_DB = dbShortNames[dbShortNames.length - 1];
let env: TestEnv & { api: BytebaseApiClient };
let pgPort = "";
let sharedContext: BrowserContext;
let page: Page;
let issueUrl = "";
test.beforeAll(async ({ browser }) => {
test.setTimeout(240_000);
env = loadTestEnv();
await env.api.login(env.adminEmail, env.adminPassword);
pgPort = await getInstancePgPort(env);
// 1. Create the databases via psql (CREATE DATABASE can't run in the same db
// being changed, but a single psql -c against the env database is fine).
for (const name of dbShortNames) {
execSql(env.databaseId, pgPort, `CREATE DATABASE ${name}`);
}
// 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(
async () => {
const { databases } = await env.api.listDatabases(env.instance);
const names = new Set((databases ?? []).map((d) => d.name));
return dbShortNames.every((short) =>
names.has(`${env.instance}/databases/${short}`),
);
},
{ timeout: 60_000, message: "synced databases should appear" },
)
.toBe(true);
// 3. Transfer each into the project (backend validateSpecs rejects targets not
// in the plan's project).
const targetFullNames: string[] = [];
for (const short of dbShortNames) {
const full = `${env.instance}/databases/${short}`;
await env.api.transferDatabaseToProject(full, env.project);
targetFullNames.push(full);
}
// 4. One spec targeting all 21 new databases → "View all (21)".
const sheet = await env.api.createSheet(env.project, "SELECT 1; -- byt9558");
const plan = await env.api.createPlan(env.project, `BYT-9558 ${STAMP}`, [
{ id: `spec-${STAMP}`, targets: targetFullNames, sheet },
]);
const issue = await env.api.createIssue(env.project, `BYT-9558 ${STAMP}`, plan.name);
const projectId = env.project.split("/").pop()!;
const issueId = issue.name.split("/").pop()!;
issueUrl = `${env.baseURL}/projects/${projectId}/issues/${issueId}`;
sharedContext = await browser.newContext({ storageState: ".auth/state.json" });
page = await sharedContext.newPage();
});
test.afterAll(async () => {
await sharedContext?.close();
// Best-effort: drop the databases and re-sync so Bytebase forgets them.
for (const name of dbShortNames) {
try {
execSql(env.databaseId, pgPort, `DROP DATABASE IF EXISTS ${name}`);
} catch {
/* best-effort — a lingering connection can block DROP on a disposable server */
}
}
await env.api.syncInstance(env.instance).catch(() => {});
});
test.describe("Targets 'View all' sheet scrolls to the last target on Plan Detail (BYT-9558)", () => {
test("the all-targets sheet is scrollable — the last target can be brought into view", async () => {
test.setTimeout(120_000);
// Open the Changes phase explicitly. A change issue redirects to Plan Detail
// (BYT-9721) and the loader preserves the query string, so `?phase=changes`
// survives the redirect and opens the Changes section this test asserts on —
// rather than depending on the phase Plan Detail picks by status (a plan that
// has a rollout would default to Deploy, which collapses Changes and would
// hide the "View all" button).
await page.goto(`${issueUrl}?phase=changes`);
await page.waitForURL(/\/projects\/[^/]+\/plans\/\d+/, { timeout: 20_000 });
await page.keyboard.press("Escape").catch(() => {});
await page.waitForLoadState("networkidle").catch(() => {});
// The Targets section shows "View all (21)".
const viewAll = page.getByRole("button", {
name: `View all (${TARGET_COUNT})`,
});
await expect(viewAll).toBeVisible({ timeout: 15_000 });
await viewAll.click();
// The Sheet opens with title "Targets (21)".
const sheet = page
.getByRole("dialog")
.filter({ hasText: `Targets (${TARGET_COUNT})` });
await expect(sheet).toBeVisible({ timeout: 5000 });
// THE REGRESSION ORACLE: the last target row can be scrolled into the
// viewport. Pre-fix the Dialog had no functioning scroll container, so rows
// below the fold were unreachable → scrollIntoViewIfNeeded can't surface it
// and toBeInViewport fails.
const lastRow = sheet.getByText(LAST_DB, { exact: false }).first();
await expect(
lastRow,
"the last target must be present in the (initially scrolled-off) list",
).toHaveCount(1);
// The list must actually overflow the element that scrolls it — sanity
// that we have enough rows to exercise the bug. The container is found
// from the row by computed style, not by a styling class.
const overflow = await lastRow.evaluate((el) => {
for (let node = el.parentElement; node; node = node.parentElement) {
const { overflowY } = getComputedStyle(node);
if (overflowY === "auto" || overflowY === "scroll") {
return node.scrollHeight - node.clientHeight;
}
}
return 0;
});
expect(
overflow,
"the targets list must overflow its container (otherwise scroll can't be tested)",
).toBeGreaterThan(10);
await lastRow.scrollIntoViewIfNeeded();
await expect(
lastRow,
"the last target must be reachable by scrolling the sheet (pre-fix the " +
"popup was frozen and the bottom targets were unreachable)",
).toBeInViewport({ timeout: 5000 });
// Anti-freeze: the in-sheet search narrows the list. Each target shows its
// database name as its own text, so the per-run prefix counts the listed
// targets: all 21 at baseline.
const targetNames = sheet.getByText(new RegExp(`^${DB_PREFIX}\\d{2}$`));
await expect(targetNames).toHaveCount(TARGET_COUNT, { timeout: 5000 });
const search = sheet.getByPlaceholder("Search").first();
await expect(search).toBeVisible({ timeout: 5000 });
await search.click();
await search.pressSequentially(LAST_DB, { delay: 15 });
// Filtering down to the single matching target proves the list is live
// (not a frozen popup).
await expect(targetNames).toHaveCount(1, { timeout: 5000 });
await expect(sheet.getByText(LAST_DB, { exact: false })).toBeVisible();
// Escape closes the sheet.
await page.keyboard.press("Escape");
await expect(sheet).toHaveCount(0, { timeout: 5000 });
});
});