mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(desktop): repair clippy and doc-comment issues from pass-3 corrections
- backfill.rs: remove blank line between two consecutive doc comment blocks - detach.rs: merge orphaned step-list doc comment into function doc comment - migration.rs: remove blank line after doc comment before private fn - migration_tests.rs, migration_command_tests.rs, migration_avatar_tests.rs, migration_databricks_tests.rs: add .unwrap() to calls that now return Result after C5 migration fallibility changes Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
co-authored by
Will Pfleger
parent
b0cc726d3f
commit
db225c63dd
@@ -1162,7 +1162,6 @@ fn reconcile_databricks_v1_to_v2_in_file(
|
||||
/// Covers both the current app data dir and the canonical dev data dir
|
||||
/// (for worktree instances) — same dual-dir pattern as
|
||||
/// `reconcile_legacy_command_names` and `reconcile_provider_mcp_commands`.
|
||||
|
||||
fn rename_provider_to_runtime_in_personas(path: &Path) {
|
||||
if let Err(e) = patch_json_records(path, |obj| {
|
||||
if obj.contains_key("runtime") {
|
||||
|
||||
@@ -31,7 +31,6 @@ use crate::managed_agents::{
|
||||
/// The manufactured definition's slug is the agent's pubkey: 64-hex passes
|
||||
/// the NIP-AP slug grammar on both relay and desktop ends, and agent pubkeys
|
||||
/// are unique, so the coordinate is collision-free by construction.
|
||||
|
||||
/// Core backfill logic, decoupled from the Tauri `AppHandle` for testing.
|
||||
/// Returns the number of records backfilled (0 = nothing to do).
|
||||
pub(crate) fn backfill_standalone_agents_in_dir(base_dir: &Path) -> Result<usize, String> {
|
||||
|
||||
@@ -9,10 +9,8 @@ use crate::managed_agents::{ManagedAgentRecord, TeamRecord};
|
||||
/// Lift pack instructions into `TeamRecord.instructions` and detach
|
||||
/// directory-backed teams from their source directories.
|
||||
///
|
||||
/// Runs on app launch if any `TeamRecord` still has `source_dir` set.
|
||||
/// Both output files are written atomically (temp-file + rename), so a crash
|
||||
/// mid-write leaves the previous version intact and the migration can safely
|
||||
/// retry on next boot.
|
||||
/// `base_dir` is the managed-agents base directory (`<AppDataDir>/agents/`).
|
||||
/// Returns the number of teams detached (0 = nothing to do).
|
||||
///
|
||||
/// Steps (written last so the idempotency gate stays open until both files
|
||||
/// are committed):
|
||||
@@ -24,10 +22,6 @@ use crate::managed_agents::{ManagedAgentRecord, TeamRecord};
|
||||
/// `instructions` if the field is not already set.
|
||||
/// 4. Clear `source_dir`, `is_symlink`, `symlink_target`, `version` on each
|
||||
/// directory-backed `TeamRecord`.
|
||||
/// Core logic, decoupled from the Tauri `AppHandle` for testing.
|
||||
///
|
||||
/// `base_dir` is the managed-agents base directory (`<AppDataDir>/agents/`).
|
||||
/// Returns the number of teams detached (0 = nothing to do).
|
||||
pub(crate) fn detach_directory_backed_teams_in_dir(base_dir: &Path) -> Result<usize, String> {
|
||||
let teams_path = base_dir.join("teams.json");
|
||||
let agents_path = base_dir.join("managed-agents.json");
|
||||
|
||||
@@ -106,7 +106,7 @@ fn refresh_builtin_agent_avatars_updates_seeded_values_and_preserves_customizati
|
||||
]);
|
||||
std::fs::write(&path, serde_json::to_vec_pretty(&records).unwrap()).unwrap();
|
||||
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after");
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after").unwrap();
|
||||
|
||||
let migrated: Vec<serde_json::Value> =
|
||||
serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
||||
@@ -141,7 +141,7 @@ fn refresh_builtin_agent_avatars_updates_seeded_values_and_preserves_customizati
|
||||
assert_eq!(migrated[4]["updated_at"], "before");
|
||||
|
||||
let once = std::fs::read(&path).unwrap();
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "later");
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "later").unwrap();
|
||||
assert_eq!(std::fs::read(&path).unwrap(), once);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ fn refresh_builtin_agent_avatars_updates_versions_without_stored_definitions() {
|
||||
]);
|
||||
std::fs::write(&path, serde_json::to_vec_pretty(&records).unwrap()).unwrap();
|
||||
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after");
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after").unwrap();
|
||||
|
||||
let migrated: Vec<serde_json::Value> =
|
||||
serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
||||
@@ -272,7 +272,7 @@ fn refresh_builtin_agent_avatars_updates_uploaded_media_urls() {
|
||||
]);
|
||||
std::fs::write(&path, serde_json::to_vec_pretty(&records).unwrap()).unwrap();
|
||||
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after");
|
||||
refresh_builtin_agent_avatars_in_file(&path, &legacy_avatars, "after").unwrap();
|
||||
|
||||
let migrated: Vec<serde_json::Value> =
|
||||
serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
||||
|
||||
@@ -14,7 +14,7 @@ fn reconcile_legacy_command_names_rewrites_renamed_sidecars() {
|
||||
}]),
|
||||
);
|
||||
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["acp_command"], "buzz-acp");
|
||||
@@ -35,7 +35,7 @@ fn reconcile_legacy_command_names_updates_removed_mcp_server_for_buzz_agent() {
|
||||
}]),
|
||||
);
|
||||
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["acp_command"], "buzz-acp");
|
||||
@@ -56,7 +56,7 @@ fn reconcile_legacy_command_names_clears_removed_mcp_server_for_goose() {
|
||||
}]),
|
||||
);
|
||||
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_legacy_command_names_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["acp_command"], "buzz-acp");
|
||||
@@ -77,7 +77,7 @@ fn reconcile_legacy_command_names_preserves_custom_commands() {
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
|
||||
reconcile_legacy_command_names_in_file(&path);
|
||||
reconcile_legacy_command_names_in_file(&path).unwrap();
|
||||
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ fn reconcile_databricks_v1_to_v2_rewrites_v1_provider_on_block_build() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(
|
||||
@@ -56,7 +57,8 @@ fn reconcile_databricks_v1_to_v2_preserves_v1_provider_on_oss_build() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ false,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
// Provider field preserved.
|
||||
@@ -92,7 +94,8 @@ fn reconcile_databricks_v1_to_v2_clears_model_on_provider_rewrite() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
// V1 records: provider migrated, model cleared.
|
||||
@@ -126,7 +129,7 @@ fn reconcile_databricks_v1_to_v2_preserves_v2_provider() {
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true);
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true).unwrap();
|
||||
|
||||
// File must be unchanged — no spurious re-write.
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
@@ -151,7 +154,8 @@ fn reconcile_databricks_v1_to_v2_strips_stale_buzz_agent_provider_from_env_vars(
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
// Stale derived key must be removed.
|
||||
@@ -188,7 +192,8 @@ fn reconcile_databricks_v1_to_v2_strips_all_derived_keys_from_env_vars() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
let env_vars = &records[0]["env_vars"];
|
||||
@@ -230,7 +235,8 @@ fn reconcile_databricks_v1_to_v2_handles_multiple_records_block_build() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
// A: provider rewritten, stale env_var stripped.
|
||||
@@ -256,9 +262,9 @@ fn reconcile_databricks_v1_to_v2_is_idempotent() {
|
||||
);
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true);
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true).unwrap();
|
||||
let after_first = std::fs::read_to_string(&path).unwrap();
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true);
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true).unwrap();
|
||||
let after_second = std::fs::read_to_string(&path).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
@@ -279,7 +285,7 @@ fn reconcile_databricks_v1_to_v2_preserves_non_databricks_providers() {
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true);
|
||||
reconcile_databricks_v1_to_v2_in_file(&path, /*rewrite_v1_provider=*/ true).unwrap();
|
||||
|
||||
// No provider is modified, so the file content is identical.
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
@@ -310,7 +316,8 @@ fn reconcile_databricks_v1_to_v2_strips_derived_keys_from_keyless_persona_defini
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
let env_vars = &records[0]["env_vars"];
|
||||
@@ -348,7 +355,8 @@ fn reconcile_databricks_v1_to_v2_strips_derived_keys_case_insensitively() {
|
||||
reconcile_databricks_v1_to_v2_in_file(
|
||||
&dir.path().join("agents/managed-agents.json"),
|
||||
/*rewrite_v1_provider=*/ true,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let records = read_agents_json(dir.path());
|
||||
let env_vars = &records[0]["env_vars"];
|
||||
|
||||
@@ -538,7 +538,8 @@ fn patch_json_records_rewrites_secret_store_owner_only() {
|
||||
let provider = obj.remove("provider").unwrap();
|
||||
obj.insert("runtime".to_string(), provider);
|
||||
true
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let mode = std::fs::metadata(&path).unwrap().permissions().mode() & 0o777;
|
||||
assert_eq!(mode, 0o600, "secret-bearing rewrite must be owner-only");
|
||||
@@ -633,7 +634,7 @@ fn reconcile_mcp_commands_clears_stale_buzz_mcp_server() {
|
||||
"mcp_command": "buzz-mcp-server"
|
||||
}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["mcp_command"], "");
|
||||
}
|
||||
@@ -649,7 +650,7 @@ fn reconcile_mcp_commands_sets_canonical_for_buzz_agent() {
|
||||
"mcp_command": "buzz-mcp-server"
|
||||
}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["mcp_command"], "buzz-dev-mcp");
|
||||
}
|
||||
@@ -665,7 +666,7 @@ fn reconcile_mcp_commands_leaves_custom_value_untouched() {
|
||||
write_agents_json(dir.path(), &json);
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
reconcile_mcp_commands_in_file(&path);
|
||||
reconcile_mcp_commands_in_file(&path).unwrap();
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
}
|
||||
|
||||
@@ -680,7 +681,7 @@ fn reconcile_mcp_commands_leaves_unknown_runtime_untouched() {
|
||||
write_agents_json(dir.path(), &json);
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
reconcile_mcp_commands_in_file(&path);
|
||||
reconcile_mcp_commands_in_file(&path).unwrap();
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
}
|
||||
|
||||
@@ -696,9 +697,9 @@ fn reconcile_mcp_commands_is_idempotent() {
|
||||
}]),
|
||||
);
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
reconcile_mcp_commands_in_file(&path);
|
||||
reconcile_mcp_commands_in_file(&path).unwrap();
|
||||
let after_first = std::fs::read_to_string(&path).unwrap();
|
||||
reconcile_mcp_commands_in_file(&path);
|
||||
reconcile_mcp_commands_in_file(&path).unwrap();
|
||||
assert_eq!(after_first, std::fs::read_to_string(&path).unwrap());
|
||||
}
|
||||
|
||||
@@ -714,7 +715,7 @@ fn reconcile_mcp_commands_handles_mixed_agents() {
|
||||
{"name": "Stale Buzz", "agent_command": "buzz-agent", "mcp_command": "buzz-mcp-server"}
|
||||
]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["mcp_command"], "");
|
||||
assert_eq!(records[1]["mcp_command"], "");
|
||||
@@ -741,7 +742,7 @@ fn reconcile_mcp_commands_resolves_persona_runtime_over_stale_snapshot() {
|
||||
dir.path(),
|
||||
&serde_json::json!([{"id": "p1", "runtime": "goose"}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["mcp_command"], "");
|
||||
}
|
||||
@@ -771,7 +772,7 @@ fn reconcile_mcp_commands_sees_team_dir_runtime_edit_same_launch() {
|
||||
dir.path(),
|
||||
&serde_json::json!([{"id": "p1", "runtime": "goose"}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
assert_eq!(
|
||||
read_agents_json(dir.path())[0]["mcp_command"],
|
||||
"",
|
||||
@@ -785,7 +786,7 @@ fn reconcile_mcp_commands_sees_team_dir_runtime_edit_same_launch() {
|
||||
dir.path(),
|
||||
&serde_json::json!([{"id": "p1", "runtime": "buzz-agent"}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
assert_eq!(
|
||||
read_agents_json(dir.path())[0]["mcp_command"],
|
||||
"buzz-dev-mcp",
|
||||
@@ -813,7 +814,7 @@ fn reconcile_mcp_commands_honors_explicit_override_over_persona() {
|
||||
dir.path(),
|
||||
&serde_json::json!([{"id": "p1", "runtime": "goose"}]),
|
||||
);
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
|
||||
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json")).unwrap();
|
||||
let records = read_agents_json(dir.path());
|
||||
assert_eq!(records[0]["mcp_command"], "buzz-dev-mcp");
|
||||
}
|
||||
@@ -828,7 +829,7 @@ fn reconcile_mcp_commands_skips_record_without_agent_command() {
|
||||
write_agents_json(dir.path(), &json);
|
||||
let path = dir.path().join("agents/managed-agents.json");
|
||||
let before = std::fs::read_to_string(&path).unwrap();
|
||||
reconcile_mcp_commands_in_file(&path);
|
||||
reconcile_mcp_commands_in_file(&path).unwrap();
|
||||
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user