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,26 +12,27 @@ When a field should only accept specific values (status, role, type), use `z.enu
**Incorrect (plain string for fixed values):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const orderSchema = z.object({
id: z.string(),
status: z.string(), // Accepts any string
priority: z.string(), // No constraints
})
status: z.string(), // Accepts any string
priority: z.string() // No constraints
});
type Order = z.infer<typeof orderSchema>
type Order = z.infer<typeof orderSchema>;
// { id: string; status: string; priority: string }
// Typos and invalid values pass validation
orderSchema.parse({
id: '123',
status: 'pendng', // Typo passes
priority: 'super-urgent', // Invalid value passes
})
id: "123",
status: "pendng", // Typo passes
priority: "super-urgent" // Invalid value passes
});
function processOrder(order: Order) {
if (order.status === 'pending') { // Might never match due to typos
if (order.status === "pending") {
// Might never match due to typos
// ...
}
}
@@ -40,67 +41,65 @@ function processOrder(order: Order) {
**Correct (using z.enum):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const OrderStatus = z.enum(['pending', 'processing', 'shipped', 'delivered'])
const Priority = z.enum(['low', 'medium', 'high'])
const OrderStatus = z.enum(["pending", "processing", "shipped", "delivered"]);
const Priority = z.enum(["low", "medium", "high"]);
const orderSchema = z.object({
id: z.string(),
status: OrderStatus,
priority: Priority,
})
priority: Priority
});
type Order = z.infer<typeof orderSchema>
type Order = z.infer<typeof orderSchema>;
// { id: string; status: 'pending' | 'processing' | 'shipped' | 'delivered'; priority: 'low' | 'medium' | 'high' }
// Typos are caught at validation
orderSchema.parse({
id: '123',
status: 'pendng', // ZodError: Invalid enum value
priority: 'super-urgent', // ZodError: Invalid enum value
})
id: "123",
status: "pendng", // ZodError: Invalid enum value
priority: "super-urgent" // ZodError: Invalid enum value
});
// Extract enum values for reuse
OrderStatus.options // ['pending', 'processing', 'shipped', 'delivered']
type OrderStatusType = z.infer<typeof OrderStatus> // 'pending' | 'processing' | ...
OrderStatus.options; // ['pending', 'processing', 'shipped', 'delivered']
type OrderStatusType = z.infer<typeof OrderStatus>; // 'pending' | 'processing' | ...
```
**For native TypeScript enums:**
```typescript
enum Role {
Admin = 'admin',
User = 'user',
Guest = 'guest',
Admin = "admin",
User = "user",
Guest = "guest"
}
// Use z.nativeEnum for TS enums
const userSchema = z.object({
role: z.nativeEnum(Role),
})
role: z.nativeEnum(Role)
});
```
**For single literal values (discriminated unions):**
```typescript
const successResponse = z.object({
status: z.literal('success'),
data: z.unknown(),
})
status: z.literal("success"),
data: z.unknown()
});
const errorResponse = z.object({
status: z.literal('error'),
message: z.string(),
})
status: z.literal("error"),
message: z.string()
});
const response = z.discriminatedUnion('status', [
successResponse,
errorResponse,
])
const response = z.discriminatedUnion("status", [successResponse, errorResponse]);
```
**When NOT to use this pattern:**
- When the set of valid values is dynamic or user-defined
- When values come from a database that may have more options