droboticflow/tests/frontend/project-storage-contract.test.mjs

74 lines
3.7 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { buildProjectWorkflowArtifactStorage, defaultWorkflowArtifactPrefix } from "../../src/lib/project-storage.js";
const source = async (path) => readFile(new URL(`../../${path}`, import.meta.url), "utf8");
test("workflow artifact directories inherit the project connection and bucket", () => {
const project = {
storageConnectionId: "connection-bos",
storageBucket: "robot-data",
storagePrefix: "/projects/convenience-store/",
};
assert.equal(
defaultWorkflowArtifactPrefix(project.storagePrefix),
"projects/convenience-store/workflows/{workflowId}/runs/{runId}/{nodeId}",
);
assert.deepEqual(buildProjectWorkflowArtifactStorage(project, "intermediate/{runId}/{nodeId}"), {
connectionId: "connection-bos",
bucket: "robot-data",
prefixTemplate: "intermediate/{runId}/{nodeId}",
});
assert.equal(buildProjectWorkflowArtifactStorage({ storageConnectionId: "", storageBucket: "" }), null);
});
test("project creation requires an explicit storage connection and bucket in the UI", async () => {
const projects = await source("src/pages/Projects.tsx");
assert.match(projects, /Promise\.allSettled\(\[projectsApi\.list\(\), storageConnectionsApi\.list\(\)\]\)/);
assert.match(projects, /创建项目前必须选择存储连接并指定 Bucket/);
assert.match(projects, /storageConnectionId: defaultConnection\?\.id \|\| ""/);
assert.match(projects, /storageBucket: defaultConnection\?\.bucket \|\| ""/);
assert.match(projects, /<option value="">请选择存储连接<\/option>/);
assert.match(projects, /list="project-storage-buckets"/);
});
test("project editor keeps actions visible and reports save errors inside the modal", async () => {
const projects = await source("src/pages/Projects.tsx");
assert.match(projects, /role="dialog"/);
assert.match(projects, /aria-labelledby="project-modal-title"/);
assert.match(projects, /min-h-0 flex-1 space-y-4 overflow-y-auto/);
assert.match(projects, /flex shrink-0 justify-end gap-3 border-t/);
assert.match(projects, /\{actionError \? \([\s\S]*role="alert"/);
assert.match(projects, /\{bucketLoadWarning \? \([\s\S]*role="status"/);
assert.match(projects, /无法读取 Bucket 列表,可继续使用当前值或手动填写/);
assert.match(projects, /不影响保存项目/);
});
test("Mongo project updates persist empty optional fields instead of retaining stale values", async () => {
const mongo = await source("internal/store/mongo.go");
assert.match(mongo, /return bson\.M\{/);
assert.match(mongo, /"customer":\s+item\.Customer/);
assert.match(mongo, /"scene":\s+item\.Scene/);
assert.match(mongo, /"annotationStandard":\s+item\.AnnotationStandard/);
assert.match(mongo, /\$set": persisted/);
});
test("workflow creation sends the selected intermediate artifact directory", async () => {
const detail = await source("src/pages/ProjectDetail.tsx");
assert.match(detail, /artifactPrefixTemplate: defaultArtifactPrefix/);
assert.match(detail, /artifactStorage,\s*\}\)/);
assert.match(detail, /运行产物目录模板/);
assert.match(detail, /每个节点的中间产物会按此目录写入项目 Bucket/);
assert.match(detail, /!newWfData\.artifactPrefixTemplate\.trim\(\)[\s\S]*!projectStorageReady/);
});
test("backend validates project storage and inherits it into workflows", async () => {
const server = await source("internal/api/server.go");
assert.match(server, /project_storage_connection_required/);
assert.match(server, /project_storage_bucket_required/);
assert.match(server, /applyProjectWorkflowArtifactStorage\(project, &payload\.ArtifactStorage\)/);
assert.match(server, /workflow_project_storage_bucket_mismatch/);
});