fix(agent): report missing inbox projection
This commit is contained in:
1 parent
f3858fc2a7
commit
ea222a1f72
2 files changed
+18
-3
No files matched your search
@@ -128,9 +128,13 @@ export class Inbox {
|
||||
|
||||
/** Read the current durable projection state. */
|
||||
private current(): InboxState {
|
||||
// AgentLoop requires sessionProjections; AgentRegistry contributes this unit to it.
|
||||
// oxlint-disable-next-line typescript/no-non-null-assertion
|
||||
return this.ctx.sessionProjections.stateOf(this.session, 'inbox')!
|
||||
const state = this.ctx.sessionProjections.stateOf(this.session, 'inbox')
|
||||
if (state === undefined) {
|
||||
throw new Error(
|
||||
`agent "${this.session.id}" cannot read inbox state: session projection "inbox" is not registered; load AgentRegistry with SessionProjectionRegistry before constructing Inbox`,
|
||||
)
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
/** Commit one normalized mutation and publish its live events. */
|
||||
|
||||
@@ -74,6 +74,17 @@ async function reconstructPersistedInbox(
|
||||
}
|
||||
|
||||
describe('Inbox', () => {
|
||||
it('reports a missing Inbox projection as a composition error', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionProjectionRegistry)
|
||||
const agent = stubAgent('missing-inbox-projection', { ctx })
|
||||
const inbox = new Inbox(ctx, agent.session, agentEvents(ctx, agent))
|
||||
|
||||
expect(() => inbox.nextTurn).toThrow(
|
||||
'agent "missing-inbox-projection" cannot read inbox state: session projection "inbox" is not registered; load AgentRegistry with SessionProjectionRegistry before constructing Inbox',
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects invalid durable coordinates and duplicate identities during reconstruction', async () => {
|
||||
const outOfRange = await reconstructPersistedInbox('invalid-inbox-range', (session) => {
|
||||
session.append('agent/inbox/spliced', {
|
||||
|
||||
Reference in new issue
Block a user