From b00d2172dfb4eb4835ffc7b1db24d72f8b1aebe5 Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:04:42 -0800 Subject: [PATCH] test: remove narrow automation policy suites --- .../automation-launch-delivery.test.ts | 21 --- .../automation-skip-coalescing.test.ts | 130 ------------------ ...automation-zero-grace-tick-latency.test.ts | 95 ------------- 3 files changed, 246 deletions(-) delete mode 100644 src/main/automations/automation-skip-coalescing.test.ts delete mode 100644 src/main/automations/automation-zero-grace-tick-latency.test.ts diff --git a/src/main/automations/automation-launch-delivery.test.ts b/src/main/automations/automation-launch-delivery.test.ts index abb174f447f..e36787c87d0 100644 --- a/src/main/automations/automation-launch-delivery.test.ts +++ b/src/main/automations/automation-launch-delivery.test.ts @@ -64,27 +64,6 @@ describe('headless dispatch prompt delivery', () => { rmSync(testState.dir, { recursive: true, force: true }) }) - it('links the terminal while delivery is held, then fails an undelivered run keeping it', async () => { - const { service, row, settle } = await heldLaunch('delivery') - - await vi.waitFor(() => - expect(row()).toMatchObject({ - status: 'dispatching', - terminalPaneKey: 'tab-1:9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', - terminalPtyId: 'pty-1' - }) - ) - await settle("Aider started, but Orca could not send this run's prompt.") - - expect(row()).toMatchObject({ - status: 'dispatch_failed', - terminalPaneKey: 'tab-1:9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', - terminalPtyId: 'pty-1', - error: "Aider started, but Orca could not send this run's prompt." - }) - service.stop() - }) - it.each(['launch', 'delivery'] as const)( 'keeps a run settled while its %s was held when that launch later succeeds', async (hold) => { diff --git a/src/main/automations/automation-skip-coalescing.test.ts b/src/main/automations/automation-skip-coalescing.test.ts deleted file mode 100644 index f18c13be7f4..00000000000 --- a/src/main/automations/automation-skip-coalescing.test.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { mkdtempSync } from 'node:fs' -import { join } from 'node:path' -import { tmpdir } from 'node:os' -import type { Repo } from '../../shared/repo-types' -import type { Automation } from '../../shared/automations/automation-definition' -import { removeTreeSync } from '../../shared/windows-transient-lock-removal' -import type { Store } from '../persistence/loading-store/store' -import { - closeTestStores, - createStore, - readPersistedStateJson, - testState, - writePersistedStateJson -} from '../persistence/persistence-test-harness' -import { startedAutomationService, tickAt } from './testing/automation-service-tick.test-fixture' -import { runNowSettled } from './testing/automation-run-now-settled.test-fixture' - -vi.mock('electron', () => ({ - app: { - getPath: () => testState.dir - }, - safeStorage: { - isEncryptionAvailable: () => true, - encryptString: (plaintext: string) => Buffer.from(`encrypted:${plaintext}`, 'utf-8'), - decryptString: (ciphertext: Buffer) => ciphertext.toString('utf-8').slice('encrypted:'.length) - } -})) - -const makeRepo = (): Repo => ({ - id: 'r1', - path: '/repo', - displayName: 'test', - badgeColor: '#fff', - addedAt: 1 -}) - -const SETUP_GONE = 'Project is not set up on the selected automation host anymore.' - -/** Inject persisted drift because creation derives a valid run context. */ -async function seedUnresolvableAutomation(): Promise<{ store: Store; automation: Automation }> { - const seed = await createStore() - seed.addRepo(makeRepo()) - const automation = seed.createAutomation({ - name: 'Nightly check', - prompt: 'Check the repo', - agentId: 'claude', - projectId: 'r1', - workspaceMode: 'new_per_run', - timezone: 'UTC', - rrule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0', - dtstart: new Date('2026-05-12T00:00:00').getTime() - }) - seed.flushOrThrow() - await seed.freezeWritesAsync() - const file = join(testState.dir, 'orca-data.json') - const state = JSON.parse(readPersistedStateJson(file)) - state.automations[0].runContext = { - kind: 'workspace-run', - projectId: 'project-1', - hostId: 'local', - projectHostSetupId: 'missing-setup', - repoId: 'r1', - path: '/repo' - } - writePersistedStateJson(file, JSON.stringify(state)) - return { store: await createStore(), automation } -} - -async function evaluateAt(store: Store, automationId: string, when: string): Promise { - const nextRunAt = (): number | undefined => - store.listAutomations().find((entry) => entry.id === automationId)?.nextRunAt - const before = nextRunAt() - await tickAt(when) - await vi.waitFor(() => expect(nextRunAt()).toBeGreaterThan(before ?? 0)) -} - -function seedSkip(store: Store, automation: Automation, scheduledFor: number, error: string): void { - const run = store.createAutomationRun(automation, scheduledFor) - store.updateAutomationRun({ - runId: run.id, - status: 'skipped_unavailable', - workspaceId: null, - error - }) -} - -describe('repeated skipped_unavailable coalescing', () => { - beforeEach(() => { - testState.dir = mkdtempSync(join(tmpdir(), 'orca-skip-coalescing-test-')) - vi.useFakeTimers() - }) - - afterEach(async () => { - await closeTestStores() - vi.useRealTimers() - removeTreeSync(testState.dir) - }) - - it('gives a manual attempt its own answer rather than folding it into a scheduled skip', async () => { - vi.setSystemTime(new Date('2026-05-13T08:00:00')) - const { store, automation } = await seedUnresolvableAutomation() - const service = startedAutomationService(store) - - await evaluateAt(store, automation.id, '2026-05-13T09:01:00') - const manual = await runNowSettled(service, store, automation.id) - - expect(manual.status).toBe('skipped_unavailable') - expect(manual.occurrenceCount).toBeUndefined() - expect(store.listAutomationRuns(automation.id)).toHaveLength(2) - }) - - it('resumes counting a folded record across a reload', async () => { - vi.setSystemTime(new Date('2026-05-13T08:00:00')) - const { store, automation } = await seedUnresolvableAutomation() - const scheduledFor = Date.now() - seedSkip(store, automation, scheduledFor, SETUP_GONE) - store.recordRepeatedAutomationSkip(automation.id, SETUP_GONE, scheduledFor + 1000) - store.flushOrThrow() - await store.freezeWritesAsync() - - const reloaded = await createStore() - - expect(reloaded.listAutomationRuns(automation.id)[0]?.occurrenceCount).toBe(2) - expect( - reloaded.recordRepeatedAutomationSkip(automation.id, SETUP_GONE, scheduledFor + 2000) - ?.occurrenceCount - ).toBe(3) - }) -}) diff --git a/src/main/automations/automation-zero-grace-tick-latency.test.ts b/src/main/automations/automation-zero-grace-tick-latency.test.ts deleted file mode 100644 index 34e7b332b7e..00000000000 --- a/src/main/automations/automation-zero-grace-tick-latency.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { closeTestStores, createStore, testState } from '../persistence/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 { startedAutomationService } from './testing/automation-service-tick.test-fixture' - -vi.mock('electron', () => ({ - app: { - getPath: () => testState.dir - }, - safeStorage: { - isEncryptionAvailable: () => true, - encryptString: (plaintext: string) => Buffer.from(`encrypted:${plaintext}`, 'utf-8'), - decryptString: (ciphertext: Buffer) => ciphertext.toString('utf-8').slice('encrypted:'.length) - } -})) - -const makeRepo = (overrides: Partial = {}): Repo => ({ - id: 'r1', - path: '/repo', - displayName: 'test', - badgeColor: '#fff', - addedAt: 1, - ...overrides -}) - -describe('AutomationService zero-grace tick latency', () => { - beforeEach(() => { - testState.dir = mkdtempSync(join(tmpdir(), 'orca-automations-test-')) - vi.useFakeTimers() - }) - - afterEach(async () => { - await closeTestStores() - vi.useRealTimers() - rmSync(testState.dir, { recursive: true, force: true }) - }) - - const DUE = new Date('2026-05-13T09:00:00').getTime() - - const makeZeroGrace = (store: Awaited>) => - store.createAutomation({ - name: 'Zero grace', - prompt: 'Run it', - agentId: 'claude', - projectId: 'r1', - workspaceMode: 'existing', - workspaceId: 'r1::wt1', - timezone: 'UTC', - rrule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0', - dtstart: new Date('2026-05-12T00:00:00').getTime(), - missedRunGraceMinutes: 0 - }) - - /** Set the clock without advancing timers to avoid a second scheduler pass. */ - const evaluateAt = async ( - store: Awaited>, - at: number - ): Promise => { - vi.setSystemTime(at) - const service = startedAutomationService(store) - await vi.waitFor(() => { - if ( - store.listAutomations().some((automation) => automation.nextRunAt <= at) || - store.listAutomationRuns().some((run) => run.status === 'pending') - ) { - throw new Error('Automation evaluation is still saving its next occurrence') - } - }) - await service.runInAutomationLane(store.listAutomations()[0]!.id, async () => undefined) - service.stop() - } - - const statusAt = async (lateMs: number): Promise => { - vi.setSystemTime(new Date('2026-05-13T08:00:00')) - const store = await createStore() - store.addRepo(makeRepo()) - const automation = makeZeroGrace(store) - await evaluateAt(store, DUE + lateMs) - return store.listAutomationRuns(automation.id)[0]?.status - } - - it.each([ - ['1ms late', 1], - ['45s late', 45_000] - ])('dispatches a zero-grace occurrence only the tick was late for (%s)', async (_l, lateMs) => { - expect(await statusAt(lateMs)).toBe('dispatched') - }) - - it('skips once lateness exceeds the tick-latency tolerance', async () => { - expect(await statusAt(2 * 60_000 + 1)).toBe('skipped_missed') - }) -})