Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/cortex-cli/src/agent_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#[cfg(test)]
mod tests {
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
use crate::agent_cmd::loader::{
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
};
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
use crate::agent_cmd::types::AgentMode;
use crate::utils::file::read_file_with_encoding;

#[test]
fn test_read_file_with_utf8() {
Expand Down
51 changes: 36 additions & 15 deletions src/cortex-cli/src/github_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,7 @@ async fn handle_issue_comment(
client.add_reaction(comment.comment_id, "eyes").await?;

// Process the command
let response = match command.as_str() {
"help" => get_help_message(),
"review" => {
if comment.is_pull_request {
"Starting code review... (not yet implemented)".to_string()
} else {
"This command is only available on pull requests.".to_string()
}
}
"fix" => "Analyzing and suggesting fixes... (not yet implemented)".to_string(),
_ => format!(
"Unknown command: `{}`\n\nUse `/cortex help` to see available commands.",
command
),
};
let response = build_cortex_command_response(&command, comment.is_pull_request);

// Post response comment
client
Expand All @@ -439,6 +425,26 @@ async fn handle_issue_comment(
Ok(())
}

fn build_cortex_command_response(command: &str, is_pull_request: bool) -> String {
match command {
"help" => get_help_message(),
"review" => {
if is_pull_request {
"Starting code review... (not yet implemented)".to_string()
} else {
"This command is only available on pull requests.".to_string()
}
}
"fix" => "Analyzing and suggesting fixes... (not yet implemented)".to_string(),
"explain" => "Explaining code changes... (not yet implemented)".to_string(),
"test" => "Suggesting tests for changes... (not yet implemented)".to_string(),
_ => format!(
"Unknown command: `{}`\n\nUse `/cortex help` to see available commands.",
command
),
}
}

/// Handle pull request events.
async fn handle_pull_request(
token: &str,
Expand Down Expand Up @@ -845,6 +851,21 @@ mod tests {
let help = get_help_message();
assert!(help.contains("/cortex help"));
assert!(help.contains("/cortex review"));
assert!(help.contains("/cortex explain"));
assert!(help.contains("/cortex test"));
}

#[test]
fn test_advertised_commands_have_responses() {
for command in ["explain", "test"] {
let response = build_cortex_command_response(command, true);

assert!(
!response.contains("Unknown command"),
"{command} should not return unknown-command help"
);
assert!(response.contains("not yet implemented"));
}
}

#[tokio::test]
Expand Down