Skip to content

cli: add TOML output format to changefeed query#4986

Open
JesseZhuang wants to merge 2 commits intopingcap:masterfrom
JesseZhuang:jessezhuang/query-output-toml
Open

cli: add TOML output format to changefeed query#4986
JesseZhuang wants to merge 2 commits intopingcap:masterfrom
JesseZhuang:jessezhuang/query-output-toml

Conversation

@JesseZhuang
Copy link
Copy Markdown

@JesseZhuang JesseZhuang commented May 2, 2026

What problem does this PR solve?

cdc cli changefeed create --config consumes TOML, but cdc cli changefeed query only returns JSON. This asymmetry makes changefeed migration, config review, and version control more manual than necessary.

Issue Number: ref #4936

What is changed and how it works?

Add --output json|toml flag to cdc cli changefeed query, keeping JSON as the default.

TOML output uses kebab-case keys, human-readable durations (10m0s instead of nanoseconds), and readable timestamps (2026-04-18 09:35:00.139).

The TOML conversion happens entirely in the CLI layer without adding TOML struct tags to api/v2/model.go. This is achieved via two-stage encoding:

  1. BurntSushi/toml encodes config.ReplicaConfig (which already has toml tags) into a map[string]interface{} — this produces correct kebab-case keys and human-readable duration strings.
  2. pelletier/go-toml/v2 encodes the outer CLI struct (cfMetaTOML) with SetIndentTables/SetArraysMultiline for formatting. The Config field is interface{} holding the map from step 1.

This keeps the API model as a pure JSON HTTP contract per feedback in #4936.

This is PR 1 of 3 for #4936. PR 2 will add --diff-default, PR 3 will add config file enhancements.

Check List

Tests

  • Added/modified unit tests
Integration tests

Built from this branch and deployed to a local TiDB-on-k3d cluster (TiCDC Classic kernel, v8.5.6 base). 27 pytest-based integration tests, all passing:

  • T4 — Full query JSON vs TOML (11 tests): valid output, kebab-case keys, [config] section structure, durations as '10m0s', readable timestamps, single-quoted strings, JSON↔TOML field correspondence, overrides changefeed
  • T4 — Escape-sensitive fields (4 tests): CRLF terminator, \N csv null in both formats
  • T9 — Realistic sink URI (4 tests): password redaction in both formats, config override values, JSON↔TOML match
  • TOML formatting (4 tests): multi-line arrays with exact indentation (6-space elements), table headers indented under parent, all nested [config.*] fields 4-space indented
  • T14 — Large filter array (4 tests): 12-rule filter array preserved, exact block format, JSON↔TOML match

integration-tests-pr1-20260502.zip

Questions

Will it cause performance regression or break compatibility?

No. JSON output is unchanged (default). TOML output is a new opt-in flag. No changes to the API model or server behavior.

Do you need to update user documentation, design documentation or monitoring documentation?

CLI help text is updated via the new --output flag. No other documentation changes needed.

Release note

Add `--output json|toml` flag to `cdc cli changefeed query` to support TOML-formatted output with kebab-case keys and human-readable durations.

Summary by CodeRabbit

  • New Features

    • CLI changefeed query gains an --output/-o option to emit JSON or TOML (full or simplified); TOML uses kebab-case keys and human-readable durations/timestamps.
    • Timestamp values now support an unquoted text format for outputs.
  • Tests

    • Added extensive automated checks validating JSON vs TOML output, simplified output behavior, key naming, durations, timestamps, array/indentation formatting, and invalid-format handling.
  • Chores

    • Test harness and CI grouping updated to include the new TOML/JSON validation suite.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Review Change Stack

Warning

Rate limit exceeded

@JesseZhuang has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 45 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0d89f995-44c8-4c5d-8cb3-3d3aae4606ae

📥 Commits

Reviewing files that changed from the base of the PR and between d1260ec and b063815.

📒 Files selected for processing (6)
  • tests/integration_tests/cli_query_toml/conf/large_filter.toml
  • tests/integration_tests/cli_query_toml/conf/overrides.toml
  • tests/integration_tests/cli_query_toml/conf/realistic.toml
  • tests/integration_tests/cli_query_toml/main.go
  • tests/integration_tests/cli_query_toml/run.sh
  • tests/integration_tests/run_light_it_in_ci.sh
📝 Walkthrough

Walkthrough

Adds TOML output support to cli changefeed query (flag parsing and printing), TOML metadata structs and config serialization, text-based timestamp marshal/unmarshal for api.JSONTime, unit and integration tests with a TOML validator and fixtures, and CI grouping for the integration test.

Changes

Changefeed Query TOML Output

Layer / File(s) Summary
Output Format Types & Printing
cmd/util/util.go
Added OutputFormat type and constants, ParseOutputFormat, TOMLPrint (using pelletier encoder), and FormatPrint dispatcher.
Timestamp Text Encoding
pkg/api/util.go
Added textTimeFormat constant and JSONTime.MarshalText / JSONTime.UnmarshalText for unquoted text timestamps.
CLI Data Structures
cmd/cdc/cli/cli_changefeed_query.go
Added cfMetaSimplifiedTOML and cfMetaTOML structs, outputFormat field on queryChangefeedOptions, and registered --output/-o flag.
CLI Logic & Serialization
cmd/cdc/cli/cli_changefeed_query.go
Updated run() to parse output format and branch for JSON vs TOML for both simplified and full outputs; added configToMap to serialize replica config into map[string]interface{} (JSON path or TOML path using internal transform and TOML encode/decode for key formatting).
Tests: Unit
cmd/cdc/cli/cli_changefeed_query_test.go
Added tests covering full vs simplified TOML rendering, kebab-case TOML key naming, duration and timestamp formatting, nil-config handling, JSONTime text marshal/unmarshal, and ParseOutputFormat behavior; added newJSONDuration test helper.
Integration Test Harness & Fixtures
tests/integration_tests/cli_query_toml/main.go, .../conf/*.toml, .../run.sh
Added TOML validator CLI with additional checks, TOML fixture files (large_filter.toml, overrides.toml, realistic.toml), and run script that creates changefeeds, captures JSON/TOML outputs, and validates formatting/content across formats.
CI Grouping
tests/integration_tests/run_light_it_in_ci.sh
Included cli_query_toml in G13 test group for mysql, kafka, pulsar, and storage.
Dependency Bump
go.mod
Moved github.com/pelletier/go-toml/v2 from indirect to direct require.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Suggested labels

lgtm, approved, size/XL

Suggested reviewers

  • asddongmen
  • hongyunyan

Poem

🐰 I nibble keys in kebab and hum,
JSON and TOML now both can come.
Timestamps tidy, durations sing,
Validator hops to check each thing.
Hop on, review — a crunchy crumb.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'cli: add TOML output format to changefeed query' clearly and concisely summarizes the main change—adding TOML output support to the changefeed query command.
Description check ✅ Passed The PR description includes all required template sections: problem statement with issue reference, detailed explanation of changes and design, test coverage confirmation, compatibility assessment, and a release note.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds TOML output support to the cdc cli changefeed query command, including a new --output flag and specialized handling for kebab-case keys and human-readable timestamps. Reviewers suggested addressing an inconsistency where simplified TOML output fails to use kebab-case keys and recommended performance improvements to avoid unnecessary string allocations during TOML encoding and decoding.

Comment thread cmd/cdc/cli/cli_changefeed_query.go Outdated
Comment thread cmd/cdc/cli/cli_changefeed_query.go Outdated
Comment thread cmd/util/util.go
@JesseZhuang JesseZhuang force-pushed the jessezhuang/query-output-toml branch from 1d4486b to 9a03166 Compare May 2, 2026 20:42
@JesseZhuang JesseZhuang marked this pull request as ready for review May 2, 2026 21:34
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
cmd/util/util.go (1)

181-190: ⚡ Quick win

Wrap TOML encoder failures before returning.

pelletier.NewEncoder(...).Encode is a library boundary, so returning the raw error drops the stack trace expected by this repo's error-handling rule. Please wrap it with errors.Trace(err) or errors.WrapError(...) before bubbling it up. As per coding guidelines, when an error comes from a third party/library call, wrap it immediately with errors.Trace(err) or errors.WrapError(...) to attach a stack trace.

Suggested change
 func TOMLPrint(cmd *cobra.Command, v interface{}) error {
 	var buf strings.Builder
 	enc := pelletier.NewEncoder(&buf)
 	enc.SetArraysMultiline(true)
 	enc.SetIndentTables(true)
 	if err := enc.Encode(v); err != nil {
-		return err
+		return errors.Trace(err)
 	}
 	cmd.Printf("%s", buf.String())
 	return nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/util/util.go` around lines 181 - 190, The TOMLPrint function returns raw
errors from the pelletier encoder (enc.Encode) which loses stack traces; update
the error return to wrap the encoder error with the repo's error helpers (e.g.,
return errors.Trace(err) or return errors.WrapError(err, "encode toml") ) right
where enc.Encode(v) is called so any library error is immediately annotated with
a stack trace before being bubbled up from TOMLPrint.
cmd/cdc/cli/cli_changefeed_query.go (1)

233-258: ⚡ Quick win

Wrap the config round-trip errors as well.

The TOML/JSON encode/decode calls here all return raw library errors, which drops stack traces on a user-visible CLI path. Please wrap each failure with errors.Trace(err) before returning. As per coding guidelines, when an error comes from a third party/library call, wrap it immediately with errors.Trace(err) or errors.WrapError(...) to attach a stack trace.

Suggested change
 func configToMap(cfg *v2.ReplicaConfig, format util.OutputFormat) (map[string]interface{}, error) {
 	if cfg == nil {
 		return nil, nil
 	}
 	if format == util.OutputFormatTOML {
 		internalCfg := cfg.ToInternalReplicaConfig()
 		var buf bytes.Buffer
 		if err := toml.NewEncoder(&buf).Encode(internalCfg); err != nil {
-			return nil, err
+			return nil, errors.Trace(err)
 		}
 		var m map[string]interface{}
 		if _, err := toml.NewDecoder(&buf).Decode(&m); err != nil {
-			return nil, err
+			return nil, errors.Trace(err)
 		}
 		return m, nil
 	}
 	data, err := json.Marshal(cfg)
 	if err != nil {
-		return nil, err
+		return nil, errors.Trace(err)
 	}
 	var m map[string]interface{}
 	if err := json.Unmarshal(data, &m); err != nil {
-		return nil, err
+		return nil, errors.Trace(err)
 	}
 	return m, nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/cdc/cli/cli_changefeed_query.go` around lines 233 - 258, In configToMap,
wrap all third-party encode/decode errors with a stack-tracing wrapper before
returning: replace raw returns from toml.NewEncoder(&buf).Encode(...),
toml.NewDecoder(&buf).Decode(...), json.Marshal(cfg), and json.Unmarshal(data,
&m) so each error is returned as errors.Trace(err) (or errors.WrapError(...))
instead of the raw err; this ensures all failures in configToMap have stack
traces while keeping the existing control flow and return values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/cdc/cli/cli_changefeed_query.go`:
- Around line 233-258: In configToMap, wrap all third-party encode/decode errors
with a stack-tracing wrapper before returning: replace raw returns from
toml.NewEncoder(&buf).Encode(...), toml.NewDecoder(&buf).Decode(...),
json.Marshal(cfg), and json.Unmarshal(data, &m) so each error is returned as
errors.Trace(err) (or errors.WrapError(...)) instead of the raw err; this
ensures all failures in configToMap have stack traces while keeping the existing
control flow and return values.

In `@cmd/util/util.go`:
- Around line 181-190: The TOMLPrint function returns raw errors from the
pelletier encoder (enc.Encode) which loses stack traces; update the error return
to wrap the encoder error with the repo's error helpers (e.g., return
errors.Trace(err) or return errors.WrapError(err, "encode toml") ) right where
enc.Encode(v) is called so any library error is immediately annotated with a
stack trace before being bubbled up from TOMLPrint.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5379bfa6-f18b-4d0a-bf7f-c9fc210d45f5

📥 Commits

Reviewing files that changed from the base of the PR and between 5518eb2 and 9a03166.

📒 Files selected for processing (5)
  • cmd/cdc/cli/cli_changefeed_query.go
  • cmd/cdc/cli/cli_changefeed_query_test.go
  • cmd/util/util.go
  • go.mod
  • pkg/api/util.go

Add `--output json|toml` flag to `cdc cli changefeed query`, keeping
JSON as the default. TOML output uses kebab-case keys, human-readable
durations ("10m0s" instead of nanoseconds), and readable timestamps.

The TOML conversion happens entirely in the CLI layer without adding
TOML struct tags to the API model (api/v2/model.go). This is achieved
via two-stage encoding: BurntSushi/toml encodes the internal config
(which already has toml tags) into a map, then pelletier/go-toml/v2
encodes the outer CLI struct with formatting control.

Issue: pingcap#4936

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JesseZhuang JesseZhuang force-pushed the jessezhuang/query-output-toml branch from 9a03166 to c7602c0 Compare May 2, 2026 21:55
@ti-chi-bot ti-chi-bot Bot added contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. labels May 3, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 3, 2026

Welcome @JesseZhuang!

It looks like this is your first PR to pingcap/ticdc 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/ticdc. 😃

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign flowbehappy for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

2 similar comments
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign flowbehappy for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign flowbehappy for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels May 3, 2026
@wlwilliamx
Copy link
Copy Markdown
Collaborator

Could you add a integration test?

@wlwilliamx
Copy link
Copy Markdown
Collaborator

I want to clarify the intended contract of query -o toml here.

If this PR is only adding a TOML format for human-readable inspection, the current direction looks reasonable to me. But if this output is meant to become the foundation for a later “copy from query -o toml and paste into create --config” workflow, I think we may need to reconsider the shape of the output and possibly the requirement itself.

The full query result contains runtime/status fields such as upstream-id, create-time, resolved-ts, checkpoint-tso, checkpoint-time, state, error, and task-status. These are useful when inspecting a changefeed, but they are not creation config. Making this output importable later would either require create --config to ignore/accept non-config status fields, or require a separate export mode with a different schema.

We need to clarify whether query -o toml in this PR is intended only as an alternative display format, or whether it is expected to be compatible with the future create --config workflow. What do you think?

@JesseZhuang
Copy link
Copy Markdown
Author

Thanks for the thoughtful question. Let me clarify the design intent:

This PR (PR 1) is only adding TOML as an alternative display format — full parity with the existing JSON output for human-readable inspection.

In subsequent PRs, create --config will support accepting TOML input from cdc cli changefeed query -o toml --diff-default (which outputs only migration-relevant fields: id, sink-uri, start-ts, and non-default config). At that point we can discuss whether a friendlier error message is needed for the full output case.

That said, the existing code already rejects runtime/status fields in config input via strict TOML decoding. The --config flag invokes StrictDecodeFile which uses metaData.Undecoded():

// cmd/util/util.go:52-68
if undecoded := metaData.Undecoded(); len(undecoded) > 0 {
    var b strings.Builder
    hasUnknownConfigSize := 0
    for _, item := range undecoded {
        if hasIgnoreItem(item) {
            continue
        }
        if hasUnknownConfigSize > 0 {
            b.WriteString(", ")
        }
        b.WriteString(item.String())
        hasUnknownConfigSize++
    }
    if hasUnknownConfigSize > 0 {
        err = errors.Errorf("component %s's config file %s contained unknown configuration options: %s",
            component, path, b.String())
    }
}

Since the input struct (ReplicaConfig) only defines replication config fields, any runtime field (upstream-id, state, checkpoint-tso, resolved-ts, task-status, etc.) will be caught as an "unknown configuration option" and the create/update command will fail with a clear error.

So the contract is:

Output mode Contains runtime fields? Can be used as create --config?
query -o toml (this PR) Yes — full parity with JSON No — strict decoder rejects unknown fields
query -o toml --diff-default (future PR) No — only id, sink-uri, start-ts, non-default config Yes — round-trips cleanly

@pingcap-cla-assistant
Copy link
Copy Markdown

pingcap-cla-assistant Bot commented May 7, 2026

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 7, 2026
@JesseZhuang
Copy link
Copy Markdown
Author

JesseZhuang commented May 7, 2026

Updated integration test in the second commit. The test (tests/integration_tests/cli_query_toml/) now covers 28 checks:

  • TOML output validity & parseability (Go helper using BurntSushi/toml)
  • Kebab-case keys with no snake_case leakage
  • Section structure ([config], [config.filter], [config.mounter], [config.sink])
  • Human-readable durations (10m0s not nanoseconds) and timestamps
  • Single-quote string values
  • JSON/TOML field correspondence across default, overrides, realistic, and large-filter changefeeds
  • Password redaction in realistic sink URI (both JSON and TOML)
  • Realistic config values (scheduler, filter overrides)
  • TOML indentation (config fields 2-space, nested headers, nested fields 4-space)
  • Single-element and multi-element array block format
  • Simplified query (--simple -o toml)
  • Invalid format error handling
  • Short flag (-o toml) support

Local validation

All 28 checks pass locally on macOS arm64 (M4 Pro). The TiKV gRPC issue I mentioned earlier turned out to be caused by macOS Application Firewall blocking TiKV — once allowed through System Settings, the cluster bootstraps fine.

I verified by running the integration tests on mac. The docker route had an End of Life centos 7 container which was not available from the official repo. What is the recommended way to run integration tests locally?

[Thu May  7 03:27:49 PDT 2026] <<<<<< run test case cli_query_toml success! >>>>>>

My own integration tests I mentioned earlier were run against a local tidb k8s cluster I started on my mac.

Built from this branch and deployed to a local TiDB-on-k3d cluster (TiCDC Classic kernel, v8.5.6 base). pytest-based integration tests, all passing

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration_tests/cli_query_toml/main.go`:
- Around line 68-84: The error returns in readTOML and readJSON currently wrap
third-party errors directly with fmt.Errorf; update both functions to wrap the
original errors using the project helpers (use errors.Trace(err) or
errors.WrapError(err, "message")) instead of fmt.Errorf so stack traces are
attached — for example, when toml.DecodeFile returns an error in readTOML and
when os.ReadFile or json.Unmarshal return errors in readJSON, pass the original
err into errors.Trace or errors.WrapError and return that wrapped error with the
same contextual message.
- Around line 150-181: The comparison currently only validates nested fields
when both type assertions succeed (jOk && tOk), allowing missing or
differently-typed sections to pass silently; update the logic around
jConfig/tConfig, jMounter/tMounter and jFilter/tFilter to explicitly detect and
return an error when one side is missing or has the wrong type (e.g., if jOk !=
tOk or jmOk != tmOk or jfOk != tfOk) with clear messages like "config missing or
type mismatch", "config.mounter missing or type mismatch", and "config.filter
missing or type mismatch" while keeping the existing field-level comparisons
(num(...), toStringSlice(...)) intact so absent sections fail fast instead of
being treated as equal.

In `@tests/integration_tests/cli_query_toml/run.sh`:
- Line 152: The shell invocation currently uses the globbed/expanded form run $*
which can split arguments with spaces; update the script so the test runner call
uses the positional-parameter expansion that preserves argument boundaries by
replacing the use of $* with "$@" (i.e., change the invocation containing the
token run $* to use run "$@" so quoted arguments are passed intact).
- Around line 125-133: The test currently only inspects stderr text for the
invalid-format case using bad_output but doesn't check the command's exit
status; update the block that runs cdc_cli_changefeed query -c "cf-default"
--output yaml to capture the command's exit code (e.g., immediately after
running and redirecting stderr into bad_output) and assert that the exit code is
non-zero in addition to checking stderr content; refer to the variables/command
used (bad_output and the cdc_cli_changefeed query invocation) and fail the test
if the exit code is zero or the stderr doesn't match the expected
invalid/unknown/unsupported text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 72e330d4-3c73-4f6d-99be-36cdcc4af55b

📥 Commits

Reviewing files that changed from the base of the PR and between 9a03166 and 4785fa1.

📒 Files selected for processing (10)
  • cmd/cdc/cli/cli_changefeed_query.go
  • cmd/cdc/cli/cli_changefeed_query_test.go
  • cmd/util/util.go
  • go.mod
  • pkg/api/util.go
  • tests/integration_tests/cli_query_toml/conf/large_filter.toml
  • tests/integration_tests/cli_query_toml/conf/overrides.toml
  • tests/integration_tests/cli_query_toml/main.go
  • tests/integration_tests/cli_query_toml/run.sh
  • tests/integration_tests/run_light_it_in_ci.sh
✅ Files skipped from review due to trivial changes (3)
  • tests/integration_tests/cli_query_toml/conf/large_filter.toml
  • tests/integration_tests/run_light_it_in_ci.sh
  • tests/integration_tests/cli_query_toml/conf/overrides.toml
🚧 Files skipped from review as they are similar to previous changes (5)
  • go.mod
  • pkg/api/util.go
  • cmd/cdc/cli/cli_changefeed_query.go
  • cmd/cdc/cli/cli_changefeed_query_test.go
  • cmd/util/util.go

Comment thread tests/integration_tests/cli_query_toml/main.go
Comment thread tests/integration_tests/cli_query_toml/main.go
Comment thread tests/integration_tests/cli_query_toml/run.sh
Comment thread tests/integration_tests/cli_query_toml/run.sh Outdated
@JesseZhuang
Copy link
Copy Markdown
Author

can you help to add a type label on #4936? looks like one check is failing on this pr because of that.

@JesseZhuang JesseZhuang force-pushed the jessezhuang/query-output-toml branch from 4785fa1 to d1260ec Compare May 7, 2026 10:35
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration_tests/cli_query_toml/main.go`:
- Around line 53-55: The code currently ignores fmt.Sscanf's error when parsing
the CLI expected count causing invalid input to silently become 0; change the
parsing of os.Args[3] (used as expected) to validate the conversion (e.g., use
strconv.Atoi or capture fmt.Sscanf's returned n and err), and on parse failure
emit a clear error and exit non-zero instead of proceeding to call
checkFilterRules; update the call site around fmt.Sscanf/os.Args[3] to check the
error and only call checkFilterRules(os.Args[2], expected) when parsing
succeeds.

In `@tests/integration_tests/cli_query_toml/run.sh`:
- Line 3: The test script uses "set -eu" which allows upstream command failures
(e.g., `cdc_cli_changefeed query` piped into `grep`) to be masked; update the
shell options in run.sh by adding pipefail (e.g., change the invocation to
include -o pipefail or use set -euo pipefail) so any failure in a piped pipeline
(such as the `cdc_cli_changefeed query | grep ...` commands) causes the script
to exit with error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 529d481d-40fd-4087-aa97-2a961d241bfb

📥 Commits

Reviewing files that changed from the base of the PR and between 4785fa1 and d1260ec.

📒 Files selected for processing (6)
  • tests/integration_tests/cli_query_toml/conf/large_filter.toml
  • tests/integration_tests/cli_query_toml/conf/overrides.toml
  • tests/integration_tests/cli_query_toml/conf/realistic.toml
  • tests/integration_tests/cli_query_toml/main.go
  • tests/integration_tests/cli_query_toml/run.sh
  • tests/integration_tests/run_light_it_in_ci.sh
✅ Files skipped from review due to trivial changes (4)
  • tests/integration_tests/cli_query_toml/conf/large_filter.toml
  • tests/integration_tests/cli_query_toml/conf/overrides.toml
  • tests/integration_tests/run_light_it_in_ci.sh
  • tests/integration_tests/cli_query_toml/conf/realistic.toml

Comment thread tests/integration_tests/cli_query_toml/main.go
Comment thread tests/integration_tests/cli_query_toml/run.sh Outdated
Add cli_query_toml integration test that verifies:
- TOML output is valid and parseable
- Kebab-case keys (no snake_case leakage)
- Config section structure ([config], [config.filter], etc.)
- Human-readable durations and timestamps
- JSON/TOML field correspondence
- Config overrides reflected correctly
- Large filter array formatting
- Password redaction in realistic sink URI
- TOML indentation (config fields, nested headers, nested fields)
- Single-element and multi-element array block format
- Simplified query TOML output
- Invalid format error handling
- Short flag (-o toml) support

Uses a Go helper program for structured TOML/JSON validation
(BurntSushi/toml, already a project dependency).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JesseZhuang JesseZhuang force-pushed the jessezhuang/query-output-toml branch from d1260ec to b063815 Compare May 7, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. do-not-merge/needs-triage-completed first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants