if isinstance(elem, ast.FunctionDef):
            if elem.name == "serialize":
                method_def = elem
                break
    kwonly_args = [x.arg for x in method_def.args.kwonlyargs]
    for elem in ast.walk(method_def):
        if isinstance(elem, ast.Call):
            if getattr(elem.func, "attr", "") == "serialize":
                kwargs = {y.arg: y.value for y in elem.keywords}
                for name in kwonly_args:
                    if name not in kwargs or getattr(kwargs[name], "id", "") != name:
                        ref = f"{file}:{elem.lineno}"
                        message = (
                            f"Error at {ref}; recursive calls to `cls.serialize` "
                            f"must forward the `{name}` argument"
                        )
                        raise Exception(message)
                    valid_recursive_call_count += 1
    print(f"validated calls: {valid_recursive_call_count}")
    assert valid_recursive_call_count > 0
def test_strict_mode():
    """If strict=True, serialization should fail when object is not JSON serializable."""
    class Test:
        a = 1
    from airflow.serialization.serialized_objects import BaseSerialization
    obj = [[[Test()]]]  
    BaseSerialization.serialize(obj)  
    with pytest.raises(SerializationError, match="Encountered unexpected type"):
        BaseSerialization.serialize(obj, strict=True)