清设计痕迹(卖源码): 删 84 项跟踪文档/spec/plan/prompt+5 支纯文档用例+4 支没人接进闸门的审计工具,9 支混合用例只摘读 docs 的那几段
V143–V152 的迁移契约用例逐支过:87 例 0 红(mvn -o test 实跑)。混合类里钉"迁移文件本体"的断言全部保留, 只删/只切按路径读 docs 的方法;两支 scannedSignaturesAreActuallyPresent 是防恒绿的自检, 它自检的对象(回滚补丁)已随文档出仓,那几行留在类里就变成给空断言背书,所以一并摘掉。 删除面 241 个唯一副本的归档在 D:\archive\design-scrub-2026-10-11\,逐个 sha256 回读。
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
"""task-166 HTTP 客户端契约盘点测试。
|
||||
|
||||
对应 plan 10 任务 166 的 8 条用例:
|
||||
1. test_contract_table_all_clients 全客户端覆盖
|
||||
2. test_timeouts_listed 超时现状
|
||||
3. test_retry_listed 重试现状
|
||||
4. test_idempotency_listed 幂等性标注
|
||||
5. test_jdk_limits_noted 平台限制
|
||||
6. test_doc_committed 文档存在
|
||||
7. test_no_code_change 零代码变更
|
||||
8. test_repeatable 可复查
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from http_client_audit import (
|
||||
REPO_ROOT,
|
||||
extract_client_sites,
|
||||
extract_timeout_configs,
|
||||
scan,
|
||||
)
|
||||
|
||||
DOC_PATH = REPO_ROOT / "docs" / "http-client-contract-audit.md"
|
||||
|
||||
|
||||
class HttpClientAuditTest(unittest.TestCase):
|
||||
def test_contract_table_all_clients(self):
|
||||
configs = extract_timeout_configs()
|
||||
self.assertGreaterEqual(len(configs), 4, "超时/重试配置字段必须齐全")
|
||||
classes = {c["config_class"] for c in configs}
|
||||
self.assertTrue(
|
||||
any("Transient" in name or "Storage" in name for name in classes),
|
||||
"存储客户端配置存在",
|
||||
)
|
||||
self.assertTrue(
|
||||
any("SimilarAsin" in name or "ImageVideo" in name for name in classes),
|
||||
"LLM/图片客户端配置存在",
|
||||
)
|
||||
|
||||
def test_timeouts_listed(self):
|
||||
fields = {c["field"] for c in extract_timeout_configs()}
|
||||
self.assertTrue(any("connectTimeout" in f for f in fields), "connect 超时缺失")
|
||||
self.assertTrue(any("readTimeout" in f for f in fields), "read 超时缺失")
|
||||
self.assertTrue(any("writeTimeout" in f for f in fields), "write 超时缺失")
|
||||
self.assertTrue(any("callTimeout" in f for f in fields), "call 超时缺失")
|
||||
|
||||
def test_retry_listed(self):
|
||||
fields = {c["field"] for c in extract_timeout_configs()}
|
||||
self.assertTrue(any("Retry" in f for f in fields), "重试配置缺失")
|
||||
|
||||
def test_idempotency_listed(self):
|
||||
sites = extract_client_sites()
|
||||
self.assertGreater(len(sites), 0, "客户端配置调用点必须记录")
|
||||
|
||||
def test_jdk_limits_noted(self):
|
||||
sites = extract_client_sites()
|
||||
self.assertTrue(
|
||||
any(
|
||||
"HttpClient" in s["snippet"] or "newBuilder" in s["snippet"]
|
||||
for s in sites
|
||||
),
|
||||
"JDK HttpClient 使用点必须记录",
|
||||
)
|
||||
|
||||
def test_doc_committed(self):
|
||||
self.assertTrue(DOC_PATH.is_file(), f"契约表文档缺失: {DOC_PATH}")
|
||||
text = DOC_PATH.read_text(encoding="utf-8")
|
||||
self.assertIn("超时", text)
|
||||
self.assertIn("重试", text)
|
||||
self.assertIn("幂等", text)
|
||||
|
||||
def test_no_code_change(self):
|
||||
changed = subprocess.run(
|
||||
["git", "diff", "--name-only", "HEAD", "--", "backend-java/src"],
|
||||
cwd=REPO_ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
self.assertEqual(changed, "", f"生产代码被改动: {changed}")
|
||||
|
||||
def test_repeatable(self):
|
||||
first = json.dumps(scan().to_dict(), sort_keys=True)
|
||||
second = json.dumps(scan().to_dict(), sort_keys=True)
|
||||
self.assertEqual(first, second, "盘点可复查")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,199 +0,0 @@
|
||||
"""task-121 N+1 扫描审计测试。
|
||||
|
||||
对应 plan 06 任务 121 的 8 条用例 + 2 条补强:
|
||||
1. test_scan_select_in_loop 识别循环内单查
|
||||
2. test_scan_output_listed 清单产出(位置/对象/影响字段齐全)
|
||||
3. test_scan_priority 按影响排序
|
||||
4. test_scan_module_coverage 覆盖主要模块(真实代码扫描)
|
||||
5. test_scan_false_positive_checked 排除误报(已批量/循环外)
|
||||
6. test_scan_repeatable 可重复(同输入同输出)
|
||||
7. test_scan_documented 审计文档产出
|
||||
8. test_scan_no_edit 本任务不改生产代码
|
||||
9. test_scan_lambda_brace_less 无花括号 lambda 内单查识别
|
||||
10. test_scan_iterating_query_result 遍历查询结果集判 HIGH
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from n1_scan import (
|
||||
HIGH,
|
||||
LOW,
|
||||
MEDIUM,
|
||||
MODULES_ROOT,
|
||||
scan_modules,
|
||||
scan_text,
|
||||
)
|
||||
|
||||
SCRIPTS_DIR = Path(__file__).resolve().parent
|
||||
REPO_ROOT = SCRIPTS_DIR.parent.parent
|
||||
DOC_PATH = REPO_ROOT / "backend-java" / "docs" / "n1-scan-audit.md"
|
||||
|
||||
FIXTURE_LOOP = """package com.example;
|
||||
public class DemoService {
|
||||
public void batchByIds(List<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
FileTaskEntity task = fileTaskMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_QUERY_RESULT_LOOP = """package com.example;
|
||||
public class DemoService {
|
||||
public List<Vo> listVos() {
|
||||
List<FileTaskEntity> tasks = fileTaskMapper.selectList(new LambdaQueryWrapper<>());
|
||||
List<Vo> vos = new ArrayList<>();
|
||||
for (FileTaskEntity t : tasks) {
|
||||
FileResultEntity r = fileResultMapper.selectById(t.getResultId());
|
||||
vos.add(toVo(r));
|
||||
}
|
||||
return vos;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_LAMBDA_BRACELESS = """package com.example;
|
||||
public class DemoService {
|
||||
public void touch(List<Long> ids) {
|
||||
ids.forEach(id -> fileTaskMapper.selectOne(
|
||||
new LambdaQueryWrapper<FileTaskEntity>().eq(FileTaskEntity::getId, id)));
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_BATCH_SAFE = """package com.example;
|
||||
public class DemoService {
|
||||
public List<FileTaskEntity> load(List<Long> ids) {
|
||||
List<FileTaskEntity> tasks = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
tasks.addAll(fileTaskMapper.selectBatchIds(Collections.singleton(id)));
|
||||
}
|
||||
for (Long id : ids) {
|
||||
tasks.addAll(fileTaskMapper.selectByIds(Collections.singleton(id)));
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_NO_LOOP = """package com.example;
|
||||
public class DemoService {
|
||||
public FileTaskEntity one(Long id) {
|
||||
return fileTaskMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_LOOP_NO_QUERY = """package com.example;
|
||||
public class DemoService {
|
||||
public int sum(List<Integer> nums) {
|
||||
int s = 0;
|
||||
for (Integer n : nums) {
|
||||
s += n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_INDEX_LOOP = """package com.example;
|
||||
public class DemoService {
|
||||
public List<Vo> listVos(List<Long> ids) {
|
||||
List<Vo> vos = new ArrayList<>();
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
FileTaskEntity t = fileTaskMapper.selectById(ids.get(i));
|
||||
vos.add(toVo(t));
|
||||
}
|
||||
return vos;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_MIXED = (
|
||||
FIXTURE_QUERY_RESULT_LOOP
|
||||
+ "\n"
|
||||
+ FIXTURE_LAMBDA_BRACELESS
|
||||
+ "\n"
|
||||
+ FIXTURE_INDEX_LOOP
|
||||
)
|
||||
|
||||
|
||||
class ScanDetectTest(unittest.TestCase):
|
||||
def test_scan_select_in_loop(self):
|
||||
findings = scan_text(FIXTURE_LOOP, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertIn("selectById", findings[0]["statement"])
|
||||
self.assertEqual(findings[0]["loop_type"], "for")
|
||||
self.assertEqual(findings[0]["line"], 5)
|
||||
|
||||
def test_scan_output_listed(self):
|
||||
for finding in scan_text(FIXTURE_MIXED, "DemoService.java"):
|
||||
for key in ("file", "line", "statement", "loop_type", "impact"):
|
||||
self.assertIn(key, finding)
|
||||
self.assertTrue(finding[key] is not None and finding[key] != "")
|
||||
|
||||
def test_scan_priority(self):
|
||||
findings = scan_text(FIXTURE_MIXED, "DemoService.java")
|
||||
order = {HIGH: 0, MEDIUM: 1, LOW: 2}
|
||||
impacts = [order[f["impact"]] for f in findings]
|
||||
self.assertEqual(impacts, sorted(impacts))
|
||||
|
||||
def test_scan_false_positive_checked(self):
|
||||
self.assertEqual(len(scan_text(FIXTURE_BATCH_SAFE, "Batch.java")), 0)
|
||||
self.assertEqual(len(scan_text(FIXTURE_NO_LOOP, "NoLoop.java")), 0)
|
||||
self.assertEqual(len(scan_text(FIXTURE_LOOP_NO_QUERY, "NoQuery.java")), 0)
|
||||
|
||||
def test_scan_repeatable(self):
|
||||
first = scan_text(FIXTURE_MIXED, "DemoService.java")
|
||||
second = scan_text(FIXTURE_MIXED, "DemoService.java")
|
||||
self.assertEqual(
|
||||
json.dumps(first, sort_keys=True), json.dumps(second, sort_keys=True)
|
||||
)
|
||||
|
||||
def test_scan_lambda_brace_less(self):
|
||||
findings = scan_text(FIXTURE_LAMBDA_BRACELESS, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertEqual(findings[0]["loop_type"], "forEach")
|
||||
self.assertEqual(findings[0]["impact"], MEDIUM)
|
||||
|
||||
def test_scan_iterating_query_result(self):
|
||||
findings = scan_text(FIXTURE_QUERY_RESULT_LOOP, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertEqual(findings[0]["impact"], HIGH)
|
||||
|
||||
|
||||
class ScanCoverageTest(unittest.TestCase):
|
||||
def test_scan_module_coverage(self):
|
||||
report = scan_modules(MODULES_ROOT)
|
||||
self.assertGreaterEqual(report.scanned_files, 600)
|
||||
self.assertGreater(len(report.findings), 0)
|
||||
modules = {f["module"] for f in report.findings}
|
||||
self.assertGreaterEqual(len(modules), 3)
|
||||
order = {HIGH: 0, MEDIUM: 1, LOW: 2}
|
||||
impacts = [order[f["impact"]] for f in report.findings]
|
||||
self.assertEqual(impacts, sorted(impacts))
|
||||
|
||||
def test_scan_documented(self):
|
||||
self.assertTrue(DOC_PATH.is_file(), f"audit doc missing: {DOC_PATH}")
|
||||
text = DOC_PATH.read_text(encoding="utf-8")
|
||||
self.assertIn("N+1", text)
|
||||
self.assertIn("影响", text)
|
||||
|
||||
def test_scan_no_edit(self):
|
||||
changed = subprocess.run(
|
||||
["git", "diff", "--name-only", "HEAD", "--", "backend-java/src"],
|
||||
cwd=REPO_ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
self.assertEqual(changed, "", f"生产代码被改动: {changed}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,89 +0,0 @@
|
||||
"""task-148 临时目录配置盘点测试。
|
||||
|
||||
对应 plan 09 任务 148 的 8 条用例:
|
||||
1. test_config_listed 配置项清单齐全
|
||||
2. test_temp_root_defined 临时根目录定义
|
||||
3. test_retention_period 保留期定义
|
||||
4. test_payload_prefixes payload 前缀
|
||||
5. test_upload_dir 上传目录
|
||||
6. test_existing_cleanup_noted 现有清理逻辑记录
|
||||
7. test_doc_committed 文档存在
|
||||
8. test_no_code_change 零代码变更
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from temp_config_audit import REPO_ROOT, extract_cleanup_calls, extract_configs, scan
|
||||
|
||||
DOC_PATH = REPO_ROOT / "docs" / "temp-file-config-audit.md"
|
||||
|
||||
|
||||
class TempConfigAuditTest(unittest.TestCase):
|
||||
def test_config_listed(self):
|
||||
configs = extract_configs()
|
||||
self.assertGreaterEqual(len(configs), 8, "配置项清单必须齐全")
|
||||
for item in configs:
|
||||
for key in ("key", "value", "line", "source"):
|
||||
self.assertIn(key, item)
|
||||
|
||||
def test_temp_root_defined(self):
|
||||
keys = {c["key"] for c in extract_configs()}
|
||||
self.assertTrue(
|
||||
any("local-temp-dir" in k for k in keys),
|
||||
f"临时根目录配置缺失: {sorted(keys)}",
|
||||
)
|
||||
|
||||
def test_retention_period(self):
|
||||
keys = {c["key"] for c in extract_configs()}
|
||||
self.assertTrue(any("retention" in k for k in keys), "保留期配置缺失")
|
||||
|
||||
def test_payload_prefixes(self):
|
||||
keys = {c["key"] for c in extract_configs()}
|
||||
self.assertTrue(
|
||||
any("transient-payload" in k for k in keys), "transient payload 配置缺失"
|
||||
)
|
||||
|
||||
def test_upload_dir(self):
|
||||
configs = extract_configs()
|
||||
self.assertTrue(
|
||||
any(
|
||||
"upload" in c["key"].lower() or "tmp" in c["key"].lower()
|
||||
for c in configs
|
||||
),
|
||||
"上传/临时目录配置缺失",
|
||||
)
|
||||
|
||||
def test_existing_cleanup_noted(self):
|
||||
calls = extract_cleanup_calls()
|
||||
self.assertGreater(len(calls), 0, "必须记录既有清理调用点")
|
||||
files = {c["file"] for c in calls}
|
||||
self.assertGreaterEqual(len(files), 3, "清理调用应覆盖多个文件")
|
||||
|
||||
def test_doc_committed(self):
|
||||
self.assertTrue(DOC_PATH.is_file(), f"盘点文档缺失: {DOC_PATH}")
|
||||
text = DOC_PATH.read_text(encoding="utf-8")
|
||||
self.assertIn("临时", text)
|
||||
self.assertIn("保留期", text)
|
||||
|
||||
def test_no_code_change(self):
|
||||
changed = subprocess.run(
|
||||
["git", "diff", "--name-only", "HEAD", "--", "backend-java/src"],
|
||||
cwd=REPO_ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
self.assertEqual(changed, "", f"生产代码被改动: {changed}")
|
||||
|
||||
def test_scan_repeatable(self):
|
||||
first = json.dumps(scan().to_dict(), sort_keys=True)
|
||||
second = json.dumps(scan().to_dict(), sort_keys=True)
|
||||
self.assertEqual(first, second, "盘点结果可重复")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,204 +0,0 @@
|
||||
"""task-124 @Transactional 方法审计清单测试。
|
||||
|
||||
对应 plan 07 任务 124 的 8 条用例 + 2 条补强:
|
||||
1. test_audit_covers_all_modules 覆盖全部业务模块
|
||||
2. test_audit_classification 分类完整(必须/可移出)
|
||||
3. test_audit_result_endpoints /result 相关方法都在清单
|
||||
4. test_audit_python_facing Python 回调相关标记
|
||||
5. test_audit_priority_order 按收益排序
|
||||
6. test_audit_no_code_change 本任务零代码变更
|
||||
7. test_audit_documented 文档产出
|
||||
8. test_audit_repeatable 可重复执行
|
||||
9. test_audit_detects_tx_method 识别 @Transactional 方法
|
||||
10. test_audit_classifies_movable 事务内可移出段分类
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from tx_audit import MODULES_ROOT, scan_modules, scan_text
|
||||
|
||||
SCRIPTS_DIR = Path(__file__).resolve().parent
|
||||
REPO_ROOT = SCRIPTS_DIR.parent.parent
|
||||
DOC_PATH = REPO_ROOT / "backend-java" / "docs" / "transaction-boundary-audit.md"
|
||||
|
||||
FIXTURE_TX = """package com.example;
|
||||
@Service
|
||||
public class DemoService {
|
||||
@Transactional
|
||||
public boolean submitResult(Long taskId, List<RowVo> rows) {
|
||||
List<ItemVo> items = rows.stream()
|
||||
.map(row -> toVo(row))
|
||||
.collect(Collectors.toList());
|
||||
int updated = fileResultMapper.update(null, new LambdaUpdateWrapper<FileResultEntity>()
|
||||
.eq(FileResultEntity::getId, taskId)
|
||||
.set(FileResultEntity::getStatus, "SUCCESS"));
|
||||
log.info("submitted taskId={} count={}", taskId, items.size());
|
||||
Files.deleteIfExists(Path.of("/tmp/task-" + taskId));
|
||||
return updated > 0;
|
||||
}
|
||||
|
||||
public void noTxMethod(Long id) {
|
||||
fileTaskMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_WRITE_ONLY = """package com.example;
|
||||
@Service
|
||||
public class DemoService {
|
||||
@Transactional
|
||||
public int markFailed(Long id) {
|
||||
return fileTaskMapper.update(null, new LambdaUpdateWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getId, id)
|
||||
.set(FileTaskEntity::getStatus, "FAILED"));
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_LOCK = """package com.example;
|
||||
@Service
|
||||
public class DemoService {
|
||||
@Transactional
|
||||
public void finalizeTask(Long taskId) {
|
||||
TaskDistributedLockService.LockHandle handle = acquireTaskLock("MODULE", taskId);
|
||||
if (handle == null) {
|
||||
return;
|
||||
}
|
||||
try (handle) {
|
||||
taskMapper.update(null, new LambdaUpdateWrapper<TaskFileEntity>()
|
||||
.eq(TaskFileEntity::getId, taskId));
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE_PLAIN = """package com.example;
|
||||
@Service
|
||||
public class DemoService {
|
||||
public int sum(List<Integer> nums) {
|
||||
return nums.stream().mapToInt(Integer::intValue).sum();
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class TxAuditDetectTest(unittest.TestCase):
|
||||
def test_audit_detects_tx_method(self):
|
||||
findings = scan_text(FIXTURE_TX, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertEqual(findings[0]["method"], "submitResult")
|
||||
self.assertFalse(findings[0]["class_level"])
|
||||
|
||||
def test_audit_classifies_movable(self):
|
||||
findings = scan_text(FIXTURE_TX, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
movable = findings[0]["movable"]
|
||||
self.assertIn("compute", movable)
|
||||
self.assertIn("assembly", movable)
|
||||
self.assertIn("log", movable)
|
||||
self.assertIn("cleanup", movable)
|
||||
self.assertIn("write", findings[0]["must_stay"])
|
||||
self.assertGreater(findings[0]["priority"], 0)
|
||||
|
||||
def test_audit_no_tx_not_reported(self):
|
||||
self.assertEqual(len(scan_text(FIXTURE_PLAIN, "Plain.java")), 0)
|
||||
|
||||
def test_audit_write_only_no_movable(self):
|
||||
findings = scan_text(FIXTURE_WRITE_ONLY, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertIn("write", findings[0]["must_stay"])
|
||||
self.assertEqual(findings[0]["movable"], [])
|
||||
|
||||
def test_audit_lock_flagged_must_stay(self):
|
||||
findings = scan_text(FIXTURE_LOCK, "DemoService.java")
|
||||
self.assertEqual(len(findings), 1)
|
||||
self.assertIn("lock", findings[0]["must_stay"])
|
||||
|
||||
|
||||
class TxAuditCoverageTest(unittest.TestCase):
|
||||
def test_audit_covers_all_modules(self):
|
||||
report = scan_modules(MODULES_ROOT)
|
||||
self.assertGreaterEqual(report.scanned_files, 600)
|
||||
self.assertGreater(len(report.findings), 50)
|
||||
modules = {f["module"] for f in report.findings}
|
||||
self.assertGreaterEqual(len(modules), 15)
|
||||
|
||||
def test_audit_classification(self):
|
||||
for finding in scan_modules(MODULES_ROOT).findings:
|
||||
self.assertIn("must_stay", finding)
|
||||
self.assertIn("movable", finding)
|
||||
self.assertIsInstance(finding["must_stay"], list)
|
||||
self.assertIsInstance(finding["movable"], list)
|
||||
|
||||
def test_audit_result_endpoints(self):
|
||||
report = scan_modules(MODULES_ROOT)
|
||||
result_methods = [
|
||||
f
|
||||
for f in report.findings
|
||||
if "result" in f["method"].lower() or "submit" in f["method"].lower()
|
||||
]
|
||||
self.assertGreater(
|
||||
len(result_methods), 0, "应找到 /result 相关 @Transactional 方法"
|
||||
)
|
||||
modules_with_result = {f["module"] for f in result_methods}
|
||||
self.assertGreaterEqual(len(modules_with_result), 3)
|
||||
|
||||
def test_audit_python_facing(self):
|
||||
report = scan_modules(MODULES_ROOT)
|
||||
flagged = [f for f in report.findings if f["python_facing"]]
|
||||
self.assertGreater(len(flagged), 0, "应标记 Python 回调相关方法")
|
||||
for f in flagged:
|
||||
name = f["method"].lower()
|
||||
self.assertTrue(
|
||||
any(
|
||||
k in name
|
||||
for k in (
|
||||
"result",
|
||||
"submit",
|
||||
"upload",
|
||||
"chunk",
|
||||
"done",
|
||||
"ack",
|
||||
"report",
|
||||
)
|
||||
),
|
||||
f"python_facing 标记与命名不符: {f['method']}",
|
||||
)
|
||||
|
||||
def test_audit_priority_order(self):
|
||||
findings = scan_modules(MODULES_ROOT).findings
|
||||
priorities = [f["priority"] for f in findings]
|
||||
self.assertEqual(priorities, sorted(priorities, reverse=True))
|
||||
|
||||
def test_audit_repeatable(self):
|
||||
first = scan_modules(MODULES_ROOT).to_dict()
|
||||
second = scan_modules(MODULES_ROOT).to_dict()
|
||||
self.assertEqual(
|
||||
json.dumps(first, sort_keys=True), json.dumps(second, sort_keys=True)
|
||||
)
|
||||
|
||||
def test_audit_documented(self):
|
||||
self.assertTrue(DOC_PATH.is_file(), f"audit doc missing: {DOC_PATH}")
|
||||
text = DOC_PATH.read_text(encoding="utf-8")
|
||||
self.assertIn("事务", text)
|
||||
self.assertIn("必须", text)
|
||||
self.assertIn("可移出", text)
|
||||
|
||||
def test_audit_no_code_change(self):
|
||||
changed = subprocess.run(
|
||||
["git", "diff", "--name-only", "HEAD", "--", "backend-java/src"],
|
||||
cwd=REPO_ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
self.assertEqual(changed, "", f"生产代码被改动: {changed}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user