Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions apps/web/src/components/ProviderUpdatesAction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { m } from "../i18n/messages";
import { thrownErrorMessage } from "@t3tools/client-runtime/errors";
import { AuthProvidersManageScope, PROVIDER_DISPLAY_NAMES } from "@t3tools/contracts";
import {
AuthProvidersManageScope,
type EnvironmentId,
PROVIDER_DISPLAY_NAMES,
} from "@t3tools/contracts";
import {
isAtomCommandInterrupted,
settlePromise,
Expand All @@ -19,6 +23,7 @@ import {
getProviderUpdateRunToastView,
type ProviderUpdateRun,
} from "./ProviderUpdateLaunchNotification.logic";
import { selectUpdateMachines } from "./sidebar/updateEverything.logic";
import { Button } from "./ui/button";
import { stackedThreadToast, toastManager } from "./ui/toast";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
Expand Down Expand Up @@ -94,19 +99,26 @@ export function useProviderUpdates() {
: [];
});

const updateAll = async ({ quiet = false }: { readonly quiet?: boolean } = {}) => {
const updateAll = async ({
quiet = false,
environmentIds,
}: {
readonly quiet?: boolean;
readonly environmentIds?: ReadonlyArray<EnvironmentId>;
} = {}) => {
const runs = await Promise.all(
machines.flatMap(({ environmentId, label, candidates }) =>
candidates.map(async (candidate): Promise<ProviderUpdateRun> => ({
environmentId,
machineLabel: label,
driver: candidate.driver,
instanceId: candidate.instanceId,
result: await updateProvider({
selectUpdateMachines(machines, environmentIds).flatMap(
({ environmentId, label, candidates }) =>
candidates.map(async (candidate): Promise<ProviderUpdateRun> => ({
environmentId,
input: { provider: candidate.driver, instanceId: candidate.instanceId },
}),
})),
machineLabel: label,
driver: candidate.driver,
instanceId: candidate.instanceId,
result: await updateProvider({
environmentId,
input: { provider: candidate.driver, instanceId: candidate.instanceId },
}),
})),
),
);
const view = quiet ? null : getProviderUpdateRunToastView(runs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ describe("SidebarUpdatePill update everything", () => {
await userEvent.click(screen.getByRole("button", { name: "Update everything" }));

const table = page.getByRole("table");
await expect.element(table.getByRole("columnheader", { name: "Machine" })).toBeVisible();
await expect
.element(table.getByRole("columnheader", { name: "Select all machines Machine" }))
.toBeVisible();
await expect.element(table.getByRole("columnheader", { name: "T3 Code" })).toBeVisible();
await expect.element(table.getByRole("columnheader", { name: "Providers" })).toBeVisible();
const row = table.getByRole("row", { name: new RegExp(label) });
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/components/sidebar/SidebarUpdatePill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import {
import { SidebarUpdateReleaseNotes } from "./SidebarUpdateReleaseNotes";
import { SidebarUpdateCapsule } from "./SidebarUpdateCapsule";
import { UpdateEverythingDialog } from "./UpdateEverythingDialog";
import type { UpdateEverythingRun, UpdateRunLocalState } from "./updateEverything.logic";
import type {
UpdateEverythingRun,
UpdateRunLocalState,
UpdateMachineSelection,
} from "./updateEverything.logic";
import {
clearSavedUpdateEverythingResult,
saveUpdateEverythingResult,
Expand Down Expand Up @@ -371,12 +375,13 @@ function SidebarUpdateControl() {
void Promise.allSettled([appCheck, providersChecked]).then(() => setIsActionPending(false));
};

const runEverything = async () => {
const runEverything = async (selection?: UpdateMachineSelection) => {
const bridge = window.desktopBridge;
setIsConfirmingEverything(false);
setIsActionPending(true);
const result = await settlePromise(() =>
everything.run({
...(selection ? { selection } : {}),
...(bridge && action === "download"
? {
downloadLocal: (reportError) =>
Expand Down Expand Up @@ -430,7 +435,8 @@ function SidebarUpdateControl() {
rows={everything.rows}
restarts={everything.restarts}
checking={providerCheck === "dialog"}
onConfirm={() => void runEverything()}
selectable
onConfirm={(selection) => void runEverything(selection)}
/>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { EnvironmentId } from "@t3tools/contracts";
import { expect, it, vi } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";

import "~/index.css";
import { render } from "../../../test/render";
import { describeUpdateEverything } from "./updateEverything.logic";
import { UpdateEverythingDialog } from "./UpdateEverythingDialog";

it("lets a remote user update the laptop without updating the PC host", async () => {
const pc = EnvironmentId.make("pc");
const laptop = EnvironmentId.make("laptop");
const onConfirm = vi.fn();
await using _screen = await render(
<UpdateEverythingDialog
open
onOpenChange={() => {}}
selectable
version="0.2.0"
providerCount={2}
rows={[
{
environmentId: pc,
label: "PC host",
app: "this-app",
providers: ["Codex"],
skipped: null,
},
{
environmentId: laptop,
label: "Laptop",
app: "desktop-app",
providers: ["Claude"],
skipped: null,
},
]}
restarts={[]}
onConfirm={onConfirm}
/>,
);
const selectAll = page.getByRole("checkbox", { name: "Select all machines" });
await expect.element(page.getByRole("heading", { name: "Update 2 machines?" })).toBeVisible();
await userEvent.click(selectAll);
await expect.element(page.getByRole("checkbox", { name: "Laptop" })).not.toBeChecked();
await expect.element(page.getByRole("button", { name: "Update", exact: true })).toBeDisabled();
await userEvent.click(selectAll);
await expect.element(page.getByRole("heading", { name: "Update 2 machines?" })).toBeVisible();
await userEvent.click(page.getByRole("checkbox", { name: "PC host" }));
await expect.element(selectAll).toHaveAttribute("aria-checked", "mixed");
await expect.element(page.getByRole("heading", { name: "Update 1 machine?" })).toBeVisible();
await expect.element(page.getByText(/1 provider update$/)).toBeVisible();
await userEvent.click(page.getByRole("checkbox", { name: "Laptop" }));
await expect.element(page.getByRole("button", { name: "Update", exact: true })).toBeDisabled();
await userEvent.click(page.getByRole("checkbox", { name: "Laptop" }));
await userEvent.click(page.getByRole("button", { name: "Update", exact: true }));
expect(onConfirm).toHaveBeenCalledWith({ environmentIds: [laptop], updateLocal: false });
});
it("keeps local provider exclusions when an app update arrives", async () => {
const pc = EnvironmentId.make("pc");
const laptop = EnvironmentId.make("laptop");
const onConfirm = vi.fn();
const dialog = (app: "this-app" | null) => (
<UpdateEverythingDialog
open
onOpenChange={() => {}}
selectable
checking
version={app === null ? null : "0.2.0"}
providerCount={2}
rows={
describeUpdateEverything({
localVersion: app === null ? null : "0.2.0",
localMachines: [{ environmentId: pc, label: "PC host" }],
servers: [],
providerMachines: [
{ environmentId: pc, label: "PC host", providers: ["Codex"] },
{ environmentId: laptop, label: "Laptop", providers: ["Claude"] },
],
skipped: [],
}).rows
}
restarts={[]}
onConfirm={onConfirm}
/>
);
await using screen = await render(dialog(null));
await userEvent.click(page.getByRole("checkbox", { name: "PC host" }));
await screen.rerender(dialog("this-app"));
await expect.element(page.getByRole("checkbox", { name: "PC host" })).not.toBeChecked();
await expect
.element(page.getByText(/1 provider update/))
.toHaveTextContent("1 provider update · Checking for more…");
await userEvent.click(page.getByRole("button", { name: "Update", exact: true }));
expect(onConfirm).toHaveBeenCalledWith({ environmentIds: [laptop], updateLocal: false });
await userEvent.click(page.getByRole("checkbox", { name: "Laptop" }));
await expect.element(page.getByText("Checking for more…", { exact: true })).toBeVisible();
});
Loading
Loading