feat(plugins): add AI tools and consent-gated data access

This commit is contained in:
t8y2 committed 2026-09-25 01:56:26 +08:00
1 parent 1bc6f70cd8
commit 26a015cd86
71 files changed
+4613 -129

No files matched your search

+19
View File
@@ -217,3 +217,22 @@ describe("AI schema selector visibility", () => {
expect(resolveAiDatabaseTarget(queryTab("app", "public"), postgres)).toEqual({ database: "app", schema: "public" });
});
});
describe("Plugin AI context", () => {
beforeEach(() => vi.clearAllMocks());
it.each([false, true])("skips database metadata even with stale table context: %s", async (withTable) => {
const connection: ConnectionConfig = { ...postgresConnection(), db_type: "plugin", plugin_id: "sample.plugin" };
const tab = { ...queryTab("stale-db", "public"), connectionId: connection.id, tableMeta: withTable ? { schema: "public", tableName: "stale_table", columns: [] } : undefined };
const context = await buildAiContext(tab, connection, { mentionedTables: [{ schema: "public", table: "stale_mention" }], sqlFiles: [{ name: "notes.sql", content: "SELECT 1" }] });
expect(context.databaseType).toBe("plugin");
expect(context.connectionName).toBe(connection.name);
expect(context.tables).toEqual([]);
expect(context.truncated).toBe(false);
expect(context.sqlFiles).toEqual([{ name: "notes.sql", content: "SELECT 1" }]);
expect(apiMock.listTables).not.toHaveBeenCalled();
expect(apiMock.getColumns).not.toHaveBeenCalled();
expect(apiMock.listIndexes).not.toHaveBeenCalled();
expect(apiMock.listForeignKeys).not.toHaveBeenCalled();
});
});