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
@@ -12,28 +12,28 @@ Zod collects all validation failures, not just the first one. When displaying er
|
||||
**Incorrect (showing only first error):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email('Invalid email'),
|
||||
password: z.string().min(8, 'Password must be 8+ characters'),
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password must be 8+ characters"),
|
||||
confirmPassword: z.string(),
|
||||
age: z.number().min(18, 'Must be 18 or older'),
|
||||
})
|
||||
age: z.number().min(18, "Must be 18 or older")
|
||||
});
|
||||
|
||||
function validateForm(data: unknown) {
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
// Only shows first error - terrible UX
|
||||
return { error: result.error.issues[0].message }
|
||||
return { error: result.error.issues[0].message };
|
||||
}
|
||||
|
||||
return { data: result.data }
|
||||
return { data: result.data };
|
||||
}
|
||||
|
||||
// User submits empty form
|
||||
validateForm({})
|
||||
validateForm({});
|
||||
// Returns: { error: 'Invalid email' }
|
||||
// User fixes email, submits again
|
||||
// Returns: { error: 'Password must be 8+ characters' }
|
||||
@@ -44,38 +44,38 @@ validateForm({})
|
||||
**Correct (showing all errors):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email('Invalid email'),
|
||||
password: z.string().min(8, 'Password must be 8+ characters'),
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password must be 8+ characters"),
|
||||
confirmPassword: z.string(),
|
||||
age: z.number().min(18, 'Must be 18 or older'),
|
||||
})
|
||||
age: z.number().min(18, "Must be 18 or older")
|
||||
});
|
||||
|
||||
function validateForm(data: unknown) {
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
// Collect errors by field for form display
|
||||
const fieldErrors: Record<string, string[]> = {}
|
||||
const fieldErrors: Record<string, string[]> = {};
|
||||
|
||||
for (const issue of result.error.issues) {
|
||||
const field = issue.path.join('.')
|
||||
const field = issue.path.join(".");
|
||||
if (!fieldErrors[field]) {
|
||||
fieldErrors[field] = []
|
||||
fieldErrors[field] = [];
|
||||
}
|
||||
fieldErrors[field].push(issue.message)
|
||||
fieldErrors[field].push(issue.message);
|
||||
}
|
||||
|
||||
return { errors: fieldErrors }
|
||||
return { errors: fieldErrors };
|
||||
}
|
||||
|
||||
return { data: result.data }
|
||||
return { data: result.data };
|
||||
}
|
||||
|
||||
// User submits empty form
|
||||
validateForm({})
|
||||
validateForm({});
|
||||
// Returns: {
|
||||
// errors: {
|
||||
// email: ['Invalid email'],
|
||||
@@ -90,10 +90,10 @@ validateForm({})
|
||||
**Using flatten() for simpler error structure:**
|
||||
|
||||
```typescript
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
const flattened = result.error.flatten()
|
||||
const flattened = result.error.flatten();
|
||||
// {
|
||||
// formErrors: [], // Top-level errors
|
||||
// fieldErrors: {
|
||||
@@ -102,23 +102,24 @@ if (!result.success) {
|
||||
// ...
|
||||
// }
|
||||
// }
|
||||
return { errors: flattened.fieldErrors }
|
||||
return { errors: flattened.fieldErrors };
|
||||
}
|
||||
```
|
||||
|
||||
**With React Hook Form integration:**
|
||||
|
||||
```typescript
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema),
|
||||
resolver: zodResolver(formSchema)
|
||||
// All errors are automatically collected and displayed
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- Rate-limited APIs where you want to fail fast on first error
|
||||
- Large batch processing where full validation is expensive
|
||||
|
||||
|
||||
Reference in new issue
Block a user