# A new named rule in an existing shop

We froze both evaluators and their approved v4 editions, then randomly selected one card from the three requests in the [manifest and draw](named-results.json). One operator prepared the cards and translated the selected request into one common structured input. The same whole-cent amount domain, 30-second evaluator timeout and zero model calls applied to both. The input mentioned return eligibility and the named minimum. The credit rule and store mappings were inherited from v4.

The stock Python comparison refused the new name. Phaseline's existing syntax and comparison accepted it. Python reused its existing evaluator after [one change](python-named-rule.patch), six added lines and four removed. That repaired adapter is the starting point for the next comparison. Both arms used the [same new 12-line read-only lookup](named_quote.py) for the customer desk. The old order's answer was “not declared at purchase”. No new public shop interface was part of this test.

The [runner](named_order_trial.py) checks each returned balance, amount-only answer, approval retry and settled credit retry. A separate Rails process queried Spree's database for the 22 completed paid orders, their purchase-edition metadata and USD credit records, including the order memo and remaining amounts. Its [ledger read](named-ledger.json) agreed with both arms. Another name at $50.07 was a comparison-only control. No v6 edition was issued. The machine times in the receipts cover the automated store exercise in fixed tool order. They exclude human setup, authoring, troubleshooting and approval wait.

## Replay on a separate test store

First reproduce [the successive checkout run](checkout-trial.md) through v4. From an extracted capacity kit, use the same private store connection and catalog as that run. Point the following commands at its directory containing the two v4 SQLite books. The commands create a fresh copy, retain that store's own purchase-edition fingerprints, and replay the recorded card. No credentials belong in these files.

```sh
python3 - ./successive ./named-replay <<'PY'
from pathlib import Path
import hashlib, json, sqlite3, sys
from checkout_trial import SHOP
previous, out = map(Path, sys.argv[1:])
out.mkdir(exist_ok=False)
record=json.loads(Path("named-results.json").read_text())
manifest=record["freeze"]
for arm in ("Phaseline","Python"):
    with sqlite3.connect((previous/(arm+".sqlite")).resolve().as_uri()+"?mode=ro",uri=True) as src, sqlite3.connect(out/(arm+".sqlite")) as dest:
        src.backup(dest)
        manifest["heads"][arm]=dest.execute("SELECT sha FROM head WHERE shop=?",(SHOP,)).fetchone()[0]
frozen=json.dumps(manifest,indent=2).encode()
(out/"freeze.json").write_bytes(frozen)
draw=record["draw"]|{"freeze_sha256":hashlib.sha256(frozen).hexdigest()}
(out/"draw.json").write_text(json.dumps(draw))
(out/"frozen-results.json").write_text(json.dumps(record["frozen_results"]))
PY
mkdir ./named-replay/python-runtime
cp checkout_release.py spree-rules.py checkout_baselines.py ./named-replay/python-runtime/
(cd ./named-replay/python-runtime && patch -p1 < ../../python-named-rule.patch)
python3 named_order_trial.py ./named-replay ./private ./catalog.json
```

Run only on a disposable test store. The command places paid test orders and issues test credits. Replaying from the exact archived v4 books and store reproduces the original fingerprints. A separately provisioned store has different catalog IDs and edition hashes.
