feat(queries): 完成 M04 查询定义与版本激活

交付不可变查询版本、保存即生效与激活(D26),并带控制台列表筛选排序与试跑预览;补 RLS 下 current_version_no 回填迁移。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
unknownandCursor committed 2026-11-18 18:32:24 +08:00
1 parent 8c0335040f
commit 21cc721fcc
97 files changed
+13354 -153

No files matched your search

+39 -2
View File
@@ -197,7 +197,39 @@ async function mockDatasources(page: Page, rows: Row[] = seedRows()): Promise<Mo
}
if (parts.length === 1) {
if (method === "GET") {
return json(200, ok({ items: mock.rows }));
const name = (url.searchParams.get("name") || "").trim().toLowerCase();
const engine = url.searchParams.get("engine") || "";
const enabledParam = url.searchParams.get("enabled");
const page = Number(url.searchParams.get("page") || "1");
const pageSize = Number(url.searchParams.get("page_size") || "20");
const sortBy = url.searchParams.get("sort_by") || "created_at";
const sortOrder = url.searchParams.get("sort_order") || "asc";
let rows = [...mock.rows];
if (name) {
rows = rows.filter((item) => item.name.toLowerCase().includes(name));
}
if (engine) {
rows = rows.filter((item) => item.engine === engine);
}
if (enabledParam === "true") {
rows = rows.filter((item) => item.enabled);
}
if (enabledParam === "false") {
rows = rows.filter((item) => !item.enabled);
}
const dir = sortOrder === "asc" ? 1 : -1;
rows.sort((a, b) => {
const av = (a as Record<string, unknown>)[sortBy];
const bv = (b as Record<string, unknown>)[sortBy];
if (av === bv) return 0;
if (av == null) return 1;
if (bv == null) return -1;
return av < bv ? -dir : dir;
});
const total = rows.length;
const start = Math.max(0, (page - 1) * pageSize);
const items = rows.slice(start, start + pageSize);
return json(200, ok({ items, total, page, page_size: pageSize }));
}
const created = row({ id: "55555555-5555-4555-8555-555555555555", name: "x" });
Object.assign(created, body, { secret_configured: true });
@@ -262,11 +294,13 @@ test.describe("datasources console", () => {
await expect(page.getByTestId("datasource-table")).toBeVisible();
const crumb = page.getByTestId("breadcrumb");
await expect(crumb).toContainText("Watchman");
await expect(crumb).toContainText("预警平台");
await expect(crumb).toContainText("数据源");
await expect(crumb).not.toContainText("新建");
await expect(crumb).not.toContainText("详情");
await expect(page.getByTestId("nav-datasources")).toBeVisible();
await expect(page.getByTestId("side-logo")).toBeVisible();
await expect(page.getByTestId("side-user").getByTestId("shell-welcome")).toBeVisible();
for (const header of ["名称", "引擎", "主机", "端口", "库名", "用户名", "状态", "最近测试", "操作"]) {
await expect(page.locator(".el-table__header").getByText(header, { exact: true })).toBeVisible();
@@ -275,6 +309,9 @@ test.describe("datasources console", () => {
await expect(page.getByTestId("datasource-table")).toContainText("SQL Server");
await expect(page.getByTestId("datasource-table")).toContainText("2026-11-17");
await expect(page.getByTestId("datasource-table")).toContainText("尚未测试");
await expect(page.getByTestId("datasource-pagination")).toBeVisible();
await expect(page.getByTestId("datasource-filter-search")).toBeVisible();
await expect(page.getByTestId("datasource-filter-reset")).toBeVisible();
// 新建 sits above the table, right aligned.
const create = await page.getByTestId("datasource-create").boundingBox();