Skip to content

Commit 3268a68

Browse files
committed
ci: add standalone workflow to enforce test naming rules (Fixes #744)
Signed-off-by: Raja Rathour <imraja729@gmail.com>
1 parent 01e2369 commit 3268a68

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Test File Naming Check"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, edited]
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: test-name-check-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test-name-check:
16+
name: Test File Naming Check
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Harden the runner (Audit all outbound calls)
21+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
22+
with:
23+
egress-policy: audit
24+
25+
# Using the specific commit SHA for actions/checkout@v5.0.0, as requested
26+
- name: Checkout repository
27+
uses: actions/checkout@8ade135a368bb9860e15bcafd2cf940ba6f36c4c
28+
29+
- name: Validate test file naming convention
30+
run: |
31+
echo "🔍 Checking test file naming rules..."
32+
33+
# Helper files that must be excluded from naming validation
34+
EXCLUDES="__init__.py conftest.py mock_server.py utils_for_test.py"
35+
36+
# Build exclude arguments for find
37+
EX_ARGS=""
38+
for f in $EXCLUDES; do
39+
EX_ARGS="$EX_ARGS ! -name \"$f\""
40+
done
41+
42+
# Rule 1 — Unit tests (tests/unit) must start with test_*.py
43+
echo "➡️ Checking UNIT tests (must start with test_)..."
44+
invalid_unit=$(eval "find tests/unit -type f -name '*.py' $EX_ARGS ! -name 'test_*.py'")
45+
46+
# Rule 2 — Integration tests (tests/integration) must end with *_test.py
47+
echo "➡️ Checking INTEGRATION tests (must end with _test.py)..."
48+
invalid_integration=$(eval "find tests/integration -type f -name '*.py' $EX_ARGS ! -name '*_test.py'")
49+
50+
if [ -n "$invalid_unit" ]; then
51+
echo "❌ Invalid Unit Test Filenames:"
52+
echo "$invalid_unit"
53+
exit 1
54+
fi
55+
56+
if [ -n "$invalid_integration" ]; then
57+
echo "❌ Invalid Integration Test Filenames:"
58+
echo "$invalid_integration"
59+
exit 1
60+
fi
61+
62+
echo "✅ All test files follow the correct conventions!"

.github/workflows/pr-checks.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,24 @@ jobs:
7070
7171
echo "Checking files changed in PR #${PR_NUMBER}..."
7272
73-
# List files in the PR and check for CHANGELOG.md (root or any path ending with /CHANGELOG.md)
7473
FILES_JSON="$(gh api repos/${{ github.repository }}/pulls/${PR_NUMBER}/files --paginate)"
7574
if ! echo "${FILES_JSON}" | jq -e '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i"))' >/dev/null; then
7675
echo "FAIL: CHANGELOG.md was not changed in this PR."
7776
exit 1
7877
fi
7978
80-
# Ensure there is at least one line-level change (+ or -) in the patch for CHANGELOG.md
8179
PATCH_CONTENT="$(echo "${FILES_JSON}" \
8280
| jq -r '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i")) | .patch // empty')"
8381
84-
# If no patch is returned (very large file or API omission), treat presence as sufficient
8582
if [[ -z "${PATCH_CONTENT}" ]]; then
86-
echo "CHANGELOG.md modified (no patch provided by API). Passing."
83+
echo "CHANGELOG.md modified (patch omitted). Passing."
8784
exit 0
8885
fi
8986
90-
# Look for actual line changes (exclude diff headers +++/---)
9187
if echo "${PATCH_CONTENT}" | awk '{print $0}' | grep -E '^[+-]' | grep -vE '^\+\+\+|^\-\-\-' >/dev/null; then
9288
echo "PASS: CHANGELOG.md contains line-level changes."
9389
exit 0
9490
else
9591
echo "FAIL: No line-level changes detected in CHANGELOG.md."
9692
exit 1
97-
fi
93+
fi

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2020
## [0.1.8] - 2025-11-07
2121

2222
### Added
23+
- 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)
2324
- Add `TokenFeeScheduleUpdateTransaction` class to support updating custom fee schedules on tokens (#471).
2425
- Add `examples/token_update_fee_schedule_fungible.py` and `examples/token_update_fee_schedule_nft.py` demonstrating the use of `TokenFeeScheduleUpdateTransaction`.
2526
- Update `docs/sdk_users/running_examples.md` to include `TokenFeeScheduleUpdateTransaction`.

0 commit comments

Comments
 (0)