refactor(control-plane): split handlers/nodes.go into 5 focused files#481
Open
kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
Open
refactor(control-plane): split handlers/nodes.go into 5 focused files#481kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
Conversation
Splits the 1753 LOC handlers/nodes.go (22 funcs mixing registration,
heartbeat, listing, status lifecycle, and URL-discovery helpers) into
5 focused files within the same handlers package:
nodes_register.go (950 LOC) - RegisterNodeHandler,
RegisterServerlessAgentHandler, readCloser,
validate, and all URL/candidate helpers
nodes_heartbeat.go (298 LOC) - HeartbeatHandler + HeartbeatCache +
shouldUpdateDatabase + processHeartbeatAsync
nodes_status.go (460 LOC) - UpdateLifecycleStatusHandler,
GetNodeStatusHandler, RefreshNodeStatusHandler,
BulkNodeStatusHandler, RefreshAllNodeStatusHandler,
StartNodeHandler, StopNodeHandler
nodes_list.go (57 LOC) - ListNodesHandler
nodes_detail.go (36 LOC) - GetNodeHandler
Pure file moves within the handlers package: no renames, no behavior
change. The old nodes.go is deleted (issue says "tiny shared helpers
only, if any" — no such helpers remain after the split, so keeping an
empty file would be noise).
All existing tests (nodes_test.go, nodes_rest_test.go,
nodes_discovery_test.go, nodes_serverless_revocation_test.go, and the
coverage_* tests that reference heartbeatCache/processHeartbeatAsync/
readCloser by name) resolve unchanged via same-package visibility.
Closes Agent-Field#416
Co-Authored-By: Claude <noreply@anthropic.com>
15a7897 to
dacefe5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #416
Summary
Splits
control-plane/internal/handlers/nodes.go(1753 LOC, 22 funcs, 3 types, 2 package vars — mixing registration, heartbeat, list/detail, status lifecycle, and URL-discovery helpers) into 5 focused files within the samehandlerspackage. Pure file moves: no renames, no behavior change.File layout
nodes_register.goRegisterNodeHandler,RegisterServerlessAgentHandler,readCloser+validate, and all URL/candidate helpers (validateCallbackURL,extractPortFromURL,gatherCallbackCandidates,normalizeCandidate,resolveCallbackCandidates,normalizeServerlessDiscoveryURL,isServerlessDiscoveryHostAllowed)nodes_heartbeat.goHeartbeatHandler,HeartbeatCache,CachedNodeData,heartbeatCache/dbUpdateThresholdvars,shouldUpdateDatabase,processHeartbeatAsyncnodes_status.goUpdateLifecycleStatusHandler,GetNodeStatusHandler,RefreshNodeStatusHandler,BulkNodeStatusHandler,RefreshAllNodeStatusHandler,StartNodeHandler,StopNodeHandlernodes_list.goListNodesHandlernodes_detail.goGetNodeHandlerBefore: 1 file × 1753 LOC → After: 5 files summing to 1801 LOC (+48 from 4 extra
package/import blocks + gofmt of a pre-existing stray indentation in the register section).The old
nodes.gois deleted. The issue allowsnodes.goto remain for "tiny shared helpers only" — after the split there are no shared helpers left that would otherwise be homeless, so an emptynodes.gowould be noise. Git detects the rename ofnodes.go→nodes_register.go(54% similarity), which keeps the diff reviewable.Why this split
The issue proposed:
nodes_register.go/nodes_heartbeat.go/nodes_list.go/nodes_detail.go/ (nodes_tags.goif tag approval lives here) /nodes.go(shared helpers).Tag approval handlers are in
handlers/admin/tag_approval.go, not this file, so nonodes_tags.go. The 7 status/lifecycle handlers (UpdateLifecycleStatusHandler,GetNodeStatusHandler,RefreshNodeStatusHandler,BulkNodeStatusHandler,RefreshAllNodeStatusHandler,StartNodeHandler,StopNodeHandler) form a natural group and don't fit into detail/list, so they live together innodes_status.go. Open to re-splitting if the reviewer prefers a different boundary.Guardrails respected
diff <(grep '^(func|type|var|const) ' original | sort) <(cat new_files | grep '^(func|type|var|const) ' | sort)is emptynodes_discovery_test.go,nodes_rest_test.go,nodes_test.go,nodes_serverless_revocation_test.go, and thecoverage_*_test.gofiles that pokeheartbeatCache/processHeartbeatAsync/readCloser/CachedNodeDataby name all resolve unchanged via same-package visibilityTest plan
cd control-plane && go build ./...→ greencd control-plane && go test ./internal/handlers/... -count=1→okacross all 5 handler sub-packages (handlers,handlers/admin,handlers/agentic,handlers/connector,handlers/ui)cd control-plane && go vet ./...→ cleangofmt -l control-plane/internal/handlers/nodes*.go→ cleancd control-plane && go test ./... -count=1→ handlers green; only pre-existing failures ininternal/application,internal/core/services,internal/server(TestGenerateAgentFieldServerID,TestDevServicePortHelpers*,TestGenerateAgentFieldServerIDFallsBackWhenGetwdFails,TestStartAdminGRPCServerReturnsListenError). These all reproduce on a fresh clone ofmain— unrelated to this PRAI assistance
Authored with AI assistance (Claude Code). Please apply the
ai-assistedtag.