Skip to content

Commit 4869e00

Browse files
committed
test(scoring): cover loadContributorRepoOpenPrSignalRecords's login/repo match branches
loadContributorRepoOpenPrSignalRecords filters open PRs by sameLogin (which short-circuits a null/undefined authorLogin via Boolean(value && ...)) and sameRepoFullName (case-insensitive), but neither branch was directly covered. Add two tests extending the existing loader test: (1) PRs with authorLogin null and undefined are excluded (not matched or thrown on), asserting only the target login's PR is loaded; (2) a repoFullName differing from the query only in letter case still matches. No source change -- coverage for existing, correct logic.
1 parent ddb674e commit 4869e00

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,36 @@ describe("pending PR scenario detection", () => {
461461
expect(records.pullRequestChecks).toHaveLength(0);
462462
vi.restoreAllMocks();
463463
});
464+
465+
it("excludes PRs whose authorLogin is null or undefined via sameLogin's short-circuit (#8329)", async () => {
466+
const env = {} as Env;
467+
// Only the target login's own open PR (#70) should be loaded; the null/undefined-author rows must be
468+
// excluded by sameLogin (`Boolean(value && ...)`), not matched or thrown on.
469+
const reviewsSpy = vi.spyOn(repositories, "listPullRequestReviews").mockResolvedValue([approvedReview(70)]);
470+
vi.spyOn(repositories, "listCheckSummaries").mockResolvedValue([]);
471+
const records = await loadContributorRepoOpenPrSignalRecords(env, "entrius/allways-ui", "miner-a", [
472+
pr({ number: 70 }),
473+
pr({ number: 73, authorLogin: null }),
474+
pr({ number: 74, authorLogin: undefined }),
475+
]);
476+
// Reviews/checks are fetched per matched PR only, so exactly one PR (the target login's) was matched.
477+
expect(records.pullRequestReviews).toHaveLength(1);
478+
expect(reviewsSpy).toHaveBeenCalledTimes(1);
479+
expect(reviewsSpy).toHaveBeenCalledWith(env, "entrius/allways-ui", 70);
480+
vi.restoreAllMocks();
481+
});
482+
483+
it("matches a repoFullName that differs from the query only in letter case (#8329)", async () => {
484+
const env = {} as Env;
485+
// The PR record's repoFullName differs in case from the query argument; sameRepoFullName lowercases both,
486+
// so the PR is still matched and its cached reviews loaded.
487+
const reviewsSpy = vi.spyOn(repositories, "listPullRequestReviews").mockResolvedValue([approvedReview(70)]);
488+
vi.spyOn(repositories, "listCheckSummaries").mockResolvedValue([]);
489+
const records = await loadContributorRepoOpenPrSignalRecords(env, "entrius/allways-ui", "miner-a", [
490+
pr({ number: 70, repoFullName: "Entrius/Allways-UI" }),
491+
]);
492+
expect(records.pullRequestReviews).toHaveLength(1);
493+
expect(reviewsSpy).toHaveBeenCalledWith(env, "Entrius/Allways-UI", 70);
494+
vi.restoreAllMocks();
495+
});
464496
});

0 commit comments

Comments
 (0)