fix: refresh Pi credential readiness

This commit is contained in:
2026-08-05 06:30:25 +02:00
parent 7df21b5f21
commit fd1fd2f802
5 changed files with 117 additions and 15 deletions
+48 -5
View File
@@ -81,6 +81,38 @@ test("saves only a selected non-secret configuration", async () => {
expect(screen.getByRole("status", { name: "Pi management feedback" })).toHaveTextContent("Defaults saved");
});
// Catches a provider switch updating only the saved config while leaving the credential rail
// attached to the previously selected provider.
test("shows authoritative credential presence after saving a different provider", async () => {
const user = userEvent.setup();
let saved = false;
server.use(
http.get("/api/pi-management/status", () => HttpResponse.json(saved ? {
...readyStatus,
credentials: "missing",
config: { provider: "deepseek", model: "deepseek-v4", reasoning: "medium" },
checkedAt: "2026-08-05T10:02:00.000Z",
} : readyStatus)),
http.put("/api/pi-management/config", async ({ request }) => {
saved = true;
return HttpResponse.json({
...await request.json() as object,
updatedAt: "2026-08-05T10:01:00.000Z",
});
}),
);
renderManagement();
expect(await screen.findByText("Credentials present")).toBeVisible();
await user.selectOptions(screen.getByLabelText("Provider"), "deepseek");
await user.click(screen.getByRole("button", { name: "Save defaults" }));
expect(await screen.findByText("Credentials missing")).toBeVisible();
expect(screen.queryByText("Credentials present")).not.toBeInTheDocument();
expect(screen.getByLabelText("Provider")).toHaveValue("deepseek");
expect(screen.getByRole("status", { name: "Pi management feedback" })).toHaveTextContent("Defaults saved");
});
test("runs the saved-configuration test without changing credential presence", async () => {
const user = userEvent.setup();
let tests = 0;
@@ -196,17 +228,28 @@ test("shows an explicit recoverable incomplete state when no provider model is a
});
test("keeps suggested draft choices distinct from invalid persisted defaults until save succeeds", async () => {
let configured = false;
const persisted = {
...readyStatus,
credentials: "missing",
config: { provider: "retired", model: "old-model", reasoning: "medium" },
};
server.use(
http.get("/api/pi-management/status", () => HttpResponse.json(persisted)),
http.put("/api/pi-management/config", async ({ request }) => HttpResponse.json({
...await request.json() as object,
updatedAt: "2026-08-05T10:05:00.000Z",
})),
http.get("/api/pi-management/status", () => HttpResponse.json(configured ? {
...readyStatus,
credentials: "missing",
config: { provider: "zai", model: "glm-5.2", reasoning: "medium" },
checkedAt: "2026-08-05T10:05:00.000Z",
} : persisted)),
http.put("/api/pi-management/config", () => {
configured = true;
return HttpResponse.json({
provider: "zai",
model: "glm-5.2",
reasoning: "medium",
updatedAt: "2026-08-05T10:05:00.000Z",
});
}),
);
const user = userEvent.setup();
renderManagement();
+2 -5
View File
@@ -10,7 +10,6 @@ import {
savePiManagementConfig,
type PiInstallationConfig,
type PiManagementOptions,
type PiManagementStatus,
} from "../api/pi-management";
import { Button } from "../components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../components/ui/dialog";
@@ -143,13 +142,11 @@ export function PiManagement({ open, onClose }: { open: boolean; onClose: () =>
const saveMutation = useMutation({
mutationFn: savePiManagementConfig,
onSuccess: (saved) => {
onSuccess: async (saved) => {
const config = { provider: saved.provider, model: saved.model, reasoning: saved.reasoning };
queryClient.setQueryData<PiManagementStatus>(["pi-management", "status"], (current) => (
current ? { ...current, config } : current
));
setDraft(config);
setSmokeState(undefined);
await queryClient.invalidateQueries({ queryKey: ["pi-management", "status"] });
setFeedback({ tone: "success", message: "Defaults saved." });
},
onError: (error) => setFeedback({ tone: "error", message: errorMessage(error, "Could not save Pi defaults.") }),