#!/usr/bin/env bash
set -euo pipefail

root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
guard="${root}/guardrails/repository/no-extension-compiler.sh"
fixture="$(mktemp -d)"
trap 'rm -rf "${fixture}"' EXIT

compiler_word="compiler"
command_name="agentteam-ext-${compiler_word}"
package_path="internal/extension/${compiler_word}"

expect_failure() {
  local label="$1"
  if AGENTTEAM_EXTENSION_COMPILER_GUARD_ROOT="${fixture}" bash "${guard}" >/dev/null 2>&1; then
    echo "expected ${label} fixture to fail" >&2
    exit 1
  fi
}

AGENTTEAM_EXTENSION_COMPILER_GUARD_ROOT="${fixture}" bash "${guard}" >/dev/null

mkdir -p "${fixture}/cmd/${command_name}"
expect_failure "retired command directory"
rm -rf "${fixture}/cmd"

mkdir -p "${fixture}/${package_path}"
expect_failure "retired implementation package"
rm -rf "${fixture}/internal"

mkdir -p "${fixture}/scripts"
printf 'go run ./cmd/%s\n' "${command_name}" >"${fixture}/scripts/ci.sh"
expect_failure "retired CI command reference"
rm -rf "${fixture}/scripts"

mkdir -p "${fixture}/specs/extension"
printf 'import %s\n' "${package_path}" >"${fixture}/specs/extension/stale.md"
expect_failure "retired product documentation reference"

echo "Extension Compiler absence guard tests passed."
