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,78 +12,75 @@ Plain `z.string()` accepts any string including empty strings, extremely long st
**Incorrect (no string validations):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const commentSchema = z.object({
author: z.string(), // Empty string passes
email: z.string(), // "not-an-email" passes
content: z.string(), // 10MB string passes, script tags pass
website: z.string().optional(), // "javascript:alert(1)" passes
})
author: z.string(), // Empty string passes
email: z.string(), // "not-an-email" passes
content: z.string(), // 10MB string passes, script tags pass
website: z.string().optional() // "javascript:alert(1)" passes
});
// All of these pass validation
commentSchema.parse({
author: '', // Empty - who wrote this?
email: 'invalid', // Not a real email
content: '<script>alert("XSS")</script>'.repeat(100000), // XSS + huge
website: 'javascript:void(0)', // Dangerous URL
})
author: "", // Empty - who wrote this?
email: "invalid", // Not a real email
content: '<script>alert("XSS")</script>'.repeat(100000), // XSS + huge
website: "javascript:void(0)" // Dangerous URL
});
```
**Correct (string validations applied):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const commentSchema = z.object({
author: z.string()
.min(1, 'Author is required')
.max(100, 'Author name too long'),
author: z.string().min(1, "Author is required").max(100, "Author name too long"),
email: z.string()
.email('Invalid email address'),
email: z.string().email("Invalid email address"),
content: z.string()
.min(1, 'Comment cannot be empty')
.max(5000, 'Comment too long'),
content: z.string().min(1, "Comment cannot be empty").max(5000, "Comment too long"),
website: z.string()
.url('Invalid URL')
website: z
.string()
.url("Invalid URL")
.refine(
url => url.startsWith('http://') || url.startsWith('https://'),
'Only http/https URLs allowed'
(url) => url.startsWith("http://") || url.startsWith("https://"),
"Only http/https URLs allowed"
)
.optional(),
})
.optional()
});
// Invalid data is rejected
commentSchema.parse({
author: '',
email: 'invalid',
content: '',
})
author: "",
email: "invalid",
content: ""
});
// ZodError with all violations listed
```
**Common string validations:**
```typescript
z.string().min(1) // Non-empty (most common need)
z.string().max(255) // Database varchar limit
z.string().length(36) // Exact length (UUIDs)
z.string().email() // Email format
z.string().url() // URL format
z.string().uuid() // UUID format
z.string().cuid() // CUID format
z.string().regex(/^[a-z0-9-]+$/) // Custom pattern (slugs)
z.string().startsWith('https://') // Prefix check
z.string().endsWith('.pdf') // Suffix check
z.string().includes('@') // Contains check
z.string().trim() // Strips whitespace (transform)
z.string().toLowerCase() // Normalizes case (transform)
z.string().min(1); // Non-empty (most common need)
z.string().max(255); // Database varchar limit
z.string().length(36); // Exact length (UUIDs)
z.string().email(); // Email format
z.string().url(); // URL format
z.string().uuid(); // UUID format
z.string().cuid(); // CUID format
z.string().regex(/^[a-z0-9-]+$/); // Custom pattern (slugs)
z.string().startsWith("https://"); // Prefix check
z.string().endsWith(".pdf"); // Suffix check
z.string().includes("@"); // Contains check
z.string().trim(); // Strips whitespace (transform)
z.string().toLowerCase(); // Normalizes case (transform)
```
**When NOT to use this pattern:**
- When accepting arbitrary user content for display only (sanitize on output instead)
- When building a passthrough/proxy that shouldn't validate content