forked from longtao.wu/droboticflow
✨ Group artifacts and preview HTML reports
This commit is contained in:
parent
6866f5acc8
commit
f52fdc7819
@ -19,6 +19,20 @@ from .common import (
|
||||
|
||||
OPERATOR_ID = "ubt-quality-report"
|
||||
|
||||
RULE_LABELS = {
|
||||
"start_ts_mismatch": "起始时间戳不一致",
|
||||
"end_ts_mismatch": "结束时间戳不一致",
|
||||
"alignment_time_diff_out_of_range": "时间对齐偏差超限",
|
||||
"joint_jump_violation": "关节跳变",
|
||||
"joint_limit_violation": "关节限位异常",
|
||||
"gripper_position_out_of_range": "夹爪位置超范围",
|
||||
"master_slave_joint_mismatch": "主从关节偏差",
|
||||
"camera_fps_out_of_range": "相机帧率异常",
|
||||
"robot_state_fps_out_of_range": "机器人状态帧率异常",
|
||||
"ee_pose_mismatch": "末端位姿偏差",
|
||||
"gripper_state_mismatch": "夹爪状态不一致",
|
||||
}
|
||||
|
||||
|
||||
def _episode_results(artifacts: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
for item in artifacts:
|
||||
@ -57,6 +71,33 @@ def _date_statistics(results: list[dict[str, Any]]) -> dict[str, dict[str, int]]
|
||||
}
|
||||
|
||||
|
||||
def _quality_report_summary(
|
||||
status_counts: dict[str, int],
|
||||
rule_counts: Counter[str],
|
||||
total_count: int,
|
||||
) -> dict[str, Any]:
|
||||
success_count = status_counts.get("PASS", 0)
|
||||
return {
|
||||
"schemaVersion": 1,
|
||||
"kind": "quality",
|
||||
"title": "数据质量报告",
|
||||
"unit": "trajectory",
|
||||
"totalCount": total_count,
|
||||
"successCount": success_count,
|
||||
"failureCount": status_counts.get("ERROR", 0),
|
||||
"runtimeErrorCount": status_counts.get("RUNTIME_ERROR", 0),
|
||||
"successRate": success_count / total_count if total_count else 0.0,
|
||||
"issueHits": [
|
||||
{
|
||||
"code": code,
|
||||
"label": RULE_LABELS.get(code, code),
|
||||
"count": count,
|
||||
}
|
||||
for code, count in sorted(rule_counts.items())
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _manifest_entry(item: dict[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
"episode": item.get("episode"),
|
||||
@ -207,6 +248,11 @@ def run_report() -> None:
|
||||
"passRate": status_counts["PASS"] / len(results),
|
||||
"dateStatistics": _date_statistics(results),
|
||||
"ruleStatistics": dict(sorted(rule_counts.items())),
|
||||
"reportSummary": _quality_report_summary(
|
||||
status_counts,
|
||||
rule_counts,
|
||||
len(results),
|
||||
),
|
||||
"checkerSummary": checker_summary,
|
||||
}
|
||||
pass_manifest = {
|
||||
|
||||
@ -6,15 +6,18 @@ import {
|
||||
artifactContentPath,
|
||||
artifactDownloadLabel,
|
||||
artifactExtension,
|
||||
isHTMLArtifact,
|
||||
artifactPreviewCategory,
|
||||
artifactPreviewTitle,
|
||||
} from "../lib/artifact-download.js";
|
||||
import { summarizePocAcceptanceArtifact } from "../lib/poc-acceptance-summary.js";
|
||||
import { summarizeQualityReportArtifact } from "../lib/report-summary.js";
|
||||
import { LazyVideoPreview } from "./LazyVideoPreview";
|
||||
import { HoloBrainTrainingReportCard } from "./HoloBrainTrainingReportCard";
|
||||
import { PocAcceptanceSummaryCard } from "./PocAcceptanceSummaryCard";
|
||||
import { QualityReportSummaryCard } from "./QualityReportSummaryCard";
|
||||
import { buildAPIURL } from "../services/api/base-url.js";
|
||||
import { Download, ExternalLink } from "lucide-react";
|
||||
import { Code2, Download, ExternalLink, Eye, Loader2 } from "lucide-react";
|
||||
import { cn } from "../lib/utils";
|
||||
|
||||
const ObjModelPreview = lazy(() => import("./ObjModelPreview").then((module) => ({ default: module.ObjModelPreview })));
|
||||
@ -44,13 +47,13 @@ const derivedPreview = (item: ExecutionData) => {
|
||||
};
|
||||
|
||||
const artifactPreviewURL = (item: ExecutionData, preview: Record<string, any>) => {
|
||||
if (typeof preview.url === "string" && preview.url) {
|
||||
return preview.url;
|
||||
}
|
||||
const contentPath = artifactContentPath(item);
|
||||
if (contentPath) {
|
||||
return buildAPIURL(contentPath);
|
||||
}
|
||||
if (typeof preview.url === "string" && preview.url) {
|
||||
return preview.url;
|
||||
}
|
||||
const source = item.data?.source;
|
||||
if (source && typeof source === "object") {
|
||||
if (typeof source.previewURL === "string" && source.previewURL) {
|
||||
@ -116,11 +119,13 @@ function TextContentPreview({
|
||||
previewURL,
|
||||
inlineText,
|
||||
fullscreen = false,
|
||||
showActions = true,
|
||||
}: {
|
||||
item: ExecutionData;
|
||||
previewURL: string;
|
||||
inlineText?: string;
|
||||
fullscreen?: boolean;
|
||||
showActions?: boolean;
|
||||
}) {
|
||||
const [state, setState] = useState<{
|
||||
status: "idle" | "loading" | "ready" | "error";
|
||||
@ -175,7 +180,7 @@ function TextContentPreview({
|
||||
<div className="text-sm font-semibold text-white">{artifactPreviewTitle(item)}</div>
|
||||
<div className="text-xs uppercase tracking-wide text-gray-500">{language}</div>
|
||||
</div>
|
||||
<ArtifactActions item={item} />
|
||||
{showActions ? <ArtifactActions item={item} /> : null}
|
||||
</div>
|
||||
{state.status === "loading" ? (
|
||||
<div className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-4 text-sm text-gray-400">正在加载预览...</div>
|
||||
@ -202,6 +207,128 @@ function TextContentPreview({
|
||||
);
|
||||
}
|
||||
|
||||
function HTMLArtifactPreview({
|
||||
item,
|
||||
previewURL,
|
||||
inlineText,
|
||||
fullscreen,
|
||||
}: {
|
||||
item: ExecutionData;
|
||||
previewURL: string;
|
||||
inlineText?: string;
|
||||
fullscreen: boolean;
|
||||
}) {
|
||||
const [mode, setMode] = useState<"report" | "source">("report");
|
||||
const [frameStatus, setFrameStatus] = useState<"loading" | "ready" | "error">(previewURL ? "loading" : "error");
|
||||
const [verifiedFrameURL, setVerifiedFrameURL] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
setMode("report");
|
||||
setVerifiedFrameURL("");
|
||||
if (!previewURL) {
|
||||
setFrameStatus("error");
|
||||
return;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
setFrameStatus("loading");
|
||||
fetch(previewURL, {
|
||||
method: "HEAD",
|
||||
credentials: "include",
|
||||
signal: controller.signal,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
setVerifiedFrameURL(previewURL);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
if (error.name !== "AbortError") {
|
||||
setFrameStatus("error");
|
||||
}
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [item.id, previewURL]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#0f1012]",
|
||||
fullscreen && "flex h-full min-h-[65vh] flex-col",
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-[#2a2b2f] p-3">
|
||||
<div className="flex rounded-lg border border-[#2a2b2f] bg-black/20 p-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("report")}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",
|
||||
mode === "report" ? "bg-blue-600 text-white" : "text-gray-400 hover:text-white",
|
||||
)}
|
||||
>
|
||||
<Eye className="h-3.5 w-3.5" />
|
||||
报告预览
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("source")}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",
|
||||
mode === "source" ? "bg-blue-600 text-white" : "text-gray-400 hover:text-white",
|
||||
)}
|
||||
>
|
||||
<Code2 className="h-3.5 w-3.5" />
|
||||
查看源码
|
||||
</button>
|
||||
</div>
|
||||
<ArtifactActions item={item} />
|
||||
</div>
|
||||
|
||||
{mode === "source" ? (
|
||||
<div className={cn("p-3", fullscreen && "min-h-0 flex-1")}>
|
||||
<TextContentPreview
|
||||
item={item}
|
||||
previewURL={previewURL}
|
||||
inlineText={inlineText}
|
||||
fullscreen={fullscreen}
|
||||
showActions={false}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className={cn("relative bg-white", fullscreen ? "min-h-0 flex-1" : "h-[520px]")}>
|
||||
{verifiedFrameURL === previewURL ? (
|
||||
<iframe
|
||||
key={`${item.id}-${previewURL}`}
|
||||
src={previewURL}
|
||||
sandbox=""
|
||||
referrerPolicy="no-referrer"
|
||||
title={`${item.name} 报告预览`}
|
||||
className="h-full w-full bg-white"
|
||||
onLoad={() => setFrameStatus("ready")}
|
||||
onError={() => setFrameStatus("error")}
|
||||
/>
|
||||
) : null}
|
||||
{frameStatus === "loading" ? (
|
||||
<div className="absolute inset-0 flex items-center justify-center gap-2 bg-[#0f1012] text-sm text-gray-400">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-blue-400" />
|
||||
正在渲染报告...
|
||||
</div>
|
||||
) : null}
|
||||
{frameStatus === "error" ? (
|
||||
<div className="absolute inset-0 flex flex-col items-center justify-center gap-2 bg-[#0f1012] px-6 text-center">
|
||||
<div className="text-sm font-semibold text-red-200">报告预览加载失败</div>
|
||||
<div className="max-w-md text-xs leading-5 text-gray-500">
|
||||
当前产物没有可用的内容地址,或浏览器无法渲染该文件。仍可查看源码、打开原文件或下载产物。
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function FileSummaryPreview({ item }: { item: ExecutionData }) {
|
||||
const ext = artifactExtension(item) || "-";
|
||||
const mimeType = item.metadata?.mimeType || "-";
|
||||
@ -248,6 +375,7 @@ export function ArtifactPreviewPanel({
|
||||
const playablePreviewURL = preview?.kind === "video" ? buildBrowserPlayableVideoURL(previewURL) : previewURL;
|
||||
const holoBrainSummary = item ? summarizeHoloBrainArtifact(item) : null;
|
||||
const pocAcceptanceSummary = item ? summarizePocAcceptanceArtifact(item) : null;
|
||||
const qualityReportSummary = item ? summarizeQualityReportArtifact(item) : null;
|
||||
|
||||
if (!item) {
|
||||
return (
|
||||
@ -257,6 +385,17 @@ export function ArtifactPreviewPanel({
|
||||
);
|
||||
}
|
||||
|
||||
if (isHTMLArtifact(item)) {
|
||||
return (
|
||||
<HTMLArtifactPreview
|
||||
item={item}
|
||||
previewURL={previewURL}
|
||||
inlineText={!preview.truncated && typeof preview.text === "string" ? preview.text : undefined}
|
||||
fullscreen={fullscreen}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "image" && previewURL) {
|
||||
return (
|
||||
<div
|
||||
@ -377,6 +516,17 @@ export function ArtifactPreviewPanel({
|
||||
);
|
||||
}
|
||||
|
||||
if (qualityReportSummary) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex justify-end">
|
||||
<ArtifactActions item={item} />
|
||||
</div>
|
||||
<QualityReportSummaryCard item={item} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "table" && Array.isArray(preview.rows)) {
|
||||
const columns = Array.isArray(preview.columns) ? preview.columns : [];
|
||||
return (
|
||||
@ -420,7 +570,7 @@ export function ArtifactPreviewPanel({
|
||||
<TextContentPreview
|
||||
item={item}
|
||||
previewURL={previewURL}
|
||||
inlineText={typeof preview.text === "string" ? preview.text : undefined}
|
||||
inlineText={!preview.truncated && typeof preview.text === "string" ? preview.text : undefined}
|
||||
fullscreen={fullscreen}
|
||||
/>
|
||||
);
|
||||
@ -431,7 +581,7 @@ export function ArtifactPreviewPanel({
|
||||
<TextContentPreview
|
||||
item={item}
|
||||
previewURL={previewURL}
|
||||
inlineText={typeof preview.text === "string" ? preview.text : undefined}
|
||||
inlineText={!preview.truncated && typeof preview.text === "string" ? preview.text : undefined}
|
||||
fullscreen={fullscreen}
|
||||
/>
|
||||
);
|
||||
|
||||
77
src/components/QualityReportSummaryCard.tsx
Normal file
77
src/components/QualityReportSummaryCard.tsx
Normal file
@ -0,0 +1,77 @@
|
||||
import { AlertTriangle, CheckCircle2, CircleSlash2, Gauge } from "lucide-react";
|
||||
import type { ExecutionData } from "../types";
|
||||
import { qualityReportUnitLabel, summarizeQualityReportArtifact } from "../lib/report-summary.js";
|
||||
|
||||
const formatCount = (value: number) => new Intl.NumberFormat("zh-CN").format(value);
|
||||
|
||||
export function QualityReportSummaryCard({ item }: { item: ExecutionData }) {
|
||||
const summary = summarizeQualityReportArtifact(item);
|
||||
if (!summary) {
|
||||
return null;
|
||||
}
|
||||
const unitLabel = qualityReportUnitLabel(summary.unit);
|
||||
const cards = [
|
||||
{ label: `总${unitLabel}数`, value: formatCount(summary.totalCount), icon: Gauge, tone: "text-blue-300" },
|
||||
{ label: "通过", value: formatCount(summary.successCount), icon: CheckCircle2, tone: "text-emerald-300" },
|
||||
{ label: "失败", value: formatCount(summary.failureCount), icon: AlertTriangle, tone: "text-amber-300" },
|
||||
{
|
||||
label: "运行错误",
|
||||
value: formatCount(summary.runtimeErrorCount),
|
||||
icon: CircleSlash2,
|
||||
tone: "text-red-300",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="space-y-4 rounded-xl border border-[#2a2b2f] bg-[#0f1012] p-4">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h5 className="text-base font-semibold text-white">{summary.title}</h5>
|
||||
<p className="mt-1 text-xs text-gray-500">结构化质量摘要 · {unitLabel}为主统计单位</p>
|
||||
</div>
|
||||
<div className="rounded-lg border border-emerald-500/20 bg-emerald-500/10 px-3 py-2 text-right">
|
||||
<div className="text-[10px] uppercase tracking-wide text-emerald-200/70">通过率</div>
|
||||
<div className="text-xl font-bold text-emerald-300">{(summary.successRate * 100).toFixed(2)}%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 xl:grid-cols-4">
|
||||
{cards.map(({ label, value, icon: Icon, tone }) => (
|
||||
<div key={label} className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-3">
|
||||
<div className="flex items-center gap-2 text-xs text-gray-500">
|
||||
<Icon className={`h-3.5 w-3.5 ${tone}`} />
|
||||
{label}
|
||||
</div>
|
||||
<div className={`mt-2 text-xl font-semibold ${tone}`}>{value}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{summary.issueHits.length > 0 ? (
|
||||
<div className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-3">
|
||||
<div className="text-xs font-semibold text-gray-200">规则命中次数</div>
|
||||
<div className="mt-1 text-[11px] text-gray-500">
|
||||
同一{unitLabel}可命中多条规则,不等同于失败{unitLabel}数。
|
||||
</div>
|
||||
<div className="mt-3 grid gap-2 sm:grid-cols-2">
|
||||
{summary.issueHits
|
||||
.slice()
|
||||
.sort((left: { count: number }, right: { count: number }) => right.count - left.count)
|
||||
.map((issue: { code: string; label: string; count: number }) => (
|
||||
<div
|
||||
key={issue.code}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-[#292b30] bg-black/20 px-3 py-2"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-xs text-gray-200">{issue.label}</div>
|
||||
<div className="truncate font-mono text-[10px] text-gray-600">{issue.code}</div>
|
||||
</div>
|
||||
<div className="shrink-0 font-mono text-sm text-amber-300">{formatCount(issue.count)}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,5 +1,36 @@
|
||||
const MODEL_EXTENSIONS = new Set(["bin", "ckpt", "gguf", "h5", "hdf5", "joblib", "json", "mar", "mlmodel", "npz", "onnx", "pkl", "pt", "pth", "safetensors"]);
|
||||
const ASSET_3D_EXTENSIONS = new Set(["dae", "fbx", "glb", "gltf", "mjcf", "mtl", "obj", "ply", "stl", "urdf", "usd", "usda", "usdc", "xml"]);
|
||||
const MODEL_EXTENSIONS = new Set([
|
||||
"bin",
|
||||
"ckpt",
|
||||
"gguf",
|
||||
"h5",
|
||||
"hdf5",
|
||||
"joblib",
|
||||
"json",
|
||||
"mar",
|
||||
"mlmodel",
|
||||
"npz",
|
||||
"onnx",
|
||||
"pkl",
|
||||
"pt",
|
||||
"pth",
|
||||
"safetensors",
|
||||
]);
|
||||
const ASSET_3D_EXTENSIONS = new Set([
|
||||
"dae",
|
||||
"fbx",
|
||||
"glb",
|
||||
"gltf",
|
||||
"mjcf",
|
||||
"mtl",
|
||||
"obj",
|
||||
"ply",
|
||||
"stl",
|
||||
"urdf",
|
||||
"usd",
|
||||
"usda",
|
||||
"usdc",
|
||||
"xml",
|
||||
]);
|
||||
const TEXT_EXTENSIONS = new Set([
|
||||
"cfg",
|
||||
"conf",
|
||||
@ -20,11 +51,40 @@ const TEXT_EXTENSIONS = new Set([
|
||||
"yaml",
|
||||
"yml",
|
||||
]);
|
||||
const STRUCTURED_TEXT_EXTENSIONS = new Set(["json", "jsonl", "xml", "html", "htm", "gltf", "obj", "mtl", "urdf", "mjcf", "dae", "usd", "usda"]);
|
||||
const STRUCTURED_TEXT_EXTENSIONS = new Set([
|
||||
"json",
|
||||
"jsonl",
|
||||
"xml",
|
||||
"html",
|
||||
"htm",
|
||||
"gltf",
|
||||
"obj",
|
||||
"mtl",
|
||||
"urdf",
|
||||
"mjcf",
|
||||
"dae",
|
||||
"usd",
|
||||
"usda",
|
||||
]);
|
||||
const TABLE_EXTENSIONS = new Set(["csv", "tsv", "jsonl"]);
|
||||
const DOCUMENT_EXTENSIONS = new Set(["pdf"]);
|
||||
const HTML_EXTENSIONS = new Set(["html", "htm"]);
|
||||
const ARCHIVE_EXTENSIONS = new Set(["7z", "gz", "tar", "tgz", "zip"]);
|
||||
const DATASET_EXTENSIONS = new Set(["bag", "db", "db3", "h5", "hdf5", "mcap", "npy", "npz", "parquet", "pkl", "sqlite", "tfrecord", "zarr"]);
|
||||
const DATASET_EXTENSIONS = new Set([
|
||||
"bag",
|
||||
"db",
|
||||
"db3",
|
||||
"h5",
|
||||
"hdf5",
|
||||
"mcap",
|
||||
"npy",
|
||||
"npz",
|
||||
"parquet",
|
||||
"pkl",
|
||||
"sqlite",
|
||||
"tfrecord",
|
||||
"zarr",
|
||||
]);
|
||||
|
||||
export function artifactExtension(item) {
|
||||
const source = item?.name || item?.path || "";
|
||||
@ -106,6 +166,12 @@ export function isTextPreviewArtifact(item) {
|
||||
return TEXT_EXTENSIONS.has(ext) || STRUCTURED_TEXT_EXTENSIONS.has(ext);
|
||||
}
|
||||
|
||||
export function isHTMLArtifact(item) {
|
||||
const ext = artifactExtension(item);
|
||||
const mimeType = artifactMimeType(item);
|
||||
return HTML_EXTENSIONS.has(ext) || mimeType === "text/html" || mimeType === "application/xhtml+xml";
|
||||
}
|
||||
|
||||
export function artifactPreviewCategory(item) {
|
||||
const ext = artifactExtension(item);
|
||||
const mimeType = artifactMimeType(item);
|
||||
@ -114,17 +180,20 @@ export function artifactPreviewCategory(item) {
|
||||
if (mimeType.startsWith("video/") || item?.type === "video") return "video";
|
||||
if (mimeType.startsWith("audio/")) return "audio";
|
||||
if (DOCUMENT_EXTENSIONS.has(ext)) return "document";
|
||||
if (isHTMLArtifact(item)) return "html";
|
||||
if (TABLE_EXTENSIONS.has(ext)) return "table";
|
||||
if (isTextPreviewArtifact(item)) return "text";
|
||||
if (is3DAssetArtifact(item)) return "3d";
|
||||
if (isModelArtifact(item)) return "model";
|
||||
if (DATASET_EXTENSIONS.has(ext) || datasetType.includes("dataset") || datasetType.includes("rosbag")) return "dataset";
|
||||
if (DATASET_EXTENSIONS.has(ext) || datasetType.includes("dataset") || datasetType.includes("rosbag"))
|
||||
return "dataset";
|
||||
if (ARCHIVE_EXTENSIONS.has(ext)) return "archive";
|
||||
return "file";
|
||||
}
|
||||
|
||||
export function artifactPreviewTitle(item) {
|
||||
const category = artifactPreviewCategory(item);
|
||||
if (category === "html") return "HTML 报告";
|
||||
if (category === "3d") return "3D 资产";
|
||||
if (category === "model") return "模型文件";
|
||||
if (category === "dataset") return "数据集文件";
|
||||
|
||||
109
src/lib/artifact-groups.js
Normal file
109
src/lib/artifact-groups.js
Normal file
@ -0,0 +1,109 @@
|
||||
import { artifactExtension } from "./artifact-download.js";
|
||||
import { summarizeQualityReportArtifact } from "./report-summary.js";
|
||||
|
||||
export const ARTIFACT_GROUP_ORDER = ["final", "intermediate", "input"];
|
||||
|
||||
export const ARTIFACT_GROUP_LABELS = {
|
||||
final: "最终结果",
|
||||
intermediate: "中间产物",
|
||||
input: "输入数据",
|
||||
};
|
||||
|
||||
const artifactPriority = (item) => {
|
||||
if (summarizeQualityReportArtifact(item)) return 0;
|
||||
const extension = artifactExtension(item);
|
||||
if (extension === "html" || extension === "htm" || extension === "pdf") return 1;
|
||||
if (item?.type === "json" || extension === "json") return 2;
|
||||
return 3;
|
||||
};
|
||||
|
||||
export const sortArtifactsForDisplay = (items) =>
|
||||
[...items].sort((left, right) => {
|
||||
const priority = artifactPriority(left) - artifactPriority(right);
|
||||
if (priority !== 0) return priority;
|
||||
return String(left?.name || "").localeCompare(String(right?.name || ""), "zh-CN");
|
||||
});
|
||||
|
||||
const emptyGroups = () => ({
|
||||
final: [],
|
||||
intermediate: [],
|
||||
input: [],
|
||||
});
|
||||
|
||||
const appendNodeArtifact = (groups, kind, node, artifact) => {
|
||||
let group = groups[kind].find((item) => item.nodeId === node.nodeId);
|
||||
if (!group) {
|
||||
group = {
|
||||
nodeId: node.nodeId,
|
||||
nodeLabel: node.nodeLabel || node.nodeId || "未知节点",
|
||||
artifacts: [],
|
||||
};
|
||||
groups[kind].push(group);
|
||||
}
|
||||
group.artifacts.push(artifact);
|
||||
};
|
||||
|
||||
export function groupArtifactsByLineage(artifacts = [], lineage) {
|
||||
const items = Array.isArray(artifacts) ? artifacts : [];
|
||||
const nodes = Array.isArray(lineage?.nodes) ? lineage.nodes : [];
|
||||
if (nodes.length === 0) {
|
||||
return {
|
||||
hasLineage: false,
|
||||
groups: {
|
||||
...emptyGroups(),
|
||||
final: [
|
||||
{
|
||||
nodeId: "legacy",
|
||||
nodeLabel: "运行产物",
|
||||
artifacts: sortArtifactsForDisplay(items),
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const incoming = new Set();
|
||||
const outgoing = new Set();
|
||||
for (const edge of Array.isArray(lineage?.edges) ? lineage.edges : []) {
|
||||
if (edge?.sourceNodeId) outgoing.add(edge.sourceNodeId);
|
||||
if (edge?.targetNodeId) incoming.add(edge.targetNodeId);
|
||||
}
|
||||
const nodeById = new Map(nodes.map((node) => [node.nodeId, node]));
|
||||
const kindByNodeId = new Map(
|
||||
nodes.map((node) => {
|
||||
if (!outgoing.has(node.nodeId)) return [node.nodeId, "final"];
|
||||
if (!incoming.has(node.nodeId)) return [node.nodeId, "input"];
|
||||
return [node.nodeId, "intermediate"];
|
||||
}),
|
||||
);
|
||||
const groups = emptyGroups();
|
||||
for (const artifact of items) {
|
||||
const node = nodeById.get(artifact?.nodeId) || {
|
||||
nodeId: artifact?.nodeId || "legacy",
|
||||
nodeLabel: artifact?.nodeId || "运行产物",
|
||||
};
|
||||
const kind = kindByNodeId.get(node.nodeId) || "final";
|
||||
appendNodeArtifact(groups, kind, node, artifact);
|
||||
}
|
||||
for (const kind of ARTIFACT_GROUP_ORDER) {
|
||||
groups[kind] = groups[kind]
|
||||
.map((group) => ({ ...group, artifacts: sortArtifactsForDisplay(group.artifacts) }))
|
||||
.sort((left, right) => left.nodeLabel.localeCompare(right.nodeLabel, "zh-CN"));
|
||||
}
|
||||
return { hasLineage: true, groups };
|
||||
}
|
||||
|
||||
export function preferredArtifact(grouped, kinds = ARTIFACT_GROUP_ORDER) {
|
||||
for (const kind of kinds) {
|
||||
for (const node of grouped?.groups?.[kind] || []) {
|
||||
if (node.artifacts.length > 0) {
|
||||
return node.artifacts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function artifactGroupCount(groups, kind) {
|
||||
return (groups?.[kind] || []).reduce((total, node) => total + node.artifacts.length, 0);
|
||||
}
|
||||
120
src/lib/report-summary.js
Normal file
120
src/lib/report-summary.js
Normal file
@ -0,0 +1,120 @@
|
||||
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
|
||||
const finiteNumber = (value) => {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) && number >= 0 ? number : undefined;
|
||||
};
|
||||
|
||||
const normalizedIssueHits = (value) => {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
return value
|
||||
.map((item) => {
|
||||
if (!isObject(item)) {
|
||||
return null;
|
||||
}
|
||||
const count = finiteNumber(item.count);
|
||||
const code = String(item.code || "").trim();
|
||||
if (!code || count === undefined) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
code,
|
||||
label: String(item.label || code).trim() || code,
|
||||
count,
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const normalizeExplicitSummary = (value) => {
|
||||
if (!isObject(value) || value.kind !== "quality") {
|
||||
return null;
|
||||
}
|
||||
const totalCount = finiteNumber(value.totalCount);
|
||||
const successCount = finiteNumber(value.successCount);
|
||||
const failureCount = finiteNumber(value.failureCount);
|
||||
const runtimeErrorCount = finiteNumber(value.runtimeErrorCount) ?? 0;
|
||||
if (totalCount === undefined || successCount === undefined || failureCount === undefined) {
|
||||
return null;
|
||||
}
|
||||
const explicitRate = finiteNumber(value.successRate);
|
||||
return {
|
||||
schemaVersion: finiteNumber(value.schemaVersion) || 1,
|
||||
kind: "quality",
|
||||
title: String(value.title || "数据质量报告"),
|
||||
unit: String(value.unit || "item"),
|
||||
totalCount,
|
||||
successCount,
|
||||
failureCount,
|
||||
runtimeErrorCount,
|
||||
successRate: explicitRate === undefined ? (totalCount > 0 ? successCount / totalCount : 0) : explicitRate,
|
||||
issueHits: normalizedIssueHits(value.issueHits),
|
||||
};
|
||||
};
|
||||
|
||||
const legacySummary = (value) => {
|
||||
if (!isObject(value) || !isObject(value.statusCounts)) {
|
||||
return null;
|
||||
}
|
||||
const totalCount = finiteNumber(value.totalEpisodes);
|
||||
const successCount = finiteNumber(value.statusCounts.PASS);
|
||||
const failureCount = finiteNumber(value.statusCounts.ERROR);
|
||||
const runtimeErrorCount = finiteNumber(value.statusCounts.RUNTIME_ERROR) ?? 0;
|
||||
if (totalCount === undefined || successCount === undefined || failureCount === undefined) {
|
||||
return null;
|
||||
}
|
||||
const issueHits = isObject(value.ruleStatistics)
|
||||
? Object.entries(value.ruleStatistics)
|
||||
.map(([code, count]) => {
|
||||
const normalizedCount = finiteNumber(count);
|
||||
return normalizedCount === undefined ? null : { code, label: code, count: normalizedCount };
|
||||
})
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const successRate = finiteNumber(value.passRate);
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
kind: "quality",
|
||||
title: "数据质量报告",
|
||||
unit: "trajectory",
|
||||
totalCount,
|
||||
successCount,
|
||||
failureCount,
|
||||
runtimeErrorCount,
|
||||
successRate: successRate === undefined ? (totalCount > 0 ? successCount / totalCount : 0) : successRate,
|
||||
issueHits,
|
||||
legacy: true,
|
||||
};
|
||||
};
|
||||
|
||||
const candidatePayloads = (item) => {
|
||||
const data = isObject(item?.data) ? item.data : {};
|
||||
const preview = isObject(data.preview) ? data.preview : {};
|
||||
const previewValue = isObject(preview.value) ? preview.value : {};
|
||||
return [data.reportSummary, previewValue.reportSummary, data, previewValue];
|
||||
};
|
||||
|
||||
export function summarizeQualityReportArtifact(item) {
|
||||
for (const candidate of candidatePayloads(item)) {
|
||||
const explicit = normalizeExplicitSummary(candidate);
|
||||
if (explicit) {
|
||||
return explicit;
|
||||
}
|
||||
}
|
||||
for (const candidate of candidatePayloads(item)) {
|
||||
const legacy = legacySummary(candidate);
|
||||
if (legacy) {
|
||||
return legacy;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function qualityReportUnitLabel(unit) {
|
||||
if (unit === "trajectory") return "轨迹";
|
||||
if (unit === "episode") return "片段";
|
||||
if (unit === "file") return "文件";
|
||||
return "项";
|
||||
}
|
||||
@ -3,8 +3,19 @@ import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { formatClockTime, formatCompactDateTime } from "../lib/datetime";
|
||||
import { copyText } from "../lib/clipboard.js";
|
||||
import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js";
|
||||
import { artifactContentPath, artifactDownloadLabel } from "../lib/artifact-download.js";
|
||||
import {
|
||||
artifactContentPath,
|
||||
artifactDownloadLabel,
|
||||
artifactExtension,
|
||||
artifactPreviewCategory,
|
||||
} from "../lib/artifact-download.js";
|
||||
import {
|
||||
ARTIFACT_GROUP_LABELS,
|
||||
ARTIFACT_GROUP_ORDER,
|
||||
artifactGroupCount,
|
||||
groupArtifactsByLineage,
|
||||
preferredArtifact,
|
||||
} from "../lib/artifact-groups.js";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import { dedupeRunLogs } from "../lib/run-logs.js";
|
||||
import { buildAPIURL } from "../services/api/base-url.js";
|
||||
@ -13,8 +24,8 @@ import {
|
||||
pocAcceptanceSecondaryLabel,
|
||||
summarizePocAcceptanceArtifact,
|
||||
} from "../lib/poc-acceptance-summary.js";
|
||||
import { LazyVideoPreview } from "../components/LazyVideoPreview";
|
||||
import { PocAcceptanceSummaryCard } from "../components/PocAcceptanceSummaryCard";
|
||||
import { summarizeQualityReportArtifact } from "../lib/report-summary.js";
|
||||
import { ArtifactPreviewPanel } from "../components/ArtifactPreviewPanel";
|
||||
import {
|
||||
Play,
|
||||
CheckCircle2,
|
||||
@ -28,7 +39,6 @@ import {
|
||||
Filter,
|
||||
X,
|
||||
Loader2,
|
||||
ExternalLink,
|
||||
Download,
|
||||
FileJson,
|
||||
FileVideo,
|
||||
@ -59,19 +69,11 @@ const formatDuration = (durationMs?: number) => {
|
||||
return `${minutes}m ${seconds}s`;
|
||||
};
|
||||
|
||||
const hasDirectArtifactURL = (item: ExecutionData) => /^https?:\/\//i.test(item.path);
|
||||
|
||||
const artifactDownloadURL = (item: ExecutionData) => {
|
||||
const path = artifactContentPath(item, { download: true });
|
||||
return path ? buildAPIURL(path) : "";
|
||||
};
|
||||
|
||||
const artifactExtension = (item: ExecutionData) => {
|
||||
const source = item.name || item.path || "";
|
||||
const parts = source.split(".");
|
||||
return parts.length > 1 ? parts[parts.length - 1].toLowerCase() : "";
|
||||
};
|
||||
|
||||
type ModalType = "logs" | "resources" | "data" | "lineage";
|
||||
|
||||
type ArtifactPreview = {
|
||||
@ -115,7 +117,10 @@ const derivedPreview = (item: ExecutionData) => {
|
||||
if (ext === "pdf") {
|
||||
return { kind: "document", format: "pdf" };
|
||||
}
|
||||
if (["txt", "md", "log", "yaml", "yml", "xml", "html", "htm"].includes(ext)) {
|
||||
if (["html", "htm"].includes(ext)) {
|
||||
return { kind: "html", format: ext };
|
||||
}
|
||||
if (["txt", "md", "log", "yaml", "yml", "xml"].includes(ext)) {
|
||||
return { kind: "text", format: ext };
|
||||
}
|
||||
if (["csv", "tsv", "jsonl"].includes(ext)) {
|
||||
@ -139,6 +144,9 @@ const artifactKindLabel = (item: ExecutionData) => {
|
||||
if (preview.kind === "text") {
|
||||
return String(preview.format || "text").toUpperCase();
|
||||
}
|
||||
if (preview.kind === "html") {
|
||||
return "HTML 报告";
|
||||
}
|
||||
if (preview.kind === "document") {
|
||||
return String(preview.format || "document").toUpperCase();
|
||||
}
|
||||
@ -167,19 +175,28 @@ const artifactSecondaryLabel = (item: ExecutionData) => {
|
||||
return preview.format || item.metadata?.mimeType || "dataset";
|
||||
}
|
||||
if (preview.kind === "table") {
|
||||
return `${preview.rowCount ?? "--"} rows`;
|
||||
return typeof preview.rowCount === "number"
|
||||
? `${preview.rowCount} 行`
|
||||
: item.metadata?.mimeType || item.portName || "表格数据";
|
||||
}
|
||||
if (preview.kind === "text") {
|
||||
return `${preview.lineCount ?? "--"} lines`;
|
||||
return typeof preview.lineCount === "number"
|
||||
? `${preview.lineCount} 行`
|
||||
: item.metadata?.mimeType || item.portName || "文本内容";
|
||||
}
|
||||
return item.metadata?.resolution || item.metadata?.mimeType || item.portName || "N/A";
|
||||
if (preview.kind === "html") {
|
||||
return typeof preview.lineCount === "number"
|
||||
? `${preview.lineCount} 行`
|
||||
: item.metadata?.mimeType || item.portName || "可阅读报告";
|
||||
}
|
||||
return item.metadata?.resolution || item.metadata?.mimeType || item.portName || "无附加信息";
|
||||
};
|
||||
|
||||
const renderArtifactIcon = (item: ExecutionData) => {
|
||||
if (summarizePocAcceptanceArtifact(item)) {
|
||||
if (summarizePocAcceptanceArtifact(item) || summarizeQualityReportArtifact(item)) {
|
||||
return <CheckCircle2 className="w-5 h-5" />;
|
||||
}
|
||||
const kind = derivedPreview(item).kind;
|
||||
const kind = artifactPreviewCategory(item);
|
||||
if (kind === "dataset") {
|
||||
return <Database className="w-5 h-5" />;
|
||||
}
|
||||
@ -189,7 +206,7 @@ const renderArtifactIcon = (item: ExecutionData) => {
|
||||
if (kind === "image") {
|
||||
return <FileBox className="w-5 h-5" />;
|
||||
}
|
||||
if (item.type === "json" || kind === "json") {
|
||||
if (item.type === "json") {
|
||||
return <FileJson className="w-5 h-5" />;
|
||||
}
|
||||
return <FileText className="w-5 h-5" />;
|
||||
@ -200,6 +217,120 @@ const compactArtifactLabel = (item: ExecutionData) => {
|
||||
return port ? `${item.name} (${port})` : item.name;
|
||||
};
|
||||
|
||||
function ArtifactListItem({
|
||||
item,
|
||||
selected,
|
||||
onSelect,
|
||||
onCopyPath,
|
||||
}: {
|
||||
item: ExecutionData;
|
||||
selected: boolean;
|
||||
onSelect: () => void;
|
||||
onCopyPath: () => void;
|
||||
}) {
|
||||
const sizeLabel = item.size?.trim() || "大小未知";
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={onSelect}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
onSelect();
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"group flex cursor-pointer items-center justify-between gap-3 rounded-xl border bg-[#0a0a0a] p-3 transition-all",
|
||||
selected ? "border-blue-500 bg-blue-500/5" : "border-[#2a2b2f] hover:border-blue-500/50",
|
||||
)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-white/5 text-gray-400 transition-colors group-hover:text-blue-500">
|
||||
{renderArtifactIcon(item)}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm font-bold text-white">{item.name}</div>
|
||||
<div className="mt-0.5 truncate font-mono text-[10px] text-gray-500">
|
||||
{sizeLabel} · {artifactSecondaryLabel(item)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{item.portName ? (
|
||||
<span className="hidden rounded border border-blue-500/20 bg-blue-500/10 px-2 py-1 font-mono text-[10px] text-blue-300 xl:inline">
|
||||
{item.portName}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="rounded border border-[#2a2b2f] bg-white/5 px-2 py-1 font-mono text-[10px] text-gray-400">
|
||||
{artifactKindLabel(item)}
|
||||
</span>
|
||||
{artifactDownloadURL(item) ? (
|
||||
<a
|
||||
href={artifactDownloadURL(item)}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
className="rounded-lg p-2 text-gray-400 transition-colors hover:bg-white/5 hover:text-white"
|
||||
title={artifactDownloadLabel(item)}
|
||||
>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
</a>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCopyPath();
|
||||
}}
|
||||
className="rounded-lg p-2 text-gray-400 transition-colors hover:bg-white/5 hover:text-white"
|
||||
title="复制存储路径"
|
||||
>
|
||||
<Database className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ArtifactNodeSection({
|
||||
node,
|
||||
defaultOpen,
|
||||
selectedArtifactId,
|
||||
onSelect,
|
||||
onCopyPath,
|
||||
}: {
|
||||
node: { nodeId: string; nodeLabel: string; artifacts: ExecutionData[] };
|
||||
defaultOpen: boolean;
|
||||
selectedArtifactId?: string;
|
||||
onSelect: (item: ExecutionData) => void;
|
||||
onCopyPath: (path: string) => void;
|
||||
}) {
|
||||
const [open, setOpen] = useState(defaultOpen);
|
||||
return (
|
||||
<details
|
||||
open={open}
|
||||
onToggle={(event) => setOpen(event.currentTarget.open)}
|
||||
className="rounded-xl border border-[#24262a] bg-black/10 p-2"
|
||||
>
|
||||
<summary className="cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-gray-400">
|
||||
{node.nodeLabel}
|
||||
<span className="ml-2 text-[10px] text-gray-600">{node.artifacts.length}</span>
|
||||
</summary>
|
||||
<div className="mt-2 space-y-2">
|
||||
{node.artifacts.map((item) => (
|
||||
<div key={item.id}>
|
||||
<ArtifactListItem
|
||||
item={item}
|
||||
selected={selectedArtifactId === item.id}
|
||||
onSelect={() => onSelect(item)}
|
||||
onCopyPath={() => onCopyPath(item.path)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
const formatResourceMemory = (value?: number | null) => {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) {
|
||||
return "N/A";
|
||||
@ -242,6 +373,7 @@ export default function Monitoring() {
|
||||
}>({});
|
||||
const [modalError, setModalError] = useState("");
|
||||
const [selectedArtifact, setSelectedArtifact] = useState<ExecutionData | null>(null);
|
||||
const [artifactView, setArtifactView] = useState<"final" | "all">("final");
|
||||
const [artifactLineage, setArtifactLineage] = useState<ArtifactLineage | null>(null);
|
||||
const [artifactLineageLoading, setArtifactLineageLoading] = useState(false);
|
||||
const [artifactLineageError, setArtifactLineageError] = useState("");
|
||||
@ -360,6 +492,15 @@ export default function Monitoring() {
|
||||
);
|
||||
const hasGpuSeries = resourceChartData.length > 0;
|
||||
const hasGpuMemorySeries = resourceChartData.some((sample) => typeof sample.gpuMemoryUsedMiB === "number");
|
||||
const groupedArtifacts = useMemo(
|
||||
() => groupArtifactsByLineage(modalData.data || [], modalData.lineage),
|
||||
[modalData.data, modalData.lineage],
|
||||
);
|
||||
const finalArtifactCount = artifactGroupCount(groupedArtifacts.groups, "final");
|
||||
const totalArtifactCount = ARTIFACT_GROUP_ORDER.reduce(
|
||||
(total, kind) => total + artifactGroupCount(groupedArtifacts.groups, kind),
|
||||
0,
|
||||
);
|
||||
|
||||
const openModal = async (type: ModalType, run: ExecutionRunSummary) => {
|
||||
setSelectedRun(run);
|
||||
@ -368,6 +509,7 @@ export default function Monitoring() {
|
||||
setModalData({});
|
||||
setModalError("");
|
||||
setSelectedArtifact(null);
|
||||
setArtifactView("final");
|
||||
setArtifactLineage(null);
|
||||
setArtifactLineageError("");
|
||||
setArtifactLineageLoading(false);
|
||||
@ -382,9 +524,16 @@ export default function Monitoring() {
|
||||
const resources = await monitoringApi.getResourceUsage(run.id);
|
||||
setModalData({ resources });
|
||||
} else if (type === "data") {
|
||||
const data = await monitoringApi.getExecutionData(run.id);
|
||||
setModalData({ data });
|
||||
setSelectedArtifact(data[0] || null);
|
||||
const [data, lineage] = await Promise.all([
|
||||
monitoringApi.getExecutionData(run.id),
|
||||
monitoringApi.getLineage(run.id).catch((error) => {
|
||||
console.warn("Artifact lineage is unavailable; falling back to historical artifact display", error);
|
||||
return undefined;
|
||||
}),
|
||||
]);
|
||||
const grouped = groupArtifactsByLineage(data, lineage);
|
||||
setModalData({ data, lineage });
|
||||
setSelectedArtifact(preferredArtifact(grouped, ["final"]));
|
||||
} else if (type === "lineage") {
|
||||
const lineage = await monitoringApi.getLineage(run.id);
|
||||
setModalData({ lineage });
|
||||
@ -481,6 +630,7 @@ export default function Monitoring() {
|
||||
setModalData({});
|
||||
setModalError("");
|
||||
setSelectedArtifact(null);
|
||||
setArtifactView("final");
|
||||
setArtifactLineage(null);
|
||||
setArtifactLineageError("");
|
||||
setArtifactLineageLoading(false);
|
||||
@ -614,149 +764,6 @@ export default function Monitoring() {
|
||||
}
|
||||
};
|
||||
|
||||
const renderArtifactPreview = (item: ExecutionData) => {
|
||||
if (summarizePocAcceptanceArtifact(item)) {
|
||||
return <PocAcceptanceSummaryCard item={item} />;
|
||||
}
|
||||
|
||||
const preview = derivedPreview(item);
|
||||
const directURL = hasDirectArtifactURL(item) ? item.path : "";
|
||||
const previewURL = typeof preview.url === "string" && preview.url ? preview.url : directURL;
|
||||
const playablePreviewURL = preview.kind === "video" ? buildBrowserPlayableVideoURL(previewURL) : previewURL;
|
||||
|
||||
if (preview.kind === "image" && previewURL) {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col gap-4">
|
||||
<div className="min-h-[280px] bg-black rounded-lg overflow-hidden border border-[#2a2b2f] flex items-center justify-center">
|
||||
<img src={previewURL} alt={item.name} className="max-h-[420px] w-auto max-w-full object-contain" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "video" && playablePreviewURL) {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col gap-4">
|
||||
<div className="aspect-video bg-black rounded-lg overflow-hidden border border-[#2a2b2f]">
|
||||
<LazyVideoPreview
|
||||
src={playablePreviewURL}
|
||||
originalSrc={previewURL}
|
||||
title={item.name}
|
||||
className="h-full min-h-0 rounded-none border-0"
|
||||
videoClassName="h-full max-h-none rounded-none object-contain"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "audio" && previewURL) {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col justify-center gap-4">
|
||||
<div className="bg-black rounded-lg border border-[#2a2b2f] p-6">
|
||||
<audio src={previewURL} controls className="w-full" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "document" && preview.format === "pdf" && previewURL) {
|
||||
return (
|
||||
<div className="flex-1 min-h-[420px] rounded-lg overflow-hidden border border-[#2a2b2f] bg-black">
|
||||
<iframe src={previewURL} className="w-full h-[460px]" title={item.name} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "table" && Array.isArray(preview.rows)) {
|
||||
const columns = Array.isArray(preview.columns) ? preview.columns : [];
|
||||
return (
|
||||
<div className="flex-1 flex flex-col gap-4">
|
||||
<div className="text-[11px] text-gray-500 font-mono">
|
||||
{artifactKindLabel(item)} • {preview.rowCount ?? preview.rows.length} rows
|
||||
</div>
|
||||
<div className="rounded-lg border border-[#2a2b2f] overflow-auto max-h-[420px]">
|
||||
<table className="min-w-full text-xs">
|
||||
<thead className="bg-[#111214] sticky top-0">
|
||||
<tr>
|
||||
{columns.map((column) => (
|
||||
<th key={column} className="px-3 py-2 text-left text-gray-400 font-mono border-b border-[#2a2b2f]">
|
||||
{column}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{preview.rows.map((row: Record<string, unknown>, index: number) => (
|
||||
<tr key={index} className="border-b border-[#1f2024] last:border-b-0">
|
||||
{columns.map((column) => (
|
||||
<td key={`${index}-${column}`} className="px-3 py-2 text-gray-200 align-top">
|
||||
<div className="max-w-[240px] break-all">{String(row?.[column] ?? "")}</div>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "text") {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col gap-4">
|
||||
<div className="text-[11px] text-gray-500 font-mono">
|
||||
{artifactKindLabel(item)}
|
||||
{preview.truncated ? " • truncated" : ""}
|
||||
</div>
|
||||
<pre className="flex-1 min-h-[420px] bg-black rounded-lg border border-[#2a2b2f] p-4 text-xs text-gray-200 overflow-auto whitespace-pre-wrap break-all">
|
||||
{String(preview.text || "")}
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (preview.kind === "json" || item.type === "json") {
|
||||
const jsonValue = preview.kind === "json" ? (preview.value ?? item.data) : item.data;
|
||||
return (
|
||||
<pre className="flex-1 min-h-[420px] bg-black rounded-lg border border-[#2a2b2f] p-4 text-xs text-gray-200 overflow-auto whitespace-pre-wrap break-all">
|
||||
{JSON.stringify(jsonValue ?? {}, null, 2)}
|
||||
</pre>
|
||||
);
|
||||
}
|
||||
|
||||
if (item.data) {
|
||||
return (
|
||||
<pre className="flex-1 min-h-[420px] bg-black rounded-lg border border-[#2a2b2f] p-4 text-xs text-gray-200 overflow-auto whitespace-pre-wrap break-all">
|
||||
{JSON.stringify(item.data, null, 2)}
|
||||
</pre>
|
||||
);
|
||||
}
|
||||
|
||||
if (previewURL && preview.kind === "document") {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col justify-center gap-4">
|
||||
<div className="bg-black rounded-lg border border-[#2a2b2f] p-6 text-center text-sm text-gray-300">
|
||||
当前格式支持直接打开预览链接。
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex flex-col items-center justify-center text-center p-8">
|
||||
<div className="w-16 h-16 bg-white/5 rounded-full flex items-center justify-center text-gray-600 mb-4">
|
||||
<FileText className="w-8 h-8" />
|
||||
</div>
|
||||
<h5 className="text-sm font-bold text-gray-300">当前产物暂无内联预览</h5>
|
||||
<p className="text-xs text-gray-500 mt-2 max-w-sm">
|
||||
系统已保存真实路径和元数据。你仍然可以打开真实资源链接,或复制路径到下游系统继续处理。
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderArtifactLineagePanel = () => {
|
||||
if (!selectedArtifact) {
|
||||
return null;
|
||||
@ -941,7 +948,10 @@ export default function Monitoring() {
|
||||
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||
className="relative w-full max-w-4xl bg-[#151619] border border-[#2a2b2f] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]"
|
||||
className={cn(
|
||||
"relative flex max-h-[85vh] w-full flex-col overflow-hidden rounded-2xl border border-[#2a2b2f] bg-[#151619] shadow-2xl",
|
||||
activeModal === "data" ? "max-w-7xl" : "max-w-4xl",
|
||||
)}
|
||||
>
|
||||
{/* Modal Header */}
|
||||
<div className="px-6 py-4 border-b border-[#2a2b2f] flex items-center justify-between bg-[#1a1b1e]">
|
||||
@ -1098,82 +1108,93 @@ export default function Monitoring() {
|
||||
)}
|
||||
|
||||
{activeModal === "data" && (
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-xs font-medium text-gray-500 uppercase tracking-wider mb-2">文件列表</h4>
|
||||
{modalData.data?.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
onClick={() => setSelectedArtifact(item)}
|
||||
className={cn(
|
||||
"bg-[#0a0a0a] border p-4 rounded-xl flex items-center justify-between transition-all group cursor-pointer",
|
||||
selectedArtifact?.id === item.id
|
||||
? "border-blue-500 bg-blue-500/5"
|
||||
: "border-[#2a2b2f] hover:border-blue-500/50",
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-10 h-10 bg-white/5 rounded-lg flex items-center justify-center text-gray-400 group-hover:text-blue-500 transition-colors">
|
||||
{renderArtifactIcon(item)}
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm font-bold text-white truncate max-w-[180px]">{item.name}</div>
|
||||
<div className="text-[10px] text-gray-500 font-mono mt-0.5">
|
||||
{item.size} • {artifactSecondaryLabel(item)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
{item.portName && (
|
||||
<span className="text-[10px] px-2 py-1 rounded border border-blue-500/20 bg-blue-500/10 text-blue-300 font-mono">
|
||||
{item.portName}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-[10px] px-2 py-1 rounded border border-[#2a2b2f] bg-white/5 text-gray-400 font-mono">
|
||||
{artifactKindLabel(item)}
|
||||
</span>
|
||||
{artifactDownloadURL(item) && (
|
||||
<a
|
||||
href={artifactDownloadURL(item)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="p-2 hover:bg-white/5 rounded-lg text-gray-400 hover:text-white transition-colors"
|
||||
title={artifactDownloadLabel(item)}
|
||||
>
|
||||
<Download className="w-3.5 h-3.5" />
|
||||
</a>
|
||||
)}
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyToClipboard(item.path);
|
||||
}}
|
||||
className="p-2 hover:bg-white/5 rounded-lg text-gray-400 hover:text-white transition-colors"
|
||||
title="复制 OSS 路径"
|
||||
>
|
||||
<Database className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
{hasDirectArtifactURL(item) && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
window.open(item.path, "_blank", "noopener,noreferrer");
|
||||
}}
|
||||
className="p-2 hover:bg-white/5 rounded-lg text-gray-400 hover:text-white transition-colors"
|
||||
title="打开真实资源"
|
||||
>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-12">
|
||||
<div className="space-y-4 lg:col-span-5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h4 className="text-xs font-medium uppercase tracking-wider text-gray-500">结果文件</h4>
|
||||
<div className="mt-1 text-[11px] text-gray-600">
|
||||
{groupedArtifacts.hasLineage
|
||||
? "已按工作流血缘区分最终、处理中间和输入数据"
|
||||
: "历史运行缺少血缘,全部产物作为最终结果展示"}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex rounded-lg border border-[#2a2b2f] bg-black/20 p-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setArtifactView("final");
|
||||
setSelectedArtifact(preferredArtifact(groupedArtifacts, ["final"]));
|
||||
}}
|
||||
className={cn(
|
||||
"rounded-md px-3 py-1.5 text-xs font-medium transition-colors",
|
||||
artifactView === "final"
|
||||
? "bg-blue-600 text-white"
|
||||
: "text-gray-400 hover:text-white",
|
||||
)}
|
||||
>
|
||||
最终结果 {finalArtifactCount}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setArtifactView("all");
|
||||
if (!selectedArtifact) {
|
||||
setSelectedArtifact(preferredArtifact(groupedArtifacts));
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"rounded-md px-3 py-1.5 text-xs font-medium transition-colors",
|
||||
artifactView === "all" ? "bg-blue-600 text-white" : "text-gray-400 hover:text-white",
|
||||
)}
|
||||
>
|
||||
查看全部流程产物 {totalArtifactCount}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{totalArtifactCount === 0 ? (
|
||||
<div className="rounded-xl border border-dashed border-[#2a2b2f] bg-[#0a0a0a] px-4 py-12 text-center text-sm text-gray-500">
|
||||
当前运行没有可展示的产物
|
||||
</div>
|
||||
) : (
|
||||
(artifactView === "final" ? ["final"] : ARTIFACT_GROUP_ORDER).map((kind) => {
|
||||
const nodes = groupedArtifacts.groups[kind] || [];
|
||||
if (nodes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<section key={kind} className="space-y-2">
|
||||
<div className="flex items-center justify-between px-1">
|
||||
<h5 className="text-xs font-semibold text-gray-300">
|
||||
{ARTIFACT_GROUP_LABELS[kind]}
|
||||
</h5>
|
||||
<span className="text-[10px] text-gray-600">
|
||||
{artifactGroupCount(groupedArtifacts.groups, kind)} 个
|
||||
</span>
|
||||
</div>
|
||||
{nodes.map((node) => (
|
||||
<div key={`${kind}-${node.nodeId}`}>
|
||||
<ArtifactNodeSection
|
||||
node={node}
|
||||
defaultOpen={kind === "final" || nodes.length === 1}
|
||||
selectedArtifactId={selectedArtifact?.id}
|
||||
onSelect={setSelectedArtifact}
|
||||
onCopyPath={copyToClipboard}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bg-[#0a0a0a] border border-[#2a2b2f] rounded-xl p-4 flex flex-col min-h-[400px]">
|
||||
<div className="flex min-h-[400px] flex-col rounded-xl border border-[#2a2b2f] bg-[#0a0a0a] p-4 lg:col-span-7">
|
||||
<h4 className="text-xs font-medium text-gray-500 uppercase tracking-wider mb-4">预览面板</h4>
|
||||
{selectedArtifact ? (
|
||||
<div className="flex-1 flex flex-col">
|
||||
{renderArtifactPreview(selectedArtifact)}
|
||||
<ArtifactPreviewPanel item={selectedArtifact} />
|
||||
<div className="mt-4 space-y-4">
|
||||
<div>
|
||||
<div className="text-sm font-bold text-white">{selectedArtifact.name}</div>
|
||||
@ -1190,7 +1211,9 @@ export default function Monitoring() {
|
||||
</div>
|
||||
<div className="bg-white/5 p-3 rounded-lg border border-[#2a2b2f]">
|
||||
<div className="text-[10px] text-gray-500 uppercase font-mono mb-1">文件大小</div>
|
||||
<div className="text-sm font-bold text-white">{selectedArtifact.size}</div>
|
||||
<div className="text-sm font-bold text-white">
|
||||
{selectedArtifact.size?.trim() || "大小未知"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
@ -1208,36 +1231,14 @@ export default function Monitoring() {
|
||||
</div>
|
||||
</div>
|
||||
{renderArtifactLineagePanel()}
|
||||
<div className="grid grid-cols-1 gap-2">
|
||||
{artifactDownloadURL(selectedArtifact) && (
|
||||
<a
|
||||
href={artifactDownloadURL(selectedArtifact)}
|
||||
className="w-full py-3 bg-blue-600 hover:bg-blue-500 text-white rounded-xl text-sm font-bold transition-all flex items-center justify-center gap-2"
|
||||
>
|
||||
<Download className="w-4 h-4" />
|
||||
{artifactDownloadLabel(selectedArtifact)}
|
||||
</a>
|
||||
)}
|
||||
{hasDirectArtifactURL(selectedArtifact) ? (
|
||||
<button
|
||||
onClick={() =>
|
||||
window.open(selectedArtifact.path, "_blank", "noopener,noreferrer")
|
||||
}
|
||||
className="w-full py-3 bg-white/5 hover:bg-white/10 text-white rounded-xl text-sm font-bold transition-all flex items-center justify-center gap-2 border border-[#2a2b2f]"
|
||||
>
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
打开真实资源链接
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => copyToClipboard(selectedArtifact.path)}
|
||||
className="w-full py-3 bg-white/5 hover:bg-white/10 text-white rounded-xl text-sm font-bold transition-all flex items-center justify-center gap-2 border border-[#2a2b2f]"
|
||||
>
|
||||
<Database className="w-4 h-4" />
|
||||
复制真实存储路径
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => copyToClipboard(selectedArtifact.path)}
|
||||
className="flex w-full items-center justify-center gap-2 rounded-xl border border-[#2a2b2f] bg-white/5 py-3 text-sm font-bold text-white transition-all hover:bg-white/10"
|
||||
>
|
||||
<Database className="h-4 w-4" />
|
||||
复制真实存储路径
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
24
src/types.ts
24
src/types.ts
@ -574,6 +574,7 @@ export interface ExecutionData {
|
||||
name: string;
|
||||
type: PortType;
|
||||
size: string;
|
||||
sizeBytes?: number;
|
||||
path: string;
|
||||
metadata?: {
|
||||
duration?: string;
|
||||
@ -583,7 +584,28 @@ export interface ExecutionData {
|
||||
mimeType?: string;
|
||||
sha256?: string;
|
||||
};
|
||||
data?: Record<string, any>;
|
||||
data?: Record<string, any> & {
|
||||
reportSummary?: ArtifactReportSummary;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ArtifactReportIssueHit {
|
||||
code: string;
|
||||
label?: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface ArtifactReportSummary {
|
||||
schemaVersion: number;
|
||||
kind: "quality";
|
||||
title?: string;
|
||||
unit?: "trajectory" | "episode" | "file" | "item" | string;
|
||||
totalCount: number;
|
||||
successCount: number;
|
||||
failureCount: number;
|
||||
runtimeErrorCount?: number;
|
||||
successRate?: number;
|
||||
issueHits?: ArtifactReportIssueHit[];
|
||||
}
|
||||
|
||||
export interface LightweightOperatorCodeFileManifest {
|
||||
|
||||
@ -276,6 +276,109 @@ def test_html_report_escapes_untrusted_episode_and_error_text():
|
||||
assert "<bad>" in rendered
|
||||
|
||||
|
||||
def test_quality_report_summary_matches_legacy_counts_and_rule_hits():
|
||||
summary = report._quality_report_summary(
|
||||
{"PASS": 130, "ERROR": 5, "RUNTIME_ERROR": 0},
|
||||
report.Counter({"start_ts_mismatch": 117}),
|
||||
135,
|
||||
)
|
||||
assert summary == {
|
||||
"schemaVersion": 1,
|
||||
"kind": "quality",
|
||||
"title": "数据质量报告",
|
||||
"unit": "trajectory",
|
||||
"totalCount": 135,
|
||||
"successCount": 130,
|
||||
"failureCount": 5,
|
||||
"runtimeErrorCount": 0,
|
||||
"successRate": 130 / 135,
|
||||
"issueHits": [
|
||||
{
|
||||
"code": "start_ts_mismatch",
|
||||
"label": "起始时间戳不一致",
|
||||
"count": 117,
|
||||
}
|
||||
],
|
||||
}
|
||||
assert summary["successCount"] + summary["failureCount"] == summary["totalCount"]
|
||||
assert summary["issueHits"][0]["count"] != summary["failureCount"]
|
||||
|
||||
|
||||
def test_report_run_keeps_existing_artifacts_and_embeds_generic_summary(
|
||||
tmp_path: pathlib.Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
inputs_path = tmp_path / "inputs.json"
|
||||
inputs_path.write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{
|
||||
"name": "checker-summary.json",
|
||||
"data": {
|
||||
"datasetId": "test-data",
|
||||
"datasetFingerprint": "dataset-fingerprint",
|
||||
"urdfFingerprint": "urdf-fingerprint",
|
||||
"sourceCommit": "abc123",
|
||||
"imageDigest": "sha256:test",
|
||||
"datePrefixes": ["2026_06_16"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "episode-results.json",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"episode": "episode-pass",
|
||||
"date": "2026_06_16",
|
||||
"status": "PASS",
|
||||
"ruleResults": [],
|
||||
},
|
||||
{
|
||||
"episode": "episode-fail",
|
||||
"date": "2026_06_16",
|
||||
"status": "ERROR",
|
||||
"ruleResults": [
|
||||
{
|
||||
"rule_id": "start_ts_mismatch",
|
||||
"status": "fail",
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
]
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
output_dir = tmp_path / "output"
|
||||
result_path = tmp_path / "result.json"
|
||||
monkeypatch.setenv("INPUT_ARTIFACTS_PATH", str(inputs_path))
|
||||
monkeypatch.setenv("OUTPUT_DIR", str(output_dir))
|
||||
monkeypatch.setenv("RESULT_OUTPUT_PATH", str(result_path))
|
||||
monkeypatch.setenv("STAGE_MANIFEST_PATH", str(tmp_path / "stage-manifest.json"))
|
||||
monkeypatch.setenv("RUN_ID", "run-report-test")
|
||||
|
||||
report.run_report()
|
||||
|
||||
summary = json.loads((output_dir / "ubt-quality-summary.json").read_text())
|
||||
assert summary["totalEpisodes"] == 2
|
||||
assert summary["statusCounts"] == {"PASS": 1, "ERROR": 1, "RUNTIME_ERROR": 0}
|
||||
assert summary["passRate"] == 0.5
|
||||
assert summary["reportSummary"]["successCount"] == 1
|
||||
assert summary["reportSummary"]["failureCount"] == 1
|
||||
result = json.loads(result_path.read_text())
|
||||
assert [item["name"] for item in result["artifacts"]] == [
|
||||
"ubt-quality-summary.json",
|
||||
"episode-results.csv",
|
||||
"pass-manifest.json",
|
||||
"fail-manifest.json",
|
||||
"rule-statistics.json",
|
||||
"ubt-quality-report.html",
|
||||
]
|
||||
assert (output_dir / "ubt-quality-report.html").is_file()
|
||||
|
||||
|
||||
def test_artifact_relative_path_survives_worker_data_contract(
|
||||
tmp_path: pathlib.Path,
|
||||
):
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
artifactPreviewCategory,
|
||||
artifactPreviewTitle,
|
||||
is3DAssetArtifact,
|
||||
isHTMLArtifact,
|
||||
isModelArtifact,
|
||||
isTextPreviewArtifact,
|
||||
} from "../../src/lib/artifact-download.js";
|
||||
@ -78,3 +79,11 @@ test("treats code and structured text artifacts as text previews", () => {
|
||||
assert.equal(isTextPreviewArtifact({ name: "manifest.gltf" }), true);
|
||||
assert.equal(isTextPreviewArtifact({ name: "weights.onnx" }), false);
|
||||
});
|
||||
|
||||
test("classifies HTML as a rendered report before generic text", () => {
|
||||
const artifact = { name: "quality-report.html", metadata: { mimeType: "text/html" } };
|
||||
assert.equal(isHTMLArtifact(artifact), true);
|
||||
assert.equal(isTextPreviewArtifact(artifact), true);
|
||||
assert.equal(artifactPreviewCategory(artifact), "html");
|
||||
assert.equal(artifactPreviewTitle(artifact), "HTML 报告");
|
||||
});
|
||||
|
||||
97
tests/frontend/artifact-groups.test.mjs
Normal file
97
tests/frontend/artifact-groups.test.mjs
Normal file
@ -0,0 +1,97 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { artifactGroupCount, groupArtifactsByLineage, preferredArtifact } from "../../src/lib/artifact-groups.js";
|
||||
|
||||
const artifact = (id, nodeId, name, data = undefined) => ({
|
||||
id,
|
||||
nodeId,
|
||||
name,
|
||||
path: `/tmp/${name}`,
|
||||
type: name.endsWith(".json") ? "json" : "file",
|
||||
data,
|
||||
});
|
||||
|
||||
test("groups input, intermediate and final artifacts from workflow lineage", () => {
|
||||
const grouped = groupArtifactsByLineage(
|
||||
[
|
||||
artifact("input", "prepare", "input.zip"),
|
||||
artifact("middle", "check", "episode-results.json"),
|
||||
artifact("final", "report", "quality-report.html"),
|
||||
],
|
||||
{
|
||||
nodes: [
|
||||
{ nodeId: "prepare", nodeLabel: "数据准备" },
|
||||
{ nodeId: "check", nodeLabel: "质量检查" },
|
||||
{ nodeId: "report", nodeLabel: "报告生成" },
|
||||
],
|
||||
edges: [
|
||||
{ sourceNodeId: "prepare", targetNodeId: "check" },
|
||||
{ sourceNodeId: "check", targetNodeId: "report" },
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(artifactGroupCount(grouped.groups, "input"), 1);
|
||||
assert.equal(artifactGroupCount(grouped.groups, "intermediate"), 1);
|
||||
assert.equal(artifactGroupCount(grouped.groups, "final"), 1);
|
||||
assert.equal(preferredArtifact(grouped).id, "final");
|
||||
});
|
||||
|
||||
test("treats a single isolated workflow node as final output", () => {
|
||||
const grouped = groupArtifactsByLineage([artifact("only", "single", "result.json")], {
|
||||
nodes: [{ nodeId: "single", nodeLabel: "单节点" }],
|
||||
edges: [],
|
||||
});
|
||||
|
||||
assert.equal(artifactGroupCount(grouped.groups, "final"), 1);
|
||||
assert.equal(artifactGroupCount(grouped.groups, "input"), 0);
|
||||
});
|
||||
|
||||
test("returns no default selection when the requested final group is empty", () => {
|
||||
const grouped = {
|
||||
groups: {
|
||||
final: [],
|
||||
intermediate: [],
|
||||
input: [{ nodeId: "source", nodeLabel: "输入", artifacts: [artifact("input", "source", "input.zip")] }],
|
||||
},
|
||||
};
|
||||
|
||||
assert.equal(preferredArtifact(grouped, ["final"]), null);
|
||||
assert.equal(preferredArtifact(grouped).id, "input");
|
||||
});
|
||||
|
||||
test("keeps every historical artifact visible when lineage is missing", () => {
|
||||
const grouped = groupArtifactsByLineage(
|
||||
[artifact("one", "unknown-a", "one.zip"), artifact("two", "unknown-b", "two.html")],
|
||||
undefined,
|
||||
);
|
||||
|
||||
assert.equal(grouped.hasLineage, false);
|
||||
assert.equal(artifactGroupCount(grouped.groups, "final"), 2);
|
||||
});
|
||||
|
||||
test("prefers quality summary, then rendered reports, JSON and other files", () => {
|
||||
const grouped = groupArtifactsByLineage(
|
||||
[
|
||||
artifact("archive", "report", "bundle.zip"),
|
||||
artifact("json", "report", "details.json"),
|
||||
artifact("html", "report", "report.html"),
|
||||
artifact("summary", "report", "summary.json", {
|
||||
reportSummary: {
|
||||
schemaVersion: 1,
|
||||
kind: "quality",
|
||||
totalCount: 1,
|
||||
successCount: 1,
|
||||
failureCount: 0,
|
||||
},
|
||||
}),
|
||||
],
|
||||
{ nodes: [{ nodeId: "report", nodeLabel: "报告" }], edges: [] },
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
grouped.groups.final[0].artifacts.map((item) => item.id),
|
||||
["summary", "html", "json", "archive"],
|
||||
);
|
||||
});
|
||||
29
tests/frontend/artifact-preview-panel.test.mjs
Normal file
29
tests/frontend/artifact-preview-panel.test.mjs
Normal file
@ -0,0 +1,29 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
|
||||
const previewPanelURL = new URL("../../src/components/ArtifactPreviewPanel.tsx", import.meta.url);
|
||||
const monitoringURL = new URL("../../src/pages/Monitoring.tsx", import.meta.url);
|
||||
|
||||
test("HTML artifacts default to sandboxed report rendering with source and download fallbacks", async () => {
|
||||
const source = await readFile(previewPanelURL, "utf8");
|
||||
|
||||
assert.match(source, /报告预览/);
|
||||
assert.match(source, /查看源码/);
|
||||
assert.match(source, /sandbox=""/);
|
||||
assert.match(source, /method: "HEAD"/);
|
||||
assert.match(source, /Range: "bytes=0-262143"/);
|
||||
assert.match(source, /!preview\.truncated/);
|
||||
assert.match(source, /打开原文件/);
|
||||
assert.match(source, /下载产物/);
|
||||
});
|
||||
|
||||
test("Monitoring reuses the public preview panel and exposes final and all-artifact views", async () => {
|
||||
const source = await readFile(monitoringURL, "utf8");
|
||||
|
||||
assert.match(source, /<ArtifactPreviewPanel item=\{selectedArtifact\}/);
|
||||
assert.match(source, /最终结果/);
|
||||
assert.match(source, /查看全部流程产物/);
|
||||
assert.match(source, /groupArtifactsByLineage/);
|
||||
assert.doesNotMatch(source, /const renderArtifactPreview/);
|
||||
});
|
||||
58
tests/frontend/report-summary.test.mjs
Normal file
58
tests/frontend/report-summary.test.mjs
Normal file
@ -0,0 +1,58 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { qualityReportUnitLabel, summarizeQualityReportArtifact } from "../../src/lib/report-summary.js";
|
||||
|
||||
test("parses the explicit generic quality report summary", () => {
|
||||
const summary = summarizeQualityReportArtifact({
|
||||
data: {
|
||||
reportSummary: {
|
||||
schemaVersion: 1,
|
||||
kind: "quality",
|
||||
title: "数据质量报告",
|
||||
unit: "trajectory",
|
||||
totalCount: 135,
|
||||
successCount: 130,
|
||||
failureCount: 5,
|
||||
runtimeErrorCount: 0,
|
||||
successRate: 130 / 135,
|
||||
issueHits: [{ code: "start_ts_mismatch", label: "起始时间戳不一致", count: 117 }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(summary.totalCount, 135);
|
||||
assert.equal(summary.successCount + summary.failureCount, 135);
|
||||
assert.equal(summary.runtimeErrorCount, 0);
|
||||
assert.equal((summary.successRate * 100).toFixed(2), "96.30");
|
||||
assert.equal(summary.issueHits[0].count, 117);
|
||||
assert.notEqual(summary.issueHits[0].count, summary.failureCount);
|
||||
assert.equal(qualityReportUnitLabel(summary.unit), "轨迹");
|
||||
});
|
||||
|
||||
test("adapts historical UBT summary fields without relying on names or operator IDs", () => {
|
||||
const summary = summarizeQualityReportArtifact({
|
||||
name: "renamed-result.json",
|
||||
data: {
|
||||
preview: {
|
||||
kind: "json",
|
||||
value: {
|
||||
totalEpisodes: 135,
|
||||
statusCounts: { PASS: 130, ERROR: 5, RUNTIME_ERROR: 0 },
|
||||
passRate: 130 / 135,
|
||||
ruleStatistics: { start_ts_mismatch: 117 },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(summary.legacy, true);
|
||||
assert.equal(summary.totalCount, 135);
|
||||
assert.equal(summary.successCount, 130);
|
||||
assert.equal(summary.failureCount, 5);
|
||||
assert.equal((summary.successRate * 100).toFixed(2), "96.30");
|
||||
});
|
||||
|
||||
test("does not classify unrelated JSON as a quality report", () => {
|
||||
assert.equal(summarizeQualityReportArtifact({ data: { status: "completed", items: [] } }), null);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user