Skip to content

Add Goa-backed query-svc commands - #23

Merged
emsearcy merged 13 commits into
mainfrom
ems/21-goa-cli-spike
Oct 30, 2026
Merged

emsearcy merged 13 commits into
mainfrom
ems/21-goa-cli-spike

Conversation

@emsearcy

@emsearcy emsearcy commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds lfx query-svc, the first set of commands generated from an LFX v2 service's Goa module, and settles the approach investigated in #21.

Findings from #21

  • Goa's generated CLI package (gen/http/cli/...) can't be wrapped. Its ParseEndpoint reads the global os.Args, exits the process on a bad flag, and writes usage straight to stderr.
  • The layer beneath it can be. Goa's CLI calls the same SDK client lfx-mcp uses, through exported Build<Method>Payload functions. These take one string per parameter and apply Goa's validation and type parsing. lfx calls them directly from urfave flags.
  • Switching to Cobra wouldn't help. The obstacle is Goa's flag handling, which neither framework can host, and both could call the builders. We stay on urfave/cli.
  • Authentication and host come from lfx auth: the stored token, and the environment's API base URL plus the service path.

Changes

  • internal/commands/goa.go: shared plumbing for Goa-backed commands. Each endpoint is an ordered table of builder parameters, each mapped to a flag. The command calls the builder, prints the service's raw JSON, supports --query/-q like lfx api, and gives readable messages for Goa's typed errors.
  • internal/commands/api.go, internal/commands/goa.go: share resolveAuthenticatedBaseURL (access token, environment, and base URL resolution) between lfx api and Goa-backed commands, and the no-redirect HTTP client and --query output helper.
  • internal/commands/query.go: query-svc tables (query-resources, query-resources-count, query-membership-summary, query-orgs, suggest-orgs) and help examples.
  • internal/commands/goa_test.go: TestGoaBuilderSignatures reads the generated source and checks each table against the builder's parameter names in order. Reordered same-type string parameters would still compile, so this catches that and fails on added, removed or renamed parameters. It also rejects service flags that collide with reserved output flags; suggest-orgs uses --search because --query is reserved.
  • internal/commands/goa_payload_test.go: TestGoaFlagsToBuilderArgs checks the shared flag-to-builder conversion once per argument kind with a stand-in builder; new services do not need their own payload tests.
  • .agents/skills/upgrade-maintenance/SKILL.md: new skill for reconciling these tables when service modules change, adapted from lfx-mcp's.
  • AGENTS.md, README.md: document the pattern and the new commands.
  • go.mod/go.sum: routine go get -u ./... && go mod tidy dependency refresh (goa.design/goa/v3 to v3.34.0, the newest release compatible with the repo's go1.26 toolchain policy target; go-chi/chi/v5 to v5.5.0; go.mod's go directive to the latest 1.26 patch, 1.26.10). No lfx-v2-* service module changed, so no Goa-backed command reconciliation was needed.

Testing

  • make check and make test pass, including TestGoaFlagsToBuilderArgs (defaults, omitted and repeated comma-containing lists, token insertion, builder errors).
  • Swapping two same-type entries in a table compiled, and TestGoaBuilderSignatures failed as intended.
  • Manually tested against the live API: slug lookup with -q, and committee search by parent and name.
  • Addressed review feedback in follow-up commits: removed the unused goaService.Path field, added a default case for an unsupported goaArgKind, capped rawBodyDoer's response read, added TestFormatGoaError/TestRawBodyDoer, extracted resolveAuthenticatedBaseURL to fix a jscpd duplicate-code finding, reformatted SKILL.md's tables to clear markdownlint findings, and extracted a shared readLimitedBody helper so an oversized response body is rejected with a clear error instead of silently truncated, applying the same 64 MiB cap to lfx api's --query branch for consistency.

Follow-up

Write commands (fetch, merge, then PUT with If-Match and strict decoding, as in linuxfoundation/lfx-mcp#196) are tracked in #22. Query service is read-only and doesn't need them.

Resolves: #21

🤖 Generated with GitHub Copilot (via OpenCode)

Add `lfx query-svc` with commands for each query service endpoint,
built on lfx-v2-query-service's generated Go module. Each command maps
urfave flags onto the generated Build<Method>Payload function, so Goa's
validation runs before the request, and prints the raw JSON response,
with the same --query/-q gjson filter as `lfx api`.

Each endpoint is an ordered table of builder parameters.
TestGoaBuilderSignatures parses the generated source and checks the
tables in order, because a reordering of same-typed string parameters
would still compile. It also keeps service flags off names reserved for
output flags; suggest-orgs' search text is --search for this reason.

Also add an upgrade-maintenance skill for reconciling these tables when
service modules change, help examples for common queries, and share the
no-redirect HTTP client with `lfx api`.

Resolves: #21

Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 22:54
@emsearcy
emsearcy requested a review from a team as a code owner October 28, 2026 22:54
Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>

Copilot AI 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.

🟡 Changes recommended

Flag-to-payload conversion lacks parser-based test coverage, and the domain flag help advertises URLs that validation rejects.

2 open issues
What changed in this PR

Adds lfx query-svc as the first Goa-backed service command group, establishing a reusable integration pattern while retaining urfave/cli and existing authentication.

Changes:

  • Exposes five read-only query endpoints with validated flags, raw JSON output, and --query filtering.
  • Adds shared Goa plumbing and tests that check builder parameter order and flag collisions.
  • Documents usage and dependency-maintenance procedures; write commands remain deferred to #22.
File Description
README.md Documents service commands with query examples.
internal/​commands/​query.go Defines five query-service endpoints and their flags.
internal/​commands/​goa.go Adds shared command construction, payload conversion, and response handling.
internal/​commands/​goa_test.go Checks builder signatures and reserved flag names.
internal/​commands/​api.go Extracts shared HTTP-client and output-filter helpers.
go.sum Records checksums for new dependencies.
go.mod Adds query-service, Goa, and supporting dependencies.
cmd/​lfx/​main.go Registers the query-service command group.
AGENTS.md Documents the Goa integration and maintenance pattern.
.agents/​skills/​upgrade-maintenance/​SKILL.md Defines dependency-upgrade and argument-table reconciliation procedures.

Review effort: Balanced

Comment thread internal/commands/goa.go Resolved
Comment thread internal/commands/query.go Resolved
Copilot AI balanced review requested due to automatic review settings October 28, 2026 22:58

Copilot AI 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.

🔵 Needs a closer look

Flag-to-payload conversion lacks parsed-command tests for defaults, repeatable values, token injection, and validation failures, while domain help recommends URLs that the pinned builder rejects.

2 open issues

Review effort: Balanced

Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 23:06

Copilot AI 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.

🔵 Needs a closer look

Missing behavioral tests for real-command flag-to-builder conversion leave repeated and comma-containing lists, omitted lists, defaults, and token injection unverified.

2 open issues

Review effort: Balanced

Address review comments from copilot-pull-request-reviewer on PR #23:

- internal/commands/query.go: describe --domain as a bare domain name,
  matching the builder's domain-only validation.
- internal/commands/goa_payload_test.go: add one table-driven test of the
  shared flag-to-builder conversion, using a stand-in builder with one
  argument per kind: defaults, omitted lists, repeated comma-containing
  list values, bearer-token insertion and builder error passthrough.
- AGENTS.md: note that this test covers argument kinds, not services, so
  new services and endpoints do not need their own payload tests.

Resolves 2 review threads.

Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 23:12

Copilot AI 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.

🟢 Approval recommended

No active review issues are identified for the query-service commands and shared service plumbing.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 23:15
Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Assisted-by: github-copilot:claude-opus-5.5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the new query-service commands and shared service plumbing.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 23:18

Copilot AI 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.

🟢 Approval recommended

No active review issues are blocking the query-service command integration.

No open issues 🎉

Review effort: Balanced

Bump goa.design/goa/v3 to v3.34.0 (newest release compatible with the
go1.26 toolchain policy target) and go-chi/chi/v5 to v5.5.0. Also bump
go.mod's go directive to the latest 1.26 patch, 1.26.10.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 16:43

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the query-service command integration.

No open issues 🎉

Review effort: Balanced

bramwelt
bramwelt previously approved these changes Oct 29, 2026
andrest50
andrest50 previously approved these changes Oct 29, 2026

@andrest50 andrest50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR adds lfx query-svc, the first Goa-backed command group. Each endpoint is a table of builder parameters mapped to flags, and the command calls the generated Build<Method>Payload through reflection so Goa's validation applies. It prints the service's raw JSON and keeps lfx api's --query behavior. It does what the description says, and the shared plumbing is small and easy to extend.

What's done well

  • TestGoaBuilderSignatures parses the generated source to catch reordered same-typed string parameters, which compile but silently misroute flags.
  • DisableSliceFlagSeparator is set on the endpoint command. I checked urfave/cli v3.14.0: it is applied per command to that command's own flags (command.go:573), so it still works when nested under lfx.
  • The no-redirect HTTP client is now shared with lfx api, so the bearer token can't leak across a downgrade redirect.
  • The next-page token is in the response body at v0.4.33 (page_token in types.go), so printing only the body doesn't hide pagination.

Outside the diff

  • README lost security-relevant notes. The restructure deleted two passages and didn't re-add them: "Automatic browser opening accepts only absolute HTTPS URLs… control characters in login instructions are escaped", and "the base URL is not configurable per call". The second is only partly covered by the new "Later commands send requests to the API for the environment you logged in to". Please restore both under "Authentication" and "Raw API calls". (Minor)
  • go directive bump, 1.26.9 to 1.26.10. AGENTS.md says go get -u upgrades modules only, not the toolchain. Was the bump forced by a new dependency, or did it come from go get -u? If it's forced, a line in the description would help. (Question)

Reconciliation with existing reviews

  • ✅ Copilot: parser-based tests for flag-to-payload conversion. Resolved by TestGoaFlagsToBuilderArgs (332c5f2).
  • ✅ Copilot: --domain help advertised URLs. Resolved; the help now says "no scheme or path".
  • ⚠️ github-license-compliance on go.mod (BSD-3-Clause AND the Go patent grant) is still open. This is the usual license of Go's x/ modules, so it's probably a false positive. It needs a policy allow-list entry or a maintainer sign-off, or the check may block merge.

Issue count

  • 🔴 Blocking: 0
  • 🟡 Major: 0
  • 🔵 Minor: 3 (the dead Path field, untested formatGoaError/rawBodyDoer, and the README gap above)
  • ⚪ Nit: 2
  • ❔ Question: 1

Decision

Approving: there are no blocking or major findings. I'd like the Path and README items addressed before merge, and the license check resolved.

Comment thread internal/commands/goa.go Resolved
Comment thread internal/commands/goa.go Resolved
Comment thread internal/commands/goa.go Resolved
Comment thread internal/commands/goa.go Resolved
Address review comments from the reviewers on PR #23:

- internal/commands/goa.go, internal/commands/query.go: removed the
  unused goaService.Path field; its serviceURL was built but only
  Scheme/Host reached NewClient, since the generated client already
  emits each endpoint's full path. run() now validates baseURL
  directly.
- internal/commands/goa.go: added a default case to endpointCommand's
  flag-building switch that panics on an unsupported goaArgKind,
  matching goaBuilderValues's existing error for the same case.
- internal/commands/goa.go: capped rawBodyDoer's response body read
  with io.LimitReader (maxGoaResponseBodyBytes, 64 MiB) instead of an
  unbounded io.ReadAll.
- internal/commands/goa_response_test.go: added TestFormatGoaError
  (named error with/without Message, plus an ordinary error) and
  TestRawBodyDoer (keeps a readable copy of the body while leaving
  resp.Body readable).

Resolves 4 review threads.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
@emsearcy
emsearcy dismissed stale reviews from andrest50 and bramwelt via ea47409 October 30, 2026 16:39
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:39

Copilot AI 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.

🟡 Changes recommended

The 64 MiB response limit can silently truncate valid JSON, producing a misleading unexpected EOF instead of an explicit oversized-response error.

1 open issue

Review effort: Balanced

Comment thread internal/commands/goa.go Resolved
Address additional review feedback on PR #23:

- internal/commands/api.go, internal/commands/goa.go: extracted
  resolveAuthenticatedBaseURL, shared by `lfx api` and every
  Goa-backed command, to fix a jscpd duplicate-code finding introduced
  by the earlier Path-field removal (both had resolved the access
  token, environment, and base URL with the same sequence).
- .agents/skills/upgrade-maintenance/SKILL.md: reformatted both
  reference tables with markdown-table-formatter and shortened one
  cell over MD013's line-length limit, clearing markdownlint findings.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:08
@emsearcy

Copy link
Copy Markdown
Contributor Author

@andrest50 replying to your review (#23 (review)):

go directive bump, 1.26.9 → 1.26.10. Not forced by a new dependency. go get -u ./... on its own actually tried to pull goa.design/goa/v3 to v3.35.0, which requires go1.27 — outside this repo's go1.26 toolchain policy target, so I pinned goa.design/goa/v3 back to v3.34.0 (the newest release still compatible with go1.26). While I had the go directive open for that, I bumped it to the latest available 1.26.x patch (1.26.10) rather than leaving it at 1.26.9, as routine maintenance — not something either dependency required. I've added a line about this to the PR description's Changes section.

README lost security-relevant notes. After discussion, I'm not restoring either passage, for different reasons for each:

  • The browser auto-open validation note ("accepts only absolute HTTPS URLs... control characters are escaped") describes an internal control over a value the IdP (Auth0) returns, not something the user supplies or chooses — the user never sees or picks that URL before the CLI validates it. It's not something a user acts on, so it doesn't belong in user-facing docs; it's already documented where it matters, as code comments on validateBrowserURL/openBrowser in internal/commands/auth.go, with TestAuthLogin covering the refusal path. I've also written it up more fully in a draft ARCHITECTURE.md (docs: add ARCHITECTURE.md and CODEOWNERS guard #24) aimed at contributors, alongside the other internal security controls in this area.
  • The "base URL is not configurable per call" note is user-relevant, but restoring it as a standalone negative statement ("X is not configurable") is worse documentation than what's already there: the restructured README already states the positive fact a user needs — that commands send requests to the environment logged into via lfx auth login --env ... — and a permanent "this is not configurable" sentence reads like a changelog entry about an absent feature rather than a description of how the tool works. I don't think re-adding it improves the docs.

Thanks for the thorough review — addressed the Path, formatGoaError/rawBodyDoer test coverage, and nit items inline.

@emsearcy

Copy link
Copy Markdown
Contributor Author

Review Feedback Addressed

Commits: ea47409, 77ac3e1

Changes Made

  • internal/commands/goa.go, internal/commands/query.go (discussion, per @andrest50): removed the unused goaService.Path field, which was built into a URL but never actually reached the request — the generated client already emits each endpoint's full path. run now validates the resolved baseURL directly.
  • internal/commands/goa.go (discussion, per @andrest50): added TestFormatGoaError and TestRawBodyDoer covering previously-untested error formatting and response-body capture.
  • internal/commands/goa.go (discussion, per @andrest50): capped rawBodyDoer's response read with io.LimitReader (64 MiB) instead of an unbounded io.ReadAll.
  • internal/commands/goa.go (discussion, per @andrest50): added a default case to endpointCommand's flag-building switch that panics on an unsupported goaArgKind, matching goaBuilderValues's existing behavior.
  • internal/commands/api.go, internal/commands/goa.go: extracted resolveAuthenticatedBaseURL, shared by lfx api and every Goa-backed command, fixing a jscpd duplicate-code CI finding that the Path-field fix above introduced (both had ended up resolving the token/environment/base-URL in an identical sequence).
  • .agents/skills/upgrade-maintenance/SKILL.md: reformatted both reference tables with markdown-table-formatter and trimmed one cell over MD013's line-length limit, clearing a markdownlint failure.

Questions Answered

  • go directive bump, 1.26.9 → 1.26.10 (discussion, asked by @andrest50): not forced by a dependency; go get -u tried to pull goa.design/goa/v3 to a go1.27-requiring version, which I pinned back down, and bumped the go directive to the latest 1.26.x patch as routine maintenance while already touching it. Detail posted inline and added to the PR description.

No Change Needed

  • README's two removed passages (discussion, flagged by @andrest50): declined to restore either, for different reasons — full rationale posted inline. Short version: the browser-URL validation note describes an internal control over an IdP-supplied value, not user-actionable guidance, and now lives in code comments plus a draft ARCHITECTURE.md (docs: add ARCHITECTURE.md and CODEOWNERS guard #24); the "base URL not configurable" note would just restate as a negative what the README already says positively (requests go to the environment you logged into).

Feedback Items Addressed

6 of 7 actionable feedback items addressed in this iteration (4 code-change threads, 1 question, 1 no-change-needed explanation).

Threads Resolved

4 of 5 initially unresolved threads resolved in this iteration.

Still Open

  • go.mod license-compliance finding (github-license-compliance bot): flags the standard BSD-3-Clause + Go patent grant license on Go's own x/ modules. This needs a license-policy allow-list entry or maintainer sign-off, not a code change — left open for that decision.

Copilot AI 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.

🔵 Needs a closer look

Responses larger than 64 MiB are silently truncated, causing misleading JSON decoding errors instead of an explicit size-limit diagnostic.

1 open issue

Review effort: Balanced

internal/commands/api.go, internal/commands/goa.go: extracted a shared
readLimitedBody helper that reads one byte past the limit and returns
a distinct error when a body is larger than that, instead of silently
truncating it. io.LimitReader alone returns a clean EOF at the limit,
so an oversized-but-otherwise-valid response could reach the Goa
decoder as truncated JSON and fail with a misleading "unexpected EOF"
rather than identifying the client-side size limit as the cause.

`lfx api`'s --query branch now also enforces a 64 MiB cap via the same
helper, closing a gap where it had no response-size limit at all.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:19

Copilot AI 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.

🟢 Approval recommended

No active review issues require changes before approval.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

internal/commands/api.go: revive flags a parameter named max as a
redefinition of Go's built-in max function; renamed to limit.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:27

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the response-size limit lacks regression coverage for boundary conditions and reader errors affecting API and service commands.

No open issues 🎉

Review effort: Balanced

@emsearcy
emsearcy merged commit e323bdf into main Oct 30, 2026
9 checks passed
@emsearcy
emsearcy deleted the ems/21-goa-cli-spike branch October 30, 2026 20:48
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.

Investigate integrating Goa-generated CLI stubs into lfx (urfave/cli v3)

4 participants