# Reproduce an empty delivery-date bug

This authored synthetic packet keeps one safe request fixed: `GET /orders/order_demo_001`. A 200 response with `delivery_date: ""` breaks the original frontend formatter. The corrected client renders an unavailable estimate and retains the normal and error controls.

These files exercise a local consumer view model. The packet is not a Gostly import format, recording, upstream capture or replay receipt. No request is sent, no credentials are needed, and no package installation is required.

Save `order-bug-packet.json` and `check-order-view.mjs` in one directory. With a current Node.js release, run:

```sh
node check-order-view.mjs broken
node check-order-view.mjs fixed
```

Both commands read the same adjacent packet and compare the actual view or typed error with the same declared expectations. Each prints a compact actual/expected line per case. The broken variant is expected to exit 1; the corrected variant is expected to exit 0. Usage or packet-input errors exit 2.

An explicit packet path is optional:

```sh
node check-order-view.mjs fixed ./order-bug-packet.json
```

## The consumer contract

Both variants require HTTP 200, an object body, the requested order ID and a non-negative safe-integer `total_minor`. They return a view with `id`, `totalMinor` and `deliveryText`. Their only difference is delivery-date formatting.

The original formatter runs:

```js
new Date(body.delivery_date).toISOString().slice(0, 10)
```

An empty string throws. Null becomes an epoch date, and an impossible calendar date can normalize to a different day. The original client maps the native invalid-date exception to stable code `DELIVERY_FORMAT_ERROR`; the assertions do not depend on exception prose.

The corrected contract requires the `delivery_date` field. `""` or `null` renders `Delivery estimate unavailable`. Otherwise the value must be a real calendar date in exactly `YYYY-MM-DD` form, yielding `Delivery estimate: YYYY-MM-DD`. It rejects missing values, nonstrings, malformed strings and impossible dates with distinct codes. A UTC calendar roundtrip validates the day; display preserves the original date-only value without timezone conversion. Arbitrary timestamp strings are outside this contract.

The packet includes the empty-string trigger, null and normal controls, malformed and impossible dates, a missing date, a wrong order ID, an HTTP error and an invalid total. The clients apply their logic to each response independently of its case name; neither client reads expected results. Changing a response still subjects it to the same assertions.

## Reuse a small boundary

The ES module exports `originalOrderView`, `fixedOrderView`, `validateOrderResponse`, `formatDeliveryDate`, `captureOutcome`, `validatePacket`, `runPacket`, `loadPacket` and `OrderViewError`. Importing it does not run the CLI.

```js
import { fixedOrderView } from "./check-order-view.mjs";

const view = fixedOrderView({
  status: 200,
  body: { id: "order_demo_001", total_minor: 4200, delivery_date: "" }
}, "order_demo_001");
// { id: "order_demo_001", totalMinor: 4200,
//   deliveryText: "Delivery estimate unavailable" }
```

Adapt the contract to the affected application and keep a reviewed failing input with a normal control. This packet checks date formatting and selected response guards. It does not establish estimate freshness or truth, provider behavior, authentication, transport/replay behavior, DOM rendering or the whole application workflow.
