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,15 +12,15 @@ Zod's default error messages are technical and confusing for end users. Provide
**Incorrect (default error messages):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const signupSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
age: z.number().min(18),
})
age: z.number().min(18)
});
signupSchema.parse({ email: 'bad', password: '123', age: 15 })
signupSchema.parse({ email: "bad", password: "123", age: 15 });
// ZodError issues:
// - "Invalid email"
// - "String must contain at least 8 character(s)"
@@ -31,25 +31,31 @@ signupSchema.parse({ email: 'bad', password: '123', age: 15 })
**Correct (custom error messages):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const signupSchema = z.object({
email: z.string({
required_error: 'Email is required',
invalid_type_error: 'Email must be text',
}).email('Please enter a valid email address'),
email: z
.string({
required_error: "Email is required",
invalid_type_error: "Email must be text"
})
.email("Please enter a valid email address"),
password: z.string({
required_error: 'Password is required',
}).min(8, 'Password must be at least 8 characters'),
password: z
.string({
required_error: "Password is required"
})
.min(8, "Password must be at least 8 characters"),
age: z.number({
required_error: 'Age is required',
invalid_type_error: 'Age must be a number',
}).min(18, 'You must be at least 18 years old'),
})
age: z
.number({
required_error: "Age is required",
invalid_type_error: "Age must be a number"
})
.min(18, "You must be at least 18 years old")
});
signupSchema.parse({ email: 'bad', password: '123', age: 15 })
signupSchema.parse({ email: "bad", password: "123", age: 15 });
// ZodError issues:
// - "Please enter a valid email address"
// - "Password must be at least 8 characters"
@@ -59,19 +65,20 @@ signupSchema.parse({ email: 'bad', password: '123', age: 15 })
**Message types and when they trigger:**
```typescript
const schema = z.string({
// When field is undefined
required_error: 'This field is required',
const schema = z
.string({
// When field is undefined
required_error: "This field is required",
// When field is wrong type (e.g., number instead of string)
invalid_type_error: 'This field must be text',
// When field is wrong type (e.g., number instead of string)
invalid_type_error: "This field must be text",
// Fallback for any other error
message: 'Invalid value',
})
.min(1, 'Cannot be empty') // When length < 1
.max(100, 'Too long') // When length > 100
.email('Invalid email format') // When format fails
// Fallback for any other error
message: "Invalid value"
})
.min(1, "Cannot be empty") // When length < 1
.max(100, "Too long") // When length > 100
.email("Invalid email format"); // When format fails
```
**Using error maps for consistent messaging:**
@@ -80,38 +87,40 @@ const schema = z.string({
const customErrorMap: z.ZodErrorMap = (issue, ctx) => {
// Customize messages by error code
if (issue.code === z.ZodIssueCode.too_small) {
if (issue.type === 'string') {
return { message: `Must be at least ${issue.minimum} characters` }
if (issue.type === "string") {
return { message: `Must be at least ${issue.minimum} characters` };
}
if (issue.type === 'number') {
return { message: `Must be at least ${issue.minimum}` }
if (issue.type === "number") {
return { message: `Must be at least ${issue.minimum}` };
}
}
if (issue.code === z.ZodIssueCode.invalid_type) {
if (issue.expected === 'string') {
return { message: 'Must be text' }
if (issue.expected === "string") {
return { message: "Must be text" };
}
}
// Default to Zod's message
return { message: ctx.defaultError }
}
return { message: ctx.defaultError };
};
// Apply globally
z.setErrorMap(customErrorMap)
z.setErrorMap(customErrorMap);
// Or per-schema
schema.parse(data, { errorMap: customErrorMap })
schema.parse(data, { errorMap: customErrorMap });
```
**Good error message principles:**
- Say what's wrong: "Password too short" not "Invalid password"
- Say how to fix it: "at least 8 characters" not just "too short"
- Use user's language: "email" not "string field at path .email"
- Be specific: "Must be a positive number" not "Invalid"
**When NOT to use this pattern:**
- Internal development scripts where technical errors are fine
- When you'll map errors to user-facing messages in the UI layer