Skip to content

[CFX-7834] refactor(pipeline): validate count flags at parse time - #859

Merged
ajalon1 merged 1 commit into
aj/CFX-7834-countflagsfrom
aj/CFX-7834-countflags-pipelines
Aug 31, 2026
Merged

[CFX-7834] refactor(pipeline): validate count flags at parse time#859
ajalon1 merged 1 commit into
aj/CFX-7834-countflagsfrom
aj/CFX-7834-countflags-pipelines

Conversation

@ajalon1

@ajalon1 ajalon1 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

RATIONALE

The pipeline list commands did no flag validation at all — the workload family validated, this family didn't, so the same mistake failed differently depending on which command ate it. The latent bugs this closes:

  • --limit 0 (or negative) silently returned fewer rows than asked. The old query builder omitted the limit param when it was <= 0, so the server's default page size applied: a script requesting 100 rows got the default, with no error and nothing in the output saying so.
  • A negative --offset silently restarted results from the beginning. Same omission: the param was dropped, so every page request returned page 1. A paging loop with a computed offset that dipped negative re-fetched duplicate rows forever instead of failing.
  • pipeline run task logs --tail -5 sent tail_lines=-5 to the live-log endpoint. The negative value was forwarded verbatim once the flag was set, producing a server-side failure mid-command — after authentication, deep past the point of feedback.
  • No parse-time gate for CI. Any of the above burned a full auth + network round trip before surfacing; now cobra rejects them during flag parsing.

Migrating onto internal/countflags (from part 1, #858) makes the fix mechanical rather than per-command.

CHANGES

  • --limit -> countflags.PositiveInt on dr pipeline list (default 50) and version/run/image/input/schedule list (default 100).
  • --offset -> countflags.NonNegativeInt (default 0) on all six list commands.
  • --tail on dr pipeline run task logs -> NonNegativeInt, keeping 0 as "no limit".
  • New invalid-limit/invalid-offset reject tests per list command and an invalid---tail test, in the existing runCmd style.

TESTING

task lint (all GOOS legs) and task test (race + coverage) pass.

NOTES

Part 2/4 of a stacked review. Based on #858 (base = its branch), so this diff shows only the pipeline changes. Invalid values now error at parse time instead of reaching the API. (Result truncation for large limits is a separate fix, part 4 #861.)


Note

Low Risk
CLI-only flag validation and tests; behavior is stricter for invalid pagination/tail values with no changes to auth or server contracts beyond not sending bad query params.

Overview
Pipeline list commands and run task logs now validate pagination and tail flags during Cobra parsing via internal/countflags, instead of plain IntVar flags that could reach the API with bad values.

--limit uses PositiveInt (rejects 0 and negatives) on pipeline list, and on image/input/run/schedule/version list commands with the same defaults as before. --offset uses NonNegativeInt on those list commands. pipeline run task logs --tail uses NonNegativeInt so negatives fail before auth/network; --tail 0 remains “no limit.”

Each touched command gains tests that invalid --limit, --offset, or --tail fail at parse time with the expected error messages.

Reviewed by Cursor Bugbot for commit 23c9407. Configure here.

@datarobot-pr-review-router

Copy link
Copy Markdown

🎫 Jira: CFX-7834 — Refactor --limit/--offset flags to custom pflag.Value (move validation to parsetime)

@ajalon1
ajalon1 force-pushed the aj/CFX-7834-countflags-pipelines branch from 335411f to 23c9407 Compare August 27, 2026 20:49
@github-actions github-actions Bot added the go Pull requests that update go code label Aug 27, 2026
@ajalon1
ajalon1 marked this pull request as ready for review August 27, 2026 21:15
@ajalon1
ajalon1 requested a review from a team as a code owner August 27, 2026 21:15
@ajalon1
ajalon1 requested a review from sunny2get August 28, 2026 22:55

@sunny2get sunny2get 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.

LGTM - thanks for covering this.

Migrates the pipeline family's count flags onto internal/countflags from
the base stack:

- --limit -> countflags.PositiveInt on pipeline list (default 50),
  version/run/image/input/schedule list (default 100)
- --offset -> countflags.NonNegativeInt on all six list commands
- --tail on pipeline run task logs -> countflags.NonNegativeInt, keeping
  0 as "no limit"

These commands previously did no validation at all, so --limit 0/-1 and
negative offsets went straight to the API; they are now rejected during
flag parsing with cobra's standard "invalid argument" message, before
any request is made.

Adds invalid-limit/invalid-offset reject tests per list command and an
invalid-tail test for task logs, in the existing runCmd style.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@ajalon1
ajalon1 force-pushed the aj/CFX-7834-countflags-pipelines branch from 23c9407 to 7d67898 Compare August 31, 2026 17:34
@ajalon1
ajalon1 merged commit 9b8a13b into main Aug 31, 2026
23 of 36 checks passed
@ajalon1
ajalon1 deleted the aj/CFX-7834-countflags-pipelines branch August 31, 2026 18:02
ajalon1 added a commit to ajalon1/derkeley that referenced this pull request Aug 31, 2026
Today's countflags migration (CFX-7834, datarobot-oss#858/datarobot-oss#859/datarobot-oss#860) is documented in
docs/development/flags.md but had no reviewer-facing rule — a new count-like
flag validated in RunE instead of at parse time would sail through review.
Adds the parse-time-validation rule plus its documented exception (0 as a
"use default" sentinel, per the workload config --port/--replicas precedent).
cdevent pushed a commit that referenced this pull request Sep 3, 2026
Migrates the pipeline family's count flags onto internal/countflags from
the base stack:

- --limit -> countflags.PositiveInt on pipeline list (default 50),
  version/run/image/input/schedule list (default 100)
- --offset -> countflags.NonNegativeInt on all six list commands
- --tail on pipeline run task logs -> countflags.NonNegativeInt, keeping
  0 as "no limit"

These commands previously did no validation at all, so --limit 0/-1 and
negative offsets went straight to the API; they are now rejected during
flag parsing with cobra's standard "invalid argument" message, before
any request is made.

Adds invalid-limit/invalid-offset reject tests per list command and an
invalid-tail test for task logs, in the existing runCmd style.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants