mirror of
https://github.com/stablyai/orca.git
synced 2026-10-09 00:02:39 +00:00
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
This commit is contained in:
@@ -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<Store> {
|
||||
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'
|
||||
|
||||
|
||||
@@ -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<Store> {
|
||||
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',
|
||||
|
||||
@@ -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> = {}): Repo => ({
|
||||
id: 'r1',
|
||||
path: '/repo',
|
||||
|
||||
@@ -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<ReturnType<typeof createStore>>
|
||||
|
||||
const makeRepo = (): Repo => ({
|
||||
|
||||
@@ -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<string, (event: unknown, args: unknown) => 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> = {}): Repo => ({
|
||||
id: 'r1',
|
||||
path: '/repo',
|
||||
|
||||
@@ -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<string, unknown>[] }) => void): void {
|
||||
const file = join(testState.dir, 'orca-data.json')
|
||||
|
||||
Reference in New Issue
Block a user