Skip to content

Commit 8fd7c50

Browse files
style: apply cargo fmt across all workspace crates
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 24070ea commit 8fd7c50

16 files changed

Lines changed: 1834 additions & 903 deletions

File tree

rsworkspace/crates/discord-agent/src/agent.rs

Lines changed: 125 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
385385
let update_subject = discord_nats::subjects::bot::guild_update(self.subscriber.prefix());
386386
let delete_subject = discord_nats::subjects::bot::guild_delete(self.subscriber.prefix());
387387

388-
info!("Subscribing to guild lifecycle: {}, {}, {}", create_subject, update_subject, delete_subject);
388+
info!(
389+
"Subscribing to guild lifecycle: {}, {}, {}",
390+
create_subject, update_subject, delete_subject
391+
);
389392

390393
let mut create_stream = self
391394
.subscriber
@@ -458,7 +461,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
458461
let update_subject = discord_nats::subjects::bot::channel_update(self.subscriber.prefix());
459462
let delete_subject = discord_nats::subjects::bot::channel_delete(self.subscriber.prefix());
460463

461-
info!("Subscribing to channel lifecycle: {}, {}, {}", create_subject, update_subject, delete_subject);
464+
info!(
465+
"Subscribing to channel lifecycle: {}, {}, {}",
466+
create_subject, update_subject, delete_subject
467+
);
462468

463469
let mut create_stream = self
464470
.subscriber
@@ -531,7 +537,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
531537
let update_subject = discord_nats::subjects::bot::role_update(self.subscriber.prefix());
532538
let delete_subject = discord_nats::subjects::bot::role_delete(self.subscriber.prefix());
533539

534-
info!("Subscribing to role lifecycle: {}, {}, {}", create_subject, update_subject, delete_subject);
540+
info!(
541+
"Subscribing to role lifecycle: {}, {}, {}",
542+
create_subject, update_subject, delete_subject
543+
);
535544

536545
let mut create_stream = self
537546
.subscriber
@@ -652,7 +661,8 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
652661
async fn handle_autocomplete(&self) -> Result<()> {
653662
use discord_types::events::AutocompleteEvent;
654663

655-
let subject = discord_nats::subjects::bot::interaction_autocomplete(self.subscriber.prefix());
664+
let subject =
665+
discord_nats::subjects::bot::interaction_autocomplete(self.subscriber.prefix());
656666
info!("Subscribing to autocomplete: {}", subject);
657667

658668
let mut stream = self
@@ -832,8 +842,20 @@ mod tests {
832842
let client = MockNatsClient::new();
833843
let publisher = MockPublisher::new("test");
834844
DiscordAgent::new(
835-
client, "test".to_string(), publisher, "test-agent".to_string(),
836-
None, None, None, None, None, None, None, 20, 120, None,
845+
client,
846+
"test".to_string(),
847+
publisher,
848+
"test-agent".to_string(),
849+
None,
850+
None,
851+
None,
852+
None,
853+
None,
854+
None,
855+
None,
856+
20,
857+
120,
858+
None,
837859
)
838860
}
839861

@@ -851,7 +873,12 @@ mod tests {
851873
id: message_id,
852874
channel_id,
853875
guild_id: None,
854-
author: DiscordUser { id: 42, username: "tester".to_string(), global_name: None, bot: false },
876+
author: DiscordUser {
877+
id: 42,
878+
username: "tester".to_string(),
879+
global_name: None,
880+
bot: false,
881+
},
855882
content: content.to_string(),
856883
timestamp: "2024-01-01T00:00:00Z".to_string(),
857884
edited_timestamp: None,
@@ -878,7 +905,10 @@ mod tests {
878905
async fn test_agent_run_returns_err_when_subscribe_fails() {
879906
let agent = make_agent();
880907
let result = agent.run().await;
881-
assert!(result.is_err(), "run() must return Err when subscribe fails");
908+
assert!(
909+
result.is_err(),
910+
"run() must return Err when subscribe fails"
911+
);
882912
let msg = result.unwrap_err().to_string();
883913
assert!(!msg.is_empty(), "error must have a message");
884914
}
@@ -891,15 +921,30 @@ mod tests {
891921
let pub_ref = MockPublisher::new("test");
892922
let event = make_message_event("sess-1", "hello world", 100, 50);
893923

894-
agent.processor.process_message(&event, &pub_ref).await.unwrap();
924+
agent
925+
.processor
926+
.process_message(&event, &pub_ref)
927+
.await
928+
.unwrap();
895929

896930
let msgs = pub_ref.published_messages();
897-
assert_eq!(msgs.len(), 2, "echo mode must publish typing + send_message");
931+
assert_eq!(
932+
msgs.len(),
933+
2,
934+
"echo mode must publish typing + send_message"
935+
);
898936
let cmd: discord_types::SendMessageCommand =
899937
serde_json::from_value(msgs[1].1.clone()).unwrap();
900938
assert_eq!(cmd.channel_id, 100, "send must target the right channel");
901-
assert!(cmd.content.contains("hello world"), "send must echo the content");
902-
assert_eq!(cmd.reply_to_message_id, Some(50), "send must reply to the original message");
939+
assert!(
940+
cmd.content.contains("hello world"),
941+
"send must echo the content"
942+
);
943+
assert_eq!(
944+
cmd.reply_to_message_id,
945+
Some(50),
946+
"send must reply to the original message"
947+
);
903948
}
904949

905950
/// With ack_emoji: process_message publishes ack_reaction first, then typing, then send_message.
@@ -909,21 +954,49 @@ mod tests {
909954
let client = MockNatsClient::new();
910955
let publisher = MockPublisher::new("test");
911956
let agent = DiscordAgent::new(
912-
client, "test".to_string(), publisher, "ack-agent".to_string(),
913-
None, None, None, None, None, None, None, 20, 120, Some("⏳".to_string()),
957+
client,
958+
"test".to_string(),
959+
publisher,
960+
"ack-agent".to_string(),
961+
None,
962+
None,
963+
None,
964+
None,
965+
None,
966+
None,
967+
None,
968+
20,
969+
120,
970+
Some("⏳".to_string()),
914971
);
915972
let pub_ref = MockPublisher::new("test");
916973
let event = make_message_event("sess-2", "help me", 200, 99);
917974

918-
agent.processor.process_message(&event, &pub_ref).await.unwrap();
975+
agent
976+
.processor
977+
.process_message(&event, &pub_ref)
978+
.await
979+
.unwrap();
919980

920981
let msgs = pub_ref.published_messages();
921-
assert!(msgs.len() >= 3, "with ack_emoji: must publish ack_reaction + typing + send_message");
982+
assert!(
983+
msgs.len() >= 3,
984+
"with ack_emoji: must publish ack_reaction + typing + send_message"
985+
);
922986
let reaction: discord_types::AddReactionCommand =
923987
serde_json::from_value(msgs[0].1.clone()).unwrap();
924-
assert_eq!(reaction.emoji, "⏳", "ack reaction must use the configured emoji");
925-
assert_eq!(reaction.message_id, 99, "ack reaction must target the original message");
926-
assert_eq!(reaction.channel_id, 200, "ack reaction must be in the right channel");
988+
assert_eq!(
989+
reaction.emoji, "⏳",
990+
"ack reaction must use the configured emoji"
991+
);
992+
assert_eq!(
993+
reaction.message_id, 99,
994+
"ack reaction must target the original message"
995+
);
996+
assert_eq!(
997+
reaction.channel_id, 200,
998+
"ack reaction must be in the right channel"
999+
);
9271000
}
9281001

9291002
/// Two agents with different prefixes must not share publisher state.
@@ -932,16 +1005,44 @@ mod tests {
9321005
let pub_a = MockPublisher::new("pfx-a");
9331006
let pub_b = MockPublisher::new("pfx-b");
9341007
let agent_a = DiscordAgent::new(
935-
MockNatsClient::new(), "pfx-a".to_string(), pub_a.clone(), "agent-a".to_string(),
936-
None, None, None, None, None, None, None, 20, 120, None,
1008+
MockNatsClient::new(),
1009+
"pfx-a".to_string(),
1010+
pub_a.clone(),
1011+
"agent-a".to_string(),
1012+
None,
1013+
None,
1014+
None,
1015+
None,
1016+
None,
1017+
None,
1018+
None,
1019+
20,
1020+
120,
1021+
None,
9371022
);
9381023
let agent_b = DiscordAgent::new(
939-
MockNatsClient::new(), "pfx-b".to_string(), pub_b.clone(), "agent-b".to_string(),
940-
None, None, None, None, None, None, None, 20, 120, None,
1024+
MockNatsClient::new(),
1025+
"pfx-b".to_string(),
1026+
pub_b.clone(),
1027+
"agent-b".to_string(),
1028+
None,
1029+
None,
1030+
None,
1031+
None,
1032+
None,
1033+
None,
1034+
None,
1035+
20,
1036+
120,
1037+
None,
9411038
);
9421039

9431040
let event = make_message_event("sess-a", "ping", 100, 1);
944-
agent_a.processor.process_message(&event, &pub_a).await.unwrap();
1041+
agent_a
1042+
.processor
1043+
.process_message(&event, &pub_a)
1044+
.await
1045+
.unwrap();
9451046

9461047
assert!(!pub_a.is_empty(), "agent_a's publisher must have messages");
9471048
assert!(pub_b.is_empty(), "agent_b's publisher must be unaffected");

rsworkspace/crates/discord-agent/src/llm.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ mod tests {
238238
#[test]
239239
fn test_sse_unknown_top_level_fields_do_not_panic() {
240240
// Claude API may add new top-level fields; we must not fail on them
241-
let json = r#"{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}"#;
241+
let json =
242+
r#"{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}"#;
242243
let event: SseEvent = serde_json::from_str(json).unwrap();
243244
assert_eq!(event.event_type, "content_block_start");
244245
assert!(event.delta.is_none());
@@ -341,10 +342,9 @@ mod tests {
341342
let server = MockServer::start().await;
342343
Mock::given(method("POST"))
343344
.and(path("/v1/messages"))
344-
.respond_with(
345-
ResponseTemplate::new(401)
346-
.set_body_string(r#"{"error":{"type":"authentication_error","message":"Invalid API key"}}"#),
347-
)
345+
.respond_with(ResponseTemplate::new(401).set_body_string(
346+
r#"{"error":{"type":"authentication_error","message":"Invalid API key"}}"#,
347+
))
348348
.mount(&server)
349349
.await;
350350

@@ -402,8 +402,16 @@ mod tests {
402402
let client = ClaudeClient::new(config);
403403

404404
let history = vec![
405-
Message { role: "user".to_string(), content: "previous user message".to_string(), message_id: Some(1) },
406-
Message { role: "assistant".to_string(), content: "previous reply".to_string(), message_id: None },
405+
Message {
406+
role: "user".to_string(),
407+
content: "previous user message".to_string(),
408+
message_id: Some(1),
409+
},
410+
Message {
411+
role: "assistant".to_string(),
412+
content: "previous reply".to_string(),
413+
message_id: None,
414+
},
407415
];
408416

409417
let (tx, _rx) = mpsc::channel::<String>(16);

rsworkspace/crates/discord-agent/src/processor.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use discord_types::{
99
GuildMemberAddEvent, GuildMemberRemoveEvent, GuildMemberUpdateEvent, GuildUpdateEvent,
1010
MessageCreatedEvent, MessageDeletedEvent, MessageUpdatedEvent, ModalSubmitEvent,
1111
PresenceUpdateEvent, ReactionAddEvent, ReactionRemoveEvent, RoleCreateEvent,
12-
RoleDeleteEvent, RoleUpdateEvent, SlashCommandEvent, TypingStartEvent, VoiceStateUpdateEvent,
12+
RoleDeleteEvent, RoleUpdateEvent, SlashCommandEvent, TypingStartEvent,
13+
VoiceStateUpdateEvent,
1314
},
1415
types::{Attachment, ChannelType},
1516
AddReactionCommand, AutocompleteChoice, AutocompleteRespondCommand, InteractionDeferCommand,
16-
InteractionFollowupCommand, InteractionRespondCommand, SendMessageCommand, StreamMessageCommand,
17-
TypingCommand,
17+
InteractionFollowupCommand, InteractionRespondCommand, SendMessageCommand,
18+
StreamMessageCommand, TypingCommand,
1819
};
1920
use tokio::time::{Duration, Instant};
2021
use tracing::{debug, info, warn};
@@ -995,10 +996,7 @@ impl MessageProcessor {
995996
// This covers the most common case: the user deletes the bot's most recent
996997
// message to request a fresh response.
997998
let len = history.len();
998-
if len >= 2
999-
&& history[len - 1].role == "assistant"
1000-
&& history[len - 2].role == "user"
1001-
{
999+
if len >= 2 && history[len - 1].role == "assistant" && history[len - 2].role == "user" {
10021000
debug!(
10031001
"Removing last user+assistant pair from session {} (heuristic: assistant message deleted)",
10041002
session_id
@@ -1578,7 +1576,10 @@ impl MessageProcessor {
15781576
}
15791577

15801578
pub async fn process_guild_update(&self, event: &GuildUpdateEvent) -> Result<()> {
1581-
debug!("Guild '{}' updated (id: {})", event.guild.name, event.guild.id);
1579+
debug!(
1580+
"Guild '{}' updated (id: {})",
1581+
event.guild.name, event.guild.id
1582+
);
15821583
Ok(())
15831584
}
15841585

0 commit comments

Comments
 (0)