fix(plugins): pass schema to result views

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-10-03 23:42:38 +08:00
1 parent ff3c036f79
commit fc28c4a41e
5 files changed
+87 -6

No files matched your search

@@ -1382,13 +1382,19 @@ function openPluginResultView(pluginId: string, contributionId: string, label: s
// bounded snapshot — plugins that need more rows re-run the statement through
// `host.queryData` (host.data:read, with the user's consent).
const cappedRows = result.rows.slice(0, 500);
const connectionId = activeResultConnectionId.value || "";
const database = activeResultDatabase.value || "";
const schema = activeResultSchema.value || "";
queryStore.openPluginWorkbench(pluginId, contributionId, {
title: label,
connectionId: props.activeTab.connectionId || "",
database: props.activeTab.database || "",
connectionId,
database,
context: {
connectionId: props.activeTab.connectionId || "",
database: props.activeTab.database || "",
connectionId,
database,
// The plugin re-runs `sql` through `host.queryData`, whose backend sets
// search_path from this; without it unqualified table names miss.
schema,
sql: resultSqlForGrid(props.activeTab),
result: { columns: result.columns, rows: cappedRows, truncated: result.rows.length > cappedRows.length },
},
@@ -50,6 +50,12 @@ const connection = {
password: "",
};
const targetConnection = {
...connection,
id: "conn-2",
name: "Target MySQL",
};
function result(sourceStatement?: string): QueryResult {
return {
columns: ["id"],
@@ -81,8 +87,9 @@ async function mountContentArea(tab: QueryTab) {
const pinia = createPinia();
setActivePinia(pinia);
const connectionStore = useConnectionStore();
connectionStore.connections = [connection];
connectionStore.connections = [connection, targetConnection];
const queryStore = useQueryStore();
queryStore.tabs = [tab];
const openPluginWorkbench = vi.spyOn(queryStore, "openPluginWorkbench");
const state = reactive({ activeTab: tab });
const host = document.createElement("div");
@@ -180,4 +187,59 @@ describe("ContentArea result-view context", () => {
}),
);
});
it("passes the active tab schema so plugin re-runs resolve unqualified names", async () => {
const openPluginWorkbench = await mountContentArea(
queryTab({
schema: "public",
lastExecutedSql: "SELECT * FROM users",
result: result("SELECT * FROM users"),
}),
);
expect(openPluginWorkbench).toHaveBeenCalledWith(
"com.example.chart",
"result.chart",
expect.objectContaining({
context: expect.objectContaining({ schema: "public" }),
}),
);
});
it("uses the active multi-database result execution scope", async () => {
const activeResult = result("SELECT * FROM users");
const openPluginWorkbench = await mountContentArea(
queryTab({
schema: "source_schema",
result: activeResult,
activeResultRunId: "target-run",
resultRuns: [
{
id: "target-run",
title: "Target run",
sequence: 1,
sql: "SELECT * FROM users",
createdAt: 1,
result: activeResult,
multiDbExecution: {
kind: "multi-db",
batchId: "batch-1",
target: { connectionId: targetConnection.id, database: "target_database", schema: "target_schema" },
status: "success",
},
},
],
}),
);
expect(openPluginWorkbench).toHaveBeenCalledWith(
"com.example.chart",
"result.chart",
expect.objectContaining({
connectionId: targetConnection.id,
database: "target_database",
context: expect.objectContaining({ connectionId: targetConnection.id, database: "target_database", schema: "target_schema" }),
}),
);
});
});