aKode fase 3: provider locali, chiavi per provider, modelli dal server, SearXNG
- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
--provider <id> --with-api-key`, `logout --provider`; login status e doctor
mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
(/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
quelli successivi restano al loro posto come user (cache del server
preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
(protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
cache riusata, connessioni solo verso .25 e .57.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,12 +22,12 @@ use regex_lite::Regex;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod mcp_test_server;
|
||||
#[cfg(unix)]
|
||||
pub mod code_mode_host;
|
||||
pub mod context_snapshot;
|
||||
pub mod exec_server;
|
||||
pub mod hooks;
|
||||
pub mod mcp_test_server;
|
||||
pub mod network_policy_mcp;
|
||||
pub mod oauth;
|
||||
pub mod process;
|
||||
@@ -207,17 +207,44 @@ pub async fn load_default_config_for_test(codex_home: &TempDir) -> Config {
|
||||
pub async fn load_default_config_for_test_with_managed_config(
|
||||
codex_home: &TempDir,
|
||||
managed_config: ManagedConfigFixture,
|
||||
) -> Config {
|
||||
let mut config = load_config_with_test_provider(codex_home, managed_config).await;
|
||||
if config.model_catalog.is_none() && config.model_provider.model_catalog_url.is_none() {
|
||||
config.model_catalog = codex_models_manager::bundled_models_response().ok();
|
||||
}
|
||||
config
|
||||
}
|
||||
|
||||
/// Like [`load_default_config_for_test_with_managed_config`], without injecting the bundled
|
||||
/// catalog into `config.model_catalog`. `test_codex` serves the bundled catalog through its
|
||||
/// models manager instead, so an explicit config catalog keeps its upstream meaning.
|
||||
pub(crate) async fn load_config_with_test_provider(
|
||||
codex_home: &TempDir,
|
||||
managed_config: ManagedConfigFixture,
|
||||
) -> Config {
|
||||
let loader_overrides = managed_config
|
||||
.loader_overrides_for_tests(codex_home.path())
|
||||
.expect("managed config fixture should be writable");
|
||||
ConfigBuilder::default()
|
||||
let mut config = ConfigBuilder::default()
|
||||
.loader_overrides(loader_overrides)
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.harness_overrides(default_test_overrides())
|
||||
.build()
|
||||
.await
|
||||
.expect("defaults for test should always succeed")
|
||||
.expect("defaults for test should always succeed");
|
||||
// aKode has no built-in OpenAI provider: give tests a mock Responses provider (stored-key
|
||||
// auth, unreachable endpoint unless a test overrides it) and the bundled model catalog.
|
||||
if !config.model_provider_configured() {
|
||||
let provider =
|
||||
crate::test_codex::test_model_provider_info(Some("http://127.0.0.1:9/v1".to_string()));
|
||||
config.model_provider_id = crate::test_codex::TEST_MODEL_PROVIDER_ID.to_string();
|
||||
config.model_providers.insert(
|
||||
crate::test_codex::TEST_MODEL_PROVIDER_ID.to_string(),
|
||||
provider.clone(),
|
||||
);
|
||||
config.model_provider = provider;
|
||||
}
|
||||
config
|
||||
}
|
||||
|
||||
pub fn managed_network_requirements() -> ManagedConfigFixture {
|
||||
|
||||
@@ -660,4 +660,3 @@ impl Respond for McpJsonRpcResponder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@ use codex_home::CodexHomeUserInstructionsProvider;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_model_provider_info::built_in_model_providers;
|
||||
use codex_models_manager::ModelOrigin;
|
||||
use codex_models_manager::bundled_models_response;
|
||||
use codex_models_manager::manager::ModelCatalogSettings;
|
||||
use codex_models_manager::manager::SharedModelsManager;
|
||||
use codex_models_manager::manager::StaticModelsManager;
|
||||
use codex_protocol::config_types::CollaborationMode;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
@@ -83,8 +84,6 @@ use wiremock::MockServer;
|
||||
|
||||
use crate::TempDirExt;
|
||||
use crate::TestEnvironment;
|
||||
use crate::load_default_config_for_test;
|
||||
use crate::load_default_config_for_test_with_managed_config;
|
||||
use crate::responses::WebSocketTestServer;
|
||||
use crate::responses::output_value_to_text;
|
||||
use crate::responses::start_mock_server;
|
||||
@@ -445,6 +444,14 @@ impl TestCodexBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Point the provider's model catalog at `{base_url}/models` (unless a test sets its own
|
||||
/// `model_catalog_url`) and drop the bundled test catalog, so remote catalog refresh runs
|
||||
/// with whatever auth the test selected.
|
||||
pub fn with_catalog_discovery(mut self) -> Self {
|
||||
self.catalog_discovery = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Authenticate with host-supplied (empty) request headers. Header auth refreshes the
|
||||
/// provider catalog from the provider base URL and merges it over the bundled catalog.
|
||||
pub fn with_header_auth(mut self) -> Self {
|
||||
@@ -883,9 +890,25 @@ impl TestCodexBuilder {
|
||||
.code_mode_host_program
|
||||
.take()
|
||||
.or_else(|| codex_utils_cargo_bin::cargo_bin("codex-code-mode-host").ok());
|
||||
// Upstream tests ran against the built-in provider's bundled catalog without an explicit
|
||||
// `config.model_catalog`. Providers without a catalog URL now list OpenAI-format
|
||||
// `/models` instead, so serve the bundled catalog (origin `Bundled`) through the models
|
||||
// manager and keep `config.model_catalog` unset, as the built-in provider had it.
|
||||
let bundled_catalog = self.models_manager.is_none()
|
||||
&& self.model_catalog_settings.is_none()
|
||||
&& config.model_catalog.is_none()
|
||||
&& config.model_provider.model_catalog_url.is_none();
|
||||
let factory =
|
||||
match &self.models_manager {
|
||||
Some(models) => codex_core::test_support::fixed_model_catalog(Arc::clone(models)),
|
||||
None if bundled_catalog => {
|
||||
let models: SharedModelsManager = Arc::new(StaticModelsManager::new(
|
||||
Some(Arc::clone(&auth_manager)),
|
||||
bundled_models_response().expect("bundled catalog"),
|
||||
ModelOrigin::Bundled,
|
||||
));
|
||||
codex_core::test_support::fixed_model_catalog(models)
|
||||
}
|
||||
None => Arc::new(self.model_catalog_settings.clone().unwrap_or_else(|| {
|
||||
ModelCatalogSettings::disk(config.codex_home.to_path_buf())
|
||||
})),
|
||||
@@ -1024,26 +1047,28 @@ impl TestCodexBuilder {
|
||||
home: &TempDir,
|
||||
cwd_override: AbsolutePathBuf,
|
||||
) -> anyhow::Result<(Config, Arc<TempDir>)> {
|
||||
// aKode has no built-in OpenAI provider: tests talk to the mock server through a
|
||||
// generic Responses provider that uses the stored test API key.
|
||||
let model_provider = ModelProviderInfo {
|
||||
base_url: Some(base_url),
|
||||
// Most core tests use SSE-only mock servers, so keep websocket transport off unless
|
||||
// a test explicitly opts into websocket coverage.
|
||||
supports_websockets: false,
|
||||
..built_in_model_providers(/*openai_base_url*/ None)["openai"].clone()
|
||||
..test_model_provider_info(Some(base_url))
|
||||
};
|
||||
let cwd = Arc::new(TempDir::new()?);
|
||||
for hook in self.pre_build_hooks.drain(..) {
|
||||
hook(home.path());
|
||||
}
|
||||
let mut config = if let Some(managed_config) = self.managed_config.take() {
|
||||
load_default_config_for_test_with_managed_config(home, managed_config).await
|
||||
} else {
|
||||
load_default_config_for_test(home).await
|
||||
};
|
||||
let managed_config = self.managed_config.take().unwrap_or_default();
|
||||
let mut config = crate::load_config_with_test_provider(home, managed_config).await;
|
||||
// Keep generic tests stable when the bundled catalog default changes. Tests that need a
|
||||
// specific model can still override this with a config mutator.
|
||||
config.model = Some("gpt-5.5".to_string());
|
||||
config.cwd = cwd_override;
|
||||
config.model_provider_id = TEST_MODEL_PROVIDER_ID.to_string();
|
||||
config
|
||||
.model_providers
|
||||
.insert(TEST_MODEL_PROVIDER_ID.to_string(), model_provider.clone());
|
||||
config.model_provider = model_provider;
|
||||
if let Ok(path) = codex_utils_cargo_bin::cargo_bin("codex") {
|
||||
config.codex_self_exe = Some(path);
|
||||
@@ -1063,6 +1088,10 @@ impl TestCodexBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if self.catalog_discovery {
|
||||
// Discovery tests read the provider catalog instead of the bundled test catalog.
|
||||
config.model_catalog = None;
|
||||
}
|
||||
let mut mutators = vec![];
|
||||
swap(&mut self.config_mutators, &mut mutators);
|
||||
for mutator in mutators {
|
||||
@@ -1083,6 +1112,38 @@ impl TestCodexBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider id of the mock Responses server used by core tests.
|
||||
pub const TEST_MODEL_PROVIDER_ID: &str = "mock";
|
||||
|
||||
/// Mock provider for tests, with the transport features of the removed built-in provider so
|
||||
/// upstream behavior tests keep their meaning. Request-shape tests keep the unmerged
|
||||
/// instruction layout; instruction merging has dedicated tests.
|
||||
/// Strips the removed built-in provider's OpenAI-only features from a test provider, as
|
||||
/// renaming the provider away from "OpenAI" used to.
|
||||
pub fn without_openai_features(provider: ModelProviderInfo) -> ModelProviderInfo {
|
||||
ModelProviderInfo {
|
||||
supports_standalone_web_search: false,
|
||||
include_internal_metadata: false,
|
||||
capabilities: None,
|
||||
..provider
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_model_provider_info(base_url: Option<String>) -> ModelProviderInfo {
|
||||
ModelProviderInfo {
|
||||
supports_websockets: true,
|
||||
supports_standalone_web_search: true,
|
||||
include_internal_metadata: true,
|
||||
merge_system_messages: Some(false),
|
||||
capabilities: Some(codex_model_provider_info::ModelProviderCapabilities {
|
||||
hosted_web_search: Some(true),
|
||||
remote_compaction: Some(codex_model_provider_info::RemoteCompactionSupport::V2),
|
||||
..Default::default()
|
||||
}),
|
||||
..ModelProviderInfo::create_responses_provider(TEST_MODEL_PROVIDER_ID, base_url)
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_test_model_catalog(config: &mut Config) -> Result<()> {
|
||||
if config.model.as_deref() != Some(TEST_MODEL_WITH_EXPERIMENTAL_TOOLS)
|
||||
|| config.model_catalog.is_some()
|
||||
|
||||
@@ -9,7 +9,8 @@ pub struct TestCodexExecBuilder {
|
||||
}
|
||||
|
||||
impl TestCodexExecBuilder {
|
||||
pub fn cmd(&self) -> assert_cmd::Command {
|
||||
/// `codex-exec` with no model provider configured at all.
|
||||
pub fn cmd_without_provider(&self) -> assert_cmd::Command {
|
||||
let mut cmd = assert_cmd::Command::new(
|
||||
codex_utils_cargo_bin::cargo_bin("codex-exec")
|
||||
.expect("should find binary for codex-exec"),
|
||||
@@ -20,11 +21,40 @@ impl TestCodexExecBuilder {
|
||||
.env(CODEX_API_KEY_ENV_VAR, "dummy");
|
||||
cmd
|
||||
}
|
||||
|
||||
/// `codex-exec` with a mock provider at an unreachable endpoint and the bundled catalog.
|
||||
pub fn cmd(&self) -> assert_cmd::Command {
|
||||
self.cmd_with_base_url("http://127.0.0.1:9/v1")
|
||||
}
|
||||
|
||||
pub fn cmd_with_server(&self, server: &MockServer) -> assert_cmd::Command {
|
||||
let mut cmd = self.cmd();
|
||||
let base = format!("{}/v1", server.uri());
|
||||
self.cmd_with_base_url(&format!("{}/v1", server.uri()))
|
||||
}
|
||||
|
||||
fn cmd_with_base_url(&self, base: &str) -> assert_cmd::Command {
|
||||
let mut cmd = self.cmd_without_provider();
|
||||
// aKode has no built-in OpenAI provider: point a mock provider at the server, use
|
||||
// the env test key, and keep the bundled catalog the removed provider defaulted to.
|
||||
let catalog = self.home.path().join("test-models.json");
|
||||
if !catalog.exists() {
|
||||
std::fs::write(
|
||||
&catalog,
|
||||
include_str!("../../../models-manager/models.json"),
|
||||
)
|
||||
.expect("write test model catalog");
|
||||
}
|
||||
cmd.arg("-c")
|
||||
.arg(format!("openai_base_url={}", toml_string_literal(&base)));
|
||||
.arg("model_provider=\"mock\"")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"model_providers.mock={{name=\"mock\",base_url={},requires_openai_auth=true,supports_websockets=false,merge_system_messages=false}}",
|
||||
toml_string_literal(base)
|
||||
))
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"model_catalog_json={}",
|
||||
toml_string_literal(&catalog.display().to_string())
|
||||
));
|
||||
cmd
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user