One source of truth for a business rule
Give a business rule one stored value, and make every place that states it a function of that value. On a Shopify storefront I work on, the free-delivery threshold had a CMS field for 936 days, while one product-page panel still printed a hard-coded £75 beside a £100 banner. A threshold that disagrees with itself costs money.
The client is anonymized. The dates, counts and code come from the repository’s history, read on 2026-11-20, and from a test run that day: 8 of 8 passing.
How one threshold ended up in six places
The number has three surfaces that shoppers read. A delivery banner on the product page. A collapsible “Delivery and returns” panel lower on the same page. A progress bar in the cart drawer that says how much more to spend.
The history is a slow migration that never finished:
- December 2023. The delivery copy is localized per region. Every number is a literal: £75 for the UK, $100 for the US, 100€ for the EU.
- 2024-01-11. A
deliveryPricefield goes into the CMS settings. The banner reads it. The panel does not. - 2025-05-23. The cart progress bar reads the field too. Two surfaces of three now agree with the CMS.
- 2026-01-08. A clean-up moves hard-coded strings into one i18n file. The panel’s literals move with it.
- 2026-08-04. The fix merges: the panel reads the field.
Just before the fix, the number lived in six places. One was the CMS field. Four
were string literals in the i18n file, which held the UK threshold twice: “FREE
standard delivery on UK orders over £75” and “£3 standard delivery on UK orders
under £75”. Two were fallbacks, deliveryPrice || 100, one in the banner and one
in the cart.
The test file added with the fix records what a shopper saw: the panel “shipped ‘£75’ beside a ‘£100’ announcement on the same page”.
Why a central strings file did not centralize the number
The January 2026 clean-up looked like the fix. After it, all the copy lived in one file, and anyone searching for the delivery text found it there. For 208 days the wrong threshold sat in the most central file in the codebase.
A strings file centralizes wording. It does not centralize facts. “Free delivery over £75” is a sentence with a business rule inside it, and moving the sentence moves the rule as a literal. The file answered “where is the copy?” correctly and “where is the threshold?” wrongly, and only the first question was being asked.
Make the copy a function of the value
The fix touched 3 files: 73 lines added, 11 removed. Five delivery strings became functions that take the threshold:
// Before
deliveryFreeOverUK: 'FREE standard delivery on UK orders over £75.',
deliveryStandardUK: '£3 standard delivery on UK orders under £75.',
// After
deliveryFreeOverUK: (price: number) =>
`FREE standard delivery on UK orders over £${price}.`,
deliveryStandardUK: (price: number) =>
`£3 standard delivery on UK orders under £${price}.`,
The panel then reads the same field, with the same fallback, as the banner and the cart:
// Same source and fallback as the announcement and the cart drawer:
// the CMS value is the threshold's source of truth.
const deliveryPrice = rootData?.settings?.globalValues?.deliveryPrice || 100;
The change of type was the useful part. A string can hold any number. A function
that takes price cannot be rendered without one, so TypeScript rejected any
caller that forgot to pass the value. The £3 and $6 delivery fees stayed
literals: they are a second rule, and nobody had asked to move them.
That guarantee lasted 107 days. On 2026-11-19 the five functions became plain
templates, '… over £{{price}}.', rendered with a small t() helper, because
every value in the strings table must now be a plain string that the store’s
translation records can hold. The rendered text did not change. The type check
did: t() takes any record of parameters, so a caller that leaves out price
compiles and renders “over £.” The failure is now visible on the page instead of
rejected by the compiler. It still cannot show a wrong number, which was the bug.
Test the interpolation with a second value
The new tests check every string with two thresholds, not one:
expect(en.deliveryFreeOverUK(100)).toBe(
'FREE standard delivery on UK orders over £100.',
);
expect(en.deliveryFreeOverUK(75)).toBe(
'FREE standard delivery on UK orders over £75.',
);
The second value was its own commit in the pull request. A test that checks only
100 passes against a function that ignores its argument and returns a literal
“£100”. With two values, a function that ignores its input fails one of them.
The same reasoning applies to any test of derived output: if the test’s input is
the same as the old constant, the test cannot tell derivation from a copy.
The fix did not stop the next copy
On 2026-08-19, 15 days after the fix merged, a release added an llms.txt
builder: a machine-readable summary of the store for AI crawlers. Its UK text
says “Free standard UK delivery on orders over £75”. It is a literal, and it is
the number the fix had just removed from the panel. It is still on master today.
I cannot say from the repository which number the store charges today. The CMS value is not in the code, and the shipping rates themselves live in Shopify’s admin. What the code does show is that one surface states a literal and three read a field, and nothing compares them.
That is the limit of converting copies. The fix found the copies that existed on 2026-08-04. A new surface written later had no reason to know the rule had a source, because no part of the build said so. Parameters protect the strings in the i18n file; a template literal in another file goes around them.
Copies are fine if something checks them
The fix also left three copies of the fallback || 100, one per surface. A later
feature for an Express delivery tier took the other route on purpose. Its field
has no numeric fallback, and a comment in the cart says why: “an unset Express
amount means the store has no Express tier”. A missing value hides the tier; it
does not make up a number.
This site has the same problem with colour. tokens.css defines every colour the
pages render, and three static files need literal copies of some of them: the
Open Graph image renderer, the SVG favicon and the ICO favicon. The copies are
allowed because check-a11y asserts the first two against tokens.css on every
build, and the ICO is regenerated from the SVG by hand. A copy that a check reads
is a cache. A copy that nothing reads is a second source of truth, and
the contrast defect shows how long one can stay
wrong unseen.
The storefront has the source and not yet the check. The rule I take from it: when a business rule has a number, store it once, make the copy a function of it, and add one test that fails when a literal of that number shows up somewhere new.
Revisions
- Created from the storefront repository's commits from 2023-12 to 2026-11, its master branch read that day, and a run of the threshold tests that day (8 of 8 passing), anonymized.
- Published on the Nov 20 slot, swapped with the soft-gated @umxr/justscroll row because that package is not yet on npm; auto-drafted by the publishing run because no draft existed for the row.