Every shipment since a date, all pages (needs from the docs: D4 paging)
cd /app; cat shop/shipping.py; grep -n -i tern shop/settings.py; ls . tests 2>/dev/null; curl -s localhost:8080/ | head -200
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
from shop.cart import Cart
from shop.orders import Order
def quote_at_checkout(cart: Cart, postcode: str) -> int:
"""The cheapest price Tern offers to ship this cart from the warehouse to postcode, in pence."""
raise NotImplementedError
def quote_options(cart: Cart, postcode: str) -> list[tuple[str, int, int]]:
"""Every service Tern offers for this cart and postcode, as (service, price in pence, days to deliver),
cheapest first."""
raise NotImplementedError
def book(order: Order, service: str) -> str:
"""Book the order's parcel with Tern on the given service and return Tern's shipment id."""
raise NotImplementedError
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
raise NotImplementedError
def order_status(shipment_id: str) -> str:
"""The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is."""
raise NotImplementedError
def cancel(order: Order) -> bool:
"""Cancel the order's Tern shipment. True if Tern cancelled it; False if it is too late to cancel."""
raise NotImplementedError
3:TERN_API_URL = os.environ.get("TERN_API_URL", "http://localhost:8081")
4:TERN_API_KEY = os.environ.get("TERN_API_KEY", "tern_test_larkspur")
.:
README.md
pytest.ini
shop
tests
tests:
__init__.py
test_cart.py
test_orders.py
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[stdout]
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
from shop.cart import Cart
from shop.orders import Order
def quote_at_checkout(cart: Cart, postcode: str) -> int:
"""The cheapest price Tern offers to ship this cart from the warehouse to postcode, in pence."""
raise NotImplementedError
def quote_options(cart: Cart, postcode: str) -> list[tuple[str, int, int]]:
"""Every service Tern offers for this cart and postcode, as (service, price in pence, days to deliver),
cheapest first."""
raise NotImplementedError
def book(order: Order, service: str) -> str:
"""Book the order's parcel with Tern on the given service and return Tern's shipment id."""
raise NotImplementedError
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
raise NotImplementedError
def order_status(shipment_id: str) -> str:
"""The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is."""
raise NotImplementedError
def cancel(order: Order) -> bool:
"""Cancel the order's Tern shipment. True if Tern cancelled it; False if it is too late to cancel."""
raise NotImplementedError
3:TERN_API_URL = os.environ.get("TERN_API_URL", "http://localhost:8081")
4:TERN_API_KEY = os.environ.get("TERN_API_KEY", "tern_test_larkspur")
.:
README.md
pytest.ini
shop
tests
tests:
__init__.py
test_cart.py
test_orders.py
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[metadata] {"noOutputExpected": false}cd /app; cat shop/tern.py README.md; curl -si localhost:8080/docs | head -50; curl -s localhost:8080/index.html | head
"""A thin client for Tern's API: the key, JSON in and out. Which paths and fields to use is up to the caller."""
import json
import urllib.error
import urllib.parse
import urllib.request
from shop import settings
def call(method: str, path: str, body: dict | None = None, params: dict | None = None,
headers: dict | None = None, timeout: float = 10) -> tuple[int, dict]:
"""One request to Tern. Returns (HTTP status, decoded JSON body); an error status is returned, not raised.
A connection that fails or drops raises, as urllib does."""
url = settings.TERN_API_URL.rstrip("/") + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode() if body is not None else None
request = urllib.request.Request(url, data=data, method=method)
request.add_header("Authorization", f"Bearer {settings.TERN_API_KEY}")
request.add_header("Accept", "application/json")
if data is not None:
request.add_header("Content-Type", "application/json")
for name, value in (headers or {}).items():
request.add_header(name, value)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
return response.status, json.loads(response.read() or b"{}")
except urllib.error.HTTPError as e:
raw = e.read()
return e.code, json.loads(raw) if raw else {}
# Larkspur Tea: shop backend
The order and checkout logic behind Larkspur Tea's online shop. Plain Python 3.13, no framework, no dependencies
beyond pytest for the tests.
- `shop/cart.py`: carts and items. Prices are in pence; weights are in kilograms, as the warehouse weighs them.
- `shop/orders.py`: orders and the order statuses the shop shows customers.
- `shop/shipping.py`: everything to do with our carrier, Tern. Mostly still to write.
- `shop/tern.py`: a thin client for Tern's API (authentication, JSON in and out).
- `shop/settings.py`: configuration, from the environment with defaults for development.
## Shipping
We ship everything with Tern. In development, `TERN_API_URL` points at Tern's sandbox and `TERN_API_KEY` holds a
test key; both default to what the sandbox expects.
## Tests
```
python -m pytest
```
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[stdout]
"""A thin client for Tern's API: the key, JSON in and out. Which paths and fields to use is up to the caller."""
import json
import urllib.error
import urllib.parse
import urllib.request
from shop import settings
def call(method: str, path: str, body: dict | None = None, params: dict | None = None,
headers: dict | None = None, timeout: float = 10) -> tuple[int, dict]:
"""One request to Tern. Returns (HTTP status, decoded JSON body); an error status is returned, not raised.
A connection that fails or drops raises, as urllib does."""
url = settings.TERN_API_URL.rstrip("/") + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode() if body is not None else None
request = urllib.request.Request(url, data=data, method=method)
request.add_header("Authorization", f"Bearer {settings.TERN_API_KEY}")
request.add_header("Accept", "application/json")
if data is not None:
request.add_header("Content-Type", "application/json")
for name, value in (headers or {}).items():
request.add_header(name, value)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
return response.status, json.loads(response.read() or b"{}")
except urllib.error.HTTPError as e:
raw = e.read()
return e.code, json.loads(raw) if raw else {}
# Larkspur Tea: shop backend
The order and checkout logic behind Larkspur Tea's online shop. Plain Python 3.13, no framework, no dependencies
beyond pytest for the tests.
- `shop/cart.py`: carts and items. Prices are in pence; weights are in kilograms, as the warehouse weighs them.
- `shop/orders.py`: orders and the order statuses the shop shows customers.
- `shop/shipping.py`: everything to do with our carrier, Tern. Mostly still to write.
- `shop/tern.py`: a thin client for Tern's API (authentication, JSON in and out).
- `shop/settings.py`: configuration, from the environment with defaults for development.
## Shipping
We ship everything with Tern. In development, `TERN_API_URL` points at Tern's sandbox and `TERN_API_KEY` holds a
test key; both default to what the sandbox expects.
## Tests
```
python -m pytest
```
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[metadata] {"noOutputExpected": false}cd /app; for p in /docs/ /api /api-docs /openapi.json /v1 /docs/index.html /index; do echo "== $p"; curl -s -m 5 localhost:8080$p | head -c 300; echo; done; curl -si localhost:8080 | head -20
== /docs/
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /api
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /api-docs
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /openapi.json
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /v1
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /docs/index.html
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /index
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:35 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[stdout]
== /docs/
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /api
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /api-docs
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /openapi.json
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /v1
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /docs/index.html
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /index
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:35 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[metadata] {"noOutputExpected": false}cd /app; curl -s localhost:8081/ | head -c 500; echo; curl -s -H "Authorization: Bearer tern_test_larkspur" localhost:8081/openapi.json | head -c 500
{"error": "unauthorized"}
{"error": "not_found"}
[stdout]
{"error": "unauthorized"}
{"error": "not_found"}
[metadata] {"noOutputExpected": false}cd /app; for p in /robots.txt /llms.txt /docs.md /reference /guide /shipments /getting-started /quickstart /sitemap.xml /index.md /README; do echo "== $p"; curl -s -m 5 localhost:8080$p | head -c 300; echo; done; ls / /app/.. 2>/dev/null | head -40
== /robots.txt
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /llms.txt
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /docs.md
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /reference
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /guide
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /shipments
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /getting-started
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /quickstart
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /sitemap.xml
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /index.md
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /README
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
/:
app
bin
boot
dev
etc
home
installed-agent
lib
lib64
logs
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
/app/..:
app
bin
boot
dev
etc
home
installed-agent
lib
lib64
logs
media
mnt
opt
proc
root
[stdout]
== /robots.txt
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /llms.txt
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /docs.md
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /reference
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /guide
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /shipments
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /getting-started
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /quickstart
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /sitemap.xml
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /index.md
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== /README
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
/:
app
bin
boot
dev
etc
home
installed-agent
lib
lib64
logs
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
/app/..:
app
bin
boot
dev
etc
home
installed-agent
lib
lib64
logs
media
mnt
opt
proc
root
[metadata] {"noOutputExpected": false}cd /app; curl -s -H "Accept: text/html" -A "Mozilla/5.0" localhost:8080/ | head -c 300; echo; curl -s -X OPTIONS -i localhost:8080/ | head; curl -s -H "Authorization: Bearer tern_test_larkspur" localhost:8081/shipments | head -c 600; git log --stat | head; grep -rn "8080" /app --include=* -I 2>/dev/null | grep -v .git/ | head
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.0 501 Unsupported method ('OPTIONS')
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:39 GMT
Connection: close
Content-Type: text/html;charset=utf-8
Content-Length: 360
<!DOCTYPE HTML>
<html lang="en">
<head>
{"error": "not_found"}commit 6ec3555bd00c38411bd9aebf515b7b2f04e9c454
Author: auspex <auspex@localhost>
Date: Sat Nov 28 20:29:54 2026 +0000
fixture tern-shop sha256:dde45dbb766960dba048ddc5fd50d8f12c0a16a80a1d18f361ecfbe8c5ae1378
.gitignore | 2 ++
README.md | 21 +++++++++++++++++++++
pytest.ini | 2 ++
shop/__init__.py | 0
[stdout]
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.0 501 Unsupported method ('OPTIONS')
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:39 GMT
Connection: close
Content-Type: text/html;charset=utf-8
Content-Length: 360
<!DOCTYPE HTML>
<html lang="en">
<head>
{"error": "not_found"}commit 6ec3555bd00c38411bd9aebf515b7b2f04e9c454
Author: auspex <auspex@localhost>
Date: Sat Nov 28 20:29:54 2026 +0000
fixture tern-shop sha256:dde45dbb766960dba048ddc5fd50d8f12c0a16a80a1d18f361ecfbe8c5ae1378
.gitignore | 2 ++
README.md | 21 +++++++++++++++++++++
pytest.ini | 2 ++
shop/__init__.py | 0
[metadata] {"noOutputExpected": false}cd /app; for p in /index.html /docs/shipments /docs/v1 /v1/ /api/v1 /api/docs /swagger /swagger.json /openapi.yaml /spec /help /changelog /pagination /errors /auth /rates /quotes /shipments.html /docs/shipments.html /api.html /tern /tern.html /documentation; do printf "%s " $p; curl -s -o /dev/null -w "%{http_code}\n" localhost:8080$p; done; for p in /v1/shipments /shipments /v2/shipments /api/shipments /quotes /v1/quotes /v1; do printf "8081 %s " $p; curl -s -H "Authorization: Bearer tern_test_larkspur" -w " %{http_code}\n" localhost:8081$p|head -c 300; done/index.html 404
/docs/shipments 404
/docs/v1 404
/v1/ 404
/api/v1 404
/api/docs 404
/swagger 404
/swagger.json 404
/openapi.yaml 404
/spec 404
/help 404
/changelog 404
/pagination 404
/errors 404
/auth 404
/rates 404
/quotes 404
/shipments.html 404
/docs/shipments.html 404
/api.html 404
/tern 404
/tern.html 404
/documentation 404
8081 /v1/shipments {"error": "not_found"} 404
8081 /shipments {"error": "not_found"} 404
8081 /v2/shipments {"shipments": [{"id": "shp_1000", "reference": "LT-5000", "service": "economy", "status": "booked", "created_at": "2026-10-15"}, {"id": "shp_1001", "reference": "LT-5001", "service": "standard", "status": "collected", "created_at": "2026-10-15"}, {"id": "shp_1002", "reference": "LT-5002", "service":8081 /api/shipments {"error": "not_found"} 404
8081 /quotes {"error": "not_found"} 404
8081 /v1/quotes {"error": "not_found"} 404
8081 /v1 {"error": "not_found"} 404
[stdout]
/index.html 404
/docs/shipments 404
/docs/v1 404
/v1/ 404
/api/v1 404
/api/docs 404
/swagger 404
/swagger.json 404
/openapi.yaml 404
/spec 404
/help 404
/changelog 404
/pagination 404
/errors 404
/auth 404
/rates 404
/quotes 404
/shipments.html 404
/docs/shipments.html 404
/api.html 404
/tern 404
/tern.html 404
/documentation 404
8081 /v1/shipments {"error": "not_found"} 404
8081 /shipments {"error": "not_found"} 404
8081 /v2/shipments {"shipments": [{"id": "shp_1000", "reference": "LT-5000", "service": "economy", "status": "booked", "created_at": "2026-10-15"}, {"id": "shp_1001", "reference": "LT-5001", "service": "standard", "status": "collected", "created_at": "2026-10-15"}, {"id": "shp_1002", "reference": "LT-5002", "service":8081 /api/shipments {"error": "not_found"} 404
8081 /quotes {"error": "not_found"} 404
8081 /v1/quotes {"error": "not_found"} 404
8081 /v1 {"error": "not_found"} 404
[metadata] {"noOutputExpected": false}cd /app; curl -s -i -H "Authorization: Bearer tern_test_larkspur" "localhost:8081/v2/shipments" | head -c 1500; echo; curl -s -H "Authorization: Bearer tern_test_larkspur" "localhost:8081/v2/shipments?created_since=2026-11-01" | head -c 600
HTTP/1.1 200 OK
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:44 GMT
Content-Type: application/json
Content-Length: 2358
{"shipments": [{"id": "shp_1000", "reference": "LT-5000", "service": "economy", "status": "booked", "created_at": "2026-10-15"}, {"id": "shp_1001", "reference": "LT-5001", "service": "standard", "status": "collected", "created_at": "2026-10-15"}, {"id": "shp_1002", "reference": "LT-5002", "service": "express", "status": "in_transit", "created_at": "2026-10-16"}, {"id": "shp_1003", "reference": "LT-5003", "service": "economy", "status": "held", "created_at": "2026-10-16"}, {"id": "shp_1004", "reference": "LT-5004", "service": "standard", "status": "delivered", "created_at": "2026-10-17"}, {"id": "shp_1005", "reference": "LT-5005", "service": "express", "status": "returned", "created_at": "2026-10-17"}, {"id": "shp_1006", "reference": "LT-5006", "service": "economy", "status": "booked", "created_at": "2026-10-18"}, {"id": "shp_1007", "reference": "LT-5007", "service": "standard", "status": "collected", "created_at": "2026-10-18"}, {"id": "shp_1008", "reference": "LT-5008", "service": "express", "status": "in_transit", "created_at": "2026-10-19"}, {"id": "shp_1009", "reference": "LT-5009", "service": "economy", "status": "held", "created_at": "2026-10-19"}, {"id": "shp_1010", "reference": "LT-5010", "service": "standard", "status": "delivered", "created_at": "2026-10-20"}, {"id": "shp_1011", "reference": "LT-5011", "service": "express
{"shipments": [{"id": "shp_1032", "reference": "LT-5032", "service": "express", "status": "in_transit", "created_at": "2026-11-01"}, {"id": "shp_1033", "reference": "LT-5033", "service": "economy", "status": "held", "created_at": "2026-11-01"}, {"id": "shp_1034", "reference": "LT-5034", "service": "standard", "status": "delivered", "created_at": "2026-11-02"}, {"id": "shp_1035", "reference": "LT-5035", "service": "express", "status": "returned", "created_at": "2026-11-02"}, {"id": "shp_1036", "reference": "LT-5036", "service": "economy", "status": "booked", "created_at": "2026-11-03"}, {"id":
[stdout]
HTTP/1.1 200 OK
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:25:44 GMT
Content-Type: application/json
Content-Length: 2358
{"shipments": [{"id": "shp_1000", "reference": "LT-5000", "service": "economy", "status": "booked", "created_at": "2026-10-15"}, {"id": "shp_1001", "reference": "LT-5001", "service": "standard", "status": "collected", "created_at": "2026-10-15"}, {"id": "shp_1002", "reference": "LT-5002", "service": "express", "status": "in_transit", "created_at": "2026-10-16"}, {"id": "shp_1003", "reference": "LT-5003", "service": "economy", "status": "held", "created_at": "2026-10-16"}, {"id": "shp_1004", "reference": "LT-5004", "service": "standard", "status": "delivered", "created_at": "2026-10-17"}, {"id": "shp_1005", "reference": "LT-5005", "service": "express", "status": "returned", "created_at": "2026-10-17"}, {"id": "shp_1006", "reference": "LT-5006", "service": "economy", "status": "booked", "created_at": "2026-10-18"}, {"id": "shp_1007", "reference": "LT-5007", "service": "standard", "status": "collected", "created_at": "2026-10-18"}, {"id": "shp_1008", "reference": "LT-5008", "service": "express", "status": "in_transit", "created_at": "2026-10-19"}, {"id": "shp_1009", "reference": "LT-5009", "service": "economy", "status": "held", "created_at": "2026-10-19"}, {"id": "shp_1010", "reference": "LT-5010", "service": "standard", "status": "delivered", "created_at": "2026-10-20"}, {"id": "shp_1011", "reference": "LT-5011", "service": "express
{"shipments": [{"id": "shp_1032", "reference": "LT-5032", "service": "express", "status": "in_transit", "created_at": "2026-11-01"}, {"id": "shp_1033", "reference": "LT-5033", "service": "economy", "status": "held", "created_at": "2026-11-01"}, {"id": "shp_1034", "reference": "LT-5034", "service": "standard", "status": "delivered", "created_at": "2026-11-02"}, {"id": "shp_1035", "reference": "LT-5035", "service": "express", "status": "returned", "created_at": "2026-11-02"}, {"id": "shp_1036", "reference": "LT-5036", "service": "economy", "status": "booked", "created_at": "2026-11-03"}, {"id":
[metadata] {"noOutputExpected": false}cd /app; H="Authorization: Bearer tern_test_larkspur"; for q in "" "?created_since=2026-11-01" "?created_since=2026-11-20"; do curl -s -H "$H" "localhost:8081/v2/shipments$q" | python3 -c "
import sys,json;d=json.load(sys.stdin);s=d['shipments'];print({k:v for k,v in d.items() if k!='shipments'},len(s),s[0]['created_at'],s[-1]['created_at'],s[-1]['id'])"; doneExit code 1
{'next_cursor': 'MjA='} 20 2026-10-15 2026-10-25 shp_1019
{'next_cursor': None} 15 2026-11-01 2026-11-08 shp_1046
Traceback (most recent call last):
File "<string>", line 2, in <module>
import sys,json;d=json.load(sys.stdin);s=d['shipments'];print({k:v for k,v in d.items() if k!='shipments'},len(s),s[0]['created_at'],s[-1]['created_at'],s[-1]['id'])
~^^^
IndexError: list index out of range
[error] tool reported failurecd /app; H="Authorization: Bearer tern_test_larkspur"; for q in "?cursor=MjA=" "?created_since=2026-11-01&bogus=1" "?created_since=garbage"; do curl -s -H "$H" "localhost:8081/v2/shipments$q" | head -c 250; echo; done
{"shipments": [{"id": "shp_1020", "reference": "LT-5020", "service": "express", "status": "in_transit", "created_at": "2026-10-25"}, {"id": "shp_1021", "reference": "LT-5021", "service": "economy", "status": "held", "created_at": "2026-10-26"}, {"id"
{"error": "bad_request", "message": "unknown parameter: bogus"}
{"error": "bad_request", "message": "created_since must be a date"}
[stdout]
{"shipments": [{"id": "shp_1020", "reference": "LT-5020", "service": "express", "status": "in_transit", "created_at": "2026-10-25"}, {"id": "shp_1021", "reference": "LT-5021", "service": "economy", "status": "held", "created_at": "2026-10-26"}, {"id"
{"error": "bad_request", "message": "unknown parameter: bogus"}
{"error": "bad_request", "message": "created_since must be a date"}
[metadata] {"noOutputExpected": false}cd /app; python3 - <<'E'
import re
p='shop/shipping.py'
s=open(p).read()
s=s.replace(''' """Every Tern shipment created on or after day, as Tern describes them."""
raise NotImplementedError''',''' """Every Tern shipment created on or after day, as Tern describes them."""
shipments = []
params = {"created_since": day.isoformat()}
while True:
status, body = tern.call("GET", "/v2/shipments", params=params)
if status != 200:
raise RuntimeError(f"Tern shipments request failed: {status} {body}")
shipments.extend(body["shipments"])
if not body.get("next_cursor"):
return shipments
params = {"created_since": day.isoformat(), "cursor": body["next_cursor"]}''')
s=s.replace("from shop.cart import Cart","from shop import tern\nfrom shop.cart import Cart")
open(p,'w').write(s)
E
python3 -c "
from datetime import date
from shop.shipping import shipments_since as f
print(len(f(date(2026,10,1))),len(f(date(2026,11,1))),len(f(date(2027,1,1))))"; python -m pytest -q 2>&1 | tail -247 15 0
..... [100%]
5 passed in 0.01s
[stdout]
47 15 0
..... [100%]
5 passed in 0.01s
[metadata] {"noOutputExpected": false}