feat(risk): Enhance risk management functionality and access control

- Updated `RiskListAccess` and `ThresholdWriteAccess` to enforce access control in the risk repository and threshold repository, ensuring only authorized roles can perform sensitive operations.
- Introduced new methods in `RiskRepository` for counting pending alerts and listing alerts with access checks, improving data security and compliance.
- Enhanced the `chat.py` and `deps.py` files to integrate compliance roles into the risk management matrix, allowing for more granular access control.
- Updated documentation to reflect the new testing baseline of 825 passed tests, indicating improved stability and functionality across the application.

This update significantly strengthens the risk management capabilities, ensuring robust access control and compliance with organizational policies.
This commit is contained in:
2026-09-11 17:07:22 +08:00
parent 8556da489a
commit 793c0307f8
46 changed files with 1308 additions and 122 deletions
@@ -15,7 +15,7 @@
| S2 接缝 | `auth_adapter.module_auth_from_host()` 已接线 |
| trace 中间件 | ApiError / AppError / PermissionDenied / RequestValidationError / StarletteHTTPException **re-raise**;仅未捕获 → 500 |
| 边界测试 | `tests/test_module_boundary.py` 全绿(宿主 D 类文件排除跨层扫描) |
| 测试基线 | **`python -m pytest` → 530 passed, 0 skipped** |
| 测试基线 | **`python -m pytest` → 530 passed, 0 skipped**(AL-09 当时快照)· **当前 merger 全量见 `docs/memory/MEMORY.md` §0(825)** |
**架构结论:** 宿主 `gateway/` 与模块 `deps.py` **双栈并存**;对外 token 统一;模块 API 禁止 import `app/gateway/`。
@@ -66,8 +66,8 @@
| A-15 | 智能看数板后端接口 | D-12 | `/api/analyst/dashboard` | 按角色出卡片、钻取进对话 | A-04 | ⬜ |
| A-16 | 指标消歧反问 | N-01 | `analyst_agent` ambiguity 节点 | 多义词先反问,澄清后口径一致 | A-08 | ⬜ |
| A-17 | 空/零/不命中三态区分 | N-02 | `sql_tool` | 三种空态分别准确说明 | A-03 | ⬜ |
| A-18 | 聚合抽样明细溯源 | N-03 | `/api/analyst/query/{trace_id}/sample` | 明细与聚合一致 | A-07 | ⬜ |
| A-19 | 转人工兜底 | N-07 | `/api/analyst/escalate` | 失败场景一键转人工、留痕可还原 | A-07 | ⬜ |
| A-18 | 聚合抽样明细溯源 | N-03 | `/api/analyst/query/{trace_id}/sample` | 明细与聚合一致 | A-07 | ✅ 2026-09-11 |
| A-19 | 转人工兜底 | N-07 | `/api/analyst/escalate` | 失败场景一键转人工、留痕可还原 | A-07 | ✅ 2026-09-11 |
**阶段 3 验收**:D-10 造错用例被拦;D-11 沉淀生效;D-12 卡片钻取;N-01/02/03/07 各跑通。
@@ -548,7 +548,7 @@ CREATE TABLE analytics_query_template (
| Wave 0(平台) | JWT/RBAC(T-01)、审计贯通(T-02)、agent 库灌库(T-05) | 未做(复用,非分析组) |
| Wave 1-A(P0 闭环) | `analytics_query_log` + `sql_guard` + `analyst_agent` 主链路 → D-01~D-04 闭环 | 未做 |
| Wave 1-B(P0 增强) | 口径字典(D-07)、缓存+记忆(D-06)、追问改写(D-09)、数字护栏(D-10) | 未做 |
| Wave 1-C(P0 亮点) | 养 Agent 资产沉淀(D-11)、智能看数板后端(D-12)、消歧(N-01)、空零(N-02)、溯源(N-03)、转人工(N-07) | 未做 |
| Wave 1-C(P0 亮点) | 养 Agent 资产沉淀(D-11)、智能看数板后端(D-12)、消歧(N-01)、空零(N-02)、溯源(N-03)、转人工(N-07) | **N-03/N-07 已做**;D-12 未做 |
| Wave 2(P1) | 配额(N-04)、保存/分享/订阅(N-05)、质量提示(N-06)、运营面板(N-08) | 未做 |
> 已有实现:`CoreReadOnlyRepository`(只读 SELECT)、`settings` 双库、Core 模拟库脚本、`customer_advisor_rel` 同步脚本。分析 Agent 业务层尚未实现。
@@ -36,7 +36,7 @@
| `app/gateway/trade_gateway.py` | 交易网关(C6 需透传 actor_id) |
| `app/model/suitability.py` | 适当性落库行构造(AL-04 引入,与 main 同名 → **冲突时以模块版为准**) |
| `scripts/demo/*`、`scripts/core/*` | 演示与 Core 种子脚本 |
| `tests/`(除 test_module_boundary 外) | 模块测试;**AL-09 后全量基线 530 passed 0 skipped** |
| `tests/`(除 test_module_boundary 外) | 模块测试;**AL-09 当时 530 passed** · **当前全量基线见 MEMORY §0** |
### 1.2 B 类 · 模块私有基建(与宿主同类但模块内自用,**允许与 main 并存**)