refactor(session): route construction through Session.create

This commit is contained in:
imccyu
2026-08-04 18:41:07 +08:00
parent c7f693aa40
commit 8cbdd5b9d0
61 changed files with 305 additions and 292 deletions

View File

@@ -31,7 +31,7 @@ async function settle(): Promise<void> {
describe('all-messages LLM title provider', () => {
it('includes seeded history and the latest prompt while inheriting the logged request route', async () => {
const seeded = new Session(SessionId('seed-source'))
const seeded = Session.create(SessionId('seed-source'))
seeded.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
const inherited = seeded.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'inherited prompt' }], source: { kind: 'user' },

View File

@@ -45,7 +45,7 @@ describe('first-message LLM title provider', () => {
providerPlugin.apply(ctx, LLM_CONFIG)
await expect(registered!.generate({
session: new Session(SessionId('empty-first-provider')),
session: Session.create(SessionId('empty-first-provider')),
messages: [],
signal: new AbortController().signal,
})).rejects.toThrow(/requires one human message/)

View File

@@ -61,7 +61,7 @@ describe('SessionTitleService.rename', () => {
const session = ctx.sessions.create(SessionId('rename-reject'))
expect(() => ctx.sessionTitle.rename(session, '  ')).toThrow(/visible characters/)
expect(() => ctx.sessionTitle.rename(new Session(SessionId('detached')), 'name'))
expect(() => ctx.sessionTitle.rename(Session.create(SessionId('detached')), 'name'))
.toThrow(/not live in this store/)
})

View File

@@ -82,7 +82,7 @@ describe('SessionTitleService configuration and refresh boundaries', () => {
await expect(withProvider.sessionTitle.refresh(providerEmpty)).resolves.toBeUndefined()
expect(generate).not.toHaveBeenCalled()
await expect(withProvider.sessionTitle.refresh(new Session(SessionId('detached'))))
await expect(withProvider.sessionTitle.refresh(Session.create(SessionId('detached'))))
.rejects.toThrow(/not live in this store/)
const controller = new AbortController()
controller.abort(new Error('already cancelled'))
@@ -165,7 +165,7 @@ describe('SessionTitleService configuration and refresh boundaries', () => {
it('shares one fallback across concurrent refreshes', async () => {
const ctx = await setup()
const seed = new Session(SessionId('fallback-concurrency-seed'))
const seed = Session.create(SessionId('fallback-concurrency-seed'))
seed.append('turn/start', {
turn: 1,
trigger: { kind: 'message', source: { kind: 'user' } },

View File

@@ -134,7 +134,7 @@ describe('SessionTitleService', () => {
})
it('folds the latest title event during replay', () => {
const seed = new Session(SessionId('source'))
const seed = Session.create(SessionId('source'))
seed.append('session/title', {
title: 'Earlier',
messageSeqs: [1],