Skip to content

Commit c77cba3

Browse files
author
Greyforge Admin
committed
Add verbose diagnostics to CLI commands
1 parent 7954d02 commit c77cba3

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

src/cortex-cli/src/agent_cmd/handlers/list.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use crate::agent_cmd::utils::matches_pattern;
99

1010
/// List agents command.
1111
pub async fn run_list(args: ListArgs) -> Result<()> {
12+
tracing::debug!(
13+
all = args.all,
14+
primary = args.primary,
15+
subagents = args.subagents,
16+
remote = args.remote,
17+
filter = ?args.filter,
18+
"listing agents"
19+
);
20+
1221
// Validate mutually exclusive flags
1322
if args.primary && args.subagents {
1423
bail!(
@@ -31,6 +40,7 @@ pub async fn run_list(args: ListArgs) -> Result<()> {
3140
}
3241

3342
let agents = load_all_agents()?;
43+
tracing::debug!(total_agents = agents.len(), "loaded agent definitions");
3444

3545
// Filter agents
3646
let mut filtered: Vec<_> = agents
@@ -56,6 +66,7 @@ pub async fn run_list(args: ListArgs) -> Result<()> {
5666
true
5767
})
5868
.collect();
69+
tracing::debug!(filtered_agents = filtered.len(), "filtered agent list");
5970

6071
// Sort by display_name (if present) or name for user-friendly ordering
6172
// This ensures agents are listed in the order users expect (by visible name)

src/cortex-cli/src/github_cmd.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ fn get_help_message() -> String {
587587
/// Check GitHub Actions installation status.
588588
async fn run_status(args: StatusArgs) -> Result<()> {
589589
let repo_path = args.path.unwrap_or_else(|| PathBuf::from("."));
590+
tracing::debug!(
591+
path = %repo_path.display(),
592+
json = args.json,
593+
"checking GitHub Actions installation status"
594+
);
590595

591596
let mut status = InstallationStatus::default();
592597

@@ -601,6 +606,10 @@ async fn run_status(args: StatusArgs) -> Result<()> {
601606
if content.contains("Cortex") {
602607
status.workflow_installed = true;
603608
status.workflow_path = Some(path.clone());
609+
tracing::debug!(
610+
workflow_path = %path.display(),
611+
"found Cortex workflow"
612+
);
604613

605614
// Check workflow features
606615
if content.contains("issue_comment") {
@@ -623,6 +632,13 @@ async fn run_status(args: StatusArgs) -> Result<()> {
623632

624633
// Check if we're in a git repo
625634
status.is_git_repo = repo_path.join(".git").exists();
635+
tracing::debug!(
636+
is_git_repo = status.is_git_repo,
637+
github_dir_exists = status.github_dir_exists,
638+
workflow_installed = status.workflow_installed,
639+
features = ?status.features,
640+
"computed GitHub Actions installation status"
641+
);
626642

627643
if args.json {
628644
let json = serde_json::to_string_pretty(&status)?;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use std::fs;
2+
use std::process::Command;
3+
4+
use tempfile::tempdir;
5+
6+
fn combined_output(output: &std::process::Output) -> String {
7+
format!(
8+
"{}{}",
9+
String::from_utf8_lossy(&output.stdout),
10+
String::from_utf8_lossy(&output.stderr)
11+
)
12+
}
13+
14+
#[test]
15+
fn verbose_agent_list_adds_diagnostics() {
16+
let home_dir = tempdir().unwrap();
17+
18+
let normal = Command::new(env!("CARGO_BIN_EXE_Cortex"))
19+
.args(["agent", "list"])
20+
.env("HOME", home_dir.path())
21+
.env_remove("CORTEX_HOME")
22+
.output()
23+
.unwrap();
24+
assert!(
25+
normal.status.success(),
26+
"normal agent list failed:\n{}",
27+
combined_output(&normal)
28+
);
29+
30+
let verbose = Command::new(env!("CARGO_BIN_EXE_Cortex"))
31+
.args(["--verbose", "agent", "list"])
32+
.env("HOME", home_dir.path())
33+
.env_remove("CORTEX_HOME")
34+
.output()
35+
.unwrap();
36+
assert!(
37+
verbose.status.success(),
38+
"verbose agent list failed:\n{}",
39+
combined_output(&verbose)
40+
);
41+
42+
let normal_output = combined_output(&normal);
43+
let verbose_output = combined_output(&verbose);
44+
assert_ne!(normal_output, verbose_output);
45+
assert!(verbose_output.contains("listing agents"));
46+
}
47+
48+
#[test]
49+
fn verbose_github_status_adds_diagnostics() {
50+
let repo = tempdir().unwrap();
51+
fs::create_dir(repo.path().join(".git")).unwrap();
52+
let workflows_dir = repo.path().join(".github").join("workflows");
53+
fs::create_dir_all(&workflows_dir).unwrap();
54+
fs::write(
55+
workflows_dir.join("Cortex.yml"),
56+
r#"# Cortex CI/CD Automation
57+
# Generated by: cortex github install
58+
59+
name: Cortex
60+
61+
on:
62+
workflow_dispatch:
63+
64+
jobs:
65+
cortex:
66+
runs-on: ubuntu-latest
67+
steps: []
68+
"#,
69+
)
70+
.unwrap();
71+
72+
let normal = Command::new(env!("CARGO_BIN_EXE_Cortex"))
73+
.args(["github", "status", "--path", repo.path().to_str().unwrap()])
74+
.output()
75+
.unwrap();
76+
assert!(
77+
normal.status.success(),
78+
"normal github status failed:\n{}",
79+
combined_output(&normal)
80+
);
81+
82+
let verbose = Command::new(env!("CARGO_BIN_EXE_Cortex"))
83+
.args([
84+
"--verbose",
85+
"github",
86+
"status",
87+
"--path",
88+
repo.path().to_str().unwrap(),
89+
])
90+
.output()
91+
.unwrap();
92+
assert!(
93+
verbose.status.success(),
94+
"verbose github status failed:\n{}",
95+
combined_output(&verbose)
96+
);
97+
98+
let normal_output = combined_output(&normal);
99+
let verbose_output = combined_output(&verbose);
100+
assert_ne!(normal_output, verbose_output);
101+
assert!(verbose_output.contains("checking GitHub Actions installation status"));
102+
}

0 commit comments

Comments
 (0)