Merge remote-tracking branch 'origin/master' into codex/simp-prune-tools-prompt-surface
# Conflicts: # docs/config-catalog.md # docs/cordis-catalog/services.md # packages/core/agent-loop/src/loop.ts # packages/core/session/README.md # packages/core/session/tests/derived-cache.spec.ts
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
/**
|
||||
* Derived-message cache tests: the session projects each surface node exactly
|
||||
* once (O(new nodes) per call), rebuilds on a surface replacement (the
|
||||
* replaceGeneration signal), returns a fresh array snapshot
|
||||
* per call over shared frozen messages, and stays deep-equal to a from-scratch
|
||||
* replay derivation at every step — the incremental==scratch property the
|
||||
* reconstructability RFC's invariant enforces in dev at request time.
|
||||
* Derived-message cache contract against a scratch oracle: project new nodes
|
||||
* once, rebuild on surface replacements, return fresh arrays over shared
|
||||
* frozen messages, and remain value-equal to replay at every step.
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
@@ -28,7 +25,6 @@ describe('derived-message cache', () => {
|
||||
userText(session, 'two')
|
||||
session.append('assistant/message', { turn: 1, step: 1, content: [{ type: 'text', text: 'reply' }] }, { surfaceOp: 'append' })
|
||||
expect(session.deriveMessages()).toEqual(scratch(session))
|
||||
// An empty-content assistant/message (usage host) projects to nothing.
|
||||
session.append('assistant/message', { turn: 1, step: 2, content: [], usage: { inputTokens: 1, outputTokens: 0 } }, { surfaceOp: 'append' })
|
||||
expect(session.deriveMessages()).toEqual(scratch(session))
|
||||
})
|
||||
@@ -48,7 +44,6 @@ describe('derived-message cache', () => {
|
||||
|
||||
expect(session.deriveMessages()).toHaveLength(1)
|
||||
expect(session.deriveMessages()).toEqual(scratch(session))
|
||||
// The array a caller took before the replace is untouched.
|
||||
expect(beforeReplace).toHaveLength(2)
|
||||
})
|
||||
|
||||
@@ -61,7 +56,7 @@ describe('derived-message cache', () => {
|
||||
const second = session.deriveMessages()
|
||||
expect(first).toHaveLength(1)
|
||||
expect(second).toHaveLength(2)
|
||||
// Shared projection objects: the same frozen message instance, once ever.
|
||||
// Array snapshots share their frozen message projections.
|
||||
expect(second[0]).toBe(first[0])
|
||||
expect(Object.isFrozen(first[0])).toBe(true)
|
||||
})
|
||||
@@ -73,8 +68,7 @@ describe('Session.deriveEventMessage — the per-event projection', () => {
|
||||
const session = new Session(SessionId('per-event'))
|
||||
session.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
|
||||
const event = session.append('user/message', { content: [{ type: 'text', text: 'hi' }], source: { kind: 'user' } }, { surfaceOp: 'append' })
|
||||
// The fold path (deriveMessages) and the per-event path share the
|
||||
// projection, so an external reconstructor cannot disagree with the cache.
|
||||
// Full and per-event derivation share one projection.
|
||||
expect(session.deriveEventMessage(event)).toEqual(session.deriveMessages().at(-1))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user