Skip to content

Refuse integers that cannot be sent exactly (#963) - #964

Draft
rawsun007 wants to merge 3 commits into
erwindon:masterfrom
rawsun007:fix/refuse-inexact-integers
Draft

Refuse integers that cannot be sent exactly (#963)#964
rawsun007 wants to merge 3 commits into
erwindon:masterfrom
rawsun007:fix/refuse-inexact-integers

Conversation

@rawsun007

Copy link
Copy Markdown

Fixes #963, taking the "raise an error" direction you asked for rather than the string coercion I had suggested — your command-line output settles it: salt keeps the value the user typed, so anything SaltGUI rounds is simply a different number, and there is nothing sensible to send.

The integer branch now refuses when the value is not exactly representable, matching the float branch immediately below it that already refuses a value it cannot represent:

12345678901234567   ->  error: Integer argument is too large to be sent exactly
9007199254740991    ->  9007199254740991      (largest exact integer, unchanged)
20180814033130818988 -> "20180814033130818988" (job-id, still a string via getPatJid)

The boundary is 2**53-1, so everything through 9007199254740991 is unaffected. Job-ids are matched as strings before the integer branch, so #41 keeps working.

One thing worth flagging about the tests. The three existing expectations for long integers were written as numeric literals:

assert.equal(args[0], 2018082000341133831);   // the literal is already ...800

The test file rounds that literal exactly as the parser did, so the assertion compared one rounded value against an identically rounded one and could never fail. They now compare against strings and assert the refusal, with the 2**53-1 boundary and a real job-id added on either side. That is why the diff touches assertions that look unrelated to the change.

npm run test:unit — 300 passing. Reverting only ParseCommandLine.js fails one of the new assertions. npm run eslint and npm run stylelint are clean.

AI disclosure per your policy: the code and this description were written by Claude Code (Claude Opus 5) working through my account, recorded in the commit's ai-assisted-by: trailer. I have not reviewed the diff line by line myself yet — say the word if you would rather I did that before you spend time on it.

An integer above 2**53-1 was accepted and rounded on the way to salt, so
`12345678901234567` arrived as `...68`. The command-line keeps the value the
user typed, as you showed on the issue, so the number SaltGUI sends was simply
a different one.

The integer branch now returns an error, matching the float branch beside it
that already refuses a value it cannot represent. Job-ids are unaffected:
getPatJid() matches them as strings before this point.

The three existing expectations for long integers compared against numeric
literals, which the test file rounded identically, so they could not tell a
correct value from a wrong one. They now compare against strings and assert
the refusal, with the 2**53-1 boundary and a real job-id added either side.

ai-assisted-by: Claude Code (Claude Opus 5)
Signed-off-by: Roshan Ramani <roshanramani.dev@gmail.com>
SonarQube flagged 39% duplication on new code: the added cases repeated the
same four-line setup-and-assert block six times. Two loops over a list of
values cover the same inputs in half the lines, and name the value in each
assertion message so a failure still says which one broke.

No change to what is asserted.

ai-assisted-by: Claude Code (Claude Opus 5)
Signed-off-by: Roshan Ramani <roshanramani.dev@gmail.com>
SonarQube read `assert.equal(String(args[0]), nr, nr)` as a likely copy-paste
slip, which is fair: the same variable served as both the expected value and
the failure message. Each loop now builds a label once and uses it for the
messages, leaving the value argument on its own.
@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

@erwindon erwindon self-assigned this Sep 7, 2026
@erwindon
erwindon marked this pull request as draft September 7, 2026 10:37
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.

Long integers other than job-ids are still silently rounded (residue of #40)

2 participants