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,23 +12,23 @@ When you need an object that satisfies multiple schemas simultaneously (like com
**Incorrect (manual combination):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const timestampsSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
})
updatedAt: z.date()
});
const softDeleteSchema = z.object({
deletedAt: z.date().nullable(),
deletedBy: z.string().nullable(),
})
deletedBy: z.string().nullable()
});
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
})
email: z.string().email()
});
// Manual combination - verbose and error-prone
const fullUserSchema = z.object({
@@ -38,43 +38,41 @@ const fullUserSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
deletedAt: z.date().nullable(),
deletedBy: z.string().nullable(),
})
deletedBy: z.string().nullable()
});
```
**Correct (using intersection):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const timestampsSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
})
updatedAt: z.date()
});
const softDeleteSchema = z.object({
deletedAt: z.date().nullable(),
deletedBy: z.string().nullable(),
})
deletedBy: z.string().nullable()
});
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
})
email: z.string().email()
});
// Using .and() for intersection
const fullUserSchema = userSchema
.and(timestampsSchema)
.and(softDeleteSchema)
const fullUserSchema = userSchema.and(timestampsSchema).and(softDeleteSchema);
// Or using z.intersection()
const fullUserSchema2 = z.intersection(
z.intersection(userSchema, timestampsSchema),
softDeleteSchema
)
);
type FullUser = z.infer<typeof fullUserSchema>
type FullUser = z.infer<typeof fullUserSchema>;
// {
// id: string;
// name: string;
@@ -92,51 +90,52 @@ type FullUser = z.infer<typeof fullUserSchema>
// Reusable mixins
const auditable = z.object({
createdBy: z.string(),
updatedBy: z.string(),
})
updatedBy: z.string()
});
const versioned = z.object({
version: z.number().int().positive(),
})
version: z.number().int().positive()
});
const tagged = z.object({
tags: z.array(z.string()),
})
tags: z.array(z.string())
});
// Apply mixins to any schema
function withAudit<T extends z.ZodRawShape>(schema: z.ZodObject<T>) {
return schema.and(auditable).and(timestampsSchema)
return schema.and(auditable).and(timestampsSchema);
}
function withVersioning<T extends z.ZodRawShape>(schema: z.ZodObject<T>) {
return schema.and(versioned)
return schema.and(versioned);
}
// Usage
const documentSchema = z.object({
id: z.string(),
title: z.string(),
content: z.string(),
})
content: z.string()
});
const fullDocumentSchema = withAudit(withVersioning(documentSchema))
const fullDocumentSchema = withAudit(withVersioning(documentSchema));
```
**Intersection vs Merge:**
```typescript
// .merge() - replaces fields from first with second
const a = z.object({ x: z.string(), y: z.number() })
const b = z.object({ y: z.string() }) // y is string, not number
const a = z.object({ x: z.string(), y: z.number() });
const b = z.object({ y: z.string() }); // y is string, not number
a.merge(b) // { x: string, y: string } - b's y wins
a.merge(b); // { x: string, y: string } - b's y wins
// .and() - requires fields to be compatible
// If both have y with different types, intersection fails at runtime
a.and(b) // Validation will fail - y can't be both number and string
a.and(b); // Validation will fail - y can't be both number and string
```
**When NOT to use this pattern:**
- When schemas have overlapping fields with different types (use merge)
- When you need to override fields (use extend)
- Simple cases where extend works fine