Skip to content

Commit 75d7e6b

Browse files
YAML linter: Add check for manual steps, remove known bad unit tests (#35493)
* YAML linter: Add check for manual steps, remove known bad unit tests * test bad change * Restyled by isort * Trying again for CI - checkout had no depth * testing - I can't repro locally * ha...removed my test bad test * more testing...ci is different than local and act * debugging in ci...fun times * Restyled by whitespace * let's just run the one, ya? * Fix git on the VM * Actually error though * Revert "let's just run the one, ya?" This reverts commit e3c045d. * Remove the added bad step --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent ea8b849 commit 75d7e6b

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

.github/workflows/cert_test_checks.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ on:
1818
pull_request:
1919
paths:
2020
- "src/app/tests/suites/certification/**"
21+
permissions:
22+
contents: read
2123

2224
jobs:
2325
check-certification-tests:
@@ -30,6 +32,8 @@ jobs:
3032
steps:
3133
- name: Checkout
3234
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
3337
- name: Run checks
3438
run: |
3539
python3 scripts/tests/matter_yaml_linter.py

scripts/tests/matter_yaml_linter.py

+30-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
import os
1717
import re
18+
import subprocess
1819
import sys
1920
from pathlib import Path
2021

@@ -23,15 +24,12 @@
2324
DEFAULT_CHIP_ROOT = os.path.abspath(
2425
os.path.join(os.path.dirname(__file__), '..', '..'))
2526

26-
# TODO: These tests need to be re-written. Please see https://github.com/project-chip/connectedhomeip/issues/32620
27-
KNOWN_BAD_UNIT_TESTING = set(('Test_TC_S_2_2.yaml', 'Test_TC_S_2_3.yaml'))
28-
2927

3028
def _is_cert_test(path):
3129
return "certification" in os.path.dirname(path)
3230

3331

34-
def main():
32+
def check_unit_testing():
3533
bad_tests = set()
3634
for test in AllChipToolYamlTests(use_short_run_name=False):
3735
with open(test.run_name, "r") as f:
@@ -47,10 +45,37 @@ def main():
4745
print(f'\t{line+1}: {val}')
4846
bad_tests.add(Path(test.run_name).name)
4947

50-
if bad_tests - KNOWN_BAD_UNIT_TESTING:
48+
if bad_tests:
5149
return 1
5250
return 0
5351

5452

53+
def check_manual_steps():
54+
# Doing this on a test-by-test basis so the log message is more obvious
55+
bad_test = False
56+
# We are operating in a VM, and although there is a checkout, it is working in a scratch directory
57+
# where the ownership is different than the runner.
58+
# Adding an exception for this directory so that git can function properly.
59+
subprocess.run("git config --global --add safe.directory '*'", shell=True)
60+
for test in AllChipToolYamlTests(use_short_run_name=False):
61+
62+
cmd = f'git diff HEAD^..HEAD --unified=0 -- {test.run_name}'
63+
output = subprocess.check_output(cmd, shell=True).decode().splitlines()
64+
user_prompt_added = [line for line in output if re.search(r'^\+.*UserPrompt.*', line)]
65+
user_prompt_removed = [line for line in output if re.search(r'^\-.*UserPrompt.*', line)]
66+
if len(user_prompt_added) > len(user_prompt_removed):
67+
print(f'Found YAML test with additional manual steps: {test.name}')
68+
bad_test = True
69+
if bad_test:
70+
return 1
71+
return 0
72+
73+
74+
def main():
75+
ret = check_unit_testing()
76+
ret += check_manual_steps()
77+
return ret
78+
79+
5580
if __name__ == '__main__':
5681
sys.exit(main())

0 commit comments

Comments
 (0)