fix: use jsonc-parser for safe JSONC migration and add project-local config detection
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
/// <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(() => ({
|
||||
const mockCheckForLegacyPluginEntry = mock((): LegacyPluginCheckResult => ({
|
||||
hasLegacyEntry: false,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: [] as string[],
|
||||
configPath: null,
|
||||
}))
|
||||
|
||||
const mockAutoMigrate = mock((): MigrationResult => ({
|
||||
@@ -67,6 +72,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: false,
|
||||
hasCanonicalEntry: true,
|
||||
legacyEntries: [],
|
||||
configPath: null,
|
||||
})
|
||||
mockAutoMigrate.mockReturnValue({ migrated: false, from: null, to: null, configPath: null })
|
||||
mockShowToast.mockResolvedValue(undefined)
|
||||
@@ -93,6 +99,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: true,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: ["oh-my-opencode"],
|
||||
configPath: "/tmp/opencode.json",
|
||||
})
|
||||
mockAutoMigrate.mockReturnValue({
|
||||
migrated: true,
|
||||
@@ -120,6 +127,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: true,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: ["oh-my-opencode"],
|
||||
configPath: "/tmp/opencode.json",
|
||||
})
|
||||
mockAutoMigrate.mockReturnValue({
|
||||
migrated: false,
|
||||
@@ -147,6 +155,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: true,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: ["oh-my-opencode"],
|
||||
configPath: "/tmp/opencode.json",
|
||||
})
|
||||
mockAutoMigrate.mockReturnValue({
|
||||
migrated: true,
|
||||
@@ -173,6 +182,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: true,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: ["oh-my-opencode"],
|
||||
configPath: "/tmp/opencode.json",
|
||||
})
|
||||
const { createLegacyPluginToastHook } = await importFreshModule()
|
||||
const hook = createLegacyPluginToastHook(createMockCtx())
|
||||
@@ -192,6 +202,7 @@ describe("createLegacyPluginToastHook", () => {
|
||||
hasLegacyEntry: true,
|
||||
hasCanonicalEntry: false,
|
||||
legacyEntries: ["oh-my-opencode"],
|
||||
configPath: "/tmp/opencode.json",
|
||||
})
|
||||
const { createLegacyPluginToastHook } = await importFreshModule()
|
||||
const hook = createLegacyPluginToastHook(createMockCtx())
|
||||
@@ -203,4 +214,25 @@ 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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user