zizi c9f69d9d6d 治理: Skill 测试治理第一阶段——harness 控制平面 + 实现测试迁出运行时目录
范围(不含 design-story-foundation、docs/、humanization/README.md 等进行中改动):

1. 新增 harness/ 控制平面
   - skill_harness.py 静态审计:32 个运行时 Skill 的 frontmatter/manifest/文档污染,当前 0 问题
   - run_selected.py 选择性执行器:manifest 与磁盘一一对账、依赖阻断、
     空跑与 skip-only 失败关闭、AST 测试形状门
   - manifests/skills.json:32 个 Skill 的合同责任方与协作领域登记
   - manifests/test-inventory.json:81 个测试资产登记
   - specs/skill-testing.md 与 README.md:测试分层、证据边界与 harness 职责

2. 实现测试从 .claude/skills/*/scripts/ 迁至 tests/skills/<skill>/
   - 71 个测试文件迁移并修复项目根与临时目录运行导入
   - 数据库触发器测试宽泛异常收窄为 psycopg.errors.RaiseException
   - 抽取离线大测试拆出真实 PG smoke(默认阻断,不计入离线通过)
   - 抽取 presence 去重边界拆出独立测试:493 + 78 = 571 项检查不变

3. 运行时文档清理
   - 13 个 SKILL.md 移除自测/离线验证段落、测试命令与测试文件事实源表述,
     只保留运行时合同;业务运行合同、额度、授权与离线模式均保留

4. SoT 同步
   - AGENTS.md:新增 Skill 领域索引(7 个合同责任方分组,覆盖 32 个运行时 Skill)
   - 领域 07:测试入口改由 harness/manifests/ 登记,SKILL.md 不承载测试命令
   - humanization 覆盖矩阵:活动测试路径同步迁移

验证证据: harness 自测 15 项 + runner 自测 13 项通过;静态审计 32 Skill / 0 问题;
73 个非数据库测试通过;8 个集成条目中 6 个 PostgreSQL 项被依赖门明确阻断;
py_compile 与 git diff --check 通过。未连接 PostgreSQL、网络、真实模型或额度。

已知边界: 真正 skill_behavior_eval 仍为 0,尚未验证任何 Skill 自然语言行为;
evaluate-frozen-replay 的 raw 存储边界冲突留待单独治理。
2026-08-19 01:50:20 +08:00

83 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""细纲功能合同的离线回归测试,不启动模型、不访问作品数据。
字段权威 = meta/schemas/fine_outline.yaml;本测试同时校验技能文档(产出侧)与
该 schema(字段权威)声明的必填/推荐字段一致,防止两者再次漂移。
"""
from pathlib import Path
import unittest
PROJECT_ROOT = Path(__file__).resolve().parents[3]
SKILL = (
PROJECT_ROOT / ".claude" / "skills" / "plan-chapter" / "SKILL.md"
).read_text(encoding="utf-8")
PLANNER = (PROJECT_ROOT / ".claude" / "agents" / "planner.md").read_text(encoding="utf-8")
CHAINS = (PROJECT_ROOT / "meta" / "chains" / "README.md").read_text(encoding="utf-8")
SCHEMA = (
PROJECT_ROOT / "meta" / "schemas" / "fine_outline.yaml"
).read_text(encoding="utf-8")
# 与 meta/schemas/fine_outline.yaml 的必填/推荐集保持一致。
REQUIRED_FIELDS = (
"targetChapter",
"sourceRef",
"chapterGoal",
"hardConstraints",
"keyEvents",
"adjustableBeats",
"declaredNewFacts",
"mustAppearEntities",
"chapterEndHook",
)
RECOMMENDED_FIELDS = (
"foreshadowing",
"entities",
"stateChanges",
"unknowns",
"assumptions",
"sourceRefs",
"targetChars",
)
class FineOutlineContractTest(unittest.TestCase):
def test_contract_is_bound_to_existing_planner_slot(self):
self.assertIn("scenario: fine_outline", SKILL)
self.assertIn("fine_outline", PLANNER)
self.assertIn("fine_outline", CHAINS)
self.assertIn("规划→planner", CHAINS)
def test_skill_cites_schema_as_field_authority(self):
# 技能文档必须把字段权威指向 schema,不再自持一套字段集。
self.assertIn("meta/schemas/fine_outline.yaml", SKILL)
self.assertIn("字段权威", SCHEMA)
def test_required_fields_present_in_skill_and_schema(self):
for field in REQUIRED_FIELDS:
self.assertIn(field, SKILL, f"技能文档缺必填字段 {field}")
self.assertIn(field, SCHEMA, f"schema 缺必填字段 {field}")
# hook 已统一为 chapterEndHook,不应再以裸 hook 作字段名出现于必填纪律。
self.assertIn("chapterEndHook", SKILL)
def test_recommended_fields_present_in_skill_and_schema(self):
for field in RECOMMENDED_FIELDS:
self.assertIn(field, SKILL, f"技能文档缺推荐字段 {field}")
self.assertIn(field, SCHEMA, f"schema 缺推荐字段 {field}")
def test_shadow_boundary_and_red_lines_are_explicit(self):
self.assertIn("不得输出正文", SKILL)
self.assertIn("Shadow", SKILL)
self.assertIn("目标章细纲作为生成输入", SKILL)
def test_freeze_and_two_line_retrieval_rules_are_explicit(self):
self.assertIn("<= as_of", SKILL)
self.assertIn("卡是检索索引和事实补充", SKILL)
self.assertIn("目标章正文", SKILL)
self.assertIn("unknowns", SKILL)
if __name__ == "__main__":
unittest.main()