#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/detect-pipeline.sh" PASS=0 FAIL=0 assert_eq() { local test_name="$1" expected="$2" actual="$3" if [ "$expected" = "$actual" ]; then echo "PASS: $test_name" PASS=$((PASS + 1)) else echo "FAIL: $test_name (expected=$expected, actual=$actual)" FAIL=$((FAIL + 1)) fi } run_detect() { echo "$1" | detect_pipeline } # --- Pipeline B cases (infra-only) --- assert_eq "single .github root file" "pipeline-b" \ "$(run_detect ".github/dependabot.yml")" assert_eq ".github/workflows subdirectory" "pipeline-b" \ "$(run_detect ".github/workflows/ci.yaml")" assert_eq "deeply nested .github path" "pipeline-b" \ "$(run_detect ".github/workflows/reusable/build.yaml")" assert_eq "markdown file at root" "pipeline-b" \ "$(run_detect "README.md")" assert_eq "markdown in subdirectory" "pipeline-b" \ "$(run_detect "docs/CONTRIBUTING.md")" assert_eq "eslintrc config" "pipeline-b" \ "$(run_detect ".eslintrc.json")" assert_eq "prettierrc config" "pipeline-b" \ "$(run_detect ".prettierrc.yaml")" assert_eq "renovate config" "pipeline-b" \ "$(run_detect "renovate.json")" assert_eq "renovate config5" "pipeline-b" \ "$(run_detect "renovate.json5")" assert_eq "gitignore" "pipeline-b" \ "$(run_detect ".gitignore")" assert_eq "editorconfig" "pipeline-b" \ "$(run_detect ".editorconfig")" assert_eq "LICENSE" "pipeline-b" \ "$(run_detect "LICENSE")" assert_eq "mixed infra files" "pipeline-b" \ "$(run_detect ".github/workflows/ci.yaml README.md .eslintrc.json LICENSE")" assert_eq "workflow + markdown combo" "pipeline-b" \ "$(run_detect ".github/workflows/detect-pr-pipeline.yaml .github/workflows/README.md")" assert_eq "infra root file" "pipeline-b" \ "$(run_detect "infra/helmrelease.yaml")" assert_eq "infra nested file" "pipeline-b" \ "$(run_detect "infra/clusters/prod/kustomization.yaml")" assert_eq "org root file" "pipeline-b" \ "$(run_detect "org/CODEOWNERS")" assert_eq "org nested file" "pipeline-b" \ "$(run_detect "org/policies/branch-protection.json")" assert_eq "Dockerfile" "pipeline-b" \ "$(run_detect "Dockerfile")" assert_eq "docker-compose.yaml" "pipeline-b" \ "$(run_detect "docker-compose.yaml")" assert_eq "docker-compose.override.yml" "pipeline-b" \ "$(run_detect "docker-compose.override.yml")" assert_eq "Makefile" "pipeline-b" \ "$(run_detect "Makefile")" assert_eq "mixed infra + org + workflow" "pipeline-b" \ "$(run_detect ".github/workflows/ci.yaml infra/helmrelease.yaml org/CODEOWNERS README.md")" # --- Pipeline A cases (has non-infra files) --- assert_eq "plugin source file" "pipeline-a" \ "$(run_detect "headlamp-polaris-plugin/src/index.tsx")" assert_eq "plugin package.json" "pipeline-a" \ "$(run_detect "headlamp-polaris-plugin/package.json")" assert_eq "root source file" "pipeline-a" \ "$(run_detect "src/main.ts")" assert_eq "mixed infra + code" "pipeline-a" \ "$(run_detect ".github/workflows/ci.yaml headlamp-polaris-plugin/src/index.tsx README.md")" assert_eq "single non-infra file" "pipeline-a" \ "$(run_detect "server.js")" assert_eq "plugin code + infra files" "pipeline-a" \ "$(run_detect "infra/helmrelease.yaml org/CODEOWNERS headlamp-polaris-plugin/src/index.tsx")" # --- Edge cases --- assert_eq "empty input" "pipeline-b" \ "$(run_detect "")" assert_eq "root dot file (not in infra list)" "pipeline-a" \ "$(run_detect ".env")" assert_eq ".github-like but not .github dir" "pipeline-a" \ "$(run_detect ".github-backup/config.yaml")" # --- Summary --- echo "" echo "Results: $PASS passed, $FAIL failed" if [ "$FAIL" -gt 0 ]; then exit 1 fi