Files
streamline/control-web/test/submit_all_mrs.test.ts
T
2026-11-16 17:26:44 -08:00

69 lines
3.0 KiB
TypeScript

import { test, expect, describe } from "bun:test";
import { readFileSync } from "node:fs";
import path from "node:path";
/**
* 「一次提交全部 MR」—— 钉住的是它<b>怎么失败</b>,而不是它长什么样。
*
* 多仓交付里「部分成功」是常态而不是异常:跨团队仓的写权限往往只批下来一部分
* (试点里 9 堵权限墙分属 9 个平台)。所以这个按钮有两条不能松的性质:
*
* 一、**串行**。每次调用都在 Codebase 上真的建 MR,还各自跑一遍权限闸;并发时
* 失败原因会混在一起分不清是哪个仓。更要命的是这轮实测已确认平台侧在并发下
* 会返回非 success 的响应而**不报错** —— 那会让一次平台故障看起来像
* 「这个仓提交失败」。
* 二、**失败不中断**。第一个仓没权限就停下,会把本来能提的那几个也挡住。
*/
const REPO = path.resolve(import.meta.dir, "../..");
const drawer = readFileSync(path.join(REPO, "control-web/src/components/TaskDetailDrawer.tsx"), "utf8");
const body = drawer.slice(drawer.indexOf("const submitAllMrs"), drawer.indexOf("const isPendingConfirm"));
describe("串行提交", () => {
test("用 for 循环挨个 await,而不是 Promise.all", () => {
expect(body).toContain("for (const st of steps)");
expect(body).toContain("await act.submitMr");
});
test("整个函数体里没有任何并发原语", () => {
for (const banned of ["Promise.all", "Promise.allSettled", "Promise.race"]) {
expect(body).not.toContain(banned);
}
});
});
describe("失败不中断,且逐仓归因", () => {
test("catch 在循环体内 —— 一个仓抛错不能带走整轮", () => {
const loopStart = body.indexOf("for (const st of steps)");
const loopEnd = body.indexOf("setMrRetrying(null)");
const loop = body.slice(loopStart, loopEnd);
expect(loop).toContain("try {");
expect(loop).toContain("catch");
});
test("失败逐条记下来并带上是哪个仓", () => {
expect(body).toContain("failed.push(`${st.key}");
});
test("汇总区分「全成 / 部分成 / 全败」三档", () => {
expect(body).toContain("if (!failed.length)");
expect(body).toContain("else if (ok)");
});
test("Bits Token 失效时仍然唤起补 Token 的入口", () => {
// 这是最常见的一类失败;漏掉它会让人对着一串「提交失败」找不到原因。
expect(body).toContain("Bits 个人 Token 已失效");
expect(body).toContain("setBitsTokenOpen(true)");
});
});
describe("按钮的出现条件", () => {
test("只在两个及以上待提时出现", () => {
// 只剩一个时它与那一行自己的按钮完全等价,多一个入口只是噪音。
expect(drawer).toContain("pending.length > 1 &&");
});
test("待提 = 还没有 MR 链接的那些步骤;主仓无改动时交付仓不算", () => {
expect(drawer).toContain(`codeSteps.filter((st) => !st.url && !(st.key === "delivery" && sidecarOnly))`);
});
});