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:
1 parent
db53296d78
commit
78bf8e9e41
87 files changed
+6003
-2587
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { withRetry } from "../src/retry.js";
|
||||
|
||||
class HttpLikeError extends Error {
|
||||
status: number;
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
test("custom retryable predicate treats specific errors as retryable", async () => {
|
||||
let attempts = 0;
|
||||
const result = await withRetry(
|
||||
"custom-retryable",
|
||||
async () => {
|
||||
attempts += 1;
|
||||
if (attempts < 3) {
|
||||
throw new HttpLikeError(403, "forbidden but transient per our rule");
|
||||
}
|
||||
return "done";
|
||||
},
|
||||
{
|
||||
baseDelayMs: 1,
|
||||
retryable: (error) => {
|
||||
if (typeof error === "object" && error !== null && "status" in error) {
|
||||
const e = error as { status: number };
|
||||
return e.status === 403;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
assert.equal(result, "done");
|
||||
assert.equal(attempts, 3);
|
||||
});
|
||||
|
||||
test("custom retryable predicate prevents retry when it returns false", async () => {
|
||||
let attempts = 0;
|
||||
await assert.rejects(
|
||||
withRetry(
|
||||
"custom-non-retryable",
|
||||
async () => {
|
||||
attempts += 1;
|
||||
throw new HttpLikeError(500, "always fatal per our rule");
|
||||
},
|
||||
{
|
||||
baseDelayMs: 1,
|
||||
retryable: () => false
|
||||
}
|
||||
),
|
||||
/always fatal/
|
||||
);
|
||||
assert.equal(attempts, 1);
|
||||
});
|
||||
|
||||
test("default behavior unchanged when no custom retryable provided", async () => {
|
||||
let attempts = 0;
|
||||
const result = await withRetry(
|
||||
"default-behavior",
|
||||
async () => {
|
||||
attempts += 1;
|
||||
if (attempts < 3) {
|
||||
throw new HttpLikeError(502, "bad gateway");
|
||||
}
|
||||
return "ok";
|
||||
},
|
||||
{ baseDelayMs: 1 }
|
||||
);
|
||||
assert.equal(result, "ok");
|
||||
assert.equal(attempts, 3);
|
||||
});
|
||||
|
||||
test("default behavior still rejects non-retryable errors", async () => {
|
||||
let attempts = 0;
|
||||
await assert.rejects(
|
||||
withRetry("default-non-retryable", async () => {
|
||||
attempts += 1;
|
||||
throw new HttpLikeError(404, "not found");
|
||||
})
|
||||
);
|
||||
assert.equal(attempts, 1);
|
||||
});
|
||||
|
||||
test("maxTotalTimeoutMs stops retries when elapsed time exceeds limit", async () => {
|
||||
const startTime = Date.now();
|
||||
let attempts = 0;
|
||||
await assert.rejects(
|
||||
withRetry(
|
||||
"timeout-limit",
|
||||
async () => {
|
||||
attempts += 1;
|
||||
// Simulate a brief operation that takes some time
|
||||
throw new HttpLikeError(502, "timeout test");
|
||||
},
|
||||
{ maxAttempts: 5, baseDelayMs: 100, maxTotalTimeoutMs: 50 }
|
||||
)
|
||||
);
|
||||
const elapsed = Date.now() - startTime;
|
||||
assert.ok(attempts > 0, "at least one attempt was made");
|
||||
assert.ok(attempts < 5, "should not reach max attempts due to total timeout");
|
||||
assert.ok(elapsed < 500, "should complete within reasonable time given the short timeout");
|
||||
});
|
||||
Reference in new issue
Block a user