瀏覽代碼

fix(session): validate seeded projection boundary

pku-xht 1 月之前
父節點
當前提交
57d8a79bfe

+ 1 - 1
packages/session/session-projection/src/index.ts

@@ -199,8 +199,8 @@ export class SessionProjectionRegistry extends Service {
   constructor(ctx: Context) {
     super(ctx, 'sessionProjections')
     ctx.on('session/created', (session: Session) => {
-      if (session.seq !== 0) return
       validateSeedLength(session.header, session.seq)
+      if (session.seq !== 0) return
       for (const registration of this.registrations.values()) {
         if (registration.cells.has(session)) continue
         registration.cells.set(session, {

+ 4 - 0
packages/session/session-projection/tests/registry.spec.ts

@@ -152,6 +152,10 @@ describe('SessionProjectionRegistry drive', () => {
     expect(() => ctx.sessions.create(undefined, {
       meta: { seedLength: 1 },
     })).toThrow(/seedLength 1 exceeds observed log length 0/)
+    expect(() => ctx.sessions.create(undefined, {
+      seed: [{ type: 'turn/start', seq: 0, time: 0, data: { turn: 1 } }],
+      meta: { seedLength: 3 },
+    })).toThrow(/seedLength 3 exceeds observed log length 2/)
   })
 
   it('notifies onChanged with the validated view and the causing seq, and skips same-reference applies', async () => {