test(plugin): update plugin config and registry tests
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+18
-10
@@ -3,7 +3,7 @@ import { chmodSync, existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, wr
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import * as shared from "./shared"
|
||||
import { loadPluginConfig, mergeConfigs, parseConfigPartially } from "./plugin-config";
|
||||
import { mergeConfigs, parseConfigPartially } from "./plugin-config";
|
||||
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "./config";
|
||||
|
||||
const tempDirs: string[] = []
|
||||
@@ -12,6 +12,10 @@ function createConfig(config: Partial<OhMyOpenCodeConfig>): OhMyOpenCodeConfig {
|
||||
return OhMyOpenCodeConfigSchema.parse(config)
|
||||
}
|
||||
|
||||
async function importFreshPluginConfigModule(): Promise<typeof import("./plugin-config")> {
|
||||
return import(`./plugin-config?test=${Date.now()}-${Math.random()}`)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
mock.restore()
|
||||
|
||||
@@ -297,7 +301,7 @@ describe("parseConfigPartially", () => {
|
||||
});
|
||||
|
||||
describe("loadPluginConfig", () => {
|
||||
it("should only honor mcp_env_allowlist from user config", () => {
|
||||
it("should only honor mcp_env_allowlist from user config", async () => {
|
||||
// given
|
||||
const rootDir = mkdtempSync(join(tmpdir(), "omo-plugin-config-"))
|
||||
const userConfigDir = join(rootDir, "user-config")
|
||||
@@ -317,16 +321,17 @@ describe("loadPluginConfig", () => {
|
||||
JSON.stringify({ mcp_env_allowlist: ["PROJECT_TOKEN"] })
|
||||
)
|
||||
|
||||
spyOn(shared, "getOpenCodeConfigDir").mockReturnValue(userConfigDir)
|
||||
process.env.OPENCODE_CONFIG_DIR = userConfigDir
|
||||
|
||||
// when
|
||||
const { loadPluginConfig } = await importFreshPluginConfigModule()
|
||||
const config = loadPluginConfig(projectDir, {})
|
||||
|
||||
// then
|
||||
expect(config.mcp_env_allowlist).toEqual(["USER_ONLY_TOKEN"])
|
||||
})
|
||||
|
||||
it("should ignore edits to the renamed legacy backup after migration", () => {
|
||||
it("should ignore edits to the renamed legacy backup after migration", async () => {
|
||||
// given
|
||||
const rootDir = mkdtempSync(join(tmpdir(), "omo-plugin-config-legacy-"))
|
||||
const userConfigDir = join(rootDir, "user-config")
|
||||
@@ -341,9 +346,10 @@ describe("loadPluginConfig", () => {
|
||||
mkdirSync(projectConfigDir, { recursive: true })
|
||||
writeFileSync(legacyConfigPath, JSON.stringify({ agents: { oracle: { model: "openai/gpt-5.4" } } }))
|
||||
|
||||
spyOn(shared, "getOpenCodeConfigDir").mockReturnValue(userConfigDir)
|
||||
process.env.OPENCODE_CONFIG_DIR = userConfigDir
|
||||
|
||||
// when
|
||||
const { loadPluginConfig } = await importFreshPluginConfigModule()
|
||||
loadPluginConfig(projectDir, {})
|
||||
writeFileSync(backupConfigPath, JSON.stringify({ agents: { oracle: { model: "openai/gpt-5-nano" } } }))
|
||||
const reloadedConfig = loadPluginConfig(projectDir, {})
|
||||
@@ -355,7 +361,7 @@ describe("loadPluginConfig", () => {
|
||||
expect(reloadedConfig.agents?.oracle?.model).toBe("openai/gpt-5.4")
|
||||
})
|
||||
|
||||
it("should still load config from legacy path when migration fails", () => {
|
||||
it("should still load config from legacy path when migration fails", async () => {
|
||||
// given - legacy config exists but canonical path is not writable
|
||||
const rootDir = mkdtempSync(join(tmpdir(), "omo-plugin-config-fail-"))
|
||||
const userConfigDir = join(rootDir, "user-config")
|
||||
@@ -374,12 +380,13 @@ describe("loadPluginConfig", () => {
|
||||
chmodSync(projectConfigDir, 0o555)
|
||||
}
|
||||
|
||||
spyOn(shared, "getOpenCodeConfigDir").mockReturnValue(userConfigDir)
|
||||
process.env.OPENCODE_CONFIG_DIR = userConfigDir
|
||||
|
||||
// when
|
||||
let config: OhMyOpenCodeConfig
|
||||
try {
|
||||
config = loadPluginConfig(projectDir, {})
|
||||
const fresh = await importFreshPluginConfigModule()
|
||||
config = fresh.loadPluginConfig(projectDir, {})
|
||||
} finally {
|
||||
// Restore permissions for cleanup
|
||||
if (process.platform !== "win32") {
|
||||
@@ -391,7 +398,7 @@ describe("loadPluginConfig", () => {
|
||||
expect(config.agents?.oracle?.model).toBe("openai/gpt-5.4")
|
||||
})
|
||||
|
||||
it("should load migrated legacy project config on the first load", () => {
|
||||
it("should load migrated legacy project config on the first load", async () => {
|
||||
// given
|
||||
const rootDir = mkdtempSync(join(tmpdir(), "omo-plugin-config-first-load-"))
|
||||
const userConfigDir = join(rootDir, "user-config")
|
||||
@@ -405,9 +412,10 @@ describe("loadPluginConfig", () => {
|
||||
mkdirSync(projectConfigDir, { recursive: true })
|
||||
writeFileSync(legacyConfigPath, JSON.stringify({ agents: { oracle: { model: "openai/gpt-5.4" } } }))
|
||||
|
||||
spyOn(shared, "getOpenCodeConfigDir").mockReturnValue(userConfigDir)
|
||||
process.env.OPENCODE_CONFIG_DIR = userConfigDir
|
||||
|
||||
// when
|
||||
const { loadPluginConfig } = await importFreshPluginConfigModule()
|
||||
const config = loadPluginConfig(projectDir, {})
|
||||
|
||||
// then
|
||||
|
||||
Reference in New Issue
Block a user