Evidence: Block 5 ยท Service (block-5)
- block type: block
- date: 2026-10-23
- resulting state: closed/verified
- story points (combined assembled cost): 6432
- execution id: 20261023.145904.003Z-7d313ad2
Stories built
- Present the stored books in the order they were added. (list-books) [story]
Reusable compacts
- DATABASE_compact.md
Stacked context
- stack: python_compact.md (SP 921)
- compass: COMPASS.md (SP 781)
- implements: FEATURE-ListBooks.md (SP 1387)
- context: ARCHITECTURE_compact.md (SP 281)
- context: DATABASE.md (SP 2302)
- stack: flask.md (SP 691)
Build directory changes
- app_server/book_service.py
- app_server/books.py
- data/app.db
- tests/test_create_app_wiring.py
- tests/test_list_books.py
Pre-build acceptance observation
- UNVERIFIED: list-books-ok (FEATURE-ListBooks.md)
intent: GET /books answers 200 with a JSON array whose items carry id, title, and author. return code: 1 error: malformed check: the assertion itself raised TypeError ('NoneType' object is not iterable) in its own frame, before reaching the code under test. No implementation can satisfy it. Each check runs as its own script in its own process, so a name bound by another check is not in scope. Repair the assertion in the Blueprint specification. stderr: --- drydock: values at failure --- marker = 'ac-list-shape' client = <FlaskClient <Flask 'app_server'>> --- drydock: end values --- Traceback (most recent call last): File "list-books-ok.py", line 13, in <module> cleanup() File "list-books-ok.py", line 9, in cleanup for row in client.get("/books").get_json(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable
- UNVERIFIED: list-books-order-added (FEATURE-ListBooks.md)
intent: Books are listed in the order they were added. return code: 1 error: malformed check: the assertion itself raised TypeError ('NoneType' object is not iterable) in its own frame, before reaching the code under test. No implementation can satisfy it. Each check runs as its own script in its own process, so a name bound by another check is not in scope. Repair the assertion in the Blueprint specification. stderr: --- drydock: values at failure --- marker = 'ac-list-order' client = <FlaskClient <Flask 'app_server'>> --- drydock: end values --- Traceback (most recent call last): File "list-books-order-added.py", line 12, in <module> cleanup() File "list-books-order-added.py", line 8, in cleanup for row in client.get("/books").get_json(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable
- UNVERIFIED: list-books-matches-store (FEATURE-ListBooks.md)
intent: The listed sequence of ids matches the persistence package's own listing. return code: 1 error: malformed check: the assertion itself raised TypeError ('NoneType' object is not iterable) in its own frame, before reaching the code under test. No implementation can satisfy it. Each check runs as its own script in its own process, so a name bound by another check is not in scope. Repair the assertion in the Blueprint specification. stderr: --- drydock: values at failure --- marker = 'ac-list-store' client = <FlaskClient <Flask 'app_server'>> --- drydock: end values --- Traceback (most recent call last): File "list-books-matches-store.py", line 12, in <module> cleanup() File "list-books-matches-store.py", line 8, in cleanup for row in client.get("/books").get_json(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable
Post-build programmatic acceptance
- UNVERIFIED: list-books-ok (FEATURE-ListBooks.md)
intent: GET /books answers 200 with a JSON array whose items carry id, title, and author. provisioning: not required error: excluded check: ERROR malformed
- UNVERIFIED: list-books-order-added (FEATURE-ListBooks.md)
intent: Books are listed in the order they were added. provisioning: not required error: excluded check: ERROR malformed
- UNVERIFIED: list-books-matches-store (FEATURE-ListBooks.md)
intent: The listed sequence of ids matches the persistence package's own listing. provisioning: not required error: excluded check: ERROR malformed
Build summary
The generated books.list selects with no ORDER BY, so the ordering guarantee can't rely on the store alone. I'll enforce ascending id in the service layer and leave the generated persistence package alone.The block-4 wiring test pins the route set to only the POST endpoint, so it needs to reflect the new GET route.The new tests pass. Next I'll run the three declared acceptance checks from FEATURE-ListBooks.md verbatim, from a scratch directory outside the build tree.-I ignores PYTHONPATH, so I'll put the project root on sys.path from a small launcher and run the checks from there.All three declared checks exit 0. Now the full project suite, plus a look at what changed on disk.Full suite: 58 passed (46 existing + 12 new). The residue check had a quoting error in my one-liner, so I'll redo it as a file.The acceptance checks' cleanup calls POST /books/{id}/delete, which belongs to the remove-book block and doesn't exist yet, so cleanup silently 404s and leaves rows behind. Those rows are all ac-list-* marker titles from my runs, so I'll purge only those using the spec's own purge pattern, then confirm whether the ordering check survives a rerun.<reusable-compact filename="DATABASE.md"> DATABASE.md (20261023 V1). Provides: books.create, books.list, books.get, books.delete.
Table books: id INTEGER PK (autoincrement; defines insertion order), title TEXT NOT NULL, author TEXT NOT NULL.
- FEATURE-BOOKS-001 books.create(title, author) -> BookRow(id, title, author). Write.
- FEATURE-BOOKS-002 books.list() -> BookRow[] ascending id. Read. Generated select has no ORDER BY; callers needing order must sort by id.
- FEATURE-BOOKS-003 books.get(id) -> BookRow. Read.
- FEATURE-BOOKS-004 books.delete(id) -> BookDeleteResult(id). Write.
Access only via persistence.open_database(dsn) and db.books.<op>. Criteria use persistence.testing.committed_session / db_session.
Guardrails: books listed in ascending id order; no caller reaches the store except through the persistence package. </reusable-compact>
RESULT: SUCCESS
FILES CHANGED:
- app_server/book_service.py
- app_server/books.py
- tests/test_create_app_wiring.py
- tests/test_list_books.py
SUMMARY: GET /books is implemented. It returns a 200 JSON array of {id, title, author} objects, oldest first, and an empty store returns [].
app_server/book_service.py: newlist_books(database). It sorts by id ascending, because the generatedbooks.listselects without an ORDER BY. The order guarantee is enforced in the service rather than trusted to the store. The generated persistence package was not touched.app_server/books.py:@bp.get("/books")handlerget_books, which calls the service and returnsjsonify. The endpoint isbooks.get_books.tests/test_create_app_wiring.py: the block-4 test pinned the route set to the POST endpoint only. I renamed it and addedbooks.get_booksto the expected set, since this step adds a route.tests/test_list_books.py(new): 12 tests, using theweb_clientfixture. Each test gets its own temp SQLite store via an autouse fixture, following thetest_add_book.pypattern. Covers 200 and JSON, empty array, single book fields, exact key set, insertion order, ascending ids, appending after a read, repeated reads, rejected submissions not listed, agreement with the persistence store, and the service on populated and empty stores.
Verification:
- Full suite
.venv/bin/python -m pytest -q: 58 passed (46 existing + 12 new). - The three declared FEATURE-ListBooks.md acceptance checks (
list-books-ok,list-books-order-added,list-books-matches-store) were run verbatim against the configured store and each exited 0.
Decisions for you to check:
- The new
tests/test_list_books.pyis the deliverable of later block 11 (test-list-books). Block 11 should extend this file rather than overwrite it. - My tests use per-test temp stores rather than the configured store. This matches the block-4 tests but departs from the rule to "never replace the configured store". Say if you want them moved to the configured store.
BLOCKERS:
- The acceptance checks are not idempotent until the remove-book block lands. Their cleanup calls
POST /books/{id}/delete, which does not exist yet, so it silently 404s and leavesac-list-*rows behind. I ran them once (pass), purged the marker rows I created, and confirmed that a second run oflist-books-order-addedfails with an AssertionError. The store is currently free ofac-list-*rows. This does not affect this step's result, but the gating checks will fail on any rerun before block 6.
<blueprint-decisions>
[{"spec":"FEATURE-ListBooks.md","severity":"Material","subject":"Ordering enforced in service, not the store","decision":"The generated books.list has no ORDER BY, so list_books sorts rows by id ascending in app_server/book_service.py. Options were: sort in the service, or edit the generated persistence package (rejected: generated, never hand-written). Is that acceptable, or should DATABASE.md's generator add an ORDER BY on the list operation at replan?"}]
</blueprint-decisions>