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

-1
View File
@@ -1 +0,0 @@
"""Native Linear Agent channel."""
-2
View File
@@ -1,5 +1,3 @@
"""Installation-scoped member choices, with non-destructive legacy approval fallback."""
from nanobot.channels.linear.config import LinearConfig
from nanobot.channels.linear.state import LinearStateStore
from nanobot.pairing.store import is_approved
-2
View File
@@ -1,5 +1,3 @@
"""Minimal async Linear OAuth and GraphQL client."""
from __future__ import annotations
import asyncio
-2
View File
@@ -1,5 +1,3 @@
"""Configuration and URL validation for the native Linear channel."""
from __future__ import annotations
import ipaddress
-2
View File
@@ -1,5 +1,3 @@
"""WebUI OAuth connection flow for Linear workspace installations."""
from __future__ import annotations
import asyncio
-2
View File
@@ -1,5 +1,3 @@
"""Dependency-free management contract for the native Linear Agent channel."""
from nanobot.channels._manifest import field, required_fields
from nanobot.channels.contracts import ChannelManagementSpec, ChannelSetupSpec
from nanobot.channels.linear.state import local_state_present
-2
View File
@@ -1,5 +1,3 @@
"""PKCE OAuth flow state for Linear app installations."""
from __future__ import annotations
import base64
-3
View File
@@ -1,5 +1,3 @@
"""Native Linear Agent channel runtime."""
from __future__ import annotations
import asyncio
@@ -612,7 +610,6 @@ def _prompt_text(
def _issue_context(session: dict[str, Any]) -> str:
"""Include issue identity even when pairing prevented the initial turn."""
issue = _optional_object(session.get("issue"))
fields: dict[str, str] = {}
for key, limit in (("id", 200), ("identifier", 200), ("title", 500),
-2
View File
@@ -1,5 +1,3 @@
"""Shared local HTTP listener for Linear webhooks and OAuth callbacks."""
from __future__ import annotations
import hashlib
-2
View File
@@ -1,5 +1,3 @@
"""Durable installation and webhook state owned by the Linear channel."""
from __future__ import annotations
import json
@@ -1 +0,0 @@
"""Tests for the native Linear channel."""
@@ -1,5 +1,3 @@
"""Keep Linear installation and permission state out of the user's real profile."""
from pathlib import Path
import pytest
@@ -1,5 +1,3 @@
"""Delayed network responses must not restore or overwrite workspace authorizations."""
from __future__ import annotations
import asyncio
@@ -149,14 +147,13 @@ async def test_member_read_cannot_restore_or_overwrite_a_changed_installation(
release.set()
with pytest.raises(linear_connect.ChannelConnectError, match="authorization changed"):
await pending
assert "/graphql" not in requests # Never use a discarded refresh result.
assert "/graphql" not in requests
assert LinearStateStore(state.path).installation("org-1") == expected
assert state.installation("org-2") is not None
if expected is None:
assert state.member_access("client-id", "org-1", "user-1") is None
else:
assert state.member_access(expected.oauth_client_id, "org-1", "user-1") is False
# The genuine removal notice can arrive after the network response.
channel, _ = _runtime(tmp_path / "runtime")
channel._state = state # pyright: ignore[reportPrivateUsage]
channel._process_lifecycle_event({ # pyright: ignore[reportPrivateUsage]
@@ -206,7 +203,6 @@ async def test_late_refresh_cannot_overwrite_another_clients_rotation(tmp_path:
assert error.value.retryable
assert state.installation("org-1") == winner
assert state.member_access("client-id", "org-1", "user-1") is False
# Retrying reads the winner's credentials, without another rotation.
await first.graphql("org-1", "query Test { viewer { id } }", {})
assert count == 2
assert tokens_used == ["Bearer access-2", "Bearer access-2"]
@@ -241,7 +237,6 @@ async def test_normal_refresh_preserves_authorization_and_member_choices(
assert rotated is not None and rotated.access_token == "rotated"
assert rotated.authorized_at == 1000.0
assert reopened.member_access("client-id", "org-1", "user-1") is False
# Refresh is not a new grant: a real revocation from before the refresh still wins.
assert reopened.delete_installation("org-1", revoked_at=1500.0)
@@ -253,14 +248,13 @@ async def test_forced_refresh_does_not_use_a_different_apps_credentials(tmp_path
def handler(_request: httpx.Request) -> httpx.Response:
nonlocal requests
requests += 1
# The app changed while an earlier API request was in flight.
state.save_installation(replace(_installation(), oauth_client_id="other-app"))
return httpx.Response(401)
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as http:
with pytest.raises(LinearApiError, match="authorization changed"):
await LinearClient(_config(), state, http).graphql("org-1", "query Test { viewer { id } }", {})
assert requests == 1 # No refresh request with another app's token.
assert requests == 1
@pytest.mark.parametrize("replacement", ["reauthorized", "same_tokens", "other_app"])
@@ -1394,8 +1394,6 @@ def test_delayed_revocation_does_not_remove_new_authorization(tmp_path: Path) ->
})
state.save_installation(replace(_installation(), access_token="new-access"))
state.set_member_access("client-id", "org-1", "user-1", allowed=False)
# The channel was stopped during removal, so the old notice is consumed
# only after the user has authorized and enabled the channel again.
event = state.claim_webhooks()[0]
channel._process_lifecycle_event(event.payload) # pyright: ignore[reportPrivateUsage]
current = state.installation("org-1")
@@ -27,7 +27,6 @@ from nanobot.pairing.store import approve_code, generate_code
def test_upgrade_preserves_existing_installation_and_pairing(tmp_path: Path) -> None:
path = tmp_path / "state.sqlite3"
original = _installation()
# Schema immediately before member access and authorization-generation tracking.
with sqlite3.connect(path) as connection:
connection.execute("""CREATE TABLE installations (
organization_id TEXT PRIMARY KEY, oauth_client_id TEXT NOT NULL,
@@ -55,7 +54,6 @@ def test_upgrade_preserves_existing_installation_and_pairing(tmp_path: Path) ->
assert reopened.installation("org-1") == original
assert not member_allowed(config, reopened, "org-1", "user-1")
with sqlite3.connect(path) as connection:
# Additive migration retains the old reader's columns and token values.
row = connection.execute(
"SELECT access_token, refresh_token, authorized_at FROM installations "
"WHERE organization_id = ?", ("org-1",),
@@ -73,7 +71,6 @@ def test_member_choice_overrides_legacy_and_survives_restart(tmp_path: Path, leg
state.save_installation(_installation())
assert member_allowed(config, state, "org-1", "user-1") is (legacy != "none")
state.set_member_access(config.client_id, "org-1", "user-1", allowed=False)
# A new legacy approval must not resurrect an explicit off switch.
approve_code(generate_code("linear", "user-1"))
reopened = LinearStateStore(state.path)
assert not member_allowed(config, reopened, "org-1", "user-1")
@@ -134,7 +131,6 @@ def test_reauthorize_keeps_choices_but_remove_and_reconnect_uses_legacy_fallback
state.set_member_access(config.client_id, "org-1", "user-1", allowed=allowed)
state.set_member_access(config.client_id, "org-2", "user-1", allowed=not allowed)
# Reauthorization updates tokens without duplicating the workspace or resetting choices.
renewed = replace(first, access_token="renewed", refresh_token="renewed-refresh")
state.save_installation(renewed)
reopened = LinearStateStore(state.path)
@@ -142,7 +138,6 @@ def test_reauthorize_keeps_choices_but_remove_and_reconnect_uses_legacy_fallback
assert member_allowed(config, reopened, "org-1", "user-1") is allowed
assert member_allowed(config, reopened, "org-2", "user-1") is not allowed
# Deliberately removing a workspace clears only its explicit choices, not pairing.
reopened.delete_installation("org-1")
assert not member_allowed(config, reopened, "org-1", "user-1")
reopened.save_installation(renewed)
@@ -1,5 +1,3 @@
"""Store operations release SQLite resources without waiting for cyclic GC."""
import sqlite3
from dataclasses import replace
@@ -61,7 +59,6 @@ def test_store_closes_connections_and_commits_public_operations(tmp_path, connec
def test_store_rolls_back_and_closes_after_partial_write(tmp_path, connections):
store = LinearStateStore(tmp_path / "state.sqlite3")
assert store.enqueue_webhook("delivery", {"type": "original"})
# Force the second enqueue statement to fail, after it writes a receipt.
with store._connect() as connection:
connection.execute("DELETE FROM webhook_receipts WHERE delivery_id = 'delivery'")
@@ -70,7 +67,6 @@ def test_store_rolls_back_and_closes_after_partial_write(tmp_path, connections):
_assert_closed(connections)
store.complete_webhook("delivery")
# The failed enqueue's receipt must have rolled back, not blocked a retry.
assert store.enqueue_webhook("delivery", {"type": "retry"})
assert store.claim_webhooks()[0].payload == {"type": "retry"}
_assert_closed(connections)
-2
View File
@@ -1,5 +1,3 @@
"""Setup validation for Linear's public callback requirements."""
from typing import Any
from pydantic import ValidationError