Skip to content

fix(tools): scope bridge.groovy config vars with @Field - #1099

Open
milamberspace wants to merge 1 commit into
apache:mainfrom
milamberspace:fix/bridge-groovy-field-scoping
Open

fix(tools): scope bridge.groovy config vars with @Field#1099
milamberspace wants to merge 1 commit into
apache:mainfrom
milamberspace:fix/bridge-groovy-field-scoping

Conversation

@milamberspace

Copy link
Copy Markdown
Contributor

Summary

  • Every bridge.groovy subcommand threw groovy.lang.MissingPropertyException: No such property: TRACKER_URL for class: bridge before making any HTTP call.
  • Root cause: the script-level config vars (ENV, TRACKER_URL, API_TOKEN, AUTH_SCHEME) were declared with a bare top-level def. In a Groovy script that makes them locals of the generated run() method, so the cmd_* methods and the httpGet/httpPost helpers — compiled onto the script class — cannot see them. The if (!TRACKER_URL) guard passed because it runs inside run(), masking the bug until a method was entered.
  • Fix: annotate them with @groovy.transform.Field (via import groovy.transform.Field) so they become fields visible to every method. Added a short comment explaining the @Field requirement.

Type of change

  • Groovy reference impl

Test plan

  • prek run --all-files passes — including pytest (workspace), which runs tools/jira/tests/test_bridge_write.py (the suite that was failing before this change).
  • For Groovy bridges touched: command-line invocation tested end-to-end — groovy tools/jira/bridge.groovy search 'project = FOO' now reaches the HTTP layer instead of throwing MissingPropertyException; the missing-ISSUE_TRACKER_URL guard still exits 2.

Before:

Caught: groovy.lang.MissingPropertyException: No such property: TRACKER_URL for class: bridge
	at bridge.cmd_search(bridge.groovy:182)

After: 28 passed in tools/jira/tests/test_bridge_write.py.

RFC-AI-0004 compliance

  • Write-access discipline — unchanged; the bridge still only executes confirmed mutations, this fix only makes existing config resolution work. No other principles touched.

Linked issues

Closes #1098

Notes for reviewers (optional)

  • PROJECT_KEY is promoted to @Field too for consistency, though it is currently dead code (defined, never read) — no runtime impact either way.
  • The other Groovy tool, 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.

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 dpol1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 @Field block) — the comment says "the httpGet/httpPost helpers", but no httpPost exists in this file; the write-path helpers are httpWrite and httpMultipart. 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.

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.

bug: bridge.groovy throws MissingPropertyException — top-level def config vars invisible to cmd_* methods

2 participants