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
7 changes: 6 additions & 1 deletion src/cortex-cli/src/github_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("."));
Expand All @@ -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());

Expand Down
51 changes: 51 additions & 0 deletions src/cortex-cli/tests/github_status_workflow_detection.rs
Original file line number Diff line number Diff line change
@@ -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}"
);
}