feat(query): show live statement execution progress
This commit is contained in:
1 parent
1774126f76
commit
ed018dbc77
27 files changed
+974
-85
No files matched your search
@@ -37,4 +37,17 @@ describe("CodeMirror statement gutter marker", () => {
|
||||
expect(marker.querySelectorAll(".cm-statement-execution-badge")).toHaveLength(0);
|
||||
expect(marker.getAttribute("aria-label")).toBe("1 statement failed");
|
||||
});
|
||||
|
||||
it("renders an animated running marker", () => {
|
||||
const marker = createStatementGutterMarkerDom({
|
||||
canExecute: false,
|
||||
executeLabel: "Execute SQL",
|
||||
status: "running",
|
||||
statusLabel: "1 statement running",
|
||||
});
|
||||
|
||||
expect(marker.classList.contains("cm-statement-execution-marker--running")).toBe(true);
|
||||
expect(marker.querySelector(".cm-statement-execution-spinner")).not.toBeNull();
|
||||
expect(marker.getAttribute("aria-label")).toBe("1 statement running");
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,18 @@ describe("QueryEditor execution routing", () => {
|
||||
expect(executeModeBranch).toBeGreaterThan(selectionBranch);
|
||||
});
|
||||
|
||||
it("preserves the source range when executing a current/all candidate without a manual selection", () => {
|
||||
expect(queryEditorSource).toContain("emitExecutionRequest(sqlExecutionSnapshotForRange(currentView, candidate), options.openInNewResultTab)");
|
||||
expect(queryEditorSource).toContain("currentView ? sqlExecutionSnapshotForRange(currentView, candidate) : candidate.sql");
|
||||
expect(queryEditorSource).toContain("selectionFrom: range.from");
|
||||
expect(queryEditorSource).toContain("selectionTo: range.to");
|
||||
});
|
||||
|
||||
it("preserves the source range when executing from the statement gutter", () => {
|
||||
expect(queryEditorSource).toContain("emitExecutionRequest(sqlExecutionSnapshotForRange(currentView, statementRange))");
|
||||
expect(queryEditorSource).not.toContain('emit("execute", statementRange.sql)');
|
||||
});
|
||||
|
||||
it("lets the shortcut skip the picker without affecting other execution entry points", () => {
|
||||
// The picker guard must also honor the shortcut's bypass flag, otherwise Ctrl+Enter would keep popping the dialog.
|
||||
expect(queryEditorSource).toContain("if (options.bypassPicker || !settingsStore.editorSettings.showExecutionTargetPicker");
|
||||
|
||||
+43
-1
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { connectionGroupDisplayName, middleEllipsis, queryResultBaseSql, queryResultExecutionSql, resultSourceRange, statementExecutionMarkers, tabTooltipLines, tabularResultItems } from "@/lib/tabs/tabPresentation";
|
||||
import { sqlTextFingerprint } from "@/lib/sql/sqlTextFingerprint";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
const translations: Record<string, string> = {
|
||||
@@ -224,6 +225,47 @@ describe("query result source ranges", () => {
|
||||
});
|
||||
|
||||
describe("statement execution markers", () => {
|
||||
it("renders a live marker for a single statement", () => {
|
||||
const sql = "SELECT 1";
|
||||
expect(
|
||||
statementExecutionMarkers(sql, undefined, "mysql", sql, "", {
|
||||
executionId: "run-single",
|
||||
submittedSql: sql,
|
||||
editorFingerprint: sqlTextFingerprint(sql),
|
||||
sourceOffset: 0,
|
||||
completed: 0,
|
||||
total: 1,
|
||||
startedAt: 1,
|
||||
items: [{ statementIndex: 0, sql, from: 0, to: sql.length, status: "running" }],
|
||||
}),
|
||||
).toEqual([{ from: 0, status: "running", successCount: 0, errorCount: 0, runningCount: 1 }]);
|
||||
});
|
||||
|
||||
it("renders running and completed markers from live batch state", () => {
|
||||
const sql = "SELECT 1;\nSELECT 2;\nSELECT 3;";
|
||||
const secondFrom = sql.indexOf("SELECT 2");
|
||||
const thirdFrom = sql.indexOf("SELECT 3");
|
||||
expect(
|
||||
statementExecutionMarkers(sql, undefined, "sqlite", sql, "", {
|
||||
executionId: "run-1",
|
||||
submittedSql: sql,
|
||||
editorFingerprint: sqlTextFingerprint(sql),
|
||||
sourceOffset: 0,
|
||||
completed: 1,
|
||||
total: 3,
|
||||
startedAt: 1,
|
||||
items: [
|
||||
{ statementIndex: 0, sql: "SELECT 1", from: 0, to: 8, status: "success" },
|
||||
{ statementIndex: 1, sql: "SELECT 2", from: secondFrom, to: secondFrom + 8, status: "running" },
|
||||
{ statementIndex: 2, sql: "SELECT 3", from: thirdFrom, to: thirdFrom + 8, status: "pending" },
|
||||
],
|
||||
}),
|
||||
).toEqual([
|
||||
{ from: 0, status: "success", successCount: 1, errorCount: 0 },
|
||||
{ from: secondFrom, status: "running", successCount: 0, errorCount: 0, runningCount: 1 },
|
||||
]);
|
||||
});
|
||||
|
||||
it("projects explicit statement indexes to current editor lines", () => {
|
||||
const sql = "SELECT 1;\nSELECT * FROM missing;\nSELECT 3;";
|
||||
const secondFrom = sql.indexOf("SELECT *");
|
||||
@@ -243,7 +285,7 @@ describe("statement execution markers", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits unindexed query-level errors and single-statement executions", () => {
|
||||
it("omits unindexed query-level errors and legacy single-statement results without live state", () => {
|
||||
expect(statementExecutionMarkers("SELECT 1; SELECT 2;", [{ columns: ["Error"], rows: [["pool failed"]], affected_rows: 0, execution_time_ms: 1, execution_error: true }], "mysql", "SELECT 1; SELECT 2;")).toEqual([]);
|
||||
expect(statementExecutionMarkers("SELECT 1", [{ columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1, statement_index: 0, sourceStatement: "SELECT 1", sourceFrom: 0, sourceTo: 8 }], "mysql", "SELECT 1")).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -107,6 +107,43 @@ describe("tab result cache statement execution metadata", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves result-run statement execution state", () => {
|
||||
const encoded = encodeTabResultSnapshot({
|
||||
resultRuns: [
|
||||
{
|
||||
id: "run-1",
|
||||
title: "Run 1",
|
||||
sequence: 1,
|
||||
sql: "SELECT 1; SELECT bad",
|
||||
createdAt: 1,
|
||||
batchSqlExecution: {
|
||||
executionId: "exec-1",
|
||||
submittedSql: "SELECT 1; SELECT bad",
|
||||
editorFingerprint: "20:0123456789abcdef",
|
||||
sourceOffset: 0,
|
||||
completed: 2,
|
||||
total: 2,
|
||||
startedAt: 1,
|
||||
finishedAt: 2,
|
||||
items: [
|
||||
{ statementIndex: 0, sql: "SELECT 1", from: 0, to: 8, status: "success", executionTimeMs: 1 },
|
||||
{ statementIndex: 1, sql: "SELECT bad", from: 10, to: 20, status: "error", error: "failed", executionTimeMs: 1 },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
activeResultRunId: "run-1",
|
||||
cachedAt: 1,
|
||||
});
|
||||
|
||||
expect(decodeTabResultSnapshot(encoded)?.resultRuns?.[0]?.batchSqlExecution).toMatchObject({
|
||||
executionId: "exec-1",
|
||||
completed: 2,
|
||||
total: 2,
|
||||
items: [{ status: "success" }, { status: "error", error: "failed" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("restores multi-result, pagination, local-sort, and editable metadata fixtures", () => {
|
||||
const restored = decodeTabResultSnapshot(encodeTabResultSnapshot(queryResultLifecycleSnapshot()));
|
||||
|
||||
|
||||
Reference in new issue
Block a user