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,78 @@ Once data is validated by Zod, trust the result. Re-validating the same data in
**Incorrect (validating at every layer):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const userSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
name: z.string(),
})
name: z.string()
});
// Controller validates
export async function POST(req: NextRequest) {
const body = await req.json()
const user = userSchema.parse(body) // First parse
return await userService.create(user)
const body = await req.json();
const user = userSchema.parse(body); // First parse
return await userService.create(user);
}
// Service validates again
const userService = {
async create(data: unknown) {
const user = userSchema.parse(data) // Second parse - redundant
return await userRepository.insert(user)
const user = userSchema.parse(data); // Second parse - redundant
return await userRepository.insert(user);
}
}
};
// Repository validates again
const userRepository = {
async insert(data: unknown) {
const user = userSchema.parse(data) // Third parse - wasteful
return await db.users.create({ data: user })
const user = userSchema.parse(data); // Third parse - wasteful
return await db.users.create({ data: user });
}
}
};
```
**Correct (validate once, pass typed data):**
```typescript
import { z } from 'zod'
import { z } from "zod";
const userSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
name: z.string(),
})
name: z.string()
});
type User = z.infer<typeof userSchema>
type User = z.infer<typeof userSchema>;
// Controller validates at boundary
export async function POST(req: NextRequest) {
const body = await req.json()
const body = await req.json();
const result = userSchema.safeParse(body)
const result = userSchema.safeParse(body);
if (!result.success) {
return NextResponse.json({ errors: result.error.issues }, { status: 400 })
return NextResponse.json({ errors: result.error.issues }, { status: 400 });
}
// Pass validated, typed data
return await userService.create(result.data)
return await userService.create(result.data);
}
// Service receives typed data, no re-validation needed
const userService = {
async create(user: User) {
// user is guaranteed to match schema
return await userRepository.insert(user)
return await userRepository.insert(user);
}
}
};
// Repository receives typed data
const userRepository = {
async insert(user: User) {
return await db.users.create({ data: user })
return await db.users.create({ data: user });
}
}
};
```
**When you might validate at multiple layers:**
@@ -92,20 +92,20 @@ const userRepository = {
// Different schemas for different layers
const apiUserSchema = z.object({
email: z.string().email(),
password: z.string().min(8), // Only in API layer
})
password: z.string().min(8) // Only in API layer
});
const dbUserSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
passwordHash: z.string(), // Transformed before storage
})
passwordHash: z.string() // Transformed before storage
});
// API validates input format
export async function POST(req: NextRequest) {
const input = apiUserSchema.parse(await req.json())
const user = await userService.create(input)
return NextResponse.json(user)
const input = apiUserSchema.parse(await req.json());
const user = await userService.create(input);
return NextResponse.json(user);
}
// Service transforms and validates for storage
@@ -114,14 +114,15 @@ const userService = {
const dbUser = dbUserSchema.parse({
id: crypto.randomUUID(),
email: input.email,
passwordHash: await hash(input.password),
})
return await userRepository.insert(dbUser)
passwordHash: await hash(input.password)
});
return await userRepository.insert(dbUser);
}
}
};
```
**When NOT to use this pattern:**
- When schemas differ between layers (API vs DB shape)
- When data crosses trust boundaries (external service response)
- During development when debugging data flow