| 1 | from __future__ import annotations |
| 2 | |
| 3 | from plugins._a0_connector.helpers import ws_runtime |
| 4 | |
| 5 | |
| 6 | def test_computer_use_metadata_preserves_structured_capabilities() -> None: |
| 7 | sid = "sid-capabilities" |
| 8 | ws_runtime.clear_sid_computer_use_metadata(sid) |
| 9 | |
| 10 | ws_runtime.store_sid_computer_use_metadata( |
| 11 | sid, |
| 12 | { |
| 13 | "supported": True, |
| 14 | "enabled": True, |
| 15 | "trust_mode": "allow", |
| 16 | "status": "active", |
| 17 | "last_error": "", |
| 18 | "restore_token_present": True, |
| 19 | "artifact_root": "/a0/tmp/_a0_connector/computer_use", |
| 20 | "backend_id": "windows", |
| 21 | "backend_family": "windows", |
| 22 | "features": ["native-window-list", "element-index-targeting"], |
| 23 | "contract_version": 1, |
| 24 | "capabilities": { |
| 25 | "contract_version": 1, |
| 26 | "identity": { |
| 27 | "pid": True, |
| 28 | "window_id": True, |
| 29 | "element_index": True, |
| 30 | }, |
| 31 | "dispatch": { |
| 32 | "default": "background", |
| 33 | "background": True, |
| 34 | }, |
| 35 | }, |
| 36 | "support_reason": "Windows UIA backend is available.", |
| 37 | }, |
| 38 | ) |
| 39 | |
| 40 | metadata = ws_runtime.computer_use_metadata_for_sid(sid) |
| 41 | |
| 42 | assert metadata is not None |
| 43 | assert metadata["contract_version"] == 1 |
| 44 | assert metadata["capabilities"]["identity"]["element_index"] is True |
| 45 | assert metadata["capabilities"]["dispatch"]["default"] == "background" |
| 46 | |
| 47 | metadata["capabilities"]["dispatch"]["default"] = "foreground" |
| 48 | fresh_metadata = ws_runtime.computer_use_metadata_for_sid(sid) |
| 49 | assert fresh_metadata is not None |
| 50 | assert fresh_metadata["capabilities"]["dispatch"]["default"] == "background" |
| 51 | |
| 52 | ws_runtime.clear_sid_computer_use_metadata(sid) |