Skip to content

Fix unit-test bugfix validation: force submodule checkout so the before-binary configures - #111530

Merged
alexey-milovidov merged 5 commits into
masterfrom
ci-fix-ut-bugfix-submodules
Jul 25, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
ci-fix-ut-bugfix-submodules

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

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):

Fix the Bugfix validation (unit tests) job failing to configure the "before" binary.

Description

The Bugfix validation (unit tests) job builds a "before" binary from the merge-base sources (with only the PR's unit-test files overlaid) and checks that the new test fails without the fix. It populates the before-worktree's submodule working trees by hardlinking them from the primary checkout, whose submodules are checked out by ensure_primary_submodules with git submodule update --depth 1 --single-branch.

When the runner restores the submodule S3 cache, each submodule's .git/modules data is present with HEAD already at the recorded gitlink, but the working tree is empty. In that state git submodule update (without --force) sees HEAD == the recorded commit, considers the submodule up to date, and leaves the working tree empty. The hardlink loop then found contrib/abseil-cpp empty in the primary checkout, silently continued past it, and cmake later failed with a misleading Cannot find source file ... throw_delegate.cc / borrowed_fixup_buffer.cc. This is an infrastructure problem that surfaced as a red job which never actually validated the bugfix.

Fixes:

  • ensure_primary_submodules: add --force so git submodule update runs git checkout --force unconditionally and repopulates a submodule whose HEAD already matches but whose working tree is empty. Verified in isolation: with the .git link and module HEAD present at the recorded commit but the files removed, plain update leaves the working tree empty while --force restores it.
  • prepare_before_worktree: run ensure_primary_submodules before creating the worktree; check the cp -al exit status and that the destination ended up with real content (a directory holding only the bookkeeping .git entry counts as empty); treat a submodule that is empty in the primary checkout as a hard failure instead of silently skipping it. Any failure now fails close with a precise per-submodule message and the job reports an infrastructure ERROR rather than a spurious cmake source-file error.
  • Fail close when submodule state (any gitlink or .gitmodules) differs between the merge-base and the checkout HEAD (normally GitHub's synthetic base+PR merge ref, whose submodule working trees are what gets hardlinked): whether the PR edits submodule state or the base branch moved a submodule after the branch split, the before-binary would otherwise silently build merge-base sources against the wrong submodule content and could report a false reproduction/refutation. The job reports an infrastructure ERROR (inconclusive) instead. The guard's git diff is strict: a failed diff raises instead of silently disabling the guard. Covered by focused unit tests in ci/tests/test_unit_tests_bugfix_validation.py.

Surfaced by the Bugfix validation (unit tests) job on https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110833&sha=1fd7b845e718f6d4ce0f2dbffb5a44b20d43eb9e&name_0=PR&name_1=Bugfix%20validation%20%28unit%20tests%29 (PR #110833).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

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

…fore-binary configures

The "Bugfix validation (unit tests)" job builds a "before" binary from the
merge-base sources (with only the PR's unit-test files overlaid) and checks that
the new test fails without the fix. It populates the before-worktree's submodule
working trees by hardlinking them from the primary checkout, whose submodules are
in turn checked out by `ensure_primary_submodules`.

That checkout used `git submodule update --depth 1 --single-branch`. When the
runner restores the submodule S3 cache, each submodule's `.git/modules` data is
present with `HEAD` already at the recorded gitlink, but the working tree is
empty. In that state `git submodule update` (without `--force`) sees
`HEAD == recorded commit`, considers the submodule up-to-date, and leaves the
working tree empty. The hardlink loop then found `contrib/abseil-cpp` empty in
the primary checkout, silently `continue`d past it, and `cmake` later failed
with a misleading `Cannot find source file ... throw_delegate.cc /
borrowed_fixup_buffer.cc` — an infrastructure problem reported as a red job that
never actually validated anything.

Fixes:

- `ensure_primary_submodules`: add `--force` so `git submodule update` runs
  `git checkout --force` unconditionally and repopulates a submodule whose
  `HEAD` already matches but whose working tree is empty. Verified in isolation:
  with the `.git` link and module `HEAD` present at the recorded commit but the
  files removed, plain `update` leaves the working tree empty while `--force`
  restores it.

- `prepare_before_worktree`: run `ensure_primary_submodules` before creating the
  worktree; check the `cp -al` exit status and that the destination ended up
  non-empty; treat a submodule that is empty in the primary checkout as a hard
  failure instead of silently skipping it. Any failure now fails close with a
  precise per-submodule message and the job reports an infrastructure ERROR
  rather than a spurious cmake source-file error.

Surfaced by the "Bugfix validation (unit tests)" job on
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110833&sha=1fd7b845e718f6d4ce0f2dbffb5a44b20d43eb9e&name_0=PR&name_1=Bugfix%20validation%20%28unit%20tests%29
Related: #110833

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e5e777]

Summary: ✅


AI Review

Summary

This PR hardens the Bugfix validation (unit tests) job around submodule handling: it now forces cached submodule checkouts to repopulate empty working trees, fails close when the merge-base and checkout disagree on submodule state, and rejects .git-only hardlink copies that would still leave the before-worktree unbuildable. I reviewed the current diff and the full prior thread history; the previously reported fail-open paths are fixed in the current head, and I did not find any new correctness or safety issues that still warrant an inline comment.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 23, 2026
The before-worktree's submodules are hardlinked from the primary checkout,
which is at the PR-head revisions. If the PR changes any submodule gitlink or
`.gitmodules`, the "before" binary would be built against PR-head submodule
content (or miss a merge-base-only submodule), and the validator could report
a false reproduction or refutation. Detect submodule state changes between the
merge-base and the PR head via `git diff --raw --ignore-submodules=none` (the
override matters: a `diff.ignoreSubmodules=all` config would otherwise hide
every gitlink change) and report an infrastructure `ERROR` instead of
validating against the wrong code.

Co-Authored-By: Claude Fable 5 <[email protected]>
The AI review requested focused tests for the submodule-state guard added in
the previous commit. Cover, with a mocked `Shell.get_output`: a gitlink bump,
added/removed gitlinks (mode 160000 on one side only), a `.gitmodules`-only
edit, a clean diff, an empty diff, and malformed/noise lines. Also assert the
command passes `--ignore-submodules=none` and diffs the merge-base against
the PR head.

Co-Authored-By: Claude Fable 5 <[email protected]>
…not the PR head

The fail-close guard `get_submodule_state_changes` diffed the merge-base
against the PR head, but `prepare_before_worktree` hardlinks submodule
working trees from the primary checkout, whose submodules are checked out
at `HEAD`'s recorded revisions — normally GitHub's synthetic base+PR merge
ref. A base-only submodule bump after the branch split therefore escaped
the guard: the PR's own diff shows no gitlink change, yet
`ensure_primary_submodules` checks out the base-tip revision and the
hardlink step copies it into the merge-base worktree, so the before-binary
would build merge-base sources against base-tip contrib content and could
produce a false reproduction or refutation.

Compare the merge-base against `git rev-parse HEAD` instead — the commit
whose submodule trees are actually copied — which catches both PR-side
gitlink/`.gitmodules` edits and base-side drift. Add a focused wiring test
that `main` passes the checkout `HEAD` (not the PR head) to the guard.

Co-Authored-By: Claude Fable 5 <[email protected]>
…dule worktrees

Two fail-close gaps from the AI review:

- `get_submodule_state_changes` now runs the `git diff --raw` with
  `strict=True`: without it, `Shell.get_output` swallows a non-zero git
  exit (missing object in the shallow checkout, transient error) into an
  empty string, and the drift guard would silently disable itself.

- `prepare_before_worktree` now uses `submodule_worktree_populated`,
  which ignores the bookkeeping `.git` entry, for both the source
  submodule and the hardlinked destination: a plain `git submodule
  update` can exit 0 leaving exactly `['.git']` in the working tree,
  which a bare `os.listdir` non-empty check would accept, propagating a
  sourceless tree into the before-worktree and reintroducing the
  misleading cmake "cannot find source file" failure.

Covered by new unit tests (strict flag asserted, diff failure
propagates, `.git`-only and empty directories rejected, real content
accepted).

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Jul 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 25, 2026
Merged via the queue into master with commit 9aaf5d3 Jul 25, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the ci-fix-ut-bugfix-submodules branch July 25, 2026 17:42
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 25, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-submodules

Fix unit-test bugfix validation: force submodule checkout so the before-binary configures
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.

2 participants