Skip to content

Commit 01c621b

Browse files
exploreriiiAbhijeet2409
authored andcommitted
ci: expand test naming check globally and resolve naming errors (hiero-ledger#2065)
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent 63b035d commit 01c621b

11 files changed

Lines changed: 81 additions & 108 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require("child_process");
4+
const fs = require("fs");
5+
6+
// These are the directories we want to check for correct naming
7+
const TEST_DIRS = ["tests/unit", "tests/integration", "tests/tck", "tests/fuzz"];
8+
9+
// These are the excluded paths and file names inside the TEST_DIRS
10+
const IGNORED = ["tests/fuzz/support"];
11+
const EXCEPTIONS = ["conftest.py", "__init__.py", "init.py", "mock_server.py", "utils.py"];
12+
13+
// Collect naming errors to report at the end
14+
const nameErrors = [];
15+
16+
// Use "git ls-files" to get all tracked files in the repository
17+
const output = execSync("git ls-files", { encoding: "utf-8" });
18+
// Split output into lines and filter out empty lines for easy manipulation
19+
// e.g. output = "tests/unit/my_test.py\ntests/integration/other_test.py"
20+
const files = output.split("\n").filter(Boolean);
21+
22+
for (const file of files) {
23+
// --- PATH FILTERING ---
24+
// Skip files that are not in any of the specified test directories
25+
if (!TEST_DIRS.some(dir => file.startsWith(dir))) continue;
26+
27+
// Skip ignored paths (e.g. helpers)
28+
if (IGNORED.some(path => file.startsWith(path))) continue;
29+
30+
// Now we have file paths that we need to check for correct naming
31+
// e.g. file = "tests/unit/my_test.py"
32+
33+
// --- Correct PATH now apply NAMING checks ---
34+
35+
// Extract the file name from the path
36+
// e.g. from file = "tests/unit/my_test.py" get name = "my_test.py"
37+
const name = file.split("/").pop();
38+
39+
// Skip allowed special files
40+
if (EXCEPTIONS.includes(name)) continue;
41+
42+
// Enforce naming rule on files
43+
if (!name.endsWith("_test.py")) {
44+
console.error(`Invalid test file name: ${file}`);
45+
console.error(`::error file=${file}::Must end with '_test.py'`);
46+
nameErrors.push(file);
47+
}
48+
}
49+
50+
// Generate a summary of the results for the GitHub Actions UI
51+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
52+
53+
if (summaryPath) {
54+
let summary = `## 🧪 Test File Naming Check\n\n`;
55+
56+
if (nameErrors.length === 0) {
57+
summary += `✅ All test files are correctly named\n`;
58+
} else {
59+
// Counts and lists all the incorrectly named test files
60+
summary += `❌ Found ${nameErrors.length} incorrectly named test files:\n\n`;
61+
nameErrors.forEach(f => {
62+
summary += `- \`${f}\`\n`;
63+
});
64+
}
65+
66+
fs.appendFileSync(summaryPath, summary);
67+
}
68+
69+
// Fail job if needed
70+
if (nameErrors.length > 0) {
71+
process.exit(1);
72+
}

.github/scripts/pr-check-test-files.sh

Lines changed: 0 additions & 93 deletions
This file was deleted.

.github/workflows/pr-check-primary-test-files.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,26 @@ permissions:
1515
contents: read
1616

1717
concurrency:
18-
group: pr-checks-${{ github.workflow }}-${{ github.ref || github.run_id }}
18+
group: pr-checks-${{ github.workflow }}-${{ github.event.pull_request.number }}
1919
cancel-in-progress: true
2020

2121
jobs:
2222
check-test-files:
23-
# No fork check needed: push-only workflow; fork pushes have different repository_owner
24-
runs-on: ${{ (github.repository_owner != 'hiero-ledger') && 'ubuntu-latest' || 'hl-sdk-py-lin-md' }}
23+
runs-on: ${{ (github.event.pull_request.head.repo.full_name == github.repository && github.repository_owner == 'hiero-ledger') && 'hl-sdk-py-lin-md' || 'ubuntu-latest' }}
2524

2625
steps:
2726
- name: Harden the runner (Audit all outbound calls)
2827
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
2928
with:
3029
egress-policy: audit
3130

32-
- name: Checkout repository
31+
- name: Checkout repository (shallow)
3332
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
33+
with:
34+
fetch-depth: 1 # Only fetch the latest commit
3435

35-
- name: Set up Hiero SDK Upstream
36-
run: |
37-
git remote set-url origin https://github.com/hiero-ledger/hiero-sdk-python.git
38-
39-
- name: Fetch main branch
40-
run: |
41-
git fetch origin main
36+
- name: Set up Node.js
37+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
4238

43-
- name: Check added test file names
44-
run: |
45-
chmod +x .github/scripts/pr-check-test-files.sh
46-
.github/scripts/pr-check-test-files.sh
39+
- name: Run test file naming check
40+
run: node .github/scripts/pr-check-test-files.js
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)