=== BEGIN ARTIFACT FEATURE-RemoveBookTests.md === # FEATURE: Remove Book Tests | Field | Value | |-------|-------| | Version | 20261023 V1 | | Description | Automated pytest tests that prove removing a book omits it on the next read, preserves the order of the rest, and answers 404 for an unknown id. | | Depends On | FEATURE-RemoveBook.md, FEATURE-AddBook.md, FEATURE-ListBooks.md, ARCHITECTURE.md | | Provides | tests/test_remove_book.py | | Consumes | POST /books/{id}/delete, POST /books, GET /books | ## Questions - None. ## Purpose The Reading List guardrail "Never ship a behavior without an automated test covering it" applies to removal. This specification governs the project's own pytest module `tests/test_remove_book.py`, written by the build agent beside the finished code against observed output. It exercises removal only through the public HTTP interface. ## Database Interface - None — persistence is owned by FEATURE-RemoveBook.md. ## Test Module `tests/test_remove_book.py` uses the `web_client` fixture from `tests/conftest.py` and covers one behavior per test, each named for the behavior: | Behavior | Expectation | |----------|-------------| | Removed book is omitted | After `POST /books/{id}/delete` answers 303, `GET /books` no longer lists that id. | | Other books remain | Removing one of several books leaves the others listed. | | Remaining order preserved | The remaining books keep their relative order of addition. | | Unknown id | `POST /books/{id}/delete` for an id that does not exist answers 404. | | Repeat removal | Removing the same id twice answers 303 then 404. | Each test creates the books it needs through `POST /books`, reads ids back from `GET /books`, and removes the books it created before finishing, so tests do not depend on each other's residue. ## Programmatic Acceptance === AC remove-tests-module-passes === Intent: The remove-book pytest module exists and every test in it passes against the built application. Suite: scoped Requires: executable=python3; scope=test import subprocess import sys from pathlib import Path import app_server module = Path("tests/test_remove_book.py") assert module.is_file() result = subprocess.run( [sys.executable, "-m", "pytest", "-q", str(module)], capture_output=True, text=True, ) print(result.stdout) print(result.stderr, file=sys.stderr) assert result.returncode == 0 === END AC remove-tests-module-passes === === AC remove-omits-on-next-read === Intent: A removed book is absent from GET /books on the next read. from app_server.testing import web_client client = web_client() marker = "AC-rmtests-omit" def owned(): return [b for b in client.get("/books").get_json() if b["title"].startswith(marker)] def cleanup(): for b in owned(): client.post(f"/books/{b['id']}/delete") cleanup() try: title = marker + "-one" author = "Remove Author" created = client.post("/books", data={"title": title, "author": author}) assert created.status_code == 303 found = owned() assert len(found) == 1 book_id = found[0]["id"] removed = client.post(f"/books/{book_id}/delete") assert removed.status_code == 303 assert book_id not in [b["id"] for b in client.get("/books").get_json()] finally: cleanup() === END AC remove-omits-on-next-read === === AC remove-preserves-order === Intent: Removing the middle book leaves the other two listed in the order they were added. from app_server.testing import web_client client = web_client() marker = "AC-rmtests-order" def owned(): return [b for b in client.get("/books").get_json() if b["title"].startswith(marker)] def cleanup(): for b in owned(): client.post(f"/books/{b['id']}/delete") cleanup() try: titles = [marker + "-a", marker + "-b", marker + "-c"] for t in titles: assert client.post("/books", data={"title": t, "author": "Order Author"}).status_code == 303 before = owned() assert [b["title"] for b in before] == titles middle = before[1] assert client.post(f"/books/{middle['id']}/delete").status_code == 303 after = owned() assert [b["id"] for b in after] == [before[0]["id"], before[2]["id"]] finally: cleanup() === END AC remove-preserves-order === === AC remove-unknown-id-404 === Intent: Removing an id that does not exist answers 404. from app_server.testing import web_client client = web_client() existing = [b["id"] for b in client.get("/books").get_json()] unknown_id = max(existing, default=0) + 100000 assert unknown_id not in existing response = client.post(f"/books/{unknown_id}/delete") assert response.status_code == 404 === END AC remove-unknown-id-404 === === AC remove-twice-second-404 === Intent: Removing the same book twice succeeds once and then answers 404. from app_server.testing import web_client client = web_client() marker = "AC-rmtests-twice" def owned(): return [b for b in client.get("/books").get_json() if b["title"].startswith(marker)] def cleanup(): for b in owned(): client.post(f"/books/{b['id']}/delete") cleanup() try: assert client.post("/books", data={"title": marker, "author": "Twice Author"}).status_code == 303 found = owned() assert len(found) == 1 book_id = found[0]["id"] assert client.post(f"/books/{book_id}/delete").status_code == 303 assert client.post(f"/books/{book_id}/delete").status_code == 404 finally: cleanup() === END AC remove-twice-second-404 === ## User Acceptance - None. ## Guardrails - Tests reach removal only through the public HTTP routes, never through the store. - Tests create and remove only the books they own and never reset the store. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-ValidationTests.md === # FEATURE: Validation Tests | Field | Value | |-------|-------| | Version | 20261023 V1 | | Description | Automated pytest tests that prove an empty or whitespace-only title or author is rejected with status 400, a reported reason, and nothing stored. | | Depends On | FEATURE-RejectEmptyTitle.md, FEATURE-RejectEmptyAuthor.md, FEATURE-AddBook.md, ARCHITECTURE.md | | Provides | tests/test_validation.py | | Consumes | POST /books, GET /books | ## Questions - None. ## Purpose The guardrails "Never accept an empty title or an empty author" and "Never omit a rejection reason when a submission is rejected" require automated coverage. This specification governs the project's own pytest module `tests/test_validation.py`, written by the build agent beside the finished code. It exercises validation only through `POST /books` and `GET /books`. ## Database Interface - None — persistence is owned by FEATURE-AddBook.md. ## Test Module `tests/test_validation.py` uses the `web_client` fixture and covers one behavior per test: | Behavior | Expectation | |----------|-------------| | Empty title rejected | Status 400, a non-empty `error`, and `field` naming the title. | | Whitespace-only title rejected | Same as an empty title. | | Missing title rejected | Same as an empty title. | | Empty author rejected | Status 400, a non-empty `error`, and `field` naming the author. | | Whitespace-only author rejected | Same as an empty author. | | Missing author rejected | Same as an empty author. | | Nothing stored on rejection | The list from `GET /books` is unchanged after a rejected submission. | | Browser rejection shows reason | Without `Accept: application/json` the answer is 400 and the page body is non-empty. | ## Programmatic Acceptance === AC validation-tests-module-passes === Intent: The validation pytest module exists and every test in it passes against the built application. Suite: scoped Requires: executable=python3; scope=test import subprocess import sys from pathlib import Path import app_server module = Path("tests/test_validation.py") assert module.is_file() result = subprocess.run( [sys.executable, "-m", "pytest", "-q", str(module)], capture_output=True, text=True, ) print(result.stdout) print(result.stderr, file=sys.stderr) assert result.returncode == 0 === END AC validation-tests-module-passes === === AC validation-empty-title-rejected === Intent: An empty title is rejected with 400, a non-empty reason, the title field named, and nothing stored. from app_server.testing import web_client client = web_client() field = "title" other = "author" before = client.get("/books").get_json() response = client.post( "/books", data={field: "", other: "Valid Author"}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-empty-title-rejected === === AC validation-blank-title-rejected === Intent: A whitespace-only title is rejected with 400 and a non-empty reason, and nothing is stored. from app_server.testing import web_client client = web_client() field = "title" blank = " " before = client.get("/books").get_json() response = client.post( "/books", data={field: blank, "author": "Valid Author"}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-blank-title-rejected === === AC validation-missing-title-rejected === Intent: A submission with no title field is rejected with 400 and a non-empty reason. from app_server.testing import web_client client = web_client() field = "title" before = client.get("/books").get_json() response = client.post( "/books", data={"author": "Valid Author"}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-missing-title-rejected === === AC validation-empty-author-rejected === Intent: An empty author is rejected with 400, a non-empty reason, the author field named, and nothing stored. from app_server.testing import web_client client = web_client() field = "author" other = "title" before = client.get("/books").get_json() response = client.post( "/books", data={field: "", other: "Valid Title"}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-empty-author-rejected === === AC validation-blank-author-rejected === Intent: A whitespace-only author is rejected with 400 and a non-empty reason, and nothing is stored. from app_server.testing import web_client client = web_client() field = "author" blank = " " before = client.get("/books").get_json() response = client.post( "/books", data={"title": "Valid Title", field: blank}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-blank-author-rejected === === AC validation-missing-author-rejected === Intent: A submission with no author field is rejected with 400 and a non-empty reason. from app_server.testing import web_client client = web_client() field = "author" before = client.get("/books").get_json() response = client.post( "/books", data={"title": "Valid Title"}, headers={"Accept": "application/json"}, ) assert response.status_code == 400 body = response.get_json() assert isinstance(body["error"], str) and body["error"].strip() assert body["field"] == field assert client.get("/books").get_json() == before === END AC validation-missing-author-rejected === === AC validation-browser-rejection-has-body === Intent: A rejected browser submission answers 400 with a non-empty page that reports the rejection. from app_server.testing import web_client client = web_client() before = client.get("/books").get_json() response = client.post("/books", data={"title": "", "author": ""}) assert response.status_code == 400 assert len(response.get_data()) > 0 assert client.get("/books").get_json() == before === END AC validation-browser-rejection-has-body === ## User Acceptance - None. ## Guardrails - Tests assert the status code, the presence of a non-empty reason, and the named field, never the wording of the reason. - A rejected submission never changes the stored list. === END ARTIFACT === === BEGIN ARTIFACT VERIFICATION.md === # FEATURE: Verification | Field | Value | |-------|-------| | Version | 20261023 V1 | | Description | The POSIX-compatible bin/test.sh runner and the terminal full-suite gate that proves every automated test passes. | | Depends On | ARCHITECTURE.md, FEATURE-AddBookTests.md, FEATURE-ListBooksTests.md, FEATURE-RemoveBookTests.md, FEATURE-ValidationTests.md, SCREEN-ReadingList.md | | Provides | bin/test.sh | ## Questions - None. ## Purpose The application root provides `bin/test.sh`, a POSIX `sh` script that runs the complete automated test suite from the application root. `sh bin/test.sh` exits zero only when every test passes. This is the terminal story: it runs after every implementation and test story, runs the whole suite through the Commander-owned dispatcher `sources/full_test.sh`, and preserves the command, exit code, standard output, and standard error as evidence. ## Database Interface - None — persistence is owned by FEATURE-AddBook.md. ## Runner Behavior - `bin/test.sh` is written in POSIX `sh`, with no bash-only syntax. - It changes to the application root (the parent of `bin/`) so it runs correctly from any working directory. - It activates `.venv` when present, then runs `pytest -q` over the entire suite with no filter, skip, or selection. - Its exit status is that of `pytest -q`; it never masks a failure. ## Programmatic Acceptance === AC runner-is-posix-script === Intent: bin/test.sh exists at the application root and parses as POSIX sh. Requires: executable=sh; scope=test import subprocess from pathlib import Path runner = Path("bin/test.sh") assert runner.is_file() result = subprocess.run(["sh", "-n", str(runner)], capture_output=True, text=True) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC runner-is-posix-script === === AC suite-files-present === Intent: Every behavior has its pytest module in the application's test suite. from pathlib import Path import app_server modules = [ "tests/test_add_book.py", "tests/test_list_books.py", "tests/test_remove_book.py", "tests/test_validation.py", ] missing = [m for m in modules if not Path(m).is_file()] print(f"missing modules: {missing}") assert missing == [] === END AC suite-files-present === === AC full-suite-gate === Intent: The complete suite, run through the staged dispatcher from the application root, exits zero. Suite: full Requires: executable=sh; scope=test import os import subprocess import sys import app_server result = subprocess.run( ["sh", "sources/full_test.sh"], capture_output=True, text=True, env={**os.environ}, ) print(result.stdout) print(result.stderr, file=sys.stderr) assert result.returncode == 0 === END AC full-suite-gate === ## User Acceptance - None. ## Guardrails - `bin/test.sh` never filters, skips, or reinterprets tests and never exits zero while any test fails. - The full suite runs only in this terminal story; earlier stories run their own scoped slices. === END ARTIFACT ===