Initial import of streamline

This commit is contained in:
2026-11-16 17:26:44 -08:00
commit 8e4aec1855
1221 changed files with 274256 additions and 0 deletions
+185
View File
@@ -0,0 +1,185 @@
import { test, expect, describe } from "bun:test";
import {
localizeSpecLabels, hasSpecSection, resolveSpecLabel, specSalvageRegex,
specHeading, specLabel, specLabels, specGlossaryBlock,
} from "@bbbug/shared/spec_sections";
/**
* 章节标签的语言归一。
*
* 这个模块承担的是**保证**,不是建议:提示词那一侧只是"请模型这么写",真正让
* lang=en 的执行计划不再出现中文骨架的,是落盘前跑的 `localizeSpecLabels`。所以
* 这里的用例大部分是防回归的边界:改写只能发生在行首的结构位置,正文里出现同名
* 词、代码块里出现同名行,都不许动。
*
* 夹具用的是生产上那份 lang=en 计划的真实形状(任务 91b94d51 的执行计划节选):
* 英文正文 + 中文骨架,正是用户反馈里"headers and labels 读不了"的那个样子。
*/
const PROD_EN_PLAN = `## 复现条件 // Reproduct condition
- 账号/环境:
- Mentioner (主态): \`zhuxingxing02\`, phone \`+81 12342117006\`.
- UI 入口指引:
- Repro path: bottom Profile tab → Edit profile → Bio field.
- 其他特殊要求:
- 必须使用远程构建: \`./start.sh ./gradlew app:assembleMusicallyI18nDebug\`.
## 复现步骤 // Operations
1. On \`zhuxingxing0002\`, set Mentions privacy to "No one".
2. Switch to \`zhuxingxing02\`.
修复后验证 // Post-fix verification (negative + positive + mechanism-level + adversarial):
1. 负向: Re-run steps 1-2; confirm the row no longer accepts a tap.
2. 正向: The target's row renders greyed.
3. 机制级: \`isMentionEnabled\` resolves to \`false\`.
4. 对抗性条件: Cold-start the app and clear the cache.
## 期望与实际
- 期望: The disallowed target appears greyed and cannot be mentioned.
- 实际(bug 现象): The avatar is not greyed and can still be mentioned.
## 回归风险点
- The block/toast logic is shared by all mention scenes.`;
describe("章节标签 · 归一到提交人的语言", () => {
test("生产上那份 en 计划的中文骨架被整体改写成英文", () => {
const out = localizeSpecLabels(PROD_EN_PLAN, "bug", "en");
for (const id of ["reproConditions", "reproSteps", "expectedActual", "regressionRisks"]) {
expect(out).toContain(specHeading("bug", id, "en"));
}
expect(out).toContain("- Account / environment:");
expect(out).toContain("- UI entry path:");
expect(out).toContain("- Other special requirements:");
expect(out).toContain("1. Negative:");
expect(out).toContain("4. Adversarial condition:");
expect(out).toContain("- Expected:");
expect(out).toContain("- Actual (observed bug):");
// 双语副标题连同它当年带的拼写错误("Reproduct")一起消失。
expect(out).not.toContain("// Reproduct condition");
expect(out).not.toContain("// Operations");
expect(out).not.toContain("// Post-fix verification");
for (const d of specLabels("bug")) expect(out).not.toContain(d.zh);
});
test("只改结构位,正文一个字都不动", () => {
const out = localizeSpecLabels(PROD_EN_PLAN, "bug", "en");
// 作者写的内容(含其中的中文)原样保留 —— 归一的是骨架,不是内容。
expect(out).toContain("Mentioner (主态): `zhuxingxing02`");
expect(out).toContain("必须使用远程构建");
expect(out).toContain('set Mentions privacy to "No one"');
});
test("正文里提到同名词不算标签", () => {
// 「期望」是 bullet 标签,但句子中间出现的「期望」只是普通词。改写只认行首 +
// 紧跟其后的冒号,否则一份讲 bug 的 spec 会被自己的用词改坏。
const prose = "- 复现后请对照上面的期望: 这句话里的期望只是叙述";
const out = localizeSpecLabels(prose, "bug", "en");
expect(out).toBe(prose);
});
test("围栏代码块里的同形行不动", () => {
// 代码块里的内容是被引用的输出或命令,不是本文档的结构。
const src = ["## 复现步骤", "```", "## 期望与实际", "```", "- 期望: x"].join("\n");
const out = localizeSpecLabels(src, "bug", "en");
expect(out).toContain("## Reproduction steps");
expect(out).toContain("\n## 期望与实际\n"); // 仍在围栏内,未被改写
expect(out).toContain("- Expected: x");
});
test("幂等,且中英往返稳定", () => {
const en = localizeSpecLabels(PROD_EN_PLAN, "bug", "en");
expect(localizeSpecLabels(en, "bug", "en")).toBe(en);
const zh = localizeSpecLabels(en, "bug", "zh");
expect(zh).toContain("## 复现条件");
expect(zh).toContain("- 实际(bug 现象):");
expect(localizeSpecLabels(zh, "bug", "en")).toBe(en);
});
test("模型自己的说法也认", () => {
// 模型不总是逐字照抄模板。别名只在匹配时生效、从不被渲染出去,所以这些写法
// 会被收敛成规范拼写,而不是原样留在计划里。
const loose = "## Repro steps\n- Account/env: x\n- 实际: y";
const out = localizeSpecLabels(loose, "bug", "en");
expect(out).toContain("## Reproduction steps");
expect(out).toContain("- Account / environment: x");
expect(out).toContain("- Actual (observed bug): y");
});
});
describe("章节标签 · 下游按 id 双语匹配", () => {
test("重放评分对中英两版计划一视同仁", () => {
// 这条是重点:评分器过去按中文字面量查分节,标签一旦跟语言走,每份英文计划
// 都会被判成"缺章节" —— 一次伪装成质量崩塌的评分回归。
const en = localizeSpecLabels(PROD_EN_PLAN, "bug", "en");
const zh = localizeSpecLabels(PROD_EN_PLAN, "bug", "zh");
for (const id of ["reproConditions", "reproSteps", "expectedActual", "regressionRisks"]) {
expect(hasSpecSection(en, "bug", id), `en 缺 ${id}`).toBe(true);
expect(hasSpecSection(zh, "bug", id), `zh 缺 ${id}`).toBe(true);
}
// 历史计划(双语标题 + 那个拼写错误)同样要能被认出来。
expect(hasSpecSection(PROD_EN_PLAN, "bug", "reproConditions")).toBe(true);
});
test("真的缺一节时仍然报缺", () => {
const withoutRisks = PROD_EN_PLAN.replace("## 回归风险点", "## 别的东西");
expect(hasSpecSection(withoutRisks, "bug", "regressionRisks")).toBe(false);
});
test("兜底捞取正则认两种语言的开头", () => {
const re = () => specSalvageRegex("bug", "reproConditions");
expect(`prelude\n${PROD_EN_PLAN}`.match(re())?.[1]).toStartWith("## 复现条件");
const en = localizeSpecLabels(PROD_EN_PLAN, "bug", "en");
expect(`prelude\n${en}`.match(re())?.[1]).toStartWith("## Reproduction conditions");
});
test("确认页芯片按读者的界面语言显示", () => {
// 芯片是 UI 而不是 spec 内容:英文界面的复核人打开一份中文计划,不该拿到一个
// 「复现条件」芯片。
expect(resolveSpecLabel("bug", "## 复现条件 // Reproduct condition")?.en).toBe("Reproduction conditions");
expect(resolveSpecLabel("bug", "Reproduction conditions")?.zh).toBe("复现条件");
// 手工加的章节没有答案,调用方回退到原文 —— 猜一个翻译比直接照抄更糟。
expect(resolveSpecLabel("bug", "## 我自己加的一节")).toBeNull();
});
});
describe("章节标签 · 三条线各自独立", () => {
test("feature / security 的骨架也跟随语言", () => {
const feat = localizeSpecLabels("## 目标 // Goal\n- 触发场景: x\n## 验收标准\n1. 无回归: y", "feature", "en");
expect(feat).toContain("## Goal");
expect(feat).toContain("- Trigger scenario: x");
expect(feat).toContain("## Acceptance criteria");
expect(feat).toContain("1. No regression: y");
const sec = localizeSpecLabels("## 证据目标 // Evidence Goal\n## 判定标准", "security", "en");
expect(sec).toContain("## Evidence goal");
expect(sec).toContain("## Verdict criteria");
});
test("一条线的标签不会去改另一条线的文档", () => {
// 三张表刻意不合并(见 CLAUDE.md):三种任务的分节本来就不通用,合并只会让
// 改一条线时误伤另外两条。
const bugText = "## 复现条件\n- 期望: x";
expect(localizeSpecLabels(bugText, "feature", "en")).toBe(bugText);
});
test("id 在每条线内唯一", () => {
for (const track of ["bug", "feature", "security"] as const) {
const ids = specLabels(track).map((d) => d.id);
expect(new Set(ids).size, `${track} 有重复 id`).toBe(ids.length);
}
});
test("未知 id 立刻报错,不静默渲染成空串", () => {
expect(() => specLabel("bug", "nope", "zh")).toThrow();
});
});
describe("章节标签 · 执行期词表", () => {
test("只在英文任务上追加,中文任务原样", () => {
// 执行期模板整份是中文,并按中文名点名分节。英文 spec 上那些引用会指向不存在
// 的标题,所以补一张对照表;中文任务不需要,追加只会白占上下文。
expect(specGlossaryBlock("bug", "zh")).toBe("");
const en = specGlossaryBlock("bug", "en");
expect(en).toContain("复现条件 → Reproduction conditions");
expect(en).toContain("修复后验证 → Post-fix verification");
});
});