alishahryar1--free-claude-code
85b601884d
## Problem Python 3.14 provides native lazy annotations, but the codebase still relied on legacy future annotation imports. Those imports also made type-only import cycles easier to hide instead of fixing ownership boundaries. ## Changes | Before | After | | --- | --- | | Python files used `from __future__ import annotations`. | Python files rely on Python 3.14 native lazy annotations. | | Some runtime modules used `TYPE_CHECKING` or local imports for required dependencies. | Runtime modules use top-level owner-module imports with explicit boundaries. | | Local and GitHub guardrails only rejected type ignore suppressions. | Local and GitHub guardrails reject type ignore suppressions and legacy future annotation imports. | | Agent docs only documented the no-type-ignore rule. | Agent docs document the Python 3.14 annotation and import-boundary rules. | <!-- greptile_comment --> <details open><summary><h3>Greptile Summary</h3></summary> This PR moves the codebase to Python 3.14 native lazy annotations. The main changes are: - Removed legacy `from __future__ import annotations` imports across Python modules. - Promoted selected runtime dependencies from `TYPE_CHECKING` or local imports to explicit owner-module imports. - Added local, GitHub, and contract-test guardrails to reject legacy future annotation imports. - Updated agent docs with the annotation and import-boundary rules. - Bumped the package patch version for production-file changes. </details> <h3>Confidence Score: 5/5</h3> Safe to merge with low risk. The changes are mostly mechanical annotation cleanup with matching CI and contract-test guardrails. Reviewed import-boundary updates did not show a confirmed runtime cycle or dependency break. No files require special attention. <details><summary><h3><a href="https://www.greptile.com/trex"><img alt="T-Rex" src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg" height="20" align="absmiddle"></a> T-Rex Logs</h3></summary> **What T-Rex did** - Performed an end-to-end validation of the guardrail contract suite: an environment check confirmed uv availability, a guardrail pytest run used CPython 3.14.0 with 5 passing contract tests, 3 focused CI-script tests passed, and the direct CI suppressions guardrail command (including the legacy future-annotations grep) also passed. <a href="https://app.greptile.com/trex/runs/13303335/artifacts"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifactsDark.svg?v=4"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"><img alt="View all artifacts" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"></picture></a> <sub><a href="https://www.greptile.com/trex"><img alt="T-Rex" src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg" height="14" align="absmiddle"></a> Ran code and verified through T-Rex</sub> </details> <details open><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | api/runtime.py | Moves messaging, CLI manager, session, limiter, and tree dependencies from local/type-checking imports to explicit top-level owner-module imports. | | messaging/platforms/telegram.py | Removes future annotations and promotes Telegram SDK type imports into the existing availability guard. | | messaging/platforms/telegram_inbound.py | Removes future annotations and imports Telegram SDK types at module scope for inbound normalization. | | tests/contracts/test_import_boundaries.py | Adds an AST contract that rejects legacy future annotation imports across Python files. | | scripts/ci.sh | Extends the local suppression check to reject legacy future annotation imports alongside type-ignore suppressions. | | scripts/ci.ps1 | Mirrors the local PowerShell CI suppression check for legacy future annotations. | | .github/workflows/tests.yml | Renames and broadens the GitHub guardrail job to reject both type suppressions and legacy future annotations. | | pyproject.toml | Bumps the patch version for production-file changes. | </details> <details open><summary><h3>Sequence Diagram</h3></summary> <a href="#gh-light-mode-only"> ```mermaid %%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Dev as Developer/CI participant Guard as Suppression guard participant AST as Import-boundary contract test participant Py as Python modules Dev->>Guard: Run local/GitHub suppression check Guard->>Py: "Scan *.py for type ignores and future annotations" Guard-->>Dev: Fail if legacy annotation import remains Dev->>AST: Run pytest contract tests AST->>Py: Parse imports with ast AST-->>Dev: Assert no future annotations/import-boundary violations Py-->>Dev: Use Python 3.14 native lazy annotations ``` </a> <a href="#gh-dark-mode-only"> ```mermaid %%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Dev as Developer/CI participant Guard as Suppression guard participant AST as Import-boundary contract test participant Py as Python modules Dev->>Guard: Run local/GitHub suppression check Guard->>Py: "Scan *.py for type ignores and future annotations" Guard-->>Dev: Fail if legacy annotation import remains Dev->>AST: Run pytest contract tests AST->>Py: Parse imports with ast AST-->>Dev: Assert no future annotations/import-boundary violations Py-->>Dev: Use Python 3.14 native lazy annotations ``` </a> </details> <sub>Reviews (2): Last reviewed commit: ["Remove legacy future annotations import"](https://github.com/alishahryar1/free-claude-code/commit/6e6cda69da243bbdb92831207aecb3731ad469f8) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=41875785)</sub> <!-- /greptile_comment -->
127 行
3.6 KiB
Python
127 行
3.6 KiB
Python
from collections.abc import Iterator
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
from smoke.lib.config import ProviderModel, SmokeConfig, auth_headers
|
|
from smoke.lib.report import SmokeReport
|
|
from smoke.lib.server import RunningServer, start_server
|
|
|
|
DISABLED_PROVIDER_MODEL = ProviderModel(
|
|
provider="smoke_disabled",
|
|
full_model="smoke_disabled/smoke-disabled",
|
|
source="smoke_disabled",
|
|
)
|
|
|
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
|
|
if "provider_model" in metafunc.fixturenames:
|
|
config = SmokeConfig.load()
|
|
metafunc.parametrize("provider_model", provider_model_params(config))
|
|
|
|
|
|
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
|
|
if SmokeConfig.load().live:
|
|
return
|
|
skip = pytest.mark.skip(reason="set FCC_LIVE_SMOKE=1 to run local smoke tests")
|
|
for item in items:
|
|
item.add_marker(skip)
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
|
global _REPORT
|
|
smoke_config = SmokeConfig.load()
|
|
_REPORT = SmokeReport(smoke_config)
|
|
|
|
|
|
def pytest_runtest_setup(item: pytest.Item) -> None:
|
|
config = SmokeConfig.load()
|
|
target_marks = list(item.iter_markers("smoke_target"))
|
|
if not target_marks:
|
|
return
|
|
targets = [str(mark.args[0]) for mark in target_marks if mark.args]
|
|
if targets and not any(config.target_enabled(target) for target in targets):
|
|
pytest.skip(f"smoke target disabled: {', '.join(targets)}")
|
|
|
|
|
|
def pytest_runtest_logreport(report: pytest.TestReport) -> None:
|
|
if report.when == "setup" and not report.skipped:
|
|
return
|
|
if report.when == "teardown" and not report.failed:
|
|
return
|
|
if _REPORT is None:
|
|
return
|
|
markers = sorted(
|
|
str(name) for name in report.keywords if str(name).startswith("smoke_")
|
|
)
|
|
detail = "" if report.longrepr is None else str(report.longrepr)
|
|
_REPORT.add(
|
|
nodeid=report.nodeid,
|
|
outcome=report.outcome,
|
|
duration_s=report.duration,
|
|
markers=markers,
|
|
detail=detail,
|
|
)
|
|
|
|
|
|
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
|
|
if _REPORT is not None:
|
|
_REPORT.write()
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def smoke_config() -> SmokeConfig:
|
|
return SmokeConfig.load()
|
|
|
|
|
|
@pytest.fixture
|
|
def smoke_server(smoke_config: SmokeConfig) -> Iterator[RunningServer]:
|
|
with start_server(smoke_config) as server:
|
|
yield server
|
|
|
|
|
|
@pytest.fixture
|
|
def smoke_headers() -> dict[str, str]:
|
|
return auth_headers()
|
|
|
|
|
|
def provider_model_params(config: SmokeConfig) -> list[Any]:
|
|
"""Return provider params grouped for pytest-xdist ``--dist=loadgroup``."""
|
|
if not config.live:
|
|
return [_disabled_provider_param("set FCC_LIVE_SMOKE=1 to run provider smoke")]
|
|
|
|
models = config.provider_smoke_models()
|
|
if not models:
|
|
return [_disabled_provider_param("missing_env: no configured provider smoke")]
|
|
|
|
return [
|
|
pytest.param(
|
|
model,
|
|
id=provider_model_id(model),
|
|
marks=pytest.mark.xdist_group(provider_xdist_group(model)),
|
|
)
|
|
for model in models
|
|
]
|
|
|
|
|
|
def _disabled_provider_param(reason: str) -> Any:
|
|
return pytest.param(
|
|
DISABLED_PROVIDER_MODEL,
|
|
id=provider_model_id(DISABLED_PROVIDER_MODEL),
|
|
marks=(
|
|
pytest.mark.skip(reason=reason),
|
|
pytest.mark.xdist_group(provider_xdist_group(DISABLED_PROVIDER_MODEL)),
|
|
),
|
|
)
|
|
|
|
|
|
def provider_model_id(provider_model: ProviderModel) -> str:
|
|
return provider_model.provider
|
|
|
|
|
|
def provider_xdist_group(provider_model: ProviderModel) -> str:
|
|
return f"provider:{provider_model.provider}"
|
|
|
|
|
|
_REPORT: SmokeReport | None = None
|