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:
ghbot committed 2026-08-24 17:34:04 +08:00
1 parent db53296d78
commit 78bf8e9e41
87 files changed
+6003 -2587

No files matched your search

+38 -37
View File
@@ -12,40 +12,40 @@ Validating large arrays (thousands of items) can become a performance bottleneck
**Baseline performance:**
```typescript
import { z } from 'zod'
import { z } from "zod";
const itemSchema = z.object({
id: z.string(),
value: z.number(),
})
value: z.number()
});
const arraySchema = z.array(itemSchema)
const arraySchema = z.array(itemSchema);
// 10,000 items: ~100ms
// 100,000 items: ~1000ms
arraySchema.parse(largeArray)
arraySchema.parse(largeArray);
```
**Early exit on first error:**
```typescript
import { z } from 'zod'
import { z } from "zod";
function validateArrayFastFail<T>(
schema: z.ZodType<T>,
items: unknown[]
): { success: true; data: T[] } | { success: false; error: z.ZodError; index: number } {
const validated: T[] = []
const validated: T[] = [];
for (let i = 0; i < items.length; i++) {
const result = schema.safeParse(items[i])
const result = schema.safeParse(items[i]);
if (!result.success) {
return { success: false, error: result.error, index: i }
return { success: false, error: result.error, index: i };
}
validated.push(result.data)
validated.push(result.data);
}
return { success: true, data: validated }
return { success: true, data: validated };
}
// Stops at first invalid item instead of validating all
@@ -60,27 +60,25 @@ function validateSample<T>(
sampleSize: number = 100
): { valid: boolean; sampleErrors?: z.ZodIssue[] } {
// Validate random sample
const indices = new Set<number>()
const indices = new Set<number>();
while (indices.size < Math.min(sampleSize, items.length)) {
indices.add(Math.floor(Math.random() * items.length))
indices.add(Math.floor(Math.random() * items.length));
}
const errors: z.ZodIssue[] = []
const errors: z.ZodIssue[] = [];
for (const i of indices) {
const result = schema.safeParse(items[i])
const result = schema.safeParse(items[i]);
if (!result.success) {
errors.push(...result.error.issues)
errors.push(...result.error.issues);
}
}
return errors.length > 0
? { valid: false, sampleErrors: errors }
: { valid: true }
return errors.length > 0 ? { valid: false, sampleErrors: errors } : { valid: true };
}
// Check 100 random items from 100,000 - very fast
const check = validateSample(itemSchema, hugeArray)
const check = validateSample(itemSchema, hugeArray);
```
**Batched validation with progress:**
@@ -92,40 +90,42 @@ async function validateInBatches<T>(
batchSize: number = 1000,
onProgress?: (percent: number) => void
): Promise<z.SafeParseReturnType<unknown, T[]>> {
const validated: T[] = []
const errors: z.ZodIssue[] = []
const validated: T[] = [];
const errors: z.ZodIssue[] = [];
for (let i = 0; i < items.length; i += batchSize) {
const batch = items.slice(i, i + batchSize)
const batch = items.slice(i, i + batchSize);
// Validate batch
for (let j = 0; j < batch.length; j++) {
const result = schema.safeParse(batch[j])
const result = schema.safeParse(batch[j]);
if (result.success) {
validated.push(result.data)
validated.push(result.data);
} else {
errors.push(...result.error.issues.map(issue => ({
...issue,
path: [i + j, ...issue.path],
})))
errors.push(
...result.error.issues.map((issue) => ({
...issue,
path: [i + j, ...issue.path]
}))
);
}
}
// Report progress and yield to event loop
onProgress?.(Math.min(100, ((i + batchSize) / items.length) * 100))
await new Promise(resolve => setTimeout(resolve, 0))
onProgress?.(Math.min(100, ((i + batchSize) / items.length) * 100));
await new Promise((resolve) => setTimeout(resolve, 0));
}
if (errors.length > 0) {
return { success: false, error: new z.ZodError(errors) }
return { success: false, error: new z.ZodError(errors) };
}
return { success: true, data: validated }
return { success: true, data: validated };
}
// Use with progress reporting
await validateInBatches(itemSchema, largeArray, 1000, (percent) => {
console.log(`Validating: ${percent.toFixed(1)}%`)
})
console.log(`Validating: ${percent.toFixed(1)}%`);
});
```
**Streaming validation:**
@@ -136,17 +136,18 @@ async function* validateStream<T>(
items: AsyncIterable<unknown>
): AsyncGenerator<T, void, unknown> {
for await (const item of items) {
yield schema.parse(item) // Throws on invalid
yield schema.parse(item); // Throws on invalid
}
}
// Process items as they arrive
for await (const validItem of validateStream(itemSchema, dataStream)) {
await processItem(validItem)
await processItem(validItem);
}
```
**When NOT to use this pattern:**
- Small arrays (< 1000 items) - standard validation is fine
- When all items must be validated for correctness guarantees