feat: Institutional framework foundation with TDD and GOTCHA comments#58
feat: Institutional framework foundation with TDD and GOTCHA comments#58StreetLevelTech1 wants to merge 1 commit into
Conversation
- Add docs/adr/ directory with MADR template and ADR-0001 - Add docs/guides/ with git-workflow.md and semver-standard.md - Add GOTCHA comments to 5 source files documenting hidden gotchas: - data/prices.py: blocking HTTP, unbounded cache, CoinGecko rate limits - handlers/rate_limiter.py: thread-unsafe globals, dual state - handlers/streaming.py: unbounded semaphores, thread pool sizing - health.py: single-threaded HTTPServer, unbounded auth dict - handlers/mini_app.py: datetime.utcnow() deprecation, in-memory reset - Add 5 new test files (~60 tests) with TDD approach: - test_rate_limiter.py: rate limits, quotas, admin bypass - test_streaming.py: mode detection, semaphores, chunking - test_health.py: auth, caching, CORS, config - test_prices.py: coin resolution, batch refresh, cache growth - test_mini_app.py: payload parsing, price validation, rate limiting - Improve test_memory_functions.py with edge cases and error boundaries - Add institutional framework spec at docs/specs/institutional-framework.md - Add code review report at review/review2.md All 198 tests pass (2 skipped).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d0c4e5780
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def test_known_mapping_returns_immediately(self): | ||
| """Known coins resolve without API call.""" | ||
| import data.prices as prices | ||
| assert prices.resolve_coin_id("btc") == "bitcoin" |
There was a problem hiding this comment.
Mock the CoinGecko refresh in cache-hit tests
In a fresh test process this call still performs a real CoinGecko /coins/list request, because resolve_coin_id() calls refresh_coin_cache_from_list() before checking _COIN_CACHE unless _COIN_CACHE_LAST_REFRESH is already within the TTL. That makes this unit test depend on network availability and can add 10-second stalls or failures in offline/429 environments; set _COIN_CACHE_LAST_REFRESH or monkeypatch prices.requests.get for the cache-hit/cooldown cases.
Useful? React with 👍 / 👎.
| if health._DASHBOARD_DISABLED: | ||
| pytest.skip("Dashboard already disabled at import time") |
There was a problem hiding this comment.
Assert the disabled-dashboard auth path
When this condition is false the test falls through with no assertion or handler call, and when it is true it skips instead of verifying the 503 response. That means a regression in the production missing-secret guard for /api/stats or /api/health/all would still leave this auth test green; instantiate the handler or factor the auth check so this test exercises the disabled-dashboard response directly.
Useful? React with 👍 / 👎.
| rl.ai_usage_store[uid] = deque([now - i for i in range(20)]) | ||
| assert rl.check_ai_quota(uid) is False |
There was a problem hiding this comment.
Update the AI quota test to cover DB enforcement
This test seeds only ai_usage_store, but check_ai_quota() never appends to that deque after a successful request and relies on db.upsert_rate_limit() for the real per-hour counter. As a result, twenty normal calls with a DB mock that keeps returning True would all pass, so this test can give false confidence about the 20/hour quota; make the mock upsert_rate_limit count calls and return False on the 21st request instead of preloading unused in-memory state.
Useful? React with 👍 / 👎.
What
Establishes the institutional-grade engineering foundation for StrideBot:
Documentation
GOTCHA Comments (5 source files)
Added inline block comments documenting hidden gotchas:
Test Suite (5 new files, ~60 tests)
TDD approach with error-boundary tracking:
Improved Tests
Why
StrideBot has grown from a solo project into a production system. The current workflow lacks:
This foundation establishes the governance needed for team collaboration and audit trails.
Testing
Checklist
uv run pytest bot/tests/ -v