fix(tools): scope bridge.groovy config vars with @Field - #1099
fix(tools): scope bridge.groovy config vars with @Field#1099milamberspace wants to merge 1 commit into
Conversation
Top-level `def` config vars (TRACKER_URL, API_TOKEN, AUTH_SCHEME, ENV) are locals of the script's run() method and are invisible to the cmd_* methods and the httpGet/httpPost helpers, so every subcommand threw MissingPropertyException before any HTTP call. Annotate them with @groovy.transform.Field so they become fields visible to every method. Fixes the failing tools/jira/tests/test_bridge_write.py suite. Closes apache#1098 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dpol1
left a comment
There was a problem hiding this comment.
Approving — the bug is real and reproducible from the source on main, the @Field conversion is complete, and the test evidence in the PR body checks out against the tree. One naming nit below, not blocking.
The bug is confirmed on main
httpGet (line 51), httpWrite (70), httpMultipart (96) and the cmd_* methods all reference the script-level config vars, which as bare top-level defs are locals of the generated run() method and invisible from methods compiled onto the script class. The stack line quoted in the PR body — MissingPropertyException at bridge.cmd_search(bridge.groovy:182) — matches exactly the ${TRACKER_URL} interpolation at line 182 on main. The @Field conversion covers all five vars, no other script-level state remains in the file, and the early if (!TRACKER_URL) guard keeps working since fields stay visible from run().
Smaller observations
tools/jira/bridge.groovy(new comment above the@Fieldblock) — the comment says "thehttpGet/httpPosthelpers", but nohttpPostexists in this file; the write-path helpers arehttpWriteandhttpMultipart. Worth naming the real methods so the comment doesn't point at a phantom identifier.
This review was drafted by an AI-assisted tool and checked and
submitted by an Apache Magpie contributor — not a maintainer, so
a maintainer's review remains the authoritative next step. If
something feels off, please reply on the PR.More on how Apache Magpie handles maintainer review:
CONTRIBUTING.md § Opening a pull request.
Summary
bridge.groovysubcommand threwgroovy.lang.MissingPropertyException: No such property: TRACKER_URL for class: bridgebefore making any HTTP call.ENV,TRACKER_URL,API_TOKEN,AUTH_SCHEME) were declared with a bare top-leveldef. In a Groovy script that makes them locals of the generatedrun()method, so thecmd_*methods and thehttpGet/httpPosthelpers — compiled onto the script class — cannot see them. Theif (!TRACKER_URL)guard passed because it runs insiderun(), masking the bug until a method was entered.@groovy.transform.Field(viaimport groovy.transform.Field) so they become fields visible to every method. Added a short comment explaining the@Fieldrequirement.Type of change
Test plan
prek run --all-filespasses — includingpytest (workspace), which runstools/jira/tests/test_bridge_write.py(the suite that was failing before this change).groovy tools/jira/bridge.groovy search 'project = FOO'now reaches the HTTP layer instead of throwingMissingPropertyException; the missing-ISSUE_TRACKER_URLguard still exits 2.Before:
After: 28 passed in
tools/jira/tests/test_bridge_write.py.RFC-AI-0004 compliance
Linked issues
Closes #1098
Notes for reviewers (optional)
PROJECT_KEYis promoted to@Fieldtoo for consistency, though it is currently dead code (defined, never read) — no runtime impact either way.tools/dashboard-generator/reference.groovy, is not affected: it defines no methods (linear script + closures, which capture the script scope) and reads no environment variables.