mirror of
https://github.com/openai/codex.git
synced 2026-11-07 20:30:33 +00:00
fix code mode host packaging compatibility
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex as StdMutex;
|
||||
@@ -63,7 +64,7 @@ impl ProcessOwnedCodeModeSessionProvider {
|
||||
|
||||
impl Default for ProcessOwnedCodeModeSessionProvider {
|
||||
fn default() -> Self {
|
||||
Self::with_host_program(InstallContext::current().code_mode_host_program())
|
||||
Self::with_host_program(default_host_program())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,9 +193,7 @@ impl ProcessOwnedCodeModeSession {
|
||||
pub fn new() -> Self {
|
||||
Self::with_process_host(
|
||||
Arc::new(NoopCodeModeSessionDelegate),
|
||||
Arc::new(OwnedProcessHost::new(
|
||||
InstallContext::current().code_mode_host_program(),
|
||||
)),
|
||||
Arc::new(OwnedProcessHost::new(default_host_program())),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -493,6 +492,26 @@ impl CodeModeSession for ProcessOwnedCodeModeSession {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_host_program() -> PathBuf {
|
||||
InstallContext::current()
|
||||
.code_mode_host_program()
|
||||
.unwrap_or_else(|| resolve_host_program(std::env::current_exe()))
|
||||
}
|
||||
|
||||
fn resolve_host_program(current_exe: io::Result<PathBuf>) -> PathBuf {
|
||||
let executable_name = if cfg!(windows) {
|
||||
"codex-code-mode-host.exe"
|
||||
} else {
|
||||
"codex-code-mode-host"
|
||||
};
|
||||
if let Ok(current_exe) = current_exe
|
||||
&& let Some(parent) = current_exe.parent()
|
||||
{
|
||||
return parent.join(executable_name);
|
||||
}
|
||||
PathBuf::from(executable_name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "remote_session_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_code_mode_protocol::CodeModeSessionProvider;
|
||||
@@ -8,6 +10,7 @@ use pretty_assertions::assert_eq;
|
||||
|
||||
use super::ProcessOwnedCodeModeSession;
|
||||
use super::ProcessOwnedCodeModeSessionProvider;
|
||||
use super::resolve_host_program;
|
||||
use crate::NoopCodeModeSessionDelegate;
|
||||
|
||||
#[test]
|
||||
@@ -20,6 +23,37 @@ fn provider_reuses_its_live_process_host() {
|
||||
assert!(Arc::ptr_eq(&first, &second));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn host_program_is_next_to_the_main_executable_even_when_missing() {
|
||||
let executable_name = if cfg!(windows) {
|
||||
"codex-code-mode-host.exe"
|
||||
} else {
|
||||
"codex-code-mode-host"
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
resolve_host_program(Ok(PathBuf::from("/opt/codex/bin/codex"))),
|
||||
PathBuf::from("/opt/codex/bin").join(executable_name)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn host_program_falls_back_to_its_name_when_main_executable_is_unknown() {
|
||||
let executable_name = if cfg!(windows) {
|
||||
"codex-code-mode-host.exe"
|
||||
} else {
|
||||
"codex-code-mode-host"
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
resolve_host_program(Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"missing executable"
|
||||
))),
|
||||
PathBuf::from(executable_name)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn provider_falls_back_to_in_process_session_when_host_is_missing() {
|
||||
let provider = ProcessOwnedCodeModeSessionProvider::with_host_program(
|
||||
|
||||
Reference in New Issue
Block a user