-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtest-examples.py
More file actions
689 lines (579 loc) · 26 KB
/
Copy pathtest-examples.py
File metadata and controls
689 lines (579 loc) · 26 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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#!/usr/bin/env python3
"""
Test script for CDK GitHub Runners examples.
This is mostly for internal use. Users have no reason to use this script.
This script:
1. Synths all TypeScript and Python examples
2. Compares synthesized outputs to ensure they match
3. Deploys TypeScript examples one by one
4. Destroys them immediately after deployment
5. Reports all errors and results
"""
import argparse
import json
import os
import shutil
import subprocess
import sys
import time
from pathlib import Path
from typing import Dict, List, Tuple, Optional
import difflib
cdk_path = shutil.which("cdk")
if not cdk_path:
print_colored(" ✗ CDK not found. Please install AWS CDK CLI.", Colors.RED)
sys.exit(1)
pnpm_path = shutil.which("pnpm")
if not pnpm_path:
print_colored(" ✗ pnpm not found. Please install pnpm.", Colors.RED)
sys.exit(1)
_python_requirements_baseline: Optional[str] = None
class Colors:
"""ANSI color codes for terminal output."""
GREEN = '\033[92m'
RED = '\033[91m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
RESET = '\033[0m'
BOLD = '\033[1m'
def print_colored(message: str, color: str = Colors.RESET):
"""Print colored message."""
print(f"{color}{message}{Colors.RESET}")
def format_duration(seconds: float) -> str:
"""Format duration in seconds to human-readable string."""
if seconds < 60:
return f"{seconds:.1f}s"
minutes = int(seconds // 60)
secs = seconds % 60
return f"{minutes}m {secs:.1f}s"
def run_command(cmd: List[str], cwd: Optional[Path] = None, capture_output: bool = True) -> Tuple[int, str, str]:
"""Run a command and return exit code, stdout, and stderr."""
try:
result = subprocess.run(
cmd,
cwd=cwd,
capture_output=capture_output,
text=True,
check=False,
timeout=600, # 10 minute timeout
)
stdout = result.stdout if capture_output else ""
stderr = result.stderr if capture_output else ""
return result.returncode, stdout, stderr
except subprocess.TimeoutExpired:
return 1, "", "Command timed out after 10 minutes"
except Exception as e:
return 1, "", str(e)
def find_examples(filter_names: Optional[List[str]] = None) -> Tuple[List[str], List[str]]:
"""Find all TypeScript and Python examples.
Args:
filter_names: Optional list of example names to include. If None, includes all examples.
"""
examples_dir = Path(__file__).parent
ts_examples = []
py_examples = []
for lang in ["typescript", "python"]:
lang_dir = examples_dir / lang
if not lang_dir.exists():
continue
for example_dir in lang_dir.iterdir():
if not example_dir.is_dir():
continue
# Filter by example name if filter_names is provided
if filter_names is not None and example_dir.name not in filter_names:
continue
app_file = example_dir / ("app.ts" if lang == "typescript" else "app.py")
if app_file.exists():
if lang == "typescript":
ts_examples.append(str(example_dir.relative_to(examples_dir)))
else:
py_examples.append(str(example_dir.relative_to(examples_dir)))
return sorted(ts_examples), sorted(py_examples)
def normalize_json(json_str: str) -> str:
"""Normalize JSON for comparison."""
try:
data = json.loads(json_str)
return json.dumps(data, sort_keys=True, indent=2)
except json.JSONDecodeError:
return json_str
def synth_example(example_path: str, lang: str) -> Tuple[bool, Optional[str], str]:
"""Synthesize a CDK example and return success, template, and error message."""
global _python_requirements_baseline
project_root = Path(__file__).parent.parent
example_dir = Path(__file__).parent / example_path
# Install dependencies first
if lang == "typescript":
start_time = time.time()
print_colored(f" Installing dependencies for {example_path}...", Colors.BLUE)
code, out, err = run_command([pnpm_path, "install"], cwd=example_dir)
duration = time.time() - start_time
if code != 0:
return False, None, f"pnpm install failed: {err}\n{out}"
print_colored(f" ✓ Dependencies installed ({format_duration(duration)})", Colors.GREEN)
# Install local package - use the pre-copied simple name
start_time = time.time()
print_colored(f" Installing local package for {example_path}...", Colors.BLUE)
examples_dir = Path(__file__).parent
simple_tgz_path = examples_dir / "cdk-github-runners.tgz"
if not simple_tgz_path.exists():
return False, None, f"Package file not found: {simple_tgz_path}"
# Use relative path from example directory to the simple tgz path
code, out, err = run_command([pnpm_path, "add", simple_tgz_path.absolute()], cwd=example_dir)
duration = time.time() - start_time
if code != 0:
return False, None, f"npm install local package failed: {err}\n{out}"
print_colored(f" ✓ Local package installed ({format_duration(duration)})", Colors.GREEN)
elif lang == "python":
req_path = example_dir / "requirements.txt"
if not req_path.exists():
return False, None, "requirements.txt not found"
current_req = req_path.read_text()
if _python_requirements_baseline is None:
# First Python example - install requirements and local package
start_time = time.time()
print_colored(f" Installing dependencies for {example_path}...", Colors.BLUE)
code, out, err = run_command(["pip", "install", "--upgrade", "-r", "requirements.txt"], cwd=example_dir)
duration = time.time() - start_time
if code != 0:
return False, None, f"pip install requirements failed: {err}\n{out}"
print_colored(f" ✓ Dependencies installed ({format_duration(duration)})", Colors.GREEN)
start_time = time.time()
print_colored(f" Installing local package for {example_path}...", Colors.BLUE)
dist_python_dir = (project_root / "dist" / "python").resolve()
whl_files = list(dist_python_dir.glob("*.whl"))
if not whl_files:
return False, None, f"No .whl files found in {dist_python_dir}"
code, out, err = run_command(["pip", "install", "--force-reinstall"] + [str(w) for w in whl_files], cwd=example_dir)
duration = time.time() - start_time
if code != 0:
return False, None, f"pip install local package failed: {err}\n{out}"
print_colored(f" ✓ Local package installed ({format_duration(duration)})", Colors.GREEN)
_python_requirements_baseline = current_req
else:
if current_req != _python_requirements_baseline:
return False, None, f"requirements.txt differs from first Python example"
print_colored(f" ✓ requirements.txt matches first example (skipping install)", Colors.GREEN)
# Run CDK synth (exclude metadata for cleaner diffs)
start_time = time.time()
print_colored(f" Synthing {example_path}...", Colors.BLUE)
code, out, err = run_command([
cdk_path, "synth",
"--quiet",
"--no-asset-metadata",
"--no-path-metadata",
"--no-version-reporting",
"--no-notices",
], cwd=example_dir)
duration = time.time() - start_time
if code != 0:
return False, None, f"cdk synth failed: {err}\n{out}"
print_colored(f" ✓ Synthesis completed ({format_duration(duration)})", Colors.GREEN)
# Find the synthesized template
# CDK synth outputs to cdk.out/<stack-name>.template.json
cdk_out = example_dir / "cdk.out"
if not cdk_out.exists():
return False, None, "cdk.out directory not found"
# Find the template file
template_files = list(cdk_out.glob("*.template.json"))
if not template_files:
# Also check for nested directories (some CDK versions use subdirectories)
template_files = list(cdk_out.rglob("*.template.json"))
if not template_files:
return False, None, "No template.json file found in cdk.out"
# If multiple templates, combine them (for multi-stack examples)
# For comparison, we'll use the first/main stack template
template_path = template_files[0]
try:
with open(template_path, 'r', encoding='utf-8') as f:
template = f.read()
return True, template, ""
except Exception as e:
return False, None, f"Failed to read template: {str(e)}"
def compare_templates(ts_template: str, py_template: str) -> Tuple[bool, str]:
"""Compare two CloudFormation templates and return if they match and diff."""
ts_normalized = normalize_json(ts_template)
py_normalized = normalize_json(py_template)
if ts_normalized == py_normalized:
return True, ""
# Generate diff
diff = list(difflib.unified_diff(
ts_normalized.splitlines(keepends=True),
py_normalized.splitlines(keepends=True),
fromfile="TypeScript",
tofile="Python",
lineterm="",
))
return False, "".join(diff)
def deploy_example(example_path: str) -> Tuple[bool, str]:
"""Deploy a CDK example."""
example_dir = Path(__file__).parent / example_path
start_time = time.time()
print_colored(f" Deploying {example_path}...", Colors.BLUE)
try:
# Run with real-time output but capture for error reporting
process = subprocess.Popen(
[cdk_path, "deploy", "--require-approval", "never", "--all", "--no-notices"],
cwd=example_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding='utf-8',
errors='replace', # Replace invalid characters instead of failing
text=True,
bufsize=1,
universal_newlines=True,
)
output_lines = []
for line in process.stdout:
print(f" {line.rstrip()}")
output_lines.append(line)
process.wait()
output = "".join(output_lines)
duration = time.time() - start_time
if process.returncode != 0:
return False, f"cdk deploy failed:\n{output}"
print_colored(f" ✓ Deployment completed ({format_duration(duration)})", Colors.GREEN)
return True, ""
except Exception as e:
return False, f"Deployment error: {str(e)}"
def destroy_example(example_path: str) -> Tuple[bool, str]:
"""Destroy a CDK example."""
example_dir = Path(__file__).parent / example_path
start_time = time.time()
print_colored(f" Destroying {example_path}...", Colors.BLUE)
try:
# Run with real-time output but capture for error reporting
process = subprocess.Popen(
[cdk_path, "destroy", "--force", "--all", "--no-notices"],
cwd=example_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding='utf-8',
errors='replace', # Replace invalid characters instead of failing
text=True,
bufsize=1,
universal_newlines=True,
)
output_lines = []
for line in process.stdout:
print(f" {line.rstrip()}")
output_lines.append(line)
process.wait()
output = "".join(output_lines)
duration = time.time() - start_time
if process.returncode != 0:
return False, f"cdk destroy failed:\n{output}"
print_colored(f" ✓ Destruction completed ({format_duration(duration)})", Colors.GREEN)
return True, ""
except Exception as e:
return False, f"Destruction error: {str(e)}"
def get_stack_name(example_path: str) -> str:
"""Get the stack name from the example."""
# Try to extract from the app file
example_dir = Path(__file__).parent / example_path
app_file = example_dir / ("app.ts" if "typescript" in example_path else "app.py")
if app_file.exists():
content = app_file.read_text(encoding='utf-8')
# Look for common patterns like "new Stack(app, 'StackName')" or "Stack(app, 'StackName')"
import re
match = re.search(r"new\s+\w+Stack\([^,]+,\s*['\"]([^'\"]+)['\"]", content)
if match:
return match.group(1)
match = re.search(r"\w+Stack\([^,]+,\s*['\"]([^'\"]+)['\"]", content)
if match:
return match.group(1)
# Fallback to directory name
return Path(example_path).name.replace("-", "").title().replace(" ", "")
def check_prerequisites() -> bool:
"""Check if required tools are available."""
print_colored("Checking prerequisites...", Colors.BLUE)
# Check CDK
code, _, _ = run_command([cdk_path, "--version", "--no-notices"])
if code != 0:
print_colored(" ✗ CDK not found. Please install AWS CDK CLI.", Colors.RED)
return False
print_colored(" ✓ CDK found", Colors.GREEN)
# Check pnpm (for TypeScript examples)
code, _, _ = run_command([pnpm_path, "--version"])
if code != 0:
print_colored(" ✗ pnpm not found. TypeScript examples will fail.", Colors.YELLOW)
else:
print_colored(" ✓ pnpm found", Colors.GREEN)
# Check python (for Python examples)
code, _, _ = run_command(["python", "--version"])
if code != 0:
code, _, _ = run_command(["python3", "--version"])
if code != 0:
print_colored(" ✗ Python not found. Python examples will fail.", Colors.YELLOW)
else:
print_colored(" ✓ Python found", Colors.GREEN)
print()
return True
def main():
"""Main test function."""
parser = argparse.ArgumentParser(description="Test CDK GitHub Runners examples")
parser.add_argument(
"--skip-deploy",
action="store_true",
help="Skip deployment and destruction phase (faster, only tests synthesis and comparison)",
)
parser.add_argument(
"--skip-package",
action="store_true",
help="Skip package building phase (faster, only tests synthesis and comparison)",
)
parser.add_argument(
"--skip-synth",
action="store_true",
help="Skip synthesis phase (faster, only tests deployment if not skipped)",
)
parser.add_argument(
"--examples",
nargs="+",
metavar="EXAMPLE",
help="Only process specific examples by name (e.g., --examples advanced simple-codebuild). Can be specified multiple times or space-separated.",
)
args = parser.parse_args()
script_start_time = time.time()
print_colored("=" * 80, Colors.BOLD)
print_colored("CDK GitHub Runners Examples Test Script", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
# Check prerequisites
if not check_prerequisites():
print_colored("Prerequisites check failed. Please install required tools.", Colors.RED)
return 1
# Build the package
if not args.skip_package:
print_colored("=" * 80, Colors.BOLD)
print_colored("Building Package", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
project_root = Path(__file__).parent.parent
start_time = time.time()
print_colored("Running pnpm run bundle...", Colors.BLUE)
code, out, err = run_command([pnpm_path, "run", "bundle"], cwd=project_root)
duration = time.time() - start_time
if code != 0:
print_colored(f" ✗ Bundle failed: {err}\n{out}", Colors.RED)
print_colored("\nPackage building failed. Stopping.", Colors.RED)
return 1
print_colored(f" ✓ Bundle successful ({format_duration(duration)})", Colors.GREEN)
print()
start_time = time.time()
print_colored("Running pnpm run compile...", Colors.BLUE)
code, out, err = run_command([pnpm_path, "run", "compile"], cwd=project_root)
duration = time.time() - start_time
if code != 0:
print_colored(f" ✗ Compile failed: {err}\n{out}", Colors.RED)
print_colored("\nPackage building failed. Stopping.", Colors.RED)
return 1
print_colored(f" ✓ Compile successful ({format_duration(duration)})", Colors.GREEN)
print()
start_time = time.time()
print_colored("Running pnpm run package:js...", Colors.BLUE)
code, out, err = run_command([pnpm_path, "run", "package:js"], cwd=project_root)
duration = time.time() - start_time
if code != 0:
print_colored(f" ✗ Package JS failed: {err}\n{out}", Colors.RED)
print_colored("\nPackage building failed. Stopping.", Colors.RED)
return 1
print_colored(f" ✓ Package JS successful ({format_duration(duration)})", Colors.GREEN)
print()
# Copy tgz to a simple name once for all examples to use
dist_js_dir = (project_root / "dist" / "js").resolve()
tgz_files = list(dist_js_dir.glob("*.tgz"))
if tgz_files:
examples_dir = Path(__file__).parent
simple_tgz_path = examples_dir / "cdk-github-runners.tgz"
shutil.copy2(tgz_files[0], simple_tgz_path)
print_colored(f" ✓ Copied package to {simple_tgz_path.name} for examples", Colors.GREEN)
print()
start_time = time.time()
print_colored("Running pnpm run package:python...", Colors.BLUE)
code, out, err = run_command([pnpm_path, "run", "package:python"], cwd=project_root)
duration = time.time() - start_time
if code != 0:
print_colored(f" ✗ Package Python failed: {err}\n{out}", Colors.RED)
print_colored("\nPackage building failed. Stopping.", Colors.RED)
return 1
print_colored(f" ✓ Package Python successful ({format_duration(duration)})", Colors.GREEN)
print()
# Find examples
print_colored("Finding examples...", Colors.BLUE)
filter_names = args.examples if args.examples else None
if filter_names:
print_colored(f"Filtering to examples: {', '.join(filter_names)}", Colors.BLUE)
ts_examples, py_examples = find_examples(filter_names=filter_names)
if not ts_examples and not py_examples:
print_colored("No examples found matching the filter.", Colors.RED)
return 1
print_colored(f"Found {len(ts_examples)} TypeScript examples", Colors.GREEN)
print_colored(f"Found {len(py_examples)} Python examples", Colors.GREEN)
print()
# Build a mapping of example names
example_names = set()
for ex in ts_examples:
example_names.add(Path(ex).name)
for ex in py_examples:
example_names.add(Path(ex).name)
# Phase 1: Synth all examples
ts_templates: Dict[str, str] = {}
py_templates: Dict[str, str] = {}
synth_errors: List[Tuple[str, str, str]] = [] # (example, lang, error)
comparison_errors: List[Tuple[str, str]] = [] # (example, diff)
if args.skip_synth:
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 1: Skipped (--skip-synth flag)", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 2: Skipped (--skip-synth flag)", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
else:
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 1: Synthesizing Examples", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
# Synth TypeScript examples
for example in ts_examples:
example_name = Path(example).name
print_colored(f"Synthing TypeScript: {example}", Colors.YELLOW)
success, template, error = synth_example(example, "typescript")
if success:
ts_templates[example_name] = template
print_colored(f" ✓ Success", Colors.GREEN)
else:
synth_errors.append((example, "TypeScript", error))
print_colored(f" ✗ Failed: {error}", Colors.RED)
print()
# Synth Python examples
for example in py_examples:
example_name = Path(example).name
print_colored(f"Synthing Python: {example}", Colors.YELLOW)
success, template, error = synth_example(example, "python")
if success:
py_templates[example_name] = template
print_colored(f" ✓ Success", Colors.GREEN)
else:
synth_errors.append((example, "Python", error))
print_colored(f" ✗ Failed: {error}", Colors.RED)
print()
# Phase 2: Compare templates
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 2: Comparing Templates", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
for example_name in example_names:
if example_name not in ts_templates:
print_colored(f"⚠ {example_name}: No TypeScript template", Colors.YELLOW)
continue
if example_name not in py_templates:
print_colored(f"⚠ {example_name}: No Python template", Colors.YELLOW)
continue
print_colored(f"Comparing {example_name}...", Colors.YELLOW)
match, diff = compare_templates(ts_templates[example_name], py_templates[example_name])
if match:
print_colored(f" ✓ Templates match", Colors.GREEN)
else:
comparison_errors.append((example_name, diff))
print_colored(f" ✗ Templates differ", Colors.RED)
# Show first 20 lines of diff
diff_lines = diff.split('\n')[:20]
for line in diff_lines:
if line.startswith('+'):
print_colored(f" {line}", Colors.GREEN)
elif line.startswith('-'):
print_colored(f" {line}", Colors.RED)
else:
print(f" {line}")
if len(diff.split('\n')) > 20:
remaining = len(diff.split('\n')) - 20
print_colored(f" ... ({remaining} more lines)", Colors.YELLOW)
print()
# Phase 3: Deploy and destroy TypeScript examples
deploy_errors: List[Tuple[str, str]] = [] # (example, error)
destroy_errors: List[Tuple[str, str]] = [] # (example, error)
if args.skip_deploy:
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 3: Skipped (--skip-deploy flag)", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
else:
print_colored("=" * 80, Colors.BOLD)
print_colored("Phase 3: Deploying and Destroying TypeScript Examples", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
# Only deploy examples that successfully synthesized (if synth was not skipped)
if args.skip_synth:
successful_ts_examples = ts_examples
else:
successful_ts_examples = [ex for ex in ts_examples if Path(ex).name in ts_templates]
for example in successful_ts_examples:
print_colored(f"Testing deployment: {example}", Colors.YELLOW)
# Deploy
success, error = deploy_example(example)
if not success:
deploy_errors.append((example, error))
print_colored(f" ✗ Deploy failed: {error}", Colors.RED)
print()
continue
print_colored(f" ✓ Deployed successfully", Colors.GREEN)
# Destroy
success, error = destroy_example(example)
if not success:
destroy_errors.append((example, error))
print_colored(f" ✗ Destroy failed: {error}", Colors.RED)
else:
print_colored(f" ✓ Destroyed successfully", Colors.GREEN)
print()
# Report skipped examples (only if synth was not skipped)
if not args.skip_synth:
skipped_examples = [ex for ex in ts_examples if Path(ex).name not in ts_templates]
if skipped_examples:
print_colored(f"Skipped {len(skipped_examples)} example(s) due to synthesis failures:", Colors.YELLOW)
for ex in skipped_examples:
print_colored(f" - {ex}", Colors.YELLOW)
print()
# Summary
print_colored("=" * 80, Colors.BOLD)
print_colored("Summary", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
total_errors = len(synth_errors) + len(comparison_errors) + len(deploy_errors) + len(destroy_errors)
if synth_errors:
print_colored(f"Synthesis Errors: {len(synth_errors)}", Colors.RED)
for example, lang, error in synth_errors:
print_colored(f" - {lang}: {example}", Colors.RED)
print(f" {error[:300]}...")
print()
if comparison_errors:
print_colored(f"Template Comparison Errors: {len(comparison_errors)}", Colors.RED)
for example, diff in comparison_errors:
print_colored(f" - {example}: Templates differ", Colors.RED)
print()
if deploy_errors:
print_colored(f"Deployment Errors: {len(deploy_errors)}", Colors.RED)
for example, error in deploy_errors:
print_colored(f" - {example}", Colors.RED)
print(f" {error[-500:]}...")
print()
if destroy_errors:
print_colored(f"Destroy Errors: {len(destroy_errors)}", Colors.RED)
for example, error in destroy_errors:
print_colored(f" - {example}", Colors.RED)
print(f" {error[-500:]}...")
print()
total_duration = time.time() - script_start_time
print_colored("=" * 80, Colors.BOLD)
print_colored(f"Total execution time: {format_duration(total_duration)}", Colors.BOLD)
print_colored("=" * 80, Colors.BOLD)
print()
if total_errors == 0:
print_colored("✓ All tests passed!", Colors.GREEN)
return 0
else:
print_colored(f"✗ {total_errors} error(s) found", Colors.RED)
return 1
if __name__ == "__main__":
sys.exit(main())