feat: 安全应用采购规格解析结果 (#257)

This commit is contained in:
chengma
2026-08-17 17:43:25 +08:00
parent 484ce4e8ec
commit afc1cdf719
19 changed files with 1669 additions and 24 deletions
+54
View File
@@ -114,6 +114,60 @@ class TaskRepositoryTests(unittest.TestCase):
self.assertEqual(detail.admin_payload["task_id"], "TASK-001")
self.assertEqual(detail.pdd_data["schema_version"], 1)
def test_purchase_spec_resolution_request_is_persisted_before_response(self):
self.repository.add_claimed_task(
self._task("PUR-SPEC", TaskType.PURCHASE)
)
started = self.repository.start_purchase_run("PUR-SPEC", "USB-001")
request = {
"schema_version": 1,
"candidate_snapshot_hash": "a" * 64,
"candidates": [{"candidate_id": "c1", "raw_text": "L"}],
}
first = self.repository.prepare_purchase_spec_resolution(
"PUR-SPEC", started.attempt_id, "spec-resolution-v1:key", request
)
second = self.repository.prepare_purchase_spec_resolution(
"PUR-SPEC", started.attempt_id, "spec-resolution-v1:key", request
)
self.assertEqual(first.id, second.id)
self.assertEqual(first.status, "pending")
self.assertEqual(first.request_json, request)
saved = self.repository.save_purchase_spec_resolution(
first.id,
{
"resolution_id": "psr-001",
"outcome": "matched",
"source": "rule",
"confidence_bps": 10000,
"match": {
"candidate_id": "c1",
"raw_text": "L",
"options": {"color": "黑色", "size": "L"},
},
"reason": "唯一匹配",
"resolved_at": "2026-08-17T08:00:01Z",
},
)
self.assertEqual(saved.status, "resolved")
self.assertEqual(saved.resolution_id, "psr-001")
self.assertEqual(saved.match_options["size"], "L")
with self.assertRaisesRegex(ValueError, "不同响应"):
self.repository.save_purchase_spec_resolution(
first.id,
{
"resolution_id": "psr-other",
"outcome": "rejected",
"source": None,
"confidence_bps": None,
"match": None,
"reason": "内容变化",
"resolved_at": "2026-08-17T08:00:02Z",
},
)
def test_live_mode_and_irreversible_marker_are_persisted_once(self) -> None:
self.repository.add_claimed_task(
self._task(