| 93 | |
| 94 | |
| 95 | def predict(root, changed, selection, detect, depth): |
| 96 | file_suites, test_suites, universe, sources, runnable = suitemap(root) |
| 97 | reasons, run_all = [], False |
| 98 | if selection.get("full"): |
| 99 | run_all = True |
| 100 | reasons.append(f"run-all: the lane selector ran everything ({selection.get('tier')})") |
| 101 | for p in changed: |
| 102 | if p.startswith("tests/") and not p.startswith("tests/fixtures/") and p.endswith(".h"): |
| 103 | run_all = True |
| 104 | reasons.append(f"run-all: test header {p}") |
| 105 | elif p.startswith("test-infrastructure/"): |
| 106 | run_all = True |
| 107 | reasons.append(f"run-all: test infrastructure {p}") |
| 108 | |
| 109 | graph = {"consulted": detect is not None} |
| 110 | picked = {} # suite -> "ALL" | set(tests) |
| 111 | if detect is not None: |
| 112 | rows = detect.get("impacted", []) |
| 113 | total = detect.get("impacted_total", len(rows)) |
| 114 | shown = detect.get("impacted_shown", len(rows)) |
| 115 | graph.update(impacted_total=total, impacted_shown=shown, |
| 116 | saturated=bool(detect.get("engine_saturated"))) |
| 117 | if graph["saturated"]: |
| 118 | run_all = True |
| 119 | reasons.append("run-all: detect_changes saturated") |
| 120 | if total > len(rows) or shown > len(rows): |
| 121 | run_all = True |
| 122 | reasons.append(f"run-all: impact set truncated ({len(rows)} of {total} rows)") |
| 123 | tests = 0 |
| 124 | for r in rows: |
| 125 | fp, name = r.get("file", ""), r.get("qn", "").rsplit(".", 1)[-1] |
| 126 | if not fp.startswith("tests/") or r.get("label") != "Function" or r.get("hop", 0) > depth: |
| 127 | continue |
| 128 | local = file_suites.get(fp, []) |
| 129 | if name in local: |
| 130 | continue # the SUITE function itself |
| 131 | candidates = test_suites.get(name, []) |
| 132 | for suite in [s for s in candidates if s in local] or candidates: |
| 133 | for runner in runnable(suite): |
| 134 | picked.setdefault(runner, set()).add(name) |
| 135 | tests += 1 |
| 136 | graph["test_rows"] = tests |
| 137 | elif needs_graph(changed): |
| 138 | run_all = True |
| 139 | reasons.append("run-all: C change but no impact set (graph not consulted)") |
| 140 | |
| 141 | for p in changed: |
| 142 | if p.startswith("tests/fixtures/"): # fixture sources are data, not tests |
| 143 | key = p.split("/")[2] if p.count("/") >= 2 else p |
| 144 | for f, src in sources.items(): |
| 145 | if key in src: |
| 146 | for suite in file_suites.get(f, []): |
| 147 | for runner in runnable(suite): |
| 148 | picked[runner] = "ALL" |
| 149 | reasons.append(f"changed fixture {p}: suites whose tests name '{key}'") |
| 150 | elif p.startswith("tests/") and p.endswith(".c"): |
| 151 | for suite in file_suites.get(p, []): |
| 152 | for runner in runnable(suite): |