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,137 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { categorizeFailure, formatFailureMessage } from "../src/ai/failureMessages.js";
|
||||
|
||||
/* ---------- categorizeFailure ---------- */
|
||||
|
||||
test("categorizeFailure: timeout by error code", () => {
|
||||
const err = Object.assign(new Error("timed out"), { code: "ETIMEDOUT" });
|
||||
assert.equal(categorizeFailure(err), "timeout");
|
||||
});
|
||||
|
||||
test("categorizeFailure: timeout by message", () => {
|
||||
const err = new Error("the operation timed out after 30s");
|
||||
assert.equal(categorizeFailure(err), "timeout");
|
||||
});
|
||||
|
||||
test("categorizeFailure: auth by status code 401", () => {
|
||||
const err = Object.assign(new Error("unauthorized"), { status: 401 });
|
||||
assert.equal(categorizeFailure(err), "auth");
|
||||
});
|
||||
|
||||
test("categorizeFailure: auth by status code 403", () => {
|
||||
const err = Object.assign(new Error("forbidden"), { status: 403 });
|
||||
assert.equal(categorizeFailure(err), "auth");
|
||||
});
|
||||
|
||||
test("categorizeFailure: auth by message", () => {
|
||||
const err = new Error("API key is invalid");
|
||||
assert.equal(categorizeFailure(err), "auth");
|
||||
});
|
||||
|
||||
test("categorizeFailure: rate_limit by status code 429", () => {
|
||||
const err = Object.assign(new Error("too many"), { status: 429 });
|
||||
assert.equal(categorizeFailure(err), "rate_limit");
|
||||
});
|
||||
|
||||
test("categorizeFailure: rate_limit by message", () => {
|
||||
const err = new Error("rate limit exceeded, retry later");
|
||||
assert.equal(categorizeFailure(err), "rate_limit");
|
||||
});
|
||||
|
||||
test("categorizeFailure: network by error code ECONNRESET", () => {
|
||||
const err = Object.assign(new Error("socket hang up"), { code: "ECONNRESET" });
|
||||
assert.equal(categorizeFailure(err), "network");
|
||||
});
|
||||
|
||||
test("categorizeFailure: network by error code ECONNREFUSED", () => {
|
||||
const err = Object.assign(new Error("refused"), { code: "ECONNREFUSED" });
|
||||
assert.equal(categorizeFailure(err), "network");
|
||||
});
|
||||
|
||||
test("categorizeFailure: network by error code EAI_AGAIN", () => {
|
||||
const err = Object.assign(new Error("again"), { code: "EAI_AGAIN" });
|
||||
assert.equal(categorizeFailure(err), "network");
|
||||
});
|
||||
|
||||
test("categorizeFailure: network by message", () => {
|
||||
const err = new Error("network error: unable to reach host");
|
||||
assert.equal(categorizeFailure(err), "network");
|
||||
});
|
||||
|
||||
test("categorizeFailure: model by status 502", () => {
|
||||
const err = Object.assign(new Error("upstream error"), { status: 502 });
|
||||
assert.equal(categorizeFailure(err), "model");
|
||||
});
|
||||
|
||||
test("categorizeFailure: model by message", () => {
|
||||
const err = new Error("model completion failed: context length exceeded");
|
||||
assert.equal(categorizeFailure(err), "model");
|
||||
});
|
||||
|
||||
test("categorizeFailure: validation by status 422", () => {
|
||||
const err = Object.assign(new Error("invalid"), { status: 422 });
|
||||
assert.equal(categorizeFailure(err), "validation");
|
||||
});
|
||||
|
||||
test("categorizeFailure: validation by message", () => {
|
||||
const err = new Error("validation error: invalid schema");
|
||||
assert.equal(categorizeFailure(err), "validation");
|
||||
});
|
||||
|
||||
test("categorizeFailure: null input returns unknown", () => {
|
||||
assert.equal(categorizeFailure(null), "unknown");
|
||||
});
|
||||
|
||||
test("categorizeFailure: string input returns unknown", () => {
|
||||
assert.equal(categorizeFailure("some error"), "unknown");
|
||||
});
|
||||
|
||||
test("categorizeFailure: plain error with no recognizable pattern returns unknown", () => {
|
||||
const err = new Error("something unexpected happened");
|
||||
assert.equal(categorizeFailure(err), "unknown");
|
||||
});
|
||||
|
||||
/* ---------- formatFailureMessage ---------- */
|
||||
|
||||
test("formatFailureMessage: timeout includes action and attempts", () => {
|
||||
const msg = formatFailureMessage("timeout", { action: "runReview", attempts: 3 });
|
||||
assert.ok(msg.includes("runReview"));
|
||||
assert.ok(msg.includes("3"));
|
||||
assert.ok(msg.includes("timed out"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: auth includes action and attempts", () => {
|
||||
const msg = formatFailureMessage("auth", { action: "createComment", attempts: 2 });
|
||||
assert.ok(msg.includes("createComment"));
|
||||
assert.ok(msg.includes("2"));
|
||||
assert.ok(msg.includes("authentication error"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: rate_limit mentions backing off", () => {
|
||||
const msg = formatFailureMessage("rate_limit", { action: "listReviews", attempts: 5 });
|
||||
assert.ok(msg.includes("rate-limited"));
|
||||
assert.ok(msg.includes("backing off"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: network mentions service unreachable", () => {
|
||||
const msg = formatFailureMessage("network", { action: "fetchData", attempts: 1 });
|
||||
assert.ok(msg.includes("network error"));
|
||||
assert.ok(msg.includes("unreachable"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: model mentions model error", () => {
|
||||
const msg = formatFailureMessage("model", { action: "runReview", attempts: 3 });
|
||||
assert.ok(msg.includes("model error"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: validation mentions validation check", () => {
|
||||
const msg = formatFailureMessage("validation", { action: "parseResponse", attempts: 2 });
|
||||
assert.ok(msg.includes("validation check"));
|
||||
});
|
||||
|
||||
test("formatFailureMessage: unknown mentions unknown error", () => {
|
||||
const msg = formatFailureMessage("unknown", { action: "someAction", attempts: 4 });
|
||||
assert.ok(msg.includes("unknown error"));
|
||||
assert.ok(msg.includes("Check the logs") || msg.includes("check the logs"));
|
||||
});
|
||||
Reference in new issue
Block a user