stage 4 of 6 · try of no-docs

sync-shipments

right

Every shipment since a date, all pages (needs from the docs: D4 paging)

Made
28 Nov 2026, 21:17 UTC
Model
claude-sonnet-5-5
Steps
11
Tool calls
10
Friction
7 flagged steps
Tokens read
270k
Time
27s
Cost
$0.077
Address
tern-docs/try/20261128-2029-dps9/sync-shipments
1quote-at-checkoutwrong2quote-optionswrong3book-shipmentwrong4sync-shipmentsright5order-statuswrong6cancel-before-pickupright
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..a1222df 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -3,6 +3,7 @@ from datetime import date
 
 from shop.cart import Cart
 from shop.orders import Order
+from shop import tern
 
 
 def quote_at_checkout(cart: Cart, postcode: str) -> int:
@@ -23,7 +24,19 @@ def book(order: Order, service: str) -> str:
 
 def shipments_since(day: date) -> list[dict]:
     """Every Tern shipment created on or after day, as Tern describes them."""
-    raise NotImplementedError
+    shipments = []
+    cursor = None
+    while True:
+        params = {"created_since": day.isoformat()}
+        if cursor:
+            params["cursor"] = cursor
+        status, body = tern.call("GET", "/v2/shipments", params=params)
+        if status != 200:
+            raise RuntimeError(f"Tern shipment list failed: {status} {body}")
+        shipments.extend(body["shipments"])
+        cursor = body.get("next_cursor")
+        if not cursor:
+            return shipments
 
 
 def order_status(shipment_id: str) -> str:
diff --git a/tests/test_shipping.py b/tests/test_shipping.py
new file mode 100644
index 0000000..cb6a0b3
--- /dev/null
+++ b/tests/test_shipping.py
@@ -0,0 +1,19 @@
+from datetime import date
+
+from shop import shipping, tern
+
+
+def test_shipments_since_follows_pages(monkeypatch):
+    pages = {None: ([{"id": "a", "created_at": "2026-10-20"}], "c1"),
+             "c1": ([{"id": "b", "created_at": "2026-10-21"}], None)}
+    seen = []
+
+    def fake_call(method, path, params=None, **kw):
+        seen.append(params)
+        items, nxt = pages[params.get("cursor")]
+        return 200, {"shipments": items, "next_cursor": nxt}
+
+    monkeypatch.setattr(tern, "call", fake_call)
+    result = shipping.shipments_since(date(2026, 10, 20))
+    assert [s["id"] for s in result] == ["a", "b"]
+    assert all(p["created_since"] == "2026-10-20" for p in seen)