-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconformance_check.py
More file actions
635 lines (520 loc) · 26.3 KB
/
conformance_check.py
File metadata and controls
635 lines (520 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#!/usr/bin/env python3
"""
Conformance check module: runs the same logical input through both the COBOL
program (acct-processing.cbl) and the Java Spring Batch program, then asserts
their outputs are equivalent field-by-field.
Usage:
python3 conformance_check.py # run with default 10 test records
python3 conformance_check.py --records 50 # run with 50 random records
python3 conformance_check.py --seed 42 # reproducible random generation
Exit code 0 = conformance PASS, 1 = conformance FAIL, 2 = execution error.
"""
import argparse
import os
import random
import shutil
import struct
import subprocess
import sys
import tempfile
from dataclasses import dataclass
from decimal import Decimal, ROUND_HALF_EVEN
from pathlib import Path
from typing import List, Optional, Tuple
# ── Constants ────────────────────────────────────────────────────────────────
INTEREST_RATE = Decimal("0.0325")
MIN_BALANCE = Decimal("100.00")
COBOL_SRC = "acct-processing.cbl"
JAVA_PROJECT_ROOT = Path(".")
# COBOL binary record sizes
COBOL_INPUT_REC_LEN = 55 # 10 + 20 + 15 + 7 + 2 + 1
COBOL_OUTPUT_REC_LEN = 24 # 10 + 7 + 5 + 2
# Java text output: 40 chars per line
JAVA_OUTPUT_LINE_LEN = 40
# ── Data model ───────────────────────────────────────────────────────────────
@dataclass
class InputRecord:
cust_id: int
last_name: str
first_name: str
balance: Decimal
acct_type: str # "SA" or "CH"
status: str # "A" or "C"
@dataclass
class OutputRecord:
"""Normalized output record for comparison."""
cust_id: int
new_balance: Decimal
interest: Decimal
return_code: str # "OK", "LB", "SK"
def __eq__(self, other):
return (self.cust_id == other.cust_id
and self.new_balance == other.new_balance
and self.interest == other.interest
and self.return_code == other.return_code)
@dataclass
class FieldDiff:
record_index: int
cust_id: int
field: str
cobol_value: str
java_value: str
# ── Test data generation ─────────────────────────────────────────────────────
LAST_NAMES = [
"Smith", "Johnson", "Williams", "Brown", "Davis",
"Miller", "Wilson", "Taylor", "Anderson", "Thomas",
"Jackson", "White", "Harris", "Martin", "Garcia",
"Clark", "Lewis", "Lee", "Walker", "Hall",
]
FIRST_NAMES = [
"John", "Jane", "Robert", "Emily", "Michael",
"Sarah", "David", "Lisa", "James", "Patricia",
"Daniel", "Mary", "Chris", "Laura", "Kevin",
]
def generate_test_records(count: int, seed: Optional[int] = None) -> List[InputRecord]:
"""Generate test input records with a mix of edge cases and random data."""
rng = random.Random(seed)
# Always include these edge cases first
edge_cases = [
InputRecord(1, "Smith", "John", Decimal("10000.00"), "SA", "A"), # savings, active, normal
InputRecord(2, "Johnson", "Jane", Decimal("25000.50"), "CH", "A"), # checking, active
InputRecord(3, "Williams", "Robert", Decimal("50.00"), "SA", "A"), # savings, low balance
InputRecord(4, "Brown", "Emily", Decimal("150000.75"), "CH", "C"), # closed -> skip
InputRecord(5, "Davis", "Michael", Decimal("5000.00"), "SA", "A"), # savings, active
InputRecord(6, "Miller", "Sarah", Decimal("0.00"), "SA", "C"), # closed, zero balance
InputRecord(7, "Wilson", "David", Decimal("75000.25"), "CH", "A"), # checking, active
InputRecord(8, "Taylor", "Lisa", Decimal("99.99"), "SA", "A"), # savings, just under min
InputRecord(9, "Anderson", "James", Decimal("500000.00"), "CH", "A"), # checking, large balance
InputRecord(10, "Thomas", "Patricia", Decimal("1200.00"), "SA", "C"), # closed
]
records = edge_cases[:min(count, len(edge_cases))]
# Fill remaining with random records
for i in range(len(records), count):
cust_id = i + 1
last = rng.choice(LAST_NAMES)
first = rng.choice(FIRST_NAMES)
# Balance: 0.00 to 999999.99
balance = Decimal(rng.randint(0, 99999999)) / Decimal(100)
balance = balance.quantize(Decimal("0.01"))
acct_type = rng.choice(["SA", "CH"])
status = rng.choice(["A", "C"])
records.append(InputRecord(cust_id, last, first, balance, acct_type, status))
return records
# ── Expected output computation (reference oracle) ───────────────────────────
def compute_expected_output(records: List[InputRecord],
include_skipped: bool = False) -> List[OutputRecord]:
"""
Compute expected output using the same business rules as both COBOL and Java.
This serves as the reference oracle.
Args:
include_skipped: If True, include SK records in output (Java behavior).
If False, omit them (COBOL behavior).
"""
outputs = []
for rec in records:
if rec.status != "A":
if include_skipped:
outputs.append(OutputRecord(
rec.cust_id, rec.balance, Decimal("0.00"), "SK"))
continue
# Interest calculation (paragraph 2100)
if rec.acct_type == "SA":
interest = (rec.balance * INTEREST_RATE).quantize(
Decimal("0.01"), rounding=ROUND_HALF_EVEN)
else:
interest = Decimal("0.00")
# Balance validation (paragraph 2200)
if rec.balance < MIN_BALANCE:
return_code = "LB"
else:
return_code = "OK"
new_balance = (rec.balance + interest).quantize(
Decimal("0.01"), rounding=ROUND_HALF_EVEN)
outputs.append(OutputRecord(rec.cust_id, new_balance, interest, return_code))
return outputs
# ── COBOL binary I/O ─────────────────────────────────────────────────────────
def to_comp3(value: int, num_digits: int = 13, signed: bool = True) -> bytes:
"""Encode an integer value as COMP-3 packed decimal."""
negative = value < 0
digits_str = str(abs(value)).zfill(num_digits)
if not signed:
sign_nibble = 0xF
elif negative:
sign_nibble = 0xD
else:
sign_nibble = 0xC
nibbles = [int(d) for d in digits_str] + [sign_nibble]
if len(nibbles) % 2 != 0:
nibbles = [0] + nibbles
result = bytearray()
for i in range(0, len(nibbles), 2):
result.append((nibbles[i] << 4) | nibbles[i + 1])
return bytes(result)
def from_comp3(data: bytes) -> int:
"""Decode COMP-3 packed decimal to integer."""
result = 0
sign = 0xC
for i, b in enumerate(data):
high = (b >> 4) & 0x0F
low = b & 0x0F
if i == len(data) - 1:
result = result * 10 + high
sign = low
else:
result = result * 10 + high
result = result * 10 + low
if sign == 0xD:
result = -result
return result
def write_cobol_input(records: List[InputRecord], path: str):
"""Write COBOL binary input file (55 bytes per record)."""
with open(path, "wb") as f:
for rec in records:
buf = bytearray()
buf += f"{rec.cust_id:010d}".encode("ascii")
buf += f"{rec.last_name:<20s}".encode("ascii")
buf += f"{rec.first_name:<15s}".encode("ascii")
cents = int(rec.balance * 100)
buf += to_comp3(cents, num_digits=13, signed=True)
buf += rec.acct_type.encode("ascii")
buf += rec.status.encode("ascii")
assert len(buf) == COBOL_INPUT_REC_LEN, f"Record len {len(buf)} != {COBOL_INPUT_REC_LEN}"
f.write(buf)
def read_cobol_output(path: str) -> List[OutputRecord]:
"""Read COBOL binary output file (24 bytes per record)."""
with open(path, "rb") as f:
data = f.read()
records = []
num = len(data) // COBOL_OUTPUT_REC_LEN
for i in range(num):
rec = data[i * COBOL_OUTPUT_REC_LEN:(i + 1) * COBOL_OUTPUT_REC_LEN]
cust_id = int(rec[0:10].decode("ascii"))
# AO-NEW-BALANCE: PIC S9(11)V99 COMP-3 = 7 bytes, implied 2 decimals
new_bal_cents = from_comp3(rec[10:17])
new_balance = Decimal(new_bal_cents) / Decimal(100)
# AO-INTEREST: PIC S9(7)V99 COMP-3 = 5 bytes, implied 2 decimals
interest_cents = from_comp3(rec[17:22])
interest = Decimal(interest_cents) / Decimal(100)
return_code = rec[22:24].decode("ascii")
records.append(OutputRecord(cust_id, new_balance, interest, return_code))
return records
# ── Java text I/O ────────────────────────────────────────────────────────────
def write_java_input(records: List[InputRecord], path: str):
"""Write Java text fixed-width input file (63 chars per line)."""
with open(path, "w") as f:
for rec in records:
int_part = int(abs(rec.balance))
dec_part = int(round((abs(rec.balance) - int_part) * 100))
bal_str = f"{int_part:011d}.{dec_part:02d}"
line = (f"{rec.cust_id:010d}"
f"{rec.last_name:<20s}"
f"{rec.first_name:<15s}"
f"{bal_str}"
f"{rec.acct_type:<2s}"
f"{rec.status:<2s}")
assert len(line) == 63, f"Line length {len(line)} != 63"
f.write(line + "\n")
def read_java_output(path: str) -> List[OutputRecord]:
"""Read Java text fixed-width output file (40 chars per line)."""
records = []
with open(path, "r") as f:
for line_num, line in enumerate(f, 1):
line = line.rstrip("\n")
if not line:
continue
if len(line) != JAVA_OUTPUT_LINE_LEN:
print(f" WARNING: Java output line {line_num} has length {len(line)}, expected {JAVA_OUTPUT_LINE_LEN}")
print(f" Line: [{line}]")
continue
cust_id = int(line[0:10])
# Positions 11-24: new balance as "XXXXXXXXXXX.XX" (14 chars)
new_balance = Decimal(line[10:24].strip())
# Positions 25-38: interest as "XXXXXXXXXXX.XX" (14 chars)
interest = Decimal(line[24:38].strip())
return_code = line[38:40].strip()
records.append(OutputRecord(cust_id, new_balance, interest, return_code))
return records
# ── Program execution ────────────────────────────────────────────────────────
def compile_and_run_cobol(src: str, input_file: str, output_file: str, work_dir: str) -> bool:
"""Compile and run the COBOL program. Returns True on success."""
exe_path = os.path.join(work_dir, "acct-proc")
print(" Compiling COBOL program...")
result = subprocess.run(
["cobc", "-x", "-o", exe_path, src],
capture_output=True, text=True, cwd=work_dir
)
if result.returncode != 0:
print(f" COBOL compilation FAILED:\n{result.stderr}")
return False
# The COBOL program reads ACCT-IN.DAT and writes ACCT-OUT.DAT in its CWD
cobol_in = os.path.join(work_dir, "ACCT-IN.DAT")
cobol_out = os.path.join(work_dir, "ACCT-OUT.DAT")
shutil.copy2(input_file, cobol_in)
# Remove old output if present
if os.path.exists(cobol_out):
os.remove(cobol_out)
print(" Running COBOL program...")
result = subprocess.run(
[exe_path],
capture_output=True, text=True, cwd=work_dir
)
if result.returncode != 0:
print(f" COBOL execution FAILED (rc={result.returncode}):\n{result.stderr}")
return False
print(f" COBOL stdout:\n {result.stdout.strip().replace(chr(10), chr(10) + ' ')}")
if not os.path.exists(cobol_out):
print(" COBOL output file not created")
return False
shutil.copy2(cobol_out, output_file)
return True
def run_java_program(input_file: str, output_file: str, work_dir: str) -> bool:
"""Build and run the Java Spring Batch program. Returns True on success."""
project_root = str(JAVA_PROJECT_ROOT.resolve())
# Copy input file to where Spring Batch expects it
java_input_dest = os.path.join(project_root, "src", "main", "resources", "input", "ACCT-IN.DAT")
shutil.copy2(input_file, java_input_dest)
# Clean output directory
java_output = os.path.join(project_root, "output", "ACCT-OUT.DAT")
os.makedirs(os.path.join(project_root, "output"), exist_ok=True)
if os.path.exists(java_output):
os.remove(java_output)
# Also remove the H2 database to ensure a fresh job run
h2_files = Path(project_root).glob("*.mv.db")
for h2 in h2_files:
h2.unlink(missing_ok=True)
print(" Building Java project (mvn package -q -DskipTests)...")
result = subprocess.run(
["./mvnw", "package", "-q", "-DskipTests"],
capture_output=True, text=True, cwd=project_root
)
if result.returncode != 0:
print(f" Maven build FAILED:\n{result.stderr[:2000]}")
return False
print(" Running Java Spring Batch job...")
jar_path = find_jar(os.path.join(project_root, "target"))
if not jar_path:
print(" Could not find executable JAR in target/")
return False
result = subprocess.run(
["java", "-jar", jar_path,
f"--job.input.file=file:{input_file}",
f"--job.output.file=file:{output_file}"],
capture_output=True, text=True, cwd=project_root,
timeout=120
)
if result.returncode != 0:
print(f" Java execution FAILED (rc={result.returncode})")
# Print last 30 lines of output for debugging
lines = (result.stdout + result.stderr).strip().split("\n")
for l in lines[-30:]:
print(f" {l}")
return False
if not os.path.exists(output_file):
print(" Java output file not created")
return False
return True
def find_jar(target_dir: str) -> Optional[str]:
"""Find the Spring Boot executable JAR."""
target = Path(target_dir)
for jar in target.glob("*.jar"):
if "original" not in jar.name:
return str(jar)
return None
# ── Comparison engine ────────────────────────────────────────────────────────
def compare_outputs(cobol_records: List[OutputRecord],
java_records: List[OutputRecord],
expected_records: List[OutputRecord],
tolerance: Decimal = Decimal("0.00")) -> Tuple[bool, List[str]]:
"""
Compare COBOL and Java outputs field-by-field.
Also validates both against the expected oracle.
Returns (passed, list_of_messages).
"""
messages = []
passed = True
# ── Record count check ───────────────────────────────────────────────
if len(cobol_records) != len(java_records):
messages.append(
f"RECORD COUNT MISMATCH: COBOL produced {len(cobol_records)} records, "
f"Java produced {len(java_records)} records "
f"(expected {len(expected_records)})")
passed = False
if len(cobol_records) != len(expected_records):
messages.append(
f"COBOL record count ({len(cobol_records)}) differs from expected ({len(expected_records)})")
passed = False
if len(java_records) != len(expected_records):
messages.append(
f"Java record count ({len(java_records)}) differs from expected ({len(expected_records)})")
passed = False
# ── Field-by-field comparison ────────────────────────────────────────
diffs: List[FieldDiff] = []
compare_count = min(len(cobol_records), len(java_records))
for i in range(compare_count):
cr = cobol_records[i]
jr = java_records[i]
if cr.cust_id != jr.cust_id:
diffs.append(FieldDiff(i, cr.cust_id, "cust_id",
str(cr.cust_id), str(jr.cust_id)))
if abs(cr.new_balance - jr.new_balance) > tolerance:
diffs.append(FieldDiff(i, cr.cust_id, "new_balance",
str(cr.new_balance), str(jr.new_balance)))
if abs(cr.interest - jr.interest) > tolerance:
diffs.append(FieldDiff(i, cr.cust_id, "interest",
str(cr.interest), str(jr.interest)))
if cr.return_code != jr.return_code:
diffs.append(FieldDiff(i, cr.cust_id, "return_code",
cr.return_code, jr.return_code))
# ── Also compare each against expected oracle ────────────────────────
oracle_diffs_cobol = []
oracle_diffs_java = []
for i in range(min(len(cobol_records), len(expected_records))):
cr = cobol_records[i]
er = expected_records[i]
for field in ["cust_id", "new_balance", "interest", "return_code"]:
cv = getattr(cr, field)
ev = getattr(er, field)
if isinstance(cv, Decimal) and isinstance(ev, Decimal):
if abs(cv - ev) > tolerance:
oracle_diffs_cobol.append(
f" Record {i} (cust_id={er.cust_id}): {field}: "
f"COBOL={cv}, expected={ev}")
elif cv != ev:
oracle_diffs_cobol.append(
f" Record {i} (cust_id={er.cust_id}): {field}: "
f"COBOL={cv}, expected={ev}")
for i in range(min(len(java_records), len(expected_records))):
jr = java_records[i]
er = expected_records[i]
for field in ["cust_id", "new_balance", "interest", "return_code"]:
jv = getattr(jr, field)
ev = getattr(er, field)
if isinstance(jv, Decimal) and isinstance(ev, Decimal):
if abs(jv - ev) > tolerance:
oracle_diffs_java.append(
f" Record {i} (cust_id={er.cust_id}): {field}: "
f"Java={jv}, expected={ev}")
elif jv != ev:
oracle_diffs_java.append(
f" Record {i} (cust_id={er.cust_id}): {field}: "
f"Java={jv}, expected={ev}")
# ── Report ───────────────────────────────────────────────────────────
if diffs:
passed = False
messages.append(f"\nCOBOL vs Java FIELD DIFFERENCES ({len(diffs)} differences):")
for d in diffs:
messages.append(
f" Record {d.record_index} (cust_id={d.cust_id}): "
f"{d.field}: COBOL={d.cobol_value}, Java={d.java_value}")
if oracle_diffs_cobol:
passed = False
messages.append(f"\nCOBOL vs EXPECTED ORACLE ({len(oracle_diffs_cobol)} differences):")
messages.extend(oracle_diffs_cobol)
if oracle_diffs_java:
passed = False
messages.append(f"\nJava vs EXPECTED ORACLE ({len(oracle_diffs_java)} differences):")
messages.extend(oracle_diffs_java)
# ── Extra records ────────────────────────────────────────────────────
if len(cobol_records) > compare_count:
messages.append(f"\nCOBOL has {len(cobol_records) - compare_count} extra records:")
for r in cobol_records[compare_count:]:
messages.append(f" cust_id={r.cust_id} bal={r.new_balance} int={r.interest} rc={r.return_code}")
if len(java_records) > compare_count:
messages.append(f"\nJava has {len(java_records) - compare_count} extra records:")
for r in java_records[compare_count:]:
messages.append(f" cust_id={r.cust_id} bal={r.new_balance} int={r.interest} rc={r.return_code}")
return passed, messages
# ── Main ─────────────────────────────────────────────────────────────────────
def main():
parser = argparse.ArgumentParser(description="COBOL ↔ Java conformance check")
parser.add_argument("--records", type=int, default=10,
help="Number of test records to generate (default: 10)")
parser.add_argument("--seed", type=int, default=None,
help="Random seed for reproducible test data")
parser.add_argument("--tolerance", type=str, default="0.01",
help="Decimal tolerance for numeric comparisons (default: 0.00 = exact). "
"Use e.g. 0.01 to allow 1-cent rounding differences from COBOL truncation.")
args = parser.parse_args()
print("=" * 70)
print(" COBOL ↔ Java Conformance Check")
print("=" * 70)
tolerance = Decimal(args.tolerance)
print(f" Records: {args.records}, Seed: {args.seed or 'random'}, Tolerance: {tolerance}")
print()
# ── Generate test data ───────────────────────────────────────────────
records = generate_test_records(args.records, args.seed)
expected_cobol = compute_expected_output(records, include_skipped=False)
expected_java = compute_expected_output(records, include_skipped=True)
print(f"Generated {len(records)} input records")
print(f" Expected COBOL output: {len(expected_cobol)} records (active only)")
print(f" Expected Java output: {len(expected_java)} records (all, including SK)")
print()
# ── Create temp working directory ────────────────────────────────────
work_dir = tempfile.mkdtemp(prefix="conformance_")
print(f"Working directory: {work_dir}")
cobol_src_abs = str(Path(COBOL_SRC).resolve())
cobol_input = os.path.join(work_dir, "cobol_input.dat")
cobol_output = os.path.join(work_dir, "cobol_output.dat")
java_input = os.path.join(work_dir, "java_input.dat")
java_output = os.path.join(work_dir, "java_output.dat")
try:
# ── Write input files ────────────────────────────────────────────
write_cobol_input(records, cobol_input)
write_java_input(records, java_input)
print(f" COBOL input: {os.path.getsize(cobol_input)} bytes ({len(records)} × {COBOL_INPUT_REC_LEN})")
print(f" Java input: {os.path.getsize(java_input)} bytes")
print()
# ── Run COBOL ────────────────────────────────────────────────────
print("─── COBOL Execution ───")
cobol_ok = compile_and_run_cobol(cobol_src_abs, cobol_input, cobol_output, work_dir)
if not cobol_ok:
print("\nCOBOL execution failed. Cannot perform conformance check.")
return 2
print()
# ── Run Java ─────────────────────────────────────────────────────
print("─── Java Execution ───")
java_ok = run_java_program(java_input, java_output, work_dir)
if not java_ok:
print("\nJava execution failed. Cannot perform conformance check.")
return 2
print()
# ── Read outputs ─────────────────────────────────────────────────
cobol_records = read_cobol_output(cobol_output)
java_records = read_java_output(java_output)
print(f"COBOL produced {len(cobol_records)} output records")
print(f"Java produced {len(java_records)} output records")
print()
# ── Compare ──────────────────────────────────────────────────────
print("─── Comparison Results ───")
# Key behavioral difference: COBOL only writes active records,
# Java writes ALL records (including SK). For conformance, we compare
# the active-record subset from Java against COBOL output.
java_active = [r for r in java_records if r.return_code != "SK"]
java_skipped = [r for r in java_records if r.return_code == "SK"]
print(f" Java active records: {len(java_active)}")
print(f" Java skipped records: {len(java_skipped)}")
print()
# Primary check: COBOL output vs Java active-only output
passed, messages = compare_outputs(cobol_records, java_active, expected_cobol, tolerance)
if passed:
print(f"\n✅ CONFORMANCE PASS — {len(cobol_records)} active records match "
f"across COBOL and Java.")
if java_skipped:
print(f" (Java also produced {len(java_skipped)} SK records "
f"not present in COBOL output — known behavioral difference)")
print()
print(f" {'CustID':>10} {'NewBalance':>14} {'Interest':>12} {'RC':<2}")
print(f" {'─'*10} {'─'*14} {'─'*12} {'─'*2}")
for r in cobol_records:
print(f" {r.cust_id:>10} {r.new_balance:>14} {r.interest:>12} {r.return_code:<2}")
return 0
else:
print(f"\n❌ CONFORMANCE FAIL")
for msg in messages:
print(msg)
return 1
finally:
# Clean up temp dir
shutil.rmtree(work_dir, ignore_errors=True)
if __name__ == "__main__":
sys.exit(main())