From 16484827c95a964db606b82fe0552e6751f433c9 Mon Sep 17 00:00:00 2001 From: mzaxd Date: Mon, 23 Feb 2026 20:15:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=A2=E7=B4=A2=E6=A0=87=E7=AD=BE=E6=95=B0=E9=87=8F=E4=B8=8A?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/AGENTS.md | 2 +- src/lib/validations.test.ts | 33 ++++++++++++++++++++++++++++++++- src/lib/validations.ts | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/lib/AGENTS.md b/src/lib/AGENTS.md index 9907e90..8662a22 100644 --- a/src/lib/AGENTS.md +++ b/src/lib/AGENTS.md @@ -12,7 +12,7 @@ Shared utilities and infrastructure layers used across the application. **Purpose**: Input validation and type safety using Zod schemas -- `ProjectInputSchema`: Project data validation (1-10 tags, 1-10 links) +- `ProjectInputSchema`: Project data validation (1+ tags, 1-10 links) - `WebhookPayloadSchema`: Webhook request validation with API key auth - `KeywordInputSchema`: Keyword cloud data with visual config - `ProjectQuerySchema`: Query parameter validation (search, tags, status, pagination) diff --git a/src/lib/validations.test.ts b/src/lib/validations.test.ts index 78f7607..90f505b 100644 --- a/src/lib/validations.test.ts +++ b/src/lib/validations.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { AIEventInputSchema } from './validations'; +import { AIEventInputSchema, ProjectInputSchema } from './validations'; describe('AIEventInputSchema', () => { const validEvent = { @@ -62,3 +62,34 @@ describe('AIEventInputSchema', () => { })).toThrow(); }); }); + +describe('ProjectInputSchema', () => { + const baseProjectInput = { + name: 'Agent Park', + description: 'A curated list of practical AI agent tools.', + tags: [{ name: 'ai-agent' }], + links: [{ type: 'GITHUB' as const, url: 'https://github.com/example/repo' }], + }; + + it('should allow more than 10 tags', () => { + const manyTags = Array.from({ length: 20 }, (_, index) => ({ + name: `tag-${index + 1}`, + })); + + expect(() => + ProjectInputSchema.parse({ + ...baseProjectInput, + tags: manyTags, + }) + ).not.toThrow(); + }); + + it('should still require at least one tag', () => { + expect(() => + ProjectInputSchema.parse({ + ...baseProjectInput, + tags: [], + }) + ).toThrow(); + }); +}); diff --git a/src/lib/validations.ts b/src/lib/validations.ts index 27ecb4c..6c251c5 100644 --- a/src/lib/validations.ts +++ b/src/lib/validations.ts @@ -49,7 +49,7 @@ export const ProjectBaseSchema = z.object({ }); export const ProjectInputSchema = ProjectBaseSchema.extend({ - tags: z.array(TagSchema).min(1, "At least one tag is required").max(10), + tags: z.array(TagSchema).min(1, "At least one tag is required"), links: z.array(ExternalLinkSchema).min(1, "At least one link is required").max(10), });