refactor: remove redundant comments and docstrings (#6527)

* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-30 13:07:03 +08:00
1 parent cb3ba45317
commit a4d2430140
922 files changed
+406 -7738

No files matched your search

-2
View File
@@ -1,5 +1,3 @@
"""One SQLite owner for model messages and durable, generation-bound display facts."""
from __future__ import annotations
import json
-3
View File
@@ -1,5 +1,3 @@
"""Follow-up consumption commits against the owner, not an old turn snapshot."""
import sqlite3
from datetime import datetime
from unittest.mock import AsyncMock, MagicMock
@@ -95,7 +93,6 @@ async def test_failed_followup_commit_rolls_back_history_and_ack_then_can_retry(
BEGIN SELECT RAISE(ABORT, 'failed follow-up commit'); END""")
with pytest.raises(sqlite3.IntegrityError, match="failed follow-up commit"):
await state.finish_turn(draft)
# Both the durable snapshot and published cache remain at the pre-commit boundary.
for stored in (sessions.read_session_snapshot(draft.key), state.peek(draft.key)):
assert [row["content"] for row in stored.messages] == ["initial input"]
assert [item.content for item in pending_followups(stored)] == ["consumed input"]
-2
View File
@@ -1,5 +1,3 @@
"""Tests for ``goal_state`` session metadata helpers."""
from __future__ import annotations
from nanobot.session.goal_state import (
-9
View File
@@ -54,7 +54,6 @@ async def test_restart_before_model_call_waits_for_confirmation(tmp_path: Path)
@pytest.mark.asyncio
async def test_stale_incomplete_transcript_waits_for_confirmation(tmp_path: Path, monkeypatch) -> None:
"""A materialized shutdown must not reappear as an endless Working state."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
_persist(sessions, session)
@@ -80,7 +79,6 @@ async def test_materialized_interruption_can_continue_from_saved_context(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Older shutdowns may have cleared the checkpoint after saving partial history."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
session.messages.extend(
@@ -193,7 +191,6 @@ async def test_scan_loads_only_sessions_that_need_webui_recovery(
@pytest.mark.asyncio
async def test_live_turn_followup_survives_restart_until_it_is_committed(tmp_path: Path) -> None:
"""A message injected mid-turn is not lost between checkpoints."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
_persist(sessions, session)
@@ -224,7 +221,6 @@ async def test_live_turn_followup_survives_restart_until_it_is_committed(tmp_pat
def test_followup_journal_keeps_every_uncommitted_message(tmp_path: Path) -> None:
"""A live queue limit must never truncate durable WebUI follow-ups."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
followup_ids = [
@@ -251,7 +247,6 @@ def test_followup_journal_keeps_every_uncommitted_message(tmp_path: Path) -> Non
def test_requeued_followup_preserves_its_journal_id(tmp_path: Path) -> None:
"""Routing a recovered follow-up into a live turn must remain idempotent."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
original_id = record_pending_followup(
@@ -343,7 +338,6 @@ async def test_uncertain_tool_is_never_replayed(tmp_path: Path) -> None:
@pytest.mark.asyncio
async def test_unknown_checkpoint_waits_for_confirmation(tmp_path: Path) -> None:
"""Malformed or newer checkpoint phases fail closed pending confirmation."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
session.messages.append({"role": "user", "content": "deploy it"})
@@ -385,7 +379,6 @@ async def test_unknown_checkpoint_waits_for_confirmation(tmp_path: Path) -> None
@pytest.mark.asyncio
async def test_malformed_checkpoint_can_always_be_dismissed(tmp_path: Path) -> None:
"""Corrupt private state must not trap the user in a failed recovery notice."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
session.messages.append({"role": "user", "content": "deploy it"})
@@ -414,7 +407,6 @@ async def test_malformed_checkpoint_can_always_be_dismissed(tmp_path: Path) -> N
@pytest.mark.asyncio
async def test_known_but_malformed_checkpoint_cannot_continue(tmp_path: Path) -> None:
"""A known phase does not make corrupt tool state safe to resume."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
session.messages.append({"role": "user", "content": "send it"})
@@ -473,7 +465,6 @@ async def test_malformed_final_response_is_not_reported_as_restored(tmp_path: Pa
@pytest.mark.asyncio
async def test_checkpoint_with_missing_tool_result_cannot_continue(tmp_path: Path) -> None:
"""Never resume when persisted results do not cover every requested tool."""
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
session.messages.append({"role": "user", "content": "send both"})
-2
View File
@@ -1,5 +1,3 @@
"""Admission, ordering, and shutdown at the asynchronous session boundary."""
import asyncio
import sqlite3
import threading
-3
View File
@@ -1,5 +1,3 @@
"""Detached views and transient session lifetime."""
import pytest
from nanobot.session.manager import Session, SessionManager
@@ -8,7 +6,6 @@ from nanobot.session.sqlite_store import SessionConflictError
async def test_committed_view_cache_is_bounded(tmp_path):
manager = SessionManager(tmp_path)
# Persist the input before binding the async owner; exercise real cache reads below.
with manager._store.transaction():
for i in range(140):
manager.save(Session(key=str(i), metadata={"title": str(i)}))
-2
View File
@@ -1,5 +1,3 @@
"""Durability configuration is applied to every SQLite connection."""
from nanobot.session.manager import SessionManager
@@ -1,5 +1,3 @@
"""Incremental storage must preserve snapshot isolation and cross-process conflicts."""
import asyncio
import sqlite3
import threading
@@ -76,7 +74,6 @@ async def test_nested_draft_edits_and_failed_commits_remain_private(tmp_path, tr
draft.messages[0]["content"][0]["text"] = "edited"
assert state.peek(draft.key).messages[0]["content"][0]["text"] == "original"
await state.finish_turn(draft)
# Previously issued drafts still represent their old revision.
assert peer.messages[0]["content"][0]["text"] == "original"
peer.add_message("assistant", "stale append")
with pytest.raises(SessionConflictError):
@@ -114,7 +111,6 @@ async def test_external_append_merges_and_external_edit_conflicts(tmp_path):
external = other.get_or_create(draft.key)
external.messages[0]["content"] = "replaced"
other.save(external)
# A metadata-only command must not revalidate stale cached history accidentally.
await state.update_metadata(draft.key, {"title": "new"})
draft.add_message("assistant", "stale")
with pytest.raises(SessionConflictError):
-8
View File
@@ -1,5 +1,3 @@
"""Session storage location: outside the agent workspace (ADR-0001)."""
from __future__ import annotations
import os
@@ -22,19 +20,15 @@ def test_sessions_are_stored_outside_workspace(tmp_path: Path) -> None:
session.add_message("user", "hello")
manager.save(session)
# The session file must NOT live inside the workspace.
workspace_sessions = workspace / "sessions"
assert not workspace_sessions.exists() or not any(workspace_sessions.glob("*.jsonl"))
# The out-of-workspace store records which workspace it belongs to and the
# workspace carries only a non-secret stable identity marker.
marker = manager.sessions_dir / ".workspace"
assert marker.read_text(encoding="utf-8").strip() == str(workspace.resolve())
workspace_id = (workspace / ".nanobot" / "workspace-id").read_text(encoding="utf-8").strip()
assert manager.sessions_dir.name == workspace_id
assert manager.sessions_dir.parent.name == "sessions"
# And it must still round-trip through a fresh manager for the same workspace.
reloaded = SessionManager(workspace=workspace).get_or_create("telegram:1")
assert reloaded.messages[-1]["content"] == "hello"
@@ -66,7 +60,6 @@ def test_different_workspaces_are_isolated(tmp_path: Path) -> None:
session.add_message("user", "secret-for-a")
manager_a.save(session)
# A second workspace must not see A's session.
assert manager_a.sessions_dir != SessionManager(workspace=workspace_b).sessions_dir
in_b = SessionManager(workspace=workspace_b).get_or_create("telegram:1")
assert in_b.messages == []
@@ -179,7 +172,6 @@ def test_equivalent_workspace_paths_share_one_store(tmp_path: Path) -> None:
except OSError as exc:
pytest.skip(f"directory symlink unavailable: {exc}")
# Save via the real path, then read via an equivalent directory link.
manager = SessionManager(workspace=real_workspace)
session = manager.get_or_create("telegram:1")
session.add_message("user", "via-real")
-2
View File
@@ -1,5 +1,3 @@
"""Administrative SQLite repository operations."""
from datetime import datetime
from nanobot.providers.base import ProviderConversationState
-2
View File
@@ -1,5 +1,3 @@
"""Session schema upgrades preserve records and fail atomically."""
import sqlite3
from contextlib import closing
from pathlib import Path
-2
View File
@@ -1,5 +1,3 @@
"""SQLite durability and asynchronous state ownership contracts."""
import asyncio
import sqlite3
import subprocess
-3
View File
@@ -1,5 +1,3 @@
"""Tests for internal turn continuation policy."""
from __future__ import annotations
import asyncio
@@ -153,7 +151,6 @@ def test_internal_continuation_requires_budget_boundary_and_queue():
def test_save_skip_unchanged_for_standalone_current_message():
# [system, history user, current user] with the current user already saved.
assert _save_skip_for_turn(
message_metadata=None,
initial_message_count=3,