b98d474812
The global test-setup.ts (preloaded via bunfig.toml) already snapshots process.env in beforeEach and restores it in afterEach for every test. Per-file env tracking is duplicate work and creates four different patterns for the same problem. Affected files: - src/shared/claude-config-dir.test.ts (beforeEach/afterEach pair) - src/shared/plugin-command-discovery.test.ts (ENV_KEYS + envSnapshot) - src/features/claude-code-agent-loader/loader.test.ts (try/finally) - src/features/skill-mcp-manager/connection-env-vars.test.ts (ORIGINAL_ENV)
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
|
import { tmpdir } from "node:os"
|
|
import { join } from "node:path"
|
|
import { discoverPluginCommandDefinitions } from "./plugin-command-discovery"
|
|
|
|
function writePluginFixture(baseDir: string): void {
|
|
const claudeConfigDir = join(baseDir, "claude-config")
|
|
const pluginsHome = join(claudeConfigDir, "plugins")
|
|
const settingsPath = join(claudeConfigDir, "settings.json")
|
|
const opencodeConfigDir = join(baseDir, "opencode-config")
|
|
const pluginInstallPath = join(baseDir, "installed-plugins", "daplug")
|
|
const pluginKey = "daplug@1.0.0"
|
|
|
|
mkdirSync(join(pluginInstallPath, ".claude-plugin"), { recursive: true })
|
|
mkdirSync(join(pluginInstallPath, "commands"), { recursive: true })
|
|
mkdirSync(join(pluginInstallPath, "skills", "plugin-plan"), { recursive: true })
|
|
|
|
writeFileSync(
|
|
join(pluginInstallPath, ".claude-plugin", "plugin.json"),
|
|
JSON.stringify({ name: "daplug", version: "1.0.0" }, null, 2),
|
|
)
|
|
writeFileSync(
|
|
join(pluginInstallPath, "commands", "run-prompt.md"),
|
|
`---
|
|
description: Run prompt from daplug
|
|
---
|
|
Execute daplug prompt flow.
|
|
`,
|
|
)
|
|
writeFileSync(
|
|
join(pluginInstallPath, "skills", "plugin-plan", "SKILL.md"),
|
|
`---
|
|
name: plugin-plan
|
|
description: Plan work from daplug skill
|
|
---
|
|
Build a plan from plugin skill context.
|
|
`,
|
|
)
|
|
|
|
mkdirSync(pluginsHome, { recursive: true })
|
|
writeFileSync(
|
|
join(pluginsHome, "installed_plugins.json"),
|
|
JSON.stringify(
|
|
{
|
|
version: 2,
|
|
plugins: {
|
|
[pluginKey]: [
|
|
{
|
|
scope: "user",
|
|
installPath: pluginInstallPath,
|
|
version: "1.0.0",
|
|
installedAt: "2026-01-01T00:00:00.000Z",
|
|
lastUpdated: "2026-01-01T00:00:00.000Z",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
|
|
mkdirSync(claudeConfigDir, { recursive: true })
|
|
writeFileSync(
|
|
settingsPath,
|
|
JSON.stringify(
|
|
{
|
|
enabledPlugins: {
|
|
[pluginKey]: true,
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
mkdirSync(opencodeConfigDir, { recursive: true })
|
|
|
|
process.env.CLAUDE_CONFIG_DIR = claudeConfigDir
|
|
process.env.CLAUDE_PLUGINS_HOME = pluginsHome
|
|
process.env.CLAUDE_SETTINGS_PATH = settingsPath
|
|
process.env.OPENCODE_CONFIG_DIR = opencodeConfigDir
|
|
}
|
|
|
|
describe("plugin command discovery utility", () => {
|
|
let tempDir = ""
|
|
|
|
beforeEach(() => {
|
|
tempDir = mkdtempSync(join(tmpdir(), "omo-shared-plugin-discovery-test-"))
|
|
writePluginFixture(tempDir)
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(tempDir, { recursive: true, force: true })
|
|
})
|
|
|
|
describe("#given plugin loading is enabled", () => {
|
|
it("#then returns plugin command and skill definitions", () => {
|
|
// given
|
|
const options = { pluginsEnabled: true }
|
|
|
|
// when
|
|
const definitions = discoverPluginCommandDefinitions(options)
|
|
|
|
// then
|
|
expect(Object.keys(definitions)).toContain("daplug:run-prompt")
|
|
expect(Object.keys(definitions)).toContain("daplug:plugin-plan")
|
|
})
|
|
})
|
|
})
|