Round five. 47 -> 34 -> 15 -> 7 -> 6 raw findings, and this round's sharpest was the loop's own blind spot: **the branch did not pass the gate.** `prettier --check` is one of its eight lanes and I had been running the other seven, so an unformatted `onError` from round one sat on the branch for four rounds — `siftlode publish` would have refused it, with no --skip flag to get past. **The restart hint could still strand the restored data.** Round four said the scripts no longer print a command they cannot resolve; they did. The COMPOSE_FILE fallback only fires when `docker-compose.yml` is ABSENT, so in a source checkout it never fires and the hint expanded to a bare, pasteable `docker compose up -d` — which reads the other file, whose volumes are `pgdata`/`downloads` rather than `siftlode_pgdata`/`siftlode_downloads`, and recreates the database on an empty one. When the file is unresolved the scripts now print `-f <the compose file you started with>`: not runnable, which is the point. **A comment naming the wrong owner.** `formats.py` still said a zero budget is "a refusal for enqueue to make" — the premise round one disproved, three files away from the two docstrings that now say the opposite. Anyone acting on it would delete the worker's refusal and re-open the original inversion, so it now says where the refusal actually lives. Also: the reset-flag rule was rewritten in three consecutive rounds and pinned by nothing — two tests now cover a fragment losing its token, both by a pasted verify link and by navigating away entirely; `backup.ps1` deletes a partially-copied dump before throwing, the guard round four gave the docs but not the script it mirrors; and one comment that read as if the asset were untouched by a line four below it. Gate green, all eight lanes: ruff, ruff format, 3x tsc, eslint, prettier, knip, vitest 687, pytest 950.
141 lines
5.0 KiB
TypeScript
141 lines
5.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The admin account panel's RECOVERY actions, and specifically that a refusal is visible.
|
|
//
|
|
// All three call `quiet: true` endpoints, which suppress the global error dialog on the promise that
|
|
// the caller reports the failure inline. Without an `onError` that promise is broken and a refusal
|
|
// renders as nothing at all — and on the broken-SMTP instance this panel exists for, an admin reads
|
|
// silence as "the mail went out". These pin that each failure says something, and that the resend
|
|
// distinguishes "this instance has no working mail" from a genuine send failure.
|
|
//
|
|
// i18n is a key-passthrough so assertions read stable keys; the API and the notify singleton are
|
|
// stubbed so the panel can be driven without a server.
|
|
import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
|
|
import { render, screen, cleanup, waitFor, fireEvent } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react-i18next")>();
|
|
return {
|
|
...actual,
|
|
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "en" } }),
|
|
};
|
|
});
|
|
|
|
const notifyMock = vi.fn();
|
|
vi.mock("../lib/notifications", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../lib/notifications")>();
|
|
return { ...actual, notify: (...a: unknown[]) => notifyMock(...a) };
|
|
});
|
|
|
|
const access = {
|
|
email_verified: false,
|
|
email_configured: true,
|
|
is_active: false,
|
|
is_allowed: true,
|
|
can_activate: true,
|
|
has_password: false,
|
|
google_email: null,
|
|
invite_status: null,
|
|
};
|
|
|
|
const apiMock = {
|
|
adminUserAccess: vi.fn(async () => access),
|
|
createSetPasswordLink: vi.fn(),
|
|
resendUserVerification: vi.fn(),
|
|
activateUser: vi.fn(),
|
|
};
|
|
vi.mock("../lib/api", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../lib/api")>();
|
|
return { ...actual, api: apiMock };
|
|
});
|
|
|
|
const { HttpError } = await import("../lib/api");
|
|
const AccountPanel = (await import("./AccountPanel")).default;
|
|
|
|
const user = {
|
|
id: 7,
|
|
email: "stuck@example.com",
|
|
display_name: null,
|
|
role: "user",
|
|
is_demo: false,
|
|
is_active: false,
|
|
is_suspended: false,
|
|
};
|
|
|
|
function mount() {
|
|
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
render(
|
|
<QueryClientProvider client={qc}>
|
|
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
|
<AccountPanel user={user as any} onClose={() => {}} />
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
/** Click the recovery button whose label is `key`, once the readout has loaded. */
|
|
async function clickAction(key: string) {
|
|
mount();
|
|
await screen.findByText("users.account.recovery");
|
|
fireEvent.click(screen.getByText(key));
|
|
}
|
|
|
|
beforeEach(() => {
|
|
notifyMock.mockClear();
|
|
Object.values(apiMock).forEach((m) => m.mockClear());
|
|
apiMock.adminUserAccess.mockResolvedValue(access);
|
|
});
|
|
afterEach(cleanup);
|
|
|
|
const errorMessages = () =>
|
|
notifyMock.mock.calls
|
|
.map(([a]) => a as { level?: string; message?: string })
|
|
.filter((a) => a.level === "error")
|
|
.map((a) => a.message);
|
|
|
|
describe("the account panel reports a refused recovery action", () => {
|
|
it("says the link could not be minted instead of leaving the button inert", async () => {
|
|
apiMock.createSetPasswordLink.mockRejectedValue(new HttpError(404, "gone", null));
|
|
|
|
await clickAction("users.account.setPassword");
|
|
|
|
await waitFor(() => expect(errorMessages()).toContain("users.account.linkFailed"));
|
|
// …and no link block was rendered, so the toast is the only thing that happened.
|
|
expect(screen.queryByText("users.account.copy")).toBeNull();
|
|
});
|
|
|
|
it("names the no-mail case, so a no-SMTP instance does not read as a bug", async () => {
|
|
apiMock.resendUserVerification.mockRejectedValue(
|
|
new HttpError(409, "email off", { code: "resend", reason: "email_off" }),
|
|
);
|
|
|
|
await clickAction("users.account.resend");
|
|
|
|
await waitFor(() => expect(errorMessages()).toContain("users.pendingAccess.resendEmailOff"));
|
|
});
|
|
|
|
it("reports a genuine send failure as a failure, not as a sent mail", async () => {
|
|
apiMock.resendUserVerification.mockRejectedValue(
|
|
new HttpError(422, "send failed", { code: "resend", reason: "send_failed" }),
|
|
);
|
|
|
|
await clickAction("users.account.resend");
|
|
|
|
await waitFor(() => expect(errorMessages()).toContain("users.pendingAccess.resendFailed"));
|
|
// The success toast must NOT also fire — that is the exact lie the backend guards against.
|
|
expect(notifyMock.mock.calls.map(([a]) => (a as { message?: string }).message)).not.toContain(
|
|
"users.account.resendSent",
|
|
);
|
|
});
|
|
|
|
it("reports a refused activation", async () => {
|
|
apiMock.activateUser.mockRejectedValue(
|
|
new HttpError(409, "not allowed", { code: "activate", reason: "not_allowed" }),
|
|
);
|
|
|
|
await clickAction("users.account.activate");
|
|
|
|
await waitFor(() => expect(errorMessages()).toContain("users.pendingAccess.activateFailed"));
|
|
});
|
|
});
|