From 385fe8ab4eeed0ae819376bac59265f3945004fb Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Wed, 7 Oct 2026 01:04:36 -0700 Subject: [PATCH] perf(tests): avoid repeated persistence imports in automation fixtures (#26111) * perf(tests): cache Vitest module transforms between runs * test(native-chat): align resume fixture with mention menu props * perf(tests): reuse the SQLite store fixture in automation suites --- .../automation-dispatch-host-fence.test.ts | 13 +------------ .../automation-skip-coalescing.test.ts | 14 ++------------ .../automation-zero-grace-tick-latency.test.ts | 13 +------------ .../retained-run-reconciliation.test.ts | 13 +------------ .../automations/run-completion-watcher.test.ts | 12 +----------- src/main/automations/service.test.ts | 15 ++------------- 6 files changed, 8 insertions(+), 72 deletions(-) diff --git a/src/main/automations/automation-dispatch-host-fence.test.ts b/src/main/automations/automation-dispatch-host-fence.test.ts index 1f28f5accd7..2fbc3215485 100644 --- a/src/main/automations/automation-dispatch-host-fence.test.ts +++ b/src/main/automations/automation-dispatch-host-fence.test.ts @@ -21,10 +21,7 @@ import { removeTreeSync } from '../../shared/windows-transient-lock-removal' import type { Store } from '../persistence' import { resolveAutomationRunTarget } from './run-target-resolution' import { AutomationService } from './service' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' -import { closeTestStores, createSqliteTestStore } from '../persistence-test-harness' - -const testState = { dir: '' } +import { closeTestStores, createStore, testState } from '../persistence-test-harness' vi.mock('electron', () => ({ app: { @@ -37,14 +34,6 @@ vi.mock('electron', () => ({ } })) -async function createStore(): Promise { - vi.resetModules() - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store: StoreClass, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(StoreClass, { dataFile: join(testState.dir, 'orca-data.json') }) -} - /** The reachable shape: a runtime-owned id is derived, not minted per lifecycle. */ const TARGET_ID = 'runtime-ssh-recipe-1' diff --git a/src/main/automations/automation-skip-coalescing.test.ts b/src/main/automations/automation-skip-coalescing.test.ts index 089a0dab196..1de193cd9c7 100644 --- a/src/main/automations/automation-skip-coalescing.test.ts +++ b/src/main/automations/automation-skip-coalescing.test.ts @@ -15,14 +15,12 @@ import { removeTreeSync } from '../../shared/windows-transient-lock-removal' import type { Store } from '../persistence' import { closeTestStores, - createSqliteTestStore, + createStore, readPersistedStateJson, + testState, writePersistedStateJson } from '../persistence-test-harness' import { AutomationService } from './service' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' - -const testState = { dir: '' } vi.mock('electron', () => ({ app: { @@ -35,14 +33,6 @@ vi.mock('electron', () => ({ } })) -async function createStore(): Promise { - vi.resetModules() - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store: StoreClass, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(StoreClass, { dataFile: join(testState.dir, 'orca-data.json') }) -} - const makeRepo = (): Repo => ({ id: 'r1', path: '/repo', diff --git a/src/main/automations/automation-zero-grace-tick-latency.test.ts b/src/main/automations/automation-zero-grace-tick-latency.test.ts index 94020e03bef..4d434c77d68 100644 --- a/src/main/automations/automation-zero-grace-tick-latency.test.ts +++ b/src/main/automations/automation-zero-grace-tick-latency.test.ts @@ -1,13 +1,10 @@ -import { closeTestStores, createSqliteTestStore } from '../persistence-test-harness' +import { closeTestStores, createStore, testState } from '../persistence-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { mkdtempSync, rmSync } from 'node:fs' import { join } from 'node:path' import { tmpdir } from 'node:os' import type { Repo } from '../../shared/repo-types' import { AutomationService } from './service' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' - -const testState = { dir: '' } vi.mock('electron', () => ({ app: { @@ -20,14 +17,6 @@ vi.mock('electron', () => ({ } })) -async function createStore() { - vi.resetModules() - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(Store, { dataFile: join(testState.dir, 'orca-data.json') }) -} - const makeRepo = (overrides: Partial = {}): Repo => ({ id: 'r1', path: '/repo', diff --git a/src/main/automations/retained-run-reconciliation.test.ts b/src/main/automations/retained-run-reconciliation.test.ts index f8f8b6e9017..547729d2c55 100644 --- a/src/main/automations/retained-run-reconciliation.test.ts +++ b/src/main/automations/retained-run-reconciliation.test.ts @@ -1,4 +1,4 @@ -import { closeTestStores, createSqliteTestStore } from '../persistence-test-harness' +import { closeTestStores, createStore, testState } from '../persistence-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { mkdtempSync, rmSync } from 'node:fs' import { join } from 'node:path' @@ -14,9 +14,6 @@ import type { AutomationRunCompletionObservation, AutomationRunTerminalObserver } from './run-completion-watcher' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' - -const testState = { dir: '' } vi.mock('electron', () => ({ app: { getPath: () => testState.dir }, @@ -28,14 +25,6 @@ vi.mock('electron', () => ({ } })) -async function createStore() { - vi.resetModules() - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(Store, { dataFile: join(testState.dir, 'orca-data.json') }) -} - type TestStore = Awaited> const makeRepo = (): Repo => ({ diff --git a/src/main/automations/run-completion-watcher.test.ts b/src/main/automations/run-completion-watcher.test.ts index 69eb7a17201..fb1400a2886 100644 --- a/src/main/automations/run-completion-watcher.test.ts +++ b/src/main/automations/run-completion-watcher.test.ts @@ -1,4 +1,4 @@ -import { closeTestStores, createSqliteTestStore } from '../persistence-test-harness' +import { closeTestStores, createStore, testState } from '../persistence-test-harness' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { mkdtempSync, rmSync } from 'node:fs' import { join } from 'node:path' @@ -11,9 +11,7 @@ import type { AutomationRunCompletionObservation, AutomationRunTerminalObserver } from './run-completion-watcher' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' -const testState = { dir: '' } const ipcHandlers = new Map unknown>() vi.mock('electron', () => ({ @@ -32,14 +30,6 @@ vi.mock('electron', () => ({ } })) -async function createStore() { - vi.resetModules() - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(Store, { dataFile: join(testState.dir, 'orca-data.json') }) -} - const makeRepo = (overrides: Partial = {}): Repo => ({ id: 'r1', path: '/repo', diff --git a/src/main/automations/service.test.ts b/src/main/automations/service.test.ts index 77aa8b8a6f3..092c774feb6 100644 --- a/src/main/automations/service.test.ts +++ b/src/main/automations/service.test.ts @@ -1,6 +1,7 @@ import { closeTestStores, - createSqliteTestStore, + createStore, + testState, readPersistedStateJson, writePersistedStateJson } from '../persistence-test-harness' @@ -11,9 +12,6 @@ import { tmpdir } from 'node:os' import type { Repo } from '../../shared/repo-types' import { toRuntimeExecutionHostId } from '../../shared/execution-host' import { AutomationService } from './service' -import { installFakeAppEnvironment } from '../../../config/scripts/vitest-host-ports-setup' - -const testState = { dir: '' } vi.mock('electron', () => ({ app: { @@ -26,15 +24,6 @@ vi.mock('electron', () => ({ } })) -async function createStore() { - vi.resetModules() - // Why: userData resolves through AppEnvironment; point it at this file's temp dir. - installFakeAppEnvironment({ getPath: () => testState.dir }) - const { Store, initDataPath } = await import('../persistence') - initDataPath() - return createSqliteTestStore(Store, { dataFile: join(testState.dir, 'orca-data.json') }) -} - /** Simulate registry drift after a record was stored; the create path derives contexts itself. */ function mutateDataFile(mutate: (state: { automations: Record[] }) => void): void { const file = join(testState.dir, 'orca-data.json')