test(app): a key replaced or a server removed through the admin API while running stays masked

Covers the admin paths (`mcp_env_set`, `settings_apply` removing a server): after the services
started with the old values, a late worker line carrying them is masked on the log screen and in
the error report. Fails with the in-use values dropped from the masks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-13 20:39:00 +09:00
parent 71f9b0cd54
commit d531eb0ffc

View File

@@ -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");