From 96ba16f2ca2f784603a6e79f5980c823edb810b5 Mon Sep 17 00:00:00 2001 From: Sam Mirazi Date: Sat, 31 May 2025 23:49:27 -0700 Subject: [PATCH] docs(TDD): Clarify FastAPI server execution and fix markdown for Phase 4 This commit enhances the Technical Design Document (Design Docs/TDD.md) by providing explicit instructions for running the FastAPI server, pertinent to the completion of Phase 4 ("Green Implementation for FastAPI"). It also includes a minor markdown syntax correction. Key changes: - Added a dedicated markdown block in Phase 4 with the precise command `uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000` and context for running the FastAPI application. This makes the instruction more prominent and user-friendly. - Removed the previous, less visible comment `# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000` from within the FastAPI Python code example to avoid redundancy and improve clarity. - Corrected markdown code block specifiers (from ``` to ````) around the FastAPI example and the new instruction block to ensure correct rendering of the document. These changes make it easier for anyone following the TDD to manually start and test the FastAPI server as intended at the end of Phase 4, before proceeding to the benchmarking in Phase 5. --- Design Docs/TDD.md | 8 +++++--- app_fastapi/__pycache__/app.cpython-312.pyc | Bin 714 -> 721 bytes app_fastapi/app.py | 2 +- app_flask/flask_application.py | 2 +- tests/test_fastapi_route.py | 2 +- tests/test_flask_route.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Design Docs/TDD.md b/Design Docs/TDD.md index 71c232d..3a4aa1e 100644 --- a/Design Docs/TDD.md +++ b/Design Docs/TDD.md @@ -253,7 +253,7 @@ _Key Tasks_ - Includes an artificial `await asyncio.sleep(3)` (non-blocking). - Ensure `uvicorn` runs it on the port expected by the test (e.g., 8000). -```python +````python # app_fastapi/app.py (example) from fastapi import FastAPI, Response import asyncio @@ -266,8 +266,10 @@ async def home(): html = "

Slow FastAPI Demo

" return Response(content=html, media_type="text/html") -# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000 -``` +To run this FastAPI server manually from your project root (after ensuring `uvicorn` and `fastapi` are installed in your environment), use the following command: +```bash +uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000 +```` _Tests_ diff --git a/app_fastapi/__pycache__/app.cpython-312.pyc b/app_fastapi/__pycache__/app.cpython-312.pyc index 16396b34ee7129fdfa1e6260ecc348fa0b802d4d..a12b7f3b44a4d26a4f6d0901b775417de03e3922 100644 GIT binary patch delta 62 zcmX@bdXbg)G%qg~0}!12YMtS>kynmU*1{&k(9SKfxWqBQQz1CDs4TU}O2Jq+I5jyx QFJ-bL;}b^L$!bhX06ftX0RR91 delta 55 zcmcb}dWx0zG%qg~0}%9Gwa&2L$ScPvW@wXPXy=w#T;dqusSuo6RF+y~rC>bSgYgNY J-DF*+B>=4x5Dx$V diff --git a/app_fastapi/app.py b/app_fastapi/app.py index bc0f0cf..8a1936c 100644 --- a/app_fastapi/app.py +++ b/app_fastapi/app.py @@ -7,5 +7,5 @@ app = FastAPI() @app.get("/") async def home(): await asyncio.sleep(3) # simulate slow work (non-blocking) - html = "

FastAPI Server: 3s Artificial Delay Demo

" + html = "

FastAPI Server: 3-Seconds Artificial Delay Demo

" return Response(content=html, media_type="text/html") \ No newline at end of file diff --git a/app_flask/flask_application.py b/app_flask/flask_application.py index 5da77ea..8dbca04 100644 --- a/app_flask/flask_application.py +++ b/app_flask/flask_application.py @@ -7,7 +7,7 @@ app = Flask(__name__) @app.route("/") def home(): time.sleep(3) # simulate slow work - html = "

Flask Server: 3s Artificial Delay Demo

" # Updated content + html = "

Flask Server: 3-Seconds Artificial Delay Demo

" # Updated content return Response(html, mimetype="text/html") if __name__ == "__main__": diff --git a/tests/test_fastapi_route.py b/tests/test_fastapi_route.py index 015dbd6..40ff1d2 100644 --- a/tests/test_fastapi_route.py +++ b/tests/test_fastapi_route.py @@ -49,7 +49,7 @@ async def test_home_returns_html_fastapi(): async with httpx.AsyncClient(timeout=10) as client: r = await client.get(f"http://{HOST}:{PORT}/") assert r.status_code == 200 - assert "

FastAPI Server: 3s Artificial Delay Demo

" in r.text # Expected content + assert "

FastAPI Server: 3-Seconds Artificial Delay Demo

" in r.text # Expected content finally: if server_process and server_process.is_alive(): server_process.terminate() # Send SIGTERM diff --git a/tests/test_flask_route.py b/tests/test_flask_route.py index 5185c79..1065743 100644 --- a/tests/test_flask_route.py +++ b/tests/test_flask_route.py @@ -27,7 +27,7 @@ def test_home_returns_html(): } r = httpx.get("http://127.0.0.1:3000/", timeout=10, headers=headers) assert r.status_code == 200 - assert "

Flask Server: 3s Artificial Delay Demo

" in r.text + assert "

Flask Server: 3-Seconds Artificial Delay Demo

" in r.text finally: proc.terminate() try: -- 2.25.1