Files
imeai-aKode/akode-rs/utils/pty/tests/conpty_search_path.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

71 lines
2.0 KiB
Rust

#![cfg(windows)]
use akode_utils_pty::RawConPty;
use std::ffi::OsStr;
use std::fs;
use std::os::windows::ffi::OsStrExt;
use std::path::Path;
use std::path::PathBuf;
use winapi::um::libloaderapi::GetModuleHandleW;
struct CurrentDirGuard {
original: PathBuf,
}
impl CurrentDirGuard {
fn enter(path: &Path) -> std::io::Result<Self> {
let original = std::env::current_dir()?;
std::env::set_current_dir(path)?;
Ok(Self { original })
}
}
impl Drop for CurrentDirGuard {
fn drop(&mut self) {
let _ = std::env::set_current_dir(&self.original);
}
}
#[test]
fn conpty_ignores_dll_in_current_directory() -> anyhow::Result<()> {
let temp_dir = std::env::temp_dir().join(format!(
"codex-conpty-search-path-{}-{}",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)?
.as_nanos()
));
fs::create_dir(&temp_dir)?;
let system_root =
std::env::var_os("SystemRoot").ok_or_else(|| anyhow::anyhow!("SystemRoot is not set"))?;
let candidate = temp_dir.join("conpty.dll");
// A kernel32 copy exports the ConPTY functions, so the old bare-name probe
// would successfully load and retain this repository-controlled file.
akode_utils_cargo_bin::copy_executable(
&PathBuf::from(system_root)
.join("System32")
.join("kernel32.dll"),
&candidate,
)?;
{
let _current_dir = CurrentDirGuard::enter(&temp_dir)?;
drop(RawConPty::new(/*cols*/ 80, /*rows*/ 24)?);
let conpty_dll = OsStr::new("conpty.dll")
.encode_wide()
.chain(std::iter::once(0))
.collect::<Vec<_>>();
let module = unsafe { GetModuleHandleW(conpty_dll.as_ptr()) };
assert!(
module.is_null(),
"ConPTY loaded conpty.dll from the process current directory"
);
}
fs::remove_file(candidate)?;
fs::remove_dir(temp_dir)?;
Ok(())
}