Skip to content

fix(cli): flag, duration, and env-var parity with charon#519

Open
varex83agent wants to merge 2 commits into
mainfrom
bohdan/cli-flag-env-parity
Open

fix(cli): flag, duration, and env-var parity with charon#519
varex83agent wants to merge 2 commits into
mainfrom
bohdan/cli-flag-env-parity

Conversation

@varex83agent

Copy link
Copy Markdown
Collaborator

Summary

Three CLI parity fixes against charon v1.7.1 (improvement plan area 06 — CLI flag / duration / env-var parity):

1. Go-equivalent duration parsing (T01)

CLI duration flags were parsed with humantime, which diverges from Go's time.ParseDuration: it accepts 1d/1w/1y/1M (Go rejects them) and rejects a leading + (Go accepts it).

  • Adds parse_go_duration in crates/cli/src/duration.rs — a faithful port of Go's time.ParseDuration grammar (cmd/duration.go binds all charon duration flags through it): units ns/us/µs/μs/ms/s/m/h, multi-segment (1h30m), fractional (1.5h), leading +, the bare-"0" special case, and Go's 1<<63-1 ns overflow limit.
  • Documented deviation: a leading - is rejected (Go accepts negative durations) because std::time::Duration is unsigned and every flag using this parser is a non-negative timeout/delay. Noted in a // PARITY: comment.
  • Duration::FromStr keeps its bare-integer-nanoseconds branch (charon UnmarshalText strconv.ParseInt parity) and falls back to the new parser; the serde/JSON path is untouched.
  • All value_parser = humantime::parse_duration sites repointed: test/mod.rs, test/validator.rs, test/peers.rs (×3), and test/beacon.rs (missed by the plan); the three dkg.rs flags pick it up via FromStr.
  • humantime is dropped from the workspace (no remaining users).
  • ~35 table-driven success/error tests added.

2. test validator missing --quiet guard (T02)

pluto alpha test validator --quiet without --output-json silently ran and produced no output at all. Adds the must_output_to_file_on_quiet guard as the first statement of run(), matching charon cmd/testvalidator.go PreRunE and the sibling mev/peers/infra/beacon subcommands, plus a test asserting the error path.

3. Relay command env vars PLUTO_*CHARON_* (T03)

Charon binds every flag under the charon env prefix (cmd/cmd.go), so relay env vars are CHARON_HTTP_ADDRESS etc. The relay command was the only Pluto command using PLUTO_* (19 bindings). Renamed all 19 to CHARON_*; all 20 resulting env names in the file (incl. pre-existing CHARON_DATA_DIR) are unique, so no clap duplicate-env conflicts.

Out of scope (follow-ups per the plan): T04 alpha test all orchestration, T05 cosmetic help-text drifts.

Test plan

  • cargo +nightly fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace --all-features — 52 test binaries, 0 failures ✅
  • cargo deny check — fails on a pre-existing quick-xml advisory also present on main; unrelated (this PR's Cargo.lock diff only removes humantime)

🤖 Generated with Claude Code

varex83agent and others added 2 commits July 3, 2026 14:54
Three parity fixes against charon v1.7.1 (improvement plan area 06):

- Replace humantime with a hand-written Go time.ParseDuration-equivalent
  parser (parse_go_duration): accepts ns/us/µs/μs/ms/s/m/h units,
  multi-segment and fractional values, leading +, and the bare "0"
  special case; rejects d/w/y/M units and unitless values. Deviation:
  negative durations are rejected since std::time::Duration is unsigned.
  All CLI duration flags (dkg via Duration::FromStr; test
  beacon/validator/peers/mod via value_parser) now use it. The
  serde/UnmarshalText bare-integer-nanoseconds path is unchanged. The
  humantime dependency is dropped from the workspace.

- Add the missing must_output_to_file_on_quiet guard to test validator,
  matching charon cmd/testvalidator.go PreRunE and the sibling
  mev/peers/infra/beacon subcommands.

- Rename the 19 PLUTO_* env bindings on the relay command to CHARON_*,
  matching charon's env prefix (cmd/cmd.go) and the rest of the CLI.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
quick-xml 0.39.4 is flagged by RUSTSEC for unbounded namespace
allocation (fixed in >=0.41.0). Bump the workspace dependency and
dedupe the lockfile to a single quick-xml 0.41.0.

Co-authored-by: varex83 <ivan.uvarov02@gmail.com>
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.

2 participants