1- """Discover test base directories via __test_labels__ .yaml or MatrixBenchmarking settings.yaml."""
1+ """Discover test base directories via __caliper_test_metadata__ .yaml or MatrixBenchmarking settings.yaml."""
22
33from __future__ import annotations
44
88
99import yaml
1010
11+ from projects .caliper .engine .constants import (
12+ LEGACY_METADATA_FILE ,
13+ MATRIXBENCHMARKING_SETTINGS_FILE ,
14+ METADATA_FILE ,
15+ )
1116from projects .caliper .engine .model import TestBaseNode
1217
13- MARKER = "__test_labels__.yaml"
14- MATRIXBENCHMARKING_MARKER = "settings.yaml"
18+ # Primary marker
19+ MARKER = METADATA_FILE
20+ # Legacy marker for backwards compatibility
21+ LEGACY_MARKER = LEGACY_METADATA_FILE
22+ MATRIXBENCHMARKING_MARKER = MATRIXBENCHMARKING_SETTINGS_FILE
1523
1624
1725def discover_test_bases (
@@ -40,6 +48,8 @@ def discover_test_bases(
4048 marker_found = None
4149 if MARKER in filenames :
4250 marker_found = MARKER
51+ elif LEGACY_MARKER in filenames :
52+ marker_found = LEGACY_MARKER # Backwards compatibility
4353 elif MATRIXBENCHMARKING_MARKER in filenames :
4454 marker_found = MATRIXBENCHMARKING_MARKER
4555
@@ -49,7 +59,7 @@ def discover_test_bases(
4959 path = Path (dirpath )
5060
5161 # Use hierarchical label loading for both marker types
52- if marker_found == MARKER :
62+ if marker_found == MARKER or marker_found == LEGACY_MARKER :
5363 test_labels = _load_hierarchical_test_labels (path , base_dir )
5464 # For filtering, use the labels directly (hierarchical loading returns the labels dict)
5565 # Normalize missing "labels" entry to empty mapping to allow discovery of empty marker files
@@ -144,15 +154,16 @@ def _matches_any_local(labels_dict: dict, key: str, filter_values: list[str]) ->
144154
145155
146156def _load_hierarchical_test_labels (test_dir : Path , base_dir : Path ) -> dict [str , Any ]:
147- """Load and merge __test_labels__.yaml files hierarchically from base_dir down to test_dir.
157+ """Load and merge test metadata files hierarchically from base_dir down to test_dir.
148158
149- Merges in order:
150- 1. base_dir/__test_labels__ .*.yaml (all variants)
151- 2. parent_dir/ __test_labels__.*.yaml (all variants)
152- 3. test_dir/__test_labels__.*. yaml (all variants )
153- 4. test_dir/ __test_labels__.yaml (final, cannot be overridden )
159+ Merges in order (for each directory) :
160+ 1. __caliper_test_metadata__ .*.yaml (all variants, new format )
161+ 2. __test_labels__.*.yaml (all variants, legacy format )
162+ 3. __caliper_test_metadata__. yaml (final, new format )
163+ 4. __test_labels__.yaml (final, legacy fallback )
154164
155- Later files override earlier ones, with the main __test_labels__.yaml having final priority.
165+ Later files override earlier ones, with the main metadata file having final priority.
166+ New format files are preferred over legacy format when both exist.
156167 """
157168 import glob
158169
@@ -172,14 +183,19 @@ def _load_hierarchical_test_labels(test_dir: Path, base_dir: Path) -> dict[str,
172183 # test_dir is not under base_dir, just use test_dir
173184 path_parts = [test_dir_abs ]
174185
175- # For each directory in the hierarchy, merge __test_labels__.*.yaml files (excluding plain __test_labels__.yaml )
186+ # For each directory in the hierarchy, merge variant files (new format first, then legacy )
176187 for dir_path in path_parts :
177188 if not dir_path .is_dir ():
178189 continue
179190
180- # Find all __test_labels__.*.yaml files (but not __test_labels__.yaml itself)
181- pattern = str (dir_path / "__test_labels__.*.yaml" )
182- variant_files = sorted (glob .glob (pattern ))
191+ # Find all variant files - new format first
192+ new_pattern = str (dir_path / f"{ METADATA_FILE .replace ('.yaml' , '.*.yaml' )} " )
193+ legacy_pattern = str (dir_path / f"{ LEGACY_METADATA_FILE .replace ('.yaml' , '.*.yaml' )} " )
194+
195+ # Collect all variant files, prioritizing new format
196+ variant_files = []
197+ variant_files .extend (sorted (glob .glob (new_pattern )))
198+ variant_files .extend (sorted (glob .glob (legacy_pattern )))
183199
184200 for variant_file in variant_files :
185201 variant_path = Path (variant_file )
@@ -192,8 +208,12 @@ def _load_hierarchical_test_labels(test_dir: Path, base_dir: Path) -> dict[str,
192208 # Skip files that can't be loaded
193209 pass
194210
195- # Finally, load the main __test_labels__.yaml from the test directory (final priority)
211+ # Finally, load the main metadata file from the test directory (final priority)
212+ # Prefer new format, fall back to legacy format
196213 main_labels_path = test_dir / MARKER
214+ if not main_labels_path .is_file ():
215+ main_labels_path = test_dir / LEGACY_MARKER
216+
197217 if main_labels_path .is_file ():
198218 try :
199219 main_labels = _load_labels (main_labels_path , is_matrixbenchmarking = False )
0 commit comments