[阶段4] 删除 shim(旧路径 re-export 全部清掉) #31

Closed
opened 2026-08-21 13:39:40 +08:00 by tao.chen · 1 comment
Owner

范围(L1 风险)

所有测试和 main.py 已切到新 import 后,删除旧路径 shim 文件。

验收

  • grep -r "from backend\\.\\(scripts\\|resources\\|auth\\|jupyter\\|platform\\|admin\\|schedules\\|schedule_runs\\|runtime_client\\|rclone_rc_client\\|schedule_client\\|schedule_schemas\\|schemas\\|storage_api\\|dependencies\\|audit\\)" backend/ 全部 0 命中
  • 删 shim 后 pytest backend/tests -q 全绿
  • compileall 无错

Task: crzkkz9si8d3p2loxi70j443

## 范围(L1 风险) 所有测试和 main.py 已切到新 import 后,删除旧路径 shim 文件。 ## 验收 - [ ] `grep -r "from backend\\.\\(scripts\\|resources\\|auth\\|jupyter\\|platform\\|admin\\|schedules\\|schedule_runs\\|runtime_client\\|rclone_rc_client\\|schedule_client\\|schedule_schemas\\|schemas\\|storage_api\\|dependencies\\|audit\\)" backend/` 全部 0 命中 - [ ] 删 shim 后 `pytest backend/tests -q` 全绿 - [ ] `compileall` 无错 --- <sub>Task: crzkkz9si8d3p2loxi70j443</sub>
tao.chen added the priority:lowstatus:to-do labels 2026-08-21 13:39:43 +08:00
tao.chen added status:done and removed status:to-do labels 2026-08-21 15:27:13 +08:00
Author
Owner

tao.chen commented:

阶段4 完成:shim 全部删除,测试 import 统一到新路径,父任务 #48 整体 done。

Shim 删除清单(14 个平铺 shim + 1 个 schemas/__init__.py)

  • backend/src/backend/{admin,auth,dependencies,jupyter,platform,rclone_rc_client,resources,runtime_client,schedule_client,schedule_runs,schedule_schemas,schedules,scripts,storage_api}.py
  • backend/src/backend/schemas/__init__.py

保留

  • audit.py — 实际代码(main.py 引用 backend.audit.configure_audit_logging
  • main.py — 应用入口
  • __init__.py — 包标记

测试 import 迁移(5 个 test 文件)

  • test_list_scripts_parent_path.pybackend.scripts.*backend.api.scripts.*(6 处)
  • test_count_scripts.py — 同上(2 处)
  • test_scripts.pybackend.scripts.* / backend.resources.* / backend.jupyter.* / backend.schemas.UpdateScriptRequest(11 处)
  • test_resources.pybackend.resources.*(12 处)
  • test_runtime_client_directories.pybackend.runtime_client.*backend.clients.runtime.*(1 处)

按 CLAUDE.md "Mock patch() string targets... rewrite every hit" 教训,所有 monkeypatch.setattr 字符串参数已在阶段1迁到 backend.api.scripts.*;本次阶段4没再改它们。

最终结构

backend/src/backend/
├── __init__.py
├── audit.py
├── main.py
├── api/
│   ├── admin.py, auth.py, dependencies.py, jupyter.py, platform.py
│   ├── resources.py, scripts.py, storage.py
│   └── schedules/{schedules.py, runs.py}
├── schemas/
│   ├── auth.py, common.py, jupyter.py, platform.py
│   ├── resources.py, schedules.py, scripts.py
├── services/
│   └── storage.py, schedules.py(已下沉 validate_dag)
├── clients/
│   └── rclone.py, runtime.py, scheduler.py

验证

  • uv run python -m compileall backend/src backend/tests 零错误
  • uv run --package backend pytest backend/tests -q122 passed
  • grep -r 'from backend\.\(scripts\|resources\|...\)' backend/ 0 命中
  • 阶段3下沉的 validate_dag 服务路径 backend.services.schedules.validate_dag 仍被 8 个新 unit test 覆盖

最终迁移摘要

阶段 任务 测试通过
1 纯位置迁移 + shim 114
2 APIRouter prefix 收口 114
3 validate_dag 下沉到 services/ 122 (+8)
4 删 shim + 统一 import 122

遗留

  • 工作树未提交(按 CLAUDE.md "Commit or push only when the user asks")
  • 后续 candidates: cron_preview / validate_script_content / compute_jupyter_relative_path / can_view 等下沉 task 可开新 PR
**tao.chen** commented: > 阶段4 完成:shim 全部删除,测试 import 统一到新路径,父任务 #48 整体 done。 **Shim 删除清单**(14 个平铺 shim + 1 个 schemas/__init__.py) - `backend/src/backend/{admin,auth,dependencies,jupyter,platform,rclone_rc_client,resources,runtime_client,schedule_client,schedule_runs,schedule_schemas,schedules,scripts,storage_api}.py` - `backend/src/backend/schemas/__init__.py` **保留** - `audit.py` — 实际代码(main.py 引用 `backend.audit.configure_audit_logging`) - `main.py` — 应用入口 - `__init__.py` — 包标记 **测试 import 迁移**(5 个 test 文件) - `test_list_scripts_parent_path.py` — `backend.scripts.*` → `backend.api.scripts.*`(6 处) - `test_count_scripts.py` — 同上(2 处) - `test_scripts.py` — `backend.scripts.*` / `backend.resources.*` / `backend.jupyter.*` / `backend.schemas.UpdateScriptRequest`(11 处) - `test_resources.py` — `backend.resources.*`(12 处) - `test_runtime_client_directories.py` — `backend.runtime_client.*` → `backend.clients.runtime.*`(1 处) 按 CLAUDE.md "Mock patch() string targets... rewrite every hit" 教训,所有 `monkeypatch.setattr` 字符串参数已在阶段1迁到 `backend.api.scripts.*`;本次阶段4没再改它们。 **最终结构** ```text backend/src/backend/ ├── __init__.py ├── audit.py ├── main.py ├── api/ │ ├── admin.py, auth.py, dependencies.py, jupyter.py, platform.py │ ├── resources.py, scripts.py, storage.py │ └── schedules/{schedules.py, runs.py} ├── schemas/ │ ├── auth.py, common.py, jupyter.py, platform.py │ ├── resources.py, schedules.py, scripts.py ├── services/ │ └── storage.py, schedules.py(已下沉 validate_dag) ├── clients/ │ └── rclone.py, runtime.py, scheduler.py ``` **验证** - `uv run python -m compileall backend/src backend/tests` 零错误 - `uv run --package backend pytest backend/tests -q` → **122 passed** - `grep -r 'from backend\.\(scripts\|resources\|...\)' backend/` **0 命中** - 阶段3下沉的 validate_dag 服务路径 `backend.services.schedules.validate_dag` 仍被 8 个新 unit test 覆盖 **最终迁移摘要** | 阶段 | 任务 | 测试通过 | | --- | --- | --- | | 1 | 纯位置迁移 + shim | 114 | | 2 | APIRouter prefix 收口 | 114 | | 3 | validate_dag 下沉到 services/ | 122 (+8) | | 4 | 删 shim + 统一 import | 122 | **遗留** - 工作树未提交(按 CLAUDE.md "Commit or push only when the user asks") - 后续 candidates: `cron_preview` / `validate_script_content` / `compute_jupyter_relative_path` / `can_view` 等下沉 task 可开新 PR
tao.chen added status:archived and removed status:done labels 2026-08-24 10:09:10 +08:00
tao.chen reopened this issue 2026-08-24 10:09:17 +08:00
tao.chen added the status:in-review label 2026-08-24 14:21:57 +08:00
tao.chen removed the status:in-review label 2026-08-24 14:25:18 +08:00
tao.chen reopened this issue 2026-08-24 14:25:35 +08:00
tao.chen added the status:to-do label 2026-08-24 14:25:52 +08:00
tao.chen added status:done and removed status:to-do labels 2026-08-24 14:49:55 +08:00
tao.chen removed the status:done label 2026-08-24 14:50:15 +08:00
tao.chen reopened this issue 2026-08-24 14:50:18 +08:00
tao.chen added the status:done label 2026-08-24 14:50:22 +08:00
Sign in to join this conversation.