🌱 [scanner] refactor: move demo data generators to mcp subpackage (epic #23685 phase 1) - #23721
Conversation
#23685 phase 1) Move the demo-data generator functions from pkg/api/handlers/demo_data.go into pkg/api/handlers/mcp (their only caller) since mcp already imports the root handlers package and would create an import cycle if the functions stayed aliased from root. The root file keeps only the already-extracted compat aliases (IsDemoMode, ErrNoClusterAccess, DemoResponse, GetDemoLimaInstances, GetDemoCRDs, GetDemoWebhooks) that delegate to internal/httputil and the k8s subpackage. Behavior is unchanged; route registration is untouched since mcp handlers now call the functions unqualified from their own package. auth_compat.go was left in place: it is already a thin backward-compat re-export delegating entirely to the extracted auth subpackage (mirrors the *_aliases.go pattern), and its callers span github/gitops/mcp/route files, not admin. Moving it into admin/ would add an indirection with no code reduction and no clear ownership fit, so it was skipped per the 'do not force it' guidance. 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.
Verified this as a pure code-motion refactor — looks correct to me.
What I checked (repo at PR head d94eb7b):
- No stale callers. Grepped every
GetDemo*/GetWasmCloud*call site acrosspkg/andcmd/; all consumers of the moved generators live inpkg/api/handlers/mcp(cluster.go,gpu.go,resources.go,sse_handler.go,workloads.go), and the caller-side edits are purely mechanical (drop thehandlers.qualifier).go build ./...passes at head, so nothing external dangles. - Delegates left behind are intact. Root
demo_data.gocorrectly keepsIsDemoMode/ErrNoClusterAccess(demo_data.go:12-26) and theGetDemoLimaInstancesdelegate to thek8ssubpackage (demo_data.go:28-32), whichpkg/api/handlers/k8s/lima.go:68still exercises. - Coverage ratchet clears. Moving both code and tests shifts package coverage; measured at head:
pkg/api/handlers95.2% (floor 69.0),pkg/api/handlers/mcp68.1% (floor 65.5) per.github/go-package-coverage-ratchet.txt:116,71. Both floors satisfied. go test ./pkg/api/handlers ./pkg/api/handlers/mcpboth pass.
The body's import-cycle rationale (moving rather than aliasing, since mcp already imports root handlers) matches what the code shows. No findings.
— 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 tracker — remaining root helper files and Phases 2-3 stay open)
What moved
demo_data.gogenerator functions →pkg/api/handlers/mcp/demo_data.go. All ~35GetDemo*/GetWasmCloud*demo-data generator functions were called exclusively frompkg/api/handlers/mcp(verified by grepping every call site acrosspkg/api). Sincemcpalready imports the roothandlerspackage, keeping these functions in root and adding a back-alias from root tomcpwould create an import cycle (handlers→mcp→handlers). Instead, the generator functions moved directly intomcpand the internal call sites there were updated to call them unqualified (dropping thehandlers.prefix) — no alias layer needed since nothing outsidemcpreferenced them.TestGetDemoFunctions,TestGetDemoFunctions_All,TestGetDemoClusterHealth_UnknownCluster) moved topkg/api/handlers/mcp/demo_data_test.goalongside the functions.pkg/api/handlers/demo_data.gonow contains only the already-extracted compat aliases (IsDemoMode,ErrNoClusterAccess,DemoResponse,GetDemoLimaInstances,GetDemoCRDs,GetDemoWebhooks) that delegate tointernal/httputiland thek8ssubpackage, plus their tests.Skipped:
auth_compat.goauth_compat.gowas not moved. It is already a thin backward-compat re-export that delegates entirely to the already-extractedauthsubpackage (mirrors the*_aliases.gopattern used elsewhere). Its callers spangithub,gitops,mcp, and root route-registration files — notadmin. Moving it intopkg/api/handlers/admin/would add an extra indirection layer (admin re-exporting auth symbols) with no code reduction and no clear domain ownership, so per the "don't force it" guidance it was left as-is.Behavior
No behavior change — this is a pure code-motion refactor. Route registration and all existing call sites are unaffected (mcp handlers now call the demo functions unqualified from their own package instead of via the root package).
Verification
All pass (all handlers subpackages, including
mcp, green).— hive: agent=scanner backend=copilot model=claude-fable-5 copilot=1.0.88