From 66901af21433756413c7a36699522ea3c80f7a9e Mon Sep 17 00:00:00 2001 From: Bortlesboat Date: Tue, 12 May 2026 16:50:21 -0400 Subject: [PATCH] fix: avoid github status workflow false positives --- src/cortex-cli/src/github_cmd.rs | 7 ++- .../tests/github_status_workflow_detection.rs | 51 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/cortex-cli/tests/github_status_workflow_detection.rs diff --git a/src/cortex-cli/src/github_cmd.rs b/src/cortex-cli/src/github_cmd.rs index 83763b3bd..32ac81af3 100644 --- a/src/cortex-cli/src/github_cmd.rs +++ b/src/cortex-cli/src/github_cmd.rs @@ -584,6 +584,11 @@ fn get_help_message() -> String { .to_string() } +fn is_cortex_github_workflow(content: &str) -> bool { + content.contains("# Generated by: cortex github install") + && content.contains("cortex github run") +} + /// Check GitHub Actions installation status. async fn run_status(args: StatusArgs) -> Result<()> { let repo_path = args.path.unwrap_or_else(|| PathBuf::from(".")); @@ -598,7 +603,7 @@ async fn run_status(args: StatusArgs) -> Result<()> { let path = entry.path(); if path.extension().is_some_and(|e| e == "yml" || e == "yaml") { let content = std::fs::read_to_string(&path)?; - if content.contains("Cortex") { + if is_cortex_github_workflow(&content) { status.workflow_installed = true; status.workflow_path = Some(path.clone()); diff --git a/src/cortex-cli/tests/github_status_workflow_detection.rs b/src/cortex-cli/tests/github_status_workflow_detection.rs new file mode 100644 index 000000000..2ec889d41 --- /dev/null +++ b/src/cortex-cli/tests/github_status_workflow_detection.rs @@ -0,0 +1,51 @@ +use std::fs; +use std::process::Command; + +#[test] +fn github_status_rejects_unrelated_workflow_that_mentions_cortex() { + let repo = tempfile::tempdir().expect("create temp repo"); + fs::create_dir(repo.path().join(".git")).expect("create .git dir"); + let workflows_dir = repo.path().join(".github").join("workflows"); + fs::create_dir_all(&workflows_dir).expect("create workflows dir"); + fs::write( + workflows_dir.join("homebrew.yml"), + r#"name: Homebrew Release + +on: + push: + tags: + - "v*" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Publish unrelated package + with: + formula-name: Cortex +"#, + ) + .expect("write unrelated workflow"); + + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) + .args(["github", "status", "--json", "--path"]) + .arg(repo.path()) + .output() + .expect("run Cortex github status"); + + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + + assert!( + !output.status.success(), + "unrelated workflow should not be treated as installed\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + + let status: serde_json::Value = + serde_json::from_str(&stdout).expect("status output should be JSON"); + assert_eq!( + status["workflow_installed"], + serde_json::Value::Bool(false), + "status should reject unrelated workflow content\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); +}