77af6c643e
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
140 lines
4.1 KiB
TypeScript
140 lines
4.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, spyOn, test, mock } from "bun:test"
|
|
|
|
import type { OhMyOpenCodeConfig } from "../config"
|
|
import * as agentConfigHandler from "./agent-config-handler"
|
|
import * as commandConfigHandler from "./command-config-handler"
|
|
import * as mcpConfigHandler from "./mcp-config-handler"
|
|
import * as pluginComponentsLoader from "./plugin-components-loader"
|
|
import * as providerConfigHandler from "./provider-config-handler"
|
|
import * as shared from "../shared"
|
|
import * as toolConfigHandler from "./tool-config-handler"
|
|
|
|
let logSpy: ReturnType<typeof spyOn>
|
|
let loadPluginComponentsSpy: ReturnType<typeof spyOn>
|
|
let applyAgentConfigSpy: ReturnType<typeof spyOn>
|
|
let applyToolConfigSpy: ReturnType<typeof spyOn>
|
|
let applyMcpConfigSpy: ReturnType<typeof spyOn>
|
|
let applyCommandConfigSpy: ReturnType<typeof spyOn>
|
|
let applyProviderConfigSpy: ReturnType<typeof spyOn>
|
|
let createConfigHandler: (typeof import("./config-handler"))["createConfigHandler"]
|
|
|
|
async function importFreshConfigHandlerModule(): Promise<typeof import("./config-handler")> {
|
|
return import(`./config-handler?test=${Date.now()}-${Math.random()}`)
|
|
}
|
|
|
|
function createPluginConfig(overrides: Partial<OhMyOpenCodeConfig> = {}): OhMyOpenCodeConfig {
|
|
return {
|
|
git_master: {
|
|
commit_footer: true,
|
|
include_co_authored_by: true,
|
|
git_env_prefix: "GIT_MASTER=1",
|
|
},
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
mock.restore()
|
|
|
|
logSpy = spyOn(shared, "log").mockImplementation(() => {})
|
|
loadPluginComponentsSpy = spyOn(
|
|
pluginComponentsLoader,
|
|
"loadPluginComponents",
|
|
).mockResolvedValue({
|
|
commands: {},
|
|
skills: {},
|
|
agents: {},
|
|
mcpServers: {},
|
|
hooksConfigs: [],
|
|
plugins: [],
|
|
errors: [],
|
|
})
|
|
applyAgentConfigSpy = spyOn(agentConfigHandler, "applyAgentConfig").mockResolvedValue(
|
|
{},
|
|
)
|
|
applyToolConfigSpy = spyOn(toolConfigHandler, "applyToolConfig").mockImplementation(
|
|
() => {},
|
|
)
|
|
applyMcpConfigSpy = spyOn(mcpConfigHandler, "applyMcpConfig").mockResolvedValue()
|
|
applyCommandConfigSpy = spyOn(
|
|
commandConfigHandler,
|
|
"applyCommandConfig",
|
|
).mockResolvedValue()
|
|
applyProviderConfigSpy = spyOn(
|
|
providerConfigHandler,
|
|
"applyProviderConfig",
|
|
).mockImplementation(() => {})
|
|
;({ createConfigHandler } = await importFreshConfigHandlerModule())
|
|
})
|
|
|
|
afterEach(() => {
|
|
logSpy.mockRestore()
|
|
loadPluginComponentsSpy.mockRestore()
|
|
applyAgentConfigSpy.mockRestore()
|
|
applyToolConfigSpy.mockRestore()
|
|
applyMcpConfigSpy.mockRestore()
|
|
applyCommandConfigSpy.mockRestore()
|
|
applyProviderConfigSpy.mockRestore()
|
|
mock.restore()
|
|
})
|
|
|
|
describe("createConfigHandler formatter pass-through", () => {
|
|
test("preserves formatter object configured in opencode config", async () => {
|
|
// given
|
|
const pluginConfig = createPluginConfig()
|
|
const formatterConfig = {
|
|
prettier: {
|
|
command: ["prettier", "--write"],
|
|
extensions: [".ts", ".tsx"],
|
|
environment: {
|
|
PRETTIERD_DEFAULT_CONFIG: ".prettierrc",
|
|
},
|
|
},
|
|
eslint: {
|
|
disabled: false,
|
|
command: ["eslint", "--fix"],
|
|
extensions: [".js", ".ts"],
|
|
},
|
|
}
|
|
const config: Record<string, unknown> = {
|
|
formatter: formatterConfig,
|
|
}
|
|
const handler = createConfigHandler({
|
|
ctx: { directory: "/tmp" },
|
|
pluginConfig,
|
|
modelCacheState: {
|
|
anthropicContext1MEnabled: false,
|
|
modelContextLimitsCache: new Map(),
|
|
},
|
|
})
|
|
|
|
// when
|
|
await handler(config)
|
|
|
|
// then
|
|
expect(config.formatter).toEqual(formatterConfig)
|
|
})
|
|
|
|
test("preserves formatter=false configured in opencode config", async () => {
|
|
// given
|
|
const pluginConfig = createPluginConfig()
|
|
const config: Record<string, unknown> = {
|
|
formatter: false,
|
|
}
|
|
const handler = createConfigHandler({
|
|
ctx: { directory: "/tmp" },
|
|
pluginConfig,
|
|
modelCacheState: {
|
|
anthropicContext1MEnabled: false,
|
|
modelContextLimitsCache: new Map(),
|
|
},
|
|
})
|
|
|
|
// when
|
|
await handler(config)
|
|
|
|
// then
|
|
expect(config.formatter).toBe(false)
|
|
})
|
|
})
|