From 5522842b19d5b177b1cb06ade647a707cf49bce4 Mon Sep 17 00:00:00 2001
From: t8y2 <1156263951@qq.com>
Date: Thu, 25 Jun 2026 00:16:11 +0800
Subject: [PATCH] fix(ci): fix broken tests after external-sql and xlsx changes
---
apps/desktop/src/stores/queryStore.ts | 13 +++++++++++
crates/dbx-core/src/table_export.rs | 23 ++++++++++++++-----
.../app-tests/openTabsPersistence.test.ts | 1 +
packages/app-tests/queryStore.test.ts | 3 +--
4 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index b3b3714e39..262f876dfe 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -536,6 +536,18 @@ export const useQueryStore = defineStore("query", () => {
{ flush: "post" },
);
+ // Immediately flush any pending debounced persist so the on-disk content
+ // reflects the latest in-memory tabs without waiting for the 300ms debounce.
+ // Lets callers (e.g. tests that reload the store) read back persisted state
+ // deterministically instead of racing the debounce timer.
+ function flushPendingPersist() {
+ if (_persistTimer) {
+ clearTimeout(_persistTimer);
+ _persistTimer = null;
+ }
+ saveTabs(tabs.value, activeTabId.value);
+ }
+
function findTabByIdentity(connectionId: string, database: string, title: string, mode: QueryTab["mode"], schema?: string) {
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || ""));
}
@@ -2319,6 +2331,7 @@ export const useQueryStore = defineStore("query", () => {
closeTab,
forceClosePendingTab,
cancelClosePendingTab,
+ flushPendingPersist,
saveAndClosePendingTab,
isTabDirty,
markTabClean,
diff --git a/crates/dbx-core/src/table_export.rs b/crates/dbx-core/src/table_export.rs
index 8002425c3f..da6e41f0c2 100644
--- a/crates/dbx-core/src/table_export.rs
+++ b/crates/dbx-core/src/table_export.rs
@@ -647,6 +647,16 @@ mod tests {
use crate::database_export::{clear_export_cancelled, set_export_cancelled};
use crate::xlsx_export::{build_xlsx_workbook, XlsxWorksheetData};
use serde_json::json;
+ use std::io::Read;
+
+ /// Read and decompress a single entry from an in-memory XLSX (ZIP) buffer.
+ fn read_zip_entry(bytes: &[u8], path: &str) -> String {
+ let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).expect("open xlsx as zip archive");
+ let mut entry = archive.by_name(path).unwrap_or_else(|_| panic!("missing zip entry: {path}"));
+ let mut content = String::new();
+ entry.read_to_string(&mut content).expect("read zip entry");
+ content
+ }
// -----------------------------------------------------------------------
// Helper: check that two CSV strings are equivalent by splitting lines
@@ -766,15 +776,16 @@ mod tests {
],
};
let workbook = build_xlsx_workbook(&data).expect("XLSX build should succeed");
- let text = String::from_utf8_lossy(&workbook);
assert_eq!(workbook[0], 0x50, "Should be a ZIP (PK) archive");
assert_eq!(workbook[1], 0x4b);
- assert!(text.contains("[Content_Types].xml"));
- assert!(text.contains("xl/worksheets/sheet1.xml"));
- assert!(text.contains("name=\"employees\""));
- assert!(text.contains("75000.5"));
- assert!(text.contains("Alice"));
+
+ // Entries are Deflate-compressed; assert on their decompressed contents.
+ let workbook_xml = read_zip_entry(&workbook, "xl/workbook.xml");
+ let sheet = read_zip_entry(&workbook, "xl/worksheets/sheet1.xml");
+ assert!(workbook_xml.contains("name=\"employees\""));
+ assert!(sheet.contains("75000.5"));
+ assert!(sheet.contains("Alice"));
}
// -----------------------------------------------------------------------
diff --git a/packages/app-tests/openTabsPersistence.test.ts b/packages/app-tests/openTabsPersistence.test.ts
index 59af1b0850..e88351f0db 100644
--- a/packages/app-tests/openTabsPersistence.test.ts
+++ b/packages/app-tests/openTabsPersistence.test.ts
@@ -32,6 +32,7 @@ test("serializes unsaved query tabs with editor context", () => {
schema: "public",
sql: "select * from users",
savedSqlId: undefined,
+ externalSqlPath: undefined,
pinned: true,
mode: "query",
objectBrowser: undefined,
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index a575418197..36809f9d40 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -119,8 +119,7 @@ test("external SQL file paths persist with open query tabs", async () => {
const tabId = store.createTab("conn-1", "db", "draft.sql");
store.updateSql(tabId, "select 1;");
store.linkExternalSqlPath(tabId, "/tmp/draft.sql", "draft.sql");
-
- await waitFor(() => !!globalThis.localStorage.getItem("dbx-open-tabs"), 1000);
+ store.flushPendingPersist();
setActivePinia(createPinia());
store = useQueryStore();