Skip to content

Enterprise agent platform for building, deploying, and operating AI teammates.

feat(connectors): add smoke V2 Tier 1 read checks for github (#3735)

Q1hangLb716c8328b7c
diff --git a/docs/operations/connector-smoke-v2.md b/docs/operations/connector-smoke-v2.md
index 819b412a3..98bf92f04 100644
--- a/docs/operations/connector-smoke-v2.md
+++ b/docs/operations/connector-smoke-v2.md
@@ -175,7 +175,7 @@ A path is a tuple of object keys and list indexes into the payload; `()` is the
### Fixture keys
-A fixture key is `<namespace>.<name>`, at most 80 characters: the namespace is kebab-case, by convention the app id of the connector or tenant family that owns the value, and the name is one or more dot-separated snake_case parts (`google-docs.document_id`, `jira.seed.project_key`). The identity adapter resolves keys from server-side configuration, per environment and identity (`fixtures.FixtureResolver`). An unresolved key reports the check as `skip` with `fixture_missing` and the key as the row's `reason`. Errors and results name the key, never its value. The document, Google and Microsoft 365 connectors' read checks use these keys; the probe route does not take fixtures yet (#3284).
+A fixture key is `<namespace>.<name>`, at most 80 characters: the namespace is kebab-case, by convention the app id of the connector or tenant family that owns the value, and the name is one or more dot-separated snake_case parts (`google-docs.document_id`, `jira.seed.project_key`). The identity adapter resolves keys from server-side configuration, per environment and identity (`fixtures.FixtureResolver`). An unresolved key reports the check as `skip` with `fixture_missing` and the key as the row's `reason`. Errors and results name the key, never its value. The document, Google, GitHub, Jira and Microsoft 365 connectors' read checks use these keys; the probe route does not take fixtures yet (#3284).
### Today's L3 probes
@@ -209,6 +209,10 @@ Every other Google tool is exempt: the reads outside the 80% cut; the writes, wh
The checked tools carry over 80% of each connector's calls over seven days on production-au: OneDrive 52 of 63 calls (82.5%), Teams 46 of 51 (90.2%, its L3 row's `get_current_user` included), Word 15 of 18 (83%), Excel 27 of 31 (87%) and PowerPoint 21 of 26 (80.8%). Teams' fifth read is `list_chats` rather than a second `/me` read beside `auth_status`: the chat side had no other check, and `/me/chats` needs a different Graph permission, so a grant that lost it fails a check (#3569). The other reads, Teams' `get_chat_messages` and `list_team_members` among them, are exempt as left unchecked. No Microsoft 365 connector declares a write check. A write check runs after a tenant pin, and the registry pins a Microsoft 365 connection by `microsoft-365.tenant_id`, the Entra tenant id: no tool of the OneDrive, Excel or PowerPoint servers returns a tenant id, so whether they get write checks is decided separately in #3569. Teams' `list_teams` does return each team's `tenantId`, but its writes are blocked by cleanup instead: no tool of its server deletes a message. The writes a write check could clean up (OneDrive's, Excel's worksheet and PowerPoint's slide tools) say so in their exemption. The writes that edit content in place (Word's paragraph and text edits, Excel's range, row, column and table-row edits, `powerpoint_set_shape_text`) carry the in-place reason, and those that create an object no tool of their server deletes (`word_create_document`, `excel_add_table`, `powerpoint_create_presentation`, and Teams' `send_channel_message` and `send_chat_message`) carry the no-cleanup reason.
+`github` has adopted V2 at the Tier 1 bar (#3568). Its five read checks are the five most called of its tools in the 7-day production-au tool-call volume reported on xorbitsai/xagent-saas#2532 — `github_get_current_user`, `github_get_repository`, `github_get_issue`, `github_list_commits` and `github_get_pull_request` — against the private `smoke-read` repository of the test organization, which the seed fills with two files and the commit that writes each, one issue, one branch and one pull request opened from that branch. It keeps its probe-derived `github.l3_probe` row alongside them, as `jira` and `google-analytics` do. Every check but the probe-derived one reads a value the tenant registry records under a fixture key: `github.login` (the account that answers, the one the QA member's connection uses), `github.read_repo` (the repository itself), `github.seed_file_path` (the file whose newest commit is the seed's), `github.issue_number` and `github.pull_number` (the two numbers GitHub assigns), and `github.pr_branch` (the branch the pull request comes from). The checks assert the seed's own values: the account is the one the fixture names, the repository is the one the fixture names and is private, the issue is open, is not a pull request and carries the seed's title, the newest commit on the seeded file is the seed's, and the pull request is open, not a draft, and comes from the seeded branch. The issue and pull request numbers are recorded as YAML integers, which is the type the two tools take, and each of those two checks compares the number its tool returns with the fixture under `Equals`, which compares values as JSON does. A fixture key the identity adapter has no value for reports its check as `skip` with `fixture_missing`, and the check never calls its tool. The two numbers GitHub assigns are recorded in the xagent-saas tenant fixtures. Under an identity that resolves no fixture, all five of these checks skip. The `l3_probe` row reads no fixture, so it still calls `github_get_current_user` there and fails when the grant is revoked, which the five fixture-bound rows cannot report while they skip. The seed commits a second file after the seed file, so the default branch's newest commit is not the seed file's: `github.read_commits` asks for `path` and `limit=1`, and it is that filter which finds the seed's commit rather than the branch head. The two files carry different commit messages, so a check that dropped `path` would judge the branch head's message and fail. Before the seed creates its file, `github.read_commits` finds no commit to judge and fails.
+
+Every other GitHub tool is exempt. Eight reads beyond the five stay unchecked: GitHub's 80% cut takes eight tools of its 89 calls, and under the rule of #3568 the probe-derived row does not take one of the five read slots, so the five most called tools carry 52 of the 89 calls (58.4%); the cumulative share passes 80% only at the eighth tool (82.0%). The cap stays at five, and GitHub is recorded at its 58.4% share (#3568): the five read checks `github` declares stay within the cap and `github.current_user` stays because it asserts which account answers, which the probe-derived row does not. Seven writes share one reason: the server has no tool that deletes an issue, a comment, a pull request, a branch, a commit, a release or a submodule pointer, so a write check would have nothing to clean up with, and the write flows wait for a cleanup path (#3568). The eighth write, `github_update_release`, edits a release in place rather than creating one, so it carries the in-place-edit reason instead.
+
## Identity adapters
The engine runs as an identity through an `IdentityAdapter` (`identity.py`):
diff --git a/src/xagent/web/connector_checks/registry.py b/src/xagent/web/connector_checks/registry.py
index 27454844e..e9ecc0b64 100644
--- a/src/xagent/web/connector_checks/registry.py
+++ b/src/xagent/web/connector_checks/registry.py
@@ -41,6 +41,7 @@ from .fixtures import FixtureRef
# Why a tool of an in-repo connector has no check yet (#3565). A reason for
# work still to come names the issue of the connector's family that decides
# it; a write whose object no tool can delete is a reason of its own.
+_GITHUB_TIER_1 = "#3568"
_GOOGLE_TIER_1 = "#3567"
_JIRA_TIER_1 = "#3570"
_MICROSOFT_365_TIER_1 = "#3569"
@@ -73,6 +74,15 @@ _SLIDE_THUMBNAIL_WITHOUT_SLIDE_ID = (
"seed deck holds Google's default slide, but no fixture names it, so "
"whether a check is added is decided in #3567"
)
+# GitHub's 80% cut takes eight tools of its 89 calls in the 7-day production-au
+# volume reported on xorbitsai/xagent-saas#2532, and a Tier 1 connector declares
+# at most five read checks. The five go to the most called tools, and the rest
+# stay unchecked (#3568).
+_GITHUB_READS_BEYOND_THE_FIVE = (
+ "read left unchecked: GitHub's 80% cut needs more tools than the five read "
+ "checks a Tier 1 connector declares, so the five most called carry the "
+ f"checks, as decided in {_GITHUB_TIER_1}"
+)
# The registry pins a Microsoft 365 connection by microsoft-365.tenant_id,
# the Entra tenant id, and no tool of the OneDrive, Excel or PowerPoint
# servers returns one, so their write checks would have no tenant pin to run
@@ -710,6 +720,130 @@ CONNECTOR_CHECKS: Mapping[str, ConnectorChecks] = {
writes_without_cleanup=("excel_add_table",),
),
),
+ # Tier 1 (#3568): the five most called reads, against the test
+ # organization's private read repository, which the seed fills with two
+ # files and the commit that writes each, one issue, one branch and one pull
+ # request opened from it. The two checks that read the issue and the pull
+ # request compare the number the tool returns with the one the tenant
+ # fixtures record. The probe-derived `github.l3_probe` stays alongside
+ # them, as it does for jira and google-analytics: it reads no fixture, so
+ # a revoked grant that the fixture-bound checks cannot call still fails a
+ # row.
+ "github": ConnectorChecks(
+ "github",
+ reads=(
+ _declared_l3("github"),
+ ReadCheck(
+ "github.current_user",
+ "github_get_current_user",
+ assertions=(
+ StatusSuccess(),
+ HasKeys(("user",), ("login", "id", "html_url")),
+ Equals(("user", "login"), FixtureRef("github.login")),
+ ),
+ ),
+ ReadCheck(
+ "github.read_repository",
+ "github_get_repository",
+ {"repo": FixtureRef("github.read_repo")},
+ assertions=(
+ StatusSuccess(),
+ HasKeys(
+ ("repository",),
+ ("full_name", "private", "default_branch", "html_url"),
+ ),
+ Equals(("repository", "full_name"), FixtureRef("github.read_repo")),
+ Equals(("repository", "private"), True),
+ ),
+ ),
+ ReadCheck(
+ "github.read_issue",
+ "github_get_issue",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "issue_number": FixtureRef("github.issue_number"),
+ },
+ assertions=(
+ StatusSuccess(),
+ HasKeys(
+ ("issue",),
+ ("number", "title", "state", "labels", "user", "html_url"),
+ ),
+ Equals(("issue", "number"), FixtureRef("github.issue_number")),
+ Equals(("issue", "title"), "xagent smoke seed issue"),
+ Equals(("issue", "state"), "open"),
+ Equals(("issue", "is_pull_request"), False),
+ ),
+ ),
+ ReadCheck(
+ "github.read_commits",
+ "github_list_commits",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "path": FixtureRef("github.seed_file_path"),
+ "limit": 1,
+ },
+ assertions=(
+ StatusSuccess(),
+ HasKeys((), ("commits", "truncated")),
+ Length(("commits",), 1, 1),
+ EachHasKeys(("commits",), ("sha", "message", "author", "date")),
+ Equals(("commits", 0, "message"), "xagent smoke seed"),
+ ),
+ ),
+ ReadCheck(
+ "github.read_pull_request",
+ "github_get_pull_request",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "pull_number": FixtureRef("github.pull_number"),
+ },
+ assertions=(
+ StatusSuccess(),
+ HasKeys(
+ ("pull_request",),
+ ("number", "title", "state", "head", "base", "draft"),
+ ),
+ Equals(
+ ("pull_request", "number"),
+ FixtureRef("github.pull_number"),
+ ),
+ Equals(("pull_request", "title"), "xagent smoke seed pull request"),
+ Equals(("pull_request", "state"), "open"),
+ Equals(("pull_request", "draft"), False),
+ Equals(("pull_request", "head"), FixtureRef("github.pr_branch")),
+ ),
+ ),
+ ),
+ exemptions=(
+ *(
+ ToolExemption(tool, _GITHUB_READS_BEYOND_THE_FIVE)
+ for tool in (
+ "github_get_file_contents",
+ "github_get_latest_release",
+ "github_get_ref_status",
+ "github_list_issues",
+ "github_list_pull_requests",
+ "github_list_workflow_runs",
+ "github_search_code",
+ "github_search_repositories",
+ )
+ ),
+ *_exemptions(
+ issue=_GITHUB_TIER_1,
+ in_place_edits=("github_update_release",),
+ writes_without_cleanup=(
+ "github_comment_on_issue",
+ "github_create_branch",
+ "github_create_issue",
+ "github_create_or_update_file",
+ "github_create_pull_request",
+ "github_create_release",
+ "github_update_submodule",
+ ),
+ ),
+ ),
+ ),
"gmail": ConnectorChecks(
"gmail",
reads=(
@@ -1445,7 +1579,6 @@ LEGACY_CONNECTORS: frozenset[str] = frozenset(
"facebook",
"fireflies",
"freshdesk",
- "github",
"google-maps",
"google-search-console",
"granola",
diff --git a/tests/web/connector_checks/test_cli.py b/tests/web/connector_checks/test_cli.py
index ba2bd723e..5964c7271 100644
--- a/tests/web/connector_checks/test_cli.py
+++ b/tests/web/connector_checks/test_cli.py
@@ -20,7 +20,12 @@ from typing import Any
import jsonschema
import pytest
-from tests.web.services.test_connector_probe import _github_ok, _Loader
+from tests.web.services.test_connector_probe import (
+ _connect_catalog_stripe,
+ _github_ok,
+ _Loader,
+ _stripe_ok,
+)
from tests.web.services.test_mcp_connector_session import (
LOADER,
_connect_github,
@@ -382,8 +387,8 @@ def test_a_probe_user_runs_their_connectors_checks(
db_users, probe_users, monkeypatch, capfd
):
db, user, _ = db_users
- _connect_github(db, user)
- monkeypatch.setattr(LOADER, _Loader(_github_ok()))
+ _connect_catalog_stripe(db, user)
+ monkeypatch.setattr(LOADER, _Loader(_stripe_ok()))
_with_database(monkeypatch, db)
code = cli.main(["--user", "[email protected]"])
@@ -393,7 +398,7 @@ def test_a_probe_user_runs_their_connectors_checks(
assert [
(row["connector"], row["check"], row["outcome"])
for row in _document(out)["rows"]
- ] == [("github", None, "pass"), ("github", "github.l3_probe", "pass")]
+ ] == [("stripe", None, "pass"), ("stripe", "stripe.l3_probe", "pass")]
@pytest.mark.parametrize(
diff --git a/tests/web/connector_checks/test_registry.py b/tests/web/connector_checks/test_registry.py
index d1d9f8ccb..48b39b40e 100644
--- a/tests/web/connector_checks/test_registry.py
+++ b/tests/web/connector_checks/test_registry.py
@@ -5,12 +5,16 @@ from __future__ import annotations
import inspect
import json
from collections.abc import Callable, Iterator, Mapping
+from contextlib import asynccontextmanager
+from types import SimpleNamespace
from typing import Any
from unittest.mock import Mock
import pytest
from mcp.server.fastmcp.exceptions import ToolError
+from xagent.core.tools.adapters.vibe import mcp_adapter
+from xagent.core.tools.adapters.vibe.mcp_adapter import MCPToolAdapter
from xagent.web.builtin_mcp_registry import get_builtin_public_mcp_app_rows
from xagent.web.connector_checks.assertions import judge_result, resolve_expected
from xagent.web.connector_checks.declarations import (
@@ -30,7 +34,9 @@ from xagent.web.connector_checks.declarations import (
UnprobeableCheck,
validate_connector_checks,
)
+from xagent.web.connector_checks.fixtures import FixtureValue, resolve_fixtures
from xagent.web.connector_checks.registry import (
+ _GITHUB_READS_BEYOND_THE_FIVE,
_GMAIL_LABEL_WITHOUT_READ,
_SLIDE_THUMBNAIL_WITHOUT_SLIDE_ID,
CONNECTOR_CHECKS,
@@ -43,6 +49,7 @@ from xagent.web.connector_checks.results import FailureClass
from xagent.web.tools.mcp import calendar as google_calendar
from xagent.web.tools.mcp import (
excel,
+ github,
gmail,
google_ads,
google_analytics,
@@ -1194,10 +1201,16 @@ _GOOGLE_FIXTURE_KEYS_USED = frozenset(
class _Fixtures:
- """The Google seed's values, as the identity adapter would resolve them."""
+ """The seeds' values, as the identity adapter would resolve them."""
_VALUES = {
"gmail.seed_label_id": "Label_1",
+ "github.issue_number": 1,
+ "github.login": "xagent-app",
+ "github.pr_branch": "xagent-smoke-seed",
+ "github.pull_number": 2,
+ "github.read_repo": "xagent-smoke/smoke-read",
+ "github.seed_file_path": "seed.md",
"google-analytics.property_id": "563334905",
"google-docs.document_id": "doc-1",
"google-drive.seed_folder_id": "folder-1",
@@ -1205,14 +1218,14 @@ class _Fixtures:
"google-slides.presentation_id": "deck-1",
}
- def resolve_fixture(self, key: str) -> str | None:
+ def resolve_fixture(self, key: str) -> FixtureValue | None:
return self._VALUES.get(key)
_FIXTURES = _Fixtures()
-def _google_fixture_keys(check: ReadCheck) -> Iterator[FixtureRef]:
+def _fixture_keys(check: ReadCheck) -> Iterator[FixtureRef]:
yield from _fixture_refs(check.arguments)
for assertion in check.assertions:
if isinstance(assertion, Equals):
@@ -1285,7 +1298,7 @@ def test_the_google_read_checks_use_exactly_these_fixture_keys() -> None:
for app_id in _GOOGLE_APP_MODULES
for check in CONNECTOR_CHECKS[app_id].reads
if isinstance(check, ReadCheck)
- for ref in _google_fixture_keys(check)
+ for ref in _fixture_keys(check)
}
assert keys == _GOOGLE_FIXTURE_KEYS_USED
@@ -2026,3 +2039,657 @@ def test_a_google_fixture_check_fails_on_an_error_envelope(
monkeypatch.setattr(module, dependency, _unreachable)
_assert_check_fails(check_id, call(), "status_success")
+
+
+# --- GitHub (#3568) ------------------------------------------------------------------
+
+_READ_REPO = "xagent-smoke/smoke-read"
+
+# The read checks, pinned: the tool, its arguments and its assertions. Five of
+# them are the five most called tools of the 89 GitHub calls in the 7-day
+# production-au tool-call volume reported on xorbitsai/xagent-saas#2532, the
+# five read checks a Tier 1 connector declares at most; `github.l3_probe` is
+# the probe-derived one the connector keeps alongside them, so a check that
+# reads no fixture still calls GitHub.
+_GITHUB_READS: Mapping[str, tuple[str, dict[str, Any], tuple[Assertion, ...]]] = {
+ "github.l3_probe": ("github_get_current_user", {}, (L3Envelope(),)),
+ "github.current_user": (
+ "github_get_current_user",
+ {},
+ (
+ StatusSuccess(),
+ HasKeys(("user",), ("login", "id", "html_url")),
+ Equals(("user", "login"), FixtureRef("github.login")),
+ ),
+ ),
+ "github.read_repository": (
+ "github_get_repository",
+ {"repo": FixtureRef("github.read_repo")},
+ (
+ StatusSuccess(),
+ HasKeys(
+ ("repository",),
+ ("full_name", "private", "default_branch", "html_url"),
+ ),
+ Equals(("repository", "full_name"), FixtureRef("github.read_repo")),
+ Equals(("repository", "private"), True),
+ ),
+ ),
+ "github.read_issue": (
+ "github_get_issue",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "issue_number": FixtureRef("github.issue_number"),
+ },
+ (
+ StatusSuccess(),
+ HasKeys(
+ ("issue",),
+ ("number", "title", "state", "labels", "user", "html_url"),
+ ),
+ Equals(("issue", "number"), FixtureRef("github.issue_number")),
+ Equals(("issue", "title"), "xagent smoke seed issue"),
+ Equals(("issue", "state"), "open"),
+ Equals(("issue", "is_pull_request"), False),
+ ),
+ ),
+ "github.read_commits": (
+ "github_list_commits",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "path": FixtureRef("github.seed_file_path"),
+ "limit": 1,
+ },
+ (
+ StatusSuccess(),
+ HasKeys((), ("commits", "truncated")),
+ Length(("commits",), 1, 1),
+ EachHasKeys(("commits",), ("sha", "message", "author", "date")),
+ Equals(("commits", 0, "message"), "xagent smoke seed"),
+ ),
+ ),
+ "github.read_pull_request": (
+ "github_get_pull_request",
+ {
+ "repo": FixtureRef("github.read_repo"),
+ "pull_number": FixtureRef("github.pull_number"),
+ },
+ (
+ StatusSuccess(),
+ HasKeys(
+ ("pull_request",),
+ ("number", "title", "state", "head", "base", "draft"),
+ ),
+ Equals(("pull_request", "number"), FixtureRef("github.pull_number")),
+ Equals(("pull_request", "title"), "xagent smoke seed pull request"),
+ Equals(("pull_request", "state"), "open"),
+ Equals(("pull_request", "draft"), False),
+ Equals(("pull_request", "head"), FixtureRef("github.pr_branch")),
+ ),
+ ),
+}
+
+# The fixture keys the GitHub read checks use, pinned here so that adding or
+# dropping one shows in the diff. The xagent-saas tenant fixtures record the
+# login, the three ids the seed's layout knows, and the two numbers GitHub
+# assigns (xorbitsai/xagent-saas#2533).
+_GITHUB_FIXTURE_KEYS_USED = frozenset(
+ {
+ "github.issue_number",
+ "github.login",
+ "github.pr_branch",
+ "github.pull_number",
+ "github.read_repo",
+ "github.seed_file_path",
+ }
+)
+
+# The reads left to an exemption: GitHub's 80% cut needs eight tools, and the
+# five most called have the checks.
+_GITHUB_READS_BEYOND_THE_FIVE_TOOLS = frozenset(
+ {
+ "github_get_file_contents",
+ "github_get_latest_release",
+ "github_get_ref_status",
+ "github_list_issues",
+ "github_list_pull_requests",
+ "github_list_workflow_runs",
+ "github_search_code",
+ "github_search_repositories",
+ }
+)
+
+# The writes that create an object GitHub's own tools cannot remove: the server
+# has no delete tool at all, so a write check would have nothing to clean up
+# with. A release edit is the one write that creates no object.
+_GITHUB_WRITES_WITHOUT_CLEANUP = frozenset(
+ {
+ "github_comment_on_issue",
+ "github_create_branch",
+ "github_create_issue",
+ "github_create_or_update_file",
+ "github_create_pull_request",
+ "github_create_release",
+ "github_update_submodule",
+ }
+)
+
+
[email protected](("check_id", "expected"), sorted(_GITHUB_READS.items()))
+def test_a_github_read_check_is_declared_exactly(
+ check_id: str, expected: tuple[str, dict[str, Any], tuple[Assertion, ...]]
+) -> None:
+ tool, arguments, assertions = expected
+ check = _read_check(check_id)
+ assert (check.tool, dict(check.arguments), check.assertions) == (
+ tool,
+ arguments,
+ assertions,
+ )
+
+
+def test_a_github_connector_declares_exactly_its_reads() -> None:
+ assert [check.id for check in CONNECTOR_CHECKS["github"].reads] == list(
+ _GITHUB_READS
+ )
+
+
+def test_the_github_read_checks_use_exactly_these_fixture_keys() -> None:
+ keys = {
+ ref.key
+ for check in CONNECTOR_CHECKS["github"].reads
+ if isinstance(check, ReadCheck)
+ for ref in _fixture_keys(check)
+ }
+
+ assert keys == _GITHUB_FIXTURE_KEYS_USED
+
+
+def test_a_github_fixture_is_bound_to_a_parameter_of_its_tool() -> None:
+ """A fixture in the arguments names a parameter of the tool, and every
+ required argument is pinned: an omitted one would make the tool prompt.
+ That the value is the type the parameter declares is the adapter test's
+ judgement, below."""
+ for check in CONNECTOR_CHECKS["github"].reads:
+ if not isinstance(check, ReadCheck):
+ continue
+ parameters = inspect.signature(getattr(github, check.tool)).parameters
+ bound = [
+ name for name, value in check.arguments.items() if any(_fixture_refs(value))
+ ]
+ for name in bound:
+ assert name in parameters, (check.tool, name)
+ required = {
+ name
+ for name, parameter in parameters.items()
+ if parameter.default is inspect.Parameter.empty
+ and parameter.kind not in (parameter.VAR_POSITIONAL, parameter.VAR_KEYWORD)
+ }
+ assert required <= set(check.arguments), (check.tool, required)
+
+
+async def test_a_github_fixture_bound_argument_passes_the_tools_own_validation(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The value a fixture resolves to survives the adapter's own checks.
+
+ The tools validate their arguments locally before a call leaves, and a
+ string where a tool declares an integer is refused there, so a fixture the
+ registry holds as a string would make its check fail on every run. The
+ session is replaced with one that refuses: reaching it means the adapter
+ accepted the arguments.
+ """
+ reached: list[str] = []
+
+ @asynccontextmanager
+ async def _refuse_session(connection: Any) -> Any:
+ reached.append(str(connection))
+ raise RuntimeError("no server in this test")
+ yield # pragma: no cover
+
+ monkeypatch.setattr(mcp_adapter, "create_session", _refuse_session)
+ tools = {tool.name: tool for tool in await github.mcp.list_tools()}
+ for check in CONNECTOR_CHECKS["github"].reads:
+ if not isinstance(check, ReadCheck) or not any(_fixture_refs(check.arguments)):
+ continue
+ adapter = MCPToolAdapter(
+ mcp_tool=tools[check.tool],
+ connection={
+ "transport": "streamable_http",
+ "url": "https://mcp.example.test",
+ },
+ )
+ reached.clear()
+
+ raw = await adapter.run_json_async(
+ resolve_fixtures(dict(check.arguments), _FIXTURES)
+ )
+
+ assert reached, (check.id, raw)
+ assert "Invalid MCP tool arguments" not in raw["content"][0]["text"], check.id
+
+
+def test_a_github_read_outside_the_five_is_exempt_for_the_cut() -> None:
+ exemptions = {
+ exemption.tool: exemption.reason
+ for exemption in CONNECTOR_CHECKS["github"].exemptions
+ }
+
+ for tool in _GITHUB_READS_BEYOND_THE_FIVE_TOOLS:
+ assert exemptions[tool] == _GITHUB_READS_BEYOND_THE_FIVE, tool
+ assert set(exemptions) == _GITHUB_READS_BEYOND_THE_FIVE_TOOLS | (
+ _GITHUB_WRITES_WITHOUT_CLEANUP | {"github_update_release"}
+ )
+
+
+def test_a_github_write_has_no_cleanup_tool() -> None:
+ """Every write but a release edit creates an object, and the server has no
+ delete tool for any of them, so no write check can clean up yet."""
+ exemptions = {
+ exemption.tool: exemption.reason
+ for exemption in CONNECTOR_CHECKS["github"].exemptions
+ }
+
+ for tool in _GITHUB_WRITES_WITHOUT_CLEANUP:
+ assert exemptions[tool] == WRITE_WITHOUT_CLEANUP, tool
+
+
+def test_the_github_release_edit_waits_on_an_edit_step() -> None:
+ exemption = next(
+ exemption
+ for exemption in CONNECTOR_CHECKS["github"].exemptions
+ if exemption.tool == "github_update_release"
+ )
+
+ assert exemption.reason == (
+ "write that edits content in place: a write check creates, verifies "
+ "and deletes its own object and has no step for an edit, so whether a "
+ "check is added is decided in #3568"
+ )
+
+
+# Output samples for the GitHub read checks
+
+
+class _GitHubResponse:
+ """The part of a ``requests`` response ``github.py`` reads."""
+
+ def __init__(self, body: Any, status: int = 200) -> None:
+ self.status_code = status
+ self.content = json.dumps(body).encode()
+ self.headers: dict[str, str] = {}
+
+ def json(self) -> Any:
+ return json.loads(self.content)
+
+
+def _fake_github(
+ monkeypatch: pytest.MonkeyPatch,
+ *routes: tuple[str, str, Any],
+ status: int = 200,
+) -> dict[tuple[str, str], Any]:
+ """``github.py``'s HTTP layer: one body per route, answered with ``status``,
+ and the query params every request carried. A callable body is answered
+ from the params, for a route whose answer depends on them."""
+ # The token the server reads its grant from; the fake transport never sends
+ # it anywhere.
+ monkeypatch.setenv("GITHUB_ACCESS_TOKEN", "access-token")
+ bodies = {(method, path): body for method, path, body in routes}
+ params_of: dict[tuple[str, str], Any] = {}
+
+ def request(**kwargs: Any) -> _GitHubResponse:
+ route = (
+ kwargs["method"],
+ str(kwargs["url"]).removeprefix(github.GITHUB_BASE_URL),
+ )
+ params_of[route] = kwargs.get("params")
+ try:
+ body = bodies[route]
+ except KeyError:
+ raise AssertionError(f"unrouted request: {route[0]} {route[1]}") from None
+ if callable(body):
+ body = body(params_of[route] or {})
+ return _GitHubResponse(body, status)
+
+ monkeypatch.setattr(github, "requests", SimpleNamespace(request=request))
+ return params_of
+
+
+def _github_repository(**overrides: Any) -> dict[str, Any]:
+ return {
+ "full_name": _READ_REPO,
+ "private": True,
+ "default_branch": "main",
+ "html_url": "https://github.com/xagent-smoke/smoke-read",
+ "description": "Seed repository of the GitHub smoke tenant",
+ "stargazers_count": 0,
+ "open_issues_count": 2,
+ "language": None,
+ "updated_at": "2026-11-12T00:00:00Z",
+ **overrides,
+ }
+
+
+def _github_issue(**overrides: Any) -> dict[str, Any]:
+ return {
+ "number": 1,
+ "title": "xagent smoke seed issue",
+ "state": "open",
+ "body": "Seeded issue the read checks assert on.",
+ "labels": [],
+ "user": {"login": "xagent-app"},
+ "comments": 0,
+ "html_url": "https://github.com/xagent-smoke/smoke-read/issues/1",
+ "created_at": "2026-11-12T00:00:00Z",
+ "updated_at": "2026-11-12T00:00:00Z",
+ **overrides,
+ }
+
+
+def _github_commit(**overrides: Any) -> dict[str, Any]:
+ return {
+ "sha": "0" * 40,
+ "commit": {
+ "message": "xagent smoke seed",
+ "author": {"name": "xagent-app", "date": "2026-11-12T00:00:00Z"},
+ },
+ "html_url": "https://github.com/xagent-smoke/smoke-read/commit/" + "0" * 40,
+ **overrides,
+ }
+
+
+def _github_pull_request(**overrides: Any) -> dict[str, Any]:
+ return {
+ "number": 2,
+ "title": "xagent smoke seed pull request",
+ "state": "open",
+ "body": "Seeded pull request the read checks assert on.",
+ "user": {"login": "xagent-app"},
+ "head": {"ref": "xagent-smoke-seed"},
+ "base": {"ref": "main"},
+ "draft": False,
+ "merged": False,
+ "mergeable": True,
+ "html_url": "https://github.com/xagent-smoke/smoke-read/pull/2",
+ "created_at": "2026-11-12T00:00:00Z",
+ "updated_at": "2026-11-12T00:00:00Z",
+ **overrides,
+ }
+
+
+def _github_user(**overrides: Any) -> dict[str, Any]:
+ return {
+ "login": "xagent-app",
+ "id": 424242,
+ "name": "Xagent Smoke",
+ "email": None,
+ "company": None,
+ "bio": None,
+ "public_repos": 0,
+ "followers": 0,
+ "following": 0,
+ "html_url": "https://github.com/xagent-app",
+ **overrides,
+ }
+
+
+def _github_declared_output(check_id: str) -> str:
+ """The check's own tool called with the arguments its declaration resolves
+ to: the sample is the call the check makes, not one built from literals."""
+ check = _read_check(check_id)
+ return getattr(github, check.tool)(
+ **resolve_fixtures(dict(check.arguments), _FIXTURES)
+ )
+
+
+def test_github_current_user_output_satisfies_its_declaration(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _fake_github(monkeypatch, ("GET", "/user", _github_user()))
+
+ _assert_check_output(
+ "github.current_user", _github_declared_output("github.current_user")
+ )
+
+
+def test_github_current_user_output_fails_on_another_account(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # The tenant registry pins the account the QA member's connection uses. An
+ # account that can see the private repository passes the other four checks,
+ # so this is the one that notices the wrong account.
+ _fake_github(monkeypatch, ("GET", "/user", _github_user(login="qhhh-personal")))
+
+ _assert_check_fails(
+ "github.current_user", github.github_get_current_user(), "equals"
+ )
+
+
+def test_github_repository_output_satisfies_its_declaration(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}", _github_repository()),
+ )
+
+ _assert_check_output(
+ "github.read_repository", _github_declared_output("github.read_repository")
+ )
+
+
+def test_github_repository_output_fails_on_another_repository(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _fake_github(
+ monkeypatch,
+ (
+ "GET",
+ f"/repos/{_READ_REPO}",
+ _github_repository(full_name="xagent-smoke/smoke-write"),
+ ),
+ )
+
+ _assert_check_fails(
+ "github.read_repository",
+ github.github_get_repository(_READ_REPO),
+ "equals",
+ )
+
+
+def test_github_repository_output_fails_on_a_public_repository(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # A public repository is readable without the organization's grant, so the
+ # check would no longer see a revoked one.
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}", _github_repository(private=False)),
+ )
+
+ _assert_check_fails(
+ "github.read_repository",
+ github.github_get_repository(_READ_REPO),
+ "equals",
+ )
+
+
+def test_github_issue_output_satisfies_its_declaration(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}/issues/1", _github_issue()),
+ )
+
+ _assert_check_output(
+ "github.read_issue", _github_declared_output("github.read_issue")
+ )
+
+
+def test_github_issue_output_fails_on_a_pull_request(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # GitHub answers both from the issues endpoints, and a number that reaches
+ # a pull request proves the fixture names the wrong one.
+ _fake_github(
+ monkeypatch,
+ (
+ "GET",
+ f"/repos/{_READ_REPO}/issues/1",
+ _github_issue(pull_request={"url": "https://api.github.com/x"}),
+ ),
+ )
+
+ _assert_check_fails(
+ "github.read_issue", github.github_get_issue(_READ_REPO, 1), "equals"
+ )
+
+
+def test_github_issue_output_fails_on_another_number(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # The fixture names the issue the seed creates, so a payload carrying
+ # another number is not the issue the check reads.
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}/issues/1", _github_issue(number=7)),
+ )
+
+ _assert_check_fails(
+ "github.read_issue", github.github_get_issue(_READ_REPO, 1), "equals"
+ )
+
+
+def test_github_commits_output_satisfies_its_declaration(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ params_of = _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}/commits", [_github_commit()]),
+ )
+
+ _assert_check_output(
+ "github.read_commits", _github_declared_output("github.read_commits")
+ )
+ # The declaration's `path` and `limit` are what GitHub is asked for: a
+ # dropped path would judge the branch head instead of the seed file's
+ # commit.
+ assert params_of[("GET", f"/repos/{_READ_REPO}/commits")] == {
+ "per_page": 1,
+ "page": 1,
+ "path": "seed.md",
+ }
+
+
+def test_github_commits_output_judges_the_seed_files_commit_not_the_branch_head(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The default branch's newest commit is the seed's second file, under the
+ message the seed writes there, so it is not the message the check asserts;
+ the check reads the seed file's history, so it still passes."""
+ head = _github_commit(
+ commit={
+ "message": "xagent smoke seed after",
+ "author": {"name": "xagent-app", "date": "2026-11-12T00:00:01Z"},
+ }
+ )
+ seeded = _github_commit()
+ _fake_github(
+ monkeypatch,
+ (
+ "GET",
+ f"/repos/{_READ_REPO}/commits",
+ lambda params: [seeded] if params.get("path") == "seed.md" else [head],
+ ),
+ )
+
+ _assert_check_output(
+ "github.read_commits", _github_declared_output("github.read_commits")
+ )
+
+
+def test_github_commits_output_fails_on_another_commit(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ another = _github_commit(
+ commit={"message": "edit by hand", "author": {"name": "someone"}}
+ )
+ _fake_github(monkeypatch, ("GET", f"/repos/{_READ_REPO}/commits", [another]))
+
+ _assert_check_fails(
+ "github.read_commits",
+ github.github_list_commits(_READ_REPO, path="seed.md", limit=1),
+ "equals",
+ )
+
+
+def test_github_pull_request_output_satisfies_its_declaration(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}/pulls/2", _github_pull_request()),
+ )
+
+ _assert_check_output(
+ "github.read_pull_request", _github_declared_output("github.read_pull_request")
+ )
+
+
+def test_github_pull_request_output_fails_on_another_head(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # The head is the seed's branch, so a pull request opened from anywhere
+ # else is not the seeded one.
+ _fake_github(
+ monkeypatch,
+ (
+ "GET",
+ f"/repos/{_READ_REPO}/pulls/2",
+ _github_pull_request(head={"ref": "someone-elses-branch"}),
+ ),
+ )
+
+ _assert_check_fails(
+ "github.read_pull_request",
+ github.github_get_pull_request(_READ_REPO, 2),
+ "equals",
+ )
+
+
+def test_github_pull_request_output_fails_on_another_number(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # The fixture names the pull request the seed opens, so a payload carrying
+ # another number is not the one the check reads.
+ _fake_github(
+ monkeypatch,
+ ("GET", f"/repos/{_READ_REPO}/pulls/2", _github_pull_request(number=9)),
+ )
+
+ _assert_check_fails(
+ "github.read_pull_request",
+ github.github_get_pull_request(_READ_REPO, 2),
+ "equals",
+ )
+
+
+ ("check_id", "path"),
+ [
+ ("github.current_user", "/user"),
+ ("github.read_repository", f"/repos/{_READ_REPO}"),
+ ("github.read_issue", f"/repos/{_READ_REPO}/issues/1"),
+ ("github.read_commits", f"/repos/{_READ_REPO}/commits"),
+ ("github.read_pull_request", f"/repos/{_READ_REPO}/pulls/2"),
+ ],
+)
+def test_a_github_check_fails_on_a_revoked_grant(
+ monkeypatch: pytest.MonkeyPatch, check_id: str, path: str
+) -> None:
+ # A revoked token is a 401 with this body: the tool catches the error and
+ # returns its error envelope, which the check sees as not a success.
+ _fake_github(monkeypatch, ("GET", path, {"message": "Bad credentials"}), status=401)
+
+ _assert_check_fails(check_id, _github_declared_output(check_id), "status_success")
diff --git a/tests/web/connector_checks/test_tool_coverage.py b/tests/web/connector_checks/test_tool_coverage.py
index ef47eb081..64ff45bb7 100644
--- a/tests/web/connector_checks/test_tool_coverage.py
+++ b/tests/web/connector_checks/test_tool_coverage.py
@@ -40,7 +40,6 @@ _PINNED_LEGACY = frozenset(
"facebook",
"fireflies",
"freshdesk",
- "github",
"google-maps",
"google-search-console",
"granola",
diff --git a/tests/web/connector_checks/test_user_identity.py b/tests/web/connector_checks/test_user_identity.py
index 7654eacdd..99e57a123 100644
--- a/tests/web/connector_checks/test_user_identity.py
+++ b/tests/web/connector_checks/test_user_identity.py
@@ -11,6 +11,8 @@ from typing import Any
import pytest
from tests.web.services.test_connector_probe import (
+ _chartmogul_ok,
+ _connect_catalog_chartmogul,
_connect_catalog_stripe,
_custom_row,
_github_ok,
@@ -49,10 +51,10 @@ async def test_the_users_connected_catalog_connectors_run_their_checks(
db_users, monkeypatch
):
db, user, _ = db_users
+ _connect_catalog_chartmogul(db, user)
_connect_catalog_stripe(db, user)
- _connect_github(db, user)
- github, stripe = _github_ok(), _stripe_ok()
- loader = _Loader(github, stripe)
+ chartmogul, stripe = _chartmogul_ok(), _stripe_ok()
+ loader = _Loader(chartmogul, stripe)
monkeypatch.setattr(LOADER, loader)
result = await run_checks(UserIdentityAdapter(db, "monitor"))
@@ -60,14 +62,14 @@ async def test_the_users_connected_catalog_connectors_run_their_checks(
assert result.identity == "user"
assert result.failure is None
assert rows(result) == [
- ("github", None, "pass", None, None),
- ("github", "github.l3_probe", "pass", None, None),
+ ("chartmogul", None, "pass", None, None),
+ ("chartmogul", "chartmogul.l3_probe", "pass", None, None),
("stripe", None, "pass", None, None),
("stripe", "stripe.l3_probe", "pass", None, None),
]
# One listing per connector, then one call per check.
assert len(loader.calls) == 2
- assert github.calls == [{}]
+ assert chartmogul.calls == [{"per_page": 1}]
assert len(stripe.calls) == 1
@@ -122,6 +124,31 @@ async def test_a_user_is_found_by_email_case_insensitively(
assert rows(result)[0] == ("github", None, "pass", None, None)
+async def test_a_github_grant_is_still_judged_where_the_checks_need_fixtures(
+ db_users, monkeypatch
+):
+ """The user identity resolves no fixture, so the five fixture-bound GitHub
+ checks skip without a call, while the probe-derived row reads none and still
+ calls its tool and reports a result. A revoked grant, which fails that row,
+ is covered by the 401 case in `test_registry.py`."""
+ db, user, _ = db_users
+ _connect_github(db, user)
+ monkeypatch.setattr(LOADER, _Loader(_github_ok()))
+
+ result = await run_checks(UserIdentityAdapter(db, "monitor"))
+
+ fixture_missing = ("skip", "fixture_missing")
+ assert rows(result) == [
+ ("github", None, "pass", None, None),
+ ("github", "github.l3_probe", "pass", None, None),
+ ("github", "github.current_user", *fixture_missing, "github.login"),
+ ("github", "github.read_repository", *fixture_missing, "github.read_repo"),
+ ("github", "github.read_issue", *fixture_missing, "github.read_repo"),
+ ("github", "github.read_commits", *fixture_missing, "github.read_repo"),
+ ("github", "github.read_pull_request", *fixture_missing, "github.read_repo"),
+ ]
+
+
async def test_the_allow_list_is_matched_on_the_user_found(db_users, monkeypatch):
"""Named by username, allowed by email: one account, one rule
(``is_connector_probe_user``)."""
@@ -153,12 +180,12 @@ async def test_a_custom_server_is_not_a_target(db_users, monkeypatch):
db.add(custom)
db.commit()
_link(db, user, custom)
- _connect_github(db, user)
- monkeypatch.setattr(LOADER, _Loader(_github_ok()))
+ _connect_catalog_stripe(db, user)
+ monkeypatch.setattr(LOADER, _Loader(_stripe_ok()))
result = await run_checks(UserIdentityAdapter(db, "monitor"))
- assert [row[0] for row in rows(result)] == ["github", "github"]
+ assert [row[0] for row in rows(result)] == ["stripe", "stripe"]
def _lookalike_rows() -> list[tuple[Any, ...]]:
diff --git a/tests/web/services/test_connector_probe.py b/tests/web/services/test_connector_probe.py
index d7cf601f4..24141d58e 100644
--- a/tests/web/services/test_connector_probe.py
+++ b/tests/web/services/test_connector_probe.py
@@ -121,25 +121,40 @@ def _connect_catalog_stripe(db, user) -> MCPServer:
"""Connect the shared catalog stripe row the way POST /apps/{id}/connect
does: the row has no owner, and the user's link is a non-owner link."""
server, _ = _ensure_catalog_app_server(db, "stripe")
- db.add(
- UserMCPServer(
- user_id=user.id,
- mcpserver_id=server.id,
- is_owner=False,
- can_edit=False,
- can_delete=True,
- is_active=True,
- env=encrypt_env_dict({"STRIPE_API_KEY": "user-key"}),
- env_source="own",
- )
+ _link_without_owning(
+ db,
+ user,
+ server,
+ env=encrypt_env_dict({"STRIPE_API_KEY": "user-key"}),
+ env_source="own",
)
- db.commit()
return server
-def _stripe_ok() -> _Adapter:
+def _connect_catalog_chartmogul(db, user) -> MCPServer:
+ """Connect the shared catalog chartmogul row, as the stripe helper does."""
+ server, _ = _ensure_catalog_app_server(db, "chartmogul")
+ _link_without_owning(
+ db,
+ user,
+ server,
+ env=encrypt_env_dict({"CHARTMOGUL_API_KEY": "user-key"}),
+ env_source="own",
+ )
+ return server
+
+
+def _list_customers_ok(tool: str) -> _Adapter:
payload = {"status": "success", "customers": [], "truncated": False}
- return _Adapter("stripe_list_customers", _text_result(json.dumps(payload)))
+ return _Adapter(tool, _text_result(json.dumps(payload)))
+
+
+def _stripe_ok() -> _Adapter:
+ return _list_customers_ok("stripe_list_customers")
+
+
+def _chartmogul_ok() -> _Adapter:
+ return _list_customers_ok("chartmogul_list_customers")
class _ForbiddenSandboxManager: