def validate_test_result(name: str, expect_fail: bool, test_result: TestResult):
    """Validate if the test result meets expectations"""
    if not test_result.result:
        test_result.passed = False
        test_result.validation_error = "No result returned"
        return

    test_result.passed = test_result.result.status == ResultStatus.SUCCESS
    # General validation logic
    if expect_fail:
        # Tests expected to fail should return a non-success status
        if test_result.passed:
            test_result.validation_error = "Expected failure but actually succeeded"
    else:
        # Tests expected to succeed should return a success status
        if not test_result.passed:
            test_result.validation_error = f"Unexpected failure (status={test_result.result.status})"
Validate if the test result meets expectations
sandbox/tests/sandbox_security_tests_full.py