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

@@ -13,99 +13,103 @@ When the same schema pattern appears in multiple places, extract it into a share
```typescript
// api/users.ts
import { z } from 'zod'
import { z } from "zod";
const userSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
name: z.string().min(1),
createdAt: z.date(),
})
createdAt: z.date()
});
// api/orders.ts
import { z } from 'zod'
import { z } from "zod";
const orderSchema = z.object({
id: z.string().uuid(), // Duplicated
userId: z.string().uuid(), // Same pattern
items: z.array(z.object({
productId: z.string().uuid(), // Duplicated
quantity: z.number().int().positive(),
})),
createdAt: z.date(), // Duplicated
})
id: z.string().uuid(), // Duplicated
userId: z.string().uuid(), // Same pattern
items: z.array(
z.object({
productId: z.string().uuid(), // Duplicated
quantity: z.number().int().positive()
})
),
createdAt: z.date() // Duplicated
});
// api/comments.ts
import { z } from 'zod'
import { z } from "zod";
const commentSchema = z.object({
id: z.string().uuid(), // Same duplication
id: z.string().uuid(), // Same duplication
userId: z.string().uuid(),
content: z.string().min(1),
createdAt: z.date(), // Inconsistency risk
})
createdAt: z.date() // Inconsistency risk
});
```
**Correct (shared schema modules):**
```typescript
// schemas/common.ts
import { z } from 'zod'
import { z } from "zod";
// Reusable ID types
export const uuid = z.string().uuid()
export type UUID = z.infer<typeof uuid>
export const uuid = z.string().uuid();
export type UUID = z.infer<typeof uuid>;
// Timestamps
export const timestamps = z.object({
createdAt: z.date(),
updatedAt: z.date(),
})
updatedAt: z.date()
});
// Base entity with ID
export const baseEntity = z.object({
id: uuid,
}).merge(timestamps)
export const baseEntity = z
.object({
id: uuid
})
.merge(timestamps);
export type BaseEntity = z.infer<typeof baseEntity>
export type BaseEntity = z.infer<typeof baseEntity>;
// Pagination
export const paginationParams = z.object({
page: z.coerce.number().int().positive().default(1),
limit: z.coerce.number().int().min(1).max(100).default(20),
})
limit: z.coerce.number().int().min(1).max(100).default(20)
});
```
```typescript
// schemas/user.ts
import { z } from 'zod'
import { baseEntity, uuid } from './common'
import { z } from "zod";
import { baseEntity, uuid } from "./common";
export const userSchema = baseEntity.extend({
email: z.string().email(),
name: z.string().min(1),
})
name: z.string().min(1)
});
export type User = z.infer<typeof userSchema>
export type User = z.infer<typeof userSchema>;
```
```typescript
// schemas/order.ts
import { z } from 'zod'
import { baseEntity, uuid } from './common'
import { z } from "zod";
import { baseEntity, uuid } from "./common";
const orderItemSchema = z.object({
productId: uuid,
quantity: z.number().int().positive(),
})
quantity: z.number().int().positive()
});
export const orderSchema = baseEntity.extend({
userId: uuid,
items: z.array(orderItemSchema).min(1),
total: z.number().positive(),
})
total: z.number().positive()
});
export type Order = z.infer<typeof orderSchema>
export type Order = z.infer<typeof orderSchema>;
```
**Organizing schema modules:**
@@ -121,16 +125,17 @@ schemas/
```typescript
// schemas/index.ts
export * from './common'
export * from './user'
export * from './order'
export * from './product'
export * from "./common";
export * from "./user";
export * from "./order";
export * from "./product";
// Usage
import { userSchema, orderSchema, uuid, type User } from '@/schemas'
import { userSchema, orderSchema, uuid, type User } from "@/schemas";
```
**When NOT to use this pattern:**
- One-off schemas used only in a single file
- When schemas look similar but have different semantics (don't over-abstract)