Rimossi i provider integrati OpenAI, Bedrock e GCP e ogni fallback a OpenAI (B)

Parte "sicurezza" della fase 3 di aKode (e39aae00), senza le funzioni di imeAI:

- via i provider integrati openai, amazon-bedrock, amazon-bedrock-runtime e gcp
  (crate model-provider: moduli amazon_bedrock, gcp, chatgpt_base_url; login Bedrock;
  onboarding Bedrock/GCP; richieste app-server di setup cloud);
- nessun URL predefinito verso api.openai.com / chatgpt.com: un provider senza
  base_url non viene mai contattato; senza model_provider configurato exec e TUI
  mostrano come scriverne uno in config.toml (NO_MODEL_PROVIDER_CONFIGURED_ERROR);
- via la skill openai-docs, la sample skill-installer (scaricava da github.com/openai/skills),
  request_plugin_install, AppsInstructions, URL predefiniti di realtime e updater;
- test di sicurezza adattati (provider "mock" al posto di quello integrato), non cancellati.

Restano fuori da questo commit (categoria F/D/E, non portate): chiave per provider nel
portachiavi, modelli da /models, unione dei messaggi di sistema, crate web-tools e
SearXNG, header @@ in apply_patch, modello ausiliario, tool function per apply_patch.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-17 12:31:29 +01:00
parent 22a79feba1
commit 2f8b6a3e16
481 changed files with 4319 additions and 25142 deletions

View File

@@ -93,7 +93,8 @@ async fn create_and_patch_gateway_providers_without_changing_the_default() -> Re
.find(|p| p["id"] == "team-gateway"),
Some(&expected)
);
assert_eq!(after["defaultProviderId"], "openai");
// aKode: there is no default (`openai`) provider when none is configured.
assert_eq!(after["defaultProviderId"], "");
let persisted: Value = toml::from_str(&before)?;
assert_eq!(
persisted["model_providers"]["team-gateway"],
@@ -145,11 +146,8 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
json!({"name": "Changed"}),
"configLayerReadonly",
),
(
"openai",
json!({"name": "Changed"}),
"configValidationError",
),
// aKode: `openai` is no longer a built-in provider, so it is an unknown id here.
("openai", json!({"name": "Changed"}), "configPathNotFound"),
("external", json!({"envKey": null}), "configValidationError"),
(
"basic",
@@ -163,7 +161,6 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
"configValidationError",
),
("ollama", json!({}), "configValidationError"),
("gcp", json!({}), "configValidationError"),
] {
patch["type"] = json!("customGateway");
patch["providerId"] = json!(id);
@@ -191,177 +188,3 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
assert_eq!(persisted, expected);
Ok(())
}
#[tokio::test]
async fn custom_provider_writes_reject_builtin_auth_names_and_preserve_existing_ids() -> Result<()>
{
let home = TempDir::new()?;
let config_path = home.path().join("config.toml");
let ids = [r"team\gpu", "corp.gateway", r#"team"gpu"#];
let mut providers = json!({});
for id in ids {
providers[id] = json!({"name":"Amazon Bedrock", "base_url":"https://old.example.test"});
}
std::fs::write(
&config_path,
toml::to_string(&json!({"model_providers":providers}))?,
)?;
let mut server = TestAppServer::builder()
.with_codex_home(home.path())
.with_env_overrides(CLEARED_AUTH_ENV)
.build_initialized()
.await?;
let new_url = "https://new.example.test";
for (provider_id, mut settings) in [
(None, json!({"name": "OpenAI", "baseUrl": new_url})),
(
None,
json!({"name": " Amazon Bedrock ", "baseUrl": new_url}),
),
(Some(ids[0]), json!({"name": "Amazon Bedrock Runtime"})),
(Some(ids[0]), json!({"name": "Google Cloud Vertex AI"})),
(Some(ids[0]), json!({"baseUrl": new_url})),
(Some(ids[0]), json!({"name":"Renamed", "envKey":null})),
] {
settings["type"] = json!("customGateway");
settings["providerId"] = json!(provider_id);
let request = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(request))
.await?;
assert_eq!(
error.error.data,
Some(json!({"config_write_error_code":"configValidationError"}))
);
}
for id in ids {
let request = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":{"type":"customGateway","providerId":id,"name":"Amazon Bedrock Mantle","baseUrl":new_url}})),
)
.await?;
let saved: Value = server.read_response(request).await?;
assert_eq!(saved["provider"]["id"], id);
providers[id] = json!({"name": "Amazon Bedrock Mantle", "base_url": new_url});
}
let saved: Value = toml::from_str(&std::fs::read_to_string(config_path)?)?;
assert_eq!(saved["model_providers"], providers);
Ok(())
}
#[tokio::test]
async fn builtin_provider_patches_preserve_auth_and_do_not_select_or_authenticate() -> Result<()> {
let home = TempDir::new()?;
let config_path = home.path().join("config.toml");
std::fs::write(
home.path().join("requirements.toml"),
"model_provider = 'openai'\n",
)?;
let mut server = TestAppServer::builder()
.with_codex_home(home.path())
.with_env_overrides(CLEARED_AUTH_ENV)
.build_initialized()
.await?;
let credential_file = home.path().join("missing-credentials.json");
for mut settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock", "profile":"work", "region":"us-east-1"}),
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":null, "region":"us-west-2"}),
json!({"type":"gcp", "providerId":"gcp", "projectId":"test-project", "location":"global", "credentialFile":credential_file}),
] {
let params = serde_json::from_value(json!({"settings":settings}))?;
let saved: Value = server
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
.await?;
let id = settings
.as_object_mut()
.unwrap()
.remove("providerId")
.unwrap();
assert_eq!(saved["provider"]["id"], id);
assert_eq!(saved["provider"]["settings"], settings);
}
let refresh = json!({"command":"aws", "args":["sso", "login"]});
let export = json!({"command":"unused-credential-command", "args":["test-only"]});
let mut configured: Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
configured["model_providers"]["amazon-bedrock"]["aws"]["auth_refresh"] = refresh.clone();
configured["model_providers"]["amazon-bedrock-runtime"]["aws"]["credential_export"] =
export.clone();
std::fs::write(&config_path, toml::to_string(&configured)?)?;
for settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock", "region":null}),
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "region":"eu-west-1"}),
json!({"type":"gcp", "providerId":"gcp", "location":"us-central1", "credentialFile":null}),
json!({"type":"gcp", "providerId":"gcp"}),
] {
let params = serde_json::from_value(json!({"settings":settings}))?;
let saved: Value = server
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
.await?;
assert_eq!(saved["provider"]["id"], settings["providerId"]);
}
let list: Value = server
.request(|request_id| ClientRequest::ModelProviderList {
request_id,
params: Default::default(),
})
.await?;
assert_eq!(list["defaultProviderId"], "openai");
assert_eq!(list["canChangeDefault"], false);
let before_rejections = std::fs::read_to_string(&config_path)?;
let actual: Value = toml::from_str(&before_rejections)?;
assert_eq!(
actual,
json!({"model_providers": {
"amazon-bedrock": {"aws":{"profile":"work", "auth_refresh":refresh}},
"amazon-bedrock-runtime": {"aws":{"region":"eu-west-1", "credential_export":export}},
"gcp":{"project_id":"test-project", "location":"us-central1"}
}})
);
for settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":"conflicts-with-command", "region":"must-not-save"}),
json!({"type":"gcp", "providerId":"gcp", "credentialFile":"relative/path", "location":"must-not-save"}),
] {
let write = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(write))
.await?;
assert_eq!(
error.error.data,
Some(json!({"config_write_error_code":"configValidationError"}))
);
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
}
for settings in [
json!({"type":"bedrock", "providerId":"gcp", "region":"must-not-save"}),
json!({"type":"gcp", "providerId":"amazon-bedrock", "location":"must-not-save"}),
json!({"type":"bedrock", "providerId":"amazon-bedrock", "envKey":"UNSUPPORTED"}),
json!({"type":"gcp", "providerId":"gcp", "profile":"wrong-provider-field"}),
json!({"type":"gcp", "location":"missing-id"}),
] {
let write = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(write))
.await?;
assert_eq!(error.error.code, -32600);
}
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
Ok(())
}