基于 skills-index 与 baseline 双重证据的 unit_tests 验证回填:claude-trading-skills 的 Issue 496 实践

原创2026-11-14 12:27:462,129 阅读
文章标签:金融科技AI 技能人工智能数据分析

基于 skills-index 与 baseline 双重证据的 unit_tests 验证回填:claude-trading-skills 的 Issue #496 实践

本文以 claude-trading-skills 仓库中 docs/dev/issue-496-unit-tests-backfill.md 这份评估记录为主线,讲清楚一件事:为什么一个 skill 被标记为 status: production,它的 unit_tests 轴仍然可能停留在 not_verified;以及如何用采集器脚本、CI 测试矩阵、baseline override 三者配合,把“测试确实证明了输出契约和 fail-closed 行为”这件事变成可复核、可重放的证据。读完后你能独立复现这套回填流程、读懂每条 gap 的成因,并知道在什么情况下才有资格写下一个 passed。

一、问题的起点:production 不是测试合格的证明

status: production 在 claude-trading-skills 里只是目录生命周期标签,它本身不构成“交易逻辑正确”的证明。因此每个生产 skill 在 skills-index.yaml 中另有一个 verification 块,包含八个轴:

verification:
  instruction_contract: passed | not_verified | not_applicable
  unit_tests: passed | not_verified | not_applicable
  workflow_contract: passed | not_verified | not_applicable
  end_to_end_replay: passed | not_verified | not_applicable
  data_provenance: passed | not_verified | not_applicable
  financial_logic_review: passed | not_verified | not_applicable
  empirical_validation: passed | not_verified | not_applicable
  security_review: passed | not_verified | not_applicable

这个块的 schema 定义在 metadata-and-workflow-schema.md,校验逻辑落在 validate_skills_index.py(错误码 IDX013:块类型错误、缺轴、多轴或枚举值非法都是硬错误)。

unit_tests 轴的 passed 判据在 production-verification.md 里写得很克制:

每个可执行 helper 脚本都有自动化的 happy-path、boundary、error-path fixture;fail-closed 行为与输出 schema 一致性被证明;记录的命令退出码为 0。

它同时明确否定了三类“看起来像证据”的东西:仅仅存在测试文件、聚合 CI 绿灯、仓库级扫描。passed 是一个 AND 命题,这也是为什么共享 baseline profile 里 unit_tests 的 rationale 统一写成「测试存在或聚合运行通过,不能证明每个可执行脚本都有 happy、boundary、error-path 和 fail-closed 覆盖」。

Issue #496 的第 1 步,就是把这条 AND 命题逐 skill 落地。评估时点记录在标题里(assessed 2026-10-26),产出结论是:

  • 12 个 skill 标为 passed(index 与同提交 baseline override 同时更新,每条 override 带 per-skill rationale);
  • 47 个 skill 保持 not_verified 并记录具体缺口;
  • 3 个无可执行 helper 脚本的 skill 为 not_applicable。

这三个数字可以直接从索引里复算出来(当前仓库实测:62 个 production skill,Counter({'not_verified': 47, 'passed': 12, 'not_applicable': 3})),因此文档结论与索引状态是自洽的。

二、提交锚点约定:为什么 assessed_commit 不是 PR head

原文档开头有一段容易被跳过的元信息,但它是整套证据可信的前提:

Assessed commit convention: assessed_commit pins 52c93232..., the last revision common to origin/main and this PR branch(PR head 的祖先,squash-merge 之后仍可达;一个提交无法包含它自己的最终 SHA)。记录的证据命令与所引用的 skill-local 测试文件在 PR head 修订上是逐字节一致的。

这里有三层设计意图,值得在写任何审计记录时复用:

  1. 锚点必须可解析、可复算。52c932329e25a614eea9e55f7aa8e7677e8c0b84 在 baseline 的每条 passed override 的 evidence 里重复出现(见 production-verification-baseline.yaml)。选 PR head 的祖先而不是 head 自身,是因为 squash-merge 会重写 SHA,导致证据永久失效。
  2. 被测对象与证据必须同修订。文档专门声明:记录的 evidence command 与被引用的 skill-local 测试文件在 head 上 byte-identical。否则“我跑的命令”和“你看到的测试”可能是两份不同的东西。
  3. CI 状态要指名到 run 与 job。文档记录了 GitHub Actions run 40103302803 在该提交上对本评估覆盖的所有 test-matrix 行都是绿的,并主动披露该 run 上唯一失败的 job 是 Supply chain——一个在 #587 上同样失败的既有依赖审计问题,与 skill 测试无关。这种“主动标注已知红灯的归属”是审计记录区别于营销材料的核心。

另外一个细节体现了同样的谨慎:position-sizer 的 override 里额外记录了 assessed_source_blob(position_sizer.py 的 Git blob 哈希),并说明「用被测实现的 blob 标识被测试版本,避免自引用提交」。原因是当一个修复本身就包含在评估提交中时,assessed_commit 无法干净地指代“修复前的被测代码”,blob 哈希是更精确的做法。

三、两条硬规则:证据来源的白名单与黑名单

回填最容易出错的地方不是跑不通测试,而是把错误的测试当成了证据。原文档用一句话定了边界:

只有位于 skills/<id>/scripts/tests 下、且断言该 skill 自己产出的 output keys / schema file 的 skill-local 测试,才能为 output-schema conformance 和 error/fail-closed 信号提供来源;仓库级套件(scripts/tests/*)只计入 coverage mapping,永远不被引用为 schema 证据。

这条规则在代码里是硬编码的,见 backfill_unit_tests_evidence.py 的 signals():只有传入的 skill_local_files 会被扫描,candidate_files(仓库级测试)仅被记入 repo_level_candidates_present 供人看,不参与判定。docstring 给出的理由是具体的:scripts/tests/test_provider_contracts.py 断言的是 provider 的输入契约(对应 issue #332),不是某个 skill 的输出 schema。

第二条规则关于“绿灯”的含义:

记录的命令保留真实安装/运行状态(install && run),不写无条件 exit 0。安装失败时采集器在运行该行之前停止。passed 提案要求该 skill 行安装与执行都成功;当映射了仓库级测试时,repo-scripts 行也必须成功。缺失退出码证据即视为缺口。

原文档的 portfolio-manager 一行是这条规则最好的注脚:本地记录行 exit 1(消息文本与锁定 CI 环境存在漂移),而 CI 的 Test (portfolio-manager) 行在该提交上是绿的——仍然保持 not_verified,因为本地记录的运行没能建立 exit-0 证据。同理,theme-detector 的缺口原因里还带了一次自我更正:

Corrected: the earlier explanation blaming an ambient interpreter flake was wrong; cause was environment drift.

四、采集器的六步流水线

scripts/backfill_unit_tests_evidence.py 的模块 docstring 把流程写成了六步,这也是阅读代码的最佳索引:

步骤 行为 关键实现
1 枚举可执行脚本,规则与 ci_test_matrix.executable_test_inventory 完全一致 executable_scripts(),L67-L75
2 从两个规范位置 + 仓库级套件收集候选测试模块 test_locations(),skills/<id>/scripts/tests、skills/<id>/tests、scripts/tests
3 提出 script→test 映射(建议性质,须经 reviewer 确认) propose_mapping(),L104-L132
4 运行可重放的证据命令对并记录退出码 run_row(),L184-L205
5 记录 error-path / fail-closed 与 output-schema 一致性的建议信号 signals()
6 输出 JSON 证据报告与 per-skill passed/gap 提案 main(),写 reports/unit_tests_evidence.json

最值得注意的是第 6 步的边界:脚本从不写 YAML。docstring 明确写着「人类/agent reviewer 确认提案后再单独应用 index/baseline 编辑」。这把“机器收集”与“人工背书”拆成两个动作,避免了自动化工具把自己的启发式判断直接变成合规声明。

4.1 脚本枚举:与 CI 矩阵同源

第 1 步之所以要强调“与 ci_test_matrix 同规则”,是因为两处实现必须给出同一个答案,否则覆盖盘点会互相矛盾。对照 ci_test_matrix.py 的 executable_test_inventory(),采集器复用了同样的三条件:

path.is_file()
and path.name != "__init__.py"
and "tests" not in path.relative_to(scripts_dir).parts

递归 rglob("*.py")、排除 __init__.py、排除路径中出现 tests 段。CI 侧在此基础上还做了正反两向的 fail-closed 校验(validate_executable_test_coverage(),L389-L423):有可执行脚本却没 canonical 测试要报错;knowledge_only: true 只允许出现在“无任何 scripts/**/*.py”的生产 skill 上。这正是 not_applicable 这一类别的机器判据——它对应 test_production_verification_baseline.py 里的一条不变量:

assert (resolved_values["unit_tests"] == "not_applicable") is (not has_scripts)

也就是说,not_applicable 不是主观豁免,而是“目录里没有脚本”这一事实的镜像。文档里 market-news-analyst、scenario-analyzer、us-stock-analysis 三个 skill 属于此类,理由统一写作「无 executable helper scripts(超出 #496 第 1 步范围)」。

4.2 映射:按脚本名整词命中的建议式匹配

propose_mapping() 的算法相当朴素,值得完整理解才能正确解读它的误报:

stem_word = re.compile(rf"\b{re.escape(script.stem)}\b")
for test_rel, text in test_texts:
    if stem_word.search(text) or script_rel in text:
        hits.add(test_rel)

用脚本文件名(去扩展名)作整词正则,或直接用脚本相对路径在测试源码文本里检索。命中即记为映射,未命中即进入 unmatched。

两个直接后果:

  • 它是文本级、非 AST 级的。测试若通过间接导入、packaging 或 fixture 才用到某脚本,不会被匹配到——这正是文档中 kanchi-dividend-sop 缺口的原因:「1 个未匹配脚本(thresholds.py)通过被测试的 importers 间接执行;单凭这一点不足以判定 passed」。反过来,trade-hypothesis-ideator 的 run_hypothesis_ideator.py 唯一覆盖是经 scripts/workflow_replay.py 的传递覆盖,同样被判不足。
  • 未匹配本身就是缺口。unmatched 只要非空就会追加一条 gap reason("{n} executable script(s) without a mapped test module"),哪怕其余信号全绿。parabolic-short-trade-planner 的「3 个可执行脚本无映射测试模块」、institutional-flow-tracker 的「track_institution_portfolio.py 未被任何测试模块引用,且它是未实现的占位脚本」都属此类。

4.3 信号检测:两个正则与一个刻意的空缺

signals() 用两个正则组合判定,见 L50-L57:

SCHEMA_QUESTION_RE = re.compile(
    r"schema\.json|jsonschema|required_ |declared[_ ]outputs", re.IGNORECASE
)
SCHEMA_ASSERT_RE = re.compile(r"assert |\.issubset\(", re.IGNORECASE)
FAILOPEN_ASSERT_RE = re.compile(
    r"pytest\.raises|assert .*returncode|assert .*exit|assert .*invalid|assert .*error",
    re.IGNORECASE,
)
  • schema_conformance_signal = 文件里同时出现 schema 相关标识与该断言形态;
  • fail_closed_signal = 出现 pytest.raises、断言 returncode/exit、断言 invalid/error 之一。

配套的细节规则都能在测试里找到对应守卫:

行为 守卫测试
conftest.py 一律跳过,避免共享 fixture 冒充证据 test_signals_ignore_conftest
仅 docstring 提到 schema 不算证据 test_signals_skip_docstring_only_schema_mention
assert proc.returncode == 2 这类退出码断言算 fail-closed test_signals_accept_exit_code_error_paths
只有普通 happy-path 断言时两个信号都为 False test_signals_reject_when_no_schema_or_failopen_evidence

最关键的诚实之处在于一个没有被自动化的维度。signals() 输出里固定包含:

"fixture_type_signal": "not_assessed",
"signal_scope": "skill_local_scripts_tests_only",

也就是说,判据中“happy-path / boundary 覆盖”这一半完全不由脚本检测。这正是原文档要求「per-skill 证据逐条记录在 override rationale 中」的原因——passed 的边界覆盖声明必须由人写清楚。同理,schema_conformance_confirmed_by_reviewer 默认 False,采集器永远不会给自己盖章:

采集器的原始输出从不标记 reviewer 确认:schema_conformance_confirmed_by_reviewer 默认 False,确认每条 schema 主张的 per-skill 深审记录在 override rationale 里。

五、命令契约:install && run 与退出码

第 4 步执行的命令对是本文档反复出现的两个命令行:

python3 scripts/ci_test_matrix.py install <skill-id> && python3 scripts/ci_test_matrix.py run <skill-id>

run_row() 逐条执行并把 install_exit、run_exit 与各自 stderr 的最后 10 行写入报告;recorded_command 字符串按实际执行形态拼装(check_only 时插入 --check),且不含任何 exit 0 后缀:

results["recorded_command"] = (
    f"python3 scripts/ci_test_matrix.py install {entry_id}{check_flag} && "
    f"python3 scripts/ci_test_matrix.py run {entry_id}"
)

有两条测试专门守护这一点:test_run_row_stops_after_install_failure(安装失败时只调用一次 subprocess,run_exit 为 None)和 test_run_row_records_actual_check_command("; exit" not in recorded_command)。

两端的语义差异也值得说明:

  • install 不加 --check 时,会读 uv.lock 把裸需求钉到锁定版本,然后优先用 uv pip install --python <sys.executable>,无 uv 时回退 python -m pip install(ci_test_matrix.py)。这解释了为什么本地失败常被归为 environment drift:安装会落到当前解释器环境。
  • install --check 完全不安装,只校验锁定环境里的版本是否满足每条 requirement,并给出「修改 ci-test-policy.yaml 的 matrix.<id>.requirements」的提示(L584-L605)。repo_scripts_row_check() 永远以 check_only=True 调用它——因为 repo-scripts 行只用于给仓库级映射测试提供集成覆盖,不应该顺手往环境里装东西。
  • run 就是 python -m pytest <test_paths> --tb=short -q,开启覆盖率时附加 --cov=<coverage_source> 与 --cov-fail-under=0(L624-L655)。注意 --cov-fail-under=0:覆盖率门禁不在这条路径上,所以“跑通了”绝不能被读成“覆盖达标了”。

5.1 采集器自身的 CLI

# 全量扫描全部 production skill
python3 scripts/backfill_unit_tests_evidence.py

# 只评估单个 skill(可重复传参)
python3 scripts/backfill_unit_tests_evidence.py --skill position-sizer

# 只做结构分析,不执行任何测试
python3 scripts/backfill_unit_tests_evidence.py --skip-run

# 改变报告落盘目录(默认 reports/)
python3 scripts/backfill_unit_tests_evidence.py --output-dir reports/

参数定义在 main() 的 argparse 段。行为上有一个容易踩的坑:--skip-run 永远不可能给出 passed,因为只要用了它就会追加 reason "test execution skipped (--skip-run); exit status not recorded",而任何非空 reason 都会把提案压回 gap。它的正确用途是结构盘点与 CI 中免网络的快速回归。

输出形态固定为:

{
  "assessment_date": "YYYY-MM-DD",
  "command": "python3 scripts/backfill_unit_tests_evidence.py",
  "issue": "...issues/496",
  "note": "proposals are advisory; reviewer confirmation required before baseline edits. ...",
  "results": [ /* 每 skill 一条 */ ]
}

每条结果含 skill_id、current_value、proposed_value、unmatched_scripts、script_test_mapping、candidate_tests、signals、row_execution、gap_reasons。

六、判定逻辑:gap_reasons 是唯一的真相来源

把 main() 里累加 reason 的顺序读一遍,就能反推出整棵判定树(L267-L289):

proposed = "gap"
reasons = []
if unmatched:
    reasons.append(f"{len(unmatched)} executable script(s) without a mapped test module")
if not mapping:
    reasons.append("no test modules proposed for any executable script")
if args.skip_run:
    reasons.append("test execution skipped (--skip-run); exit status not recorded")
else:
    if row.get("install_exit") != 0:
        reasons.append("recorded ci_test_matrix install did not exit 0")
    if row.get("run_exit") != 0:
        reasons.append("recorded ci_test_matrix row did not exit 0")
    if mapped_repo_level:
        repo_row = row.get("repo_scripts_row", {})
        if repo_row.get("install_exit") != 0 or repo_row.get("run_exit") != 0:
            reasons.append("mapped repo-scripts install/run did not both exit 0")
if mapping and not sig["fail_closed_signal"]:
    reasons.append("no assertion-shaped error-path/fail-closed test among mapped tests")
if mapping and not sig["schema_conformance_signal"]:
    reasons.append("no assertion-shaped output-schema conformance test among mapped tests")
if not reasons:
    proposed = "passed"

由此可以列出五类必然缺口:

  1. 有脚本未匹配到测试模块;
  2. 完全没有映射;
  3. 运行被跳过,或 install/run/repo-scripts 任一非 0;
  4. 有映射但无 fail-closed 断言;
  5. 有映射但无 output-schema 一致性断言。

注意第 4、5 条都带 if mapping and 前置条件:没有映射时不会重复报信号缺失(此时第 2 条已经覆盖)。这套“先结构性、再运行性、最后语义性”的顺序,也解释了为什么文档里 47 条缺口能归成少数几个高频句式。

七、证据契约:baseline override 与三道一致性检验

采集器只出 JSON。要把它变成一个可发布的声明,必须同时改两处,且被测试强制对齐。

7.1 override 的结构

passed 只能以 skill 级 override 形式出现,模板如 production-verification-baseline.yaml:

skills:
- id: backtest-expert
  profile: executable_workflow_trading
  overrides:
    unit_tests:
      value: passed
      rationale: "Single executable script evaluate_backtest.py: required_keys.issubset on the produced
        evaluate() result and write_outputs read-back of the JSON/MD report (output-schema conformance);
        fail-closed CLI test exits 1, writes no report, on invalid input, plus evidence gates blocking
        Deploy on too-good results; happy/boundary fixtures (win_rate 0/100, expectancy threshold,
        profit-factor boundaries)."
      evidence:
      - command: python3 scripts/ci_test_matrix.py install backtest-expert && python3 scripts/ci_test_matrix.py run backtest-expert
      - tests: skills/backtest-expert/scripts/tests/test_evaluate_backtest.py
      - provenance: skills/<id>/scripts/tests (skill-local) validate this skill's own output schema and fail-closed behavior; repo-level tests are NOT cited as schema evidence
      - assessed_commit: 52c932329e25a614eea9e55f7aa8e7677e8c0b84
      - assessed_date: '2026-10-25'

每条 rationale 都遵循同一套叙述骨架,12 条 passed 抽查可见其一致性:

维度 典型表述(摘自对应 override)
输出 schema 一致性 Plan output key-set asserted (summary/warnings/actionable_orders/order_templates/input_metadata, schema_version 1.0);thesis.schema.json validated with Draft7Validator directly;Produced JSON report asserted to match the declared schema
fail-closed fail-closed CLI test exits 1, writes no report, on invalid input;fail-closed suite exits 2 (not 1) on degenerate values, geometry violation, non-USD without FX
boundary happy/boundary fixtures (win_rate 0/100, expectancy threshold, profit-factor boundaries);boundary fixtures for penny stocks, large accounts, fractional precision, and Kelly negative expectancy
脚本覆盖 all four executable scripts have direct test modules;12 executable scripts exercised with fmp_compat covered transitively

若干 override 还主动写出了“这条证据的边界在哪里”,这是最值得学习的写作方式:

  • futures-position-sizer:Caveat: CONTRACT_SPECS required-keys asserts table-internal keys; evidence is the produced-payload assertions, not those.
  • macro-regime-detector:Caveat: component required-key asserts are calculator-internal; evidence is the CLI produced-output assertions.
  • market-breadth-analyzer:invalid primary date writes no artifacts (fail-closed, ValueError path)

也就是说,passed 的成立依赖具体那几条断言,而不是“文件里有 assert”这件事。

7.2 三道由测试强制执行的一致性

test_production_verification_baseline.py 把“baseline 与 index 不许漂移”变成了红灯:

  1. 集合一致:baseline 的 skills[].id 必须与 index 中 status: production 的集合完全相同,且不重复(test_baseline_covers_exactly_current_production_skills)。

  2. 值一致:每行按 profile.axes 解析(override 覆盖 profile),得到的八轴值必须逐项等于 index 里该 skill 的 verification:

    assert resolved_values == production[row["id"]]["verification"]
    
  3. passed 必须有 override 与证据:if resolved["value"] == "passed": assert axis in overrides,且 assert resolved["evidence"] 非空;证据的每一项必须是非空 dict、键值都是非空白字符串(_assert_evidence_entries)。

再加一条与脚本存在性强绑定的不变量,把 not_applicable 钉在文件事实上:

assert (resolved_values["unit_tests"] == "not_applicable") is (not has_scripts)
assert (resolved_values["workflow_contract"] == "not_applicable") is (not has_workflows)
assert (resolved_values["end_to_end_replay"] == "not_applicable") is (not has_workflows)

此外还有一条针对这次回填的回归守卫,见 test_backfill_unit_tests_evidence.py 的 test_fresh_module_reports_baseline_rationale_untruncated。函数名直白点出了它防的 bug:YAML 中 #... 注释把 rationale 文本吞掉。它从全新的 YAML 加载开始,要求:passed override 数量落在 10~20 之间、每条 rationale 长度 > 50、以白名单前缀(Produced、Plan output、Ticket payload、thesis.schema.json、E2E asserts、TestOutput 等)开头、且必须出现 schema 或 JSON 字样。

这条测试的副作用需要提前知晓:给 passed override 写 rationale 时,开头措辞和 schema/JSON 关键词是被测试约束的。随手改写成另一种开句会导致红灯。

7.3 采集器提案逻辑的自测矩阵

采集器本身的判定分支由参数化测试覆盖(test_proposal_requires_successful_install_and_all_mapped_rows),六种组合里只有最后一种产出 passed:

skill 行 repo-scripts 行 期望
install 1, run 0 0/0 gap
0/0 install 1, run 0 gap
0/0 0, run 1 gap
0/0 {}(缺失) gap
仅 run_exit: 0(无 install) 0/0 gap
0/0 0/0 passed

第五行是“缺失退出码证据即视为缺口”的代码化表达。

八、评估结果全表:12 / 47 / 3

下表是原文档的核心产出,也是 Issue #496 验收标准 #1 要求的 per-skill 状态记录(完整保留,一字未删):

Skill Proposed value Gap reasons / notes
backtest-expert passed -
breadth-chart-analyst gap 本地安装/运行无法执行:uv pip install 安装 opencv/pillow 时被 ambient Homebrew 解释器拒绝。CI Test (breadth-chart-analyst) 在 52c93232 上为绿。保持 not_verified(环境漂移,非环境偶发故障)。
breakout-trade-planner passed -
canslim-screener gap 映射测试中无断言形态的 output-schema 一致性测试
contrarian-setup-gate gap 映射测试中无断言形态的 output-schema 一致性测试
cot-contrarian-detector gap 映射测试中无断言形态的 output-schema 一致性测试
data-quality-checker gap 映射测试中无断言形态的 output-schema 一致性测试
dividend-growth-pullback-screener gap 映射测试中无断言形态的 output-schema 一致性测试
downtrend-duration-analyzer gap 映射测试中无断言形态的 output-schema 一致性测试
drawdown-circuit-breaker gap 映射测试中无断言形态的 output-schema 一致性测试
dual-axis-skill-reviewer gap 映射测试中无断言形态的 output-schema 一致性测试
earnings-calendar gap 映射测试中无断言形态的 output-schema 一致性测试
earnings-trade-analyzer passed -
economic-calendar-fetcher gap 映射测试中无断言形态的 output-schema 一致性测试
edge-candidate-agent passed -
edge-concept-synthesizer gap 映射测试中无断言形态的 error-path/fail-closed 测试;无断言形态的 output-schema 一致性测试
edge-hint-extractor gap 映射测试中无断言形态的 output-schema 一致性测试
edge-pipeline-orchestrator gap 映射测试中无断言形态的 output-schema 一致性测试
edge-signal-aggregator gap 映射测试中无断言形态的 output-schema 一致性测试
edge-strategy-designer gap 映射测试中无断言形态的 output-schema 一致性测试
edge-strategy-reviewer gap 映射测试中无断言形态的 error-path/fail-closed 测试;无断言形态的 output-schema 一致性测试;
exposure-coach gap 映射测试中无断言形态的 output-schema 一致性测试
finviz-screener gap 映射测试中无断言形态的 output-schema 一致性测试
ftd-detector gap 映射测试中无断言形态的 output-schema 一致性测试
futures-position-sizer passed -
ibd-distribution-day-monitor gap 映射测试中无断言形态的 output-schema 一致性测试
institutional-flow-tracker gap 占位脚本 track_institution_portfolio.py 未匹配(无测试模块引用;它是未实现的占位)。保持 not_verified。
kanchi-dividend-review-monitor gap 映射测试中无断言形态的 output-schema 一致性测试
kanchi-dividend-sop gap 1 个未匹配脚本(thresholds.py)经被测试的 importers 间接执行;单凭此不足以判 passed,且映射测试中无 skill-local 输出 schema 断言。保持 not_verified。
kanchi-dividend-us-tax-accounting gap 映射测试中无断言形态的 error-path/fail-closed 测试;无断言形态的 output-schema 一致性测试
macro-regime-detector passed -
market-breadth-analyzer passed -
market-environment-analysis gap 映射测试中无断言形态的 output-schema 一致性测试
market-news-analyst not_applicable(范围外) 无可执行 helper 脚本(超出 #496 第 1 步范围)
market-top-detector gap 映射测试中无断言形态的 output-schema 一致性测试
news-reaction-failure-analyzer passed -
options-strategy-advisor gap 本地安装/运行无法执行(同一 uv/pillow ambient 解释器原因)。CI 行在 52c93232 上为绿。保持 not_verified(环境漂移)。
pair-trade-screener gap 本地安装/运行无法执行(同一 uv/pandas ambient 原因)。CI 行在 52c93232 上为绿。保持 not_verified(环境漂移)。
parabolic-short-trade-planner gap 3 个可执行脚本无映射测试模块
pead-screener passed -
portfolio-manager gap 评估环境中本地行 exit 1(消息文本与锁定 CI 环境漂移)。该 CI 行在 52c93232 上为绿(run 40103302803)。因本地记录运行未建立 exit-0 证据,保持 not_verified。
position-sizer passed -
pre-trade-discipline-gate gap 映射测试中无断言形态的 output-schema 一致性测试
scenario-analyzer not_applicable(范围外) 无可执行 helper 脚本(超出 #496 第 1 步范围)
sector-analyst gap 映射测试中无断言形态的 output-schema 一致性测试
signal-postmortem gap 映射测试中无断言形态的 output-schema 一致性测试
skill-designer gap 映射测试中无断言形态的 output-schema 一致性测试
skill-idea-miner gap 映射测试中无断言形态的 output-schema 一致性测试
skill-integration-tester gap 映射测试中无断言形态的 error-path/fail-closed 测试
stanley-druckenmiller-investment gap 映射测试中无断言形态的 output-schema 一致性测试
strategy-pivot-designer gap 映射测试中无断言形态的 output-schema 一致性测试
technical-analyst passed -
theme-detector gap 本地行 exit 1(yfinance provider-fallback 测试对 ambient 包版本)。CI 行在 52c93232 上为绿。保持 not_verified。(已更正:此前归因于 ambient 解释器偶发的解释是错的;原因是环境漂移。)
trade-hypothesis-ideator gap run_hypothesis_ideator.py 未匹配;其唯一覆盖是经 scripts/workflow_replay.py 的传递覆盖,判不足。保持 not_verified。
trader-memory-core passed -
trading-skills-navigator gap 映射测试中无断言形态的 output-schema 一致性测试
uptrend-analyzer gap 映射测试中无断言形态的 output-schema 一致性测试
us-market-bubble-detector gap 映射测试中无断言形态的 output-schema 一致性测试
us-stock-analysis not_applicable(范围外) 无可执行 helper 脚本(超出 #496 第 1 步范围)
value-dividend-screener gap 映射测试中无断言形态的 output-schema 一致性测试
vcp-screener gap 映射测试中无断言形态的 output-schema 一致性测试
weekly-performance-digest gap 映射测试中无断言形态的 output-schema 一致性测试

8.1 把 47 条缺口归成六类

通读上表,gap 的原因实际上只有六种,识别它们决定了下一步该怎么修:

类型 计数特征 修复动作
A. 缺 output-schema 断言 绝大多数(约 35 条) 在 skill-local 测试里加对产出 JSON 的 key-set / schema 断言
B. 同时缺 fail-closed 断言 edge-concept-synthesizer、edge-strategy-reviewer、kanchi-dividend-us-tax-accounting 补 pytest.raises 或 CLI 退出码断言
C. 有脚本无映射测试 parabolic-short-trade-planner、institutional-flow-tracker、trade-hypothesis-ideator 补直接测试,或用显式 mapping 覆盖文本引用
D. 仅传递覆盖 kanchi-dividend-sop、trade-hypothesis-ideator 把传递覆盖变为直接断言
E. 本地环境漂移 breadth-chart-analyst、options-strategy-advisor、pair-trade-screener、portfolio-manager、theme-detector 修 CI 环境对齐,而不是改 code
F. 无脚本 market-news-analyst、scenario-analyzer、us-stock-analysis 无需动作,已是 not_applicable

值得单独指出的是 E 类:五个 skill 的 CI 行在评估提交上全绿,却依然保留 not_verified。这不是保守过度,而是因为规则要求「本地记录的运行建立 exit-0 证据」,而 install 步骤会落到当前的 ambient 解释器(uv pip install --python sys.executable)。环境漂移在语义上等价于“这条命令在评审者的机器上不可重放”,因此不能计入 passed。

九、可复现的复核流程

下面这套顺序与文档描述的方法一一对应,可以直接当作操作手册:

# 1) 只做结构盘点,先看清脚本/测试映射与未匹配脚本
python3 scripts/backfill_unit_tests_evidence.py --skip-run

# 2) 针对候选 skill 跑真实行,建立退出码证据
python3 scripts/backfill_unit_tests_evidence.py --skill position-sizer

# 3) 若要确认环境版本是否与锁定一致,单独跑 check 形态
python3 scripts/ci_test_matrix.py install position-sizer --check

# 4) 直接重放证据命令(与 baseline 里记录的形式一致)
python3 scripts/ci_test_matrix.py install position-sizer && \
python3 scripts/ci_test_matrix.py run position-sizer

# 5) 校验 index 与 baseline 的一致性(strict 模式会硬拦)
python3 scripts/validate_skills_index.py --strict-metadata --strict-workflows

# 6) 跑守护测试,确认 override 文本与解析均未被破坏
python3 -m pytest scripts/tests/test_backfill_unit_tests_evidence.py \
                 scripts/tests/test_production_verification_baseline.py -q

第 2、4 步的产物会落在 reports/unit_tests_evidence.json。把这个 JSON 里的 script_test_mapping、signals.signal_sources_schema、signals.signal_sources_fail_closed 与 override 的 rationale 逐条对齐,就是文档所说的“per-skill 深审”。复核时要回答三个问题,缺一不可:

  1. 这条断言作用于本 skill 产出的输出吗?(不是表内部键、不是 provider 输入)
  2. 失败路径是真的不写任何产物吗?(如 test_zero_available_components_fail_closed_without_reports 断言 exit 1 且无写入)
  3. boundary 场景是具体的数值边界吗?(如 win_rate 0/100、2^53 解析、penny stock)

十、七个容易踩的坑

把源码与文档的注意点合并,得到以下清单:

  1. 把仓库级测试当 schema 证据。scripts/tests/test_provider_contracts.py 断言的是 provider 输入契约,signals() 因此只扫 skill-local。override 里必须写上 repo-level tests are NOT cited as schema evidence 这句 provenance。
  2. 让 conftest.py 冒充证据。signals() 显式跳过它,并有专门测试守护。
  3. 用 docstring 里的 “schema” 交差。需要同时命中标识正则与断言正则;纯文本提及不算。
  4. 相信覆盖率。run 附加的是 --cov-fail-under=0,覆盖率门禁在 ci-test-policy.yaml 的另一条路径上,与 unit_tests 轴判定无关。
  5. 手写 exit 0。recorded_command 由代码按实际执行形态拼装,测试明确断言其中不含 ; exit。
  6. 用 gag 覆盖代替修复。--skip-run 一定产出 gap;它只能用于结构盘点。
  7. 改坏 override 措辞。test_fresh_module_reports_baseline_rationale_untruncated 约束了 rationale 的起始前缀、长度与关键词。

还有一条流程性的约束:采集器不写 YAML。任何 index/baseline 变更都必须由 reviewer 确认提案后单独提交,并保证 validate_skills_index.py --strict-metadata --strict-workflows 与两道守护测试同时通过。

十一、这份证据的有效期与边界

原文档的产出是 Issue #496 的第 1 步,其边界需要被准确理解:

  • 它是“per-skill unit test 证据回填”,不是完整的 #496 结论。文档结尾的后续记录要求仍包括 semantic audit、security review 与 instruction contract。
  • 它与更早的 生产单测清单 是两种不同性质的材料:后者是文件与策略盘点(62 个 skill、267 个 helper、251 个测试模块),文档里明确写着“不满足 #496 任何验收标准、不证明覆盖缺失、不建立 passed”;前者才是逐 skill 的语义判定。
  • 证据与其伴随的修订绑定。production-verification.md 的“Keeping evidence current” 要求:当 skill 的脚本、测试、workflow 契约、schema、数据源或财务逻辑变化时,必须重跑记录的证据并更新;若同一变更内未能重新建立证据,就把受影响的轴重置为 not_verified。这也解释了为什么 news-reaction-failure-analyzer、technical-analyst 的 assessed_date 更新到了 2026-11-08 并把 assessed_commit 换成了 10e38e14...,而 trader-memory-core 额外记录了 assessed_base_commit 与 assessed_change(Issue 682 的 legacy-short postmortem 变更)。
  • all_applicable_axes_passed 依然不等于可发布。发布前仍需查询实时的 GitHub issue 状态,确认无未决高优问题;该检查记录在 external_release_gates.open_high_severity_issues,状态为 not_evaluated 时明确表示“未冻结进八轴”。

十二、这套方法可迁移的部分

抛开具体项目名,这次回填留下的可复用模式有四条:

  1. 把“通过”拆成可机检与需人判两层。脚本负责脚本枚举、映射、退出码与正则级信号;fixture_type_signal: "not_assessed" 与 schema_conformance_confirmed_by_reviewer: False 是对能力边界的显式声明,而不是隐藏的假设。
  2. 让机器只产出提案,不产出结论。backfill_unit_tests_evidence.py 写 JSON 不写 YAML,把最终责任留在人工/agent reviewer 的 override rationale 上。
  3. 用测试锁住审计记录本身。baseline 与 index 的集合一致性、值一致性、passed 必须有 override 与证据、not_applicable 必须与“无脚本”互为充要、rationale 文本不许被 YAML 注释吞掉——每一条都有对应红灯。
  4. 主动披露不利信息。文档写明了唯一失败的 Supply chain job 归属、环境漂移导致的四个 skill、以及一次被自我更正的错误归因。这些“不好看”的记录,恰恰是这份证据能被信任的原因。
登录后查看全文
claude-trading-skills