Skip to content

Commit 34d1498

Browse files
committed
fix(harness): reject invalid --legs values at the CLI (CodeRabbit)
parse_legs stays a lenient normalizer (test_drops_unknown_legs), but main() now validates the raw --legs input against the shared ALLOWED_LEGS and exits 2 on any unknown value -- so a typo like `smoke,edimode` fails loudly instead of silently dropping the bad leg and running a subset.
1 parent 86d6f7a commit 34d1498

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tools/local_harness.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,21 @@ def build_arg_parser() -> argparse.ArgumentParser:
706706
aggregate_exit_code = aggregate_exit
707707

708708

709+
ALLOWED_LEGS = ("smoke", "editmode", "playmode")
710+
711+
709712
def parse_legs(legs: str) -> list[str]:
710-
"""Normalize the --legs CSV into an ordered, de-duplicated list."""
711-
allowed = ["smoke", "editmode", "playmode"]
713+
"""Normalize the --legs CSV into an ordered, de-duplicated list.
714+
715+
Lenient by design -- unknown values are dropped (see test_drops_unknown_legs).
716+
The CLI entry point (main) validates raw input against ALLOWED_LEGS and
717+
rejects unknown values before calling this; keep this a pure normalizer.
718+
"""
712719
seen: set[str] = set()
713720
out: list[str] = []
714721
for part in (legs or "").split(","):
715722
leg = part.strip().lower()
716-
if leg and leg in allowed and leg not in seen:
723+
if leg and leg in ALLOWED_LEGS and leg not in seen:
717724
seen.add(leg)
718725
out.append(leg)
719726
return out
@@ -1348,9 +1355,15 @@ def _print_summary(outcomes: list[LegOutcome], exit_code: int) -> None:
13481355
def main(argv: list[str] | None = None) -> int:
13491356
args = build_arg_parser().parse_args(argv)
13501357

1358+
requested_legs = [p.strip().lower() for p in (args.legs or "").split(",") if p.strip()]
1359+
invalid_legs = [leg for leg in requested_legs if leg not in ALLOWED_LEGS]
1360+
if invalid_legs:
1361+
print(f"::error:: --legs included invalid value(s): {', '.join(invalid_legs)} "
1362+
f"(allowed: {', '.join(ALLOWED_LEGS)})")
1363+
return 2
13511364
legs = parse_legs(args.legs)
13521365
if not legs:
1353-
print("::error:: --legs did not include any valid values (allowed: smoke,editmode,playmode)")
1366+
print(f"::error:: --legs did not include any valid values (allowed: {', '.join(ALLOWED_LEGS)})")
13541367
return 2
13551368
if args.ci:
13561369
args.no_warmup = True

0 commit comments

Comments
 (0)