Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 2.57 KB

File metadata and controls

64 lines (46 loc) · 2.57 KB

Accessibility Identifier Generation Investigation

Problem Summary

707 tests are failing because accessibility identifiers are not being generated. Tests expect identifiers but get empty strings.

Root Cause Analysis

The Issue

The AutomaticComplianceModifier uses an EnvironmentAccessor helper view that only executes when the view is actually installed in a view hierarchy. In test environments:

  1. ViewInspector: When using ViewInspector.inspect(), the view might not be fully rendered/installed, so the modifier body never executes.

  2. Platform View Hosting: When using UIHostingController/NSHostingController in tests without a proper window hierarchy, the view might not be fully rendered, so the modifier body never executes.

  3. SwiftUI Modifier Lazy Evaluation: SwiftUI modifiers are lazy - they only execute their body when the view is actually rendered. Without proper rendering, identifiers are never generated.

The Modifier Structure

public struct AutomaticComplianceModifier: ViewModifier {
    public func body(content: Content) -> some View {
        EnvironmentAccessor(content: content)  // Helper view
    }
    
    private struct EnvironmentAccessor: View {
        // Environment access happens here
        // Only executes when view is installed in hierarchy
        var body: some View {
            // Identifier generation happens here
        }
    }
}

Test Helper Flow

  1. Test creates view with .automaticCompliance()
  2. Test helper wraps view with environment: .environment(\.globalAutomaticAccessibilityIdentifiers, true)
  3. View is inspected/hosted
  4. PROBLEM: Modifier body might not execute if view isn't fully rendered

Potential Solutions

Option 1: Force View Rendering

Force the view to render by:

  • Adding the hosting controller to a window/view hierarchy
  • Calling layout methods (but this can hang in tests)
  • Using a different inspection method

Option 2: Pre-generate Identifiers

Generate identifiers eagerly when the modifier is applied, not lazily when the view renders.

Option 3: Test-Specific Identifier Generation

Create a test-specific path that generates identifiers without requiring full view rendering.

Option 4: Fix Environment Setup

Ensure the environment is properly set up before the view is created, and ensure the config is available via task-local.

Next Steps

  1. Verify if modifier body is being called in tests
  2. Check if environment is properly available when modifier runs
  3. Determine if we need to force rendering or change the approach
  4. Implement fix based on findings