# Reproduce the store credit comparison

Run only on a fresh, dedicated Spree 6.0.5 test store. This exercise creates customers and paid orders, issues account credits, and spends the three control credits. The test tender is Spree’s built-in offline Check method. The customer, order, payment and store-credit records use normal Spree APIs and PostgreSQL. The public evidence contains synthetic order and credit IDs. The store listens only on loopback.

## Prepare the test store once for all three tools

Use the [Spree starter](https://github.com/spree/spree-starter) and PostgreSQL. The tested image was `ghcr.io/spree/spree@sha256:ccb50f584a6623a480a7d4d078e8adc53d3e78fec883a4c12d174b1a3d763cb1` with Postgres 18. Bind the web port to 127.0.0.1:41696, give it a generated SECRET_KEY_BASE and DATABASE_URL, disable forced HTTPS for this loopback fixture, and run the starter database preparation. On the seeded shop, create the following resources via the built-in Rails runner. Keep the resulting three files in a private config directory, outside any web root.

```ruby
s = Spree::Store.first!
product = Spree::Product.create!(name: "Plane Works test voucher", store: s, track_inventory: false, status: "active")
variant = product.default_variant
variant.prices.create!(currency: "USD", amount: 50)
product.channels << s.channels.find_by!(name: "Online Store")
tender = s.payment_methods.create!(type: "Spree::PaymentMethod::Check", name: "Offline trial tender", active: true)
key = Spree::ApiKey.create!(name: "Store credit trial", store: s, key_type: "secret",
  scopes: %w[write_customers write_orders write_store_credits write_payments read_products])
File.umask(0077)
File.write("/tmp/variant", variant.prefixed_id)
File.write("/tmp/tender", tender.prefixed_id)
File.write("/tmp/tender-key", key.plaintext_token)
```

Copy the three files privately out of the test container. Use Node, Python 3.11 or later, a JDK on PATH, and Alloy 6.2.0. Set ALLOY_JAR to the full path of its distribution jar. Use SPREE_TEST_PORT only if you chose another loopback port. Unpack the comparison kit into one directory. From that directory run the following, using paths to your own private test configuration and a fresh result directory.

```sh
python3 spree_trial.py baseline ./trial ./private
cp trial/state.json trial/v1-frozen.json
python3 spree_trial.py issue ./trial ./private --edit spree-edit.json
# Restart only this test store's web process and wait for /up.
python3 spree_trial.py readback ./trial ./private
python3 spree_redeem.py ./private ./trial/state.json ./trial/redemptions.json
```

The baseline wires a full-order USD credit to return eligibility, exercises an actual issuance per tool, and places three more orders per tool before v2. The next input is an eligibility-only partial edit. The harness merges that edit into each retained edition. The three engines compute the downstream result. All three receive the same structured rule maps. Each paid order carries its edition fingerprint in Spree metadata. The common receiver reloads that fingerprint at refund time. Spree issues account credit through its customer store-credits endpoint with an order reference in the memo. Every eligible issuance is followed by a repeated refund request and a read of the count and balance. This was a serial retry test. After restart the runner reads all balances again, then redeems the separate wiring-control credits as the sole payment on three new purchases.

The published frozen manifest covers the engines, comparator dependencies, receiver and runner across phases. Timing starts with the fixture available. Each engine gets 30 seconds per invocation and Alloy is limited to a 512 MiB Java heap. The first stage includes compiling the existing Alloy driver. The baseline and new orders use the same store, SKU, USD currency, test tender and price probes. Human authoring, merchant deployment, natural-language understanding, fulfillment and the physical return of goods were outside this test. The tested credit is a native customer-ledger grant. The next purchase demonstrates it was spendable.

[Baseline freeze](./spree-v1-frozen.json) · [Issued edit](./spree-edit.json) · [Sale and account readback](./spree-orders.json) · [Redemptions](./spree-redemptions.json)
