Skip to content

Commit 66901af

Browse files
committed
fix: avoid github status workflow false positives
1 parent 7954d02 commit 66901af

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

src/cortex-cli/src/github_cmd.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ fn get_help_message() -> String {
584584
.to_string()
585585
}
586586

587+
fn is_cortex_github_workflow(content: &str) -> bool {
588+
content.contains("# Generated by: cortex github install")
589+
&& content.contains("cortex github run")
590+
}
591+
587592
/// Check GitHub Actions installation status.
588593
async fn run_status(args: StatusArgs) -> Result<()> {
589594
let repo_path = args.path.unwrap_or_else(|| PathBuf::from("."));
@@ -598,7 +603,7 @@ async fn run_status(args: StatusArgs) -> Result<()> {
598603
let path = entry.path();
599604
if path.extension().is_some_and(|e| e == "yml" || e == "yaml") {
600605
let content = std::fs::read_to_string(&path)?;
601-
if content.contains("Cortex") {
606+
if is_cortex_github_workflow(&content) {
602607
status.workflow_installed = true;
603608
status.workflow_path = Some(path.clone());
604609

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use std::fs;
2+
use std::process::Command;
3+
4+
#[test]
5+
fn github_status_rejects_unrelated_workflow_that_mentions_cortex() {
6+
let repo = tempfile::tempdir().expect("create temp repo");
7+
fs::create_dir(repo.path().join(".git")).expect("create .git dir");
8+
let workflows_dir = repo.path().join(".github").join("workflows");
9+
fs::create_dir_all(&workflows_dir).expect("create workflows dir");
10+
fs::write(
11+
workflows_dir.join("homebrew.yml"),
12+
r#"name: Homebrew Release
13+
14+
on:
15+
push:
16+
tags:
17+
- "v*"
18+
19+
jobs:
20+
release:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Publish unrelated package
24+
with:
25+
formula-name: Cortex
26+
"#,
27+
)
28+
.expect("write unrelated workflow");
29+
30+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
31+
.args(["github", "status", "--json", "--path"])
32+
.arg(repo.path())
33+
.output()
34+
.expect("run Cortex github status");
35+
36+
let stdout = String::from_utf8_lossy(&output.stdout);
37+
let stderr = String::from_utf8_lossy(&output.stderr);
38+
39+
assert!(
40+
!output.status.success(),
41+
"unrelated workflow should not be treated as installed\nstdout:\n{stdout}\nstderr:\n{stderr}"
42+
);
43+
44+
let status: serde_json::Value =
45+
serde_json::from_str(&stdout).expect("status output should be JSON");
46+
assert_eq!(
47+
status["workflow_installed"],
48+
serde_json::Value::Bool(false),
49+
"status should reject unrelated workflow content\nstdout:\n{stdout}\nstderr:\n{stderr}"
50+
);
51+
}

0 commit comments

Comments
 (0)