Files
OmniRoute/tests/unit/ui/codex-tool-card-wire-api-default.test.tsx
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

132 lines
4.1 KiB
TypeScript

import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
true;
const translate = (key: string) => key;
vi.mock("next-intl", () => ({ useTranslations: () => translate }));
vi.mock("@/shared/components/ProviderIcon", () => ({ default: () => null }));
vi.mock("@/app/(dashboard)/dashboard/cli-code/components/CliStatusBadge", () => ({
default: () => null,
}));
vi.mock("@/shared/components", () => ({
Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Button: ({
children,
onClick,
disabled,
loading,
}: {
children: React.ReactNode;
onClick?: () => void;
disabled?: boolean;
loading?: boolean;
}) => (
<button type="button" onClick={onClick} disabled={disabled || loading}>
{children}
</button>
),
ModelSelectModal: () => null,
ManualConfigModal: () => null,
}));
import CodexToolCard from "@/app/(dashboard)/dashboard/cli-code/components/CodexToolCard";
const mounted: Array<{ container: HTMLDivElement; root: Root }> = [];
const jsonResponse = (body: unknown) => ({
ok: true,
json: async () => body,
});
const waitFor = async (predicate: () => boolean, timeoutMs = 2000) => {
const started = Date.now();
while (!predicate()) {
if (Date.now() - started > timeoutMs) throw new Error("waitFor timed out");
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
}
};
const wireApiSelect = (container: HTMLElement): HTMLSelectElement | null =>
Array.from(container.querySelectorAll("select")).find((select) => {
const values = Array.from(select.options).map((option) => option.value);
return values.length === 2 && values[0] === "chat" && values[1] === "responses";
}) ?? null;
afterEach(() => {
for (const { container, root } of mounted.splice(0)) {
act(() => root.unmount());
container.remove();
}
vi.restoreAllMocks();
});
describe("CodexToolCard wire API default", () => {
it("restores responses after reset returns config without wire_api", async () => {
let statusRequests = 0;
vi.stubGlobal(
"fetch",
vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
const url = String(input);
if (url === "/api/cli-tools/codex-settings" && init?.method === "DELETE") {
return jsonResponse({ success: true });
}
if (url === "/api/cli-tools/codex-settings") {
statusRequests += 1;
return jsonResponse({
installed: true,
runnable: true,
config:
statusRequests === 1
? 'model = "gpt-5.6-sol"\nbase_url = "http://localhost:20128/v1"\nwire_api = "chat"\n'
: 'model = "gpt-5.6-sol"\n',
});
}
if (url === "/api/models/alias") return jsonResponse({ aliases: {} });
if (url === "/api/cli-tools/codex-profiles") return jsonResponse({ profiles: [] });
if (url === "/api/cli-tools/backups?tool=codex") return jsonResponse({ backups: [] });
throw new Error(`Unexpected fetch: ${url}`);
})
);
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
mounted.push({ container, root });
await act(async () => {
root.render(
<CodexToolCard
tool={{ name: "Codex" }}
isExpanded
baseUrl="http://localhost:20128"
apiKeys={[]}
activeProviders={[]}
cloudEnabled={false}
batchStatus={null}
lastConfiguredAt={null}
/>
);
});
await waitFor(() => wireApiSelect(container)?.value === "chat");
const reset = Array.from(container.querySelectorAll("button")).find(
(button) => button.textContent?.trim() === "restorereset"
);
expect(reset).toBeDefined();
await act(async () => {
reset!.click();
});
await waitFor(() => statusRequests === 2);
expect(wireApiSelect(container)?.value).toBe("responses");
});
});