fix(test): move auto-slash-command-leak test to isolated subdirectory
mock.module('./executor') leaks across all files in the same batch because
Bun runs test files in a directory in parallel. The afterAll restore trick
doesn't work when other files load the module concurrently at startup.
Moving the leak test to its own subdirectory (leak/) ensures CI's batch
runner isolates it in a separate bun test invocation, preventing executor
mock contamination in executor-resolution.test.ts and index.test.ts.
This commit is contained in:
+7
-7
@@ -1,12 +1,12 @@
|
|||||||
import { afterAll, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
import { afterAll, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
||||||
import { AUTO_SLASH_COMMAND_TAG_OPEN } from "./constants"
|
import { AUTO_SLASH_COMMAND_TAG_OPEN } from "../constants"
|
||||||
import type {
|
import type {
|
||||||
AutoSlashCommandHookInput,
|
AutoSlashCommandHookInput,
|
||||||
AutoSlashCommandHookOutput,
|
AutoSlashCommandHookOutput,
|
||||||
CommandExecuteBeforeInput,
|
CommandExecuteBeforeInput,
|
||||||
CommandExecuteBeforeOutput,
|
CommandExecuteBeforeOutput,
|
||||||
} from "./types"
|
} from "../types"
|
||||||
import * as shared from "../../shared"
|
import * as shared from "../../../shared"
|
||||||
|
|
||||||
const executeSlashCommandMock = mock(
|
const executeSlashCommandMock = mock(
|
||||||
async (parsed: { command: string; args: string; raw: string }) => ({
|
async (parsed: { command: string; args: string; raw: string }) => ({
|
||||||
@@ -15,7 +15,7 @@ const executeSlashCommandMock = mock(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
mock.module("./executor", () => ({
|
mock.module("../executor", () => ({
|
||||||
executeSlashCommand: executeSlashCommandMock,
|
executeSlashCommand: executeSlashCommandMock,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@@ -23,13 +23,13 @@ afterAll(async () => {
|
|||||||
mock.restore()
|
mock.restore()
|
||||||
// Restore the real executor module so subsequent test files in the same batch
|
// Restore the real executor module so subsequent test files in the same batch
|
||||||
// (e.g. executor-resolution.test.ts) don't get the mocked version
|
// (e.g. executor-resolution.test.ts) don't get the mocked version
|
||||||
const realExecutor = await import("./executor")
|
const realExecutor = await import("../executor")
|
||||||
mock.module("./executor", () => realExecutor)
|
mock.module("../executor", () => realExecutor)
|
||||||
})
|
})
|
||||||
|
|
||||||
const logMock = spyOn(shared, "log").mockImplementation(() => {})
|
const logMock = spyOn(shared, "log").mockImplementation(() => {})
|
||||||
|
|
||||||
const { createAutoSlashCommandHook } = await import("./hook")
|
const { createAutoSlashCommandHook } = await import("../hook")
|
||||||
|
|
||||||
function createChatInput(sessionID: string, messageID: string): AutoSlashCommandHookInput {
|
function createChatInput(sessionID: string, messageID: string): AutoSlashCommandHookInput {
|
||||||
return {
|
return {
|
||||||
Reference in New Issue
Block a user