|
| 1 | +# Prompts |
| 2 | + |
| 3 | +Copy-paste these into Cursor and Windsurf in order while following the tutorial. |
| 4 | + |
| 5 | +## 1. Set up the project |
| 6 | + |
| 7 | +``` |
| 8 | +Set up a Python project in this directory following standard Python |
| 9 | +packaging conventions: |
| 10 | +- Create a virtual environment |
| 11 | +- Install httpx==0.28.1 and pytest==9.0.2 |
| 12 | +- Add a tests/ directory |
| 13 | +- Use the directory name as the package name |
| 14 | +- Only include the dependencies explicitly listed here |
| 15 | +``` |
| 16 | + |
| 17 | +## 2. Write the async fetch function |
| 18 | + |
| 19 | +``` |
| 20 | +Create a file called `fetcher.py` and write an async function |
| 21 | +called fetch_json that: |
| 22 | +- Takes a URL string and an optional integer max_retries (default 3) |
| 23 | +- Uses httpx.AsyncClient to fetch JSON from the URL |
| 24 | +- Retries up to max_retries times with exponential backoff (1s, 2s, 4s) |
| 25 | + on any httpx.HTTPError |
| 26 | +- Returns the JSON response as a typed dataclass called FetchResult |
| 27 | + with fields: url (str), status_code (int), and data (dict[str, Any]) |
| 28 | +- Uses proper type hints throughout |
| 29 | +``` |
| 30 | + |
| 31 | +## 3. Generate tests |
| 32 | + |
| 33 | +Before sending this prompt, open `fetcher.py` and replace |
| 34 | +`await asyncio.sleep(delay)` with `time.sleep(delay)`, then add |
| 35 | +`import time` at the top. Save the file. |
| 36 | + |
| 37 | +``` |
| 38 | +Create tests/test_fetcher.py with pytest tests for fetch_json that: |
| 39 | +- Test successful fetch returns correct FetchResult |
| 40 | +- Test fetch retries twice then succeeds |
| 41 | +- Test fetch raises after exhausting retries |
| 42 | +- Test two concurrent fetches complete in <4s |
| 43 | + (one with 1s+2s retry delays, one instant) |
| 44 | +- Test fetch can be cancelled during retry delay |
| 45 | +Use httpx.MockTransport for mocking. |
| 46 | +``` |
| 47 | + |
| 48 | +## 4. Plan-mode prompt |
| 49 | + |
| 50 | +Switch each editor to its Plan mode before sending: |
| 51 | + |
| 52 | +``` |
| 53 | +Add a retry_budget parameter to fetch_json that limits the total |
| 54 | +cumulative wait time across all retries. |
| 55 | +``` |
| 56 | + |
| 57 | +## 5. Autocomplete starter snippet |
| 58 | + |
| 59 | +Type this into a file and let each editor complete it: |
| 60 | + |
| 61 | +```python |
| 62 | +@dataclass |
| 63 | +class RetryMetadata: |
| 64 | + attempts_made: int |
| 65 | +# ... |
| 66 | +``` |
| 67 | + |
| 68 | +## 6. Manual review (Windsurf Ask mode) |
| 69 | + |
| 70 | +``` |
| 71 | +Review fetcher.py for bugs and lint issues and summarize what you find. |
| 72 | +``` |
0 commit comments