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:
@@ -1,9 +1,6 @@
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::login_with_bedrock_access_keys;
|
||||
use predicates::str::contains;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
@@ -169,79 +166,68 @@ fn legacy_chatgpt_auth_is_reported_as_not_logged_in_and_logout_removes_it() -> R
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logout_clears_only_the_selected_bedrock_provider() -> Result<()> {
|
||||
for (model_provider_id, managed_bedrock_auth, model) in [
|
||||
("amazon-bedrock", true, "openai.gpt-5.6-sol"),
|
||||
("amazon-bedrock-runtime", true, "global.openai.gpt-5.6-sol"),
|
||||
("openai", true, "gpt-5.6-sol"),
|
||||
("amazon-bedrock", false, "gpt-5.6-sol"),
|
||||
("amazon-bedrock-runtime", false, "us.openai.gpt-5.6-sol"),
|
||||
("openai", false, "gpt-5.6-sol"),
|
||||
] {
|
||||
let codex_home = TempDir::new()?;
|
||||
let config_path = codex_home.path().join("config.toml");
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
format!(
|
||||
"cli_auth_credentials_store = \"file\"\n\
|
||||
model_provider = \"{model_provider_id}\"\n\
|
||||
model = \"{model}\"\n\
|
||||
model_reasoning_effort = \"high\"\n\
|
||||
[model_providers.amazon-bedrock]\n\
|
||||
base_url = \"https://mantle.example.com/v1\"\n\
|
||||
[model_providers.amazon-bedrock.aws]\n\
|
||||
profile = \"mantle-profile\"\n\
|
||||
region = \"us-west-2\"\n\
|
||||
auth_refresh = {{ command = \"aws\", args = [\"sso\", \"login\"] }}\n\
|
||||
[model_providers.amazon-bedrock-runtime]\n\
|
||||
base_url = \"https://runtime.example.com/v1\"\n\
|
||||
[model_providers.amazon-bedrock-runtime.aws]\n\
|
||||
profile = \"runtime-profile\"\n\
|
||||
region = \"us-east-1\"\n\
|
||||
auth_refresh = {{ command = \"aws\", args = [\"login\"] }}\n"
|
||||
),
|
||||
)?;
|
||||
if managed_bedrock_auth {
|
||||
login_with_bedrock_access_keys(
|
||||
codex_home.path(),
|
||||
"managed-access-key-id",
|
||||
"managed-secret-access-key",
|
||||
Some("managed-session-token"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
AuthKeyringBackendKind::default(),
|
||||
)?;
|
||||
}
|
||||
let mut expected_config: toml::Value =
|
||||
toml::from_str(&std::fs::read_to_string(&config_path)?)?;
|
||||
if model_provider_id != "openai" {
|
||||
let expected_root = expected_config
|
||||
.as_table_mut()
|
||||
.expect("config should be a table");
|
||||
expected_root.remove("model_provider");
|
||||
expected_root.remove("model");
|
||||
expected_root["model_providers"][model_provider_id]
|
||||
.as_table_mut()
|
||||
.expect("selected Bedrock provider should be a table")
|
||||
.remove("aws");
|
||||
}
|
||||
let expected_message = if managed_bedrock_auth || model_provider_id != "openai" {
|
||||
"Successfully logged out"
|
||||
} else {
|
||||
"Not logged in"
|
||||
};
|
||||
fn provider_api_key_login_uses_private_file_store_and_never_prints_the_key() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
std::fs::write(
|
||||
codex_home.path().join("config.toml"),
|
||||
"provider_api_key_store = \"file\"\n\
|
||||
model_provider = \"imeai\"\n\
|
||||
[model_providers.imeai]\n\
|
||||
name = \"imeAI\"\n\
|
||||
base_url = \"http://127.0.0.1:9/v1\"\n\
|
||||
api_key = \"keyring\"\n",
|
||||
)?;
|
||||
let secret = "sk-provider-secret-0123456789";
|
||||
|
||||
codex_command(codex_home.path())?
|
||||
.env("AWS_ACCESS_KEY_ID", "environment-access-key-id")
|
||||
.env("AWS_SECRET_ACCESS_KEY", "environment-secret-access-key")
|
||||
.args(["logout"])
|
||||
.assert()
|
||||
.success()
|
||||
.stderr(contains(expected_message));
|
||||
let login = codex_command(codex_home.path())?
|
||||
.args(["login", "--provider", "imeai", "--with-api-key"])
|
||||
.write_stdin(format!("{secret}\n"))
|
||||
.assert()
|
||||
.success();
|
||||
let stderr = String::from_utf8_lossy(&login.get_output().stderr).to_string();
|
||||
assert!(
|
||||
stderr.contains("API key for `imeai` saved in file"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert!(!stderr.contains(secret), "{stderr}");
|
||||
|
||||
assert!(!codex_home.path().join("auth.json").exists());
|
||||
let actual_config: toml::Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
|
||||
assert_eq!(actual_config, expected_config);
|
||||
let path = codex_home.path().join("provider_api_keys.json");
|
||||
let stored: Value = serde_json::from_str(&std::fs::read_to_string(&path)?)?;
|
||||
assert_eq!(stored, json!({ "imeai": secret }));
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
assert_eq!(
|
||||
std::fs::metadata(&path)?.permissions().mode() & 0o777,
|
||||
0o600
|
||||
);
|
||||
}
|
||||
// The shared stored key is untouched.
|
||||
assert!(!codex_home.path().join("auth.json").exists());
|
||||
|
||||
let status = codex_command(codex_home.path())?
|
||||
.args(["login", "status"])
|
||||
.assert()
|
||||
.success();
|
||||
let stderr = String::from_utf8_lossy(&status.get_output().stderr).to_string();
|
||||
assert!(
|
||||
stderr.contains("Provider `imeai`: API key stored in file"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert!(!stderr.contains(secret), "{stderr}");
|
||||
|
||||
codex_command(codex_home.path())?
|
||||
.args(["logout", "--provider", "imeai"])
|
||||
.assert()
|
||||
.success()
|
||||
.stderr(contains("Removed the stored API key for `imeai`"));
|
||||
assert!(!path.exists());
|
||||
codex_command(codex_home.path())?
|
||||
.args(["login", "status"])
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(contains(
|
||||
"Provider `imeai`: no API key stored (codex login --provider imeai --with-api-key)",
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user