Skip to content

Commit a176bfb

Browse files
committed
Fix Makefile test command syntax error
1 parent a2dc3dd commit a176bfb

File tree

2 files changed

+98
-18
lines changed

2 files changed

+98
-18
lines changed

Makefile

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,7 @@ test: lindfs
7777
if LIND_WASM_BASE=. LINDFS_ROOT=$(LINDFS_ROOT) \
7878
python3 ./scripts/test_runner.py --export-report report.html && \
7979
find reports -maxdepth 1 -name '*.json' -print -exec cat {} \; && \
80-
python3 -c "import glob,json,sys; paths=glob.glob('reports/*.json'); \
81-
def count_failures(node): \
82-
if not isinstance(node, dict): \
83-
return 0; \
84-
direct=node.get('number_of_failures'); \
85-
try: \
86-
direct_val=int(direct) if direct is not None else None; \
87-
except (TypeError, ValueError): \
88-
direct_val=None; \
89-
nested=sum(count_failures(v) for v in node.values() if isinstance(v, dict)); \
90-
return nested if direct_val is None else max(direct_val, nested); \
91-
total=1 if not paths else 0; \
92-
for path in paths: \
93-
with open(path, encoding='utf-8') as handle: \
94-
total += count_failures(json.load(handle)); \
95-
print(f'total_failures={total}'); \
96-
sys.exit(1 if total else 0)"; then \
80+
python3 ./scripts/check_reports.py; then \
9781
echo "E2E_STATUS=pass" > e2e_status; \
9882
else \
9983
echo "E2E_STATUS=fail" > e2e_status; \
@@ -106,7 +90,7 @@ sys.exit(1 if total else 0)"; then \
10690
if [ ! -f reports/grates.json ]; then printf '%s\n' '{"number_of_failures":1,"results":[],"error":"missing grate report"}' > reports/grates.json; fi; \
10791
fi; \
10892
exit 0
109-
93+
11094
.PHONY: md_generation
11195
OUT ?= .
11296
REPORT ?= report.html

scripts/check_reports.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# This file is used by Makefile in testing to check whether test
2+
# is successful
3+
import glob
4+
import json
5+
import sys
6+
import argparse
7+
8+
# Parse optional debug flag from CLI
9+
# When enabled, prints detailed report inspection info
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("--debug", action="store_true")
12+
args = parser.parse_args()
13+
14+
DEBUG = args.debug
15+
16+
17+
def dprint(*args, **kwargs):
18+
"""
19+
Debug print helper.
20+
Only prints when DEBUG flag is enabled to avoid polluting CI output.
21+
"""
22+
if DEBUG:
23+
print(*args, **kwargs)
24+
25+
26+
# Collect all JSON reports under reports/
27+
paths = sorted(glob.glob("reports/*.json"))
28+
dprint("DEBUG: report paths =", paths)
29+
30+
31+
def count_failures(node):
32+
"""
33+
Recursively count failures in a JSON report.
34+
35+
Rules:
36+
- If a node has 'number_of_failures', treat it as authoritative
37+
but still compare with nested counts (take max for safety)
38+
- Otherwise, aggregate failures from children
39+
- Handles mixed nested structures (dict/list)
40+
41+
This makes the checker robust to different report schemas.
42+
"""
43+
if isinstance(node, list):
44+
return sum(count_failures(x) for x in node)
45+
46+
if not isinstance(node, dict):
47+
return 0
48+
49+
# Direct failure count (if present)
50+
direct = node.get("number_of_failures")
51+
try:
52+
direct_val = int(direct) if direct is not None else None
53+
except (TypeError, ValueError):
54+
direct_val = None
55+
56+
# Recursively count nested failures
57+
nested = sum(count_failures(v) for v in node.values())
58+
59+
# Prefer explicit count but guard against under-reporting
60+
return nested if direct_val is None else max(direct_val, nested)
61+
62+
63+
# If no reports exist, treat as failure (fail closed)
64+
total = 1 if not paths else 0
65+
66+
for path in paths:
67+
dprint(f"\n===== DEBUG REPORT: {path} =====")
68+
69+
with open(path, encoding="utf-8") as f:
70+
data = json.load(f)
71+
72+
# Print top-level structure for debugging schema issues
73+
if isinstance(data, dict):
74+
dprint("top-level keys =", list(data.keys()))
75+
dprint("top-level number_of_failures =", data.get("number_of_failures"))
76+
dprint("top-level error =", data.get("error"))
77+
dprint(
78+
"top-level results type =",
79+
type(data.get("results")).__name__ if "results" in data else "MISSING",
80+
)
81+
else:
82+
dprint("root type =", type(data).__name__)
83+
84+
failures = count_failures(data)
85+
dprint("computed failures =", failures)
86+
87+
total += failures
88+
89+
90+
# Final aggregated result
91+
dprint(f"\nDEBUG: total_failures={total}")
92+
93+
# Exit code:
94+
# 0 -> success (no failures)
95+
# 1 -> failure detected
96+
sys.exit(1 if total else 0)

0 commit comments

Comments
 (0)