- pnpm workspace: apps/{web,server}, packages/{contracts,db,domain,adapters,tasks,agent,testkit}
- server: Hono + zod-openapi, API Key auth with scopes, redacting pino logger, SSE event bus with replay, worker heartbeat
- db: Kysely + pg, file migrator, 0001_init (settings/api_key/audit_event/outbox_event)
- web: React Router 7 SPA console shell with 12 workspace placeholders, uhd_web tokens/ui/guard scripts
- docs: ADR-001 (Node over Deno), dev runbook, design system rules
Co-Authored-By: Claude Fable 5.1 <[email protected]>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
import { API_ERROR_STATUS, apiResponse, CapabilityId, CursorQuery, EventEnvelope, Id } from "../src";
|
|
|
|
describe("contracts", () => {
|
|
it("Id 只接受 uuid", () => {
|
|
expect(Id.safeParse("7d3f7f5e-8a8c-4b8e-9f0a-1b2c3d4e5f60").success).toBe(true);
|
|
expect(Id.safeParse("abc").success).toBe(false);
|
|
});
|
|
|
|
it("CursorQuery 默认 limit 50 且限制上限", () => {
|
|
expect(CursorQuery.parse({}).limit).toBe(50);
|
|
expect(CursorQuery.safeParse({ limit: 1000 }).success).toBe(false);
|
|
});
|
|
|
|
it("ApiResponse 信封", () => {
|
|
const s = apiResponse(z.object({ n: z.number() }));
|
|
expect(s.parse({ ok: true, data: { n: 1 } }).data?.n).toBe(1);
|
|
expect(s.safeParse({ ok: false, error: { code: "nope", message: "" } }).success).toBe(false);
|
|
});
|
|
|
|
it("错误码都有 HTTP 状态", () => {
|
|
expect(API_ERROR_STATUS.not_found).toBe(404);
|
|
});
|
|
|
|
it("事件信封与能力 ID", () => {
|
|
expect(
|
|
EventEnvelope.safeParse({ seq: 1, type: "system.heartbeat", at: new Date().toISOString(), payload: {} }).success,
|
|
).toBe(true);
|
|
expect(CapabilityId.safeParse("download.submit").success).toBe(true);
|
|
expect(CapabilityId.safeParse("Download").success).toBe(false);
|
|
});
|
|
});
|