mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
fix(native-chat): own async option preparation and port SQL runtime fixtures
This commit is contained in:
-40
@@ -1,40 +0,0 @@
|
||||
import { readTestJournalItems } from '../journal-observation.test-support'
|
||||
import type { createFixture } from './journal-terminal-validation-test-fixture'
|
||||
import { expect, it } from 'vitest'
|
||||
import { AGENT_JOURNAL_THREAD_SCOPE } from '../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { agentJournalItemKey } from '../../../../shared/agent-session/journal/agent-session-journal-item-key'
|
||||
|
||||
export function registerJournalApprovalRevisionValidationTests(
|
||||
fixture: ReturnType<typeof createFixture>
|
||||
): void {
|
||||
it('admits an answer on an exhausted approval without changing the saved item', async () => {
|
||||
await fixture.saveOldItems([
|
||||
{
|
||||
itemId: agentJournalItemKey(fixture.identity),
|
||||
revision: Number.MAX_SAFE_INTEGER + 1,
|
||||
body: fixture.pendingApproval()
|
||||
}
|
||||
])
|
||||
const before = (await readTestJournalItems(fixture.journal))[0]
|
||||
const cursor = fixture.journal.cursor()
|
||||
await expect(
|
||||
fixture.journal.appendItem(
|
||||
fixture.identity,
|
||||
{
|
||||
...fixture.pendingApproval(),
|
||||
kind: 'approval',
|
||||
resolution: {
|
||||
state: 'resolved',
|
||||
selectedOptionId: null,
|
||||
resolvedBy: 'user',
|
||||
resolvedAt: 1_000
|
||||
}
|
||||
},
|
||||
{ fence: 8, turnScope: AGENT_JOURNAL_THREAD_SCOPE }
|
||||
)
|
||||
).resolves.toBeDefined()
|
||||
expect(fixture.journal.cursor().sequence).toBe(cursor.sequence + 1)
|
||||
expect((await readTestJournalItems(fixture.journal))[0]).toEqual(before)
|
||||
await fixture.expectSendStillWritable()
|
||||
})
|
||||
}
|
||||
+1
-1
@@ -67,7 +67,7 @@ export function registerJournalSubagentItemTests(): void {
|
||||
})
|
||||
await live.close()
|
||||
|
||||
const reopened = await open()
|
||||
const reopened = await open({ recover: { fence: 0 } })
|
||||
const row = (await readTestJournalItems(reopened)).at(-1)!
|
||||
expect(row.recovered).toBe(true)
|
||||
expect(row.body).toMatchObject({
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
import { createFixture } from './journal-terminal-validation-test-fixture'
|
||||
import { registerJournalApprovalRevisionValidationTests } from './journal-approval-revision-validation.spec'
|
||||
|
||||
export function registerJournalTerminalSettlementValidationTests(): void {
|
||||
const fixture = createFixture()
|
||||
registerJournalApprovalRevisionValidationTests(fixture)
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, expect } from 'vitest'
|
||||
import {
|
||||
agentSessionJournalProviderHandle,
|
||||
codexProviderHandle
|
||||
} from '../../../../shared/agent-session/lifecycle/agent-session-provider-handle-encoding'
|
||||
import {
|
||||
createTrackedJournalOpener,
|
||||
openTestJournalHostDatabase
|
||||
} from '../store-lifecycle/journal-host-database-test-support'
|
||||
import { seedTestJournalHistoricalRows } from '../replay/journal-historical-inputs.test-support'
|
||||
import type { JournalRow } from '../durable-rows/journal-row-schema'
|
||||
import type { AgentSessionJournal } from '../journal-store'
|
||||
|
||||
export function createFixture() {
|
||||
const journals = createTrackedJournalOpener()
|
||||
const identity = { provider: 'orca' as const, clientMessageId: 'old-turn' }
|
||||
const savedIdentity = {
|
||||
sessionId: 'validation',
|
||||
workspaceId: 'folder',
|
||||
hostId: 'host',
|
||||
agent: 'codex' as const,
|
||||
providerHandle: codexProviderHandle('thread')
|
||||
}
|
||||
let root: string
|
||||
let journal: AgentSessionJournal
|
||||
beforeEach(async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'orca-settlement-validation-'))
|
||||
})
|
||||
afterEach(async () => {
|
||||
await journals.closeAll()
|
||||
await rm(root, { recursive: true, force: true })
|
||||
})
|
||||
async function saveOldItems(inputs: { itemId: string; revision?: number; body: unknown }[]) {
|
||||
const epoch = 'saved-approval'
|
||||
const rows: JournalRow[] = [
|
||||
{
|
||||
v: 3,
|
||||
kind: 'epoch',
|
||||
epoch,
|
||||
seq: 1,
|
||||
ts: 900,
|
||||
fence: 7,
|
||||
reason: 'session_created',
|
||||
providerHandle: agentSessionJournalProviderHandle(savedIdentity.providerHandle)
|
||||
}
|
||||
]
|
||||
for (const [index, input] of inputs.entries()) {
|
||||
rows.push({
|
||||
v: 3,
|
||||
kind: 'item',
|
||||
epoch,
|
||||
seq: index + 2,
|
||||
ts: 900,
|
||||
fence: 7,
|
||||
revision: 1,
|
||||
...input,
|
||||
turnScope: { kind: 'thread' }
|
||||
} as JournalRow)
|
||||
}
|
||||
seedTestJournalHistoricalRows(openTestJournalHostDatabase(root).db, savedIdentity, rows)
|
||||
journal = await journals.open({
|
||||
identity: savedIdentity,
|
||||
stateDirectory: root,
|
||||
now: () => 1_000
|
||||
})
|
||||
}
|
||||
async function expectSendStillWritable() {
|
||||
const sequence = journal.cursor().sequence + 1
|
||||
await expect(
|
||||
journal.appendSubmission({
|
||||
clientMessageId: 'new-send',
|
||||
payloadFingerprint: 'new',
|
||||
fence: 8,
|
||||
body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'hello' }] }
|
||||
})
|
||||
).resolves.toMatchObject({ sequence })
|
||||
}
|
||||
function pendingApproval() {
|
||||
return {
|
||||
kind: 'approval',
|
||||
title: 'Allow?',
|
||||
detail: null,
|
||||
options: [],
|
||||
resolution: { state: 'pending', selectedOptionId: null, resolvedBy: null, resolvedAt: null }
|
||||
}
|
||||
}
|
||||
return {
|
||||
identity,
|
||||
get journal() {
|
||||
return journal
|
||||
},
|
||||
saveOldItems,
|
||||
pendingApproval,
|
||||
expectSendStillWritable
|
||||
}
|
||||
}
|
||||
-2
@@ -5,7 +5,6 @@ import { registerJournalRowContextUsageTests } from '../durable-rows/journal-row
|
||||
import { registerJournalSubagentItemTests } from '../item-lifecycle/journal-subagent-item.spec'
|
||||
import { registerJournalSubmissionPositionsTests } from '../submissions/journal-submission-positions.spec'
|
||||
import { registerJournalSubmissionQueuedLinkTests } from '../submissions/journal-submission-queued-link.spec'
|
||||
import { registerJournalTerminalSettlementValidationTests } from '../item-lifecycle/journal-terminal-settlement-validation.spec'
|
||||
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
@@ -15,4 +14,3 @@ describe('journal-row-context-usage', registerJournalRowContextUsageTests)
|
||||
describe('journal-subagent-item', registerJournalSubagentItemTests)
|
||||
describe('journal-submission-positions', registerJournalSubmissionPositionsTests)
|
||||
describe('journal-submission-queued-link', registerJournalSubmissionQueuedLinkTests)
|
||||
describe('journal-terminal-settlement-validation', registerJournalTerminalSettlementValidationTests)
|
||||
|
||||
+6
-2
@@ -153,7 +153,7 @@ it('keeps full child requests answerable outside the bounded transcript and clea
|
||||
expect((await current.host.currentWork(SESSION))?.requestProjection(SESSION).marker.version).toBe(
|
||||
requestVersion
|
||||
)
|
||||
await current.host.subscribe({
|
||||
const closeReopened = await current.host.subscribe({
|
||||
id: 'reopened',
|
||||
sessionId: SESSION,
|
||||
boundedFrames: true,
|
||||
@@ -161,7 +161,10 @@ it('keeps full child requests answerable outside the bounded transcript and clea
|
||||
cursor,
|
||||
emit
|
||||
})
|
||||
coalescer.flush()
|
||||
await vi.waitFor(() => {
|
||||
coalescer.flush()
|
||||
expect(state.cursor).toEqual(journal.cursor())
|
||||
})
|
||||
await vi.waitFor(() =>
|
||||
expect(state.requestAuthority?.version).toEqual(state.requestMarker?.version)
|
||||
)
|
||||
@@ -200,6 +203,7 @@ it('keeps full child requests answerable outside the bounded transcript and clea
|
||||
await vi.waitFor(() => expect(state.currentRequests).toEqual([]))
|
||||
expect(journal.cursor()).toEqual(beforeExit)
|
||||
expect(selectAgentSessionCurrentRequests(state)).toEqual([])
|
||||
closeReopened()
|
||||
reader.invalidate()
|
||||
coalescer.dispose()
|
||||
})
|
||||
|
||||
+9
-1
@@ -213,7 +213,15 @@ export async function setStructuredAgentSessionOption(
|
||||
readsWithoutModel: caller.readsOptionsWithoutModel !== false
|
||||
})
|
||||
if (picked.ok) {
|
||||
confirmIdleStructuredAgentSessionOption(context, ctx, params)
|
||||
const confirming = confirmIdleStructuredAgentSessionOption(context, ctx, params)
|
||||
context.trackProviderOperation?.(confirming)
|
||||
void confirming.catch((error) => {
|
||||
ctx.logger.warn('confirming idle session metadata failed', {
|
||||
scope: 'idle-option',
|
||||
sessionId: ctx.sessionId,
|
||||
error
|
||||
})
|
||||
})
|
||||
}
|
||||
return picked
|
||||
},
|
||||
|
||||
@@ -34,6 +34,10 @@ import { createStructuredAgentSessionLogger } from '../native-chat/agent-session
|
||||
import type { AgentSessionRecord } from '../../shared/agent-session/lifecycle/agent-session-record'
|
||||
import { conversationRecordReader } from './orchestration/addressing/session-lineage/structured-session-lineage'
|
||||
import './agent-session/structured-agent-session-create-adoption'
|
||||
import {
|
||||
journalSqlReaderPath,
|
||||
journalSqlWorkerPath
|
||||
} from '../native-chat/agent-session-journal/journal-sql-worker-bundle.test-fixture'
|
||||
|
||||
const referenceRuntime = {
|
||||
getOrchestrationFleetAgentStatusSnapshot: () => [],
|
||||
@@ -151,7 +155,9 @@ describe('persisted conversation inventory identity', () => {
|
||||
legacySessionTabIds: [],
|
||||
stateDirectory: root,
|
||||
hostId: 'local',
|
||||
logger: createStructuredAgentSessionLogger()
|
||||
logger: createStructuredAgentSessionLogger(),
|
||||
writerPath: journalSqlWorkerPath(),
|
||||
readerPath: journalSqlReaderPath()
|
||||
})
|
||||
const db = new OrchestrationDb(':memory:')
|
||||
try {
|
||||
|
||||
@@ -18,6 +18,11 @@ import { foundAgentSessionRecord } from './records/agent-session-record-founding
|
||||
import { closeTestJournalHostDatabases } from '../../native-chat/agent-session-journal/store-lifecycle/journal-host-database-test-support'
|
||||
import { recordingStructuredAgentSessionLogger } from '../../native-chat/agent-session-wire/host/testing/structured-agent-session-logger.test-fixture'
|
||||
import { onStructuredAgentSessionsHeldChanged } from '../../native-chat/agent-session-wire/host/structured-agent-session-registry'
|
||||
import { openAgentSessionRecordStoreOnce } from './records/agent-session-record-store-slot'
|
||||
import {
|
||||
journalSqlReaderPath,
|
||||
journalSqlWorkerPath
|
||||
} from '../../native-chat/agent-session-journal/journal-sql-worker-bundle.test-fixture'
|
||||
|
||||
const HOST_ID = 'local'
|
||||
|
||||
@@ -58,6 +63,14 @@ describe('structured agent-session runtime install', () => {
|
||||
fullAccessAgents: readonly string[],
|
||||
logger = recordingStructuredAgentSessionLogger().logger
|
||||
) {
|
||||
await openAgentSessionRecordStoreOnce({
|
||||
stateDirectory: stateDirectory!,
|
||||
hostId: HOST_ID,
|
||||
logger,
|
||||
legacySessionTabIds: [],
|
||||
writerPath: journalSqlWorkerPath(),
|
||||
readerPath: journalSqlReaderPath()
|
||||
})
|
||||
return await ensureStructuredAgentSessionHost({
|
||||
logger,
|
||||
stateDirectory: stateDirectory!,
|
||||
|
||||
+9
-10
@@ -65,15 +65,11 @@ it('commits a legacy no-choice answer before reply and replays it after upgrade
|
||||
options: { effort: 'high' },
|
||||
now: fixture.rig.clock.now
|
||||
})
|
||||
const replace = vi.spyOn(fixture.rig.store, 'replaceSessionOptions')
|
||||
fixture.rig.sink.publish.mockClear()
|
||||
const params = optionRequest('')
|
||||
const inert = { key: 'model', value: '', options: {} }
|
||||
expect((await call('agentSession.setOption', params))[0]).toMatchObject({
|
||||
result: { ok: true, replayed: false, value: inert }
|
||||
})
|
||||
expect(replace).not.toHaveBeenCalled()
|
||||
expect(fixture.rig.sink.publish).not.toHaveBeenCalled()
|
||||
expect(fixture.rig.store.getRecord(SESSION)?.options).toEqual({ effort: 'high' })
|
||||
expect(
|
||||
fixture.rig.store.getOperationRow('device-1', params.envelope.clientOperationId)?.outcome
|
||||
@@ -424,12 +420,15 @@ it('resets catch-up over an unreadable event while keeping the current conversat
|
||||
page: { items: [{ body: { kind: 'message' } }] }
|
||||
}
|
||||
})
|
||||
expect(
|
||||
(await call('agentSession.subscribe', { sessionId: SESSION, cursor: stale }))[0]
|
||||
).toMatchObject({ ok: true, result: { type: 'reset', reset: 'schema_unreadable' } })
|
||||
expect(
|
||||
(await call('agentSession.subscribe', { sessionId: SESSION, cursor: live }))[0]
|
||||
).toMatchObject({ ok: true, result: { type: 'batch' } })
|
||||
const reset = await call('agentSession.subscribe', { sessionId: SESSION, cursor: stale })
|
||||
await vi.waitFor(() =>
|
||||
expect(reset[0]).toMatchObject({
|
||||
ok: true,
|
||||
result: { type: 'reset', reset: 'schema_unreadable' }
|
||||
})
|
||||
)
|
||||
const caughtUp = await call('agentSession.subscribe', { sessionId: SESSION, cursor: live })
|
||||
await vi.waitFor(() => expect(caughtUp[0]).toMatchObject({ ok: true, result: { type: 'batch' } }))
|
||||
})
|
||||
|
||||
it('keeps a storage failure during catch-up retryable instead of resetting the client', async () => {
|
||||
|
||||
Reference in New Issue
Block a user