test: cover canonical plugin config detection
This commit is contained in:
@@ -268,7 +268,7 @@ describe("detectConfigFile", () => {
|
||||
describe("detectPluginConfigFile", () => {
|
||||
const testDir = join(__dirname, ".test-detect-plugin")
|
||||
|
||||
test("prefers oh-my-opencode over oh-my-openagent", () => {
|
||||
test("prefers oh-my-openagent over oh-my-opencode when both jsonc files exist", () => {
|
||||
// given
|
||||
if (!existsSync(testDir)) mkdirSync(testDir, { recursive: true })
|
||||
writeFileSync(join(testDir, "oh-my-openagent.jsonc"), "{}")
|
||||
@@ -279,7 +279,8 @@ describe("detectPluginConfigFile", () => {
|
||||
|
||||
// then
|
||||
expect(result.format).toBe("jsonc")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-opencode.jsonc"))
|
||||
expect(result.path).toBe(join(testDir, "oh-my-openagent.jsonc"))
|
||||
expect(result.legacyPath).toBe(join(testDir, "oh-my-opencode.jsonc"))
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
@@ -295,13 +296,15 @@ describe("detectPluginConfigFile", () => {
|
||||
// then
|
||||
expect(result.format).toBe("jsonc")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-opencode.jsonc"))
|
||||
expect(result.legacyPath).toBeUndefined()
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
test("falls back to oh-my-opencode.json when no jsonc exists", () => {
|
||||
test("loads oh-my-openagent.json before oh-my-opencode.json when no jsonc exists", () => {
|
||||
// given
|
||||
if (!existsSync(testDir)) mkdirSync(testDir, { recursive: true })
|
||||
writeFileSync(join(testDir, "oh-my-openagent.json"), "{}")
|
||||
writeFileSync(join(testDir, "oh-my-opencode.json"), "{}")
|
||||
|
||||
// when
|
||||
@@ -309,7 +312,8 @@ describe("detectPluginConfigFile", () => {
|
||||
|
||||
// then
|
||||
expect(result.format).toBe("json")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-opencode.json"))
|
||||
expect(result.path).toBe(join(testDir, "oh-my-openagent.json"))
|
||||
expect(result.legacyPath).toBe(join(testDir, "oh-my-opencode.json"))
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
@@ -324,12 +328,12 @@ describe("detectPluginConfigFile", () => {
|
||||
|
||||
// then
|
||||
expect(result.format).toBe("none")
|
||||
expect(result.path).toBe(join(emptyDir, "oh-my-opencode.json"))
|
||||
expect(result.path).toBe(join(emptyDir, "oh-my-openagent.json"))
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
test("prefers oh-my-opencode.json over oh-my-openagent.jsonc", () => {
|
||||
test("prefers canonical jsonc over legacy json when both exist", () => {
|
||||
// given
|
||||
if (!existsSync(testDir)) mkdirSync(testDir, { recursive: true })
|
||||
writeFileSync(join(testDir, "oh-my-opencode.json"), "{}")
|
||||
@@ -339,8 +343,25 @@ describe("detectPluginConfigFile", () => {
|
||||
const result = detectPluginConfigFile(testDir)
|
||||
|
||||
// then
|
||||
expect(result.format).toBe("json")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-opencode.json"))
|
||||
expect(result.format).toBe("jsonc")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-openagent.jsonc"))
|
||||
expect(result.legacyPath).toBe(join(testDir, "oh-my-opencode.json"))
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
test("loads oh-my-openagent when only canonical jsonc exists", () => {
|
||||
// given
|
||||
if (!existsSync(testDir)) mkdirSync(testDir, { recursive: true })
|
||||
writeFileSync(join(testDir, "oh-my-openagent.jsonc"), "{}")
|
||||
|
||||
// when
|
||||
const result = detectPluginConfigFile(testDir)
|
||||
|
||||
// then
|
||||
expect(result.format).toBe("jsonc")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-openagent.jsonc"))
|
||||
expect(result.legacyPath).toBeUndefined()
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { detectPluginConfigFile } from "./jsonc-parser"
|
||||
|
||||
describe("detectPluginConfigFile - canonical config detection", () => {
|
||||
const testDir = join(__dirname, ".test-detect-plugin-canonical")
|
||||
|
||||
test("detects oh-my-openagent config when no legacy config exists", () => {
|
||||
//#given
|
||||
if (!existsSync(testDir)) mkdirSync(testDir, { recursive: true })
|
||||
writeFileSync(join(testDir, "oh-my-openagent.jsonc"), "{}")
|
||||
|
||||
//#when
|
||||
const result = detectPluginConfigFile(testDir)
|
||||
|
||||
//#then
|
||||
expect(result.format).toBe("jsonc")
|
||||
expect(result.path).toBe(join(testDir, "oh-my-openagent.jsonc"))
|
||||
|
||||
rmSync(testDir, { recursive: true, force: true })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user