Skip to content

fix(platform): send product stock as the number the form accepted - #4251

Merged
yannickmonney merged 1 commit into
mainfrom
fix/product-stock-exponent-parse
Oct 9, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/product-stock-exponent-parse

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What changed

A stock of 1e3 in a product passed the form as 1000 and was saved as 1 (#3616). The cause is two different parsers:

  • The form's rule (productNumberSchema) judges the string with Number.
  • Create and Save then sent it through parseInt (stock) and parseFloat (price).

A number input keeps an exponent as typed. In real Chromium 141, typing 1e3 leaves value === "1e3" (valueAsNumber 1000, valid). So the two readings disagreed: parseInt('1e3') is 1 and parseInt('2.5e2') is 2.

  • One reading. parseProductNumber (product-number-schema.ts) is now the only parse, for stock and price. The rule judges with it and both dialogs send it. A submit can no longer send a number other than the one the step or Save accepted.

  • The numeric meaning is accepted, not refused. The issue allows either. I accepted it because:

    • the native input calls 1e3 valid with value 1000;
    • the rule already reads exponents by value (1e20 is refused as too large, not as "not a number");
    • no new message or locale is needed.

    Review still shows the entry as typed (1e3), as it does for price.

  • Price behaviour is unchanged. Number and parseFloat agree on every value a number input can hold. They disagree only on 0x10, 0b1 and 0o7. A browser empties those; the rule passed them by value (16) while parseFloat sent 0. That gap closes too.

  • Manual layer. KNOW-B9 gains the exponent case and its readback: the row shows 1000, never 1. One reference/automation.md row names the specs, beside the products price row.

Decisions a reviewer may want to challenge

  1. The submits keep data.x ? parseProductNumber(data.x) : undefined. I chose that over a schema .transform() to numbers, which would make data.stock a number. fix(platform): clear the product fields an edit empties #4230 (open) rewrites the same edit submit as data.stock ? … : blank('stock'). With a number there, a stock of 0 would read as blank and be cleared. With this shape, a trial merge with fix(platform): clear the product fields an edit empties #4230's head 53738010e has one conflict hunk, in product-edit-dialog.tsx, and automation.md merges cleanly. The hunk covers four lines (stock, price, currency, category), because fix(platform): clear the product fields an edit empties #4230 also edits the two adjacent lines. The resolution is fix(platform): clear the product fields an edit empties #4230's four lines with parseProductNumber for stock and price, for example data.stock ? parseProductNumber(data.stock) : blank('stock').

On that composed tree, 4 files / 43 tests pass with one worker: both PRs' edit and wire suites (#4230's "every emptied optional field as null" included) and the create suite. The new tests assert only the stock and price keys, so #4230's other body changes do not touch them. The file names do not collide either.
2. Review shows 1e3, not 1000. It shows what the person typed, as it does for price. Showing the normalized number would be a separate UI change.

Out of scope

How I verified it

Exact head 394dcb947f53e8f55db511719ce2b2d448dbadab, base main bd2275c3f.

Failing tests first. The failing boundary is the args each dialog hands its mutation. The new cases enter the value through a change event, which leaves it the way a browser does. user.type cannot reproduce this bug: user-event turns a typed 1e3 into 1000 in a number input (its input events read "1", "", "1000").

case main bd2275c this branch
create: stock 1e3 → Review → Create FAIL: stock: 1 PASS: stock: 1000, Review shows 1e3
create: stock 2.5e2 FAIL: stock: 2 PASS: 250
edit: stock 1e3 → Save FAIL: stock: 1 PASS: 1000
edit: stock 2.5e2 → Save FAIL: stock: 2 PASS: 250
control: stock 1000 (create, edit) PASS PASS
control: price 12.5 and 1.25e1 → 12.5 (create, edit) PASS PASS

Real browser. I typed into <input type="number" min="0"> with Playwright's keyboard in Chromium 141 (headless shell):

typed value valueAsNumber
1e3 "1e3" 1000
2.5e2 "2.5e2" 250
1000 "1000" 1000

Request leg. product-number.wire.test.tsx runs the real write path with only fetch answered:

  • the real dialogs and useCreateProduct / useUpdateProduct;
  • useBackendMutation;
  • the products/mutations:* adapter rows;
  • backendFetch.

For 1e3, the body on POST /api/app/products and POST /api/app/products/prod-1 carries "stock": 1000, as it does for the control 1000.

Readback. The door and service are unchanged. With this fix, 1e3 sends the same stock as the control 1000, and the issue's own HTTP probe confirmed that the control reads back 1000. I ran no local stack, so there is no PostgreSQL readback from this branch. The manual box KNOW-B9 carries the row check.

Mutation check (each one reverted afterwards):

  • parseInt back at both dialog stock sites fails 6 tests: the four dialog exponent cases and both wire exponent cases. The controls stay green.
  • parseProductNumber reading like parseInt fails 8 tests across the schema and wire suites.

Suites on the exact head.

  • app/features/products (UI config, one worker): 18 files, 127 tests passed.
  • An earlier two-worker run on a shared host at load average ~18 timed out four existing tests at the 5 s and findBy limits. Two were in product-create-dialog.pending.test.tsx and two in product-edit-dialog.test.tsx. Both files then passed on their own (19/19), and the whole directory passed with one worker.
  • tests/guards/single-failure-toast and error-message-description (server project): 75 passed.

Gates on the changed files.

  • oxlint --type-aware: no diagnostics.
  • oxfmt --check: clean.
  • Scoped tsc --noEmit (TypeScript 6.0.2): exit 0. It covered the changed files plus app/router.tsx, lib/env.ts, tests/setup-ui.ts and the platform's .d.ts files.
  • bun run knip:check: exit 0.
  • bun run lint:manual: ok. check-guide.ts on suites/knowledge.md: OK.
  • The commit hooks' checks, run by hand because this worktree had no .husky/_: conflict markers clean, opengrep 0 findings, commitlint clean.

Not run here: the full platform suites, a whole-workspace tsc, browser and E2E projects, and backend:integration. CI runs those.

Closes #3616

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ACCEPT — independent review of PR #4251

Reviewed exact head 394dcb947f53e8f55db511719ce2b2d448dbadab against origin/main / base bd2275c3f8bc5f928349cc2a38f10134e666eb42, the TALE-161 contract and issue #3616. Reviewer: agent #9 b7c66e31, TALE-582, run 39985569; distinct from implementation agent #4 5f5307c9, run 72f61644. No blocking findings within this review's scope.

Observed evidence

  • parseProductNumber uses Number; validation and both create/edit submit sites call that same parser. Exponent stock is accepted by numeric meaning, explicitly permitted by the issue. String form values remain strings, so stock "0" stays truthy at submit and is not mistaken for an empty field.
  • Exact-head targeted jsdom run: 4 files / 48 tests passed, one worker. Both create and edit submit 1e3 as 1000 and 2.5e2 as 250. Ordinary 1000, price 12.5 and exponent price 1.25e1 controls pass. Review retains the entered spelling.
  • The wire suite reads JSON.parse(init.body) from the actual intercepted fetch call. The dialogs, product mutation hooks, useBackendMutation, product adapter rows and backendFetch are real; only the network response and unrelated upload/router/toast dependencies are stubbed. Both POST request bodies carry stock 1000 for 1e3 and the 1000 control. This is request serialization proof, not server persistence proof.
  • Main negative control: retained the head's dialog/wire regression tests and restored the three changed production source files from main. 6 tests failed / 32 passed: create/edit exponent mutation cases fail with 1 or 2, and both 1e3 wire cases fail with 1. Decimal stock and price controls stay green. Restored head sources afterward.
  • Independently composed #4230 at 53738010e50c357eeea71ab0933ac6c030f62978: exactly one conflict hunk, in product-edit-dialog.tsx around stock/price/currency/category. Resolution preserves #4230's blank(...) semantics and uses parseProductNumber for stock and price. All other hunks, including the automation register, apply cleanly. Composed targeted jsdom run: 5 files / 53 tests passed, including #4230's real-body clearing, absent-field and zero controls. This is an ephemeral local composition, not a pushed merge.
  • Manual documentation accurately distinguishes automated client/request proof from the remaining saved-row readback. No backend, schema, locale or visible control change in #4251.

Reproduction and artifacts

Run from services/platform, using /opt/node/bin on PATH and the existing installed Vitest:

../../node_modules/.bin/vitest run --config vitest.review.config.ts \
  app/features/products/components/product-create-dialog.test.tsx \
  app/features/products/components/product-edit-dialog.test.tsx \
  app/features/products/components/product-number.wire.test.tsx \
  app/features/products/utils/product-number-schema.test.ts \
  --maxWorkers 1 --reporter verbose

The review config imports the repository's unchanged vitest.ui.config.ts and only permits Vite filesystem access to /agent so reused dependency symlinks work in the isolated checkout. The main replay omits the parser test (main does not export the new helper); the composed run additionally includes product-edit-dialog.wire.test.tsx.

Artifacts in the TALE-582 delivery box: head-tests.log, main-regression.log, composition-apply.log, composed-tests.log, composed-edit.diff, pr4230.patch, plan.md and this report.

Unrun proof / handoff

No independent real-browser typing or visual check, full app/stack, HTTP server or PostgreSQL saved-row readback; no broad suite, lint/format/type-check rerun, E2E or CI execution. The unchanged backend accepts the same numeric request value as the established 1000 control, but that is not a claim of independently observed persistence. The manual KNOW-B9 saved-row check remains unrun. No CI wait, rerun or cancellation; no push, merge or card move. Final merge readiness and any additional readback/CI proof remain with TALE-359.

This ACCEPT is an independent agent verdict, not a native task completion decision. It is recorded as a COMMENT review because the repository token uses the same GitHub principal as the author; it does not claim a separate GitHub approver identity or bypass branch protection.

The product form judged a stock or price with `Number`, then Create and
Save sent it through `parseInt` / `parseFloat`. A number input keeps an
exponent as typed, so stock `1e3` passed the Pricing step and Save as
1000 and went out as 1; `2.5e2` went out as 2.

`parseProductNumber` in `product-number-schema.ts` is now the one
reading of such a value, the one the rule judges and both dialogs send,
for stock and price. Price sends what it sent for every value a number
input can hold, and the `data.x ? … : undefined` shape of both submits
is unchanged. `KNOW-B9` gains the exponent case and its readback.

Closes #3616
@yannickmonney
yannickmonney force-pushed the fix/product-stock-exponent-parse branch from e3bdb6a to 4ff3ff2 Compare October 9, 2026 04:43
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 9, 2026
@yannickmonney
yannickmonney merged commit 86dfcb9 into main Oct 9, 2026
@yannickmonney
yannickmonney deleted the fix/product-stock-exponent-parse branch October 9, 2026 22:21
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.

Bug: Product stock 1e3 passes validation and is silently saved as 1

1 participant