""" Cleanup the remaining test mapping and verify count """ import asyncio import sys sys.path.insert(0, r'C:\DEV\COPILOT\geutebruck-api\src\api\protos') import grpc import configuration_pb2 import configuration_pb2_grpc async def count_mappings(): channel = grpc.aio.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) try: request = configuration_pb2.ReadActionMappingsRequest() response = await stub.ReadActionMappings(request, timeout=10.0) await channel.close() return len(response.mappings) except Exception as e: await channel.close() return 0 async def delete_mapping(mapping_id): channel = grpc.aio.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) try: request = configuration_pb2.DeleteActionMappingRequest(mapping_id=mapping_id) response = await stub.DeleteActionMapping(request, timeout=10.0) await channel.close() return response.success except Exception as e: print(f"Error: {e}") await channel.close() return False async def main(): print("Cleaning up test mapping...") before = await count_mappings() print(f"Before: {before} mappings") # Delete mapping #62 success = await delete_mapping(62) if success: print("Deleted mapping #62") after = await count_mappings() print(f"After: {after} mappings") print(f"Delta: {before - after} (expected: 1)") if after == before - 1: print("[PASS] Delete worked correctly - no cascade!") else: print(f"[FAIL] Expected {before - 1}, got {after}") if __name__ == "__main__": asyncio.run(main())