From 03e73982204f7c74641305ab42856161113ab15c Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 16 Sep 2026 21:27:50 +0000 Subject: [PATCH 1/8] test: reset shared mock state before each test Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- docs/guidance/vitest.md | 103 +++++++++++++++--- .../auth/__mocks__/useAuthActions.ts | 6 + src/utils/__tests__/mockStateReset.test.ts | 39 +++++++ src/utils/__tests__/mockStateReset.ts | 15 +++ src/vitestSetup.test.ts | 15 +++ vitest.setup.ts | 2 + 6 files changed, 162 insertions(+), 18 deletions(-) create mode 100644 src/utils/__tests__/mockStateReset.test.ts create mode 100644 src/utils/__tests__/mockStateReset.ts diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index ba0aba8b7dc..a3694ba24b6 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -24,8 +24,9 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. - Use `vi.hoisted()` only for bindings needed by a hoisted mock factory. Keep mutable scenario state inside the test that uses it. - Vitest automatically resets mocks, restores spies, and unstubs globals and - environment variables before each test. Do not repeat that cleanup in test - lifecycle hooks. + environment variables before each test, and `vitest.setup.ts` runs every + reset a shared mock registered with `resetBeforeEachTest`. Do not repeat + that cleanup in test lifecycle hooks. - Install `vi.stubGlobal()` and `vi.spyOn()` calls in `beforeEach` or in the test that needs them. Module-scope stubs and spies are removed before the first test runs. @@ -40,31 +41,97 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. state, or duplicate spies. - Type each complete default from the real function's return type. Preserve async and cancellation behavior. Pass the default implementation to - `vi.fn` instead of setting it in `beforeEach`. -- For composables, return fresh state from each call. If repeated calls must - share a result, create it in the test and pin it with - `vi.mocked(useX).mockReturnValue(result)`. + `vi.fn` instead of setting it in `beforeEach`; `mockReset` + restores that implementation before every test. +- A composable mock returns one stable object, so a test can configure it + and then create the consumer that reads it. Never replace a field that + holds a `ref`, `computed`, or object: a consumer that already destructured + it keeps the old one. - Do not use `mock.results` or other call history as a cache. Keep shared result identity explicit in the test that needs it. -- Assign writable fields directly. To override a readonly field on a - configurable mock object, use `vi.spyOn(flags, 'flagName', 'get')`. Vitest - also supports plain data properties; it installs a temporary getter and - restores the original property with the spy. Use `mockReturnValue` for a - fixed value or `mockImplementation` to read changing test state. - Override only the field the test needs. Do not rebuild a full result with nested spreads or add hooks that repeat the shared defaults. -For example, configure a live flag inside the test before creating its consumer: +#### Mock state that `mockReset` does not touch + +`mockReset` restores `vi.fn` implementations and call history. It does not +restore plain fields, `reactive()` objects, or `ref` values, so a test that +writes `useFeatureFlags().flags.assetsEnabled = true` leaks it into every +later test in the file unless something restores it. The mock module owns +that restore: ```ts -const enabled = ref(false) -const featureFlags = useFeatureFlags() -vi.mocked(useFeatureFlags).mockReturnValue(featureFlags) -vi.spyOn(featureFlags.flags, 'billingControlEnabled', 'get').mockImplementation( - () => enabled.value -) +import { resetBeforeEachTest } from '@/utils/__tests__/mockStateReset' + +function defaultFlags() { + return { assetsEnabled: false, maxUploadSize: 0 } +} + +const featureFlags: ReturnType = { + flags: reactive(defaultFlags()), + featureFlag: vi.fn((_, defaultValue) => computed(() => defaultValue)) +} + +resetBeforeEachTest(() => Object.assign(featureFlags.flags, defaultFlags())) + +export const useFeatureFlags = vi.fn(() => featureFlags) ``` +- Restore in place: `Object.assign(reactiveObject, defaults())` and + `someRef.value = default`. Writes through the reactive proxy notify every + consumer `computed`; replacing the object or ref does not. +- Do not call `beforeEach` inside a mock module. It binds to whichever file + is being collected, so it silently stops running when the module is cached + (`isolate: false`) or re-imported after `vi.resetModules()`. +- Test files do not repeat the reset. They configure state in `beforeEach` or + in the test, never at module scope, because the reset runs before the first + test just as it does for stubs and spies. + +#### Reactive fields: writable, derived, or derived with a mutator + +Match the real contract: + +- Writable in the contract (`flags.x`, `enableAppBuilder`): back it with + `reactive()` or `ref` in the mock and assign it in the test. When the + contract types the field `readonly` but the mock backs it with a writable + `reactive()`, write through `vi.mocked(useFeatureFlags().flags).x = true`. +- Derived in the contract with a real mutator (`mode` set by `setMode`): + derive every `computed` from one private source in the mock and implement + the mutator against it, so related fields cannot disagree. Tests drive the + state through the contract and register the source for reset: + + ```ts + const mode = ref('graph') + const appMode: ReturnType = { + mode: computed(() => mode.value), + isArrangeMode: computed(() => mode.value === 'builder:arrange'), + // …every other derived field reads `mode` the same way + setMode: vi.fn((next) => { + mode.value = next + }) + } + resetBeforeEachTest(() => { + mode.value = 'graph' + }) + ``` + +- Derived in the contract with no mutator (`isLoggedIn`, `canTopUp`): + override it in the test with `vi.spyOn(x, 'value', 'get')`. `restoreMocks` + removes the spy, so nothing is registered for reset. Use + `mockReturnValue` for a fixed value. When the value changes during the + test, use `mockImplementation(() => testRef.value)`: Vue does not track a + spy's fixed return, so a consumer `computed` caches the first read. + + ```ts + const loggedIn = ref(false) + vi.spyOn(useCurrentUser().isLoggedIn, 'value', 'get').mockImplementation( + () => loggedIn.value + ) + ``` + + Never assign `useCurrentUser().isLoggedIn = computed(() => true)`. It + leaks, and a consumer created earlier keeps the old computed. + ## No Real Network `vitest.setup.ts` blocks every `http(s)` `fetch`, and happy-dom is configured not diff --git a/src/composables/auth/__mocks__/useAuthActions.ts b/src/composables/auth/__mocks__/useAuthActions.ts index 50ea460b89f..4dc00865163 100644 --- a/src/composables/auth/__mocks__/useAuthActions.ts +++ b/src/composables/auth/__mocks__/useAuthActions.ts @@ -1,6 +1,8 @@ import { vi } from 'vitest' import { ref } from 'vue' +import { resetBeforeEachTest } from '@/utils/__tests__/mockStateReset' + import type { useAuthActions as realUseAuthActions } from '../useAuthActions' const actions: ReturnType = { @@ -19,4 +21,8 @@ const actions: ReturnType = { accessError: ref(false) } +resetBeforeEachTest(() => { + actions.accessError.value = false +}) + export const useAuthActions = vi.fn(() => actions) diff --git a/src/utils/__tests__/mockStateReset.test.ts b/src/utils/__tests__/mockStateReset.test.ts new file mode 100644 index 00000000000..4612b33ef62 --- /dev/null +++ b/src/utils/__tests__/mockStateReset.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from 'vitest' +import { computed, reactive, ref } from 'vue' + +import { resetBeforeEachTest, runMockStateResets } from './mockStateReset' + +describe('runMockStateResets', () => { + it('restores registered state in place so held references see the reset', () => { + const flags = reactive({ enabled: false, label: 'a' }) + const count = ref(0) + const derived = computed(() => (flags.enabled ? count.value : -1)) + resetBeforeEachTest(() => { + Object.assign(flags, { enabled: false, label: 'a' }) + count.value = 0 + }) + + flags.enabled = true + flags.label = 'b' + count.value = 3 + expect(derived.value).toBe(3) + + runMockStateResets() + + expect(flags).toEqual({ enabled: false, label: 'a' }) + expect(derived.value).toBe(-1) + }) + + it('registers the same reset once', () => { + let runs = 0 + const reset = () => { + runs++ + } + resetBeforeEachTest(reset) + resetBeforeEachTest(reset) + + runMockStateResets() + + expect(runs).toBe(1) + }) +}) diff --git a/src/utils/__tests__/mockStateReset.ts b/src/utils/__tests__/mockStateReset.ts new file mode 100644 index 00000000000..ebec5babecf --- /dev/null +++ b/src/utils/__tests__/mockStateReset.ts @@ -0,0 +1,15 @@ +declare global { + var __vitestMockStateResets: Set<() => void> | undefined +} + +function registry(): Set<() => void> { + return (globalThis.__vitestMockStateResets ??= new Set()) +} + +export function resetBeforeEachTest(reset: () => void): void { + registry().add(reset) +} + +export function runMockStateResets(): void { + for (const reset of registry()) reset() +} diff --git a/src/vitestSetup.test.ts b/src/vitestSetup.test.ts index 3f8534c05fa..e643fa80567 100644 --- a/src/vitestSetup.test.ts +++ b/src/vitestSetup.test.ts @@ -1,5 +1,20 @@ import { describe, expect, it, vi } from 'vitest' +import { useAuthActions } from '@/composables/auth/useAuthActions' + +vi.mock(import('@/composables/auth/useAuthActions')) + +describe.sequential('shared mock state reset', () => { + it('lets a test dirty writable mock state', () => { + useAuthActions().accessError.value = true + expect(useAuthActions().accessError.value).toBe(true) + }) + + it('restores the mock module defaults before the next test', () => { + expect(useAuthActions().accessError.value).toBe(false) + }) +}) + describe.sequential('registered LiteGraph type cleanup', () => { it('tracks a singleton registered after a module reset', async () => { vi.resetModules() diff --git a/vitest.setup.ts b/vitest.setup.ts index 7701345e9f4..8ce6960e8c5 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -5,8 +5,10 @@ import { afterEach, beforeEach, vi } from 'vitest' import 'vue' import { clearRegisteredLiteGraphTypes } from '@/lib/litegraph/src/litegraphInstance' +import { runMockStateResets } from '@/utils/__tests__/mockStateReset' beforeEach(() => { + runMockStateResets() vi.stubGlobal('__VUE_DEVTOOLS_GLOBAL_HOOK__', { emit: vi.fn() }) setActivePinia(createTestingPinia({ stubActions: false })) }) From 118a0d3d48198add3b51befd560a58652269103f Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 16 Sep 2026 21:38:30 +0000 Subject: [PATCH 2/8] test: drop registry unit test, tighten mock reset guidance Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- docs/guidance/vitest.md | 63 ++++++++++------------ src/utils/__tests__/mockStateReset.test.ts | 39 -------------- 2 files changed, 27 insertions(+), 75 deletions(-) delete mode 100644 src/utils/__tests__/mockStateReset.test.ts diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index a3694ba24b6..b62fd307410 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -54,11 +54,10 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. #### Mock state that `mockReset` does not touch -`mockReset` restores `vi.fn` implementations and call history. It does not -restore plain fields, `reactive()` objects, or `ref` values, so a test that -writes `useFeatureFlags().flags.assetsEnabled = true` leaks it into every -later test in the file unless something restores it. The mock module owns -that restore: +`mockReset` restores `vi.fn` implementations and call history, not plain +fields, `reactive()` objects, or `ref` values. A test that writes +`useFeatureFlags().flags.assetsEnabled = true` leaks it into every later test +unless the mock module registers a restore: ```ts import { resetBeforeEachTest } from '@/utils/__tests__/mockStateReset' @@ -77,35 +76,28 @@ resetBeforeEachTest(() => Object.assign(featureFlags.flags, defaultFlags())) export const useFeatureFlags = vi.fn(() => featureFlags) ``` -- Restore in place: `Object.assign(reactiveObject, defaults())` and - `someRef.value = default`. Writes through the reactive proxy notify every - consumer `computed`; replacing the object or ref does not. -- Do not call `beforeEach` inside a mock module. It binds to whichever file - is being collected, so it silently stops running when the module is cached - (`isolate: false`) or re-imported after `vi.resetModules()`. -- Test files do not repeat the reset. They configure state in `beforeEach` or - in the test, never at module scope, because the reset runs before the first - test just as it does for stubs and spies. - -#### Reactive fields: writable, derived, or derived with a mutator - -Match the real contract: - -- Writable in the contract (`flags.x`, `enableAppBuilder`): back it with - `reactive()` or `ref` in the mock and assign it in the test. When the - contract types the field `readonly` but the mock backs it with a writable - `reactive()`, write through `vi.mocked(useFeatureFlags().flags).x = true`. -- Derived in the contract with a real mutator (`mode` set by `setMode`): - derive every `computed` from one private source in the mock and implement - the mutator against it, so related fields cannot disagree. Tests drive the - state through the contract and register the source for reset: +Restore in place (`Object.assign(reactiveObject, defaults())`, +`someRef.value = default`) so consumer `computed`s are notified. Do not call +`beforeEach` inside a mock module: it binds to the file being collected and +stops running once the module is cached or re-imported after +`vi.resetModules()`. Test files configure state in `beforeEach` or in the +test, never at module scope, because the reset runs before the first test. + +#### Reactive fields: match the real contract + +- Writable (`flags.x`, `enableAppBuilder`): back it with `reactive()` or + `ref` and assign it in the test. When the contract types it `readonly`, + write through `vi.mocked(useFeatureFlags().flags).x = true`. +- Derived with a real mutator (`mode` set by `setMode`): derive every + `computed` from one private source and implement the mutator against it, so + related fields cannot disagree. Tests call the mutator; the mock registers + the source for reset: ```ts const mode = ref('graph') const appMode: ReturnType = { mode: computed(() => mode.value), isArrangeMode: computed(() => mode.value === 'builder:arrange'), - // …every other derived field reads `mode` the same way setMode: vi.fn((next) => { mode.value = next }) @@ -115,12 +107,11 @@ Match the real contract: }) ``` -- Derived in the contract with no mutator (`isLoggedIn`, `canTopUp`): - override it in the test with `vi.spyOn(x, 'value', 'get')`. `restoreMocks` - removes the spy, so nothing is registered for reset. Use - `mockReturnValue` for a fixed value. When the value changes during the - test, use `mockImplementation(() => testRef.value)`: Vue does not track a - spy's fixed return, so a consumer `computed` caches the first read. +- Derived with no mutator (`isLoggedIn`, `canTopUp`): spy on the getter in + the test; `restoreMocks` removes it. Use `mockReturnValue` for a fixed + value. When the value changes mid-test, read a `ref` inside + `mockImplementation`, because Vue does not track a spy's fixed return and + a consumer `computed` caches the first read: ```ts const loggedIn = ref(false) @@ -129,8 +120,8 @@ Match the real contract: ) ``` - Never assign `useCurrentUser().isLoggedIn = computed(() => true)`. It - leaks, and a consumer created earlier keeps the old computed. +Never assign `useCurrentUser().isLoggedIn = computed(() => true)`: it leaks, +and a consumer created earlier keeps the old computed. ## No Real Network diff --git a/src/utils/__tests__/mockStateReset.test.ts b/src/utils/__tests__/mockStateReset.test.ts deleted file mode 100644 index 4612b33ef62..00000000000 --- a/src/utils/__tests__/mockStateReset.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { computed, reactive, ref } from 'vue' - -import { resetBeforeEachTest, runMockStateResets } from './mockStateReset' - -describe('runMockStateResets', () => { - it('restores registered state in place so held references see the reset', () => { - const flags = reactive({ enabled: false, label: 'a' }) - const count = ref(0) - const derived = computed(() => (flags.enabled ? count.value : -1)) - resetBeforeEachTest(() => { - Object.assign(flags, { enabled: false, label: 'a' }) - count.value = 0 - }) - - flags.enabled = true - flags.label = 'b' - count.value = 3 - expect(derived.value).toBe(3) - - runMockStateResets() - - expect(flags).toEqual({ enabled: false, label: 'a' }) - expect(derived.value).toBe(-1) - }) - - it('registers the same reset once', () => { - let runs = 0 - const reset = () => { - runs++ - } - resetBeforeEachTest(reset) - resetBeforeEachTest(reset) - - runMockStateResets() - - expect(runs).toBe(1) - }) -}) From 8d4c07fea102dd8e3d67207fdb905f6801dbc114 Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 16 Sep 2026 21:56:34 +0000 Subject: [PATCH 3/8] test: cover mock state reset across vi.resetModules Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- docs/guidance/vitest.md | 9 +++++---- src/vitestSetup.test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index b62fd307410..dcf297759f2 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -78,10 +78,11 @@ export const useFeatureFlags = vi.fn(() => featureFlags) Restore in place (`Object.assign(reactiveObject, defaults())`, `someRef.value = default`) so consumer `computed`s are notified. Do not call -`beforeEach` inside a mock module: it binds to the file being collected and -stops running once the module is cached or re-imported after -`vi.resetModules()`. Test files configure state in `beforeEach` or in the -test, never at module scope, because the reset runs before the first test. +`beforeEach` inside a mock module: it binds to the file being collected, so a +cached module (`isolate: false`) registers no hook for later files, and a +re-import after `vi.resetModules()` registers a duplicate. Test files +configure state in `beforeEach` or in the test, never at module scope, +because the reset runs before the first test. #### Reactive fields: match the real contract diff --git a/src/vitestSetup.test.ts b/src/vitestSetup.test.ts index e643fa80567..efad568a31d 100644 --- a/src/vitestSetup.test.ts +++ b/src/vitestSetup.test.ts @@ -13,6 +13,18 @@ describe.sequential('shared mock state reset', () => { it('restores the mock module defaults before the next test', () => { expect(useAuthActions().accessError.value).toBe(false) }) + + it('lets a test dirty a mock re-evaluated after a module reset', async () => { + vi.resetModules() + const fresh = await import('@/composables/auth/useAuthActions') + expect(fresh.useAuthActions()).not.toBe(useAuthActions()) + fresh.useAuthActions().accessError.value = true + }) + + it('restores the re-evaluated mock before the next test', async () => { + const fresh = await import('@/composables/auth/useAuthActions') + expect(fresh.useAuthActions().accessError.value).toBe(false) + }) }) describe.sequential('registered LiteGraph type cleanup', () => { From bba760be5438cc15a08489f83b474e05366852c8 Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 16 Sep 2026 22:43:21 +0000 Subject: [PATCH 4/8] test: restore shared mock state with onTestFinished Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- docs/guidance/vitest.md | 38 +++++++++++-------- .../auth/__mocks__/useAuthActions.ts | 13 +++---- src/utils/__tests__/mockStateReset.ts | 15 -------- src/vitestSetup.test.ts | 12 ------ vitest.setup.ts | 2 - 5 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 src/utils/__tests__/mockStateReset.ts diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index dcf297759f2..a908e3a34a5 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -24,9 +24,9 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. - Use `vi.hoisted()` only for bindings needed by a hoisted mock factory. Keep mutable scenario state inside the test that uses it. - Vitest automatically resets mocks, restores spies, and unstubs globals and - environment variables before each test, and `vitest.setup.ts` runs every - reset a shared mock registered with `resetBeforeEachTest`. Do not repeat - that cleanup in test lifecycle hooks. + environment variables before each test, and shared mocks restore their own + reactive state with `onTestFinished`. Do not repeat that cleanup in test + lifecycle hooks. - Install `vi.stubGlobal()` and `vi.spyOn()` calls in `beforeEach` or in the test that needs them. Module-scope stubs and spies are removed before the first test runs. @@ -57,10 +57,11 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. `mockReset` restores `vi.fn` implementations and call history, not plain fields, `reactive()` objects, or `ref` values. A test that writes `useFeatureFlags().flags.assetsEnabled = true` leaks it into every later test -unless the mock module registers a restore: +unless the mock restores it. Register the restore with `onTestFinished` inside +the mock function, so every test that touches the mock cleans up after itself: ```ts -import { resetBeforeEachTest } from '@/utils/__tests__/mockStateReset' +import { onTestFinished, vi } from 'vitest' function defaultFlags() { return { assetsEnabled: false, maxUploadSize: 0 } @@ -71,18 +72,22 @@ const featureFlags: ReturnType = { featureFlag: vi.fn((_, defaultValue) => computed(() => defaultValue)) } -resetBeforeEachTest(() => Object.assign(featureFlags.flags, defaultFlags())) - -export const useFeatureFlags = vi.fn(() => featureFlags) +export const useFeatureFlags = vi.fn(() => { + onTestFinished(() => Object.assign(featureFlags.flags, defaultFlags())) + return featureFlags +}) ``` Restore in place (`Object.assign(reactiveObject, defaults())`, `someRef.value = default`) so consumer `computed`s are notified. Do not call `beforeEach` inside a mock module: it binds to the file being collected, so a cached module (`isolate: false`) registers no hook for later files, and a -re-import after `vi.resetModules()` registers a duplicate. Test files -configure state in `beforeEach` or in the test, never at module scope, -because the reset runs before the first test. +re-import after `vi.resetModules()` registers a duplicate. + +`onTestFinished` throws `Hook onTestFinished() can only be called inside a +test` when the mock is called at `describe` scope or in `beforeAll`. That is +intended: configure mock state in `beforeEach` or in the test, where the +cleanup can be attached to the test that dirtied it. #### Reactive fields: match the real contract @@ -91,8 +96,8 @@ because the reset runs before the first test. write through `vi.mocked(useFeatureFlags().flags).x = true`. - Derived with a real mutator (`mode` set by `setMode`): derive every `computed` from one private source and implement the mutator against it, so - related fields cannot disagree. Tests call the mutator; the mock registers - the source for reset: + related fields cannot disagree. Tests call the mutator; the mock restores + the source: ```ts const mode = ref('graph') @@ -103,8 +108,11 @@ because the reset runs before the first test. mode.value = next }) } - resetBeforeEachTest(() => { - mode.value = 'graph' + export const useAppMode = vi.fn(() => { + onTestFinished(() => { + mode.value = 'graph' + }) + return appMode }) ``` diff --git a/src/composables/auth/__mocks__/useAuthActions.ts b/src/composables/auth/__mocks__/useAuthActions.ts index 4dc00865163..f8adcd834c8 100644 --- a/src/composables/auth/__mocks__/useAuthActions.ts +++ b/src/composables/auth/__mocks__/useAuthActions.ts @@ -1,8 +1,6 @@ -import { vi } from 'vitest' +import { onTestFinished, vi } from 'vitest' import { ref } from 'vue' -import { resetBeforeEachTest } from '@/utils/__tests__/mockStateReset' - import type { useAuthActions as realUseAuthActions } from '../useAuthActions' const actions: ReturnType = { @@ -21,8 +19,9 @@ const actions: ReturnType = { accessError: ref(false) } -resetBeforeEachTest(() => { - actions.accessError.value = false +export const useAuthActions = vi.fn(() => { + onTestFinished(() => { + actions.accessError.value = false + }) + return actions }) - -export const useAuthActions = vi.fn(() => actions) diff --git a/src/utils/__tests__/mockStateReset.ts b/src/utils/__tests__/mockStateReset.ts deleted file mode 100644 index ebec5babecf..00000000000 --- a/src/utils/__tests__/mockStateReset.ts +++ /dev/null @@ -1,15 +0,0 @@ -declare global { - var __vitestMockStateResets: Set<() => void> | undefined -} - -function registry(): Set<() => void> { - return (globalThis.__vitestMockStateResets ??= new Set()) -} - -export function resetBeforeEachTest(reset: () => void): void { - registry().add(reset) -} - -export function runMockStateResets(): void { - for (const reset of registry()) reset() -} diff --git a/src/vitestSetup.test.ts b/src/vitestSetup.test.ts index efad568a31d..e643fa80567 100644 --- a/src/vitestSetup.test.ts +++ b/src/vitestSetup.test.ts @@ -13,18 +13,6 @@ describe.sequential('shared mock state reset', () => { it('restores the mock module defaults before the next test', () => { expect(useAuthActions().accessError.value).toBe(false) }) - - it('lets a test dirty a mock re-evaluated after a module reset', async () => { - vi.resetModules() - const fresh = await import('@/composables/auth/useAuthActions') - expect(fresh.useAuthActions()).not.toBe(useAuthActions()) - fresh.useAuthActions().accessError.value = true - }) - - it('restores the re-evaluated mock before the next test', async () => { - const fresh = await import('@/composables/auth/useAuthActions') - expect(fresh.useAuthActions().accessError.value).toBe(false) - }) }) describe.sequential('registered LiteGraph type cleanup', () => { diff --git a/vitest.setup.ts b/vitest.setup.ts index 8ce6960e8c5..7701345e9f4 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -5,10 +5,8 @@ import { afterEach, beforeEach, vi } from 'vitest' import 'vue' import { clearRegisteredLiteGraphTypes } from '@/lib/litegraph/src/litegraphInstance' -import { runMockStateResets } from '@/utils/__tests__/mockStateReset' beforeEach(() => { - runMockStateResets() vi.stubGlobal('__VUE_DEVTOOLS_GLOBAL_HOOK__', { emit: vi.fn() }) setActivePinia(createTestingPinia({ stubActions: false })) }) From 1c431becdf5a27eb1f3eeeefee735a4c0b18c3e7 Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 16 Sep 2026 23:31:18 +0000 Subject: [PATCH 5/8] docs: note concurrency limit and interim mockReturnValue pinning Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- docs/guidance/vitest.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index a908e3a34a5..7e5d947daa9 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -46,7 +46,11 @@ ESLint rule enforces the Testing Library query rule. Do not disable it. - A composable mock returns one stable object, so a test can configure it and then create the consumer that reads it. Never replace a field that holds a `ref`, `computed`, or object: a consumer that already destructured - it keeps the old one. + it keeps the old one. Because that object is shared by every test in the + file, tests that configure it must not run with `test.concurrent`. +- Until an older mock that builds a fresh object per call (`useBillingContext`) + is converted, pin it in the test with + `vi.mocked(useX).mockReturnValue(useX())` before configuring the result. - Do not use `mock.results` or other call history as a cache. Keep shared result identity explicit in the test that needs it. - Override only the field the test needs. Do not rebuild a full result with From a702fd1304f763ee258396da8954d218d1a78f06 Mon Sep 17 00:00:00 2001 From: Amp Date: Thu, 17 Sep 2026 00:39:44 +0000 Subject: [PATCH 6/8] test: drop mock-specific reset test from setup suite Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac08-0e1b-706f-b479-939fc9a702da --- src/vitestSetup.test.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/vitestSetup.test.ts b/src/vitestSetup.test.ts index e643fa80567..3f8534c05fa 100644 --- a/src/vitestSetup.test.ts +++ b/src/vitestSetup.test.ts @@ -1,20 +1,5 @@ import { describe, expect, it, vi } from 'vitest' -import { useAuthActions } from '@/composables/auth/useAuthActions' - -vi.mock(import('@/composables/auth/useAuthActions')) - -describe.sequential('shared mock state reset', () => { - it('lets a test dirty writable mock state', () => { - useAuthActions().accessError.value = true - expect(useAuthActions().accessError.value).toBe(true) - }) - - it('restores the mock module defaults before the next test', () => { - expect(useAuthActions().accessError.value).toBe(false) - }) -}) - describe.sequential('registered LiteGraph type cleanup', () => { it('tracks a singleton registered after a module reset', async () => { vi.resetModules() From 2b089b93920d4a40a5167d30d57a359a9ebe4675 Mon Sep 17 00:00:00 2001 From: Amp Date: Thu, 17 Sep 2026 01:06:21 +0000 Subject: [PATCH 7/8] test: restore feature flag mock state with onTestFinished --- docs/guidance/vitest.md | 10 ++++++--- .../tabs/ModelLibrarySidebarTab.test.ts | 1 - src/composables/__mocks__/useFeatureFlags.ts | 21 ++++++++++++++----- .../billing/useBillingRouting.test.ts | 1 - src/composables/useCoreCommands.test.ts | 1 - .../useWorkflowActionsMenu.test.ts | 1 - .../components/AssetBrowserModal.test.ts | 1 - .../composables/useAssetBrowser.test.ts | 1 - .../assets/services/assetService.test.ts | 1 - .../assets/utils/assetPreviewUtil.test.ts | 1 - .../assets/utils/assetUrlUtil.test.ts | 4 ---- .../utils/resolveModelNodeFromAsset.test.ts | 1 - .../usePaymentReturnUrlLoader.test.ts | 1 - .../composables/useSubscriptionDialog.test.ts | 1 - .../settings/composables/useSettingUI.test.ts | 2 -- .../ShareWorkflowDialogContent.test.ts | 1 - .../workspace/auth/WorkspaceAuthGate.test.ts | 1 - .../workspace/stores/useWorkspaceAuth.test.ts | 1 - .../__tests__/authTokenPriority.test.ts | 1 - src/stores/authStore.test.ts | 2 -- src/stores/workspace/sidebarTabStore.test.ts | 1 - 21 files changed, 23 insertions(+), 32 deletions(-) diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index 7e5d947daa9..185bf038b9c 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -67,8 +67,10 @@ the mock function, so every test that touches the mock cleans up after itself: ```ts import { onTestFinished, vi } from 'vitest' -function defaultFlags() { - return { assetsEnabled: false, maxUploadSize: 0 } +type FeatureFlags = ReturnType['flags'] + +function defaultFlags(): FeatureFlags { + return { assetsEnabled: false, hostedBillingDestination: 'stripe' } } const featureFlags: ReturnType = { @@ -77,7 +79,9 @@ const featureFlags: ReturnType = { } export const useFeatureFlags = vi.fn(() => { - onTestFinished(() => Object.assign(featureFlags.flags, defaultFlags())) + onTestFinished(() => { + Object.assign(featureFlags.flags, defaultFlags()) + }) return featureFlags }) ``` diff --git a/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts b/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts index c6821f1e2e2..3c7a08c776e 100644 --- a/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts +++ b/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts @@ -163,7 +163,6 @@ const i18n = createI18n({ describe('ModelLibrarySidebarTab', () => { beforeEach(() => { - vi.mocked(useFeatureFlags().flags).assetsEnabled = false resetRoot() useAssetDownloadStore().lastCompletedDownload = null useSettingStore().settingValues['Comfy.ModelLibrary.AutoLoadAll'] = false diff --git a/src/composables/__mocks__/useFeatureFlags.ts b/src/composables/__mocks__/useFeatureFlags.ts index 629bf29c34b..1e9a2881521 100644 --- a/src/composables/__mocks__/useFeatureFlags.ts +++ b/src/composables/__mocks__/useFeatureFlags.ts @@ -1,12 +1,14 @@ -import { vi } from 'vitest' +import { onTestFinished, vi } from 'vitest' import { computed, reactive, watchEffect } from 'vue' import type { useFeatureFlags as realUseFeatureFlags } from '../useFeatureFlags' export const startFeatureFlagTelemetry = vi.fn(() => watchEffect(() => {})) -const featureFlags: ReturnType = { - flags: reactive({ +type FeatureFlags = ReturnType['flags'] + +function defaultFlags(): FeatureFlags { + return { supportsPreviewMetadata: false, maxUploadSize: 0, supportsManagerV4: false, @@ -40,8 +42,17 @@ const featureFlags: ReturnType = { supportsModelTypeTags: false, onboardingTourEnabled: false, assetsEnabled: false - }), + } +} + +const featureFlags: ReturnType = { + flags: reactive(defaultFlags()), featureFlag: vi.fn((_, defaultValue) => computed(() => defaultValue)) } -export const useFeatureFlags = vi.fn(() => featureFlags) +export const useFeatureFlags = vi.fn(() => { + onTestFinished(() => { + Object.assign(featureFlags.flags, defaultFlags()) + }) + return featureFlags +}) diff --git a/src/composables/billing/useBillingRouting.test.ts b/src/composables/billing/useBillingRouting.test.ts index 5133b0825f9..0dad8bef91b 100644 --- a/src/composables/billing/useBillingRouting.test.ts +++ b/src/composables/billing/useBillingRouting.test.ts @@ -32,7 +32,6 @@ const team = fromPartial< describe('useBillingRouting', () => { beforeEach(() => { - vi.mocked(useFeatureFlags().flags).legacyBillingMigrationEnabled = false const refs = storeToRefs(useTeamWorkspaceStore()) mockActiveWorkspace = refs.activeWorkspace mockActiveWorkspaceBillingRail = refs.activeWorkspaceBillingRail diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 9fec17e84dd..1d63dad08e3 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -242,7 +242,6 @@ describe('useCoreCommands', () => { const mockSubgraph = createMockSubgraph()! beforeEach(() => { - vi.mocked(useFeatureFlags().flags).assetsEnabled = false mockWorkflowStore = useWorkflowStore() mockWorkflowStore.activeWorkflow = fromPartial< NonNullable diff --git a/src/composables/useWorkflowActionsMenu.test.ts b/src/composables/useWorkflowActionsMenu.test.ts index e56bf0e6527..7a7e6e39f85 100644 --- a/src/composables/useWorkflowActionsMenu.test.ts +++ b/src/composables/useWorkflowActionsMenu.test.ts @@ -87,7 +87,6 @@ function findItem(items: MenuItems, label: string): WorkflowMenuAction { describe('useWorkflowActionsMenu', () => { beforeEach(() => { - vi.mocked(useFeatureFlags().flags).linearToggleEnabled = false mockBookmarkStore = useWorkflowBookmarkStore() mockWorkflowStore = useWorkflowStore() mockCommandStore = useCommandStore() diff --git a/src/platform/assets/components/AssetBrowserModal.test.ts b/src/platform/assets/components/AssetBrowserModal.test.ts index b42e8de306e..c1043031471 100644 --- a/src/platform/assets/components/AssetBrowserModal.test.ts +++ b/src/platform/assets/components/AssetBrowserModal.test.ts @@ -127,7 +127,6 @@ const flushPromises = () => new Promise((resolve) => setTimeout(resolve, 0)) beforeEach(() => { - vi.mocked(useFeatureFlags().flags).supportsModelTypeTags = false vi.mocked(useModelToNodeStore().getCategoryForNodeType).mockImplementation( () => 'checkpoints' ) diff --git a/src/platform/assets/composables/useAssetBrowser.test.ts b/src/platform/assets/composables/useAssetBrowser.test.ts index 7c9262dc6a5..9513dd85b71 100644 --- a/src/platform/assets/composables/useAssetBrowser.test.ts +++ b/src/platform/assets/composables/useAssetBrowser.test.ts @@ -29,7 +29,6 @@ function useAssetBrowser(...args: Parameters) { afterEach(() => { apps.splice(0).forEach((app) => app.unmount()) - vi.mocked(useFeatureFlags().flags).supportsModelTypeTags = false }) describe('useAssetBrowser', () => { diff --git a/src/platform/assets/services/assetService.test.ts b/src/platform/assets/services/assetService.test.ts index 8c3c18a0f17..069c2440ddb 100644 --- a/src/platform/assets/services/assetService.test.ts +++ b/src/platform/assets/services/assetService.test.ts @@ -88,7 +88,6 @@ function validAsset(overrides: Partial = {}): AssetItem { } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).supportsModelTypeTags = false const registeredNodeTypes: Record = { CheckpointLoaderSimple: 'ckpt_name', LoraLoader: 'lora_name' diff --git a/src/platform/assets/utils/assetPreviewUtil.test.ts b/src/platform/assets/utils/assetPreviewUtil.test.ts index 70275406182..8db1f70f025 100644 --- a/src/platform/assets/utils/assetPreviewUtil.test.ts +++ b/src/platform/assets/utils/assetPreviewUtil.test.ts @@ -79,7 +79,6 @@ const localAssetWithPreview = { } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).assetsEnabled = false vi.spyOn(useAssetsStore().outputAssets, 'invalidate').mockImplementation( mockInvalidateOutputAssets ) diff --git a/src/platform/assets/utils/assetUrlUtil.test.ts b/src/platform/assets/utils/assetUrlUtil.test.ts index bb000de6842..c313ce4b8f2 100644 --- a/src/platform/assets/utils/assetUrlUtil.test.ts +++ b/src/platform/assets/utils/assetUrlUtil.test.ts @@ -131,10 +131,6 @@ describe('getAssetFileUrl', () => { }) describe('with history-backed assets', () => { - beforeEach(() => { - vi.mocked(useFeatureFlags().flags).assetsEnabled = false - }) - it('uses preview_url, which already points at the file', () => { const asset = createAsset({ preview_url: '/api/view?filename=clip.webm&type=output&subfolder=vid' diff --git a/src/platform/assets/utils/resolveModelNodeFromAsset.test.ts b/src/platform/assets/utils/resolveModelNodeFromAsset.test.ts index 48e06092201..8124c85286b 100644 --- a/src/platform/assets/utils/resolveModelNodeFromAsset.test.ts +++ b/src/platform/assets/utils/resolveModelNodeFromAsset.test.ts @@ -46,7 +46,6 @@ function mockProvider( } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).supportsModelTypeTags = false vi.mocked(useModelToNodeStore().getNodeProvider).mockImplementation( mockGetNodeProvider ) diff --git a/src/platform/cloud/subscription/composables/usePaymentReturnUrlLoader.test.ts b/src/platform/cloud/subscription/composables/usePaymentReturnUrlLoader.test.ts index 5cc72f16adf..9978265ed8a 100644 --- a/src/platform/cloud/subscription/composables/usePaymentReturnUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/usePaymentReturnUrlLoader.test.ts @@ -11,7 +11,6 @@ vi.mock(import('@/composables/billing/useBillingContext')) vi.mock(import('@/composables/useFeatureFlags')) describe('usePaymentReturnUrlLoader', () => { beforeEach(() => { - vi.mocked(useFeatureFlags().flags).embeddedCheckoutEnabled = false window.history.replaceState({}, '', '/') }) diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index d52ca868eae..29a0a8eb9fb 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -124,7 +124,6 @@ function expectRekaPricingDialogProps( } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).embeddedCheckoutEnabled = false Object.assign(useAuthStore(), { userId: 'user-1' }) vi.mocked(useDialogStore().closeDialog).mockImplementation(mockCloseDialog) diff --git a/src/platform/settings/composables/useSettingUI.test.ts b/src/platform/settings/composables/useSettingUI.test.ts index e024b0979e6..af6348d641c 100644 --- a/src/platform/settings/composables/useSettingUI.test.ts +++ b/src/platform/settings/composables/useSettingUI.test.ts @@ -93,8 +93,6 @@ function useSettingUI( } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).partnerNodeGovernanceEnabled = false - vi.mocked(useFeatureFlags().flags).userSecretsEnabled = false vi.spyOn(usePartnerNodeGovernanceStore(), 'status', 'get').mockImplementation( () => { return env.state.partnerNodeGovernanceStatus diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 0d701c39ebb..1971462be8e 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -132,7 +132,6 @@ describe('ShareWorkflowDialogContent', () => { const onClose = vi.fn() beforeEach(() => { - vi.mocked(useFeatureFlags().flags).comfyHubUploadEnabled = false vi.mocked(useFeatureFlags().flags).comfyHubProfileGateEnabled = true Object.assign(useWorkflowStore(), { activeWorkflow: { diff --git a/src/platform/workspace/auth/WorkspaceAuthGate.test.ts b/src/platform/workspace/auth/WorkspaceAuthGate.test.ts index 5356b96332e..0d17febbd5a 100644 --- a/src/platform/workspace/auth/WorkspaceAuthGate.test.ts +++ b/src/platform/workspace/auth/WorkspaceAuthGate.test.ts @@ -25,7 +25,6 @@ import WorkspaceAuthGate from './WorkspaceAuthGate.vue' vi.mock(import('firebase/auth'), { spy: true }) beforeEach(() => { - vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false vi.mocked(setPersistence).mockResolvedValue(undefined) vi.mocked(onAuthStateChanged).mockImplementation(vi.fn()) vi.mocked(onIdTokenChanged).mockImplementation(vi.fn()) diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index 40bec6a5394..c036c2ebb45 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -113,7 +113,6 @@ function expectedExpiresAtMs(expiresAt: string): string { } beforeEach(() => { - vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false vi.mocked(setPersistence).mockResolvedValue(undefined) vi.mocked(onAuthStateChanged).mockImplementation(vi.fn()) vi.mocked(onIdTokenChanged).mockImplementation(vi.fn()) diff --git a/src/stores/__tests__/authTokenPriority.test.ts b/src/stores/__tests__/authTokenPriority.test.ts index c76e308a85b..1d47624c4b8 100644 --- a/src/stores/__tests__/authTokenPriority.test.ts +++ b/src/stores/__tests__/authTokenPriority.test.ts @@ -45,7 +45,6 @@ describe('auth token priority chain', () => { } as Partial as MockUser beforeEach(() => { - vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false mockDistributionTypes.isCloud = true vi.mocked(vuefire.useFirebaseAuth).mockReturnValue( mockAuth as unknown as ReturnType diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index 651e399a85d..867c581cc43 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -120,7 +120,6 @@ describe('useAuthStore', () => { } as Partial as MockUser beforeEach(() => { - vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false mockResetSocket = vi.spyOn(api, 'resetSocket').mockResolvedValue(undefined) vi.stubGlobal('fetch', mockFetch) clearPreservedQuery(PRESERVED_QUERY_NAMESPACES.SHARE_AUTH) @@ -2346,7 +2345,6 @@ describe('useAuthStore in local/desktop distribution', () => { } as Partial as MockUser beforeEach(() => { - vi.mocked(useFeatureFlags().flags).unifiedCloudAuthEnabled = false mockDistributionTypes.isCloud = false mockDistributionTypes.isDesktop = false mockDistributionTypes.DISTRIBUTION = 'localhost' diff --git a/src/stores/workspace/sidebarTabStore.test.ts b/src/stores/workspace/sidebarTabStore.test.ts index fa33808bcbd..e6522deef1d 100644 --- a/src/stores/workspace/sidebarTabStore.test.ts +++ b/src/stores/workspace/sidebarTabStore.test.ts @@ -84,7 +84,6 @@ vi.mock( describe('useSidebarTabStore', () => { beforeEach(() => { - vi.mocked(useFeatureFlags().flags).assetsEnabled = false vi.mocked(useMenuItemStore().registerCommands).mockImplementation(() => {}) mockOpenModelLibraryBrowser.mockClear() }) From 6c33c905d599114eb7f0f2b81ab08b5594adb610 Mon Sep 17 00:00:00 2001 From: Amp Date: Thu, 17 Sep 2026 01:16:14 +0000 Subject: [PATCH 8/8] test: use a readonly constant for feature flag mock defaults --- docs/guidance/vitest.md | 11 +-- src/composables/__mocks__/useFeatureFlags.ts | 74 ++++++++++---------- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/docs/guidance/vitest.md b/docs/guidance/vitest.md index 185bf038b9c..45c1a7a5824 100644 --- a/docs/guidance/vitest.md +++ b/docs/guidance/vitest.md @@ -69,24 +69,25 @@ import { onTestFinished, vi } from 'vitest' type FeatureFlags = ReturnType['flags'] -function defaultFlags(): FeatureFlags { - return { assetsEnabled: false, hostedBillingDestination: 'stripe' } +const defaultFlags: FeatureFlags = { + assetsEnabled: false, + hostedBillingDestination: 'stripe' } const featureFlags: ReturnType = { - flags: reactive(defaultFlags()), + flags: reactive({ ...defaultFlags }), featureFlag: vi.fn((_, defaultValue) => computed(() => defaultValue)) } export const useFeatureFlags = vi.fn(() => { onTestFinished(() => { - Object.assign(featureFlags.flags, defaultFlags()) + Object.assign(featureFlags.flags, defaultFlags) }) return featureFlags }) ``` -Restore in place (`Object.assign(reactiveObject, defaults())`, +Restore in place (`Object.assign(reactiveObject, defaults)`, `someRef.value = default`) so consumer `computed`s are notified. Do not call `beforeEach` inside a mock module: it binds to the file being collected, so a cached module (`isolate: false`) registers no hook for later files, and a diff --git a/src/composables/__mocks__/useFeatureFlags.ts b/src/composables/__mocks__/useFeatureFlags.ts index 1e9a2881521..d81f52cc587 100644 --- a/src/composables/__mocks__/useFeatureFlags.ts +++ b/src/composables/__mocks__/useFeatureFlags.ts @@ -7,52 +7,50 @@ export const startFeatureFlagTelemetry = vi.fn(() => watchEffect(() => {})) type FeatureFlags = ReturnType['flags'] -function defaultFlags(): FeatureFlags { - return { - supportsPreviewMetadata: false, - maxUploadSize: 0, - supportsManagerV4: false, - modelUploadButtonEnabled: false, - assetDeletionEnabled: false, - assetRenameEnabled: false, - privateModelsEnabled: false, - onboardingSurveyEnabled: false, - linearToggleEnabled: false, - partnerNodeGovernanceEnabled: false, - partnerRunGateEnabled: false, - userSecretsEnabled: false, - nodeReplacementsEnabled: false, - nodeLibraryEssentialsEnabled: false, - workflowSharingEnabled: false, - comfyHubUploadEnabled: false, - comfyHubProfileGateEnabled: false, - hostedBillingDestination: 'stripe', - hostedBillingWebEnabled: false, - showSignInButton: undefined, - unifiedCloudAuthEnabled: false, - billingControlEnabled: false, - legacyBillingMigrationEnabled: false, - embeddedCheckoutEnabled: false, - billingSdkTopupEnabled: false, - billingSdkTopupRailEnabled: false, - v1PaymentRecovery: false, - freeTierJobAllowanceEnabled: false, - churnkeyAppId: '', - signupTurnstileMode: 'off', - supportsModelTypeTags: false, - onboardingTourEnabled: false, - assetsEnabled: false - } +const defaultFlags: FeatureFlags = { + supportsPreviewMetadata: false, + maxUploadSize: 0, + supportsManagerV4: false, + modelUploadButtonEnabled: false, + assetDeletionEnabled: false, + assetRenameEnabled: false, + privateModelsEnabled: false, + onboardingSurveyEnabled: false, + linearToggleEnabled: false, + partnerNodeGovernanceEnabled: false, + partnerRunGateEnabled: false, + userSecretsEnabled: false, + nodeReplacementsEnabled: false, + nodeLibraryEssentialsEnabled: false, + workflowSharingEnabled: false, + comfyHubUploadEnabled: false, + comfyHubProfileGateEnabled: false, + hostedBillingDestination: 'stripe', + hostedBillingWebEnabled: false, + showSignInButton: undefined, + unifiedCloudAuthEnabled: false, + billingControlEnabled: false, + legacyBillingMigrationEnabled: false, + embeddedCheckoutEnabled: false, + billingSdkTopupEnabled: false, + billingSdkTopupRailEnabled: false, + v1PaymentRecovery: false, + freeTierJobAllowanceEnabled: false, + churnkeyAppId: '', + signupTurnstileMode: 'off', + supportsModelTypeTags: false, + onboardingTourEnabled: false, + assetsEnabled: false } const featureFlags: ReturnType = { - flags: reactive(defaultFlags()), + flags: reactive({ ...defaultFlags }), featureFlag: vi.fn((_, defaultValue) => computed(() => defaultValue)) } export const useFeatureFlags = vi.fn(() => { onTestFinished(() => { - Object.assign(featureFlags.flags, defaultFlags()) + Object.assign(featureFlags.flags, defaultFlags) }) return featureFlags })