Fix dev-loop breakages and harden the scan API - #2
Merged
Merged
Conversation
… fuzzy text normalisation
…o-frame, results context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the things that currently stop a fresh clone from running, plus the backend/frontend rough edges that would bite the first time this is used on a real device.
Frontend install and device reachability
npm cifailed on npm 11: the lockfile hadreact-dom@19.2.3alongsidereact@19.1.0. Pinnedreact-domto19.1.0(Expo SDK 54's version); clean installs work again.@expo/vector-iconswas imported byresult.tsxbut only present as a nested transitive dependency. Added it as a direct dependency.localhost, which only works on the iOS simulator. It now resolvesEXPO_PUBLIC_API_URLfirst, then falls back to the host serving the Expo dev bundle (viaexpo-constants), so a physical phone on the same network reachespython run.pywith no config.frontendtoAddiGuard/addiguardand added theexpo-cameraconfig plugin with a permission string so native iOS builds don't crash on camera access.Backend
ScanService()was built at import time, so importingapp(includingseed.py) loaded torch and the EasyOCR models. The reader is now acached_propertycreated on the first scan;create_appruns in 0.16s with torch never imported.MAX_CONTENT_LENGTHis 10 MB → 413. AllHTTPExceptions (404, 413, 405…) return JSON.str(e)to the client; the traceback goes to the app logger and the client gets a fixed message./api/*so Expo web can call the API.debug,PORTandDATABASE_URLcome from the environment instead of being hardcoded.requirements.txtis pinned and pulls CPU-only torch/torchvision from the PyTorch index (the code runsgpu=False; this avoids ~2 GB of CUDA wheels). Droppedpython-Levenshtein(thefuzz 0.22 uses rapidfuzz) and the unusednumpyimport.backend/app.py, a hello-world duplicate ofrun.py.Single source of truth for the traffic light
The frontend re-derived Red/Yellow/Green from
risk_scorewith its own copy of the thresholds and computed the overall label itself, ignoring thetraffic_lightthe API already returned. The API now also returnsoverall_risk_scoreandoverall_traffic_light; the app renders thetraffic_lightvalues it receives through one colour/label map. The detail sheet also shows all four risk factors instead of two.Mock mode
The toggle is now only rendered in
__DEV__builds, and the capture flow is a singletry/finallyso the spinner always resets (the old path skippedsetScanning(false)in mock mode and used a detachedsetTimeout).Tests, CI, README
backend/tests/: 19 pytest cases covering the risk formula, threshold boundaries, fuzzy matching against OCR-like text (including a typo), lazy reader construction, and every route branch (400/413/500/404, CORS header, overall fields).pytestandtsc --noEmiton pushes tomainand PRs.Verification
pytest: 19 passed.npx tsc --noEmit: clean. Freshnpm ci: succeeds./api/scan; response found both additives,overall_risk_score0.83 /Red. First call 4.4s including model download, warm call 0.8s. 404/400/413 and CORS preflight verified over HTTP.Removed
frontend/App.tsx.bakandfrontend/index.ts.bak.