fix: allow underscores in parent field type fragment (LFXV2-1652)#50
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (2)
WalkthroughA parent field regex pattern is tightened in the query service design DSL to require the prefix to start with a letter; a new Go test file validates the updated pattern against expected valid and invalid inputs. ChangesParent Pattern Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the Query Service’s parent query parameter validation to accept resource type fragments containing underscores (and digits after the first character), and applies the same validation consistently across both the /query/resources and /query/resources/count endpoints. This aligns runtime request decoding, CLI payload validation, and the generated OpenAPI specs with the updated contract.
Changes:
- Relaxed
parentregex validation to^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$to support types likepast_meetingandv1_past_meeting. - Added missing
parentvalidation to thequery-resources-countendpoint for parity withquery-resources. - Added a regression unit test to lock in the expected
parentformat.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| gen/http/query_svc/server/encode_decode.go | Updates/extends server-side request decoding validation for parent on both endpoints. |
| gen/http/query_svc/client/cli.go | Updates/extends CLI payload validation for parent on both endpoints. |
| gen/http/openapi3.yaml | Updates OpenAPI v3 schema patterns for parent (including count endpoint). |
| gen/http/openapi3.json | Regenerates OpenAPI v3 JSON reflecting updated parent pattern. |
| gen/http/openapi.yaml | Updates Swagger/OpenAPI v2 schema patterns for parent (including count endpoint). |
| gen/http/openapi.json | Regenerates Swagger/OpenAPI v2 JSON reflecting updated parent pattern. |
| design/query-svc.go | Updates Goa design parent pattern and applies it to query-resources-count. |
| cmd/service/parent_regex_test.go | Adds a regression test covering valid/invalid parent formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cmd/service/parent_regex_test.go (1)
8-12: ⚡ Quick winAvoid regex duplication in the test; colocate with implementation and reuse a shared constant.
Line 10 hardcodes a second copy of the production regex. That can drift over time and reduces the value of this regression test. Prefer defining one shared constant in
design/query-svc.go, then use it from a colocateddesign/*_test.gotest.♻️ Proposed refactor
--- a/design/query-svc.go +++ b/design/query-svc.go @@ package design @@ +const ParentPattern = `^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$` @@ - dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`) + dsl.Pattern(ParentPattern) @@ - dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`) + dsl.Pattern(ParentPattern)--- a/cmd/service/parent_regex_test.go +++ b/design/parent_regex_test.go @@ -package service_test +package design @@ -const parentPattern = `^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$` +const parentPattern = ParentPatternAs per coding guidelines,
**/*_test.go: Test files should follow the*_test.gonaming pattern and be placed alongside their implementation files.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/service/parent_regex_test.go` around lines 8 - 12, The test duplicates the production regex (parentPattern) which can drift; remove the hardcoded const in cmd/service/parent_regex_test.go and instead reference the single source of truth defined in design/query-svc.go (e.g., the existing parentPattern constant) by colocating the test next to that implementation as design/parent_regex_test.go and using TestParentPattern to assert the same behavior; if the constant is unexported and the test needs package access, place the test in the same package (not package_test) or make the constant exported so the test can reuse the implementation constant rather than duplicating it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/service/parent_regex_test.go`:
- Line 1: Add the project's required license header at the very top of this file
above the package declaration (package service_test) so CI's license-check
passes; insert the exact canonical license block used across the repo (copy from
other files) as the first lines, keeping the existing package service_test line
unchanged.
---
Nitpick comments:
In `@cmd/service/parent_regex_test.go`:
- Around line 8-12: The test duplicates the production regex (parentPattern)
which can drift; remove the hardcoded const in cmd/service/parent_regex_test.go
and instead reference the single source of truth defined in design/query-svc.go
(e.g., the existing parentPattern constant) by colocating the test next to that
implementation as design/parent_regex_test.go and using TestParentPattern to
assert the same behavior; if the constant is unexported and the test needs
package access, place the test in the same package (not package_test) or make
the constant exported so the test can reuse the implementation constant rather
than duplicating it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dbc592dd-8042-48c9-ae19-e5991e1dffc6
⛔ Files ignored due to path filters (6)
gen/http/openapi.jsonis excluded by!**/gen/**gen/http/openapi.yamlis excluded by!**/gen/**gen/http/openapi3.jsonis excluded by!**/gen/**gen/http/openapi3.yamlis excluded by!**/gen/**gen/http/query_svc/client/cli.gois excluded by!**/gen/**gen/http/query_svc/server/encode_decode.gois excluded by!**/gen/**
📒 Files selected for processing (2)
cmd/service/parent_regex_test.godesign/query-svc.go
Relaxes the `parent` query param regex from `^[a-zA-Z]+:...` to `^[a-zA-Z][a-zA-Z0-9_]*:...` so resource types like `past_meeting` and `v1_past_meeting` are accepted. Also applies the same pattern to the `query-resources-count` endpoint for consistency and adds a regression test. Issue: LFXV2-1652 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Jordan Evans <jevans@linuxfoundation.org>
Summary
parentquery param regex from^[a-zA-Z]+:[a-zA-Z0-9_-]+$to^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$so resource types containing underscores (e.g.past_meeting,v1_past_meeting) are acceptedquery-resources-countendpoint, which previously had no validation onparent, for consistencycmd/service/parent_regex_test.gocovering valid and invalid parent formatsFixes: LFXV2-1652
🤖 Generated with Claude Code