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,30 +12,30 @@ When a field is optional but should have a default value when missing, use `.def
|
||||
**Incorrect (defaults spread across codebase):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const configSchema = z.object({
|
||||
timeout: z.number().optional(),
|
||||
retries: z.number().optional(),
|
||||
debug: z.boolean().optional(),
|
||||
})
|
||||
debug: z.boolean().optional()
|
||||
});
|
||||
|
||||
type Config = z.infer<typeof configSchema>
|
||||
type Config = z.infer<typeof configSchema>;
|
||||
|
||||
function createClient(config: Config) {
|
||||
// Defaults handled in business logic - duplicated everywhere
|
||||
const timeout = config.timeout ?? 5000
|
||||
const retries = config.retries ?? 3
|
||||
const debug = config.debug ?? false
|
||||
const timeout = config.timeout ?? 5000;
|
||||
const retries = config.retries ?? 3;
|
||||
const debug = config.debug ?? false;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
function createOtherClient(config: Config) {
|
||||
// Same defaults duplicated - risk of inconsistency
|
||||
const timeout = config.timeout ?? 5000
|
||||
const retries = config.retries ?? 3 // What if someone uses 2 here?
|
||||
const debug = config.debug ?? false
|
||||
const timeout = config.timeout ?? 5000;
|
||||
const retries = config.retries ?? 3; // What if someone uses 2 here?
|
||||
const debug = config.debug ?? false;
|
||||
|
||||
// ...
|
||||
}
|
||||
@@ -44,30 +44,30 @@ function createOtherClient(config: Config) {
|
||||
**Correct (defaults in schema):**
|
||||
|
||||
```typescript
|
||||
import { z } from 'zod'
|
||||
import { z } from "zod";
|
||||
|
||||
const configSchema = z.object({
|
||||
timeout: z.number().default(5000),
|
||||
retries: z.number().default(3),
|
||||
debug: z.boolean().default(false),
|
||||
})
|
||||
debug: z.boolean().default(false)
|
||||
});
|
||||
|
||||
type Config = z.infer<typeof configSchema>
|
||||
type Config = z.infer<typeof configSchema>;
|
||||
// { timeout: number; retries: number; debug: boolean }
|
||||
// No optional - defaults fill in missing values
|
||||
|
||||
function createClient(config: Config) {
|
||||
// config.timeout is guaranteed to exist
|
||||
console.log(config.timeout) // 5000 if not provided
|
||||
console.log(config.retries) // 3 if not provided
|
||||
console.log(config.debug) // false if not provided
|
||||
console.log(config.timeout); // 5000 if not provided
|
||||
console.log(config.retries); // 3 if not provided
|
||||
console.log(config.debug); // false if not provided
|
||||
}
|
||||
|
||||
// Parse fills in defaults
|
||||
configSchema.parse({})
|
||||
configSchema.parse({});
|
||||
// { timeout: 5000, retries: 3, debug: false }
|
||||
|
||||
configSchema.parse({ timeout: 10000 })
|
||||
configSchema.parse({ timeout: 10000 });
|
||||
// { timeout: 10000, retries: 3, debug: false }
|
||||
```
|
||||
|
||||
@@ -76,13 +76,13 @@ configSchema.parse({ timeout: 10000 })
|
||||
```typescript
|
||||
const schema = z.object({
|
||||
name: z.string(),
|
||||
role: z.enum(['admin', 'user']).default('user'),
|
||||
})
|
||||
role: z.enum(["admin", "user"]).default("user")
|
||||
});
|
||||
|
||||
type SchemaInput = z.input<typeof schema>
|
||||
type SchemaInput = z.input<typeof schema>;
|
||||
// { name: string; role?: 'admin' | 'user' }
|
||||
|
||||
type SchemaOutput = z.output<typeof schema>
|
||||
type SchemaOutput = z.output<typeof schema>;
|
||||
// { name: string; role: 'admin' | 'user' }
|
||||
|
||||
// Input type is optional, output type is required
|
||||
@@ -93,38 +93,39 @@ type SchemaOutput = z.output<typeof schema>
|
||||
```typescript
|
||||
// Static default
|
||||
const schema1 = z.object({
|
||||
id: z.string().default('temp-id'),
|
||||
})
|
||||
id: z.string().default("temp-id")
|
||||
});
|
||||
|
||||
// Factory function for dynamic defaults
|
||||
const schema2 = z.object({
|
||||
id: z.string().default(() => crypto.randomUUID()),
|
||||
createdAt: z.date().default(() => new Date()),
|
||||
})
|
||||
createdAt: z.date().default(() => new Date())
|
||||
});
|
||||
|
||||
// Each parse creates new values
|
||||
schema2.parse({}) // { id: 'abc-123...', createdAt: 2024-01-15... }
|
||||
schema2.parse({}) // { id: 'def-456...', createdAt: 2024-01-15... }
|
||||
schema2.parse({}); // { id: 'abc-123...', createdAt: 2024-01-15... }
|
||||
schema2.parse({}); // { id: 'def-456...', createdAt: 2024-01-15... }
|
||||
```
|
||||
|
||||
**Combining with optional/nullable:**
|
||||
|
||||
```typescript
|
||||
// .optional().default() - if undefined, use default
|
||||
z.string().optional().default('fallback')
|
||||
z.string().optional().default("fallback");
|
||||
|
||||
// .nullable().default() - null stays null, only undefined gets default
|
||||
z.string().nullable().default('fallback')
|
||||
z.string().nullable().default("fallback");
|
||||
// null -> null
|
||||
// undefined -> 'fallback'
|
||||
|
||||
// .nullish().default() - both null and undefined get default
|
||||
z.string().nullish().default('fallback')
|
||||
z.string().nullish().default("fallback");
|
||||
// null -> 'fallback'
|
||||
// undefined -> 'fallback'
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- When absence of value has different meaning than default
|
||||
- When defaults depend on other fields (use transform)
|
||||
|
||||
|
||||
Reference in new issue
Block a user