2026-01-07 11:44:03 -03:00
|
|
|
import { describe, expect, test, beforeEach, afterEach } from "bun:test"
|
|
|
|
|
import { detectExternalNotificationPlugin, getNotificationConflictWarning } from "./external-plugin-detector"
|
|
|
|
|
import * as fs from "node:fs"
|
|
|
|
|
import * as path from "node:path"
|
|
|
|
|
import * as os from "node:os"
|
|
|
|
|
|
|
|
|
|
describe("external-plugin-detector", () => {
|
|
|
|
|
let tempDir: string
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "omo-test-"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
fs.rmSync(tempDir, { recursive: true, force: true })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("detectExternalNotificationPlugin", () => {
|
|
|
|
|
test("should return detected=false when no plugins configured", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - empty directory
|
|
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(false)
|
|
|
|
|
expect(result.pluginName).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should return detected=false when only oh-my-opencode is configured", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - opencode.json with only oh-my-opencode
|
2026-01-07 11:44:03 -03:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["oh-my-opencode"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(false)
|
|
|
|
|
expect(result.pluginName).toBeNull()
|
|
|
|
|
expect(result.allPlugins).toContain("oh-my-opencode")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should detect opencode-notifier plugin", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - opencode.json with opencode-notifier
|
2026-01-07 11:44:03 -03:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["oh-my-opencode", "opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should detect opencode-notifier with version suffix", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - opencode.json with versioned opencode-notifier
|
2026-01-07 11:44:03 -03:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["oh-my-opencode", "opencode-notifier@1.2.3"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should detect @mohak34/opencode-notifier", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - opencode.json with scoped package name
|
2026-01-07 11:44:03 -03:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["oh-my-opencode", "@mohak34/opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then - returns the matched known plugin pattern, not the full entry
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toContain("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should handle JSONC format with comments", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - opencode.jsonc with comments
|
2026-01-07 11:44:03 -03:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.jsonc"),
|
|
|
|
|
`{
|
|
|
|
|
// This is a comment
|
|
|
|
|
"plugin": [
|
|
|
|
|
"oh-my-opencode",
|
|
|
|
|
"opencode-notifier" // Another comment
|
|
|
|
|
]
|
|
|
|
|
}`
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-27 09:24:23 +09:00
|
|
|
describe("false positive prevention", () => {
|
|
|
|
|
test("should NOT match my-opencode-notifier-fork (suffix variation)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - plugin with similar name but different suffix
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["my-opencode-notifier-fork"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(false)
|
|
|
|
|
expect(result.pluginName).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should NOT match some-other-plugin/opencode-notifier-like (path with similar name)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - plugin path containing similar substring
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["some-other-plugin/opencode-notifier-like"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(false)
|
|
|
|
|
expect(result.pluginName).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should NOT match opencode-notifier-extended (prefix match but different package)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - plugin with prefix match but extended name
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["opencode-notifier-extended"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(false)
|
|
|
|
|
expect(result.pluginName).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match opencode-notifier exactly", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - exact match
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match opencode-notifier@1.2.3 (version suffix)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - version suffix
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["opencode-notifier@1.2.3"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match @mohak34/opencode-notifier (scoped package)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - scoped package
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["@mohak34/opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toContain("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match npm:opencode-notifier (npm prefix)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - npm prefix
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["npm:opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match npm:opencode-notifier@2.0.0 (npm prefix with version)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - npm prefix with version
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["npm:opencode-notifier@2.0.0"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("should match file:///path/to/opencode-notifier (file path)", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given - file path
|
2026-01-27 09:24:23 +09:00
|
|
|
const opencodeDir = path.join(tempDir, ".opencode")
|
|
|
|
|
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
path.join(opencodeDir, "opencode.json"),
|
|
|
|
|
JSON.stringify({ plugin: ["file:///home/user/plugins/opencode-notifier"] })
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-27 09:24:23 +09:00
|
|
|
const result = detectExternalNotificationPlugin(tempDir)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-27 09:24:23 +09:00
|
|
|
expect(result.detected).toBe(true)
|
|
|
|
|
expect(result.pluginName).toBe("opencode-notifier")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-07 11:44:03 -03:00
|
|
|
describe("getNotificationConflictWarning", () => {
|
|
|
|
|
test("should generate warning message with plugin name", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-07 11:44:03 -03:00
|
|
|
const warning = getNotificationConflictWarning("opencode-notifier")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-07 11:44:03 -03:00
|
|
|
expect(warning).toContain("opencode-notifier")
|
|
|
|
|
expect(warning).toContain("session.idle")
|
|
|
|
|
expect(warning).toContain("auto-disabled")
|
|
|
|
|
expect(warning).toContain("force_enable")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|