Files
unknownandCursor 21cc721fcc feat(queries): 完成 M04 查询定义与版本激活
交付不可变查询版本、保存即生效与激活(D26),并带控制台列表筛选排序与试跑预览;补 RLS 下 current_version_no 回填迁移。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 18:32:24 +08:00

169 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# M04 查询定义与采集 Implementation Plan
## Requirement Source
`.task/2026-11-18/m04-queries/requirement.md`(D24)
## Scope Summary
参数化 SQL 查询草稿、不可变版本发布、只读预览执行与控制台 UI。正式场景采集不在本轮。
## Involved Modules Or Areas
- `services/watchman`:模型、迁移、执行器、API、权限、数据源 references 回填。
- `web/apps/console`:仅 S4 确认后的查询页面。
- 不改 Casdoor 登录语义;不改熔断参数模型本身。
## Loaded Rules
- `AGENTS.md` 项目本地段;`.cursor/rules/sy-standards.mdc`
- Marionettist `gatePolicy.selected=autonomous`
## Loaded Docs
- `docs/tasks/INDEX.md` M04;交接稿 A-02;`docs/decisions.md` D14/D19/D22/D23/D24
- `docs/current/frontend-ui.md`
- M03:`assert_usable`、datasources routes/services
## Global Forbidden Scope
- 口令、连接串、加密密钥、预览全文入仓库/日志/证据。
- `.env.local`、`.cursor/mcp.json`
- 映射/规则/报警/企微/场景 Cron 正式采集
- 原型确认前的 Vue 查询页(S5 起允许)
- 生产库、`git reset --hard`、未授权自动 commit
## Execution Strategy
- Complexity: complex
- Default Execution: sequential
- Parallel Execution: not-needed
- Merge Owner: 主 Agent
## Slice Dependency Graph
| Slice | Depends On | Fallback Order | Gate Class | Risk Score |
| --- | --- | --- | --- | --- |
| S1 模型与版本 | 分析确认 | 1 | high-risk | 4 |
| S2 只读执行器 | S1 | 2 | high-risk | 4 |
| S3 API 与权限 | S1、S2 | 3 | boundary-sensitive | 4 |
| S4 HTML 原型 | S3 字段口径 | 4 | simple | 2 |
| S5 Vue 页面 | S4 用户确认 | 5 | standard | 3 |
| S6 整体验收 | S5 | 6 | boundary-sensitive | 3 |
## Implementation Slices
### Slice 1: 模型、迁移与不可变版本约束
#### Goal
平台库可按租户保存查询草稿与不可变版本;RLS 生效;版本内容更新路径在服务/测试层被拒绝。
#### Allowed Modification Scope
- `services/watchman/src/watchman/models/`
- `services/watchman/migrations/`
- `services/watchman/tests/` 本切片测试
#### Forbidden Scope
- API 路由、执行器真实连源、前端
#### Gate Class / Risk Score
high-risk / 4 — schema-migration
#### Validation
- `uv run pytest` 本切片测试;`alembic upgrade head`
#### Done Criteria
- 表与 RLS 就绪;版本行内容不可被服务辅助函数更新(测试覆盖)
### Slice 2: 只读执行器
#### Goal
对给定 SQL 模板+参数+限制在 usable 数据源上只读执行;空/非法类型/失败三分;绑定防注入。
#### Allowed Modification Scope
- `services/watchman/src/watchman/queries/`(或等价包)
- `services/watchman/src/watchman/services/` 执行相关
- 测试;必要时薄改 datasources 记账调用
#### Forbidden Scope
- 前端;发布 API 完整面
#### Gate Class / Risk Score
high-risk / 4 — device/datasource communication, injection
#### Validation
- 单元/集成:绑定、超时、行数、空结果、类型不匹配、参数含 SQL 片段不注入
### Slice 3: API、权限、引用回填
#### Goal
CRUD/启停/publish/版本/preview/references;四权限点;审计;数据源 references 列查询。
#### Allowed Modification Scope
- `api/routes/`、`auth/access.py`、`services/`、`api/app.py` 注册
- datasources `list_references` 回填
- 测试
#### Gate Class / Risk Score
boundary-sensitive / 4 — permissions, public API
#### Validation
- API 测试:权限拒绝、发布递增、版本只读、预览三分、信封
### Slice 4: HTML 原型
#### Goal
静态原型覆盖列表/编辑/版本/预览/角色门,供确认。
#### Allowed Modification Scope
- `.task/2026-11-18/m04-queries/prototype/` 仅
#### Gate Class / Risk Score
simple / 2
#### Stop
用户确认前不开始 S5。
### Slice 5: Vue 控制台
#### Goal
按确认原型与 D22 实现查询页与 e2e/单测。
#### Allowed Modification Scope
- `web/apps/console/**` 查询相关、导航、四语言、e2e
#### Gate Class / Risk Score
standard / 3
### Slice 6: 模块整体 review 与正式测试
#### Goal
独立 review、修复、pytest/unit/Playwright 证据、主 Agent 验收(DONE_LOCAL 仅用户最终确认后)。
#### Gate Class / Risk Score
boundary-sensitive / 3