144 lines
7.1 KiB
TypeScript
144 lines
7.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
alphaBaseRefFor, alphaVersionOf, isAlphaBranch, isAlphaPriority, latestAlphaBranch, parseRetarget, retargetBlock,
|
|
retargetBranchName, settleRetargetPatch, type TaskRetarget,
|
|
} from "@bbbug/shared/alpha_branch";
|
|
import { customBranchNote } from "@bbbug/shared/product_profiles";
|
|
|
|
describe("认 alpha 分支", () => {
|
|
test("两端写法不同,版本号折算成一样的", () => {
|
|
expect(alphaVersionOf("android", "alpha/v4770")).toEqual([47, 7, 0]);
|
|
expect(alphaVersionOf("ios", "alpha/47.7.0")).toEqual([47, 7, 0]);
|
|
expect(alphaVersionOf("android", "alpha/47.7.0")).toBeNull();
|
|
expect(alphaVersionOf("ios", "alpha/v4770")).toBeNull();
|
|
});
|
|
|
|
test("只认顶层的:lite / whee / 个人分支和带后缀的都不算", () => {
|
|
expect(latestAlphaBranch("android", [
|
|
"refs/heads/alpha/v4760", "refs/heads/alpha/v4770", "refs/heads/lite/alpha/v4780",
|
|
"refs/heads/whee/alpha/v4790", "refs/heads/alpha/v4790_test", "refs/heads/zl/alpha/v4800",
|
|
])).toBe("alpha/v4770");
|
|
expect(latestAlphaBranch("ios", ["alpha/47.6.0", "yaorx/alpha/47.9.0-test", "alpha/47.7.0", "alpha/47.8.0-x"])).toBe("alpha/47.7.0");
|
|
expect(latestAlphaBranch("android", [])).toBeNull();
|
|
});
|
|
|
|
test("按版本号比,不按字典序", () => {
|
|
expect(latestAlphaBranch("ios", ["alpha/47.9.0", "alpha/47.10.0", "alpha/46.12.0"])).toBe("alpha/47.10.0");
|
|
});
|
|
});
|
|
|
|
describe("增量托管:哪张单走 alpha", () => {
|
|
const latest = "alpha/v4770";
|
|
const pick = (priority: string | null, discoveryVersions: string[] = []) =>
|
|
alphaBaseRefFor({ platform: "android", priority, discoveryVersions, latest });
|
|
|
|
test("P0、P1 走,P2 及以下、没填优先级都不走", () => {
|
|
expect(isAlphaPriority("P0")).toBe(true);
|
|
expect(pick("P0")).toBe(latest);
|
|
expect(pick("P1")).toBe(latest);
|
|
expect(pick("P2")).toBeNull();
|
|
expect(pick("P3")).toBeNull();
|
|
expect(pick(null)).toBeNull();
|
|
});
|
|
|
|
test("发现版本比最新 alpha 新:这版还没切 alpha,留在主干", () => {
|
|
expect(pick("P1", ["TikTok-M-Android-47.8.0"])).toBeNull();
|
|
});
|
|
|
|
test("发现版本等于或早于最新 alpha、或读不到:走 alpha", () => {
|
|
expect(pick("P1", ["TikTok-M-Android-47.7.0"])).toBe(latest);
|
|
expect(pick("P1", ["TikTok-M-Android-47.5.0"])).toBe(latest);
|
|
expect(pick("P1", [])).toBe(latest);
|
|
expect(pick("P1", ["乱写的版本名"])).toBe(latest);
|
|
});
|
|
|
|
test("查不到最新 alpha:走主干,不卡建单", () => {
|
|
expect(alphaBaseRefFor({ platform: "android", priority: "P1", discoveryVersions: [], latest: null })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("提示词:alpha 不能再被说成特性分支", () => {
|
|
test("alpha 说版本分支,特性分支文案不变", () => {
|
|
expect(customBranchNote({ baseRef: "alpha/v4770" }, "develop")).toContain("版本分支");
|
|
expect(customBranchNote({ baseRef: "alpha/v4770" }, "develop")).not.toContain("特性分支");
|
|
expect(customBranchNote({ baseRef: "p/x/feature" }, "develop")).toContain("特性分支");
|
|
expect(customBranchNote({ baseRef: null }, "develop")).toBe("");
|
|
});
|
|
});
|
|
|
|
describe("重做到 alpha:能不能发起", () => {
|
|
const ok = { status: "manual_review", platform: "android", branchName: "bugfix/x", baseRef: null };
|
|
const L = "alpha/v4770";
|
|
test("待复核、主干上的单可以", () => expect(retargetBlock(ok, L)).toBeNull());
|
|
test("上一个 alpha 上的可以再挪", () => expect(retargetBlock({ ...ok, baseRef: "alpha/v4760" }, L)).toBeNull());
|
|
test("基线写明 develop 等同主干", () => expect(retargetBlock({ ...ok, baseRef: "develop" }, L)).toBeNull());
|
|
test.each([
|
|
["不是待复核", { status: "fixing" }],
|
|
["MR 已合入", { mrState: "merged" }],
|
|
["MR 已合入(时间戳)", { mrMergedAt: 1 }],
|
|
["没有分支", { branchName: null }],
|
|
["其它产品", { productProfile: { id: "x" } }],
|
|
["有附加仓", { codeSidecars: [{}] }],
|
|
["已在最新", { baseRef: L }],
|
|
["比最新还新", { baseRef: "alpha/v4780" }],
|
|
["特性分支基线", { baseRef: "p/x/feature" }],
|
|
])("%s 不行", (_n, over) => expect(retargetBlock({ ...ok, ...over }, L)).toBeTruthy());
|
|
test("查不到 alpha 不行", () => expect(retargetBlock(ok, null)).toBeTruthy());
|
|
});
|
|
|
|
describe("重做到 alpha:新分支名", () => {
|
|
test("加后缀;再挪一次替换后缀,不叠", () => {
|
|
expect(retargetBranchName("bugfix/x", "alpha/v4770")).toBe("bugfix/x-alpha-v4770");
|
|
expect(retargetBranchName("bugfix/x", "alpha/47.7.0")).toBe("bugfix/x-alpha-47.7.0");
|
|
expect(retargetBranchName("bugfix/x-alpha-v4760", "alpha/v4770")).toBe("bugfix/x-alpha-v4770");
|
|
});
|
|
});
|
|
|
|
describe("重做到 alpha:一轮结束怎么落", () => {
|
|
const r: TaskRetarget = { ref: "alpha/v4770", fromBranch: "bugfix/x", fromBase: "develop", oldMrUrl: "https://bits/old", by: "a", at: 1, phase: "running" };
|
|
|
|
test("成功:换基线、清 MR 触发新建,旧 MR 记着等关", () => {
|
|
const patch: Record<string, unknown> = { status: "manual_review", branchName: "bugfix/x-alpha-v4770" };
|
|
expect(settleRetargetPatch(r, patch)).toBe("moved");
|
|
expect(patch).toMatchObject({ status: "manual_review", baseRef: "alpha/v4770", mrUrl: null, mrState: null });
|
|
expect((patch.retarget as TaskRetarget).phase).toBe("closing_old");
|
|
});
|
|
|
|
test("成功但原来没有 MR:没东西要关,直接清掉", () => {
|
|
const patch: Record<string, unknown> = { status: "manual_review", branchName: "bugfix/x-alpha-v4770" };
|
|
settleRetargetPatch({ ...r, oldMrUrl: null }, patch);
|
|
expect(patch.retarget).toBeNull();
|
|
});
|
|
|
|
test("报成功但还在原分支:按失败,绝不换基线", () => {
|
|
const patch: Record<string, unknown> = { status: "manual_review", branchName: "bugfix/x" };
|
|
expect(settleRetargetPatch(r, patch)).toBe("failed");
|
|
expect(patch.baseRef).toBeUndefined();
|
|
expect("mrUrl" in patch).toBe(false);
|
|
expect((patch.retarget as TaskRetarget).phase).toBe("failed");
|
|
});
|
|
|
|
test.each(["fix_failed", "unreproducible"])("%s:退回待复核,分支还原,MR 不碰", (status) => {
|
|
const patch: Record<string, unknown> = { status, branchName: "bugfix/x-alpha-v4770", failureReason: "冲突解决不了" };
|
|
expect(settleRetargetPatch(r, patch)).toBe("failed");
|
|
expect(patch).toMatchObject({ status: "manual_review", branchName: "bugfix/x", failureReason: null });
|
|
expect("mrUrl" in patch).toBe(false);
|
|
expect("baseRef" in patch).toBe(false);
|
|
expect((patch.retarget as TaskRetarget).error).toBeTruthy();
|
|
});
|
|
|
|
test("中途的状态(再排一轮)不结算", () => {
|
|
const patch: Record<string, unknown> = { status: "awaiting_fix" };
|
|
expect(settleRetargetPatch(r, patch)).toBeNull();
|
|
expect(patch).toEqual({ status: "awaiting_fix" });
|
|
});
|
|
|
|
test("库里读出来坏数据当没有", () => {
|
|
expect(parseRetarget("not json")).toBeNull();
|
|
expect(parseRetarget(null)).toBeNull();
|
|
expect(parseRetarget(JSON.stringify({ ref: "x", phase: "weird" }))).toBeNull();
|
|
expect(parseRetarget(JSON.stringify(r))?.ref).toBe("alpha/v4770");
|
|
expect(isAlphaBranch("alpha/v4770")).toBe(true);
|
|
});
|
|
});
|