Initial import of streamline
This commit is contained in:
@@ -0,0 +1,558 @@
|
||||
// MUST be first — pins env before anything that reads it at module load.
|
||||
import "./setup_env";
|
||||
|
||||
import { test, expect, describe, beforeAll, beforeEach, afterAll } from "bun:test";
|
||||
import { awaitingOwnerDevTaskReason, bugAutoMrBlocksWalk, createMergeRequest, describeBitsDevTaskCredentialError, findExistingMr, resolveDevTaskOperator, submitMrForFix, BITS_FIXED_OPERATOR } from "../src/bits";
|
||||
import { CODE_REPOS, REPO_UNPUSHED, repoByKey, repoForMr, type CodeRepoDef } from "@bbbug/shared/repos";
|
||||
|
||||
/**
|
||||
* `bits-dev-task` 通道的样本仓。tt_im_monorepo 2026-11 改走 code.byted.org MR(gitlab 通道,
|
||||
* 见 gitlab_mr_channel.test.ts)之后,生产注册表里没有仓走开发任务了;实现还在,就用一个
|
||||
* 只在本文件里存在的仓把它钉住 —— 值照搬 tt_im_monorepo 当时的开发任务配置。
|
||||
* beforeAll 加进注册表、afterAll 删掉,不往生产注册表里塞测试仓。
|
||||
*/
|
||||
const DEV_TASK_REPO_KEY = "test-dev-task-repo";
|
||||
const DEV_TASK_REPO: CodeRepoDef = {
|
||||
key: DEV_TASK_REPO_KEY,
|
||||
label: "tt_im_monorepo",
|
||||
platforms: ["android", "ios"],
|
||||
mrChannel: "bits-dev-task",
|
||||
mrTrigger: "auto",
|
||||
gitlabProjectId: 753114,
|
||||
codebaseRepoPath: null,
|
||||
bitsGroupName: null,
|
||||
bitsSpaceId: "39151416834",
|
||||
bitsDevTask: {
|
||||
teamFlowId: 424599259394,
|
||||
workflowId: 25538,
|
||||
projectType: "HYBRID",
|
||||
controlPanel: "I18N",
|
||||
repoPath: "tiktok/tt_im_monorepo",
|
||||
},
|
||||
localPaths: [],
|
||||
remoteHints: ["test/dev-task-fixture"],
|
||||
defaultTargetBranch: "master",
|
||||
webUrl: "https://code.byted.org/tiktok/tt_im_monorepo",
|
||||
};
|
||||
beforeAll(() => { CODE_REPOS.push(DEV_TASK_REPO); });
|
||||
afterAll(() => {
|
||||
const i = CODE_REPOS.indexOf(DEV_TASK_REPO);
|
||||
if (i >= 0) CODE_REPOS.splice(i, 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* MR 开在哪个仓 —— 以及开不了的时候说什么。
|
||||
*
|
||||
* 挡的是生产上真实发生过的一次:一个 android feature 改的是 IM 的 Lynx 前端,分支推到了
|
||||
* `tt_im_monorepo`,控制面照旧拿这个分支名去 TikTok 主仓建 MR,GitLab 回一句
|
||||
* 「source branch not found」。报错说分支不存在,真相是仓库找错了 —— 面板上这两件事
|
||||
* 长得一模一样,于是所有人先去查分支推没推,查完发现推了,再从头怀疑一遍。
|
||||
*
|
||||
* 所以这里断言两件事:默认路径一个字节都没变;非默认仓在**打 Bits 之前**就被拦下,
|
||||
* 并且拦下时说的是人能照着做的话。
|
||||
*/
|
||||
|
||||
const BRANCH = "feature/lynx-im-page-ui-tree-audit";
|
||||
const ANDROID_PROJECT = 113818;
|
||||
const IOS_PROJECT = 114467;
|
||||
|
||||
const realFetch = globalThis.fetch;
|
||||
let calls: { url: string; body: any; headers?: Headers }[] = [];
|
||||
|
||||
function bitsDevTaskPrepareReply(url: string, requestBody: any, fallback: unknown) {
|
||||
if (url.includes("/openapi/onesite/v1/user/me")) {
|
||||
return { code: 200, data: { jwtToken: "test-jwt", email: "johnlee@bytedance.com", username: "johnlee" } };
|
||||
}
|
||||
if (url.includes("/api/v1/dev/app/components")) {
|
||||
const uid = requestBody?.queryProjects?.[0]?.projectUniqueId || "68d38ce6003b041ba643fcf3";
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
projects: [{
|
||||
projectType: 5,
|
||||
projectUniqueId: uid,
|
||||
projectName: "tiktok_im_business_page",
|
||||
nodeId: "10990000",
|
||||
controlPlaneDetail: [{
|
||||
controlPlane: 2,
|
||||
scmInfo: [{
|
||||
id: "410000",
|
||||
name: "tiktok/im/business_page",
|
||||
isMain: true,
|
||||
gitRepoName: "tiktok/tt_im_monorepo",
|
||||
gitRepoId: "753114",
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
},
|
||||
};
|
||||
}
|
||||
if (url.includes("/api/v1/dev/config/workflow/get")) {
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
workflow: {
|
||||
orchestration: [{
|
||||
id: 766087,
|
||||
name: "自测流水线",
|
||||
nodeType: 10,
|
||||
nodeConfig: {
|
||||
ciPipelineNodeConfig: {
|
||||
env: {
|
||||
ppe: {
|
||||
enabled: true,
|
||||
lanes: [{
|
||||
laneType: "ppe_i18n_env_",
|
||||
laneId: "feature_d_${random}",
|
||||
overwritePrefix: "ppe_",
|
||||
laneGcStrategy: 1,
|
||||
envTypes: [2],
|
||||
}],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
if (url.includes("/api/v5/env/env_manager/get_project_env_config")) {
|
||||
return {
|
||||
BaseResp: { StatusCode: 0 },
|
||||
nodeConfigs: requestBody?.nodeConfigs ?? [{
|
||||
nodeID: 766087,
|
||||
nodeName: "自测流水线",
|
||||
ppe: { enabled: true, lanes: [{ laneType: "ppe_i18n_env_", laneId: "feature_d_${random}", overwritePrefix: "ppe_", laneGcStrategy: 1, envTypes: [2] }] },
|
||||
}],
|
||||
projectConfigs: [{ projectUniqueId: "68d38ce6003b041ba643fcf3" }],
|
||||
};
|
||||
}
|
||||
if (url.includes("/api/v1/dev/task/checks/mr")) {
|
||||
return { code: 200, data: { hasExisted: false } };
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function stubFetch(reply: unknown = { code: 200, data: { mr_id: 8327494 } }) {
|
||||
calls = [];
|
||||
globalThis.fetch = (async (input: any, init?: RequestInit) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
let body: any = null;
|
||||
try { body = init?.body ? JSON.parse(String(init.body)) : null; } catch { /* keep null */ }
|
||||
calls.push({ url, body, headers: new Headers(init?.headers) });
|
||||
const response = bitsDevTaskPrepareReply(url, body, reply);
|
||||
return new Response(JSON.stringify(response), { status: 200, headers: { "content-type": "application/json" } });
|
||||
}) as typeof fetch;
|
||||
}
|
||||
|
||||
beforeEach(() => { calls = []; });
|
||||
afterAll(() => { globalThis.fetch = realFetch; });
|
||||
|
||||
describe("默认仓 · 老行为一字不改", () => {
|
||||
test("整条流水线:请求体逐字段与改动前相同,步骤顺序不变,不碰 code.byted.org", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android",
|
||||
sourceBranch: BRANCH,
|
||||
targetBranch: "develop",
|
||||
title: "[bug] 标题",
|
||||
mrType: "bug",
|
||||
bitsUser: "jingyuan.yi",
|
||||
note: "streamline: …",
|
||||
meegoWorkItems: [{ taskId: "7034950124", taskType: "bug", projectKey: "tiktok" }],
|
||||
assigneeEmail: "a@bytedance.com",
|
||||
reporterEmail: "b@bytedance.com",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
// 建 MR 的请求体是这条通路上最不能动的东西 —— 整体比对,少一个字段就红。
|
||||
expect(calls[0].body).toEqual({
|
||||
host_group_name: "TikTok_Android",
|
||||
hosts: [{ project_gitlab_id: ANDROID_PROJECT, source: BRANCH, target: "develop" }],
|
||||
type: "bug",
|
||||
optimize: "[bug] 标题",
|
||||
mr_reviewers: [],
|
||||
skip_feature_check: true,
|
||||
review_fetch_mode: 0,
|
||||
review_start_type: 1,
|
||||
});
|
||||
expect(r.steps.map((s) => s.step)).toEqual([
|
||||
"create_mr", "set_note", "bind_meego", "start_review", "reviewers_rd", "reviewers_qa",
|
||||
]);
|
||||
expect(r.steps.every((s) => s.ok)).toBe(true);
|
||||
expect(r.mrUrl).toBe("https://bits.bytedance.net/devops/1499114242/code/detail/8327494");
|
||||
// 这次改动引入的第二条通道,绝不能出现在主通路上。
|
||||
expect(calls.every((c) => c.url.startsWith("https://bits.bytedance.net"))).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
test("不带 repoKey 时,create 打的还是 platform 那个 project / group", async () => {
|
||||
stubFetch();
|
||||
const r = await createMergeRequest({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "feature",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(calls[0].url).toContain("/merge_request/create");
|
||||
expect(calls[0].body.host_group_name).toBe("TikTok_Android");
|
||||
expect(calls[0].body.hosts[0].project_gitlab_id).toBe(ANDROID_PROJECT);
|
||||
});
|
||||
|
||||
test("显式给 platform 默认仓的 key,等价于不给", async () => {
|
||||
stubFetch();
|
||||
await createMergeRequest({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "feature", repoKey: "tiktok-android",
|
||||
});
|
||||
expect(calls[0].body.hosts[0].project_gitlab_id).toBe(ANDROID_PROJECT);
|
||||
});
|
||||
|
||||
test("TikTok iOS 只多打开 BUILD_TIKTOK_T,其余字段与安卓同一套默认", async () => {
|
||||
stubFetch();
|
||||
const r = await createMergeRequest({
|
||||
platform: "ios", sourceBranch: BRANCH, targetBranch: "alpha/47.4.0",
|
||||
title: "t", mrType: "bug", repoKey: "tiktok-ios",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(calls[0].body).toEqual({
|
||||
host_group_name: "TikTok_iOS",
|
||||
hosts: [{ project_gitlab_id: IOS_PROJECT, source: BRANCH, target: "alpha/47.4.0" }],
|
||||
type: "bug",
|
||||
optimize: "t",
|
||||
mr_reviewers: [],
|
||||
skip_feature_check: true,
|
||||
review_fetch_mode: 0,
|
||||
review_start_type: 1,
|
||||
custom_fields: { CUSTOM_CI_BUILD_TIKTOK_T: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("reviewer 只来自单上的人 · 不再默认加固定操作人", () => {
|
||||
// 以前每条 MR 都会把 BITS_FIXED_OPERATOR(jiaopengwen)额外加成 RD reviewer,
|
||||
// 于是所有单(包括没有经办人的 feature)的评审队列都落到同一个人头上。
|
||||
// 现在 RD 只取 Meego 经办人,没有就不加。
|
||||
const callWithRole = (role: string) =>
|
||||
calls.find((c) => c.url.includes("/openapi/merge_request/reviewer") && c.body?.role === role);
|
||||
|
||||
test("有经办人时,RD 只有经办人一个", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android",
|
||||
sourceBranch: BRANCH,
|
||||
targetBranch: "develop",
|
||||
title: "[bug] 标题",
|
||||
mrType: "bug",
|
||||
assigneeEmail: "a@bytedance.com",
|
||||
reporterEmail: "b@bytedance.com",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(callWithRole("RD")?.body.username).toEqual(["a"]);
|
||||
expect(callWithRole("RD")?.body.username).not.toContain(BITS_FIXED_OPERATOR);
|
||||
expect(callWithRole("QA")?.body.username).toEqual(["b"]);
|
||||
});
|
||||
|
||||
test("没有经办人邮箱时,不加 RD reviewer,并在步骤里说清楚", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android",
|
||||
sourceBranch: BRANCH,
|
||||
targetBranch: "develop",
|
||||
title: "[feature] 标题",
|
||||
mrType: "feature",
|
||||
reporterEmail: "b@bytedance.com",
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(calls.some((c) => c.url.includes("/openapi/merge_request/reviewer") && c.body?.role === "RD")).toBe(false);
|
||||
expect(r.steps.find((s) => s.step === "reviewers_rd")).toMatchObject({
|
||||
ok: true,
|
||||
error: "no assignee email — skipped",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("非默认仓 · 在打 Bits 之前就拦住", () => {
|
||||
test("失效的个人 Token 报错归到点击者,并明确引导更新", () => {
|
||||
const error = describeBitsDevTaskCredentialError(
|
||||
'HTTP 401: {"error":"Invalid JWT token"}',
|
||||
"johnlee",
|
||||
);
|
||||
expect(error).toContain("当前登录用户 johnlee");
|
||||
expect(error).toContain("更新「Bits 个人 Token」");
|
||||
expect(error).toContain("Invalid JWT token");
|
||||
expect(describeBitsDevTaskCredentialError("HTTP 500: unavailable", "johnlee"))
|
||||
.toBe("HTTP 500: unavailable");
|
||||
expect(describeBitsDevTaskCredentialError('HTTP 401: {"error":"Invalid JWT token"}', null))
|
||||
.toBe('HTTP 401: {"error":"Invalid JWT token"}');
|
||||
});
|
||||
|
||||
test("没有 bits-dev-task 应用 ⇒ 跳过 create,一次 Bits 请求都不发", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "feature", repoKey: DEV_TASK_REPO_KEY,
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(r.skippedCreate).toBe(true);
|
||||
expect(r.mrId).toBeNull();
|
||||
expect(r.mrUrl).toBeNull();
|
||||
expect(calls.length).toBe(0);
|
||||
const [step] = r.steps;
|
||||
expect(step.step).toBe("create_dev_task");
|
||||
expect(step.ok).toBe(true);
|
||||
expect(step.error).toContain("skipped");
|
||||
});
|
||||
|
||||
/** 人点后只创建开发任务并立即回填任务链接;不等待异步 MR,也不跑 mr-id 后置步骤。 */
|
||||
test("人点的那一次 ⇒ 创建需求研发开发任务,不再把 space 名误传成 group", async () => {
|
||||
stubFetch({ code: 200, data: { devBasicId: 2709999 } });
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH,
|
||||
title: "[bug] 标题", mrType: "bug", repoKey: DEV_TASK_REPO_KEY, trigger: "manual",
|
||||
bitsUser: "jingyuan.yi",
|
||||
tokenUser: "jingyuan.yi",
|
||||
devTaskApplications: [{ projectName: "tiktok_im_business_page", scmName: "tiktok/im/business_page", projectUniqueId: "68d38ce6003b041ba643fcf3" }],
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(calls.filter((c) => c.url.includes("/openapi/onesite/v1/dev/create"))).toHaveLength(1);
|
||||
const createCall = calls.find((c) => c.url.includes("/openapi/onesite/v1/dev/create"))!;
|
||||
expect(createCall.url).not.toContain("/openapi/merge_request/create");
|
||||
expect(createCall.body.task).toMatchObject({
|
||||
space_id: 39151416834,
|
||||
team_flow_id: 424599259394,
|
||||
dev_task_template_id: 25538,
|
||||
});
|
||||
expect(createCall.body.changes[0].manifest.code_element.target_branch).toBe("master");
|
||||
expect(r.mrId).toBeNull();
|
||||
expect(r.steps.map((s) => s.step)).toEqual(["create_dev_task"]);
|
||||
expect(r.mrUrl).toBe("https://bits.bytedance.net/devops/39151416834/develop/detail/2709999?devops_space_type=server_fe");
|
||||
const createHeaders = createCall.headers!;
|
||||
expect(createHeaders.get("authorization")).toMatch(/^Bearer /);
|
||||
expect(createHeaders.has("x-bits-user")).toBe(false);
|
||||
expect(createHeaders.has("x-jwt-token")).toBe(false);
|
||||
});
|
||||
|
||||
test("仓库元数据没解析出应用 ⇒ 一次 Bits 请求都不发", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH,
|
||||
title: "[bug] 标题", mrType: "bug", repoKey: DEV_TASK_REPO_KEY, trigger: "manual",
|
||||
devTaskResolutionError: "执行节点未找到可校验元数据检出",
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
expect(calls).toHaveLength(0);
|
||||
expect(r.steps).toEqual([{
|
||||
step: "create_dev_task",
|
||||
ok: false,
|
||||
error: expect.stringContaining("执行节点未找到可校验元数据检出"),
|
||||
}]);
|
||||
});
|
||||
|
||||
test("分支哪个已知仓的远端都没有 ⇒ 同样先拦下,并说清楚重试没用", async () => {
|
||||
stubFetch();
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "feature", repoKey: REPO_UNPUSHED,
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
// 先按分支捞过一次已有 MR(见下一条用例),没捞到才拦 —— 但绝不会去建。
|
||||
expect(calls.every((c) => c.url.includes("/merge_request/search"))).toBe(true);
|
||||
expect(r.steps[0].step).toBe("preflight");
|
||||
expect(r.steps[0].error).toContain("没有推到交付仓");
|
||||
expect(r.steps[0].error).toContain("TikTok (Android)");
|
||||
expect(r.steps[0].error).not.toContain("tt_im_monorepo");
|
||||
});
|
||||
|
||||
test("不认识的 repoKey ⇒ 退回 platform 默认仓,而不是拒绝服务", async () => {
|
||||
// 老行、手工写坏的值、以及一个仓被从注册表里删掉之后的存量行,都会走到这里。
|
||||
// 认领 MR 时仍按默认仓的 project id 核对 —— 生产上实测过同一个 `feat/test-mr`
|
||||
// 同时命中 unisus 与 TiktokShopAndroid 两个仓,不核对就会认错。
|
||||
globalThis.fetch = (async (input: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
calls.push({ url, body: null });
|
||||
const body = url.includes("/merge_request/search")
|
||||
? { code: 200, data: [8327494] }
|
||||
: { code: 200, data: { id: 8327494, iid: 296301, project_id: ANDROID_PROJECT, from_branch: BRANCH, target_branch: "develop", state: "opened" } };
|
||||
return new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } });
|
||||
}) as typeof fetch;
|
||||
calls = [];
|
||||
const found = await findExistingMr({
|
||||
platform: "android", repoKey: "no-such-repo", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
});
|
||||
expect(found?.mrId).toBe(8327494);
|
||||
});
|
||||
|
||||
test("分支不在任何已知仓的远端、但这条分支上已有 MR ⇒ 认领它,而不是拿报错换掉一次恢复", async () => {
|
||||
// 老代码靠 create 失败之后的 findExistingMr 捞回这种情况(create 其实成功了但回包
|
||||
// 没到我们手里 / MR 建好之后源分支被删)。预检把 create 拦掉了,这条路不能跟着没。
|
||||
globalThis.fetch = (async (input: any) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
calls.push({ url, body: null });
|
||||
const body = url.includes("/merge_request/search")
|
||||
? { code: 200, data: [8327494] }
|
||||
: url.includes("/merge_request/info")
|
||||
? { code: 200, data: { id: 8327494, iid: 296301, project_id: ANDROID_PROJECT, from_branch: BRANCH, target_branch: "develop", state: "opened" } }
|
||||
: { code: 200, data: {} };
|
||||
return new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } });
|
||||
}) as typeof fetch;
|
||||
calls = [];
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "bug", repoKey: REPO_UNPUSHED,
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
expect(r.mrId).toBe(8327494);
|
||||
expect(r.steps[0].step).toBe("preflight");
|
||||
expect(r.steps[0].ok).toBe(true);
|
||||
expect(r.steps[0].error).toContain("认领它");
|
||||
// 没有再去建一次。
|
||||
expect(calls.some((c) => c.url.includes("/merge_request/create"))).toBe(false);
|
||||
});
|
||||
|
||||
test("agent 自己已经开好的 MR 不受预检影响 —— 它已经存在了,拦它没有意义", async () => {
|
||||
stubFetch({ code: 200, data: {} });
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "t", mrType: "feature", repoKey: REPO_UNPUSHED, existingMrId: 8327494,
|
||||
});
|
||||
expect(r.mrId).toBe(8327494);
|
||||
expect(r.steps[0].step).toBe("create_mr");
|
||||
expect(r.steps[0].ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 目标分支是**仓的属性**,不是全局常量。
|
||||
*
|
||||
* `BASE_BRANCH=develop` 对 TikTok 主仓成立,对 tt_im_monorepo 不成立 —— 那个仓的主干叫
|
||||
* master,压根没有 develop 分支。朝一根不存在的分支提 MR 必然失败,而报错落在建 MR 那
|
||||
* 一步,离「目标分支配错了」这个真因隔着一整条链路。
|
||||
*
|
||||
* 这两条是 2eed432 留下的唯一护栏(把 defaultTargetBranch 改回 null 两条都会红),原先
|
||||
* 挂在 gitlab 通道的用例文件里;该仓改走 Bits 之后搬到这里,断言从 GitLab 的
|
||||
* `target_branch` 换成开发任务 create body 里的 codeElement.targetBranch —— 两条通道取目标分支的是同一个
|
||||
* `targetBranchForRepo`,搬家不减少覆盖。
|
||||
*
|
||||
* 顺带更正一条史料:2eed432 的提交信息把生产上那次 `404 Project Not Found` 归给了目标
|
||||
* 分支。那个归因是错的 —— project id 在 URL 路径里、target_branch 在 body 里,项目解析
|
||||
* 不过根本读不到 body。那次 404 是 code.byted.org 通道自己的问题(见 gitlab_mr.ts 头部)。
|
||||
* 这里修的目标分支是一个真实但当时还没被走到的 bug。
|
||||
*/
|
||||
describe("目标分支按仓取(开发任务通道)", () => {
|
||||
const IM_BASE = {
|
||||
platform: "android" as const,
|
||||
sourceBranch: BRANCH,
|
||||
title: "t",
|
||||
mrType: "bug" as const,
|
||||
repoKey: DEV_TASK_REPO_KEY,
|
||||
trigger: "manual" as const,
|
||||
bitsUser: "johnlee",
|
||||
tokenUser: "johnlee",
|
||||
devTaskApplications: [{ projectName: "tiktok_im_business_page", scmName: "tiktok/im/business_page", projectUniqueId: "68d38ce6003b041ba643fcf3" }],
|
||||
};
|
||||
|
||||
test("主干是 master 的仓提到 master,哪怕 BASE_BRANCH=develop", async () => {
|
||||
const prev = process.env.BASE_BRANCH;
|
||||
process.env.BASE_BRANCH = "develop";
|
||||
try {
|
||||
stubFetch({ code: 200, data: { devBasicId: 2709999 } });
|
||||
await submitMrForFix({ ...IM_BASE });
|
||||
const createCall = calls.find((c) => c.url.includes("/openapi/onesite/v1/dev/create"))!;
|
||||
expect(createCall.body.changes[0].manifest.code_element.target_branch).toBe("master");
|
||||
} finally {
|
||||
if (prev === undefined) delete process.env.BASE_BRANCH; else process.env.BASE_BRANCH = prev;
|
||||
}
|
||||
});
|
||||
|
||||
test("任务自己的 baseRef 压过仓库主干 —— 特性验收 bug 必须回基线分支", async () => {
|
||||
stubFetch({ code: 200, data: { devBasicId: 2709999 } });
|
||||
await submitMrForFix({ ...IM_BASE, baseRef: "feature/streak-pet-baseline" });
|
||||
const createCall = calls.find((c) => c.url.includes("/openapi/onesite/v1/dev/create"))!;
|
||||
expect(createCall.body.changes[0].manifest.code_element.target_branch).toBe("feature/streak-pet-baseline");
|
||||
});
|
||||
});
|
||||
|
||||
describe("交付仓钳制", () => {
|
||||
test("repoForMr 把附加仓 key 钳回 platform 交付仓,不认 FE", () => {
|
||||
expect(repoForMr("android", "tt-im-monorepo").key).toBe("tiktok-android");
|
||||
expect(repoForMr("ios", "tt-im-monorepo").key).toBe("tiktok-ios");
|
||||
expect(repoForMr("android", "tiktok-android").key).toBe("tiktok-android");
|
||||
expect(repoForMr("android", REPO_UNPUSHED).key).toBe("tiktok-android");
|
||||
expect(repoForMr("android", null).key).toBe("tiktok-android");
|
||||
});
|
||||
});
|
||||
|
||||
describe("创建凭证不降级到负责人个人 Token", () => {
|
||||
test("自动提交(无 tokenUser)带 x-bits-user,不把负责人个人 Token 当 Bearer", async () => {
|
||||
const headers: string[][] = [];
|
||||
globalThis.fetch = (async (input: any, init?: RequestInit) => {
|
||||
const url = typeof input === "string" ? input : input.url;
|
||||
headers.push([...(new Headers(init?.headers)).entries()]);
|
||||
calls.push({ url, body: init?.body ? JSON.parse(String(init.body)) : null });
|
||||
return new Response(JSON.stringify({ code: 200, data: { mr_id: 8327494 } }), {
|
||||
status: 200, headers: { "content-type": "application/json" },
|
||||
});
|
||||
}) as typeof fetch;
|
||||
await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, title: "t", mrType: "bug",
|
||||
bitsUser: "mathan.raj",
|
||||
});
|
||||
const create = calls.findIndex((c) => c.url.includes("/openapi/merge_request/create"));
|
||||
expect(create).toBeGreaterThanOrEqual(0);
|
||||
const h = new Headers(headers[create]);
|
||||
expect(h.get("x-bits-user")).toBe("mathan.raj");
|
||||
expect(h.get("authorization")).toMatch(/^Bearer /);
|
||||
});
|
||||
|
||||
test("自动提交开发任务没有 tokenUser ⇒ 不发 create,不走服务号", async () => {
|
||||
stubFetch({ code: 200, data: { id: 2709999 } });
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, title: "t", mrType: "bug",
|
||||
repoKey: DEV_TASK_REPO_KEY,
|
||||
bitsUser: "mathan.raj",
|
||||
devTaskApplications: [{ projectName: "tiktok_im_business_page", scmName: "tiktok/im/business_page", projectUniqueId: "68d38ce6003b041ba643fcf3" }],
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.steps).toEqual([{
|
||||
step: "create_dev_task",
|
||||
ok: false,
|
||||
error: expect.stringContaining("绑定 Bits 个人 Token"),
|
||||
}]);
|
||||
expect(calls).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("自动路径:点过按钮的人优先于负责人", async () => {
|
||||
expect(await resolveDevTaskOperator("alice", "bob")).toBe("alice");
|
||||
});
|
||||
|
||||
test("自动路径:测试环境不查库,没有点击人就不给操作人", async () => {
|
||||
expect(await resolveDevTaskOperator(null, "wangshuo.frontend")).toBeNull();
|
||||
expect(await resolveDevTaskOperator("", "wangshuo.frontend")).toBeNull();
|
||||
});
|
||||
|
||||
test("负责人没绑 Token 的待办文案仍能被面板/飞书认成待办锚点", () => {
|
||||
const repo = repoByKey(DEV_TASK_REPO_KEY)!;
|
||||
const reason = awaitingOwnerDevTaskReason(repo, BRANCH, "wangshuo.frontend");
|
||||
expect(reason).toContain("未绑定 Bits 个人 Token");
|
||||
expect(reason).toContain("需要在面板上点「创建开发任务」发起");
|
||||
expect(reason).not.toContain("不自动建");
|
||||
expect(reason).toContain("tt_im_monorepo");
|
||||
});
|
||||
});
|
||||
|
||||
describe("分支不在远端 · 说人话", () => {
|
||||
/** 生产 68b5cad8:不可复现的单被重新打开、复核通过,分支从没推过,面板只拿到一段 GitLab 英文。 */
|
||||
test("Bits 回 source branch not found ⇒ 失败原因是中文,且仍被认作「分支没了」", async () => {
|
||||
stubFetch({ code: 400, message: "Gitlab Error: TikTok {\"message\":\"input: createMergeRequest resource Branch is not found: merge request source branch not found\\n\"}" });
|
||||
const r = await submitMrForFix({
|
||||
platform: "android", sourceBranch: BRANCH, targetBranch: "develop",
|
||||
title: "[bug] 标题", mrType: "bug", bitsUser: "jingyuan.yi",
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
const create = r.steps.find((s) => s.step === "create_mr")!;
|
||||
expect(create.ok).toBe(false);
|
||||
expect(create.error).toContain(`分支 ${BRANCH} 没有推到交付仓`);
|
||||
expect(create.error).not.toContain("Gitlab Error");
|
||||
expect(bugAutoMrBlocksWalk(create.error)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user