From 0a66a21da5dad07cef81bb727f1e783eb125ad24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribal=20del=20R=C3=ADo?= Date: Thu, 5 Mar 2026 12:57:15 +0100 Subject: [PATCH 1/2] chore(adj-validator): copy ADJ-Validator from test-adj --- .github/workflows/adj-tester.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/adj-tester.yaml b/.github/workflows/adj-tester.yaml index 891756a..9bc7507 100644 --- a/.github/workflows/adj-tester.yaml +++ b/.github/workflows/adj-tester.yaml @@ -24,7 +24,7 @@ jobs: - name: Run ADJ validation run: | - python3 .github/workflows/scripts/adj-tester/main.py > /dev/null 2>&1 + python3 .github/workflows/scripts/adj-tester/main.py - name: Notify Slack on failure if: failure() From b24c5e87df703307bb53d25158dc62a3ecf2ee0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribal=20del=20R=C3=ADo?= Date: Sat, 14 Mar 2026 22:59:15 +0100 Subject: [PATCH 2/2] chore(adj-validator): copy ADJ-Validator from test-adj --- .github/workflows/scripts/adj-tester/main.py | 19 ++++++++--- .github/workflows/scripts/adj-tester/utils.py | 32 ++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scripts/adj-tester/main.py b/.github/workflows/scripts/adj-tester/main.py index dc25c9b..99b925c 100755 --- a/.github/workflows/scripts/adj-tester/main.py +++ b/.github/workflows/scripts/adj-tester/main.py @@ -2,7 +2,7 @@ ADJ Validator -Version: 11.1.2 +Version: 11.1.3 JavierRibaldelRio @@ -13,6 +13,7 @@ (e.g. uniqueness constraints and IPv4 validation). """ +import argparse import sys from pathlib import Path @@ -23,7 +24,7 @@ is_valid_ipv4, print_results, logError, - info_message, + set_color_enabled, validate_with_schema, ) @@ -452,10 +453,10 @@ def check_packet_json( has_period_type = "period_type" in pkt has_period = "period" in pkt has_socket = "socket" in pkt - + # Count how many of the three fields are present fields_present = sum([has_period_type, has_period, has_socket]) - + # If any field is present, all three must be present if fields_present > 0 and fields_present < 3: error_list.append( @@ -598,6 +599,16 @@ def main(): non-zero status code if any validation step fails. """ + parser = argparse.ArgumentParser(description="Validate ADJ JSON schemas") + parser.add_argument( + "--no-color", + action="store_true", + help="Disable ANSI color codes in output", + ) + args = parser.parse_args() + + set_color_enabled(not args.no_color) + # App header print_header("JSON Validation Script") diff --git a/.github/workflows/scripts/adj-tester/utils.py b/.github/workflows/scripts/adj-tester/utils.py index eb01ab5..71fcba5 100644 --- a/.github/workflows/scripts/adj-tester/utils.py +++ b/.github/workflows/scripts/adj-tester/utils.py @@ -10,6 +10,22 @@ from pathlib import Path from jsonschema import Draft7Validator +# Global switch to control whether ANSI colors are used in output. +# This is controlled from CLI via the `--no-color` flag. +ENABLE_COLOR = True + + +def set_color_enabled(enabled: bool): + """Enable or disable ANSI color output. + + Args: + enabled: If False, all helper output functions will omit ANSI + escape sequences. + """ + + global ENABLE_COLOR + ENABLE_COLOR = enabled + def print_header(header: str): """Print a simple boxed header to stdout. @@ -39,10 +55,14 @@ def format_status(message: str, validated: bool = False): red "Failed". """ + if not ENABLE_COLOR: + result = "Passed" if validated else "Failed" + return f"{message} {result}" + # ANSI color codes used for terminal output if not validated: result = "\033[31mFailed\033[0m" # red - elif validated: + else: result = "\033[32mPassed\033[0m" # green return f"{message} {result}" @@ -51,6 +71,9 @@ def format_status(message: str, validated: bool = False): def info_message(message: str): """format to blue color and return the message string.""" + if not ENABLE_COLOR: + return message + return f"\033[34m{message}\033[0m" @@ -69,6 +92,10 @@ def log_message(message: str, status: int = 0): (success). """ + if not ENABLE_COLOR: + print(message) + return + colors = {-1: "\033[31m", 1: "\033[32m"} color = colors.get(status, "") reset = "\033[0m" if color else "" @@ -143,6 +170,9 @@ def logError(label: str, path: str, message: str): single formatted string instead of printing directly. """ + if not ENABLE_COLOR: + return f"{label}: {path} → {message}" + return f"\033[31m{label}: {path} → {message}\033[0m"