From 3268a683c321941f8263a2cda246a3956dcd7712 Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Tue, 11 Nov 2025 00:21:47 +0530 Subject: [PATCH 1/6] ci: add standalone workflow to enforce test naming rules (Fixes #744) Signed-off-by: Raja Rathour --- .github/workflows/pr-check-naming-test.yml | 62 ++++++++++++++++++++++ .github/workflows/pr-checks.yml | 8 +-- CHANGELOG.md | 1 + 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pr-check-naming-test.yml diff --git a/.github/workflows/pr-check-naming-test.yml b/.github/workflows/pr-check-naming-test.yml new file mode 100644 index 000000000..45d91b436 --- /dev/null +++ b/.github/workflows/pr-check-naming-test.yml @@ -0,0 +1,62 @@ +name: "Test File Naming Check" + +on: + pull_request: + types: [opened, reopened, synchronize, edited] + +permissions: + contents: read + +concurrency: + group: test-name-check-${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + test-name-check: + name: Test File Naming Check + runs-on: ubuntu-latest + + steps: + - name: Harden the runner (Audit all outbound calls) + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 + with: + egress-policy: audit + + # Using the specific commit SHA for actions/checkout@v5.0.0, as requested + - name: Checkout repository + uses: actions/checkout@8ade135a368bb9860e15bcafd2cf940ba6f36c4c + + - name: Validate test file naming convention + run: | + echo "🔍 Checking test file naming rules..." + + # Helper files that must be excluded from naming validation + EXCLUDES="__init__.py conftest.py mock_server.py utils_for_test.py" + + # Build exclude arguments for find + EX_ARGS="" + for f in $EXCLUDES; do + EX_ARGS="$EX_ARGS ! -name \"$f\"" + done + + # Rule 1 — Unit tests (tests/unit) must start with test_*.py + echo "➡️ Checking UNIT tests (must start with test_)..." + invalid_unit=$(eval "find tests/unit -type f -name '*.py' $EX_ARGS ! -name 'test_*.py'") + + # Rule 2 — Integration tests (tests/integration) must end with *_test.py + echo "➡️ Checking INTEGRATION tests (must end with _test.py)..." + invalid_integration=$(eval "find tests/integration -type f -name '*.py' $EX_ARGS ! -name '*_test.py'") + + if [ -n "$invalid_unit" ]; then + echo "❌ Invalid Unit Test Filenames:" + echo "$invalid_unit" + exit 1 + fi + + if [ -n "$invalid_integration" ]; then + echo "❌ Invalid Integration Test Filenames:" + echo "$invalid_integration" + exit 1 + fi + + echo "✅ All test files follow the correct conventions!" \ No newline at end of file diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index eba973ba3..0be68c5a7 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 435fd7dff..866a07e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1. ## [0.1.8] - 2025-11-07 ### Added +- CI: Add standalone workflow `pr-check-naming-test.yml` to validate test filenames. Enforces unit tests begin with `test_` and integration tests end with `_test.py`, with exclusions for helper files. (Fixes #744) - Add `TokenFeeScheduleUpdateTransaction` class to support updating custom fee schedules on tokens (#471). - Add `examples/token_update_fee_schedule_fungible.py` and `examples/token_update_fee_schedule_nft.py` demonstrating the use of `TokenFeeScheduleUpdateTransaction`. - Update `docs/sdk_users/running_examples.md` to include `TokenFeeScheduleUpdateTransaction`. From c978d2cc49011eebb3131c6c74f4dc103d407172 Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Tue, 11 Nov 2025 22:24:05 +0530 Subject: [PATCH 2/6] ci: add standalone workflow for _test.py naming enforcement Signed-off-by: Raja Rathour --- .github/workflows/pr-check-naming-test.yml | 64 +++++++++------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/.github/workflows/pr-check-naming-test.yml b/.github/workflows/pr-check-naming-test.yml index 45d91b436..266d509f7 100644 --- a/.github/workflows/pr-check-naming-test.yml +++ b/.github/workflows/pr-check-naming-test.yml @@ -2,7 +2,7 @@ name: "Test File Naming Check" on: pull_request: - types: [opened, reopened, synchronize, edited] + types: [opened, reopened, edited, synchronize] permissions: contents: read @@ -12,51 +12,41 @@ concurrency: cancel-in-progress: true jobs: - test-name-check: - name: Test File Naming Check + test-file-naming: + name: Test File Naming Check (pull request) runs-on: ubuntu-latest steps: - - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 + - name: Harden the runner + uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a with: egress-policy: audit - # Using the specific commit SHA for actions/checkout@v5.0.0, as requested - name: Checkout repository - uses: actions/checkout@8ade135a368bb9860e15bcafd2cf940ba6f36c4c + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - - name: Validate test file naming convention + - name: Validate test filename convention + shell: bash run: | - echo "🔍 Checking test file naming rules..." - - # Helper files that must be excluded from naming validation - EXCLUDES="__init__.py conftest.py mock_server.py utils_for_test.py" - - # Build exclude arguments for find - EX_ARGS="" - for f in $EXCLUDES; do - EX_ARGS="$EX_ARGS ! -name \"$f\"" - done - - # Rule 1 — Unit tests (tests/unit) must start with test_*.py - echo "➡️ Checking UNIT tests (must start with test_)..." - invalid_unit=$(eval "find tests/unit -type f -name '*.py' $EX_ARGS ! -name 'test_*.py'") - - # Rule 2 — Integration tests (tests/integration) must end with *_test.py - echo "➡️ Checking INTEGRATION tests (must end with _test.py)..." - invalid_integration=$(eval "find tests/integration -type f -name '*.py' $EX_ARGS ! -name '*_test.py'") - - if [ -n "$invalid_unit" ]; then - echo "❌ Invalid Unit Test Filenames:" - echo "$invalid_unit" + echo "🔍 Checking for invalid test filenames..." + + invalid_files=$( + find tests -type f -name "*.py" \ + ! -name "*_test.py" \ + ! -path "tests/__init__.py" \ + ! -path "tests/unit/__init__.py" \ + ! -path "tests/unit/conftest.py" \ + ! -path "tests/unit/mock_server.py" \ + ! -path "tests/integration/__init__.py" \ + ! -path "tests/integration/utils_for_test.py" \ + | sort || true + ) + + if [ -n "$invalid_files" ]; then + echo "❌ Invalid filenames detected (must end with _test.py):" + echo "$invalid_files" + echo exit 1 fi - if [ -n "$invalid_integration" ]; then - echo "❌ Invalid Integration Test Filenames:" - echo "$invalid_integration" - exit 1 - fi - - echo "✅ All test files follow the correct conventions!" \ No newline at end of file + echo "✅ All test filenames follow the convention (*_test.py)." From 3d9d3dbe47f675a2634e17dd1ec804c5a7f33e8a Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Tue, 11 Nov 2025 22:31:28 +0530 Subject: [PATCH 3/6] docs: move changelog entry to new unreleased section Signed-off-by: Raja Rathour --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 866a07e69..435fd7dff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,6 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1. ## [0.1.8] - 2025-11-07 ### Added -- CI: Add standalone workflow `pr-check-naming-test.yml` to validate test filenames. Enforces unit tests begin with `test_` and integration tests end with `_test.py`, with exclusions for helper files. (Fixes #744) - Add `TokenFeeScheduleUpdateTransaction` class to support updating custom fee schedules on tokens (#471). - Add `examples/token_update_fee_schedule_fungible.py` and `examples/token_update_fee_schedule_nft.py` demonstrating the use of `TokenFeeScheduleUpdateTransaction`. - Update `docs/sdk_users/running_examples.md` to include `TokenFeeScheduleUpdateTransaction`. From 242cdbc4f92f00d27f4bba255d455eb7b35f399c Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Tue, 11 Nov 2025 22:33:03 +0530 Subject: [PATCH 4/6] docs: move changelog entry to new unreleased section Signed-off-by: Raja Rathour --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 435fd7dff..96cc53055 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 From 711e73982a89fdd636c42fb3a110879a3ee3f1db Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Tue, 11 Nov 2025 23:41:28 +0530 Subject: [PATCH 5/6] ci: refine test-naming exclusions and rules Signed-off-by: Raja Rathour --- .github/workflows/pr-check-naming-test.yml | 58 ++++++++-------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/.github/workflows/pr-check-naming-test.yml b/.github/workflows/pr-check-naming-test.yml index 266d509f7..54bb357f4 100644 --- a/.github/workflows/pr-check-naming-test.yml +++ b/.github/workflows/pr-check-naming-test.yml @@ -1,52 +1,38 @@ -name: "Test File Naming Check" +name: "PR Test Naming Check" on: pull_request: - types: [opened, reopened, edited, synchronize] + types: [opened, reopened, synchronize, edited] permissions: contents: read -concurrency: - group: test-name-check-${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - jobs: - test-file-naming: - name: Test File Naming Check (pull request) + test-name-check: + name: Validate test naming convention runs-on: ubuntu-latest steps: - - name: Harden the runner - uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a - with: - egress-policy: audit - - - name: Checkout repository - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Validate test filename convention - shell: bash + - name: Run test naming validation run: | - echo "🔍 Checking for invalid test filenames..." - - invalid_files=$( - find tests -type f -name "*.py" \ - ! -name "*_test.py" \ - ! -path "tests/__init__.py" \ - ! -path "tests/unit/__init__.py" \ - ! -path "tests/unit/conftest.py" \ - ! -path "tests/unit/mock_server.py" \ - ! -path "tests/integration/__init__.py" \ - ! -path "tests/integration/utils_for_test.py" \ - | sort || true - ) - - if [ -n "$invalid_files" ]; then - echo "❌ Invalid filenames detected (must end with _test.py):" - echo "$invalid_files" - echo + 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 filenames follow the convention (*_test.py)." + echo "✅ All test files follow the _test.py convention!" From 27ee708db05ed8681441985c9db7ef0b006d5409 Mon Sep 17 00:00:00 2001 From: Raja Rathour Date: Wed, 12 Nov 2025 09:54:44 +0530 Subject: [PATCH 6/6] fix(tests): rename token fee schedule integration test to follow _test.py convention Signed-off-by: Raja Rathour --- ...n_e2e.py => token_fee_schedule_update_transaction_e2e_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/integration/{test_token_fee_schedule_update_transaction_e2e.py => token_fee_schedule_update_transaction_e2e_test.py} (100%) 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