Skip to content

Add a style check against modifying the server's data directory in stateless tests - #114056

Closed
alexey-milovidov wants to merge 1 commit into
masterfrom
stateless-no-server-data-modification
Closed

alexey-milovidov wants to merge 1 commit into
masterfrom
stateless-no-server-data-modification

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Related: #113978

Stateless tests are not allowed to modify the server's data on disk at all (#113978 (review)). The stateless suite runs against arbitrary server configurations — object storage, shared merge tree, encrypted disks — where the local part layout either does not exist or does not mean what the test assumes, and modifying it corrupts shared state. For example, on a remote disk a plain cp of a part directory duplicates metadata files without incrementing blob reference counts, and a later removal deletes blobs still referenced by the live part; test 04630_merge_over_stale_packed_tmp_dir failed every stress check this way until #113978. Such scenarios belong in integration tests.

This PR adds a style check (server_data_manipulation_in_stateless_tests in ci/jobs/check_style.py) that flags stateless .sh tests which fetch a server-side filesystem path from a system table (system.parts, system.detached_parts, system.projection_parts, system.tables, system.disks, system.server_settings with name = 'path') and also run file-modifying shell commands (rm/cp/mv/dd/truncate/ln/chmod/touch/mkdir/tar, sed -i, output redirection into a variable-derived path, clickhouse-disks write/remove/...).

The 35 existing offenders are grandfathered with an explicit list and must be converted to integration tests over time; the list must only shrink. New violations are rejected with a message explaining the policy. Verified locally: the check is clean on the current tree, catches each grandfathered test when its entry is removed (including the tricky cases: dd after a pipe in 04506, the flags/ directory via system.server_settings in 04329, and the canned-backup installer helper), and 04326_disks_app_read_checksums — which only writes an mktemp scratch file under CLICKHOUSE_TMP — is documented as the single known false positive.

The conversion of the first offender, 04630_merge_over_stale_packed_tmp_dir, is sent separately.

Changelog category (leave one):

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

…ateless tests

Stateless tests run against arbitrary server configurations - object storage,
shared merge tree, encrypted disks - where the local part layout either does
not exist or does not mean what the test assumes, and modifying it corrupts
shared state. For example, on a remote disk a plain `cp` of a part directory
duplicates metadata files without incrementing blob reference counts, and a
later removal deletes blobs still referenced by the live part (test 04630
failed every stress check this way, see
#113978).

The check flags stateless `.sh` tests that fetch a server-side filesystem path
from a system table (`system.parts`, `system.detached_parts`,
`system.projection_parts`, `system.tables`, `system.disks`,
`system.server_settings`) and also run file-modifying shell commands. The
existing offenders are grandfathered until they are converted to integration
tests; new ones are rejected.

Related: #113978

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

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f4c9a28]

Summary: ✅


AI Review

Summary

This PR adds a new check_style.py pass that rejects stateless .sh tests which fetch server-side filesystem paths and then mutate files on disk, while grandfathering the current offenders. The direction is correct, but the checker still has a concrete quoted-# escape hatch, so it does not yet enforce the stated policy reliably.

Findings

⚠️ Majors

  • [ci/jobs/check_style.py:334] line.split("#")[0] is not shell-aware, so any write that includes a quoted # payload is invisible to the mutation regexes. For example, echo '# bad metadata' > "${DATA_PATH}columns_substreams.txt" becomes just echo ' before matching, which lets a new stateless test modify server metadata while bypassing this check. Strip # only when it starts an actual shell comment, or use a quote-aware tokenizer.
Final Verdict

Changes requested: close the quoted-# bypass so the new style check reliably blocks the class of tests this PR is meant to ban.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 9, 2026
Comment thread ci/jobs/check_style.py
continue

for line_number, line in enumerate(file_content.splitlines(), 1):
code = line.split("#")[0]

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 split("#") is not shell-aware, so a quoted # becomes an escape hatch. For example, a new stateless test can still write server metadata with:

echo '# bad metadata' > "${DATA_PATH}columns_substreams.txt"

After this split the line becomes just echo ', so neither the redirection rule nor the mutation-command regex fires and CI lets the test through. These tests often corrupt text metadata/checksum files, so # in the payload is realistic rather than contrived. Please only strip # when it starts an actual shell comment, or make this parsing quote-aware.

alexey-milovidov added a commit that referenced this pull request Aug 9, 2026
…ateless tests

The check (`server_data_manipulation_in_stateless_tests`) flags stateless `.sh`
tests that fetch a server-side filesystem path from a system table
(`system.parts`, `system.detached_parts`, `system.projection_parts`,
`system.tables`, `system.disks`, `system.server_settings` with `name = 'path'`)
and also run file-modifying shell commands. With all offenders converted to
integration tests in this PR, the exclusion list holds only one documented
false positive and one test whose conversion is pending in
#114057.

Folds in #114056.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Folded into #114070, which converts all the grandfathered tests to integration tests and ships the check with the exclusion list already pruned.

pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Aug 23, 2026
…gration tests

Stateless tests must not modify the server's data on disk: the suite runs
against arbitrary server configurations (object storage, shared merge tree,
encrypted disks), where the local part layout either does not exist or does
not mean what the test assumes, and modifying it corrupts shared state.

37 stateless tests move to integration tests, grouped by scenario:
- test_broken_projections (extended): 02254, 04511
- test_broken_tmp_txn_version_startup (extended): 04104, 04492, 04493, 04507
- test_lost_part (extended): 02369, 02370, 04215
- test_corrupted_part_files (new): 02253, 02255, 02444, 04151, 04235, 04323, 04506
- test_mutations_with_tampered_parts (new): 04401, 04412, 04426, 04427, 04428, 04431
- test_attach_tampered_detached_parts (new): 04063, 04246, 04402, 04403, 04404, 04425
- test_backups_from_disk (new): 04054, 04495, 02864, 03001_restore..., 03214, 03231,
  replacing helpers/install_predefined_backup.sh; the canned backups move along
- test_server_metadata_files (new): 03001_matview..., 04329, 04545

The conversions are faithful: every .reference output became an exact
assertion, the explanatory comments are preserved, and DETACH/ATTACH stayed
DETACH/ATTACH except where the original explicitly emulated a server restart
(02255, 04215). Notable: 02444's `rm -f "$path/*.bin"` never expanded the
glob (quoting bug), so its corruption was an accidental no-op; the converted
test applies it for real and the assertions still hold.

See ClickHouse#113978 (review)
Related: ClickHouse#114056
Related: ClickHouse#114057

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant