Initial import of streamline
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { parseAuditReport } from "@bbbug/shared/audit_report";
|
||||
import {
|
||||
addIssue, doneScene, initReport, recountSummary, setConstructed, setCoverage, setRecipe, setRoute, setScene,
|
||||
} from "@bbbug/shared/audit_report_edit";
|
||||
import { extractUiTexts, uiWaitLoop } from "@bbbug/shared/ui_wait";
|
||||
|
||||
/**
|
||||
* audit-report 命令的小块修改,和平台解析器是同一份契约:每一步改完都必须还能被 parseAuditReport 读对。
|
||||
* 起因见 shared/src/audit_report_edit.ts 头注释(00889383 写报告 122 次、34 分钟,还改坏过表格)。
|
||||
*/
|
||||
describe("audit-report:小块修改 ↔ 解析器", () => {
|
||||
let md = initReport({ title: "走查", langs: ["en", "de"] });
|
||||
md = setScene(md, "A 场景", "待走", "还没走");
|
||||
md = setScene(md, "B 场景", "待走", "还没走");
|
||||
const r1 = addIssue(md, { page: "s3-dm/01-inbox", title: "收件箱", surface: "面 3 · DM", sev: "P1", cat: "热区", langs: ["en", "de"], text: "「…」只有 24pt。" });
|
||||
md = r1.md;
|
||||
const r2 = addIssue(md, { page: "s3-dm/01-inbox", sev: "P2", cat: "布局", langs: ["en"], text: "头像上距 < 左距。" });
|
||||
md = r2.md;
|
||||
md = setCoverage(md, "s3-dm/02-chat", "en", "ok");
|
||||
md = setCoverage(md, "s3-dm/02-chat", "ja", "missing"); // 新语言列
|
||||
md = doneScene(md, "A 场景").md;
|
||||
md = setConstructed(md, "s3-dm/01-inbox", "断网", "hooks/x.js");
|
||||
md = setRoute(md, "s3-dm/01-inbox", "收件箱", "旧路");
|
||||
md = setRoute(md, "s3-dm/01-inbox", "收件箱", "新路"); // 同键覆盖
|
||||
md = setRecipe(md, "断网态", "svc wifi disable");
|
||||
md = recountSummary(md);
|
||||
const r = parseAuditReport(md)!;
|
||||
|
||||
test("问题编号接着这一页往下排,覆盖格自动 ⚠", () => {
|
||||
expect([r1.n, r2.n]).toEqual([1, 2]);
|
||||
const p = r.pages.find((x) => x.id === "s3-dm/01-inbox")!;
|
||||
expect(p.title).toBe("收件箱");
|
||||
expect(p.surface).toBe("面 3 · DM");
|
||||
expect(p.issues.map((i) => `${i.n}${i.sev}${i.cat}`)).toEqual(["1P1热区", "2P2布局"]);
|
||||
expect(p.coverage).toEqual(["issue", "issue", "missing"]);
|
||||
});
|
||||
test("覆盖矩阵:新页面补行、新语言补列", () => {
|
||||
expect(r.langs).toEqual(["en", "de", "ja"]);
|
||||
expect(r.pages.find((x) => x.id === "s3-dm/02-chat")!.coverage).toEqual(["ok", "missing", "missing"]);
|
||||
});
|
||||
test("第 3 节:done 删行,不留「已覆盖」", () => {
|
||||
expect(r.blocked.map((b) => `${b.scope}:${b.cause}`)).toEqual(["B 场景:pending"]);
|
||||
});
|
||||
test("第 5、6 节:同键覆盖不重复", () => {
|
||||
expect(r.constructed).toEqual([{ page: "s3-dm/01-inbox", how: "断网", script: "hooks/x.js" }]);
|
||||
expect(r.routes).toEqual([{ page: "s3-dm/01-inbox", title: "收件箱", how: "新路" }]);
|
||||
expect(r.recipes).toEqual([{ scene: "断网态", how: "svc wifi disable" }]);
|
||||
});
|
||||
test("summary 按第 4 节数,保留 agent 写的结论段", () => {
|
||||
const withNote = md.replace("## 2. 覆盖矩阵", "### 一句话结论\n\n热区问题最多。\n\n## 2. 覆盖矩阵");
|
||||
const again = recountSummary(withNote);
|
||||
expect(again).toContain("| P1 | 1 | 2 |");
|
||||
expect(again).toContain("| 热区 | 1 | 2 |");
|
||||
expect(again).toContain("热区问题最多。");
|
||||
expect(again.match(/### 按严重度/g)).toHaveLength(1);
|
||||
});
|
||||
test("表格里的竖线被转义,不会把一格拆成两格", () => {
|
||||
const m = addIssue(md, { page: "s3-dm/03-x", sev: "P3", cat: "布局", langs: ["en"], text: "A | B 挤在一起" }).md;
|
||||
// 以前只断言「含 A」:转义的竖线被解析器劈开后,现象只剩「A \\」也能过。现在要原样回来。
|
||||
expect(parseAuditReport(m)!.pages.find((x) => x.id === "s3-dm/03-x")!.issues[0].text).toBe("A | B 挤在一起");
|
||||
});
|
||||
});
|
||||
|
||||
/** 复现条件 / 原因:九列新表头;往写到一半、还是七列表头的老页面里追加时并进「细节」,不错位。 */
|
||||
describe("audit-report:复现条件与原因", () => {
|
||||
const base = initReport({ title: "走查", langs: ["en"] });
|
||||
test("新表九列,两格原样读回", () => {
|
||||
const md = addIssue(base, {
|
||||
page: "s1-profile/12-find-friends", sev: "P1", cat: "布局", langs: ["en"], text: "推荐理由被挤成竖排。",
|
||||
repro: "昵称和 handle 都很短的推荐账号", cause: "这一列跟着昵称 / handle 的宽度走", detail: "16×51", code: "—",
|
||||
}).md;
|
||||
expect(md).toContain("| # | 严重度 | 类别 | 语言 | 现象 | 复现条件 | 原因 | 细节 | 代码位置 |");
|
||||
const i = parseAuditReport(md)!.pages[0].issues[0];
|
||||
expect(i).toMatchObject({ repro: "昵称和 handle 都很短的推荐账号", cause: "这一列跟着昵称 / handle 的宽度走", detail: "16×51", code: "—" });
|
||||
});
|
||||
test("没写的两格是 —,读回来是空", () => {
|
||||
const i = parseAuditReport(addIssue(base, { page: "s1-a/01-b", sev: "P3", cat: "热区", langs: ["en"], text: "小。" }).md)!.pages[0].issues[0];
|
||||
expect(i.repro).toBeUndefined();
|
||||
expect(i.cause).toBeUndefined();
|
||||
});
|
||||
test("七列老表头的页面:追加的行跟着老表头走,复现条件和原因并进细节", () => {
|
||||
const old = `${base.replace("## 4. 逐页问题与截图\n", `## 4. 逐页问题与截图
|
||||
|
||||
### 面 1 · Profile
|
||||
|
||||
#### \`s1-a/01-b\` · 页
|
||||
|
||||
| # | 严重度 | 类别 | 语言 | 现象 | 细节 | 代码位置 |
|
||||
|---|---|---|---|---|---|---|
|
||||
| 1 | P2 | 热区 | en | 老问题。 | 老取证 | — |
|
||||
`)}`;
|
||||
const md = addIssue(old, { page: "s1-a/01-b", sev: "P2", cat: "布局", langs: ["en"], text: "新问题。", repro: "R", cause: "C", detail: "D" }).md;
|
||||
const [a, b] = parseAuditReport(md)!.pages.find((p) => p.id === "s1-a/01-b")!.issues;
|
||||
expect(a).toMatchObject({ n: 1, text: "老问题。", detail: "老取证", code: "—" });
|
||||
expect(b).toMatchObject({ n: 2, text: "新问题。", detail: "复现条件:R;原因:C;D", code: "—" });
|
||||
expect(b.repro).toBeUndefined();
|
||||
});
|
||||
test("按表头名取值:列序不同也读得对", () => {
|
||||
// 覆盖矩阵为空的报告解析器整份不认,先补一行。
|
||||
const md = setCoverage(base, "s1-a/01-b", "en", "issue").replace("## 4. 逐页问题与截图\n", `## 4. 逐页问题与截图
|
||||
|
||||
#### \`s1-a/01-b\` · 页
|
||||
|
||||
| # | 严重度 | 类别 | 语言 | 现象 | 细节 | 原因 | 复现条件 | 代码位置 |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| 1 | P2 | 热区 | en | 现。 | 细。 | 因。 | 复。 | a.m:1 |
|
||||
`);
|
||||
expect(parseAuditReport(md)!.pages[0].issues[0]).toMatchObject({ text: "现。", detail: "细。", cause: "因。", repro: "复。", code: "a.m:1" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("wait-for --ui-text 的核心", () => {
|
||||
test("两种结构树都取得出文案", () => {
|
||||
expect(extractUiTexts('<hierarchy><node text="Inbox" content-desc="More options"/><node text=""/></hierarchy>')).toEqual(["Inbox", "More options"]);
|
||||
expect(extractUiTexts('@1 UILabel "Inbox" (1,1 2x2)\n@2 UIButton "Friends" #btn (1,1 2x2)')).toEqual(["Inbox", "Friends"]);
|
||||
});
|
||||
test("出现即返回;等不到时带上当前屏幕文案;--ui-gone 等消失", async () => {
|
||||
let t = 0;
|
||||
const clock = { now: () => t, sleep: async (ms: number) => { t += ms; } };
|
||||
const seq = ["<hierarchy><node text=\"Loading\"/></hierarchy>", "<hierarchy><node text=\"Inbox\"/></hierarchy>"];
|
||||
let i = 0;
|
||||
const hit = await uiWaitLoop({ probe: async () => seq[Math.min(i++, 1)], pattern: /inbox/i, timeoutMs: 30_000, ...clock });
|
||||
expect(hit.ok).toBe(true);
|
||||
expect(hit.hit).toBe("Inbox");
|
||||
const miss = await uiWaitLoop({ probe: async () => seq[0], pattern: /Settings/, timeoutMs: 3000, ...clock });
|
||||
expect(miss.ok).toBe(false);
|
||||
expect(miss.lastTexts).toEqual(["Loading"]);
|
||||
i = 0;
|
||||
const gone = await uiWaitLoop({ probe: async () => seq[Math.min(i++, 1)], pattern: /Loading/, gone: true, timeoutMs: 30_000, ...clock });
|
||||
expect(gone.ok).toBe(true);
|
||||
const none = await uiWaitLoop({ probe: async () => null, pattern: /x/, timeoutMs: 2000, ...clock });
|
||||
expect(none.error).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user