2020{% set hf_home_fsx = "/fsx/hf_cache" %}
2121{% set list_file_diff = list_file_diff | split ("|" ) %}
2222
23- {# Intelligent test targeting: Detect when only test files changed and collect them #}
24- {% - set tests_acc = namespace (only_tests =true , any =false , changed =[]) %}
25- {% - for file in list_file_diff %}
26- {% - if file [:6] == 'tests/' and '/test_' in file and file [-3:] == '.py' %}
27- {% - set tests_acc .any = true %}
28- {% - set tests_acc .changed = tests_acc .changed + [file [6:]] %}
29- {% - else %}
30- {% - set tests_acc .only_tests = false %}
31- {% - endif %}
32- {% - endfor %}
33- {% - set tests_only = (tests_acc .only_tests and tests_acc .any ) %}
34- {% - set changed_tests = tests_acc .changed %}
35-
3623{% macro add_pytest_coverage (cmd , coverage_file ) %}
3724{% if "pytest " in cmd %}
3825COVERAGE_FILE={{ coverage_file }} {{ cmd | replace("pytest ", "pytest --cov=vllm --cov-report= --cov-append --durations=0 ") }} || true
@@ -47,131 +34,6 @@ COVERAGE_FILE={{ coverage_file }} {{ cmd | replace("pytest ", "pytest --cov=vllm
4734{% set step_first = step .label | first | default ("x" ) %}
4835{% set coverage_file = ".coverage." + step_length ~ "_" ~ step_first %}
4936
50- {# Intelligent test targeting: Build matched test targets for this step when only tests changed #}
51- {% - set match_ns = namespace (targets =[]) %}
52- {% - if tests_only and step .source_file_dependencies %}
53- {% - for dep in step .source_file_dependencies %}
54- {% - if dep [:6] == 'tests/' %}
55- {% - set dep_rel = dep [6:] %}
56- {# Handle deps that already end with '/' (e.g., tests/benchmarks/) #}
57- {% - if dep_rel [-1:] == '/' %}
58- {% - set dep_dir_prefix = dep_rel %}
59- {% - set dep_file_name = dep_rel [:-1] ~ '.py' %}
60- {% - else %}
61- {% - set dep_dir_prefix = dep_rel ~ '/' %}
62- {% - set dep_file_name = dep_rel ~ '.py' %}
63- {% - endif %}
64- {% - for t in changed_tests %}
65- {# Check if t starts with dep_dir_prefix (for directories) or equals dep_file_name (for files) #}
66- {% - set prefix_len = dep_dir_prefix | length %}
67- {% - set t_prefix = t [:prefix_len ] %}
68- {% - set cond 1 = (t | length >= prefix_len and t_prefix == dep_dir_prefix ) %}
69- {% - set cond 2 = (t == dep_file_name ) %}
70- {% - if cond 1 or cond 2 %}
71- {% - set match_ns .targets = match_ns .targets + [t ] %}
72- {% - endif %}
73- {% - endfor %}
74- {% - endif %}
75- {% - endfor %}
76- {% - endif %}
77- {% - set matched_targets = match_ns .targets %}
78-
79- {# Filter matched targets to only include those actually covered by step commands #}
80- {# This ensures intelligent filtering mirrors normal behavior - if a test isn't run normally, don't run it in intelligent mode #}
81- {% - set filter_ns = namespace (filtered_targets =[], covered_paths =[]) %}
82- {% - if matched_targets | length > 0 %}
83- {% - set all_commands = step .commands if step .commands else ([step .command ] if step .command else []) %}
84- {# Extract test paths from pytest commands (e.g., "v1/core", "v1/executor") #}
85- {% - for cmd in all_commands %}
86- {% - if "pytest " in cmd %}
87- {# Split command to find pytest arguments #}
88- {% - set cmd_parts = cmd | split (" " ) | list %}
89- {% - set in_pytest = false %}
90- {% - for part in cmd_parts %}
91- {% - if part == "pytest" %}
92- {% - set in_pytest = true %}
93- {% - elif in_pytest and part [:1] != "-" and "/" in part %}
94- {# This looks like a test path (contains / and doesn't start with -) #}
95- {# Skip specific tests (contain ::) - we only want directories or files #}
96- {% - if "::" not in part %}
97- {% - if part [-3:] == ".py" %}
98- {# It's a file - add both the file itself and its directory (if deep enough) #}
99- {# Add the file as-is for exact matching #}
100- {% - set filter_ns .covered_paths = filter_ns .covered_paths + [part ] %}
101- {# Also add directory if it has at least 2 levels (e.g., v1/core but not just v1) #}
102- {% - set path_parts = part | split ("/" ) | list %}
103- {% - if path_parts | length > 2 %}
104- {% - set dir_parts = path_parts [:-1] %}
105- {% - set dir_path = dir_parts | join ("/" ) %}
106- {% - set filter_ns .covered_paths = filter_ns .covered_paths + [dir_path ] %}
107- {% - endif %}
108- {% - else %}
109- {# It's a directory path #}
110- {% - set filter_ns .covered_paths = filter_ns .covered_paths + [part ] %}
111- {% - endif %}
112- {% - endif %}
113- {% - endif %}
114- {% - endfor %}
115- {% - endif %}
116- {% - endfor %}
117- {# Now check each matched target against covered paths #}
118- {% - for target in matched_targets %}
119- {% - set target_ns = namespace (is_covered =false ) %}
120- {% - for covered_path in filter_ns .covered_paths %}
121- {# Check if target starts with this covered path (ensure proper directory matching) #}
122- {% - set covered_len = covered_path | length %}
123- {% - if target [:covered_len ] == covered_path %}
124- {# Ensure it's a proper directory match (next char is / or end of string) #}
125- {% - if target | length == covered_len or target [covered_len :covered_len +1] == "/" %}
126- {% - set target_ns .is_covered = true %}
127- {% - endif %}
128- {% - endif %}
129- {% - endfor %}
130- {% - if target_ns .is_covered %}
131- {% - set filter_ns .filtered_targets = filter_ns .filtered_targets + [target ] %}
132- {% - endif %}
133- {% - endfor %}
134- {% - endif %}
135- {% - set matched_targets = filter_ns .filtered_targets %}
136-
137- {# Extract pytest markers from original commands to preserve them in intelligent filtering #}
138- {% - set marker_ns = namespace (markers ='' ) %}
139- {% - if matched_targets | length > 0 %}
140- {% - set all_commands = step .commands if step .commands else ([step .command ] if step .command else []) %}
141- {% - for cmd in all_commands %}
142- {% - if "pytest " in cmd and " -m " in cmd %}
143- {# Extract the -m marker argument using split filter and convert to list #}
144- {% - set parts = cmd | split (" -m " ) | list %}
145- {% - if parts | length > 1 %}
146- {% - set after_m = parts [1] %}
147- {# Find the marker value (first token after -m, handling quotes) #}
148- {% - if after_m [0:1] == "'" %}
149- {% - set marker_parts = after_m [1:] | split ("'" ) | list %}
150- {% - if marker_parts | length > 0 %}
151- {% - set marker_ns .markers = " -m '" ~ marker_parts [0] ~ "'" %}
152- {% - endif %}
153- {% - elif after_m [0:1] == '"' %}
154- {% - set marker_parts = after_m [1:] | split ('"' ) | list %}
155- {% - if marker_parts | length > 0 %}
156- {% - set marker_ns .markers = ' -m "' ~ marker_parts [0] ~ '"' %}
157- {% - endif %}
158- {% - else %}
159- {# No quotes, take first word #}
160- {% - set marker_parts = after_m | split (" " ) | list %}
161- {% - if marker_parts | length > 0 %}
162- {% - set marker_ns .markers = " -m " ~ marker_parts [0] %}
163- {% - endif %}
164- {% - endif %}
165- {% - endif %}
166- {% - endif %}
167- {% - endfor %}
168- {% - endif %}
169-
170- {# If we have matched targets, run only those specific tests #}
171- {% if matched_targets | length > 0 %}
172- pytest -v -s{{ marker_ns.markers }} {{ matched_targets | join(' ') }}
173- {% else %}
174- {# Default behavior: preserve original commands with optional coverage injection #}
17537{% if cov_enabled %}
17638{% set ns = namespace (has_pytest =false ) %}
17739{% if step .command %}
@@ -185,7 +47,6 @@ pytest -v -s{{ marker_ns.markers }} {{ matched_targets | join(' ') }}
18547{% else %}
18648{{ step.command or (step.commands | join(' && ')) | safe }}
18749{% endif %}
188- {% endif %}
18950{% endmacro %}
19051
19152{% macro render_cuda_config (step , image , default_working_dir , hf_home_fsx , hf_home , branch ) %}
0 commit comments