From 1bccad9c0179a2bc9b6836fc7e9f79c8fed40fc2 Mon Sep 17 00:00:00 2001 From: JATMN Date: Fri, 23 Oct 2026 14:03:21 -0700 Subject: [PATCH] test: restore thinking exports after attachment tests (#2361) --- src/utils/attachments.ultrathink.test.ts | 33 +++++++++--------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/utils/attachments.ultrathink.test.ts b/src/utils/attachments.ultrathink.test.ts index f59707489..3ce016837 100644 --- a/src/utils/attachments.ultrathink.test.ts +++ b/src/utils/attachments.ultrathink.test.ts @@ -1,24 +1,24 @@ import { afterEach, beforeEach, expect, mock, test } from 'bun:test' +import { snapshotEnv } from '../test/envSnapshot.js' import { acquireSharedMutationLock, releaseSharedMutationLock, } from '../test/sharedMutationLock.js' -import * as realThinking from './thinking.js' + +// Keep a copy: mock.module also repoints an imported module namespace. +const realThinking = { + ...await import(`./thinking.js?real=${Date.now()}-${Math.random()}`), +} let getUltrathinkEffortAttachment: typeof import('./attachments.js').getUltrathinkEffortAttachment -let savedEnv: { - disableAttachments: string | undefined - simple: string | undefined -} +let restoreEnv: () => void beforeEach(async () => { await acquireSharedMutationLock('utils/attachments.ultrathink.test.ts') - savedEnv = { - disableAttachments: process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS, - simple: process.env.CLAUDE_CODE_SIMPLE, - } - delete process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS - delete process.env.CLAUDE_CODE_SIMPLE + restoreEnv = snapshotEnv([ + 'CLAUDE_CODE_DISABLE_ATTACHMENTS', + 'CLAUDE_CODE_SIMPLE', + ], { clear: true }) mock.module('./thinking.js', () => ({ ...realThinking, isUltrathinkEnabled: () => true, @@ -30,16 +30,7 @@ beforeEach(async () => { afterEach(() => { try { - if (savedEnv.disableAttachments === undefined) { - delete process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS - } else { - process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS = savedEnv.disableAttachments - } - if (savedEnv.simple === undefined) { - delete process.env.CLAUDE_CODE_SIMPLE - } else { - process.env.CLAUDE_CODE_SIMPLE = savedEnv.simple - } + restoreEnv() mock.restore() // Bun's mock.restore() does not unregister module mocks. mock.module('./thinking.js', () => realThinking)