codex-mobile-bridge 0.3.3

Remote bridge and service manager for codex-mobile.
Documentation
use std::env;
use std::fs;
use std::path::PathBuf;
use std::sync::Arc;

use uuid::Uuid;

use crate::config::Config;
use crate::storage::PRIMARY_RUNTIME_ID;

use super::super::{BridgeState, runtime::ManagedRuntime};

pub(super) async fn primary_runtime(state: &Arc<BridgeState>) -> Arc<ManagedRuntime> {
    let runtimes = state.runtimes.read().await;
    runtimes
        .get(PRIMARY_RUNTIME_ID)
        .cloned()
        .expect("primary runtime 不存在")
}

pub(super) async fn bootstrap_test_state() -> Arc<BridgeState> {
    let base_dir = env::temp_dir().join(format!("codex-mobile-state-test-{}", Uuid::new_v4()));
    fs::create_dir_all(&base_dir).expect("创建测试目录失败");
    let db_path = base_dir.join("bridge.db");

    let config = Config {
        listen_addr: "127.0.0.1:0".to_string(),
        token: "test-token".to_string(),
        runtime_limit: 4,
        db_path,
        codex_home: None,
        codex_binary: resolve_true_binary(),
        directory_bookmarks: Vec::new(),
    };

    BridgeState::bootstrap(config)
        .await
        .expect("bootstrap 测试 BridgeState 失败")
}

fn resolve_true_binary() -> String {
    for candidate in ["/usr/bin/true", "/bin/true"] {
        if PathBuf::from(candidate).exists() {
            return candidate.to_string();
        }
    }
    "true".to_string()
}