test: harden reliable PR detection refresh
Issue: #4106 Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
375ea9504a
commit
4517d7631b
5 files changed
+47
-25
No files matched your search
@@ -790,6 +790,7 @@ describe("VcsStatusBroadcaster", () => {
|
||||
const secondRefresh = yield* Effect.forkChild(
|
||||
broadcaster.refreshChangeRequestStatus("/repo"),
|
||||
);
|
||||
yield* Effect.yieldNow;
|
||||
yield* TestClock.adjust(Duration.millis(10));
|
||||
yield* Deferred.succeed(release, undefined);
|
||||
yield* Fiber.join(firstRefresh);
|
||||
|
||||
@@ -15,13 +15,13 @@ import {
|
||||
} from "lucide-react";
|
||||
import {
|
||||
ChangeRequestStatusIcon,
|
||||
changeRequestLookupWarning,
|
||||
prStatusIndicator,
|
||||
resolveThreadPr,
|
||||
terminalStatusFromRunningIds,
|
||||
ThreadStatusLabel,
|
||||
ThreadWorktreeIndicator,
|
||||
} from "./ThreadStatusIndicators";
|
||||
import { changeRequestLookupWarning } from "./ThreadStatusIndicators.logic";
|
||||
import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { autoAnimate } from "@formkit/auto-animate";
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { VcsStatusResult } from "@t3tools/contracts";
|
||||
|
||||
import { resolveChangeRequestPresentation } from "../sourceControlPresentation";
|
||||
|
||||
export function changeRequestLookupWarning(
|
||||
threadBranch: string | null,
|
||||
gitStatus: VcsStatusResult | null,
|
||||
): string | null {
|
||||
if (
|
||||
threadBranch === null ||
|
||||
gitStatus === null ||
|
||||
gitStatus.refName !== threadBranch ||
|
||||
gitStatus.changeRequestLookup._tag !== "failed"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const presentation = resolveChangeRequestPresentation(gitStatus.sourceControlProvider);
|
||||
switch (gitStatus.changeRequestLookup.reason) {
|
||||
case "authentication_required":
|
||||
return `${presentation.shortName} status unavailable: authentication required.`;
|
||||
case "provider_unavailable":
|
||||
return `${presentation.shortName} status unavailable: provider integration unavailable.`;
|
||||
case "lookup_failed":
|
||||
return `${presentation.shortName} status unavailable: lookup failed.`;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ import { ThreadId, type VcsStatusResult } from "@t3tools/contracts";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { changeRequestLookupWarning, ThreadWorktreeIndicator } from "./ThreadStatusIndicators";
|
||||
import { changeRequestLookupWarning } from "./ThreadStatusIndicators.logic";
|
||||
import { ThreadWorktreeIndicator } from "./ThreadStatusIndicators";
|
||||
|
||||
const failedStatus: VcsStatusResult = {
|
||||
isRepo: true,
|
||||
@@ -34,6 +35,22 @@ describe("changeRequestLookupWarning", () => {
|
||||
it("does not leak warnings across branches", () => {
|
||||
expect(changeRequestLookupWarning("feature/other", failedStatus)).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps the refresh warning when a cached open PR remains actionable", () => {
|
||||
expect(
|
||||
changeRequestLookupWarning("feature/sidebar-indicator", {
|
||||
...failedStatus,
|
||||
pr: {
|
||||
number: 42,
|
||||
title: "Cached open PR",
|
||||
url: "https://example.com/pr/42",
|
||||
baseRef: "main",
|
||||
headRef: "feature/sidebar-indicator",
|
||||
state: "open",
|
||||
},
|
||||
}),
|
||||
).toBe("PR status unavailable: authentication required.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ThreadWorktreeIndicator", () => {
|
||||
|
||||
@@ -20,6 +20,7 @@ import { vcsEnvironment } from "../state/vcs";
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
import { resolveChangeRequestPresentation } from "../sourceControlPresentation";
|
||||
import { resolveThreadStatusPill, type ThreadStatusPill } from "./Sidebar.logic";
|
||||
import { changeRequestLookupWarning } from "./ThreadStatusIndicators.logic";
|
||||
import type { SidebarThreadSummary } from "../types";
|
||||
import { formatWorktreePathForDisplay } from "../worktreeCleanup";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
@@ -39,29 +40,6 @@ export interface TerminalStatusIndicator {
|
||||
|
||||
export type ThreadPr = VcsStatusResult["pr"];
|
||||
|
||||
export function changeRequestLookupWarning(
|
||||
threadBranch: string | null,
|
||||
gitStatus: VcsStatusResult | null,
|
||||
): string | null {
|
||||
if (
|
||||
threadBranch === null ||
|
||||
gitStatus === null ||
|
||||
gitStatus.refName !== threadBranch ||
|
||||
gitStatus.changeRequestLookup._tag !== "failed"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const presentation = resolveChangeRequestPresentation(gitStatus.sourceControlProvider);
|
||||
switch (gitStatus.changeRequestLookup.reason) {
|
||||
case "authentication_required":
|
||||
return `${presentation.shortName} status unavailable: authentication required.`;
|
||||
case "provider_unavailable":
|
||||
return `${presentation.shortName} status unavailable: provider integration unavailable.`;
|
||||
case "lookup_failed":
|
||||
return `${presentation.shortName} status unavailable: lookup failed.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function prStatusIndicator(
|
||||
pr: ThreadPr,
|
||||
provider: VcsStatusResult["sourceControlProvider"] | null | undefined,
|
||||
|
||||
Reference in new issue
Block a user