Skip to content

tvOS: RegularSnapshotTree's focus forward has no test through the runner's own traversal loop #4713

Open

Description

@thymikee

Purpose

RegularSnapshotTree.append decides which duplicate node survives a regular tvOS tree capture, and its tvOS branch forwards focused to the first surviving node. Nothing tests that branch through the code that runs on a device. The only tests reach the policy's identity function, or a harness that re-implements the walk. A regression in the guard, or in the loop that feeds it, reaches a tvOS Simulator undetected.

This splits out the two non-blocking notes from the review of #4700, which merged at b2338f377d.

Evidence

Source at origin/main (b2338f377d):

  • The device path is the runner's own traversal: RunnerTests+Snapshot.swift:228-250 pops a stack, builds each node, and calls regularTree.append(node, elementType: String(describing: snapshot.elementType), to: &nodes). A rejected node's children re-parent onto entry.parentIndex.
  • The focus forward lives only inside append: apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/RegularSnapshotTree.swift:45-54 sets nodes[firstIndex].focused = true when the policy is .tvOS, the duplicate is focused, its type is Other, it carries a label or identifier, it is a direct child of the survivor, and label and identifier match.
  • No test calls append. grep finds two call sites: the runner path above, and apple/snapshot-presentation/Sources/SnapshotPresentationConformance/main.swift:88-103. The conformance harness builds its own loop with its own childParents map and its own index re-numbering, so it covers append in isolation and never the stack loop, the currentIndex choice, or the re-parenting that fix(snapshot): revalidate Apple runner payloads with the producer's fold policy #4700's live capture exercised at three focus positions.
  • The only new XCTest is UnitTests/RunnerTests+SnapshotTraversalIdentityTests.swift, and it asserts on Policy.identity alone. It does not construct a duplicate pair and does not read the focus forward.
  • The published golden case replays append through the harness copy of the walk, so it agrees with the harness by construction and not with the runner.

Second note, verified before acting on it: the elementType argument is not a copy of node.type on the device path, and the two call sites already disagree. makeSnapshotNode sets type: elementTypeName(snapshot.elementType) (RunnerTests+SnapshotAcquisition.swift:246), which maps an XCUIElement.ElementType raw value through elementTypeNamesByRawValue and falls back to Element(<raw>) for an unmapped value (RunnerTests+Snapshot.swift:92-118, and #4657 files that table's incompleteness as its own bug). The runner passes String(describing: snapshot.elementType) instead (RunnerTests+Snapshot.swift:241). The conformance harness passes node.type (SnapshotPresentationConformance/main.swift:99). identity(elementType:…) builds the dedup key from the passed argument (RegularSnapshotTree.swift:20-26), while the focus guard compares node.type (:48), so the key text the runner dedups on and the key text the golden replay dedups on come from two different expressions, and neither is checked against the other. Whether the two expressions agree for each element type is not established here; no test compares them, and the table's Element(<raw>) fallback is the place they are known to differ. Replacing the parameter with node.type therefore changes the identity key on the device path, which is where the tvOS focus forward depends on that key. Treat that as a behavior change with its own evidence, not as a delete.

Required behavior

  • append has a regression test that drives the runner's own loop: a focused Other duplicate, direct child of a same-label survivor, arrives through the stack walk, and the capture names the survivor with focused: true and the duplicate's children under it. Cover at least the tvOS policy and one non-tvOS policy, so the branch's platform split stays pinned.
  • Drive it through the code the device runs, not through a copy of the walk. Either the runner unit-test target covers the loop, or the loop moves somewhere both the runner and the conformance executable link.
  • Leave the elementType parameter in place until a change shows the identity keys stay equal.

Completion conditions:

  • Removing the tvOS focus forward from append turns a test red without a device attached.
  • Changing currentIndex so a rejected node's children keep the rejected index turns a test red without a device attached.

Dependencies

Blocked by: none. #4654 and #4700 do not need this and neither is reopened by it.

Owner: RegularSnapshotTree and the runner snapshot traversal, with the conformance harness's copy of the walk as the thing to retire. The harness duplication is the root: while it exists, every new merge guard in append ships with a test that cannot fail for the wrong reason.

Activity

  1. added
    needs-triage
    on Nov 18, 2026
  2. apex-sentinel-staging commented on Nov 18, 2026

    @apex-sentinel-staging

    Apex Sentinel · Issue review

    Suggested label: feature

    The issue requests adding regression test coverage and possibly refactoring the snapshot traversal so the tvOS focus-forward path is tested through the runner's actual loop. It is not reporting current broken behavior, but it is a detailed, actionable test/infrastructure enhancement.

  3. added
    enhancement
    and removed
    needs-triage
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions