# A small reproducible transformation repair

**Original synthetic demonstration. This has NOT been executed in an n8n
runtime.** It is not a client case study, an imported n8n workflow, an external
API test or proof of a customer's production integration. The item envelopes
use the familiar `{ "json": ... }` shape; the executable proof is plain
JavaScript running locally on Node.js. It performs no external calls, uses no
credentials, and needs no paid service or package installation.

## Buyer-visible problem

An inventory transformation treats zero as missing and accepts malformed input.
Its `parseInt(value, 10) || null` converts `"0"` into null, silently converts
`"12pcs"` into 12 and truncates `"1.5"` to 1. That can hide out-of-stock values
or pass ambiguous supplier data to a later update step.

The patch validates the complete quantity before converting it. Zero stays
zero. Invalid values remain visible as review rows. It never drops a row or
invents a replacement quantity.

| Synthetic input | Original result | Corrected result |
|---|---|---|
| stock `"0"` | Missing/review | Zero/ready |
| stock `"12"` | 12/ready | 12/ready |
| stock `"12pcs"` | 12/ready | Null/review |
| stock `"1.5"` | 1/ready | Null/review |

## Agreed demonstration contract

- Input: an array of item envelopes containing `json.sku` and `json.stock`.
- SKU: a nonempty string after trimming. Case is preserved.
- Stock: a nonnegative safe integer, or a decimal-digit string representing
  one. Leading zeros and surrounding whitespace are allowed. Unit suffixes,
  empty values, booleans, exponent notation and fractions are rejected.
- Output: one item per input row, original order retained, with a one-based
  source row, normalized SKU and quantity, status and issue codes.
- Invalid rows are preserved for review, and invalid quantities become null.
  Downstream code must use only rows whose status is `ready`.
- Unknown input fields are intentionally omitted. This sample does not merge
  duplicate SKUs, import files, mutate inventory, execute supplied code or
  contact Shopify, n8n or another service.

The contract is an example, not a universal stock rule: some businesses allow
fractions or negative inventory. A real paid repair must use the customer's
agreed rules, n8n version and sanitized examples.

## Reproduce

From this repository with Node.js 22 or newer:

```sh
node --test hermes/revenue-demo/transform.test.mjs
node hermes/revenue-demo/demonstrate.mjs
```

The demonstration command asserts that the intentionally broken implementation
differs from the agreed fixture and that the patch matches every expected row.
It prints both outputs and an explicit runtime limitation. Tests include the
zero bug, malformed quantities, safe-integer bounds, malformed item shapes,
row preservation, non-mutation and deterministic replay.

Files: `input.json`, `expected.json`, `before.mjs` (intentionally wrong),
`transform.mjs` (patch), `transform.test.mjs`, and `demonstrate.mjs`.

## Honest delivery statement

“Here is an original synthetic transformation bug, its patch and reproducible
tests. The patch preserves zero and routes malformed quantities for review.
This was tested as JavaScript. It has not been run in your n8n instance or
against your live services.”

No payment, customer acceptance, runtime deployment or external outreach is
created by running this example. Do not describe it as end-to-end n8n execution.
