From f56de54c109f8ef128c79c4db667644806566c40 Mon Sep 17 00:00:00 2001 From: sudacode Date: Fri, 20 Feb 2026 02:04:50 -0800 Subject: [PATCH] refactor: extract ipc runtime handler wiring --- docs/subagents/INDEX.md | 2 +- .../codex-task85-20260219T233711Z-46hc.md | 4 ++ src/main.ts | 39 ++++++------------- src/main/runtime/ipc-runtime-handlers.test.ts | 38 ++++++++++++++++++ src/main/runtime/ipc-runtime-handlers.ts | 37 ++++++++++++++++++ 5 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 src/main/runtime/ipc-runtime-handlers.test.ts create mode 100644 src/main/runtime/ipc-runtime-handlers.ts diff --git a/docs/subagents/INDEX.md b/docs/subagents/INDEX.md index 9821135..1053adc 100644 --- a/docs/subagents/INDEX.md +++ b/docs/subagents/INDEX.md @@ -6,7 +6,7 @@ Read first. Keep concise. | ------------ | -------------- | ---------------------------------------------------- | --------- | ------------------------------------- | ---------------------- | | `codex-generate-minecard-image-20260220T112900Z-vsxr` | `codex-generate-minecard-image` | `Generate media fallbacks (GIF) from assets/minecard.webm and wire README/docs fallback markup` | `done` | `docs/subagents/agents/codex-generate-minecard-image-20260220T112900Z-vsxr.md` | `2026-02-20T11:35:30Z` | | `codex-main` | `planner-exec` | `Fix frequency/N+1 regression in plugin --start flow` | `in_progress` | `docs/subagents/agents/codex-main.md` | `2026-02-19T19:36:46Z` | -| `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T10:02:30Z` | +| `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T10:04:27Z` | | `codex-config-validation-20260219T172015Z-iiyf` | `codex-config-validation` | `Find root cause of config validation error for ~/.config/SubMiner/config.jsonc` | `completed` | `docs/subagents/agents/codex-config-validation-20260219T172015Z-iiyf.md` | `2026-02-19T17:26:17Z` | | `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T02:56:34Z` | | `codex-anilist-deeplink-20260219T233926Z` | `anilist-deeplink` | `Fix external subminer:// AniList callback handling from browser` | `done` | `docs/subagents/agents/codex-anilist-deeplink-20260219T233926Z.md` | `2026-02-19T23:59:21Z` | diff --git a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md index d8743ea..d315a2f 100644 --- a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md +++ b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md @@ -9,6 +9,10 @@ ## Current Work (newest first) +- [2026-02-20T10:04:27Z] progress: extracted IPC bridge composition from `src/main.ts` into `src/main/runtime/ipc-runtime-handlers.ts`; `main.ts` now builds `handleMpvCommandFromIpc` and `runSubsyncManualFromIpc` via one `createIpcRuntimeHandlers(...)` factory. +- [2026-02-20T10:04:27Z] progress: added `src/main/runtime/ipc-runtime-handlers.test.ts` for composed IPC handler wiring behavior. +- [2026-02-20T10:04:27Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + focused suites pass for `ipc-runtime-handlers*`, `ipc-bridge-actions*`, `cli-command-context*`, `yomitan-extension-runtime*`, and `overlay-visibility-runtime*` (11/11). +- [2026-02-20T10:04:27Z] scope: staging only `src/main.ts`, new IPC runtime module/tests, and subagent bookkeeping. - [2026-02-20T10:02:30Z] progress: extracted overlay visibility action composition from `src/main.ts` into new runtime module `src/main/runtime/overlay-visibility-runtime.ts`; `main.ts` now consumes a single `createOverlayVisibilityRuntime(...)` factory for set/toggle overlay handlers. - [2026-02-20T10:02:30Z] progress: added `src/main/runtime/overlay-visibility-runtime.test.ts` to lock behavior of composed set/toggle/setOverlay/toggleOverlay wiring. - [2026-02-20T10:02:30Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + focused suites pass for `overlay-visibility-runtime*`, `overlay-visibility-actions*`, `overlay-runtime-bootstrap*`, `overlay-window-layout*`, and `cli-command-context*` (16/16). diff --git a/src/main.ts b/src/main.ts index cc157c3..63a6784 100644 --- a/src/main.ts +++ b/src/main.ts @@ -380,14 +380,7 @@ import { createBuildSendToActiveOverlayWindowMainDepsHandler, createBuildSetOverlayDebugVisualizationEnabledMainDepsHandler, } from './main/runtime/overlay-runtime-main-actions-main-deps'; -import { - createHandleMpvCommandFromIpcHandler, - createRunSubsyncManualFromIpcHandler, -} from './main/runtime/ipc-bridge-actions'; -import { - createBuildHandleMpvCommandFromIpcMainDepsHandler, - createBuildRunSubsyncManualFromIpcMainDepsHandler, -} from './main/runtime/ipc-bridge-actions-main-deps'; +import { createIpcRuntimeHandlers } from './main/runtime/ipc-runtime-handlers'; import { createBuildMpvCommandFromIpcRuntimeMainDepsHandler } from './main/runtime/ipc-mpv-command-main-deps'; import { createCreateInvisibleWindowHandler, @@ -2957,27 +2950,17 @@ const buildMpvCommandFromIpcRuntimeMainDepsHandler = hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null, }); -const buildHandleMpvCommandFromIpcMainDepsHandler = - createBuildHandleMpvCommandFromIpcMainDepsHandler({ - handleMpvCommandFromIpcRuntime, - buildMpvCommandDeps: () => mpvCommandFromIpcRuntimeMainDeps, -}); const mpvCommandFromIpcRuntimeMainDeps = buildMpvCommandFromIpcRuntimeMainDepsHandler(); -const handleMpvCommandFromIpcMainDeps = - buildHandleMpvCommandFromIpcMainDepsHandler(); -const handleMpvCommandFromIpcHandler = createHandleMpvCommandFromIpcHandler( - handleMpvCommandFromIpcMainDeps, -); - -const buildRunSubsyncManualFromIpcMainDepsHandler = - createBuildRunSubsyncManualFromIpcMainDepsHandler({ - runManualFromIpc: (request: SubsyncManualRunRequest) => subsyncRuntime.runManualFromIpc(request), -}); -const runSubsyncManualFromIpcMainDeps = - buildRunSubsyncManualFromIpcMainDepsHandler(); -const runSubsyncManualFromIpcHandler = createRunSubsyncManualFromIpcHandler( - runSubsyncManualFromIpcMainDeps, -); +const { handleMpvCommandFromIpc: handleMpvCommandFromIpcHandler, runSubsyncManualFromIpc: runSubsyncManualFromIpcHandler } = + createIpcRuntimeHandlers>>({ + handleMpvCommandFromIpcDeps: { + handleMpvCommandFromIpcRuntime, + buildMpvCommandDeps: () => mpvCommandFromIpcRuntimeMainDeps, + }, + runSubsyncManualFromIpcDeps: { + runManualFromIpc: (request) => subsyncRuntime.runManualFromIpc(request), + }, + }); const buildCliCommandContextMainDepsHandler = createBuildCliCommandContextMainDepsHandler({ appState, texthookerService, diff --git a/src/main/runtime/ipc-runtime-handlers.test.ts b/src/main/runtime/ipc-runtime-handlers.test.ts new file mode 100644 index 0000000..c1e687a --- /dev/null +++ b/src/main/runtime/ipc-runtime-handlers.test.ts @@ -0,0 +1,38 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createIpcRuntimeHandlers } from './ipc-runtime-handlers'; + +test('ipc runtime handlers wire command and subsync handlers through built deps', async () => { + let receivedCommand: (string | number)[] | null = null; + let receivedCommandDeps: { tag: string } | null = null; + let buildMpvCommandDepsCalls = 0; + let receivedSubsyncRequest: { id: string } | null = null; + + const runtime = createIpcRuntimeHandlers({ + handleMpvCommandFromIpcDeps: { + handleMpvCommandFromIpcRuntime: (command, deps) => { + receivedCommand = command; + receivedCommandDeps = deps as unknown as { tag: string }; + }, + buildMpvCommandDeps: () => { + buildMpvCommandDepsCalls += 1; + return { tag: 'mpv-deps' } as never; + }, + }, + runSubsyncManualFromIpcDeps: { + runManualFromIpc: async (request: { id: string }) => { + receivedSubsyncRequest = request; + return { ok: true, id: request.id }; + }, + }, + }); + + runtime.handleMpvCommandFromIpc(['set_property', 'pause', 'yes']); + assert.deepEqual(receivedCommand, ['set_property', 'pause', 'yes']); + assert.deepEqual(receivedCommandDeps, { tag: 'mpv-deps' }); + assert.equal(buildMpvCommandDepsCalls, 1); + + const response = await runtime.runSubsyncManualFromIpc({ id: 'abc' }); + assert.deepEqual(receivedSubsyncRequest, { id: 'abc' }); + assert.deepEqual(response, { ok: true, id: 'abc' }); +}); diff --git a/src/main/runtime/ipc-runtime-handlers.ts b/src/main/runtime/ipc-runtime-handlers.ts new file mode 100644 index 0000000..74c50a2 --- /dev/null +++ b/src/main/runtime/ipc-runtime-handlers.ts @@ -0,0 +1,37 @@ +import { createHandleMpvCommandFromIpcHandler, createRunSubsyncManualFromIpcHandler } from './ipc-bridge-actions'; +import { + createBuildHandleMpvCommandFromIpcMainDepsHandler, + createBuildRunSubsyncManualFromIpcMainDepsHandler, +} from './ipc-bridge-actions-main-deps'; + +type HandleMpvCommandFromIpcMainDeps = Parameters< + typeof createBuildHandleMpvCommandFromIpcMainDepsHandler +>[0]; +type RunSubsyncManualFromIpcMainDeps = Parameters< + typeof createBuildRunSubsyncManualFromIpcMainDepsHandler +>[0]; + +export function createIpcRuntimeHandlers(deps: { + handleMpvCommandFromIpcDeps: HandleMpvCommandFromIpcMainDeps; + runSubsyncManualFromIpcDeps: RunSubsyncManualFromIpcMainDeps; +}) { + const handleMpvCommandFromIpcMainDeps = createBuildHandleMpvCommandFromIpcMainDepsHandler( + deps.handleMpvCommandFromIpcDeps, + )(); + const handleMpvCommandFromIpc = createHandleMpvCommandFromIpcHandler( + handleMpvCommandFromIpcMainDeps, + ); + + const runSubsyncManualFromIpcMainDeps = + createBuildRunSubsyncManualFromIpcMainDepsHandler( + deps.runSubsyncManualFromIpcDeps, + )(); + const runSubsyncManualFromIpc = createRunSubsyncManualFromIpcHandler( + runSubsyncManualFromIpcMainDeps, + ); + + return { + handleMpvCommandFromIpc, + runSubsyncManualFromIpc, + }; +}