test: remove redundant local env restoration

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)
This commit is contained in:
Matan Kushner
2026-05-04 20:11:50 +09:00
parent 6b9731923d
commit b98d474812
4 changed files with 7 additions and 70 deletions
@@ -4,16 +4,6 @@ import { tmpdir } from "node:os"
import { join } from "node:path"
import { discoverPluginCommandDefinitions } from "./plugin-command-discovery"
const ENV_KEYS = [
"CLAUDE_CONFIG_DIR",
"CLAUDE_PLUGINS_HOME",
"CLAUDE_SETTINGS_PATH",
"OPENCODE_CONFIG_DIR",
] as const
type EnvKey = (typeof ENV_KEYS)[number]
type EnvSnapshot = Record<EnvKey, string | undefined>
function writePluginFixture(baseDir: string): void {
const claudeConfigDir = join(baseDir, "claude-config")
const pluginsHome = join(claudeConfigDir, "plugins")
@@ -94,28 +84,13 @@ Build a plan from plugin skill context.
describe("plugin command discovery utility", () => {
let tempDir = ""
let envSnapshot: EnvSnapshot
beforeEach(() => {
tempDir = mkdtempSync(join(tmpdir(), "omo-shared-plugin-discovery-test-"))
envSnapshot = {
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR,
CLAUDE_PLUGINS_HOME: process.env.CLAUDE_PLUGINS_HOME,
CLAUDE_SETTINGS_PATH: process.env.CLAUDE_SETTINGS_PATH,
OPENCODE_CONFIG_DIR: process.env.OPENCODE_CONFIG_DIR,
}
writePluginFixture(tempDir)
})
afterEach(() => {
for (const key of ENV_KEYS) {
const previousValue = envSnapshot[key]
if (previousValue === undefined) {
delete process.env[key]
} else {
process.env[key] = previousValue
}
}
rmSync(tempDir, { recursive: true, force: true })
})