Skip to content

Commit 52dbb7d

Browse files
committed
test(server): validate the response envelope in the catalog route tests
1 parent 6f38288 commit 52dbb7d

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

packages/server/test/catalog.e2e.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
33
import { join } from 'node:path';
44

55
import { pino } from 'pino';
6+
import { z } from 'zod';
67
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
78

89
import { ICatalogService } from '@pymodel/agent-core';
@@ -85,8 +86,22 @@ function appOf(r: RunningServer): {
8586
});
8687
}
8788

88-
function envelopeOf<T>(body: unknown): { code: number; msg: string; data: T | null } {
89-
return body as { code: number; msg: string; data: T | null };
89+
const envelopeSchema = z.object({
90+
code: z.number(),
91+
msg: z.string(),
92+
data: z.unknown(),
93+
request_id: z.string().min(1),
94+
});
95+
96+
/** Parses the uniform `{code, msg, data, request_id}` envelope every route returns. */
97+
function envelopeOf<T>(body: unknown): {
98+
code: number;
99+
msg: string;
100+
data: T | null;
101+
request_id: string;
102+
} {
103+
const envelope = envelopeSchema.parse(body);
104+
return { ...envelope, data: envelope.data as T | null };
90105
}
91106

92107
describe('catalog routes', () => {

0 commit comments

Comments
 (0)