Skip to content

Commit 649f3dd

Browse files
committed
fix tests
1 parent 7fb5724 commit 649f3dd

File tree

10 files changed

+55
-24
lines changed

10 files changed

+55
-24
lines changed

examples/lang-chain/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ pip install sentienceapi[langchain]
1111
Examples:
1212
- `langchain_tools_demo.py`: build a Sentience tool pack for LangChain
1313
- `langgraph_self_correcting_graph.py`: observe → act → verify → branch (retry) template
14-

examples/lang-chain/langchain_tools_demo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import asyncio
1717

1818
from sentience import AsyncSentienceBrowser
19-
from sentience.integrations.langchain import SentienceLangChainContext, build_sentience_langchain_tools
19+
from sentience.integrations.langchain import (
20+
SentienceLangChainContext,
21+
build_sentience_langchain_tools,
22+
)
2023

2124

2225
async def main() -> None:
@@ -36,4 +39,3 @@ async def main() -> None:
3639

3740
if __name__ == "__main__":
3841
asyncio.run(main())
39-

examples/lang-chain/langgraph_self_correcting_graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ def branch(state: State) -> str:
7878

7979
if __name__ == "__main__":
8080
asyncio.run(main())
81-

examples/langgraph/sentience_self_correcting_graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ def should_continue(state: State) -> str:
8686

8787
if __name__ == "__main__":
8888
asyncio.run(main())
89-

sentience/cloud_tracing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def _finalize_trace_file_for_upload(self) -> bool:
203203
self._generate_index()
204204
return True
205205

206-
def _close_and_upload_background(self, on_progress: Callable[[int, int], None] | None = None) -> None:
206+
def _close_and_upload_background(
207+
self, on_progress: Callable[[int, int], None] | None = None
208+
) -> None:
207209
"""
208210
Background worker for non-blocking close.
209211

sentience/integrations/langchain/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
from .tools import build_sentience_langchain_tools
1111

1212
__all__ = ["SentienceLangChainContext", "SentienceLangChainCore", "build_sentience_langchain_tools"]
13-

sentience/integrations/langchain/context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ class SentienceLangChainContext:
1616

1717
browser: AsyncSentienceBrowser
1818
tracer: Tracer | None = None
19-

sentience/integrations/langchain/core.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ async def _trace(self, tool_name: str, exec_coro, exec_meta: dict[str, Any]):
100100
if success is not None:
101101
exec_data["success"] = success
102102

103-
verify_data = {"passed": bool(success) if success is not None else True, "signals": {}}
103+
verify_data = {
104+
"passed": bool(success) if success is not None else True,
105+
"signals": {},
106+
}
104107

105108
step_end_data = TraceEventBuilder.build_step_end_event(
106109
step_id=step_id,
@@ -123,7 +126,9 @@ async def _trace(self, tool_name: str, exec_coro, exec_meta: dict[str, Any]):
123126
raise
124127

125128
# ===== Observe =====
126-
async def snapshot_state(self, limit: int = 50, include_screenshot: bool = False) -> BrowserState:
129+
async def snapshot_state(
130+
self, limit: int = 50, include_screenshot: bool = False
131+
) -> BrowserState:
127132
async def _run():
128133
opts = SnapshotOptions(limit=limit, screenshot=include_screenshot)
129134
snap = await snapshot_async(self.ctx.browser, opts)
@@ -153,7 +158,9 @@ async def read_page(
153158
enhance_markdown: bool = True,
154159
) -> ReadResult:
155160
async def _run():
156-
return await read_async(self.ctx.browser, output_format=format, enhance_markdown=enhance_markdown)
161+
return await read_async(
162+
self.ctx.browser, output_format=format, enhance_markdown=enhance_markdown
163+
)
157164

158165
return await self._trace(
159166
"read_page",
@@ -178,7 +185,9 @@ async def type_text(self, element_id: int, text: str):
178185
)
179186

180187
async def press_key(self, key: str):
181-
return await self._trace("press_key", lambda: press_async(self.ctx.browser, key), {"key": key})
188+
return await self._trace(
189+
"press_key", lambda: press_async(self.ctx.browser, key), {"key": key}
190+
)
182191

183192
async def scroll_to(
184193
self,
@@ -221,7 +230,14 @@ async def _run():
221230
return await self._trace(
222231
"click_rect",
223232
_run,
224-
{"x": x, "y": y, "width": width, "height": height, "button": button, "click_count": click_count},
233+
{
234+
"x": x,
235+
"y": y,
236+
"width": width,
237+
"height": height,
238+
"button": button,
239+
"click_count": click_count,
240+
},
225241
)
226242

227243
async def find_text_rect(
@@ -243,7 +259,12 @@ async def _run():
243259
return await self._trace(
244260
"find_text_rect",
245261
_run,
246-
{"query": text, "case_sensitive": case_sensitive, "whole_word": whole_word, "max_results": max_results},
262+
{
263+
"query": text,
264+
"case_sensitive": case_sensitive,
265+
"whole_word": whole_word,
266+
"max_results": max_results,
267+
},
247268
)
248269

249270
# ===== Verify / guard =====
@@ -272,7 +293,9 @@ async def verify_text_present(
272293
async def _run():
273294
result = await read_async(self.ctx.browser, output_format=format, enhance_markdown=True)
274295
if result.status != "success":
275-
return AssertionResult(passed=False, reason=f"read failed: {result.error}", details={})
296+
return AssertionResult(
297+
passed=False, reason=f"read failed: {result.error}", details={}
298+
)
276299

277300
haystack = result.content if case_sensitive else result.content.lower()
278301
needle = text if case_sensitive else text.lower()
@@ -301,4 +324,3 @@ async def assert_eventually_url_matches(
301324
return last
302325
await asyncio.sleep(poll_s)
303326
return last or AssertionResult(passed=False, reason="No attempts executed", details={})
304-

sentience/integrations/langchain/tools.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ def build_sentience_langchain_tools(ctx: SentienceLangChainContext) -> list[Any]
2626
# ---- Schemas ----
2727
class SnapshotStateArgs(BaseModel):
2828
limit: int = Field(50, ge=1, le=500, description="Max elements to return (default 50)")
29-
include_screenshot: bool = Field(False, description="Include screenshot in snapshot (default false)")
29+
include_screenshot: bool = Field(
30+
False, description="Include screenshot in snapshot (default false)"
31+
)
3032

3133
class ReadPageArgs(BaseModel):
3234
format: Literal["raw", "text", "markdown"] = Field("text", description="Output format")
33-
enhance_markdown: bool = Field(True, description="Enhance markdown conversion (default true)")
35+
enhance_markdown: bool = Field(
36+
True, description="Enhance markdown conversion (default true)"
37+
)
3438

3539
class ClickArgs(BaseModel):
3640
element_id: int = Field(..., description="Sentience element id from snapshot_state()")
@@ -44,8 +48,12 @@ class PressKeyArgs(BaseModel):
4448

4549
class ScrollToArgs(BaseModel):
4650
element_id: int = Field(..., description="Sentience element id from snapshot_state()")
47-
behavior: Literal["smooth", "instant", "auto"] = Field("smooth", description="Scroll behavior")
48-
block: Literal["start", "center", "end", "nearest"] = Field("center", description="Vertical alignment")
51+
behavior: Literal["smooth", "instant", "auto"] = Field(
52+
"smooth", description="Scroll behavior"
53+
)
54+
block: Literal["start", "center", "end", "nearest"] = Field(
55+
"center", description="Vertical alignment"
56+
)
4957

5058
class NavigateArgs(BaseModel):
5159
url: str = Field(..., description="URL to navigate to")
@@ -79,7 +87,9 @@ class AssertEventuallyUrlMatchesArgs(BaseModel):
7987

8088
# ---- Sync wrappers (explicitly unsupported) ----
8189
def _sync_unsupported(*args, **kwargs):
82-
raise RuntimeError("Sentience LangChain tools are async-only. Use an async LangChain agent/runner.")
90+
raise RuntimeError(
91+
"Sentience LangChain tools are async-only. Use an async LangChain agent/runner."
92+
)
8393

8494
# ---- Tools ----
8595
return [
@@ -168,4 +178,3 @@ def _sync_unsupported(*args, **kwargs):
168178
coroutine=lambda **kw: core.assert_eventually_url_matches(**kw),
169179
),
170180
]
171-

tests/unit/test_langchain_integration_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ async def _fake_snapshot_async(browser, options):
8686
],
8787
)
8888

89-
monkeypatch.setattr("sentience.integrations.langchain.core.snapshot_async", _fake_snapshot_async)
89+
monkeypatch.setattr(
90+
"sentience.integrations.langchain.core.snapshot_async", _fake_snapshot_async
91+
)
9092

9193
ctx = SentienceLangChainContext(browser=_FakeAsyncBrowser()) # type: ignore[arg-type]
9294
core = SentienceLangChainCore(ctx)
@@ -95,4 +97,3 @@ async def _fake_snapshot_async(browser, options):
9597
assert state.url == "https://example.com/"
9698
assert len(state.elements) == 1
9799
assert state.elements[0].id == 1
98-

0 commit comments

Comments
 (0)