Enforce archive state for runtime activation
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (pull_request) Canceled after 0s

This commit is contained in:
WebUp Cloud committed 2026-11-08 23:39:27 +08:00
1 parent da93d4fa1c
commit bbd5eeb605
4 files changed
+49 -2

No files matched your search

@@ -43,6 +43,8 @@ public class DeploymentWorker {
UUID id = UUID.fromString(op.get("id").toString());
String lease = op.get("lease_token").toString();
try {
if ("RESUME".equals(op.get("action")))
operations.checkAllowed(UUID.fromString(op.get("project_id").toString()));
gateway.request(
"/runtime/projects/" + op.get("project_id") + "/state",
Map.of("action", op.get("action"), "operationId", id.toString()));
@@ -270,8 +270,7 @@ public class HostingService {
}
Map<String, Object> beforeSourceSnapshot(UUID user, UUID project, String key) {
if ("ARCHIVED".equals(own(user, project).get("status")))
throw new ApiError.Failure(409, "归档项目不能发布");
own(user, project);
operations.checkAllowed(project);
var replay = deploymentReplay(project, key);
if (replay != null) return replay;
@@ -28,6 +28,7 @@ public class RuntimeOperationService {
return UUID.fromString(p.get("id").toString());
}
if (action.equals("RESUME")) {
checkNotArchived(project);
var allowed =
db.queryForList("SELECT status FROM project_moderation WHERE project_id=?", project);
if (allowed.isEmpty() || !"APPROVED".equals(allowed.getFirst().get("status")))
@@ -98,6 +99,7 @@ public class RuntimeOperationService {
}
public void checkAllowed(UUID project) {
checkNotArchived(project);
String message =
switch (reviewStatus(project)) {
case "APPROVED" -> null;
@@ -107,4 +109,12 @@ public class RuntimeOperationService {
};
if (message != null) throw new ApiError.Failure(403, message);
}
private void checkNotArchived(UUID project) {
if (db.queryForObject(
"SELECT COUNT(*) FROM projects WHERE id=? AND status='ARCHIVED'",
Integer.class,
project)
!= 0) throw new ApiError.Failure(409, "归档项目不能执行运行操作");
}
}
@@ -18,6 +18,7 @@ class HostingIntegrationTest {
@Autowired WalletService wallets;
@Autowired HostingService hosting;
@Autowired DeploymentCoordinator deployments;
@Autowired RuntimeOperationService operations;
@Autowired ObjectMapper json;
@MockitoBean EphemeralStore store;
UUID user, project, plan;
@@ -93,6 +94,41 @@ class HostingIntegrationTest {
assertEquals(snapshot, deployments.payload(deployments.claim()).path("source"));
}
@Test
void archivedProjectCannotQueueOrApplyReleasesOrResumeRuntime() {
hosting.subscribe(user, project, plan, "archived-plan");
hosting.service(user, project, null, spec(200));
hosting.deploy(user, project, "before-archive", null);
users.db().update("UPDATE projects SET status='ARCHIVED' WHERE id=?", project);
assertEquals(
409,
assertThrows(
ApiError.Failure.class, () -> hosting.deploy(user, project, "after-archive", null))
.status);
assertEquals(
409,
assertThrows(
ApiError.Failure.class,
() -> hosting.deploy(user, project, "rollback", UUID.randomUUID()))
.status);
assertEquals(
409,
assertThrows(
ApiError.Failure.class, () -> hosting.beforeSourceSnapshot(user, project, "source"))
.status);
assertEquals(
409,
assertThrows(
ApiError.Failure.class,
() -> operations.enqueue(project, user, "RESUME", "test", "archived-resume"))
.status);
var queued = deployments.claim();
assertNotNull(queued);
assertEquals(
409, assertThrows(ApiError.Failure.class, () -> deployments.payload(queued)).status);
assertNotNull(operations.enqueue(project, user, "SUSPEND", "test", "archived-suspend"));
}
@Test
void purchaseIsIdempotentAndSnapshotsPlan() {
hosting.subscribe(user, project, plan, "first");