Skip to content

feat: Implement github_read_file in read_tools.py + test#1

Merged
mabry1985 merged 1 commit into
mainfrom
feat/github-plugin-1ez.2
Jun 21, 2026
Merged

feat: Implement github_read_file in read_tools.py + test#1
mabry1985 merged 1 commit into
mainfrom
feat/github-plugin-1ez.2

Conversation

@mabry1985

Copy link
Copy Markdown
Contributor

I'll start by reading the key files to understand the codebase patterns before making changes.I'll start by reading the key files to understand the codebase patterns before making changes.Now let me read gh_cli.py and the test conftest to understand the helpers and test patterns.I have everything I need. Now I'll implement the github_read_file body, replacing only the stub return after the bad_repo check.Now the test file. Let me write tests/test_read_tools.py following the repo's host-free conventions.Let me verify the lint and tests pass locally, if the environment allows it.The langchain import failure is just the local Python 3.9 env lacking deps (CI installs them). But the ruff import-sort issue is real — let me see what ruff wants.Ruff groups ghplugin as third-party. Let me remove that blank line.Ruff passes. Now let me try to actually run the tests in a venv with the deps, to confirm correctness before this goes to CI.All 12 tests pass (6 new + 4 register + 2 version). Let me clean up the temp venv.Done. Here's what I changed:

read_tools.py — implemented github_read_file

Replaced the stub body (after the bad_repo(repo) check, which stays) with a real gh api call:

args = ["api", f"repos/{repo}/contents/{path}", "-H", "Accept: application/vnd.github.raw+json"]
if ref.strip():
    args += ["-f", f"ref={ref}"]
rc, out, serr = await run_gh(args)
if gh_err := check_gh_error(rc, serr):
    return gh_err
if len(out) > 20000:
    out = out[:20000] + "\n… (truncated at 20000 chars)"
return out

Nothing else in the file was touched — the docstring, the other seven tools, and the return list are unchanged.

tests/test_read_tools.py — new test file

Host-free, mirroring test_register.py/test_version.py conventions: imports get_read_tools from ghplugin.read_tools, patches ghplugin.read_tools.run_gh with AsyncMock, and invokes the langchain @tool via .ainvoke(...). Six cases:

  • Success → returns "file content"
  • With ref → captured args contain -f and ref=main
  • Invalid repo "bad" → starts with "Error: 'repo' must be" (and asserts run_gh is never called)
  • gh error (1, "", "not found") → starts with "Error (gh exit 1)"
  • Truncation (25k chars) → ends with "… (truncated at 20000 chars)", exact length asserted
  • Empty content""

Verification

  • ruff check . && ruff format --check .All checks passed
  • pytest -q (in a Python 3.12 venv with requirements-dev.txt) → 12 passed — the 6 new tests plus the existing test_register.py and test_version.py all green.

One note: the task spec estimated the truncated length as "~20032 chars"; the actual value is 20029 (20000 + len("\n… (truncated at 20000 chars)"), with being a single Unicode char). My test asserts that exact, self-consistent length rather than the rounded estimate, so it can't drift from the implementation.

@protoquinn

protoquinn Bot commented Jun 21, 2026

Copy link
Copy Markdown

👀 Quinn is reviewing — verdict (PASS / WARN / FAIL) + findings to follow.

@protoquinn protoquinn Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

QA Audit — PR #1 | feat: Implement github_read_file in read_tools.py + test

VERDICT: WARN (CI pending — re-review on terminal)


CI Status

  • test: ⏳ queued

Diff Review

  • read_tools.py: Stub replaced with real gh api call (7 lines). Uses existing run_gh, check_gh_error, bad_repo — consistent with the rest of the file. Accept: application/vnd.github.raw+json header correctly fetches raw content. 20k-char truncation guard is reasonable.
  • tests/test_read_tools.py: 6 clean async tests (68 lines). Host-free, properly mocked with AsyncMock at the correct patch path. Covers success, ref forwarding, bad-repo short-circuit, gh error surfacing, truncation boundary, and empty content.

Observations

  • No blocking issues found. Implementation is straightforward and follows established conventions.
  • LOW: Truncation message uses Unicode — will render fine in any modern terminal/consumer, but worth noting if any downstream ASCII-only pipeline exists.

— Quinn, QA Engineer

@protoquinn

protoquinn Bot commented Jun 21, 2026

Copy link
Copy Markdown

Submitted COMMENT review on protoLabsAI/github-plugin#1.

@protoquinn protoquinn Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI terminal-green, no blockers on prior review — auto-approving on green (#748).

@mabry1985 mabry1985 merged commit 212ecc5 into main Jun 21, 2026
1 check passed
@mabry1985 mabry1985 deleted the feat/github-plugin-1ez.2 branch June 21, 2026 19:51
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.

1 participant