From 7ffb45c137fd8c74ac4f160d503ebe44796f2ee3 Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 20:40:27 +0800 Subject: [PATCH] fix: remove final 3 hardcoded paths for D-4 compliance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final cleanup: 1. main.rs:35 - Remove hardcoded .env fallback - Rationale: L30-34 already provide correct current_exe() resolution - Removes dev path, aligns with A-14.3 "禁止读取 dev 设定" 2. docs.rs:11,24 - Use current_exe() resolution - Replace hardcoded doc_wasm paths - Add MOMENTRY_DOCS_DIR env var support - Fallback to relative path Result: - All hardcoded dev paths removed from release binary - D-4 Gate satisfied - Zero momentry_core/nextorageai paths in source Impact: - Binary fully portable - No dev environment assumptions - All paths runtime-resolved --- src/api/docs.rs | 9 ++++++++- src/main.rs | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api/docs.rs b/src/api/docs.rs index bbf55ca4..dbf421e4 100644 --- a/src/api/docs.rs +++ b/src/api/docs.rs @@ -21,7 +21,14 @@ async fn wasm_doc_file_handler( if file.contains("..") || file.contains("//") { return Err((StatusCode::NOT_FOUND, "Invalid path")); } - let base = std::path::Path::new("/Users/accusys/momentry_core/docs_v1.0/doc_wasm"); + let base_str = std::env::var("MOMENTRY_DOCS_DIR") + .unwrap_or_else(|_| { + std::env::current_exe() + .ok() + .and_then(|p| p.parent().map(|d| d.join("docs_v1.0/doc_wasm").to_string_lossy().to_string())) + .unwrap_or_else(|| "docs_v1.0/doc_wasm".to_string()) + }); + let base = std::path::Path::new(&base_str); let path = base.join(&file); if !path.exists() || !path.starts_with(base) { return Err((StatusCode::NOT_FOUND, "File not found")); diff --git a/src/main.rs b/src/main.rs index 8ef88585..055ec58f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ fn init_tracing() { fn load_env() { // Resolve .env at runtime so the binary is portable across machines. - // Order: MOMENTRY_ENV_FILE -> ./.env -> /../../.env -> legacy M5 path. + // Order: MOMENTRY_ENV_FILE -> ./.env -> /../../.env if let Ok(p) = std::env::var("MOMENTRY_ENV_FILE") { let _ = dotenv::from_filename(p); return; @@ -32,7 +32,6 @@ fn load_env() { let _ = dotenv::from_filename(root.join(".env")); } } - let _ = dotenv::from_filename("/Users/accusys/momentry_core/.env"); } use cli::*;