inspect-ai 0.3.74__py3-none-any.whl → 0.3.76__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. inspect_ai/__init__.py +3 -2
  2. inspect_ai/_cli/cache.py +1 -1
  3. inspect_ai/_cli/common.py +15 -0
  4. inspect_ai/_cli/eval.py +4 -5
  5. inspect_ai/_cli/log.py +1 -1
  6. inspect_ai/_cli/sandbox.py +1 -1
  7. inspect_ai/_cli/trace.py +1 -1
  8. inspect_ai/_cli/view.py +1 -1
  9. inspect_ai/_display/core/config.py +3 -1
  10. inspect_ai/_eval/eval.py +55 -61
  11. inspect_ai/_eval/evalset.py +64 -154
  12. inspect_ai/_eval/loader.py +27 -54
  13. inspect_ai/_eval/registry.py +4 -15
  14. inspect_ai/_eval/run.py +7 -4
  15. inspect_ai/_eval/task/__init__.py +8 -2
  16. inspect_ai/_eval/task/log.py +9 -1
  17. inspect_ai/_eval/task/resolved.py +35 -0
  18. inspect_ai/_eval/task/run.py +4 -0
  19. inspect_ai/_eval/task/task.py +50 -69
  20. inspect_ai/_eval/task/tasks.py +30 -0
  21. inspect_ai/_util/constants.py +3 -0
  22. inspect_ai/_util/dotenv.py +17 -0
  23. inspect_ai/_util/logger.py +3 -0
  24. inspect_ai/_util/registry.py +43 -2
  25. inspect_ai/_view/server.py +28 -10
  26. inspect_ai/_view/www/dist/assets/index.css +32 -19
  27. inspect_ai/_view/www/dist/assets/index.js +17682 -29989
  28. inspect_ai/_view/www/log-schema.json +79 -9
  29. inspect_ai/_view/www/package.json +2 -2
  30. inspect_ai/_view/www/src/appearance/styles.ts +6 -5
  31. inspect_ai/_view/www/src/components/AnsiDisplay.tsx +2 -2
  32. inspect_ai/_view/www/src/constants.ts +3 -0
  33. inspect_ai/_view/www/src/logfile/remoteZipFile.ts +141 -20
  34. inspect_ai/_view/www/src/plan/PlanDetailView.tsx +2 -1
  35. inspect_ai/_view/www/src/samples/SampleSummaryView.tsx +1 -1
  36. inspect_ai/_view/www/src/samples/chat/tools/tool.ts +7 -5
  37. inspect_ai/_view/www/src/samples/descriptor/score/CategoricalScoreDescriptor.tsx +1 -1
  38. inspect_ai/_view/www/src/samples/descriptor/score/NumericScoreDescriptor.tsx +2 -2
  39. inspect_ai/_view/www/src/samples/error/FlatSampleErrorView.module.css +1 -0
  40. inspect_ai/_view/www/src/samples/error/FlatSampleErrorView.tsx +3 -1
  41. inspect_ai/_view/www/src/samples/sample-tools/SortFilter.tsx +1 -1
  42. inspect_ai/_view/www/src/samples/sample-tools/sample-filter/SampleFilter.tsx +5 -2
  43. inspect_ai/_view/www/src/samples/transcript/ModelEventView.module.css +2 -2
  44. inspect_ai/_view/www/src/samples/transcript/state/StateEventView.tsx +5 -1
  45. inspect_ai/_view/www/src/types/log.d.ts +11 -5
  46. inspect_ai/_view/www/src/workspace/navbar/PrimaryBar.tsx +17 -12
  47. inspect_ai/_view/www/src/workspace/sidebar/SidebarLogEntry.tsx +2 -1
  48. inspect_ai/_view/www/yarn.lock +12 -5
  49. inspect_ai/log/_log.py +10 -1
  50. inspect_ai/log/_recorders/eval.py +27 -8
  51. inspect_ai/log/_recorders/json.py +10 -2
  52. inspect_ai/log/_transcript.py +13 -4
  53. inspect_ai/model/_call_tools.py +13 -4
  54. inspect_ai/model/_chat_message.py +15 -1
  55. inspect_ai/model/_model.py +30 -12
  56. inspect_ai/model/_model_output.py +6 -1
  57. inspect_ai/model/_openai.py +11 -6
  58. inspect_ai/model/_providers/anthropic.py +167 -77
  59. inspect_ai/model/_providers/google.py +6 -2
  60. inspect_ai/model/_providers/none.py +31 -0
  61. inspect_ai/model/_providers/openai.py +11 -8
  62. inspect_ai/model/_providers/providers.py +7 -0
  63. inspect_ai/model/_providers/vertex.py +5 -2
  64. inspect_ai/solver/_bridge/bridge.py +1 -1
  65. inspect_ai/solver/_chain.py +7 -6
  66. inspect_ai/tool/__init__.py +4 -0
  67. inspect_ai/tool/_tool_call.py +5 -2
  68. inspect_ai/tool/_tool_support_helpers.py +200 -0
  69. inspect_ai/tool/_tools/_bash_session.py +119 -0
  70. inspect_ai/tool/_tools/_computer/_computer.py +1 -1
  71. inspect_ai/tool/_tools/_text_editor.py +121 -0
  72. inspect_ai/tool/_tools/_web_browser/_back_compat.py +150 -0
  73. inspect_ai/tool/_tools/_web_browser/_web_browser.py +75 -130
  74. inspect_ai/tool/_tools/_web_search.py +2 -2
  75. inspect_ai/util/_json.py +28 -0
  76. inspect_ai/util/_sandbox/context.py +18 -8
  77. inspect_ai/util/_sandbox/docker/config.py +1 -1
  78. inspect_ai/util/_sandbox/docker/internal.py +3 -3
  79. inspect_ai/util/_sandbox/environment.py +17 -2
  80. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info}/METADATA +8 -5
  81. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info}/RECORD +85 -108
  82. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info}/WHEEL +1 -1
  83. inspect_ai/tool/_tools/_web_browser/_resources/.pylintrc +0 -8
  84. inspect_ai/tool/_tools/_web_browser/_resources/.vscode/launch.json +0 -24
  85. inspect_ai/tool/_tools/_web_browser/_resources/.vscode/settings.json +0 -25
  86. inspect_ai/tool/_tools/_web_browser/_resources/Dockerfile +0 -22
  87. inspect_ai/tool/_tools/_web_browser/_resources/README.md +0 -63
  88. inspect_ai/tool/_tools/_web_browser/_resources/accessibility_tree.py +0 -71
  89. inspect_ai/tool/_tools/_web_browser/_resources/accessibility_tree_node.py +0 -323
  90. inspect_ai/tool/_tools/_web_browser/_resources/cdp/__init__.py +0 -5
  91. inspect_ai/tool/_tools/_web_browser/_resources/cdp/a11y.py +0 -279
  92. inspect_ai/tool/_tools/_web_browser/_resources/cdp/dom.py +0 -9
  93. inspect_ai/tool/_tools/_web_browser/_resources/cdp/dom_snapshot.py +0 -293
  94. inspect_ai/tool/_tools/_web_browser/_resources/cdp/page.py +0 -94
  95. inspect_ai/tool/_tools/_web_browser/_resources/constants.py +0 -2
  96. inspect_ai/tool/_tools/_web_browser/_resources/images/usage_diagram.svg +0 -2
  97. inspect_ai/tool/_tools/_web_browser/_resources/mock_environment.py +0 -45
  98. inspect_ai/tool/_tools/_web_browser/_resources/playwright_browser.py +0 -50
  99. inspect_ai/tool/_tools/_web_browser/_resources/playwright_crawler.py +0 -48
  100. inspect_ai/tool/_tools/_web_browser/_resources/playwright_page_crawler.py +0 -280
  101. inspect_ai/tool/_tools/_web_browser/_resources/pyproject.toml +0 -65
  102. inspect_ai/tool/_tools/_web_browser/_resources/rectangle.py +0 -64
  103. inspect_ai/tool/_tools/_web_browser/_resources/rpc_client_helpers.py +0 -146
  104. inspect_ai/tool/_tools/_web_browser/_resources/scale_factor.py +0 -64
  105. inspect_ai/tool/_tools/_web_browser/_resources/test_accessibility_tree_node.py +0 -180
  106. inspect_ai/tool/_tools/_web_browser/_resources/test_playwright_crawler.py +0 -99
  107. inspect_ai/tool/_tools/_web_browser/_resources/test_rectangle.py +0 -15
  108. inspect_ai/tool/_tools/_web_browser/_resources/test_web_client.py +0 -44
  109. inspect_ai/tool/_tools/_web_browser/_resources/web_browser_rpc_types.py +0 -39
  110. inspect_ai/tool/_tools/_web_browser/_resources/web_client.py +0 -214
  111. inspect_ai/tool/_tools/_web_browser/_resources/web_client_new_session.py +0 -35
  112. inspect_ai/tool/_tools/_web_browser/_resources/web_server.py +0 -192
  113. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info}/entry_points.txt +0 -0
  114. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info/licenses}/LICENSE +0 -0
  115. {inspect_ai-0.3.74.dist-info → inspect_ai-0.3.76.dist-info}/top_level.txt +0 -0
@@ -1,146 +0,0 @@
1
- """
2
- This module provides helper functions and classes for making strongly typed RPC calls.
3
-
4
- The module is designed to be generic and should not contain any use case specific logic.
5
- It uses the `httpx` library for making HTTP requests, `jsonrpcclient` for handling JSON-RPC responses,
6
- and `pydantic` for validating and parsing response data into Python objects.
7
-
8
- Classes:
9
- RPCError: Custom exception for handling RPC errors.
10
-
11
- Functions:
12
- typed_rpc_call: Makes a typed RPC call and returns the response as a Pydantic model.
13
- """
14
-
15
- from typing import Generic, Mapping, Type, TypedDict, TypeVar
16
-
17
- from httpx import (
18
- URL,
19
- Client,
20
- ConnectError,
21
- ConnectTimeout,
22
- HTTPStatusError,
23
- ReadTimeout,
24
- Response,
25
- )
26
- from jsonrpcclient import Error, Ok, parse, request
27
- from pydantic import BaseModel
28
- from tenacity import (
29
- retry,
30
- retry_if_exception,
31
- stop_after_attempt,
32
- stop_after_delay,
33
- wait_exponential_jitter,
34
- )
35
-
36
-
37
- class RPCError(RuntimeError):
38
- def __init__(self, *, code: int, message: str, data: object):
39
- self.code = code
40
- self.message = message
41
- self.data = data
42
- super().__init__(f"RPCError {code}: {message}")
43
-
44
- def __str__(self):
45
- return f"RPCError {self.code}: {self.message} (data: {self.data})"
46
-
47
-
48
- TBaseModel = TypeVar("TBaseModel", bound=BaseModel)
49
-
50
-
51
- def rpc_call(
52
- url: URL | str,
53
- method: str,
54
- params: dict[str, object] | None,
55
- response_class: Type[TBaseModel],
56
- ) -> TBaseModel:
57
- """
58
- Makes an RPC call to the specified URL with the given method and parameters, and returns the response as a parsed and validated instance of the specified response class.
59
-
60
- Args:
61
- url (URL | str): The URL to which the RPC call is made.
62
- method (str): The RPC method to be called.
63
- response_class (Type[TBaseModel]): The class to which the response should be deserialized.
64
- params (dict[str, object] | None, optional): The parameters to be sent with the RPC call. Defaults to None.
65
-
66
- Returns:
67
- TBaseModel: An instance of the response class containing the result of the RPC call.
68
-
69
- Raises:
70
- RPCError: If the RPC call returns an error response.
71
- RuntimeError: If an unexpected response is received.
72
- """
73
- match parse(_retrying_post(url, request(method, params)).json()):
74
- case Ok(ok_result):
75
- return response_class(**ok_result)
76
- case Error(code, message, data):
77
- raise RPCError(code=code, message=message, data=data)
78
- case _:
79
- raise RuntimeError("how did we get here")
80
-
81
-
82
- def _retrying_post(url: URL | str, json: object | None = None) -> Response:
83
- max_retries = 3
84
- total_timeout = 180
85
-
86
- @retry(
87
- wait=wait_exponential_jitter(),
88
- stop=(stop_after_attempt(max_retries) | stop_after_delay(total_timeout)),
89
- retry=retry_if_exception(httpx_should_retry),
90
- )
91
- def do_post() -> Response:
92
- with Client() as client:
93
- return client.post(url, json=json, timeout=30)
94
-
95
- return do_post()
96
-
97
-
98
- RPCArgsType = Type[Mapping[str, object]]
99
-
100
-
101
- class RPCCallTypes(TypedDict, Generic[TBaseModel]):
102
- args_type: RPCArgsType
103
- response_class: Type[TBaseModel]
104
-
105
-
106
- # TODO: cloned from inspect_ai repo code that is unavailable in the container
107
- # fix this by copying that source file into the container
108
- def httpx_should_retry(ex: BaseException) -> bool:
109
- """Check whether an exception raised from httpx should be retried.
110
-
111
- Implements the strategy described here: https://cloud.google.com/storage/docs/retry-strategy
112
-
113
- Args:
114
- ex (BaseException): Exception to examine for retry behavior
115
-
116
- Returns:
117
- True if a retry should occur
118
- """
119
- # httpx status exception
120
- if isinstance(ex, HTTPStatusError):
121
- # request timeout
122
- if ex.response.status_code == 408:
123
- return True
124
- # lock timeout
125
- elif ex.response.status_code == 409:
126
- return True
127
- # rate limit
128
- elif ex.response.status_code == 429:
129
- return True
130
- # internal errors
131
- elif ex.response.status_code >= 500:
132
- return True
133
- else:
134
- return False
135
-
136
- # connection error
137
- elif is_httpx_connection_error(ex):
138
- return True
139
-
140
- # don't retry
141
- else:
142
- return False
143
-
144
-
145
- def is_httpx_connection_error(ex: BaseException) -> bool:
146
- return isinstance(ex, ConnectTimeout | ConnectError | ConnectionError | ReadTimeout)
@@ -1,64 +0,0 @@
1
- import subprocess
2
- import sys
3
-
4
- # Playwright launches Chromium with --force-device-scale-factor=1 by default, which
5
- # ensures consistent rendering and measurement behavior using CSS pixels instead of
6
- # native device pixels, regardless of the actual display's DPI. On HiDPI displays,
7
- # like Apple Retina, the ratio of native pixels to CSS pixels is typically 2x or even 3x.
8
- #
9
- # However, the Chrome DevTools Protocol (CDP) has an inconsistency when running on
10
- # HiDPI devices with --force-device-scale-factor=1. Although window.devicePixelRatio
11
- # correctly reports as 1 (honoring the forced scale factor), CDP's LayoutTreeSnapshot.bounds
12
- # still returns coordinates in native device pixels without applying the forced scale factor,
13
- # resulting in a mismatch between CSS and native pixels.
14
- #
15
- # To work around this inconsistency, we determine the native scale factor independently
16
- # of browser-reported values, using system-level data via the get_screen_scale_factor helper
17
- # function. We then apply this actual scale factor to adjust the window bounds, ensuring
18
- # they are in the same coordinate space as LayoutTreeSnapshot.bounds. This alignment
19
- # allows the code to accurately calculate node visibility.
20
-
21
-
22
- def get_screen_scale_factor() -> float:
23
- if sys.platform == "darwin":
24
- from AppKit import NSScreen
25
-
26
- return NSScreen.mainScreen().backingScaleFactor()
27
- elif sys.platform == "win32":
28
- try:
29
- # Using GetDpiForSystem from Windows API
30
- import ctypes
31
-
32
- user32 = ctypes.windll.user32
33
- user32.SetProcessDPIAware()
34
- return user32.GetDpiForSystem() / 96.0
35
- except Exception:
36
- return 1.0
37
- elif sys.platform.startswith("linux"):
38
- try:
39
- # Try to get scaling from gsettings (GNOME)
40
- result = subprocess.run(
41
- ["gsettings", "get", "org.gnome.desktop.interface", "scaling-factor"],
42
- capture_output=True,
43
- text=True,
44
- )
45
- if result.returncode == 0:
46
- return float(result.stdout.strip())
47
-
48
- # Try to get scaling from xrandr (X11)
49
- result = subprocess.run(
50
- ["xrandr", "--current"], capture_output=True, text=True
51
- )
52
- if result.returncode == 0:
53
- # Parse xrandr output to find scaling
54
- # This is a simplified check - might need adjustment
55
- for line in result.stdout.splitlines():
56
- if "connected primary" in line and "x" in line:
57
- # Look for something like "3840x2160+0+0"
58
- resolution = line.split()[3].split("+")[0]
59
- if "3840x2160" in resolution: # 4K
60
- return 2.0
61
- return 1.0
62
- except Exception:
63
- return 1.0
64
- return 1.0 # Default fallback
@@ -1,180 +0,0 @@
1
- from cdp.dom_snapshot import (
2
- DocumentSnapshot,
3
- DOMSnapshot,
4
- LayoutTreeSnapshot,
5
- NodeTreeSnapshot,
6
- RareBooleanData,
7
- StringIndex,
8
- TextBoxSnapshot,
9
- )
10
-
11
- simple_node_tree = NodeTreeSnapshot()
12
- simple_layout_tree = LayoutTreeSnapshot(
13
- nodeIndex=(),
14
- styles=(),
15
- bounds=(),
16
- text=(),
17
- stackingContexts=RareBooleanData(index=()),
18
- )
19
- simple_text_boxes = TextBoxSnapshot(layoutIndex=(), bounds=(), start=(), length=())
20
- simple_doc_snapshot = DocumentSnapshot(
21
- documentURL=StringIndex(0),
22
- title=StringIndex(1),
23
- baseURL=StringIndex(0),
24
- contentLanguage=StringIndex(2),
25
- encodingName=StringIndex(3),
26
- publicId=StringIndex(666),
27
- systemId=StringIndex(666),
28
- frameId=StringIndex(666),
29
- nodes=simple_node_tree,
30
- layout=simple_layout_tree,
31
- textBoxes=simple_text_boxes,
32
- )
33
- simple_dom_snapshot = DOMSnapshot(
34
- documents=(), strings=("documentUrl", "title", "contentLanguage", "encoding")
35
- )
36
-
37
- # THIS TEST MODULE IS DISABLED FOR NOW. IT WILL COME BACK
38
-
39
- # def test_foo():
40
- # ax_node = cast(
41
- # AXNode,
42
- # {"nodeId": "666", "name": {"value": "Test"}, "role": {"value": "button"}},
43
- # )
44
- # ax_nodes = {ax_node.nodeId: ax_node}
45
- # nodes: dict[AXNodeId, AccessibilityTreeNode] = {}
46
- # snapshot_context = create_snapshot_context(simple_dom_snapshot)
47
- # window_bounds = Rectangle(0, 0, 1024, 768)
48
-
49
- # node = AccessibilityTreeNode(
50
- # ax_node={"name": {"value": "Test"}, "role": {"value": "button"}},
51
- # ax_nodes=ax_nodes,
52
- # parent=None,
53
- # all_accessibility_tree_nodes=nodes,
54
- # snapshot_context=snapshot_context,
55
- # device_scale_factor=1,
56
- # window_bounds=window_bounds,
57
- # )
58
-
59
-
60
- # class TestAccessibilityTreeNode(absltest.TestCase):
61
- # def test_getitem(self):
62
- # node_data = {"name": {"value": "Test"}, "role": {"value": "button"}}
63
- # node = AccessibilityTreeNode(node_data)
64
- # self.assertEqual(node["name"], {"value": "Test"})
65
- # self.assertEqual(node["role"], {"value": "button"})
66
- # self.assertIsNone(node["invalid_key"])
67
-
68
- # def test_setitem(self):
69
- # node_data = {"name": {"value": "Test"}}
70
- # node = AccessibilityTreeNode(node_data)
71
- # node["role"] = {"value": "button"}
72
- # self.assertEqual(
73
- # node._node, {"name": {"value": "Test"}, "role": {"value": "button"}}
74
- # )
75
-
76
- # def test_str_role_name(self):
77
- # node_data = {
78
- # "nodeId": "1",
79
- # "role": {"value": "button"},
80
- # "name": {"value": "Test Button"},
81
- # }
82
- # node = AccessibilityTreeNode(node_data, bounds=Rectangle(10, 10, 20, 20))
83
- # self.assertIn('[1] button "Test Button"', str(node))
84
-
85
- # def test_str_image_src(self):
86
- # node_data = {
87
- # "nodeId": "1",
88
- # "role": {"value": "image"},
89
- # "name": {"value": "Test Image"},
90
- # "src": "image.png",
91
- # }
92
- # node = AccessibilityTreeNode(node_data, bounds=Rectangle(10, 10, 20, 20))
93
- # self.assertIn('[1] image "Test Image" image.png', str(node))
94
-
95
- # def test_str_property(self):
96
- # node_data = {
97
- # "nodeId": "1",
98
- # "role": {"value": "link"},
99
- # "name": {"value": "Test Link"},
100
- # "properties": [{"name": "url", "value": {"value": "www.example.com"}}],
101
- # }
102
- # node = AccessibilityTreeNode(node_data, bounds=Rectangle(10, 10, 20, 20))
103
- # self.assertIn('[1] link "Test Link" [url: www.example.com]', str(node))
104
-
105
- # def test_str_empty(self):
106
- # node_data = {"nodeId": "1"}
107
- # node = AccessibilityTreeNode(node_data)
108
- # self.assertIn('[*] ""', str(node))
109
-
110
- # def test_link_children(self):
111
- # node_data = {"nodeId": "1", "childIds": [2, 3]}
112
- # node = AccessibilityTreeNode(node_data)
113
- # child1 = AccessibilityTreeNode({"nodeId": "2"})
114
- # child2 = AccessibilityTreeNode({"nodeId": "3"})
115
- # node_lookup = {2: child1, 3: child2}
116
- # node.link_children(node_lookup)
117
-
118
- # self.assertEqual(node.children, [child1, child2])
119
- # self.assertEqual(child1._parent, node)
120
- # self.assertEqual(child2._parent, node)
121
-
122
- # def test_get_property(self):
123
- # node_data = {"name": {"value": "Test"}, "role": {"value": "button"}}
124
- # node = AccessibilityTreeNode(node_data)
125
- # self.assertEqual(node.get_property("name"), {"value": "Test"})
126
- # self.assertEqual(node.get_property("role"), {"value": "button"})
127
- # self.assertIsNone(node.get_property("invalid_key"))
128
-
129
- # def test_render(self):
130
- # node_data = {
131
- # "nodeId": "1",
132
- # "ignored": False,
133
- # "childIds": [2],
134
- # "role": {"value": "button"},
135
- # "name": {"value": "Test Button"},
136
- # }
137
- # node = AccessibilityTreeNode(node_data, bounds=Rectangle(20, 20, 30, 30))
138
- # self.assertIn('[1] button "Test Button"', node.render())
139
-
140
- # def test_to_render_with_children(self):
141
- # node_data = {
142
- # "nodeId": "1",
143
- # "ignored": False,
144
- # "childIds": [2, 3],
145
- # "role": {"value": "button"},
146
- # "name": {"value": "Test Button"},
147
- # }
148
- # node = AccessibilityTreeNode(node_data, bounds=Rectangle(20, 20, 30, 30))
149
- # child_data = {
150
- # "nodeId": "2",
151
- # "ignored": False,
152
- # "role": {"value": "text"},
153
- # "name": {"value": "Child Text"},
154
- # }
155
- # child = AccessibilityTreeNode(child_data, bounds=Rectangle(20, 20, 30, 30))
156
- # ignored_child_data = {
157
- # "nodeId": "3",
158
- # "ignored": True,
159
- # "role": {"value": "text"},
160
- # "name": {"value": "Child Text"},
161
- # }
162
- # ignored_child = AccessibilityTreeNode(
163
- # ignored_child_data, bounds=Rectangle(20, 20, 30, 30)
164
- # )
165
- # node.link_children({2: child, 3: ignored_child})
166
- # self.assertIn('[2] text "Child Text"', node.render())
167
- # self.assertNotIn('[3] text "Child Text"', node.render())
168
-
169
- # def test_property_string(self):
170
- # node_data = {"properties": [{"name": "checked", "value": {"value": True}}]}
171
- # node = AccessibilityTreeNode(node_data)
172
- # self.assertEqual(node.property_string(), " [checked: True]")
173
-
174
- # def test_property_string_with_ignored_property(self):
175
- # node_data = {
176
- # "properties": [{"name": "focusable", "value": {"value": "some_value"}}]
177
- # }
178
- # node = AccessibilityTreeNode(node_data)
179
- # # 'focusable' is in _IGNORED_ACTREE_PROPERTIES
180
- # self.assertEqual(node.property_string(), "")
@@ -1,99 +0,0 @@
1
- from absl.testing import parameterized
2
-
3
- import playwright_browser
4
- import playwright_crawler
5
-
6
-
7
- class TestPlaywrightCrawler(parameterized.TestCase):
8
- def setUp(self):
9
- self._browser = playwright_browser.PlaywrightBrowser()
10
- self._crawler = playwright_crawler.PlaywrightCrawler(
11
- self._browser.get_new_context()
12
- )
13
-
14
- def test_go_to_page_changes_url(self):
15
- self.assertEqual(self._crawler.url, "about:blank")
16
- self._crawler.go_to_page("https://www.example.com")
17
- self.assertEqual(self._crawler.url, "https://www.example.com/")
18
-
19
- def test_go_to_page_adds_missing_protocol(self):
20
- self._crawler.go_to_page("www.example.com")
21
- self.assertEqual(self._crawler.url, "https://www.example.com/")
22
-
23
- def test_nodes_change_on_update(self):
24
- self._crawler.go_to_page("https://www.example.com")
25
- self.assertFalse(self._crawler._nodes)
26
- self._crawler.update()
27
- self.assertTrue(self._crawler._nodes)
28
-
29
- def test_render_accessibility_tree(self):
30
- self._crawler.go_to_page("https://www.example.com")
31
- at_no_update = self._crawler.render_at(
32
- playwright_crawler.CrawlerOutputFormat.AT
33
- )
34
- self.assertEqual(at_no_update, "")
35
-
36
- self._crawler.update()
37
-
38
- at_update = self._crawler.render_at(playwright_crawler.CrawlerOutputFormat.AT)
39
- nodes = at_update.splitlines()
40
- self.assertEqual(len(nodes), 3)
41
- self.assertTrue(
42
- nodes[0].startswith(
43
- '[5] RootWebArea "Example Domain" [focused: True, url: https://www.example.com/]'
44
- )
45
- )
46
- self.assertTrue(
47
- nodes[1].startswith(
48
- ' [3] StaticText "This domain is for use in illustrative examples in documents'
49
- )
50
- )
51
- self.assertTrue(
52
- nodes[2].startswith(
53
- ' [12] link "More information..." [url: https://www.iana.org/domains/example]'
54
- )
55
- )
56
-
57
- def test_click_adjusts_to_scrolling_position(self):
58
- test_html = """
59
- <!DOCTYPE html>
60
- <html lang="en">
61
- <head>
62
- <meta charset="UTF-8">
63
- <title>Scrolling Test Page</title>
64
- <style>
65
- body { height: 3000px; }
66
- .my-button { position: absolute; top: 1500px; }
67
- </style>
68
- </head>
69
- <body>
70
- <button class="my-button" onclick="changeText(this)">Click Me</button>
71
- <script>
72
- function changeText(button) {
73
- button.textContent = "Text Changed!";
74
- }
75
- </script>
76
- </body>
77
- </html>
78
- """
79
- self._crawler._page_future.set_content(test_html)
80
- self._crawler.update()
81
- at_before_scroll = self._crawler.render_at(
82
- playwright_crawler.CrawlerOutputFormat.AT
83
- )
84
- self.assertIn("Scrolling Test Page", at_before_scroll)
85
- self.assertNotIn("Click Me", at_before_scroll)
86
-
87
- self._crawler.scroll("down")
88
- self._crawler.update()
89
- at_after_scroll = self._crawler.render_at(
90
- playwright_crawler.CrawlerOutputFormat.AT
91
- )
92
- self.assertIn("Click Me", at_after_scroll)
93
-
94
- self._crawler.click("17")
95
- self._crawler.update()
96
- at_after_click = self._crawler.render_at(
97
- playwright_crawler.CrawlerOutputFormat.AT
98
- )
99
- self.assertIn("Text Changed!", at_after_click)
@@ -1,15 +0,0 @@
1
- from rectangle import Rectangle
2
-
3
-
4
- def test_overlaps():
5
- bounds1 = Rectangle(10, 20, 30, 40)
6
- bounds2 = Rectangle(20, 30, 40, 50)
7
- assert bounds1.overlaps(bounds2)
8
- bounds3 = Rectangle(50, 60, 20, 30)
9
- assert not bounds1.overlaps(bounds3)
10
-
11
-
12
- def test_within():
13
- bounds1 = Rectangle(231, 167, 2, 9)
14
- bounds2 = Rectangle(231, 167, 26, 9)
15
- assert bounds1.within(bounds2)
@@ -1,44 +0,0 @@
1
- import sys
2
-
3
- from web_browser_rpc_types import GoArgs
4
- from web_client import _parse_args
5
-
6
-
7
- def test_parse_args_session_name_handling() -> None:
8
- test_cases: list[tuple[list[str], str, object]] = [
9
- (
10
- ["cli", "--session_name=my_session", "web_go", "boston.com"],
11
- "web_go",
12
- GoArgs(session_name="my_session", url="boston.com"),
13
- ),
14
- (
15
- ["cli", "web_go", "boston.com", "--session_name=my_session"],
16
- "web_go",
17
- GoArgs(session_name="my_session", url="boston.com"),
18
- ),
19
- (
20
- ["cli", "web_go", "--session_name=my_session", "boston.com"],
21
- "web_go",
22
- GoArgs(session_name="my_session", url="boston.com"),
23
- ),
24
- (
25
- ["cli", "--session_name", "my_session", "web_go", "boston.com"],
26
- "web_go",
27
- GoArgs(session_name="my_session", url="boston.com"),
28
- ),
29
- (
30
- ["cli", "web_go", "boston.com", "--session_name", "my_session"],
31
- "web_go",
32
- GoArgs(session_name="my_session", url="boston.com"),
33
- ),
34
- (
35
- ["cli", "web_go", "--session_name", "my_session", "boston.com"],
36
- "web_go",
37
- GoArgs(session_name="my_session", url="boston.com"),
38
- ),
39
- ]
40
- for argv, expected_cmd, expected_params in test_cases:
41
- sys.argv = argv
42
- cmd, params = _parse_args()
43
- assert cmd == expected_cmd
44
- assert params == expected_params
@@ -1,39 +0,0 @@
1
- from typing import Literal, TypedDict
2
-
3
- from pydantic import BaseModel
4
-
5
-
6
- class NewSessionArgs(TypedDict):
7
- headful: bool
8
-
9
-
10
- class CrawlerBaseArgs(TypedDict):
11
- session_name: str
12
-
13
-
14
- class GoArgs(CrawlerBaseArgs):
15
- url: str
16
-
17
-
18
- class ClickArgs(CrawlerBaseArgs):
19
- element_id: str
20
-
21
-
22
- class ScrollArgs(CrawlerBaseArgs):
23
- direction: Literal["up", "down"]
24
-
25
-
26
- class TypeOrSubmitArgs(CrawlerBaseArgs):
27
- element_id: str
28
- text: str
29
-
30
-
31
- class NewSessionResponse(BaseModel):
32
- session_name: str
33
-
34
-
35
- class CrawlerResponse(BaseModel):
36
- web_url: str
37
- main_content: str | None = None
38
- web_at: str
39
- error: str | None = None