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:
@@ -6,40 +6,22 @@ import { checkForLegacyPluginEntry } from "./legacy-plugin-warning"
|
|||||||
|
|
||||||
describe("checkForLegacyPluginEntry", () => {
|
describe("checkForLegacyPluginEntry", () => {
|
||||||
let testConfigDir = ""
|
let testConfigDir = ""
|
||||||
let originalXdgConfigHome: string | undefined
|
|
||||||
let originalOpenCodeConfigDir: string | undefined
|
|
||||||
|
|
||||||
beforeEach(() => {
|
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)}`)
|
testConfigDir = join(tmpdir(), `omo-legacy-check-${Date.now()}-${Math.random().toString(36).slice(2)}`)
|
||||||
mkdirSync(join(testConfigDir, "opencode"), { recursive: true })
|
mkdirSync(testConfigDir, { recursive: true })
|
||||||
process.env.XDG_CONFIG_HOME = testConfigDir
|
|
||||||
delete process.env.OPENCODE_CONFIG_DIR
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
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 })
|
rmSync(testConfigDir, { recursive: true, force: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("detects a bare legacy plugin entry", () => {
|
it("detects a bare legacy plugin entry", () => {
|
||||||
// given
|
// 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
|
// when
|
||||||
const result = checkForLegacyPluginEntry()
|
const result = checkForLegacyPluginEntry(testConfigDir)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.hasLegacyEntry).toBe(true)
|
expect(result.hasLegacyEntry).toBe(true)
|
||||||
@@ -49,10 +31,10 @@ describe("checkForLegacyPluginEntry", () => {
|
|||||||
|
|
||||||
it("detects a version-pinned legacy plugin entry", () => {
|
it("detects a version-pinned legacy plugin entry", () => {
|
||||||
// given
|
// 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
|
// when
|
||||||
const result = checkForLegacyPluginEntry()
|
const result = checkForLegacyPluginEntry(testConfigDir)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.hasLegacyEntry).toBe(true)
|
expect(result.hasLegacyEntry).toBe(true)
|
||||||
@@ -62,10 +44,10 @@ describe("checkForLegacyPluginEntry", () => {
|
|||||||
|
|
||||||
it("does not flag a canonical plugin entry", () => {
|
it("does not flag a canonical plugin entry", () => {
|
||||||
// given
|
// 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
|
// when
|
||||||
const result = checkForLegacyPluginEntry()
|
const result = checkForLegacyPluginEntry(testConfigDir)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.hasLegacyEntry).toBe(false)
|
expect(result.hasLegacyEntry).toBe(false)
|
||||||
@@ -75,10 +57,10 @@ describe("checkForLegacyPluginEntry", () => {
|
|||||||
|
|
||||||
it("detects legacy entries in quoted jsonc config", () => {
|
it("detects legacy entries in quoted jsonc config", () => {
|
||||||
// given
|
// 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
|
// when
|
||||||
const result = checkForLegacyPluginEntry()
|
const result = checkForLegacyPluginEntry(testConfigDir)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.hasLegacyEntry).toBe(true)
|
expect(result.hasLegacyEntry).toBe(true)
|
||||||
@@ -86,8 +68,10 @@ describe("checkForLegacyPluginEntry", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns no warning data when config is missing", () => {
|
it("returns no warning data when config is missing", () => {
|
||||||
|
// given — empty dir, no config files
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const result = checkForLegacyPluginEntry()
|
const result = checkForLegacyPluginEntry(testConfigDir)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.hasLegacyEntry).toBe(false)
|
expect(result.hasLegacyEntry).toBe(false)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { existsSync, readFileSync } from "node:fs"
|
import { existsSync, readFileSync } from "node:fs"
|
||||||
|
import { join } from "node:path"
|
||||||
|
|
||||||
import { parseJsoncSafe } from "./jsonc-parser"
|
import { parseJsoncSafe } from "./jsonc-parser"
|
||||||
import { getOpenCodeConfigPaths } from "./opencode-config-dir"
|
import { getOpenCodeConfigPaths } from "./opencode-config-dir"
|
||||||
@@ -14,7 +15,15 @@ export interface LegacyPluginCheckResult {
|
|||||||
legacyEntries: string[]
|
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 })
|
const { configJsonc, configJson } = getOpenCodeConfigPaths({ binary: "opencode", version: null })
|
||||||
|
|
||||||
if (existsSync(configJsonc)) return configJsonc
|
if (existsSync(configJsonc)) return configJsonc
|
||||||
@@ -30,8 +39,8 @@ function isCanonicalPluginEntry(entry: string): boolean {
|
|||||||
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkForLegacyPluginEntry(): LegacyPluginCheckResult {
|
export function checkForLegacyPluginEntry(overrideConfigDir?: string): LegacyPluginCheckResult {
|
||||||
const configPath = getOpenCodeConfigPath()
|
const configPath = getOpenCodeConfigPath(overrideConfigDir)
|
||||||
if (!configPath) {
|
if (!configPath) {
|
||||||
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [] }
|
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [] }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user