-
Notifications
You must be signed in to change notification settings - Fork 22
fix(aft-bridge): align PATH defaults to plugin #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,12 @@ pub fn run(args: Vec<OsString>) -> Result<(), WarmupError> { | |||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| // Resolve ONNX Runtime from the plugin-managed cache so `aft warmup` | ||||||||
| // can build the semantic index without the plugin setting ORT_DYLIB_PATH. | ||||||||
| if args.areas.semantic { | ||||||||
| try_set_ort_dylib_path(&storage_dir); | ||||||||
| } | ||||||||
|
|
||||||||
| let ctx = AppContext::new(Box::new(TreeSitterProvider::new()), Config::default()); | ||||||||
| configure(&ctx, &root, &storage_dir, args.areas, args.force)?; | ||||||||
|
|
||||||||
|
|
@@ -248,11 +254,50 @@ fn warmup_storage_dir() -> PathBuf { | |||||||
| if let Some(value) = std::env::var_os("AFT_STORAGE_DIR") { | ||||||||
| return PathBuf::from(value); | ||||||||
| } | ||||||||
| let home = std::env::var_os("HOME") | ||||||||
| .or_else(|| std::env::var_os("USERPROFILE")) | ||||||||
| .map(PathBuf::from) | ||||||||
| .unwrap_or_else(std::env::temp_dir); | ||||||||
| home.join(".cache").join("aft") | ||||||||
| // Fallback mirrors resolveCortexKitStorageRoot() from the TS plugin. | ||||||||
| if let Some(dir) = std::env::var_os("XDG_DATA_HOME") { | ||||||||
| return PathBuf::from(dir).join("cortexkit").join("aft"); | ||||||||
| } | ||||||||
| if cfg!(target_os = "windows") { | ||||||||
| if let Some(dir) = std::env::var_os("LOCALAPPDATA") | ||||||||
| .or_else(|| std::env::var_os("APPDATA")) | ||||||||
| { | ||||||||
| return PathBuf::from(dir).join("cortexkit").join("aft"); | ||||||||
| } | ||||||||
| } | ||||||||
| let home = if cfg!(target_os = "windows") { | ||||||||
| std::env::var_os("USERPROFILE").or_else(|| std::env::var_os("HOME")) | ||||||||
| } else { | ||||||||
| std::env::var_os("HOME") | ||||||||
| } | ||||||||
| .map(PathBuf::from) | ||||||||
| .unwrap_or_else(std::env::temp_dir); | ||||||||
| if cfg!(target_os = "windows") { | ||||||||
| home.join("AppData").join("Local").join("cortexkit").join("aft") | ||||||||
| } else { | ||||||||
| home.join(".local").join("share").join("cortexkit").join("aft") | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// Set `ORT_DYLIB_PATH` from a cached ONNX Runtime library if not already set. | ||||||||
| fn try_set_ort_dylib_path(storage_dir: &std::path::Path) { | ||||||||
| if std::env::var_os("ORT_DYLIB_PATH").is_some() { | ||||||||
| return; | ||||||||
| } | ||||||||
| let lib_name = if cfg!(target_os = "macos") { | ||||||||
| "libonnxruntime.dylib" | ||||||||
| } else if cfg!(target_os = "windows") { | ||||||||
| "onnxruntime.dll" | ||||||||
| } else { | ||||||||
| "libonnxruntime.so" | ||||||||
| }; | ||||||||
| let ort_dir = storage_dir.join("onnxruntime").join("1.24.4"); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Hardcoded ONNX Runtime version string can drift from the actual cached ORT version and break semantic warmup. Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing pattern! The plugin side already pins There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||
| for candidate in [ort_dir.join(lib_name), ort_dir.join("lib").join(lib_name)] { | ||||||||
| if candidate.is_file() { | ||||||||
| std::env::set_var("ORT_DYLIB_PATH", &candidate); | ||||||||
| break; | ||||||||
| } | ||||||||
| } | ||||||||
|
Comment on lines
+294
to
+300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
| } | ||||||||
|
|
||||||||
| /// Build the `configure` params for a warmup run. | ||||||||
|
|
@@ -863,4 +908,33 @@ mod tests { | |||||||
| assert_eq!(err.exit_code(), 2); | ||||||||
| assert!(err.to_string().contains("--only requires a value")); | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
| fn try_set_ort_dylib_path_finds_cached_library() { | ||||||||
| use std::sync::Mutex; | ||||||||
| static LOCK: Mutex<()> = Mutex::new(()); | ||||||||
| let _guard = LOCK.lock().unwrap(); | ||||||||
| std::env::remove_var("ORT_DYLIB_PATH"); | ||||||||
|
|
||||||||
| let temp = tempfile::tempdir().unwrap(); | ||||||||
| let lib_name = if cfg!(target_os = "macos") { | ||||||||
| "libonnxruntime.dylib" | ||||||||
| } else if cfg!(target_os = "windows") { | ||||||||
| "onnxruntime.dll" | ||||||||
| } else { | ||||||||
| "libonnxruntime.so" | ||||||||
| }; | ||||||||
| let ort_dir = temp.path().join("onnxruntime").join("1.24.4"); | ||||||||
| std::fs::create_dir_all(&ort_dir).unwrap(); | ||||||||
| let lib_path = ort_dir.join(lib_name); | ||||||||
| std::fs::write(&lib_path, b"fake").unwrap(); | ||||||||
|
|
||||||||
| try_set_ort_dylib_path(temp.path()); | ||||||||
|
|
||||||||
| assert_eq!( | ||||||||
| std::env::var_os("ORT_DYLIB_PATH"), | ||||||||
| Some(lib_path.as_os_str().to_owned()) | ||||||||
| ); | ||||||||
| std::env::remove_var("ORT_DYLIB_PATH"); | ||||||||
| } | ||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.