Skip to content

fix(guardian): drop the gh dependency and bump node24 action pins - #773

Merged
zaebee merged 3 commits into
mainfrom
agent/drop-gh-dependency-60e328050426
Nov 1, 2026
Merged

zaebee merged 3 commits into
mainfrom
agent/drop-gh-dependency-60e328050426

Conversation

@it-start

@it-start it-start commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

This is by an automated agent, not a human.

Why

The reusable guardian workflow assumed the GitHub CLI: the trigger reaction and the base-branch lookup shelled out to gh, and github_poster.py posted the inline review with gh api. A self-hosted runner without gh failed on the second step. The action pins were also node20-era majors (#742, items 1–2).

What changed

  • No gh in the review path. The reaction and the base-branch lookup are actions/github-script REST calls; the poster POSTs to /repos/{repo}/pulls/{pr}/reviews with urllib and GH_TOKEN (GITHUB_TOKEN fallback for local runs). An API rejection raises RuntimeError carrying GitHub's response body instead of CalledProcessError, so the runner's existing fallback still fires and logs the reason.
  • Current majors, all node24 (# vN comments name them): actions/checkout v7, astral-sh/setup-uv v10.3.3, actions/github-script v9, peter-evans/create-or-update-comment v5, actions/upload-artifact v7, actions/create-github-app-token v3.3.0. This repo's caller (guardian.yml) gets checkout v7, download-artifact v8, github-script v9 and setup-uv v10.3.3.
  • Runner requirement documented: the reusable workflow now states that the node24 pins need an Actions runner v2.327.1 or later, which GitHub-hosted runners are and a self-hosted runner may not be.
  • Tests pin it: no run: block in either guardian workflow calls gh; no guardian module or scripts/guardian_review.py spawns gh (AST scan over subprocess/os/asyncio spawn calls); every remote uses: is SHA-pinned to the current majors. The poster tests mock urlopen and check the URL, method, bearer auth, payload, token fallback, missing-token failure and the response body on rejection.
  • README: local --inline now needs GH_TOKEN (or GITHUB_TOKEN); Actions exports it.

Verification

  • make format, make lint, make type-check, make doc-coverage pass.
  • Focused: pytest tests/unit/test_guardian_poster.py tests/unit/test_guardian_workflow.py tests/unit/test_guardian_runner.py tests/unit/test_guardian_review_script.py — 177 passed, 2 skipped.
  • Full pytest: 4477 passed, 2 skipped, 15 xfailed (complete local checkout; a shallow one cannot resolve the historical SHA fixtures).

Limitations

  • The github-script calls and the node24 action bumps are not exercised by a live workflow run here; the next /guardian review on this repository is the end-to-end check.
  • External callers that pin this workflow at a SHA (uses: zaebee/codegraph-brain/...@<sha>) must move their pin to this PR's merge commit in their own PRs; that is outside this repository.

Addresses #742.

The reusable workflow shelled out to `gh` for the trigger reaction and the
base-branch lookup, and github_poster.py posted the inline review with
`gh api`; a self-hosted runner without the CLI failed on the second step.
Both workflow steps now call the REST API through actions/github-script, and
the poster POSTs over HTTPS with urllib and GH_TOKEN (GITHUB_TOKEN locally).
An API rejection raises RuntimeError carrying GitHub's response body.

Bump the guardian workflows to current, node24 action majors: checkout v7,
setup-uv v10.3.3, github-script v9, create-or-update-comment v5,
upload-artifact v7, create-github-app-token v3.3.0, download-artifact v8.
The workflow notes the v2.327.1+ self-hosted runner requirement.

Tests pin the absence of gh in both workflow steps and in guardian code,
and hold every remote action pin to the current majors. README says that
local --inline needs GH_TOKEN.

Co-authored-by: zaebee <305761+zaebee@users.noreply.github.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the dependency on the GitHub CLI (gh) with plain HTTPS requests using Python's built-in urllib library for posting inline review comments, improving compatibility with self-hosted runners. It also introduces comprehensive tests, including AST-based checks, to ensure gh is not spawned. The review comments are highly valuable: one suggests stripping whitespace from retrieved tokens to prevent authentication failures, and the other improves the AST check in tests to robustly detect direct imports of subprocess functions.

Comment thread src/cgis/guardian/github_poster.py Resolved
Comment thread tests/unit/test_guardian_workflow.py Resolved
Review follow-up on #773: the AST scan now sees direct imports and aliases (from subprocess import run as spawn, import subprocess as sp), with cases pinning each spelling; a token pasted with surrounding whitespace is stripped before it reaches the Authorization header.

Co-authored-by: zaebee <305761+zaebee@users.noreply.github.com>
it-start added a commit that referenced this pull request Nov 1, 2026
Review follow-up on #773: the AST scan now sees direct imports and aliases (from subprocess import run as spawn, import subprocess as sp), with cases pinning each spelling; a token pasted with surrounding whitespace is stripped before it reaches the Authorization header.
@it-start
it-start force-pushed the agent/drop-gh-dependency-60e328050426 branch from 48e8e4d to 926e23c Compare November 1, 2026 13:48
@zaebee

zaebee commented Nov 1, 2026

Copy link
Copy Markdown
Owner

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the dependency on the GitHub CLI (gh) by refactoring the inline review poster to use direct HTTPS requests via Python's built-in urllib library. Key changes include implementing a robust token extraction helper, updating the asynchronous runner, and adapting unit tests to mock HTTP requests instead of subprocesses. Additionally, new AST-based tests are introduced to guarantee that no library code or workflow steps shell out to gh, and GitHub Actions are pinned to specific SHAs. There are no review comments to evaluate, and I have no feedback to provide.

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

@zaebee
zaebee merged commit 969f566 into main Nov 1, 2026
4 checks passed
@zaebee
zaebee deleted the agent/drop-gh-dependency-60e328050426 branch November 1, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants