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,23 +12,23 @@ When handling PATCH/PUT updates, you need a schema where all fields are optional
|
||||
**Incorrect (duplicating schemas):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
// Base schema
|
||||
const userSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
email: z.string().email(),
|
||||
age: z.number().int().positive(),
|
||||
role: z.enum(['admin', 'user']),
|
||||
})
|
||||
role: z.enum(["admin", "user"])
|
||||
});
|
||||
|
||||
// Manually duplicated for updates - will drift!
|
||||
const updateUserSchema = z.object({
|
||||
name: z.string().min(1).optional(),
|
||||
email: z.string().email().optional(),
|
||||
age: z.number().int().positive().optional(),
|
||||
age: z.number().int().positive().optional()
|
||||
// Forgot to add role - schemas out of sync!
|
||||
})
|
||||
});
|
||||
|
||||
// Later, you add a field to userSchema but forget updateUserSchema
|
||||
// Now updates silently ignore the new field
|
||||
@@ -37,28 +37,28 @@ const updateUserSchema = z.object({
|
||||
**Correct (using partial):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
// Base schema - single source of truth
|
||||
const userSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
email: z.string().email(),
|
||||
age: z.number().int().positive(),
|
||||
role: z.enum(['admin', 'user']),
|
||||
})
|
||||
role: z.enum(["admin", "user"])
|
||||
});
|
||||
|
||||
// All fields optional for updates
|
||||
const updateUserSchema = userSchema.partial()
|
||||
const updateUserSchema = userSchema.partial();
|
||||
|
||||
type User = z.infer<typeof userSchema>
|
||||
type User = z.infer<typeof userSchema>;
|
||||
// { name: string; email: string; age: number; role: 'admin' | 'user' }
|
||||
|
||||
type UpdateUser = z.infer<typeof updateUserSchema>
|
||||
type UpdateUser = z.infer<typeof updateUserSchema>;
|
||||
// { name?: string; email?: string; age?: number; role?: 'admin' | 'user' }
|
||||
|
||||
// Validate partial updates
|
||||
updateUserSchema.parse({ email: 'new@example.com' }) // Valid
|
||||
updateUserSchema.parse({}) // Valid - all fields optional
|
||||
updateUserSchema.parse({ email: "new@example.com" }); // Valid
|
||||
updateUserSchema.parse({}); // Valid - all fields optional
|
||||
```
|
||||
|
||||
**Partial specific fields only:**
|
||||
@@ -67,10 +67,10 @@ updateUserSchema.parse({}) // Valid - all fields optional
|
||||
// Only name and email are optional for updates
|
||||
const updateUserSchema = userSchema.partial({
|
||||
name: true,
|
||||
email: true,
|
||||
})
|
||||
email: true
|
||||
});
|
||||
|
||||
type UpdateUser = z.infer<typeof updateUserSchema>
|
||||
type UpdateUser = z.infer<typeof updateUserSchema>;
|
||||
// { name?: string; email?: string; age: number; role: 'admin' | 'user' }
|
||||
// age and role still required
|
||||
```
|
||||
@@ -81,21 +81,21 @@ type UpdateUser = z.infer<typeof updateUserSchema>
|
||||
const addressSchema = z.object({
|
||||
street: z.string(),
|
||||
city: z.string(),
|
||||
country: z.string(),
|
||||
})
|
||||
country: z.string()
|
||||
});
|
||||
|
||||
const userSchema = z.object({
|
||||
name: z.string(),
|
||||
address: addressSchema,
|
||||
})
|
||||
address: addressSchema
|
||||
});
|
||||
|
||||
// .partial() only makes top-level fields optional
|
||||
const shallowPartial = userSchema.partial()
|
||||
const shallowPartial = userSchema.partial();
|
||||
// { name?: string; address?: { street: string; city: string; country: string } }
|
||||
// If address is provided, all its fields are still required!
|
||||
|
||||
// Use deepPartial for nested optionality
|
||||
const deepPartialSchema = userSchema.deepPartial()
|
||||
const deepPartialSchema = userSchema.deepPartial();
|
||||
// { name?: string; address?: { street?: string; city?: string; country?: string } }
|
||||
```
|
||||
|
||||
@@ -106,17 +106,18 @@ const baseSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
name: z.string(),
|
||||
email: z.string().email(),
|
||||
createdAt: z.date(),
|
||||
})
|
||||
createdAt: z.date()
|
||||
});
|
||||
|
||||
// Create: id and createdAt are generated, rest required
|
||||
const createSchema = baseSchema.omit({ id: true, createdAt: true })
|
||||
const createSchema = baseSchema.omit({ id: true, createdAt: true });
|
||||
|
||||
// Update: all user-editable fields optional
|
||||
const updateSchema = baseSchema.partial().omit({ id: true, createdAt: true })
|
||||
const updateSchema = baseSchema.partial().omit({ id: true, createdAt: true });
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When update logic differs significantly from create (different validations)
|
||||
- When using GraphQL with explicit input types
|
||||
|
||||
|
||||
Reference in new issue
Block a user