Skip to content

Commit 89f0946

Browse files
fix(web): show idle server updates on environment controls (#21950)
1 parent 673c5e3 commit 89f0946

10 files changed

Lines changed: 441 additions & 145 deletions

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,37 @@ describe("shouldShowEnvironmentIndicator", () => {
439439
});
440440

441441
describe("shouldShowComposerContextStrip", () => {
442+
it("keeps a sole primary server update reachable in a non-Git draft", () => {
443+
const environment = {
444+
activeEnvironment: { isPrimary: true },
445+
canPickEnvironment: false,
446+
serverUpdateAvailable: true,
447+
};
448+
const showEnvironmentIndicator = shouldShowEnvironmentIndicator(environment);
449+
expect(showEnvironmentIndicator).toBe(true);
450+
expect(
451+
shouldShowComposerContextStrip({
452+
isDraftHeroState: true,
453+
persistInActiveThreads: false,
454+
hasActiveProject: true,
455+
isGitRepo: false,
456+
showEnvironmentIndicator,
457+
hostsRestingComposerControls: false,
458+
}),
459+
).toBe(true);
460+
expect(
461+
shouldShowComposerContextStrip({
462+
isDraftHeroState: false,
463+
persistInActiveThreads: false,
464+
hasActiveProject: true,
465+
isGitRepo: false,
466+
showEnvironmentIndicator,
467+
serverUpdateAvailable: true,
468+
hostsRestingComposerControls: false,
469+
}),
470+
).toBe(true);
471+
});
472+
442473
it.each([false, true])(
443474
"honors the active-thread preference with resting controls %s",
444475
(hostsRestingComposerControls) => {

‎apps/web/src/components/BranchToolbar.logic.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ export function resolveEnvironmentOptionLabel(input: {
5555
export function shouldShowEnvironmentIndicator(input: {
5656
activeEnvironment: Pick<EnvironmentOption, "isPrimary"> | null;
5757
canPickEnvironment: boolean;
58+
serverUpdateAvailable?: boolean;
5859
}): boolean {
59-
if (input.canPickEnvironment) return true;
60+
if (input.canPickEnvironment || input.serverUpdateAvailable) return true;
6061
return input.activeEnvironment !== null && !input.activeEnvironment.isPrimary;
6162
}
6263

@@ -67,10 +68,13 @@ export function shouldShowComposerContextStrip(input: {
6768
isGitRepo: boolean;
6869
showEnvironmentIndicator: boolean;
6970
hostsRestingComposerControls: boolean;
71+
serverUpdateAvailable?: boolean;
7072
}): boolean {
7173
return (
7274
input.hasActiveProject &&
73-
(input.isDraftHeroState || input.persistInActiveThreads) &&
75+
(input.isDraftHeroState ||
76+
input.persistInActiveThreads ||
77+
input.serverUpdateAvailable === true) &&
7478
(input.isGitRepo || input.showEnvironmentIndicator || input.hostsRestingComposerControls)
7579
);
7680
}

‎apps/web/src/components/BranchToolbar.panel.browser.test.tsx‎

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ vi.mock(import("../localApi"), async (original) => ({
1919
vi.mock(import("../hooks/useCopyToClipboard"), async (original) => ({
2020
...(await original()),
2121
writeTextToClipboard: state.writeTextToClipboard,
22+
useCopyToClipboard: ((options: { target: string }) => ({
23+
copyToClipboard: (command: string) => state.writeTextToClipboard(command, options.target),
24+
isCopied: false,
25+
})) as never,
2226
}));
2327
vi.mock(import("./BranchToolbarBranchSelector"), async (original) => ({
2428
...(await original()),
@@ -36,6 +40,8 @@ vi.mock(import("../state/entities"), async (original) => ({
3640
}));
3741

3842
import { BranchToolbar } from "./BranchToolbar";
43+
import { ComposerSurface } from "./chat/ComposerSurface";
44+
import type { ServerUpdateTarget } from "./ServerUpdateAction";
3945

4046
let root: Root;
4147
let container: HTMLDivElement;
@@ -59,19 +65,21 @@ afterEach(async () => {
5965
function render(props: Partial<ComponentProps<typeof BranchToolbar>>) {
6066
return act(async () =>
6167
root.render(
62-
<BranchToolbar
63-
layout="panel"
64-
panelSection="workspace"
65-
environmentId={EnvironmentId.make("local")}
66-
threadId={ThreadId.make("thread")}
67-
showGitControls
68-
envMode="local"
69-
envLocked={false}
70-
startFromOrigin={false}
71-
onStartFromOriginChange={vi.fn()}
72-
onEnvModeChange={vi.fn()}
73-
{...props}
74-
/>,
68+
<ComposerSurface.Shell>
69+
<BranchToolbar
70+
layout="panel"
71+
panelSection="workspace"
72+
environmentId={EnvironmentId.make("local")}
73+
threadId={ThreadId.make("thread")}
74+
showGitControls
75+
envMode="local"
76+
envLocked={false}
77+
startFromOrigin={false}
78+
onStartFromOriginChange={vi.fn()}
79+
onEnvModeChange={vi.fn()}
80+
{...props}
81+
/>
82+
</ComposerSurface.Shell>,
7583
),
7684
);
7785
}
@@ -146,3 +154,55 @@ it.each([
146154
}
147155
},
148156
);
157+
158+
it.each([
159+
{ layout: "wide Git", width: 900, showGitControls: true },
160+
{ layout: "narrow Git", width: 360, showGitControls: true },
161+
{ layout: "sole primary non-Git", width: 360, showGitControls: false },
162+
])(
163+
"copies the pending update from the $layout composer chip",
164+
async ({ width, showGitControls }) => {
165+
await page.viewport(1000, 700);
166+
container.style.width = `${width}px`;
167+
container.style.setProperty("--chat-content-max-width", `${width}px`);
168+
const serverUpdate = {
169+
environmentId: EnvironmentId.make("local"),
170+
serverLabel: "Build box",
171+
serverVersion: "0.0.30",
172+
targetVersion: "0.0.31",
173+
selfUpdate: null,
174+
installation: { kind: "npm-global", prefix: "/opt/node" },
175+
} satisfies ServerUpdateTarget & { serverVersion: string };
176+
await render({
177+
layout: "composer",
178+
envLocked: showGitControls,
179+
showGitControls,
180+
availableEnvironments: [
181+
{
182+
environmentId: serverUpdate.environmentId,
183+
projectId: ProjectId.make("project"),
184+
label: serverUpdate.serverLabel,
185+
isPrimary: true,
186+
machine: "server",
187+
},
188+
],
189+
serverUpdate,
190+
});
191+
192+
expect(
193+
container.querySelector('[data-slot="composer-shell"]')!.getBoundingClientRect().width,
194+
).toBe(width);
195+
const chip = page.getByRole("button", { name: /Build box|Copy update command/ });
196+
await expect.element(chip).toBeVisible();
197+
await userEvent.hover(chip);
198+
await expect.element(page.getByRole("tooltip")).toMatchTextContent("0.0.30");
199+
await expect.element(page.getByRole("tooltip")).toMatchTextContent("0.0.31");
200+
await userEvent.click(chip);
201+
await vi.waitFor(() =>
202+
expect(state.writeTextToClipboard).toHaveBeenCalledWith(
203+
"npm install --global --prefix '/opt/node' [email protected]",
204+
"update command",
205+
),
206+
);
207+
},
208+
);

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
type BranchToolbarBranchSelectorHandle,
4343
} from "./BranchToolbarBranchSelector";
4444
import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
45+
import type { PendingServerUpdate } from "./ServerUpdateAction";
4546
import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
4647
import { PreviousWorktreeItemContent } from "./PreviousWorktreeItemContent";
4748
import { ThreadDetailsControl } from "./chat/ThreadDetailsControl";
@@ -99,6 +100,7 @@ interface BranchToolbarProps {
99100
onEnvironmentChange?: (environmentId: EnvironmentId) => void;
100101
composerControlsHostRef?: (element: HTMLDivElement | null) => void;
101102
contextStripVisible?: boolean;
103+
serverUpdate?: PendingServerUpdate | null;
102104
}
103105

104106
function showWorkspaceContextMenu(event: ReactMouseEvent, workspacePath: string) {
@@ -586,6 +588,7 @@ export const BranchToolbar = memo(function BranchToolbar({
586588
onEnvironmentChange,
587589
composerControlsHostRef,
588590
contextStripVisible = true,
591+
serverUpdate = null,
589592
}: BranchToolbarProps) {
590593
const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);
591594
const threadRef = scopeThreadRef(environmentId, threadId);
@@ -659,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({
659662
const showEnvironmentIndicator = shouldShowEnvironmentIndicator({
660663
activeEnvironment: activeEnvironmentOption,
661664
canPickEnvironment: hasMultipleEnvironments,
665+
serverUpdateAvailable: serverUpdate !== null,
662666
});
663667
const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
664668
const labelsOverflow = useLabelsOverflow(stripElement);
@@ -723,6 +727,17 @@ export const BranchToolbar = memo(function BranchToolbar({
723727
!contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full",
724728
)}
725729
>
730+
{serverUpdate && availableEnvironments ? (
731+
<BranchToolbarEnvironmentSelector
732+
autoEnvironmentLabel={autoEnvironmentLabel}
733+
onAutoEnvironment={onAutoEnvironment}
734+
envLocked={envLocked}
735+
environmentId={environmentId}
736+
availableEnvironments={availableEnvironments}
737+
{...(showEnvironmentPicker ? { onEnvironmentChange } : {})}
738+
serverUpdate={serverUpdate}
739+
/>
740+
) : null}
726741
{showGitControls ? (
727742
<div className="contents @3xl/composer-surface:hidden">
728743
<RunContextSelector
@@ -733,8 +748,8 @@ export const BranchToolbar = memo(function BranchToolbar({
733748
envModeLocked={envModeLocked}
734749
environmentId={environmentId}
735750
availableEnvironments={availableEnvironments}
736-
showEnvironmentPicker={showEnvironmentPicker}
737-
showEnvironmentIndicator={showEnvironmentIndicator}
751+
showEnvironmentPicker={showEnvironmentPicker && serverUpdate === null}
752+
showEnvironmentIndicator={showEnvironmentIndicator && serverUpdate === null}
738753
onEnvironmentChange={onEnvironmentChange}
739754
effectiveEnvMode={effectiveEnvMode}
740755
activeWorktreePath={activeWorktreePath}
@@ -745,7 +760,7 @@ export const BranchToolbar = memo(function BranchToolbar({
745760
/>
746761
</div>
747762
) : null}
748-
{showGitControls || showEnvironmentIndicator ? (
763+
{showGitControls || (showEnvironmentIndicator && serverUpdate === null) ? (
749764
<div
750765
className={cn(
751766
"min-h-7 min-w-10 items-center gap-1 sm:min-h-6",
@@ -755,14 +770,16 @@ export const BranchToolbar = memo(function BranchToolbar({
755770
>
756771
{showEnvironmentIndicator && availableEnvironments && (
757772
<>
758-
<BranchToolbarEnvironmentSelector
759-
autoEnvironmentLabel={autoEnvironmentLabel}
760-
onAutoEnvironment={onAutoEnvironment}
761-
envLocked={envLocked}
762-
environmentId={environmentId}
763-
availableEnvironments={availableEnvironments}
764-
{...(showEnvironmentPicker ? { onEnvironmentChange } : {})}
765-
/>
773+
{serverUpdate === null ? (
774+
<BranchToolbarEnvironmentSelector
775+
autoEnvironmentLabel={autoEnvironmentLabel}
776+
onAutoEnvironment={onAutoEnvironment}
777+
envLocked={envLocked}
778+
environmentId={environmentId}
779+
availableEnvironments={availableEnvironments}
780+
{...(showEnvironmentPicker ? { onEnvironmentChange } : {})}
781+
/>
782+
) : null}
766783
{showGitControls ? (
767784
<Separator
768785
orientation="vertical"

0 commit comments

Comments
 (0)