feat(T-003): 建立日志与运行产物目录策略

- src/paths.py: 集中管理 logs/、artifacts/ 路径与产物命名
  (artifacts/<task_id>/<时间戳>_<step>.png|.xml),_safe 安全化防路径穿越,
  运行时自动创建且被 .gitignore 忽略。
- src/logging_config.py: 统一日志格式(含 task_id/step),控制台 + logs/app.log,
  缺上下文时由 filter 补默认值,setup 幂等;约定不记录敏感信息。
- src/main.py: 启动时初始化运行目录与日志。
- 运行方式统一为 python -m src.main(绝对导入下的唯一干净入口),
  同步替换 00/03/05/current-state 文档命令与 dev.bat。
- 文档:04 §七 补 paths.py 与产物命名规则;tasks/progress/current-state 更新。

验证:compileall OK;unittest Ran 17 tests OK;python -m src.main exit=0,logs/app.log 写入正常。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
chengma
2026-06-24 17:32:28 +08:00
co-authored by Claude Opus 4.8
parent 41bc666322
commit b1e38ffd7a
13 changed files with 246 additions and 25 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ MVP 不做:
```powershell
python -m compileall src
python -m unittest discover -s tests -t .
python src/main.py
python -m src.main
```
说明:
+2 -2
View File
@@ -38,7 +38,7 @@
| 创建虚拟环境 | `python -m venv .venv` |
| 激活虚拟环境 | `.venv\Scripts\Activate.ps1` |
| 安装依赖 | `pip install -r requirements.txt` |
| 本地运行 | `python src/main.py` |
| 本地运行 | `python -m src.main` |
| 测试 | `python -m unittest discover -s tests -t .` |
| 语法检查 | `python -m compileall src` |
| 打包(待 T-402) | `pyinstaller app.spec` |
@@ -49,7 +49,7 @@ Windows PowerShell:
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python src/main.py
python -m src.main
python -m unittest discover -s tests -t .
```
+6 -3
View File
@@ -324,7 +324,8 @@ cmpdd/
│ ├── android/
│ │ ├── device.py
│ │ └── pdd_flow.py
│ └── logging_config.py
│ ├── logging_config.py
│ └── paths.py
├── tests/
├── samples/
├── logs/
@@ -337,8 +338,10 @@ cmpdd/
- `src/core/`:任务模型、状态机、执行编排。
- `src/excel/`:Excel 导入、校验、回写。
- `src/android/`:设备连接、拼多多 App 自动化流程。
- `logs/`:本地运行日志,默认不提交真实敏感日志。
- `artifacts/`:截图、UI XML、结果文件等运行产物,默认不提交真实数据。
- `src/logging_config.py`:统一日志格式(含 `task_id`、`step`),输出到控制台与 `logs/app.log`;不记录敏感信息。
- `src/paths.py`:集中管理运行时路径与产物命名;截图与 UI XML 按 `artifacts/<task_id>/<时间戳>_<step>.png|.xml` 归档,`task_id`/`step` 入路径前安全化以防穿越。
- `logs/`:本地运行日志(`app.log`),运行时自动创建并被 `.gitignore` 忽略,不提交真实敏感日志。
- `artifacts/`:截图、UI XML、结果文件等运行产物,运行时自动创建并被 `.gitignore` 忽略,不提交真实数据。
- `samples/`:脱敏样例 Excel。
## 八、架构纪律
+1 -1
View File
@@ -78,7 +78,7 @@
```powershell
python -m compileall src
python -m unittest discover -s tests -t .
python src/main.py
python -m src.main
```
## 8. 绝不
+10 -10
View File
@@ -7,10 +7,10 @@
## 当前快照
- 日期:2026-06-24
- 阶段:Phase 0 地基(T-001、T-002 完成)/ 原型验证前
- 阶段:Phase 0 地基(T-001、T-002、T-003 完成)/ 进入 Phase 1 原型验证
- 技术栈:Python 3.10(骨架已跑通);计划接入 PySide6 + `uiautomator2` + ADB + `openpyxl`
- 生产代码:骨架 + 核心数据模型(`src/main.py` 入口、`src/core/` 状态枚举与任务模型)
- 测试:标准库 `unittest`,覆盖冒烟与核心模型(`tests/test_smoke.py`、`tests/test_models.py`)
- 生产代码:骨架 + 核心数据模型 + 运行时基建(`src/main.py` 入口、`src/core/` 模型与状态、`src/logging_config.py` 日志、`src/paths.py` 产物路径)
- 测试:标准库 `unittest`,覆盖冒烟、核心模型、日志与产物路径(`tests/` 下 4 个测试文件)
- 数据:尚未提供真实 Excel 样例
## 当前目录要点
@@ -18,20 +18,20 @@
| 路径 | 状态 | 说明 |
| --- | --- | --- |
| `docs/` | 已有 | 项目规范化文档,已按 harness coding 文档风格建立。 |
| `src/` | 已有 | `main.py` 入口 + `core/`(`status.py` 状态枚举、`models.py` 任务模型);GUI/执行器/Excel/Android 模块后续添加。 |
| `tests/` | 已有 | 已建冒烟测试 `tests/test_smoke.py`(unittest)。 |
| `src/` | 已有 | `main.py` 入口 + `core/`(状态枚举、任务模型)+ `logging_config.py`、`paths.py`;GUI/执行器/Excel/Android 模块后续添加。 |
| `tests/` | 已有 | `test_smoke`、`test_models`、`test_paths`、`test_logging`(unittest)。 |
| `requirements.txt` | 已有 | 依赖清单;当前零第三方运行时依赖,含依赖纪律注释。 |
| `samples/` | 待建 | 脱敏 Excel 样例。 |
| `logs/` | 待建 | 本地运行日志。 |
| `artifacts/` | 待建 | 截图、UI XML、结果文件等运行产物。 |
| `logs/` | 运行时创建 | `app.log` 运行日志;被 `.gitignore` 忽略。 |
| `artifacts/` | 运行时创建 | 截图、UI XML 等运行产物;被 `.gitignore` 忽略。 |
## 任务与进度状态
任务定义以 [`../tasks.md`](../tasks.md) 为准,执行记录以 [`../progress.md`](../progress.md) 为准。
- 已完成:项目文档初始化;`T-001 初始化 Python 项目骨架`;`T-002 建立核心数据模型和状态枚举`。
- 已完成:项目文档初始化;`T-001`、`T-002`、`T-003`(Phase 0 地基全部完成)。
- 正在进行:无。
- 下一个可领取任务:`T-003 建立日志和运行产物目录策略`。
- 下一个可领取任务:`T-101 验证 ADB 和 uiautomator2 真机连接`(Phase 1,需真机环境)。
## 当前可运行内容
@@ -39,7 +39,7 @@
```powershell
# 本地运行入口
python src/main.py
python -m src.main
# 测试
python -m unittest discover -s tests -t .