Files
2026-11-16 17:26:44 -08:00

82 lines
3.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MUST be first — pins env before anything that reads it at module load.
import "./setup_env";
import { test, expect, describe } from "bun:test";
import { handoverCandidates, handoverStep } from "../src/mr_handover";
import { planMrRegeneration } from "../src/mr_regenerate";
import type { MrSubmitter } from "../src/mr_submission_identity";
const item = (over: Record<string, unknown> = {}) =>
({ kind: "bug" as const, id: "t1", status: "manual_review", watchers: ["rd.li@bytedance.com"], ...over });
describe("handoverCandidates", () => {
test("待复核、关注人里有他的 Bug / Feature", () => {
const got = handoverCandidates([
item(),
item({ id: "f1", kind: "feature" }),
item({ id: "t2", status: "fixing" }),
item({ id: "t3", watchers: ["qa.zhang@bytedance.com"] }),
item({ id: "t4", status: "archived" }),
], "rd.li");
expect(got.map((x) => x.id)).toEqual(["t1", "f1"]);
});
test("按邮箱前缀比,不认非邮箱的关注人", () => {
expect(handoverCandidates([item({ watchers: ["RD.Li@bytedance.com"] })], "rd.li@bytedance.com")).toHaveLength(1);
expect(handoverCandidates([item({ watchers: ["rd.li"] })], "rd.li")).toHaveLength(0);
});
});
const sub = (user: string, roles: MrSubmitter["roles"], hasToken = true): MrSubmitter => ({ user, roles, hasToken });
describe("handoverStep:没有 MR", () => {
test("他是经办人、默认提交人就是他:提交", () => {
const s = handoverStep({ user: "rd.li", kind: "bug", hasMr: false, submitters: [sub("rd.li", ["assignee", "watcher"]), sub("qa.zhang", ["watcher"])] });
expect(s).toEqual({ do: "submit" });
});
test("Feature 建单人:提交", () => {
const s = handoverStep({ user: "pm.wu", kind: "feature", hasMr: false, submitters: [sub("pm.wu", ["creator", "watcher"])] });
expect(s).toEqual({ do: "submit" });
});
test("非 Meego Bug(UI 走查转出的)的建单人:提交", () => {
const s = handoverStep({ user: "qa.liu", kind: "bug", hasMr: false, submitters: [sub("qa.liu", ["creator", "watcher"])] });
expect(s).toEqual({ do: "submit" });
});
test("只是关注人:不动", () => {
const s = handoverStep({ user: "qa.zhang", kind: "bug", hasMr: false, submitters: [sub("rd.li", ["assignee"], false), sub("qa.zhang", ["watcher"])] });
expect(s.do).toBe("skip");
});
test("排在前面的另一位经办人也绑了:归他,不动", () => {
const s = handoverStep({ user: "rd.wang", kind: "bug", hasMr: false, submitters: [sub("rd.li", ["assignee"]), sub("rd.wang", ["assignee"])] });
expect(s.do).toBe("skip");
});
});
describe("handoverStep:已有 MR", () => {
const plan = (author: string, withToken: string[], assignees = ["rd.li"]) =>
planMrRegeneration({ assignees, withToken: new Set(withToken), mr: { mrId: 1, author, state: "opened", merged: false } });
test("Bug 的 MR 在导入人名下、重建会落到他:重建", () => {
expect(handoverStep({ user: "rd.li", kind: "bug", hasMr: true, regen: plan("importer", ["rd.li"]) })).toEqual({ do: "regen" });
});
test("已在他名下:不动", () => {
expect(handoverStep({ user: "rd.li", kind: "bug", hasMr: true, regen: plan("rd.li", ["rd.li"]) }).do).toBe("skip");
});
test("重建会落到另一位经办人:不动", () => {
const s = handoverStep({ user: "rd.wang", kind: "bug", hasMr: true, regen: plan("importer", ["rd.li", "rd.wang"], ["rd.li", "rd.wang"]) });
expect(s.do).toBe("skip");
});
test("读不到重建判断 / Feature:不动", () => {
expect(handoverStep({ user: "rd.li", kind: "bug", hasMr: true, regen: { error: "当前状态 archived 不能重建 MR" } }).do).toBe("skip");
expect(handoverStep({ user: "pm.wu", kind: "feature", hasMr: true }).do).toBe("skip");
});
});