|
| 1 | +"""Entry point for the install-smoke harness. See README.md.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import importlib |
| 6 | +import sys |
| 7 | + |
| 8 | + |
| 9 | +# Modules under each list MUST be importable with only that profile's |
| 10 | +# extras installed -- no leakage from other extras (grpc, http-server, |
| 11 | +# sql, signing, telemetry, vertex, etc.). Modules that require |
| 12 | +# optional extras must use try/except ImportError guards internally. |
| 13 | +CORE_MODULES = [ |
| 14 | + 'a2a', |
| 15 | + 'a2a.client', |
| 16 | + 'a2a.client.auth', |
| 17 | + 'a2a.client.base_client', |
| 18 | + 'a2a.client.card_resolver', |
| 19 | + 'a2a.client.client', |
| 20 | + 'a2a.client.client_factory', |
| 21 | + 'a2a.client.errors', |
| 22 | + 'a2a.client.interceptors', |
| 23 | + 'a2a.client.optionals', |
| 24 | + 'a2a.client.transports', |
| 25 | + 'a2a.server', |
| 26 | + 'a2a.server.agent_execution', |
| 27 | + 'a2a.server.context', |
| 28 | + 'a2a.server.events', |
| 29 | + 'a2a.server.request_handlers', |
| 30 | + 'a2a.server.tasks', |
| 31 | + 'a2a.types', |
| 32 | + 'a2a.utils', |
| 33 | + 'a2a.utils.constants', |
| 34 | + 'a2a.utils.error_handlers', |
| 35 | + 'a2a.utils.version_validator', |
| 36 | + 'a2a.utils.proto_utils', |
| 37 | + 'a2a.utils.task', |
| 38 | + 'a2a.helpers.agent_card', |
| 39 | + 'a2a.helpers.proto_helpers', |
| 40 | +] |
| 41 | + |
| 42 | +HTTP_SERVER_MODULES = [ |
| 43 | + 'a2a.server.routes', |
| 44 | + 'a2a.server.routes.agent_card_routes', |
| 45 | + 'a2a.server.routes.common', |
| 46 | + 'a2a.server.routes.jsonrpc_dispatcher', |
| 47 | + 'a2a.server.routes.jsonrpc_routes', |
| 48 | + 'a2a.server.routes.rest_dispatcher', |
| 49 | + 'a2a.server.routes.rest_routes', |
| 50 | +] |
| 51 | + |
| 52 | +GRPC_MODULES = [ |
| 53 | + 'a2a.server.request_handlers.grpc_handler', |
| 54 | + 'a2a.client.transports.grpc', |
| 55 | + 'a2a.compat.v0_3.grpc_handler', |
| 56 | + 'a2a.compat.v0_3.grpc_transport', |
| 57 | +] |
| 58 | + |
| 59 | +TELEMETRY_MODULES = [ |
| 60 | + 'a2a.utils.telemetry', |
| 61 | +] |
| 62 | + |
| 63 | +SQL_MODULES = [ |
| 64 | + 'a2a.server.models', |
| 65 | + 'a2a.server.tasks.database_task_store', |
| 66 | + 'a2a.server.tasks.database_push_notification_config_store', |
| 67 | +] |
| 68 | + |
| 69 | + |
| 70 | +PROFILES: dict[str, list[str]] = { |
| 71 | + 'base': CORE_MODULES, |
| 72 | + 'http-server': CORE_MODULES + HTTP_SERVER_MODULES, |
| 73 | + 'grpc': CORE_MODULES + GRPC_MODULES, |
| 74 | + 'telemetry': CORE_MODULES + TELEMETRY_MODULES, |
| 75 | + 'sql': CORE_MODULES + SQL_MODULES, |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +# Imported lazily in `main()` so a check that needs one profile's |
| 80 | +# extras can't break the harness when running a different profile. |
| 81 | +RUNTIME_CHECKS: dict[str, list[str]] = { |
| 82 | + 'base': ['tests.install_smoke.runtime.base_send_message'], |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +def main(argv: list[str]) -> int: |
| 87 | + profile = argv[1] if len(argv) > 1 else 'base' |
| 88 | + if profile not in PROFILES: |
| 89 | + print(f'Unknown profile {profile!r}. Available: {sorted(PROFILES)}') |
| 90 | + return 1 |
| 91 | + |
| 92 | + modules = PROFILES[profile] |
| 93 | + import_failures: list[str] = [] |
| 94 | + for module_name in modules: |
| 95 | + try: |
| 96 | + importlib.import_module(module_name) |
| 97 | + except Exception as e: # noqa: BLE001, PERF203 |
| 98 | + import_failures.append(f'{module_name}: {e}') |
| 99 | + |
| 100 | + print(f'Profile: {profile}') |
| 101 | + print(f'Tested {len(modules)} modules') |
| 102 | + print(f' Passed: {len(modules) - len(import_failures)}') |
| 103 | + print(f' Failed: {len(import_failures)}') |
| 104 | + |
| 105 | + if import_failures: |
| 106 | + print('\nFAILED imports:') |
| 107 | + for failure in import_failures: |
| 108 | + print(f' - {failure}') |
| 109 | + return 1 |
| 110 | + |
| 111 | + print('\nAll modules imported successfully.') |
| 112 | + |
| 113 | + runtime_checks = RUNTIME_CHECKS.get(profile, []) |
| 114 | + if not runtime_checks: |
| 115 | + return 0 |
| 116 | + |
| 117 | + print(f'\nRunning {len(runtime_checks)} runtime check(s):') |
| 118 | + runtime_failures: list[str] = [] |
| 119 | + for module_path in runtime_checks: |
| 120 | + label = module_path |
| 121 | + try: |
| 122 | + module = importlib.import_module(module_path) |
| 123 | + label = module.NAME |
| 124 | + module.check() |
| 125 | + except Exception as e: # noqa: BLE001, PERF203 |
| 126 | + runtime_failures.append(f'{label}: {type(e).__name__}: {e}') |
| 127 | + print(f' - FAIL: {label}') |
| 128 | + else: |
| 129 | + print(f' - OK: {label}') |
| 130 | + |
| 131 | + if runtime_failures: |
| 132 | + print('\nFAILED runtime checks:') |
| 133 | + for failure in runtime_failures: |
| 134 | + print(f' - {failure}') |
| 135 | + return 1 |
| 136 | + |
| 137 | + print('\nAll runtime checks passed.') |
| 138 | + return 0 |
| 139 | + |
| 140 | + |
| 141 | +if __name__ == '__main__': |
| 142 | + sys.exit(main(sys.argv)) |
0 commit comments