Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/scripts/pr-check-test-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env node

const { execSync } = require("child_process");
const fs = require("fs");

// These are the directories we want to check for correct naming
const TEST_DIRS = ["tests/unit", "tests/integration", "tests/tck", "tests/fuzz"];

// These are the excluded paths and file names inside the TEST_DIRS
const IGNORED = ["tests/fuzz/support"];
const EXCEPTIONS = ["conftest.py", "__init__.py", "init.py", "mock_server.py", "utils.py"];

// Collect naming errors to report at the end
const nameErrors = [];

// Use "git ls-files" to get all tracked files in the repository
Comment thread
exploreriii marked this conversation as resolved.
const output = execSync("git ls-files", { encoding: "utf-8" });
// Split output into lines and filter out empty lines for easy manipulation
// e.g. output = "tests/unit/my_test.py\ntests/integration/other_test.py"
const files = output.split("\n").filter(Boolean);
Comment thread
exploreriii marked this conversation as resolved.

for (const file of files) {
// --- PATH FILTERING ---
// Skip files that are not in any of the specified test directories
if (!TEST_DIRS.some(dir => file.startsWith(dir))) continue;

// Skip ignored paths (e.g. helpers)
if (IGNORED.some(path => file.startsWith(path))) continue;

// Now we have file paths that we need to check for correct naming
// e.g. file = "tests/unit/my_test.py"

// --- Correct PATH now apply NAMING checks ---

// Extract the file name from the path
// e.g. from file = "tests/unit/my_test.py" get name = "my_test.py"
const name = file.split("/").pop();

// Skip allowed special files
if (EXCEPTIONS.includes(name)) continue;

// Enforce naming rule on files
if (!name.endsWith("_test.py")) {
console.error(`Invalid test file name: ${file}`);
console.error(`::error file=${file}::Must end with '_test.py'`);
nameErrors.push(file);
Comment thread
exploreriii marked this conversation as resolved.
}
Comment thread
exploreriii marked this conversation as resolved.
}

// Generate a summary of the results for the GitHub Actions UI
const summaryPath = process.env.GITHUB_STEP_SUMMARY;

if (summaryPath) {
let summary = `## 🧪 Test File Naming Check\n\n`;

if (nameErrors.length === 0) {
summary += `✅ All test files are correctly named\n`;
} else {
// Counts and lists all the incorrectly named test files
summary += `❌ Found ${nameErrors.length} incorrectly named test files:\n\n`;
nameErrors.forEach(f => {
summary += `- \`${f}\`\n`;
});
}

fs.appendFileSync(summaryPath, summary);
}

// Fail job if needed
if (nameErrors.length > 0) {
process.exit(1);
}
93 changes: 0 additions & 93 deletions .github/scripts/pr-check-test-files.sh

This file was deleted.

24 changes: 9 additions & 15 deletions .github/workflows/pr-check-primary-test-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,26 @@ permissions:
contents: read

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

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

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

- name: Checkout repository
- name: Checkout repository (shallow)
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
with:
fetch-depth: 1 # Only fetch the latest commit

- name: Set up Hiero SDK Upstream
run: |
git remote set-url origin https://github.com/hiero-ledger/hiero-sdk-python.git

- name: Fetch main branch
run: |
git fetch origin main
- name: Set up Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0

- name: Check added test file names
run: |
chmod +x .github/scripts/pr-check-test-files.sh
.github/scripts/pr-check-test-files.sh
- name: Run test file naming check
run: node .github/scripts/pr-check-test-files.js
Comment thread
exploreriii marked this conversation as resolved.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading