项目整机拼装与资源文件上传

This commit is contained in:
lxp
2026-10-28 17:49:54 +08:00
parent 4e7d11d586
commit 0dd39eb23d
32 changed files with 964 additions and 29 deletions
@@ -10,15 +10,23 @@ final class FakeOssObjectStore implements OssObjectStore {
final Map<String, byte[]> objects = new ConcurrentHashMap<>();
boolean failNextCopy;
Runnable afterHead;
int headCalls;
int copyCalls;
boolean unavailable;
void reset() {
objects.clear();
failNextCopy = false;
afterHead = null;
headCalls = 0;
copyCalls = 0;
unavailable = false;
}
@Override
public Metadata head(String objectKey) {
headCalls++;
if (unavailable) throw new BusinessException(502, "OSS_ERROR", "OSS 暂不可用");
byte[] bytes = objects.get(objectKey);
if (bytes == null)
throw new BusinessException(400, "URDF_FILE_MISSING", "URDF 文件未上传完整,请重新上传");
@@ -33,6 +41,7 @@ final class FakeOssObjectStore implements OssObjectStore {
@Override
public void copy(String sourceKey, String targetKey, String sourceEtag) {
copyCalls++;
if (failNextCopy) {
failNextCopy = false;
throw new BusinessException(502, "OSS_ERROR", "OSS 资源访问失败,请稍后重试");
@@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkerbot.vibemake.common.BusinessException;
import com.linkerbot.vibemake.security.CaptchaService;
import com.linkerbot.vibemake.service.admin.AdminProjectResourceService;
import com.linkerbot.vibemake.service.support.ProjectActors;
import com.linkerbot.vibemake.service.config.VibemakeProperties;
import com.linkerbot.vibemake.service.config.OssProperties;
import com.linkerbot.vibemake.service.config.UrdfProperties;
@@ -90,6 +92,7 @@ class WorkflowTest {
@Autowired FakeOssObjectStore ossObjects;
@Autowired UrdfProperties urdfLimits;
@Autowired FakeGitSnapshotCopier snapshots;
@Autowired AdminProjectResourceService projectResources;
@BeforeEach
void reset() throws Exception {
@@ -977,6 +980,77 @@ class WorkflowTest {
.isEqualTo(source.path("urdfMainUrl"));
}
@ParameterizedTest
@ValueSource(booleans = {false, true})
void newProjectResourcesAreReturnedInDetailsAndForkedWithoutAnyOssAccess(boolean ossEnabled) throws Exception {
String owner = login("resource-source@example.com");
String other = login("resource-fork@example.com");
String code = create(owner, "资源来源");
enableUrdfOss();
oss.setEnabled(ossEnabled);
ossObjects.unavailable = true;
String base = "/project-resources/" + code + "/";
String batch = "a".repeat(32);
String parts = base + "model-parts/" + batch + "/";
String walking = base + "walking-resources/" + batch + "/";
String glb = base + "model-glb/" + batch + "/整机.glb";
String assembly = base + "assembly-json/" + batch + "/steps.json";
String manifest = "[{\"relativePath\":\"目录/a #?.glb\",\"sizeBytes\":5368709120}]";
jdbc.update("UPDATE project SET model_glb_object_key=?, model_glb_size_bytes=?, model_parts_prefix=?,"
+ " model_parts_files=?, assembly_json_object_key=?, assembly_json_size_bytes=?,"
+ " walking_resources_prefix=?, walking_resources_files=? WHERE project_code=?",
glb, 5368709120L, parts, manifest, assembly, 123L, walking, manifest, code);
String ownerEndpoint = "/api/workspace/projects/" + code;
JsonNode source = perform(auth(get(ownerEndpoint), owner), 200).path("data");
assertThat(source.path("modelGlbUrl").asText()).endsWith("/%E6%95%B4%E6%9C%BA.glb");
assertThat(source.path("modelPartsFiles").get(0).path("url").asText()).endsWith("/%E7%9B%AE%E5%BD%95/a%20%23%3F.glb");
assertThat(source.path("walkingResourcesFiles").get(0).path("sizeBytes").asLong()).isEqualTo(5368709120L);
assertThat(source.has("id")).isFalse();
String sha = head(owner, code);
publish(owner, code, sha);
JsonNode publicDetail = perform(get("/api/community/projects/" + code), 200).path("data");
assertThat(publicDetail.path("modelPartsFiles")).isEqualTo(source.path("modelPartsFiles"));
assertThat(publicDetail.path("assemblyJsonUrl")).isEqualTo(source.path("assemblyJsonUrl"));
for (JsonNode listing : List.of(
perform(auth(get("/api/workspace/projects"), owner), 200).path("data").path("items").get(0),
perform(get("/api/community/projects"), 200).path("data").path("items").get(0))) {
assertThat(listing.path("modelGlbUrl")).isEqualTo(source.path("modelGlbUrl"));
assertThat(listing.has("modelPartsFiles")).isFalse();
assertThat(listing.has("walkingResourcesFiles")).isFalse();
}
JsonNode fork = perform(body(auth(post("/api/community/projects/" + code + "/forks"), other),
Map.of("name", "资源副本", "publishedCommitSha", sha)), 200).path("data");
String target = fork.path("projectCode").asText();
assertThat(fork.path("repoStatus").asText()).isEqualTo("READY");
for (String field : List.of("modelGlbUrl", "modelPartsBaseUrl", "modelPartsFiles", "assemblyJsonUrl",
"walkingResourcesBaseUrl", "walkingResourcesFiles"))
assertThat(fork.path(field)).isEqualTo(source.path(field));
for (String column : List.of("model_glb_object_key", "model_glb_size_bytes", "model_parts_prefix", "model_parts_files",
"assembly_json_object_key", "assembly_json_size_bytes", "walking_resources_prefix", "walking_resources_files")) {
assertThat(jdbc.queryForObject("SELECT " + column + " FROM project WHERE project_code=?", String.class, target))
.isEqualTo(jdbc.queryForObject("SELECT " + column + " FROM project WHERE project_code=?", String.class, code));
}
// 模拟来源资源被管理员替换,副本仍持有原批次。
jdbc.update("UPDATE project SET model_glb_object_key=? WHERE project_code=?", glb.replace(batch, "b".repeat(32)), code);
assertThat(perform(auth(get("/api/workspace/projects/" + target), other), 200).path("data").path("modelGlbUrl"))
.isEqualTo(fork.path("modelGlbUrl"));
try (ProjectActors.Scope scope = ProjectActors.enter(new ProjectActors.AdminActor("a".repeat(32), "测试管理员"))) {
projectResources.clear(code, "model-parts");
projectResources.clear(target, "assembly-json");
}
JsonNode independentSource = perform(auth(get(ownerEndpoint), owner), 200).path("data");
JsonNode independentTarget = perform(auth(get("/api/workspace/projects/" + target), other), 200).path("data");
assertThat(independentSource.path("modelPartsFiles").isEmpty()).isTrue();
assertThat(independentSource.path("assemblyJsonUrl")).isEqualTo(source.path("assemblyJsonUrl"));
assertThat(independentTarget.path("modelPartsFiles")).isEqualTo(fork.path("modelPartsFiles"));
assertThat(independentTarget.path("assemblyJsonUrl").isNull()).isTrue();
perform(auth(delete(ownerEndpoint), owner), 200);
JsonNode remaining = perform(auth(get("/api/workspace/projects/" + target), other), 200).path("data");
assertThat(remaining.path("walkingResourcesFiles")).isEqualTo(fork.path("walkingResourcesFiles"));
assertThat(ossObjects.headCalls).isZero();
assertThat(ossObjects.copyCalls).isZero();
}
@Test
void coverSignaturesAuthenticateValidateAndReturnDirectUploadForms() throws Exception {
String endpoint = "/api/uploads/project-covers/signature";