Skip to content

refactor(platform): split 981-line plugins.go into per-domain modules - #11

Merged
HongmingWang-Rabbit merged 1 commit into
mainfrom
refactor/split-plugins-handler
Apr 14, 2026
Merged

refactor(platform): split 981-line plugins.go into per-domain modules#11
HongmingWang-Rabbit merged 1 commit into
mainfrom
refactor/split-plugins-handler

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

Pure mechanical split of platform/internal/handlers/plugins.go — no behavior changes, no test changes. Groups the PluginsHandler surface area by responsibility.

Before / after

File Before After Contents
plugins.go 981 194 PluginsHandler struct, constructor, With* options, RuntimeLookup, pluginInfo + supportsRuntime, manifest parsing (parseManifestYAML, readPluginManifest, strDefault), container helpers (findRunningContainer, execInContainer/execAsRoot/execInContainerAs)
plugins_sources.go 14 ListSources (GET /plugins/sources)
plugins_listing.go 174 Read-only endpoints: ListRegistry, listRegistryFiltered, ListAvailableForWorkspace, ListInstalled, CheckRuntimeCompatibility
plugins_install.go 276 Route entrypoints for mutating ops: Install, Uninstall, Download
plugins_install_pipeline.go 368 Install pipeline: install-layer consts + env-var caps, httpErr + newHTTPErr, logInstallLimitsOnce, dirSize, validatePluginName, installRequest/stageResult, resolveAndStage, deliverToContainer, copyPluginToContainer, streamDirAsTar, readPluginSkillsFromContainer, stripPluginMarkersFromMemory, regexpEscapeForAwk

Function count preserved: 32 total (was 32 in original plugins.go).

Every file is under the 400-line soft cap; plugins.go hits the ≤200 target.

Judgment calls

  • validatePluginName is used by every domain file; parked it in plugins_install_pipeline.go (alongside the other sanitization helpers) rather than plugins.go, purely to keep plugins.go under the 200-line target. Same-package, so callers don't care.
  • Install/Uninstall/Download stay as full handler bodies in plugins_install.go (not thin wrappers in plugins.go) so the split is mechanical — moving a func (h *PluginsHandler) Foo() method between files in the same package is a no-op to callers.
  • plugins_sources.go is tiny (14 lines, one handler) but kept as its own file per the grouping requested in the task.

Test plan

  • cd platform && go build ./... — clean
  • go vet ./... — clean
  • go test -race ./internal/handlers/... — passes (cached ok)
  • plugins_test.go untouched (1365 lines, 59 test funcs)
  • No other handler files modified — diffstat is 5 files, all plugins*.go

🤖 Generated with Claude Code

Pure mechanical split — no behavior changes. Groups the PluginsHandler
surface area by responsibility so each file stays focused and readable.

Before: plugins.go — 981 lines, 32 funcs
After:
  plugins.go                   — 194  (struct, constructor, shared helpers)
  plugins_sources.go           —  14  (ListSources)
  plugins_listing.go           — 174  (ListRegistry, ListInstalled,
                                       ListAvailableForWorkspace,
                                       CheckRuntimeCompatibility)
  plugins_install.go           — 276  (Install, Uninstall, Download handlers)
  plugins_install_pipeline.go  — 368  (resolveAndStage, deliverToContainer,
                                       copy/stream tar, CLAUDE.md marker
                                       stripping, dirSize, httpErr,
                                       installRequest/stageResult,
                                       install-layer consts + envx caps)

plugins_test.go (1365 lines) untouched — tests pass unchanged.
go build, go vet, and go test -race ./internal/handlers/... all clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@HongmingWang-Rabbit HongmingWang-Rabbit left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

7-Gate Verification — PASSED

  1. CI — 6/6 green (pre-verified).
  2. Checkout + buildgo build ./... and go vet ./... clean on refactor/split-plugins-handler.
  3. Comprehensive testsgo test -race -count=1 ./... all packages pass (handlers 4.03s fresh, no cache). tests/e2e/test_api.sh = 62/62 pass against live platform.
  4. Security audit — diff grep for fmt.Sprintf w/ SQL verbs, new os.Getenv(, bearer/CanCommunicate bypass, sk-ant-/ghp_/AKIA, X-Workspace-ID tampering: all clean. Pure code motion, no new env vars, no new auth paths.
  5. Design fit — Go backend refactor; no dialogs/CSS/PM-bypass/doc-link rules apply. Runtime-agnostic plugin filtering logic preserved verbatim in plugins_listing.go.
  6. Line-level review — function count preserved: original plugins.go had 32 funcs; new split is plugins.go(11) + plugins_install.go(3) + plugins_install_pipeline.go(12) + plugins_listing.go(5) + plugins_sources.go(1) = 32. plugins_test.go untouched (0-line diff). Stat: 787 deletions / 832 insertions (delta = package-level doc comments on new files). No behavior change.
  7. Manual UI test — N/A, backend-only refactor.

Pure file-split, no behavior change, no auth/billing/data-deletion surface. Safe to merge via merge-commit.

@HongmingWang-Rabbit
HongmingWang-Rabbit merged commit 1e1eec1 into main Apr 14, 2026
6 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the refactor/split-plugins-handler branch April 14, 2026 02:20
molecule-ai Bot pushed a commit that referenced this pull request Apr 21, 2026
refactor(platform): split 981-line plugins.go into per-domain modules
molecule-ai Bot pushed a commit that referenced this pull request Apr 22, 2026
…ession flagged

- PR #1582 (staging-to-main-p0-fix): mergeable=True, 1155 commits, correct
  exec-form ✅ — add as item #12, recommend as primary path to main
- PR #1583: REQUEST_CHANGES review posted — Cmd regression to string concat,
  same as F1502. Add as item #11.
- Update item #3 (superseded by #1582) and #4 (merged)
- Update branch HEAD to 034601c
- Add PRs row to Affected Systems

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant