小程序上传此前连续失败,根因分散在状态机、产物路径、模块导入、私钥解析和进程隔离上,逐项修复: - 构建进度改用 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 前缀 新增对应单测与集成断言,并更新部署说明。
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { buildingStaleMs, isStaleBuilding } from "../src/modules/admin/miniapp-build-status.js";
|
|
|
|
const now = Date.UTC(2026, 9, 13, 12, 0, 0);
|
|
|
|
function task(buildStatus: string, minutesAgo: number) {
|
|
return { buildStatus, updatedAt: new Date(now - minutesAgo * 60_000) };
|
|
}
|
|
|
|
test("构建中的任务在超过阈值未更新时视为已中断", () => {
|
|
assert.equal(isStaleBuilding(task("building", 1), now), false);
|
|
assert.equal(isStaleBuilding(task("building", 16), now), true);
|
|
assert.equal(isStaleBuilding(task("building", 24 * 60), now), true);
|
|
});
|
|
|
|
test("非 building 状态永远不算中断,避免误伤正常流程", () => {
|
|
for (const status of ["idle", "success", "failed"]) {
|
|
assert.equal(isStaleBuilding(task(status, 24 * 60), now), false);
|
|
}
|
|
});
|
|
|
|
test("时间戳异常时按未中断处理,宁可挡住重试也不允许并发构建", () => {
|
|
assert.equal(isStaleBuilding({ buildStatus: "building", updatedAt: "not-a-date" }, now), false);
|
|
});
|
|
|
|
test("阈值可通过环境变量覆盖,非法值回退到默认 15 分钟", () => {
|
|
assert.equal(buildingStaleMs("60000"), 60_000);
|
|
for (const invalid of [undefined, "0", "-1", "abc"]) {
|
|
assert.equal(buildingStaleMs(invalid), 15 * 60 * 1000);
|
|
}
|
|
});
|