1717{% set hf_home_fsx = "/fsx/hf_cache" %}
1818{% set list_file_diff = list_file_diff | split ("|" ) %}
1919
20+ {# Intelligent test targeting: Detect when only test files changed and collect them #}
21+ {% - set tests_acc = namespace (only_tests =true , any =false , changed =[]) %}
22+ {% - for file in list_file_diff %}
23+ {% - if file [:6] == 'tests/' and '/test_' in file and file [-3:] == '.py' %}
24+ {% - set tests_acc .any = true %}
25+ {% - set tests_acc .changed = tests_acc .changed + [file [6:]] %}
26+ {% - else %}
27+ {% - set tests_acc .only_tests = false %}
28+ {% - endif %}
29+ {% - endfor %}
30+ {% - set tests_only = (tests_acc .only_tests and tests_acc .any ) %}
31+ {% - set changed_tests = tests_acc .changed %}
32+
2033{% macro add_pytest_coverage (cmd , coverage_file ) %}
2134{% if "pytest " in cmd %}
2235COVERAGE_FILE={{ coverage_file }} {{ cmd | replace("pytest ", "pytest --cov=vllm --cov-report=xml --cov-append --durations=0 ") }} || true
@@ -26,10 +39,46 @@ COVERAGE_FILE={{ coverage_file }} {{ cmd | replace("pytest ", "pytest --cov=vllm
2639{% endmacro %}
2740
2841{% macro add_docker_pytest_coverage (step , cov_enabled ) %}
29- {% if cov_enabled % }
42+ {# Compute coverage file id # }
3043{% set step_length = step .label | length %}
3144{% set step_first = step .label | first | default ("x" ) %}
3245{% set coverage_file = ".coverage." + step_length ~ "_" ~ step_first %}
46+
47+ {# Intelligent test targeting: Build matched test targets for this step when only tests changed #}
48+ {% - set match_ns = namespace (targets =[]) %}
49+ {% - if tests_only and step .source_file_dependencies %}
50+ {% - for dep in step .source_file_dependencies %}
51+ {% - if dep [:6] == 'tests/' %}
52+ {% - set dep_rel = dep [6:] %}
53+ {# Handle deps that already end with '/' (e.g., tests/benchmarks/) #}
54+ {% - if dep_rel [-1:] == '/' %}
55+ {% - set dep_dir_prefix = dep_rel %}
56+ {% - set dep_file_name = dep_rel [:-1] ~ '.py' %}
57+ {% - else %}
58+ {% - set dep_dir_prefix = dep_rel ~ '/' %}
59+ {% - set dep_file_name = dep_rel ~ '.py' %}
60+ {% - endif %}
61+ {% - for t in changed_tests %}
62+ {# Check if t starts with dep_dir_prefix (for directories) or equals dep_file_name (for files) #}
63+ {% - set prefix_len = dep_dir_prefix | length %}
64+ {% - set t_prefix = t [:prefix_len ] %}
65+ {% - set cond 1 = (t | length >= prefix_len and t_prefix == dep_dir_prefix ) %}
66+ {% - set cond 2 = (t == dep_file_name ) %}
67+ {% - if cond 1 or cond 2 %}
68+ {% - set match_ns .targets = match_ns .targets + [t ] %}
69+ {% - endif %}
70+ {% - endfor %}
71+ {% - endif %}
72+ {% - endfor %}
73+ {% - endif %}
74+ {% - set matched_targets = match_ns .targets %}
75+
76+ {# If we have matched targets, run only those specific tests #}
77+ {% if matched_targets | length > 0 %}
78+ pytest -v -s {{ matched_targets | join(' ') }}
79+ {% else %}
80+ {# Default behavior: preserve original commands with optional coverage injection #}
81+ {% if cov_enabled %}
3382{% set ns = namespace (has_pytest =false ) %}
3483{% if step .command %}
3584{% if "pytest " in step .command %}{% set ns .has_pytest = true %}{% endif %}
@@ -42,6 +91,7 @@ COVERAGE_FILE={{ coverage_file }} {{ cmd | replace("pytest ", "pytest --cov=vllm
4291{% else %}
4392{{ step.command or (step.commands | join(' && ')) | safe }}
4493{% endif %}
94+ {% endif %}
4595{% endmacro %}
4696
4797{% macro render_cuda_config (step , image , default_working_dir , hf_home_fsx , hf_home , branch ) %}
0 commit comments