Skip to content

test(nightly): cover crud.photo batch_create/save_and_create/replace (2026-08-21) - #142

Open
LC044 wants to merge 4 commits into
masterfrom
nightly/test-watch-20260821
Open

test(nightly): cover crud.photo batch_create/save_and_create/replace (2026-08-21)#142
LC044 wants to merge 4 commits into
masterfrom
nightly/test-watch-20260821

Conversation

@LC044

@LC044 LC044 commented Aug 21, 2026

Copy link
Copy Markdown
Owner

What

新增 6 个单元测试覆盖 app/crud/photo.py 中覆盖率长期偏低的三个函数:

  • batch_create_photos -- file_path dedup (DB 已存在 + 批内重复) + bulk insert
  • save_and_create_photo -- file-extension -> FileType dispatch (.mp4 走 video 分支, 默认 image)
  • replace_photo_file -- 删除旧文件 + 缩略图重新生成 + 路径变更/不变两种分支

Why

2026-08-19 nightly coverage scan 显示 app/crud/photo.py 上述函数仍未被覆盖. 沿用 2026-08-17 / 2026-08-19 nightly round 的 MagicMock + patch.object 模式, 规避 SQLite pollution (memory 2026-08-19 持续问题).

How

  • pytestmark = [pytest.mark.smoke] -- 与既有 nightly 测试一致
  • crud/photo.py 中函数体内 lazy import (from app.crud.album, from app.service.task_manager) -> 在源模块上 patch (patch.multiple('app.crud.album', ...), patch('app.service.task_manager.TaskManager', fake))
  • replace_photo_file commit 后触发 TaskManager.get_instance().add_tasks 走下游副作用, 用 _patch_task_manager() stub
  • 文件 IO 用 pytest 内置 tmp_path fixture, 不依赖 data/uploads/
  • 共 6 个用例, 单文件全绿 (uv run pytest tests/unit/test_nightly_crud_photo_gaps_20260821.py -> 6 passed)

Test

`
uv run python -m pytest tests/unit/test_nightly_crud_photo_gaps_20260821.py -v

6 passed, 14 warnings in 2.80s

`

Notes

Nightly watch run 2026-08-21
Co-authored-by: Codex noreply@openai.com

LC044 and others added 2 commits August 21, 2026 08:35
…(2026-08-21)

- 新增覆盖: app.crud.photo (batch_create_photos 去重 + save_and_create_photo FileType dispatch + replace_photo_file 文件替换), 6 用例.

- 模式: MagicMock + patch.object, 零 DB / 网络依赖 (与 nightly 2026-08-17 一致, 规避 SQLite pollution).

Nightly watch run 2026-08-21

Co-authored-by: Codex <noreply@openai.com>
@LC044 LC044 added the codex-automation PRs opened by codex automation label Aug 21, 2026
@LC044

LC044 commented Aug 21, 2026

Copy link
Copy Markdown
Owner Author

Nightly watch follow-up #9b (2026-08-21 11:00 CST): 完整 E2E 300 passed / 4 skipped / 0 failed in 7m (run.log 落盘到 tests/artifacts/nightly/2026-08-21/run.log)。
un-tests.ps1 -Layer e2e -Level full\ 实际跑了 304 个用例 + 1 个 teardown = 305,未触发 §3 失败分类。本轮 §4 覆盖扫描在 test_sqlite_backend.py 附近仍触发 python teardown hang(与 2026-08-19 一致),已 kill 进程并回退到 2026-08-19 的 coverage XML 排序:\n\n- crud/photo.py (38.8%, 345 missed) — 已由 commit 58d6149 部分覆盖(batch_create/save_and_create/replace 共 6 用例),本次未继续补测\n- 下一轮首选:api/settings.py (48.2%, 282 missed) / service/face_cluster.py (53.2%, 168 missed) / api/photo.py (55.1%, 173 missed)\n- 备选方案:下一轮用 \ ests/unit/test_nightly__gaps_2026.py -k \ 跑子集后再合并 .coverage,避免 SQLite 进程污染\n\nPR #142 状态不变 (CI 11/11 SUCCESS from 01:28Z run 32210932902)。无需合入 master。

…-08-21)

- Adds 34 unit cases in package/server/tests/unit/test_nightly_api_settings_directories_gaps_20260821.py
  exercising the previously untested endpoints on app/api/settings.py:
  GET /models, POST /verify-connection, DELETE /ai-models/{model_id},
  POST /directories, DELETE /directories, GET /directories/browse,
  GET /directories/candidates, POST /directories/validate,
  POST /directories/batch, PUT /storage-root, POST /filter/apply,
  POST /map/upload, GET /map/files/{filename}.

- Rationale (2nd round on api/settings.py gap-list, follows crud/photo coverage
  on commit 58d6149): the Cobertura trace from the previous watch listed
  api/settings.py at 48.2% (282 missed). This new file targets the high-density
  miss lines with MagicMock + AsyncMock isolation (no DB, no HTTP).

Nightly watch run 2026-08-21
Co-authored-by: Codex <noreply@openai.com>
@LC044

LC044 commented Aug 21, 2026

Copy link
Copy Markdown
Owner Author

Nightly watch round 2 (2026-08-21)

  • New commit: 7283981 on top of 58d6149
  • E2E: 300 passed / 4 skipped / 0 failed (10m, full re-run on this branch)
  • New tests: 34 cases across 13 endpoints on app/api/settings.py
    (test_nightly_api_settings_directories_gaps_20260821.py):
    • GET /models, POST /verify-connection, DELETE /ai-models/{model_id}
    • POST /directories, DELETE /directories (incl. dedupe + scan-task path)
    • GET /directories/{browse,candidates}, POST /directories/{validate,batch}
    • PUT /storage-root, POST /filter/apply
    • POST /map/upload, GET /map/files/{filename}
  • Style: MagicMock + AsyncMock + SimpleNamespace, no DB or HTTP required.
    add_directory is tested for its real path (config_manager write + scan-task
    trigger) rather than the legacy gallery_service.add mock that the previous
    watch's coverage report could have led us to assume.

Decisions

  • Skipped the coverage-gap scan (§4.1) this round after last night's scan
    stalled at the same point both attempts; the new tests already cover the
    most-cited high-miss lines, so the next round will rerun §4 cleanly.
  • No regression in other settings suites; ran test_settings_api.py plus
    test_nightly_api_photo_settings_gaps_20260812.py -> 39 passed (24 existing + 15).

Follow-up gaps (queue for next round)

  • app/service/face_cluster.py 53% (168 missed)
  • app/service/task_worker.py 56% (229 missed)
  • app/service/moment/day_caption_service.py 55%
  • AI services/ticket_parser.py ~60% (carry)

Round 1 commit 58d6149 + round 2 commit 7283981 both already pushed,
this branch is nightly/test-watch-20260821, head is 7283981. CI reruns
have been triggered by the push.

🤖 generated by Codex nightly agent

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 23, 2026

Copy link
Copy Markdown

Deploying trailsnap with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6bf7dba
Status: ✅  Deploy successful!
Preview URL: https://635184a4.trailsnap-bfa.pages.dev
Branch Preview URL: https://nightly-test-watch-20260821.trailsnap-bfa.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-automation PRs opened by codex automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant