Skip to content

Add Node port of ClickHouse Java's clickhouse-test-runner harness#706

Merged
peter-leonov-ch merged 7 commits into
mainfrom
copilot/add-js-client-cli-tests
May 8, 2026
Merged

Add Node port of ClickHouse Java's clickhouse-test-runner harness#706
peter-leonov-ch merged 7 commits into
mainfrom
copilot/add-js-client-cli-tests

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Ports ClickHouse/clickhouse-java/tests/clickhouse-client to this repo as tests/clickhouse-test-runner/, a small Node CLI that wraps @clickhouse/client to mimic the upstream clickhouse-client binary. With it on PATH, the official tests/clickhouse-test runner will exercise the JS client against the core ClickHouse SQL test suite.

  • Standalone package (tests/clickhouse-test-runner/, not a workspace, only depends on @clickhouse/client) with its own tsconfig, eslint, and Vitest config.
  • bin/clickhouse bash shim — short-circuits extract-from-config --key listen_host127.0.0.1 (the only key the upstream runner needs), otherwise exec node dist/main.js.
  • Two backends selected via CLICKHOUSE_CLIENT_CLI_IMPL (mirrors Java's client/jdbc split):
    • client (default) — client.exec({ query, clickhouse_settings: { default_format: 'TabSeparated', ... } }) with the response stream piped straight to stdout (raw bytes, no decoding).
    • http — Node fetch against /?default_format=TabSeparated&... with basic auth, body-streamed to stdout with backpressure.
  • Arg parser (src/args.ts) accepting both --foo bar and --foo=bar, dashed/underscored variants listed as separate canonical entries in BASE_OPTIONS, short forms (-h/-u/-d/-q/-s/-n), and dynamic long options. Unknown long options are classified against SERVER/CLIENT_ONLY allowlists copied from the Java port: server settings are forwarded, client-only and unknown are silently dropped. Per review feedback, max_threads was reclassified from CLIENT_ONLY_SETTINGS to SERVER_SETTINGS so --max_threads=N from the upstream test runner is forwarded to ClickHouse instead of being silently dropped. The unused aliases field on OptionSpec was removed since the parser never read it (dash/underscore forms work via separate BASE_OPTIONS entries).
  • Quote-aware multi-query splitter (src/split-queries.ts) — tracks single/double/backtick state and \-escapes; only splits on unquoted ;.
  • Logging to CLICKHOUSE_CLIENT_CLI_LOG (default /tmp/clickhouse-client-cli.log) with CWD fallback; failures are swallowed so the CLI never breaks tests.
  • Exit codes via process.exitCode only — never process.exit() — to avoid truncating stdout writes.
  • Vitest unit tests for split-queries, args, extract-from-config, and log. Live smoke against docker compose up -d clickhouse exercises both backends and --multiquery over stdin.

Usage:

cd tests/clickhouse-test-runner && npm install && npm run build

# Drive the upstream runner (download CH test files; do NOT clone the full repo)
CLICKHOUSE_CLIENT_CLI_LOG=./test-run.log \
  PATH="$PWD/tests/clickhouse-test-runner/bin:$PATH" \
  /path/to/ClickHouse/tests/clickhouse-test 01428_hash_set_nan_key

The SERVER/CLIENT_ONLY allowlists are copied from the Java port and will need periodic resync as ClickHouse adds settings.

Checklist

  • Unit and integration tests covering the common scenarios were added

Copilot AI and others added 3 commits May 7, 2026 19:05
Implements step 2 of porting the Java clickhouse-client test harness:
- src/backends/client.ts: @clickhouse/client backend, streams exec() output
- src/backends/http.ts: built-in fetch backend, streams response.body
- src/main.ts: CLI entrypoint with extract-from-config short-circuit,
  arg parsing, stdin fallback, impl dispatch, and diagnostic logging
- bin/clickhouse: bash shim that fast-paths extract-from-config and
  exec's node on the built dist/main.js entrypoint
- package.json: chmod +x dist/main.js after build so bin/clickhouse works

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@CLAassistant

CLAassistant commented May 7, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ peter-leonov-ch
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@peter-leonov-ch peter-leonov-ch marked this pull request as ready for review May 7, 2026 20:54
@peter-leonov-ch peter-leonov-ch self-requested a review as a code owner May 7, 2026 20:54
Copilot AI review requested due to automatic review settings May 7, 2026 20:54
@peter-leonov-ch peter-leonov-ch requested a review from mshustov as a code owner May 7, 2026 20:54

Copilot AI left a comment

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.

Pull request overview

This PR introduces tests/clickhouse-test-runner/, a standalone Node.js CLI harness that emulates the upstream clickhouse-client interface so the official ClickHouse tests/clickhouse-test runner can exercise @clickhouse/client against the core SQL test suite.

Changes:

  • Added a Node-based clickhouse-client-like CLI with argument parsing, multi-query splitting, logging, and extract-from-config support.
  • Implemented two execution backends (@clickhouse/client streaming and raw HTTP fetch) that stream results to stdout.
  • Added standalone tooling/config (TypeScript, ESLint, Vitest) plus unit tests for core utilities.

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/clickhouse-test-runner/vitest.config.ts Vitest config scoped to the harness tests.
tests/clickhouse-test-runner/tsconfig.json Typecheck config for the harness sources/tests.
tests/clickhouse-test-runner/tsconfig.build.json Build config emitting dist/ output.
tests/clickhouse-test-runner/src/split-queries.ts Quote-aware SQL ; splitter for --multiquery.
tests/clickhouse-test-runner/src/settings.ts Setting allowlists and classifier for forwarding/dropping flags.
tests/clickhouse-test-runner/src/main.ts CLI entrypoint: parse args, read query, dispatch backend, set exit codes.
tests/clickhouse-test-runner/src/log.ts Best-effort logging utilities with fallback path.
tests/clickhouse-test-runner/src/extract-from-config.ts Implements extract-from-config --key behavior.
tests/clickhouse-test-runner/src/backends/http.ts Raw HTTP backend using fetch and streaming stdout writes.
tests/clickhouse-test-runner/src/backends/client.ts @clickhouse/client backend streaming raw response bytes to stdout.
tests/clickhouse-test-runner/src/args.ts CLI argument parser + dynamic setting handling.
tests/clickhouse-test-runner/README.md Documentation for build/usage and environment variables.
tests/clickhouse-test-runner/package.json Standalone package definition + scripts/deps.
tests/clickhouse-test-runner/package-lock.json Locked dependency tree for standalone installs.
tests/clickhouse-test-runner/eslint.config.mjs ESLint flat config for this harness.
tests/clickhouse-test-runner/bin/clickhouse Bash shim to shadow clickhouse-client and short-circuit extract-from-config.
tests/clickhouse-test-runner/.gitignore Ignores build artifacts and logs.
tests/clickhouse-test-runner/tests/split-queries.test.ts Unit tests for query splitting.
tests/clickhouse-test-runner/tests/log.test.ts Unit tests for logging helpers.
tests/clickhouse-test-runner/tests/extract-from-config.test.ts Unit tests for extract-from-config behavior.
tests/clickhouse-test-runner/tests/args.test.ts Unit tests for argument parsing and setting classification.
Files not reviewed (1)
  • tests/clickhouse-test-runner/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/clickhouse-test-runner/src/settings.ts
Comment thread tests/clickhouse-test-runner/src/args.ts Outdated
Comment thread tests/clickhouse-test-runner/src/args.ts
Comment thread tests/clickhouse-test-runner/package.json
Comment thread tests/clickhouse-test-runner/src/main.ts
Comment thread tests/clickhouse-test-runner/package.json Outdated
peter-leonov-ch and others added 2 commits May 8, 2026 00:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ClickHouse/clickhouse-js/sessions/5d9d9755-83c5-4b96-971a-a23e734237b4

Co-authored-by: peter-leonov-ch <209667683+peter-leonov-ch@users.noreply.github.com>
@peter-leonov-ch peter-leonov-ch merged commit dbe8486 into main May 8, 2026
60 checks passed
@peter-leonov-ch peter-leonov-ch deleted the copilot/add-js-client-cli-tests branch May 8, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants