From 46ae0dd8bfd268d75f6c146dfdd66dc39e6918e3 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 13 Oct 2025 15:18:24 +0000 Subject: [PATCH] test: add default-config-macro smoke test This uses an AI generated python script to diff the contents of the bots field of the default configuration file and the data/meta/default-config.yaml file. It emits a patch showing what needs to be changed. Signed-off-by: Xe Iaso --- .github/workflows/smoke-tests.yml | 1 + test/default-config-macro/compare_bots.py | 82 +++++++++++++++++++++++ test/default-config-macro/test.sh | 7 ++ 3 files changed, 90 insertions(+) create mode 100644 test/default-config-macro/compare_bots.py create mode 100755 test/default-config-macro/test.sh diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index ef1a834c..d34ee9bb 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -14,6 +14,7 @@ jobs: strategy: matrix: test: + - default-config-macro - double_slash - forced-language - git-clone diff --git a/test/default-config-macro/compare_bots.py b/test/default-config-macro/compare_bots.py new file mode 100644 index 00000000..edc04963 --- /dev/null +++ b/test/default-config-macro/compare_bots.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +Script to verify that the 'bots' field in data/botPolicies.yaml +has the same semantic contents as data/meta/default-config.yaml. + +CW: generated by AI +""" + +import yaml +import sys +import os +import subprocess +import difflib + +def load_yaml(file_path): + """Load YAML file and return the data.""" + try: + with open(file_path, 'r') as f: + return yaml.safe_load(f) + except Exception as e: + print(f"Error loading {file_path}: {e}") + sys.exit(1) + +def normalize_yaml(data): + """Normalize YAML data by removing comments and standardizing structure.""" + # For lists, just return as is, since YAML comments are stripped by safe_load + return data + +def get_repo_root(): + """Get the root directory of the git repository.""" + try: + result = subprocess.run(['git', 'rev-parse', '--show-toplevel'], capture_output=True, text=True, check=True) + return result.stdout.strip() + except subprocess.CalledProcessError: + print("Error: Not in a git repository") + sys.exit(1) + +def main(): + # Get the git repository root + repo_root = get_repo_root() + + # Paths relative to the repo root + bot_policies_path = os.path.join(repo_root, 'data', 'botPolicies.yaml') + default_config_path = os.path.join(repo_root, 'data', 'meta', 'default-config.yaml') + + # Load the files + bot_policies = load_yaml(bot_policies_path) + default_config = load_yaml(default_config_path) + + # Extract the 'bots' field from botPolicies.yaml + if 'bots' not in bot_policies: + print("Error: 'bots' field not found in botPolicies.yaml") + sys.exit(1) + bots_field = bot_policies['bots'] + + # The default-config.yaml is a list directly + default_bots = default_config + + # Normalize both + normalized_bots = normalize_yaml(bots_field) + normalized_default = normalize_yaml(default_bots) + + # Compare + if normalized_bots == normalized_default: + print("SUCCESS: The 'bots' field in botPolicies.yaml matches the contents of default-config.yaml") + sys.exit(0) + else: + print("FAILURE: The 'bots' field in botPolicies.yaml does not match the contents of default-config.yaml") + print("\nDiff:") + bots_yaml = yaml.dump(normalized_bots, default_flow_style=False) + default_yaml = yaml.dump(normalized_default, default_flow_style=False) + diff = difflib.unified_diff( + bots_yaml.splitlines(keepends=True), + default_yaml.splitlines(keepends=True), + fromfile='bots field in botPolicies.yaml', + tofile='default-config.yaml' + ) + print(''.join(diff)) + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test/default-config-macro/test.sh b/test/default-config-macro/test.sh new file mode 100755 index 00000000..6e0b7ab2 --- /dev/null +++ b/test/default-config-macro/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")" +python3 -c 'import yaml' +python3 ./compare_bots.py \ No newline at end of file