Skip to content

Commit 50ec638

Browse files
Address code review: add round-trip decode assertion, expand content validation tests
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/fc1d7caa-ef41-4b0b-9ce4-267c262596b4 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 68c79e0 commit 50ec638

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/services/service-ai/src/__tests__/ai-service.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,26 @@ describe('AI Routes', () => {
623623
const routes = buildAIRoutes(service, service.conversationService, silentLogger);
624624
const chatRoute = routes.find(r => r.path === '/api/v1/ai/chat')!;
625625

626+
// Numeric content should be rejected
626627
const response = await chatRoute.handler({
627628
body: { messages: [{ role: 'user', content: 123 }] },
628629
});
629-
630630
expect(response.status).toBe(400);
631631
expect((response.body as any).error).toContain('content');
632+
633+
// Object content (not an array) should be rejected
634+
const response2 = await chatRoute.handler({
635+
body: { messages: [{ role: 'user', content: { nested: true } }] },
636+
});
637+
expect(response2.status).toBe(400);
638+
expect((response2.body as any).error).toContain('content');
639+
640+
// Boolean content should be rejected
641+
const response3 = await chatRoute.handler({
642+
body: { messages: [{ role: 'user', content: true }] },
643+
});
644+
expect(response3.status).toBe(400);
645+
expect((response3.body as any).error).toContain('content');
632646
});
633647

634648
it('POST /api/v1/ai/conversations/:id/messages should return 400 for invalid role', async () => {

packages/services/service-ai/src/__tests__/vercel-stream-encoder.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ describe('encodeStreamPart', () => {
1919
const frame = encodeStreamPart(part);
2020
expect(frame).toBe(`0:${JSON.stringify('say "hi"\nnewline')}\n`);
2121
expect(frame.startsWith('0:')).toBe(true);
22+
23+
// Verify round-trip: decode the frame payload back to the original text
24+
const decoded = JSON.parse(frame.slice(2).trim());
25+
expect(decoded).toBe('say "hi"\nnewline');
2226
});
2327

2428
it('should encode tool-call as "9:" frame', () => {

0 commit comments

Comments
 (0)