Skip to content

fix(json): preserve numeric lexemes when formatting - #977

Open
trac3r00 wants to merge 1 commit into
release/product-value-20260912-07from
release/product-value-20260912-08
Open

trac3r00 wants to merge 1 commit into
release/product-value-20260912-07from
release/product-value-20260912-08

Conversation

@trac3r00

@trac3r00 trac3r00 commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

fix(json): preserve numeric lexemes when formatting. This is logical change 8/11 in the dependency-ordered product-audit release stack.

Refs #969

What changed

  • fix(json): preserve numeric lexemes when formatting
  • Exact source commit: 6e568d42170e075d649947907358a623a0f87c8a; validated tree: 7be508496c9d4ea0a54aec5065ff6bdbb9d47f99.
  • Depends on the preceding release-stack PR. Retarget to main only after its dependency is merged and deployed.

Why

Prevent JSON formatting or minification from silently rounding large integers or rewriting numeric lexemes.

Verification

  • bun run build passed on this exact candidate tree.
  • npm test -- --maxWorkers=2 passed on this exact candidate tree.
  • Affected behavior manually exercised as described below.
  • Latest GitHub Build, Unit Tests (Vitest), and E2E Tests (Playwright) must all pass before merge.
Tests  774 passed (774)
CANDIDATE_BUILD_UNIT_GREEN
Committed tree equals validated tree: 7be508496c9d4ea0a54aec5065ff6bdbb9d47f99

Desktop/mobile Format and Minify preserve 9007199254740993; real clipboard output matches; malformed input clears stale output.

Final combined tree additionally passed 801 unit tests and all 293 Playwright tests with retries disabled, plus all 48 primary tool workflows at desktop and mobile. The exploratory Color Converter exact-HEX boundary remains a documented pre-existing defect; its runtime is unchanged by this stack.

Risk & rollback

  • Risk: Dependent commits require earlier stack changes; merge in order.
  • Rollback: revert this PR through a new PR; do not revert dependencies beneath already-merged dependents.
  • Release: require an approving review and latest-SHA CI. Respect the 15-minute soak between deploy-affecting merges and verify the production deployment before continuing.

Summary by cubic

Fixes JSON formatting and minification to preserve numeric lexemes (large integers, exponent/decimal spellings, negative zero) and escaped strings by reformatting only whitespace instead of re-serializing through JSON.parse/stringify.

  • Adds a new formatJsonLosslessly utility and uses it in both the JSON format contract and the formatter route.
  • Preserves numeric literals, -0, exponent forms, and escaped strings while still validating with the native JSON parser.
  • Adds unit and e2e tests covering desktop and mobile formatting, minify, and copy behavior.
  • Malformed input now clears stale output before showing the error.
  • This PR depends on the preceding release-stack PR and should be merged and deployed after it.

Written for commit 6e568d4. Summary will update on new commits.

Review in cubic

Share syntax-validated lexical whitespace formatting across the route and machine contract; preserve large integers, exponent/decimal spellings and negative zero.

Ultraworked with [omo](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Confidence score: 5/5

  • src/contracts/json-format.test.js duplicates the LOSSLESS_INPUT and LOSSLESS_PRETTY fixtures from src/utils/lossless-json.test.js, creating maintenance drift risk without indicating a functional regression; consolidate the coverage or clearly justify the separate contract boundary.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/contracts/json-format.test.js">

<violation number="1" location="src/contracts/json-format.test.js:21">
P3: These new contract tests duplicate the exact fixture and expected outputs already present in src/utils/lossless-json.test.js (LOSSLESS_INPUT, LOSSLESS_PRETTY). The escaped-string lexeme is subtle and error-prone, and maintaining two independent copies means a fix or coverage change in one fixture silently drifts from the other. Keep the contract-level tests (they do verify the transform wrapper), but share the fixture instead of copying it: export LOSSLESS_INPUT/LOSSLESS_PRETTY from lossless-json.test.js (or move them to a shared fixture module) and import them here.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

expect(result).toBe('{"a":1,"b":2}');
});

it("preserves every numeric and string lexeme while formatting", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: These new contract tests duplicate the exact fixture and expected outputs already present in src/utils/lossless-json.test.js (LOSSLESS_INPUT, LOSSLESS_PRETTY). The escaped-string lexeme is subtle and error-prone, and maintaining two independent copies means a fix or coverage change in one fixture silently drifts from the other. Keep the contract-level tests (they do verify the transform wrapper), but share the fixture instead of copying it: export LOSSLESS_INPUT/LOSSLESS_PRETTY from lossless-json.test.js (or move them to a shared fixture module) and import them here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/contracts/json-format.test.js, line 21:

<comment>These new contract tests duplicate the exact fixture and expected outputs already present in src/utils/lossless-json.test.js (LOSSLESS_INPUT, LOSSLESS_PRETTY). The escaped-string lexeme is subtle and error-prone, and maintaining two independent copies means a fix or coverage change in one fixture silently drifts from the other. Keep the contract-level tests (they do verify the transform wrapper), but share the fixture instead of copying it: export LOSSLESS_INPUT/LOSSLESS_PRETTY from lossless-json.test.js (or move them to a shared fixture module) and import them here.</comment>

<file context>
@@ -18,6 +18,40 @@ describe("json-format transform", () => {
     expect(result).toBe('{"a":1,"b":2}');
   });
 
+  it("preserves every numeric and string lexeme while formatting", () => {
+    const input =
+      '{"max":9007199254740993,"min":-9007199254740993,"huge":1e400,"fixed":1.2300,"negativeZero":-0,"nested":[[9007199254740993],{"text":"quote: \\" slash: \\\\"}]}';
</file context>

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.

1 participant