Files
eagle0/scripts/check_build_deps.sh
T
6e7611d547 Move ShardokBattle boundary conversion to ShardokInterfaceGrpcClient (#5471)
* Remove stale proto_converter deps from library/ BUILD files

Library code should not depend on proto_converters - those belong at
the service layer boundary. Removed 9 stale proto_converter deps that
were no longer used by any Scala code.

The only remaining proto_converter dep is shardok_battle_converter,
which is actually used by ResolveBattleAction.scala (to be fixed in
a follow-up PR).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Move ShardokBattle boundary conversion to ShardokInterfaceGrpcClient

Previously, BattleResolution contained a proto ShardokBattle, requiring
ResolveBattleAction in library/ to depend on ShardokBattleConverter.
This violated the boundary principle where proto conversions should
happen at the service layer, not in library code.

This change:
- Updates BattleResolution.battle to use Scala ShardokBattle
- Moves the proto-to-Scala conversion into ShardokInterfaceGrpcClient
- Removes ShardokBattleConverter dependency from library/ code
- Updates tests to use the scalaBattle() helper for conversion

This completely removes proto_converters dependencies from library/
(the last one was shardok_battle_converter).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add linter check for library/ proto_converters boundary

Adds Rule 3 to check_build_deps.sh that verifies library/ code does not
depend on proto_converters. Proto conversions should happen at service
boundaries (ShardokInterfaceGrpcClient, EagleServiceImpl, etc.), not in
library code.

Also updates baseline from 167 to 75 proto deps reflecting recent cleanup.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 06:27:57 -08:00

183 lines
6.5 KiB
Bash
Executable File

#!/bin/bash
# Check BUILD.bazel dependency constraints
# This script enforces architectural boundaries in the codebase.
#
# Usage:
# ./scripts/check_build_deps.sh # Check all rules
# ./scripts/check_build_deps.sh --ci # CI mode (fail on any violation)
# ./scripts/check_build_deps.sh --count # Just count current violations (for tracking progress)
# ./scripts/check_build_deps.sh --strict # Fail if proto deps in library/ exceed baseline
#
# The baseline for proto deps is stored in scripts/build_deps_baseline.txt
# Update it with: ./scripts/check_build_deps.sh --update-baseline
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BASELINE_FILE="$SCRIPT_DIR/build_deps_baseline.txt"
cd "$REPO_ROOT"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
MODE="${1:-check}"
EXIT_CODE=0
# Get baseline proto count (default to a high number if no baseline exists)
get_baseline() {
if [ -f "$BASELINE_FILE" ]; then
grep "^library_proto_deps=" "$BASELINE_FILE" | cut -d= -f2
else
echo "999999" # No baseline = don't fail
fi
}
# Rule 1: src/main should not depend on src/test
check_main_depends_on_test() {
echo -e "${YELLOW}Checking: src/main should not depend on src/test...${NC}"
violations=$(bazel query 'deps(//src/main/...) intersect //src/test/...' 2>/dev/null || true)
if [ -n "$violations" ]; then
echo -e "${RED}VIOLATION: src/main depends on src/test:${NC}"
echo "$violations"
return 1
else
echo -e "${GREEN}✓ No violations${NC}"
return 0
fi
}
# Rule 2: library/ should not depend on src/main/protobuf
# Note: This rule is aspirational - there are currently many violations as part of ongoing deproto effort
check_library_depends_on_proto() {
echo -e "${YELLOW}Checking: library/ should not depend on src/main/protobuf...${NC}"
violations=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null || true)
count=$(echo "$violations" | grep -c "^//" || echo "0")
if [ "$count" -gt 0 ]; then
echo -e "${YELLOW}Found $count proto dependencies in library/ (deproto in progress)${NC}"
if [ "$MODE" == "--count" ]; then
echo "$violations" | head -20
if [ "$count" -gt 20 ]; then
echo "... and $((count - 20)) more"
fi
fi
# Don't fail on this rule yet - it's aspirational
return 0
else
echo -e "${GREEN}✓ No proto dependencies in library/${NC}"
return 0
fi
}
# Rule 3: library/ should not depend on proto_converters
# Proto conversions should happen at service boundaries, not in library code
check_library_depends_on_proto_converters() {
echo -e "${YELLOW}Checking: library/ should not depend on proto_converters...${NC}"
violations=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/scala/net/eagle0/eagle/model/proto_converters/...' 2>/dev/null | grep "^//" || true)
if [ -n "$violations" ]; then
count=$(echo "$violations" | wc -l | tr -d ' ')
echo -e "${RED}VIOLATION: library/ depends on $count proto_converters targets:${NC}"
echo "$violations"
echo ""
echo "Proto conversions should happen at service boundaries (ShardokInterfaceGrpcClient,"
echo "EagleServiceImpl, etc.), not in library code."
return 1
else
echo -e "${GREEN}✓ No proto_converters dependencies in library/${NC}"
return 0
fi
}
# Count proto deps for tracking deproto progress
count_proto_deps() {
echo -e "${YELLOW}=== Proto dependency counts ===${NC}"
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
echo "library/: $library_count proto dependencies"
baseline=$(get_baseline)
if [ "$baseline" != "999999" ]; then
echo "baseline: $baseline"
if [ "$library_count" -lt "$baseline" ]; then
echo -e "${GREEN}↓ Reduced by $((baseline - library_count)) from baseline${NC}"
elif [ "$library_count" -gt "$baseline" ]; then
echo -e "${RED}↑ Increased by $((library_count - baseline)) from baseline${NC}"
fi
fi
}
# Check if proto deps exceed baseline (for strict mode)
check_proto_baseline() {
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
baseline=$(get_baseline)
echo -e "${YELLOW}Checking: proto deps in library/ should not exceed baseline...${NC}"
echo "Current: $library_count, Baseline: $baseline"
if [ "$library_count" -gt "$baseline" ]; then
echo -e "${RED}VIOLATION: Proto dependencies increased from $baseline to $library_count${NC}"
echo "Run './scripts/check_build_deps.sh --count' to see which protos are used"
return 1
else
echo -e "${GREEN}✓ Proto deps at or below baseline${NC}"
return 0
fi
}
# Update baseline file
update_baseline() {
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
echo "# BUILD dependency baseline - updated $(date)" > "$BASELINE_FILE"
echo "# Do not increase these numbers - only decrease!" >> "$BASELINE_FILE"
echo "library_proto_deps=$library_count" >> "$BASELINE_FILE"
echo -e "${GREEN}Updated baseline: library_proto_deps=$library_count${NC}"
}
echo "=== BUILD.bazel Dependency Check ==="
echo ""
case "$MODE" in
--count)
count_proto_deps
;;
--ci)
check_main_depends_on_test || EXIT_CODE=1
check_library_depends_on_proto || EXIT_CODE=1
check_library_depends_on_proto_converters || EXIT_CODE=1
;;
--strict)
check_main_depends_on_test || EXIT_CODE=1
check_proto_baseline || EXIT_CODE=1
check_library_depends_on_proto_converters || EXIT_CODE=1
;;
--update-baseline)
update_baseline
;;
*)
check_main_depends_on_test || EXIT_CODE=1
check_library_depends_on_proto
check_library_depends_on_proto_converters || EXIT_CODE=1
echo ""
count_proto_deps
;;
esac
echo ""
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}=== All checks passed ===${NC}"
else
echo -e "${RED}=== Some checks failed ===${NC}"
fi
exit $EXIT_CODE