Skip to content

Add test: randBinomial probability-domain guard p < 0.0 || p > 1.0 is untested - #112006

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr111909
Jul 29, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr111909

Conversation

@clickgapai

@clickgapai clickgapai commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

This is a test-only PR — no source code changes. Please review: test quality, whether the claimed coverage gaps are real, and whether test output makes sense.

Adds test coverage for 1 untested code path(s), found during automated review of PR #111909.
That PR The PR hardens randChiSquared, randStudentT, randFisherF and randBinomial against unkillable hangs with extreme parameters. It adds unconditional hard bounds (max_degrees_of_freedom = FLT_MAX/12 and max_number_of_trials = 10^9) that apply even when the tunable settings `max_rand_distribu

1. randBinomial probability-domain guard p < 0.0 || p > 1.0 is untested
src/Functions/randDistribution.cpp:244
Risk: BinomialDistribution::generate at randDistribution.cpp:243 checks if (p < 0.0 || p > 1.0) and throws at line 244 (LLVM-confirmed uncovered). This guard prevents an invalid probability from reaching std::binomial_distribution<UInt64>(t, p), whose behavior for p outside [0, 1] is undefined. Risk if broken: an invalid p reaches the standard-library sampler, producing undefined behavior in the same class of unbounded/garbage sampling this PR set out to eliminate.
What's unique vs PR tests: The PR's 04628 test only exercises the trials-too-large guard (line 245-246) and in-domain values for randBinomial; it never passes a probability outside [0, 1], so the line-243/244 probability guard is left uncovered.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not applicable — test-only change.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.339 (included in 26.8 and later)

@clickgapai

Copy link
Copy Markdown
Contributor Author

Pre-PR Validation Gate (per ClickGap pipeline):

a) Deterministic repro? ✅
Test exercises the previously-uncovered branch and passes (correct behaviour).

b) Root cause explained? ✅
src/Functions/randDistribution.cpp:243-244 — if (p < 0.0 || p > 1.0) throw Exception(...) for randBinomial has zero coverage across 0_stateless and integration.

c) Fix matches root cause? ✅
N/A for coverage gap — this PR adds a regression test, not a fix. Asserts current correct behaviour at the cited line.

d) Test intent preserved? / New tests added? ✅
New regression test added: 04629_rand_binomial_invalid_probability.sql.

e) Both directions demonstrated? ✅
Test passes (MATCH) on master proving current correctness; would fail if the cited branch regressed. Single-direction is the correct shape for a coverage gap test.

f) Fix is general, not a narrow patch? ✅
Test asserts the invariant at the cited line — covers the branch, not a specific input shape.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [68c7669]

Summary: ✅


AI Review

Summary

This PR adds a focused stateless test for randBinomial rejecting probabilities outside [0, 1]. I checked the current diff, the existing PR discussion, and the execution path in randDistribution.cpp; the new test does exercise the intended BAD_ARGUMENTS guard, and the final positive-path query still evaluates randBinomial rather than being optimized away. I did not find a material correctness, coverage, or PR-metadata issue that warrants an inline review comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 27, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Jul 29, 2026
Merged via the queue into ClickHouse:master with commit 908f62b Jul 29, 2026
178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants