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,50 +12,50 @@ TypeScript can't infer recursive Zod schema types automatically. Use `z.lazy()`
**Incorrect (direct self-reference):**
```typescript
import { z } from 'zod'
import { z } from "zod";
// This fails - categorySchema used before it's defined
const categorySchema = z.object({
id: z.string(),
name: z.string(),
children: z.array(categorySchema), // Error: Block-scoped variable used before declaration
})
children: z.array(categorySchema) // Error: Block-scoped variable used before declaration
});
```
**Correct (using z.lazy with type annotation):**
```typescript
import { z } from 'zod'
import { z } from "zod";
// Define the type manually
interface Category {
id: string
name: string
children: Category[]
id: string;
name: string;
children: Category[];
}
// Use z.lazy() to defer schema reference
const categorySchema: z.ZodType<Category> = z.object({
id: z.string(),
name: z.string(),
children: z.lazy(() => z.array(categorySchema)),
})
children: z.lazy(() => z.array(categorySchema))
});
// Now it works
const tree = categorySchema.parse({
id: '1',
name: 'Electronics',
id: "1",
name: "Electronics",
children: [
{
id: '2',
name: 'Phones',
id: "2",
name: "Phones",
children: [
{ id: '3', name: 'iPhones', children: [] },
{ id: '4', name: 'Android', children: [] },
],
},
],
})
{ id: "3", name: "iPhones", children: [] },
{ id: "4", name: "Android", children: [] }
]
}
]
});
```
**Common recursive patterns:**
@@ -63,56 +63,50 @@ const tree = categorySchema.parse({
```typescript
// Comments with replies
interface Comment {
id: string
content: string
author: string
replies: Comment[]
id: string;
content: string;
author: string;
replies: Comment[];
}
const commentSchema: z.ZodType<Comment> = z.object({
id: z.string(),
content: z.string(),
author: z.string(),
replies: z.lazy(() => z.array(commentSchema)),
})
replies: z.lazy(() => z.array(commentSchema))
});
// Binary tree
interface TreeNode {
value: number
left: TreeNode | null
right: TreeNode | null
value: number;
left: TreeNode | null;
right: TreeNode | null;
}
const treeNodeSchema: z.ZodType<TreeNode> = z.object({
value: z.number(),
left: z.lazy(() => treeNodeSchema.nullable()),
right: z.lazy(() => treeNodeSchema.nullable()),
})
right: z.lazy(() => treeNodeSchema.nullable())
});
// Nested menu structure
interface MenuItem {
label: string
href?: string
children?: MenuItem[]
label: string;
href?: string;
children?: MenuItem[];
}
const menuItemSchema: z.ZodType<MenuItem> = z.object({
label: z.string(),
href: z.string().url().optional(),
children: z.lazy(() => z.array(menuItemSchema)).optional(),
})
children: z.lazy(() => z.array(menuItemSchema)).optional()
});
```
**JSON Schema (any valid JSON):**
```typescript
type JSONValue =
| string
| number
| boolean
| null
| JSONValue[]
| { [key: string]: JSONValue }
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
z.union([
@@ -121,9 +115,9 @@ const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
z.boolean(),
z.null(),
z.array(jsonValueSchema),
z.record(jsonValueSchema),
z.record(jsonValueSchema)
])
)
);
```
**Performance consideration:**
@@ -137,6 +131,7 @@ const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
```
**When NOT to use this pattern:**
- Non-recursive schemas (lazy adds unnecessary indirection)
- When you can flatten the structure instead