Skip to content

Commit b36ab54

Browse files
ScottN-PVclaude
andcommitted
test(web): cover the Settings action on a generation failure
The Git actions test now records toasts and navigation, so it checks that each model setting opens its own Settings page and section with the acting checkout's scope, closes the toast, and that a failure naming no setting offers no action. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 94cbc02 commit b36ab54

1 file changed

Lines changed: 73 additions & 2 deletions

File tree

‎apps/web/src/components/GitActionsControl.test.ts‎

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AuthOrchestrationOperateScope,
33
AuthSourceControlWriteScope,
44
EnvironmentId,
5+
TextGenerationError,
56
ThreadId,
67
} from "@t3tools/contracts";
78
import * as Cause from "effect/Cause";
@@ -19,6 +20,10 @@ const state = vi.hoisted(() => ({
1920
metadataRequests: [] as { environmentId: string; branch: string }[],
2021
afterGitAction: undefined as (() => void) | undefined,
2122
run: null as ((input: { action: "commit"; featureBranch?: boolean }) => Promise<void>) | null,
23+
failure: null as unknown,
24+
toasts: [] as { actionProps?: { children: string; onClick: () => void } }[],
25+
closedToasts: [] as string[],
26+
navigations: [] as unknown[],
2227
}));
2328

2429
vi.mock("react", async (importOriginal) => ({
@@ -40,6 +45,7 @@ vi.mock("~/state/entities", () => ({
4045
useThreadProjection: (ref: unknown) =>
4146
ref === null || state.detail === null ? null : { projection: { thread: state.detail } },
4247
useThreadShell: () => state.shell,
48+
readProjects: () => [],
4349
}));
4450
vi.mock("~/state/session", () => ({
4551
useEnvironmentScope: (environmentId: unknown, scope: string) =>
@@ -108,6 +114,7 @@ vi.mock("~/lib/sourceControlActions", () => ({
108114
useSourceControlPublishRepositoryAction: () => ({}),
109115
useGitStackedAction: () => ({
110116
run: async ({ featureBranch }: { featureBranch?: boolean }) => {
117+
if (state.failure !== null) return AsyncResult.failure(Cause.fail(state.failure));
111118
state.commits += 1;
112119
if (featureBranch) state.branch = "feature";
113120
state.afterGitAction?.();
@@ -126,11 +133,17 @@ vi.mock("~/lib/sourceControlActions", () => ({
126133
vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
127134
vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
128135
vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
129-
vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
136+
vi.mock("@tanstack/react-router", () => ({
137+
useNavigate: () => (input: unknown) => state.navigations.push(input),
138+
}));
130139
vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
131140
vi.mock("~/components/ui/toast", () => ({
132141
stackedThreadToast: (input: unknown) => input,
133-
toastManager: { add: () => "toast", update: () => {}, close: () => {} },
142+
toastManager: {
143+
add: (toast: (typeof state.toasts)[number]) => state.toasts.push(toast) && "toast",
144+
update: () => {},
145+
close: (id: string) => state.closedToasts.push(id),
146+
},
134147
}));
135148
vi.mock("~/components/ui/dialog", () => ({
136149
Dialog: "Dialog",
@@ -195,6 +208,10 @@ describe("Git actions while thread details load", () => {
195208
state.metadataRequests = [];
196209
state.afterGitAction = undefined;
197210
state.run = null;
211+
state.failure = null;
212+
state.toasts = [];
213+
state.closedToasts = [];
214+
state.navigations = [];
198215
});
199216

200217
it("does not create a feature branch for a server thread without task permission", async () => {
@@ -294,3 +311,57 @@ describe("Git actions while thread details load", () => {
294311
expect(state.metadataRequests).toEqual([]);
295312
});
296313
});
314+
315+
describe("Settings action on a generation failure", () => {
316+
beforeEach(() => {
317+
state.scopes = new Set([AuthSourceControlWriteScope]);
318+
state.primaryScopes = new Set();
319+
state.shell = { branch: "main" };
320+
state.detail = null;
321+
state.draft = null;
322+
state.run = null;
323+
state.toasts = [];
324+
state.closedToasts = [];
325+
state.navigations = [];
326+
});
327+
328+
it.each([
329+
["textGenerationModelSelection", "/settings/general", "text-generation-model"],
330+
[
331+
"sourceControlWriterModelSelection",
332+
"/settings/source-control",
333+
"source-control-writer-model",
334+
],
335+
] as const)("opens Settings at %s and closes the toast", async (modelSetting, to, hash) => {
336+
state.failure = new TextGenerationError({
337+
operation: "generateCommitMessage",
338+
detail: "Model unavailable",
339+
modelSetting,
340+
});
341+
await renderActions()({ action: "commit" });
342+
343+
const action = state.toasts.at(-1)?.actionProps;
344+
expect(action?.children).toBe("Settings");
345+
action?.onClick();
346+
347+
expect(state.closedToasts).toEqual(["toast"]);
348+
expect(state.navigations).toEqual([
349+
{
350+
to,
351+
hash,
352+
search: { machine: "environment", project: undefined, checkout: "environment:/repo" },
353+
},
354+
]);
355+
});
356+
357+
it("offers no Settings action when the failure names no setting", async () => {
358+
state.failure = new TextGenerationError({
359+
operation: "generateCommitMessage",
360+
detail: "Timed out",
361+
});
362+
await renderActions()({ action: "commit" });
363+
364+
expect(state.toasts).toHaveLength(1);
365+
expect(state.toasts[0]?.actionProps).toBeUndefined();
366+
});
367+
});

0 commit comments

Comments
 (0)