test(slashcommand): isolate command-loader cache between tests
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
|||||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
import { clearCommandLoaderCache } from "../../features/claude-code-command-loader"
|
||||||
import { executeSlashCommand } from "./executor"
|
import { executeSlashCommand } from "./executor"
|
||||||
|
|
||||||
const ENV_KEYS = [
|
const ENV_KEYS = [
|
||||||
@@ -95,6 +96,7 @@ describe("auto-slash command executor plugin dispatch", () => {
|
|||||||
let envSnapshot: EnvSnapshot
|
let envSnapshot: EnvSnapshot
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
tempDir = mkdtempSync(join(tmpdir(), "omo-executor-plugin-test-"))
|
tempDir = mkdtempSync(join(tmpdir(), "omo-executor-plugin-test-"))
|
||||||
envSnapshot = {
|
envSnapshot = {
|
||||||
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR,
|
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR,
|
||||||
@@ -106,6 +108,7 @@ describe("auto-slash command executor plugin dispatch", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
for (const key of ENV_KEYS) {
|
for (const key of ENV_KEYS) {
|
||||||
const previousValue = envSnapshot[key]
|
const previousValue = envSnapshot[key]
|
||||||
if (previousValue === undefined) {
|
if (previousValue === undefined) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, expect, it, beforeEach, afterEach, spyOn, mock } from "bun:te
|
|||||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
import { clearCommandLoaderCache } from "../../features/claude-code-command-loader"
|
||||||
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
|
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
|
||||||
import type {
|
import type {
|
||||||
AutoSlashCommandHookInput,
|
AutoSlashCommandHookInput,
|
||||||
@@ -43,6 +44,7 @@ describe("createAutoSlashCommandHook", () => {
|
|||||||
let createAutoSlashCommandHook: AutoSlashCommandModule["createAutoSlashCommandHook"]
|
let createAutoSlashCommandHook: AutoSlashCommandModule["createAutoSlashCommandHook"]
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
mock.restore()
|
mock.restore()
|
||||||
logCalls = []
|
logCalls = []
|
||||||
spyOn(shared, "log").mockImplementation((message: string, data?: unknown) => {
|
spyOn(shared, "log").mockImplementation((message: string, data?: unknown) => {
|
||||||
@@ -56,6 +58,7 @@ describe("createAutoSlashCommandHook", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
process.chdir(originalWorkingDirectory)
|
process.chdir(originalWorkingDirectory)
|
||||||
rmSync(tempDir, { recursive: true, force: true })
|
rmSync(tempDir, { recursive: true, force: true })
|
||||||
mock.restore()
|
mock.restore()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
|||||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
import { clearCommandLoaderCache } from "../../features/claude-code-command-loader"
|
||||||
|
|
||||||
function requireFresh<T>(modulePath: string): T {
|
function requireFresh<T>(modulePath: string): T {
|
||||||
const resolvedPath = require.resolve(modulePath)
|
const resolvedPath = require.resolve(modulePath)
|
||||||
@@ -25,12 +26,14 @@ describe("slashcommand discovery and execution compatibility", () => {
|
|||||||
let originalOpencodeConfigDir: string | undefined
|
let originalOpencodeConfigDir: string | undefined
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
tempDir = mkdtempSync(join(tmpdir(), "omo-slashcommand-compat-test-"))
|
tempDir = mkdtempSync(join(tmpdir(), "omo-slashcommand-compat-test-"))
|
||||||
originalWorkingDirectory = process.cwd()
|
originalWorkingDirectory = process.cwd()
|
||||||
originalOpencodeConfigDir = process.env.OPENCODE_CONFIG_DIR
|
originalOpencodeConfigDir = process.env.OPENCODE_CONFIG_DIR
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
clearCommandLoaderCache()
|
||||||
process.chdir(originalWorkingDirectory)
|
process.chdir(originalWorkingDirectory)
|
||||||
|
|
||||||
if (originalOpencodeConfigDir === undefined) {
|
if (originalOpencodeConfigDir === undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user