Repository navigation
Description
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-250pops a stack, builds each node, and callsregularTree.append(node, elementType: String(describing: snapshot.elementType), to: &nodes). A rejected node's children re-parent ontoentry.parentIndex. - The focus forward lives only inside
append:apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/RegularSnapshotTree.swift:45-54setsnodes[firstIndex].focused = truewhen the policy is.tvOS, the duplicate is focused, its type isOther, it carries a label or identifier, it is a direct child of the survivor, and label and identifier match. - No test calls
append.grepfinds two call sites: the runner path above, andapple/snapshot-presentation/Sources/SnapshotPresentationConformance/main.swift:88-103. The conformance harness builds its own loop with its ownchildParentsmap and its own index re-numbering, so it coversappendin isolation and never the stack loop, thecurrentIndexchoice, 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 onPolicy.identityalone. It does not construct a duplicate pair and does not read the focus forward. - The published golden case replays
appendthrough 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
appendhas a regression test that drives the runner's own loop: a focusedOtherduplicate, direct child of a same-label survivor, arrives through the stack walk, and the capture names the survivor withfocused: trueand 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
elementTypeparameter in place until a change shows the identity keys stay equal.
Completion conditions:
- Removing the tvOS focus forward from
appendturns a test red without a device attached. - Changing
currentIndexso 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
apex-sentinel-staging commentedon Nov 18, 2026
Apex Sentinel · Issue review
Suggested label:
featureThe 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.