一、技能重组(动作-对象命名) - 旧目录 clean/confirm/continuation/db/detect/embed/… 重组为 clean-book-text/decide-candidate/write-next-chapter/access-database/ check-content-consistency/embed-knowledge/…(git 识别为 rename,内容保持) - agents/*.md、AGENTS.md/CLAUDE.md 收编、example_skill 登记表同步新名 二、先审后入创作闭环(本次核心) 正文接受从"机械门一过就写正典"改为"机械门+语义审查双通过+用户批准+单事务原子提交", DB 级兜底,编排层跳步即被硬拒。 - candidate_cas.py + example_candidate_cas(109):持久化 CAS 状态链 - fact_delta.py + example_fact_delta/example_fact_ledger(106):结构化事实增量, 模型只提六型闭集增量+正文证据引文,仅用户批准的增量随正文同事务入账本 - projection_registry.py + example_projection_run(107):投影登记与恢复 - acceptance_state.py:接受前置实时状态重读 - lesson_registry.py + example_lesson(108):经验升格链,禁止自动升格 - DDL 105:example_candidate 增 semantic_status/semantic_report_sha256 - write_canonical.accept:语义兜底+同事务合并增量+登记投影; run_writer_pipeline/persist_writer_run/run_writer_semantic_detector/step2 接入全链 - claude_runtime:兼容新 CLI modelUsage 信息字段 三、审查修复(独立子代理四维审查后) - 事实增量 propose→approve 翻态正道,不撞唯一键 - 冻结配置探针重刷(CLI 2.1.211→2.1.231 漂移),profileSha256/adapterVersion 再登记 - 可视化合同悬空路径/五六空间矛盾、 SoT 旧技能名漂移、行尾空白清理 测试:离线 65 套 + 真实库集成 5 套(CAS/接受故障注入/事实增量/投影/经验升格)+ 回放 79 项全绿。 创作内容(docs/design、生成正文 artifacts)按"框架与创作分开"未入本提交。
61 lines
2.5 KiB
Python
61 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""知识确认合同的离线测试,不连接 PostgreSQL。"""
|
|
import pathlib
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
SCRIPT_DIR = pathlib.Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
|
|
import confirm_knowledge as confirm # noqa: E402
|
|
|
|
|
|
class ConfirmKnowledgeContractTest(unittest.TestCase):
|
|
def test英文实体卡投影到正式实体字段(self):
|
|
card = confirm.normalize_entity_payload({
|
|
"type": "character", "name": "林深", "brief": "机师",
|
|
"fields": {"身份": "驾驶员"},
|
|
"source": {"workId": 12, "chapter": 1, "chapterId": 17473},
|
|
"evidence": "林深坐在二号观测位。",
|
|
})
|
|
self.assertEqual(card["entity_type"], "character")
|
|
self.assertEqual(card["normalized_name"], "林深")
|
|
self.assertEqual(card["attributes"], {"身份": "驾驶员"})
|
|
self.assertEqual(card["source_ref"]["chapterId"], 17473)
|
|
|
|
def test关系端点从对象名称解析(self):
|
|
relation = confirm.normalize_relation_payload({
|
|
"type": "驾驶", "source": {"name": "林深"},
|
|
"target": {"name": "茧"}, "description": "首次实战驾驶",
|
|
})
|
|
self.assertEqual(relation["source_name"], "林深")
|
|
self.assertEqual(relation["target_name"], "茧")
|
|
self.assertEqual(relation["relation_type"], "驾驶")
|
|
|
|
def test缺失关系端点失败关闭(self):
|
|
with self.assertRaisesRegex(confirm.KnowledgeConfirmationError, "relation.target"):
|
|
confirm.normalize_relation_payload({
|
|
"type": "驾驶", "source": "林深", "description": "x",
|
|
})
|
|
|
|
def test来源回放链只追加去重结构化引用(self):
|
|
old = {"sourceRefs": [{"chapter": 1}], "lastDraftId": 10}
|
|
same = confirm._lineage(old, {"chapter": 1}, 11, "chapter_extract")
|
|
self.assertEqual(same["sourceRefs"], [{"chapter": 1}])
|
|
newer = confirm._lineage(same, {"chapter": 2}, 12, "chapter_extract")
|
|
self.assertEqual(newer["sourceRefs"], [{"chapter": 1}, {"chapter": 2}])
|
|
self.assertEqual(newer["lastDraftId"], 12)
|
|
|
|
def test已确认关系点名重试返回幂等结果(self):
|
|
row = (7, 12, "relation", {}, "confirmed", "chapter_extract", 17473, 0.9,
|
|
"active", "allowed", 2, None, 91)
|
|
result = confirm._confirm_relation_locked(None, row, kb_id=3, decided_by="1")
|
|
self.assertEqual(result, {
|
|
"draft_id": 7, "status": "already_confirmed", "relation_id": 91,
|
|
})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|