Skip to content

Commit 96e7b39

Browse files
code-yeongyuG-hoon
andauthored
fix: use _resetForTesting() consistently to prevent flaky tests (#1318)
- Replace setMainSession(undefined) with _resetForTesting() in keyword-detector tests - Add _resetForTesting() to afterEach hooks for proper cleanup - Un-skip the previously flaky mainSessionID test in state.test.ts Fixes #848 Co-authored-by: 배지훈 <new0126@naver.com>
1 parent bb181ee commit 96e7b39

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

bun.lock

Lines changed: 7 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks/keyword-detector/index.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("keyword-detector message transform", () => {
2121
afterEach(() => {
2222
logSpy?.mockRestore()
2323
getMainSessionSpy?.mockRestore()
24+
_resetForTesting()
2425
})
2526

2627
function createMockPluginInput() {
@@ -101,7 +102,7 @@ describe("keyword-detector session filtering", () => {
101102
let logSpy: ReturnType<typeof spyOn>
102103

103104
beforeEach(() => {
104-
setMainSession(undefined)
105+
_resetForTesting()
105106
logCalls = []
106107
logSpy = spyOn(sharedModule, "log").mockImplementation((msg: string, data?: unknown) => {
107108
logCalls.push({ msg, data })
@@ -110,7 +111,7 @@ describe("keyword-detector session filtering", () => {
110111

111112
afterEach(() => {
112113
logSpy?.mockRestore()
113-
setMainSession(undefined)
114+
_resetForTesting()
114115
})
115116

116117
function createMockPluginInput(options: { toastCalls?: string[] } = {}) {
@@ -246,7 +247,7 @@ describe("keyword-detector word boundary", () => {
246247
let logSpy: ReturnType<typeof spyOn>
247248

248249
beforeEach(() => {
249-
setMainSession(undefined)
250+
_resetForTesting()
250251
logCalls = []
251252
logSpy = spyOn(sharedModule, "log").mockImplementation((msg: string, data?: unknown) => {
252253
logCalls.push({ msg, data })
@@ -255,7 +256,7 @@ describe("keyword-detector word boundary", () => {
255256

256257
afterEach(() => {
257258
logSpy?.mockRestore()
258-
setMainSession(undefined)
259+
_resetForTesting()
259260
})
260261

261262
function createMockPluginInput(options: { toastCalls?: string[] } = {}) {
@@ -343,7 +344,7 @@ describe("keyword-detector system-reminder filtering", () => {
343344
let logSpy: ReturnType<typeof spyOn>
344345

345346
beforeEach(() => {
346-
setMainSession(undefined)
347+
_resetForTesting()
347348
logCalls = []
348349
logSpy = spyOn(sharedModule, "log").mockImplementation((msg: string, data?: unknown) => {
349350
logCalls.push({ msg, data })
@@ -352,7 +353,7 @@ describe("keyword-detector system-reminder filtering", () => {
352353

353354
afterEach(() => {
354355
logSpy?.mockRestore()
355-
setMainSession(undefined)
356+
_resetForTesting()
356357
})
357358

358359
function createMockPluginInput() {
@@ -534,7 +535,7 @@ describe("keyword-detector agent-specific ultrawork messages", () => {
534535
let logSpy: ReturnType<typeof spyOn>
535536

536537
beforeEach(() => {
537-
setMainSession(undefined)
538+
_resetForTesting()
538539
logCalls = []
539540
logSpy = spyOn(sharedModule, "log").mockImplementation((msg: string, data?: unknown) => {
540541
logCalls.push({ msg, data })
@@ -543,7 +544,7 @@ describe("keyword-detector agent-specific ultrawork messages", () => {
543544

544545
afterEach(() => {
545546
logSpy?.mockRestore()
546-
setMainSession(undefined)
547+
_resetForTesting()
547548
})
548549

549550
function createMockPluginInput() {

src/hooks/session-notification.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("session-notification", () => {
4545
afterEach(() => {
4646
// #given - cleanup after each test
4747
subagentSessions.clear()
48-
setMainSession(undefined)
48+
_resetForTesting()
4949
})
5050

5151
test("should not trigger notification for subagent session", async () => {

0 commit comments

Comments
 (0)