tommulder commited on
Commit
34c6057
·
1 Parent(s): 5537ceb

chore(test): commit Makefile and testing scripts

Browse files
Files changed (3) hide show
  1. Makefile +29 -0
  2. scripts/README_TESTING.md +18 -0
  3. scripts/test_debug_ocr.sh +79 -0
Makefile CHANGED
@@ -102,3 +102,32 @@ clean-docker: ## Clean up Docker images and containers
102
  docker stop kybtech-dots-ocr || true
103
  docker rm kybtech-dots-ocr || true
104
  docker rmi kybtech-dots-ocr || true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  docker stop kybtech-dots-ocr || true
103
  docker rm kybtech-dots-ocr || true
104
  docker rmi kybtech-dots-ocr || true
105
+
106
+ # -----------------------------
107
+ # Debug testing helpers
108
+ # -----------------------------
109
+ .PHONY: debug-test-local debug-test-hf debug-test
110
+
111
+ debug-test-local: ## Run debug curl test against local server
112
+ ./scripts/test_debug_ocr.sh -u http://localhost:7860 -f scripts/tom_id_card_front.jpg -d
113
+
114
+ debug-test-hf: ## Run debug curl test against HF Space (set HF_URL var)
115
+ @if [ -z "$(HF_URL)" ]; then echo "HF_URL not set. Example: make debug-test-hf HF_URL=https://your-space.hf.space"; exit 1; fi
116
+ ./scripts/test_debug_ocr.sh -u $(HF_URL) -f scripts/tom_id_card_front.jpg -d
117
+
118
+ # debug-test allows overriding URL/FILE/ROI/DEBUG via envs
119
+ # Example:
120
+ # make debug-test URL=https://space.hf.space FILE=scripts/tom_id_card_front.jpg ROI='{"x1":0,"y1":0,"x2":1,"y2":0.5}' DEBUG=1
121
+
122
+ debug-test: ## Run debug curl test with overrides: URL, FILE, ROI, DEBUG
123
+ @URL=${URL:-http://localhost:7860} \
124
+ FILE=${FILE:-scripts/tom_id_card_front.jpg} \
125
+ ROI=${ROI:-} \
126
+ DBG=${DEBUG:-0} \
127
+ sh -c '\
128
+ CMD="./scripts/test_debug_ocr.sh -u $$URL -f $$FILE"; \
129
+ if [ "$$DBG" = "1" ]; then CMD="$$CMD -d"; fi; \
130
+ if [ -n "$$ROI" ]; then CMD="$$CMD -r '$$ROI'"; fi; \
131
+ echo "Running: $$CMD"; \
132
+ eval $$CMD \
133
+ '
scripts/README_TESTING.md CHANGED
@@ -213,3 +213,21 @@ These metrics can be integrated with monitoring systems like Prometheus or DataD
213
  ./run_tests.sh -e staging # Staging environment
214
  ./run_tests.sh -e production # Production environment
215
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  ./run_tests.sh -e staging # Staging environment
214
  ./run_tests.sh -e production # Production environment
215
  ```
216
+
217
+ ---
218
+
219
+ ### 5. `test_debug_ocr.sh` - Per-request debug logging via curl
220
+
221
+ Use this for quick, dependency-light testing of the server-side debug mode that prints OCR snippets, extracted fields, and MRZ details to logs.
222
+
223
+ **Usage:**
224
+ ```bash
225
+ # Local server (per-request debug on)
226
+ ./test_debug_ocr.sh -u http://localhost:7860 -f tom_id_card_front.jpg -d
227
+
228
+ # Hugging Face Space (replace with your Space URL)
229
+ ./test_debug_ocr.sh -u https://<your-space>.hf.space -f tom_id_card_front.jpg -d \
230
+ -r '{"x1":0,"y1":0,"x2":1,"y2":0.5}'
231
+ ```
232
+
233
+ You can also enable debug globally on the server with `DOTS_OCR_DEBUG=1`. The script only toggles the request-level flag via `-d`.
scripts/test_debug_ocr.sh ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Quick tester for Dots.OCR debug mode using curl.
3
+ #
4
+ # Usage examples:
5
+ # scripts/test_debug_ocr.sh -u http://localhost:7860 -f scripts/tom_id_card_front.jpg -d
6
+ # scripts/test_debug_ocr.sh -u https://<your-hf-space>.hf.space -f scripts/tom_id_card_front.jpg -d -r '{"x1":0,"y1":0,"x2":1,"y2":0.5}'
7
+ #
8
+ # Notes:
9
+ # - The `debug` form field enables per-request debug logging on the server.
10
+ # - You can also set env DOTS_OCR_DEBUG=1 on the server to enable globally.
11
+
12
+ set -euo pipefail
13
+
14
+ API_URL="http://localhost:7860"
15
+ FILE_PATH=""
16
+ ROI_JSON=""
17
+ ENABLE_DEBUG=false
18
+
19
+ usage() {
20
+ echo "Usage: $0 -u <api_url> -f <image_or_pdf> [-d] [-r '<roi-json>']" >&2
21
+ echo " -u API base URL (default: ${API_URL})" >&2
22
+ echo " -f Path to image/PDF file to upload" >&2
23
+ echo " -d Enable per-request debug logging (adds -F debug=true)" >&2
24
+ echo " -r ROI JSON string, e.g. '{\"x1\":0,\"y1\":0,\"x2\":1,\"y2\":0.5}'" >&2
25
+ exit 1
26
+ }
27
+
28
+ while getopts ":u:f:r:d" opt; do
29
+ case ${opt} in
30
+ u) API_URL="$OPTARG" ;;
31
+ f) FILE_PATH="$OPTARG" ;;
32
+ r) ROI_JSON="$OPTARG" ;;
33
+ d) ENABLE_DEBUG=true ;;
34
+ *) usage ;;
35
+ esac
36
+ done
37
+
38
+ if [[ -z "$FILE_PATH" ]]; then
39
+ echo "Error: file path is required." >&2
40
+ usage
41
+ fi
42
+
43
+ if [[ ! -f "$FILE_PATH" ]]; then
44
+ echo "Error: file not found: $FILE_PATH" >&2
45
+ exit 2
46
+ fi
47
+
48
+ echo "🚀 Testing Dots.OCR API at $API_URL"
49
+ echo "File: $FILE_PATH"
50
+ if [[ -n "$ROI_JSON" ]]; then
51
+ echo "ROI: $ROI_JSON"
52
+ fi
53
+ echo "Debug: $ENABLE_DEBUG"
54
+
55
+ CURL_ARGS=(
56
+ -sS -X POST "$API_URL/v1/id/ocr"
57
+ -F "file=@$FILE_PATH"
58
+ )
59
+
60
+ if [[ -n "$ROI_JSON" ]]; then
61
+ CURL_ARGS+=( -F "roi=$ROI_JSON" )
62
+ fi
63
+
64
+ if [[ "$ENABLE_DEBUG" == true ]]; then
65
+ CURL_ARGS+=( -F "debug=true" )
66
+ fi
67
+
68
+ # Pretty-print with jq if available
69
+ if command -v jq >/dev/null 2>&1; then
70
+ curl "${CURL_ARGS[@]}" | jq '.'
71
+ else
72
+ echo "(Install jq for pretty JSON)"
73
+ curl "${CURL_ARGS[@]}"
74
+ fi
75
+
76
+ echo ""
77
+ echo "Done. Check server logs for detailed debug output when enabled."
78
+
79
+