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
@@ -13,15 +13,15 @@ For applications with many complex schemas, importing all of them upfront increa
|
||||
|
||||
```typescript
|
||||
// schemas/index.ts - barrel file with everything
|
||||
export * from './user'
|
||||
export * from './order'
|
||||
export * from './product'
|
||||
export * from './analytics' // Large, complex schema
|
||||
export * from './reports' // Another large schema
|
||||
export * from './admin' // Admin-only schemas
|
||||
export * from "./user";
|
||||
export * from "./order";
|
||||
export * from "./product";
|
||||
export * from "./analytics"; // Large, complex schema
|
||||
export * from "./reports"; // Another large schema
|
||||
export * from "./admin"; // Admin-only schemas
|
||||
|
||||
// app/page.tsx
|
||||
import { userSchema, orderSchema, analyticsSchema, reportsSchema } from '@/schemas'
|
||||
import { userSchema, orderSchema, analyticsSchema, reportsSchema } from "@/schemas";
|
||||
// All schemas loaded even if not used on this page
|
||||
```
|
||||
|
||||
@@ -29,17 +29,17 @@ import { userSchema, orderSchema, analyticsSchema, reportsSchema } from '@/schem
|
||||
|
||||
```typescript
|
||||
// Only import what's immediately needed
|
||||
import { userSchema } from '@/schemas/user'
|
||||
import { userSchema } from "@/schemas/user";
|
||||
|
||||
async function loadAnalyticsSchema() {
|
||||
const { analyticsSchema } = await import('@/schemas/analytics')
|
||||
return analyticsSchema
|
||||
const { analyticsSchema } = await import("@/schemas/analytics");
|
||||
return analyticsSchema;
|
||||
}
|
||||
|
||||
// Use when needed
|
||||
async function handleAnalyticsData(data: unknown) {
|
||||
const schema = await loadAnalyticsSchema()
|
||||
return schema.safeParse(data)
|
||||
const schema = await loadAnalyticsSchema();
|
||||
return schema.safeParse(data);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -104,30 +104,31 @@ export default function ReportsForm() {
|
||||
```typescript
|
||||
// schemas/registry.ts
|
||||
const schemaLoaders = {
|
||||
user: () => import('./user').then(m => m.userSchema),
|
||||
order: () => import('./order').then(m => m.orderSchema),
|
||||
analytics: () => import('./analytics').then(m => m.analyticsSchema),
|
||||
reports: () => import('./reports').then(m => m.reportsSchema),
|
||||
} as const
|
||||
user: () => import("./user").then((m) => m.userSchema),
|
||||
order: () => import("./order").then((m) => m.orderSchema),
|
||||
analytics: () => import("./analytics").then((m) => m.analyticsSchema),
|
||||
reports: () => import("./reports").then((m) => m.reportsSchema)
|
||||
} as const;
|
||||
|
||||
type SchemaName = keyof typeof schemaLoaders
|
||||
type SchemaName = keyof typeof schemaLoaders;
|
||||
|
||||
const schemaCache = new Map<SchemaName, z.ZodType>()
|
||||
const schemaCache = new Map<SchemaName, z.ZodType>();
|
||||
|
||||
export async function getSchema(name: SchemaName) {
|
||||
if (!schemaCache.has(name)) {
|
||||
const schema = await schemaLoaders[name]()
|
||||
schemaCache.set(name, schema)
|
||||
const schema = await schemaLoaders[name]();
|
||||
schemaCache.set(name, schema);
|
||||
}
|
||||
return schemaCache.get(name)!
|
||||
return schemaCache.get(name)!;
|
||||
}
|
||||
|
||||
// Usage
|
||||
const schema = await getSchema('analytics')
|
||||
schema.parse(data)
|
||||
const schema = await getSchema("analytics");
|
||||
schema.parse(data);
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- Server-side rendering where all code is available
|
||||
- Small applications with few schemas
|
||||
- Schemas used on every page (defeats purpose)
|
||||
|
||||
Reference in new issue
Block a user