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,21 +12,21 @@ HTML forms and URL query parameters always transmit data as strings. Using `z.nu
|
||||
**Incorrect (no coercion for form data):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const searchSchema = z.object({
|
||||
query: z.string(),
|
||||
page: z.number(), // Expects actual number
|
||||
page: z.number(), // Expects actual number
|
||||
limit: z.number(),
|
||||
showDeleted: z.boolean(), // Expects actual boolean
|
||||
})
|
||||
showDeleted: z.boolean() // Expects actual boolean
|
||||
});
|
||||
|
||||
// Form data / query params are strings
|
||||
const formData = new URLSearchParams('query=test&page=1&limit=10&showDeleted=true')
|
||||
const params = Object.fromEntries(formData)
|
||||
const formData = new URLSearchParams("query=test&page=1&limit=10&showDeleted=true");
|
||||
const params = Object.fromEntries(formData);
|
||||
// { query: 'test', page: '1', limit: '10', showDeleted: 'true' }
|
||||
|
||||
searchSchema.parse(params)
|
||||
searchSchema.parse(params);
|
||||
// ZodError: Expected number, received string at "page"
|
||||
// ZodError: Expected number, received string at "limit"
|
||||
// ZodError: Expected boolean, received string at "showDeleted"
|
||||
@@ -35,20 +35,20 @@ searchSchema.parse(params)
|
||||
**Correct (using coercion):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const searchSchema = z.object({
|
||||
query: z.string(),
|
||||
page: z.coerce.number().int().positive().default(1),
|
||||
limit: z.coerce.number().int().min(1).max(100).default(10),
|
||||
showDeleted: z.coerce.boolean().default(false),
|
||||
})
|
||||
showDeleted: z.coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
// Form data / query params are strings
|
||||
const formData = new URLSearchParams('query=test&page=1&limit=10&showDeleted=true')
|
||||
const params = Object.fromEntries(formData)
|
||||
const formData = new URLSearchParams("query=test&page=1&limit=10&showDeleted=true");
|
||||
const params = Object.fromEntries(formData);
|
||||
|
||||
const result = searchSchema.parse(params)
|
||||
const result = searchSchema.parse(params);
|
||||
// { query: 'test', page: 1, limit: 10, showDeleted: true }
|
||||
// Types are correct: number, number, boolean
|
||||
```
|
||||
@@ -56,32 +56,33 @@ const result = searchSchema.parse(params)
|
||||
**Available coercion types:**
|
||||
|
||||
```typescript
|
||||
z.coerce.string() // Converts anything to string via String(value)
|
||||
z.coerce.number() // Converts via Number(value), NaN fails validation
|
||||
z.coerce.boolean() // Truthy/falsy conversion
|
||||
z.coerce.bigint() // Converts via BigInt(value)
|
||||
z.coerce.date() // Converts via new Date(value)
|
||||
z.coerce.string(); // Converts anything to string via String(value)
|
||||
z.coerce.number(); // Converts via Number(value), NaN fails validation
|
||||
z.coerce.boolean(); // Truthy/falsy conversion
|
||||
z.coerce.bigint(); // Converts via BigInt(value)
|
||||
z.coerce.date(); // Converts via new Date(value)
|
||||
```
|
||||
|
||||
**Coercion edge cases:**
|
||||
|
||||
```typescript
|
||||
// z.coerce.number() behavior
|
||||
z.coerce.number().parse("42") // 42
|
||||
z.coerce.number().parse("") // 0 (empty string becomes 0!)
|
||||
z.coerce.number().parse("abc") // ZodError (NaN fails)
|
||||
z.coerce.number().parse("42"); // 42
|
||||
z.coerce.number().parse(""); // 0 (empty string becomes 0!)
|
||||
z.coerce.number().parse("abc"); // ZodError (NaN fails)
|
||||
|
||||
// z.coerce.boolean() behavior
|
||||
z.coerce.boolean().parse("true") // true
|
||||
z.coerce.boolean().parse("false") // true! (non-empty string is truthy)
|
||||
z.coerce.boolean().parse("") // false
|
||||
z.coerce.boolean().parse("0") // true! (non-empty string)
|
||||
z.coerce.boolean().parse("true"); // true
|
||||
z.coerce.boolean().parse("false"); // true! (non-empty string is truthy)
|
||||
z.coerce.boolean().parse(""); // false
|
||||
z.coerce.boolean().parse("0"); // true! (non-empty string)
|
||||
|
||||
// For strict boolean parsing from strings:
|
||||
const strictBooleanSchema = z.enum(['true', 'false']).transform(v => v === 'true')
|
||||
const strictBooleanSchema = z.enum(["true", "false"]).transform((v) => v === "true");
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When receiving JSON payloads (already typed correctly)
|
||||
- When you want strict type checking without conversion
|
||||
|
||||
|
||||
Reference in new issue
Block a user