Skip to content

[code-reusability] Reuse positive integer helper - #340

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
code-reusability/copilot/code-reusability-positive-int-d9e5991dd2d58ebc
Oct 4, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
code-reusability/copilot/code-reusability-positive-int-d9e5991dd2d58ebc

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This [code-reusability] change reuses the existing common.positive_int helper at the benchmark parser's second equivalent call site.

  • Existing helper and callers: scripts/nvx_tools/common.py::positive_int is already used by the performance, microVM, adversarial, and CLI parsing code.
  • Second call site: scripts/nvx_tools/benchmark.py previously reimplemented the same int() conversion and positive-value check inline.
  • Behavior evidence: both implementations accepted the same integer inputs, propagated the same conversion errors, and rejected non-positive values; the shared helper now accepts a keyword-only message so benchmark retains its existing must be at least 1 diagnostic while all existing callers keep their default behavior. Benchmark's positive_int stays a named wrapper rather than a functools.partial, so argparse still reports a non-integer value as invalid positive_int value instead of the partial's repr.
  • Focused tests: PositiveIntTests.test_accepts_custom_error_message covers the shared helper's custom message, and CliTests.test_benchmark_positive_integer_diagnostics_are_stable parses benchmark --runs to check that non-integer and zero values keep their existing diagnostics.

The patch changes scripts/nvx_tools/common.py, scripts/nvx_tools/benchmark.py, and scripts/test_nvx_tools.py: 22 additions and 6 deletions (28 added-plus-deleted lines). It adds no dependency and makes no public API/CLI/ABI, gitlink, OpenVMM, workflow, or protected-file change.

Validation

Re-run on Windows with Python 3.14 after rebasing onto 073de2724 and addressing review feedback:

  • python -m unittest scripts.test_nvx_tools.CliTests.test_benchmark_positive_integer_diagnostics_are_stable scripts.test_nvx_tools.PositiveIntTests -v — passed (5 tests); the CLI test fails when benchmark.positive_int is a functools.partial
  • python -m unittest scripts/test_performance.py scripts/test_nvx_tools.py scripts/test_microvm_tests.py scripts/test_development_release.py scripts/test_egress_policy.py scripts/test_control_session.py scripts/test_managed_agent.py — passed (528 tests, 28 skipped)
  • python scripts/test_adversarial.py — passed (70 tests, 6 skipped)
  • python scripts/nvx.py benchmark --help — passed
  • python -m compileall -q scripts — passed
  • python -m ruff check scripts .github/specula — passed
  • python -m ruff format --check scripts .github/specula — passed
  • python -m pyright --pythonplatform Linux — passed
  • python -m pyright --pythonplatform Windows — passed
  • git diff --check — passed

Generated by code-reusability · copilot · gpt56 · 6.51 AIC · ⌖ 0.674 AIC · ⊞ 16.4K · ◷

  • expires on Oct 17, 2026, 4:59 PM UTC

Copilot AI balanced review requested due to automatic review settings October 3, 2026 16:59

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.

Copilot review overview

🟡 Changes recommended

The partial callable regresses malformed-integer CLI diagnostics by exposing an unstable implementation repr.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Reuses the shared positive-integer parser while retaining benchmark-specific validation text.

Changes:

  • Adds customizable error text to common.positive_int.
  • Replaces benchmark validation with a configured shared helper.
  • Tests custom validation messages.
File Description
scripts/​nvx_tools/​common.py Adds keyword-only custom error text.
scripts/​nvx_tools/​benchmark.py Reuses the shared helper.
scripts/​test_nvx_tools.py Tests custom error text.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/nvx_tools/benchmark.py Outdated
The benchmark parser kept its own positive_int(), which converted the
argument with int() and rejected values below 1. common.positive_int()
already does the same for the performance, microVM test, and
adversarial parsers, but rejects with "must be greater than zero",
while the benchmark options report "must be at least 1".

Give common.positive_int() a keyword-only message argument, whose
default keeps the existing message for those callers, and make the
benchmark positive_int() call it with "must be at least 1".

Keep the benchmark parser a named function rather than a
functools.partial. argparse names the type callable in its
"invalid <type> value" error, and a partial has no __name__, so a
non-integer value would be reported with the partial's repr, which
includes a process-specific function address, instead of as an
"invalid positive_int value".

Test the custom message of the shared parser, and parse
"benchmark --runs" through the NVX CLI parser to check that a
non-integer value and zero keep their existing diagnostics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna
Pedro Henrique Penna (ppenna) force-pushed the code-reusability/copilot/code-reusability-positive-int-d9e5991dd2d58ebc branch from a7a5070 to 7667f7a Compare October 4, 2026 18:03
Copilot AI balanced review requested due to automatic review settings October 4, 2026 18:03

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.

Copilot review overview

🟢 Approval recommended

The focused refactor preserves behavior and has adequate regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@ppenna
Pedro Henrique Penna (ppenna) merged commit acd6472 into dev Oct 4, 2026
28 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the code-reusability/copilot/code-reusability-positive-int-d9e5991dd2d58ebc branch October 4, 2026 18:56
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