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,28 +12,28 @@ Making too many fields optional creates overly permissive schemas that validate
**Incorrect (optional abuse):**
```typescript
import { z } from 'zod'
import { z } from "zod";
// Every field optional - almost anything passes
const userSchema = z.object({
id: z.string().optional(),
name: z.string().optional(),
email: z.string().optional(),
role: z.string().optional(),
})
role: z.string().optional()
});
type User = z.infer<typeof userSchema>
type User = z.infer<typeof userSchema>;
// { id?: string; name?: string; email?: string; role?: string }
// Empty object passes validation!
userSchema.parse({}) // ✓ Valid: {}
userSchema.parse({}); // ✓ Valid: {}
function greetUser(user: User) {
// Forced to add null checks everywhere
if (user.name) {
console.log(`Hello, ${user.name}`)
console.log(`Hello, ${user.name}`);
} else {
console.log('Hello, stranger') // Shouldn't happen if data is clean
console.log("Hello, stranger"); // Shouldn't happen if data is clean
}
}
```
@@ -41,30 +41,30 @@ function greetUser(user: User) {
**Correct (explicit required vs optional):**
```typescript
import { z } from 'zod'
import { z } from "zod";
// Required fields are required, optional fields are intentional
const userSchema = z.object({
id: z.string().uuid(), // Required
name: z.string().min(1), // Required, non-empty
email: z.string().email(), // Required
role: z.enum(['admin', 'user', 'guest']), // Required
nickname: z.string().optional(), // Intentionally optional
bio: z.string().nullable(), // Can be explicitly null
})
id: z.string().uuid(), // Required
name: z.string().min(1), // Required, non-empty
email: z.string().email(), // Required
role: z.enum(["admin", "user", "guest"]), // Required
nickname: z.string().optional(), // Intentionally optional
bio: z.string().nullable() // Can be explicitly null
});
type User = z.infer<typeof userSchema>
type User = z.infer<typeof userSchema>;
// Empty object fails validation
userSchema.parse({}) // ✗ Throws ZodError
userSchema.parse({}); // ✗ Throws ZodError
function greetUser(user: User) {
// user.name is guaranteed to exist
console.log(`Hello, ${user.name}`)
console.log(`Hello, ${user.name}`);
// Only optional fields need checks
if (user.nickname) {
console.log(`Also known as: ${user.nickname}`)
console.log(`Also known as: ${user.nickname}`);
}
}
```
@@ -76,17 +76,18 @@ function greetUser(user: User) {
const userSchema = z.object({
id: z.string().uuid(),
name: z.string().min(1),
email: z.string().email(),
})
email: z.string().email()
});
// All fields optional for PATCH updates
const updateUserSchema = userSchema.partial()
const updateUserSchema = userSchema.partial();
// Only specific fields optional
const createUserSchema = userSchema.partial({ id: true })
const createUserSchema = userSchema.partial({ id: true });
```
**When NOT to use this pattern:**
- When modeling partial updates (PATCH endpoints)
- When fields genuinely may not exist (legacy data, external APIs)