fix: integrate phase_completed into status logic (A-9)

Issue: phase_completed was calculated but never used
File: src/api/files.rs:1982

Root cause:
- phase_completed = (phase == "COMPLETED")
- But new_status only checked all_consistent and any_json_exists
- This caused inconsistency between DB phase and reported status

Solution:
- Add phase_completed as highest priority condition
- If phase is COMPLETED and any_json_exists → status = completed
- This ensures DB phase is respected when available

Logic:
1. phase_completed + any_json_exists → completed (trust DB)
2. all_consistent + any_json_exists → completed (all JSONs ready)
3. any_json_exists → scanning (in progress)
4. no JSONs → registered (not started)

Benefits:
- Fixes G-1 gate condition
- Resolves potential inconsistency between phase and status
- Matches original design intent

Verification: cargo check --lib passes

References:
- A-9 in Momentry_Release_Requirements_20261004.md v1.1
- G-1 in M5Max128_Portability_Install_Test_20261004.md
This commit is contained in:
Accusys
2026-10-04 15:55:04 +08:00
parent 1ca3eb1abe
commit ad30742374
+8 -3
View File
@@ -1982,13 +1982,18 @@ async fn sync_file_status(
let phase_completed = phase == "COMPLETED";
// 狀態判斷
let new_status = if all_consistent && any_json_exists {
// Priority: phase completed > all_consistent > any_json_exists
let new_status = if phase_completed && any_json_exists {
// Phase marked completed in DB → trust it
"completed"
} else if all_consistent && any_json_exists {
// All processor JSONs consistent → completed
"completed"
} else if any_json_exists {
// 部分 JSON 存在或不一致 → 入庫中
// Some JSONs exist but incomplete or inconsistent → scanning
"scanning"
} else {
// 無 JSON → 未開始
// No JSONs → not started
"registered"
};