fix: validate gitea_edit_pr no-fields before authentication (#43) #44

Closed
jcwalker3 wants to merge 0 commits from fix/issue-43-edit-pr-validate-before-auth into master
Owner

Closes #43.

Problem

gitea_edit_pr called _auth() (and resolved the remote) before checking whether any editable field was provided. A pure validation error (no fields) then surfaced as RuntimeError: No credentials … in environments without Gitea auth — making tests/test_mcp_server.py::TestEditPR::test_edit_pr_no_fields_raises depend on credentials/network/env.

Fix

Move the payload build + no-fields ValueError ahead of _resolve/_auth/URL setup. When fields are provided the path is unchanged (_resolve_auth → audited PATCH). No change to auth, retry/backoff, audit, config profiles, or worktree helpers; no secrets/env touched.

# validate first — pure validation must not need creds/network/env
payload = {...}                 # title/body/state/base
if not payload:
    raise ValueError("At least one field to edit ... must be provided.")
h, o, r = _resolve(...); auth = _auth(h); url = ...

Tests

  • Added test_edit_pr_no_fields_validates_before_auth: no-fields call raises ValueError and calls neither get_auth_header nor api_request (auth mocked to None).
  • Existing test_edit_pr_success / test_edit_pr_no_fields_raises unchanged.

Checks

  • Compile clean (mcp_server.py, tests/test_mcp_server.py).
  • Targeted TestEditPR: 3 passed.
  • Full suite run in the isolated worktree (no .env creds): 287 passed, 0 failures, 0 errors — proving the no-fields test no longer depends on the environment. (JUnit XML; harness swallows pytest stdout on multi-file runs.)
  • git diff --check: clean.

Files changed

mcp_server.py, tests/test_mcp_server.py.

Process

Done in an isolated worktree per the new standard: ./scripts/worktree-start fix/issue-43-edit-pr-validate-before-authbranches/fix-issue-43-edit-pr-validate-before-auth.


⚠️ Authored by me — do not self-merge. Needs review by another author.

Closes #43. ## Problem `gitea_edit_pr` called `_auth()` (and resolved the remote) **before** checking whether any editable field was provided. A pure validation error (no fields) then surfaced as `RuntimeError: No credentials …` in environments without Gitea auth — making `tests/test_mcp_server.py::TestEditPR::test_edit_pr_no_fields_raises` depend on credentials/network/env. ## Fix Move the payload build + no-fields `ValueError` **ahead** of `_resolve`/`_auth`/URL setup. When fields are provided the path is unchanged (`_resolve` → `_auth` → audited `PATCH`). No change to auth, retry/backoff, audit, config profiles, or worktree helpers; no secrets/env touched. ```python # validate first — pure validation must not need creds/network/env payload = {...} # title/body/state/base if not payload: raise ValueError("At least one field to edit ... must be provided.") h, o, r = _resolve(...); auth = _auth(h); url = ... ``` ## Tests - Added `test_edit_pr_no_fields_validates_before_auth`: no-fields call raises `ValueError` and calls **neither** `get_auth_header` **nor** `api_request` (auth mocked to `None`). - Existing `test_edit_pr_success` / `test_edit_pr_no_fields_raises` unchanged. ## Checks - Compile clean (`mcp_server.py`, `tests/test_mcp_server.py`). - Targeted `TestEditPR`: 3 passed. - **Full suite run in the isolated worktree (no `.env` creds): 287 passed, 0 failures, 0 errors** — proving the no-fields test no longer depends on the environment. (JUnit XML; harness swallows pytest stdout on multi-file runs.) - `git diff --check`: clean. ## Files changed `mcp_server.py`, `tests/test_mcp_server.py`. ## Process Done in an isolated worktree per the new standard: `./scripts/worktree-start fix/issue-43-edit-pr-validate-before-auth` → `branches/fix-issue-43-edit-pr-validate-before-auth`. --- ⚠️ Authored by me — do **not** self-merge. Needs review by another author.
jcwalker3 added 1 commit 2026-07-02 02:09:02 -05:00
gitea_edit_pr called _auth() (and resolved the remote) before checking whether
any editable field was provided, so a pure validation error (no fields) surfaced
as a RuntimeError "no credentials" in environments without Gitea auth — making
test_edit_pr_no_fields_raises depend on credentials/network/env.

Move the payload build + no-fields ValueError ahead of _resolve/_auth/URL setup.
Behavior is unchanged when fields are provided (same _resolve → _auth → audited
PATCH path). No change to auth, retry/backoff, audit, config profiles, or
worktree helpers.

Tests: add test_edit_pr_no_fields_validates_before_auth asserting the no-fields
path raises ValueError and calls neither get_auth_header nor api_request (even
with auth mocked to None). Existing edit-PR tests unchanged.

Full suite passes with no Gitea credentials (287 passed, 0 failures) — the
no-fields test no longer depends on the environment.

Closes #43.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jcwalker3 closed this pull request 2026-07-02 02:12:15 -05:00
jcwalker3 deleted branch fix/issue-43-edit-pr-validate-before-auth 2026-07-02 02:12:15 -05:00

Pull request closed

Sign in to join this conversation.