fix: 打通小程序代码上传链路
小程序上传此前连续失败,根因分散在状态机、产物路径、模块导入、私钥解析和进程隔离上,逐项修复: - 构建进度改用 updateBuild 只写 buildStatus/buildLogs,不再用 updateStatus 记录进度,避免状态机拒绝自我迁移而返回 409 - 产物目录锚定仓库根目录,不再随 API 进程工作目录变成 apps/api/apps/taro/dist - miniprogram-ci 为 CommonJS 包,动态导入后从 default 归一化取 Project/upload,替换原有的类型断言 - 上传私钥统一还原成合法 PEM;输入框曾把换行吞成单行,导致 OpenSSL 解码失败,现保存时校验、上传时自动修复存量数据 - 上传改在独立子进程执行,miniprogram-ci 崩溃或超时不再终止 API 进程,失败返回 502 并保留微信原始错误 - 构建超过 MINIAPP_BUILD_STALE_MS 无进度即视为中断,允许重新上传,避免任务永久卡在 building - 构建前校验请求地址与 AppID,请求地址支持在品牌配置中维护,环境变量仅作回落,避免再打出指向 localhost 的包 - 小程序 /media/ 按请求地址的 origin 解析,不再依赖网关剥离 /api 前缀 新增对应单测与集成断言,并更新部署说明。
This commit is contained in:
1 parent
f52577ff9e
commit
44fe7a0142
27 files changed
+986
-62
No files matched your search
@@ -94,6 +94,23 @@ test("miniapp release tasks are authorized, idempotent, and state checked", asyn
|
||||
payload: { status: "published" },
|
||||
});
|
||||
assert.equal(JSON.parse(published.body).status, "published");
|
||||
|
||||
const buildingTask = await prisma.miniAppReleaseTask.create({
|
||||
data: {
|
||||
brandId,
|
||||
version: 900001,
|
||||
actorId: "integration-test",
|
||||
status: "built",
|
||||
buildStatus: "building",
|
||||
},
|
||||
});
|
||||
const busy = await request(`/admin/miniapp-releases/${buildingTask.id}/upload`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: {},
|
||||
});
|
||||
assert.equal(busy.statusCode, 409);
|
||||
await prisma.miniAppReleaseTask.delete({ where: { id: buildingTask.id } });
|
||||
});
|
||||
|
||||
test("miniapp release settings never expose or persist plaintext private keys", async () => {
|
||||
@@ -102,18 +119,47 @@ test("miniapp release settings never expose or persist plaintext private keys",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const headers = { authorization: `Bearer ${JSON.parse(login.body).token}` };
|
||||
const privateKey = `-----BEGIN TEST KEY-----\n${Date.now()}\n-----END TEST KEY-----`;
|
||||
const { generateKeyPairSync } = await import("node:crypto");
|
||||
const privateKey = generateKeyPairSync("rsa", {
|
||||
modulusLength: 2048,
|
||||
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
||||
publicKeyEncoding: { type: "spki", format: "pem" },
|
||||
}).privateKey;
|
||||
const invalid = await request("/admin/miniapp-releases/settings", {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: {
|
||||
appId: "wxtestsettings",
|
||||
privateKey: "-----BEGIN PRIVATE KEY-----\nMIIB\n-----END PRIVATE KEY-----",
|
||||
},
|
||||
});
|
||||
assert.equal(invalid.statusCode, 400);
|
||||
const rejected = await request("/admin/miniapp-releases/settings", {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { appId: "wxtestsettings", apiBaseUrl: "http://wechat.example.com/api" },
|
||||
});
|
||||
assert.equal(rejected.statusCode, 400);
|
||||
const saved = await request("/admin/miniapp-releases/settings", {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { appId: "wxtestsettings", privateKey },
|
||||
payload: {
|
||||
appId: "wxtestsettings",
|
||||
apiBaseUrl: "https://wechat.example.com/api/",
|
||||
privateKey,
|
||||
},
|
||||
});
|
||||
assert.equal(saved.statusCode, 200);
|
||||
const body = JSON.parse(saved.body);
|
||||
assert.equal(body.appId, "wxtestsettings");
|
||||
assert.equal(body.apiBaseUrl, "https://wechat.example.com/api");
|
||||
assert.equal(body.requestDomain, "wechat.example.com");
|
||||
assert.equal(body.hasStoredCredentials, true);
|
||||
assert.equal(body.privateKey, undefined);
|
||||
assert.equal(body.credential?.algorithm, "aes-256-gcm");
|
||||
assert.ok(body.requestDomain === null || typeof body.requestDomain === "string");
|
||||
assert.ok(body.buildError === null || typeof body.buildError === "string");
|
||||
if (typeof body.requestDomain === "string") assert.ok(!body.requestDomain.includes("localhost"));
|
||||
const brand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
|
||||
const credential = brand.miniAppSettings?.credential;
|
||||
assert.ok(credential);
|
||||
|
||||
Reference in new issue
Block a user