Files
dev/codex-rs/test-binary-support/lib.rs
T
zeekayandHanzo Dev 6cbbea2d03 merge: just-every/code v0.6.169 (e4fe007150) — keep Hanzo identity
Our history is just-every's with author emails rewritten, so the graphs are
disjoint and git finds no merge base. Supplied one by hand: d1f1f51a41, the
just-every commit matching our Oct-2025 fork point (22 files apart). 9618
upstream commits, 7004 files, +1.81M/-159k, 37 conflicts.

Resolution:
- Upstream code where our side was the Oct-2025 prototype of a feature they
  have since reimplemented 3-5x larger (agent_runs, browser_sessions,
  history_cell/{agent,browser}, the vt100 harness and its snapshots).
- Upstream's config.rs module split (builder/defaults/sources/validation)
  kept; zen5-coder and the provider-follows-model rule re-applied on top.
- Ours where the file IS the identity: README, package.json, postinstall,
  release notes pipeline, integration-zed.
- Hybrid where upstream improved a file we had branded: updates.rs (their
  release-repo migration, our hanzoai/dev), release.yml (their fail-fast npm
  auth check, our package name), chatwidget.rs (their turn handling, our
  HANZO_USER_KEY hint), exec human output (their 237 lines, our banner).

Superseded and dropped deliberately: our resume_command_name() coder-alias
hack — upstream's derive_resume_command_name() reads the invocation basename
generically, which yields "dev" for us.

LLM.md now records the real topology and the sync point; AGENTS.md and
CLAUDE.md are symlinks to it again. Single parent on purpose: adopting
jecode/main as a second parent would re-import 13,742 commits carrying the
upstream author emails a prior rewrite deliberately removed.

Version 0.2.188 -> 0.2.189.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-05 23:09:12 -07:00

78 lines
2.3 KiB
Rust

use std::path::Path;
use codex_arg0::Arg0DispatchPaths;
use codex_arg0::Arg0PathEntryGuard;
use codex_arg0::arg0_dispatch;
use tempfile::TempDir;
pub struct TestBinaryDispatchGuard {
_codex_home: TempDir,
arg0: Arg0PathEntryGuard,
_previous_codex_home: Option<std::ffi::OsString>,
}
impl TestBinaryDispatchGuard {
pub fn paths(&self) -> &Arg0DispatchPaths {
self.arg0.paths()
}
}
pub enum TestBinaryDispatchMode {
DispatchArg0Only,
Skip,
InstallAliases,
}
pub fn configure_test_binary_dispatch<F>(
codex_home_prefix: &str,
classify: F,
) -> Option<TestBinaryDispatchGuard>
where
F: FnOnce(&str, Option<&str>) -> TestBinaryDispatchMode,
{
let mut args = std::env::args_os();
let argv0 = args.next().unwrap_or_default();
let exe_name = Path::new(&argv0)
.file_name()
.and_then(|name| name.to_str())
.unwrap_or("");
let argv1 = args.next();
match classify(exe_name, argv1.as_deref().and_then(|arg| arg.to_str())) {
TestBinaryDispatchMode::DispatchArg0Only => {
let _ = arg0_dispatch();
None
}
TestBinaryDispatchMode::Skip => None,
TestBinaryDispatchMode::InstallAliases => {
let codex_home = match tempfile::Builder::new().prefix(codex_home_prefix).tempdir() {
Ok(codex_home) => codex_home,
Err(error) => panic!("failed to create test CODEX_HOME: {error}"),
};
let previous_codex_home = std::env::var_os("CODEX_HOME");
// Safety: this runs from a test ctor before test threads begin.
unsafe {
std::env::set_var("CODEX_HOME", codex_home.path());
}
let arg0 = match arg0_dispatch() {
Some(arg0) => arg0,
None => panic!("failed to configure arg0 dispatch aliases for test binary"),
};
match previous_codex_home.as_ref() {
Some(value) => unsafe {
std::env::set_var("CODEX_HOME", value);
},
None => unsafe {
std::env::remove_var("CODEX_HOME");
},
}
Some(TestBinaryDispatchGuard {
_codex_home: codex_home,
arg0,
_previous_codex_home: previous_codex_home,
})
}
}
}