fix(tests): inject create-managers dependencies
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+49
-57
@@ -1,49 +1,23 @@
|
|||||||
/// <reference types="bun-types" />
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
import { afterAll, beforeEach, describe, expect, it, mock } from "bun:test"
|
import { beforeEach, describe, expect, it, mock } from "bun:test"
|
||||||
|
|
||||||
const markServerRunningInProcess = mock(() => {})
|
import { createManagers } from "./create-managers"
|
||||||
|
|
||||||
mock.module("./features/background-agent", () => ({
|
class MockBackgroundManager {
|
||||||
BackgroundManager: class BackgroundManager {
|
constructor(..._args: unknown[]) {}
|
||||||
constructor(..._args: unknown[]) {}
|
}
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./features/skill-mcp-manager", () => ({
|
class MockSkillMcpManager {
|
||||||
SkillMcpManager: class SkillMcpManager {
|
constructor(..._args: unknown[]) {}
|
||||||
constructor(..._args: unknown[]) {}
|
}
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./features/task-toast-manager", () => ({
|
class MockTmuxSessionManager {
|
||||||
initTaskToastManager: mock(() => {}),
|
constructor(..._args: unknown[]) {}
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./features/tmux-subagent", () => ({
|
async cleanup(): Promise<void> {}
|
||||||
TmuxSessionManager: class TmuxSessionManager {
|
async onSessionCreated(..._args: unknown[]): Promise<void> {}
|
||||||
constructor(..._args: unknown[]) {}
|
}
|
||||||
|
|
||||||
async cleanup(): Promise<void> {}
|
|
||||||
async onSessionCreated(..._args: unknown[]): Promise<void> {}
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./features/background-agent/process-cleanup", () => ({
|
|
||||||
registerManagerForCleanup: mock(() => {}),
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./plugin-handlers", () => ({
|
|
||||||
createConfigHandler: mock(() => ({ kind: "config-handler" })),
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./shared/tmux/tmux-utils/server-health", () => ({
|
|
||||||
isServerRunning: mock(async () => true),
|
|
||||||
markServerRunningInProcess,
|
|
||||||
resetServerCheck: mock(() => {}),
|
|
||||||
}))
|
|
||||||
|
|
||||||
const { createManagers } = await import("./create-managers")
|
|
||||||
|
|
||||||
function createTmuxConfig(enabled: boolean) {
|
function createTmuxConfig(enabled: boolean) {
|
||||||
return {
|
return {
|
||||||
@@ -57,23 +31,47 @@ function createTmuxConfig(enabled: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("createManagers", () => {
|
describe("createManagers", () => {
|
||||||
|
const markServerRunningInProcess = mock(() => {})
|
||||||
|
const initTaskToastManager = mock(() => ({}) as never)
|
||||||
|
const registerManagerForCleanup = mock(() => {})
|
||||||
|
const createConfigHandler = mock(() => (async () => {}) as never)
|
||||||
|
|
||||||
|
function createMockArgs(enabled: boolean): Parameters<typeof createManagers>[0] {
|
||||||
|
return {
|
||||||
|
ctx: {
|
||||||
|
directory: "/tmp",
|
||||||
|
client: {} as never,
|
||||||
|
project: {} as never,
|
||||||
|
worktree: "/tmp",
|
||||||
|
serverUrl: new URL("https://example.com"),
|
||||||
|
$: Bun.$,
|
||||||
|
},
|
||||||
|
pluginConfig: {} as never,
|
||||||
|
tmuxConfig: createTmuxConfig(enabled),
|
||||||
|
modelCacheState: {} as never,
|
||||||
|
backgroundNotificationHookEnabled: false,
|
||||||
|
deps: {
|
||||||
|
BackgroundManagerClass: MockBackgroundManager as never,
|
||||||
|
SkillMcpManagerClass: MockSkillMcpManager as never,
|
||||||
|
TmuxSessionManagerClass: MockTmuxSessionManager as never,
|
||||||
|
initTaskToastManagerFn: initTaskToastManager,
|
||||||
|
registerManagerForCleanupFn: registerManagerForCleanup,
|
||||||
|
createConfigHandlerFn: createConfigHandler,
|
||||||
|
markServerRunningInProcessFn: markServerRunningInProcess,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
markServerRunningInProcess.mockClear()
|
markServerRunningInProcess.mockClear()
|
||||||
})
|
initTaskToastManager.mockClear()
|
||||||
|
registerManagerForCleanup.mockClear()
|
||||||
afterAll(() => {
|
createConfigHandler.mockClear()
|
||||||
mock.restore()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("#given tmux integration is disabled #when managers are created #then it does not mark the tmux server as running", () => {
|
it("#given tmux integration is disabled #when managers are created #then it does not mark the tmux server as running", () => {
|
||||||
// #given
|
// #given
|
||||||
const args = {
|
const args = createMockArgs(false)
|
||||||
ctx: { directory: "/tmp", client: {} },
|
|
||||||
pluginConfig: {},
|
|
||||||
tmuxConfig: createTmuxConfig(false),
|
|
||||||
modelCacheState: {},
|
|
||||||
backgroundNotificationHookEnabled: false,
|
|
||||||
} as Parameters<typeof createManagers>[0]
|
|
||||||
|
|
||||||
// #when
|
// #when
|
||||||
createManagers(args)
|
createManagers(args)
|
||||||
@@ -84,13 +82,7 @@ describe("createManagers", () => {
|
|||||||
|
|
||||||
it("#given tmux integration is enabled #when managers are created #then it marks the tmux server as running", () => {
|
it("#given tmux integration is enabled #when managers are created #then it marks the tmux server as running", () => {
|
||||||
// #given
|
// #given
|
||||||
const args = {
|
const args = createMockArgs(true)
|
||||||
ctx: { directory: "/tmp", client: {} },
|
|
||||||
pluginConfig: {},
|
|
||||||
tmuxConfig: createTmuxConfig(true),
|
|
||||||
modelCacheState: {},
|
|
||||||
backgroundNotificationHookEnabled: false,
|
|
||||||
} as Parameters<typeof createManagers>[0]
|
|
||||||
|
|
||||||
// #when
|
// #when
|
||||||
createManagers(args)
|
createManagers(args)
|
||||||
|
|||||||
+29
-7
@@ -12,6 +12,26 @@ import { createConfigHandler } from "./plugin-handlers"
|
|||||||
import { log } from "./shared"
|
import { log } from "./shared"
|
||||||
import { markServerRunningInProcess } from "./shared/tmux/tmux-utils/server-health"
|
import { markServerRunningInProcess } from "./shared/tmux/tmux-utils/server-health"
|
||||||
|
|
||||||
|
type CreateManagersDeps = {
|
||||||
|
BackgroundManagerClass: typeof BackgroundManager
|
||||||
|
SkillMcpManagerClass: typeof SkillMcpManager
|
||||||
|
TmuxSessionManagerClass: typeof TmuxSessionManager
|
||||||
|
initTaskToastManagerFn: typeof initTaskToastManager
|
||||||
|
registerManagerForCleanupFn: typeof registerManagerForCleanup
|
||||||
|
createConfigHandlerFn: typeof createConfigHandler
|
||||||
|
markServerRunningInProcessFn: typeof markServerRunningInProcess
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultCreateManagersDeps: CreateManagersDeps = {
|
||||||
|
BackgroundManagerClass: BackgroundManager,
|
||||||
|
SkillMcpManagerClass: SkillMcpManager,
|
||||||
|
TmuxSessionManagerClass: TmuxSessionManager,
|
||||||
|
initTaskToastManagerFn: initTaskToastManager,
|
||||||
|
registerManagerForCleanupFn: registerManagerForCleanup,
|
||||||
|
createConfigHandlerFn: createConfigHandler,
|
||||||
|
markServerRunningInProcessFn: markServerRunningInProcess,
|
||||||
|
}
|
||||||
|
|
||||||
export type Managers = {
|
export type Managers = {
|
||||||
tmuxSessionManager: TmuxSessionManager
|
tmuxSessionManager: TmuxSessionManager
|
||||||
backgroundManager: BackgroundManager
|
backgroundManager: BackgroundManager
|
||||||
@@ -25,15 +45,17 @@ export function createManagers(args: {
|
|||||||
tmuxConfig: TmuxConfig
|
tmuxConfig: TmuxConfig
|
||||||
modelCacheState: ModelCacheState
|
modelCacheState: ModelCacheState
|
||||||
backgroundNotificationHookEnabled: boolean
|
backgroundNotificationHookEnabled: boolean
|
||||||
|
deps?: Partial<CreateManagersDeps>
|
||||||
}): Managers {
|
}): Managers {
|
||||||
const { ctx, pluginConfig, tmuxConfig, modelCacheState, backgroundNotificationHookEnabled } = args
|
const { ctx, pluginConfig, tmuxConfig, modelCacheState, backgroundNotificationHookEnabled } = args
|
||||||
|
const deps = { ...defaultCreateManagersDeps, ...args.deps }
|
||||||
|
|
||||||
if (tmuxConfig.enabled) {
|
if (tmuxConfig.enabled) {
|
||||||
markServerRunningInProcess()
|
deps.markServerRunningInProcessFn()
|
||||||
}
|
}
|
||||||
const tmuxSessionManager = new TmuxSessionManager(ctx, tmuxConfig)
|
const tmuxSessionManager = new deps.TmuxSessionManagerClass(ctx, tmuxConfig)
|
||||||
|
|
||||||
registerManagerForCleanup({
|
deps.registerManagerForCleanupFn({
|
||||||
shutdown: async () => {
|
shutdown: async () => {
|
||||||
await tmuxSessionManager.cleanup().catch((error) => {
|
await tmuxSessionManager.cleanup().catch((error) => {
|
||||||
log("[create-managers] tmux cleanup error during process shutdown:", error)
|
log("[create-managers] tmux cleanup error during process shutdown:", error)
|
||||||
@@ -41,7 +63,7 @@ export function createManagers(args: {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const backgroundManager = new BackgroundManager(
|
const backgroundManager = new deps.BackgroundManagerClass(
|
||||||
ctx,
|
ctx,
|
||||||
pluginConfig.background_task,
|
pluginConfig.background_task,
|
||||||
{
|
{
|
||||||
@@ -75,11 +97,11 @@ export function createManagers(args: {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
initTaskToastManager(ctx.client)
|
deps.initTaskToastManagerFn(ctx.client)
|
||||||
|
|
||||||
const skillMcpManager = new SkillMcpManager()
|
const skillMcpManager = new deps.SkillMcpManagerClass()
|
||||||
|
|
||||||
const configHandler = createConfigHandler({
|
const configHandler = deps.createConfigHandlerFn({
|
||||||
ctx: { directory: ctx.directory, client: ctx.client },
|
ctx: { directory: ctx.directory, client: ctx.client },
|
||||||
pluginConfig,
|
pluginConfig,
|
||||||
modelCacheState,
|
modelCacheState,
|
||||||
|
|||||||
Reference in New Issue
Block a user