✅ Stabilize preview artifact acceptance

This commit is contained in:
eust-w 2026-06-23 01:43:37 +08:00
parent 454d2a0bb8
commit d474aa3b5d

View File

@ -350,6 +350,31 @@ async function runWorkflow(workflowId) {
return finished;
}
async function waitForArtifacts(runId, requiredNames) {
const required = [...new Set(requiredNames)];
const result = await poll(
async () => {
const [run, artifactPayload] = await Promise.all([
api(`/api/runs/${runId}`),
api(`/api/runs/${runId}/artifacts`),
]);
const items = Array.isArray(artifactPayload.items) ? artifactPayload.items : [];
const names = new Set(items.map((artifact) => artifact.name));
const missing = required.filter((name) => !names.has(name));
return { run, items, missing };
},
({ run, missing }) => missing.length === 0 || ["failed", "cancelled"].includes(run.status),
`artifacts ${required.join(", ")} for run ${runId}`,
workflowRunTimeoutMs,
3000,
);
assert(
result.missing.length === 0,
`Run ${runId} missing artifacts ${result.missing.join(", ")}; status ${result.run.status}: ${result.run.error || "unknown error"}`,
);
return result.items;
}
async function createWorkflows(projectId) {
const previewWorkflow = await createWorkflow(
projectId,
@ -716,7 +741,7 @@ async function main() {
log("run preview workflow");
const previewRun = await runWorkflow(workflows.previewWorkflow.id);
const previewArtifacts = (await api(`/api/runs/${previewRun.id}/artifacts`)).items;
const previewArtifacts = await waitForArtifacts(previewRun.id, ["report.csv", "notes.txt"]);
assert(
artifactByName(previewArtifacts, "report.csv").data.preview.kind === "table",
"report.csv preview should be table",
@ -728,7 +753,14 @@ async function main() {
log("run data ops workflow");
const dataOpsRun = await runWorkflow(workflows.dataOpsWorkflow.id);
const dataOpsArtifacts = (await api(`/api/runs/${dataOpsRun.id}/artifacts`)).items;
const dataOpsArtifacts = await waitForArtifacts(dataOpsRun.id, [
"extracted.json",
"filtered.json",
"mapped.json",
"rows.csv",
"matched.json",
"unmatched.json",
]);
assert(
jsonEqual(artifactByName(dataOpsArtifacts, "extracted.json").data.value, dataOpsExtractExpected),
`JSON extract should return value from ${dataOpsExtractField}`,
@ -763,7 +795,7 @@ async function main() {
log("run csv conversion workflow");
const csvRun = await runWorkflow(workflows.csvWorkflow.id);
const csvArtifacts = (await api(`/api/runs/${csvRun.id}/artifacts`)).items;
const csvArtifacts = await waitForArtifacts(csvRun.id, ["table.json"]);
assert(
artifactItemCount(artifactByName(csvArtifacts, "table.json")) === expectedCsvRowCount(previewCsvPayload.text),
"CSV to JSON should convert the supplied CSV row count",
@ -771,7 +803,7 @@ async function main() {
log("run directory scan workflow");
const scanRun = await runWorkflow(workflows.scanWorkflow.id);
const scanArtifacts = (await api(`/api/runs/${scanRun.id}/artifacts`)).items;
const scanArtifacts = await waitForArtifacts(scanRun.id, ["directory-scan.json"]);
assert(
artifactByName(scanArtifacts, "directory-scan.json").data.summary.fileCount >= scanMinFileCount,
"Directory scan should report the minimum file count for the supplied source path",
@ -779,7 +811,7 @@ async function main() {
log("run rosbag workflow");
const rosbagRun = await runWorkflow(workflows.rosbagWorkflow.id);
const rosbagArtifacts = (await api(`/api/runs/${rosbagRun.id}/artifacts`)).items;
const rosbagArtifacts = await waitForArtifacts(rosbagRun.id, ["rosbag-summary.json"]);
const rosbagPayload = readJSONArtifactPayload(artifactByName(rosbagArtifacts, "rosbag-summary.json"));
const rosbagPreview = rosbagPayload.databasePreview || rosbagPayload.preview || {};
assert(
@ -796,7 +828,7 @@ async function main() {
log("run lerobot workflow");
const lerobotRun = await runWorkflow(workflows.lerobotWorkflow.id);
const lerobotArtifacts = (await api(`/api/runs/${lerobotRun.id}/artifacts`)).items;
const lerobotArtifacts = await waitForArtifacts(lerobotRun.id, ["lerobot-summary.json"]);
const lerobotPayload = readJSONArtifactPayload(artifactByName(lerobotArtifacts, "lerobot-summary.json"));
const lerobotPreview = lerobotPayload.preview || {};
assert(lerobotPreview.format === "lerobot", "LeRobot summary should detect dataset");