From 76f9b4cf052ba04a53f7ce3a2f3694ece058bca9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:36:46 +0000 Subject: [PATCH 1/4] Initial plan From 0b9347f4b12575da556b262479987ce4098aa42e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:45:51 +0000 Subject: [PATCH 2/4] feat: add check-validator-sizes make target and CI job (#20806) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/ci.yml | 32 +++++++++++++++ Makefile | 8 ++++ scripts/check-validator-sizes.sh | 69 ++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100755 scripts/check-validator-sizes.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b6ebdc565a..f4d49eb1ed3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -957,6 +957,38 @@ jobs: if-no-files-found: ignore retention-days: 14 + check-validator-sizes: + name: Check validator file sizes + runs-on: ubuntu-latest + # Non-blocking: report violations but don't fail the build until existing files are cleaned up + continue-on-error: true + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Check validator file sizes + id: check + run: | + set +e + OUTPUT=$(bash scripts/check-validator-sizes.sh 2>&1) + EXIT_CODE=$? + echo "$OUTPUT" + echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT + echo "## Validator File Size Check" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Checking \`*_validation.go\` files against the 300-line hard limit (AGENTS.md)." >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + if [ $EXIT_CODE -ne 0 ]; then + echo "" >> $GITHUB_STEP_SUMMARY + echo "⚠️ This check is currently non-blocking. Fix violations to keep the codebase healthy." >> $GITHUB_STEP_SUMMARY + fi + exit $EXIT_CODE + lint-go: runs-on: ubuntu-latest permissions: diff --git a/Makefile b/Makefile index e43c3205f1c..938adfc4b0d 100644 --- a/Makefile +++ b/Makefile @@ -611,6 +611,12 @@ lint-errors: check-file-sizes: @bash scripts/check-file-sizes.sh +# Check that *_validation.go files stay within the 300-line hard limit (see AGENTS.md) +# Set WARN_ONLY=1 to report violations without failing (non-blocking mode) +.PHONY: check-validator-sizes +check-validator-sizes: + @bash scripts/check-validator-sizes.sh + # Validate all project files .PHONY: lint lint: fmt-check fmt-check-json lint-cjs golint @@ -802,6 +808,8 @@ help: @echo " lint-cjs - Lint JavaScript (.cjs) and JSON files in actions/setup/js" @echo " lint-json - Lint JSON files in pkg directory (excluding actions/setup/js)" @echo " lint-errors - Lint error messages for quality compliance" + @echo " check-file-sizes - Check Go file sizes and function counts (informational)" + @echo " check-validator-sizes - Check *_validation.go files against the 300-line hard limit" @echo " security-scan - Run all security scans (gosec, govulncheck, trivy)" @echo " security-gosec - Run gosec Go security scanner" @echo " security-govulncheck - Run govulncheck for known vulnerabilities" diff --git a/scripts/check-validator-sizes.sh b/scripts/check-validator-sizes.sh new file mode 100755 index 00000000000..d8afaf16647 --- /dev/null +++ b/scripts/check-validator-sizes.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# check-validator-sizes.sh - Enforce the 300-line hard limit on validator files +# +# AGENTS.md documents a 300-line hard limit for *_validation.go files. +# This script finds any file that exceeds that limit and reports it. +# +# Exit codes: +# 0 - All validator files are within the 300-line limit (or WARN_ONLY=1) +# 1 - One or more validator files exceed the 300-line limit + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Hard limit from AGENTS.md +HARD_LIMIT=300 + +# Set WARN_ONLY=1 to make the check non-blocking (report but always exit 0) +WARN_ONLY="${WARN_ONLY:-0}" + +over_limit=0 + +echo "Checking validator file sizes in pkg/ directory (limit: ${HARD_LIMIT} lines)..." +echo "" + +# Find all *_validation.go files, excluding test files +while IFS= read -r file; do + line_count=$(wc -l < "$file") + # Note: wc -l counts newlines, so files without a trailing newline are + # counted as one line fewer. Go source files almost always have a trailing + # newline, so this off-by-one is acceptable for this advisory check. + + if [ "$line_count" -gt "$HARD_LIMIT" ]; then + echo -e "${RED}❌ OVER LIMIT${NC}: $file" + echo -e " Lines: ${RED}$line_count${NC} / ${HARD_LIMIT} (exceeded by $((line_count - HARD_LIMIT)))" + echo "" + over_limit=$((over_limit + 1)) + fi +done < <(find pkg -name "*_validation.go" ! -name "*_test.go" -type f | sort) + +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +if [ "$over_limit" -eq 0 ]; then + echo -e "${GREEN}✅ All validator files are within the ${HARD_LIMIT}-line limit${NC}" + exit 0 +fi + +echo -e "${YELLOW}⚠️ $over_limit validator file(s) exceed the ${HARD_LIMIT}-line hard limit${NC}" +echo "" +echo "See AGENTS.md 'Validation Complexity Guidelines' for guidance:" +echo " - Target size: 100-200 lines per validator" +echo " - Hard limit: 300 lines (refactor if exceeded)" +echo "" +echo "When to split a validator:" +echo " - File exceeds 300 lines" +echo " - File contains 2+ unrelated validation domains" +echo " - Complex cross-dependencies require separate testing" + +if [ "$WARN_ONLY" = "1" ]; then + echo "" + echo "Note: Running in warn-only mode (WARN_ONLY=1). Fix these files to pass a future blocking check." + exit 0 +fi + +exit 1 From 73b34bc14c2e5183481efbbcc52af68939591e42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:45:58 +0000 Subject: [PATCH 3/4] fix: raise validator size limit to 512, fix ANSI output and shell quoting Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/ci.yml | 26 ++++++++--------- Makefile | 4 +-- scripts/check-validator-sizes.sh | 49 ++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4d49eb1ed3..93b6f0a20fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -972,22 +972,22 @@ jobs: id: check run: | set +e - OUTPUT=$(bash scripts/check-validator-sizes.sh 2>&1) + OUTPUT=$(NO_COLOR=1 bash scripts/check-validator-sizes.sh 2>&1) EXIT_CODE=$? echo "$OUTPUT" - echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT - echo "## Validator File Size Check" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "Checking \`*_validation.go\` files against the 300-line hard limit (AGENTS.md)." >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - if [ $EXIT_CODE -ne 0 ]; then - echo "" >> $GITHUB_STEP_SUMMARY - echo "⚠️ This check is currently non-blocking. Fix violations to keep the codebase healthy." >> $GITHUB_STEP_SUMMARY + echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" + echo "## Validator File Size Check" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "Checking \`*_validation.go\` files against the 512-line hard limit (AGENTS.md)." >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" + echo "$OUTPUT" >> "$GITHUB_STEP_SUMMARY" + echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" + if [ "$EXIT_CODE" -ne 0 ]; then + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "⚠️ This check is currently non-blocking. Fix violations to keep the codebase healthy." >> "$GITHUB_STEP_SUMMARY" fi - exit $EXIT_CODE + exit "$EXIT_CODE" lint-go: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 938adfc4b0d..f36b8780526 100644 --- a/Makefile +++ b/Makefile @@ -611,7 +611,7 @@ lint-errors: check-file-sizes: @bash scripts/check-file-sizes.sh -# Check that *_validation.go files stay within the 300-line hard limit (see AGENTS.md) +# Check that *_validation.go files stay within the 512-line hard limit # Set WARN_ONLY=1 to report violations without failing (non-blocking mode) .PHONY: check-validator-sizes check-validator-sizes: @@ -809,7 +809,7 @@ help: @echo " lint-json - Lint JSON files in pkg directory (excluding actions/setup/js)" @echo " lint-errors - Lint error messages for quality compliance" @echo " check-file-sizes - Check Go file sizes and function counts (informational)" - @echo " check-validator-sizes - Check *_validation.go files against the 300-line hard limit" + @echo " check-validator-sizes - Check *_validation.go files against the 512-line hard limit" @echo " security-scan - Run all security scans (gosec, govulncheck, trivy)" @echo " security-gosec - Run gosec Go security scanner" @echo " security-govulncheck - Run govulncheck for known vulnerabilities" diff --git a/scripts/check-validator-sizes.sh b/scripts/check-validator-sizes.sh index d8afaf16647..b58ce1eb694 100755 --- a/scripts/check-validator-sizes.sh +++ b/scripts/check-validator-sizes.sh @@ -1,23 +1,30 @@ #!/bin/bash -# check-validator-sizes.sh - Enforce the 300-line hard limit on validator files +# check-validator-sizes.sh - Enforce the 512-line hard limit on validator files # -# AGENTS.md documents a 300-line hard limit for *_validation.go files. -# This script finds any file that exceeds that limit and reports it. +# This script finds any *_validation.go file that exceeds the limit and reports it. # # Exit codes: -# 0 - All validator files are within the 300-line limit (or WARN_ONLY=1) -# 1 - One or more validator files exceed the 300-line limit +# 0 - All validator files are within the limit (or WARN_ONLY=1) +# 1 - One or more validator files exceed the limit set -euo pipefail -# Colors for output -RED='\033[0;31m' -YELLOW='\033[1;33m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color +# Disable colors when not connected to a TTY, when NO_COLOR is set, or when +# TERM=dumb — this keeps output readable when captured into CI step summaries. +if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-}" != "dumb" ]; then + RED='\033[0;31m' + YELLOW='\033[1;33m' + GREEN='\033[0;32m' + NC='\033[0m' +else + RED='' + YELLOW='' + GREEN='' + NC='' +fi -# Hard limit from AGENTS.md -HARD_LIMIT=300 +# Hard limit (lines per validator file) +HARD_LIMIT=512 # Set WARN_ONLY=1 to make the check non-blocking (report but always exit 0) WARN_ONLY="${WARN_ONLY:-0}" @@ -29,34 +36,34 @@ echo "" # Find all *_validation.go files, excluding test files while IFS= read -r file; do + # wc -l counts newline characters; a file without a trailing newline is + # undercounted by 1. Go source files always end with a newline (enforced by + # gofmt), so in practice the count is exact. line_count=$(wc -l < "$file") - # Note: wc -l counts newlines, so files without a trailing newline are - # counted as one line fewer. Go source files almost always have a trailing - # newline, so this off-by-one is acceptable for this advisory check. if [ "$line_count" -gt "$HARD_LIMIT" ]; then - echo -e "${RED}❌ OVER LIMIT${NC}: $file" + echo -e "${RED}OVER LIMIT${NC}: $file" echo -e " Lines: ${RED}$line_count${NC} / ${HARD_LIMIT} (exceeded by $((line_count - HARD_LIMIT)))" echo "" over_limit=$((over_limit + 1)) fi done < <(find pkg -name "*_validation.go" ! -name "*_test.go" -type f | sort) -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "------------------------------------------------------------" if [ "$over_limit" -eq 0 ]; then - echo -e "${GREEN}✅ All validator files are within the ${HARD_LIMIT}-line limit${NC}" + echo -e "${GREEN}All validator files are within the ${HARD_LIMIT}-line limit${NC}" exit 0 fi -echo -e "${YELLOW}⚠️ $over_limit validator file(s) exceed the ${HARD_LIMIT}-line hard limit${NC}" +echo -e "${YELLOW}$over_limit validator file(s) exceed the ${HARD_LIMIT}-line hard limit${NC}" echo "" echo "See AGENTS.md 'Validation Complexity Guidelines' for guidance:" echo " - Target size: 100-200 lines per validator" -echo " - Hard limit: 300 lines (refactor if exceeded)" +echo " - Hard limit: ${HARD_LIMIT} lines (refactor if exceeded)" echo "" echo "When to split a validator:" -echo " - File exceeds 300 lines" +echo " - File exceeds ${HARD_LIMIT} lines" echo " - File contains 2+ unrelated validation domains" echo " - Complex cross-dependencies require separate testing" From 6954bb6b1219479371d918247f9db48bb0c1a02e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:58:13 +0000 Subject: [PATCH 4/4] fix: raise validator size limit to 768 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- Makefile | 4 ++-- scripts/check-validator-sizes.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93b6f0a20fe..6c57445a71d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -978,7 +978,7 @@ jobs: echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" echo "## Validator File Size Check" >> "$GITHUB_STEP_SUMMARY" echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Checking \`*_validation.go\` files against the 512-line hard limit (AGENTS.md)." >> "$GITHUB_STEP_SUMMARY" + echo "Checking \`*_validation.go\` files against the 768-line hard limit (AGENTS.md)." >> "$GITHUB_STEP_SUMMARY" echo "" >> "$GITHUB_STEP_SUMMARY" echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" echo "$OUTPUT" >> "$GITHUB_STEP_SUMMARY" diff --git a/Makefile b/Makefile index f36b8780526..ecba6ab3bde 100644 --- a/Makefile +++ b/Makefile @@ -611,7 +611,7 @@ lint-errors: check-file-sizes: @bash scripts/check-file-sizes.sh -# Check that *_validation.go files stay within the 512-line hard limit +# Check that *_validation.go files stay within the 768-line hard limit # Set WARN_ONLY=1 to report violations without failing (non-blocking mode) .PHONY: check-validator-sizes check-validator-sizes: @@ -809,7 +809,7 @@ help: @echo " lint-json - Lint JSON files in pkg directory (excluding actions/setup/js)" @echo " lint-errors - Lint error messages for quality compliance" @echo " check-file-sizes - Check Go file sizes and function counts (informational)" - @echo " check-validator-sizes - Check *_validation.go files against the 512-line hard limit" + @echo " check-validator-sizes - Check *_validation.go files against the 768-line hard limit" @echo " security-scan - Run all security scans (gosec, govulncheck, trivy)" @echo " security-gosec - Run gosec Go security scanner" @echo " security-govulncheck - Run govulncheck for known vulnerabilities" diff --git a/scripts/check-validator-sizes.sh b/scripts/check-validator-sizes.sh index b58ce1eb694..017ba94a8ed 100755 --- a/scripts/check-validator-sizes.sh +++ b/scripts/check-validator-sizes.sh @@ -24,7 +24,7 @@ else fi # Hard limit (lines per validator file) -HARD_LIMIT=512 +HARD_LIMIT=768 # Set WARN_ONLY=1 to make the check non-blocking (report but always exit 0) WARN_ONLY="${WARN_ONLY:-0}"