Ver Fonte

test(session): cover the turn/end step invariant and content shape guard

- invariant.spec: a turn/end whose step does not match the last opened
  step fails with 'expected last step'.
- session.spec: a seed message whose content is not an array fails with
  'message has invalid content'.
_Kerman há 1 mês atrás
pai
commit
2e2bcd0e42

+ 7 - 0
packages/core/session/tests/invariant.spec.ts

@@ -131,6 +131,13 @@ describe('session-log invariants', () => {
     expect(() => second.append('turn/start', { turn: 3 }))
       .toThrow(/expected turn 2, got 3/)
 
+    const third = (await setup()).ctx.sessions.create()
+    third.append('turn/start', { turn: 1 })
+    third.append('step/start', { turn: 1, step: 1 })
+    third.append('step/end', { turn: 1, step: 1 })
+    expect(() => third.append('turn/end', { turn: 1, step: 2, reason: { kind: 'completed' } }))
+      .toThrow(/expected last step 1, got 2/)
+
     const outside = (await setup()).ctx.sessions.create()
     expect(() => outside.append('user/message', createUserMessage({
       content: [{ type: 'text', text: 'idle context' }],

+ 8 - 0
packages/core/session/tests/session.spec.ts

@@ -232,6 +232,14 @@ describe('Session', () => {
         },
         message: 'message has invalid source',
       },
+      {
+        name: 'content shape',
+        event: {
+          type: 'user/message', seq: 0, time: 1, surfaceOp: 'append',
+          data: { ...user, content: 'not-an-array' },
+        },
+        message: 'message has invalid content',
+      },
       {
         name: 'assistant source',
         event: {