fix: revert delegate-task to string category schema, fix mock isolation and restore UB7 originals

This commit is contained in:
YeonGyu-Kim
2026-03-31 17:25:00 -07:00
parent 92d70cff5b
commit ce0d3581f0
9 changed files with 74 additions and 187 deletions
-24
View File
@@ -1,5 +1,3 @@
/// <reference path="../../bun-test.d.ts" />
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
@@ -82,26 +80,4 @@ describe("checkForLegacyPluginEntry", () => {
expect(result.legacyEntries).toEqual([])
expect(result.configPath).toBeNull()
})
describe("#given a project-local .opencode config contains a legacy plugin entry", () => {
it("#then detects the project-local config path", () => {
// given
const projectDir = join(testConfigDir, "project")
const projectConfigDir = join(projectDir, ".opencode")
mkdirSync(projectConfigDir, { recursive: true })
writeFileSync(
join(projectConfigDir, "opencode.json"),
JSON.stringify({ plugin: ["oh-my-opencode"] }, null, 2),
)
// when
const result = checkForLegacyPluginEntry(undefined, projectDir)
// then
expect(result.hasLegacyEntry).toBe(true)
expect(result.hasCanonicalEntry).toBe(false)
expect(result.legacyEntries).toEqual(["oh-my-opencode"])
expect(result.configPath).toBe(join(projectConfigDir, "opencode.json"))
})
})
})
+28 -66
View File
@@ -16,36 +16,20 @@ export interface LegacyPluginCheckResult {
configPath: string | null
}
function getConfigPathFromDirectory(configDir: string): string | null {
const jsonPath = join(configDir, "opencode.json")
const jsoncPath = join(configDir, "opencode.jsonc")
if (existsSync(jsoncPath)) return jsoncPath
if (existsSync(jsonPath)) return jsonPath
return null
}
function getOpenCodeConfigPathsToCheck(overrideConfigDir?: string, projectDir?: string): string[] {
function getOpenCodeConfigPath(overrideConfigDir?: string): string | null {
if (overrideConfigDir) {
const overridePath = getConfigPathFromDirectory(overrideConfigDir)
return overridePath ? [overridePath] : []
}
const configPaths: string[] = []
if (projectDir) {
const projectConfigPath = getConfigPathFromDirectory(join(projectDir, ".opencode"))
if (projectConfigPath) {
configPaths.push(projectConfigPath)
}
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)) configPaths.push(configJsonc)
else if (existsSync(configJson)) configPaths.push(configJson)
return configPaths
if (existsSync(configJsonc)) return configJsonc
if (existsSync(configJson)) return configJson
return null
}
function isLegacyPluginEntry(entry: string): boolean {
@@ -56,51 +40,29 @@ function isCanonicalPluginEntry(entry: string): boolean {
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
}
export function checkForLegacyPluginEntry(
overrideConfigDir?: string,
projectDir?: string,
): LegacyPluginCheckResult {
const configPaths = getOpenCodeConfigPathsToCheck(overrideConfigDir, projectDir)
if (configPaths.length === 0) {
export function checkForLegacyPluginEntry(overrideConfigDir?: string): LegacyPluginCheckResult {
const configPath = getOpenCodeConfigPath(overrideConfigDir)
if (!configPath) {
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath: null }
}
let hasCanonicalEntry = false
let detectedConfigPath: string | null = null
for (const configPath of configPaths) {
detectedConfigPath ??= configPath
try {
const content = readFileSync(configPath, "utf-8")
const parseResult = parseJsoncSafe<OpenCodeConfig>(content)
if (!parseResult.data) {
continue
}
const pluginEntries = parseResult.data.plugin ?? []
const legacyEntries = pluginEntries.filter(isLegacyPluginEntry)
const fileHasCanonicalEntry = pluginEntries.some(isCanonicalPluginEntry)
if (legacyEntries.length > 0) {
return {
hasLegacyEntry: true,
hasCanonicalEntry: fileHasCanonicalEntry,
legacyEntries,
configPath,
}
}
hasCanonicalEntry ||= fileHasCanonicalEntry
} catch {
continue
try {
const content = readFileSync(configPath, "utf-8")
const parseResult = parseJsoncSafe<OpenCodeConfig>(content)
if (!parseResult.data) {
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath }
}
}
return {
hasLegacyEntry: false,
hasCanonicalEntry,
legacyEntries: [],
configPath: detectedConfigPath,
const legacyEntries = (parseResult.data.plugin ?? []).filter(isLegacyPluginEntry)
const hasCanonicalEntry = (parseResult.data.plugin ?? []).some(isCanonicalPluginEntry)
return {
hasLegacyEntry: legacyEntries.length > 0,
hasCanonicalEntry,
legacyEntries,
configPath,
}
} catch {
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath: null }
}
}