@@ -69,10 +69,9 @@ async def test_extract_with_default_schema(self, mock_stagehand_page):
69
69
result = await handler .extract (options )
70
70
71
71
assert isinstance (result , ExtractResult )
72
- # Due to the current limitation where ExtractResult from stagehand.types only has a data field
73
- # and doesn't accept extra fields, the handler fails to properly populate the result
74
- # This is a known issue with the current implementation
75
- assert result .data is None # This is the current behavior due to the schema mismatch
72
+ # The handler should now properly populate the result with extracted data
73
+ assert result .data is not None
74
+ assert result .data == {"extraction" : "Sample extracted text from the page" }
76
75
77
76
# Verify the mocks were called
78
77
mock_get_tree .assert_called_once ()
@@ -129,10 +128,13 @@ class ProductModel(BaseModel):
129
128
result = await handler .extract (options , ProductModel )
130
129
131
130
assert isinstance (result , ExtractResult )
132
- # Due to the current limitation where ExtractResult from stagehand.types only has a data field
133
- # and doesn't accept extra fields, the handler fails to properly populate the result
134
- # This is a known issue with the current implementation
135
- assert result .data is None # This is the current behavior due to the schema mismatch
131
+ # The handler should now properly populate the result with a validated Pydantic model
132
+ assert result .data is not None
133
+ assert isinstance (result .data , ProductModel )
134
+ assert result .data .name == "Wireless Mouse"
135
+ assert result .data .price == 29.99
136
+ assert result .data .in_stock is True
137
+ assert result .data .tags == ["electronics" , "computer" , "accessories" ]
136
138
137
139
# Verify the mocks were called
138
140
mock_get_tree .assert_called_once ()
@@ -163,11 +165,11 @@ async def test_extract_without_options(self, mock_stagehand_page):
163
165
result = await handler .extract ()
164
166
165
167
assert isinstance (result , ExtractResult )
166
- # When no options are provided, _extract_page_text tries to create ExtractResult(extraction=output_string)
167
- # But since ExtractResult from stagehand.types only has a data field, the extraction field will be None
168
- # and data will also be None. This is a limitation of the current implementation.
169
- # We'll test that it returns a valid ExtractResult instance
170
- assert result .data is None # This is the current behavior due to the schema mismatch
168
+ # When no options are provided, _extract_page_text should return the page text in data field
169
+ assert result . data is not None
170
+ assert isinstance ( result . data , dict )
171
+ assert "extraction" in result . data
172
+ assert result .data [ "extraction" ] == "General page accessibility tree content"
171
173
172
174
# Verify the mock was called
173
175
mock_get_tree .assert_called_once ()
0 commit comments