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,37 +12,38 @@ Zod provides specific schemas for each primitive type. Using the wrong schema (e
|
||||
**Incorrect (wrong primitive or any):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
// Using any loses all type safety
|
||||
const userSchema = z.object({
|
||||
id: z.any(), // Accepts anything - no validation
|
||||
age: z.string(), // Wrong type - age should be number
|
||||
active: z.any(), // Should be boolean
|
||||
})
|
||||
id: z.any(), // Accepts anything - no validation
|
||||
age: z.string(), // Wrong type - age should be number
|
||||
active: z.any() // Should be boolean
|
||||
});
|
||||
|
||||
// This passes validation but data is wrong
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" })
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" });
|
||||
// Result: { id: null, age: "twenty", active: "yes" }
|
||||
```
|
||||
|
||||
**Correct (specific primitives):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const userSchema = z.object({
|
||||
id: z.string().uuid(), // Specific format validation
|
||||
age: z.number().int().positive(), // Correct type with constraints
|
||||
active: z.boolean(), // Exact boolean type
|
||||
})
|
||||
id: z.string().uuid(), // Specific format validation
|
||||
age: z.number().int().positive(), // Correct type with constraints
|
||||
active: z.boolean() // Exact boolean type
|
||||
});
|
||||
|
||||
// Now invalid data is rejected
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" })
|
||||
userSchema.parse({ id: null, age: "twenty", active: "yes" });
|
||||
// Throws ZodError with specific field errors
|
||||
```
|
||||
|
||||
**Available primitive schemas:**
|
||||
|
||||
- `z.string()` - strings with optional regex, min, max, email, url, uuid
|
||||
- `z.number()` - numbers with optional int, positive, negative, min, max
|
||||
- `z.bigint()` - BigInt values
|
||||
@@ -55,6 +56,7 @@ userSchema.parse({ id: null, age: "twenty", active: "yes" })
|
||||
- `z.never()` - no valid value
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When you genuinely need to accept any value (rare - consider `z.unknown()` instead)
|
||||
- When migrating legacy code incrementally (use `z.any()` temporarily, then fix)
|
||||
|
||||
|
||||
Reference in new issue
Block a user