Skip to content

Commit d8fc195

Browse files
committed
fix the snapshot key and make the stable-id fixture insert ahead of the field
1 parent d26ed9d commit d8fc195

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎apps/desktop/native/computer-use/ComputerUse.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ final class Driver {
757757
return ["kind": "action", "action": "activate_app", "bundleId": app.bundleIdentifier!, "dispatched": true, "verified": true]
758758
case "get_app_state":
759759
try requireAccessibility()
760-
let app = try await appFor(p.bundleId, launch: true); let snapshot = Snapshot(app: app, previous: snapshots[p.bundleId])
760+
let app = try await appFor(p.bundleId, launch: true); let snapshot = Snapshot(app: app, previous: snapshots[app.bundleIdentifier!])
761761
let preferredFrame = try p.windowId.map { try windowRect($0, pid: app.processIdentifier) }
762762
try await snapshot.read(preferredWindowFrame: preferredFrame)
763763
let axWindows = snapshot.elements.values.filter { attribute($0, kAXRoleAttribute) as? String == kAXWindowRole }

‎apps/desktop/native/computer-use/tests/Fixture.swift‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ final class FixtureDelegate: NSObject, NSApplicationDelegate {
7878
NSApplication.shared.activate()
7979
print("fixture-ready"); fflush(stdout)
8080
}
81-
/// Inserts a label above every other control, so later elements move in traversal order.
82-
@objc func addRow() { stack.insertArrangedSubview(NSTextField(labelWithString: "Added row"), at: 0) }
81+
/// Adds a label ahead of every control in Accessibility order, so positional ids after it would all shift.
82+
@objc func addRow() {
83+
let row = NSTextField(labelWithString: "Added row"); row.frame = NSRect(x: 4, y: 4, width: 120, height: 18)
84+
window.contentView!.addSubview(row, positioned: .below, relativeTo: stack)
85+
}
8386
@objc func increment() { count += 1; counter.stringValue = "Count: \(count)" }
8487
@objc func showSheet() { let alert = NSAlert(); alert.messageText = "Fixture sheet"; alert.addButton(withTitle: "Dismiss"); alert.beginSheetModal(for: window) }
8588
@objc func timeChanged(_ picker: NSDatePicker) {

‎apps/desktop/native/computer-use/tests/live.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ def coordinate(snapshot, node, fx=0.5, fy=0.5):
8282
snapshot = state(screenshot=True)
8383
assert 'fixture-only-secret' not in json.dumps(snapshot), 'Secure value leaked'
8484
assert snapshot['truncated'] is False, 'Closed menu items past the snapshot cap marked the state truncated'
85-
field_id = find(snapshot, role='AXTextField', label='Fixture editable text')['elementId']
86-
mutate('click', snapshot, elementId=find(snapshot, role='AXButton', label='Add row')['elementId'])
87-
snapshot = state()
88-
assert any(node.get('value', node.get('label')) == 'Added row' for node in snapshot['nodes']), 'Add row did not insert its label'
89-
assert find(snapshot, role='AXTextField', label='Fixture editable text')['elementId'] == field_id, 'An element changed id when another was added above it'
9085
infinite = find(snapshot, label='Fixture infinite frame')
9186
assert not {'x', 'y', 'width', 'height'} & infinite.keys(), f'An infinite frame reached the reply: {infinite}'
9287
image = snapshot.get('screenshot')
@@ -96,6 +91,11 @@ def coordinate(snapshot, node, fx=0.5, fy=0.5):
9691
else:
9792
assert 'screen_capture_permission_required' in snapshot.get('screenshotError', '')
9893
print('BLOCKED: screenshot verification skipped because Screen Recording grant is missing', flush=True)
94+
field_id = find(snapshot, role='AXTextField', label='Fixture editable text')['elementId']
95+
mutate('click', snapshot, elementId=find(snapshot, role='AXButton', label='Add row')['elementId'])
96+
snapshot = state()
97+
assert any(node.get('value', node.get('label')) == 'Added row' for node in snapshot['nodes']), 'Add row did not insert its label'
98+
assert find(snapshot, role='AXTextField', label='Fixture editable text')['elementId'] == field_id, 'An element changed id when another was added above it'
9999
baseline = int(next(node.get('value', node.get('label', '')) for node in snapshot['nodes'] if node.get('value', node.get('label', '')).startswith('Count: ')).split(': ')[1])
100100
button = find(snapshot, role='AXButton', label='Increment')
101101
snapshot = mutate('click', snapshot, elementId=button['elementId'])

0 commit comments

Comments
 (0)