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,136 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import { config } from "../src/config.js";
|
||||
import {
|
||||
buildPullRequestCoarsePrompt,
|
||||
buildPullRequestDuplicatePrompt,
|
||||
buildTriagePrompt,
|
||||
labelName,
|
||||
processIssueTriage,
|
||||
processPullRequestTriage,
|
||||
type PullRequestEvidence
|
||||
} from "../src/triage/processor.js";
|
||||
|
||||
const originalTriageEnabled = config.triageEnabled;
|
||||
|
||||
test.afterEach(() => {
|
||||
config.triageEnabled = originalTriageEnabled;
|
||||
});
|
||||
|
||||
function issueTarget(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
number: 7,
|
||||
title: "Broken login button",
|
||||
body: "Clicking login does nothing.",
|
||||
htmlUrl: "https://github.com/acme/app/issues/7",
|
||||
existingLabels: [],
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
function candidate(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
number: 9,
|
||||
title: "Login button styling",
|
||||
body: "Adjusts the login button.",
|
||||
state: "open",
|
||||
htmlUrl: "https://github.com/acme/app/issues/9",
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
function emptyEvidence(number: number): PullRequestEvidence {
|
||||
return {
|
||||
number,
|
||||
commits: [],
|
||||
comments: [],
|
||||
reviews: [],
|
||||
reviewComments: []
|
||||
};
|
||||
}
|
||||
|
||||
test("buildPullRequestCoarsePrompt embeds the target, labels, and duplicate candidates", () => {
|
||||
const prompt = buildPullRequestCoarsePrompt(issueTarget(), [candidate()]);
|
||||
|
||||
assert.match(prompt, /"title": "Broken login button"/);
|
||||
assert.match(prompt, /must contain at least one value and may only use:/);
|
||||
assert.match(prompt, /"bug"/);
|
||||
assert.match(prompt, /"number": 9/);
|
||||
assert.match(prompt, /"number": 7/);
|
||||
});
|
||||
|
||||
test("buildPullRequestDuplicatePrompt embeds target evidence and candidate evidence", () => {
|
||||
const targetEvidence = emptyEvidence(7);
|
||||
const candidateEvidence = [emptyEvidence(9)];
|
||||
const prompt = buildPullRequestDuplicatePrompt({
|
||||
target: issueTarget(),
|
||||
targetEvidence,
|
||||
candidates: [candidate()],
|
||||
candidateEvidence
|
||||
});
|
||||
|
||||
assert.match(prompt, /"number": 7/);
|
||||
assert.match(prompt, /"number": 9/);
|
||||
assert.match(prompt, /Target pull request and detailed evidence:/);
|
||||
assert.match(prompt, /"evidence": \{/);
|
||||
assert.match(prompt, /"commits": \[\]/);
|
||||
assert.match(prompt, /"comments": \[\]/);
|
||||
assert.match(prompt, /"reviews": \[\]/);
|
||||
assert.match(prompt, /"reviewComments": \[\]/);
|
||||
});
|
||||
|
||||
test("buildTriagePrompt advertises issue triage for an issue target", () => {
|
||||
const prompt = buildTriagePrompt("issue", issueTarget(), [candidate()]);
|
||||
assert.match(prompt, /triaging a GitHub issue/);
|
||||
assert.doesNotMatch(prompt, /pull request/);
|
||||
assert.match(prompt, /"body": "Clicking login does nothing\."/);
|
||||
});
|
||||
|
||||
test("buildTriagePrompt advertises pull request triage for a pull request target", () => {
|
||||
const prompt = buildTriagePrompt("pull_request", issueTarget(), [candidate()]);
|
||||
assert.match(prompt, /triaging a GitHub pull request/);
|
||||
});
|
||||
|
||||
test("buildTriagePrompt includes labels, target, and candidates", () => {
|
||||
const prompt = buildTriagePrompt("issue", issueTarget(), [candidate({ number: 9 })]);
|
||||
assert.match(prompt, /"bug"/);
|
||||
assert.match(prompt, /"title": "Broken login button"/);
|
||||
assert.match(prompt, /"title": "Login button styling"/);
|
||||
});
|
||||
|
||||
test("labelName handles a plain string label", () => {
|
||||
assert.equal(labelName("bug"), "bug");
|
||||
});
|
||||
|
||||
test("labelName extracts the name from an object label", () => {
|
||||
assert.equal(labelName({ name: "documentation", node_id: "MDU6TGFiZWwx" }), "documentation");
|
||||
});
|
||||
|
||||
test("labelName returns an empty string for an object label without a name", () => {
|
||||
assert.equal(labelName({ id: 123 }), "");
|
||||
});
|
||||
|
||||
test("labelName returns an empty string for an empty-name object label", () => {
|
||||
assert.equal(labelName({ name: "" }), "");
|
||||
});
|
||||
|
||||
test("processIssueTriage returns immediately when triage is disabled", async () => {
|
||||
config.triageEnabled = false;
|
||||
|
||||
await assert.doesNotReject(
|
||||
processIssueTriage({} as Octokit, { owner: "acme", repo: "app", issueNumber: 7 })
|
||||
);
|
||||
});
|
||||
|
||||
test("processPullRequestTriage returns immediately when triage is disabled", async () => {
|
||||
config.triageEnabled = false;
|
||||
|
||||
await assert.doesNotReject(
|
||||
processPullRequestTriage({} as Octokit, {
|
||||
owner: "acme",
|
||||
repo: "app",
|
||||
pullNumber: 9
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user