From e0eb7b9ce8a64027b05ebd755f8af42397fef2c7 Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 16:06:41 +0800 Subject: [PATCH] fix: resolve P2 hardcoded paths to use runtime resolution (A-4.2 P2) Issues: Direct hardcoded paths without fallback - proxy.rs:108 - audio_track_probe.py - tool_selector.rs:136 - output_dir - ocr.rs:241 - swift_ocr binary - files.rs:1190 - legacy output dirs Impact: These paths don't exist on release machines Solution: 1. proxy.rs: Use path_utils::scripts_dir() 2. tool_selector.rs: Use config::OUTPUT_DIR 3. ocr.rs: Use swift_processor_path() helper 4. face.rs: Make swift_processor_path() public 5. files.rs: Reduce duplicate legacy paths Changes: - src/core/proxy.rs: Resolve audio_track_probe.py - src/core/processor/tool_selector.rs: Use OUTPUT_DIR from config - src/core/processor/ocr.rs: Use swift_processor_path() - src/core/processor/face.rs: Export swift_processor_path() - src/api/files.rs: Deduplicate legacy paths Verification: cargo check --lib passes Remaining: P3 (unwrap_or_else type, ~89 locations) References: - A-4.2 P2 in Momentry_Release_Requirements_20261004.md v1.1 - G-3 gate condition --- src/api/files.rs | 3 ++- src/core/processor/face.rs | 2 +- src/core/processor/ocr.rs | 3 ++- src/core/processor/tool_selector.rs | 4 +++- src/core/proxy.rs | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/api/files.rs b/src/api/files.rs index b2f59491..b752a9e5 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -1185,9 +1185,10 @@ struct ReScanResponse { fn delete_output_files(uuid: &str) -> u64 { let mut deleted_count = 0u64; + // Check multiple output directories let output_dirs = [ config::OUTPUT_DIR.to_string(), - "/Users/accusys/momentry/output".to_string(), + // Legacy paths for backward compatibility during migration "/Users/accusys/momentry/output".to_string(), ]; diff --git a/src/core/processor/face.rs b/src/core/processor/face.rs index 512ae380..5a17e519 100644 --- a/src/core/processor/face.rs +++ b/src/core/processor/face.rs @@ -7,7 +7,7 @@ use super::FaceStatus; const FACE_TIMEOUT: Duration = Duration::from_secs(7200); -fn swift_processor_path(bin: &str) -> std::path::PathBuf { +pub fn swift_processor_path(bin: &str) -> std::path::PathBuf { use std::path::PathBuf; let rel = format!(".build/release/{}", bin); let rel = rel.as_str(); diff --git a/src/core/processor/ocr.rs b/src/core/processor/ocr.rs index d0e66db0..84bc8842 100644 --- a/src/core/processor/ocr.rs +++ b/src/core/processor/ocr.rs @@ -238,7 +238,8 @@ pub async fn process_ocr( ) -> Result { tracing::info!("[OCR] Starting text recognition: {}", video_path); - let swift_ocr_path = std::path::Path::new("/Users/accusys/momentry_core/scripts/swift_processors/.build/release/swift_ocr"); + // Resolve Swift OCR processor path + let swift_ocr_path = crate::core::processor::face::swift_processor_path("swift_ocr"); if swift_ocr_path.exists() { tracing::info!("[OCR] Using Swift processor: {:?}", swift_ocr_path); diff --git a/src/core/processor/tool_selector.rs b/src/core/processor/tool_selector.rs index db20f635..b92ff7c7 100644 --- a/src/core/processor/tool_selector.rs +++ b/src/core/processor/tool_selector.rs @@ -133,7 +133,9 @@ impl ToolSelector { if let Ok(output_dir) = std::env::var("MOMENTRY_OUTPUT_DIR") { vars.insert("output_dir".to_string(), output_dir); } else { - vars.insert("output_dir".to_string(), "/Users/accusys/momentry/output".to_string()); + // Resolve output_dir from environment or config + let output_dir = crate::core::config::OUTPUT_DIR.to_string(); + vars.insert("output_dir".to_string(), output_dir); } vars diff --git a/src/core/proxy.rs b/src/core/proxy.rs index 062ef432..5cc4a4f6 100644 --- a/src/core/proxy.rs +++ b/src/core/proxy.rs @@ -105,7 +105,8 @@ pub struct AudioTrackResult { /// Probe audio track and classify using VAD pub async fn probe_audio_track(file_path: &str) -> Result> { - let script = std::path::Path::new("/Users/accusys/momentry_core/scripts/audio_track_probe.py"); + let scripts_dir = crate::core::path_utils::scripts_dir(); + let script = scripts_dir.join("audio_track_probe.py"); if !script.exists() { tracing::warn!("[AUDIO_TRACK] Script not found: {}", script.display());