From 0246d9b04b05e14e49bc645f01af950f2d5a9744 Mon Sep 17 00:00:00 2001 From: georgiedekker Date: Sat, 14 Nov 2026 10:46:53 +0100 Subject: [PATCH 1/3] docs: state the licensing posture Names the licence that applies and states what licence enforcement (if any) this repository carries, so a reader is not left guessing whether a licence server is involved. Every public repo states its posture, including the ones that enforce nothing. Co-Authored-By: Claude Code --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b7f76da..cfa033a 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,20 @@ Issues and pull requests are welcome. See organisation-wide rules; setup, test and lint commands are in this README. Commits carry DCO sign-off. +## Licensing + +The code in this repository is Apache-2.0 and needs no licence key to build, test or run. +Licence tokens are an **optional** identity source: with `LICENSE_INTROSPECT_URL` unset (the +default), a `Bearer` licence cannot be introspected, and callers authenticate through the +platform's mesh-forwarded identity instead. With the URL set, every licence token is +introspected against the licences service, and an unreachable service yields no identity +(401) — never an admission. + +The licensing stack is public too — [`licenses`](https://github.com/nonagenticai/licenses) +(entitlements, plans and tokens) and +[`license-authz`](https://github.com/nonagenticai/license-authz) (the Envoy `ext_authz` +enforcement point). Neither is required to run this code. + ## License Apache-2.0 — see [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE). From 56bd7da45b24e11421222e30e50b8690633e3abe Mon Sep 17 00:00:00 2001 From: georgiedekker Date: Sat, 14 Nov 2026 21:06:55 +0000 Subject: [PATCH 2/3] fix(ty): clear ty 0.0.104 diagnostics on src (193 -> 0) CI pins ty 0.0.104 while pyproject pinned 0.0.39, so the config's old rule names were silently dead and the 0.0.104 checker reported 193 diagnostics. - pyproject: follow the 0.0.104 renames, `unresolved-import` -> `import-not-found` and `unresolved-attribute` -> `missing-attribute`. - Optional-dependency import fallbacks (PyGithub, aiohttp, cryptography): annotate the placeholder bindings `Any` instead of `= None` / `= Exception`. Keeping the real classes in the union made `Github(...)` "not callable" and every `except GithubException as e` / `e.status` a missing-union-attribute error; `HAS_GITHUB` / `HAS_AIOHTTP` / `CRYPTOGRAPHY_AVAILABLE` gate every use, so `None` was never a real state. Drops the stale `# type: ignore` + `# ty: ignore` comments. - `_assert_minted_repo_owner`: narrow the untrusted JSON payload once per level and `cast` it, instead of re-reading `r.get("owner")` inside the isinstance guard, which ty could not narrow. - `compare_commits._shape`: sort the raw files by `f.filename` (a plain `str`) instead of sorting shaped dicts, whose values are `str | None` and so fail `sorted`'s key overload. - `@asynccontextmanager` generators: return `AsyncGenerator`, not `AsyncIterator` (deprecated overload). - `github_error_handler`: rename the ignore comment to `invalid-explicit-return`; drop an unused `ty: ignore`. Co-Authored-By: Claude Sonnet 5.5 --- pyproject.toml | 4 +-- src/db/session.py | 4 +-- src/main.py | 4 +-- src/routers/github_internal.py | 2 +- src/routers/github_issue_operations.py | 4 +-- src/services/github/github_service.py | 40 +++++++++++---------- src/services/github/secure_token_manager.py | 8 +++-- src/services/github_app_auth.py | 17 +++++---- src/services/github_integration.py | 11 +++--- src/services/github_validation.py | 11 +++--- src/utils/github_error_handler.py | 2 +- 11 files changed, 62 insertions(+), 45 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e99c2e2..cb08bbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,8 +126,8 @@ include = ["src"] python-version = "3.14" [tool.ty.rules] -unresolved-import = "ignore" -unresolved-attribute = "ignore" +import-not-found = "ignore" +missing-attribute = "ignore" [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/src/db/session.py b/src/db/session.py index d9be162..d7fb1b2 100644 --- a/src/db/session.py +++ b/src/db/session.py @@ -13,7 +13,7 @@ from __future__ import annotations import asyncio -from collections.abc import AsyncIterator +from collections.abc import AsyncGenerator from contextlib import asynccontextmanager from psycopg import AsyncConnection @@ -73,7 +73,7 @@ async def get_pool() -> AsyncConnectionPool: @asynccontextmanager -async def get_connection() -> AsyncIterator[AsyncConnection]: +async def get_connection() -> AsyncGenerator[AsyncConnection]: """Yield a pooled connection; the block is one transaction (commit on exit).""" pool = await get_pool() async with pool.connection() as conn: diff --git a/src/main.py b/src/main.py index 1dd8a50..467ce9f 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ import logging import os -from collections.abc import AsyncIterator +from collections.abc import AsyncGenerator from contextlib import asynccontextmanager from typing import Any @@ -84,7 +84,7 @@ def get_security_client() -> Any: @asynccontextmanager -async def lifespan(app: FastAPI) -> AsyncIterator[None]: +async def lifespan(app: FastAPI) -> AsyncGenerator[None]: """Application startup / shutdown events.""" global _db_engine, _db_session_factory, _workspaces_client, _security_client # noqa: PLW0603 diff --git a/src/routers/github_internal.py b/src/routers/github_internal.py index bb0f552..6f757c4 100644 --- a/src/routers/github_internal.py +++ b/src/routers/github_internal.py @@ -636,7 +636,7 @@ def _lookup() -> _PrivateFlag: return CloneTokenResponse( token=token, expires_at=expires_at, - visibility=visibility, # type: ignore[invalid-argument-type] # ty: ignore[invalid-argument-type] + visibility=visibility, source=source, reason=reason, private=private, diff --git a/src/routers/github_issue_operations.py b/src/routers/github_issue_operations.py index 0baea74..b948917 100644 --- a/src/routers/github_issue_operations.py +++ b/src/routers/github_issue_operations.py @@ -20,7 +20,7 @@ from __future__ import annotations import logging -from collections.abc import AsyncIterator +from collections.abc import AsyncGenerator from contextlib import AsyncExitStack, asynccontextmanager from coding_client.auth.tenant import require_tenant @@ -60,7 +60,7 @@ async def _github( repo: str | None = None, tenant_id: str | None = None, permissions: dict[str, str] | None = None, -) -> AsyncIterator[GitHubService]: +) -> AsyncGenerator[GitHubService]: """Open a GitHubService on the App-first credential ladder. This used to read the platform PAT setting directly (since removed, 2026-09-30). diff --git a/src/services/github/github_service.py b/src/services/github/github_service.py index 00dcc10..265062d 100644 --- a/src/services/github/github_service.py +++ b/src/services/github/github_service.py @@ -24,7 +24,9 @@ HAS_AIOHTTP = True except ImportError: HAS_AIOHTTP = False - aiohttp = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] + # `Any`, not `module | None`: placeholder for an absent optional dependency. + # HAS_AIOHTTP gates the use, so the union case is not a real state. + aiohttp: Any = None try: from github import Github, GithubException, RateLimitExceededException @@ -32,11 +34,14 @@ HAS_GITHUB = True except ImportError: + # `Any`, not `type[X] | None`: placeholders for an absent optional dependency. + # Keeping the real classes in the union turns every downstream call and + # attribute access into a union-case error. HAS_GITHUB gates the use. HAS_GITHUB = False - Github = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - GithubException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - RateLimitExceededException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - Repository = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] + Github: Any = None + GithubException: Any = Exception + RateLimitExceededException: Any = Exception + Repository: Any = None from coding_client.models.github import PRFileChange, PullRequest from pydantic import BaseModel @@ -1451,19 +1456,18 @@ def _shape() -> dict[str, Any]: raw_files = list(comparison.files or []) if len(raw_files) >= GITHUB_COMPARE_FILES_CAP: raise CompareFilesTruncatedError(len(raw_files)) - files = sorted( - ( - { - "filename": f.filename, - "status": f.status, - "previous_filename": ( - f.previous_filename if f.status == "renamed" else None - ), - } - for f in raw_files - ), - key=lambda item: item["filename"], - ) + # Sort the raw files by filename (a plain `str`) rather than sorting + # the shaped dicts: the shaped values are `str | None` + # (previous_filename), so a dict-key sort hands `sorted` a union it + # cannot prove is ordered. + files = [ + { + "filename": f.filename, + "status": f.status, + "previous_filename": (f.previous_filename if f.status == "renamed" else None), + } + for f in sorted(raw_files, key=lambda f: f.filename) + ] status = comparison.status return { "status": status, diff --git a/src/services/github/secure_token_manager.py b/src/services/github/secure_token_manager.py index b83b009..d84333d 100644 --- a/src/services/github/secure_token_manager.py +++ b/src/services/github/secure_token_manager.py @@ -37,9 +37,11 @@ except ImportError: logger.warning("cryptography module not available - GitHub token encryption disabled") CRYPTOGRAPHY_AVAILABLE = False - Fernet = None # type: ignore[assignment] # ty: ignore[invalid-assignment] - hashes = None # type: ignore[assignment] # ty: ignore[invalid-assignment] - PBKDF2HMAC = None # type: ignore[assignment] # ty: ignore[invalid-assignment] + # `Any`, not `type[X] | None`: placeholders for an absent optional dependency. + # CRYPTOGRAPHY_AVAILABLE gates the use, so the union case is not a real state. + Fernet: Any = None + hashes: Any = None + PBKDF2HMAC: Any = None class TokenStatus(StrEnum): diff --git a/src/services/github_app_auth.py b/src/services/github_app_auth.py index 9e4fe44..d378d28 100644 --- a/src/services/github_app_auth.py +++ b/src/services/github_app_auth.py @@ -37,8 +37,10 @@ HAS_GITHUB = True except ImportError: # pragma: no cover - exercised only when PyGithub absent - Auth = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - GithubIntegration = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] + # `Any`, not `type[X] | None`: placeholders for an absent optional dependency. + # HAS_GITHUB gates the use, so the union case is not a real state. + Auth: Any = None + GithubIntegration: Any = None HAS_GITHUB = False logger = logging.getLogger(__name__) @@ -587,10 +589,13 @@ def _assert_minted_repo_owner(payload: object, expected_owner: str, owner: str, repos = body.get("repositories") seen: list[str] = [] if isinstance(repos, list): - for r in repos: - r = r if isinstance(r, dict) else {} - o = r.get("owner") if isinstance(r.get("owner"), dict) else {} - seen.append(f"{o.get('login') or '?'}/{r.get('name') or '?'}") + for entry in repos: + repo_dict = cast("dict[str, Any]", entry) if isinstance(entry, dict) else {} + owner_value = repo_dict.get("owner") + owner_dict = ( + cast("dict[str, Any]", owner_value) if isinstance(owner_value, dict) else {} + ) + seen.append(f"{owner_dict.get('login') or '?'}/{repo_dict.get('name') or '?'}") want = f"{expected_owner.strip().lower()}/{repo.strip().lower()}" if [x.lower() for x in seen] != [want]: logger.error( diff --git a/src/services/github_integration.py b/src/services/github_integration.py index 3d23698..559a85d 100644 --- a/src/services/github_integration.py +++ b/src/services/github_integration.py @@ -24,11 +24,14 @@ HAS_GITHUB = True except ImportError: + # `Any`, not `type[X] | None`: placeholders for an absent optional dependency. + # Keeping the real classes in the union turns every downstream call and + # attribute access into a union-case error. HAS_GITHUB gates the use. HAS_GITHUB = False - Auth = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - Github = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - GithubException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] - Repository = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment] + Auth: Any = None + Github: Any = None + GithubException: Any = Exception + Repository: Any = None FixValidator = None # Stub for patching in tests diff --git a/src/services/github_validation.py b/src/services/github_validation.py index 963a9e9..ad5d64d 100644 --- a/src/services/github_validation.py +++ b/src/services/github_validation.py @@ -6,7 +6,7 @@ import logging import os -from typing import TYPE_CHECKING, NamedTuple +from typing import TYPE_CHECKING, Any, NamedTuple from urllib.parse import urlparse if TYPE_CHECKING: @@ -19,10 +19,13 @@ HAS_GITHUB = True except ImportError: + # `Any`, not `type[X] | None`: these are placeholders for an absent optional + # dependency, so keeping the real classes in the union makes every call and + # attribute access downstream a union-case error. HAS_GITHUB gates the use. HAS_GITHUB = False - Auth = None # type: ignore[assignment] # ty: ignore[invalid-assignment] - Github = None # type: ignore[assignment] # ty: ignore[invalid-assignment] - GithubException = Exception # type: ignore[assignment] # ty: ignore[invalid-assignment] + Auth: Any = None + Github: Any = None + GithubException: Any = Exception from coding_client.exceptions.api_exceptions import NotFoundException, ValidationException from coding_client.models.container import GitHubRepoRequest diff --git a/src/utils/github_error_handler.py b/src/utils/github_error_handler.py index d0c6dfc..04f95a0 100644 --- a/src/utils/github_error_handler.py +++ b/src/utils/github_error_handler.py @@ -334,7 +334,7 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> T: import inspect if inspect.iscoroutinefunction(func): - return async_wrapper # type: ignore[return-value] # ty: ignore[invalid-return-type] + return async_wrapper # type: ignore[return-value] # ty: ignore[invalid-explicit-return] return sync_wrapper return decorator From 598214586ede0bbc288e0833567aca6a3463c816 Mon Sep 17 00:00:00 2001 From: georgiedekker Date: Sat, 14 Nov 2026 21:09:24 +0000 Subject: [PATCH 3/3] fix(ty): resolve the two diagnostics only visible against the real venv The first pass was checked with `uvx ty` before a `.venv` existed, so every third-party type resolved as Unknown and these two hid behind it. Against the pinned environment: - `get_repo_visibility` returns literally `"public"`/`"private"` on every path, so annotate it `Literal["public", "private"]`; the clone-token response's `visibility` field then type-checks without the ignore comment this repo used to carry. - `pr_change_detector`: `change.file_type` is a non-optional `FileType`, so the `else "unknown"` branch was dead; drop it. Co-Authored-By: Claude Sonnet 5.5 --- src/services/github_app_auth.py | 4 +++- .../pr_validation/analyzers/impact/pr_change_detector.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/github_app_auth.py b/src/services/github_app_auth.py index d378d28..abc64d4 100644 --- a/src/services/github_app_auth.py +++ b/src/services/github_app_auth.py @@ -663,7 +663,9 @@ def mint_public_repo_token( ) -def get_repo_visibility(owner: str, repo: str, token: str | None = None) -> str: +def get_repo_visibility( + owner: str, repo: str, token: str | None = None +) -> Literal["public", "private"]: """Return ``"public"`` or ``"private"`` for ``owner/repo``. coding-github is the only coding-* service with egress to api.github.com, so diff --git a/src/services/pr_validation/analyzers/impact/pr_change_detector.py b/src/services/pr_validation/analyzers/impact/pr_change_detector.py index f768f57..7aadeb8 100644 --- a/src/services/pr_validation/analyzers/impact/pr_change_detector.py +++ b/src/services/pr_validation/analyzers/impact/pr_change_detector.py @@ -437,7 +437,7 @@ def extract_change_metadata(self, changes: list[FileChange]) -> dict[str, Any]: # Analyze file types for change in changes: - file_type = change.file_type.value if change.file_type else "unknown" + file_type = change.file_type.value metadata["file_types"][file_type] = metadata["file_types"].get(file_type, 0) + 1 # Analyze change distribution