diff --git a/package.json b/package.json index 4bed5fa15..fa842edc6 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,10 @@ "dev": "next dev", "build": "next build", "start": "next start", + "test": "bash tests/sync-agent-rules.test.sh", "lint": "eslint", "typecheck": "tsc --noEmit", - "check": "npm run lint && npm run typecheck && npm run build" + "check": "npm run test && npm run lint && npm run typecheck && npm run build" }, "dependencies": { "@base-ui/react": "^1.3.0", diff --git a/scripts/sync-agent-rules.sh b/scripts/sync-agent-rules.sh index 661affc81..73d1149cd 100644 --- a/scripts/sync-agent-rules.sh +++ b/scripts/sync-agent-rules.sh @@ -42,7 +42,8 @@ resolve_imports() { cat "$resolved" echo "" else - echo "" + echo "Error: AGENTS.md import not found: $import_path" >&2 + return 1 fi else echo "$line" diff --git a/tests/sync-agent-rules.test.sh b/tests/sync-agent-rules.test.sh new file mode 100644 index 000000000..4553b05e2 --- /dev/null +++ b/tests/sync-agent-rules.test.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +FIXTURE_ROOT="$(mktemp -d)" +trap 'rm -rf "$FIXTURE_ROOT"' EXIT + +mkdir -p "$FIXTURE_ROOT/scripts" +cp "$REPO_ROOT/scripts/sync-agent-rules.sh" "$FIXTURE_ROOT/scripts/" +printf '# Fixture instructions\n\n@docs/missing-guide.md\n' > "$FIXTURE_ROOT/AGENTS.md" + +set +e +OUTPUT="$(bash "$FIXTURE_ROOT/scripts/sync-agent-rules.sh" 2>&1)" +STATUS=$? +set -e + +if [[ $STATUS -eq 0 ]]; then + echo "Expected sync-agent-rules.sh to reject a missing @file import" >&2 + exit 1 +fi + +if [[ "$OUTPUT" != *"docs/missing-guide.md"* ]]; then + echo "Expected the failure to name the missing import" >&2 + exit 1 +fi + +echo "Missing @file imports fail closed"