feat: v2.0 iteration — test coverage, reliability, observability
M0: Test coverage expansion (151 → 321 tests, 61% → 66% lines) - normalizeKnowledge CRLF/LF normalization fix - gooseReviewer: 11 tests, 97.35% coverage - r2 storage: 22 tests, 100% coverage - triage processor: 11 tests, exported buildTriagePrompt/labelName - webhook processor: 35 tests, 72.39% coverage - conflict resolver: 12 tests - review processor: 7 tests M1: Reliability hardening - Smart retry with jitter, maxTotalTimeoutMs, custom retryable predicate - MergeGuard: in-memory merge dedup tracker (100% coverage) - failureMessages: 7-category failure classifier (100% coverage) M2: Observability - MetricsCollector: Actions-run metrics with snapshot/markdown/reset - 11 tests, 100% coverage New files: 12 test files, 3 source modules All gates: typecheck ✓ lint ✓ format ✓ 321/321 tests ✓ build ✓
This commit is contained in:
1 parent
db53296d78
commit
78bf8e9e41
87 files changed
+6003
-2587
No files matched your search
@@ -58,18 +58,19 @@ function UserForm() {
|
||||
**For dynamic schemas, use useMemo:**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { useMemo } from 'react'
|
||||
import { z } from "zod";
|
||||
import { useMemo } from "react";
|
||||
|
||||
function DynamicForm({ minAge }: { minAge: number }) {
|
||||
// Schema only recreated when minAge changes
|
||||
const userSchema = useMemo(() =>
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
age: z.number().min(minAge),
|
||||
}),
|
||||
const userSchema = useMemo(
|
||||
() =>
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
age: z.number().min(minAge)
|
||||
}),
|
||||
[minAge]
|
||||
)
|
||||
);
|
||||
|
||||
// ...
|
||||
}
|
||||
@@ -79,19 +80,19 @@ function DynamicForm({ minAge }: { minAge: number }) {
|
||||
|
||||
```typescript
|
||||
// schemas/user.ts - created once per process
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
email: z.string().email(),
|
||||
})
|
||||
email: z.string().email()
|
||||
});
|
||||
|
||||
// api/users.ts
|
||||
import { userSchema } from '@/schemas/user'
|
||||
import { userSchema } from "@/schemas/user";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const body = await req.json()
|
||||
const result = userSchema.safeParse(body) // Reuses cached schema
|
||||
const body = await req.json();
|
||||
const result = userSchema.safeParse(body); // Reuses cached schema
|
||||
// ...
|
||||
}
|
||||
```
|
||||
@@ -103,35 +104,39 @@ export async function POST(req: Request) {
|
||||
function createUserSchema(role: string) {
|
||||
return z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(z.string()),
|
||||
})
|
||||
permissions: z.array(z.string())
|
||||
});
|
||||
}
|
||||
|
||||
// Called in hot loop
|
||||
users.forEach(user => {
|
||||
createUserSchema(user.role).parse(user) // New schema every iteration!
|
||||
})
|
||||
users.forEach((user) => {
|
||||
createUserSchema(user.role).parse(user); // New schema every iteration!
|
||||
});
|
||||
|
||||
// GOOD: Cache by key
|
||||
const schemaCache = new Map<string, z.ZodObject<any>>()
|
||||
const schemaCache = new Map<string, z.ZodObject<any>>();
|
||||
|
||||
function getUserSchema(role: string) {
|
||||
if (!schemaCache.has(role)) {
|
||||
schemaCache.set(role, z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(z.string()),
|
||||
}))
|
||||
schemaCache.set(
|
||||
role,
|
||||
z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(z.string())
|
||||
})
|
||||
);
|
||||
}
|
||||
return schemaCache.get(role)!
|
||||
return schemaCache.get(role)!;
|
||||
}
|
||||
|
||||
// Reuses cached schemas
|
||||
users.forEach(user => {
|
||||
getUserSchema(user.role).parse(user)
|
||||
})
|
||||
users.forEach((user) => {
|
||||
getUserSchema(user.role).parse(user);
|
||||
});
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- One-off validation where schema is used once
|
||||
- Test files where performance doesn't matter
|
||||
|
||||
|
||||
Reference in new issue
Block a user