Merge pull request #3784 from matchai/chore/remove-redundant-env-restore
test: remove redundant local env restoration
This commit is contained in:
@@ -191,31 +191,18 @@ describe("claude-code-agent-loader", () => {
|
|||||||
describe("loadUserAgents", () => {
|
describe("loadUserAgents", () => {
|
||||||
test("returns empty object when pointed at dir without agents/", () => {
|
test("returns empty object when pointed at dir without agents/", () => {
|
||||||
const root = trackDir(mkdtempSync(join(tmpdir(), "agent-loader-test-")))
|
const root = trackDir(mkdtempSync(join(tmpdir(), "agent-loader-test-")))
|
||||||
// Temporarily set env var — best-effort in parallel test runner
|
process.env.CLAUDE_CONFIG_DIR = root
|
||||||
const prev = process.env.CLAUDE_CONFIG_DIR
|
const result = loadUserAgents()
|
||||||
try {
|
expect(result).toEqual({})
|
||||||
process.env.CLAUDE_CONFIG_DIR = root
|
|
||||||
const result = loadUserAgents()
|
|
||||||
expect(result).toEqual({})
|
|
||||||
} finally {
|
|
||||||
if (prev !== undefined) process.env.CLAUDE_CONFIG_DIR = prev
|
|
||||||
else delete process.env.CLAUDE_CONFIG_DIR
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("loadOpencodeGlobalAgents", () => {
|
describe("loadOpencodeGlobalAgents", () => {
|
||||||
test("returns empty object when pointed at dir without agents/", () => {
|
test("returns empty object when pointed at dir without agents/", () => {
|
||||||
const root = trackDir(mkdtempSync(join(tmpdir(), "agent-loader-test-")))
|
const root = trackDir(mkdtempSync(join(tmpdir(), "agent-loader-test-")))
|
||||||
const prev = process.env.OPENCODE_CONFIG_DIR
|
process.env.OPENCODE_CONFIG_DIR = root
|
||||||
try {
|
const result = loadOpencodeGlobalAgents()
|
||||||
process.env.OPENCODE_CONFIG_DIR = root
|
expect(result).toEqual({})
|
||||||
const result = loadOpencodeGlobalAgents()
|
|
||||||
expect(result).toEqual({})
|
|
||||||
} finally {
|
|
||||||
if (prev !== undefined) process.env.OPENCODE_CONFIG_DIR = prev
|
|
||||||
else delete process.env.OPENCODE_CONFIG_DIR
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -126,8 +126,6 @@ function createClientKey(info: SkillMcpClientInfo): string {
|
|||||||
return `${info.sessionID}:${info.skillName}:${info.serverName}`
|
return `${info.sessionID}:${info.skillName}:${info.serverName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const ORIGINAL_ENV = { ...process.env }
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
createdStdioTransports.length = 0
|
createdStdioTransports.length = 0
|
||||||
createdHttpTransports.length = 0
|
createdHttpTransports.length = 0
|
||||||
@@ -147,15 +145,6 @@ afterEach(async () => {
|
|||||||
}
|
}
|
||||||
trackedStates.length = 0
|
trackedStates.length = 0
|
||||||
|
|
||||||
for (const key of Object.keys(process.env)) {
|
|
||||||
if (!(key in ORIGINAL_ENV)) {
|
|
||||||
delete process.env[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
|
|
||||||
process.env[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
setStdioClientDependenciesForTesting()
|
setStdioClientDependenciesForTesting()
|
||||||
setHttpClientDependenciesForTesting()
|
setHttpClientDependenciesForTesting()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,23 +1,9 @@
|
|||||||
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
|
import { describe, test, expect } from "bun:test"
|
||||||
import { homedir } from "node:os"
|
import { homedir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import { getClaudeConfigDir } from "./claude-config-dir"
|
import { getClaudeConfigDir } from "./claude-config-dir"
|
||||||
|
|
||||||
describe("getClaudeConfigDir", () => {
|
describe("getClaudeConfigDir", () => {
|
||||||
let originalEnv: string | undefined
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
originalEnv = process.env.CLAUDE_CONFIG_DIR
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
if (originalEnv !== undefined) {
|
|
||||||
process.env.CLAUDE_CONFIG_DIR = originalEnv
|
|
||||||
} else {
|
|
||||||
delete process.env.CLAUDE_CONFIG_DIR
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns CLAUDE_CONFIG_DIR when env var is set", () => {
|
test("returns CLAUDE_CONFIG_DIR when env var is set", () => {
|
||||||
process.env.CLAUDE_CONFIG_DIR = "/custom/claude/path"
|
process.env.CLAUDE_CONFIG_DIR = "/custom/claude/path"
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,6 @@ import { tmpdir } from "node:os"
|
|||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import { discoverPluginCommandDefinitions } from "./plugin-command-discovery"
|
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 {
|
function writePluginFixture(baseDir: string): void {
|
||||||
const claudeConfigDir = join(baseDir, "claude-config")
|
const claudeConfigDir = join(baseDir, "claude-config")
|
||||||
const pluginsHome = join(claudeConfigDir, "plugins")
|
const pluginsHome = join(claudeConfigDir, "plugins")
|
||||||
@@ -94,28 +84,13 @@ Build a plan from plugin skill context.
|
|||||||
|
|
||||||
describe("plugin command discovery utility", () => {
|
describe("plugin command discovery utility", () => {
|
||||||
let tempDir = ""
|
let tempDir = ""
|
||||||
let envSnapshot: EnvSnapshot
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tempDir = mkdtempSync(join(tmpdir(), "omo-shared-plugin-discovery-test-"))
|
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)
|
writePluginFixture(tempDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
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 })
|
rmSync(tempDir, { recursive: true, force: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user