1041 lines
42 KiB
JavaScript
1041 lines
42 KiB
JavaScript
import { chromium } from "playwright";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { authenticationHeaders, createAcceptanceAPIClient } from "./lib/acceptance-client.mjs";
|
|
import { apiBaseURLFromEnv } from "./lib/service-endpoints.mjs";
|
|
import { inferSourceDataSource } from "./lib/source-data-source.mjs";
|
|
|
|
const baseURL = apiBaseURLFromEnv({ env: process.env, cliArgs: process.argv });
|
|
const apiToken = (process.env.DROBOTICFLOW_API_TOKEN || "").trim();
|
|
const apiClient = createAcceptanceAPIClient({ baseURL, apiToken });
|
|
const artifactDir = path.resolve("output/playwright");
|
|
const videoDir = path.join(artifactDir, "video");
|
|
const suffix = Date.now().toString(36);
|
|
const scanBucket = (process.env.PLAYWRIGHT_SCAN_BUCKET || "").trim();
|
|
const scanPrefix = (process.env.PLAYWRIGHT_SCAN_PREFIX || "").trim().replace(/^\/+|\/+$/g, "");
|
|
const sourcePath = (process.env.PLAYWRIGHT_SOURCE_PATH || "").trim();
|
|
const sourceDataSource = inferSourceDataSource(sourcePath, process.env.PLAYWRIGHT_SOURCE_DATA_SOURCE);
|
|
const names = {
|
|
admin: `PW Admin ${suffix}`,
|
|
adminEmail: `pw-admin-${suffix}@playwright.local`,
|
|
extraUser: `PW Operator ${suffix}`,
|
|
extraUserEmail: `pw-operator-${suffix}@playwright.local`,
|
|
project: `PW Project ${suffix}`,
|
|
scanWorkflow: `PW Scan Workflow ${suffix}`,
|
|
workflow: `PW Workflow ${suffix}`,
|
|
edgeRunningWorkflow: `PW Edge Running ${suffix}`,
|
|
edgeFailedWorkflow: `PW Edge Failed ${suffix}`,
|
|
template: `PW Template ${suffix}`,
|
|
projectTemplate: `PW Project Template ${suffix}`,
|
|
auditProject: `PW Audit ${suffix}`,
|
|
};
|
|
|
|
function log(step) {
|
|
process.stdout.write(`[playwright] ${step}\n`);
|
|
}
|
|
|
|
function assert(condition, message) {
|
|
if (!condition) {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
function requirePlaywrightSourcePath() {
|
|
if (!sourcePath) {
|
|
throw new Error(
|
|
"PLAYWRIGHT_SOURCE_PATH is required. Point it at a real source path visible to the operator runner, for example a shared PVC dataset path.",
|
|
);
|
|
}
|
|
}
|
|
|
|
function sourceHyperparams() {
|
|
return [
|
|
{ key: "DATA_SOURCE", value: sourceDataSource, description: "真实数据来源类型" },
|
|
{ key: "SOURCE_PATH", value: sourcePath, description: "真实数据路径" },
|
|
];
|
|
}
|
|
|
|
async function api(path, init = {}) {
|
|
return apiClient.request(path, init);
|
|
}
|
|
|
|
async function poll(fn, predicate, label, timeoutMs = 120000, intervalMs = 2000) {
|
|
const deadline = Date.now() + timeoutMs;
|
|
let lastValue;
|
|
while (Date.now() < deadline) {
|
|
lastValue = await fn();
|
|
if (predicate(lastValue)) {
|
|
return lastValue;
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
}
|
|
throw new Error(`Timed out waiting for ${label}. Last value: ${JSON.stringify(lastValue)}`);
|
|
}
|
|
|
|
async function gotoWithRetry(page, url) {
|
|
let lastError;
|
|
for (let attempt = 1; attempt <= 6; attempt += 1) {
|
|
try {
|
|
await page.goto(url, { waitUntil: "networkidle" });
|
|
return;
|
|
} catch (error) {
|
|
lastError = error;
|
|
if (attempt === 6) {
|
|
break;
|
|
}
|
|
await page.waitForTimeout(Math.min(attempt, 3) * 1000);
|
|
}
|
|
}
|
|
throw lastError;
|
|
}
|
|
|
|
async function capture(page, name, options = {}) {
|
|
fs.mkdirSync(artifactDir, { recursive: true });
|
|
const filePath = path.join(artifactDir, `${name}.png`);
|
|
await page.screenshot({ path: filePath, fullPage: true, ...options });
|
|
return filePath;
|
|
}
|
|
|
|
async function clickWithRetry(page, locator) {
|
|
let lastError;
|
|
for (let attempt = 1; attempt <= 6; attempt += 1) {
|
|
try {
|
|
await locator.waitFor({ state: "visible" });
|
|
await locator.scrollIntoViewIfNeeded();
|
|
await locator.click({ timeout: 2000 });
|
|
return;
|
|
} catch (error) {
|
|
lastError = error;
|
|
try {
|
|
const box = await locator.boundingBox();
|
|
if (!box) {
|
|
throw new Error("Unable to resolve click target bounding box");
|
|
}
|
|
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
return;
|
|
} catch (mouseError) {
|
|
lastError = mouseError;
|
|
}
|
|
if (attempt === 6) {
|
|
break;
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, Math.min(attempt, 3) * 500));
|
|
}
|
|
}
|
|
throw lastError;
|
|
}
|
|
|
|
async function waitForWorkflowEditor(page) {
|
|
await page.waitForURL(/\/workflow\//);
|
|
await page.getByRole("button", { name: "工作流配置" }).waitFor();
|
|
await page.locator('[data-testid="operator-library-count"]').waitFor();
|
|
}
|
|
|
|
async function ensureButtonState({ page, activeLocator, inactiveLocator, activate }) {
|
|
const isVisible = async (locator) => {
|
|
try {
|
|
return await locator.isVisible();
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
if (await isVisible(activeLocator)) {
|
|
return;
|
|
}
|
|
await activate();
|
|
await activeLocator.waitFor();
|
|
if (inactiveLocator && (await isVisible(inactiveLocator))) {
|
|
throw new Error("button state did not settle to the expected active label");
|
|
}
|
|
}
|
|
|
|
async function cleanupTestData() {
|
|
log("cleanup test data");
|
|
const users = (await api("/api/users")).items;
|
|
for (const user of users) {
|
|
if (String(user.email || "").endsWith("@playwright.local")) {
|
|
await api(`/api/users/${encodeURIComponent(user.id)}`, { method: "DELETE" });
|
|
}
|
|
}
|
|
|
|
const projects = (await api("/api/projects")).items;
|
|
for (const project of projects) {
|
|
const workflows = (await api(`/api/projects/${encodeURIComponent(project.id)}/workflows`)).items;
|
|
for (const workflow of workflows) {
|
|
if (String(workflow.name || "").startsWith("PW ")) {
|
|
await api(`/api/workflows/${encodeURIComponent(workflow.id)}`, {
|
|
method: "DELETE",
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const project of projects) {
|
|
if (String(project.name || "").startsWith("PW ")) {
|
|
await api(`/api/projects/${encodeURIComponent(project.id)}`, { method: "DELETE" });
|
|
}
|
|
}
|
|
|
|
const templates = (await api("/api/templates")).items;
|
|
for (const template of templates) {
|
|
if (String(template.name || "").startsWith("PW ")) {
|
|
await api(`/api/templates/${encodeURIComponent(template.id)}`, { method: "DELETE" });
|
|
}
|
|
}
|
|
|
|
const operators = (await api("/api/operators")).items;
|
|
for (const operator of operators) {
|
|
if (String(operator.name || "").startsWith("PW ")) {
|
|
await api(`/api/operators/${encodeURIComponent(operator.id)}`, { method: "DELETE" });
|
|
}
|
|
}
|
|
|
|
const scanWorkflows = (await api("/api/scan-configs")).items;
|
|
for (const workflow of scanWorkflows) {
|
|
if (String(workflow.name || "").startsWith("PW ")) {
|
|
await api(`/api/scan-configs/${encodeURIComponent(workflow.id)}`, {
|
|
method: "DELETE",
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
async function createAuditWorkflow(projectName, workflowName) {
|
|
const project = await api("/api/projects", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
name: projectName,
|
|
description: "Created by Playwright audit setup",
|
|
}),
|
|
});
|
|
|
|
const workflow = await api(`/api/projects/${project.id}/workflows`, {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
name: workflowName,
|
|
description: "Audit workflow created by Playwright",
|
|
type: "batch",
|
|
nodes: [
|
|
{
|
|
id: "review",
|
|
type: "operator",
|
|
data: {
|
|
label: "人工审核 (Human Review)",
|
|
category: "HUMAN",
|
|
description: "review",
|
|
inputs: [{ id: "in-1", name: "json", type: "json" }],
|
|
outputs: [{ id: "approved", name: "审核通过", type: "json" }],
|
|
},
|
|
position: { x: 0, y: 0 },
|
|
},
|
|
{
|
|
id: "upload",
|
|
type: "operator",
|
|
data: {
|
|
label: "结果上传",
|
|
category: "IO",
|
|
description: "sink",
|
|
inputs: [{ id: "in-1", name: "json", type: "json" }],
|
|
outputs: [],
|
|
},
|
|
position: { x: 200, y: 0 },
|
|
},
|
|
],
|
|
edges: [
|
|
{ id: "review-upload", source: "review", sourceHandle: "approved", target: "upload", targetHandle: "in-1" },
|
|
],
|
|
}),
|
|
});
|
|
|
|
const run = await api(`/api/workflows/${workflow.id}/run`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ trigger: "manual" }),
|
|
});
|
|
|
|
await poll(
|
|
async () => api(`/api/runs/${run.id}`),
|
|
(item) => item.status === "waiting_for_audit",
|
|
`audit run ${run.id} to enter waiting_for_audit`,
|
|
120000,
|
|
3000,
|
|
);
|
|
|
|
return { project, workflow, run };
|
|
}
|
|
|
|
async function createWorkflow(projectId, name, nodes, edges, type = "batch") {
|
|
return api(`/api/projects/${projectId}/workflows`, {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
name,
|
|
description: `${name} created by Playwright`,
|
|
type,
|
|
nodes,
|
|
edges,
|
|
}),
|
|
});
|
|
}
|
|
|
|
async function clickWorkflowEdge(page, label, fallbackIndex = 0) {
|
|
const labelledLocator = page.locator(`[aria-label="${label}"]`).first();
|
|
const labelledCount = await labelledLocator.count().catch(() => 0);
|
|
if (labelledCount > 0) {
|
|
await clickWithRetry(page, labelledLocator);
|
|
return;
|
|
}
|
|
|
|
const edgeLocator = page.locator(".react-flow__edge").nth(fallbackIndex);
|
|
await edgeLocator.waitFor({ state: "visible" });
|
|
const box = await edgeLocator.boundingBox();
|
|
if (!box) {
|
|
throw new Error(`Unable to resolve workflow edge ${label}`);
|
|
}
|
|
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
}
|
|
|
|
async function fillLabeledInput(page, labelText, value) {
|
|
const group = page.locator(`label:has-text("${labelText}")`).locator("..");
|
|
const input = group.locator("input, textarea, select").first();
|
|
await input.click();
|
|
await input.fill(value);
|
|
}
|
|
|
|
async function main() {
|
|
requirePlaywrightSourcePath();
|
|
await cleanupTestData();
|
|
fs.mkdirSync(videoDir, { recursive: true });
|
|
|
|
const browser = await chromium.launch({ headless: true });
|
|
const context = await browser.newContext({
|
|
extraHTTPHeaders: authenticationHeaders(apiToken),
|
|
viewport: { width: 1440, height: 1100 },
|
|
recordVideo: {
|
|
dir: videoDir,
|
|
size: { width: 1440, height: 1100 },
|
|
},
|
|
});
|
|
const page = await context.newPage();
|
|
let recordedVideoPath = "";
|
|
|
|
try {
|
|
log("open bootstrap");
|
|
await gotoWithRetry(page, baseURL);
|
|
const bootstrapVisible = await page
|
|
.getByText("新增真实平台用户")
|
|
.isVisible({ timeout: 5000 })
|
|
.catch(() => false);
|
|
if (bootstrapVisible) {
|
|
await page.getByPlaceholder("输入真实姓名或账号名").fill(names.admin);
|
|
await page.getByPlaceholder("name@example.com").fill(names.adminEmail);
|
|
await page.locator("select").first().selectOption("admin");
|
|
await page.getByRole("button", { name: "创建并进入系统" }).click();
|
|
}
|
|
await page.getByRole("heading", { name: "Drobodata 仪表盘" }).waitFor();
|
|
await capture(page, "01-dashboard");
|
|
|
|
log("settings save round-trip");
|
|
await page.getByRole("link", { name: "系统配置" }).click();
|
|
await page.getByRole("heading", { name: "系统配置" }).waitFor();
|
|
await page.getByRole("button", { name: /保存配置/ }).waitFor();
|
|
await capture(page, "02-settings");
|
|
const pollGroup = page.locator('label:has-text("轮询间隔 (ms)")').locator("..");
|
|
const pollInput = pollGroup.locator("input");
|
|
const originalPoll = Number(await pollInput.inputValue());
|
|
await pollInput.fill(String(originalPoll + 1));
|
|
await page.getByRole("button", { name: /保存配置/ }).click();
|
|
await page.getByText("配置已保存到后端。").waitFor();
|
|
await pollInput.fill(String(originalPoll));
|
|
await page.getByRole("button", { name: /保存配置/ }).click();
|
|
await page.getByText("配置已保存到后端。").waitFor();
|
|
|
|
log("operators create edit delete");
|
|
await page.getByRole("link", { name: "算子管理" }).click();
|
|
await page.getByRole("heading", { name: "算子管理" }).waitFor();
|
|
await capture(page, "03-operators");
|
|
await page.getByRole("button", { name: "注册算子" }).click();
|
|
await page.getByPlaceholder("例如: 图像锐化").fill(`PW Operator ${suffix}`);
|
|
await page.getByPlaceholder("描述该算子的功能与用途...").fill("Playwright created operator");
|
|
await page.getByRole("button", { name: "确认注册" }).click();
|
|
await page.getByPlaceholder("搜索算子...").fill(`PW Operator ${suffix}`);
|
|
await page.getByText(`PW Operator ${suffix}`).waitFor();
|
|
const operatorCard = page
|
|
.locator("div")
|
|
.filter({ hasText: `PW Operator ${suffix}` })
|
|
.first();
|
|
await operatorCard.getByRole("button", { name: /配置详情|查看详情/ }).click();
|
|
await page.getByPlaceholder("描述该算子的功能与用途...").fill("Playwright updated operator");
|
|
await page.getByRole("button", { name: "保存修改" }).click();
|
|
await page.getByPlaceholder("搜索算子...").fill(`PW Operator ${suffix}`);
|
|
await page.locator("button:has(svg.lucide-trash-2)").first().click();
|
|
await page.getByPlaceholder("搜索算子...").fill(`PW Operator ${suffix}`);
|
|
await page.getByText("没有匹配的算子,请调整搜索条件。").waitFor();
|
|
await page.getByPlaceholder("搜索算子...").fill("");
|
|
|
|
log("database browser overview and query");
|
|
await page.getByRole("link", { name: "业务数据库" }).click();
|
|
await page.getByRole("heading", { name: "业务数据库" }).waitFor();
|
|
await page.getByText("管理用户自定义的业务 MongoDB 连接").waitFor();
|
|
const connectionSelect = page.locator('label:has-text("当前连接")').locator("..").locator("select").first();
|
|
const optionCount = await connectionSelect.locator("option").count();
|
|
if (optionCount > 1) {
|
|
await connectionSelect.selectOption({ index: 1 });
|
|
await page.waitForTimeout(1000);
|
|
}
|
|
await capture(page, "04-database-browser");
|
|
|
|
log("data assets load");
|
|
await page.getByRole("link", { name: "数据资产" }).click();
|
|
await page.getByRole("heading", { name: "数据资产" }).waitFor();
|
|
await capture(page, "05-data-assets-source");
|
|
const packageTab = page.getByRole("button", { name: /成品数据/ }).first();
|
|
if (await packageTab.isVisible().catch(() => false)) {
|
|
await clickWithRetry(page, packageTab);
|
|
await page.waitForTimeout(800);
|
|
await capture(page, "06-data-assets-packages");
|
|
}
|
|
|
|
log("object storage overview");
|
|
await page.getByRole("link", { name: "对象存储" }).click();
|
|
await page.getByRole("heading", { name: "对象存储" }).waitFor();
|
|
await page.waitForTimeout(1000);
|
|
await capture(page, "07-object-storage");
|
|
|
|
log("sampling page");
|
|
await page.getByRole("link", { name: "抽检任务" }).click();
|
|
await page.getByRole("heading", { name: "抽检任务" }).waitFor();
|
|
await capture(page, "08-sampling");
|
|
|
|
log("legacy scan workflow route redirects back into project workflows");
|
|
assert(
|
|
(await page.getByRole("link", { name: "扫描工作流" }).count()) === 0,
|
|
"sidebar should not expose a dedicated scan workflow entry",
|
|
);
|
|
await gotoWithRetry(page, `${baseURL}/scan-configs`);
|
|
await page.waitForURL(/\/projects$/);
|
|
await page.getByRole("heading", { name: "项目管理" }).waitFor();
|
|
|
|
log("projects create and open");
|
|
await page.getByRole("link", { name: "项目管理" }).click();
|
|
await page.getByRole("heading", { name: "项目管理" }).waitFor();
|
|
await page.getByRole("button", { name: "创建项目" }).click();
|
|
await page.getByPlaceholder("请输入项目名称").fill(names.project);
|
|
await page.getByPlaceholder("请输入项目描述,例如:处理机械臂抓取过程中的视觉数据").fill("Playwright project");
|
|
await page.getByRole("button", { name: "立即创建" }).click();
|
|
await page.getByPlaceholder("搜索项目...").fill(names.project);
|
|
await page.getByText(names.project).waitFor();
|
|
|
|
const projectList = (await api("/api/projects")).items;
|
|
const project = projectList.find((item) => item.name === names.project);
|
|
assert(project, "created project not found via api");
|
|
await gotoWithRetry(page, `${baseURL}/project/${project.id}`);
|
|
await capture(page, "09-project-detail");
|
|
|
|
log("project detail create scan-capable workflow through BOS operator");
|
|
await page.getByRole("heading", { name: names.project }).waitFor();
|
|
await page.getByRole("button", { name: "新建工作流" }).click();
|
|
await page.getByText("默认先创建普通工作流").waitFor();
|
|
await page.getByPlaceholder("例如: 实时障碍物检测").fill(names.scanWorkflow);
|
|
await page.getByRole("button", { name: "确认创建" }).click();
|
|
await waitForWorkflowEditor(page);
|
|
await page.getByPlaceholder("搜索算子...").fill("BOS 增量扫描");
|
|
const scanOperatorCard = page.locator("div").filter({ hasText: "BOS 增量扫描" }).first();
|
|
await scanOperatorCard.locator('button[title="点击添加到画布"]').click();
|
|
const scanCanvasNode = page.locator(".react-flow__node").filter({ hasText: "BOS 增量扫描" }).first();
|
|
await scanCanvasNode.waitFor();
|
|
await scanCanvasNode.dblclick();
|
|
await page.getByText("扫描源配置").waitFor();
|
|
await capture(page, "10-workflow-editor-scan");
|
|
await page.locator('label:has-text("Bucket")').waitFor();
|
|
await page.locator('label:has-text("Prefix")').waitFor();
|
|
await page.getByRole("button", { name: "工作流配置" }).click();
|
|
await page.getByText("手动执行").waitFor();
|
|
await page.getByText("周期执行").waitFor();
|
|
await page.getByRole("button", { name: "工作流配置" }).click();
|
|
|
|
const storageConnections = (await api("/api/storage/connections")).items || [];
|
|
if (storageConnections.length > 0 && scanBucket && scanPrefix) {
|
|
log("scan source operator favorite storage paths");
|
|
const connectionId = storageConnections[0].id;
|
|
await page
|
|
.locator('label:has-text("已选连接")')
|
|
.locator("..")
|
|
.locator("select")
|
|
.first()
|
|
.selectOption(connectionId);
|
|
await page.waitForFunction((bucket) => {
|
|
const labels = Array.from(document.querySelectorAll("label"));
|
|
const bucketLabel = labels.find((item) => item.textContent?.includes("Bucket"));
|
|
const select = bucketLabel?.parentElement?.querySelector("select");
|
|
return !!select && Array.from(select.options).some((option) => option.value === bucket);
|
|
}, scanBucket);
|
|
const bucketSelect = page.locator('label:has-text("Bucket")').locator("..").locator("select").first();
|
|
const prefixGroup = page.locator('label:has-text("Prefix")').locator("..");
|
|
const prefixInput = prefixGroup.locator("input").first();
|
|
await bucketSelect.selectOption(scanBucket);
|
|
await prefixInput.fill(scanPrefix);
|
|
await prefixInput.blur();
|
|
await ensureButtonState({
|
|
page,
|
|
activeLocator: page.getByRole("button", { name: "取消收藏当前路径" }).first(),
|
|
inactiveLocator: page.getByRole("button", { name: "收藏当前路径" }).first(),
|
|
activate: () => clickWithRetry(page, page.getByRole("button", { name: "收藏当前路径" }).first()),
|
|
});
|
|
await page.getByText("常用路径").first().waitFor();
|
|
await bucketSelect.selectOption("");
|
|
await prefixInput.fill("");
|
|
await prefixInput.blur();
|
|
const browseButton = prefixGroup.locator('button[title="浏览前缀"]').first();
|
|
const browseDisabled = await browseButton.evaluate((node) => node.hasAttribute("disabled"));
|
|
assert(!browseDisabled, "favorite storage path should keep OSS browse enabled");
|
|
await browseButton.click();
|
|
await page.getByRole("heading", { name: "OSS 资源浏览器" }).waitFor();
|
|
await page.evaluate(
|
|
({ bucket, prefix }) => {
|
|
const candidates = Array.from(document.querySelectorAll(`button[title="${bucket}/${prefix}"]`));
|
|
const target = candidates
|
|
.map((node) => ({ node, x: node.getBoundingClientRect().x }))
|
|
.sort((a, b) => a.x - b.x)[0]?.node;
|
|
if (!target) {
|
|
throw new Error("favorite storage path chip not found");
|
|
}
|
|
target.click();
|
|
},
|
|
{ bucket: scanBucket, prefix: scanPrefix },
|
|
);
|
|
await page.waitForFunction(
|
|
({ bucket, prefix }) => {
|
|
const labels = Array.from(document.querySelectorAll("label"));
|
|
const bucketLabel = labels.find((item) => item.textContent?.includes("Bucket"));
|
|
const prefixLabel = labels.find((item) => item.textContent?.includes("Prefix"));
|
|
const bucketSelect = bucketLabel?.parentElement?.querySelector("select");
|
|
const prefixInput = prefixLabel?.parentElement?.querySelector("input");
|
|
return bucketSelect?.value === bucket && prefixInput?.value === prefix;
|
|
},
|
|
{ bucket: scanBucket, prefix: scanPrefix },
|
|
);
|
|
await page.evaluate(() => {
|
|
const heading = Array.from(document.querySelectorAll("h3")).find((item) =>
|
|
item.textContent?.includes("OSS 资源浏览器"),
|
|
);
|
|
const container = heading?.closest(".relative");
|
|
const closeButton = container?.querySelector("button");
|
|
if (closeButton instanceof HTMLButtonElement) {
|
|
closeButton.click();
|
|
}
|
|
});
|
|
await page.getByRole("heading", { name: "OSS 资源浏览器" }).waitFor({ state: "hidden" });
|
|
const saveScanWorkflowRequest = page.waitForResponse(
|
|
(response) =>
|
|
response.request().method() === "PUT" && /\/api\/workflows\/[^/]+$/.test(response.url()) && response.ok(),
|
|
);
|
|
await page.getByRole("button", { name: "保存" }).click();
|
|
await saveScanWorkflowRequest;
|
|
const savedScanWorkflowId = page.url().match(/\/workflow\/([^?]+)/)?.[1];
|
|
assert(savedScanWorkflowId, `unable to resolve saved scan workflow id from ${page.url()}`);
|
|
const savedScanWorkflow = await api(`/api/workflows/${encodeURIComponent(savedScanWorkflowId)}`);
|
|
const savedScanSourceNode = (savedScanWorkflow.nodes || []).find((item) => item?.data?.label === "BOS 增量扫描");
|
|
assert(savedScanSourceNode?.id, "saved scan workflow did not persist BOS 增量扫描 node id");
|
|
|
|
log("scan source operator favorite storage paths survive fresh browser context");
|
|
const verifyContext = await browser.newContext({
|
|
extraHTTPHeaders: authenticationHeaders(apiToken),
|
|
viewport: { width: 1440, height: 1100 },
|
|
});
|
|
const verifyPage = await verifyContext.newPage();
|
|
try {
|
|
await gotoWithRetry(verifyPage, page.url());
|
|
await verifyPage.locator(".react-flow__node").filter({ hasText: "BOS 增量扫描" }).first().dblclick();
|
|
await verifyPage.locator('label:has-text("Bucket")').waitFor();
|
|
await verifyPage.getByText("我的常用路径").first().waitFor();
|
|
await verifyPage.getByRole("button", { name: "取消收藏当前路径" }).first().waitFor();
|
|
} finally {
|
|
await verifyContext.close();
|
|
}
|
|
|
|
log("scan source operator state commit and reset");
|
|
const scanWorkflowId = savedScanWorkflowId;
|
|
const scanSourceNodeId = savedScanSourceNode.id;
|
|
const scanRun = await api(`/api/workflows/${encodeURIComponent(scanWorkflowId)}/run`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ trigger: "manual" }),
|
|
});
|
|
await poll(
|
|
() => api(`/api/runs/${encodeURIComponent(scanRun.id)}`),
|
|
(run) => run.status === "completed",
|
|
"scan source workflow completion",
|
|
180000,
|
|
3000,
|
|
);
|
|
await poll(
|
|
() =>
|
|
api(
|
|
`/api/workflows/${encodeURIComponent(scanWorkflowId)}/nodes/${encodeURIComponent(scanSourceNodeId)}/source-state`,
|
|
),
|
|
(state) => state?.current?.lastRunId === scanRun.id,
|
|
"scan source state commit",
|
|
180000,
|
|
3000,
|
|
);
|
|
await page.reload({ waitUntil: "networkidle" });
|
|
await page.locator(".react-flow__node").filter({ hasText: "BOS 增量扫描" }).first().dblclick();
|
|
await page.getByText("增量状态").waitFor();
|
|
await page.getByText("最近写入 Run").waitFor();
|
|
await page.locator(".node-config-panel").getByText(scanRun.id, { exact: true }).first().waitFor();
|
|
await clickWithRetry(page, page.getByRole("button", { name: "重置当前状态" }).first());
|
|
await poll(
|
|
() =>
|
|
api(
|
|
`/api/workflows/${encodeURIComponent(scanWorkflowId)}/nodes/${encodeURIComponent(scanSourceNodeId)}/source-state`,
|
|
),
|
|
(state) => !state?.current,
|
|
"scan source state reset",
|
|
120000,
|
|
2000,
|
|
);
|
|
await page.getByText("当前配置下还没有已提交的增量状态").waitFor();
|
|
} else {
|
|
log("skip scan source live storage checks; set PLAYWRIGHT_SCAN_BUCKET and PLAYWRIGHT_SCAN_PREFIX to enable");
|
|
}
|
|
|
|
await gotoWithRetry(page, `${baseURL}/project/${project.id}`);
|
|
|
|
log("project detail create workflow");
|
|
await page.getByRole("heading", { name: names.project }).waitFor();
|
|
await page.getByRole("button", { name: "新建工作流" }).click();
|
|
await page.getByText("默认先创建普通工作流").waitFor();
|
|
await page.getByPlaceholder("例如: 实时障碍物检测").fill(names.workflow);
|
|
await page.getByRole("button", { name: "确认创建" }).click();
|
|
await waitForWorkflowEditor(page);
|
|
await capture(page, "11-workflow-editor");
|
|
await page.getByRole("button", { name: "运行工作流" }).waitFor();
|
|
await page.getByRole("button", { name: "工作流配置" }).click();
|
|
await page.getByText("手动执行").waitFor();
|
|
await page.getByText("周期执行").waitFor();
|
|
await clickWithRetry(page, page.getByRole("button", { name: "周期执行" }).last());
|
|
await page.getByText("调度间隔 (秒)").waitFor();
|
|
await clickWithRetry(page, page.getByRole("button", { name: "手动执行" }).last());
|
|
await page.getByRole("button", { name: "工作流配置" }).click();
|
|
|
|
const workflows = (await api(`/api/projects/${project.id}/workflows`)).items;
|
|
const workflow = workflows.find((item) => item.name === names.workflow);
|
|
assert(workflow, "created workflow not found via api");
|
|
|
|
log("seed workflow graph");
|
|
await api(`/api/workflows/${workflow.id}`, {
|
|
method: "PUT",
|
|
body: JSON.stringify({
|
|
nodes: [
|
|
{
|
|
id: "source-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "真实数据源",
|
|
category: "IO",
|
|
description: "Playwright source node",
|
|
inputs: [],
|
|
outputs: [{ id: "out-1", name: "manifest", type: "json" }],
|
|
hyperparams: sourceHyperparams(),
|
|
},
|
|
position: { x: 100, y: 100 },
|
|
},
|
|
{
|
|
id: "review-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "人工审核 (Human Review)",
|
|
category: "HUMAN",
|
|
description: "Playwright review node",
|
|
inputs: [{ id: "in-1", name: "json", type: "json" }],
|
|
outputs: [
|
|
{ id: "approved", name: "审核通过", type: "json" },
|
|
{ id: "rejected", name: "审核拒绝", type: "json" },
|
|
],
|
|
},
|
|
position: { x: 360, y: 100 },
|
|
},
|
|
{
|
|
id: "upload-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "结果上传",
|
|
category: "IO",
|
|
description: "Playwright upload node",
|
|
inputs: [{ id: "in-1", name: "json", type: "json" }],
|
|
outputs: [],
|
|
},
|
|
position: { x: 620, y: 100 },
|
|
},
|
|
],
|
|
edges: [
|
|
{
|
|
id: "source-review",
|
|
source: "source-1",
|
|
sourceHandle: "out-1",
|
|
target: "review-1",
|
|
targetHandle: "in-1",
|
|
},
|
|
{
|
|
id: "review-upload",
|
|
source: "review-1",
|
|
sourceHandle: "approved",
|
|
target: "upload-1",
|
|
targetHandle: "in-1",
|
|
},
|
|
],
|
|
}),
|
|
});
|
|
|
|
await page.reload({ waitUntil: "networkidle" });
|
|
await page.locator(".react-flow__node").filter({ hasText: "真实数据源" }).first().dblclick();
|
|
const sourceGroup = page.locator('label:has-text("SOURCE_PATH")').locator("..").locator("..");
|
|
await sourceGroup.locator("input").fill(sourcePath);
|
|
await page.getByRole("button", { name: "保存" }).click();
|
|
|
|
log("run workflow from editor without redirect");
|
|
await page.getByRole("button", { name: "运行工作流" }).click();
|
|
await page.getByRole("button", { name: "查看执行监控" }).waitFor();
|
|
assert(/\/workflow\//.test(page.url()), `expected to stay on workflow editor, got ${page.url()}`);
|
|
await page.getByText(/当前节点:/).waitFor();
|
|
await poll(
|
|
async () => page.locator(".react-flow__edge.animated").count(),
|
|
(count) => count > 0,
|
|
"animated workflow edge on editor",
|
|
30000,
|
|
1000,
|
|
);
|
|
await poll(
|
|
async () => {
|
|
const runList = (await api("/api/runs")).items;
|
|
return runList.find((item) => item.workflowName === names.workflow) || null;
|
|
},
|
|
(item) => Boolean(item?.id && item.status === "waiting_for_audit"),
|
|
`editor run for ${names.workflow} waiting_for_audit`,
|
|
120000,
|
|
2000,
|
|
);
|
|
const editorRun = (await api("/api/runs")).items.find((item) => item.workflowName === names.workflow);
|
|
assert(editorRun, "editor run not found via api");
|
|
await page.getByRole("button", { name: "查看执行监控" }).click();
|
|
await page.waitForURL(new RegExp(`/monitoring\\?runId=${editorRun.id}`));
|
|
await page.getByRole("heading", { name: "执行监控" }).waitFor();
|
|
await page.getByPlaceholder("搜索运行 ID、工作流或项目...").fill(names.workflow);
|
|
await page.getByText(names.workflow).waitFor();
|
|
await capture(page, "12-monitoring");
|
|
const runRow = page.locator("tr").filter({ hasText: names.workflow }).first();
|
|
await runRow.hover();
|
|
await runRow.getByTitle("查看日志").click();
|
|
await page.getByRole("heading", { name: "执行日志" }).waitFor();
|
|
await page.getByRole("button", { name: "关闭" }).click();
|
|
await runRow.hover();
|
|
await runRow.getByTitle("查看资源").click();
|
|
await page.getByRole("heading", { name: "资源监控" }).waitFor();
|
|
await page.getByRole("button", { name: "关闭" }).click();
|
|
await runRow.hover();
|
|
await runRow.getByTitle("查看数据").click();
|
|
await page.getByRole("heading", { name: "产出数据" }).waitFor();
|
|
await page.getByRole("button", { name: "关闭" }).click();
|
|
|
|
const pendingAudit = await poll(
|
|
async () => {
|
|
const tasks = (await api("/api/audit-tasks?status=all")).items;
|
|
return tasks.find((task) => task.runId === editorRun.id && task.status === "pending") || null;
|
|
},
|
|
(item) => Boolean(item?.id),
|
|
`audit task for editor run ${editorRun.id}`,
|
|
120000,
|
|
2000,
|
|
);
|
|
await api(`/api/audit-tasks/${pendingAudit.id}/approve`, { method: "POST" });
|
|
await poll(
|
|
async () => api(`/api/runs/${editorRun.id}`),
|
|
(item) => item.status === "completed",
|
|
`editor run ${editorRun.id} completion after approval`,
|
|
120000,
|
|
2000,
|
|
);
|
|
|
|
log("edge output panel for running, completed, and failed workflows");
|
|
const edgeRunningWorkflow = await createWorkflow(
|
|
project.id,
|
|
names.edgeRunningWorkflow,
|
|
[
|
|
{
|
|
id: "source-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "真实数据源",
|
|
category: "IO",
|
|
description: "Edge output running source",
|
|
inputs: [],
|
|
outputs: [{ id: "out-1", name: "manifest", type: "json" }],
|
|
hyperparams: sourceHyperparams(),
|
|
},
|
|
position: { x: 80, y: 80 },
|
|
},
|
|
{
|
|
id: "shell-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "Shell 命令执行",
|
|
category: "UTIL",
|
|
description: "Slow shell",
|
|
inputs: [{ id: "in-1", name: "input", type: "json" }],
|
|
outputs: [{ id: "out-1", name: "result", type: "json" }],
|
|
hyperparams: [
|
|
{
|
|
key: "COMMAND",
|
|
value: "sleep 8; printf '{\"ok\":true}' > result.json",
|
|
},
|
|
],
|
|
},
|
|
position: { x: 380, y: 80 },
|
|
},
|
|
],
|
|
[
|
|
{
|
|
id: "source-shell",
|
|
source: "source-1",
|
|
sourceHandle: "out-1",
|
|
target: "shell-1",
|
|
targetHandle: "in-1",
|
|
},
|
|
],
|
|
);
|
|
const edgeRunningRun = await api(`/api/workflows/${edgeRunningWorkflow.id}/run`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ trigger: "manual" }),
|
|
});
|
|
const edgeRunningRunDetail = await poll(
|
|
async () => api(`/api/runs/${edgeRunningRun.id}`),
|
|
(item) =>
|
|
item.status === "running" &&
|
|
item.nodeExecutions?.some(
|
|
(execution) =>
|
|
execution.nodeId === "source-1" && execution.status === "completed" && execution.artifacts?.length > 0,
|
|
) &&
|
|
item.nodeExecutions?.some((execution) => execution.nodeId === "shell-1" && execution.status === "running"),
|
|
`edge running workflow ${edgeRunningRun.id} to enter running state`,
|
|
120000,
|
|
1500,
|
|
);
|
|
const edgeRunningArtifact =
|
|
edgeRunningRunDetail.nodeExecutions
|
|
?.find((execution) => execution.nodeId === "source-1")
|
|
?.artifacts?.find((artifact) => artifact.portId === "out-1") ||
|
|
edgeRunningRunDetail.artifacts?.find((artifact) => artifact.nodeId === "source-1" && artifact.portId === "out-1");
|
|
assert(edgeRunningArtifact?.name, "running edge artifact not found");
|
|
|
|
await gotoWithRetry(page, `${baseURL}/workflow/${edgeRunningWorkflow.id}`);
|
|
await page.locator(".react-flow").waitFor();
|
|
await page.getByText(`Run ${edgeRunningRun.id}`).waitFor();
|
|
await clickWorkflowEdge(page, "真实数据源 到 Shell 命令执行 连线");
|
|
await page.locator(".edge-output-panel").getByText("连线输出", { exact: true }).waitFor();
|
|
await page.locator(".edge-output-panel").getByText("正在执行中", { exact: true }).waitFor();
|
|
await page.locator(".edge-output-panel").getByText(edgeRunningArtifact.name, { exact: true }).waitFor();
|
|
|
|
await poll(
|
|
async () => api(`/api/runs/${edgeRunningRun.id}`),
|
|
(item) => item.status === "completed",
|
|
`edge running workflow ${edgeRunningRun.id} completion`,
|
|
120000,
|
|
2000,
|
|
);
|
|
await gotoWithRetry(page, `${baseURL}/workflow/${edgeRunningWorkflow.id}`);
|
|
await page.getByText(`Run ${edgeRunningRun.id}`).waitFor();
|
|
await clickWorkflowEdge(page, "真实数据源 到 Shell 命令执行 连线");
|
|
await page.locator(".edge-output-panel").getByText("执行完成", { exact: true }).waitFor();
|
|
await page.locator(".edge-output-panel").getByText(edgeRunningArtifact.name, { exact: true }).waitFor();
|
|
|
|
const edgeFailedWorkflow = await createWorkflow(
|
|
project.id,
|
|
names.edgeFailedWorkflow,
|
|
[
|
|
{
|
|
id: "source-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "真实数据源",
|
|
category: "IO",
|
|
description: "Edge output failed source",
|
|
inputs: [],
|
|
outputs: [{ id: "out-1", name: "manifest", type: "json" }],
|
|
hyperparams: sourceHyperparams(),
|
|
},
|
|
position: { x: 80, y: 80 },
|
|
},
|
|
{
|
|
id: "shell-1",
|
|
type: "operator",
|
|
data: {
|
|
label: "Shell 命令执行",
|
|
category: "UTIL",
|
|
description: "Failing shell",
|
|
inputs: [{ id: "in-1", name: "input", type: "json" }],
|
|
outputs: [{ id: "out-1", name: "result", type: "json" }],
|
|
hyperparams: [
|
|
{
|
|
key: "COMMAND",
|
|
value: "echo edge-preview-failed >&2; exit 1",
|
|
},
|
|
],
|
|
},
|
|
position: { x: 380, y: 80 },
|
|
},
|
|
],
|
|
[
|
|
{
|
|
id: "source-shell",
|
|
source: "source-1",
|
|
sourceHandle: "out-1",
|
|
target: "shell-1",
|
|
targetHandle: "in-1",
|
|
},
|
|
],
|
|
);
|
|
const edgeFailedRun = await api(`/api/workflows/${edgeFailedWorkflow.id}/run`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ trigger: "manual" }),
|
|
});
|
|
const edgeFailedRunDetail = await poll(
|
|
async () => api(`/api/runs/${edgeFailedRun.id}`),
|
|
(item) =>
|
|
item.status === "failed" &&
|
|
item.nodeExecutions?.some(
|
|
(execution) =>
|
|
execution.nodeId === "source-1" && execution.status === "completed" && execution.artifacts?.length > 0,
|
|
),
|
|
`edge failed workflow ${edgeFailedRun.id} failure`,
|
|
120000,
|
|
1500,
|
|
);
|
|
const edgeFailedArtifact =
|
|
edgeFailedRunDetail.nodeExecutions
|
|
?.find((execution) => execution.nodeId === "source-1")
|
|
?.artifacts?.find((artifact) => artifact.portId === "out-1") ||
|
|
edgeFailedRunDetail.artifacts?.find((artifact) => artifact.nodeId === "source-1" && artifact.portId === "out-1");
|
|
assert(edgeFailedArtifact?.name, "failed edge artifact not found");
|
|
|
|
await gotoWithRetry(page, `${baseURL}/workflow/${edgeFailedWorkflow.id}`);
|
|
await page.locator(".react-flow").waitFor();
|
|
await page.getByText(`Run ${edgeFailedRun.id}`).waitFor();
|
|
await clickWorkflowEdge(page, "真实数据源 到 Shell 命令执行 连线");
|
|
await page.locator(".edge-output-panel").getByText("执行失败", { exact: true }).waitFor();
|
|
await page.locator(".edge-output-panel").getByText(edgeFailedArtifact.name, { exact: true }).waitFor();
|
|
|
|
log("export template from workflow editor");
|
|
await gotoWithRetry(page, `${baseURL}/workflow/${workflow.id}?runId=${editorRun.id}`);
|
|
await page.locator(".react-flow").waitFor();
|
|
await page.getByRole("button", { name: "导出模板" }).click();
|
|
await page
|
|
.locator("input")
|
|
.filter({ has: page.locator(".. >> text=模板名称") })
|
|
.first()
|
|
.fill(names.template);
|
|
await page.getByRole("button", { name: "创建模板" }).click();
|
|
await page.waitForURL(/type=template/);
|
|
|
|
log("templates search and use");
|
|
await page.getByRole("link", { name: "工作流模板" }).click();
|
|
await page.getByRole("heading", { name: "工作流模板" }).waitFor();
|
|
await page.getByPlaceholder("搜索模板...").fill(names.template);
|
|
await page.getByText(names.template).waitFor();
|
|
await capture(page, "13-templates");
|
|
const templateCard = page.locator("div").filter({ hasText: names.template }).first();
|
|
await templateCard
|
|
.locator("button")
|
|
.filter({ hasText: /^使用此模板$/ })
|
|
.click();
|
|
await page.getByText("选择目标项目").waitFor();
|
|
await page.getByRole("button", { name: names.project }).click();
|
|
await page.getByRole("button", { name: "确认并进入编辑器" }).click();
|
|
await page.waitForURL(/\/workflow\//);
|
|
|
|
log("project detail save as template");
|
|
await gotoWithRetry(page, `${baseURL}/project/${project.id}`);
|
|
await page.getByRole("button", { name: "保存为模板" }).click();
|
|
await page.getByRole("heading", { name: "保存为模板" }).waitFor();
|
|
await page.locator("select").last().selectOption(workflow.id);
|
|
await page.locator("input").last().fill(names.projectTemplate);
|
|
await page.getByRole("button", { name: "保存模板" }).click();
|
|
await page.waitForURL(/type=template/);
|
|
|
|
log("users create edit delete");
|
|
await page.getByRole("link", { name: "用户管理" }).click();
|
|
await page.getByRole("heading", { name: "用户管理" }).waitFor();
|
|
await capture(page, "14-users");
|
|
await clickWithRetry(
|
|
page,
|
|
page
|
|
.locator("button")
|
|
.filter({ hasText: /^创建用户$/ })
|
|
.first(),
|
|
);
|
|
await page.getByRole("heading", { name: "创建用户" }).waitFor();
|
|
await fillLabeledInput(page, "用户名", names.extraUser);
|
|
await fillLabeledInput(page, "邮箱地址", names.extraUserEmail);
|
|
await page.locator('label:has-text("角色权限")').locator("..").locator("select").selectOption("operator");
|
|
await clickWithRetry(
|
|
page,
|
|
page
|
|
.locator("button")
|
|
.filter({ hasText: /^创建用户$/ })
|
|
.last(),
|
|
);
|
|
await page.getByText(names.extraUser).waitFor();
|
|
const userRow = page.locator("tr").filter({ hasText: names.extraUser }).first();
|
|
await userRow.getByRole("button", { name: "编辑" }).click();
|
|
await page.locator('label:has-text("角色权限")').locator("..").locator("select").selectOption("auditor");
|
|
await page.getByRole("button", { name: "保存修改" }).click();
|
|
await userRow.getByRole("button", { name: "删除" }).click();
|
|
await page.waitForTimeout(500);
|
|
|
|
log("audit approve and reject");
|
|
const auditOne = await createAuditWorkflow(`${names.auditProject} A`, `PW Audit Workflow A ${suffix}`);
|
|
const auditTwo = await createAuditWorkflow(`${names.auditProject} B`, `PW Audit Workflow B ${suffix}`);
|
|
await gotoWithRetry(page, `${baseURL}/audit`);
|
|
await page.getByRole("heading", { name: /任务审核/ }).waitFor();
|
|
await capture(page, "15-audit");
|
|
await clickWithRetry(page, page.getByText(`${names.auditProject} A`).first());
|
|
await clickWithRetry(page, page.getByRole("button", { name: /审核通过/ }));
|
|
await clickWithRetry(page, page.getByText(`${names.auditProject} B`).first());
|
|
await clickWithRetry(page, page.getByRole("button", { name: /审核拒绝/ }));
|
|
await clickWithRetry(page, page.getByRole("button", { name: "已处理" }));
|
|
|
|
await poll(
|
|
async () => api(`/api/runs/${auditOne.run.id}`),
|
|
(item) => item.status === "completed",
|
|
`audit run ${auditOne.run.id} approved completion`,
|
|
);
|
|
await poll(
|
|
async () => api(`/api/runs/${auditTwo.run.id}`),
|
|
(item) => item.status === "completed",
|
|
`audit run ${auditTwo.run.id} rejected completion`,
|
|
);
|
|
|
|
log("functional check completed");
|
|
} catch (error) {
|
|
await page.screenshot({ path: path.join(artifactDir, `failure-${suffix}.png`), fullPage: true }).catch(() => {});
|
|
throw error;
|
|
} finally {
|
|
await page.close().catch(() => {});
|
|
if (page.video()) {
|
|
recordedVideoPath = await page
|
|
.video()
|
|
.path()
|
|
.catch(() => "");
|
|
}
|
|
await context.close();
|
|
await browser.close();
|
|
if (recordedVideoPath && fs.existsSync(recordedVideoPath)) {
|
|
const targetPath = path.join(artifactDir, "playwright-functional-check.webm");
|
|
fs.copyFileSync(recordedVideoPath, targetPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|