feat: make retry policy error-aware and expand unit coverage
- retry: retry only 5xx/429/transport errors; fail fast on 4xx - checks/diff/r2/cacheStore: add direct unit tests (D-08, D-10 area) - cacheStore: validate pullNumber in history object keys - r2: export normalizeEndpoint for testability
This commit is contained in:
1 parent
b47302e2ff
commit
3f793d746e
9 files changed
+363
-12
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { collectValidNewLines, toDiffPosition } from "../src/github/diff.js";
|
||||
|
||||
function file(patch?: string) {
|
||||
return { filename: "src/a.ts", patch, status: "modified", additions: 2, deletions: 1 };
|
||||
}
|
||||
|
||||
const samplePatch = [
|
||||
"@@ -1,3 +1,4 @@",
|
||||
" context line",
|
||||
"-removed line",
|
||||
"+added line one",
|
||||
"+added line two",
|
||||
" more context"
|
||||
].join("\n");
|
||||
|
||||
test("collectValidNewLines tracks added lines per file", () => {
|
||||
const valid = collectValidNewLines([file(samplePatch)]);
|
||||
assert.equal(valid.has("src/a.ts:2"), true);
|
||||
assert.equal(valid.has("src/a.ts:3"), true);
|
||||
assert.equal(valid.has("src/a.ts:1"), false);
|
||||
assert.equal(valid.has("src/a.ts:4"), false);
|
||||
});
|
||||
|
||||
test("files without patches contribute no valid lines", () => {
|
||||
const valid = collectValidNewLines([file(undefined)]);
|
||||
assert.equal(valid.size, 0);
|
||||
});
|
||||
|
||||
test("toDiffPosition maps valid new lines and rejects stale ones", () => {
|
||||
const valid = collectValidNewLines([file(samplePatch)]);
|
||||
assert.deepEqual(toDiffPosition(file(), 2, valid), {
|
||||
path: "src/a.ts",
|
||||
line: 2,
|
||||
side: "RIGHT"
|
||||
});
|
||||
assert.equal(toDiffPosition(file(), 99, valid), null);
|
||||
});
|
||||
|
||||
test("hunk headers with ranges are parsed correctly", () => {
|
||||
const valid = collectValidNewLines([
|
||||
file("@@ -10,5 +20,3 @@\n+first\n+second\n+third")
|
||||
]);
|
||||
assert.equal(valid.has("src/a.ts:20"), true);
|
||||
assert.equal(valid.has("src/a.ts:22"), true);
|
||||
assert.equal(valid.has("src/a.ts:23"), false);
|
||||
});
|
||||
Reference in new issue
Block a user