From 3c3544190d2efc475ed845e93d722d9e5bdcdecb Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 29 Sep 2026 20:15:11 -0700 Subject: [PATCH 1/2] test: open, seed and read the agent-session record store through one harness Tests that open the durable agent-session record store, seed it, or read back what it persisted now go through agent-session-record-store-test-harness.ts instead of calling AgentSessionRecordStore.open or touching agent-sessions.json themselves. A later change that moves the store into the chat database then changes the harness instead of every test. No production code changes. Tests whose subject is the JSON file itself (its .bak recovery, salvage, schema versions, permissions, and what older builds read back) keep reading and writing the file directly; the storage move rewrites or deletes them. --- .../tasks/agent-launch-mobile-replay.test.ts | 5 +- .../mobile-agent-launch-architecture.test.ts | 9 +- .../claude-api-retry-idle-sweep.test.ts | 7 +- .../codex-structured-question-order.test.ts | 5 +- ...-agent-session-accept-then-deliver.test.ts | 3 +- ...-agent-session-acquisition-options.test.ts | 51 ++++------- ...tured-agent-session-adopted-import.test.ts | 7 +- ...ured-agent-session-append-delivery.test.ts | 5 +- ...-agent-session-claude-compact-stop.test.ts | 5 +- ...-agent-session-claude-echo-working.test.ts | 5 +- ...-agent-session-claude-option-queue.test.ts | 5 +- ...d-agent-session-claude-queued-stop.test.ts | 5 +- ...red-agent-session-claude-root-exit.test.ts | 4 +- ...tured-agent-session-codex-stop-row.test.ts | 7 +- ...ed-agent-session-conversation-stop.test.ts | 5 +- ...ured-agent-session-crash-mid-start.test.ts | 8 +- ...tured-agent-session-crash-turn-end.test.ts | 25 ++---- ...ession-failed-create-owner-verdict.test.ts | 5 +- ...session-failed-create-sink-release.test.ts | 5 +- ...tured-agent-session-grouped-prompt.test.ts | 5 +- ...ed-agent-session-host-test-abandon.test.ts | 7 +- ...uctured-agent-session-host-test-harness.ts | 5 +- .../structured-agent-session-host.test.ts | 5 +- ...ured-agent-session-import-mismatch.test.ts | 7 +- ...ured-agent-session-late-settlement.test.ts | 5 +- ...ctured-agent-session-lease-renewer.test.ts | 5 +- ...gent-session-legacy-handoff-record.test.ts | 7 +- ...ssion-main-agent-working-agreement.test.ts | 5 +- ...ed-agent-session-option-settlement.test.ts | 5 +- ...ed-agent-session-owed-work-release.test.ts | 5 +- ...ent-session-pre-spawn-first-answer.test.ts | 7 +- ...nt-session-processless-reservation.test.ts | 23 ++--- ...gent-session-provider-child-record.test.ts | 5 +- ...red-agent-session-provider-restore.test.ts | 10 +-- ...red-agent-session-provider-started.test.ts | 5 +- ...session-queued-message-rig.test-fixture.ts | 7 +- ...tured-agent-session-recovery-exits.test.ts | 9 +- ...-agent-session-recovery-resolution.test.ts | 8 +- ...ctured-agent-session-refusal-retry.test.ts | 8 +- .../structured-agent-session-rest-test-rig.ts | 13 +-- ...ssion-restart-interruption-test-harness.ts | 8 +- ...session-restart-status-publication.test.ts | 7 +- ...tured-agent-session-rewind-at-rest.test.ts | 18 ++-- .../structured-agent-session-rewind.test.ts | 8 +- ...agent-session-send-open-stale-turn.test.ts | 7 +- ...red-agent-session-send-preparation.test.ts | 5 +- ...session-send-restarts-failed-start.test.ts | 5 +- ...agent-session-settled-attach-retry.test.ts | 9 +- ...agent-session-start-failure-writer.test.ts | 5 +- ...red-agent-session-surface-lifetime.test.ts | 9 +- ...sion-view-start-after-failed-start.test.ts | 5 +- ...t-session-wedged-profile-migration.test.ts | 30 ++----- .../structured-conversation-command.test.ts | 8 +- ...nt-session-conversation-name-store.test.ts | 9 +- ...session-death-evidence-persistence.test.ts | 23 ++--- ...agent-session-launch-env-admission.test.ts | 17 ++-- .../agent-session-lease-renewal.test.ts | 17 ++-- ...-session-older-build-lease.test-fixture.ts | 18 ++-- .../agent-session-record-options.test.ts | 6 +- ...ent-session-record-store-tab-table.test.ts | 12 ++- ...agent-session-record-store-test-harness.ts | 84 +++++++++++++++++++ .../agent-session-record-store.test.ts | 33 ++++---- ...ession-released-reservation-replay.test.ts | 5 +- ...sion-unsaved-creation-supersession.test.ts | 9 +- .../agent-launch-caller-selection.test.ts | 4 +- .../agent-launch-pane-reservation.test.ts | 5 +- .../agent-launch-prestart-failure.test.ts | 5 +- .../rpc/methods/agent-launch-replay.test.ts | 17 ++-- .../agent-launch-session-reservation.test.ts | 5 +- ...ured-agent-session-adoption-replay.test.ts | 7 +- .../structured-agent-session-hold.test.ts | 5 +- .../methods/structured-chat-tab-table.test.ts | 8 +- ...ructured-agent-session-integration.test.ts | 5 +- ...ent-session-rollback-compatibility.test.ts | 24 ++---- ...nt-session-spawn-token-descendants.test.ts | 6 +- .../structured-claude-pending-rewind.test.ts | 8 +- ...ss-version-agent-session-wire.unit.test.ts | 13 +-- ...-chat-owner-status-activation.unit.test.ts | 7 +- 78 files changed, 407 insertions(+), 396 deletions(-) create mode 100644 src/main/runtime/agent-session-record-store-test-harness.ts diff --git a/mobile/src/tasks/agent-launch-mobile-replay.test.ts b/mobile/src/tasks/agent-launch-mobile-replay.test.ts index 12a3bf495a01..aa654675f36b 100644 --- a/mobile/src/tasks/agent-launch-mobile-replay.test.ts +++ b/mobile/src/tasks/agent-launch-mobile-replay.test.ts @@ -12,7 +12,8 @@ import { } from '../../../src/shared/agent-session-host-authority' import { setStructuredAgentSessionHost } from '../../../src/main/native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../src/main/native-chat/agent-session-wire/structured-agent-session-host' -import { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store-test-harness' import type { OrcaRuntimeService } from '../../../src/main/runtime/orca-runtime' import { RpcDispatcher } from '../../../src/main/runtime/rpc/dispatcher' import { runtimeStub } from '../../../src/main/runtime/rpc/methods/agent-launch.test-fixture' @@ -30,7 +31,7 @@ beforeEach(async () => { createStructuredSession.mockReset() createStructuredSession.mockResolvedValue({ ok: true, value: { sessionId: 'session-1' } }) directory = await mkdtemp(join(tmpdir(), 'orca-mobile-launch-replay-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the launch reads only deps.store; structured session creation is the injected boundary above. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) diff --git a/mobile/src/tasks/mobile-agent-launch-architecture.test.ts b/mobile/src/tasks/mobile-agent-launch-architecture.test.ts index 2d1828d2795c..3fc2ce2a4ca2 100644 --- a/mobile/src/tasks/mobile-agent-launch-architecture.test.ts +++ b/mobile/src/tasks/mobile-agent-launch-architecture.test.ts @@ -2,7 +2,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store-test-harness' import { OrcaRuntimeRpcServer } from '../../../src/main/runtime/runtime-rpc' import { DeviceRegistry } from '../../../src/main/runtime/device-registry' import type { AuthenticatedMobileSocket } from '../../../src/main/runtime/rpc/mobile-socket-wiring' @@ -37,7 +38,7 @@ beforeEach(async () => { createStructuredSession.mockReset() createStructuredSession.mockResolvedValue({ ok: true, value: { sessionId: 'session-1' } }) directory = await mkdtemp(join(tmpdir(), 'orca-launch-architecture-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the launch reads deps.store; session creation is injected above. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) @@ -241,7 +242,7 @@ describe('mobile launch retry authority', () => { } const first = await dispatcher.dispatch(request) expect(first.ok).toBe(true) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: launch admission reads only deps.store from the installed host. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) await expect( @@ -291,7 +292,7 @@ describe('mobile launch retry authority', () => { message: 'Branch "otter" already exists locally.' } }) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: launch admission reads only deps.store from the installed host. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) await expect(dispatcher.dispatch(request)).resolves.toMatchObject({ diff --git a/src/main/claude/claude-api-retry-idle-sweep.test.ts b/src/main/claude/claude-api-retry-idle-sweep.test.ts index 30d814dcfa4e..97b0734cb8f4 100644 --- a/src/main/claude/claude-api-retry-idle-sweep.test.ts +++ b/src/main/claude/claude-api-retry-idle-sweep.test.ts @@ -4,7 +4,7 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' -import { AgentSessionRecordStore } from '../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from '../native-chat/agent-session-wire/structured-agent-session-adapter' import type { StructuredAgentSessionEventSink } from '../native-chat/agent-session-wire/structured-agent-session-event-sink' import { StructuredAgentSessionHost } from '../native-chat/agent-session-wire/structured-agent-session-host' @@ -53,10 +53,7 @@ beforeEach(async () => { sink = null clock = NOW closeSession = vi.fn(async () => true) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const adapter: StructuredAgentSessionAdapter = { acquire: async ({ fence, spawnToken, events }) => { sink = events ?? null diff --git a/src/main/codex/codex-structured-question-order.test.ts b/src/main/codex/codex-structured-question-order.test.ts index 15f82b824343..cfc84ab36c93 100644 --- a/src/main/codex/codex-structured-question-order.test.ts +++ b/src/main/codex/codex-structured-question-order.test.ts @@ -16,7 +16,8 @@ import { } from '../../shared/structured-agent-session-reducer' import { projectStructuredAgentSessionMessages } from '../../shared/structured-agent-session-message-projection' import { projectNativeChatTranscriptMessages } from '../../shared/native-chat-transcript-projection' -import { AgentSessionRecordStore } from '../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../runtime/agent-session-record-store-test-harness' import { CodexJournalPrompts } from './codex-structured-journal-prompts' import { CODEX_USER_INPUT_METHOD } from './codex-structured-prompt-replies' import type { StructuredAgentSessionAdapter } from '../native-chat/agent-session-wire/structured-agent-session-adapter' @@ -90,7 +91,7 @@ beforeEach(async () => { answerPrompt: vi.fn(async ({ commit }) => commit()), setOption: vi.fn(async () => undefined) } - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts index 0064f36ce584..4b8ff7c73ae1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts @@ -20,6 +20,7 @@ import { DISPATCH_REJECTED_CANCELLED } from '../../../shared/structured-agent-session-dispatch-rejection' import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionJournal } from '../agent-session-journal/journal-store' import { openAgentSessionJournal } from '../agent-session-journal/journal-store-factory' import { @@ -109,7 +110,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) await startHost() expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts index 4e5d44795a31..25cc6dd568be 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts @@ -5,7 +5,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionOptionsResult } from '../../../shared/agent-session-wire' import type { AgentJournalMessageItem } from '../../../shared/agent-session-journal-types' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionRecord } from '../../../shared/agent-session-record' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { digestPayload } from '../agent-session-journal/journal-payload-bounds' @@ -116,10 +117,7 @@ function expectSettledAttachLease(record: AgentSessionRecord | null): void { describe('structured session acquisition options', () => { it('samples provider history before acquiring a replacement child', async () => { root = await mkdtemp(join(tmpdir(), 'orca-history-before-acquire-')) - const initialStore = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const initialStore = await openTestAgentSessionRecordStore(join(root, 'store')) let childAcquired = false const historyWindow = (): ProviderHistoryWindow => ({ items: [], @@ -181,10 +179,7 @@ describe('structured session acquisition options', () => { fence: 1 }) await firstJournal!.close() - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) await store.reconcileOnRestart({ probe: async () => ({ outcome: 'pid-absent' }), now: NOW + 1 @@ -218,10 +213,7 @@ describe('structured session acquisition options', () => { it('persists create defaults before the first provider acquisition', async () => { root = await mkdtemp(join(tmpdir(), 'orca-create-options-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const sessionAdapter = adapter({ origin: 'created' }) const options = { model: 'gpt-5.6-sol', effort: 'medium', fastMode: 'false' } const recordPhase = vi.fn() @@ -252,10 +244,7 @@ describe('structured session acquisition options', () => { it('replays a create retried after the host re-resolved different options', async () => { root = await mkdtemp(join(tmpdir(), 'orca-create-retry-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const sessionAdapter = adapter({ origin: 'created' }) const attempt = async (options: Readonly>, spawnToken: string) => performAttach({ @@ -287,7 +276,7 @@ describe('structured session acquisition options', () => { it('persists provider options before proving a resumed legacy record', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-options-')) const storeDir = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(storeDir) const created = await performAttach({ store, @@ -313,10 +302,7 @@ describe('structured session acquisition options', () => { now: NOW }) - const resumedStore = await AgentSessionRecordStore.open({ - directory: storeDir, - hostId: 'local' - }) + const resumedStore = await openTestAgentSessionRecordStore(storeDir) await resumedStore.reconcileOnRestart({ probe: async () => ({ outcome: 'pid-absent' }), now: NOW + 1 @@ -345,7 +331,7 @@ describe('structured session acquisition options', () => { }) expect(resumed).toMatchObject({ ok: true }) - const reopened = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(storeDir) expect(reopened.getRecord(SESSION)?.options).toEqual({ approvalPolicy: 'on-request', personality: 'concise', @@ -357,10 +343,7 @@ describe('structured session acquisition options', () => { it('clears a rejected Fast restore instead of retaining the prior encoded value', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-fast-restore-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const sessionAdapter = adapter({ origin: 'created', options: { current: { model: 'gpt-standard' }, models: [] }, @@ -392,10 +375,7 @@ describe('structured session acquisition options', () => { it('releases an acquisition when provider options cannot be read', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-options-failure-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const releaseAcquisition = vi.fn(async () => true) const failingAdapter: StructuredAgentSessionAdapter = { ...adapter({ origin: 'created' }), @@ -447,7 +427,7 @@ describe('structured session acquisition options', () => { const exitProven = cleanup === true root = await mkdtemp(join(tmpdir(), `orca-acquisition-${failurePoint}-`)) const storeDir = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(storeDir) const base = adapter({ origin: 'created', options: { current: { model: 'gpt-5.6-terra' }, models: [] } @@ -534,10 +514,7 @@ describe('structured session acquisition options', () => { exitProven ? injected.message : 'agent_session_acquisition_exit_unproven' )) - const reopened = await AgentSessionRecordStore.open({ - directory: storeDir, - hostId: 'local' - }) + const reopened = await openTestAgentSessionRecordStore(storeDir) const failedRecord = reopened.getRecord(SESSION) expectSettledAttachLease(failedRecord) expect( @@ -600,7 +577,7 @@ describe('structured session acquisition options', () => { describe('the tab a create reserves', () => { async function openStore() { root = await mkdtemp(join(tmpdir(), 'orca-surface-tab-id-')) - return AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + return openTestAgentSessionRecordStore(join(root, 'store')) } function attachWith(store: AgentSessionRecordStore, surfaceTabId?: string) { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts index ac5f1d1b088c..df5f46500958 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts @@ -6,7 +6,8 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { attachFingerprintFields, @@ -119,7 +120,7 @@ async function attach( sessionAdapter: StructuredAgentSessionAdapter, onAttached: AttachFlowInput['onAttached'] = () => {} ) { - store ??= await AgentSessionRecordStore.open({ directory: join(root!, 'store'), hostId: 'local' }) + store ??= await openTestAgentSessionRecordStore(join(root!, 'store')) return performAttach({ store, adapter: sessionAdapter, @@ -230,7 +231,7 @@ describe('adopting a provider conversation on create', () => { root = await mkdtemp(join(tmpdir(), 'orca-adopt-host-failure-')) const transcriptPath = join(root, 'rollout.jsonl') await writeCodexRollout(transcriptPath, 'valid source') - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts index 19280db41e50..0585b330420e 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts @@ -12,7 +12,8 @@ import type { AgentJournalSubmission } from '../../../shared/agent-session-journal-types' import type { AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -125,7 +126,7 @@ beforeEach(async () => { acquisitionGeneration: `generation-${++generation}`, providerChildPhase: 'starting' as const })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts index 0e34cca99a71..57ad992fd771 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts @@ -14,7 +14,8 @@ import { PROVIDER_SESSION_ID, type FakeConnection } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { structuredAgentSessionCommandTurn } from './structured-agent-session-command-turn' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -67,7 +68,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => adapterNow }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, // The production router is what declares create support; the bare adapter only knows locations. diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts index 103df14eb733..bb4022924c39 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts @@ -14,7 +14,8 @@ import { fakeClaude, PROVIDER_SESSION_ID } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -63,7 +64,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts index 6787a4e7586e..c51ce418ec8f 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts @@ -4,7 +4,8 @@ import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionMutationEnvelope } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -80,7 +81,7 @@ beforeEach(async () => { resetHostTestOperationIds() activeModel = DEFAULT_MODEL optionWritable = Promise.resolve() - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts index dfbe77c68ba6..8ccc268ee241 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts @@ -16,7 +16,8 @@ import { fakeClaude, PROVIDER_SESSION_ID } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { openTestJournalHostDatabase } from '../agent-session-journal/journal-host-database-test-support' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -79,7 +80,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts index d201360cd542..59f8aad20cc2 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts @@ -8,7 +8,7 @@ import { fakeClaude, identityFor } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { createTrackedJournalOpener, openTestJournalHostDatabase @@ -31,7 +31,7 @@ describe('Claude root-exit stop', () => { it('releases a captured live claim after the provider root exits', async () => { const root = await mkdtemp(join(tmpdir(), 'orca-claude-root-exit-')) roots.push(root) - const store = await AgentSessionRecordStore.open({ directory: root, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(root) const claude = fakeClaude({ unprovenCloseVerdict: { root: 'exited', tree: 'unverifiable' } }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts index 28b4dde82e07..f4d19388029c 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts @@ -14,7 +14,7 @@ import { fakeCodex } from '../../codex/codex-structured-session-adapter-fixture' import { codexTurnLifecycleFake } from '../../codex/codex-turn-lifecycle-fake' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { HOST_TEST_NOW as NOW, @@ -49,10 +49,7 @@ beforeEach(async () => { ) return {} } - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapterFor(codex), { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts index 5793f9677d8b..4eeff810dd4a 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts @@ -11,7 +11,8 @@ import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-ses import type { AgentJournalSubmission } from '../../../shared/agent-session-journal-types' import { DISPATCH_REJECTED_CANCELLED } from '../../../shared/structured-agent-session-dispatch-rejection' import { CancelParams } from '../../../shared/rpc-contract/structured-agent-session-params' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import type { StructuredAgentSessionEventSink } from './structured-agent-session-event-sink' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -48,7 +49,7 @@ beforeEach(async () => { dispatch = vi.fn(async () => ({ state: 'admitted' as const })) cancelTurn = vi.fn(async () => ({ cancelled: true })) awaitStarted = vi.fn(async () => undefined) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts index a4831b1a7b14..87d7ba1a79e4 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts @@ -13,7 +13,8 @@ import { import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease-adjudication' import type { openCodexAppServerConnection } from '../../codex/codex-app-server-connection' import { adapterFor, fakeCodex } from '../../codex/codex-structured-session-adapter-fixture' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import type { StructuredAgentSessionHostDeps } from './structured-agent-session-host-types' @@ -58,10 +59,7 @@ async function crash(dying: AgentSessionRecordStore): Promise { } function openStore(generation: HostGeneration): Promise { - return AgentSessionRecordStore.open({ - directory: join(generationRoot(generation), 'store'), - hostId: 'local' - }) + return openTestAgentSessionRecordStore(join(generationRoot(generation), 'store')) } /** A Codex adapter whose child spawns, reports its pid the way the real connection does, and then diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts index ac1218fb2a78..54bd2789c00f 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts @@ -4,7 +4,7 @@ // that runs for half a minute leaves one journal row at its start. The lease renewal the host // wrote every ten seconds is what saw the child working after that row. -import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -18,8 +18,11 @@ import { completedStructuredAgentTurnSeconds, selectStructuredAgentTurnTimings } from '../../../shared/structured-agent-session-turn-timing' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' -import { AGENT_SESSION_STORE_FILE_NAME } from '../../runtime/agent-session-record-store-file' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { + openTestAgentSessionRecordStore, + seedTestAgentSessionRecordStore +} from '../../runtime/agent-session-record-store-test-harness' import { closeTestJournalHostDatabases, openTestJournalHostDatabase @@ -97,20 +100,8 @@ function crashedClaudeRecord(): AgentSessionRecord { async function seedCrashedStore(): Promise { const directory = join(root, 'store') - await mkdir(directory, { recursive: true }) - await writeFile( - join(directory, AGENT_SESSION_STORE_FILE_NAME), - JSON.stringify({ - schemaVersion: 2, - hostId: 'local', - records: { [SESSION]: crashedClaudeRecord() }, - operations: {}, - retiredClaimKeys: [], - unusableRecords: {} - }), - 'utf-8' - ) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + await seedTestAgentSessionRecordStore(directory, { records: [crashedClaudeRecord()] }) + store = await openTestAgentSessionRecordStore(directory) } /** A running turn whose only row after its start is a Bash call that never reported back, for a diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts index 3547f8bdd776..8d0f31367fb7 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts @@ -5,7 +5,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { AgentSessionAcquisitionExitUnprovenError, AgentSessionAcquisitionRefusal, @@ -48,7 +49,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts index 435a9be82b16..9e88829aad31 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts @@ -6,7 +6,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { AgentSessionPreSpawnError, type StructuredAgentSessionAdapter @@ -44,7 +45,7 @@ beforeEach(async () => { }, acquisitionGeneration: `generation-${fence}` })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts index df6ee094967e..29f6eabf703c 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts @@ -7,7 +7,8 @@ import { agentJournalItemKey } from '../../../shared/agent-session-journal-item- import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionMutationEnvelope } from '../../../shared/agent-session-wire' import { encodeAgentSessionQuestionAnswers } from '../../../shared/agent-session-question-answer' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionDispatchOutcome, StructuredAgentSessionAdapter @@ -130,7 +131,7 @@ beforeEach(async () => { } })) answerPrompt = vi.fn(async ({ commit }) => commit()) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts index 19f2dd003a4d..0d1dfc5d6cb1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts @@ -7,7 +7,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { describe, expect, it } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { abandonStructuredAgentSessionHost } from './structured-agent-session-host-test-abandon' @@ -25,10 +25,7 @@ const CALLER = { callerKey: 'client-1' } describe('abandoning a structured agent-session host', () => { it('waits for the restart the delivery loop woke for an accepted send', async () => { const root = await mkdtemp(join(tmpdir(), 'orca-abandon-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) // Holds the restart inside its provider acquisition, so the point teardown must not run past // is exact rather than a timing window. let gate: Promise | null = null diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts index a0caaa45b936..f3528123f998 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts @@ -8,7 +8,8 @@ import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-ses import { agentJournalItemKey } from '../../../shared/agent-session-journal-item-key' import type { AgentSessionRecord } from '../../../shared/agent-session-record' import type { AgentSessionMutationEnvelope } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { createTrackedJournalOpener, openTestJournalHostDatabase @@ -147,7 +148,7 @@ beforeEach(async () => { cancelTurn = vi.fn(async () => ({ cancelled: true })) answerPrompt = vi.fn(async ({ commit }) => commit()) setOption = vi.fn(async () => undefined) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts index 590f69c79840..78454b675026 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts @@ -5,7 +5,8 @@ import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease import type { AgentSessionRecord } from '../../../shared/agent-session-record' import type { AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' import { join } from 'node:path' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionJournal } from '../agent-session-journal/journal-store' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -560,7 +561,7 @@ describe('restart', () => { adapterOverrides: Partial = {}, stopOwnerProcess?: StructuredAgentSessionHostDeps['stopOwnerProcess'] ) { - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { ...adapter(), ...adapterOverrides }, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts index fca1d49c06cf..8d96bf346320 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts @@ -4,7 +4,7 @@ import { cp, rm } from 'node:fs/promises' import { join } from 'node:path' import { afterEach, beforeEach, expect, it, vi } from 'vitest' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { openTestJournalHostDatabase } from '../agent-session-journal/journal-host-database-test-support' import { JournalImportMismatchError, @@ -92,10 +92,7 @@ async function relaunchWithMismatchedCopy(): Promise recursive: true, filter: (source) => !source.includes('.lock') }) - const store = await AgentSessionRecordStore.open({ - directory: join(relaunched, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(relaunched, 'store')) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts index 4dfbac37c42c..5383914012a9 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts @@ -9,7 +9,8 @@ import type { AgentSessionMutationEnvelope, AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionJournal } from '../agent-session-journal/journal-store' import type { AgentSessionDispatchOutcome, @@ -92,7 +93,7 @@ beforeEach(async () => { resetHostTestOperationIds() dispatch = vi.fn(async () => accepted()) closeSession = vi.fn(async () => true) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-lease-renewer.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-lease-renewer.test.ts index 9545e42b051c..9399e4d0242b 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-lease-renewer.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-lease-renewer.test.ts @@ -6,7 +6,8 @@ import { agentSessionLeaseFixture, agentSessionRecordFixture } from '../../../shared/agent-session-record.test-fixture' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionLeaseRenewer } from './structured-agent-session-lease-renewer' const NOW = 1_800_000_000_000 @@ -15,7 +16,7 @@ const roots: string[] = [] async function liveStore(): Promise { const root = await mkdtemp(join(tmpdir(), 'orca-lease-renewer-')) roots.push(root) - const store = await AgentSessionRecordStore.open({ directory: root, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(root) const reserved = await store.reserveOwner({ sessionId: 'session-renewal', location: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts index cea81c6c4fe4..e936ef337a2a 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts @@ -10,7 +10,8 @@ import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { PersistedAgentSessionLease } from '../../../shared/agent-session-legacy-handoff-lease' import { writeOlderBuildLease } from '../../runtime/agent-session-older-build-lease.test-fixture' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -73,7 +74,7 @@ async function persistFromOlderBuild(lease: OlderBuildLease): Promise { await host.flushAllStreamedEvents() // Over the attached owner: the older build's stage or terminal owner kept it from releasing. await writeOlderBuildLease(join(root, 'store'), SESSION, { ...attached, ...lease }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) acquire.mockClear() openHost() } @@ -130,7 +131,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts index ea543785dde5..5e53dadf8beb 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts @@ -22,7 +22,8 @@ import { reduceStructuredAgentSession, type StructuredAgentSessionState } from '../../../shared/structured-agent-session-reducer' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import type { StructuredAgentSessionEventSink } from './structured-agent-session-event-sink' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -58,7 +59,7 @@ beforeEach(async () => { listed = undefined // Written, and the provider has neither opened a turn for it nor answered it. dispatch = vi.fn(async () => ({ state: 'admitted' as const })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts index 7445c1e3894c..ea7abc170c35 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts @@ -7,7 +7,8 @@ import type { AgentSessionMutationEnvelope, AgentSessionStatusEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { AgentSessionOptionRejectedError } from './structured-agent-session-option-error' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -120,7 +121,7 @@ beforeEach(async () => { closeSessionExit = true dispatchedModels.length = 0 const accountHome = join(root, 'codex-home') - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) router = adapter() host = new StructuredAgentSessionHost({ store, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts index 340b35cf21ce..ab77dea332c9 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts @@ -18,7 +18,8 @@ import { fakeClaude, PROVIDER_SESSION_ID } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -85,7 +86,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts index fd41ba7890f2..d3fb132954f7 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { mapRuntimeError } from '../../runtime/rpc/errors' import { AgentSessionPreSpawnError, @@ -66,10 +66,7 @@ function createParams(): AgentSessionAttachParams { /** The thrown first answer as the wire sends it, and the ledger's replay of the same operation. */ async function firstAnswerAndReplay(thrown: AgentSessionPreSpawnError) { root = await mkdtemp(join(tmpdir(), 'orca-pre-spawn-first-answer-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const unused = async (): Promise => { throw new Error('not reached before a spawn') } diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts index 204ffba30da6..b6df344d01ac 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { AgentSessionPreSpawnError, type StructuredAgentSessionAdapter @@ -68,10 +68,7 @@ function attachParams( describe('processless structured session reservation', () => { it('refuses an adapter that declares no create support before reserving a lease', async () => { root = await mkdtemp(join(tmpdir(), 'orca-unsupported-attach-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const reserveOwner = vi.spyOn(store, 'reserveOwner') const acquire = vi.fn() const adapter = { @@ -109,10 +106,7 @@ describe('processless structured session reservation', () => { it('refuses a replay when adapter support drifts after durable reservation', async () => { root = await mkdtemp(join(tmpdir(), 'orca-replay-support-drift-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const supportsCreate = vi .fn>() .mockReturnValueOnce(true) @@ -159,10 +153,7 @@ describe('processless structured session reservation', () => { it('releases a new reservation when support drifts before acquisition', async () => { root = await mkdtemp(join(tmpdir(), 'orca-support-drift-reservation-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const supportsCreate = vi .fn>() .mockReturnValueOnce(true) @@ -215,7 +206,7 @@ describe('processless structured session reservation', () => { it('settles a pre-spawn failure and its processless evidence in one durable transaction', async () => { root = await mkdtemp(join(tmpdir(), 'orca-processless-reservation-')) const storeDir = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(storeDir) const adapter = { acquire: vi.fn(async () => { throw new AgentSessionPreSpawnError(new Error('workspace no longer exists')) @@ -253,7 +244,7 @@ describe('processless structured session reservation', () => { }) expect(store.listOperationRows()[0]?.outcome).toMatchObject({ status: 'failed' }) - const reopened = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(storeDir) await reopened.reconcileOnRestart({ probe: async () => ({ outcome: 'indeterminate', reason: 'no owner to probe' }), now: NOW + 1 @@ -268,7 +259,7 @@ describe('processless structured session reservation', () => { it('does not rerun a settled pre-spawn failure and admits a fresh operation', async () => { root = await mkdtemp(join(tmpdir(), 'orca-processless-retry-')) const storeDir = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(storeDir) const adapter = { acquire: vi .fn() diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts index 74ae75e45d93..c302a5771561 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts @@ -22,7 +22,8 @@ import { import { agentSessionFailureWords } from '../../../shared/agent-session-failure-words' import { readAgentJournalTurn } from '../../../shared/agent-session-turn-record' import { openAgentSessionJournal } from '../agent-session-journal/journal-store-factory' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { ensureStructuredAgentSessionAgent } from './structured-agent-session-agent-start' import { StructuredAgentSessionHost } from './structured-agent-session-host' @@ -115,7 +116,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) startHost() expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) await host.close(SESSION) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts index e5025551360b..3466c5e4dfd6 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts @@ -2,7 +2,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { abandonStructuredAgentSessionHost } from './structured-agent-session-host-test-abandon' @@ -78,7 +79,7 @@ describe('structured session provider restore', () => { root = await mkdtemp(join(tmpdir(), 'orca-provider-restore-')) resetHostTestOperationIds() const storeDirectory = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory: storeDirectory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(storeDirectory) const host = createHost(store) const attached = await host.attach( { callerKey: 'client-1' }, @@ -91,10 +92,7 @@ describe('structured session provider restore', () => { ) expect(attached).toMatchObject({ ok: true }) - const reopenedStore = await AgentSessionRecordStore.open({ - directory: storeDirectory, - hostId: 'local' - }) + const reopenedStore = await openTestAgentSessionRecordStore(storeDirectory) const restarted = createHost(reopenedStore, async () => ({ outcome: 'indeterminate', reason: 'read does not need ownership' diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts index 892e45a4ad0d..9b3cd4bc378a 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts @@ -12,7 +12,8 @@ import { fakeClaude, PROVIDER_SESSION_ID } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -72,7 +73,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, // The production router is what declares create support; the bare adapter only knows locations. diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts index 739e64e94ece..bb86b5e39c1d 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts @@ -10,7 +10,7 @@ import { agentSessionFailureWords } from '../../../shared/agent-session-failure- import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentJournalSubmission } from '../../../shared/agent-session-journal-types' import type { AgentSessionQueuePause } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import type { StructuredAgentSessionEventSink } from './structured-agent-session-event-sink' import { AGENT_JOURNAL_THREAD_SCOPE } from '../../../shared/agent-session-journal-types' @@ -52,10 +52,7 @@ export async function createQueuedMessageTestRig() { providerIdentity: null })) let events: StructuredAgentSessionEventSink | undefined - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts index 4728d4256de2..66723f45654a 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts @@ -6,7 +6,8 @@ import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' import { spawnProcess } from '../../../shared/child-process/run-process' import { CODEX_SPAWN_TOKEN_ENV } from '../../codex/codex-structured-owner-identity' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { readProcessStartTimeMs } from '../../runtime/agent-session-process-identity-probe' import { createStructuredAgentSessionOwnerProbe } from '../../runtime/structured-agent-session-owner-probe' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' @@ -92,7 +93,7 @@ function openHost(overrides: Partial = {}): void async function reopenStore(): Promise { await abandonStructuredAgentSessionHost(host) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) } beforeEach(async () => { @@ -113,7 +114,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() }) @@ -296,7 +297,7 @@ describe('recovery exits', () => { const outgoingHost = host const outgoingStore = store supersededHosts.add(outgoingHost) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) const realProbe = createStructuredAgentSessionOwnerProbe('local') let overlapDriven = false openHost({ diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-resolution.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-resolution.test.ts index 063e8c64af71..8e3be9d1f3d7 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-resolution.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-resolution.test.ts @@ -8,7 +8,8 @@ import { readPersistedLease, writeOlderBuildLease } from '../../runtime/agent-session-older-build-lease.test-fixture' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { supervisedPosixLaunch } from '../../codex/codex-app-server-posix-supervisor' import { resolveStructuredSessionRecovery, @@ -32,10 +33,7 @@ async function newStoreDirectory(): Promise { } async function openStore(directory?: string): Promise { - return AgentSessionRecordStore.open({ - directory: directory ?? (await newStoreDirectory()), - hostId: 'local' - }) + return openTestAgentSessionRecordStore(directory ?? (await newStoreDirectory())) } async function reserve(store: AgentSessionRecordStore) { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts index 4c2db496c3cf..9d84252472b5 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts @@ -16,7 +16,8 @@ import { agentSessionRefusalOperationState, type AgentSessionRefusalOperationState } from '../../../shared/agent-session-refusal-retry' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { abandonStructuredAgentSessionHost } from './structured-agent-session-host-test-abandon' @@ -58,10 +59,7 @@ function operationId(timestamp = NOW): string { async function createHarness(options: { attached?: boolean } = {}) { const root = await mkdtemp(join(tmpdir(), 'orca-refusal-oracle-')) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const setOption = vi.fn(async () => undefined) const adapter: StructuredAgentSessionAdapter = { acquire: async ({ fence }) => ({ diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts index 782c1f161156..a95b1fed8683 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts @@ -13,7 +13,8 @@ import type { AgentSessionStatusEvent, AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionDispatchOutcome, StructuredAgentSessionAdapter @@ -126,10 +127,7 @@ export async function createRestTestRig( const clock = { now: HOST_TEST_NOW } const statusEvents: AgentSessionStatusEvent[] = [] const sink = { publish: vi.fn(), forget: vi.fn() } - let store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + let store = await openTestAgentSessionRecordStore(join(root, 'store')) const adapter: RestTestAdapter = { acquire: vi.fn(async ({ fence, spawnToken }) => ({ acquisitionGeneration: `generation-${++generations}`, @@ -180,10 +178,7 @@ export async function createRestTestRig( sink, restart: async (overrides = {}) => { await rig.host.flushAllStreamedEvents().catch(() => undefined) - store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) rig.store = store rig.host = hostFor(overrides) rig.host.subscribeStatus({ id: 'status', emit: (event) => statusEvents.push(event) }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts index 30eae55f36a9..7f425f61a7ea 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts @@ -9,7 +9,8 @@ import { AgentSessionRecoveryCapsule, AGENT_SESSION_RECOVERY_CAPSULE_FILE } from '../../runtime/agent-session-recovery-capsule' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { parseAgentSessionResumeMarker } from '../../../shared/agent-session-resume-marker' import { StructuredAgentSessionHost } from './structured-agent-session-host' import type { StructuredAgentSessionHostDeps } from './structured-agent-session-host-types' @@ -115,10 +116,7 @@ export async function interruptedRestart( } await previous.host.flushStreamedEvents(SESSION) await previous.host.flushAllStreamedEvents() - const store = await AgentSessionRecordStore.open({ - directory: join(previous.root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(previous.root, 'store')) const closeSession = vi.fn(async () => true) // The relaunch comes after the quit that recorded the offer. const clock = { now: NOW + 1 } diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts index 87e87a408c32..601eed15c3e3 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts @@ -13,7 +13,8 @@ import type { AgentSessionStatusEvent } from '../../../shared/agent-session-wire' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -92,7 +93,7 @@ async function restartWithPersistedTurn(): Promise { root = await mkdtemp(join(tmpdir(), 'orca-restart-status-')) resetHostTestOperationIds() const directory = join(root, 'store') - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) const host = createHost(store) expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) const body = hostTestMessage('persisted conversation') @@ -103,7 +104,7 @@ async function restartWithPersistedTurn(): Promise { // Delivered, not just accepted: a message still queued at the restart was never a request. await host.waitForSendSettlement(SESSION, sent.value.clientMessageId) await host.flushAllStreamedEvents() - return createHost(await AgentSessionRecordStore.open({ directory, hostId: 'local' })) + return createHost(await openTestAgentSessionRecordStore(directory)) } afterEach(async () => { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts index d00f6a244657..c1fb0009346f 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts @@ -8,7 +8,8 @@ import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { agentJournalItemKey } from '../../../shared/agent-session-journal-item-key' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionDispatchOutcome, StructuredAgentSessionAdapter @@ -106,10 +107,7 @@ beforeEach(async () => { } })) directory = await mkdtemp(join(tmpdir(), 'orca-rewind-rest-')) - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) host = openHost() }) @@ -174,10 +172,7 @@ async function interruptedRewindAtRest(): Promise { ) expect(store.getRecord(SESSION)?.rewind).toMatchObject({ phase: 'prepared' }) await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) host = openHost() } @@ -212,10 +207,7 @@ describe('a rewind asked of a chat at rest (P2-23)', () => { await host.flushStreamedEvents(SESSION) const epoch = (await host.journalSnapshot(SESSION)).cursor.epoch await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) host = openHost() const before = acquires rewindSupport.mockReturnValue({ supported: false, reason: 'history-not-paginated' }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts index 7b4baa03df87..8232d287f63f 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts @@ -10,7 +10,8 @@ import { } from '../../../shared/agent-session-journal-item-key' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import { nativeChatTurnMembership } from '../../../shared/native-chat-turn-membership' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionHost } from './structured-agent-session-host' import type { StructuredAgentSessionAdapter, @@ -53,10 +54,7 @@ beforeEach(async () => { }) acquires = [] directory = await mkdtemp(join(tmpdir(), 'orca-rewind-')) - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) adapter = { supportsCreate: (_location, agent) => agent === 'codex', supportsLocation: () => true, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts index 3718a60a7a98..e5a8388f7794 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts @@ -9,7 +9,7 @@ import { join } from 'node:path' import { afterEach, expect, it, vi } from 'vitest' import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease-adjudication' import { readAgentJournalTurn } from '../../../shared/agent-session-turn-record' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { adapter, @@ -66,10 +66,7 @@ async function relaunchAfterCrashMidTurn( recursive: true, filter: (source) => !source.includes('.lock') }) - const store = await AgentSessionRecordStore.open({ - directory: join(relaunched, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(relaunched, 'store')) const acquire = vi.fn(async () => { throw new Error('claude: command not found') }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts index e435110f1399..8fc9cbbf75f1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts @@ -10,7 +10,8 @@ import type { AgentSessionMutationEnvelope, AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { CodexAppServerRequestError } from '../../codex/codex-app-server-request-error' @@ -68,7 +69,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts index d8390feae1c4..c6f387a68b1c 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts @@ -14,7 +14,8 @@ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vite import { agentJournalSubmissionKey } from '../../../shared/agent-session-journal-item-key' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionMutationEnvelope } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -143,7 +144,7 @@ beforeEach(async () => { providerChildPhase: 'starting' as const })) dispatch = vi.fn(async () => ({ state: 'admitted' as const })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts index 27b408933b7c..462111f14ade 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts @@ -9,7 +9,8 @@ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vite import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionMutationEnvelope } from '../../../shared/agent-session-wire' import type * as DurableFileWrite from '../../durable-file-write' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionDispatchOutcome, StructuredAgentSessionAdapter @@ -109,7 +110,7 @@ beforeEach(async () => { })) releaseAcquisition = vi.fn(async () => true) dispatch = vi.fn(async () => accepted()) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), @@ -267,7 +268,7 @@ describe('settled attach retry', () => { }) await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), @@ -324,7 +325,7 @@ describe('settled attach retry', () => { await vi.waitFor(() => expect(dispatch).toHaveBeenCalledTimes(1)) await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts index 69bed14b7b12..517d136b581f 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts @@ -14,7 +14,8 @@ import { import { agentJournalItemKey } from '../../../shared/agent-session-journal-item-key' import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { HOST_TEST_NOW as NOW, @@ -117,7 +118,7 @@ beforeEach(async () => { awaitStarted = vi.fn( () => new Promise((resolve) => (settleStart = resolve)) ) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts index 586f8c826300..c25c92d6affb 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts @@ -18,7 +18,8 @@ import type { AgentSessionMutationEnvelope, AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { AgentSessionAcquisitionRootExitObservedError, type StructuredAgentSessionAdapter @@ -91,7 +92,7 @@ function openHost( /** A fresh app generation over the same durable store, with its owner proven gone. */ async function reboot(): Promise { await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost(async () => ({ outcome: 'pid-absent' })) acquire.mockClear() closeSession.mockClear() @@ -231,7 +232,7 @@ beforeEach(async () => { surface: 'rejection' }) })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() }) @@ -400,7 +401,7 @@ describe('startup', () => { const beforeRestart = store.getRecord(SESSION) await abandonStructuredAgentSessionHost(host) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost(async () => ({ outcome: 'pid-absent' })) await host.restoreReadableSessions() diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts index a49d411c9cf8..ac773034ced6 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts @@ -12,7 +12,8 @@ import { fakeClaude, PROVIDER_SESSION_ID } from '../../claude/claude-structured-session-test-support' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { structuredClaudeLifecycleEvent } from '../../runtime/structured-claude-runtime-adapter' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { @@ -81,7 +82,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts index da3072272576..72d88caa226d 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts @@ -11,7 +11,7 @@ import { AGENT_JOURNAL_THREAD_SCOPE } from '../../../shared/agent-session-journa // leave the lease in a state an attach can claim, and these tests prove that by adjudicating it // rather than by reading fields off it. -import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest' @@ -31,8 +31,11 @@ import type { PersistedAgentSessionRecord, PersistedAgentSessionRuntimeKind } from '../../../shared/agent-session-legacy-handoff-lease' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' -import { AGENT_SESSION_STORE_FILE_NAME } from '../../runtime/agent-session-record-store-file' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { + openTestAgentSessionRecordStore, + seedTestAgentSessionRecordStore +} from '../../runtime/agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from './structured-agent-session-adapter' import { openAgentSessionJournal } from '../agent-session-journal/journal-store-factory' import { AgentSessionJournal } from '../agent-session-journal/journal-store' @@ -112,20 +115,8 @@ function wedgedRecord(overrides: WedgeOverrides): PersistedAgentSessionRecord { async function seedStore(record: PersistedAgentSessionRecord): Promise { const directory = join(root, 'store') - await mkdir(directory, { recursive: true }) - await writeFile( - join(directory, AGENT_SESSION_STORE_FILE_NAME), - JSON.stringify({ - schemaVersion: 2, - hostId: 'local', - records: { [record.sessionId]: record }, - operations: {}, - retiredClaimKeys: [], - unusableRecords: {} - }), - 'utf-8' - ) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + await seedTestAgentSessionRecordStore(directory, { records: [record] }) + store = await openTestAgentSessionRecordStore(directory) } /** Every recorded owner in these fixtures is long gone; that is the present-time evidence. */ @@ -283,10 +274,7 @@ describe('already-wedged profiles become usable on load', () => { expect(acquire).not.toHaveBeenCalled() await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() await host.restoreReadableSessions() diff --git a/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts b/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts index 1f6d6016cf83..220b12f1d4a3 100644 --- a/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts @@ -6,7 +6,8 @@ import { AGENT_SESSION_MAX_NEW_OPERATION_AGE_MS } from '../../../shared/agent-se import { computeAgentSessionPayloadFingerprint } from '../../../shared/agent-session-mutation-envelope' import type { AgentSessionConversationCommand } from '../../../shared/agent-session-conversation-command' import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease-adjudication' -import { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { StructuredAgentSessionHost } from './structured-agent-session-host' import { AgentSessionAcquisitionRefusal, @@ -61,10 +62,7 @@ const generationRoot = () => join(directory, `generation-${generation}`) let ownerProbe: AgentSessionOwnerProbe = { outcome: 'pid-absent' } async function openHost(): Promise { - store = await AgentSessionRecordStore.open({ - directory: join(generationRoot(), 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(generationRoot(), 'store')) host = new StructuredAgentSessionHost({ store, adapter, diff --git a/src/main/runtime/agent-session-conversation-name-store.test.ts b/src/main/runtime/agent-session-conversation-name-store.test.ts index 1e8067f6dd20..07c1345f8da4 100644 --- a/src/main/runtime/agent-session-conversation-name-store.test.ts +++ b/src/main/runtime/agent-session-conversation-name-store.test.ts @@ -4,7 +4,8 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import type { AgentSessionExecutionLocation } from '../../shared/agent-session-record' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -49,7 +50,7 @@ afterEach(async () => { }) async function reservedStore(): Promise { - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) await store.reserveOwner(reserveRequest()) return store } @@ -60,7 +61,7 @@ describe('AgentSessionRecordStore.setConversationName', () => { await store.setConversationName(SESSION, 'Fix the lease probe') - const reloaded = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reloaded = await openTestAgentSessionRecordStore(directory) expect(reloaded.getRecord(SESSION)?.conversationName).toBe('Fix the lease probe') }) @@ -73,7 +74,7 @@ describe('AgentSessionRecordStore.setConversationName', () => { expect(name).toHaveLength(200) expect(name.startsWith('Fix the ')).toBe(true) // A reload validates every record; an over-long name would be dropped as unreadable. - const reloaded = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reloaded = await openTestAgentSessionRecordStore(directory) expect(reloaded.getRecord(SESSION)?.conversationName).toBe(name) }) diff --git a/src/main/runtime/agent-session-death-evidence-persistence.test.ts b/src/main/runtime/agent-session-death-evidence-persistence.test.ts index 6e0bff8098cd..9904ca7994f4 100644 --- a/src/main/runtime/agent-session-death-evidence-persistence.test.ts +++ b/src/main/runtime/agent-session-death-evidence-persistence.test.ts @@ -1,4 +1,4 @@ -import { mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -8,8 +8,11 @@ import { agentSessionRecordFixture } from '../../shared/agent-session-record.test-fixture' import type { AgentSessionFailedAcquisitionSettlement } from './agent-session-acquisition-failure-settlement' -import { AgentSessionRecordStore } from './agent-session-record-store' -import { agentSessionStorePath } from './agent-session-record-store-file' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + seedTestAgentSessionRecordStore +} from './agent-session-record-store-test-harness' const SESSION = 'session-alpha-1' /** The fixture lease's last renewal. */ @@ -27,21 +30,11 @@ async function seed(deathEvidence: AgentSessionDeathEvidence | null): Promise { - return AgentSessionRecordStore.open({ directory, hostId: 'local' }) + return openTestAgentSessionRecordStore(directory) } beforeEach(async () => { diff --git a/src/main/runtime/agent-session-launch-env-admission.test.ts b/src/main/runtime/agent-session-launch-env-admission.test.ts index 51b2fe64dafb..6cb9a576078f 100644 --- a/src/main/runtime/agent-session-launch-env-admission.test.ts +++ b/src/main/runtime/agent-session-launch-env-admission.test.ts @@ -1,8 +1,11 @@ -import { mkdtemp, readFile, rm } from 'node:fs/promises' +import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + readPersistedTestAgentSessionStoreText +} from './agent-session-record-store-test-harness' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -45,7 +48,7 @@ afterEach(async () => { describe('agent session launch environment admission', () => { it('does not persist ambient launch variables', async () => { - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) await store.reserveOwner(request()) await store.reserveOwner( request({ @@ -63,15 +66,15 @@ describe('agent session launch environment admission', () => { }) ) - const raw = await readFile(join(directory, 'agent-sessions.json'), 'utf-8') + const raw = await readPersistedTestAgentSessionStoreText(directory) expect(raw).not.toContain('OPENAI_API_KEY') expect(raw).not.toContain('"PATH"') - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(directory) expect(reopened.getRecord(SESSION)).not.toHaveProperty('launchEnv') }) it('rejects an environment that could not be validated before writing', async () => { - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) const launchEnv = Object.fromEntries( Array.from({ length: 257 }, (_, index) => [`KEY_${index}`, 'value']) ) @@ -83,7 +86,7 @@ describe('agent session launch environment admission', () => { }) it('rejects an overlong environment key before writing it', async () => { - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) await expect( store.reserveOwner(request({ launchEnv: { ['K'.repeat(513)]: 'value' } })) diff --git a/src/main/runtime/agent-session-lease-renewal.test.ts b/src/main/runtime/agent-session-lease-renewal.test.ts index b2788f816029..ec636a96eed5 100644 --- a/src/main/runtime/agent-session-lease-renewal.test.ts +++ b/src/main/runtime/agent-session-lease-renewal.test.ts @@ -1,10 +1,13 @@ -import { mkdtemp, readFile, rm } from 'node:fs/promises' +import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import type { AgentSessionRecord } from '../../shared/agent-session-record' -import { AgentSessionRecordStore } from './agent-session-record-store' -import { agentSessionStorePath } from './agent-session-record-store-file' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + readPersistedTestAgentSessionStoreText +} from './agent-session-record-store-test-harness' const NOW = 1_800_000_000_000 const MATCHED = { outcome: 'identity-matched', matchedOn: ['spawn-token'] } as const @@ -63,7 +66,7 @@ async function establishOwner( async function liveStore(): Promise<{ directory: string; store: AgentSessionRecordStore }> { const directory = await mkdtemp(join(tmpdir(), 'orca-lease-renewal-batch-')) directories.push(directory) - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) await establishOwner(store, directory, 'a') await establishOwner(store, directory, 'b') return { directory, store } @@ -93,7 +96,7 @@ describe('agent-session lease renewal batch', () => { probe: { outcome: 'pid-absent' }, now: NOW + 5_000 }) - const beforeDisk = await readFile(agentSessionStorePath(directory), 'utf-8') + const beforeDisk = await readPersistedTestAgentSessionStoreText(directory) const beforeFirst = store.getRecord('session-a') await expect( @@ -104,8 +107,8 @@ describe('agent-session lease renewal batch', () => { ).rejects.toThrow('agent_session_checkpoint_stale') expect(store.getRecord('session-a')).toEqual(beforeFirst) - expect(await readFile(agentSessionStorePath(directory), 'utf-8')).toBe(beforeDisk) - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + expect(await readPersistedTestAgentSessionStoreText(directory)).toBe(beforeDisk) + const reopened = await openTestAgentSessionRecordStore(directory) expect( reopened .listRecords() diff --git a/src/main/runtime/agent-session-older-build-lease.test-fixture.ts b/src/main/runtime/agent-session-older-build-lease.test-fixture.ts index 906921645d4d..869f8ddc14c2 100644 --- a/src/main/runtime/agent-session-older-build-lease.test-fixture.ts +++ b/src/main/runtime/agent-session-older-build-lease.test-fixture.ts @@ -1,8 +1,8 @@ -import { readFile, writeFile } from 'node:fs/promises' import type { PersistedAgentSessionLease } from '../../shared/agent-session-legacy-handoff-lease' -import { agentSessionStorePath } from './agent-session-record-store-file' - -type StoreFile = { records: Record }> } +import { + editPersistedTestAgentSessionStore, + readPersistedTestAgentSessionStore +} from './agent-session-record-store-test-harness' /** Rewrites one lease on disk as an older build left it; this build's types cannot express it. */ export async function writeOlderBuildLease( @@ -10,16 +10,14 @@ export async function writeOlderBuildLease( sessionId: string, fields: Partial ): Promise { - const path = agentSessionStorePath(directory) - const file: StoreFile = JSON.parse(await readFile(path, 'utf-8')) - file.records[sessionId].lease = { ...file.records[sessionId].lease, ...fields } - await writeFile(path, JSON.stringify(file)) + await editPersistedTestAgentSessionStore(directory, (persisted) => { + persisted.records[sessionId].lease = { ...persisted.records[sessionId].lease, ...fields } + }) } export async function readPersistedLease( directory: string, sessionId: string ): Promise> { - const file: StoreFile = JSON.parse(await readFile(agentSessionStorePath(directory), 'utf-8')) - return file.records[sessionId].lease + return (await readPersistedTestAgentSessionStore(directory)).records[sessionId].lease } diff --git a/src/main/runtime/agent-session-record-options.test.ts b/src/main/runtime/agent-session-record-options.test.ts index 5ba7c41cffcc..58385e292726 100644 --- a/src/main/runtime/agent-session-record-options.test.ts +++ b/src/main/runtime/agent-session-record-options.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, expect, it } from 'vitest' import { readNativeSessionOptions } from '../native-chat/agent-session-wire/structured-agent-session-option-restoration' -import { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' const NOW = 1_800_000_000_000 const SESSION = 'session-options' @@ -46,7 +46,7 @@ it('drops provider-rejected persisted options before the next owner proof', asyn }) it('persists resumed provider options atomically with owner proof', async () => { - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) const reserved = await store.reserveOwner({ sessionId: SESSION, location: { @@ -105,6 +105,6 @@ it('persists resumed provider options atomically with owner proof', async () => ...(options ? { options } : {}) }) - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(directory) expect(reopened.getRecord(SESSION)?.options).toEqual({ model: 'gpt-tui', effort: 'low' }) }) diff --git a/src/main/runtime/agent-session-record-store-tab-table.test.ts b/src/main/runtime/agent-session-record-store-tab-table.test.ts index 56bcb6debb6a..696eb5fd1cb0 100644 --- a/src/main/runtime/agent-session-record-store-tab-table.test.ts +++ b/src/main/runtime/agent-session-record-store-tab-table.test.ts @@ -10,7 +10,11 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest' import type { AgentSessionOwnerProbe } from '../../shared/agent-session-lease-adjudication' import type { AgentSessionExecutionLocation } from '../../shared/agent-session-record' import { isAgentSessionRefusalError } from '../../shared/agent-session-wire-refusals' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + readPersistedTestAgentSessionStore +} from './agent-session-record-store-test-harness' import { agentSessionStorePath } from './agent-session-record-store-file' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' @@ -61,7 +65,7 @@ function reserveRequest( } async function open(): Promise { - return AgentSessionRecordStore.open({ directory, hostId: 'local' }) + return openTestAgentSessionRecordStore(directory) } describe('chat tab table', () => { @@ -74,11 +78,11 @@ describe('chat tab table', () => { await store.reserveOwner(reserveRequest({ surfaceTabId: 'tab-alpha' })) // A create that dies before its tab is shown leaves nothing to restore or release. expect(store.getSessionTabId('session-alpha')).toBeNull() - expect((await readFileJson()).sessionTabs).toBeUndefined() + expect((await readPersistedTestAgentSessionStore(directory)).sessionTabs).toBeUndefined() await store.setSessionTabVisibility('session-alpha', true, 'tab-alpha') expect(store.getSessionTabId('session-alpha')).toBe('tab-alpha') - const persisted = await readFileJson() + const persisted = await readPersistedTestAgentSessionStore(directory) expect(persisted.sessionTabs).toEqual([{ tabId: 'tab-alpha', sessionId: 'session-alpha' }]) // Not copied onto the record: the table is the one place the id lives. expect(persisted.records['session-alpha']).not.toHaveProperty('surfaceTabId') diff --git a/src/main/runtime/agent-session-record-store-test-harness.ts b/src/main/runtime/agent-session-record-store-test-harness.ts new file mode 100644 index 000000000000..d590ecd296d1 --- /dev/null +++ b/src/main/runtime/agent-session-record-store-test-harness.ts @@ -0,0 +1,84 @@ +/** + * The one way tests open, seed and read back the durable agent-session record store, so a change + * to where or how the store persists is made here rather than in every test that uses it. + */ + +import { mkdir, readFile, writeFile } from 'node:fs/promises' +import type { AgentSessionOperationRow } from '../../shared/agent-session-operation-ledger' +import type { PersistedAgentSessionRecord } from '../../shared/agent-session-legacy-handoff-lease' +import { AgentSessionRecordStore } from './agent-session-record-store' +import { + AGENT_SESSION_STORE_SCHEMA_VERSION, + agentSessionStorePath, + type RetiredAgentSessionClaimKey +} from './agent-session-record-store-file' + +const TEST_HOST_ID = 'local' + +/** One committed state of the store, as tests seed it and read it back. */ +export type PersistedTestAgentSessionStore = { + schemaVersion: number + hostId: string + records: Record + operations: Record + retiredClaimKeys: RetiredAgentSessionClaimKey[] + unusableRecords: Record + /** Absent until the store first records a chat tab. */ + sessionTabs?: { tabId: string; sessionId: string }[] +} + +/** Opens, or reopens, the store kept in `directory`: what a fresh app process does at launch. */ +export function openTestAgentSessionRecordStore( + directory: string, + options: { hostId?: string } = {} +): Promise { + return AgentSessionRecordStore.open({ directory, hostId: options.hostId ?? TEST_HOST_ID }) +} + +/** Leaves `records` behind as an earlier run of the app would have, before anything opens it. */ +export async function seedTestAgentSessionRecordStore( + directory: string, + seed: { records: readonly PersistedAgentSessionRecord[] } +): Promise { + const persisted: PersistedTestAgentSessionStore = { + schemaVersion: AGENT_SESSION_STORE_SCHEMA_VERSION, + hostId: TEST_HOST_ID, + records: Object.fromEntries(seed.records.map((record) => [record.sessionId, record])), + operations: {}, + retiredClaimKeys: [], + unusableRecords: {} + } + await mkdir(directory, { recursive: true }) + await writeFile(agentSessionStorePath(directory), JSON.stringify(persisted), 'utf-8') +} + +/** Leaves an empty store a newer build wrote: this build reads it but never writes it. */ +export async function seedTestAgentSessionStoreFromNewerBuild(directory: string): Promise { + await mkdir(directory, { recursive: true }) + await writeFile( + agentSessionStorePath(directory), + JSON.stringify({ schemaVersion: 99, hostId: TEST_HOST_ID, records: {}, operations: {} }) + ) +} + +/** Everything the store has committed, as text: to assert a value never reached disk, or that an + * action wrote nothing by comparing two reads. */ +export function readPersistedTestAgentSessionStoreText(directory: string): Promise { + return readFile(agentSessionStorePath(directory), 'utf-8') +} + +export async function readPersistedTestAgentSessionStore( + directory: string +): Promise { + return JSON.parse(await readPersistedTestAgentSessionStoreText(directory)) +} + +/** Changes the committed state behind the store's back, as an older build or a damaged disk would. */ +export async function editPersistedTestAgentSessionStore( + directory: string, + edit: (persisted: PersistedTestAgentSessionStore) => void +): Promise { + const persisted = await readPersistedTestAgentSessionStore(directory) + edit(persisted) + await writeFile(agentSessionStorePath(directory), JSON.stringify(persisted)) +} diff --git a/src/main/runtime/agent-session-record-store.test.ts b/src/main/runtime/agent-session-record-store.test.ts index 5ee25d36813d..7ea6174da70d 100644 --- a/src/main/runtime/agent-session-record-store.test.ts +++ b/src/main/runtime/agent-session-record-store.test.ts @@ -1,4 +1,4 @@ -import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' @@ -10,7 +10,14 @@ import type { AgentSessionRecord } from '../../shared/agent-session-record' import type { AgentSessionProviderHandleLink } from '../../shared/agent-session-provider-handle' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { PersistedAgentSessionRecord } from '../../shared/agent-session-legacy-handoff-lease' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { + editPersistedTestAgentSessionStore, + openTestAgentSessionRecordStore, + readPersistedTestAgentSessionStore, + seedTestAgentSessionStoreFromNewerBuild +} from './agent-session-record-store-test-harness' import { AGENT_SESSION_CLAIM_KEY_RETENTION_MS } from './agent-session-claim-key-retention' import { agentSessionStorePath, @@ -97,7 +104,7 @@ function handleLink( let directory: string async function open(hostId = 'local'): Promise { - return AgentSessionRecordStore.open({ directory, hostId }) + return openTestAgentSessionRecordStore(directory, { hostId }) } /** Reserve, observe the spawn, prove the handle — the full path to an admitted writer. */ @@ -550,7 +557,7 @@ describe('restart reconciliation', () => { releaseProbe({ outcome: 'pid-absent' }) expect(await reconciliation).toEqual(new Map()) - const persisted = JSON.parse(await readFile(agentSessionStorePath(directory), 'utf-8')) + const persisted = await readPersistedTestAgentSessionStore(directory) expect(persisted.records['session-alpha'].lease).toMatchObject({ runtimeFence: 3, claimStatus: 'live', @@ -803,20 +810,20 @@ describe('claim keys, checkpoints, and unreadable rows', () => { it.each([ [ 'invalid checkpoint', - (record: AgentSessionRecord) => + (record: PersistedAgentSessionRecord) => Object.assign(record.lease, { journalCheckpoint: { epoch: 'bad', sequence: 1 } }) ], [ 'missing live proof', - (record: AgentSessionRecord) => Object.assign(record.lease, { provenHandleLinkId: null }) + (record: PersistedAgentSessionRecord) => + Object.assign(record.lease, { provenHandleLinkId: null }) ] ])('quarantines a record with %s', async (_name, corrupt) => { const first = await open() await establishOwner(first) - const filePath = agentSessionStorePath(directory) - const raw = JSON.parse(await readFile(filePath, 'utf-8')) - corrupt(raw.records['session-alpha']) - await writeFile(filePath, JSON.stringify(raw)) + await editPersistedTestAgentSessionStore(directory, (persisted) => { + corrupt(persisted.records['session-alpha']) + }) expect((await open()).isSessionUnreadable('session-alpha')).toBe(true) }) @@ -863,11 +870,7 @@ describe('claim keys, checkpoints, and unreadable rows', () => { }) it('refuses to write a store written by a newer schema', async () => { - const filePath = agentSessionStorePath(directory) - await writeFile( - filePath, - JSON.stringify({ schemaVersion: 99, hostId: 'local', records: {}, operations: {} }) - ) + await seedTestAgentSessionStoreFromNewerBuild(directory) const store = await open() expect(store.readOnly).toBe(true) await expect(store.reserveOwner(reserveRequest())).rejects.toThrow( diff --git a/src/main/runtime/agent-session-released-reservation-replay.test.ts b/src/main/runtime/agent-session-released-reservation-replay.test.ts index e3f9bcff74bc..e5f54265dcb7 100644 --- a/src/main/runtime/agent-session-released-reservation-replay.test.ts +++ b/src/main/runtime/agent-session-released-reservation-replay.test.ts @@ -12,7 +12,8 @@ import { } from '../../shared/agent-session-host-authority' import type { AgentSessionOwnerProbe } from '../../shared/agent-session-lease-adjudication' import type { AgentSessionLease } from '../../shared/agent-session-record' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -33,7 +34,7 @@ afterEach(async () => { }) function open(): Promise { - return AgentSessionRecordStore.open({ directory, hostId: 'local' }) + return openTestAgentSessionRecordStore(directory) } function createRequest( diff --git a/src/main/runtime/agent-session-unsaved-creation-supersession.test.ts b/src/main/runtime/agent-session-unsaved-creation-supersession.test.ts index 50d27baa57ac..31e473fb5e66 100644 --- a/src/main/runtime/agent-session-unsaved-creation-supersession.test.ts +++ b/src/main/runtime/agent-session-unsaved-creation-supersession.test.ts @@ -4,7 +4,8 @@ import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import type { AgentSessionProviderHandleLink } from '../../shared/agent-session-provider-handle' import { codexProviderHandleLink } from '../codex/codex-structured-owner-identity' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -72,7 +73,7 @@ async function restart(store: AgentSessionRecordStore) { probe: { outcome: 'exit-observed' }, now: NOW }) - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(directory) await reopened.reconcileOnRestart({ probe: async () => ({ outcome: 'reservation-unused' }), now: NOW @@ -90,7 +91,7 @@ afterEach(async () => { describe('a Codex thread started in place of one Codex never saved', () => { it('becomes the session identity and survives the next restart', async () => { - const first = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const first = await openTestAgentSessionRecordStore(directory) await prove(first, reserveRequest(), (fence) => codexProviderHandleLink({ threadId: 'thread-unsaved', @@ -127,7 +128,7 @@ describe('a Codex thread started in place of one Codex never saved', () => { }) it('is refused once a resume has proved the conversation Codex saved', async () => { - const first = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const first = await openTestAgentSessionRecordStore(directory) await prove(first, reserveRequest(), (fence) => codexProviderHandleLink({ threadId: 'thread-saved', resumed: false, fence, observedAt: NOW }) ) diff --git a/src/main/runtime/rpc/methods/agent-launch-caller-selection.test.ts b/src/main/runtime/rpc/methods/agent-launch-caller-selection.test.ts index 8ef0f2c904dd..2e99f5801254 100644 --- a/src/main/runtime/rpc/methods/agent-launch-caller-selection.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-caller-selection.test.ts @@ -8,7 +8,7 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import type { RpcContext } from '../core' @@ -153,7 +153,7 @@ describe('a replayed launch', () => { beforeEach(async () => { directory = await mkdtemp(join(tmpdir(), 'orca-agent-launch-caller-')) - const store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: `deps.store` is the only member `agent.launch` reads, and a member it omits throws on call. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) diff --git a/src/main/runtime/rpc/methods/agent-launch-pane-reservation.test.ts b/src/main/runtime/rpc/methods/agent-launch-pane-reservation.test.ts index 22d025106f19..d1d419a4c562 100644 --- a/src/main/runtime/rpc/methods/agent-launch-pane-reservation.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-pane-reservation.test.ts @@ -11,7 +11,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import type { OrcaRuntimeService } from '../../orca-runtime' @@ -220,7 +221,7 @@ describe('a live-pane refusal under a named operation', () => { beforeEach(async () => { directory = await mkdtemp(join(tmpdir(), 'orca-agent-launch-pane-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: `deps.store` is the only member `agent.launch` reads, and a member it omits throws on call. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) diff --git a/src/main/runtime/rpc/methods/agent-launch-prestart-failure.test.ts b/src/main/runtime/rpc/methods/agent-launch-prestart-failure.test.ts index 6b7adb8dbfc7..cfc14ec55041 100644 --- a/src/main/runtime/rpc/methods/agent-launch-prestart-failure.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-prestart-failure.test.ts @@ -8,7 +8,8 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import type { OrcaRuntimeService } from '../../orca-runtime' @@ -55,7 +56,7 @@ describe('a launch whose terminal fails', () => { beforeEach(async () => { directory = await mkdtemp(join(tmpdir(), 'orca-agent-launch-prestart-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: `deps.store` is the only member `agent.launch` reads, and a member it omits throws on call. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) diff --git a/src/main/runtime/rpc/methods/agent-launch-replay.test.ts b/src/main/runtime/rpc/methods/agent-launch-replay.test.ts index 336cd4c212b5..2cb953063391 100644 --- a/src/main/runtime/rpc/methods/agent-launch-replay.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-replay.test.ts @@ -24,7 +24,11 @@ import { settleAgentSessionOperation, type AgentSessionOperationRow } from '../../../../shared/agent-session-operation-ledger' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { + openTestAgentSessionRecordStore, + readPersistedTestAgentSessionStore +} from '../../agent-session-record-store-test-harness' import { agentSessionStorePath } from '../../agent-session-record-store-file' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' @@ -120,7 +124,7 @@ beforeEach(async () => { attachCallerKeys.length = 0 createStructuredSession.mockClear() directory = await mkdtemp(join(tmpdir(), 'orca-agent-launch-replay-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // The launch reaches the ledger through the installed host; nothing else on the host is used, // because the structured create below it is mocked out. // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: `deps.store` is the only member `agent.launch` reads, and a member it omits throws on call. @@ -241,7 +245,7 @@ describe('a replay answers from the record', () => { const params = createLaunch({ operationId: OPERATION_ID }) const first = await launch(params, runtime) - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: see the setup above. setStructuredAgentSessionHost({ deps: { store: reopened } @@ -411,9 +415,8 @@ describe('the recorded row stays readable by a build that predates it', () => { runtimeStub({ createSupport: { supported: false, reason: 'agent' } }) ) - const file: { operations: Record }> } = JSON.parse( - await readFile(agentSessionStorePath(directory), 'utf-8') - ) + const file: { operations: Record }> } = + await readPersistedTestAgentSessionStore(directory) const outcome = Object.values(file.operations)[0].outcome // The ratchet, and the reason this is not a new status arm or an optional `sessionId`: a build @@ -465,7 +468,7 @@ describe('an unreadable launch payload costs one replay, never the store', () => await launch(params, runtime) await rewriteRecordedLaunch({ outcome: { kind: 'structured' }, worktreeId: 'wt-1' }) - const reopened = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + const reopened = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: see the setup above. setStructuredAgentSessionHost({ deps: { store: reopened } diff --git a/src/main/runtime/rpc/methods/agent-launch-session-reservation.test.ts b/src/main/runtime/rpc/methods/agent-launch-session-reservation.test.ts index f59e7c676bd2..528490d1d0a6 100644 --- a/src/main/runtime/rpc/methods/agent-launch-session-reservation.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-session-reservation.test.ts @@ -10,7 +10,8 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { computeAgentLaunchFingerprint } from '../../../../shared/agent-launch-operation' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import type { OrcaRuntimeService } from '../../orca-runtime' @@ -208,7 +209,7 @@ describe('a taken session id under a named operation', () => { beforeEach(async () => { directory = await mkdtemp(join(tmpdir(), 'orca-agent-launch-session-')) - store = await AgentSessionRecordStore.open({ directory, hostId: 'local' }) + store = await openTestAgentSessionRecordStore(directory) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: `deps.store` is the only member `agent.launch` reads, and a member it omits throws on call. setStructuredAgentSessionHost({ deps: { store } } as unknown as StructuredAgentSessionHost) }) diff --git a/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts b/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts index 4748c7dd5a67..272cb8bbb92b 100644 --- a/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts +++ b/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts @@ -4,7 +4,7 @@ import { dirname, join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { computeAgentSessionPayloadFingerprint } from '../../../../shared/agent-session-mutation-envelope' import { STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import type { StructuredAgentSessionAdapter } from '../../../native-chat/agent-session-wire/structured-agent-session-adapter' import { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' @@ -176,10 +176,7 @@ describe('committed adopting create RPC replay', () => { .mockRejectedValueOnce(new Error('simulated lost tab publication')) .mockResolvedValue(undefined) - const store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + const store = await openTestAgentSessionRecordStore(join(root, 'store')) const sessionAdapter = adapter() host = new StructuredAgentSessionHost({ store, diff --git a/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts b/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts index aa2b2da15486..008038cb0190 100644 --- a/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts +++ b/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts @@ -19,7 +19,8 @@ import { } from '../../../native-chat/agent-session-wire/structured-agent-session-host-test-data' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import { STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { OrcaRuntimeService } from '../../orca-runtime' import type { RpcResponse } from '../core' import { RpcDispatcher } from '../dispatcher' @@ -75,7 +76,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts b/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts index 9bd7b1fade0e..4d6a313f8b5b 100644 --- a/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts +++ b/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts @@ -24,7 +24,8 @@ import { resetHostTestOperationIds } from '../../../native-chat/agent-session-wire/structured-agent-session-host-test-data' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' -import { AgentSessionRecordStore } from '../../agent-session-record-store' +import type { AgentSessionRecordStore } from '../../agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' import { agentSessionStorePath } from '../../agent-session-record-store-file' import { OrcaRuntimeService } from '../../orca-runtime' import { RpcDispatcher } from '../dispatcher' @@ -87,10 +88,7 @@ function providerAdapter(): StructuredAgentSessionAdapter { } async function openHost(): Promise { - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) host = new StructuredAgentSessionHost({ store, adapter: providerAdapter(), diff --git a/src/main/runtime/structured-agent-session-integration.test.ts b/src/main/runtime/structured-agent-session-integration.test.ts index cd8939b93888..2e2d87d65471 100644 --- a/src/main/runtime/structured-agent-session-integration.test.ts +++ b/src/main/runtime/structured-agent-session-integration.test.ts @@ -6,7 +6,7 @@ // that ship. The fake app-server answers the same JSON-RPC calls the real one // does and pushes the same notifications and blocking requests back. -import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -34,6 +34,7 @@ import { importLegacyTranscriptIntoJournal } from '../native-chat/agent-session- import type { AgentSessionJournal } from '../native-chat/agent-session-journal/journal-store' import { createTrackedJournalOpener } from '../native-chat/agent-session-journal/journal-host-database-test-support' import type { OrcaRuntimeService } from './orca-runtime' +import { readPersistedTestAgentSessionStoreText } from './agent-session-record-store-test-harness' import type { RpcRequest, RpcResponse } from './rpc/core' import { RpcDispatcher } from './rpc/dispatcher' import type { NativeChatShellEnvironmentPolicy } from '../../shared/native-chat-shell-environment' @@ -455,7 +456,7 @@ describe('a structured codex session over agentSession.*', () => { EXAMPLE_GATEWAY_TOKEN: 'shell-exported', CODEX_HOME: '/home/dev/.codex' }) - const store = await readFile(join(root, 'agent-sessions', 'agent-sessions.json'), 'utf-8') + const store = await readPersistedTestAgentSessionStoreText(join(root, 'agent-sessions')) expect(store).not.toContain('EXAMPLE_GATEWAY_TOKEN') expect(store).not.toContain('"launchEnv"') const stream = await subscribe('sub-first-send') diff --git a/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts b/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts index 293ec194aae7..48a9d33142c2 100644 --- a/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts +++ b/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts @@ -5,7 +5,10 @@ import { afterEach, describe, expect, it } from 'vitest' import { agentSessionRecordFixture } from '../../shared/agent-session-record.test-fixture' import { safeParseWorkspaceSession } from '../../shared/workspace-session-schema' import { journalDirectoryFor } from '../native-chat/agent-session-journal/journal-paths' -import { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + seedTestAgentSessionRecordStore +} from './agent-session-record-store-test-harness' import { AGENT_SESSION_STORE_FILE_NAME } from './agent-session-record-store-file' import { collectSavedStructuredAgentSessionIds } from './saved-structured-agent-session-restoration' @@ -78,28 +81,17 @@ describe('structured session rollback compatibility', () => { it('keeps the visible session reference through target → base → target', async () => { root = await mkdtemp(join(tmpdir(), 'orca-structured-rollback-')) const storeDir = join(root, 'agent-store') - await mkdir(storeDir, { recursive: true }) const record = agentSessionRecordFixture({ ...agentSessionRecordFixture().lease, sessionId: SESSION, runtimeKind: 'native' }) - await writeFile( - join(storeDir, AGENT_SESSION_STORE_FILE_NAME), - JSON.stringify({ - schemaVersion: 2, - hostId: 'local', - records: { [SESSION]: record }, - operations: {}, - retiredClaimKeys: [], - unusableRecords: {} - }) - ) + await seedTestAgentSessionRecordStore(storeDir, { records: [record] }) const journalDir = journalDirectoryFor(root, { workspaceId: WORKSPACE, sessionId: SESSION }) await mkdir(journalDir, { recursive: true }) await writeFile(join(journalDir, 'journal.log'), 'durable-journal-fixture\n') - const target = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const target = await openTestAgentSessionRecordStore(storeDir) expect(target.getVisibleSessionTabIndex()).toEqual({ present: false, sessionIds: [] }) await target.setSessionTabVisibility(SESSION, true) expect(target.getVisibleSessionTabIndex()).toEqual({ present: true, sessionIds: [SESSION] }) @@ -126,7 +118,7 @@ describe('structured session rollback compatibility', () => { targetReloadedProfile?.success ? targetReloadedProfile.data : null ) ).toEqual([]) - const reloaded = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const reloaded = await openTestAgentSessionRecordStore(storeDir) expect(reloaded.listVisibleSessionIds()).toEqual([SESSION]) expect(reloaded.getRecord(SESSION)?.providerHandleChain).toHaveLength(1) await expect(readFile(join(journalDir, 'journal.log'), 'utf8')).resolves.toBe( @@ -137,7 +129,7 @@ describe('structured session rollback compatibility', () => { ).toMatchObject({ visibleSessionIds: [SESSION] }) await reloaded.setSessionTabVisibility(SESSION, false) - const afterClose = await AgentSessionRecordStore.open({ directory: storeDir, hostId: 'local' }) + const afterClose = await openTestAgentSessionRecordStore(storeDir) expect(afterClose.getVisibleSessionTabIndex()).toEqual({ present: true, sessionIds: [] }) expect(afterClose.listVisibleSessionIds()).toEqual([]) expect(afterClose.getRecord(SESSION)?.providerHandleChain).toHaveLength(1) diff --git a/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts b/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts index d0650d94f495..62b3e385f0c6 100644 --- a/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts +++ b/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts @@ -9,7 +9,8 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { CODEX_SPAWN_TOKEN_ENV } from '../codex/codex-structured-owner-identity' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' import { createStructuredAgentSessionOwnerProbe } from './structured-agent-session-owner-probe' import { @@ -89,8 +90,7 @@ afterEach(async () => { }) function openStore(): Promise { - return AgentSessionRecordStore.open({ - directory: join(stateDirectory, 'agent-sessions'), + return openTestAgentSessionRecordStore(join(stateDirectory, 'agent-sessions'), { hostId: HOST_ID }) } diff --git a/src/main/runtime/structured-claude-pending-rewind.test.ts b/src/main/runtime/structured-claude-pending-rewind.test.ts index 1cce64dea323..d87a76ccd3a9 100644 --- a/src/main/runtime/structured-claude-pending-rewind.test.ts +++ b/src/main/runtime/structured-claude-pending-rewind.test.ts @@ -20,7 +20,8 @@ import { hostTestOperationId, resetHostTestOperationIds } from '../native-chat/agent-session-wire/structured-agent-session-host-test-data' -import { AgentSessionRecordStore } from './agent-session-record-store' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { openTestAgentSessionRecordStore } from './agent-session-record-store-test-harness' import { createStructuredClaudeRuntimeAdapter } from './structured-claude-runtime-adapter' import { openTestJournalHostDatabase } from '../native-chat/agent-session-journal/journal-host-database-test-support' @@ -106,10 +107,7 @@ async function reattach() { beforeEach(async () => { resetHostTestOperationIds() directory = await mkdtemp(join(tmpdir(), 'orca-claude-pending-rewind-')) - store = await AgentSessionRecordStore.open({ - directory: join(directory, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(directory, 'store')) claude = fakeClaude({ initSessionId: PROVIDER_SESSION_ID }) adapter = createStructuredClaudeRuntimeAdapter({ store, diff --git a/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts b/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts index 981731cd40f1..f24571786ad3 100644 --- a/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts +++ b/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts @@ -18,7 +18,8 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite import type { StructuredAgentSessionAdapter } from '../../../src/main/native-chat/agent-session-wire/structured-agent-session-adapter' import { StructuredAgentSessionHost } from '../../../src/main/native-chat/agent-session-wire/structured-agent-session-host' import { setStructuredAgentSessionHost } from '../../../src/main/native-chat/agent-session-wire/structured-agent-session-registry' -import { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../../src/main/runtime/agent-session-record-store-test-harness' import { RuntimeSubscriptionRegistry } from '../../../src/main/runtime/runtime-subscription-registry' import type { AgentSessionSubscribeEvent } from '../../../src/shared/agent-session-wire' import { @@ -472,10 +473,7 @@ describe('cross-version structured agent sessions', () => { beforeEach(async () => { root = await mkdtemp(join(tmpdir(), 'orca-cross-version-ai-vault-')) - store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) const host = new StructuredAgentSessionHost({ store, adapter: { @@ -701,10 +699,7 @@ describe('cross-version structured agent sessions', () => { /** Reopens the store from disk and installs a fresh host over the same journal * root — what a process restart actually leaves behind. */ async function bootHost(generation: string): Promise { - store = await AgentSessionRecordStore.open({ - directory: join(root, 'store'), - hostId: 'local' - }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/tests/e2e/structured-chat-owner-status-activation.unit.test.ts b/tests/e2e/structured-chat-owner-status-activation.unit.test.ts index dff6b466ec74..b5e7271cc195 100644 --- a/tests/e2e/structured-chat-owner-status-activation.unit.test.ts +++ b/tests/e2e/structured-chat-owner-status-activation.unit.test.ts @@ -18,7 +18,8 @@ import { resetHostTestOperationIds } from '../../src/main/native-chat/agent-session-wire/structured-agent-session-host-test-data' import { STRUCTURED_AGENT_SESSION_IDLE_MS } from '../../src/main/native-chat/agent-session-wire/structured-agent-session-idle-sweep' -import { AgentSessionRecordStore } from '../../src/main/runtime/agent-session-record-store' +import type { AgentSessionRecordStore } from '../../src/main/runtime/agent-session-record-store' +import { openTestAgentSessionRecordStore } from '../../src/main/runtime/agent-session-record-store-test-harness' import { useAppStore } from '../../src/renderer/src/store' import { runWorktreeAgentActivationGate } from '../../src/renderer/src/lib/worktree-agent-activation-gate' import { readWorktreeStructuredActivationInventory } from '../../src/renderer/src/lib/worktree-agent-structured-inventory' @@ -114,7 +115,7 @@ beforeEach(async () => { clock = NOW resetHostTestOperationIds() closeSession = vi.fn(async () => true) - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() expect(await host.attach({ callerKey: 'client-1' }, hostTestAttachParams(null))).toMatchObject({ ok: true @@ -140,7 +141,7 @@ describe('a chat at rest keeps its worktree activatable', () => { it('after an app restart restored it for reading', async () => { await host.flushAllStreamedEvents() - store = await AgentSessionRecordStore.open({ directory: join(root, 'store'), hostId: 'local' }) + store = await openTestAgentSessionRecordStore(join(root, 'store')) openHost() await host.restoreReadableSessions() expect(host.hasSession(SESSION)).toBe(true) From ed88d256bf8d916e2d7342a48f88433640684289 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 29 Sep 2026 20:41:03 -0700 Subject: [PATCH 2/2] test: address the record-store harness by the host's state directory The harness took the store's own folder, so each caller picked one (join(root, 'store'), or 'agent-sessions' where a test read the store the runtime owns). A later change that moves the store into the state directory's journal database could not tell those apart, and would have had to edit every caller again. Every harness function now takes the state directory, the one the test's journal database and recovery capsule already live in, and keeps the store in the same subfolder the runtime uses. Callers pass that directory; store-only tests pass their temp directory unchanged. Format tests that share a directory with harness calls take the file path from testAgentSessionStoreFilePath. The folder name moves from a private constant in the runtime to AGENT_SESSION_STORE_DIR_NAME beside the store's file name, so the harness shares it without importing the runtime. Its value and every path built from it are unchanged. --- .../claude-api-retry-idle-sweep.test.ts | 2 +- .../codex-structured-question-order.test.ts | 2 +- ...-agent-session-accept-then-deliver.test.ts | 2 +- ...-agent-session-acquisition-options.test.ts | 26 +++++----- ...tured-agent-session-adopted-import.test.ts | 4 +- ...ured-agent-session-append-delivery.test.ts | 2 +- ...-agent-session-claude-compact-stop.test.ts | 2 +- ...-agent-session-claude-echo-working.test.ts | 2 +- ...-agent-session-claude-option-queue.test.ts | 2 +- ...d-agent-session-claude-queued-stop.test.ts | 2 +- ...red-agent-session-claude-root-exit.test.ts | 5 +- ...tured-agent-session-codex-stop-row.test.ts | 2 +- ...ed-agent-session-conversation-stop.test.ts | 2 +- ...ured-agent-session-crash-mid-start.test.ts | 2 +- ...tured-agent-session-crash-turn-end.test.ts | 5 +- ...ession-failed-create-owner-verdict.test.ts | 2 +- ...session-failed-create-sink-release.test.ts | 2 +- ...tured-agent-session-grouped-prompt.test.ts | 2 +- ...ed-agent-session-host-test-abandon.test.ts | 2 +- ...uctured-agent-session-host-test-harness.ts | 2 +- .../structured-agent-session-host.test.ts | 3 +- ...ured-agent-session-import-mismatch.test.ts | 3 +- ...ured-agent-session-late-settlement.test.ts | 2 +- ...gent-session-legacy-handoff-record.test.ts | 6 +-- ...ssion-main-agent-working-agreement.test.ts | 2 +- ...ed-agent-session-option-settlement.test.ts | 2 +- ...ed-agent-session-owed-work-release.test.ts | 2 +- ...ent-session-pre-spawn-first-answer.test.ts | 2 +- ...nt-session-processless-reservation.test.ts | 14 +++-- ...gent-session-provider-child-record.test.ts | 2 +- ...red-agent-session-provider-restore.test.ts | 5 +- ...red-agent-session-provider-started.test.ts | 2 +- ...session-queued-message-rig.test-fixture.ts | 2 +- ...tured-agent-session-recovery-exits.test.ts | 6 +-- ...ctured-agent-session-refusal-retry.test.ts | 2 +- .../structured-agent-session-rest-test-rig.ts | 4 +- ...ssion-restart-interruption-test-harness.ts | 2 +- ...session-restart-status-publication.test.ts | 5 +- ...tured-agent-session-rewind-at-rest.test.ts | 6 +-- .../structured-agent-session-rewind.test.ts | 2 +- ...agent-session-send-open-stale-turn.test.ts | 3 +- ...red-agent-session-send-preparation.test.ts | 2 +- ...session-send-restarts-failed-start.test.ts | 2 +- ...agent-session-settled-attach-retry.test.ts | 6 +-- ...agent-session-start-failure-writer.test.ts | 2 +- ...red-agent-session-surface-lifetime.test.ts | 6 +-- ...sion-view-start-after-failed-start.test.ts | 2 +- ...t-session-wedged-profile-migration.test.ts | 7 ++- .../structured-conversation-command.test.ts | 2 +- ...-session-older-build-lease.test-fixture.ts | 8 +-- .../agent-session-record-store-file.ts | 4 ++ ...-record-store-legacy-handoff-lease.test.ts | 18 ++++--- ...ent-session-record-store-tab-table.test.ts | 6 +-- ...agent-session-record-store-test-harness.ts | 52 +++++++++++++------ .../agent-session-record-store.test.ts | 16 +++--- .../rpc/methods/agent-launch-replay.test.ts | 6 +-- ...ured-agent-session-adoption-replay.test.ts | 2 +- .../structured-agent-session-hold.test.ts | 2 +- .../methods/structured-chat-tab-table.test.ts | 10 ++-- ...ructured-agent-session-integration.test.ts | 2 +- ...ent-session-rollback-compatibility.test.ts | 19 ++++--- .../structured-agent-session-runtime.ts | 12 ++--- ...nt-session-spawn-token-descendants.test.ts | 2 +- .../structured-claude-pending-rewind.test.ts | 2 +- ...ss-version-agent-session-wire.unit.test.ts | 4 +- ...-chat-owner-status-activation.unit.test.ts | 4 +- 66 files changed, 180 insertions(+), 167 deletions(-) diff --git a/src/main/claude/claude-api-retry-idle-sweep.test.ts b/src/main/claude/claude-api-retry-idle-sweep.test.ts index 97b0734cb8f4..7f3511930292 100644 --- a/src/main/claude/claude-api-retry-idle-sweep.test.ts +++ b/src/main/claude/claude-api-retry-idle-sweep.test.ts @@ -53,7 +53,7 @@ beforeEach(async () => { sink = null clock = NOW closeSession = vi.fn(async () => true) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const adapter: StructuredAgentSessionAdapter = { acquire: async ({ fence, spawnToken, events }) => { sink = events ?? null diff --git a/src/main/codex/codex-structured-question-order.test.ts b/src/main/codex/codex-structured-question-order.test.ts index cfc84ab36c93..069fe4eb048e 100644 --- a/src/main/codex/codex-structured-question-order.test.ts +++ b/src/main/codex/codex-structured-question-order.test.ts @@ -91,7 +91,7 @@ beforeEach(async () => { answerPrompt: vi.fn(async ({ commit }) => commit()), setOption: vi.fn(async () => undefined) } - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts index 4b8ff7c73ae1..b7371ee40f36 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts @@ -110,7 +110,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) await startHost() expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts index 25cc6dd568be..a0d2f0fdb7dd 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.ts @@ -117,7 +117,7 @@ function expectSettledAttachLease(record: AgentSessionRecord | null): void { describe('structured session acquisition options', () => { it('samples provider history before acquiring a replacement child', async () => { root = await mkdtemp(join(tmpdir(), 'orca-history-before-acquire-')) - const initialStore = await openTestAgentSessionRecordStore(join(root, 'store')) + const initialStore = await openTestAgentSessionRecordStore(root) let childAcquired = false const historyWindow = (): ProviderHistoryWindow => ({ items: [], @@ -179,7 +179,7 @@ describe('structured session acquisition options', () => { fence: 1 }) await firstJournal!.close() - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) await store.reconcileOnRestart({ probe: async () => ({ outcome: 'pid-absent' }), now: NOW + 1 @@ -213,7 +213,7 @@ describe('structured session acquisition options', () => { it('persists create defaults before the first provider acquisition', async () => { root = await mkdtemp(join(tmpdir(), 'orca-create-options-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const sessionAdapter = adapter({ origin: 'created' }) const options = { model: 'gpt-5.6-sol', effort: 'medium', fastMode: 'false' } const recordPhase = vi.fn() @@ -244,7 +244,7 @@ describe('structured session acquisition options', () => { it('replays a create retried after the host re-resolved different options', async () => { root = await mkdtemp(join(tmpdir(), 'orca-create-retry-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const sessionAdapter = adapter({ origin: 'created' }) const attempt = async (options: Readonly>, spawnToken: string) => performAttach({ @@ -275,8 +275,7 @@ describe('structured session acquisition options', () => { it('persists provider options before proving a resumed legacy record', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-options-')) - const storeDir = join(root, 'store') - const store = await openTestAgentSessionRecordStore(storeDir) + const store = await openTestAgentSessionRecordStore(root) const created = await performAttach({ store, @@ -302,7 +301,7 @@ describe('structured session acquisition options', () => { now: NOW }) - const resumedStore = await openTestAgentSessionRecordStore(storeDir) + const resumedStore = await openTestAgentSessionRecordStore(root) await resumedStore.reconcileOnRestart({ probe: async () => ({ outcome: 'pid-absent' }), now: NOW + 1 @@ -331,7 +330,7 @@ describe('structured session acquisition options', () => { }) expect(resumed).toMatchObject({ ok: true }) - const reopened = await openTestAgentSessionRecordStore(storeDir) + const reopened = await openTestAgentSessionRecordStore(root) expect(reopened.getRecord(SESSION)?.options).toEqual({ approvalPolicy: 'on-request', personality: 'concise', @@ -343,7 +342,7 @@ describe('structured session acquisition options', () => { it('clears a rejected Fast restore instead of retaining the prior encoded value', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-fast-restore-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const sessionAdapter = adapter({ origin: 'created', options: { current: { model: 'gpt-standard' }, models: [] }, @@ -375,7 +374,7 @@ describe('structured session acquisition options', () => { it('releases an acquisition when provider options cannot be read', async () => { root = await mkdtemp(join(tmpdir(), 'orca-acquisition-options-failure-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const releaseAcquisition = vi.fn(async () => true) const failingAdapter: StructuredAgentSessionAdapter = { ...adapter({ origin: 'created' }), @@ -426,8 +425,7 @@ describe('structured session acquisition options', () => { ] as const)('atomically settles the lease and operation after %s', async (_case, cleanup) => { const exitProven = cleanup === true root = await mkdtemp(join(tmpdir(), `orca-acquisition-${failurePoint}-`)) - const storeDir = join(root, 'store') - const store = await openTestAgentSessionRecordStore(storeDir) + const store = await openTestAgentSessionRecordStore(root) const base = adapter({ origin: 'created', options: { current: { model: 'gpt-5.6-terra' }, models: [] } @@ -514,7 +512,7 @@ describe('structured session acquisition options', () => { exitProven ? injected.message : 'agent_session_acquisition_exit_unproven' )) - const reopened = await openTestAgentSessionRecordStore(storeDir) + const reopened = await openTestAgentSessionRecordStore(root) const failedRecord = reopened.getRecord(SESSION) expectSettledAttachLease(failedRecord) expect( @@ -577,7 +575,7 @@ describe('structured session acquisition options', () => { describe('the tab a create reserves', () => { async function openStore() { root = await mkdtemp(join(tmpdir(), 'orca-surface-tab-id-')) - return openTestAgentSessionRecordStore(join(root, 'store')) + return openTestAgentSessionRecordStore(root) } function attachWith(store: AgentSessionRecordStore, surfaceTabId?: string) { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts index df5f46500958..6bb43fb9d31d 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-adopted-import.test.ts @@ -120,7 +120,7 @@ async function attach( sessionAdapter: StructuredAgentSessionAdapter, onAttached: AttachFlowInput['onAttached'] = () => {} ) { - store ??= await openTestAgentSessionRecordStore(join(root!, 'store')) + store ??= await openTestAgentSessionRecordStore(root!) return performAttach({ store, adapter: sessionAdapter, @@ -231,7 +231,7 @@ describe('adopting a provider conversation on create', () => { root = await mkdtemp(join(tmpdir(), 'orca-adopt-host-failure-')) const transcriptPath = join(root, 'rollout.jsonl') await writeCodexRollout(transcriptPath, 'valid source') - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts index 0585b330420e..bda7cc9330f2 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-append-delivery.test.ts @@ -126,7 +126,7 @@ beforeEach(async () => { acquisitionGeneration: `generation-${++generation}`, providerChildPhase: 'starting' as const })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts index 57ad992fd771..b456bacac26e 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-compact-stop.test.ts @@ -68,7 +68,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => adapterNow }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, // The production router is what declares create support; the bare adapter only knows locations. diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts index bb4022924c39..1ba4f13e4ea8 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-echo-working.test.ts @@ -64,7 +64,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts index c51ce418ec8f..6398d96ab0a1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-option-queue.test.ts @@ -81,7 +81,7 @@ beforeEach(async () => { resetHostTestOperationIds() activeModel = DEFAULT_MODEL optionWritable = Promise.resolve() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts index 8ccc268ee241..f78be712f7cf 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts @@ -80,7 +80,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts index 59f8aad20cc2..7cfd7fe86234 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-claude-root-exit.test.ts @@ -31,7 +31,8 @@ describe('Claude root-exit stop', () => { it('releases a captured live claim after the provider root exits', async () => { const root = await mkdtemp(join(tmpdir(), 'orca-claude-root-exit-')) roots.push(root) - const store = await openTestAgentSessionRecordStore(root) + const stateDirectory = join(root, 'journal') + const store = await openTestAgentSessionRecordStore(stateDirectory) const claude = fakeClaude({ unprovenCloseVerdict: { root: 'exited', tree: 'unverifiable' } }) @@ -78,7 +79,7 @@ describe('Claude root-exit stop', () => { }) const journal = await journals.open({ identity: { ...identityFor(), hostId: 'local', workspaceId: 'folder-1' }, - stateDirectory: join(root, 'journal') + stateDirectory }) const close = vi.spyOn(journal, 'close') const publishStatus = vi.fn() diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts index f4d19388029c..8833ac4ee31b 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-codex-stop-row.test.ts @@ -49,7 +49,7 @@ beforeEach(async () => { ) return {} } - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapterFor(codex), { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts index 4eeff810dd4a..2eeae4787ce5 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts @@ -49,7 +49,7 @@ beforeEach(async () => { dispatch = vi.fn(async () => ({ state: 'admitted' as const })) cancelTurn = vi.fn(async () => ({ cancelled: true })) awaitStarted = vi.fn(async () => undefined) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts index 87d7ba1a79e4..22295ea6e864 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-mid-start.test.ts @@ -59,7 +59,7 @@ async function crash(dying: AgentSessionRecordStore): Promise { } function openStore(generation: HostGeneration): Promise { - return openTestAgentSessionRecordStore(join(generationRoot(generation), 'store')) + return openTestAgentSessionRecordStore(generationRoot(generation)) } /** A Codex adapter whose child spawns, reports its pid the way the real connection does, and then diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts index 54bd2789c00f..c7f8f09631a2 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-crash-turn-end.test.ts @@ -99,9 +99,8 @@ function crashedClaudeRecord(): AgentSessionRecord { } async function seedCrashedStore(): Promise { - const directory = join(root, 'store') - await seedTestAgentSessionRecordStore(directory, { records: [crashedClaudeRecord()] }) - store = await openTestAgentSessionRecordStore(directory) + await seedTestAgentSessionRecordStore(root, { records: [crashedClaudeRecord()] }) + store = await openTestAgentSessionRecordStore(root) } /** A running turn whose only row after its start is a Bash call that never reported back, for a diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts index 8d0f31367fb7..d1a45fc469a7 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-owner-verdict.test.ts @@ -49,7 +49,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts index 9e88829aad31..06538d783109 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts @@ -45,7 +45,7 @@ beforeEach(async () => { }, acquisitionGeneration: `generation-${fence}` })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts index 29f6eabf703c..7c37b9542536 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts @@ -131,7 +131,7 @@ beforeEach(async () => { } })) answerPrompt = vi.fn(async ({ commit }) => commit()) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts index 0d1dfc5d6cb1..4d064cbdfaa6 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-abandon.test.ts @@ -25,7 +25,7 @@ const CALLER = { callerKey: 'client-1' } describe('abandoning a structured agent-session host', () => { it('waits for the restart the delivery loop woke for an accepted send', async () => { const root = await mkdtemp(join(tmpdir(), 'orca-abandon-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) // Holds the restart inside its provider acquisition, so the point teardown must not run past // is exact rather than a timing window. let gate: Promise | null = null diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts index f3528123f998..1a701f5b13cc 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts @@ -148,7 +148,7 @@ beforeEach(async () => { cancelTurn = vi.fn(async () => ({ cancelled: true })) answerPrompt = vi.fn(async ({ commit }) => commit()) setOption = vi.fn(async () => undefined) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts index 78454b675026..46bd84905921 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts @@ -4,7 +4,6 @@ import { agentJournalItemKey } from '../../../shared/agent-session-journal-item- import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease-adjudication' import type { AgentSessionRecord } from '../../../shared/agent-session-record' import type { AgentSessionSubscribeEvent } from '../../../shared/agent-session-wire' -import { join } from 'node:path' import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import type { AgentSessionJournal } from '../agent-session-journal/journal-store' @@ -561,7 +560,7 @@ describe('restart', () => { adapterOverrides: Partial = {}, stopOwnerProcess?: StructuredAgentSessionHostDeps['stopOwnerProcess'] ) { - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { ...adapter(), ...adapterOverrides }, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts index 8d96bf346320..a173a3ad6619 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-import-mismatch.test.ts @@ -2,7 +2,6 @@ // loaded: on a send and a Stop as on a read. Each retry runs the same copy, so "try again" is wrong. import { cp, rm } from 'node:fs/promises' -import { join } from 'node:path' import { afterEach, beforeEach, expect, it, vi } from 'vitest' import { openTestAgentSessionRecordStore } from '../../runtime/agent-session-record-store-test-harness' import { openTestJournalHostDatabase } from '../agent-session-journal/journal-host-database-test-support' @@ -92,7 +91,7 @@ async function relaunchWithMismatchedCopy(): Promise recursive: true, filter: (source) => !source.includes('.lock') }) - const store = await openTestAgentSessionRecordStore(join(relaunched, 'store')) + const store = await openTestAgentSessionRecordStore(relaunched) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts index 5383914012a9..510384f3e484 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts @@ -93,7 +93,7 @@ beforeEach(async () => { resetHostTestOperationIds() dispatch = vi.fn(async () => accepted()) closeSession = vi.fn(async () => true) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts index e936ef337a2a..706d0d8fc3f3 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-legacy-handoff-record.test.ts @@ -73,8 +73,8 @@ async function persistFromOlderBuild(lease: OlderBuildLease): Promise { const attached = store.getRecord(SESSION)?.lease await host.flushAllStreamedEvents() // Over the attached owner: the older build's stage or terminal owner kept it from releasing. - await writeOlderBuildLease(join(root, 'store'), SESSION, { ...attached, ...lease }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + await writeOlderBuildLease(root, SESSION, { ...attached, ...lease }) + store = await openTestAgentSessionRecordStore(root) acquire.mockClear() openHost() } @@ -131,7 +131,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts index 5e53dadf8beb..333b5bf3e019 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-main-agent-working-agreement.test.ts @@ -59,7 +59,7 @@ beforeEach(async () => { listed = undefined // Written, and the provider has neither opened a turn for it nor answered it. dispatch = vi.fn(async () => ({ state: 'admitted' as const })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts index ea7abc170c35..1ec8f2784a28 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-option-settlement.test.ts @@ -121,7 +121,7 @@ beforeEach(async () => { closeSessionExit = true dispatchedModels.length = 0 const accountHome = join(root, 'codex-home') - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) router = adapter() host = new StructuredAgentSessionHost({ store, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts index ab77dea332c9..6ad1506e2aa3 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-owed-work-release.test.ts @@ -86,7 +86,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts index d3fb132954f7..db9406785f87 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-pre-spawn-first-answer.test.ts @@ -66,7 +66,7 @@ function createParams(): AgentSessionAttachParams { /** The thrown first answer as the wire sends it, and the ledger's replay of the same operation. */ async function firstAnswerAndReplay(thrown: AgentSessionPreSpawnError) { root = await mkdtemp(join(tmpdir(), 'orca-pre-spawn-first-answer-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const unused = async (): Promise => { throw new Error('not reached before a spawn') } diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts index b6df344d01ac..9df12ea96fde 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-processless-reservation.test.ts @@ -68,7 +68,7 @@ function attachParams( describe('processless structured session reservation', () => { it('refuses an adapter that declares no create support before reserving a lease', async () => { root = await mkdtemp(join(tmpdir(), 'orca-unsupported-attach-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const reserveOwner = vi.spyOn(store, 'reserveOwner') const acquire = vi.fn() const adapter = { @@ -106,7 +106,7 @@ describe('processless structured session reservation', () => { it('refuses a replay when adapter support drifts after durable reservation', async () => { root = await mkdtemp(join(tmpdir(), 'orca-replay-support-drift-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const supportsCreate = vi .fn>() .mockReturnValueOnce(true) @@ -153,7 +153,7 @@ describe('processless structured session reservation', () => { it('releases a new reservation when support drifts before acquisition', async () => { root = await mkdtemp(join(tmpdir(), 'orca-support-drift-reservation-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const supportsCreate = vi .fn>() .mockReturnValueOnce(true) @@ -205,8 +205,7 @@ describe('processless structured session reservation', () => { it('settles a pre-spawn failure and its processless evidence in one durable transaction', async () => { root = await mkdtemp(join(tmpdir(), 'orca-processless-reservation-')) - const storeDir = join(root, 'store') - const store = await openTestAgentSessionRecordStore(storeDir) + const store = await openTestAgentSessionRecordStore(root) const adapter = { acquire: vi.fn(async () => { throw new AgentSessionPreSpawnError(new Error('workspace no longer exists')) @@ -244,7 +243,7 @@ describe('processless structured session reservation', () => { }) expect(store.listOperationRows()[0]?.outcome).toMatchObject({ status: 'failed' }) - const reopened = await openTestAgentSessionRecordStore(storeDir) + const reopened = await openTestAgentSessionRecordStore(root) await reopened.reconcileOnRestart({ probe: async () => ({ outcome: 'indeterminate', reason: 'no owner to probe' }), now: NOW + 1 @@ -258,8 +257,7 @@ describe('processless structured session reservation', () => { it('does not rerun a settled pre-spawn failure and admits a fresh operation', async () => { root = await mkdtemp(join(tmpdir(), 'orca-processless-retry-')) - const storeDir = join(root, 'store') - const store = await openTestAgentSessionRecordStore(storeDir) + const store = await openTestAgentSessionRecordStore(root) const adapter = { acquire: vi .fn() diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts index c302a5771561..75061435a1fe 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts @@ -116,7 +116,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) startHost() expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) await host.close(SESSION) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts index 3466c5e4dfd6..411e148c586c 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-restore.test.ts @@ -78,8 +78,7 @@ describe('structured session provider restore', () => { it('restores a durable Claude session tab with its recorded provider', async () => { root = await mkdtemp(join(tmpdir(), 'orca-provider-restore-')) resetHostTestOperationIds() - const storeDirectory = join(root, 'store') - const store = await openTestAgentSessionRecordStore(storeDirectory) + const store = await openTestAgentSessionRecordStore(root) const host = createHost(store) const attached = await host.attach( { callerKey: 'client-1' }, @@ -92,7 +91,7 @@ describe('structured session provider restore', () => { ) expect(attached).toMatchObject({ ok: true }) - const reopenedStore = await openTestAgentSessionRecordStore(storeDirectory) + const reopenedStore = await openTestAgentSessionRecordStore(root) const restarted = createHost(reopenedStore, async () => ({ outcome: 'indeterminate', reason: 'read does not need ownership' diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts index 9b3cd4bc378a..ff4b5e9c4ee8 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-provider-started.test.ts @@ -73,7 +73,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, // The production router is what declares create support; the bare adapter only knows locations. diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts index bb86b5e39c1d..9aed0d4acb84 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-queued-message-rig.test-fixture.ts @@ -52,7 +52,7 @@ export async function createQueuedMessageTestRig() { providerIdentity: null })) let events: StructuredAgentSessionEventSink | undefined - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts index 66723f45654a..f69fbad10316 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-recovery-exits.test.ts @@ -93,7 +93,7 @@ function openHost(overrides: Partial = {}): void async function reopenStore(): Promise { await abandonStructuredAgentSessionHost(host) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) } beforeEach(async () => { @@ -114,7 +114,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() }) @@ -297,7 +297,7 @@ describe('recovery exits', () => { const outgoingHost = host const outgoingStore = store supersededHosts.add(outgoingHost) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) const realProbe = createStructuredAgentSessionOwnerProbe('local') let overlapDriven = false openHost({ diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts index 9d84252472b5..09ba97ee8e31 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-refusal-retry.test.ts @@ -59,7 +59,7 @@ function operationId(timestamp = NOW): string { async function createHarness(options: { attached?: boolean } = {}) { const root = await mkdtemp(join(tmpdir(), 'orca-refusal-oracle-')) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const setOption = vi.fn(async () => undefined) const adapter: StructuredAgentSessionAdapter = { acquire: async ({ fence }) => ({ diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts index a95b1fed8683..0c890767ac22 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rest-test-rig.ts @@ -127,7 +127,7 @@ export async function createRestTestRig( const clock = { now: HOST_TEST_NOW } const statusEvents: AgentSessionStatusEvent[] = [] const sink = { publish: vi.fn(), forget: vi.fn() } - let store = await openTestAgentSessionRecordStore(join(root, 'store')) + let store = await openTestAgentSessionRecordStore(root) const adapter: RestTestAdapter = { acquire: vi.fn(async ({ fence, spawnToken }) => ({ acquisitionGeneration: `generation-${++generations}`, @@ -178,7 +178,7 @@ export async function createRestTestRig( sink, restart: async (overrides = {}) => { await rig.host.flushAllStreamedEvents().catch(() => undefined) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) rig.store = store rig.host = hostFor(overrides) rig.host.subscribeStatus({ id: 'status', emit: (event) => statusEvents.push(event) }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts index 7f425f61a7ea..3bf122afde3a 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts @@ -116,7 +116,7 @@ export async function interruptedRestart( } await previous.host.flushStreamedEvents(SESSION) await previous.host.flushAllStreamedEvents() - const store = await openTestAgentSessionRecordStore(join(previous.root, 'store')) + const store = await openTestAgentSessionRecordStore(previous.root) const closeSession = vi.fn(async () => true) // The relaunch comes after the quit that recorded the offer. const clock = { now: NOW + 1 } diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts index 601eed15c3e3..35425a70afe8 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-restart-status-publication.test.ts @@ -92,8 +92,7 @@ function sendEnvelope( async function restartWithPersistedTurn(): Promise { root = await mkdtemp(join(tmpdir(), 'orca-restart-status-')) resetHostTestOperationIds() - const directory = join(root, 'store') - const store = await openTestAgentSessionRecordStore(directory) + const store = await openTestAgentSessionRecordStore(root) const host = createHost(store) expect(await host.attach(CALLER, hostTestAttachParams(null))).toMatchObject({ ok: true }) const body = hostTestMessage('persisted conversation') @@ -104,7 +103,7 @@ async function restartWithPersistedTurn(): Promise { // Delivered, not just accepted: a message still queued at the restart was never a request. await host.waitForSendSettlement(SESSION, sent.value.clientMessageId) await host.flushAllStreamedEvents() - return createHost(await openTestAgentSessionRecordStore(directory)) + return createHost(await openTestAgentSessionRecordStore(root)) } afterEach(async () => { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts index c1fb0009346f..b34de39b74f1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind-at-rest.test.ts @@ -107,7 +107,7 @@ beforeEach(async () => { } })) directory = await mkdtemp(join(tmpdir(), 'orca-rewind-rest-')) - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) host = openHost() }) @@ -172,7 +172,7 @@ async function interruptedRewindAtRest(): Promise { ) expect(store.getRecord(SESSION)?.rewind).toMatchObject({ phase: 'prepared' }) await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) host = openHost() } @@ -207,7 +207,7 @@ describe('a rewind asked of a chat at rest (P2-23)', () => { await host.flushStreamedEvents(SESSION) const epoch = (await host.journalSnapshot(SESSION)).cursor.epoch await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) host = openHost() const before = acquires rewindSupport.mockReturnValue({ supported: false, reason: 'history-not-paginated' }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts index 8232d287f63f..35e7d5af2e27 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-rewind.test.ts @@ -54,7 +54,7 @@ beforeEach(async () => { }) acquires = [] directory = await mkdtemp(join(tmpdir(), 'orca-rewind-')) - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) adapter = { supportsCreate: (_location, agent) => agent === 'codex', supportsLocation: () => true, diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts index e5a8388f7794..c85c628d9175 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-open-stale-turn.test.ts @@ -5,7 +5,6 @@ import { AGENT_JOURNAL_THREAD_SCOPE } from '../../../shared/agent-session-journa // new child starts: a start that then fails would leave the turn running for every reader. import { cp, rm } from 'node:fs/promises' -import { join } from 'node:path' import { afterEach, expect, it, vi } from 'vitest' import type { AgentSessionOwnerProbe } from '../../../shared/agent-session-lease-adjudication' import { readAgentJournalTurn } from '../../../shared/agent-session-turn-record' @@ -66,7 +65,7 @@ async function relaunchAfterCrashMidTurn( recursive: true, filter: (source) => !source.includes('.lock') }) - const store = await openTestAgentSessionRecordStore(join(relaunched, 'store')) + const store = await openTestAgentSessionRecordStore(relaunched) const acquire = vi.fn(async () => { throw new Error('claude: command not found') }) diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts index 8fc9cbbf75f1..fbe81be21ac1 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts @@ -69,7 +69,7 @@ beforeEach(async () => { ordinal: dispatch.mock.calls.length } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts index c6f387a68b1c..21e50e4dca60 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-send-restarts-failed-start.test.ts @@ -144,7 +144,7 @@ beforeEach(async () => { providerChildPhase: 'starting' as const })) dispatch = vi.fn(async () => ({ state: 'admitted' as const })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts index 462111f14ade..2d868797024c 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-settled-attach-retry.test.ts @@ -110,7 +110,7 @@ beforeEach(async () => { })) releaseAcquisition = vi.fn(async () => true) dispatch = vi.fn(async () => accepted()) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), @@ -268,7 +268,7 @@ describe('settled attach retry', () => { }) await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), @@ -325,7 +325,7 @@ describe('settled attach retry', () => { await vi.waitFor(() => expect(dispatch).toHaveBeenCalledTimes(1)) await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts index 517d136b581f..e5527d1a5afb 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-start-failure-writer.test.ts @@ -118,7 +118,7 @@ beforeEach(async () => { awaitStarted = vi.fn( () => new Promise((resolve) => (settleStart = resolve)) ) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts index c25c92d6affb..a06c70bf30ad 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-surface-lifetime.test.ts @@ -92,7 +92,7 @@ function openHost( /** A fresh app generation over the same durable store, with its owner proven gone. */ async function reboot(): Promise { await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost(async () => ({ outcome: 'pid-absent' })) acquire.mockClear() closeSession.mockClear() @@ -232,7 +232,7 @@ beforeEach(async () => { surface: 'rejection' }) })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() }) @@ -401,7 +401,7 @@ describe('startup', () => { const beforeRestart = store.getRecord(SESSION) await abandonStructuredAgentSessionHost(host) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost(async () => ({ outcome: 'pid-absent' })) await host.restoreReadableSessions() diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts index ac773034ced6..3d38c1cb38d2 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-view-start-after-failed-start.test.ts @@ -82,7 +82,7 @@ beforeEach(async () => { readProcessStartTime: async () => 1_700_000_000_000, now: () => NOW }) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: Object.assign(adapter, { supportsCreate: () => true }), diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts index 72d88caa226d..3ae6da5fa493 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.ts @@ -114,9 +114,8 @@ function wedgedRecord(overrides: WedgeOverrides): PersistedAgentSessionRecord { } async function seedStore(record: PersistedAgentSessionRecord): Promise { - const directory = join(root, 'store') - await seedTestAgentSessionRecordStore(directory, { records: [record] }) - store = await openTestAgentSessionRecordStore(directory) + await seedTestAgentSessionRecordStore(root, { records: [record] }) + store = await openTestAgentSessionRecordStore(root) } /** Every recorded owner in these fixtures is long gone; that is the present-time evidence. */ @@ -274,7 +273,7 @@ describe('already-wedged profiles become usable on load', () => { expect(acquire).not.toHaveBeenCalled() await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() await host.restoreReadableSessions() diff --git a/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts b/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts index 220b12f1d4a3..89b07045b3d5 100644 --- a/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts +++ b/src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts @@ -62,7 +62,7 @@ const generationRoot = () => join(directory, `generation-${generation}`) let ownerProbe: AgentSessionOwnerProbe = { outcome: 'pid-absent' } async function openHost(): Promise { - store = await openTestAgentSessionRecordStore(join(generationRoot(), 'store')) + store = await openTestAgentSessionRecordStore(generationRoot()) host = new StructuredAgentSessionHost({ store, adapter, diff --git a/src/main/runtime/agent-session-older-build-lease.test-fixture.ts b/src/main/runtime/agent-session-older-build-lease.test-fixture.ts index 869f8ddc14c2..d5cc9defe28c 100644 --- a/src/main/runtime/agent-session-older-build-lease.test-fixture.ts +++ b/src/main/runtime/agent-session-older-build-lease.test-fixture.ts @@ -6,18 +6,18 @@ import { /** Rewrites one lease on disk as an older build left it; this build's types cannot express it. */ export async function writeOlderBuildLease( - directory: string, + stateDirectory: string, sessionId: string, fields: Partial ): Promise { - await editPersistedTestAgentSessionStore(directory, (persisted) => { + await editPersistedTestAgentSessionStore(stateDirectory, (persisted) => { persisted.records[sessionId].lease = { ...persisted.records[sessionId].lease, ...fields } }) } export async function readPersistedLease( - directory: string, + stateDirectory: string, sessionId: string ): Promise> { - return (await readPersistedTestAgentSessionStore(directory)).records[sessionId].lease + return (await readPersistedTestAgentSessionStore(stateDirectory)).records[sessionId].lease } diff --git a/src/main/runtime/agent-session-record-store-file.ts b/src/main/runtime/agent-session-record-store-file.ts index ef0f4b1ab7f5..0aa32f74f755 100644 --- a/src/main/runtime/agent-session-record-store-file.ts +++ b/src/main/runtime/agent-session-record-store-file.ts @@ -28,6 +28,10 @@ import { serializeAgentSessionStoreState } from './agent-session-store-serializa export const AGENT_SESSION_STORE_SCHEMA_VERSION = 2 as const +/** In a host's state directory, beside the journal database: one file adjudicates every session's + * lease. */ +export const AGENT_SESSION_STORE_DIR_NAME = 'agent-sessions' + export const AGENT_SESSION_STORE_FILE_NAME = 'agent-sessions.json' export type RetiredAgentSessionClaimKey = { keyId: string; retiredAt: number } diff --git a/src/main/runtime/agent-session-record-store-legacy-handoff-lease.test.ts b/src/main/runtime/agent-session-record-store-legacy-handoff-lease.test.ts index c614cfa5515f..4180af2580b3 100644 --- a/src/main/runtime/agent-session-record-store-legacy-handoff-lease.test.ts +++ b/src/main/runtime/agent-session-record-store-legacy-handoff-lease.test.ts @@ -12,8 +12,11 @@ import { readPersistedLease, writeOlderBuildLease } from './agent-session-older-build-lease.test-fixture' -import { AgentSessionRecordStore } from './agent-session-record-store' -import { agentSessionStorePath } from './agent-session-record-store-file' +import type { AgentSessionRecordStore } from './agent-session-record-store' +import { + openTestAgentSessionRecordStore, + testAgentSessionStoreFilePath +} from './agent-session-record-store-test-harness' const NOW = 1_800_000_000_000 const SESSION = 'session-alpha' @@ -29,8 +32,7 @@ afterEach(async () => { await rm(directory, { recursive: true, force: true }) }) -const open = (): Promise => - AgentSessionRecordStore.open({ directory, hostId: 'local' }) +const open = (): Promise => openTestAgentSessionRecordStore(directory) async function persistLiveOwner(): Promise { const store = await open() @@ -89,7 +91,7 @@ describe('a lease the removed terminal handoff wrote', () => { handoffStage: 'old-owner-stopped', handoffOperationId: 'op-handoff' }) - const legacy = await readFile(agentSessionStorePath(directory), 'utf-8') + const legacy = await readFile(testAgentSessionStoreFilePath(directory), 'utf-8') const store = await open() expect(store.isSessionUnreadable(SESSION)).toBe(false) @@ -100,7 +102,7 @@ describe('a lease the removed terminal handoff wrote', () => { claimStatus: 'conflicted' }) // An open does not write: another holder of the file mid-restart would read it as a change. - expect(await readFile(agentSessionStorePath(directory), 'utf-8')).toBe(legacy) + expect(await readFile(testAgentSessionStoreFilePath(directory), 'utf-8')).toBe(legacy) // A transaction that changes nothing still writes it. Had the open's revision been taken over // anything but the normalized state, this would read the file as externally changed and @@ -127,8 +129,8 @@ describe('a lease the removed terminal handoff wrote', () => { claimStatus: 'conflicted', handoffStage: 'recovering' }) - const settled = await readFile(agentSessionStorePath(directory), 'utf-8') + const settled = await readFile(testAgentSessionStoreFilePath(directory), 'utf-8') await open() - expect(await readFile(agentSessionStorePath(directory), 'utf-8')).toBe(settled) + expect(await readFile(testAgentSessionStoreFilePath(directory), 'utf-8')).toBe(settled) }) }) diff --git a/src/main/runtime/agent-session-record-store-tab-table.test.ts b/src/main/runtime/agent-session-record-store-tab-table.test.ts index 696eb5fd1cb0..c5d4be5319cf 100644 --- a/src/main/runtime/agent-session-record-store-tab-table.test.ts +++ b/src/main/runtime/agent-session-record-store-tab-table.test.ts @@ -13,9 +13,9 @@ import { isAgentSessionRefusalError } from '../../shared/agent-session-wire-refu import type { AgentSessionRecordStore } from './agent-session-record-store' import { openTestAgentSessionRecordStore, - readPersistedTestAgentSessionStore + readPersistedTestAgentSessionStore, + testAgentSessionStoreFilePath } from './agent-session-record-store-test-harness' -import { agentSessionStorePath } from './agent-session-record-store-file' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -70,7 +70,7 @@ async function open(): Promise { describe('chat tab table', () => { const LEGACY_TAB_ID = 'structured-agent-session-session-alpha' - const filePath = () => agentSessionStorePath(directory) + const filePath = () => testAgentSessionStoreFilePath(directory) const readFileJson = async () => JSON.parse(await readFile(filePath(), 'utf-8')) it('takes a reserved id only when the tab is shown, and refuses it to a second chat', async () => { diff --git a/src/main/runtime/agent-session-record-store-test-harness.ts b/src/main/runtime/agent-session-record-store-test-harness.ts index d590ecd296d1..74af065cd01b 100644 --- a/src/main/runtime/agent-session-record-store-test-harness.ts +++ b/src/main/runtime/agent-session-record-store-test-harness.ts @@ -1,13 +1,17 @@ /** * The one way tests open, seed and read back the durable agent-session record store, so a change - * to where or how the store persists is made here rather than in every test that uses it. + * to where or how the store persists is made here rather than in every test that uses it. Every + * function takes the host's state directory, the one its journal database lives in, and keeps the + * store where the runtime does within it. */ import { mkdir, readFile, writeFile } from 'node:fs/promises' +import { join } from 'node:path' import type { AgentSessionOperationRow } from '../../shared/agent-session-operation-ledger' import type { PersistedAgentSessionRecord } from '../../shared/agent-session-legacy-handoff-lease' import { AgentSessionRecordStore } from './agent-session-record-store' import { + AGENT_SESSION_STORE_DIR_NAME, AGENT_SESSION_STORE_SCHEMA_VERSION, agentSessionStorePath, type RetiredAgentSessionClaimKey @@ -15,6 +19,15 @@ import { const TEST_HOST_ID = 'local' +function storeDirectory(stateDirectory: string): string { + return join(stateDirectory, AGENT_SESSION_STORE_DIR_NAME) +} + +/** The store's file, for the tests that assert on or damage its bytes directly. */ +export function testAgentSessionStoreFilePath(stateDirectory: string): string { + return agentSessionStorePath(storeDirectory(stateDirectory)) +} + /** One committed state of the store, as tests seed it and read it back. */ export type PersistedTestAgentSessionStore = { schemaVersion: number @@ -27,17 +40,20 @@ export type PersistedTestAgentSessionStore = { sessionTabs?: { tabId: string; sessionId: string }[] } -/** Opens, or reopens, the store kept in `directory`: what a fresh app process does at launch. */ +/** Opens, or reopens, the store in `stateDirectory`: what a fresh app process does at launch. */ export function openTestAgentSessionRecordStore( - directory: string, + stateDirectory: string, options: { hostId?: string } = {} ): Promise { - return AgentSessionRecordStore.open({ directory, hostId: options.hostId ?? TEST_HOST_ID }) + return AgentSessionRecordStore.open({ + directory: storeDirectory(stateDirectory), + hostId: options.hostId ?? TEST_HOST_ID + }) } /** Leaves `records` behind as an earlier run of the app would have, before anything opens it. */ export async function seedTestAgentSessionRecordStore( - directory: string, + stateDirectory: string, seed: { records: readonly PersistedAgentSessionRecord[] } ): Promise { const persisted: PersistedTestAgentSessionStore = { @@ -48,37 +64,39 @@ export async function seedTestAgentSessionRecordStore( retiredClaimKeys: [], unusableRecords: {} } - await mkdir(directory, { recursive: true }) - await writeFile(agentSessionStorePath(directory), JSON.stringify(persisted), 'utf-8') + await mkdir(storeDirectory(stateDirectory), { recursive: true }) + await writeFile(testAgentSessionStoreFilePath(stateDirectory), JSON.stringify(persisted), 'utf-8') } /** Leaves an empty store a newer build wrote: this build reads it but never writes it. */ -export async function seedTestAgentSessionStoreFromNewerBuild(directory: string): Promise { - await mkdir(directory, { recursive: true }) +export async function seedTestAgentSessionStoreFromNewerBuild( + stateDirectory: string +): Promise { + await mkdir(storeDirectory(stateDirectory), { recursive: true }) await writeFile( - agentSessionStorePath(directory), + testAgentSessionStoreFilePath(stateDirectory), JSON.stringify({ schemaVersion: 99, hostId: TEST_HOST_ID, records: {}, operations: {} }) ) } /** Everything the store has committed, as text: to assert a value never reached disk, or that an * action wrote nothing by comparing two reads. */ -export function readPersistedTestAgentSessionStoreText(directory: string): Promise { - return readFile(agentSessionStorePath(directory), 'utf-8') +export function readPersistedTestAgentSessionStoreText(stateDirectory: string): Promise { + return readFile(testAgentSessionStoreFilePath(stateDirectory), 'utf-8') } export async function readPersistedTestAgentSessionStore( - directory: string + stateDirectory: string ): Promise { - return JSON.parse(await readPersistedTestAgentSessionStoreText(directory)) + return JSON.parse(await readPersistedTestAgentSessionStoreText(stateDirectory)) } /** Changes the committed state behind the store's back, as an older build or a damaged disk would. */ export async function editPersistedTestAgentSessionStore( - directory: string, + stateDirectory: string, edit: (persisted: PersistedTestAgentSessionStore) => void ): Promise { - const persisted = await readPersistedTestAgentSessionStore(directory) + const persisted = await readPersistedTestAgentSessionStore(stateDirectory) edit(persisted) - await writeFile(agentSessionStorePath(directory), JSON.stringify(persisted)) + await writeFile(testAgentSessionStoreFilePath(stateDirectory), JSON.stringify(persisted)) } diff --git a/src/main/runtime/agent-session-record-store.test.ts b/src/main/runtime/agent-session-record-store.test.ts index 7ea6174da70d..908f843da981 100644 --- a/src/main/runtime/agent-session-record-store.test.ts +++ b/src/main/runtime/agent-session-record-store.test.ts @@ -1,6 +1,6 @@ -import { mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' -import { join } from 'node:path' +import { dirname, join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import type { AgentSessionOwnerProbe } from '../../shared/agent-session-lease-adjudication' import type { @@ -16,13 +16,10 @@ import { editPersistedTestAgentSessionStore, openTestAgentSessionRecordStore, readPersistedTestAgentSessionStore, - seedTestAgentSessionStoreFromNewerBuild + seedTestAgentSessionStoreFromNewerBuild, + testAgentSessionStoreFilePath } from './agent-session-record-store-test-harness' import { AGENT_SESSION_CLAIM_KEY_RETENTION_MS } from './agent-session-claim-key-retention' -import { - agentSessionStorePath, - AGENT_SESSION_STORE_FILE_NAME -} from './agent-session-record-store-file' import type { AgentSessionReserveRequest } from './agent-session-reservation-admission' const NOW = 1_800_000_000_000 @@ -837,7 +834,7 @@ describe('claim keys, checkpoints, and unreadable rows', () => { checkpoint: { epoch: 1, sequence: 1 }, now: NOW }) - await writeFile(join(directory, AGENT_SESSION_STORE_FILE_NAME), '{ truncated') + await writeFile(testAgentSessionStoreFilePath(directory), '{ truncated') const reopened = await open() expect(reopened.recoveredFromBackup).toBe(true) @@ -861,7 +858,8 @@ describe('claim keys, checkpoints, and unreadable rows', () => { ['invalid retired key', [BAD_KEY_STORE]], ['corrupt in both committed copies', ['{ truncated', '{ also truncated']] ])('fails closed when the store is %s', async (_name, copies) => { - const filePath = agentSessionStorePath(directory) + const filePath = testAgentSessionStoreFilePath(directory) + await mkdir(dirname(filePath), { recursive: true }) await writeFile(filePath, copies[0]) if (copies[1]) { await writeFile(`${filePath}.bak`, copies[1]) diff --git a/src/main/runtime/rpc/methods/agent-launch-replay.test.ts b/src/main/runtime/rpc/methods/agent-launch-replay.test.ts index 2cb953063391..bf90e650d534 100644 --- a/src/main/runtime/rpc/methods/agent-launch-replay.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-replay.test.ts @@ -27,9 +27,9 @@ import { import type { AgentSessionRecordStore } from '../../agent-session-record-store' import { openTestAgentSessionRecordStore, - readPersistedTestAgentSessionStore + readPersistedTestAgentSessionStore, + testAgentSessionStoreFilePath } from '../../agent-session-record-store-test-harness' -import { agentSessionStorePath } from '../../agent-session-record-store-file' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { StructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-host' import type { RpcContext } from '../core' @@ -434,7 +434,7 @@ describe('an unreadable launch payload costs one replay, never the store', () => /** The whole file, primary and backup: `loadAgentSessionStore` falls through to the backup, and * the backup is a copy of the validated primary, so both carry the same payload in real life. */ async function rewriteRecordedLaunch(payload: unknown): Promise { - const path = agentSessionStorePath(directory) + const path = testAgentSessionStoreFilePath(directory) const file: { operations: Record }> } = JSON.parse( await readFile(path, 'utf-8') ) diff --git a/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts b/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts index 272cb8bbb92b..90deacab5c3a 100644 --- a/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts +++ b/src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts @@ -176,7 +176,7 @@ describe('committed adopting create RPC replay', () => { .mockRejectedValueOnce(new Error('simulated lost tab publication')) .mockResolvedValue(undefined) - const store = await openTestAgentSessionRecordStore(join(root, 'store')) + const store = await openTestAgentSessionRecordStore(root) const sessionAdapter = adapter() host = new StructuredAgentSessionHost({ store, diff --git a/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts b/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts index 008038cb0190..000192cc183d 100644 --- a/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts +++ b/src/main/runtime/rpc/methods/structured-agent-session-hold.test.ts @@ -76,7 +76,7 @@ beforeEach(async () => { observedAt: NOW } })) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) host = new StructuredAgentSessionHost({ store, adapter: { diff --git a/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts b/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts index 4d6a313f8b5b..29623f623cd0 100644 --- a/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts +++ b/src/main/runtime/rpc/methods/structured-chat-tab-table.test.ts @@ -25,8 +25,10 @@ import { } from '../../../native-chat/agent-session-wire/structured-agent-session-host-test-data' import { setStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/structured-agent-session-registry' import type { AgentSessionRecordStore } from '../../agent-session-record-store' -import { openTestAgentSessionRecordStore } from '../../agent-session-record-store-test-harness' -import { agentSessionStorePath } from '../../agent-session-record-store-file' +import { + openTestAgentSessionRecordStore, + testAgentSessionStoreFilePath +} from '../../agent-session-record-store-test-harness' import { OrcaRuntimeService } from '../../orca-runtime' import { RpcDispatcher } from '../dispatcher' import type { RpcDispatchStreamingOptions } from '../dispatcher-stream-options' @@ -88,7 +90,7 @@ function providerAdapter(): StructuredAgentSessionAdapter { } async function openHost(): Promise { - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) host = new StructuredAgentSessionHost({ store, adapter: providerAdapter(), @@ -292,7 +294,7 @@ describe('a chat tab across /clear', () => { await host.flushAllStreamedEvents() // An older build rewrites the file from what it read, which drops the table. - const file = agentSessionStorePath(join(directory, 'store')) + const file = testAgentSessionStoreFilePath(directory) const raw = JSON.parse(await readFile(file, 'utf-8')) expect(raw.sessionTabs).toHaveLength(2) delete raw.sessionTabs diff --git a/src/main/runtime/structured-agent-session-integration.test.ts b/src/main/runtime/structured-agent-session-integration.test.ts index 2e2d87d65471..efc2f786c99e 100644 --- a/src/main/runtime/structured-agent-session-integration.test.ts +++ b/src/main/runtime/structured-agent-session-integration.test.ts @@ -456,7 +456,7 @@ describe('a structured codex session over agentSession.*', () => { EXAMPLE_GATEWAY_TOKEN: 'shell-exported', CODEX_HOME: '/home/dev/.codex' }) - const store = await readPersistedTestAgentSessionStoreText(join(root, 'agent-sessions')) + const store = await readPersistedTestAgentSessionStoreText(root) expect(store).not.toContain('EXAMPLE_GATEWAY_TOKEN') expect(store).not.toContain('"launchEnv"') const stream = await subscribe('sub-first-send') diff --git a/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts b/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts index 48a9d33142c2..c5aa604cb65e 100644 --- a/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts +++ b/src/main/runtime/structured-agent-session-rollback-compatibility.test.ts @@ -7,9 +7,9 @@ import { safeParseWorkspaceSession } from '../../shared/workspace-session-schema import { journalDirectoryFor } from '../native-chat/agent-session-journal/journal-paths' import { openTestAgentSessionRecordStore, - seedTestAgentSessionRecordStore + seedTestAgentSessionRecordStore, + testAgentSessionStoreFilePath } from './agent-session-record-store-test-harness' -import { AGENT_SESSION_STORE_FILE_NAME } from './agent-session-record-store-file' import { collectSavedStructuredAgentSessionIds } from './saved-structured-agent-session-restoration' const WORKSPACE = 'workspace-1' @@ -80,18 +80,17 @@ afterEach(async () => { describe('structured session rollback compatibility', () => { it('keeps the visible session reference through target → base → target', async () => { root = await mkdtemp(join(tmpdir(), 'orca-structured-rollback-')) - const storeDir = join(root, 'agent-store') const record = agentSessionRecordFixture({ ...agentSessionRecordFixture().lease, sessionId: SESSION, runtimeKind: 'native' }) - await seedTestAgentSessionRecordStore(storeDir, { records: [record] }) + await seedTestAgentSessionRecordStore(root, { records: [record] }) const journalDir = journalDirectoryFor(root, { workspaceId: WORKSPACE, sessionId: SESSION }) await mkdir(journalDir, { recursive: true }) await writeFile(join(journalDir, 'journal.log'), 'durable-journal-fixture\n') - const target = await openTestAgentSessionRecordStore(storeDir) + const target = await openTestAgentSessionRecordStore(root) expect(target.getVisibleSessionTabIndex()).toEqual({ present: false, sessionIds: [] }) await target.setSessionTabVisibility(SESSION, true) expect(target.getVisibleSessionTabIndex()).toEqual({ present: true, sessionIds: [SESSION] }) @@ -118,18 +117,18 @@ describe('structured session rollback compatibility', () => { targetReloadedProfile?.success ? targetReloadedProfile.data : null ) ).toEqual([]) - const reloaded = await openTestAgentSessionRecordStore(storeDir) + const reloaded = await openTestAgentSessionRecordStore(root) expect(reloaded.listVisibleSessionIds()).toEqual([SESSION]) expect(reloaded.getRecord(SESSION)?.providerHandleChain).toHaveLength(1) await expect(readFile(join(journalDir, 'journal.log'), 'utf8')).resolves.toBe( 'durable-journal-fixture\n' ) - expect( - JSON.parse(await readFile(join(storeDir, AGENT_SESSION_STORE_FILE_NAME), 'utf8')) - ).toMatchObject({ visibleSessionIds: [SESSION] }) + expect(JSON.parse(await readFile(testAgentSessionStoreFilePath(root), 'utf8'))).toMatchObject({ + visibleSessionIds: [SESSION] + }) await reloaded.setSessionTabVisibility(SESSION, false) - const afterClose = await openTestAgentSessionRecordStore(storeDir) + const afterClose = await openTestAgentSessionRecordStore(root) expect(afterClose.getVisibleSessionTabIndex()).toEqual({ present: true, sessionIds: [] }) expect(afterClose.listVisibleSessionIds()).toEqual([]) expect(afterClose.getRecord(SESSION)?.providerHandleChain).toHaveLength(1) diff --git a/src/main/runtime/structured-agent-session-runtime.ts b/src/main/runtime/structured-agent-session-runtime.ts index 24735c721cc2..82c9803e2a76 100644 --- a/src/main/runtime/structured-agent-session-runtime.ts +++ b/src/main/runtime/structured-agent-session-runtime.ts @@ -42,7 +42,10 @@ import { import { AgentSessionRecordStore } from './agent-session-record-store' import type { JournalHostDatabase } from '../native-chat/agent-session-journal/journal-host-database' import { openStructuredAgentSessionJournalDatabase } from './structured-agent-session-journal-open' -import { agentSessionStorePath } from './agent-session-record-store-file' +import { + AGENT_SESSION_STORE_DIR_NAME, + agentSessionStorePath +} from './agent-session-record-store-file' import { createStructuredAgentSessionOwnerProbe, createStructuredAgentSessionOwnerProbes @@ -58,14 +61,11 @@ import { type RuntimeAgentAccountHomeResolver } from './structured-agent-model-catalog-wiring' -/** Beside the journal database: one file adjudicates every session's lease. */ -const RECORD_STORE_DIR_NAME = 'agent-sessions' - export function hasPersistedStructuredAgentSessionStore( stateDirectory: string, fileExists: (path: string) => boolean = existsSync ): boolean { - const filePath = agentSessionStorePath(join(stateDirectory, RECORD_STORE_DIR_NAME)) + const filePath = agentSessionStorePath(join(stateDirectory, AGENT_SESSION_STORE_DIR_NAME)) return fileExists(filePath) || fileExists(`${filePath}.bak`) } @@ -211,7 +211,7 @@ async function installOnJournal( const envResolvers = createStructuredAgentEnvironmentResolvers(deps) const { resolveCodexEnvironment, resolveClaudeInheritedEnv } = envResolvers const store = await AgentSessionRecordStore.open({ - directory: join(deps.stateDirectory, RECORD_STORE_DIR_NAME), + directory: join(deps.stateDirectory, AGENT_SESSION_STORE_DIR_NAME), hostId: deps.hostId }) let host: StructuredAgentSessionHost | null = null diff --git a/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts b/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts index 62b3e385f0c6..3cf61c0bf3c9 100644 --- a/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts +++ b/src/main/runtime/structured-agent-session-spawn-token-descendants.test.ts @@ -90,7 +90,7 @@ afterEach(async () => { }) function openStore(): Promise { - return openTestAgentSessionRecordStore(join(stateDirectory, 'agent-sessions'), { + return openTestAgentSessionRecordStore(stateDirectory, { hostId: HOST_ID }) } diff --git a/src/main/runtime/structured-claude-pending-rewind.test.ts b/src/main/runtime/structured-claude-pending-rewind.test.ts index d87a76ccd3a9..137b7ff6961f 100644 --- a/src/main/runtime/structured-claude-pending-rewind.test.ts +++ b/src/main/runtime/structured-claude-pending-rewind.test.ts @@ -107,7 +107,7 @@ async function reattach() { beforeEach(async () => { resetHostTestOperationIds() directory = await mkdtemp(join(tmpdir(), 'orca-claude-pending-rewind-')) - store = await openTestAgentSessionRecordStore(join(directory, 'store')) + store = await openTestAgentSessionRecordStore(directory) claude = fakeClaude({ initSessionId: PROVIDER_SESSION_ID }) adapter = createStructuredClaudeRuntimeAdapter({ store, diff --git a/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts b/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts index f24571786ad3..4aaa02037ec3 100644 --- a/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts +++ b/tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts @@ -473,7 +473,7 @@ describe('cross-version structured agent sessions', () => { beforeEach(async () => { root = await mkdtemp(join(tmpdir(), 'orca-cross-version-ai-vault-')) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) const host = new StructuredAgentSessionHost({ store, adapter: { @@ -699,7 +699,7 @@ describe('cross-version structured agent sessions', () => { /** Reopens the store from disk and installs a fresh host over the same journal * root — what a process restart actually leaves behind. */ async function bootHost(generation: string): Promise { - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) const host = new StructuredAgentSessionHost({ store, adapter: adapter(), diff --git a/tests/e2e/structured-chat-owner-status-activation.unit.test.ts b/tests/e2e/structured-chat-owner-status-activation.unit.test.ts index b5e7271cc195..248adb62c991 100644 --- a/tests/e2e/structured-chat-owner-status-activation.unit.test.ts +++ b/tests/e2e/structured-chat-owner-status-activation.unit.test.ts @@ -115,7 +115,7 @@ beforeEach(async () => { clock = NOW resetHostTestOperationIds() closeSession = vi.fn(async () => true) - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() expect(await host.attach({ callerKey: 'client-1' }, hostTestAttachParams(null))).toMatchObject({ ok: true @@ -141,7 +141,7 @@ describe('a chat at rest keeps its worktree activatable', () => { it('after an app restart restored it for reading', async () => { await host.flushAllStreamedEvents() - store = await openTestAgentSessionRecordStore(join(root, 'store')) + store = await openTestAgentSessionRecordStore(root) openHost() await host.restoreReadableSessions() expect(host.hasSession(SESSION)).toBe(true)