fix(peer): clear remaining clippy warnings
`just clippy` was failing on peer test and helper code after the current lint set denied warnings. This keeps the cleanup local to the reported warnings and avoids changing runtime peer behavior or the wire protocol surface. The test helpers now avoid needless ownership, active-operation assertions take slices, and the local monitor watch-event helper no longer wraps a value that cannot fail. The install recovery matrix keeps the same cases, but moves the case table and per-case assertions into helpers so the test body stays below the clippy line limit. The remaining lint fixes replace similar temporary names and use an explicit `expect` message for test-only length conversion. No separate project documentation update is needed because this only changes internal test/helper structure and lint-only assertions; the existing peer architecture docs remain accurate. Test Plan: - just fmt - just clippy - just test - git diff --check - git diff --cached --check Refs: none
This commit is contained in:
@@ -1588,11 +1588,12 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_ctx(game_dir: PathBuf) -> Ctx {
|
||||
let state_dir = game_dir.join(".test-state");
|
||||
Ctx::new(
|
||||
Arc::new(RwLock::new(PeerGameDB::new())),
|
||||
"peer".to_string(),
|
||||
game_dir.clone(),
|
||||
game_dir.join(".test-state"),
|
||||
game_dir,
|
||||
state_dir,
|
||||
Arc::new(FakeUnpacker),
|
||||
CancellationToken::new(),
|
||||
TaskTracker::new(),
|
||||
@@ -1688,15 +1689,15 @@ mod tests {
|
||||
game
|
||||
}
|
||||
|
||||
fn assert_active_update(event: PeerEvent, expected: Vec<ActiveOperation>) {
|
||||
fn assert_active_update(event: PeerEvent, expected: &[ActiveOperation]) {
|
||||
let PeerEvent::ActiveOperationsChanged { active_operations } = event else {
|
||||
panic!("expected ActiveOperationsChanged");
|
||||
};
|
||||
assert_eq!(active_operations, expected);
|
||||
}
|
||||
|
||||
fn active_update(id: &str, operation: ActiveOperationKind) -> Vec<ActiveOperation> {
|
||||
vec![ActiveOperation {
|
||||
fn active_update(id: &str, operation: ActiveOperationKind) -> [ActiveOperation; 1] {
|
||||
[ActiveOperation {
|
||||
id: id.to_string(),
|
||||
operation,
|
||||
}]
|
||||
@@ -1934,7 +1935,7 @@ mod tests {
|
||||
);
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
vec![ActiveOperation {
|
||||
&[ActiveOperation {
|
||||
id: "game".to_string(),
|
||||
operation: ActiveOperationKind::Updating,
|
||||
}],
|
||||
@@ -1971,12 +1972,12 @@ mod tests {
|
||||
assert!(token.is_cancelled());
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
vec![ActiveOperation {
|
||||
&[ActiveOperation {
|
||||
id: "game".to_string(),
|
||||
operation: ActiveOperationKind::Updating,
|
||||
}],
|
||||
);
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(
|
||||
!ctx.active_operations.read().await.contains_key("game"),
|
||||
"timed-out drain should not leave the operation stuck active"
|
||||
@@ -2029,7 +2030,7 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Updating),
|
||||
&active_update("game", ActiveOperationKind::Updating),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
@@ -2038,7 +2039,7 @@ mod tests {
|
||||
operation: InstallOperation::Updating
|
||||
} if id == "game"
|
||||
));
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2060,7 +2061,7 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Installing),
|
||||
&active_update("game", ActiveOperationKind::Installing),
|
||||
);
|
||||
match recv_event(&mut rx).await {
|
||||
PeerEvent::InstallGameBegin { id, operation } => {
|
||||
@@ -2070,7 +2071,7 @@ mod tests {
|
||||
_ => panic!("expected InstallGameBegin"),
|
||||
}
|
||||
assert_local_update(recv_event(&mut rx).await, true, true);
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2121,7 +2122,7 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Installing),
|
||||
&active_update("game", ActiveOperationKind::Installing),
|
||||
);
|
||||
match recv_event(&mut rx).await {
|
||||
PeerEvent::InstallGameBegin { id, operation } => {
|
||||
@@ -2131,7 +2132,7 @@ mod tests {
|
||||
_ => panic!("expected InstallGameBegin"),
|
||||
}
|
||||
assert_local_update(recv_event(&mut rx).await, true, true);
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2181,7 +2182,7 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Updating),
|
||||
&active_update("game", ActiveOperationKind::Updating),
|
||||
);
|
||||
match recv_event(&mut rx).await {
|
||||
PeerEvent::InstallGameBegin { id, operation } => {
|
||||
@@ -2191,7 +2192,7 @@ mod tests {
|
||||
_ => panic!("expected InstallGameBegin"),
|
||||
}
|
||||
assert_local_update(recv_event(&mut rx).await, true, true);
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2212,7 +2213,7 @@ mod tests {
|
||||
run_install_operation(&ctx, &tx, "game".to_string()).await;
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Installing),
|
||||
&active_update("game", ActiveOperationKind::Installing),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
@@ -2223,7 +2224,7 @@ mod tests {
|
||||
));
|
||||
let game = local_update_game(recv_event(&mut rx).await, true, true);
|
||||
assert_eq!(game.local_version.as_deref(), Some("20240101"));
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2235,7 +2236,7 @@ mod tests {
|
||||
run_install_operation(&ctx, &tx, "game".to_string()).await;
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Updating),
|
||||
&active_update("game", ActiveOperationKind::Updating),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
@@ -2246,7 +2247,7 @@ mod tests {
|
||||
));
|
||||
let game = local_update_game(recv_event(&mut rx).await, true, true);
|
||||
assert_eq!(game.local_version.as_deref(), Some("20250101"));
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::InstallGameFinished { id } if id == "game"
|
||||
@@ -2255,7 +2256,7 @@ mod tests {
|
||||
run_uninstall_operation(&ctx, &tx, "game".to_string()).await;
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Uninstalling),
|
||||
&active_update("game", ActiveOperationKind::Uninstalling),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
@@ -2263,7 +2264,7 @@ mod tests {
|
||||
));
|
||||
let game = local_update_game(recv_event(&mut rx).await, false, true);
|
||||
assert_eq!(game.local_version.as_deref(), Some("20250101"));
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::UninstallGameFinished { id } if id == "game"
|
||||
@@ -2286,14 +2287,14 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::Uninstalling),
|
||||
&active_update("game", ActiveOperationKind::Uninstalling),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::UninstallGameBegin { id } if id == "game"
|
||||
));
|
||||
assert_local_update(recv_event(&mut rx).await, false, true);
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::UninstallGameFinished { id } if id == "game"
|
||||
@@ -2321,7 +2322,7 @@ mod tests {
|
||||
|
||||
assert_active_update(
|
||||
recv_event(&mut rx).await,
|
||||
active_update("game", ActiveOperationKind::RemovingDownload),
|
||||
&active_update("game", ActiveOperationKind::RemovingDownload),
|
||||
);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
@@ -2331,7 +2332,7 @@ mod tests {
|
||||
panic!("expected LocalLibraryChanged");
|
||||
};
|
||||
assert!(games.is_empty());
|
||||
assert_active_update(recv_event(&mut rx).await, Vec::new());
|
||||
assert_active_update(recv_event(&mut rx).await, &[]);
|
||||
assert!(matches!(
|
||||
recv_event(&mut rx).await,
|
||||
PeerEvent::RemoveDownloadedGameFinished { id } if id == "game"
|
||||
|
||||
Reference in New Issue
Block a user