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
@@ -8,9 +8,11 @@ import type { PluginInput } from "@opencode-ai/plugin"
import { createOpencodeClient, type Project } from "@opencode-ai/sdk"
const isCallerOrchestratorMock = mock(async () => true)
const collectGitDiffStatsMock = mock(() => {
throw new Error("background launches should not trigger verification")
})
const collectGitDiffStatsMock = mock(() => ({
filesChanged: 0,
insertions: 0,
deletions: 0,
}))
mock.module("../../shared/session-utils", () => ({
isCallerOrchestrator: isCallerOrchestratorMock,
@@ -1,5 +1,3 @@
/// <reference path="../../../bun-test.d.ts" />
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
@@ -120,37 +118,6 @@ describe("autoMigrateLegacyPluginEntry", () => {
})
})
describe("#given opencode.jsonc contains a nested plugin key before the top-level plugin array", () => {
it("#then rewrites only the top-level plugin array", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.jsonc"),
`{
"nested": {
"plugin": ["oh-my-opencode"]
},
"plugin": ["oh-my-opencode@latest"]
}
`,
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
expect(result.migrated).toBe(true)
const content = readFileSync(join(testConfigDir, "opencode.jsonc"), "utf-8")
expect(content).toContain(`"nested": {
"plugin": ["oh-my-opencode"]
}`)
expect(content).toContain(`"plugin": [
"oh-my-openagent@latest"
]`)
})
})
describe("#given only canonical entry exists", () => {
it("#then returns migrated false and leaves file untouched", async () => {
// given
+23 -4
View File
@@ -1,8 +1,7 @@
import { existsSync, readFileSync } from "node:fs"
import { existsSync, readFileSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { parseJsoncSafe } from "../../shared/jsonc-parser"
import { migrateLegacyPluginEntry } from "../../shared/migrate-legacy-plugin-entry"
import { getOpenCodeConfigPaths } from "../../shared/opencode-config-dir"
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "../../shared/plugin-identity"
@@ -21,6 +20,10 @@ function isLegacyEntry(entry: string): boolean {
return entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)
}
function isCanonicalEntry(entry: string): boolean {
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
}
function toLegacyCanonical(entry: string): string {
if (entry === LEGACY_PLUGIN_NAME) return PLUGIN_NAME
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
@@ -57,13 +60,29 @@ export function autoMigrateLegacyPluginEntry(overrideConfigDir?: string): Migrat
const legacyEntries = plugins.filter(isLegacyEntry)
if (legacyEntries.length === 0) return { migrated: false, from: null, to: null, configPath }
const hasCanonical = plugins.some(isCanonicalEntry)
const from = legacyEntries[0]
const to = toLegacyCanonical(from)
if (!migrateLegacyPluginEntry(configPath)) {
return { migrated: false, from: null, to: null, configPath }
const normalized = hasCanonical
? plugins.filter((p) => !isLegacyEntry(p))
: plugins.map((p) => (isLegacyEntry(p) ? toLegacyCanonical(p) : p))
const isJsonc = configPath.endsWith(".jsonc")
if (isJsonc) {
const pluginArrayRegex = /((?:"plugin"|plugin)\s*:\s*)\[([\s\S]*?)\]/
const match = content.match(pluginArrayRegex)
if (match) {
const formattedPlugins = normalized.map((p) => `"${p}"`).join(",\n ")
const newContent = content.replace(pluginArrayRegex, `$1[\n ${formattedPlugins}\n ]`)
writeFileSync(configPath, newContent)
return { migrated: true, from, to, configPath }
}
}
const parsed = JSON.parse(content) as Record<string, unknown>
parsed.plugin = normalized
writeFileSync(configPath, JSON.stringify(parsed, null, 2) + "\n")
return { migrated: true, from, to, configPath }
} catch {
return { migrated: false, from: null, to: null, configPath }
+1 -33
View File
@@ -1,15 +1,10 @@
/// <reference path="../../../bun-test.d.ts" />
import { afterAll, beforeEach, describe, expect, it, mock } from "bun:test"
import type { LegacyPluginCheckResult } from "../../shared/legacy-plugin-warning"
import type { MigrationResult } from "./auto-migrate"
const mockCheckForLegacyPluginEntry = mock((): LegacyPluginCheckResult => ({
const mockCheckForLegacyPluginEntry = mock(() => ({
hasLegacyEntry: false,
hasCanonicalEntry: false,
legacyEntries: [] as string[],
configPath: null,
}))
const mockAutoMigrate = mock((): MigrationResult => ({
@@ -72,7 +67,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: false,
hasCanonicalEntry: true,
legacyEntries: [],
configPath: null,
})
mockAutoMigrate.mockReturnValue({ migrated: false, from: null, to: null, configPath: null })
mockShowToast.mockResolvedValue(undefined)
@@ -99,7 +93,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/opencode.json",
})
mockAutoMigrate.mockReturnValue({
migrated: true,
@@ -127,7 +120,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/opencode.json",
})
mockAutoMigrate.mockReturnValue({
migrated: false,
@@ -155,7 +147,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/opencode.json",
})
mockAutoMigrate.mockReturnValue({
migrated: true,
@@ -182,7 +173,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/opencode.json",
})
const { createLegacyPluginToastHook } = await importFreshModule()
const hook = createLegacyPluginToastHook(createMockCtx())
@@ -202,7 +192,6 @@ describe("createLegacyPluginToastHook", () => {
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/opencode.json",
})
const { createLegacyPluginToastHook } = await importFreshModule()
const hook = createLegacyPluginToastHook(createMockCtx())
@@ -214,25 +203,4 @@ describe("createLegacyPluginToastHook", () => {
expect(mockCheckForLegacyPluginEntry).not.toHaveBeenCalled()
})
})
describe("#given a project directory is available", () => {
it("#then passes the project directory into legacy config detection", async () => {
// given
mockCheckForLegacyPluginEntry.mockReturnValue({
hasLegacyEntry: true,
hasCanonicalEntry: false,
legacyEntries: ["oh-my-opencode"],
configPath: "/tmp/test/.opencode/opencode.json",
})
const { createLegacyPluginToastHook } = await importFreshModule()
const hook = createLegacyPluginToastHook(createMockCtx())
// when
await hook.event(createEvent("session.created"))
// then
expect(mockCheckForLegacyPluginEntry).toHaveBeenCalledWith(undefined, "/tmp/test")
expect(mockAutoMigrate).toHaveBeenCalledWith("/tmp/test/.opencode")
})
})
})
+2 -4
View File
@@ -1,5 +1,3 @@
import { dirname } from "node:path"
import type { PluginInput } from "@opencode-ai/plugin"
import { checkForLegacyPluginEntry } from "../../shared/legacy-plugin-warning"
@@ -19,10 +17,10 @@ export function createLegacyPluginToastHook(ctx: PluginInput) {
fired = true
const result = checkForLegacyPluginEntry(undefined, ctx.directory)
const result = checkForLegacyPluginEntry()
if (!result.hasLegacyEntry) return
const migration = autoMigrateLegacyPluginEntry(result.configPath ? dirname(result.configPath) : undefined)
const migration = autoMigrateLegacyPluginEntry()
if (migration.migrated) {
log("[legacy-plugin-toast] Auto-migrated opencode.json plugin entry", {