mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-27 03:32:55 +00:00
test: resolver harness uses the real branch helper
plus deleted forks and same repo PRs without an origin branch
This commit is contained in:
committed by
paseo-bot[bot]
parent
c77b046337
commit
52bf490fbf
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import type { ForgeService } from "../services/forge-service.js";
|
||||
import { buildForkLocalBranchName } from "../utils/change-request-checkout.js";
|
||||
import {
|
||||
CheckoutSourceForgeMismatchError,
|
||||
MissingCheckoutTargetError,
|
||||
@@ -32,14 +33,8 @@ function createResolverHarness(overrides?: {
|
||||
defaultCheckoutRefs: ({ changeRequestNumber }) => [
|
||||
{ remoteName: "origin", remoteRef: `refs/pull/${changeRequestNumber}/head` },
|
||||
],
|
||||
buildPrLocalBranchName: ({ headRef, checkoutTarget }) => {
|
||||
const normalized = checkoutTarget.headOwnerLogin?.trim().toLowerCase() ?? "";
|
||||
const owner =
|
||||
checkoutTarget.isCrossRepository && /^[a-z0-9-]+$/.test(normalized)
|
||||
? normalized
|
||||
: null;
|
||||
return owner ? `${owner}/${headRef}` : headRef;
|
||||
},
|
||||
buildPrLocalBranchName: ({ headRef, checkoutTarget }) =>
|
||||
buildForkLocalBranchName({ headRef, ...checkoutTarget }),
|
||||
supportsCrossRepoCheckoutWithoutRefs: true,
|
||||
}
|
||||
: {};
|
||||
@@ -233,6 +228,29 @@ describe("resolveWorktreeCreationIntent", () => {
|
||||
expect(deps.headRefLookups).toEqual([]);
|
||||
});
|
||||
|
||||
test("prefixes the pr number when the fork was deleted", async () => {
|
||||
const deps = createResolverHarness();
|
||||
deps.forgeService.getPullRequestCheckoutTarget = async () => ({
|
||||
number: 42,
|
||||
baseRefName: "main",
|
||||
headRefName: "towel",
|
||||
headOwnerLogin: null,
|
||||
headRepositorySshUrl: null,
|
||||
headRepositoryUrl: null,
|
||||
isCrossRepository: true,
|
||||
});
|
||||
|
||||
const intent = await resolveWorktreeCreationIntent(
|
||||
{ action: "checkout", githubPrNumber: 42 },
|
||||
repoRoot,
|
||||
deps,
|
||||
);
|
||||
|
||||
expect(intent).toMatchObject({ headRef: "towel", localBranchName: "pr-42/towel" });
|
||||
expect(intent).not.toHaveProperty("pushRemoteUrl");
|
||||
expect(intent).not.toHaveProperty("trackOriginHead");
|
||||
});
|
||||
|
||||
test("uses an explicit PR head ref without calling GitHub", async () => {
|
||||
const deps = createResolverHarness();
|
||||
|
||||
|
||||
@@ -2385,7 +2385,14 @@ describe("createGiteaService", () => {
|
||||
|
||||
const target = await service.getPullRequestCheckoutTarget({ cwd: "/repo", number: 5 });
|
||||
|
||||
expect(target.hasOriginHeadBranch).toBe(false);
|
||||
expect(target).toMatchObject({
|
||||
checkoutRefs: [
|
||||
{ remoteName: "origin", remoteRef: "refs/pull/5/head" },
|
||||
{ remoteName: "upstream", remoteRef: "refs/pull/5/head" },
|
||||
],
|
||||
isCrossRepository: false,
|
||||
hasOriginHeadBranch: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps a pull request from a deleted fork cross-repository", async () => {
|
||||
|
||||
Reference in New Issue
Block a user