| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import { expect, test } from "bun:test"
- import { candidateImpact, nextReviewStep, reviewReport } from "../src/util/software-review-report"
- import type { Review, Evidence } from "../src/util/software-review"
- import { businessText } from "../src/util/software-review-business"
- const fixture = (): Review => ({
- id: "a".repeat(32),
- revision: 5,
- project: "Synthetic fleet",
- phase: "awaiting_review",
- candidates: [
- {
- id: "c1",
- path: "Fleet.java",
- symbol: "Fleet#start",
- suggestion: "Extract responsibility",
- method_range: { start: 1, end: 106 },
- source_excerpt: [],
- test_hints: ["FleetTest.java"],
- evidence: [],
- },
- ],
- decisions: { c1: "selected" },
- coverage: { analyzed_files: 2, java_files: 2 },
- proposal: null,
- execution: { source_unchanged: true, result: { generation: 1, changed_files: ["Fleet.java"] } },
- })
- const comparison = {
- candidate_changes: {
- resolved: [{ symbol: "Fleet#start", metrics: { method_lines: 106 } }],
- remaining: [],
- introduced: [{ symbol: "Fleet#createProfile", metrics: { method_lines: 75 } }],
- complete: true,
- },
- }
- test("business review shows test bindings and exclusions before and after execution", () => {
- const spec = { profile: "automotive", status: "incomplete", passed: false,
- contracts: [{ category: "units_ranges", invariant: "Keep units", test_path: "Check.java", test_case: "Check#units",
- quote: "assert speed == 36;", status: "unverified", reason: "Assertion did not match" }],
- exclusions: [{ category: "variant_revision", reason: "No variant field in this fixture" }],
- missing_categories: ["protocol_compatibility"] }
- expect(businessText(spec, "plan")).toContain("断言:assert speed == 36;")
- const state = fixture()
- state.execution = { result: { business_acceptance: { baseline: spec, current: spec } } }
- const report = reviewReport(state, 2)
- for (const value of ["重构前 · 业务验收", "重构后 · 业务验收", "Check.java → Check#units", "Assertion did not match",
- "排除 · 车型与版本", "缺项 · 协议兼容"]) expect(report).toContain(value)
- expect(report).not.toContain("声明范围通过")
- expect(businessText(undefined, "result")).toContain("尚未取得结果")
- expect(businessText(undefined, "plan")).toContain("未声明")
- expect(businessText({ status: "not_declared" }, "result")).toContain("未声明")
- expect(businessText({ ...spec, contracts: [{ ...spec.contracts[0], executed_test_cases: ["actual::one", "actual::two"] }] }, "result"))
- .toContain("已绑定 2 个实际执行用例")
- })
- test("ontology failure stays visible even when build and native tests pass", () => {
- const state = fixture()
- state.phase = "verification_failed"
- const evidence: Evidence = { id: state.id, revision: state.revision, token: "t", files: [], checks: {
- "round-1/checks.json": { passed: false, build_status: "passed", test_status: "passed",
- ontology_error: "Declared rule target no longer resolves" },
- } }
- expect(reviewReport(state, 2, { evidence })).toContain("本体重建失败:Declared rule target no longer resolves")
- expect(reviewReport(state, 3, { evidence })).toContain("本体重建问题")
- })
- test("reports residual extracted methods without upgrading a disappearing finding to success", () => {
- const value = reviewReport(fixture(), 1, { comparison })
- expect(value).toContain("106 行")
- expect(value).toContain("75 行")
- expect(value).toContain("新增待审线索")
- expect(value).toContain("原仓库:保持不变")
- expect(value).not.toContain('"candidate_changes"')
- expect(reviewReport(fixture(), 3, { comparison })).toContain("新增线索:Fleet#createProfile")
- })
- test("impact paths retain source evidence and do not invent runtime calls or missing legacy context", () => {
- const c = fixture().candidates[0]
- c.ontology_context = {
- dependency_paths: [{ path: "contracts/Policy.java", via: [{ origin: { path: "Fleet.java", line: 8 } }] }],
- unresolved_references_total: 2,
- impact_paths: [
- {
- path: "FleetTest.java",
- via: [{ relation: "REFERENCES", origin: { path: "FleetTest.java", line: 2, quote: "import Fleet;" } }],
- },
- ],
- }
- const value = candidateImpact(c)
- expect(value).toContain("FleetTest.java:2")
- expect(value).toContain("import Fleet;")
- expect(value).toContain("不代表运行时调用")
- expect(value).toContain("下游依赖")
- expect(value).toContain("contracts/Policy.java")
- expect(value).toContain("Fleet.java:8")
- expect(value).toContain("未解析引用:2")
- expect(candidateImpact(fixture().candidates[0])).toContain("旧记录未采集")
- expect(reviewReport(fixture(), 0)).toContain("旧记录没有全库本体汇总")
- })
- test("missing test evidence is unknown while measured zero remains zero", () => {
- expect(reviewReport(fixture(), 2)).toContain("未取得测试明细,不计通过")
- const evidence: Evidence = {
- id: "a".repeat(32),
- revision: 5,
- token: "d".repeat(64),
- files: [],
- checks: {
- "baseline/checks.json": { build_status: "passed", test_status: "passed", executed_tests: 10 },
- "round-1/checks.json": {
- build_status: "passed",
- test_status: "failed",
- executed_tests: 10,
- case_counts: { failed: 1, skipped: 0 },
- failed_cases: [{ id: "FleetTest.denied", status: "failed" }],
- },
- },
- }
- const value = reviewReport(fixture(), 2, { evidence })
- expect(value).toContain("失败 未采集")
- expect(value).toContain("失败 1 · 跳过 0")
- expect(value).toContain("FleetTest.denied")
- })
- test("partial evidence and pending cancellation never appear as completion", () => {
- const state = fixture()
- state.phase = "running"
- state.cancel_requested = true
- expect(nextReviewStep(state)).toContain("等待当前检查结束")
- expect(reviewReport(state, 3, { warning: "校验失败" })).toContain("以下缺失项不计通过")
- state.phase = "accepted_for_delivery"
- expect(nextReviewStep(state)).toContain("原仓库尚未合并")
- })
- test("measured analysis progress and declared adapter scope guide the next step", () => {
- const state = fixture()
- state.phase = "analyzing"
- state.progress = { stage: "scan", completed_batches: 2, total_batches: 5 }
- state.coverage = { analyzed_files: 240, total_files: 500 }
- state.analysis_scope = { label: "TypeScript 文件", total_files: 500, adapter: "synthetic-typescript" }
- expect(nextReviewStep(state)).toContain("2/5 个分析批次")
- expect(reviewReport(state, 0)).toContain("240 / 500 个TypeScript 文件")
- expect(reviewReport(state, 0)).not.toContain("Java 文件")
- state.progress.stage = "link"
- expect(nextReviewStep(state)).toContain("正在关联跨文件本体")
- state.cancel_requested = true
- expect(nextReviewStep(state)).toContain("等待当前检查结束")
- })
|