Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ui/litellm-dashboard/tests/mocks/autoRouterPresets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { readFileSync } from "fs";
import { resolve } from "path";
import { vi } from "vitest";
import bundledPresets from "../../../../litellm/proxy/public_endpoints/autorouter_presets.json";
import { hydratePresets, type AutoRouterPresetsResponse } from "@/lib/autorouter_presets";

// Derived from the real bundled catalog so a preset edit there flows into test expectations
// instead of redding on a stale copy. Exported as vi.fn so a test can override the query state.
export const BUNDLED_PRESETS = hydratePresets(bundledPresets as AutoRouterPresetsResponse);
const CATALOG_PATH = resolve(__dirname, "../../../../litellm/proxy/public_endpoints/autorouter_presets.json");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: hmm I never really liked this drilling. Maybe it could be absolute...?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it's not pretty, but I'd keep it: anchor-on-own-file-and-walk-up is the existing pattern on both sides of the repo, and there is no "absolute" alternative here that isn't machine-specific.

  • TS: scripts/gen-api-types.mjs computes dashboardDir and repoRoot by walking up from import.meta.url with .. hops; vitest.config.ts anchors its alias with resolve(__dirname, "src").
  • Python: 37 tests use Path(__file__).resolve().parents[2], 18 more use Path(__file__).parents[2] / "model_prices_and_context_window.json", and a handful go parents[3..5]. No shared repo-root helper exists.
  • process.cwd() was the previous version of this line; Greptile flagged it (vitest from the repo root fails at import time), which is why fcc9b81 moved to __dirname.

The only dot-free option is a repo-root constant defined in vitest.config.ts plus a global .d.ts so next build still type-checks. Happy to add that once a second test needs a repo-root path, but for one consumer it's more machinery than the line it replaces.


export const BUNDLED_PRESETS = hydratePresets(
JSON.parse(readFileSync(CATALOG_PATH, "utf8")) as AutoRouterPresetsResponse,
);

export const LOADED_PRESETS_QUERY = {
data: BUNDLED_PRESETS,
Expand Down
Loading