feat(result-tabs): support pinned tabs and batch closing
This commit is contained in:
17 files changed
+883
-57
No files matched your search
@@ -179,6 +179,7 @@ test("serializes query result run metadata without row payloads", () => {
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 100,
|
||||
pinned: true,
|
||||
result: {
|
||||
columns: ["id"],
|
||||
rows: [[1]],
|
||||
@@ -200,6 +201,7 @@ test("serializes query result run metadata without row payloads", () => {
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 100,
|
||||
pinned: true,
|
||||
activeResultIndex: undefined,
|
||||
resultCacheKey: "tab:tab-1:run:run-1",
|
||||
resultEvicted: true,
|
||||
@@ -221,6 +223,7 @@ test("restores query result run metadata as disk-backed runtime state", () => {
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 100,
|
||||
pinned: true,
|
||||
resultCacheKey: "tab:tab-1:run:run-1",
|
||||
resultEvicted: true,
|
||||
},
|
||||
@@ -234,6 +237,7 @@ test("restores query result run metadata as disk-backed runtime state", () => {
|
||||
assert.equal(restored.tabs[0]?.resultRuns?.[0]?.id, "run-1");
|
||||
assert.equal(restored.tabs[0]?.resultRuns?.[0]?.resultCacheState, "disk");
|
||||
assert.equal(restored.tabs[0]?.resultRuns?.[0]?.result, undefined);
|
||||
assert.equal(restored.tabs[0]?.resultRuns?.[0]?.pinned, true);
|
||||
});
|
||||
|
||||
test("ignores legacy table data result cache handles on restore", () => {
|
||||
|
||||
+16
@@ -80,6 +80,22 @@ test("ContentArea exposes retained result runs as switchable tabs or a compact l
|
||||
assert.equal((contentArea.match(/<QueryResultToolbarActions\b/g) ?? []).length, 2);
|
||||
});
|
||||
|
||||
test("appending a result run preserves the tab-strip scroll position", () => {
|
||||
const contentArea = source(contentAreaPath);
|
||||
const resultRunWatcherStart = contentArea.indexOf("function resultRunIdsWereAppended");
|
||||
const resultRunWatcherEnd = contentArea.indexOf("const summaryItems", resultRunWatcherStart);
|
||||
const resultRunWatcher = contentArea.slice(resultRunWatcherStart, resultRunWatcherEnd);
|
||||
|
||||
assert.ok(resultRunWatcherStart >= 0);
|
||||
assert.match(resultRunWatcher, /current\.length > previous\.length/);
|
||||
assert.match(resultRunWatcher, /activeRunId: props\.activeTab\.activeResultRunId/);
|
||||
assert.match(resultRunWatcher, /activeRunChanged && !resultRunIdsWereAppended\(previous\.runIds, current\.runIds\)/);
|
||||
assert.match(resultRunWatcher, /updateResultTabsAfterRender/);
|
||||
assert.match(resultRunWatcher, /revealActiveResultRunAfterRender/);
|
||||
assert.match(contentArea, /function focusResultRunByIndex[\s\S]*scrollIntoView/);
|
||||
assert.match(contentArea, /async function removeResultRun[\s\S]*scrollIntoView/);
|
||||
});
|
||||
|
||||
test("the close-tab shortcut clears query results before closing the tab", () => {
|
||||
const app = source(appPath);
|
||||
const closeShortcutStart = app.indexOf("if (isCloseTabShortcut(e, shortcuts))");
|
||||
|
||||
+543
@@ -1418,6 +1418,239 @@ test("removing the active result run selects an adjacent run", async () => {
|
||||
assert.deepEqual(tab.result?.columns, ["one"]);
|
||||
});
|
||||
|
||||
test("pins result runs independently and can unpin all runs", () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1 },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, pinned: true },
|
||||
];
|
||||
|
||||
assert.equal(store.toggleResultRunPinned(tabId, "run-1"), true);
|
||||
assert.equal(tab.resultRuns?.[0]?.pinned, true);
|
||||
assert.equal(store.unpinAllResultRuns(tabId), 2);
|
||||
assert.deepEqual(
|
||||
tab.resultRuns?.map((run) => run.pinned),
|
||||
[undefined, undefined],
|
||||
);
|
||||
});
|
||||
|
||||
test("changing the pin state preserves an evicted result cache", () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
|
||||
tab.resultRuns = [
|
||||
{
|
||||
id: "run-1",
|
||||
title: "Run 1",
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 1,
|
||||
resultCacheKey: "tab:tab-1:run:run-1",
|
||||
resultCacheState: "disk",
|
||||
resultEvicted: true,
|
||||
},
|
||||
];
|
||||
|
||||
assert.equal(store.toggleResultRunPinned(tabId, "run-1"), true);
|
||||
assert.equal(tab.resultRuns?.[0]?.pinned, true);
|
||||
assert.equal(tab.resultRuns?.[0]?.resultCacheKey, "tab:tab-1:run:run-1");
|
||||
assert.equal(tab.resultRuns?.[0]?.resultCacheState, "disk");
|
||||
assert.equal(tab.resultRuns?.[0]?.resultEvicted, true);
|
||||
assert.equal(store.toggleResultRunPinned(tabId, "run-1"), false);
|
||||
assert.equal(tab.resultRuns?.[0]?.pinned, undefined);
|
||||
assert.equal(tab.resultRuns?.[0]?.resultCacheKey, "tab:tab-1:run:run-1");
|
||||
assert.equal(tab.resultRuns?.[0]?.resultCacheState, "disk");
|
||||
assert.equal(tab.resultRuns?.[0]?.resultEvicted, true);
|
||||
});
|
||||
|
||||
test("result run pin and close state persist across a restart", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
try {
|
||||
setActivePinia(createPinia());
|
||||
let store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, result: { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, result: { columns: ["two"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
await store.flushPendingPersist();
|
||||
|
||||
assert.equal(store.toggleResultRunPinned(tabId, "run-1"), true);
|
||||
await waitFor(() => {
|
||||
const saved = JSON.parse(localStorage.getItem("dbx-app-state:open_tabs") ?? "null");
|
||||
return saved?.tabs?.[0]?.resultRuns?.[0]?.pinned === true;
|
||||
});
|
||||
assert.equal(await store.closeOtherResultRuns(tabId, "run-1"), true);
|
||||
await waitFor(() => {
|
||||
const saved = JSON.parse(localStorage.getItem("dbx-app-state:open_tabs") ?? "null");
|
||||
return saved?.tabs?.[0]?.resultRuns?.length === 1;
|
||||
});
|
||||
|
||||
setActivePinia(createPinia());
|
||||
store = useQueryStore();
|
||||
await store.initOpenTabs();
|
||||
const restored = store.tabs.find((item) => item.id === tabId);
|
||||
assert.deepEqual(restored?.resultRuns?.map((run) => run.id), ["run-1"]);
|
||||
assert.equal(restored?.resultRuns?.[0]?.pinned, true);
|
||||
} finally {
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("closing other result runs preserves the selected run", async () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, result: { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, pinned: true, result: { columns: ["two"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-3", title: "Run 3", sequence: 3, sql: "select 3", createdAt: 3, result: { columns: ["three"], rows: [[3]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
|
||||
assert.equal(await store.closeOtherResultRuns(tabId, "run-2"), true);
|
||||
assert.deepEqual(
|
||||
tab.resultRuns?.map((run) => run.id),
|
||||
["run-2"],
|
||||
);
|
||||
assert.equal(tab.activeResultRunId, "run-2");
|
||||
assert.deepEqual(tab.result?.rows, [[2]]);
|
||||
});
|
||||
|
||||
test("bulk result-run close leaves all runs untouched when the selected run is unavailable", async () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, result: { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, resultCacheKey: `missing-result-run-${Date.now()}`, resultCacheState: "disk", resultEvicted: true },
|
||||
{ id: "run-3", title: "Run 3", sequence: 3, sql: "select 3", createdAt: 3, result: { columns: ["three"], rows: [[3]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
|
||||
assert.equal(await store.closeOtherResultRuns(tabId, "run-2"), false);
|
||||
assert.equal(await store.closeResultRunsToLeft(tabId, "run-2"), false);
|
||||
assert.equal(await store.closeResultRunsToRight(tabId, "run-2"), false);
|
||||
assert.deepEqual(tab.resultRuns?.map((run) => run.id), ["run-1", "run-2", "run-3"]);
|
||||
assert.equal(tab.activeResultRunId, "run-1");
|
||||
assert.deepEqual(tab.result?.rows, [[1]]);
|
||||
});
|
||||
|
||||
test("bulk result-run close does not rewrite a deleted session-backed snapshot", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let releaseSessionClose: (() => void) | undefined;
|
||||
const sessionCloseGate = new Promise<void>((resolve) => {
|
||||
releaseSessionClose = resolve;
|
||||
});
|
||||
let sessionCloseRequests = 0;
|
||||
let cacheWrites = 0;
|
||||
const deletedCacheKeys: string[] = [];
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/close-session") {
|
||||
sessionCloseRequests += 1;
|
||||
await sessionCloseGate;
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
if (url === "/api/tab-runtime-cache" && init?.method === "POST") {
|
||||
cacheWrites += 1;
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
if (url.startsWith("/api/tab-runtime-cache?")) {
|
||||
if (init?.method === "DELETE") {
|
||||
deletedCacheKeys.push(new URL(url, "http://localhost").searchParams.get("key") ?? "");
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
return new Response("null", { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
const removedRun = {
|
||||
id: "run-1",
|
||||
title: "Run 1",
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 1,
|
||||
result: { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 },
|
||||
resultSessionId: "session-1",
|
||||
resultCacheKey: "tab:tab-1:run:run-1",
|
||||
};
|
||||
tab.resultRuns = [
|
||||
removedRun,
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, result: { columns: ["two"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
];
|
||||
tab.activeResultRunId = removedRun.id;
|
||||
tab.result = removedRun.result;
|
||||
tab.resultSessionId = removedRun.resultSessionId;
|
||||
tab.resultCacheKey = removedRun.resultCacheKey;
|
||||
|
||||
assert.equal(await store.closeOtherResultRuns(tabId, "run-2"), true);
|
||||
await waitFor(() => sessionCloseRequests === 1);
|
||||
assert.deepEqual(deletedCacheKeys, ["tab:tab-1:run:run-1"]);
|
||||
|
||||
releaseSessionClose?.();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
assert.equal(cacheWrites, 0);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("closes only result runs to the requested side", async () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("conn-1", "db");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, result: { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, result: { columns: ["two"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-3", title: "Run 3", sequence: 3, sql: "select 3", createdAt: 3, result: { columns: ["three"], rows: [[3]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-4", title: "Run 4", sequence: 4, sql: "select 4", createdAt: 4, result: { columns: ["four"], rows: [[4]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
|
||||
assert.equal(await store.closeResultRunsToLeft(tabId, "run-3"), true);
|
||||
assert.deepEqual(
|
||||
tab.resultRuns?.map((run) => run.id),
|
||||
["run-3", "run-4"],
|
||||
);
|
||||
assert.equal(await store.closeResultRunsToRight(tabId, "run-3"), true);
|
||||
assert.deepEqual(
|
||||
tab.resultRuns?.map((run) => run.id),
|
||||
["run-3"],
|
||||
);
|
||||
});
|
||||
|
||||
test("closing an ordinary query result preserves the query tab", async () => {
|
||||
setActivePinia(createPinia());
|
||||
const store = useQueryStore();
|
||||
@@ -1661,6 +1894,316 @@ test("completed query executions append result runs and select the latest run",
|
||||
}
|
||||
});
|
||||
|
||||
test("auto-saved result stays visible until the next run is ready", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let executeCount = 0;
|
||||
let resolveSecondExecution: ((response: Response) => void) | undefined;
|
||||
let secondExecutionStarted: (() => void) | undefined;
|
||||
const secondExecutionStartedPromise = new Promise<void>((resolve) => {
|
||||
secondExecutionStarted = resolve;
|
||||
});
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/prepare-pagination-plan") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/execute-multi") {
|
||||
executeCount++;
|
||||
if (executeCount === 2) {
|
||||
secondExecutionStarted?.();
|
||||
return await new Promise<Response>((resolve) => {
|
||||
resolveSecondExecution = resolve;
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify([{ columns: ["run_1"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 }]), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/analyze-editability") {
|
||||
return new Response(JSON.stringify({ editable: false, reason: "complex-source" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db", "Query");
|
||||
store.toggleResultAutoSave(tabId);
|
||||
await store.executeTabSql(tabId, "select 1");
|
||||
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab?.resultRuns?.[0]);
|
||||
const firstRunId = tab.resultRuns[0].id;
|
||||
const execution = store.executeTabSql(tabId, "select 2");
|
||||
await secondExecutionStartedPromise;
|
||||
|
||||
assert.equal(tab.activeResultRunId, firstRunId);
|
||||
assert.equal(tab.resultRuns?.length, 1);
|
||||
assert.deepEqual(tab.result?.columns, ["run_1"]);
|
||||
assert.deepEqual(tab.resultRuns?.[0]?.result?.rows, [[1]]);
|
||||
|
||||
resolveSecondExecution?.(new Response(JSON.stringify([{ columns: ["run_2"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 }]), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}));
|
||||
await execution;
|
||||
|
||||
assert.equal(tab.resultRuns?.length, 2);
|
||||
assert.deepEqual(tab.resultRuns?.[0]?.result?.columns, ["run_1"]);
|
||||
assert.deepEqual(tab.result?.columns, ["run_2"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("canceling an auto-saved execution restores the displayed run", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let executeCount = 0;
|
||||
let rejectSecondExecution: ((error: Error) => void) | undefined;
|
||||
let secondExecutionStarted: (() => void) | undefined;
|
||||
const secondExecutionStartedPromise = new Promise<void>((resolve) => {
|
||||
secondExecutionStarted = resolve;
|
||||
});
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/prepare-pagination-plan") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/execute-multi") {
|
||||
executeCount++;
|
||||
if (executeCount === 2) {
|
||||
secondExecutionStarted?.();
|
||||
return await new Promise<Response>((_resolve, reject) => {
|
||||
rejectSecondExecution = reject;
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify([{ columns: ["run_1"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 }]), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/cancel") {
|
||||
rejectSecondExecution?.(new Error("Query canceled"));
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
if (url === "/api/query/analyze-editability") {
|
||||
return new Response(JSON.stringify({ editable: false, reason: "complex-source" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db", "Query");
|
||||
store.toggleResultAutoSave(tabId);
|
||||
await store.executeTabSql(tabId, "select 1");
|
||||
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab?.resultRuns?.[0]);
|
||||
const firstRunId = tab.resultRuns[0].id;
|
||||
const execution = store.executeTabSql(tabId, "select 2");
|
||||
await secondExecutionStartedPromise;
|
||||
assert.equal(await store.cancelTabExecution(tabId), true);
|
||||
await execution;
|
||||
|
||||
assert.equal(tab.activeResultRunId, firstRunId);
|
||||
assert.equal(tab.resultRuns?.length, 1);
|
||||
assert.deepEqual(tab.result?.columns, ["run_1"]);
|
||||
assert.deepEqual(tab.resultRuns?.[0]?.result?.rows, [[1]]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("a failed auto-saved execution keeps the prior run and adds an error run", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let executeCount = 0;
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/prepare-pagination-plan") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/execute-multi") {
|
||||
executeCount++;
|
||||
if (executeCount === 2) return new Response("backend exploded", { status: 500 });
|
||||
return new Response(JSON.stringify([{ columns: ["run_1"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 }]), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/analyze-editability") {
|
||||
return new Response(JSON.stringify({ editable: false, reason: "complex-source" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db", "Query");
|
||||
store.toggleResultAutoSave(tabId);
|
||||
await store.executeTabSql(tabId, "select 1");
|
||||
await store.executeTabSql(tabId, "select broken");
|
||||
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.equal(tab?.resultRuns?.length, 2);
|
||||
assert.deepEqual(tab?.resultRuns?.[0]?.result?.columns, ["run_1"]);
|
||||
assert.deepEqual(tab?.result?.columns, ["Error"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("an unavailable reusable result run does not overwrite the pinned active result", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/prepare-pagination-plan") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/execute-multi") {
|
||||
return new Response(JSON.stringify([{ columns: ["fresh"], rows: [[3]], affected_rows: 0, execution_time_ms: 1 }]), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/analyze-editability") {
|
||||
return new Response(JSON.stringify({ editable: false, reason: "complex-source" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url.startsWith("/api/tab-runtime-cache?")) {
|
||||
return new Response("null", { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
if (url === "/api/tab-runtime-cache" && init?.method === "POST") {
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db", "Query");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, pinned: true, result: { columns: ["pinned"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, resultCacheKey: "missing-result-run", resultCacheState: "disk", resultEvicted: true },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
|
||||
await store.executeTabSql(tabId, "select 3");
|
||||
|
||||
assert.equal(tab.resultRuns?.length, 3);
|
||||
assert.deepEqual(tab.resultRuns?.[0]?.result?.rows, [[1]]);
|
||||
assert.notEqual(tab.activeResultRunId, "run-1");
|
||||
assert.deepEqual(tab.result?.columns, ["fresh"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("a failed execution keeps the pinned result and captures its error separately", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
|
||||
connectionStore.addEphemeralConnection(conn("conn-1"));
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/query/prepare-pagination-plan") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
if (url === "/api/query/execute-multi") {
|
||||
return new Response("backend exploded", { status: 500 });
|
||||
}
|
||||
if (url.startsWith("/api/tab-runtime-cache?")) {
|
||||
return new Response("null", { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
if (url === "/api/tab-runtime-cache" && init?.method === "POST") {
|
||||
return new Response(JSON.stringify(true), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("conn-1", "db", "Query");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.ok(tab);
|
||||
tab.resultRuns = [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, sql: "select 1", createdAt: 1, pinned: true, result: { columns: ["pinned"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, sql: "select 2", createdAt: 2, resultCacheKey: "missing-result-run", resultCacheState: "disk", resultEvicted: true },
|
||||
];
|
||||
await store.setActiveResultRun(tabId, "run-1");
|
||||
|
||||
await store.executeTabSql(tabId, "select broken");
|
||||
|
||||
assert.equal(tab.resultRuns?.length, 3);
|
||||
assert.deepEqual(tab.resultRuns?.[0]?.result?.rows, [[1]]);
|
||||
assert.notEqual(tab.activeResultRunId, "run-1");
|
||||
assert.deepEqual(tab.result?.columns, ["Error"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("kept result runs evict inactive payloads without losing switch or archive data", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
|
||||
+3
-2
@@ -324,6 +324,7 @@ test("result run items expose ordered labels and active state", () => {
|
||||
sequence: 1,
|
||||
sql: "select 1",
|
||||
createdAt: 10,
|
||||
pinned: true,
|
||||
result: result(["one"]),
|
||||
},
|
||||
{
|
||||
@@ -338,8 +339,8 @@ test("result run items expose ordered labels and active state", () => {
|
||||
});
|
||||
|
||||
assert.deepEqual(resultRunItems(tab), [
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, active: false },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, active: true },
|
||||
{ id: "run-1", title: "Run 1", sequence: 1, active: false, pinned: true },
|
||||
{ id: "run-2", title: "Run 2", sequence: 2, active: true, pinned: false },
|
||||
]);
|
||||
assert.equal(activeResultRun(tab)?.id, "run-2");
|
||||
assert.deepEqual(
|
||||
|
||||
Reference in new issue
Block a user