Files
xiaoxia-saas/tests/unit/test_temp_dir_cleanup_race.py
xiaoxia 3af65c2743
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1m4s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 1m22s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 3m2s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m16s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 3m25s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 3m28s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 3m55s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 30s
AI Code Review / AI Code Review (pull_request) Failing after 2m48s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 34s
CI/CD Pipeline / Build Staging API Image (push) Successful in 5m7s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m53s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m1s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m9s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m17s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 7m0s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 2m27s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m26s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 12m19s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 12m24s
CI/CD Pipeline / Unit Tests (push) Successful in 14m44s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 13m38s
CI/CD Pipeline / Integration Tests (push) Successful in 5m53s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m58s
CI/CD Pipeline / CI Gate (pull_request) Successful in 6s
CI/CD Pipeline / CI Gate (push) Failing after 545h46m41s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 545h48m3s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 545h48m6s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 545h48m4s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 545h48m6s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 545h48m4s
CI/CD Pipeline / Production Browser E2E (push) Failing after 545h49m8s
CI/CD Pipeline / Build Production Web Image (push) Failing after 545h49m10s
CI/CD Pipeline / Canary Release to Production (push) Failing after 545h49m9s
CI/CD Pipeline / Build Production API Image (push) Failing after 545h49m10s
CI/CD Pipeline / Deploy Production (push) Failing after 545h49m9s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 546h0m39s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 546h0m43s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 546h0m45s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 546h1m2s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 546h1m36s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 546h1m58s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 546h3m35s
CI/CD Pipeline / PR Build API Image (push) Failing after 546h3m37s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 546h3m37s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 546h3m39s
CI/CD Pipeline / Frontend Lint (push) Failing after 546h3m48s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 546h5m2s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 546h21m58s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 546h23m2s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 546h34m34s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 546h35m27s
CI/CD Pipeline / PR Build Web Image (push) Failing after 546h37m28s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 546h37m32s
fix: 渲染产物临时目录不在render_plan中提前清理,改由调用方上传后清理 (#1484)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-08-24 21:21:00 +08:00

57 lines
2.4 KiB
Python
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.
"""回归测试:渲染产物临时目录不在 render_plan 中提前清理。
根因:render_plan 的 finally 块在返回前清理了临时目录,
但 generation.py 还需要访问其中的文件进行 OSS 上传。
修复:将清理责任交给调用方(generation.py),render_plan 只在失败时清理。
"""
import ast
def test_render_adapter_result_has_temp_dir_field():
"""RenderAdapterResult 包含 temp_dir 字段"""
with open("apps/worker/video_processing/render_adapter.py") as f:
source = f.read()
tree = ast.parse(source)
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef) and node.name == "RenderAdapterResult":
for item in node.body:
if isinstance(item, ast.AnnAssign) and isinstance(item.target, ast.Name):
if item.target.id == "temp_dir":
return
raise AssertionError("RenderAdapterResult 缺少 temp_dir 字段")
def test_render_plan_does_not_cleanup_on_success():
"""render_plan 成功时不在 finally 中清理临时目录(通过将 temp_dir 置为 None)"""
with open("apps/worker/video_processing/render_adapter.py") as f:
source = f.read()
# 成功路径必须将 temp_dir 置为 None,以阻止 finally 清理
assert "temp_dir = None" in source, "render_plan 成功时应将 temp_dir 置为 None 以阻止 finally 清理"
def test_render_plan_passes_temp_dir_to_result():
"""render_plan 将 temp_dir 传递给返回结果"""
with open("apps/worker/video_processing/render_adapter.py") as f:
source = f.read()
assert "result.temp_dir = temp_dir" in source, "render_plan 应将 temp_dir 设置到 result 上"
def test_generation_cleans_up_temp_dir():
"""generation.py 在上传完成后清理临时目录"""
with open("apps/worker/worker_app/tasks/generation.py") as f:
source = f.read()
# 验证 _render_from_edit_plan 返回 temp_dir
assert "render_temp_dir" in source, "generation.py 应接收 render_temp_dir"
# 验证有清理逻辑(shutil.rmtree(render_temp_dir...)
assert "rmtree(render_temp_dir" in source, "generation.py 应清理 render_temp_dir"
# 验证清理发生在上传之后(通过查找顺序)
upload_pos = source.find("_upload_and_record")
cleanup_pos = source.find("rmtree(render_temp_dir")
assert upload_pos > 0 and cleanup_pos > upload_pos, "清理临时目录应在 _upload_and_record 之后执行"