feat: complete hermes page ai runtime bff
This commit is contained in:
@@ -18,6 +18,7 @@ async function main() {
|
||||
const sessionId = `mnote_smoke_${suffix}`;
|
||||
const runId = `run_smoke_${suffix}`;
|
||||
let sessionDetailHits = 0;
|
||||
let allowSessionRestore = false;
|
||||
const captured = [];
|
||||
const createdIds = [];
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
@@ -42,9 +43,10 @@ async function main() {
|
||||
}),
|
||||
});
|
||||
});
|
||||
await page.route(`**/api/hermes/client/sessions/${sessionId}`, async (route) => {
|
||||
await page.route(`**/api/hermes/client/sessions/${sessionId}/resume`, async (route) => {
|
||||
sessionDetailHits += 1;
|
||||
captured.push({ kind: "session-detail", method: route.request().method(), body: "" });
|
||||
assert.equal(route.request().method(), "POST", "刷新恢复必须调用 runtime resume 接口");
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
@@ -54,11 +56,22 @@ async function main() {
|
||||
traceId: "trace_restore",
|
||||
session: {
|
||||
sessionId,
|
||||
messages: [
|
||||
{ role: "user", content: `请总结 ${title}` },
|
||||
{ role: "tool", content: "mnote.page.get" },
|
||||
{ role: "assistant", content: "Smoke restored from Hermes session" },
|
||||
],
|
||||
messages: allowSessionRestore
|
||||
? [
|
||||
{ role: "user", content: `请总结 ${title}` },
|
||||
{ role: "tool", content: "mnote.page.get" },
|
||||
{ role: "assistant", content: "Smoke restored from Hermes session" },
|
||||
]
|
||||
: [],
|
||||
},
|
||||
runtime: {
|
||||
sessionId,
|
||||
runId,
|
||||
status: "completed",
|
||||
profile: "default",
|
||||
documentId: "doc_smoke",
|
||||
traceId: "trace_restore",
|
||||
lastToolName: "mnote.page.get",
|
||||
},
|
||||
}),
|
||||
});
|
||||
@@ -83,8 +96,10 @@ async function main() {
|
||||
status: 200,
|
||||
headers: { "content-type": "text/event-stream; charset=utf-8" },
|
||||
body:
|
||||
`data: ${JSON.stringify({ event: "tool.started", run_id: runId, session_id: sessionId, name: "mnote.page.get" })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "tool.completed", run_id: runId, session_id: sessionId, name: "mnote.page.get" })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "tool.started", run_id: runId, session_id: sessionId, toolCallId: "call_smoke_page_get", name: "mnote.page.get", args: { includeBody: false } })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "tool.completed", run_id: runId, session_id: sessionId, toolCallId: "call_smoke_page_get", name: "mnote.page.get", summary: "读取当前页面", auditId: "audit_smoke_page_get" })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "tool.started", run_id: runId, session_id: sessionId, toolCallId: "call_smoke_page_save", name: "mnote.page.save", args: { dryRun: true } })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "tool.failed", run_id: runId, session_id: sessionId, toolCallId: "call_smoke_page_save", name: "mnote.page.save", code: "permission_denied", error: "写入被拒绝", auditId: "audit_smoke_page_save" })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "message.delta", run_id: runId, session_id: sessionId, delta: "Smoke " })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "message.delta", run_id: runId, session_id: sessionId, delta: "response" })}\n\n` +
|
||||
`data: ${JSON.stringify({ event: "run.completed", run_id: runId, session_id: sessionId, output: "Smoke response" })}\n\n`,
|
||||
@@ -118,6 +133,22 @@ async function main() {
|
||||
null,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
const toolCards = await page.$$eval("[data-page-ai-tool-card]", (cards) =>
|
||||
cards.map((card) => ({
|
||||
id: card.getAttribute("data-page-ai-tool-call-id"),
|
||||
status: card.getAttribute("data-page-ai-tool-status"),
|
||||
text: card.textContent || "",
|
||||
})),
|
||||
);
|
||||
assert.equal(toolCards.length, 2, `应渲染 2 张工具卡:${JSON.stringify(toolCards)}`);
|
||||
assert(
|
||||
toolCards.some((card) => card.status === "completed" && card.text.includes("call_smoke_page_get")),
|
||||
`缺少 completed 工具卡:${JSON.stringify(toolCards)}`,
|
||||
);
|
||||
assert(
|
||||
toolCards.some((card) => card.status === "failed" && card.text.includes("permission_denied")),
|
||||
`缺少 failed 工具卡:${JSON.stringify(toolCards)}`,
|
||||
);
|
||||
|
||||
const sessionRequest = captured.find((entry) => entry.kind === "session");
|
||||
const runRequest = captured.find((entry) => entry.kind === "run");
|
||||
@@ -130,6 +161,7 @@ async function main() {
|
||||
assert.equal(runBody.documentId, target.documentId, "run 请求必须携带 documentId");
|
||||
assert(runBody.pageContext, "run 请求必须携带 pageContext");
|
||||
|
||||
allowSessionRestore = true;
|
||||
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
await page.getByTestId("wolai-floating-ai").click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForFunction(
|
||||
|
||||
Reference in New Issue
Block a user