feat: add guarded knowledge publication tool

This commit is contained in:
张胜宇
2026-09-10 22:08:15 +08:00
parent 24f75636a0
commit bc2f521c2e
4 changed files with 598 additions and 0 deletions
@@ -0,0 +1,40 @@
import pytest
from tools.publish_customer_service_knowledge import load_pending_manifest
def manifest() -> dict[str, object]:
return {
"summary": {"eligible_records": 1, "publication_state": "pending_review"},
"records": [{
"qa_id": "FAQ-001",
"milvus_collection": "fin_faq_collection",
"retrieval_text": "标准问题:基金开户",
"title": "基金开户",
"snippet": "基金开户",
"tags": ["开户"],
"version": "v5.8",
"content_text": "{\"answer\":\"请在官方页面开户。\"}",
"source_file": "qa-v5.8.txt",
"effective_date": None,
"expire_date": None,
"review_status": "pending_review",
"status": "active",
}],
}
def test_pending_manifest_is_converted_to_a_publishable_administrator_payload() -> None:
records = load_pending_manifest(manifest())
assert len(records) == 1
assert records[0].qa_id == "FAQ-001"
assert records[0].metadata["content_text"] == "{\"answer\":\"请在官方页面开户。\"}"
def test_manifest_that_claims_to_be_published_is_rejected() -> None:
invalid = manifest()
invalid["summary"] = {"eligible_records": 1, "publication_state": "published"}
with pytest.raises(ValueError, match="pending_review"):
load_pending_manifest(invalid)