Backtestslitellmrun-20261111-220245#48196
[Bug]: Bulk Invite Users – "Download CSV Template" button has no onClick handler (still unfixed, #27197 closed as stale).
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches wire the same onClick fix with an identical header row (user_email,user_role,teams,max_budget,budget_duration,models), so correctness of the core issue is equal. The differences are in the example data and tests. Patch A's example row populates teams with placeholder IDs (team-id-1,team-id-2) that the upload's team validation would reject, so a user who downloads the template and uploads it unmodified would see validation errors; Patch B deliberately leaves teams blank and documents why, and its example rows use only valid roles and a numeric budget, matching the issue's note on valid roles. Patch B's tests are stronger: besides checking the blob, filename and header, they round-trip the generated CSV back through the component's upload step and assert both rows appear with no 'Invalid' marker, which is the behaviour the issue actually asks for; a separate unit test validates the template builder's structure and role validity. Patch A's test is reasonable but lacks try/finally cleanup and uses toHaveBeenCalledOnce on a prototype spy that B's comment indicates is already a shared mock in setupTests, making A's count assertion potentially leak state from earlier tests. Patch A earns some craft credit for reusing the existing downloadBlob utility rather than duplicating anchor-download logic, and B's extra module is a slight scope increase, but neither offsets B's more correct example data and more meaningful test coverage. Independent tests were skipped on all trees and provide no signal.
Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.
Solve
4m 58s
Wall-clock time in the container
Full test suite
Not run
The harness did not reach the test stage
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
113vs 42 merged
Changed lines, ours vs merged
The issue
View on GitHubDescription
Check for existing issues
- I have searched the existing issues and checked that my issue is not a duplicate. (Related: #27197 was auto-closed by the stale bot on 2026-08-12 without a fix; the fix PRs #27297 and #27402 were closed without being merged.)
What happened?
In the Admin UI under Users → Bulk Invite, the "Download CSV Template" button
does nothing when clicked. No file is downloaded and there is no error.
On main, ui/litellm-dashboard/src/components/bulk_create_users_button.tsx renders:
<Button size="lg" className="w-full md:w-auto">
<Download className="size-4" />
Download CSV Template
</Button>
There is no onClick handler.
Expected behavior
Clicking the button downloads a CSV template with the columns the upload
validation expects: user_email, user_role, and optionally max_budget, teams.
Additional context
- Previous report: #27197 (closed as stale, not fixed)
- Previous fix attempts: #27297, #27402 (closed, not merged)
- Valid roles per the validation code: proxy_admin, proxy_admin_viewer, internal_user, internal_user_viewer
Config
- since this is not relevant for the bug i won't post any config file -
LiteLLM Version
v1.106.3
Steps to Repro
- Open the Admin UI → Users → Bulk Invite
- Click "Download CSV Template"
- Nothing happens
Which part of LiteLLM is this about?
Admin UI
How are you deploying?
Docker
The two patches
ui/litellm-dashboard/src/components/bulk_create_users_button.test.tsxindex e1faf8be1d..4d045048b7 100644@@ -48,6 +48,50 @@ describe("BulkCreateUsersButton", () => { expect(await screen.findByText("new.hire@example.com")).toBeInTheDocument(); }); + it("downloads a CSV template that the upload step accepts when Download CSV Template is clicked", async () => {+ const createObjectURL = vi.fn((_blob: Blob) => "blob:template");+ const revokeObjectURL = vi.fn();+ const { createObjectURL: originalCreate, revokeObjectURL: originalRevoke } = URL;+ URL.createObjectURL = createObjectURL;+ URL.revokeObjectURL = revokeObjectURL;+ const anchorClick = vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {});+ // setupTests already replaces anchor click with a shared mock; drop calls from earlier tests.+ anchorClick.mockClear();++ try {+ const user = await openUploadStep();+ await user.click(screen.getByRole("button", { name: /download csv template/i }));++ expect(createObjectURL).toHaveBeenCalledTimes(1);+ expect(anchorClick).toHaveBeenCalledTimes(1);+ const anchor = anchorClick.mock.contexts[0] as HTMLAnchorElement;+ expect(anchor.download).toBe("bulk_users_template.csv");+ expect(anchor.href).toBe("blob:template");+ expect(revokeObjectURL).toHaveBeenCalledWith("blob:template");++ const blob = createObjectURL.mock.calls[0][0];+ expect(blob.type).toBe("text/csv");+ const csv = await new Promise<string>((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = () => resolve(reader.result as string);+ reader.onerror = () => reject(reader.error);+ reader.readAsText(blob);+ });+ expect(csv.split(/\r?\n/)[0]).toBe("user_email,user_role,teams,max_budget,budget_duration,models");++ const fileInput = screen.getByLabelText(/drag and drop your csv file here/i);+ fireEvent.change(fileInput, { target: { files: [new File([csv], "template.csv", { type: "text/csv" })] } });++ expect(await screen.findByText("john.doe@example.com")).toBeInTheDocument();+ expect(screen.getByText("jane.smith@example.com")).toBeInTheDocument();+ expect(screen.queryByText("Invalid")).not.toBeInTheDocument();+ } finally {+ anchorClick.mockRestore();+ URL.createObjectURL = originalCreate;+ URL.revokeObjectURL = originalRevoke;+ }+ });+ it("exposes the drop zone as a label for a keyboard-reachable file input", async () => { await openUploadStep(); ui/litellm-dashboard/src/components/bulk_create_users_button.tsxindex 8b823ca2f7..df73047ba1 100644@@ -16,6 +16,7 @@ import Papa from "papaparse"; import { CheckCircleIcon, XCircleIcon, ExclamationIcon } from "@heroicons/react/outline"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { toast } from "@/lib/toast";+import { downloadBulkCreateUsersTemplate } from "./bulk_create_users_template"; interface BulkCreateUsersProps { accessToken: string;@@ -609,7 +610,7 @@ const BulkCreateUsersButton: React.FC<BulkCreateUsersProps> = ({ </div> </div> - <Button size="lg" className="w-full md:w-auto">+ <Button size="lg" className="w-full md:w-auto" onClick={downloadBulkCreateUsersTemplate}> <Download className="size-4" /> Download CSV Template </Button>ui/litellm-dashboard/src/components/bulk_create_users_template.test.tsnew file mode 100644index 0000000000..40c208f62b@@ -0,0 +1,30 @@+import Papa from "papaparse";+import { describe, it, expect } from "vitest";+import { BULK_CREATE_USERS_TEMPLATE_COLUMNS, buildBulkCreateUsersTemplateCsv } from "./bulk_create_users_template";++const VALID_ROLES = ["proxy_admin", "proxy_admin_viewer", "internal_user", "internal_user_viewer"];++describe("buildBulkCreateUsersTemplateCsv", () => {+ const parsed = Papa.parse<string[]>(buildBulkCreateUsersTemplateCsv(), { skipEmptyLines: true });+ const [header, ...rows] = parsed.data;++ it("starts with the required columns followed by the optional ones", () => {+ expect(parsed.errors).toEqual([]);+ expect(header).toEqual(["user_email", "user_role", "teams", "max_budget", "budget_duration", "models"]);+ expect(header).toEqual([...BULK_CREATE_USERS_TEMPLATE_COLUMNS]);+ });++ it("includes example rows with one cell per column and a valid email and role", () => {+ expect(rows.length).toBeGreaterThan(0);+ for (const row of rows) {+ expect(row).toHaveLength(header.length);+ expect(row[0]).toMatch(/^[^@\s]+@[^@\s]+\.[^@\s]+$/);+ expect(VALID_ROLES).toContain(row[1]);+ }+ });++ it("quotes comma-separated model lists so they stay in a single cell", () => {+ const modelsIndex = header.indexOf("models");+ expect(rows.map((row) => row[modelsIndex])).toContain("gpt-3.5-turbo,gpt-4");+ });+});ui/litellm-dashboard/src/components/bulk_create_users_template.tsnew file mode 100644index 0000000000..f2658810ec@@ -0,0 +1,36 @@+import Papa from "papaparse";++const BULK_CREATE_USERS_TEMPLATE_FILENAME = "bulk_users_template.csv";++// Column order matches the "Template Column Names" list shown in the Bulk Invite dialog.+// user_email and user_role are required by the upload validation; the rest are optional.+export const BULK_CREATE_USERS_TEMPLATE_COLUMNS = [+ "user_email",+ "user_role",+ "teams",+ "max_budget",+ "budget_duration",+ "models",+] as const;++// Example rows pass the upload validation as-is. teams is left blank because team IDs are+// checked against the proxy's existing teams and any placeholder would be rejected.+const EXAMPLE_ROWS: string[][] = [+ ["john.doe@example.com", "internal_user", "", "100", "30d", "gpt-3.5-turbo,gpt-4"],+ ["jane.smith@example.com", "proxy_admin_viewer", "", "", "", ""],+];++export const buildBulkCreateUsersTemplateCsv = (): string =>+ Papa.unparse({ fields: [...BULK_CREATE_USERS_TEMPLATE_COLUMNS], data: EXAMPLE_ROWS });++export const downloadBulkCreateUsersTemplate = (): void => {+ const blob = new Blob([buildBulkCreateUsersTemplateCsv()], { type: "text/csv" });+ const url = window.URL.createObjectURL(blob);+ const a = document.createElement("a");+ a.href = url;+ a.download = BULK_CREATE_USERS_TEMPLATE_FILENAME;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ window.URL.revokeObjectURL(url);+};
ui/litellm-dashboard/src/components/bulk_create_users_button.test.tsxindex e1faf8be1df..51d7521c909 100644@@ -30,6 +30,36 @@ describe("BulkCreateUsersButton", () => { expect(screen.getByText("+ Bulk Invite Users")).toBeInTheDocument(); }); + it("downloads a CSV template with the columns the upload accepts", async () => {+ const createObjectURL = vi.fn((_blob: Blob) => "blob:template");+ const revokeObjectURL = vi.fn();+ const { createObjectURL: originalCreate, revokeObjectURL: originalRevoke } = URL;+ URL.createObjectURL = createObjectURL;+ URL.revokeObjectURL = revokeObjectURL;+ const anchorClick = vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {});++ const user = await openUploadStep();+ await user.click(screen.getByRole("button", { name: /download csv template/i }));++ expect(anchorClick).toHaveBeenCalledOnce();+ const anchor = anchorClick.mock.contexts[0] as HTMLAnchorElement;+ expect(anchor.download).toBe("bulk_users_template.csv");+ expect(anchor.href).toBe("blob:template");++ const csv = await new Promise<string>((resolve) => {+ const reader = new FileReader();+ reader.onload = () => resolve(reader.result as string);+ reader.readAsText(createObjectURL.mock.calls[0][0]);+ });+ const [headerRow] = csv.split(/\r?\n/);+ expect(headerRow).toBe("user_email,user_role,teams,max_budget,budget_duration,models");+ expect(revokeObjectURL).toHaveBeenCalledWith("blob:template");++ anchorClick.mockRestore();+ URL.createObjectURL = originalCreate;+ URL.revokeObjectURL = originalRevoke;+ });+ it("parses a CSV chosen through the file input", async () => { await openUploadStep(); ui/litellm-dashboard/src/components/bulk_create_users_button.tsxindex 8b823ca2f73..840cc1af00e 100644@@ -16,6 +16,7 @@ import Papa from "papaparse"; import { CheckCircleIcon, XCircleIcon, ExclamationIcon } from "@heroicons/react/outline"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { toast } from "@/lib/toast";+import { downloadBlob } from "@/components/EntityUsageExport/utils"; interface BulkCreateUsersProps { accessToken: string;@@ -87,6 +88,15 @@ const BulkCreateUsersButton: React.FC<BulkCreateUsersProps> = ({ setBaseUrl(base.toString()); }, [accessToken]); + const downloadTemplate = () => {+ const template = [+ ["user_email", "user_role", "teams", "max_budget", "budget_duration", "models"],+ ["user@example.com", "internal_user", "team-id-1,team-id-2", "100", "30d", "gpt-3.5-turbo,gpt-4"],+ ];++ downloadBlob(new Blob([Papa.unparse(template)], { type: "text/csv" }), "bulk_users_template.csv");+ };+ const handleFileUpload = (file: File) => { // Reset all error states setParseError(null);@@ -609,7 +619,7 @@ const BulkCreateUsersButton: React.FC<BulkCreateUsersProps> = ({ </div> </div> - <Button size="lg" className="w-full md:w-auto">+ <Button size="lg" className="w-full md:w-auto" onClick={downloadTemplate}> <Download className="size-4" /> Download CSV Template </Button>