feat: add task history diagnostics
This commit is contained in:
@@ -231,6 +231,7 @@ async function serviceChecks(config: UniDeskConfig, urls: PublicUrls, checks: E2
|
||||
|
||||
function databaseChecks(config: UniDeskConfig, checks: E2ECheck[]): string {
|
||||
const markerId = `e2e_${Date.now()}_${Math.random().toString(16).slice(2, 8)}`;
|
||||
const failedTaskId = `task_${markerId}_failed_diagnostic`;
|
||||
const markerSql = `
|
||||
CREATE TABLE IF NOT EXISTS unidesk_e2e_markers (
|
||||
id TEXT PRIMARY KEY,
|
||||
@@ -238,8 +239,20 @@ function databaseChecks(config: UniDeskConfig, checks: E2ECheck[]): string {
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
INSERT INTO unidesk_e2e_markers (id, source) VALUES ('${markerId}', 'cli-e2e');
|
||||
INSERT INTO unidesk_tasks (id, provider_id, command, status, payload, result, created_at, updated_at)
|
||||
VALUES (
|
||||
'${failedTaskId}',
|
||||
'${config.providerGateway.id}',
|
||||
'echo',
|
||||
'failed',
|
||||
'{"source":"cli-e2e","case":"history-diagnostics"}'::jsonb,
|
||||
'{"error":"e2e forced failure for diagnostics","exitCode":23,"stderr":"simulated provider failure"}'::jsonb,
|
||||
now() - interval '83 seconds',
|
||||
now()
|
||||
);
|
||||
SELECT 'marker=' || id FROM unidesk_e2e_markers WHERE id = '${markerId}';
|
||||
SELECT 'marker_count=' || count(*) FROM unidesk_e2e_markers;
|
||||
SELECT 'failed_task=' || id FROM unidesk_tasks WHERE id = '${failedTaskId}' AND status = 'failed';
|
||||
SELECT 'online_main_server=' || count(*) FROM unidesk_nodes WHERE provider_id = '${config.providerGateway.id}' AND status = 'online';
|
||||
`;
|
||||
const marker = runPsql(config, markerSql);
|
||||
@@ -267,6 +280,10 @@ async function frontendCheck(config: UniDeskConfig, urls: PublicUrls, checks: E2
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForSelector('[data-testid="app-shell"]', { timeout: 10000 });
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="conn-text"]')?.textContent?.includes("核心在线"), undefined, { timeout: 15000 });
|
||||
const landedUrl = page.url();
|
||||
const publicOrigin = new URL(urls.frontendUrl).origin;
|
||||
const landed = new URL(landedUrl);
|
||||
const publicFrontendReached = landed.origin === publicOrigin && !["127.0.0.1", "localhost", "::1"].includes(landed.hostname);
|
||||
await page.waitForSelector(`text=${config.providerGateway.id}`, { timeout: 10000 });
|
||||
await page.waitForSelector(`text=${config.providerGateway.name}`, { timeout: 10000 });
|
||||
await page.setViewportSize({ width: 390, height: 860 });
|
||||
@@ -301,6 +318,9 @@ async function frontendCheck(config: UniDeskConfig, urls: PublicUrls, checks: E2
|
||||
await page.getByTestId("pending-task-card").click();
|
||||
await page.waitForSelector('[data-testid="pending-task-page"]', { timeout: 5000 });
|
||||
const pendingTaskText = await page.locator('[data-testid="pending-task-page"]').innerText({ timeout: 5000 });
|
||||
await page.getByRole("button", { name: /任务历史/ }).click();
|
||||
await page.waitForSelector('[data-testid="task-history-page"]', { timeout: 5000 });
|
||||
const taskHistoryText = await page.locator('[data-testid="task-history-page"]').innerText({ timeout: 5000 });
|
||||
await page.getByRole("button", { name: /运行总览/ }).click();
|
||||
await page.getByRole("button", { name: /态势总览/ }).click();
|
||||
await page.screenshot({ path: screenshotPath, fullPage: true });
|
||||
@@ -332,9 +352,11 @@ async function frontendCheck(config: UniDeskConfig, urls: PublicUrls, checks: E2
|
||||
}, undefined, { timeout: 10000 });
|
||||
const dockerText = await page.locator('[data-testid="docker-status-page"]').innerText({ timeout: 5000 });
|
||||
addCheck(checks, "frontend:login-provider-visible", bodyText.includes(config.providerGateway.id) && bodyText.includes(config.providerGateway.name) && bodyText.includes("核心在线"), { screenshotPath });
|
||||
addCheck(checks, "frontend:public-provider-info-visible", publicFrontendReached && bodyText.includes(config.providerGateway.id) && bodyText.includes(config.providerGateway.name) && rawText.includes('"status": "online"') && rawText.includes(`"providerId": "${config.providerGateway.id}"`), { frontendUrl: urls.frontendUrl, landedUrl, providerId: config.providerGateway.id, rawTextPreview: rawText.slice(0, 400) });
|
||||
addCheck(checks, "frontend:mobile-nav-fixed-height", mobileRailMax - mobileRailMin <= 1 && mobileRailMax <= 44, { mobileRailHeights });
|
||||
addCheck(checks, "frontend:mobile-content-top-aligned", mobileContentMetrics.pageTop <= 190 && mobileContentMetrics.emptyTextOffset <= 14, { mobileContentMetrics });
|
||||
addCheck(checks, "frontend:pending-task-drilldown", pendingTaskText.includes("待处理任务") && (pendingTaskText.includes("当前无待处理任务") || (pendingTaskText.includes("Provider") && pendingTaskText.includes("已等待"))), { pendingTaskPreview: pendingTaskText.slice(0, 600) });
|
||||
addCheck(checks, "frontend:task-history-diagnostics", taskHistoryText.includes("任务耗时") && taskHistoryText.includes("诊断信息") && taskHistoryText.includes("失败原因") && taskHistoryText.includes("e2e forced failure for diagnostics"), { taskHistoryPreview: taskHistoryText.slice(0, 900) });
|
||||
addCheck(checks, "frontend:no-naked-json-before-click", rawBlocksBefore === 0 && !nakedJsonText, { rawBlocksBefore, nakedJsonText });
|
||||
addCheck(checks, "frontend:raw-json-explicit-button", rawText.includes('"providerId"') && rawText.includes(config.providerGateway.id), { rawTextPreview: rawText.slice(0, 400) });
|
||||
addCheck(checks, "frontend:system-monitor-visible", monitorText.includes("任务管理器视图") && monitorText.includes("CPU") && monitorText.includes("Memory") && monitorText.includes("Disk") && monitorText.includes("不含缓存"), { monitorTextPreview: monitorText.slice(0, 800) });
|
||||
|
||||
Reference in New Issue
Block a user