🌱 [scanner] refactor: extract validation handlers to pkg/api/handlers/internal/httputil (epic #23685 phase 1) - #23722
Conversation
…/internal/httputil (epic #23685 phase 1) Moves the remaining cross-cutting input validators out of the flat pkg/api/handlers root package into the internal/httputil domain package, per the Phase-1 internal/httputil row of the epic plan. - validate_helpers.go + its test move via git mv; validators are exported (ValidateDNSLabel/ValidateDNSSubdomain/ValidateClusterName/ ValidateRoleName/ValidateEnum) so domain subpackages can reuse them. - Cron and Kubernetes API-version validators move to internal/httputil/validation.go (IsValidCronSchedule, IsValidK8sVersion, K8sVersionPattern), with their tests. - Root validation.go keeps the exported aliases MaxK8sNameLen, IsValidK8sName and IsValidK8sVersion used by pkg/api/handlers/mcp, and drops the now-dead unexported duplicates of httputil.ValidateK8sName / ValidateClusterAndNamespace. Behavior-preserving: no route or exported HTTP behavior changes. Coverage: pkg/api/handlers 93.8%, internal/httputil 100.0%. Refs #23685 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: GitHub Copilot <223556219+Copilot@users.noreply.github.com>
✅ Deploy Preview for kubestellarconsole canceled.
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
👋 Hey @hivecommons-hive[bot] — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
Read this against main, not just the diff — looks correct to me.
Verified specifics:
- The unexported identifiers this PR deletes from the root package (
validateK8sName,validateClusterAndNamespace,isValidCronSchedule,cronFieldPattern,k8sNamePattern, and thevalidateDNSLabelfamily) have no callers anywhere onmainoutside the moved files themselves — code search finds them only inpkg/api/handlers/validation.go/validate_helpers.goand their tests. So dropping the duplicates and exporting thehttputilversions cannot break any handler. - Function bodies in
internal/httputil/validate_helpers.goandvalidation.goare byte-identical to what left the root package (rename-only, as the body claims);IsValidK8sVersioninhttputilcorrectly reuses the already-movedMaxK8sNameLen. - The root aliases kept in
pkg/api/handlers/validation.go(MaxK8sNameLen,IsValidK8sName,IsValidK8sVersion) cover the symbolspkg/api/handlers/mcpstill uses. - All checks green on head
e098e63, includinggo test ./...and the coverage gates, consistent with the body's 93.8%/100% numbers.
Behavior-preserving as advertised; a maintainer can merge this on a quick skim.
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
✅ Post-Merge Verification: passedCommit: |
Refs #23685 (epic/multi-phase tracker — this lands one phase-1 domain slice; remaining domains follow in later PRs)
Summary
Phase-1 slice for the
internal/httputilrow of the epic plan: the last cross-cutting input validators leave the flatpkg/api/handlersroot package. Mechanical and behavior-preserving, modeled on #23684 and #23688.validate_helpers.gogit mv→internal/httputil/validate_helpers.go. Validators exported so domain subpackages can reuse them:ValidateDNSLabel,ValidateDNSSubdomain,ValidateClusterName,ValidateRoleName,ValidateEnum. Bodies unchanged.validation.go(cron + version validators)internal/httputil/validation.goasIsValidCronSchedule,IsValidK8sVersion,K8sVersionPattern. Bodies unchanged.validation.go(root)MaxK8sNameLen,IsValidK8sName,IsValidK8sVersion— the symbolspkg/api/handlers/mcpcalls. The now-dead unexported duplicates (validateK8sName,validateClusterAndNamespace,isValidCronSchedule,k8sNamePattern) are dropped;httputil.ValidateK8sName/ValidateClusterAndNamespace(landed in #23684) are the single implementation.Tests moved with the code
validate_helpers_test.go→internal/httputil/validate_helpers_test.goviagit mv(package + validator names updated only).validation_test.go→internal/httputil/validation_test.go.validation_test.gokeeps the tests for the aliases that remain (IsValidK8sName,MaxK8sNameLen, plus a short delegation check forIsValidK8sVersion).too long) forValidateClusterName/ValidateRoleNamesointernal/httputilstays at 100%.Verification
go build ./...— passes.go test ./pkg/api/... -count=1— all packages pass.pkg/api/handlers93.8% (well above the 66.5% ratchet floor),pkg/api/handlers/internal/httputil100.0%,pkg/api/handlers/mcpunchanged at 68.1%.No route registration, exported HTTP behavior, frontend, or Netlify changes.
— hive: agent=scanner backend=copilot model=claude-fable-5 copilot=1.0.88