test(session): align turn-end contract artifacts

This commit is contained in:
_Kerman
2026-08-04 14:09:52 +08:00
parent d4fa26023d
commit e874910a76
186 changed files with 408 additions and 414 deletions

View File

@@ -181,7 +181,7 @@ describe('llm-retry invariants', () => {
const closedTurn = openStep(ctx, 'retry-invariant-closed-turn')
closedTurn.append('step/end', { turn: 1, step: 1 })
closedTurn.append('turn/end', { turn: 1, step: 1, reason: { kind: 'aborted', reason: { kind: 'user' } },
closedTurn.append('turn/end', { turn: 1, reason: { kind: 'aborted', reason: { kind: 'user' } },
})
expect(() => {
closedTurn.append('llm/retry', { turn: 1, step: 1, ...normal })
@@ -228,7 +228,7 @@ describe('llm-retry invariants', () => {
appendRetryTurn(missingEnd, 2)
const nonFailureEnd = ctx.sessions.create(SessionId('retry-invariant-non-failure-end'))
nonFailureEnd.append('turn/end', { turn: 1, step: 0, reason: { kind: 'completed' } })
nonFailureEnd.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
nonFailureEnd.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'idle context' }],
source: { kind: 'user' },
@@ -236,7 +236,7 @@ describe('llm-retry invariants', () => {
appendRetryTurn(nonFailureEnd, 2)
const missingStart = ctx.sessions.create(SessionId('retry-invariant-missing-start'))
missingStart.append('turn/end', { turn: 1, step: 0, reason: { kind: 'error', error: failure },
missingStart.append('turn/end', { turn: 1, reason: { kind: 'error', error: failure },
})
appendRetryTurn(missingStart, 2)

View File

@@ -49,7 +49,7 @@ describe.each(['jsonl', 'sqlite'] as const)('%s retry-event persistence', (kind)
failure: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
})
session.append('step/end', { turn: 1, step: 1 })
session.append('turn/end', { turn: 1, step: 1, reason: { kind: 'error', error: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
session.append('turn/end', { turn: 1, reason: { kind: 'error', error: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
},
})

View File

@@ -337,7 +337,7 @@ describe('provider-routed retry policy', () => {
expect(agent.session.events.filter(event => event.type === 'llm/retry')).toHaveLength(2)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { step: 1, reason: { kind: 'error', error: { message: 'busy three', code: 'SERVER' } } },
data: { reason: { kind: 'error', error: { message: 'busy three', code: 'SERVER' } } },
})
})
@@ -451,7 +451,7 @@ describe('provider-routed retry policy', () => {
const end = agent.session.events.at(-1)
expect(end).toMatchObject({
type: 'turn/end',
data: { step: 1, reason: { kind: 'error', error: { code: 'NO_ADAPTER' } } },
data: { reason: { kind: 'error', error: { code: 'NO_ADAPTER' } } },
})
if (end?.type === 'turn/end' && end.data.reason.kind === 'error') {
expect(end.data.reason.error.message).toContain('no adapter registered for provider')

View File

@@ -193,7 +193,7 @@ describe('bounded retry through the real DeepSeek HTTP/SSE adapter', () => {
expect(agent.session.events.some(event => event.type === 'llm/retry')).toBe(false)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { step: 1, reason: { kind: 'error', error: { message: 'SSE stream ended without [DONE]', code: 'STREAM_CLOSED' } } },
data: { reason: { kind: 'error', error: { message: 'SSE stream ended without [DONE]', code: 'STREAM_CLOSED' } } },
})
})
@@ -236,7 +236,7 @@ describe('bounded retry through the real DeepSeek HTTP/SSE adapter', () => {
const end = agent.session.events.at(-1)
expect(end).toMatchObject({
type: 'turn/end',
data: { step: 1, reason: { kind: 'error', error: { code: 'TRANSPORT' } } },
data: { reason: { kind: 'error', error: { code: 'TRANSPORT' } } },
})
if (end?.type === 'turn/end' && end.data.reason.kind === 'error') {
expect(end.data.reason.error.message).toContain('DeepSeek API request to')