Skip to content

Add bugfix check for unit tests - #108827

Merged
alexey-milovidov merged 20 commits into
masterfrom
gtest-bugfix-check
Jul 20, 2026
Merged

alexey-milovidov merged 20 commits into
masterfrom
gtest-bugfix-check

Conversation

@nickitat

@nickitat nickitat commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

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

Testing:

┌──────────────────────┬──────────────────┬──────────────┬────────────────────────────────────────────────────────────────────────────────┬───────────┐
│       Scenario       │        PR        │  Job status  │                                Verdict message                                 │ Expected? │
├──────────────────────┼──────────────────┼──────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ Skip (non-bugfix)    │ #108827 self-run │ OK / skipped │ "not a bugfix PR"                                                              │ ✅        │
├──────────────────────┼──────────────────┼──────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ Reproduce            │ #108833          │ OK (XFAIL)   │ touched test fails on before / passes on PR → "bug reproduced"                 │ ✅        │
├──────────────────────┼──────────────────┼──────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ Fail-to-reproduce    │ #108946          │ FAIL         │ "all touched tests PASS on the before-binary → failed to reproduce"            │ ✅        │
├──────────────────────┼──────────────────┼──────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ Compile-inconclusive │ #108947          │ ERROR        │ "before-binary FAILED TO COMPILE … does not prove the test reproduces the bug" │ ✅        │
└──────────────────────┴──────────────────┴──────────────┴────────────────────────────────────────────────────────────────────────────────┴───────────┘

Version info

  • Merged into: 26.7.1.1243 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [270973d]

Summary: ✅


AI Review

Summary

This PR adds a unit-test bugfix validator and wires new_tests_check.py to use it as the unit-only evidence path. The hardening around merge-ref anchoring, shell quoting, typed-suite filters, unsafe .gitmodules, and zero-[ RUN ] clean exits looks correct, but three contract holes still remain: suite-level attribution can accept unrelated failures as reproduction, contrib changes can leak PR-head submodules into the "before" build, and the unit-only gate still passes inconclusive or missing validation. Because those gaps let a pr-bugfix PR pass without proof that the new regression test actually fails without the fix, I would not approve this yet.

Findings

❌ Blockers

  • [ci/jobs/unit_tests_bugfix_validation_job.py:102-120, 576-603] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/108827#discussion_r3495004216] The reproduction decision is still suite-scoped rather than case-scoped. build_gtest_filter expands every touched suite to Suite.*, and the mark_reproduced path flips the whole run to XFAIL as soon as any case in that suite fails after one [ RUN ] marker. A PR can therefore add a no-op case to an already-failing suite and satisfy the gate without evidence from the new regression case. Suggested fix: derive exact Suite.Case names from the changed hunks, or at minimum compare failed sub-results against the PR-touched cases and treat unattributable suite failures as inconclusive.
  • [ci/jobs/unit_tests_bugfix_validation_job.py:236-304] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/108827#discussion_r3509784774] The "before" worktree still hardlinks submodule working trees from the primary checkout at PR HEAD. If the PR changes a submodule gitlink or .gitmodules, the supposed merge-base build is no longer merge-base + touched tests only — it is compiled against the PR's vendored contrib tree. That can hide a real unfixed dependency bug or manufacture a false reproduction. Suggested fix: initialize submodules inside BEFORE_SRC itself, or bail out as inconclusive whenever any submodule gitlink or .gitmodules entry differs from the merge-base.
  • [ci/jobs/scripts/workflow_hooks/new_tests_check.py:148-170, 227-245] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/108827#discussion_r3501681773] The unit-only bugfix gate still treats ERROR, missing results, and skipped validation as success. Since the validator job is allow_failure, a test that does not compile on the merge-base, aborts before any touched test starts, or is skipped for any other reason still satisfies the gate with no affirmative reproduction. Suggested fix: require an affirmative OK/XFAIL result from Bugfix validation (unit tests) for has_unit, and treat ERROR/missing/skipped as non-passing unless there is some separate explicit evidence path.
Final Verdict

Status: ❌ Block

Minimum required actions: tie reproduction to the PR-touched test case rather than the whole suite, stop populating the "before" build from PR-head submodules, and make the unit-only gate require affirmative validation instead of passing on inconclusive or missing results.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 29, 2026
Remove an extraneous `f` prefix from a `print` with no placeholders, flagged
by the diff-scoped `Style check/ruff` on PR #108827.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The job required the PR's `UNITTEST_AMD_ASAN_UBSAN` artifact only to run the
touched suites on the PR binary ("must pass"). Requiring it gated the job behind
`build_amd_asan_ubsan` and its whole pre-build chain (`fast_test`, `style_check`,
`build_arm_tidy`, `ci_tests`), and forced the in-job "before" build to run only
after the artifact arrived (serial `build + build`).

Drop the requirement and delegate the "touched tests pass on the PR binary" side
to the regular `Unit tests (asan_ubsan)` job, which already compiles and runs the
full suite — including the new test — on the PR binary (a broken regression test
makes that job red and blocks the PR). This mirrors how the functional/integration
bugfix validators only check the "before" side and rely on the normal test jobs
for the "after" side.

The job's `needs` is now `[config_workflow, dockers_*]`, identical to the FT/IT
validators, so it starts as early and builds the "before" binary in parallel with
the build matrix.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 29, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A run of the synthetic reproduce test (PR #108833) "passed" for the wrong reason,
which surfaced two bugs:

1. False positive (fail-close violation). The job treated ANY before-binary build
   failure as proof the test depends on the fix. The actual failure was a `cmake`
   configure abort ("Submodules are not initialized", CMakeLists.txt) — an
   infrastructure problem — yet the job reported success. Split the build into a
   `configure` step and a `compile` step: a configure failure is now reported as an
   `ERROR` (inconclusive), and only a genuine `ninja` compile failure of the overlaid
   test counts as the "test depends on the fix" XFAIL proof. Also assert the submodule
   marker is present in the before-worktree before building and fail close if not.

2. Submodules never populated. `needs_submodules=True` only restores the submodule
   git data (`.git/modules`) from the S3 cache; the working-tree files must still be
   checked out. The job relied on hardlinking `contrib/*` from the primary checkout,
   but those working trees were empty, so nothing was copied. Add
   `ensure_primary_submodules` (mirroring the CHECKOUT_SUBMODULES stage of
   `build_clickhouse.py`: cache fast-path + full-fetch fallback) before the hardlink.

CI report (false positive): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108833&sha=d5ede1be358c25a9ce56dcedc147b3ec8efcf9ca&name_0=PR
PR: #108833

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 29, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…tions

Run of PR #108833 "reproduced" via an unrelated abort, exposing two issues:

1. Wrong run environment. The before-binary runs in the binary-builder container,
   whose default seccomp profile blocks `io_uring`. `unit_tests_dbms` links the `silk`
   fiber runtime, which calls `io_uring_queue_init_params` at startup and aborts
   (`SILK_ASSERT(!r)`) when it is denied — before any test runs. Add `--privileged` to
   this job's docker (matching how the regular `Unit tests` job runs the same binary
   in `clickhouse/test-base+--privileged`) so the before-binary can initialize.

2. Unattributable crash counted as reproduction. A before-binary failure was treated
   as "bug reproduced" even when the binary died before any touched test ran. Require a
   gtest `[ RUN ]` marker (`before_run_started_a_test`): a failure/crash counts as a
   reproduction only if the touched suite actually started (this still covers legitimate
   crash-bugs that die mid-test); otherwise report `ERROR`/inconclusive. Fail close.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108833&sha=905cf4af0fc7af775eaff662fd500554efb96e2b&name_0=PR
PR: #108833

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 29, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# At least one touched test failed or crashed on the before-binary — the bug is
# reproduced. Flip the expected failure to a success for the report.
mark_reproduced(before_result)
results.append(before_result)

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.

The reproduction decision is not tied to the test case that the PR added or modified. build_gtest_filter expands each parsed suite to Suite.*, and this block flips any non-OK result from that whole suite to XFAIL as soon as one [ RUN ] marker exists. A PR can add a passing/no-op case to an existing suite while an unrelated existing case in the same suite fails on the merge-base; this job will still mark the bug as reproduced and let the bugfix gate pass without evidence from the new regression test.

Please derive the runnable cases from the changed hunks, or otherwise compare the failed sub-results against the PR-touched cases, and only call mark_reproduced when at least one touched case failed or failed to compile on the before tree. Unattributable suite failures should be inconclusive or fail the validation.

… sccache hits

The before-build compiled the worktree at its real path
`/ClickHouse/ci/tmp/before_src`, but sccache keys bake in the absolute build path (via
`-ffile-prefix-map=<root>/=` and preprocessed `# line` markers). Master's cache was
populated by builds at `/ClickHouse`, so every key missed: 0% hits, a full cold compile
(16201 TUs, ~57 min) vs ~11 min for the regular cached build.

Run cmake+ninja inside `unshare -m` with `mount --bind <before_src> /ClickHouse`, using
the UNMODIFIED canonical cmake flags. The compile commands and preprocessed output are
then byte-identical to the regular build at `/ClickHouse`, so they reuse master's
sccache entries. The bind is private to the build subprocess, so the real checkout and
this running script are untouched, and `/ClickHouse/build` in the namespace IS
`before_src/build` on disk, so BEFORE_BINARY is unchanged. Needs CAP_SYS_ADMIN, provided
by the `--privileged` already added for io_uring.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…orks

The before-build's sccache fix uses `unshare -m` + `mount --bind`, which need
CAP_SYS_ADMIN. Jobs run as `--user $(id -u)` (non-root) by default, so `unshare`
failed with "Operation not permitted" (configure step failed in 4 ms; correctly
reported as ERROR/inconclusive by the fail-close path, not a false pass). Add the
`+root` token so the job drops `--user` and runs as root — combined with the existing
`--privileged`, that grants CAP_SYS_ADMIN. Mirrors other privileged jobs
(stateless-test, integration) which also use `+root`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108833&sha=09963e897dc78a56052a37647d305e59111dcd4a&name_0=PR
PR: #108833

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After adding `+root`, git refused the checkout with "detected dubious ownership"
(repo owned by uid 1000, process is root), so `git merge-base` returned empty and the
job errored before building. Run `git config --global --add safe.directory '*'` at the
start so merge-base, worktree, and submodule operations work as root.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108833&sha=f758451c29a819b0122eeefad59ab3f0774e6e38&name_0=PR
PR: #108833

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread ci/defs/job_configs.py Resolved
Reverts the bind-mount namespace (eb794ef), `+root` (ed56e51), and git
`safe.directory` (3c7d300) commits. The bind-mount-onto-/ClickHouse approach for
sccache reuse is a dead end: sccache is client-server and the server compiles in its
own mount namespace, not the client's, so it can't see the bind-mounted build dir
(`cd /ClickHouse/build: No such file or directory`). CCACHE_BASEDIR doesn't help
either — that's a ccache feature, the build uses sccache, and the master cache is
sccache-keyed.

The before-build is now a plain cold build of the worktree (~1h, ~0% sccache hits).
This is accepted: the job has no artifact dependency and runs in parallel with the
build matrix, so it is off the critical path. Documented inline so it is not
re-attempted naively. `--privileged` is kept (io_uring for the silk fiber runtime);
`+root` is dropped (only the namespace needed it), so git no longer hits the
dubious-ownership error.

Everything validated stays: lean scheduling, configure/compile split (no false
build-fail), submodule population, and the attributable-reproduction check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…dation

`prepare_before_worktree` built shell commands by wrapping PR-controlled paths in
single quotes (`f"'{f}'"`) and passing them to `Shell.check` (shell=True). Because
`_UNIT_TEST_FILE_RE` permits single quotes, spaces, `&`, `#`, etc. in a filename, a PR
that adds e.g. `src/Foo/tests/a' && <command> #.cpp` would break out of the quoting and
run `<command>` on the CI runner before validation. The submodule paths read from the
PR's `.gitmodules` had the same flaw.

Shell-quote every PR-controlled path with `shlex.quote` (test files, submodule src/dst),
and add `--` so a leading-dash path can't be parsed as an option. The regex is not a
sanitizer; a regression test documents that contract.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e, shared gate predicate

Addresses three review findings:

- build_gtest_filter missed typed gtest names. Typed tests are `Suite/0.Case` and
  `Prefix/Suite/0.Case`, which neither `Suite.*` nor `*/Suite.*` matches, so a PR adding
  only a typed regression test would run zero before-side cases and be misreported as
  "failed to reproduce". Add `Suite/*` and `*/Suite/*` patterns (+ tests covering all
  four gtest naming forms).

- A before-binary COMPILE failure was treated as a passing XFAIL. That only proves the
  overlaid test references some PR code (a new header/helper/symbol fails to compile on
  the merge-base too), not that it reproduces the bug. Report it as ERROR/inconclusive
  (fail close) instead of a pass.

- new_tests_check.has_new_unit_tests used a broader predicate (any path under
  src/**/tests/**) than the validator (a src source file with a runnable gtest suite),
  so a non-runnable file could satisfy the bugfix gate's unit shortcut while the
  validator skipped — passing the gate with no reproduction. Share the validator's exact
  predicate (regex + runnable-suite check).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nickitat added a commit that referenced this pull request Jun 30, 2026
…bugfix validation

Stacked on the new "Bugfix validation (unit tests)" job (PR #108827) to exercise
its reproduce path on real CI. `escapeForFileName` is changed to keep `.` verbatim
(the synthetic "fix"), and `gtest_bugfix_probe.cpp` asserts the new output. The
merge-base binary (without the fix) produces `a%2Eb` and fails the test; the PR
binary passes — so the job must report the bug as reproduced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR is purely CI infrastructure: it adds a "Bugfix validation (unit tests)" job and refactors build/CI Python and workflow YAML, with no changes to server query-execution code. The deterministic gates flagged Q4 (-11.1%) and Q15 (-21.2%) on clickbench but correctly kept both as no_change within master's current variance band; since nothing this PR changes runs during those queries, both deltas are run-to-run variance, not real improvements. The envelope suppressions are consistent with the diff and require no correction.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 0e7c3e33-9ce6-4015-9c14-295011e2b891
  • MIRAI run: 23d39fd0-7ee8-4047-9e92-df816e5265fe
  • PR check IDs:
    • clickbench_419724_1784543093
    • clickbench_419736_1784543093
    • clickbench_419742_1784543093
    • tpch_adapted_1_official_419750_1784543093
    • tpch_adapted_1_official_419765_1784543093
    • tpch_adapted_1_official_419772_1784543093

Resolves the merge conflict in the generated `.github/workflows/pull_request.yml`.
Master split `Stateless tests (amd_llvm_coverage, old analyzer, s3 storage,
DatabaseReplicated, WasmEdge, parallel)` into three batches (`_1_3`/`_2_3`/`_3_3`)
while this branch added the `Bugfix validation (unit tests)` job, so both edited
the same generated `needs` lists. The Python sources under `ci/` merged cleanly;
the YAML was regenerated with `praktika yaml` so it carries both changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

# The primary checkout must have populated submodule working trees before we can
# hardlink them across (see ensure_primary_submodules).
ensure_primary_submodules()

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.

This helper always populates submodules from the primary checkout at PR HEAD and then hardlinks those working trees into the merge-base worktree. If the PR bumps a submodule gitlink or edits .gitmodules, the "before" build is no longer merge-base + touched tests only — it is compiled against the PR's vendored code for that submodule.

That breaks the validator's core contract for any bugfix that touches a contrib dependency: the old behavior may already be gone on the "before" side, so the job can report a false FAIL/XFAIL without ever testing the unfixed dependency. Please either initialize submodules from BEFORE_SRC itself or bail out as inconclusive whenever any submodule gitlink / .gitmodules entry changed.

@alexey-milovidov

Copy link
Copy Markdown
Member

Reviewed — the approach is good. Building the merge-base "before" binary with only the test overlaid, and treating configure/compile/no-[ RUN ] outcomes as inconclusive rather than reproductions, is the right shape for a unit-test bugfix gate.

One thing must be fixed before merge; the rest are notes.

Blocker — path traversal in the submodule copy loop (ci/jobs/unit_tests_bugfix_validation_job.py). gitmodules_shape_violation is the pre-fetch safety guard, but it only rejects non-https://github.com/ URLs and name != path. It does not reject .. or absolute paths, so a PR-controlled .gitmodules with

[submodule "../../../../ClickHouse"]
	path = ../../../../ClickHouse
	url = https://github.com/x/y.git

passes the guard (I checked: name == path, github URL ⇒ it returns None). The copy loop then runs rm -rf -- {dst} / cp -al -- {path} {dst} with dst = os.path.join("ci/tmp/before_src", path), which from the container cwd /ClickHouse normalizes to /ClickHouse — i.e. it operates on the mounted checkout itself, outside before_src. Whether git submodule init happens to reject the entry first is git-version-dependent and not something to rely on. Please reject any absolute path and any .. component in gitmodules_shape_violation (requiring a contrib/ prefix would be tighter), and add a defensive check that realpath(dst) stays under realpath(BEFORE_SRC) before the rm -rf. A test_gitmodules_shape_rejects_traversal_path next to the existing shape tests would lock it in. (This is the bot's line-177 blocker — it's real.)

The red CI is unrelated. The only hard-red job (Stress test (arm_asan_ubsan)) is a clickhouse-test harness race, not this PR: load_tags_and_random_settings_limits_from_file did an unguarded open() on a sibling worker's per-PID temp copy (03745_..._roundtrip.4491.sh) that had already been deleted, so the suite scan raised FileNotFoundError before any test ran. No crash / sanitizer / logical error, and a CI-only PR cannot cause it. Separate harness bug — I'll handle it apart from this PR.

The other three bot findings are fair — touched-case (not suite-scoped) attribution of the reproduction, bailing out inconclusive when the PR changes a submodule gitlink / .gitmodules (otherwise the "before" build hardlinks PR-HEAD contrib), and the unit-only gate on inconclusive results. On the last one, blocking only on FAIL is a defensible choice for an advisory gate; the part worth a second look is that a no-op test which only compiles with the PR ⇒ compile-fail ⇒ inconclusive ⇒ pass, so the gate never actually observes a reproduction.

@alexey-milovidov

Copy link
Copy Markdown
Member

The unrelated Stress test (arm_asan_ubsan) harness flake (the FileNotFoundError in clickhouse-test's suite tag scan) — fix is up in #109120.

alexey-milovidov added a commit that referenced this pull request Jul 2, 2026
The earlier `FileNotFoundError` guard in
`load_tags_and_random_settings_limits_from_file` only masked one symptom
of the race. `SharedEngineReplacer` writes a transient per-PID copy of a
test (`<name>.<pid><ext>`, see `SharedEngineReplacer.temp_file_path`) next
to the original while the test runs. A concurrent `clickhouse-test`
invocation's suite scan (`os.listdir` in `get_selected_tests`) can list
that copy and schedule it as a real test: it then either fails as
`FileNotFoundError` in `is_valid_utf_8` once the copy is deleted, or runs
as a bogus PID-suffixed test reported `NO_REFERENCE`.

Recognize and exclude these copies in `is_test_from_dir` (the single
discovery choke point used by both `get_selected_tests` and the stress
diagnosis scan) so they never enter the test list. The copy is only
skipped when the original it was made from is present, which makes a
false positive on a genuine test impossible: no test in the tree has a
`<name>.<digits><ext>` shape. This makes the earlier `open` guard
unnecessary, so it is reverted.

Related: #108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits July 2, 2026 11:02
# Conflicts:
#	.github/workflows/pull_request.yml
`gitmodules_shape_violation` only rejected non-`https://github.com/` URLs
and `name != path`, so a PR-controlled `.gitmodules` with
`path = ../../../../ClickHouse` (name == path, github URL) passed the guard.
`prepare_before_worktree` then joined that path onto `BEFORE_SRC` and ran
`rm -rf -- {dst}` / `cp -al -- {path} {dst}`, which from the container cwd
`/ClickHouse` resolves to the mounted checkout itself — outside `before_src`.

Harden the pre-fetch guard to also reject absolute paths, any `..` component,
and any path outside `contrib/`, and add a defensive `realpath(dst)`
containment check in `prepare_before_worktree` before the destructive
`rm -rf` (defense in depth). Add `test_gitmodules_shape_rejects_traversal_path`
covering the traversal, `..`, absolute-path, and non-`contrib/` cases.

Addresses the review blocker on
#108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed two commits (cd6015db02f):

  1. Merged master (183 commits behind → the PR was CONFLICTING). The only conflict was the generated .github/workflows/pull_request.yml — the finish_workflow needs: list, where master dropped the standalone build_arm_ubsan / stress_test_arm_ubsan jobs (CI: remove leftover standalone arm_ubsan build #109048) while this PR adds bugfix_validation_unit_tests. Resolved by regenerating with python3 -m praktika yaml rather than hand-merging; the net workflow diff vs master is now exactly the one added bugfix_validation_unit_tests job (verified master.yml / release_branches.yml are byte-identical to master, and a fresh re-generation leaves the tree clean so the "workflows are outdated" check passes).

  2. Fixed the path-traversal blocker (bot line-177 / @alexey-milovidov's blocker). gitmodules_shape_violation now also rejects absolute paths, any .. component, and any path outside contrib/, and prepare_before_worktree gains a defensive realpath(dst)-under-realpath(BEFORE_SRC) containment check that hard-stops before the destructive rm -rf. Added test_gitmodules_shape_rejects_traversal_path covering the ../../../../ClickHouse, .., absolute-path, and non-contrib/ cases. Full test file green (42 tests), ruff check clean.

The other three findings (suite-scoped attribution, submodule-gitlink/ .gitmodules change, inconclusive-as-pass gate) are left as-is per your triage that only the traversal fix must land before merge. The sole red CI job (Stress test (arm_asan_ubsan)) is the unrelated clickhouse-test harness FileNotFoundError race you diagnosed, fix up in #109120.

The PR workflow checks out GitHub's synthetic merge ref by default (CHECKOUT_REF is
empty unless DISABLE_CI_MERGE_COMMIT=1), so `git rev-parse HEAD` is the base+PR merge
commit, not the PR head. As a result:
  * `git merge-base HEAD origin/master` resolved to the current base tip, and
  * the test-file overlay picked up the merged test file,
so the "before" tree was master-tip + merged test instead of the true merge-base +
PR-head test. That produces false reproductions and false refutations whenever master
changed the touched buggy code or the test after the branch split.

Compute the merge-base from and overlay the test files at the PR head commit
(`info.sha`, = github.event.pull_request.head.sha), fetching it explicitly since under
the merge-ref checkout it is only reachable as the merge commit's second parent.
Regression test locks in that merge-base uses the PR head, not HEAD.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 2, 2026
The AI review requested automated coverage for the producer/filter contract
this PR introduces. `ci/tests/test_shared_engine_replacer_discovery.py` loads
`tests/clickhouse-test` via `runpy.run_path`, has `SharedEngineReplacer`
materialize a transient per-PID copy next to `foo.sql`, and asserts that
`is_test_from_dir` skips only the marked `foo.shared_engine_replacer_tmp.<pid>.sql`
while still discovering both `foo.sql` and the `foo.1.sql` look-alike that the
earlier basename-shape heuristic silently dropped.

Related: #108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits July 9, 2026 17:22
Resolve conflicts in ci/workflows/pull_request.py and the generated
.github/workflows/pull_request.yml.

master applied `.set_run_after(CORE_BLOCKING_JOB_NAMES)` to the sibling
`bugfix_validation_ft_pr_jobs` and `bugfix_validation_it_jobs` so those
secondary validation jobs are deferred behind the core blocking jobs.
This branch adds the new `bugfix_validation_ut_job`. Combined both: kept
master's `set_run_after` wrapping for the FT/IT jobs, kept the new unit-test
bugfix job, and extended the same `set_run_after(CORE_BLOCKING_JOB_NAMES)`
to it for consistency (its `needs:` list now matches the FT/IT jobs exactly).

Regenerated .github/workflows/pull_request.yml with `praktika yaml` rather
than hand-merging the generated file.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts:
#	.github/workflows/pull_request.yml
…ve, not a refutation

`unit_tests_dbms` is built from `gtest*.cpp` sources only (`grep_gtest_sources`
in `src/CMakeLists.txt`), but `_UNIT_TEST_FILE_RE` also matches standalone
`*.cpp`/`*.cc`/`*.cxx` test files under `tests/` (e.g.
`test_hive_catalog_url_parsing.cpp`). When a bugfix touches such a file, its
suite is derived from the source but is never compiled into the binary, so the
gtest filter matches zero cases: the before-binary exits cleanly without ever
printing a `[ RUN ]` marker, and the flow previously fell through to a `FAIL`
("Failed to reproduce the bug") — a false refutation of a legitimate
regression test.

Extend the existing `[ RUN ]`-marker guard (already applied on the failure
path) to the ok path: if the before-binary ran no touched test, report the run
as inconclusive instead of a refutation. Add a regression test for
`before_run_started_a_test`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 20, 2026
Merged via the queue into master with commit d7ba33f Jul 20, 2026
353 of 354 checks passed
@alexey-milovidov
alexey-milovidov deleted the gtest-bugfix-check branch July 20, 2026 20:49
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 20, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The earlier `FileNotFoundError` guard in
`load_tags_and_random_settings_limits_from_file` only masked one symptom
of the race. `SharedEngineReplacer` writes a transient per-PID copy of a
test (`<name>.<pid><ext>`, see `SharedEngineReplacer.temp_file_path`) next
to the original while the test runs. A concurrent `clickhouse-test`
invocation's suite scan (`os.listdir` in `get_selected_tests`) can list
that copy and schedule it as a real test: it then either fails as
`FileNotFoundError` in `is_valid_utf_8` once the copy is deleted, or runs
as a bogus PID-suffixed test reported `NO_REFERENCE`.

Recognize and exclude these copies in `is_test_from_dir` (the single
discovery choke point used by both `get_selected_tests` and the stress
diagnosis scan) so they never enter the test list. The copy is only
skipped when the original it was made from is present, which makes a
false positive on a genuine test impossible: no test in the tree has a
`<name>.<digits><ext>` shape. This makes the earlier `open` guard
unnecessary, so it is reverted.

Related: ClickHouse#108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The AI review requested automated coverage for the producer/filter contract
this PR introduces. `ci/tests/test_shared_engine_replacer_discovery.py` loads
`tests/clickhouse-test` via `runpy.run_path`, has `SharedEngineReplacer`
materialize a transient per-PID copy next to `foo.sql`, and asserts that
`is_test_from_dir` skips only the marked `foo.shared_engine_replacer_tmp.<pid>.sql`
while still discovering both `foo.sql` and the `foo.1.sql` look-alike that the
earlier basename-shape heuristic silently dropped.

Related: ClickHouse#108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Remove an extraneous `f` prefix from a `print` with no placeholders, flagged
by the diff-scoped `Style check/ruff` on PR ClickHouse#108827.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`gitmodules_shape_violation` only rejected non-`https://github.com/` URLs
and `name != path`, so a PR-controlled `.gitmodules` with
`path = ../../../../ClickHouse` (name == path, github URL) passed the guard.
`prepare_before_worktree` then joined that path onto `BEFORE_SRC` and ran
`rm -rf -- {dst}` / `cp -al -- {path} {dst}`, which from the container cwd
`/ClickHouse` resolves to the mounted checkout itself — outside `before_src`.

Harden the pre-fetch guard to also reject absolute paths, any `..` component,
and any path outside `contrib/`, and add a defensive `realpath(dst)`
containment check in `prepare_before_worktree` before the destructive
`rm -rf` (defense in depth). Add `test_gitmodules_shape_rejects_traversal_path`
covering the traversal, `..`, absolute-path, and non-`contrib/` cases.

Addresses the review blocker on
ClickHouse#108827

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants