diff --git a/apps/web/src/components/chat/ThreadDetailsPanel.test.tsx b/apps/web/src/components/chat/ThreadDetailsPanel.test.tsx new file mode 100644 index 0000000000..fc1ff4e357 --- /dev/null +++ b/apps/web/src/components/chat/ThreadDetailsPanel.test.tsx @@ -0,0 +1,91 @@ +import type { EnvironmentId, T3ProjectFileScript, ThreadId } from "@t3tools/contracts"; +import { renderToStaticMarkup } from "react-dom/server"; +import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; + +const testState = vi.hoisted(() => ({ + useT3ProjectFileScripts: vi.fn(), + projectScriptsControl: vi.fn(), +})); + +vi.mock("../../hooks/useT3ProjectFileScripts", () => ({ + useT3ProjectFileScripts: (...args: ReadonlyArray) => + testState.useT3ProjectFileScripts(...args), +})); +vi.mock("../BranchToolbar", () => ({ + BranchToolbar: () => null, +})); +vi.mock("../ProjectScriptsControl", () => ({ + default: (props: unknown) => { + testState.projectScriptsControl(props); + return null; + }, +})); +vi.mock("./ThreadAutomationsPanel", () => ({ + ThreadAutomationsPanel: () => null, +})); +vi.mock("./ThreadRelationshipsControl", () => ({ + ThreadRelationshipsPanel: () => null, +})); + +import { ThreadDetailsPanel, type ThreadDetailsPanelProps } from "./ThreadDetailsPanel"; + +describe("ThreadDetailsPanel", () => { + beforeEach(() => { + testState.useT3ProjectFileScripts.mockReset(); + testState.projectScriptsControl.mockReset(); + }); + + it("passes checked-in t3.json scripts to the project scripts control", () => { + const environmentId = "environment:thread-details" as EnvironmentId; + const gitCwd = "/tmp/thread-details-project"; + const fileScripts = [ + { + name: "Check project", + command: "vp check", + icon: "test", + }, + ] satisfies ReadonlyArray; + testState.useT3ProjectFileScripts.mockReturnValue(fileScripts); + + const props: ThreadDetailsPanelProps = { + mode: "popover", + environmentId, + environmentConnection: null, + threadId: "thread:thread-details" as ThreadId, + activeProjectName: undefined, + activeProjectScripts: [], + preferredScriptId: null, + keybindings: [], + availableEditors: [], + showOpenInPicker: false, + gitCwd, + isGitRepo: false, + envLocked: false, + availableEnvironments: [], + onEnvironmentChange: vi.fn(), + onEnvModeChange: vi.fn(), + startFromOrigin: false, + onStartFromOriginChange: vi.fn(), + onComposerFocusRequest: vi.fn(), + onReconnectEnvironment: vi.fn(), + onOpenConnectionSettings: vi.fn(), + versionMismatch: null, + onDismissVersionMismatch: vi.fn(), + onRunProjectScript: vi.fn(), + onAddProjectScript: vi.fn() as ThreadDetailsPanelProps["onAddProjectScript"], + onUpdateProjectScript: vi.fn() as ThreadDetailsPanelProps["onUpdateProjectScript"], + onDeleteProjectScript: vi.fn() as ThreadDetailsPanelProps["onDeleteProjectScript"], + }; + + renderToStaticMarkup(); + + expect(testState.useT3ProjectFileScripts).toHaveBeenCalledWith(environmentId, gitCwd); + expect(testState.projectScriptsControl).toHaveBeenCalledWith( + expect.objectContaining({ + displayMode: "panel", + scripts: [], + fileScripts, + }), + ); + }); +}); diff --git a/apps/web/src/components/chat/ThreadDetailsPanel.tsx b/apps/web/src/components/chat/ThreadDetailsPanel.tsx index cbfaf1136f..cb01abe28a 100644 --- a/apps/web/src/components/chat/ThreadDetailsPanel.tsx +++ b/apps/web/src/components/chat/ThreadDetailsPanel.tsx @@ -9,6 +9,7 @@ import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/ import { AlertTriangleIcon, XIcon } from "lucide-react"; import type { DraftId } from "../../composerDraftStore"; +import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts"; import type { EnvMode, EnvironmentOption } from "../BranchToolbar.logic"; import { BranchToolbar } from "../BranchToolbar"; import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector"; @@ -70,6 +71,10 @@ export interface ThreadDetailsPanelProps { } export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) { + const fileScripts = useT3ProjectFileScripts( + props.environmentId, + props.activeProjectScripts ? props.gitCwd : null, + ); const connectionIssue = props.environmentConnection !== null && props.environmentConnection.phase !== "connected" && @@ -199,6 +204,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {