Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
perf(git): show how many checks passed and failed with the first GitHub answer (#645)
Ruben Lütke73b161f1dc18
diff --git a/jarvis/agentic_ide/git_overview.py b/jarvis/agentic_ide/git_overview.pyindex a76580d0d3..7c716e1264 100644--- a/jarvis/agentic_ide/git_overview.py+++ b/jarvis/agentic_ide/git_overview.py@@ -75,10 +75,12 @@ SLOW_READ_S = 2.0# part alone is well inside it.## The checks behind each pull request's verdict are the slow part by far, so-# the pull requests are asked twice: once with the verdict alone, which is on-# screen in about two seconds, and once with the checks, which follow.+# the pull requests are asked twice: once with the verdict and GitHub's own+# tally of the checks, which is on screen in about two seconds, and once with+# the checks themselves (their names and runs), which follow.-#: Every open pull request with the CI verdict of its newest commit, no checks.+#: Every open pull request with the CI verdict of its newest commit and how+#: many checks passed, failed and run — no single check._OPEN_QUICK_QUERY = """query($owner: String!, $name: String!) {repository(owner: $owner, name: $name) {@@ -86,7 +88,7 @@ query($owner: String!, $name: String!) {pullRequests(first: 50, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {nodes {...PullRequestRow- commits(last: 1) { nodes { commit { oid statusCheckRollup { state } } } }+ commits(last: 1) { nodes { commit { oid statusCheckRollup { ...Tally } } } }}}}@@ -163,6 +165,17 @@ fragment Rollup on StatusCheckRollup {}"""+_TALLY_FRAGMENT = """+fragment Tally on StatusCheckRollup {+ state+ contexts(first: 1) {+ totalCount+ checkRunCountsByState { state count }+ statusContextCountsByState { state count }+ }+}+"""+# Every branch name on GitHub, without CI: the main query carries CI for the# newest branches only, so older ones would otherwise never show up._REFS_QUERY = """@@ -400,6 +413,8 @@ def ci_from_rollup(rollup: dict[str, Any] | None, commit: str = "") -> CiStatus:else:ci.pending += 1pending_url = pending_url or url+ if not ci.total:+ _tally(ci, contexts)rollup_state = str(rollup.get("state") or "").upper()if ci.failed or rollup_state in {"FAILURE", "ERROR"}:ci.state = "failure"@@ -418,6 +433,33 @@ def ci_from_rollup(rollup: dict[str, Any] | None, commit: str = "") -> CiStatus:return ci+def _tally(ci: CiStatus, contexts: dict[str, Any]) -> None:+ """Counts from GitHub's own tally, for an answer that carries no single check."""+ for entry in contexts.get("checkRunCountsByState") or []:+ if not isinstance(entry, dict):+ continue+ state, count = str(entry.get("state") or "").upper(), int(entry.get("count") or 0)+ if state in _PASSED:+ ci.passed += count+ elif state == "IN_PROGRESS":+ ci.running += count+ elif state in _QUEUED:+ ci.pending += count+ else:+ ci.failed += count+ for entry in contexts.get("statusContextCountsByState") or []:+ if not isinstance(entry, dict):+ continue+ state, count = str(entry.get("state") or "").upper(), int(entry.get("count") or 0)+ if state == "SUCCESS":+ ci.passed += count+ elif state in {"FAILURE", "ERROR"}:+ ci.failed += count+ else:+ ci.pending += count+ ci.total = ci.passed + ci.failed + ci.running + ci.pending++def _pr_state(node: dict[str, Any]) -> str:state = str(node.get("state") or "").upper()if state == "MERGED":@@ -533,8 +575,9 @@ def _fetch_github("""GitHub's answer for ``repo``.``early`` is handed a first answer as soon as the quick parts are in: every- pull request with its CI verdict and every branch, without the checks- behind a verdict and without CI for a branch that has no pull request.+ pull request with its CI verdict and check counts and every branch, without+ the names and runs of the checks and without CI for a branch that has no+ pull request."""now = time.time()owner, _, name = repo.partition("/")@@ -546,7 +589,7 @@ def _fetch_github(except github_link.GitHubError as exc: # handed back to the caller belowreturn exc- quick_job = git_local.Job(ask, _OPEN_QUICK_QUERY + _PR_FRAGMENT)+ quick_job = git_local.Job(ask, _OPEN_QUICK_QUERY + _PR_FRAGMENT + _TALLY_FRAGMENT)open_job = git_local.Job(ask, _OPEN_QUERY + _PR_FRAGMENT + _ROLLUP_FRAGMENT)recent_job = git_local.Job(ask, _RECENT_QUERY + _PR_FRAGMENT)refs_job = git_local.Job(ask, _REFS_CI_QUERY + _ROLLUP_FRAGMENT)@@ -608,19 +651,26 @@ def _snapshot(def _keep_details(first: _GitHubSnapshot, last: _GitHubSnapshot) -> None:"""Fill the quick answer from the last full one wherever nothing moved.- The quick answer has each pull request's verdict but not the checks behind- it, and no CI at all for a branch without a pull request. For a commit the- last full answer already covered, what it said is still the best there is.+ The quick answer has each pull request's verdict and check counts but not+ which checks failed or run, and no CI at all for a branch without a pull+ request. For a commit the last full answer already covered, what it said+ is still the best there is."""- # A verdict alone cannot tell "running" from "waiting to start".+ # A verdict without counts cannot tell "running" from "waiting to start".coarse = {"running": "pending"}known = {pr.number: pr.ci for pr in last.prs}for pr in first.prs:old = known.get(pr.number)- if old is None or not old.total or old.commit != pr.ci.commit:+ if old is None or old.commit != pr.ci.commit:+ continue+ if coarse.get(old.state, old.state) != coarse.get(pr.ci.state, pr.ci.state):+ continue+ if not pr.ci.total:+ pr.ci = old # a bare verdict: the last answer says more in every waycontinue- if coarse.get(old.state, old.state) == coarse.get(pr.ci.state, pr.ci.state):- pr.ci = old+ # The counts are newer; which checks they are comes from the last answer.+ pr.ci.names = old.names+ pr.ci.url = old.url or pr.ci.urlfor name, (oid, ci) in list(first.refs.items()):old_ref = last.refs.get(name)if old_ref is not None and old_ref[0] == oid and ci.state == "none":diff --git a/tests/unit/agentic_ide/test_git_control_center.py b/tests/unit/agentic_ide/test_git_control_center.pyindex c8f6e70574..a325b71691 100644--- a/tests/unit/agentic_ide/test_git_control_center.py+++ b/tests/unit/agentic_ide/test_git_control_center.py@@ -680,7 +680,7 @@ def _github_in_two_steps(monkeypatch: pytest.MonkeyPatch, checks, oid: str = "a"def fake_graphql(token: str, query: str, variables: dict | None = None) -> dict:if "pageInfo" in query:return _repo_payload(refs={"pageInfo": {"hasNextPage": False}, "nodes": []})- if "states: OPEN" in query and "contexts" not in query:+ if "states: OPEN" in query and "...Tally" in query:node = _with_ci(_pr_node(1, "a"), {"state": "SUCCESS"}, oid)return _repo_payload(pullRequests={"nodes": [node]})if "states: OPEN" in query:@@ -766,6 +766,70 @@ def test_a_refresh_keeps_the_checks_of_commits_that_did_not_move(assert turned.prs[0].ci.total == 0+def test_the_quick_answer_counts_checks_from_githubs_tally() -> None:+ rollup = {+ "state": "FAILURE",+ "contexts": {+ "totalCount": 9,+ "checkRunCountsByState": [+ {"state": "SUCCESS", "count": 4},+ {"state": "SKIPPED", "count": 1},+ {"state": "FAILURE", "count": 1},+ {"state": "CANCELLED", "count": 1},+ {"state": "IN_PROGRESS", "count": 1},+ {"state": "QUEUED", "count": 1},+ ],+ "statusContextCountsByState": [],+ },+ }+ ci = git_overview.ci_from_rollup(rollup, "a" * 40)+ assert (ci.state, ci.total, ci.passed, ci.failed, ci.running, ci.pending) == (+ "failure",+ 9,+ 5,+ 2,+ 1,+ 1,+ )+ # Nothing failed and something runs: "running", which a bare verdict cannot say.+ rollup["state"] = "PENDING"+ rollup["contexts"]["checkRunCountsByState"] = [+ {"state": "SUCCESS", "count": 2},+ {"state": "IN_PROGRESS", "count": 1},+ ]+ assert git_overview.ci_from_rollup(rollup).state == "running"+++def test_a_refresh_takes_new_counts_and_keeps_which_checks_failed() -> None:+ def snapshot(ci: CiStatus) -> git_overview._GitHubSnapshot:+ snap = git_overview._GitHubSnapshot(ok=True)+ snap.prs = [+ git_overview.PullRequest(+ number=1, title="", url="", state="open", base="main", head="a", ci=ci+ )+ ]+ return snap++ last = snapshot(+ CiStatus(+ state="failure",+ total=40,+ passed=30,+ failed=1,+ running=9,+ commit="a" * 12,+ names=["CI gate"],+ url="https://github.com/o/r/actions/runs/1",+ )+ )+ fresh = CiStatus(state="failure", total=40, passed=39, failed=1, commit="a" * 12, url="x")+ quick = snapshot(fresh)+ git_overview._keep_details(quick, last)+ ci = quick.prs[0].ci+ assert (ci.passed, ci.running, ci.names) == (39, 0, ["CI gate"])+ assert ci.url == "https://github.com/o/r/actions/runs/1"++def test_a_slow_read_says_where_the_time_went(repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:from loguru import logger