fix(test): make legacy-plugin-warning tests isolation-safe

Pass explicit config dir to checkForLegacyPluginEntry instead of relying
on XDG_CONFIG_HOME env var, which gets contaminated by parallel tests on
Linux CI. Also adds missing 'join' import.
This commit is contained in:
YeonGyu-Kim
2026-03-26 19:54:05 +09:00
parent f419a3a925
commit 8e65d6cf2c
2 changed files with 24 additions and 31 deletions
+12 -28
View File
@@ -6,40 +6,22 @@ import { checkForLegacyPluginEntry } from "./legacy-plugin-warning"
describe("checkForLegacyPluginEntry", () => {
let testConfigDir = ""
let originalXdgConfigHome: string | undefined
let originalOpenCodeConfigDir: string | undefined
beforeEach(() => {
originalXdgConfigHome = process.env.XDG_CONFIG_HOME
originalOpenCodeConfigDir = process.env.OPENCODE_CONFIG_DIR
testConfigDir = join(tmpdir(), `omo-legacy-check-${Date.now()}-${Math.random().toString(36).slice(2)}`)
mkdirSync(join(testConfigDir, "opencode"), { recursive: true })
process.env.XDG_CONFIG_HOME = testConfigDir
delete process.env.OPENCODE_CONFIG_DIR
mkdirSync(testConfigDir, { recursive: true })
})
afterEach(() => {
if (originalXdgConfigHome === undefined) {
delete process.env.XDG_CONFIG_HOME
} else {
process.env.XDG_CONFIG_HOME = originalXdgConfigHome
}
if (originalOpenCodeConfigDir === undefined) {
delete process.env.OPENCODE_CONFIG_DIR
} else {
process.env.OPENCODE_CONFIG_DIR = originalOpenCodeConfigDir
}
rmSync(testConfigDir, { recursive: true, force: true })
})
it("detects a bare legacy plugin entry", () => {
// given
writeFileSync(join(testConfigDir, "opencode", "opencode.json"), JSON.stringify({ plugin: ["oh-my-opencode"] }, null, 2))
writeFileSync(join(testConfigDir, "opencode.json"), JSON.stringify({ plugin: ["oh-my-opencode"] }, null, 2))
// when
const result = checkForLegacyPluginEntry()
const result = checkForLegacyPluginEntry(testConfigDir)
// then
expect(result.hasLegacyEntry).toBe(true)
@@ -49,10 +31,10 @@ describe("checkForLegacyPluginEntry", () => {
it("detects a version-pinned legacy plugin entry", () => {
// given
writeFileSync(join(testConfigDir, "opencode", "opencode.json"), JSON.stringify({ plugin: ["oh-my-opencode@3.10.0"] }, null, 2))
writeFileSync(join(testConfigDir, "opencode.json"), JSON.stringify({ plugin: ["oh-my-opencode@3.10.0"] }, null, 2))
// when
const result = checkForLegacyPluginEntry()
const result = checkForLegacyPluginEntry(testConfigDir)
// then
expect(result.hasLegacyEntry).toBe(true)
@@ -62,10 +44,10 @@ describe("checkForLegacyPluginEntry", () => {
it("does not flag a canonical plugin entry", () => {
// given
writeFileSync(join(testConfigDir, "opencode", "opencode.json"), JSON.stringify({ plugin: ["oh-my-openagent"] }, null, 2))
writeFileSync(join(testConfigDir, "opencode.json"), JSON.stringify({ plugin: ["oh-my-openagent"] }, null, 2))
// when
const result = checkForLegacyPluginEntry()
const result = checkForLegacyPluginEntry(testConfigDir)
// then
expect(result.hasLegacyEntry).toBe(false)
@@ -75,10 +57,10 @@ describe("checkForLegacyPluginEntry", () => {
it("detects legacy entries in quoted jsonc config", () => {
// given
writeFileSync(join(testConfigDir, "opencode", "opencode.jsonc"), '{\n "plugin": ["oh-my-opencode"]\n}\n')
writeFileSync(join(testConfigDir, "opencode.jsonc"), '{\n "plugin": ["oh-my-opencode"]\n}\n')
// when
const result = checkForLegacyPluginEntry()
const result = checkForLegacyPluginEntry(testConfigDir)
// then
expect(result.hasLegacyEntry).toBe(true)
@@ -86,8 +68,10 @@ describe("checkForLegacyPluginEntry", () => {
})
it("returns no warning data when config is missing", () => {
// given — empty dir, no config files
// when
const result = checkForLegacyPluginEntry()
const result = checkForLegacyPluginEntry(testConfigDir)
// then
expect(result.hasLegacyEntry).toBe(false)
+12 -3
View File
@@ -1,4 +1,5 @@
import { existsSync, readFileSync } from "node:fs"
import { join } from "node:path"
import { parseJsoncSafe } from "./jsonc-parser"
import { getOpenCodeConfigPaths } from "./opencode-config-dir"
@@ -14,7 +15,15 @@ export interface LegacyPluginCheckResult {
legacyEntries: string[]
}
function getOpenCodeConfigPath(): string | null {
function getOpenCodeConfigPath(overrideConfigDir?: string): string | null {
if (overrideConfigDir) {
const jsonPath = join(overrideConfigDir, "opencode.json")
const jsoncPath = join(overrideConfigDir, "opencode.jsonc")
if (existsSync(jsoncPath)) return jsoncPath
if (existsSync(jsonPath)) return jsonPath
return null
}
const { configJsonc, configJson } = getOpenCodeConfigPaths({ binary: "opencode", version: null })
if (existsSync(configJsonc)) return configJsonc
@@ -30,8 +39,8 @@ function isCanonicalPluginEntry(entry: string): boolean {
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
}
export function checkForLegacyPluginEntry(): LegacyPluginCheckResult {
const configPath = getOpenCodeConfigPath()
export function checkForLegacyPluginEntry(overrideConfigDir?: string): LegacyPluginCheckResult {
const configPath = getOpenCodeConfigPath(overrideConfigDir)
if (!configPath) {
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [] }
}