aKode: eliminato chatgpt_base_url ormai inutilizzato
- La chiave è ancora accettata nei file di configurazione ma ignorata. - Schemi JSON e TypeScript dell'app-server rigenerati; i bundle ora si chiamano akode_app_server_protocol*.schemas.json, come produce il generatore. - app-server: niente più avviso unused_mut nella build release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -309,6 +309,15 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
..NetworkProxyConfig::default()
|
||||
};
|
||||
network_config.set_credential_broker_enabled(/*enabled*/ true);
|
||||
network_config.credential_providers.insert(
|
||||
"local".to_string(),
|
||||
CredentialProviderConfig {
|
||||
env: vec!["LOCAL_TOKEN".to_string()],
|
||||
patterns: vec!["local_[a-z]{24}".to_string()],
|
||||
url_prefixes: vec!["https://public.local-provider.example/v1".to_string()],
|
||||
..CredentialProviderConfig::default()
|
||||
},
|
||||
);
|
||||
let network_spec = NetworkProxySpec::from_config_and_constraints(
|
||||
network_config,
|
||||
/*requirements*/ None,
|
||||
@@ -462,7 +471,7 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
// Identical concurrent captures must not share one command's cancellation.
|
||||
fs::write(
|
||||
dir.path().join(".akode/startup.sh"),
|
||||
"export OPENAI_API_KEY=sk-snapshot-cache-test\nprintf started > capture-started\nwhile [ ! -f finish-startup ]; do sleep 0.01; done\n",
|
||||
"export LOCAL_TOKEN=local_snapshotcachetestabcdefg\nprintf started > capture-started\nwhile [ ! -f finish-startup ]; do sleep 0.01; done\n",
|
||||
)
|
||||
.await?;
|
||||
config.shell_environment_policy.r#set.insert(
|
||||
@@ -590,7 +599,12 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
|
||||
let original_config = proxy.current_cfg().await?;
|
||||
let mut changed_config = original_config.clone();
|
||||
changed_config.set_credential_broker_openai_base_url(Some("https://gateway.example/v1"));
|
||||
changed_config
|
||||
.credential_providers
|
||||
.get_mut("local")
|
||||
.context("local credential provider")?
|
||||
.url_prefixes
|
||||
.push("https://gateway.example/v1".to_string());
|
||||
for (config, remains_valid) in [
|
||||
(original_config.clone(), true),
|
||||
(changed_config, false),
|
||||
@@ -625,8 +639,8 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
new_env = context
|
||||
.prepare_child_environment(&proxy, new_env, /*environment_id*/ None)?
|
||||
.env;
|
||||
assert_ne!(new_env["OPENAI_API_KEY"], old_env["OPENAI_API_KEY"]);
|
||||
assert_ne!(new_env["OPENAI_API_KEY"], "sk-snapshot-cache-test");
|
||||
assert_ne!(new_env["LOCAL_TOKEN"], old_env["LOCAL_TOKEN"]);
|
||||
assert_ne!(new_env["LOCAL_TOKEN"], "local_snapshotcachetestabcdefg");
|
||||
|
||||
// A credential change during capture should recapture once under the new configuration.
|
||||
fs::remove_file(refreshed.path()).await?;
|
||||
@@ -634,7 +648,7 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
fs::remove_file(dir.path().join("capture-started")).await?;
|
||||
fs::write(
|
||||
dir.path().join(".akode/startup.sh"),
|
||||
"export OPENAI_API_KEY=sk-snapshot-cache-test\nprintf x >> capture-started\nwhile [ ! -f finish-startup ]; do sleep 0.01; done\n",
|
||||
"export LOCAL_TOKEN=local_snapshotcachetestabcdefg\nprintf x >> capture-started\nwhile [ ! -f finish-startup ]; do sleep 0.01; done\n",
|
||||
)
|
||||
.await?;
|
||||
let capture =
|
||||
@@ -644,7 +658,12 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
let mut config = proxy.current_cfg().await?;
|
||||
config.set_credential_broker_openai_base_url(Some("https://new-gateway.example/v1"));
|
||||
config
|
||||
.credential_providers
|
||||
.get_mut("local")
|
||||
.context("local credential provider")?
|
||||
.url_prefixes
|
||||
.push("https://new-gateway.example/v1".to_string());
|
||||
proxy
|
||||
.replace_config_state(akode_network_proxy::build_config_state(
|
||||
config,
|
||||
@@ -688,6 +707,15 @@ async fn credential_snapshot_proxy() -> Result<crate::config::StartedNetworkProx
|
||||
..CredentialProviderConfig::default()
|
||||
},
|
||||
);
|
||||
network_config.credential_providers.insert(
|
||||
"snapshot".to_string(),
|
||||
CredentialProviderConfig {
|
||||
env: vec!["SNAPSHOT_API_KEY".to_string()],
|
||||
patterns: vec!["snapshot_[a-z]{24}".to_string()],
|
||||
url_prefix_from_env: Some("SNAPSHOT_BASE_URL".to_string()),
|
||||
..CredentialProviderConfig::default()
|
||||
},
|
||||
);
|
||||
network_config.credential_providers.insert(
|
||||
"stripe".to_string(),
|
||||
CredentialProviderConfig {
|
||||
@@ -743,7 +771,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
declare -rx HOMEBREW_GITHUB_API_TOKEN=\"$GITHUB_TOKEN\"\n\
|
||||
export GH_ENTERPRISE_TOKEN='ghp_enterprise_secret'\n\
|
||||
export GH_HOST='attacker.example'\n\
|
||||
export OPENAI_API_KEY='sk-proj-snapshot-secret'\n\
|
||||
export SNAPSHOT_API_KEY='snapshot_abcdefghijklmnopqrstuvwx'\n\
|
||||
export STRIPE_API_KEY='stripe_live_abcdefghijklmnopqrstuvwx'\n\
|
||||
export STRIPE_HOST='https://startup.stripe.example/v1'\n\
|
||||
export STRIPE_AUTH_HEADER=\"Bearer $STRIPE_API_KEY\"\n\
|
||||
@@ -755,8 +783,8 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
export LOCAL_AUTH_HEADER=\"Bearer $LOCAL_TOKEN\"\n\
|
||||
unset LOCAL_TOKEN\n\
|
||||
export AUTH_BUNDLE=\"GitHub $GH_TOKEN\n\
|
||||
OpenAI $OPENAI_API_KEY\"\n\
|
||||
export OPENAI_BASE_URL='https://api.snapshot.example/v1'\n\
|
||||
Snapshot $SNAPSHOT_API_KEY\"\n\
|
||||
export SNAPSHOT_BASE_URL='https://api.snapshot.example/v1'\n\
|
||||
export IDENTITY_SEEN=\"${OPENAI_IDENTITY_TOKEN_FILE-missing}\"\n\
|
||||
export EXCLUDED_PARENT_HOME=\"${HOME-missing}\"\n\
|
||||
export STARTUP_PATH_OVERRIDE_SEEN=\"${PATH%%:*}\"\n\
|
||||
@@ -837,7 +865,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
assert_eq!(
|
||||
captured_credentials
|
||||
.context_env
|
||||
.get("OPENAI_BASE_URL")
|
||||
.get("SNAPSHOT_BASE_URL")
|
||||
.map(String::as_str),
|
||||
Some("https://api.snapshot.example/v1")
|
||||
);
|
||||
@@ -847,7 +875,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
"ghp_shell_only_secret",
|
||||
"ghp_readonly_secret",
|
||||
"ghp_enterprise_secret",
|
||||
"sk-proj-snapshot-secret",
|
||||
"snapshot_abcdefghijklmnopqrstuvwx",
|
||||
"stripe_live_abcdefghijklmnopqrstuvwx",
|
||||
"pin_abcdefgh",
|
||||
"local_abcdefghijklmnopqrstuvwx",
|
||||
@@ -1054,7 +1082,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
("GH_ENTERPRISE_TOKEN", "ghp_enterprise_secret"),
|
||||
("GITHUB_ENTERPRISE_TOKEN", "ghp_removed_enterprise_secret"),
|
||||
("UNSET_AUTH_HEADER", "Bearer ghp_removed_enterprise_secret"),
|
||||
("OPENAI_API_KEY", "sk-proj-snapshot-secret"),
|
||||
("SNAPSHOT_API_KEY", "snapshot_abcdefghijklmnopqrstuvwx"),
|
||||
("STRIPE_API_KEY", "stripe_live_abcdefghijklmnopqrstuvwx"),
|
||||
("STRIPE_HOST", "api.stripe.example"),
|
||||
("VENDOR_PASSWORD", "pin_abcdefgh"),
|
||||
@@ -1063,7 +1091,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
assert_eq!(env.get(key).map(String::as_str), Some(value), "{key}");
|
||||
}
|
||||
assert_eq!(
|
||||
env.get("OPENAI_BASE_URL").map(String::as_str),
|
||||
env.get("SNAPSHOT_BASE_URL").map(String::as_str),
|
||||
Some("https://api.snapshot.example/v1")
|
||||
);
|
||||
let explicit_vendor_policy = ShellEnvironmentPolicy {
|
||||
@@ -1116,15 +1144,15 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
policy
|
||||
.exclude
|
||||
.push(EnvironmentVariablePattern::new_case_insensitive(
|
||||
"OPENAI_BASE_URL",
|
||||
"SNAPSHOT_BASE_URL",
|
||||
));
|
||||
}
|
||||
let ambient_host = "https://api.ambient.example/v1";
|
||||
let mut restored_env =
|
||||
HashMap::from([("OPENAI_BASE_URL".to_string(), ambient_host.to_string())]);
|
||||
HashMap::from([("SNAPSHOT_BASE_URL".to_string(), ambient_host.to_string())]);
|
||||
let context = snapshot_file.restore_credentials(&mut restored_env, &policy);
|
||||
assert_eq!(
|
||||
restored_env["OPENAI_BASE_URL"],
|
||||
restored_env["SNAPSHOT_BASE_URL"],
|
||||
if excluded_context {
|
||||
ambient_host
|
||||
} else {
|
||||
@@ -1134,9 +1162,12 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
restored_env = context
|
||||
.prepare_child_environment(&network_proxy, restored_env, /*environment_id*/ None)?
|
||||
.env;
|
||||
assert_ne!(restored_env["OPENAI_API_KEY"], "sk-proj-snapshot-secret");
|
||||
assert_ne!(
|
||||
restored_env["SNAPSHOT_API_KEY"],
|
||||
"snapshot_abcdefghijklmnopqrstuvwx"
|
||||
);
|
||||
assert_eq!(
|
||||
restored_env["OPENAI_BASE_URL"],
|
||||
restored_env["SNAPSHOT_BASE_URL"],
|
||||
if excluded_context {
|
||||
ambient_host
|
||||
} else {
|
||||
@@ -1192,7 +1223,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
assert!(unbrokered_replay.status.success());
|
||||
assert_eq!(
|
||||
String::from_utf8(unbrokered_replay.stdout)?,
|
||||
"Bearer ghp_shell_only_secret\nGitHub ghp_shell_only_secret\nOpenAI sk-proj-snapshot-secret"
|
||||
"Bearer ghp_shell_only_secret\nGitHub ghp_shell_only_secret\nSnapshot snapshot_abcdefghijklmnopqrstuvwx"
|
||||
);
|
||||
|
||||
let mut cleared_local_context = HashMap::from([
|
||||
@@ -1217,7 +1248,7 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
assert_ne!(env["GH_TOKEN"], "ghp_shell_only_secret");
|
||||
assert_ne!(env["GITHUB_TOKEN"], "ghp_readonly_secret");
|
||||
assert_ne!(env["GH_ENTERPRISE_TOKEN"], "ghp_enterprise_secret");
|
||||
assert_ne!(env["OPENAI_API_KEY"], "sk-proj-snapshot-secret");
|
||||
assert_ne!(env["SNAPSHOT_API_KEY"], "snapshot_abcdefghijklmnopqrstuvwx");
|
||||
assert_ne!(
|
||||
env["STRIPE_API_KEY"],
|
||||
"stripe_live_abcdefghijklmnopqrstuvwx"
|
||||
@@ -1251,11 +1282,11 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
assert_eq!(
|
||||
String::from_utf8(replay.stdout)?,
|
||||
format!(
|
||||
"{}\nBearer {}\nGitHub {}\nOpenAI {}\n{}\n{}\nmissing\nBearer local_abcdefghijklmnopqrstuvwx",
|
||||
"{}\nBearer {}\nGitHub {}\nSnapshot {}\n{}\n{}\nmissing\nBearer local_abcdefghijklmnopqrstuvwx",
|
||||
env["GITHUB_TOKEN"],
|
||||
env["GH_TOKEN"],
|
||||
env["GH_TOKEN"],
|
||||
env["OPENAI_API_KEY"],
|
||||
env["SNAPSHOT_API_KEY"],
|
||||
env["VENDOR_PASSWORD"],
|
||||
env["VENDOR_HOST"]
|
||||
)
|
||||
@@ -1283,9 +1314,9 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
},
|
||||
allow_login_shell: false,
|
||||
};
|
||||
for (github_token, openai_api_key) in [
|
||||
("ghp_shell_only_secret", "sk-proj-snapshot-secret"),
|
||||
(env["GH_TOKEN"].as_str(), env["OPENAI_API_KEY"].as_str()),
|
||||
for (github_token, snapshot_api_key) in [
|
||||
("ghp_shell_only_secret", "snapshot_abcdefghijklmnopqrstuvwx"),
|
||||
(env["GH_TOKEN"].as_str(), env["SNAPSHOT_API_KEY"].as_str()),
|
||||
] {
|
||||
std::fs::write(
|
||||
&startup,
|
||||
@@ -1293,10 +1324,10 @@ async fn snapshot_discovers_and_redacts_shell_initialized_credentials() -> Resul
|
||||
"export GH_TOKEN='{github_token}'\n\
|
||||
export GITHUB_TOKEN=\"$GH_TOKEN\"\n\
|
||||
export AUTH_HEADER=\"Bearer $GH_TOKEN\"\n\
|
||||
export OPENAI_API_KEY='{openai_api_key}'\n\
|
||||
export SNAPSHOT_API_KEY='{snapshot_api_key}'\n\
|
||||
export AUTH_BUNDLE=\"GitHub $GH_TOKEN\n\
|
||||
OpenAI $OPENAI_API_KEY\"\n\
|
||||
unset OPENAI_API_KEY\n"
|
||||
Snapshot $SNAPSHOT_API_KEY\"\n\
|
||||
unset SNAPSHOT_API_KEY\n"
|
||||
),
|
||||
)?;
|
||||
let partially_filtered_path = dir.path().join("partially-filtered-snapshot.sh").abs();
|
||||
|
||||
Reference in New Issue
Block a user