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,33 +12,33 @@ tags: error, flatten, forms, user-experience
|
||||
**Incorrect (manual issue processing):**
|
||||
|
||||
```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 too short'),
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password too short"),
|
||||
profile: z.object({
|
||||
name: z.string().min(1, 'Name required'),
|
||||
}),
|
||||
})
|
||||
name: z.string().min(1, "Name required")
|
||||
})
|
||||
});
|
||||
|
||||
function getFieldErrors(error: z.ZodError) {
|
||||
const errors: Record<string, string> = {}
|
||||
const errors: Record<string, string> = {};
|
||||
|
||||
for (const issue of error.issues) {
|
||||
// Manual path joining - error prone
|
||||
const field = issue.path.join('.')
|
||||
const field = issue.path.join(".");
|
||||
if (!errors[field]) {
|
||||
errors[field] = issue.message
|
||||
errors[field] = issue.message;
|
||||
}
|
||||
}
|
||||
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
if (!result.success) {
|
||||
const errors = getFieldErrors(result.error)
|
||||
const errors = getFieldErrors(result.error);
|
||||
// { email: 'Invalid email', 'profile.name': 'Name required' }
|
||||
}
|
||||
```
|
||||
@@ -46,26 +46,26 @@ if (!result.success) {
|
||||
**Correct (using flatten):**
|
||||
|
||||
```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 too short'),
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password too short"),
|
||||
profile: z.object({
|
||||
name: z.string().min(1, 'Name required'),
|
||||
}),
|
||||
})
|
||||
name: z.string().min(1, "Name required")
|
||||
})
|
||||
});
|
||||
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
const { formErrors, fieldErrors } = result.error.flatten()
|
||||
const { formErrors, fieldErrors } = result.error.flatten();
|
||||
|
||||
// formErrors: string[] - top-level errors (from .refine on the object)
|
||||
// fieldErrors: { [key]: string[] } - errors by field
|
||||
|
||||
// Ready for form display
|
||||
console.log(fieldErrors)
|
||||
console.log(fieldErrors);
|
||||
// {
|
||||
// email: ['Invalid email'],
|
||||
// password: ['Password too short'],
|
||||
@@ -77,12 +77,15 @@ if (!result.success) {
|
||||
**With React Hook Form:**
|
||||
|
||||
```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 { register, formState: { errors } } = useForm({
|
||||
resolver: zodResolver(formSchema),
|
||||
})
|
||||
const {
|
||||
register,
|
||||
formState: { errors }
|
||||
} = useForm({
|
||||
resolver: zodResolver(formSchema)
|
||||
});
|
||||
|
||||
// errors are already flattened by the resolver
|
||||
// <input {...register('email')} />
|
||||
@@ -94,8 +97,8 @@ const { register, formState: { errors } } = useForm({
|
||||
```typescript
|
||||
const flattened = result.error.flatten((issue) => ({
|
||||
message: issue.message,
|
||||
code: issue.code,
|
||||
}))
|
||||
code: issue.code
|
||||
}));
|
||||
|
||||
// fieldErrors now contains custom objects
|
||||
// {
|
||||
@@ -106,10 +109,10 @@ const flattened = result.error.flatten((issue) => ({
|
||||
**For deeply nested objects, use format():**
|
||||
|
||||
```typescript
|
||||
const result = formSchema.safeParse(data)
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
const formatted = result.error.format()
|
||||
const formatted = result.error.format();
|
||||
// {
|
||||
// _errors: [],
|
||||
// email: { _errors: ['Invalid email'] },
|
||||
@@ -120,11 +123,12 @@ if (!result.success) {
|
||||
// }
|
||||
|
||||
// Access nested errors naturally
|
||||
formatted.profile?.name?._errors // ['Name required']
|
||||
formatted.profile?.name?._errors; // ['Name required']
|
||||
}
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When you need access to full issue metadata (code, path as array)
|
||||
- When using a form library that expects different error format
|
||||
|
||||
|
||||
Reference in new issue
Block a user