refactor(asv3): plugin-core.ts split — validation / topo / migration / mcp (WP-17)#404
Open
Luis85 wants to merge 2 commits into
Open
refactor(asv3): plugin-core.ts split — validation / topo / migration / mcp (WP-17)#404Luis85 wants to merge 2 commits into
Luis85 wants to merge 2 commits into
Conversation
Split the 476-LOC src/core/plugin-core.ts (audit: max-lines warning at
362 LOC) into four focused modules along the seams already implicit in
the code. PluginCore shrinks to a thin orchestrator (~211 effective LOC
after eslint skipBlankLines/skipComments — under the 220 target) that
delegates to:
- src/core/module-validation.ts (73 LOC) — validateModules,
validateSettingsKeys, validateUriActions. Pure; no port deps.
- src/core/module-topo-sort.ts (54 LOC) — topoSort. Kahn's BFS; the
eslint-disable complexity directive is preserved on the function.
- src/core/settings-migration.ts (77 LOC) — migrateSettings. Single
LoggerPort dependency; the eslint-disable complexity directive is
preserved.
- src/core/mcp-server-lifecycle.ts (100 LOC) — McpServerLifecycle class
with start, stop, isRunning, syncRunning. Owns the _syncChain serial
promise chain and the _running invariant. Constructor takes
{ port?, isEnabled?, logger } — no CorePorts aggregate.
PluginCore public surface unchanged: bus, degradedModules, allModules,
getModuleSettings, handleUri, notifySettingsChanged, isMcpServerRunning,
startMcpServer, stopMcpServer, init, destroy. Verified by 78 + 16
existing PluginCore tests passing without modification.
55 new mirror tests under tests/core/ cover the extracted helpers
directly (no PluginCore instantiation): validation rules, topo cycles
and diamond, migration fallback paths, MCP serialised-sync ordering.
The max-lines warning on plugin-core.ts is gone. No new max-lines
warnings on any extracted file.
Explicit carry-outs (untouched): src/plugin/main.ts (WP-16 candidate),
the unused eslint-disable at src/plugin/main.ts:278 (WP-6 carry-out).
https://claude.ai/code/session_01UWDtzLuFJU3QmQmLrXCxWj
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.
Summary
Behaviour-preserving refactor of the 476-LOC
src/core/plugin-core.ts(audit flagged itsmax-lineswarning at 362 LOC) into four focused modules.PluginCoreshrinks to a thin orchestrator (~211 effective LOC after eslintskipBlankLines/skipComments, under the 220-LOC brief target) that delegates to:src/core/module-validation.ts(73 LOC) —validateModules,validateSettingsKeys,validateUriActions. Pure; no port dependencies.src/core/module-topo-sort.ts(54 LOC) —topoSort. Kahn's BFS; theeslint-disable complexitydirective preserved on the function.src/core/settings-migration.ts(77 LOC) —migrateSettings. SingleLoggerPortdependency; theeslint-disable complexitydirective preserved.src/core/mcp-server-lifecycle.ts(100 LOC) —McpServerLifecycleclass withstart,stop,isRunning,syncRunning. Owns the_syncChainserial promise chain and the_runninginvariant. Constructor takes{ port?, isEnabled?, logger }— noCorePortsaggregate.PluginCorepublic surface unchanged:bus,degradedModules,allModules,getModuleSettings,handleUri,notifySettingsChanged,isMcpServerRunning,startMcpServer,stopMcpServer,init,destroy. Verified by all 78 + 16 existingPluginCoretests passing without modification.55 new mirror tests under
tests/core/cover the extracted helpers directly (noPluginCoreinstantiation): validation rules, topo cycles + diamond, migration fallback paths (including corrupted_moduleVersionsas string/array/null), and the MCP serialised-sync ordering invariants (start-wins-over-stop, last-enqueued-wins).The
max-lineswarning onplugin-core.tsis gone. No newmax-lineswarnings on any extracted file.Explicit carry-outs (untouched per brief):
src/plugin/main.ts(WP-16 candidate), the unusedeslint-disableatsrc/plugin/main.ts:278(WP-6 carry-out).Test plan
npm audit --audit-level=high --omit=dev— 0 vulnerabilitiesnpm run typecheck— cleannpm run lint— 0 errors, 23 pre-existing warnings (none onsrc/core/*)npm run test— 1918 passed (153 files); up from 1863 by exactly +55 new mirror casesnpm run build— succeedsnpm run build:web— succeedsnpm run docs:api— succeeds (one pre-existing TypeDoc resolve warning)max-lineswarning onsrc/core/plugin-core.tsgone, no new ones introducedMcpServerLifecycletests prove the seam holds without instantiatingPluginCoremodule-validation/module-topo-sorttests run without any port mockshttps://claude.ai/code/session_01UWDtzLuFJU3QmQmLrXCxWj
Generated by Claude Code