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,29 +12,29 @@ tags: object, optional, nullable, undefined
**Incorrect (confusing optional and nullable):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const userSchema = z.object({
name: z.string(),
// Intended: field might not exist
nickname: z.string().nullable(), // Wrong! Requires field to be present
nickname: z.string().nullable(), // Wrong! Requires field to be present
// Intended: field exists but might be null
deletedAt: z.date().optional(), // Wrong! Allows field to be missing
})
deletedAt: z.date().optional() // Wrong! Allows field to be missing
});
// This fails - nickname is required
userSchema.parse({ name: 'John' })
userSchema.parse({ name: "John" });
// ZodError: Required at "nickname"
// This passes but loses semantic meaning
userSchema.parse({ name: 'John', nickname: null, deletedAt: undefined })
userSchema.parse({ name: "John", nickname: null, deletedAt: undefined });
// Is deletedAt undefined because not deleted, or because data is incomplete?
```
**Correct (using optional and nullable deliberately):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const userSchema = z.object({
name: z.string(),
@@ -44,23 +44,23 @@ const userSchema = z.object({
// Type: string | undefined
// nullable() - field must exist, but value can be null
deletedAt: z.date().nullable(),
deletedAt: z.date().nullable()
// Type: Date | null
})
});
// Field can be omitted
userSchema.parse({ name: 'John', deletedAt: null }) // Valid
userSchema.parse({ name: "John", deletedAt: null }); // Valid
// Field must be present (even if null)
userSchema.parse({ name: 'John', nickname: 'Johnny' })
userSchema.parse({ name: "John", nickname: "Johnny" });
// ZodError: Required at "deletedAt"
// Correct usage
userSchema.parse({
name: 'John',
nickname: 'Johnny', // Or omit entirely
deletedAt: null, // Must be present, null means "not deleted"
})
name: "John",
nickname: "Johnny", // Or omit entirely
deletedAt: null // Must be present, null means "not deleted"
});
```
**When to use each:**
@@ -69,23 +69,23 @@ userSchema.parse({
// optional() - field may not exist
// Use for: Optional form fields, sparse updates, optional config
z.object({
bio: z.string().optional(), // User might not have filled this
middleName: z.string().optional(), // Not everyone has one
})
bio: z.string().optional(), // User might not have filled this
middleName: z.string().optional() // Not everyone has one
});
// nullable() - field exists but value can be null
// Use for: Database nullable columns, "cleared" values, explicit absence
z.object({
deletedAt: z.date().nullable(), // null = not deleted, Date = when deleted
parentId: z.string().nullable(), // null = root node, string = has parent
approvedBy: z.string().nullable(), // null = pending, string = approver
})
deletedAt: z.date().nullable(), // null = not deleted, Date = when deleted
parentId: z.string().nullable(), // null = root node, string = has parent
approvedBy: z.string().nullable() // null = pending, string = approver
});
// nullish() - either undefined or null
// Use for: Lenient APIs, legacy data, optional nullable DB columns
z.object({
legacyField: z.string().nullish(), // string | null | undefined
})
legacyField: z.string().nullish() // string | null | undefined
});
```
**API response patterns:**
@@ -94,23 +94,26 @@ z.object({
// API includes null for "no value" (good for explicit absence)
const apiResponseSchema = z.object({
data: z.object({
user: z.object({
name: z.string(),
avatar: z.string().nullable(), // null = no avatar set
}).nullable(), // null = user not found
}),
})
user: z
.object({
name: z.string(),
avatar: z.string().nullable() // null = no avatar set
})
.nullable() // null = user not found
})
});
// Type: { data: { user: { name: string; avatar: string | null } | null } }
// Partial updates send only changed fields
const updateSchema = z.object({
name: z.string().optional(), // Omitted = don't change
avatar: z.string().nullable().optional(), // null = clear avatar
})
name: z.string().optional(), // Omitted = don't change
avatar: z.string().nullable().optional() // null = clear avatar
});
```
**When NOT to use this pattern:**
- When interacting with systems that treat null and undefined as equivalent
- When using nullish() for maximum flexibility is acceptable