diff --git a/app/src/admin_api.rs b/app/src/admin_api.rs index ed43585..cb74928 100644 --- a/app/src/admin_api.rs +++ b/app/src/admin_api.rs @@ -422,6 +422,32 @@ mod tests { assert!(secrets.names().unwrap().iter().all(|n| !n.starts_with("mcp:"))); } + #[tokio::test] + async fn a_key_replaced_or_a_server_removed_while_running_stays_masked_in_late_worker_lines() { + let (a, base) = api("api-mcp-run"); + let data = base.join("d"); + a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap(); + let servers = json!([{"name": "brave", "command": "npx", "env": ["BRAVE_API_KEY"]}, + {"name": "other", "command": "npx", "env": ["OTHER_KEY"]}]); + a.call("settings_apply", json!({"changes": {"mcpServers": servers}})).await.unwrap(); + a.call("mcp_env_set", json!({"server": "brave", "name": "BRAVE_API_KEY", "value": "old-brave-key"})).await.unwrap(); + a.call("mcp_env_set", json!({"server": "other", "name": "OTHER_KEY", "value": "old-other-key"})).await.unwrap(); + // The services start with these values (services.rs does this on every start). + a.hub.set_secrets_in_use(vec!["old-brave-key".into(), "old-other-key".into()]); + // While they run, one key is replaced and the other server is removed. + a.call("mcp_env_set", json!({"server": "brave", "name": "BRAVE_API_KEY", "value": "new-brave-key"})).await.unwrap(); + let brave = json!([{"name": "brave", "command": "npx", "env": ["BRAVE_API_KEY"]}]); + a.call("settings_apply", json!({"changes": {"mcpServers": brave}})).await.unwrap(); + // The running worker still prints the old values afterwards. + a.hub.push_worker("[ llm ] Error: brave failed with old-brave-key, other with old-other-key"); + let shown = a.call("logs_query", json!({})).await.unwrap().to_string(); + let report = a.call("logs_error_report", json!({})).await.unwrap()["report"].as_str().unwrap().to_owned(); + assert!(report.contains("brave failed with"), "{report}"); + for old in ["old-brave-key", "old-other-key"] { + assert!(!shown.contains(old) && !report.contains(old), "{old}"); + } + } + #[tokio::test] async fn the_dashboard_answers_before_anything_runs() { let (a, base) = api("api3");