← run 2026-07-02T101616Z-9f192f9-minimal

gemma-4-26b-a4b — py-refactor

rep 1 PASS

pi 16.7s · verify 0.6s · 33412 tok · responded: gemma-4-26b-a4b · transcript

verify output
.......                                                                  [100%]
7 passed in 0.01s
...                                                                      [100%]
3 passed in 0.01s
behaviour (gate): 7/7 preserved
structural (score): 3/3 refactor checks
score: 100%
produced code
.gitignore
__pycache__/
*.pyc
.pytest_cache/
shop/__init__.py

shop/cart.py
"""Shopping-cart totals."""

from shop.pricing import line_total


FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


def cart_total(items):
    """Grand total for a cart: discounted line items plus shipping.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    The per-line discount rules are identical to ``order_total``:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    Shipping (``SHIPPING_FEE``) is added unless the discounted subtotal reaches
    ``FREE_SHIPPING_THRESHOLD``.
    """
    subtotal = 0.0
    for item in items:
        subtotal += line_total(item["price"], item["qty"], item["category"])
    subtotal = round(subtotal, 2)
    if subtotal >= FREE_SHIPPING_THRESHOLD:
        return subtotal
    return round(subtotal + SHIPPING_FEE, 2)
shop/orders.py
"""Order totals."""


from shop.pricing import line_total


def order_total(items):
    """Total price for a list of order line items.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    The discounted line totals are summed and rounded to 2 decimals.
    """
    total = 0.0
    for item in items:
        total += line_total(item["price"], item["qty"], item["category"])
    return round(total, 2)
shop/pricing.py
"""Pricing helpers.

Provides a single source of truth for per-line discount calculation.
"""


def line_total(price, qty, category):
    """Returns the discounted total for one line (price * qty, with the discount applied).

    Discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    """
    line = price * qty
    if category == "clearance":
        line *= 0.75
    elif qty >= 10:
        line *= 0.90
    return line
tests_visible/test_shop.py
import os
import sys

# Make the package importable no matter what directory pytest is invoked from.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from shop.orders import order_total
from shop.cart import cart_total


def test_order_no_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 20.0


def test_order_bulk_discount():
    assert order_total([{"price": 10.0, "qty": 10, "category": "std"}]) == 90.0


def test_order_clearance_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "clearance"}]) == 15.0


def test_cart_adds_shipping_below_threshold():
    assert cart_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 24.99


def test_cart_free_shipping_at_threshold():
    assert cart_total([{"price": 10.0, "qty": 5, "category": "std"}]) == 50.0

rep 2 PASS

pi 15.9s · verify 0.6s · 31100 tok · responded: gemma-4-26b-a4b · transcript

verify output
.......                                                                  [100%]
7 passed in 0.01s
...                                                                      [100%]
3 passed in 0.01s
behaviour (gate): 7/7 preserved
structural (score): 3/3 refactor checks
score: 100%
produced code
.gitignore
__pycache__/
*.pyc
.pytest_cache/
shop/__init__.py

shop/cart.py
"""Shopping-cart totals."""

FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


from shop.pricing import line_total


FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


def cart_total(items):
    """Grand total for a cart: discounted line items plus shipping.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    The per-line discount rules are identical to ``order_total``:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    Shipping (``SHIPPING_FEE``) is added unless the discounted subtotal reaches
    ``FREE_SHIPPING_THRESHOLD``.
    """
    subtotal = 0.0
    for item in items:
        subtotal += line_total(item["price"], item["qty"], item["category"])
    subtotal = round(subtotal, 2)
    if subtotal >= FREE_SHIPPING_THRESHOLD:
        return subtotal
    return round(subtotal + SHIPPING_FEE, 2)
shop/orders.py
"""Order totals."""


from shop.pricing import line_total


def order_total(items):
    """Total price for a list of order line items.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    The discounted line totals are summed and rounded to 2 decimals.
    """
    total = 0.0
    for item in items:
        total += line_total(item["price"], item["qty"], item["category"])
    return round(total, 2)
shop/pricing.py
"""Pricing helpers."""


def line_total(price, qty, category):
    """Returns the discounted total for one line.

    Discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    """
    line = price * qty
    if category == "clearance":
        line *= 0.75
    elif qty >= 10:
        line *= 0.90
    return line
tests_visible/test_shop.py
import os
import sys

# Make the package importable no matter what directory pytest is invoked from.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from shop.orders import order_total
from shop.cart import cart_total


def test_order_no_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 20.0


def test_order_bulk_discount():
    assert order_total([{"price": 10.0, "qty": 10, "category": "std"}]) == 90.0


def test_order_clearance_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "clearance"}]) == 15.0


def test_cart_adds_shipping_below_threshold():
    assert cart_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 24.99


def test_cart_free_shipping_at_threshold():
    assert cart_total([{"price": 10.0, "qty": 5, "category": "std"}]) == 50.0

rep 3 PASS

pi 16.4s · verify 0.6s · 31214 tok · responded: gemma-4-26b-a4b · transcript

verify output
.......                                                                  [100%]
7 passed in 0.01s
...                                                                      [100%]
3 passed in 0.01s
behaviour (gate): 7/7 preserved
structural (score): 3/3 refactor checks
score: 100%
produced code
.gitignore
__pycache__/
*.pyc
.pytest_cache/
shop/__init__.py

shop/cart.py
"""Shopping-cart totals."""

from shop.pricing import line_total


FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


def cart_total(items):
    """Grand total for a cart: discounted line items plus shipping.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    The per-line discount rules are identical to ``order_total``:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    Shipping (``SHIPPING_FEE``) is added unless the discounted subtotal reaches
    ``FREE_SHIPPING_THRESHOLD``.
    """
    subtotal = 0.0
    for item in items:
        subtotal += line_total(item["price"], item["qty"], item["category"])
    subtotal = round(subtotal, 2)
    if subtotal >= FREE_SHIPPING_THRESHOLD:
        return subtotal
    return round(subtotal + SHIPPING_FEE, 2)
shop/orders.py
"""Order totals."""


from shop.pricing import line_total


def order_total(items):
    """Total price for a list of order line items.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    The discounted line totals are summed and rounded to 2 decimals.
    """
    total = 0.0
    for item in items:
        total += line_total(item["price"], item["qty"], item["category"])
    return round(total, 2)
shop/pricing.py
"""Pricing helpers.

The per-line discount calculation is centralized here.
"""


def line_total(price, qty, category):
    """Returns the discounted total for one line.

    Rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    """
    line = price * qty
    if category == "clearance":
        line *= 0.75
    elif qty >= 10:
        line *= 0.90
    return line
tests_visible/test_shop.py
import os
import sys

# Make the package importable no matter what directory pytest is invoked from.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from shop.orders import order_total
from shop.cart import cart_total


def test_order_no_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 20.0


def test_order_bulk_discount():
    assert order_total([{"price": 10.0, "qty": 10, "category": "std"}]) == 90.0


def test_order_clearance_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "clearance"}]) == 15.0


def test_cart_adds_shipping_below_threshold():
    assert cart_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 24.99


def test_cart_free_shipping_at_threshold():
    assert cart_total([{"price": 10.0, "qty": 5, "category": "std"}]) == 50.0

rep 4 PASS

pi 16.9s · verify 0.6s · 31374 tok · responded: gemma-4-26b-a4b · transcript

verify output
.......                                                                  [100%]
7 passed in 0.01s
...                                                                      [100%]
3 passed in 0.01s
behaviour (gate): 7/7 preserved
structural (score): 3/3 refactor checks
score: 100%
produced code
.gitignore
__pycache__/
*.pyc
.pytest_cache/
shop/__init__.py

shop/cart.py
"""Shopping-cart totals."""

FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


from shop.pricing import line_total


def cart_total(items):
    """Grand total for a cart: discounted line items plus shipping.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    The per-line discount rules are identical to ``order_total``:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    Shipping (``SHIPPING_FEE``) is added unless the discounted subtotal reaches
    ``FREE_SHIPPING_THRESHOLD``.
    """
    subtotal = 0.0
    for item in items:
        subtotal += line_total(item["price"], item["qty"], item["category"])
    subtotal = round(subtotal, 2)
    if subtotal >= FREE_SHIPPING_THRESHOLD:
        return subtotal
    return round(subtotal + SHIPPING_FEE, 2)
shop/orders.py
"""Order totals."""


from shop.pricing import line_total


def order_total(items):
    """Total price for a list of order line items.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    The discounted line totals are summed and rounded to 2 decimals.
    """
    total = 0.0
    for item in items:
        total += line_total(item["price"], item["qty"], item["category"])
    return round(total, 2)
shop/pricing.py
"""Pricing helpers.

TODO: the per-line discount calculation currently lives (duplicated) in ``orders.py`` and
``cart.py``. It should be extracted here as ``line_total(price, qty, category)``.
"""

def line_total(price, qty, category):
    """Returns the discounted total for one line.

    Rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    """
    line = price * qty
    if category == "clearance":
        line *= 0.75
    elif qty >= 10:
        line *= 0.90
    return line
tests_visible/test_shop.py
import os
import sys

# Make the package importable no matter what directory pytest is invoked from.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from shop.orders import order_total
from shop.cart import cart_total


def test_order_no_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 20.0


def test_order_bulk_discount():
    assert order_total([{"price": 10.0, "qty": 10, "category": "std"}]) == 90.0


def test_order_clearance_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "clearance"}]) == 15.0


def test_cart_adds_shipping_below_threshold():
    assert cart_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 24.99


def test_cart_free_shipping_at_threshold():
    assert cart_total([{"price": 10.0, "qty": 5, "category": "std"}]) == 50.0

rep 5 PASS

pi 16.2s · verify 0.6s · 31415 tok · responded: gemma-4-26b-a4b · transcript

verify output
.......                                                                  [100%]
7 passed in 0.01s
...                                                                      [100%]
3 passed in 0.01s
behaviour (gate): 7/7 preserved
structural (score): 3/3 refactor checks
score: 100%
produced code
.gitignore
__pycache__/
*.pyc
.pytest_cache/
shop/__init__.py

shop/cart.py
"""Shopping-cart totals."""

from shop.pricing import line_total


FREE_SHIPPING_THRESHOLD = 50.0
SHIPPING_FEE = 4.99


def cart_total(items):
    """Grand total for a cart: discounted line items plus shipping.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    The per-line discount rules are identical to ``order_total``:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    Shipping (``SHIPPING_FEE``) is added unless the discounted subtotal reaches
    ``FREE_SHIPPING_THRESHOLD``.
    """
    subtotal = 0.0
    for item in items:
        subtotal += line_total(item["price"], item["qty"], item["category"])
    subtotal = round(subtotal, 2)
    if subtotal >= FREE_SHIPPING_THRESHOLD:
        return subtotal
    return round(subtotal + SHIPPING_FEE, 2)
shop/orders.py
"""Order totals."""


from shop.pricing import line_total


def order_total(items):
    """Total price for a list of order line items.

    Each ``item`` is a dict with keys ``price`` (float), ``qty`` (int) and ``category`` (str).
    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    The discounted line totals are summed and rounded to 2 decimals.
    """
    total = 0.0
    for item in items:
        total += line_total(item["price"], item["qty"], item["category"])
    return round(total, 2)
shop/pricing.py
"""Pricing helpers.

TODO: the per-line discount calculation currently lives (duplicated) in ``orders.py`` and
``cart.py``. It should be extracted here as ``line_total(price, qty, category)``.
"""


def line_total(price, qty, category):
    """Returns the discounted total for one line (price * qty, with the discount applied).

    Per-line discount rules:
      * ``clearance`` category: 25% off
      * otherwise, quantity 10 or more: 10% off (bulk)
      * otherwise: no discount
    """
    line = price * qty
    if category == "clearance":
        line *= 0.75
    elif qty >= 10:
        line *= 0.90
    return line
tests_visible/test_shop.py
import os
import sys

# Make the package importable no matter what directory pytest is invoked from.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from shop.orders import order_total
from shop.cart import cart_total


def test_order_no_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 20.0


def test_order_bulk_discount():
    assert order_total([{"price": 10.0, "qty": 10, "category": "std"}]) == 90.0


def test_order_clearance_discount():
    assert order_total([{"price": 10.0, "qty": 2, "category": "clearance"}]) == 15.0


def test_cart_adds_shipping_below_threshold():
    assert cart_total([{"price": 10.0, "qty": 2, "category": "std"}]) == 24.99


def test_cart_free_shipping_at_threshold():
    assert cart_total([{"price": 10.0, "qty": 5, "category": "std"}]) == 50.0