Skip to content

refactor(asv3): plugin-core.ts split — validation / topo / migration / mcp (WP-17)#404

Open
Luis85 wants to merge 2 commits into
developfrom
claude/asv3-wp17-plugin-core-split
Open

refactor(asv3): plugin-core.ts split — validation / topo / migration / mcp (WP-17)#404
Luis85 wants to merge 2 commits into
developfrom
claude/asv3-wp17-plugin-core-split

Conversation

@Luis85
Copy link
Copy Markdown
Owner

@Luis85 Luis85 commented May 17, 2026

Summary

Behaviour-preserving refactor of the 476-LOC src/core/plugin-core.ts (audit flagged its max-lines warning at 362 LOC) into four focused modules. PluginCore shrinks to a thin orchestrator (~211 effective LOC after eslint skipBlankLines/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; the eslint-disable complexity directive preserved on the function.
  • src/core/settings-migration.ts (77 LOC) — migrateSettings. Single LoggerPort dependency; the eslint-disable complexity directive 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 all 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 + diamond, migration fallback paths (including corrupted _moduleVersions as string/array/null), and the MCP serialised-sync ordering invariants (start-wins-over-stop, last-enqueued-wins).

The max-lines warning on plugin-core.ts is gone. No new max-lines warnings on any extracted file.

Explicit carry-outs (untouched per brief): src/plugin/main.ts (WP-16 candidate), the unused eslint-disable at src/plugin/main.ts:278 (WP-6 carry-out).

Test plan

  • npm audit --audit-level=high --omit=dev — 0 vulnerabilities
  • npm run typecheck — clean
  • npm run lint — 0 errors, 23 pre-existing warnings (none on src/core/*)
  • npm run test — 1918 passed (153 files); up from 1863 by exactly +55 new mirror cases
  • npm run build — succeeds
  • npm run build:web — succeeds
  • npm run docs:api — succeeds (one pre-existing TypeDoc resolve warning)
  • max-lines warning on src/core/plugin-core.ts gone, no new ones introduced
  • McpServerLifecycle tests prove the seam holds without instantiating PluginCore
  • module-validation / module-topo-sort tests run without any port mocks

https://claude.ai/code/session_01UWDtzLuFJU3QmQmLrXCxWj


Generated by Claude Code

claude added 2 commits May 17, 2026 13:34
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
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.

2 participants