feat: 收口小程序构建上传阶段
This commit is contained in:
1 parent
6420b85019
commit
ec16fff70e
23 files changed
+1185
-104
No files matched your search
@@ -10,6 +10,7 @@ import { getVisualTemplateManifest } from "@personal-brand/config";
|
||||
import { createApp } from "../dist/main.js";
|
||||
import { readIdentity, signIdentity } from "../dist/auth.js";
|
||||
import { WechatAuthService } from "../dist/wechat-auth.js";
|
||||
import { AdminMiniAppReleaseService } from "../dist/modules/admin/admin-miniapp-release.service.js";
|
||||
|
||||
let app;
|
||||
const prisma = new PrismaClient();
|
||||
@@ -571,6 +572,21 @@ test("miniapp release tasks are authorized, idempotent, and state checked", asyn
|
||||
});
|
||||
assert.equal(created.statusCode, 201);
|
||||
assert.equal(JSON.parse(created.body).version, current.version);
|
||||
await prisma.miniAppReleaseAttempt.create({
|
||||
data: {
|
||||
taskId: JSON.parse(created.body).id,
|
||||
brandId,
|
||||
actorId: "integration-test",
|
||||
phase: "build",
|
||||
attempt: 1,
|
||||
leaseToken: "integration-secret-lease-token",
|
||||
leaseExpiresAt: new Date(Date.now() + 60_000),
|
||||
},
|
||||
});
|
||||
const listedAttempts = await request("/admin/miniapp-releases", { headers });
|
||||
assert.equal(listedAttempts.statusCode, 200);
|
||||
assert.equal(listedAttempts.body.includes("integration-secret-lease-token"), false);
|
||||
assert.equal(JSON.parse(listedAttempts.body)[0].attempts[0].phase, "build");
|
||||
const repeated = await request("/admin/miniapp-releases", {
|
||||
method: "POST",
|
||||
headers,
|
||||
@@ -591,18 +607,21 @@ test("miniapp release tasks are authorized, idempotent, and state checked", asyn
|
||||
});
|
||||
assert.equal(uploaded.statusCode, 200);
|
||||
assert.equal(JSON.parse(uploaded.body).status, "uploaded");
|
||||
assert.equal(JSON.parse(uploaded.body).uploadStatus, "uploaded");
|
||||
const underReview = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "under_review" },
|
||||
});
|
||||
assert.equal(JSON.parse(underReview.body).status, "under_review");
|
||||
assert.equal(JSON.parse(underReview.body).reviewStatus, "under_review");
|
||||
const approved = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "approved" },
|
||||
});
|
||||
assert.equal(JSON.parse(approved.body).status, "approved");
|
||||
assert.equal(JSON.parse(approved.body).reviewStatus, "approved");
|
||||
const published = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
@@ -628,6 +647,60 @@ test("miniapp release tasks are authorized, idempotent, and state checked", asyn
|
||||
await prisma.miniAppReleaseTask.delete({ where: { id: buildingTask.id } });
|
||||
});
|
||||
|
||||
test("API restart recovers an expired persisted miniapp build attempt", async () => {
|
||||
const task = await prisma.miniAppReleaseTask.create({
|
||||
data: {
|
||||
brandId,
|
||||
version: 900002,
|
||||
actorId: "integration-restart-test",
|
||||
status: "built",
|
||||
buildStatus: "idle",
|
||||
},
|
||||
});
|
||||
try {
|
||||
const runningApi = app.get(AdminMiniAppReleaseService);
|
||||
const first = await runningApi.acquireAttempt(
|
||||
brandId,
|
||||
"integration-restart-test",
|
||||
task.id,
|
||||
"build",
|
||||
);
|
||||
assert.equal(
|
||||
(await prisma.miniAppReleaseAttempt.findUniqueOrThrow({ where: { id: first.id } })).status,
|
||||
"running",
|
||||
);
|
||||
|
||||
await app.close();
|
||||
await prisma.miniAppReleaseAttempt.update({
|
||||
where: { id: first.id },
|
||||
data: { leaseExpiresAt: new Date(Date.now() - 1_000) },
|
||||
});
|
||||
app = await createApp();
|
||||
await app.init();
|
||||
|
||||
const restartedApi = app.get(AdminMiniAppReleaseService);
|
||||
const recovered = await restartedApi.acquireAttempt(
|
||||
brandId,
|
||||
"integration-restart-test",
|
||||
task.id,
|
||||
"build",
|
||||
);
|
||||
const attempts = await prisma.miniAppReleaseAttempt.findMany({
|
||||
where: { taskId: task.id, phase: "build" },
|
||||
orderBy: { attempt: "asc" },
|
||||
});
|
||||
assert.equal(recovered.attempt, 2);
|
||||
assert.equal(attempts[0].status, "timed_out");
|
||||
assert.equal(attempts[1].status, "running");
|
||||
assert.equal(
|
||||
(await prisma.miniAppReleaseTask.findUniqueOrThrow({ where: { id: task.id } })).buildStatus,
|
||||
"building",
|
||||
);
|
||||
} finally {
|
||||
await prisma.miniAppReleaseTask.delete({ where: { id: task.id } });
|
||||
}
|
||||
});
|
||||
|
||||
test("miniapp release settings never expose or persist plaintext private keys", async () => {
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
|
||||
Reference in new issue
Block a user