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

@@ -12,19 +12,19 @@ When building on existing schemas, use `.extend()` to add new fields rather than
**Incorrect (manual object spreading):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const baseUserSchema = z.object({
id: z.string(),
name: z.string(),
})
name: z.string()
});
// Manual spreading loses Zod's schema relationship
const adminUserSchema = z.object({
...baseUserSchema.shape, // Accessing internal .shape
role: z.literal('admin'),
permissions: z.array(z.string()),
})
...baseUserSchema.shape, // Accessing internal .shape
role: z.literal("admin"),
permissions: z.array(z.string())
});
// Problems:
// 1. If baseUserSchema changes, TypeScript might not catch issues
@@ -35,21 +35,21 @@ const adminUserSchema = z.object({
**Correct (using extend):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const baseUserSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
})
email: z.string().email()
});
// Extend to add fields
const adminUserSchema = baseUserSchema.extend({
role: z.literal('admin'),
permissions: z.array(z.string()),
})
role: z.literal("admin"),
permissions: z.array(z.string())
});
type AdminUser = z.infer<typeof adminUserSchema>
type AdminUser = z.infer<typeof adminUserSchema>;
// {
// id: string;
// name: string;
@@ -60,8 +60,8 @@ type AdminUser = z.infer<typeof adminUserSchema>
// Override existing fields
const strictEmailSchema = baseUserSchema.extend({
email: z.string().email().endsWith('@company.com'), // Stricter validation
})
email: z.string().email().endsWith("@company.com") // Stricter validation
});
```
**Building hierarchies with extend:**
@@ -71,31 +71,33 @@ const strictEmailSchema = baseUserSchema.extend({
const entitySchema = z.object({
id: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date(),
})
updatedAt: z.date()
});
// User extends entity
const userSchema = entitySchema.extend({
email: z.string().email(),
name: z.string(),
})
name: z.string()
});
// Product extends entity
const productSchema = entitySchema.extend({
name: z.string(),
price: z.number().positive(),
sku: z.string(),
})
sku: z.string()
});
// Order extends entity with references
const orderSchema = entitySchema.extend({
userId: z.string().uuid(),
items: z.array(z.object({
productId: z.string().uuid(),
quantity: z.number().int().positive(),
})),
total: z.number().positive(),
})
items: z.array(
z.object({
productId: z.string().uuid(),
quantity: z.number().int().positive()
})
),
total: z.number().positive()
});
```
**Combining extend with other methods:**
@@ -104,22 +106,18 @@ const orderSchema = entitySchema.extend({
const baseSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string(),
})
email: z.string()
});
// Create input: no id, add password
const createSchema = baseSchema
.omit({ id: true })
.extend({
password: z.string().min(8),
})
const createSchema = baseSchema.omit({ id: true }).extend({
password: z.string().min(8)
});
// Update input: all optional except id
const updateSchema = baseSchema
.partial()
.extend({
id: z.string(), // Override to make required
})
const updateSchema = baseSchema.partial().extend({
id: z.string() // Override to make required
});
```
**Merge for combining independent schemas:**
@@ -127,20 +125,21 @@ const updateSchema = baseSchema
```typescript
const addressSchema = z.object({
street: z.string(),
city: z.string(),
})
city: z.string()
});
const contactSchema = z.object({
email: z.string().email(),
phone: z.string(),
})
phone: z.string()
});
// Merge combines two schemas (both required)
const customerSchema = addressSchema.merge(contactSchema)
const customerSchema = addressSchema.merge(contactSchema);
// { street: string; city: string; email: string; phone: string }
```
**When NOT to use this pattern:**
- When schemas are genuinely independent (use merge or intersection)
- When you need to remove fields (use omit)