Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

23.0 KB
Raw Blame
import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { QUERY_EDITOR_FULL_FEATURE_MAX_DOCUMENT_LENGTH } from "@/lib/editor/queryEditorLargeDocument";
import { assertSourceIdentity, freezeSourceIdentities } from "@/lib/table/objectSourceIdentity";

// issue #9035:源码 tab 必须先出现再加载。这批用例锁定 pending 占位 tab 的
// 行为契约:立即出现、原地填充、就地重试、加载中被关闭则丢弃、重复点击去重。
const mocks = vi.hoisted(() => {
  const connectionStore = {
    activeConnectionId: null as string | null,
    ensureConnected: vi.fn(async () => {}),
    dbType: "oracle",
    getConfig: (connectionId: string) => (connectionId ? { id: connectionId, name: connectionId, db_type: connectionStore.dbType } : undefined),
  };
  return {
    connectionStore,
    ensureConnected: connectionStore.ensureConnected,
    getObjectSource: vi.fn(),
    buildEditableObjectSource: vi.fn(async (input: { source: string }) => input.source),
    closeQuerySession: vi.fn(async () => {}),
    closeClientConnectionSession: vi.fn(async () => {}),
    saveOpenTabsState: vi.fn(async () => {}),
  };
});

vi.mock("@/lib/backend/api", () => ({
  getObjectSource: (...args: unknown[]) => mocks.getObjectSource(...args),
  buildEditableObjectSource: (input: { source: string }) => mocks.buildEditableObjectSource(input),
  closeQuerySession: mocks.closeQuerySession,
  closeClientConnectionSession: mocks.closeClientConnectionSession,
  saveOpenTabsState: mocks.saveOpenTabsState,
}));

vi.mock("@/stores/connectionStore", () => ({
  useConnectionStore: () => mocks.connectionStore,
}));

const CONNECTION_ID = "ora-1";
const DATABASE = "ORCL";
const SCHEMA = "APP";

const pendingOptions = (request: { name: string; objectType: "VIEW" | "PROCEDURE" | "FUNCTION" | "SEQUENCE" | "PACKAGE" | "PACKAGE_BODY"; signature?: string }) => ({
  connectionId: CONNECTION_ID,
  database: DATABASE,
  title: `Source - ${request.name}`,
  schema: SCHEMA,
  request,
});

const objectSource = (source: string, editable?: boolean) => ({
  name: "ignored",
  object_type: "VIEW" as const,
  source,
  ...(editable === undefined ? {} : { editable }),
});

/** 让 loader 的 await 链跑完(ensureConnected → getObjectSource → 落地)。 */
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));

describe("queryStore pending object source tab", () => {
  beforeEach(() => {
    vi.clearAllMocks();
    vi.stubGlobal("localStorage", { getItem: vi.fn(() => null), setItem: vi.fn(), removeItem: vi.fn() });
    setActivePinia(createPinia());
    mocks.connectionStore.dbType = "oracle";
  });

  it("rejects a late source response after migration and preserves a dirty old draft", async () => {
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    let resolveSource!: (value: unknown) => void;
    mocks.getObjectSource.mockReturnValue(new Promise((resolve) => (resolveSource = resolve)));
    const id = store.openObjectSourceTabPending(pendingOptions({ name: "late_migration", objectType: "VIEW" }));
    await settle();
    const migration = freezeSourceIdentities([{ connectionId: CONNECTION_ID, database: DATABASE, schema: SCHEMA, name: "late_migration", objectType: "VIEW" }]);
    migration.markDispatched();
    migration.finish();
    resolveSource(objectSource("CREATE VIEW late_migration AS SELECT 1 FROM dual"));
    await settle();
    expect(store.tabs[0]!.objectSource).toBeUndefined();
    expect(store.tabs[0]!.sourceLoad?.error).toContain("reload");

    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE VIEW late_migration AS SELECT 2 FROM dual"));
    store.retryObjectSourceTab(id);
    await settle();
    const tab = store.tabs[0]!;
    const old = store.getObjectSourceIdentitySnapshot(tab)!;
    store.updateSql(id, "my dirty draft");
    const second = freezeSourceIdentities([old]);
    second.markDispatched();
    second.finish();
    store.openObjectSourceTabPending(pendingOptions({ name: "late_migration", objectType: "VIEW" }));
    await settle();
    expect(tab.sql).toBe("my dirty draft");
    expect(() => assertSourceIdentity(store.getObjectSourceIdentitySnapshot(tab)!)).toThrow();
    expect(store.isTabDirty(tab)).toBe(true);
  });

  it("does not let background revalidation revive a frozen source but allows explicit refresh", async () => {
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    mocks.getObjectSource.mockResolvedValue(objectSource("original source"));
    const options = pendingOptions({ name: "revalidate_migration", objectType: "VIEW" });
    const id = store.openObjectSourceTabPending(options);
    await settle();
    const tab = store.tabs[0]!;
    const old = store.getObjectSourceIdentitySnapshot(tab)!;
    let complete!: (value: unknown) => void;
    mocks.getObjectSource.mockReturnValueOnce(
      new Promise((resolve) => {
        complete = resolve;
      }),
    );
    store.openObjectSourceTabPending(options);
    await settle();
    const migration = freezeSourceIdentities([old]);
    migration.markDispatched();
    migration.finish();
    complete(objectSource("late old source"));
    await settle();
    expect(tab.sql).toBe("original source");
    expect(() => assertSourceIdentity(store.getObjectSourceIdentitySnapshot(tab)!)).toThrow();
    mocks.getObjectSource.mockResolvedValue(objectSource("fresh rebuilt source"));
    expect(store.refreshObjectSourceTab(id)).toBe(true);
    await settle();
    expect(tab.sql).toBe("fresh rebuilt source");
    expect(() => assertSourceIdentity(store.getObjectSourceIdentitySnapshot(tab)!)).not.toThrow();
    expect(() => assertSourceIdentity(old)).toThrow();
  });

  it.each(["connection", "database"])("requires a successful reload after source %s retargeting", async (target) => {
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    mocks.getObjectSource.mockResolvedValue(objectSource("original retarget source"));
    const id = store.openObjectSourceTabPending(pendingOptions({ name: `retarget_${target}`, objectType: "VIEW" }));
    await settle();
    const tab = store.tabs[0]!;
    const original = store.getObjectSourceIdentitySnapshot(tab)!;
    store.updateSql(id, "dirty retarget draft");
    if (target === "connection") store.updateConnection(id, "ora-2", DATABASE);
    else store.updateDatabase(id, "ORCL2");
    expect(() => store.getObjectSourceIdentitySnapshot(tab)).toThrow();
    expect(tab.sql).toBe("dirty retarget draft");
    expect(store.isTabDirty(tab)).toBe(true);
    store.createTab(CONNECTION_ID, DATABASE, "Unrelated query");
    if (target === "connection") store.updateConnection(id, CONNECTION_ID, DATABASE);
    else store.updateDatabase(id, DATABASE);
    expect(store.getObjectSourceIdentitySnapshot(tab)).toBe(original);
    if (target === "connection") store.updateConnection(id, "ora-2", DATABASE);
    else store.updateDatabase(id, "ORCL2");
    mocks.getObjectSource.mockResolvedValue(objectSource("reloaded target source"));
    expect(store.refreshObjectSourceTab(id)).toBe(true);
    await settle();
    const reloaded = store.getObjectSourceIdentitySnapshot(tab)!;
    expect(reloaded.connectionId).toBe(tab.connectionId);
    expect(reloaded.database).toBe(tab.database);
    expect(() => assertSourceIdentity(reloaded)).not.toThrow();
    expect(original.connectionId).toBe(CONNECTION_ID);
    expect(original.database).toBe(DATABASE);
    expect(tab.sql).toBe("reloaded target source");
  });

  it("discards a source load retargeted before its response arrives", async () => {
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    let complete!: (value: unknown) => void;
    mocks.getObjectSource.mockReturnValue(new Promise((resolve) => (complete = resolve)));
    const id = store.openObjectSourceTabPending(pendingOptions({ name: "retarget_pending", objectType: "VIEW" }));
    await settle();
    store.updateDatabase(id, "ORCL2");
    complete(objectSource("late old target source"));
    await settle();
    expect(store.tabs[0]!.objectSource).toBeUndefined();
    expect(store.tabs[0]!.sql).not.toBe("late old target source");
    expect(store.tabs[0]!.sourceLoad?.error).toContain("reload");
  });

  it("keeps loaded source when a background response arrives after retargeting", async () => {
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    const options = pendingOptions({ name: "retarget_background", objectType: "VIEW" });
    mocks.getObjectSource.mockResolvedValue(objectSource("original background source"));
    const id = store.openObjectSourceTabPending(options);
    await settle();
    let complete!: (value: unknown) => void;
    mocks.getObjectSource.mockReturnValueOnce(new Promise((resolve) => (complete = resolve)));
    store.openObjectSourceTabPending(options);
    await settle();
    store.updateConnection(id, "ora-2", DATABASE);
    complete(objectSource("late old background source"));
    await settle();
    expect(store.tabs[0]!.sql).toBe("original background source");
    expect(() => store.getObjectSourceIdentitySnapshot(store.tabs[0]!)).toThrow();
  });

  it("creates a visible loading tab before the source arrives", async () => {
    let resolveSource: ((value: unknown) => void) | undefined;
    mocks.getObjectSource.mockReturnValue(new Promise((resolve) => (resolveSource = resolve)));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const id = store.openObjectSourceTabPending(pendingOptions({ name: "v_orders", objectType: "VIEW" }));

    // 请求还没回来,tab 已经在界面上:这正是 #9035 缺的那一步
    expect(store.tabs).toHaveLength(1);
    const tab = store.tabs[0]!;
    expect(tab.id).toBe(id);
    expect(tab.title).toBe("Source - v_orders");
    expect(tab.sourceView).toBe(true);
    expect(tab.sql).toBe("");
    expect(tab.objectSource).toBeUndefined();
    expect(tab.sourceLoad?.error).toBeUndefined();
    expect(tab.sourceLoad?.request).toEqual({ name: "v_orders", objectType: "VIEW", signature: undefined });
    expect(tab.sourceLoad?.startedAt).toBeTypeOf("number");

    resolveSource?.(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    await settle();
  });

  it("fills the same tab in place once the source resolves", async () => {
    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const id = store.openObjectSourceTabPending(pendingOptions({ name: "v_orders", objectType: "VIEW" }));
    await settle();

    expect(store.tabs).toHaveLength(1);
    const tab = store.tabs[0]!;
    expect(tab.id).toBe(id);
    expect(tab.sql).toBe("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual");
    expect(tab.sourceView).toBe(true);
    expect(tab.sourceLoad).toBeUndefined();
    expect(tab.objectSource).toMatchObject({ schema: SCHEMA, name: "v_orders", objectType: "VIEW" });
  });

  it("preserves every character of a realistically large package source", async () => {
    const procedures = Array.from({ length: 25_000 }, (_, index) => `PROCEDURE p_${index} IS BEGIN NULL; END p_${index};\n`).join("");
    const source = `CREATE OR REPLACE PACKAGE BODY huge_pkg AS\n${procedures}END huge_pkg;\n/`;
    expect(source.length).toBeGreaterThan(QUERY_EDITOR_FULL_FEATURE_MAX_DOCUMENT_LENGTH);
    mocks.getObjectSource.mockResolvedValue(objectSource(source));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const id = store.openObjectSourceTabPending(pendingOptions({ name: "huge_pkg", objectType: "PACKAGE_BODY" }));
    await settle();

    const tab = store.tabs.find((candidate) => candidate.id === id)!;
    expect(tab.sql).toBe(source);
    expect(tab.sql.length).toBe(source.length);
    expect(tab.objectSource).toMatchObject({ schema: SCHEMA, name: "huge_pkg", objectType: "PACKAGE_BODY" });
    expect(tab.sourceLoad).toBeUndefined();
  });

  it("keeps the resolved (fallback) object type on the tab, not the requested one", async () => {
    // 请求 PROCEDURE,后端返回空 → routine fallback 回落到 FUNCTION
    mocks.getObjectSource.mockImplementation(async (_connectionId, _database, _schema, _name, objectType: string) => objectSource(objectType === "FUNCTION" ? "CREATE OR REPLACE FUNCTION app.foo RETURN NUMBER IS BEGIN RETURN 1; END;" : ""));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    store.openObjectSourceTabPending(pendingOptions({ name: "foo", objectType: "PROCEDURE" }));
    await settle();

    expect(store.tabs[0]?.objectSource).toMatchObject({ name: "foo", objectType: "FUNCTION" });
  });

  it("surfaces a failure inside the tab and retries in place", async () => {
    mocks.getObjectSource.mockRejectedValueOnce(new Error("ORA-00942: table or view does not exist"));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const id = store.openObjectSourceTabPending(pendingOptions({ name: "v_orders", objectType: "VIEW" }));
    await settle();

    const failed = store.tabs[0]!;
    expect(failed.id).toBe(id);
    expect(failed.sourceLoad?.error).toContain("ORA-00942");
    expect(failed.sql).toBe("");
    // 失败不吞掉 tab:用户就在这个 tab 里重试,而不是只收到一个 toast

    mocks.getObjectSource.mockResolvedValueOnce(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 2 FROM dual"));
    store.retryObjectSourceTab(id);
    // 重试立即回到加载态(错误清空 → tab 栏重新转圈)
    expect(store.tabs[0]?.sourceLoad?.error).toBeUndefined();
    await settle();

    expect(store.tabs).toHaveLength(1);
    expect(store.tabs[0]?.sql).toBe("CREATE OR REPLACE VIEW app.v_orders AS SELECT 2 FROM dual");
    expect(store.tabs[0]?.sourceLoad).toBeUndefined();
  });

  it("drops the result when the tab was closed while loading", async () => {
    let resolveSource: ((value: unknown) => void) | undefined;
    mocks.getObjectSource.mockReturnValue(new Promise((resolve) => (resolveSource = resolve)));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const id = store.openObjectSourceTabPending(pendingOptions({ name: "v_orders", objectType: "VIEW" }));
    store.closeTab(id);
    expect(store.tabs).toHaveLength(0);

    resolveSource?.(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    await settle();

    // 关掉就是放弃:不重建 tab、不写入已关闭的容器
    expect(store.tabs).toHaveLength(0);
  });

  it("reuses the pending tab and the in-flight request on a repeat click", async () => {
    let resolveSource: ((value: unknown) => void) | undefined;
    mocks.getObjectSource.mockReturnValue(new Promise((resolve) => (resolveSource = resolve)));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const options = pendingOptions({ name: "v_orders", objectType: "VIEW" });
    const first = store.openObjectSourceTabPending(options);
    const second = store.openObjectSourceTabPending(options);

    expect(second).toBe(first);
    expect(store.tabs).toHaveLength(1);

    // 第二次点击发生在请求真正发出之前(loader 先 await ensureConnected),
    // 所以这里要等微任务落定后再确认只发了一次请求
    await settle();
    expect(mocks.getObjectSource).toHaveBeenCalledTimes(1);

    resolveSource?.(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    await settle();
    expect(store.tabs).toHaveLength(1);
  });

  it("reuses an already loaded tab instantly and revalidates it in the background", async () => {
    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const options = pendingOptions({ name: "v_orders", objectType: "VIEW" });
    const first = store.openObjectSourceTabPending(options);
    await settle();
    expect(mocks.getObjectSource).toHaveBeenCalledTimes(1);
    expect(store.activeTabId).toBe(first);

    // 重复打开:不出现第二个转圈 tab,立刻回到同一个 tab,也不进加载态
    mocks.getObjectSource.mockResolvedValueOnce(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 2 FROM dual"));
    expect(store.openObjectSourceTabPending(options)).toBe(first);
    expect(store.tabs).toHaveLength(1);
    expect(store.tabs[0]?.sourceLoad).toBeUndefined();
    // 复用路径不经过 ensureConnected,但树上动作的惯例仍是把该连接设为当前连接
    expect(mocks.connectionStore.activeConnectionId).toBe(CONNECTION_ID);

    await settle();
    // 后台重新校验:重开拿到的是最新 DDL(改动前每次打开都会重新取源,
    // 而源码 tab 没有别的刷新入口,所以复用不能省掉这次校验)
    expect(mocks.getObjectSource).toHaveBeenCalledTimes(2);
    expect(store.tabs[0]?.sql).toBe("CREATE OR REPLACE VIEW app.v_orders AS SELECT 2 FROM dual");
    expect(store.tabs[0]?.sourceLoad).toBeUndefined();
  });

  it("never clobbers unsaved edits when revalidating in the background", async () => {
    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 1 FROM dual"));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const options = pendingOptions({ name: "v_orders", objectType: "VIEW" });
    const id = store.openObjectSourceTabPending(options);
    await settle();

    // 用户在源码 tab 里改了内容(未保存)
    store.updateSql(id, "CREATE OR REPLACE VIEW app.v_orders AS SELECT 999 FROM dual");

    mocks.getObjectSource.mockResolvedValueOnce(objectSource("CREATE OR REPLACE VIEW app.v_orders AS SELECT 2 FROM dual"));
    store.openObjectSourceTabPending(options);
    await settle();

    expect(store.tabs[0]?.sql).toContain("SELECT 999");
    expect(store.tabs[0]?.originalSql).not.toBe(store.tabs[0]?.sql);
  });

  it("hands the loaded source to an existing tab that already matches the resolved identity", async () => {
    // 已有一个解析为 FUNCTION 的 tab;本次请求的是 PROCEDURE(树的类型可能是错的),
    // 前置复用检查匹配不上,只能先开 pending,等 fallback 解析出 FUNCTION 后再交接。
    mocks.getObjectSource.mockImplementation(async (_connectionId, _database, _schema, _name, objectType: string) => objectSource(objectType === "FUNCTION" ? "CREATE OR REPLACE FUNCTION app.foo RETURN NUMBER IS BEGIN RETURN 1; END;" : ""));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const existingId = store.openObjectSourceTab({
      connectionId: CONNECTION_ID,
      database: DATABASE,
      title: "Source - foo",
      schema: SCHEMA,
      sql: "CREATE OR REPLACE FUNCTION app.foo RETURN NUMBER IS BEGIN RETURN 0; END;",
      objectSource: { schema: SCHEMA, name: "foo", objectType: "FUNCTION" },
    });

    const pendingId = store.openObjectSourceTabPending(pendingOptions({ name: "foo", objectType: "PROCEDURE" }));
    expect(store.tabs).toHaveLength(2);
    expect(pendingId).not.toBe(existingId);

    await settle();

    // pending 占位交接给既有 tab,不留下同一个对象的第二个 tab
    expect(store.tabs).toHaveLength(1);
    expect(store.tabs[0]?.id).toBe(existingId);
    expect(store.tabs[0]?.sql).toBe("CREATE OR REPLACE FUNCTION app.foo RETURN NUMBER IS BEGIN RETURN 1; END;");
    expect(store.tabs[0]?.sourceLoad).toBeUndefined();
  });

  it("honors backend editability: read-only sources load as a plain source tab", async () => {
    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE SEQUENCE app.seq_users", false));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    store.openObjectSourceTabPending(pendingOptions({ name: "seq_users", objectType: "VIEW" }));
    await settle();

    const tab = store.tabs[0]!;
    expect(tab.sql).toBe("CREATE SEQUENCE app.seq_users");
    expect(tab.sourceView).toBe(true);
    expect(tab.objectSource).toBeUndefined();
    expect(tab.sourceLoad).toBeUndefined();
  });

  it("keeps a routine source tab saveable when opened from the view entry", async () => {
    // 侧栏单击/双击存储过程走的是「查看源码」(initialEditing=false)。该 tab 必须
    // 仍然挂着 objectSource,否则 Ctrl+S 会退化成「保存到 SQL 库」,用户再也改不了
    // 存储过程(v0.6.18 回归)。同一次「查看」也应复用同一个 tab。
    mocks.getObjectSource.mockResolvedValue(objectSource("CREATE OR REPLACE PROCEDURE app.sp_run AS BEGIN NULL; END;"));
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();

    const options = { ...pendingOptions({ name: "sp_run", objectType: "PROCEDURE" as const }), initialEditing: false };
    const id = store.openObjectSourceTabPending(options);
    await settle();

    expect(store.tabs).toHaveLength(1);
    expect(store.tabs[0]?.sql).toBe("CREATE OR REPLACE PROCEDURE app.sp_run AS BEGIN NULL; END;");
    expect(store.tabs[0]?.objectSource).toMatchObject({ schema: SCHEMA, name: "sp_run", objectType: "PROCEDURE" });

    expect(store.openObjectSourceTabPending(options)).toBe(id);
    await settle();
    expect(store.tabs).toHaveLength(1);
  });

  it("keeps OceanBase sequence CREATE source for viewing and uses ALTER only for editing", async () => {
    mocks.connectionStore.dbType = "oceanbase-oracle";
    mocks.getObjectSource.mockResolvedValue(objectSource('CREATE SEQUENCE "APP"."SEQ_USERS" START WITH 10 INCREMENT BY 2'));
    mocks.buildEditableObjectSource.mockResolvedValue('ALTER SEQUENCE "APP"."SEQ_USERS" INCREMENT BY 2');
    const { useQueryStore } = await import("@/stores/queryStore");
    const store = useQueryStore();
    const base = pendingOptions({ name: "SEQ_USERS", objectType: "SEQUENCE" });

    store.openObjectSourceTabPending({ ...base, initialEditing: false });
    await settle();
    expect(store.tabs[0]?.sql).toContain("CREATE SEQUENCE");
    expect(store.tabs[0]?.sql).toContain("START WITH 10");
    expect(store.tabs[0]?.objectSource).toBeUndefined();

    store.openObjectSourceTabPending({ ...base, initialEditing: true });
    await settle();
    expect(store.tabs).toHaveLength(2);
    expect(store.tabs[1]?.sql).toBe('ALTER SEQUENCE "APP"."SEQ_USERS" INCREMENT BY 2');
    expect(store.tabs[1]?.objectSource).toMatchObject({ schema: SCHEMA, name: "SEQ_USERS", objectType: "SEQUENCE" });

    mocks.buildEditableObjectSource.mockResolvedValue('ALTER SEQUENCE "APP"."SEQ_USERS" INCREMENT BY 4');
    const editId = store.tabs[1]!.id;
    expect(store.openObjectSourceTabPending({ ...base, initialEditing: true })).toBe(editId);
    await settle();
    expect(store.tabs).toHaveLength(2);
    expect(store.tabs[1]?.sql).toBe('ALTER SEQUENCE "APP"."SEQ_USERS" INCREMENT BY 4');
  });
});