fix: harden Pi management readiness

This commit is contained in:
2026-08-05 06:20:25 +02:00
parent 7a8bcacbfe
commit 7df21b5f21
24 changed files with 577 additions and 274 deletions
+113 -8
View File
@@ -8,6 +8,7 @@ import { PiManagement } from "./PiManagement";
const readyStatus = {
version: "0.80.3",
ready: true,
credentials: "present",
config: { provider: "zai", model: "glm-5.2", reasoning: "medium" },
checkedAt: "2026-08-05T10:00:00.000Z",
};
@@ -45,7 +46,7 @@ test("loads Pi version and readiness as an accessible operational rail", async (
expect(screen.getByRole("status", { name: "Pi readiness" })).toHaveTextContent("Ready");
expect(screen.getByText("Pi 0.80.3")).toBeVisible();
expect(screen.getByText("Defaults ready")).toBeVisible();
expect(screen.getByRole("button", { name: "Run smoke test" })).toBeVisible();
expect(screen.getByRole("button", { name: "Test saved defaults" })).toBeVisible();
});
test("uses closed provider, model, and reasoning choices without a secret field or terminal", async () => {
@@ -80,7 +81,7 @@ test("saves only a selected non-secret configuration", async () => {
expect(screen.getByRole("status", { name: "Pi management feedback" })).toHaveTextContent("Defaults saved");
});
test("runs a provider smoke test and reports credentials only as present or missing", async () => {
test("runs the saved-configuration test without changing credential presence", async () => {
const user = userEvent.setup();
let tests = 0;
server.use(http.post("/api/pi-management/test", () => {
@@ -91,11 +92,17 @@ test("runs a provider smoke test and reports credentials only as present or miss
}));
renderManagement();
await user.click(await screen.findByRole("button", { name: "Run smoke test" }));
expect(await screen.findByText("Credentials present")).toBeVisible();
await user.click(screen.getByRole("button", { name: "Run smoke test" }));
expect(await screen.findByText("Credentials missing")).toBeVisible();
expect(screen.getByRole("status", { name: "Pi management feedback" })).toHaveTextContent("Pi provider smoke check failed");
const testButton = await screen.findByRole("button", { name: "Test saved defaults" });
expect(screen.getByText("Defaults ready")).toBeVisible();
expect(screen.queryByText("Changes are not saved yet.")).not.toBeInTheDocument();
expect(testButton).toBeEnabled();
await user.click(testButton);
await waitFor(() => expect(tests).toBe(1));
expect(await screen.findByText("Saved configuration test passed")).toBeVisible();
expect(screen.getByText("Credentials present")).toBeVisible();
await user.click(screen.getByRole("button", { name: "Test saved defaults" }));
expect(await screen.findByText("Saved configuration test failed")).toBeVisible();
expect(screen.getByText("Credentials present")).toBeVisible();
});
test("fetches and displays bounded sanitized diagnostic logs only on request", async () => {
@@ -125,7 +132,7 @@ test("explains forbidden management access without offering mutation controls",
expect(await screen.findByRole("alert", { name: "Pi management unavailable" })).toHaveTextContent("Pi management is not permitted");
expect(screen.queryByLabelText("Provider")).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Save defaults" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Run smoke test" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Test saved defaults" })).not.toBeInTheDocument();
});
test("offers a copyable host-side Pi update instruction without an update action", async () => {
@@ -168,3 +175,101 @@ test("reloads installation defaults when the panel is reopened", async () => {
await waitFor(() => expect(screen.getByLabelText("Provider")).toHaveValue("deepseek"));
});
test("shows an explicit recoverable incomplete state when no provider model is available", async () => {
server.use(
http.get("/api/pi-management/status", () => HttpResponse.json({ ...readyStatus, credentials: "present" })),
http.get("/api/pi-management/options", () => HttpResponse.json({
...options,
providers: ["zai"],
models: [],
})),
);
renderManagement();
const incomplete = await screen.findByRole("alert", { name: "Pi configuration incomplete" });
expect(incomplete).toHaveTextContent("No enabled provider and model choices are available");
expect(incomplete).toHaveTextContent("Check the host-managed Pi model configuration");
expect(screen.queryByText("Loading Pi management…")).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Save defaults" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Test saved defaults" })).toBeDisabled();
});
test("keeps suggested draft choices distinct from invalid persisted defaults until save succeeds", async () => {
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",
})),
);
const user = userEvent.setup();
renderManagement();
expect(await screen.findByLabelText("Provider")).toHaveValue("zai");
expect(screen.getByText("Defaults incomplete")).toBeVisible();
expect(screen.getByText("Suggested choices are not saved yet.")).toBeVisible();
expect(screen.getByRole("button", { name: "Test saved defaults" })).toBeDisabled();
await user.click(screen.getByRole("button", { name: "Save defaults" }));
expect(await screen.findByText("Defaults ready")).toBeVisible();
expect(screen.getByRole("button", { name: "Test saved defaults" })).toBeEnabled();
});
test.each(["present", "missing"] as const)(
"shows credentials %s from status without inferring them from smoke",
async (credentials) => {
server.use(http.get("/api/pi-management/status", () => HttpResponse.json({
...readyStatus,
credentials,
})));
renderManagement();
expect(await screen.findByText(`Credentials ${credentials}`)).toBeVisible();
},
);
test("labels smoke only as a saved-configuration test and resets it when the draft changes", async () => {
server.use(
http.get("/api/pi-management/status", () => HttpResponse.json({ ...readyStatus, credentials: "present" })),
http.post("/api/pi-management/test", () => HttpResponse.json({
ready: true,
checkedAt: "2026-08-05T10:06:00.000Z",
})),
);
const user = userEvent.setup();
renderManagement();
await user.click(await screen.findByRole("button", { name: "Test saved defaults" }));
expect(await screen.findByText("Saved configuration test passed")).toBeVisible();
expect(screen.getByText("Credentials present")).toBeVisible();
await user.selectOptions(screen.getByLabelText("Provider"), "deepseek");
expect(screen.getByText("Saved configuration test not run")).toBeVisible();
expect(screen.getByText("Save these changes before testing. The test always uses saved defaults.")).toBeVisible();
expect(screen.getByRole("button", { name: "Test saved defaults" })).toBeDisabled();
expect(screen.getByText("Credentials present")).toBeVisible();
});
test("a failed saved-configuration test does not change backend credential presence", async () => {
server.use(
http.get("/api/pi-management/status", () => HttpResponse.json({ ...readyStatus, credentials: "present" })),
http.post("/api/pi-management/test", () => HttpResponse.json({
ready: false,
message: "Pi runtime is unavailable",
checkedAt: "2026-08-05T10:07:00.000Z",
})),
);
const user = userEvent.setup();
renderManagement();
await user.click(await screen.findByRole("button", { name: "Test saved defaults" }));
expect(await screen.findByText("Saved configuration test failed")).toBeVisible();
expect(screen.getByText("Credentials present")).toBeVisible();
expect(screen.queryByText("Credentials missing")).not.toBeInTheDocument();
});