2026-03-14 13:46:41 +09:00
|
|
|
import { describe, expect, it } from "bun:test"
|
|
|
|
|
import type { OhMyOpenCodeConfig } from "../../config"
|
|
|
|
|
import type { ModelCacheState } from "../../plugin-state"
|
|
|
|
|
import type { PluginContext } from "../types"
|
|
|
|
|
import { createSessionHooks } from "./create-session-hooks"
|
|
|
|
|
|
|
|
|
|
const mockContext = {
|
|
|
|
|
directory: "/tmp",
|
|
|
|
|
client: {
|
|
|
|
|
tui: {
|
|
|
|
|
showToast: async () => ({}),
|
|
|
|
|
},
|
|
|
|
|
session: {
|
|
|
|
|
get: async () => ({ data: null }),
|
|
|
|
|
update: async () => ({}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} as unknown as PluginContext
|
|
|
|
|
|
|
|
|
|
const mockModelCacheState = {} as ModelCacheState
|
|
|
|
|
|
|
|
|
|
describe("createSessionHooks", () => {
|
|
|
|
|
it("keeps model fallback disabled when config is unset", () => {
|
|
|
|
|
// given
|
|
|
|
|
const pluginConfig = {} as OhMyOpenCodeConfig
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
const result = createSessionHooks({
|
|
|
|
|
ctx: mockContext,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
modelCacheState: mockModelCacheState,
|
|
|
|
|
isHookEnabled: (hookName) => hookName === "model-fallback",
|
|
|
|
|
safeHookEnabled: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(result.modelFallback).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("creates model fallback hook when config explicitly enables it", () => {
|
|
|
|
|
// given
|
|
|
|
|
const pluginConfig = { model_fallback: true } as OhMyOpenCodeConfig
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
const result = createSessionHooks({
|
|
|
|
|
ctx: mockContext,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
modelCacheState: mockModelCacheState,
|
|
|
|
|
isHookEnabled: (hookName) => hookName === "model-fallback",
|
|
|
|
|
safeHookEnabled: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(result.modelFallback).not.toBeNull()
|
|
|
|
|
})
|
2026-04-04 14:14:19 +09:00
|
|
|
|
|
|
|
|
it("skips interactive bash session hook when tmux integration is disabled", () => {
|
|
|
|
|
// given
|
|
|
|
|
const pluginConfig = {
|
|
|
|
|
tmux: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
layout: "main-vertical",
|
|
|
|
|
main_pane_size: 60,
|
|
|
|
|
main_pane_min_width: 120,
|
|
|
|
|
agent_pane_min_width: 40,
|
|
|
|
|
isolation: "inline",
|
|
|
|
|
},
|
|
|
|
|
} as OhMyOpenCodeConfig
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
const result = createSessionHooks({
|
|
|
|
|
ctx: mockContext,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
modelCacheState: mockModelCacheState,
|
|
|
|
|
isHookEnabled: (hookName) => hookName === "interactive-bash-session",
|
|
|
|
|
safeHookEnabled: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(result.interactiveBashSession).toBeNull()
|
|
|
|
|
})
|
2026-03-14 13:46:41 +09:00
|
|
|
})
|