From afb3f252d6de47d9b6c018beeead7c3734dc34fb Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 27 Jan 2026 17:44:43 +0900 Subject: [PATCH 1/3] github: scripts: commit_prefix_check: Use basename of filenames in subject Signed-off-by: Hiroshi Hatake --- .github/scripts/commit_prefix_check.py | 46 ++++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/.github/scripts/commit_prefix_check.py b/.github/scripts/commit_prefix_check.py index 307b162d1fc..3cb427f1ce3 100644 --- a/.github/scripts/commit_prefix_check.py +++ b/.github/scripts/commit_prefix_check.py @@ -66,9 +66,19 @@ def infer_prefix_from_paths(paths): if p.startswith("lib/"): component_prefixes.add("lib:") - # ----- tests/ → tests: ----- + # ----- tests//.c → : (strip flb_) ----- if p.startswith("tests/"): - component_prefixes.add("tests:") + parts = p.split("/") + if len(parts) >= 3: + filename = os.path.basename(p) + name, _ = os.path.splitext(filename) + if name.startswith("flb_"): + name = name[4:] + if name: + component_prefixes.add(f"{name}:") + component_prefixes.add("tests:") + else: + component_prefixes.add("tests:") # ----- plugins// → : ----- if p.startswith("plugins/"): @@ -229,25 +239,35 @@ def validate_commit(commit): } # Prefixes that are allowed to cover multiple subcomponents - umbrella_prefixes = {"lib:"} + umbrella_prefixes = {"lib:", "tests:"} # If more than one non-build prefix is inferred AND the subject is not an umbrella # prefix, check if the subject prefix is in the expected list. If it is, allow it # (because the corresponding file exists). Only reject if it's not in the expected list # or if it's an umbrella prefix that doesn't match. if len(non_build_prefixes) > 1: - # Only umbrella prefixes are allowed to cover multiple components if subj_lower in umbrella_prefixes: - # Ensure all changed paths are within the umbrella domain norm_paths = [p.replace(os.sep, "/") for p in files] - if not all(p.startswith("lib/") for p in norm_paths): - expected_list = sorted(expected) - expected_str = ", ".join(expected_list) - return False, ( - f"Subject prefix '{subject_prefix}' does not match files changed.\n" - f"Expected one of: {expected_str}" - ) - elif subj_lower not in umbrella_prefixes: + + if subj_lower == "lib:": + if not all(p.startswith("lib/") for p in norm_paths): + expected_list = sorted(expected) + expected_str = ", ".join(expected_list) + return False, ( + f"Subject prefix '{subject_prefix}' does not match files changed.\n" + f"Expected one of: {expected_str}" + ) + + elif subj_lower == "tests:": + if not all(p.startswith("tests/") for p in norm_paths): + expected_list = sorted(expected) + expected_str = ", ".join(expected_list) + return False, ( + f"Subject prefix '{subject_prefix}' does not match files changed.\n" + f"Expected one of: {expected_str}" + ) + + else: expected_list = sorted(expected) expected_str = ", ".join(expected_list) return False, ( From 6b6eb37f9cd77a9280bca6f9f95b64e1da97de99 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 27 Jan 2026 17:54:58 +0900 Subject: [PATCH 2/3] github: scripts: tests: Use the actual rule on the affected test case Signed-off-by: Hiroshi Hatake --- .github/scripts/tests/test_commit_lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/tests/test_commit_lint.py b/.github/scripts/tests/test_commit_lint.py index be129679693..8c91e16363c 100644 --- a/.github/scripts/tests/test_commit_lint.py +++ b/.github/scripts/tests/test_commit_lint.py @@ -611,7 +611,7 @@ def test_valid_test_file_changes(): Generic prefixes like "tests:" are acceptable for test-related changes. """ commit = make_commit( - "tests: add unit test\n\nSigned-off-by: User", + "tests: test_router: add unit test\n\nSigned-off-by: User", ["tests/unit/test_router.c"] ) ok, _ = validate_commit(commit) From dad8f5d1ef4cc32646e4b09e37f3e5c0275afa65 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 28 Jan 2026 12:15:43 +0900 Subject: [PATCH 3/3] github: scripts: tests: Clarify the specification of tests umbrella rule Signed-off-by: Hiroshi Hatake --- .github/scripts/tests/test_commit_lint.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/scripts/tests/test_commit_lint.py b/.github/scripts/tests/test_commit_lint.py index 8c91e16363c..5773a202622 100644 --- a/.github/scripts/tests/test_commit_lint.py +++ b/.github/scripts/tests/test_commit_lint.py @@ -617,6 +617,24 @@ def test_valid_test_file_changes(): ok, _ = validate_commit(commit) assert ok is True + +def test_invalid_test_file_changes_without_umbrella_prefix(): + """ + Test that test file changes are disallowed without tests umbrella under tests components. + + + Test files (in tests/ directory) basically allows tests umbrella prefix. + Without "tests:" umbrella prefix are not acceptable for test-related changes. + """ + commit = make_commit( + "test_router: add unit test\n\nSigned-off-by: User", + ["tests/internal/test_router.c"] + ) + ok, msg = validate_commit(commit) + assert ok is False + assert "Expected one of: test_router:, tests:" in msg + + def test_valid_build_file_changes(): """ Test that build system file changes are allowed with generic prefixes.