You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/09/18 08:25:09 UTC
(magpie) branch main updated: fix(vetted-ops): read operations must say GET when they pass a field (#1272)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/magpie.git
The following commit(s) were added to refs/heads/main by this push:
new 040090ba fix(vetted-ops): read operations must say GET when they pass a field (#1272)
040090ba is described below
commit 040090ba1139afac9f8b303b46bc0faf3f47ca75
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Fri Sep 18 10:25:03 2026 +0200
fix(vetted-ops): read operations must say GET when they pass a field (#1272)
`repo-file` and `repo-tree` both passed a -F field with no explicit method.
`gh api` switches to POST as soon as any -f/-F field is present, so both
were POSTing to a read route and getting 404 back for every input:
vetted-op-read repo-file <path> 3.3.2 -> Not Found
gh api repos/.../contents/<path>?ref=3.3.2 -> works
The 404 is what makes this survive. It reads as "wrong ref" or "no such
file" rather than "malformed request", so the natural response is to doubt
the argument rather than the operation. It was first noticed on a dotted
ref, which made it look like a tag-name quoting problem; `-F ref=main`
fails identically.
`repo-file` is the content probe the fix-released gate leans on to confirm
a fix is genuinely absent from a release branch, because raw-SHA ancestry
reports `diverged` for a cherry-pick and cannot distinguish "not there"
from "there under a different SHA". That probe has never worked through
the dispatcher.
Both now pass `-X GET` explicitly. The regression test asserts the shape
for every read in the catalogue rather than for these two, so the next
operation that passes a field cannot reintroduce it; verified by reverting
the fix and watching it fail with the operation named.
Generated-by: Claude Opus 5
---
tools/vetted-ops/src/vetted_ops/ops.py | 13 +++++--
tools/vetted-ops/tests/test_vetted_ops.py | 56 +++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/tools/vetted-ops/src/vetted_ops/ops.py b/tools/vetted-ops/src/vetted_ops/ops.py
index 6f563151..31b5417d 100644
--- a/tools/vetted-ops/src/vetted_ops/ops.py
+++ b/tools/vetted-ops/src/vetted_ops/ops.py
@@ -436,7 +436,12 @@ _register(
"gh",
"api",
f"repos/{_upstream(cfg)}/contents/{path}",
- "-F",
+ # `gh api` switches to POST as soon as any -f/-F field is present,
+ # so a read that passes one must say GET explicitly or the request
+ # is sent to a route that does not exist and comes back 404.
+ "-X",
+ "GET",
+ "-f",
f"ref={ref}",
"--jq",
".content",
@@ -1535,7 +1540,11 @@ _register(
"gh",
"api",
f"repos/{_upstream(cfg)}/git/trees/{ref}",
- "-F",
+ # See the note on `repo-file`: fields without an explicit -X make
+ # `gh api` POST.
+ "-X",
+ "GET",
+ "-f",
"recursive=1",
"--jq",
".tree[].path",
diff --git a/tools/vetted-ops/tests/test_vetted_ops.py b/tools/vetted-ops/tests/test_vetted_ops.py
index 8809e0fb..8a0ee1e7 100644
--- a/tools/vetted-ops/tests/test_vetted_ops.py
+++ b/tools/vetted-ops/tests/test_vetted_ops.py
@@ -267,6 +267,62 @@ def test_issue_remove_assignee_is_gated_on_the_roster(policy: config.Config) ->
]
+def test_no_read_operation_sends_fields_without_an_explicit_get(policy: config.Config) -> None:
+ """
+ `gh api` switches to POST the moment any -f/-F field is present. A read that
+ passes one without saying `-X GET` is therefore sent to a route that does not
+ exist, and comes back 404 — which reads like "the ref is wrong" rather than
+ "the request was malformed", so it can sit unnoticed for a long time.
+
+ Both `repo-file` and `repo-tree` shipped that way. This asserts the shape for
+ every read in the catalogue rather than for those two, so the next operation
+ that passes a field cannot reintroduce it.
+ """
+ sample = {
+ "number": "1",
+ "comment_id": "1",
+ "run_id": "42",
+ "ref": "main",
+ "base": "main",
+ "head": "v1",
+ "prefix": "v1",
+ "path": "a/b.py",
+ "login": "alice",
+ "team": "sec",
+ "ghsa": "GHSA-aaaa-bbbb-cccc",
+ "item_id": "PVTI_abc",
+ "label": "needs triage",
+ "milestone": "1.2.3",
+ "state": "open",
+ "reason": "completed",
+ "column": "Assessed",
+ "query": "pr-liveness",
+ "body": "unused",
+ }
+ body = policy.workspace / "shape.md"
+ body.write_text("x")
+
+ for name, op in ops.OPS.items():
+ if op.writes:
+ continue
+ params = {}
+ for p in op.params:
+ if p in op.body_files:
+ params[p] = str(body)
+ elif p in op.enums:
+ params[p] = policy.enum_values(op.enums[p])[0]
+ else:
+ params[p] = sample[p]
+ argv = op.build(policy.as_mapping(), **params)
+ if "graphql" in argv:
+ continue
+ if any(a in ("-f", "-F") for a in argv):
+ assert "-X" in argv, (
+ f"{name} passes a -f/-F field without an explicit method; gh api will POST it"
+ )
+ assert argv[argv.index("-X") + 1] == "GET", f"{name} sends fields with a non-GET method"
+
+
# --- per-caller scoping ------------------------------------------------------