Skip to content

Unify payload size threshold validation across TOML and stdin config paths#7045

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-payload-size-threshold
Jun 5, 2026
Merged

Unify payload size threshold validation across TOML and stdin config paths#7045
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-payload-size-threshold

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 5, 2026

gateway.payload_size_threshold (TOML) and gateway.payloadSizeThreshold (stdin JSON) were validated in two places with different bounds, so 0 was accepted in TOML but rejected in stdin. This change consolidates the rule and makes both config surfaces reject explicit non-positive values consistently.

  • What changed

    • Added a shared rules.PositiveInteger validator for config fields that must be >= 1.
    • Replaced the ad-hoc payloadSizeThreshold / payload_size_threshold checks in both validation paths with the shared rule.
    • Preserved existing defaulting behavior for omitted values while rejecting explicitly configured 0 on the TOML path.
  • TOML path

    • Validates gateway.payload_size_threshold before defaults are applied.
    • Uses TOML metadata to distinguish omitted from explicitly set to 0, so:
      • omitted field still defaults
      • explicit 0 now fails validation instead of being silently normalized
  • stdin / JSON path

    • Uses the same shared validator for gateway.payloadSizeThreshold.
    • Keeps error structure and semantics aligned with the TOML path.
  • Tests

    • Extended TOML coverage to reject both 0 and negative values.
    • Added direct unit coverage for the shared positive-integer rule.
if md.IsDefined("gateway", "payload_size_threshold") {
	if err := rules.PositiveInteger(
		cfg.Gateway.PayloadSizeThreshold,
		"payload_size_threshold",
		"gateway.payload_size_threshold",
	); err != nil {
		return nil, err
	}
}

if gateway.PayloadSizeThreshold != nil {
	if err := rules.PositiveInteger(
		*gateway.PayloadSizeThreshold,
		"payloadSizeThreshold",
		"gateway.payloadSizeThreshold",
	); err != nil {
		return err
	}
}

Copilot AI changed the title [WIP] Fix duplicate validation inconsistency for payloadSizeThreshold Unify payload size threshold validation across TOML and stdin config paths Jun 5, 2026
Copilot AI requested a review from lpcox June 5, 2026 13:59
Copilot finished work on behalf of lpcox June 5, 2026 13:59
@lpcox lpcox marked this pull request as ready for review June 5, 2026 14:39
Copilot AI review requested due to automatic review settings June 5, 2026 14:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 consolidates validation for the gateway.payload_size_threshold (TOML) and gateway.payloadSizeThreshold (stdin JSON) configuration fields so both surfaces consistently reject explicitly configured non-positive values while preserving defaulting behavior when the field is omitted.

Changes:

  • Introduces a shared rules.PositiveInteger validator and uses it for stdin gateway config validation.
  • Moves TOML payload_size_threshold validation to occur before defaults are applied, using TOML metadata to distinguish omitted vs explicitly-set values.
  • Extends/updates tests to cover invalid payload_size_threshold values and the new shared rule.
Show a summary per file
File Description
internal/config/validation.go Switches stdin payloadSizeThreshold validation to the shared positive-integer rule.
internal/config/rules/rules.go Adds PositiveInteger validator used across config validation paths.
internal/config/rules/rules_test.go Adds unit tests for the new PositiveInteger validator.
internal/config/config_core.go Validates TOML payload_size_threshold before defaults (only when explicitly defined).
internal/config/config_core_test.go Updates TOML tests to reject both 0 and negative payload_size_threshold values.

Copilot's findings

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread internal/config/rules/rules.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit d87eb8f into main Jun 5, 2026
16 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-payload-size-threshold branch June 5, 2026 15:28
@github-actions github-actions Bot mentioned this pull request Jun 5, 2026
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.

[duplicate-code] Duplicate Code Pattern: payloadSizeThreshold validation inconsistency between TOML and stdin paths

3 participants