diff --git a/.github/workflows/pr-check-naming-test.yml b/.github/workflows/pr-check-naming-test.yml new file mode 100644 index 000000000..54bb357f4 --- /dev/null +++ b/.github/workflows/pr-check-naming-test.yml @@ -0,0 +1,38 @@ +name: "PR Test Naming Check" + +on: + pull_request: + types: [opened, reopened, synchronize, edited] + +permissions: + contents: read + +jobs: + test-name-check: + name: Validate test naming convention + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Run test naming validation + run: | + echo "🔍 Checking test file naming convention..." + + bad_files=$(find tests -type f -name "*.py" \ + ! -name "*_test.py" \ + ! -path "tests/__init__.py" \ + ! -path "tests/unit/__init__.py" \ + ! -path "tests/integration/__init__.py" \ + ! -path "tests/unit/conftest.py" \ + ! -path "tests/unit/mock_server.py" \ + ! -path "tests/integration/utils_for_test.py") + + if [ -n "$bad_files" ]; then + echo "❌ Invalid test filenames detected:" + echo "$bad_files" + exit 1 + fi + + echo "✅ All test files follow the _test.py convention!" diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 4aa042ae2..90d0f21d7 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -70,28 +70,24 @@ jobs: echo "Checking files changed in PR #${PR_NUMBER}..." - # List files in the PR and check for CHANGELOG.md (root or any path ending with /CHANGELOG.md) FILES_JSON="$(gh api repos/${{ github.repository }}/pulls/${PR_NUMBER}/files --paginate)" if ! echo "${FILES_JSON}" | jq -e '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i"))' >/dev/null; then echo "FAIL: CHANGELOG.md was not changed in this PR." exit 1 fi - # Ensure there is at least one line-level change (+ or -) in the patch for CHANGELOG.md PATCH_CONTENT="$(echo "${FILES_JSON}" \ | jq -r '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i")) | .patch // empty')" - # If no patch is returned (very large file or API omission), treat presence as sufficient if [[ -z "${PATCH_CONTENT}" ]]; then - echo "CHANGELOG.md modified (no patch provided by API). Passing." + echo "CHANGELOG.md modified (patch omitted). Passing." exit 0 fi - # Look for actual line changes (exclude diff headers +++/---) if echo "${PATCH_CONTENT}" | awk '{print $0}' | grep -E '^[+-]' | grep -vE '^\+\+\+|^\-\-\-' >/dev/null; then echo "PASS: CHANGELOG.md contains line-level changes." exit 0 else echo "FAIL: No line-level changes detected in CHANGELOG.md." exit 1 - fi + fi \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a2621baa4..55cab179b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1. ### Added - +- CI: Add standalone workflow `pr-check-naming-test.yml` to enforce test naming rules: + - Unit tests must be named `test_*.py` + - Integration tests must be named `*_test.py` + - Excludes helper files: `__init__.py`, `conftest.py`, `mock_server.py`, `utils_for_test.py` ### Changed - Refactored token-related example scripts (`token_delete.py`, `token_dissociate.py`, etc.) for improved readability and modularity. [#370] diff --git a/tests/integration/test_token_fee_schedule_update_transaction_e2e.py b/tests/integration/token_fee_schedule_update_transaction_e2e_test.py similarity index 100% rename from tests/integration/test_token_fee_schedule_update_transaction_e2e.py rename to tests/integration/token_fee_schedule_update_transaction_e2e_test.py