feat: add MCP research access and browser key management

This commit is contained in:
yuxuanhui
2026-09-09 16:18:27 +08:00
parent 4debca7dbd
commit 45238280e3
47 changed files with 2642 additions and 44 deletions
+86 -1
View File
@@ -28,7 +28,9 @@ test("draft, immutable preview, mixed-result persistence and responsive workspac
await page.getByRole("button", { name: "新建回测" }).click();
await page.getByLabel("运行名称", { exact: true }).fill("浏览器回测验收");
await page.getByRole("textbox", { name: "Region", exact: true }).fill("USA");
await page.getByRole("textbox", { name: "Universe", exact: true }).fill("TOP3000");
await page
.getByRole("textbox", { name: "Universe", exact: true })
.fill("TOP3000");
await page.getByLabel("回测候选").fill("rank(close)\n-rank(volume)");
await page.getByRole("button", { name: "保存草稿", exact: true }).click();
await expect(page.getByText("草稿已保存", { exact: true })).toBeVisible();
@@ -103,3 +105,86 @@ test("AI prepares one fixed preview, confirms once, and shows live run independe
await chat.getByRole("button", { name: "打开回测详情", exact: true }).click();
await expect(page.getByText("1 / 1 已保存", { exact: true })).toBeVisible();
});
test("MCP direct batch appears through its run link and source filter", async ({
page,
}) => {
await login(page);
const token = (
await (
await page.request.post("/api/v1/test/mcp-token", { headers })
).json()
).token;
const response = await page.request.post("/api/v1/mcp/", {
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json, text/event-stream",
},
data: {
jsonrpc: "2.0",
id: "browser-batch",
method: "tools/call",
params: {
name: "submit_backtests",
arguments: {
name: "MCP 浏览器留痕",
idempotency_key: "browser-mcp",
duplicate_policy: "rerun",
candidates: [
{
client_item_id: "browser-1",
expression: "rank(close) + 987",
settings: {
instrumentType: "EQUITY",
region: "USA",
universe: "TOP3000",
delay: 1,
decay: 0,
neutralization: "INDUSTRY",
truncation: 0.08,
pasteurization: "ON",
unitHandling: "VERIFY",
nanHandling: "OFF",
language: "FASTEXPR",
visualization: false,
maxTrade: "OFF",
maxPosition: "OFF",
},
},
],
source: {
reference: "browser-conversation",
hypothesis: "验证直接回测留痕",
},
},
},
},
});
expect(response.ok()).toBeTruthy();
const result = (await response.json()).result;
expect(result.isError).toBeFalsy();
const run = result.structuredContent;
await page.goto(run.web_url);
await expect(page.getByText("1 / 1 已保存", { exact: true })).toBeVisible({
timeout: 20000,
});
await expect(
page.getByText("研究来源:MCP 研究", { exact: true }),
).toBeVisible();
await expect(
page.getByText("来源引用:browser-conversation", { exact: true }),
).toBeVisible();
await page.reload();
await expect(page.getByText("1 / 1 已保存", { exact: true })).toBeVisible();
await page.keyboard.press("Escape");
await page
.getByRole("dialog")
.getByRole("heading")
.getByRole("button")
.click();
await page.getByText("全部研究来源", { exact: true }).click();
await page.getByRole("option", { name: /MCP 研究/ }).click();
await expect(
page.getByRole("button", { name: "MCP 浏览器留痕", exact: true }),
).toBeVisible();
});
+60
View File
@@ -0,0 +1,60 @@
import { expect, test } from "@playwright/test";
test("MCP Key menu creates, hides secrets on navigation, and revokes", async ({
page,
}) => {
await page.goto("/#mcp-keys");
await page.getByLabel("密码", { exact: true }).fill("browser-test-password");
await page.getByRole("button", { name: "进入工作空间" }).click();
await expect(
page.getByRole("heading", { name: "MCP Key", exact: true }),
).toBeVisible();
const headers = { "X-WQ-Request": "1" };
await page.request.put("/api/v1/account/credentials", {
headers,
data: { email: "test@example.com", password: "synthetic-password" },
});
await page.request.post("/api/v1/account/connect", { headers });
await expect
.poll(
async () =>
(await (await page.request.get("/api/v1/account")).json())
.connection_status,
)
.toBe("connected");
await page.getByRole("button", { name: "刷新列表", exact: true }).click();
await page.getByLabel("Key 名称").fill("Browser test reader");
await page.getByRole("button", { name: "创建 Key", exact: true }).click();
await expect(page.getByLabel("新 Key 明文")).toBeVisible();
const secret = await page.getByLabel("新 Key 明文").inputValue();
expect(secret).toMatch(/^wqmcp_/);
const listed = await (await page.request.get("/api/v1/mcp-tokens")).json();
expect(JSON.stringify(listed)).not.toContain(secret);
const item = listed.items.find(
(row: { name: string }) => row.name === "Browser test reader",
);
expect(item.scopes).toEqual(["research:read"]);
await page.screenshot({
path: "test-results/mcp-key-page.png",
fullPage: true,
mask: [page.getByLabel("新 Key 明文")],
});
await page
.getByRole("navigation", { name: "主导航", exact: true })
.getByRole("button", { name: "数据目录", exact: true })
.click();
await page
.getByRole("navigation", { name: "主导航", exact: true })
.getByRole("button", { name: "MCP Key", exact: true })
.click();
await expect(page.getByLabel("新 Key 明文")).toHaveCount(0);
const row = page.getByRole("row").filter({ hasText: "Browser test reader" });
await row.getByRole("button", { name: "撤销", exact: true }).click();
await row.getByRole("button", { name: "确认撤销", exact: true }).click();
await expect(row).toContainText("已撤销");
await page.reload();
await expect(
page.getByRole("heading", { name: "MCP Key", exact: true }),
).toBeVisible();
await expect(page.getByLabel("新 Key 明文")).toHaveCount(0);
});