bazelbuild/bazel

`@` character in label causes parsing issue with `--flaky_test_attempts`

Open

#19,447 opened on Sep 7, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Java (4,465 forks)batch import
P3help wantedteam-CLItype: bug

Repository metrics

Stars
 (25,384 stars)
PR merge metrics
 (Avg merge 22d 20h) (77 merged PRs in 30d)

Description

Description of the bug:

According to the documentation, @ is a valid character in target labels - https://bazel.build/concepts/labels#target-names

@ is also the character used to separate target labels from the number of attempts when using --flaky_test_attempts - https://bazel.build/reference/command-line-reference#flag--flaky_test_attempts

Alternate syntax: regex_filter@flaky_test_attempts. Where flaky_test_attempts is as above and regex_filter stands for a list of include and exclude regular expression patterns (Also see --runs_per_test). Example: --flaky_test_attempts=//foo/.*,-//foo/bar/.*@3 deflakes all tests in //foo/ except those under foo/bar three times

If you try to use this @ syntax in --flaky_test_attempts with a label that includes an @ sign, CLI argument parsing fails.

$ bazel test //... --flaky_test_attempts=//foo:v@lid-target@3
ERROR: While parsing option --flaky_test_attempts=//foo:v@lid-target@3: '//foo:v@lid-target@3' has a non-numeric value

This is due to this line of code here - https://github.com/bazelbuild/bazel/blob/7e0df68aa4d11307dff8571ebce11d37c79c170c/src/main/java/com/google/devtools/build/lib/analysis/config/PerLabelOptions.java#L50 - which uses the first @ to split the string.

Which category does this issue belong to?

CLI

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

In any repo

$ bazel test //... --flaky_test_attempts=//foo:v@lid-target@3

Confirm that you get an error.

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 6.3.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

N/A

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

N/A

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

Not as far as I know

Have you found anything relevant by searching the web?

Google didn't turn up anything

Any other information, logs, or outputs that you want to share?

No response

Contributor guide