Initial import of streamline
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// MUST be first: sets DATABASE_URL before db_client is evaluated.
|
||||
import "./setup_env";
|
||||
|
||||
// meego.ts 把凭据读成模块顶层常量,所以这三行必须跑在它被求值之前 —— 用动态
|
||||
// import 保证顺序。删掉 PLUGIN_ID/SECRET 是**结构性**的出网防线:少了它们
|
||||
// `fetchPluginToken` 在发请求前就 return null(meego.ts:137),于是这个测试进程
|
||||
// 无论断言写错成什么样,都不可能拿着开发机 .env 里的真凭据去敲生产 Meego。
|
||||
delete process.env.MEEGO_PLUGIN_ID;
|
||||
delete process.env.MEEGO_PLUGIN_SECRET;
|
||||
process.env.MEEGO_TOKEN = "test-static-token";
|
||||
|
||||
import { test, expect, describe, afterEach } from "bun:test";
|
||||
const { setMeegoIssueResolved } = await import("../src/meego");
|
||||
|
||||
/**
|
||||
* 「工单查无此单」必须和「工单翻不动」分开。
|
||||
*
|
||||
* 生产上这两件事被合成了一个 502:一条 MR 已合入的 bug,它的 Meego 工单被删了,
|
||||
* 于是 `mr_auto_confirm` 每天试一次、每天拿到同一个 `WorkItem Not Found`、每天
|
||||
* 记一行「will retry next sweep」—— 连续跑了一周多,而重试的对象永远不会回来。
|
||||
*
|
||||
* 修法是给 `MeegoUpdateResult` 加 `notFound`,让 `approveBugReview` 把它并进
|
||||
* 「本来就没有工单」那条既有的放行路径。所以这里钉两件事,第二件比第一件重要:
|
||||
*
|
||||
* 1. 查无此单要认得出来;
|
||||
* 2. **别的 Meego 故障绝不能被认成查无此单**。误判的代价是不对称的 —— 把一次
|
||||
* 超时当成「单没了」,会让一条工单还开着的任务被标成已完成,而那正是
|
||||
* review_actions.ts 那段注释一开始要防的不一致。
|
||||
*/
|
||||
const MEEGO_URL = "https://meego.larkoffice.com/tiktok/issue/detail/7328764565";
|
||||
const realFetch = globalThis.fetch;
|
||||
afterEach(() => { globalThis.fetch = realFetch; });
|
||||
|
||||
/** 只认 work_item 查询这一个 URL,其它一律抛 —— 测试进程不该有第二个出口。 */
|
||||
function stubQuery(payload: unknown, status = 200) {
|
||||
globalThis.fetch = (async (input: any) => {
|
||||
const url = String(typeof input === "string" ? input : input?.url ?? input);
|
||||
if (url.includes("/work_item/") && url.endsWith("/query")) {
|
||||
return new Response(JSON.stringify(payload), { status, headers: { "content-type": "application/json" } });
|
||||
}
|
||||
throw new Error(`意外的出网请求: ${url}`);
|
||||
}) as typeof fetch;
|
||||
}
|
||||
|
||||
describe("setMeegoIssueResolved · 查无此单 vs 翻不动", () => {
|
||||
test("WorkItem Not Found → notFound", async () => {
|
||||
stubQuery({ err: { msg: "WorkItem Not Found, please refer to https://project.feishu.cn/..." } }, 400);
|
||||
const r = await setMeegoIssueResolved("7328764565", MEEGO_URL);
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.notFound).toBe(true);
|
||||
});
|
||||
|
||||
test("查询成功但结果为空,同样是「没有这张单」", async () => {
|
||||
stubQuery({ data: [] });
|
||||
const r = await setMeegoIssueResolved("7328764565", MEEGO_URL);
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.notFound).toBe(true);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["无权限", { err: { msg: "No Permission" } }],
|
||||
["插件 token 类型配错", { err: { msg: "invalid plugin token, code 10022" } }],
|
||||
["网关抖动", { err_msg: "HTTP 502: bad gateway" }],
|
||||
["空错误信息", {}],
|
||||
])("%s → 不是 notFound,仍然可重试", async (_label, payload) => {
|
||||
stubQuery(payload, 500);
|
||||
const r = await setMeegoIssueResolved("7328764565", MEEGO_URL);
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.notFound).toBeFalsy();
|
||||
});
|
||||
|
||||
test("链接解析不出来时不会误报 notFound(那是另一类失败)", async () => {
|
||||
globalThis.fetch = (async () => { throw new Error("不该发起请求"); }) as typeof fetch;
|
||||
const r = await setMeegoIssueResolved("not-a-link", "also-not-a-link");
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.notFound).toBeFalsy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user