mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-19 18:45:15 +02:00
chore: linting
This commit is contained in:
parent
219a5977b7
commit
c187b04e82
25 changed files with 102 additions and 108 deletions
|
|
@ -362,9 +362,7 @@ async def test_full_resume_routing_glue_for_two_paused_subagents():
|
|||
SimpleNamespace(
|
||||
id="i-approver",
|
||||
value={
|
||||
"action_requests": [
|
||||
{"name": "approve", "args": {}, "description": ""}
|
||||
],
|
||||
"action_requests": [{"name": "approve", "args": {}, "description": ""}],
|
||||
"review_configs": [{}],
|
||||
"tool_call_id": "tcid-approver",
|
||||
},
|
||||
|
|
@ -403,8 +401,6 @@ async def test_full_resume_routing_glue_for_two_paused_subagents():
|
|||
|
||||
received_a = ast.literal_eval(result_a.update["decision_text"])
|
||||
assert received_a == {"decisions": flat_decisions[0:3]}
|
||||
assert result_b.update["decision_text"] == repr(
|
||||
{"decisions": flat_decisions[3:4]}
|
||||
)
|
||||
assert result_b.update["decision_text"] == repr({"decisions": flat_decisions[3:4]})
|
||||
|
||||
assert "surfsense_resume_value" not in parent_config["configurable"]
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ This module pins:
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import Annotated
|
||||
|
||||
|
|
@ -227,10 +228,8 @@ async def test_heterogeneous_decisions_route_to_correct_subagents_with_metadata_
|
|||
for msg in final_state.values.get("messages", []) or []:
|
||||
content = getattr(msg, "content", None)
|
||||
if isinstance(content, str):
|
||||
try:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
payloads.append(json.loads(content))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
expected_a = {"decisions": [a_approve, a_reject]}
|
||||
expected_b = {"decisions": [b_edit, b_approve, b_reject]}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ exploratory probe before this test was authored.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import Annotated
|
||||
|
||||
|
|
@ -243,10 +244,8 @@ async def test_partial_pause_routes_only_to_paused_branch_without_rerunning_comp
|
|||
for msg in final.values.get("messages", []) or []:
|
||||
content = getattr(msg, "content", None)
|
||||
if isinstance(content, str):
|
||||
try:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
payloads.append(json.loads(content))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
assert {"decisions": [{"type": "approve"}]} in payloads, (
|
||||
f"REGRESSION: sub-B did not receive its single approve on resume; "
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ Why a separate pin:
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import Annotated
|
||||
|
||||
|
|
@ -191,10 +192,8 @@ async def test_all_reject_decisions_route_to_each_subagent_with_messages_intact(
|
|||
for msg in final_state.values.get("messages", []) or []:
|
||||
content = getattr(msg, "content", None)
|
||||
if isinstance(content, str):
|
||||
try:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
payloads.append(json.loads(content))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
expected_a = {"decisions": [a_reject_0, a_reject_1]}
|
||||
expected_b = {"decisions": [b_reject_0]}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ silently pass such a bug because the slices would coincide.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import Annotated
|
||||
|
||||
|
|
@ -81,9 +82,7 @@ def _build_pausing_subagent(checkpointer: InMemorySaver, *, action_count: int):
|
|||
"review_configs": [{} for _ in range(action_count)],
|
||||
}
|
||||
)
|
||||
return {
|
||||
"messages": [AIMessage(content=json.dumps(decision, sort_keys=True))]
|
||||
}
|
||||
return {"messages": [AIMessage(content=json.dumps(decision, sort_keys=True))]}
|
||||
|
||||
g = StateGraph(_SubState)
|
||||
g.add_node("approve", approve_node)
|
||||
|
|
@ -202,7 +201,9 @@ async def test_parallel_resume_with_per_interrupt_id_keying_completes_both_subag
|
|||
await parent.ainvoke({"messages": [HumanMessage(content="seed")]}, config)
|
||||
|
||||
paused_state = await parent.aget_state(config)
|
||||
assert len(paused_state.interrupts) == 2, "fixture broken: expected 2 paused subagents"
|
||||
assert len(paused_state.interrupts) == 2, (
|
||||
"fixture broken: expected 2 paused subagents"
|
||||
)
|
||||
|
||||
pending = collect_pending_tool_calls(paused_state)
|
||||
assert dict(pending) == {tcid_a: 2, tcid_b: 3}, (
|
||||
|
|
@ -243,10 +244,8 @@ async def test_parallel_resume_with_per_interrupt_id_keying_completes_both_subag
|
|||
for msg in final_state.values.get("messages", []) or []:
|
||||
content = getattr(msg, "content", None)
|
||||
if isinstance(content, str):
|
||||
try:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
payloads.append(json.loads(content))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
expected_a = {"decisions": [a_d0, a_d1]}
|
||||
expected_b = {"decisions": [b_d0, b_d1, b_d2]}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ their per-slice payload.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import Annotated
|
||||
|
||||
|
|
@ -151,7 +152,11 @@ def _parent_dispatching_one_of_each(
|
|||
return [
|
||||
Send(
|
||||
"call_task",
|
||||
{"tcid": tcid_self, "desc": "approve email", "subtype": "self-gated-agent"},
|
||||
{
|
||||
"tcid": tcid_self,
|
||||
"desc": "approve email",
|
||||
"subtype": "self-gated-agent",
|
||||
},
|
||||
),
|
||||
Send(
|
||||
"call_task",
|
||||
|
|
@ -250,10 +255,8 @@ async def test_parallel_self_gated_and_middleware_gated_route_and_resume_cleanly
|
|||
for msg in final.values.get("messages", []) or []:
|
||||
content = getattr(msg, "content", None)
|
||||
if isinstance(content, str):
|
||||
try:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
payloads.append(json.loads(content))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
self_payloads = [p for p in payloads if p.get("kind") == "self_gated"]
|
||||
mw_payloads = [p for p in payloads if p.get("kind") == "middleware_gated"]
|
||||
|
|
|
|||
|
|
@ -121,7 +121,11 @@ async def test_two_parallel_atasks_same_subagent_type_different_tool_call_ids():
|
|||
shared_subagent = _build_success_subagent("ok")
|
||||
task_tool = build_task_tool_with_parent_config(
|
||||
[
|
||||
{"name": "approver", "description": "shared approver", "runnable": shared_subagent},
|
||||
{
|
||||
"name": "approver",
|
||||
"description": "shared approver",
|
||||
"runnable": shared_subagent,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
|
|
@ -163,7 +167,10 @@ async def test_two_parallel_atasks_same_subagent_type_different_tool_call_ids():
|
|||
state_parent = await shared_subagent.aget_state(
|
||||
{"configurable": {"thread_id": "shared-subagent-thread"}}
|
||||
)
|
||||
assert state_parent.values == {} or state_parent.values.get("messages") in (None, [])
|
||||
assert state_parent.values == {} or state_parent.values.get("messages") in (
|
||||
None,
|
||||
[],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -181,8 +188,16 @@ async def test_one_atask_failure_does_not_corrupt_sibling_atask():
|
|||
surviving_subagent = _build_success_subagent("still here")
|
||||
task_tool = build_task_tool_with_parent_config(
|
||||
[
|
||||
{"name": "broken", "description": "always fails", "runnable": failing_subagent},
|
||||
{"name": "healthy", "description": "always succeeds", "runnable": surviving_subagent},
|
||||
{
|
||||
"name": "broken",
|
||||
"description": "always fails",
|
||||
"runnable": failing_subagent,
|
||||
},
|
||||
{
|
||||
"name": "healthy",
|
||||
"description": "always succeeds",
|
||||
"runnable": surviving_subagent,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -84,9 +84,7 @@ async def test_resume_with_approve_envelope_returns_once_decision():
|
|||
config = {"configurable": {"thread_id": "perm-once"}}
|
||||
await graph.ainvoke({"messages": [HumanMessage(content="seed")]}, config)
|
||||
|
||||
await graph.ainvoke(
|
||||
Command(resume={"decisions": [{"type": "approve"}]}), config
|
||||
)
|
||||
await graph.ainvoke(Command(resume={"decisions": [{"type": "approve"}]}), config)
|
||||
final = await graph.aget_state(config)
|
||||
assert final.values.get("final_decision") == {"decision_type": "once"}
|
||||
|
||||
|
|
@ -116,9 +114,7 @@ async def test_resume_with_reject_and_feedback_carries_feedback_through():
|
|||
|
||||
await graph.ainvoke(
|
||||
Command(
|
||||
resume={
|
||||
"decisions": [{"type": "reject", "feedback": "use the trash bin"}]
|
||||
}
|
||||
resume={"decisions": [{"type": "reject", "feedback": "use the trash bin"}]}
|
||||
),
|
||||
config,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -141,9 +141,7 @@ async def test_kb_ruleset_resume_with_approve_lets_rm_through():
|
|||
config = {"configurable": {"thread_id": "kb-cloud-rm-approve"}}
|
||||
await graph.ainvoke({"messages": [HumanMessage(content="seed")]}, config)
|
||||
|
||||
await graph.ainvoke(
|
||||
Command(resume={"decisions": [{"type": "approve"}]}), config
|
||||
)
|
||||
await graph.ainvoke(Command(resume={"decisions": [{"type": "approve"}]}), config)
|
||||
final = await graph.aget_state(config)
|
||||
assert final.next == (), "graph must complete after approve"
|
||||
last_ai = next(
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ class TestBuildLcHitlPayload:
|
|||
interrupt_type="x",
|
||||
)
|
||||
decisions.append(LC_DECISION_REJECT)
|
||||
assert payload["review_configs"][0]["allowed_decisions"] == [LC_DECISION_APPROVE]
|
||||
assert payload["review_configs"][0]["allowed_decisions"] == [
|
||||
LC_DECISION_APPROVE
|
||||
]
|
||||
|
||||
|
||||
class TestParseLcEnvelope:
|
||||
|
|
|
|||
|
|
@ -903,9 +903,7 @@ async def test_extract_pdf_without_vision_llm_skips_picture_descriptions(
|
|||
describe_mock.assert_not_called()
|
||||
|
||||
|
||||
async def test_extract_pdf_with_vision_llm_swallows_describe_failure(
|
||||
tmp_path, mocker
|
||||
):
|
||||
async def test_extract_pdf_with_vision_llm_swallows_describe_failure(tmp_path, mocker):
|
||||
"""A pypdf or vision LLM blow-up never fails the document upload."""
|
||||
pdf_file = tmp_path / "report.pdf"
|
||||
pdf_file.write_bytes(b"%PDF-1.4 fake content")
|
||||
|
|
@ -976,9 +974,7 @@ async def test_extract_pdf_with_vision_llm_no_images_returns_parser_text(
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
async def test_extract_pdf_passes_ocr_runner_to_describe_pictures(
|
||||
tmp_path, mocker
|
||||
):
|
||||
async def test_extract_pdf_passes_ocr_runner_to_describe_pictures(tmp_path, mocker):
|
||||
"""The ETL service must wire an ocr_runner kwarg to describe_pictures."""
|
||||
pdf_file = tmp_path / "report.pdf"
|
||||
pdf_file.write_bytes(b"%PDF-1.4 fake content")
|
||||
|
|
@ -1027,9 +1023,7 @@ async def test_extract_pdf_ocr_runner_invokes_document_parser_on_image(
|
|||
mocker.patch("app.config.config.ETL_SERVICE", "DOCLING")
|
||||
|
||||
fake_docling = mocker.AsyncMock()
|
||||
fake_docling.process_document.return_value = {
|
||||
"content": "Slice 24 / 60 L R"
|
||||
}
|
||||
fake_docling.process_document.return_value = {"content": "Slice 24 / 60 L R"}
|
||||
mocker.patch(
|
||||
"app.services.docling_service.create_docling_service",
|
||||
return_value=fake_docling,
|
||||
|
|
@ -1074,7 +1068,7 @@ async def test_extract_pdf_ocr_runner_returns_empty_on_unsupported_image(
|
|||
pdf_file = tmp_path / "report.pdf"
|
||||
pdf_file.write_bytes(b"%PDF-1.4 fake content")
|
||||
weird_image = tmp_path / "Im0.jp2" # JPEG2000, unlikely to be supported
|
||||
weird_image.write_bytes(b"\x00\x00\x00\x0CjP" + b"\x00" * 50)
|
||||
weird_image.write_bytes(b"\x00\x00\x00\x0cjP" + b"\x00" * 50)
|
||||
|
||||
mocker.patch("app.config.config.ETL_SERVICE", "DOCLING")
|
||||
|
||||
|
|
|
|||
|
|
@ -330,11 +330,17 @@ def test_inject_handles_multiple_images_in_order():
|
|||
result = PictureExtractionResult(
|
||||
descriptions=[
|
||||
PictureDescription(
|
||||
page_number=1, ordinal_in_page=0, name="Im0", sha256="aa",
|
||||
page_number=1,
|
||||
ordinal_in_page=0,
|
||||
name="Im0",
|
||||
sha256="aa",
|
||||
description="Desc A",
|
||||
),
|
||||
PictureDescription(
|
||||
page_number=2, ordinal_in_page=0, name="Im1", sha256="bb",
|
||||
page_number=2,
|
||||
ordinal_in_page=0,
|
||||
name="Im1",
|
||||
sha256="bb",
|
||||
description="Desc B",
|
||||
),
|
||||
]
|
||||
|
|
@ -511,9 +517,7 @@ async def test_describe_pictures_calls_ocr_runner_per_image(tmp_path, mocker):
|
|||
assert by_name == {"Im0.jpeg": "OCR text A", "Im1.png": "OCR text B"}
|
||||
|
||||
|
||||
async def test_describe_pictures_runs_vision_and_ocr_in_parallel(
|
||||
tmp_path, mocker
|
||||
):
|
||||
async def test_describe_pictures_runs_vision_and_ocr_in_parallel(tmp_path, mocker):
|
||||
"""Vision LLM and OCR run concurrently per image, not sequentially.
|
||||
|
||||
We verify this by recording call timestamps: if both finish within
|
||||
|
|
@ -656,9 +660,7 @@ async def test_describe_pictures_vision_failure_with_ocr_runner_skips_image(
|
|||
assert result.failed == 1
|
||||
|
||||
|
||||
async def test_describe_pictures_no_ocr_runner_keeps_ocr_text_none(
|
||||
tmp_path, mocker
|
||||
):
|
||||
async def test_describe_pictures_no_ocr_runner_keeps_ocr_text_none(tmp_path, mocker):
|
||||
"""Backward compat: omitting ocr_runner produces description-only blocks."""
|
||||
pdf_file = tmp_path / "report.pdf"
|
||||
pdf_file.write_bytes(b"%PDF-1.4 fake")
|
||||
|
|
@ -824,11 +826,17 @@ def test_inject_handles_multiple_figures_in_document_order():
|
|||
result = PictureExtractionResult(
|
||||
descriptions=[
|
||||
PictureDescription(
|
||||
page_number=1, ordinal_in_page=0, name="Im0", sha256="aa",
|
||||
page_number=1,
|
||||
ordinal_in_page=0,
|
||||
name="Im0",
|
||||
sha256="aa",
|
||||
description="Description of chart A.",
|
||||
),
|
||||
PictureDescription(
|
||||
page_number=2, ordinal_in_page=0, name="Im1", sha256="bb",
|
||||
page_number=2,
|
||||
ordinal_in_page=0,
|
||||
name="Im1",
|
||||
sha256="bb",
|
||||
description="Description of chart B.",
|
||||
),
|
||||
]
|
||||
|
|
@ -842,9 +850,7 @@ def test_inject_handles_multiple_figures_in_document_order():
|
|||
assert out.count("</figure>") == 2
|
||||
assert "Description of chart A." in out
|
||||
assert "Description of chart B." in out
|
||||
assert out.index("Description of chart A.") < out.index(
|
||||
"Description of chart B."
|
||||
)
|
||||
assert out.index("Description of chart A.") < out.index("Description of chart B.")
|
||||
# Each description appears AFTER its corresponding </figure>.
|
||||
first_close = out.index("</figure>")
|
||||
assert first_close < out.index("Description of chart A.")
|
||||
|
|
@ -856,7 +862,7 @@ def test_inject_figures_with_attributes_and_nested_tags():
|
|||
"""``<figure>`` with attributes and nested tags is matched and preserved."""
|
||||
markdown = (
|
||||
'<figure id="fig-3" class="chart">\n'
|
||||
'<figcaption>Source: Pew Research</figcaption>\n'
|
||||
"<figcaption>Source: Pew Research</figcaption>\n"
|
||||
"<table><tr><td>Republican</td><td>57</td></tr></table>\n"
|
||||
"</figure>\n"
|
||||
)
|
||||
|
|
@ -899,8 +905,7 @@ def test_inject_figures_more_descriptions_than_figures_returns_remaining():
|
|||
def test_inject_figures_more_figures_than_descriptions_leaves_extras_untouched():
|
||||
"""Two figures, one description -> first figure enriched, second left raw."""
|
||||
markdown = (
|
||||
"<figure>\nfigure 1 content\n</figure>\n"
|
||||
"<figure>\nfigure 2 content\n</figure>\n"
|
||||
"<figure>\nfigure 1 content\n</figure>\n<figure>\nfigure 2 content\n</figure>\n"
|
||||
)
|
||||
result = PictureExtractionResult(
|
||||
descriptions=[_desc(name="Im0", description="Only description.")]
|
||||
|
|
|
|||
|
|
@ -151,8 +151,7 @@ async def test_preserves_state_interrupts_traversal_order():
|
|||
state_order = [
|
||||
i.value["tool_call_id"]
|
||||
for i in state.interrupts
|
||||
if isinstance(getattr(i, "value", None), dict)
|
||||
and "tool_call_id" in i.value
|
||||
if isinstance(getattr(i, "value", None), dict) and "tool_call_id" in i.value
|
||||
]
|
||||
|
||||
assert inspector_order == state_order, (
|
||||
|
|
|
|||
|
|
@ -70,7 +70,9 @@ def _tool_start(*, name: str, run_id: str) -> dict[str, Any]:
|
|||
}
|
||||
|
||||
|
||||
async def _drain_step_ids(events: list[dict[str, Any]], *, step_prefix: str) -> set[str]:
|
||||
async def _drain_step_ids(
|
||||
events: list[dict[str, Any]], *, step_prefix: str
|
||||
) -> set[str]:
|
||||
"""Run ``_stream_agent_events`` once and return every emitted thinking-step ID."""
|
||||
agent = _FakeAgent(events)
|
||||
service = VercelStreamingService()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue