code-to10 v7 mech1: scorecard rubric versioning, append-only rubric + snapshot tables

(cherry picked from commit 368475243367685bf9db9335ec929958de031ca6)
This commit is contained in:
host committed 2026-11-03 02:49:27 +00:00
1 parent 3978dbbbf2
commit be81d658b6
3 files changed
+684 -6

No files matched your search

+40 -6
View File
@@ -44,7 +44,10 @@
- 文档与技能并入架构与契约一致性
(技能文本、附录溯源、移植规则最终都是契约一致性的一部分)。
输入格式:build_scorecard(evidence, thresholds=None)
输入格式:build_scorecard(evidence, thresholds=None, rubric_version=None)
rubric_version 只是卡片上的版本锚点(版本化持久存储见
cloud/scorecard_rubric.py:标尺改动写新版本行、旧行只读,
本函数不查库、不改旧分)。
evidence: dict,键为上面 7 个维 id,值为该维的证据 dict。
每个维的证据字段见各 _score_* 函数的 docstring。
调用方必须带来源、时间、检查名;本模块不自动从测试文件、
@@ -94,7 +97,7 @@ UNTESTED_KINDS = {"fixture", "viewport_substitute", "code_review_only",
"fixture_simulated", "dry_run", "estimated"}
def _thresholds_source(thresholds):
def thresholds_source(thresholds):
"""阈值来源:只有调用方显式传入 user_approved 才算已拍板。"""
if not thresholds:
return "test_default_unapproved"
@@ -109,6 +112,29 @@ def _thresholds_source(thresholds):
return "test_default_unapproved"
# 旧私有名的兼容别名(v2cov 评分卡测试仍从这里导入它)。
_thresholds_source = thresholds_source
def _effective_thresholds(thresholds):
"""实际用于计分的阈值表:默认值 + 调用方显式覆盖,逐项归一化。
未被覆盖的键仍取 DEFAULT_THRESHOLDS(与 _t 的逐键回落一致),
因此卡片上报告的 thresholds 就是真正算分的表,不再是“恒为
默认值”的旧写法。数值本身仍一律标来源,未拍板的不冒充生产值。
"""
effective = {k: dict(v) for k, v in DEFAULT_THRESHOLDS.items()}
for key, entry in (thresholds or {}).items():
if isinstance(entry, dict):
merged = {"value": entry["value"]}
merged["source"] = entry.get("source", "test_default_unapproved")
effective[key] = merged
else:
effective[key] = {"value": entry,
"source": "test_default_unapproved"}
return effective
def _t(thresholds, key):
if thresholds and key in thresholds:
entry = thresholds[key]
@@ -437,8 +463,15 @@ _SCORERS = {
}
def build_scorecard(evidence, thresholds=None):
"""算出 7 维评分卡。evidence 缺键按空证据处理(该维记 None)。"""
def build_scorecard(evidence, thresholds=None, rubric_version=None):
"""算出 7 维评分卡。evidence 缺键按空证据处理(该维记 None)。
rubric_version:调用方显式传入的标尺版本号(见
cloud/scorecard_rubric.py)。本函数不查库、不定版本:
未传入时卡片记 rubric_version=None,表示“未锚定到版本化
标尺”,分数仍按 thresholds(或默认值)算出,但不具备
跨标尺可比性。计分规则、7 维定义、达标规则一字未改。
"""
evidence = evidence or {}
th = thresholds or {}
dimensions = []
@@ -462,8 +495,9 @@ def build_scorecard(evidence, thresholds=None):
"pass_score": PASS_SCORE,
"missing_items": missing_all,
"untested_items": untested_all,
"thresholds_source": _thresholds_source(th),
"thresholds": {k: v for k, v in DEFAULT_THRESHOLDS.items()},
"thresholds_source": thresholds_source(th),
"thresholds": _effective_thresholds(th),
"rubric_version": rubric_version,
}