sample-service — Repo X-ray

Architecture and health snapshot · scope: data/sample-service/ · generated 2026-09-07

Modules

app/main.py

Order lookup service

One file, one FastAPI app. Owns the in-memory order store, the total calculation, and both HTTP routes.

  • ORDERS — 3 hardcoded orders across 2 accounts (Account A ×2, Account B ×1, one with no line items)
  • order_total() — sums a single order's lines
  • 2 route handlers, no auth, no persistence layer
tests/test_orders.py

Test suite

5 tests: 3 hit the HTTP layer via TestClient, 2 call order_total() directly.

  • Order fetch: found + not-found
  • Total math: two-line order + empty order
  • Account rollup: order count only, not the total value

Endpoints

MethodPathInputOutput
GET /orders/{order_id} path param order_id (string) order object + computed total, or 404
GET /accounts/{account}/total path param account (exact string match) {account, orders, total}, or 404

Test run

4 passed
1 failed
pytest -q, 5 collected
TestResultNotes
test_get_order_okpass200, correct id
test_get_order_missingpass404 as expected
test_total_two_linesfailexpected 1650.0, got 1256.0 — this is the planted bug
test_empty_order_total_is_zeropasspasses regardless of the bug — an empty line list makes the broken formula irrelevant
test_account_totalpassonly checks order count (2), never checks the total value, so it doesn't catch the bug either

Top 3 risks

1. Order totals are wrong — addition instead of multiplication

app/main.py:17

This is the planted bug. order_total() does qty + unit where it should do qty × unit. Every order with line items gets the wrong total, and every account rollup inherits the error. On the real data, Account A's total is 2458.0 instead of the correct 4050.0 — off by 40%. Caught by test_total_two_lines; missed by the other two total-related tests because one uses an empty order and the other never checks the number.

2. Malformed order data crashes with a raw 500

app/main.py:16–18

Line items are read with bare line["qty"] / line["unit"] lookups against a plain dict — there's no Pydantic model, despite Pydantic already being a FastAPI dependency. Verified directly: a line missing "unit" raises an unhandled KeyError, which FastAPI turns into a bare 500 Internal Server Error instead of a controlled 4xx with a useful message.

3. No auth on either endpoint

app/main.py:21–34

Both routes hand back full order line items and account revenue totals to any caller — no API key, no auth dependency, no rate limiting. Fine for a lab sample; a real risk the moment this fronts anything with actual customer data.

Proposed fix — risk #1

--- a/app/main.py
+++ b/app/main.py
@@ order_total() @@
     for line in order["lines"]:
-        total += line["qty"] + line["unit"]
+        total += line["qty"] * line["unit"]
     return round(total, 2)

See the bug, live

Showing: currently shipped formula (qty + unit)
OrderAccountLinesTotal (shipped)

Numbers come straight from the ORDERS dict in app/main.py — nothing invented. Toggling recomputes with qty × unit instead of qty + unit.

Check by hand before trusting this page: the Account A total shown above — buggy 2458.0, fixed 4050.0. Add up A-1001 (2 × 1200) and A-1002 (10 × 45 + 1 × 1200) yourself against data/sample-service/app/main.py and confirm it lands on 4050.