Skip to content

Add fallback-mode option for subset#1308

Open
takanabe wants to merge 1 commit into
mainfrom
fallback-mode
Open

Add fallback-mode option for subset#1308
takanabe wants to merge 1 commit into
mainfrom
fallback-mode

Conversation

@takanabe
Copy link
Copy Markdown
Contributor

@takanabe takanabe commented May 28, 2026

Background

When the subset API errors or returns isBrainless=true, users can now opt into 'stop' (exit non-zero to halt CI) or 'random-sample' (split locally using --target) instead of the default run-all behavior. The option is hidden and off by default so existing pipelines are unaffected.

Changes

  • Add --fallback-mode option for subset command

When the subset API errors or returns isBrainless=true, users can now
opt into 'stop' (exit non-zero to halt CI) or 'random-sample' (split
locally using --target) instead of the default run-all behavior.
The option is hidden and off by default so existing pipelines are unaffected.
elif self.fallback_mode == FallbackMode.RANDOM_SAMPLE:
target_fraction = float(self.target) if self.target is not None else 1.0
click.echo(
"Warning: Smart Tests could not retrieve a subset. Falling back to local random sample.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since users may use options other than --target e.g.) --confidence, it might be helpful to include the target percentage in the warning message as well.

Or, if --fallback_mode is specified and the user is using an option other than --target, we could return an error in the validation arera

sampled = random.sample(test_paths, min(count, len(test_paths)))
sampled_set = {id(t): t for t in sampled}
rest = [t for t in test_paths if id(t) not in sampled_set]
return cls(subset=sampled, rest=rest, subset_id='', summary={}, is_brainless=False, is_observation=False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is_brainless=False intentionally?

result = self.cli(*self._subset_args(rest_file.name, ("--fallback-mode", "random-sample")), mix_stderr=False)
self.assert_success(result)
all_tests = result.stdout.strip().split("\n") + Path(rest_file.name).read_text().strip().split("\n")
all_tests = [t for t in all_tests if t]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: What is this loop?

# TODO(Konboi): split subset isn't provided for smart-tests initial release
# if split:
# click.echo("subset/{}".format(subset_result.subset_id))
if subset_result.is_brainless:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Brainless mode, we're already splitting requests between subset and rest on the server side.

I can understand the stop behavior, but for sampling, do you mean re-sampling the tests on the CLI side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants