|
| 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