Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
fix(settings): scope the Ollama probe to the selected provider, label the base-URL reset, and stop the model select blanking on a provider switch
Khuram Niazf089392892d6
diff --git a/__tests__/AiSettings.spec.tsx b/__tests__/AiSettings.spec.tsxnew file mode 100644index 0000000..feb8d5c--- /dev/null+++ b/__tests__/AiSettings.spec.tsx@@ -0,0 +1,98 @@+import { render, screen, waitFor, fireEvent } from "@testing-library/react";+import AiSettings from "@/components/settings/AiSettings";++const getUserSettings = vi.fn();++vi.mock("@/actions/userSettings.actions", () => ({+ getUserSettings: () => getUserSettings(),+ updateAiSettings: vi.fn(),+}));++vi.mock("@/components/agent/AgentChatProvider", () => ({+ useAgentChat: () => ({ isOpen: false, refreshPreflight: vi.fn() }),+}));++vi.mock("@/utils/ai.utils", () => ({+ checkOllamaConnection: vi.fn().mockResolvedValue({ isConnected: true }),+}));++vi.mock("@/lib/toast", () => ({ toastSuccess: vi.fn(), toastError: vi.fn() }));++// jsdom implements none of these, and Radix Select calls all four+beforeAll(() => {+ Element.prototype.hasPointerCapture = () => false;+ Element.prototype.setPointerCapture = () => {};+ Element.prototype.releasePointerCapture = () => {};+ Element.prototype.scrollIntoView = () => {};+});++const modelTrigger = () => screen.getByLabelText("Select Model");+const providerTrigger = () => screen.getByLabelText("Select AI provider");++async function pick(trigger: HTMLElement, optionName: string) {+ fireEvent.keyDown(trigger, { key: "Enter" });+ fireEvent.click(await screen.findByRole("option", { name: optionName }));+}++function mockModels(ids: string[]) {+ global.fetch = vi.fn(() =>+ Promise.resolve({+ ok: true,+ json: async () => ({ data: ids.map((id) => ({ id })) }),+ }),+ ) as unknown as typeof fetch;+}++describe("AiSettings model select", () => {+ beforeEach(() => {+ getUserSettings.mockResolvedValue({+ success: true,+ data: {+ userId: "u1",+ settings: { ai: { provider: "ollama", model: "llama3.1" }, display: {} },+ },+ });+ global.fetch = vi.fn(() =>+ Promise.resolve({+ ok: true,+ json: async () => ({ models: [{ name: "llama3.1" }] }),+ }),+ ) as unknown as typeof fetch;+ });++ it("prompts for a model after every provider switch, not just the first", async () => {+ render(<AiSettings />);+ await waitFor(() => expect(modelTrigger().textContent).toBe("llama3.1"));++ mockModels(["deepseek-chat"]);+ await pick(providerTrigger(), "DeepSeek");+ await waitFor(() => expect(modelTrigger().textContent).toBe("Select Model"));++ // Picking a model is what used to leave Radix holding a stale value+ await pick(modelTrigger(), "deepseek-chat");+ await waitFor(() => expect(modelTrigger().textContent).toBe("deepseek-chat"));++ mockModels(["gpt-4o"]);+ await pick(providerTrigger(), "OpenAI");+ await waitFor(() => expect(modelTrigger().textContent).toBe("Select Model"));+ });++ it("shows a spinner while the model list loads", async () => {+ render(<AiSettings />);+ await waitFor(() => expect(modelTrigger().textContent).toBe("llama3.1"));++ let release: (value: unknown) => void = () => {};+ global.fetch = vi.fn(+ () => new Promise((resolve) => { release = resolve; }),+ ) as unknown as typeof fetch;++ await pick(providerTrigger(), "DeepSeek");++ await waitFor(() => expect(modelTrigger()).toBeDisabled());+ expect(modelTrigger().textContent).toContain("Loading models...");+ expect(modelTrigger().querySelector(".animate-spin")).toBeTruthy();++ release({ ok: true, json: async () => ({ data: [{ id: "deepseek-chat" }] }) });+ await waitFor(() => expect(modelTrigger().textContent).toBe("Select Model"));+ });+});diff --git a/__tests__/ApiKeySettings.spec.tsx b/__tests__/ApiKeySettings.spec.tsxnew file mode 100644index 0000000..ffb9df5--- /dev/null+++ b/__tests__/ApiKeySettings.spec.tsx@@ -0,0 +1,96 @@+import { render, screen, waitFor } from "@testing-library/react";+import ApiKeySettings from "@/components/settings/ApiKeySettings";+import { AiProvider } from "@/models/ai.model";++const getUserApiKeys = vi.fn();+const getDefaultOllamaBaseUrl = vi.fn();+const deleteApiKey = vi.fn();+const getUserSettings = vi.fn();+const checkOllamaConnection = vi.fn();++vi.mock("@/actions/apiKey.actions", () => ({+ getUserApiKeys: () => getUserApiKeys(),+ saveApiKey: vi.fn(),+ deleteApiKey: (provider: string) => deleteApiKey(provider),+ getDefaultOllamaBaseUrl: () => getDefaultOllamaBaseUrl(),+}));++vi.mock("@/actions/userSettings.actions", () => ({+ getUserSettings: () => getUserSettings(),+}));++vi.mock("@/utils/ai.utils", () => ({+ checkOllamaConnection: (provider: AiProvider) =>+ checkOllamaConnection(provider),+}));++vi.mock("@/lib/toast", () => ({+ toastSuccess: vi.fn(),+ toastError: vi.fn(),+}));++function settingsFor(provider: AiProvider) {+ return {+ success: true,+ data: { userId: "u1", settings: { ai: { provider }, display: {} } },+ };+}++describe("ApiKeySettings — Ollama connection probe", () => {+ beforeEach(() => {+ getUserApiKeys.mockResolvedValue({ success: true, data: [] });+ getDefaultOllamaBaseUrl.mockResolvedValue("http://127.0.0.1:11434");+ checkOllamaConnection.mockResolvedValue({ isConnected: true });+ });++ it("does not probe Ollama when another provider is selected", async () => {+ getUserSettings.mockResolvedValue(settingsFor(AiProvider.OPENROUTER));++ render(<ApiKeySettings />);++ await waitFor(() => expect(getUserSettings).toHaveBeenCalled());+ expect(checkOllamaConnection).not.toHaveBeenCalled();+ expect(screen.queryByText(/Ollama is (not )?running/)).toBeNull();+ });++ it("probes Ollama when it is the selected provider", async () => {+ getUserSettings.mockResolvedValue(settingsFor(AiProvider.OLLAMA));++ render(<ApiKeySettings />);++ await waitFor(() =>+ expect(screen.getByText("Ollama is running")).toBeInTheDocument(),+ );+ expect(checkOllamaConnection).toHaveBeenCalledWith(AiProvider.OLLAMA);+ });+});++describe("ApiKeySettings — clearing a stored base URL", () => {+ beforeEach(() => {+ getUserApiKeys.mockResolvedValue({+ success: true,+ data: [+ {+ id: "k1",+ provider: "ollama",+ last4: "http://box:11434",+ displayValue: "http://box:11434",+ label: null,+ createdAt: new Date(),+ lastUsedAt: null,+ },+ ],+ });+ getDefaultOllamaBaseUrl.mockResolvedValue("http://127.0.0.1:11434");+ getUserSettings.mockResolvedValue(settingsFor(AiProvider.OPENROUTER));+ checkOllamaConnection.mockResolvedValue({ isConnected: false });+ });++ it("offers a labelled reset that names the server default", async () => {+ render(<ApiKeySettings />);++ await waitFor(() =>+ expect(screen.getByText("Reset to default")).toBeInTheDocument(),+ );+ });+});diff --git a/src/components/settings/AiSettings.tsx b/src/components/settings/AiSettings.tsxindex 283819e..d57b23a 100644--- a/src/components/settings/AiSettings.tsx+++ b/src/components/settings/AiSettings.tsx@@ -198,6 +198,14 @@ function AiSettings() {}};+ // Radix reads an undefined value as uncontrolled and falls back to its own+ // internal state, which still holds the previous provider's pick; a value+ // matching no item renders neither item text nor placeholder.+ const modelValue =+ selectedModel.model && fetchedModels.includes(selectedModel.model)+ ? selectedModel.model+ : "";+if (isLoadingSettings) {return (<div className="space-y-4">@@ -258,7 +266,7 @@ function AiSettings() {</Label><div className="flex flex-wrap items-start gap-2"><Select- value={isLoadingModels ? undefined : selectedModel.model}+ value={isLoadingModels ? "" : modelValue}onValueChange={setSelectedProviderModel}disabled={isLoadingModels}>@@ -267,9 +275,18 @@ function AiSettings() {aria-label="Select Model"className="w-[180px]">+ {/* a flex row here must nest inside SelectValue's span, which the+ trigger's [&>span]:line-clamp-1 outranks */}<SelectValueplaceholder={- isLoadingModels ? "Loading models..." : "Select AI Model"+ isLoadingModels ? (+ <span className="flex items-center gap-2 whitespace-nowrap">+ <Loader2 className="h-3.5 w-3.5 animate-spin" />+ Loading models...+ </span>+ ) : (+ "Select Model"+ )}/></SelectTrigger>diff --git a/src/components/settings/ApiKeySettings.tsx b/src/components/settings/ApiKeySettings.tsxindex e49b205..f09ae93 100644--- a/src/components/settings/ApiKeySettings.tsx+++ b/src/components/settings/ApiKeySettings.tsx@@ -38,6 +38,7 @@ import type {import { getAiProviders } from "@/lib/ai/provider-registry";import { AiProvider } from "@/models/ai.model";import { checkOllamaConnection } from "@/utils/ai.utils";+import { getUserSettings } from "@/actions/userSettings.actions";interface ProviderConfig {id: ApiKeyProvider;@@ -82,7 +83,13 @@ function ApiKeySettings() {useEffect(() => {fetchKeys();getDefaultOllamaBaseUrl().then(setDefaultOllamaUrl);- recheckOllamaConnection();+ // Probing on mount for someone who picked another provider reads as the+ // app overriding their choice, so only auto-check when Ollama is selected.+ getUserSettings().then((result) => {+ if (result?.success && result.data?.settings?.ai?.provider === AiProvider.OLLAMA) {+ recheckOllamaConnection();+ }+ });}, []);const fetchKeys = async () => {@@ -330,15 +337,36 @@ function ApiKeySettings() {) : (<Trash2 className="h-3 w-3" />)}+ {isBaseUrl && (+ <span className="ml-1">Reset to default</span>+ )}</Button></AlertDialogTrigger><AlertDialogContent><AlertDialogHeader>- <AlertDialogTitle>Delete API Key</AlertDialogTitle>+ <AlertDialogTitle>+ {isBaseUrl+ ? `Reset ${provider.name} Base URL`+ : "Delete API Key"}+ </AlertDialogTitle><AlertDialogDescription>- Are you sure you want to delete your{" "}- {provider.name} key? The system will fall back to- the server environment variable if available.+ {isBaseUrl ? (+ <>+ Clear the saved {provider.name} base URL?+ JobSync will use the server default,{" "}+ {provider.id === "ollama"+ ? defaultOllamaUrl+ : provider.placeholder}+ .+ </>+ ) : (+ <>+ Are you sure you want to delete your{" "}+ {provider.name} key? The system will fall back+ to the server environment variable if+ available.+ </>+ )}</AlertDialogDescription></AlertDialogHeader><AlertDialogFooter>@@ -346,7 +374,7 @@ function ApiKeySettings() {<AlertDialogActiononClick={() => handleDelete(provider.id)}>- Delete+ {isBaseUrl ? "Reset" : "Delete"}</AlertDialogAction></AlertDialogFooter></AlertDialogContent>diff --git a/wiki/getting-started.md b/wiki/getting-started.mdindex 5493e0a..3a83e23 100644--- a/wiki/getting-started.md+++ b/wiki/getting-started.md@@ -19,6 +19,8 @@ Open the app and choose **Create Account** on the sign-in page, or go straight tOpen the avatar menu at the bottom of the left sidebar and choose **Settings**, then **AI Provider**. Pick a provider, then a model. JobSync supports Ollama, OpenAI, DeepSeek, Gemini and OpenRouter. Ollama runs models on your own machine and needs no key; the other four are hosted and need an API key, which you add under **Settings → API Keys** in that same menu. Keys are encrypted before they are stored.+If you run Ollama somewhere other than the default address, add that address under **Settings → API Keys** as the Ollama Base URL. Leaving it unset is fine and is the normal case — JobSync then uses the server default shown on that card. If you have saved one and want to go back to the default, use **Reset to default** on the Ollama card. The connection check on that page only runs by itself when Ollama is your selected provider; the refresh button next to it checks on demand whatever you have selected.+Nothing AI-powered works until a provider *and* a model are both set — resume review, job matching, cover letters and the chat panel all refuse to start rather than silently picking a model for you. If you selected Ollama and the model list is empty, JobSync could not reach the Ollama server; check that it is running and reachable from wherever JobSync is running.## How do I add my first job?