Skip to content

Detect gtest suites registered with GTEST_TEST in bugfix validation - #113379

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-bugfix-validation-unit-tests-new-api
Aug 4, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-bugfix-validation-unit-tests-new-api

Conversation

@groeneai

@groeneai groeneai commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

_GTEST_MACROS in ci/jobs/unit_tests_bugfix_validation_job.py was missing GTEST_TEST.
gtest defines TEST as GTEST_TEST (gtest.h:2192, primary at :2185; same for
TEST_F/GTEST_TEST_F), and 48 registrations across 15 files under src/**/tests use the primary
spelling. derive_test_suites therefore returned [] for such a file, and the validator read that
as "this PR has no unit tests" rather than "the parser did not understand this file": it finalizes
OK with "No gtest test suites found ... nothing to validate". A green check that validated
nothing.

new_tests_check.has_new_unit_tests deliberately imports the same predicate, so the merge gate's
unit branch is not entered either. What that costs depends on the rest of the PR: one that also
adds functional or integration tests is decided by the stricter per-arch branch and is unaffected
(new_tests_check.py:213 tests those paths first), while a unit-only PR passes on the
CI-report-link fallback if its body carries such a link.

Not hypothetical: over 60 days the "No gtest test suites found" verdict fired 13 times across 5
PRs, and 3 of those 5 do contain gtest cases the regex could not see - including #111191, a merged
bugfix PR that shipped 5 GTEST_TEST cases across 3 new files with its unit validation skipped.

The fix adds GTEST_TEST and GTEST_TEST_F to the tuple; no verdict or policy changes and the
existing entries are not reordered. A 16-case probe matrix pins every registration form plus seven
negatives (substring, trailing underscore, instantiation, commented-out), each new assertion is
pinned by a mutation arm, and over origin/master 15 files go from 0 to >=1 derived suites with 0
regressions and 408/408 already-visible files unchanged.

A pr-bugfix PR whose GTEST_TEST test genuinely passes on the merge base will now be blocked
where it previously slipped through, and such PRs now run a before-build they previously skipped
(off the critical path).

The "No gtest test suites found" verdict, CIDB 60 d, classified per PR

Each class below is the verdict of the VALIDATOR, not the outcome of the merge gate: #111191,
#110997 and #106961 also add 0_stateless tests, so all three were gate-decided by the per-arch
branch either way.

PR rows state / author changed unit-test file(s) GTEST_TEST hook-visible class
#111191 3 merged, alexey-milovidov 3x gtest_block_*.cpp 2+2+1 0 false negative
#110997 4 open, mine gtest_aggregate_function_version_race.cpp 10 0 false negative
#106961 4 open, mine gtest_saturated_duration.cpp, gtest_settings.cpp 11+9 0 false negative
#109747 1 open, mine gtest_actions_dag_partial_result_type_drift.cpp 0 9 control (renamed, suite visible)
#113225 1 open, mine none match src/**/tests/ - - legitimate no-op

Exactly one file still derives 0 suites after the fix:
src/Coordination/tests/gtest_coordination_common.cpp carries only INSTANTIATE_TEST_SUITE_P,
whose first argument is a prefix and not a suite name; its two suites are declared in the four
sibling files that include its header, and build_gtest_filter already emits the */Suite.*
pattern that picks up instantiated cases. So "15 files" is not "the parser now sees everything".

Registration-macro census in src/**/tests at origin/master: TEST 2477, TEST_F 447,
TEST_P 212, GTEST_TEST 48, TYPED_TEST 22, GTEST_TEST_F 0, TYPED_TEST_P 0. So
GTEST_TEST was the only macro in use that the list missed; GTEST_TEST_F is listed for symmetry,
as TYPED_TEST_P already is at 0 users.

Version info

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

`_GTEST_MACROS` in the unit-test bugfix validator listed only `TEST`/`TEST_F`,
not the `GTEST_TEST`/`GTEST_TEST_F` spellings they are `#define`d to
(googletest `gtest.h:2192` -> `:2185`, `:2224` -> `:2220`). 48 registrations
across 15 in-tree files under src/**/tests use the primary spelling, so
`derive_test_suites` returned an empty list for those files.

The validator reads that empty list as "this PR has no unit tests" rather than
"the parser did not understand this file", and finalizes OK with "No gtest test
suites found ... nothing to validate": a green check that validated nothing.

`new_tests_check.has_new_unit_tests` imports the same predicate, so the merge
gate's `has_unit` branch is not entered either. What that costs depends on what
else the PR changes, and it is narrower than the validator half: `check` tests
`has_ft or has_it` first (`new_tests_check.py:213`), and that predicate is
decided by paths alone and never consults the gtest macros, so a PR that also
adds functional or integration tests is decided by the stricter per-arch branch
and is unaffected. A unit-only PR is affected: with a CI-report link in its body
it passes on that fallback instead of on validation, and without one it is
blocked outright. Both arms were executed against the real `check` to establish
this rather than reasoned about.

Over 60 days the "No gtest test suites found" verdict fired 13 times across 5
PRs, and 3 of those 5 do contain gtest cases the regex could not see, including
a merged bugfix PR that shipped with 5 GTEST_TEST cases across 3 new files and
its unit validation skipped. All three of those also add functional tests, so
the harm there is the validator's false negative, not a gate bypass. A PR that
renamed its own GTEST_TEST( to TEST( is the control: the suite became visible.

Adding the two names is enough because both consumers funnel through this one
tuple. No verdict, status or policy is changed and the existing entries are not
reordered: alternation is first-match-wins, and the `^\s*` anchor together with
the `\s*\(` suffix is what keeps the current order safe. `GTEST_TEST_F` has no
in-tree users today and is listed for symmetry, as `TYPED_TEST_P` already is.

Validated with a 16-case probe matrix covering every registration form, leading
and odd internal whitespace, and seven negatives (macro as a substring, trailing
underscore, INSTANTIATE_TEST_SUITE_P, two commented-out forms, EXPECT_TEST).
Over `origin/master`, 15 files go from 0 to at least 1 derived suite with no
regressions and 408 of 408 already-visible files unchanged. Exactly one file
still derives 0 suites: `src/Coordination/tests/gtest_coordination_common.cpp`
carries only INSTANTIATE_TEST_SUITE_P, whose first argument is a prefix and not
a suite name, and its two suites are declared in the four sibling files that
include its header, so `build_gtest_filter` already covers its cases. Each new
assertion is pinned by a mutation arm; the gate test is deliberately not
monkeypatched, since the existing unit-only test stubs the predicate and so
could not catch this.

Note this does not address the separate "before-binary failed to COMPILE the
overlaid test" verdict of the same job, which turns on a policy question.
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review - 2 review rounds, 2 independent gate passes, 0 open findings

Before publishing I reviewed this change cold (without reading the implementation notes),
then a second model reviewed it independently. Every finding below is recorded with its
verdict and the evidence that settled it.

❌ Blockers

None.

⚠️ Major

The merge-gate claim in my first draft was wrong, and the description said so.
The draft asserted that the missing GTEST_TEST made the merge gate fail open, citing
#111191. I executed the real check() in both arms rather than reasoning about it:

PR shape without the fix with the fix
unit-only, no CI-report link False - blocked True
unit-only, with a CI-report link True - the actual bypass True
unit test + a 0_stateless test False False - identical

check evaluates has_ft or has_it first (new_tests_check.py:213), and that predicate is
decided by paths alone - it never consults the gtest macros. So a PR that also adds functional
or integration tests is decided by the stricter per-arch branch and is unaffected, and the one
unit-only PR among the cited five was blocked outright rather than let through. The description
and the commit message were rewritten to state this accurately: the harm is the validator's
false negative (a green OK reading "No gtest test suites found ... nothing to validate" on a
merged bugfix PR that shipped 5 GTEST_TEST cases), and the gate consequence is narrower and
conditional. Both arms are recorded so a reader does not have to re-litigate it.

Dropped on re-derivation (mine, not the second model's): I first read the probe matrix as
missing an INSTANTIATE_TEST_SUITE_P negative. It is not missing - I had checked the
checked-in fixture rather than the runtime matrix. The finding does not survive, so no
INSTANTIATE arm was added.

💡 Noted, not blocking

  • Figures were originally measured on the PR base, which is 4642 commits behind master. They
    are now quoted against origin/master and re-derived independently over all 437 files under
    src/**/tests: 48 registrations in 15 files, 15 files go from 0 to at least 1 derived suite,
    408 of 408 already-visible files unchanged, 0 regressions. The partition 408 + 15 + 14 = 437
    is exhaustive, and none of the 48 occurrences sit in an already-visible file, so "15 files"
    is exact. The four consumed ci/ files are md5-identical between that base and master, so
    only the reproducibility of the numbers was ever affected, not the change.
  • One file legitimately still derives 0 suites and is now disclosed:
    src/Coordination/tests/gtest_coordination_common.cpp carries only INSTANTIATE_TEST_SUITE_P,
    whose first argument is a prefix and not a suite name; its two suites are declared in the four
    sibling files that include its header, and build_gtest_filter already emits */Suite.*.
  • "seven negatives" counts the runtime probe matrix; the checked-in fixture carries six of them
    (TEST_F_EX exists only in the matrix). Both counts are true of what they refer to.

Verification

  • Both new tests are live: they pass as committed and both fail when _GTEST_MACROS is
    reverted to the upstream five names. The gate test deliberately does not stub the predicate -
    it writes a real GTEST_TEST file and supplies a body with no CI-report link, so check()
    can only return True through the unit branch. That is the one case the pre-existing
    unit-only test could not catch, because it stubs the predicate.
  • pytest ci/tests/: 438 passed, 4 failed - all four pre-existing and unrelated (they need a
    live server), none in the two touched files.
  • The tuple has exactly two consumers and both funnel through the same regex, so there is no
    symmetric code path left unfixed; there is no other list of gtest registration macros in ci/.
  • Second-model review ran twice on this exact tree, once with no prior context (0 findings) and
    once against the corrected description (0 findings).

Session id: cron:clickhouse-review-slot-11:20260804-185100

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100% (a parse result, not a rate). derive_test_suites on a file registering with GTEST_TEST returns [], while a control file using TEST( returns ['CtlSuite'] in the same run. The control is what shows the empty list is the macro gap and not a broken fixture.
b Root cause explained? Yes. gtest defines TEST as GTEST_TEST (gtest.h:2192, primary at :2185) and TEST_F as GTEST_TEST_F (:2224/:2220), but _GTEST_MACROS listed only the aliases. _SUITE_RE is the sole mechanism answering "does this changed file register a suite?", so a GTEST_TEST file parses to zero suites, and zero is read by two consumers as "this PR has no unit tests". The validator half is the harm: it finalizes OK "nothing to validate", a green check that validated nothing. new_tests_check.has_new_unit_tests imports that same predicate, so the gate's has_unit branch is not entered either, but that is narrower and I measured it in both arms rather than assuming it: check tests has_ft or has_it first (new_tests_check.py:213) and that predicate is decided by paths alone, so a PR that also adds functional or integration tests is decided by the stricter per-arch branch and is unaffected, while a unit-only PR passes on the CI-report-link fallback if its body has such a link and is blocked outright if it does not.
c Fix matches root cause? Yes. It completes the declared macro list at the single point both consumers funnel through. No verdict, status, threshold or policy is touched, and the existing five entries are not reordered. The rejected alternative was renaming GTEST_TEST( to TEST( in the 15 affected in-tree files, which leaves the harness broken for file 16.
d Test intent preserved / new tests added? Yes, two assertions and nothing weakened. The existing exact-6-suite assertion (which passed while the bug existed) becomes exact-8, and I added in-tree negatives for GTEST_TEST_, MY_GTEST_TEST and a commented-out GTEST_TEST so the new names cannot smuggle in a false positive. The second test is a non-monkeypatched gate test: the existing unit-only test stubs has_new_unit_tests, so it structurally could not catch this half.
e Both directions demonstrated? Yes. Without the fix [], with the fix ['DemoSuite'], control unchanged in both arms. Mutation M1 (revert the tuple to 5 entries) reddens both new tests.
f Fix is general across code paths? Yes. Carriers re-verified by grep: the validator (:535), build_gtest_filter (:548), new_tests_check:55-66 (shared import, which is why a one-place fix is correct), job_configs.py:914 (digest input only), filter_job.py:374-398 (gates only the FT/IT validators, no unit branch), and the three test files. Fixed at the source rather than guarded at a call site.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. A 16-case probe matrix was executed, not reasoned about: nine positives (all five previously-listed macros, both new ones, leading and odd internal whitespace) plus seven negatives (MY_GTEST_TEST as a substring, trailing underscore GTEST_TEST_, TEST_F_EX, INSTANTIATE_TEST_SUITE_P, two commented-out forms, EXPECT_TEST). 16/16 as specified, so the added names do not turn a substring or a comment into a false suite.
h Backward compatible? (maintainer-approved exception only) Yes. CI-only Python; no setting, no SettingsChangesHistory.cpp, no serialization format, no user-visible surface. Strictly additive: over origin/master 408 of 408 already-visible files parse identically, so the only classification changes are the 15 previously-invisible files, which is the intended effect. One file stays at zero suites and correctly so: src/Coordination/tests/gtest_coordination_common.cpp has only INSTANTIATE_TEST_SUITE_P, whose first argument is a prefix rather than a suite name, and its suites are declared in the sibling files that include its header.
i Invariants and contracts preserved? Yes. derive_test_suites still returns a sorted deduplicated list; build_gtest_filter still emits its four patterns per suite and is untouched; has_new_unit_tests keeps its deliberate coupling to the validator's predicate (documented at new_tests_check.py:48-54) rather than being loosened to "any file under src/**/tests/", which would trade one fail-open for another. Alternation is first-match-wins, and mutations M3 and M4 pin the ^\s* anchor and the \s*\( suffix that make the ordering safe.

Validation beyond the table: the whole ci/tests/ suite as CI runs it, with a failure set drawn only from three pre-existing flaky live-server probe files this diff never touches, and the passed count rising by exactly the added tests; six mutation arms, where M1 to M4 each redden a named test and M5 reddens nothing as designed, with a composite M5+M1 positive control proving M5 measures rather than being vacuous; and a census over all 437 unit-test files at origin/master showing 15 files going from 0 to at least 1 derived suite with 0 regressions.

Not covered here, deliberately: the separate "before-binary failed to COMPILE the overlaid test" class of this job. That one turns on a policy question and is not addressed by this PR.

Session id: cron:clickhouse-impl-slot-6:20260804-182600

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @nickitat, could you review this? _GTEST_MACROS in the unit-test bugfix validator listed only TEST/TEST_F, not the GTEST_TEST/GTEST_TEST_F spellings they are #defined to, so derive_test_suites returned an empty list for the 48 registrations across 15 in-tree files that use the primary spelling, and the validator read that as "no unit tests" and finalized OK without validating anything.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [edcc97e]

Summary: ✅


AI Review

Summary

This PR fixes the unit-test bugfix validator's gtest-suite parser so direct GTEST_TEST and GTEST_TEST_F registrations are treated the same way as their TEST and TEST_F aliases, and it adds focused coverage in both derive_test_suites and the new_tests_check unit-only gate path. I did not find any remaining correctness or contract issues in the current diff. Local pytest execution was not available in this sandbox because python3 -m pytest fails with No module named pytest, so verification here relied on static review, direct helper-function probes against real src/**/tests files, and the current all-green PR CI report.

Missing context / blind spots
  • ⚠️ Full local test execution of the touched ci/tests modules was not possible in this environment because pytest is not installed.
Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 4, 2026
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - edcc97e

CI fully finished on this head with zero failures: 174 check-runs, all completed, 6 executed
(Config Workflow, Style check, Code Review, CI Tests, Build profile diff, Finish Workflow)
and 168 skipped as not affected by the changed files. Style check 0/13 failures, CI Tests 0/654,
Code Review 0/0. A recursive walk of every leaf in the S3 report returns 0 non-OK nodes.
No failures to own.

Session id: cron:our-pr-ci-monitor:20260804-220000

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ClickHouse:master with commit c7f88b2 Aug 4, 2026
179 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 5, 2026
@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 19, 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 groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-ci 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