chore: checkpoint pi lab rust integration work
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { chromium } = require("playwright");
|
||||
const {
|
||||
setupWorkspaceAccess,
|
||||
seedAiPolicy,
|
||||
} = require("./lib/control-plane-dev-seed");
|
||||
|
||||
const BASE = process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000";
|
||||
const STAMP = Date.now();
|
||||
const OUT = process.env.MNOTE_PI_MODEL_CAPABILITY_OUT
|
||||
|| path.join(os.tmpdir(), `mnote-pi-model-capability-${STAMP}`);
|
||||
const TIMEOUT = Number.parseInt(process.env.UI_TIMEOUT_MS || "240000", 10);
|
||||
const ACTOR_ID = process.env.MNOTE_E2E_ACTOR_ID || "mnote-e2e";
|
||||
const WORKSPACE_ID = `local-ws:${ACTOR_ID}:pi-model-capability`;
|
||||
const ROOT_PATH = path.join(OUT, "workspace");
|
||||
const ROOT_URI = `file://${ROOT_PATH}`;
|
||||
const PAGE_PATH = "model-capability.md";
|
||||
const SUPPORTED_MODEL_ID = process.env.MNOTE_PI_MODEL_CAPABILITY_SUPPORTED || "gpt-5.4-mini";
|
||||
const UNSUPPORTED_MODEL_ID = process.env.MNOTE_PI_MODEL_CAPABILITY_UNSUPPORTED || "missing-tool-capability-smoke";
|
||||
const CHROMIUM_EXECUTABLE = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE
|
||||
|| (fs.existsSync("/usr/bin/chromium-browser") ? "/usr/bin/chromium-browser" : "")
|
||||
|| (fs.existsSync("/usr/bin/chromium") ? "/usr/bin/chromium" : "")
|
||||
|| (fs.existsSync("/usr/bin/google-chrome") ? "/usr/bin/google-chrome" : "");
|
||||
|
||||
async function quickLogin(page) {
|
||||
await page.goto(`${BASE}/auth`, { waitUntil: "commit", timeout: TIMEOUT });
|
||||
const button = page.getByRole("button", { name: "测试账号快速登录" });
|
||||
await button.waitFor({ state: "visible", timeout: TIMEOUT });
|
||||
await Promise.all([
|
||||
page.waitForURL((url) => !url.toString().includes("/auth"), { timeout: TIMEOUT }).catch(() => null),
|
||||
button.click(),
|
||||
]);
|
||||
}
|
||||
|
||||
async function fetchJson(page, url, options = {}) {
|
||||
const response = await page.request.fetch(`${BASE}${url}`, {
|
||||
...options,
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
"content-type": "application/json",
|
||||
...(options.headers || {}),
|
||||
},
|
||||
timeout: options.timeout || TIMEOUT,
|
||||
});
|
||||
const text = await response.text();
|
||||
let body = {};
|
||||
try {
|
||||
body = text ? JSON.parse(text) : {};
|
||||
} catch {
|
||||
body = { raw: text };
|
||||
}
|
||||
return { response, body, text };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
fs.mkdirSync(ROOT_PATH, { recursive: true });
|
||||
fs.writeFileSync(path.join(ROOT_PATH, PAGE_PATH), "# Pi model capability smoke\n", "utf8");
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: process.env.MNOTE_PI_MODEL_CAPABILITY_HEADED !== "1",
|
||||
executablePath: CHROMIUM_EXECUTABLE || undefined,
|
||||
});
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
const result = {
|
||||
ok: false,
|
||||
base: BASE,
|
||||
outputDir: OUT,
|
||||
checks: {},
|
||||
};
|
||||
|
||||
try {
|
||||
await quickLogin(page);
|
||||
await setupWorkspaceAccess(page.request, BASE, {
|
||||
actorId: ACTOR_ID,
|
||||
email: "mnote.e2e@example.com",
|
||||
username: ACTOR_ID,
|
||||
displayName: ACTOR_ID,
|
||||
role: "admin",
|
||||
workspaceId: WORKSPACE_ID,
|
||||
workspaceName: "Pi model capability smoke",
|
||||
rootPath: ROOT_PATH,
|
||||
rootUri: ROOT_URI,
|
||||
permission: "write",
|
||||
capabilities: ["ai", "read", "write"],
|
||||
timeoutMs: TIMEOUT,
|
||||
});
|
||||
await seedAiPolicy(page.request, BASE, {
|
||||
id: `pi-model-capability-${ACTOR_ID}-${WORKSPACE_ID}`,
|
||||
userId: ACTOR_ID,
|
||||
workspaceId: WORKSPACE_ID,
|
||||
allowedRootsJson: [{ rootUri: ROOT_URI, rootPath: ROOT_PATH, permission: "write" }],
|
||||
modelPolicyJson: {
|
||||
defaultModel: `omniroute/${SUPPORTED_MODEL_ID}`,
|
||||
allowedModels: [
|
||||
`omniroute/${SUPPORTED_MODEL_ID}`,
|
||||
`omniroute/${UNSUPPORTED_MODEL_ID}`,
|
||||
],
|
||||
tools: {
|
||||
"mnote.current_page.read": "allow",
|
||||
"mnote.allowed_roots.describe": "allow",
|
||||
},
|
||||
skills: {},
|
||||
mcpServers: {},
|
||||
},
|
||||
quotaJson: { daily: 50 },
|
||||
timeoutMs: TIMEOUT,
|
||||
});
|
||||
|
||||
const status = await fetchJson(page, "/api/page-ai/pi/status");
|
||||
if (status.response.ok() && status.body.sessionId) {
|
||||
await fetchJson(page, "/api/page-ai/pi/abort", {
|
||||
method: "POST",
|
||||
data: { sessionId: status.body.sessionId },
|
||||
}).catch(() => null);
|
||||
}
|
||||
|
||||
const common = {
|
||||
rootUri: ROOT_URI,
|
||||
workspaceId: WORKSPACE_ID,
|
||||
pagePath: PAGE_PATH,
|
||||
pageTitle: "Pi model capability smoke",
|
||||
modelProvider: "omniroute",
|
||||
thinkingLevel: "medium",
|
||||
permissionMode: "full_access",
|
||||
};
|
||||
const unsupported = await fetchJson(page, "/api/page-ai/pi/start", {
|
||||
method: "POST",
|
||||
data: {
|
||||
...common,
|
||||
sessionId: `pi-model-unsupported-${STAMP}`,
|
||||
modelId: UNSUPPORTED_MODEL_ID,
|
||||
},
|
||||
});
|
||||
result.checks.unsupportedStatus = unsupported.response.status();
|
||||
result.checks.unsupportedCode = unsupported.body.code;
|
||||
result.checks.unsupportedMessage = unsupported.body.message;
|
||||
assert.equal(unsupported.response.status(), 400, unsupported.text.slice(0, 800));
|
||||
assert.equal(unsupported.body.code, "page_ai_pi_model_tools_unsupported");
|
||||
assert.match(unsupported.body.message || "", /不支持工具调用|无法确认工具调用能力/);
|
||||
|
||||
const supported = await fetchJson(page, "/api/page-ai/pi/start", {
|
||||
method: "POST",
|
||||
data: {
|
||||
...common,
|
||||
sessionId: `pi-model-supported-${STAMP}`,
|
||||
modelId: SUPPORTED_MODEL_ID,
|
||||
},
|
||||
});
|
||||
result.checks.supportedStatus = supported.response.status();
|
||||
result.checks.supportedModelId = supported.body.session?.modelId;
|
||||
result.checks.supportedRuntimePid = supported.body.session?.runtimePid;
|
||||
assert(supported.response.ok(), supported.text.slice(0, 800));
|
||||
assert.equal(supported.body.session?.modelId, SUPPORTED_MODEL_ID);
|
||||
assert(supported.body.session?.runtimePid, "tool-capable model should start a real Pi runtime");
|
||||
|
||||
await fetchJson(page, "/api/page-ai/pi/abort", {
|
||||
method: "POST",
|
||||
data: { sessionId: supported.body.session.sessionId },
|
||||
});
|
||||
result.ok = true;
|
||||
} catch (error) {
|
||||
result.error = error && error.stack ? error.stack : String(error);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
fs.writeFileSync(path.join(OUT, "result.json"), JSON.stringify(result, null, 2), "utf8");
|
||||
await browser.close();
|
||||
console.log(JSON.stringify({
|
||||
ok: result.ok,
|
||||
outputDir: OUT,
|
||||
result: path.join(OUT, "result.json"),
|
||||
}, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user