94 lines
4.2 KiB
TypeScript
94 lines
4.2 KiB
TypeScript
import { test, expect, describe } from "bun:test";
|
|
import { readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { extractPsmsFromSpec } from "@bbbug/shared/server_prompt";
|
|
|
|
/**
|
|
* 服务端范围提醒 —— 钉住「什么时候发、什么时候不发」。
|
|
*
|
|
* 通知这类功能最容易坏的方式不是不发,是**发太多**:评估会重跑(regenerate、
|
|
* info_required 补完信息后重评),每次都发就变成噪音,而噪音的终点是没人再看。
|
|
*/
|
|
const REPO = path.resolve(import.meta.dir, "../..");
|
|
const src = readFileSync(path.join(REPO, "control-server/src/server_scope_notify.ts"), "utf8");
|
|
const routes = readFileSync(path.join(REPO, "control-server/src/routes.ts"), "utf8");
|
|
|
|
describe("触发时机", () => {
|
|
test("挂在卫星回写 pending_confirmation 的那一刻,不是人工编辑方案时", () => {
|
|
// 要捕捉的是「评估器刚判定出来、还没人看过」,而不是人在改方案。
|
|
expect(routes).toContain('patch.status === "pending_confirmation"');
|
|
expect(routes).toContain("notifyServerScopeIfNew");
|
|
});
|
|
|
|
test("只在「从无到有」时发 —— 重评产出同一批 PSM 要静默", () => {
|
|
expect(src).toContain("before.has(p)");
|
|
expect(src).toContain("每次都发就变成噪音");
|
|
});
|
|
|
|
test("失败一律吞掉,不影响评估回写", () => {
|
|
expect(src).toContain("allSettled");
|
|
expect(src).toContain("best-effort");
|
|
});
|
|
});
|
|
|
|
describe("解析驱动通知", () => {
|
|
const spec = (body: string) => `## 目标\nx\n\n## 服务端范围\n${body}\n\n## 验收标准\n- 一\n`;
|
|
|
|
test("声明了 PSM 才会有内容可通知", () => {
|
|
expect(extractPsmsFromSpec(spec("- 涉及 PSM: tiktok.profile.api"), "feature"))
|
|
.toEqual(["tiktok.profile.api"]);
|
|
});
|
|
|
|
test("写「无」的纯客户端任务不触发", () => {
|
|
expect(extractPsmsFromSpec(spec("- 涉及 PSM: 无\n- 服务端改动: 无"), "feature")).toEqual([]);
|
|
});
|
|
|
|
test("哨兵不触发 —— 还没定,不该惊动人", () => {
|
|
expect(extractPsmsFromSpec(spec("- 涉及 PSM: <<NEEDS_INPUT 待确认>>"), "feature")).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("卡片形态", () => {
|
|
test("用橙色而不是红色 —— 它是「请来看一眼」,不是「出事了」", () => {
|
|
expect(src).toContain('template: "orange"');
|
|
});
|
|
|
|
test("带一个直达确认页的按钮", () => {
|
|
expect(src).toContain("open_url");
|
|
expect(src).toContain("去确认方案");
|
|
});
|
|
|
|
test("收件人可配置,默认是盯服务端的那个人", () => {
|
|
expect(src).toContain("SERVER_SCOPE_WATCHERS");
|
|
expect(src).toContain("jingyuan.yi@bytedance.com");
|
|
});
|
|
});
|
|
|
|
describe("闸上补出来的 PSM 也要发卡片", () => {
|
|
/**
|
|
* 原来通知只挂在卫星回写 pending_confirmation(也就是评估器产出 PSM)那一刻。
|
|
* 但反查唯一命中率实测只有 4%,语义通道也只有 ~75% —— 「评估器给不出、由人在闸上补」
|
|
* 才是主路径。挂点只放在评估器那一侧,等于在「入口交给人」生效之后,最常见的那条路
|
|
* 反而不发通知。这组断言钉住第二个挂点存在且判据一致。
|
|
*/
|
|
const routes = readFileSync(path.join(REPO, "control-server/src/routes.ts"), "utf8");
|
|
|
|
test("psms 编辑路由里调了通知", () => {
|
|
const seg = routes.slice(routes.indexOf("async function updatePsms"), routes.indexOf('api.post("/tasks/:id/psms"'));
|
|
expect(seg).toContain("notifyServerScopePsms");
|
|
});
|
|
|
|
test("传的是编辑前的 psms 作为 prevPsms —— 判据仍是「从没有到有」", () => {
|
|
const seg = routes.slice(routes.indexOf("async function updatePsms"), routes.indexOf('api.post("/tasks/:id/psms"'));
|
|
expect(seg).toContain("prevPsms");
|
|
expect(seg).toContain("item.psms ?? []");
|
|
});
|
|
|
|
test("task 要映射成 bug —— 通知模块用的是 bug/feature,不是 task/feature", () => {
|
|
// 三条并行 track 的命名在这个仓库里本来就不统一(HTTP 路径叫 tasks,报告叫 bug),
|
|
// 传错这个字段会让卡片里的链接指向不存在的页面。
|
|
const seg = routes.slice(routes.indexOf("async function updatePsms"), routes.indexOf('api.post("/tasks/:id/psms"'));
|
|
expect(seg).toContain('kind === "task" ? "bug" : "feature"');
|
|
});
|
|
});
|