From 93deb33a2a730db4e4f2e14592bede66205a4e81 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 10 Apr 2026 14:54:19 +0200 Subject: [PATCH] Fix validation script to tolerate expected TS7 kind/flags diffsTS5 The shell validation script now uses a structural comparison that ignores expected numeric differences in kind/flags/token/operator values between TS5 and TS7. Only truly structural diffs cause failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../typescript-go/scripts/validate-output.sh | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/javascript/extractor/lib/typescript-go/scripts/validate-output.sh b/javascript/extractor/lib/typescript-go/scripts/validate-output.sh index 73ae973d679..03823703edd 100755 --- a/javascript/extractor/lib/typescript-go/scripts/validate-output.sh +++ b/javascript/extractor/lib/typescript-go/scripts/validate-output.sh @@ -152,20 +152,58 @@ compare_output() { } if [ "$nodejs_norm" = "$go_norm" ]; then - echo -e " ${GREEN}PASS${NC} $basename" + echo -e " ${GREEN}PASS${NC} $basename (exact match)" PASS=$((PASS + 1)) else - echo -e " ${RED}FAIL${NC} $basename" - FAIL=$((FAIL + 1)) + # Check if differences are only expected TS5↔TS7 numeric kind/flags/token/operator values + local structural_diffs + structural_diffs=$(python3 -c " +import json, sys + +NUMERIC_VALUE_KEYS = {'kind', 'flags', 'token', 'operator'} + +def count_structural(a, b, path='root'): + count = 0 + if isinstance(a, dict) and isinstance(b, dict): + keys = set(a) | set(b) + for k in keys: + if k not in a or k not in b: + count += 1 + else: + count += count_structural(a[k], b[k], path + '.' + k) + elif isinstance(a, list) and isinstance(b, list): + if len(a) != len(b): + return 1 + for i in range(len(a)): + count += count_structural(a[i], b[i], f'{path}[{i}]') + elif a != b: + key = path.rsplit('.', 1)[-1] if '.' in path else path + if key in NUMERIC_VALUE_KEYS and isinstance(a, (int, float)) and isinstance(b, (int, float)): + return 0 + count = 1 + return count + +a = json.loads(sys.argv[1]) +b = json.loads(sys.argv[2]) +print(count_structural(a, b)) +" "$nodejs_norm" "$go_norm" 2>/dev/null) || structural_diffs="?" + + if [ "$structural_diffs" = "0" ]; then + echo -e " ${GREEN}PASS${NC} $basename (only expected TS5↔TS7 kind/flags diffs)" + PASS=$((PASS + 1)) + else + echo -e " ${RED}FAIL${NC} $basename ($structural_diffs structural diff(s))" + FAIL=$((FAIL + 1)) - # Save outputs for inspection - local outdir="$PROJECT_DIR/validation-output" - mkdir -p "$outdir" - echo "$nodejs_norm" > "$outdir/${basename}.nodejs.json" - echo "$go_norm" > "$outdir/${basename}.go.json" + # Save outputs for inspection + local outdir="$PROJECT_DIR/validation-output" + mkdir -p "$outdir" + echo "$nodejs_norm" > "$outdir/${basename}.nodejs.json" + echo "$go_norm" > "$outdir/${basename}.go.json" - # Show first few lines of diff - diff <(echo "$nodejs_norm") <(echo "$go_norm") | head -30 || true + # Show first few lines of diff + diff <(echo "$nodejs_norm") <(echo "$go_norm") | head -30 || true + fi fi }