feat(flywheel): 新增 GoldenCase 模型用于规则回归门禁
- 新增 golden_cases 表,承载版本化的风险规则黄金用例 (case_key/rule_code/values_json/expected_hit/expected_severity/status) - 注册到 db/base.py 和 models/__init__.py,进入 Base.metadata
This commit is contained in:
@@ -21,6 +21,7 @@ from app.models.financial_record import (
|
|||||||
ExpenseClaim,
|
ExpenseClaim,
|
||||||
ExpenseClaimItem,
|
ExpenseClaimItem,
|
||||||
)
|
)
|
||||||
|
from app.models.golden_case import GoldenCase
|
||||||
from app.models.hermes_config import HermesTaskConfig, HermesTaskExecutionLog
|
from app.models.hermes_config import HermesTaskConfig, HermesTaskExecutionLog
|
||||||
from app.models.hermes_report import HermesRiskReport
|
from app.models.hermes_report import HermesRiskReport
|
||||||
from app.models.notification_state import NotificationState
|
from app.models.notification_state import NotificationState
|
||||||
@@ -58,6 +59,7 @@ __all__ = [
|
|||||||
"EmployeeChangeLog",
|
"EmployeeChangeLog",
|
||||||
"ExpenseClaim",
|
"ExpenseClaim",
|
||||||
"ExpenseClaimItem",
|
"ExpenseClaimItem",
|
||||||
|
"GoldenCase",
|
||||||
"HermesTaskConfig",
|
"HermesTaskConfig",
|
||||||
"HermesTaskExecutionLog",
|
"HermesTaskExecutionLog",
|
||||||
"HermesRiskReport",
|
"HermesRiskReport",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from app.models.financial_record import (
|
|||||||
ExpenseClaim,
|
ExpenseClaim,
|
||||||
ExpenseClaimItem,
|
ExpenseClaimItem,
|
||||||
)
|
)
|
||||||
|
from app.models.golden_case import GoldenCase
|
||||||
from app.models.hermes_config import HermesTaskConfig, HermesTaskExecutionLog
|
from app.models.hermes_config import HermesTaskConfig, HermesTaskExecutionLog
|
||||||
from app.models.hermes_report import HermesRiskReport
|
from app.models.hermes_report import HermesRiskReport
|
||||||
from app.models.notification_state import NotificationState
|
from app.models.notification_state import NotificationState
|
||||||
@@ -49,6 +50,7 @@ __all__ = [
|
|||||||
"EmployeeChangeLog",
|
"EmployeeChangeLog",
|
||||||
"ExpenseClaim",
|
"ExpenseClaim",
|
||||||
"ExpenseClaimItem",
|
"ExpenseClaimItem",
|
||||||
|
"GoldenCase",
|
||||||
"HermesTaskConfig",
|
"HermesTaskConfig",
|
||||||
"HermesTaskExecutionLog",
|
"HermesTaskExecutionLog",
|
||||||
"HermesRiskReport",
|
"HermesRiskReport",
|
||||||
|
|||||||
48
server/src/app/models/golden_case.py
Normal file
48
server/src/app/models/golden_case.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from sqlalchemy import Boolean, DateTime, Index, String, Text, func
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
from sqlalchemy.types import JSON
|
||||||
|
|
||||||
|
from app.db.base_class import Base
|
||||||
|
|
||||||
|
|
||||||
|
class GoldenCase(Base):
|
||||||
|
"""风险规则回归门禁用的黄金用例。
|
||||||
|
|
||||||
|
由运营手动维护(或从已确认风险观测导入),在规则发布前作为回归集执行,
|
||||||
|
100% 通过才放行。``values_json`` 复用 ``AgentAssetRiskRuleSampleCase.values``
|
||||||
|
的扁平字典格式,``expected_hit`` / ``expected_severity`` 作为 ground truth。
|
||||||
|
"""
|
||||||
|
|
||||||
|
__tablename__ = "golden_cases"
|
||||||
|
__table_args__ = (
|
||||||
|
Index("ix_golden_cases_rule_code_status", "rule_code", "status"),
|
||||||
|
Index("ix_golden_cases_scene_status", "scene", "status"),
|
||||||
|
)
|
||||||
|
|
||||||
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||||
|
case_key: Mapped[str] = mapped_column(String(160), unique=True, index=True)
|
||||||
|
rule_code: Mapped[str | None] = mapped_column(String(120), nullable=True, index=True)
|
||||||
|
scene: Mapped[str] = mapped_column(String(50), default="", index=True)
|
||||||
|
|
||||||
|
name: Mapped[str] = mapped_column(String(120), default="")
|
||||||
|
values_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
|
||||||
|
expected_hit: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||||
|
expected_severity: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
||||||
|
note: Mapped[str | None] = mapped_column(Text(), nullable=True)
|
||||||
|
|
||||||
|
status: Mapped[str] = mapped_column(String(20), default="active", index=True)
|
||||||
|
source: Mapped[str] = mapped_column(String(30), default="manual")
|
||||||
|
|
||||||
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now(), server_default=func.now())
|
||||||
|
updated_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime,
|
||||||
|
default=func.now(),
|
||||||
|
onupdate=func.now(),
|
||||||
|
server_default=func.now(),
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user