Skip to content

Commit de4ea98

Browse files
committed
test(scoring): cover sameLogin/sameRepoFullName edge cases in pending-pr-scenarios (#8329)
loadContributorRepoOpenPrSignalRecords filters a contributor's open PRs via sameLogin (whose `value &&` short-circuit handles a null/undefined authorLogin from ghost/deleted accounts) and sameRepoFullName (case-insensitive). Neither the falsy-authorLogin branch nor the case-normalization was exercised. Add three tests: PRs with null/undefined authorLogin are excluded (short-circuit, no throw on the null .toLowerCase()); a repoFullName differing only in case still matches; an authorLogin differing only in case still matches. No production code changed. Closes #8329
1 parent 04d38b6 commit de4ea98

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

test/unit/pending-pr-scenarios.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,43 @@ describe("pending PR scenario detection", () => {
461461
expect(records.pullRequestChecks).toHaveLength(0);
462462
vi.restoreAllMocks();
463463
});
464+
465+
it("excludes PRs from ghost/deleted accounts (null or undefined authorLogin) via sameLogin's short-circuit (#8329)", async () => {
466+
const env = {} as Env;
467+
vi.spyOn(repositories, "listPullRequestReviews").mockResolvedValue([approvedReview(80)]);
468+
vi.spyOn(repositories, "listCheckSummaries").mockResolvedValue([]);
469+
const records = await loadContributorRepoOpenPrSignalRecords(env, "entrius/allways-ui", "miner-a", [
470+
pr({ number: 80, authorLogin: null }),
471+
pr({ number: 81, authorLogin: undefined }),
472+
]);
473+
// Both records' authorLogin is falsy, so `value &&` short-circuits to false — neither PR matches, so no
474+
// signals are loaded (rather than matching by accident or throwing on the null `.toLowerCase()`).
475+
expect(records.pullRequestReviews).toHaveLength(0);
476+
expect(records.pullRequestChecks).toHaveLength(0);
477+
vi.restoreAllMocks();
478+
});
479+
480+
it("matches a PR whose repoFullName differs from the query only in letter case (#8329)", async () => {
481+
const env = {} as Env;
482+
vi.spyOn(repositories, "listPullRequestReviews").mockResolvedValue([approvedReview(82)]);
483+
vi.spyOn(repositories, "listCheckSummaries").mockResolvedValue([]);
484+
const records = await loadContributorRepoOpenPrSignalRecords(env, "entrius/allways-ui", "miner-a", [
485+
pr({ number: 82, repoFullName: "Entrius/Allways-UI" }),
486+
]);
487+
// sameRepoFullName lower-cases both sides, so the case-differing repo still matches and is included.
488+
expect(records.pullRequestReviews).toHaveLength(1);
489+
vi.restoreAllMocks();
490+
});
491+
492+
it("matches a PR whose authorLogin differs from the query login only in letter case (#8329)", async () => {
493+
const env = {} as Env;
494+
vi.spyOn(repositories, "listPullRequestReviews").mockResolvedValue([approvedReview(83)]);
495+
vi.spyOn(repositories, "listCheckSummaries").mockResolvedValue([]);
496+
const records = await loadContributorRepoOpenPrSignalRecords(env, "entrius/allways-ui", "miner-a", [
497+
pr({ number: 83, authorLogin: "Miner-A" }),
498+
]);
499+
// sameLogin lower-cases both sides, so the case-differing login still matches and is included.
500+
expect(records.pullRequestReviews).toHaveLength(1);
501+
vi.restoreAllMocks();
502+
});
464503
});

0 commit comments

Comments
 (0)