The order summary, three traps
builds on: Why agents fill gaps with plausible guesses
This one diff has three tells. First, `.length` and `slice(0, 40)` count UTF-16 code units, so an emoji that straddles position 40 becomes a lone surrogate, shown as �. Second, `price * qty` multiplies and sums binary floats. `toFixed(2)` hides the drift on screen, yet `(1.005).toFixed(2)` is `"1.00"`, not `"1.01"`. Third, `30 * 86_400_000` ms is exactly 720 hours, but across a DST change 30 local days are 719 or 721 hours. An order placed at 00:00 comes due at 01:00, or at 23:00 the day before. BETTER: truncate by graphemes with `Intl.Segmenter`, sum integer cents, and add 30 calendar days in a named zone with `Temporal.ZonedDateTime` or a zone-aware date library.
// TypeScript
--- a/src/orders/summary.ts
+++ b/src/orders/summary.ts
@@ -12,1 +12,8 @@ export function summarize(
- return { note, total: 0 };
+ const preview = note.length > 40
+ ? note.slice(0, 40) + "…" : note;
+ const total = items.reduce(
+ (s, i) => s + i.price * i.qty, 0);
+ const due = new Date(
+ created.getTime() + 30 * 86_400_000);
+ return { preview, due,
+ total: total.toFixed(2) };