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,7 +12,7 @@ When you need different views of the same data (public vs private, create vs res
|
||||
**Incorrect (duplicating for variants):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
// Full user schema
|
||||
const userSchema = z.object({
|
||||
@@ -21,8 +21,8 @@ const userSchema = z.object({
|
||||
passwordHash: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.date(),
|
||||
isAdmin: z.boolean(),
|
||||
})
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
// Public view - manually duplicated
|
||||
const publicUserSchema = z.object({
|
||||
@@ -30,22 +30,22 @@ const publicUserSchema = z.object({
|
||||
name: z.string(),
|
||||
// Forgot email - now users can't see it
|
||||
// Added avatar field - doesn't exist in base schema
|
||||
avatar: z.string().optional(),
|
||||
})
|
||||
avatar: z.string().optional()
|
||||
});
|
||||
|
||||
// Create input - manually duplicated
|
||||
const createUserSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string().min(8), // Different from passwordHash
|
||||
name: z.string(),
|
||||
password: z.string().min(8), // Different from passwordHash
|
||||
name: z.string()
|
||||
// Missing isAdmin - can't set on create? Intentional?
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
**Correct (using pick and omit):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
// Full user schema - single source of truth
|
||||
const userSchema = z.object({
|
||||
@@ -54,35 +54,35 @@ const userSchema = z.object({
|
||||
passwordHash: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.date(),
|
||||
isAdmin: z.boolean(),
|
||||
})
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
// Public view - explicitly pick public fields
|
||||
const publicUserSchema = userSchema.pick({
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
})
|
||||
name: true
|
||||
});
|
||||
|
||||
type PublicUser = z.infer<typeof publicUserSchema>
|
||||
type PublicUser = z.infer<typeof publicUserSchema>;
|
||||
// { id: string; email: string; name: string }
|
||||
|
||||
// API response - omit sensitive fields
|
||||
const userResponseSchema = userSchema.omit({
|
||||
passwordHash: true,
|
||||
})
|
||||
passwordHash: true
|
||||
});
|
||||
|
||||
type UserResponse = z.infer<typeof userResponseSchema>
|
||||
type UserResponse = z.infer<typeof userResponseSchema>;
|
||||
// { id: string; email: string; name: string; createdAt: Date; isAdmin: boolean }
|
||||
|
||||
// Create input - omit generated fields
|
||||
const createUserInputSchema = userSchema
|
||||
.omit({ id: true, createdAt: true, passwordHash: true })
|
||||
.extend({
|
||||
password: z.string().min(8), // Add password (different from hash)
|
||||
})
|
||||
password: z.string().min(8) // Add password (different from hash)
|
||||
});
|
||||
|
||||
type CreateUserInput = z.infer<typeof createUserInputSchema>
|
||||
type CreateUserInput = z.infer<typeof createUserInputSchema>;
|
||||
// { email: string; name: string; isAdmin: boolean; password: string }
|
||||
```
|
||||
|
||||
@@ -96,27 +96,27 @@ const dbRowSchema = z.object({
|
||||
email: z.string(),
|
||||
password_hash: z.string(),
|
||||
internal_notes: z.string(),
|
||||
created_at: z.date(),
|
||||
})
|
||||
created_at: z.date()
|
||||
});
|
||||
|
||||
const apiResponseSchema = dbRowSchema.omit({
|
||||
id: true, // Internal DB id
|
||||
password_hash: true, // Sensitive
|
||||
internal_notes: true, // Staff only
|
||||
})
|
||||
id: true, // Internal DB id
|
||||
password_hash: true, // Sensitive
|
||||
internal_notes: true // Staff only
|
||||
});
|
||||
|
||||
// Form data → Database insert (add generated fields)
|
||||
const formSchema = z.object({
|
||||
title: z.string(),
|
||||
content: z.string(),
|
||||
})
|
||||
content: z.string()
|
||||
});
|
||||
|
||||
const dbInsertSchema = formSchema.extend({
|
||||
id: z.string().uuid(),
|
||||
authorId: z.string().uuid(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
})
|
||||
updatedAt: z.date()
|
||||
});
|
||||
```
|
||||
|
||||
**Chaining operations:**
|
||||
@@ -126,20 +126,21 @@ const baseSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
role: z.enum(['admin', 'user']),
|
||||
secret: z.string(),
|
||||
})
|
||||
role: z.enum(["admin", "user"]),
|
||||
secret: z.string()
|
||||
});
|
||||
|
||||
// Combine pick, omit, partial, extend
|
||||
const updateSchema = baseSchema
|
||||
.omit({ id: true, secret: true }) // Remove immutable/sensitive
|
||||
.partial() // Make all optional for updates
|
||||
.omit({ id: true, secret: true }) // Remove immutable/sensitive
|
||||
.partial() // Make all optional for updates
|
||||
.extend({
|
||||
updatedAt: z.date().optional(), // Add update timestamp
|
||||
})
|
||||
updatedAt: z.date().optional() // Add update timestamp
|
||||
});
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When derived schemas need different validation rules (not just different fields)
|
||||
- When the relationship between schemas is not subset/superset
|
||||
|
||||
|
||||
Reference in new issue
Block a user