Skip to content

Commit 054029e

Browse files
t3dotggclaude
andcommitted
test(web): cover how the palette picks a triage machine
The selection moves into a small pure helper with tests for an old primary machine and for two capable machines. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8c679ae commit 054029e

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import { useAtomCommand } from "../state/use-atom-command";
109109
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
110110
import { useScratchProject } from "../hooks/useScratchProject";
111111
import { useStartTriage } from "../hooks/useStartTriage";
112+
import { pickTriageEnvironment } from "../lib/triageTarget";
112113
import { useNewProject } from "../hooks/useNewProject";
113114
import { isScratchProject } from "@t3tools/client-runtime/state/projects";
114115
import {
@@ -635,22 +636,17 @@ function OpenCommandPaletteDialog(props: {
635636
const scratchTargetEnvironmentId = scratchEnvironmentId(
636637
currentProjectEnvironmentId ?? primaryEnvironmentId,
637638
);
638-
// Triage the machine the user is looking at. With nothing open, the primary
639-
// if it supports triage, else the first machine that does. Not limited to
640-
// machines with No project threads: without them, the action explains the
641-
// terminal fallback.
642639
const supportsTriage = (environmentId: EnvironmentId | null) =>
643640
environments.find((environment) => environment.environmentId === environmentId)?.serverConfig
644641
?.environment.capabilities.triage === true;
645-
const triageEnvironmentId =
646-
currentProjectEnvironmentId ??
647-
(supportsTriage(primaryEnvironmentId)
648-
? primaryEnvironmentId
649-
: (environments.find(
650-
(environment) =>
651-
environment.connection.phase === "connected" &&
652-
supportsTriage(environment.environmentId),
653-
)?.environmentId ?? null));
642+
const triageEnvironmentId = pickTriageEnvironment({
643+
onScreen: currentProjectEnvironmentId,
644+
primary: primaryEnvironmentId,
645+
connected: environments
646+
.filter((environment) => environment.connection.phase === "connected")
647+
.map((environment) => environment.environmentId),
648+
supportsTriage,
649+
});
654650
const canTriage =
655651
useAtomValue(serverEnvironment.prepareTriage.permissionAtom(triageEnvironmentId)) &&
656652
supportsTriage(triageEnvironmentId);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { pickTriageEnvironment } from "./triageTarget";
4+
5+
describe("pickTriageEnvironment", () => {
6+
it("skips a primary machine whose server lacks triage", () => {
7+
expect(
8+
pickTriageEnvironment({
9+
onScreen: null,
10+
primary: "old-primary",
11+
connected: ["old-primary", "new-remote"],
12+
supportsTriage: (environmentId) => environmentId === "new-remote",
13+
}),
14+
).toBe("new-remote");
15+
});
16+
17+
it("prefers a capable primary over other capable machines", () => {
18+
expect(
19+
pickTriageEnvironment({
20+
onScreen: null,
21+
primary: "primary",
22+
connected: ["remote", "primary"],
23+
supportsTriage: () => true,
24+
}),
25+
).toBe("primary");
26+
});
27+
});

‎apps/web/src/lib/triageTarget.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The machine triage runs on: the one on screen, else the primary if it
3+
* supports triage, else the first connected machine that does. Without No
4+
* project threads the action still shows and explains the terminal fallback,
5+
* so this does not check for them.
6+
*/
7+
export function pickTriageEnvironment<Id extends string>(input: {
8+
readonly onScreen: Id | null;
9+
readonly primary: Id | null;
10+
readonly connected: ReadonlyArray<Id>;
11+
readonly supportsTriage: (environmentId: Id) => boolean;
12+
}): Id | null {
13+
if (input.onScreen !== null) return input.onScreen;
14+
if (input.primary !== null && input.supportsTriage(input.primary)) return input.primary;
15+
return input.connected.find(input.supportsTriage) ?? null;
16+
}

0 commit comments

Comments
 (0)