feat(datasource): 完成 M03 数据源配置与熔断巡检

交付三种引擎登记、草稿/已保存连接测试、可逆启用、每源熔断与 Cron 巡检,以及控制台页面;用户确认收尾后标 DONE_LOCAL。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
unknownandCursor committed 2026-11-18 12:50:46 +08:00
1 parent f17bf19709
commit e6d37d176d
98 files changed
+9097 -91

No files matched your search

@@ -0,0 +1,11 @@
# M03 S1 Review
- Slice: S1 数据源模型、迁移与凭证密文
- Implementer: Claude Sonnet,[实现 S1](583d05d2-27ef-4bc9-9e40-cfe28866705e)
- Independent review: Gemini,[审查 S1](70b146aa-3bea-43f9-a853-6c5d2fa25448)
- Extra read-only pass: GPT,[代码审查](ef0eaf81-b33c-4e2e-907f-047854093f95)
- Verdict: PASS_WITH_WARNINGS
- Validation reported by implementer: `uv run pytest` in `services/watchman` → 84 passed, exit 0. Alembic upgrade, downgrade to `20261117_0003`, upgrade again, exit 0. Local database left at `20261117_0004`.
- Blockers: none
- Follow-up, not an S1 defect to fix now: `updated_at` does not auto-refresh on UPDATE. Handle in S3 when rows are edited. Do not rewrite the applied migration for this.
- Residual: empty plaintext is not rejected yet (S3). Do not `model_dump()` Settings. Key loss is unrecoverable. Cross-tenant UPDATE/DELETE is covered by the same RLS policy but not a separate test.
@@ -0,0 +1,11 @@
# M03 S2 Review
- Slice: S2 三种数据库连接测试
- Implementer: Claude Sonnet,[实现 S2](577db49f-ed40-4c5e-b538-1916ce389b51)
- First review: GPT,[审查 S2](82d483cc-7add-471f-941d-5991cf93e535),BLOCKED。缺库被标成认证失败。
- Repair and re-review: Gemini,[复审 S2](930b0683-26b7-4ae7-8d0e-63eccfb00f53),PASS_WITH_WARNINGS。
- Validation: `uv run pytest` in `services/watchman` → 134 passed, exit 0. Live wrong password is `auth_failed`. Live missing database is `rejected` for PostgreSQL, MySQL, and SQL Server.
- Blocker closed: `auth_failed` requires positive evidence. Other server rejections use `rejected`.
- Warning carried forward: S3 must expose `rejected` in the API. `updated_at` still does not auto-refresh.
- SQL Server test container: `watchman-dev-sqlserver`, published on 127.0.0.1 only.
- Fernet key and test passwords are in gitignored `.env.local` only.
@@ -0,0 +1,10 @@
# M03 S3 Review
- Slice: S3 数据源 API、权限与空引用
- Implementer: Claude Sonnet,[实现 S3](072e1cac-4f7f-409a-9672-6bd23edaa96c)
- First review: GPT,[审查 S3](b8304f13-65cd-4017-9723-95b0d016babb),BLOCKED。连接参数变更后仍保留旧测试结果。
- Repair and re-review: Gemini,[复审 S3](89b2c565-07c1-421b-b6c4-7f1925a39d6f),PASS_WITH_WARNINGS。
- Validation: `uv run pytest` in `services/watchman` → 175 passed, exit 0. Reviewer re-ran the suite.
- Closed: PATCH clears `last_test_*` when engine, host, port, database, username, or password actually changes.
- Not adopted: `@app_gate` / `permission_nodes` registry / `perm_diff`. This repository has no gateway scanner. Nodes stay as constants, the same way M02 did, and D19 does not add a second registry.
- Residual: a slow probe can write its result back if the row was edited or disabled during the probe. `password: null` keeps the stored secret.
@@ -0,0 +1,8 @@
# M03 S4 Prototype Check
- Slice: S4 static HTML prototype
- Implementer: Claude Sonnet, [原型](6ef382ff-78dc-4167-ae66-a8c204db0d61)
- Files: `.task/2026-11-17/m03-datasource/prototype/index.html` and `README.md`
- Scope: no Vue, no `web/`, no API
- Checked in a browser: list, viewer role (no save/test/disable), rejected state with an empty password field and the note that a missing database is not an authentication failure. The references section is on the detail screen as “尚无引用”.
- Not approved for Vue. S5 stays blocked until the user confirms this prototype.
@@ -0,0 +1,8 @@
# M03 S5 Review
- Slice: console datasource pages, and datasource API checks limited to watchman-admin
- Implementer: Claude Sonnet, [实现 S5](d8c04bbe-bdfe-4d10-b004-2406034e1841)
- Review: GPT, [审查 S5](0413a65a-8cd3-445b-9f42-9e5e2fffab72), PASS_WITH_WARNINGS
- Warning closed after review: principal.py docstrings now say admin-only, matching the checks
- Validation reported: backend pytest 182 passed; console unit 24; typecheck; build; Playwright 17 passed, including 10 datasource specs. APIs in Playwright were mocked.
- Not DONE_LOCAL. The user has not accepted the finished module.
@@ -0,0 +1,30 @@
# Review Result
## Recommendation
PASS_WITH_WARNINGS
## Review Scope
- Task: `2026-11-17/m03-datasource`, slice `S6`
- Routing: Tier L, `gateClass: high-risk`, `risk_score: 4`; two-stage bounded re-review performed after the P1 repair.
- Reviewed the caller-provided S6 repair paths and bounded task artifacts. No forbidden `web/**` or `services/watchman/src/watchman/jobs/**` changes were reviewed.
- Supplied validation evidence: `cd services/watchman && uv run pytest` reported `232 passed, 1 warning`. This reviewer did not rerun the suite.
## Stage 1: Boundary And Compliance Review
- **P1 fixed:** `get_datasource()` now calls `_close_if_cooled_down()` before serialization, and the detail route commits the normalized state. `list_datasources()` likewise normalizes every returned row and its route commits.
- The new regression tests advance past cooldown, verify detail and ordinary-list responses return `closed` with cleared open timestamps, and verify the persisted row is closed.
- The repair remains within allowed S6 service, route, and test scope. No scheduler, frontend, credential, or other forbidden-scope behavior was introduced.
## Stage 2: Implementation Quality Review
- No blocking implementation or regression finding was identified in the bounded re-review.
## Warning
- `services/watchman/src/watchman/services/datasources.py:116-122`: `to_public()` still says an elapsed `circuit_open_until` means “the next usability check closes it.” Detail and list reads now also normalize before serialization, so this wording is stale. It does not affect runtime behavior.
## Residual Risk
- Circuit state changes on reads are intentionally persisted by the detail/list route commits. The supplied full-suite result covers the repaired paths; migration-head verification was not supplied for this re-review.
@@ -0,0 +1,36 @@
# Review Result
## Slice
S7 — Cron periodic datasource health checks
Gate class: `high-risk`; risk score: `4`
## Stage 1: Boundary And Compliance Review
No blocking findings.
- The implementation stays within the approved S7 areas: Celery Beat registration, Cron validation, health-check orchestration, settings, dependency lock, environment example, and focused tests. No `web/**` or migration file was modified for this slice.
- It uses the existing Celery Beat application and `croniter`; no second scheduler was introduced.
- Disabled, invalid-Cron, disabled-source, and open-circuit paths all no-op or skip before probing. The per-source probe rechecks usability, preserving the S6 circuit boundary.
- Failed probes update persisted test outcomes and write a credential-free audit payload. No WeCom send path is present.
- Cron validation explicitly rejects simultaneous restricted DOM/DOW fields, avoiding the known croniter (OR) versus Celery (AND) semantic mismatch. A direct Celery compatibility check also confirmed that unsupported weekday `7` is rejected rather than silently scheduled.
## Stage 2: Implementation Quality Review
No blocking findings.
- The candidate IDs are collected before network I/O and each source is committed independently, avoiding a long database transaction during probes and preventing one source failure from aborting the batch.
- Tests cover switch and invalid-Cron no-ops, enabled-and-closed selection, mid-loop disable, outcome accounting, audit secret hygiene, circuit opening, Beat registration, configuration parsing, and task execution.
## Validation Evidence
- Supplied: `cd services/watchman && uv run pytest` — `262 passed`, including 30 new S7 tests.
- Reviewed runtime compatibility: Celery rejects an unsupported `day_of_week=7`; the adapter treats it as invalid and does not register a schedule.
## Residual Risk
This remains production scheduling/configuration work (`risk_score: 4`). The test evidence is mock-probe based, so an environment-level Beat/worker/RabbitMQ execution check is still appropriate during later integration validation.
## Recommendation
PASS
@@ -0,0 +1,35 @@
# Review Result
## Slice
S8 — 控制台增补(启用/草稿测/校验/熔断配置)
## Scope And Boundary Review
- 已审阅 `web/apps/console/src/datasources/**`、四个 locale 文件、`web/apps/console/e2e/datasources.spec.ts` 和 M03 UI 证据目录;未发现 `services/watchman/**` 的 S8 改动。
- 草稿测试走 `POST /datasources/test-draft`,保存前可用;已保存测试与草稿测试分离。
- 停用/开闸状态禁用已保存测试;停用记录可直接启用,且启用不要求预先测试。
- 详情页展示并提交三个熔断参数;host 仅做非空校验,端口和熔断参数做整数范围校验。
- 编辑密码使用固定掩码,空密码不会出现在更新或草稿测试 payload;页面不使用 localStorage 保存凭证。
- 四种 locale 的 datasource 键由单测比较,未发现键集遗漏。
## Findings
### Warning — S6 契约联调尚无独立证据
`pnpm test:e2e` 的 25 个用例均使用 mocked APIs。实现与当前 S6 路由的 `test-draft`、`enable`、熔断字段和错误详情契约一致,但实施计划要求与 S6 API 联调;现有证据不能证明真实前后端组合运行。模块整体验收前应补充一次针对运行中 S6 API 的最小端到端验证,或明确记录该环境不可用。
## Validation Evidence
- Reported: `pnpm test:unit` — 7 files / 39 tests passed.
- Reported: `pnpm typecheck` — exit 0.
- Reported: `pnpm test:e2e` — 25/25 passed with mocked APIs.
- Reviewer check: scoped frontend diff passes `git diff --check`.
## Knowledge Sync
无需在本切片额外更新知识文档。熔断/usable 边界的稳定性文档同步仍按实施计划在模块验收阶段处理。
## Recommendation
PASS_WITH_WARNINGS