Files
grok-cli/src/grok/models.test.ts
T
75efd707f7 fix: only send reasoningEffort for grok-3-mini (#200)
* fix: only send reasoningEffort for grok-3-mini

According to xAI documentation, only grok-3-mini supports the
reasoning_effort parameter. Other models (grok-3, grok-4, grok-4-fast-reasoning)
do not support this parameter and return a 'Bad request' error when it is sent.

Changes:
- Added supportsReasoningEffort field to ModelInfo interface
- Marked only grok-3-mini with supportsReasoningEffort: true
- Updated getSupportedReasoningEfforts() to check supportsReasoningEffort
  instead of the generic reasoning flag
- This prevents sending reasoningEffort to unsupported models

Fixes the 410 error when using models like grok-code-fast-1 with
reasoning effort configured.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

* test: update tests to reflect grok-3-mini-only reasoning effort support

Updated model tests to verify that only grok-3-mini supports
reasoningEffort parameter, and all other models (including reasoning
models like grok-4-0709, grok-code-fast-1) correctly return empty
supported efforts arrays.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

* test: add integration tests for resolveModelRuntime

Verify that providerOptions.xai.reasoningEffort is only included
for models that support it (currently only grok-3-mini), and is
correctly omitted for all other models regardless of their
reasoning flag.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

* fix: organize imports in client.test.ts for Biome linter

Biome requires imports to be sorted alphabetically. Moved @ai-sdk/xai
import before vitest import to satisfy the linter.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

* fix: add comprehensive tests for reasoningEffort with grok-3-mini

- Fixed misleading test name that said 'includes' but asserted undefined
- Added new test suite 'with configured reasoning effort' that mocks
  getReasoningEffortForModel to verify positive cases
- Tests now verify that grok-3-mini DOES receive providerOptions when
  reasoning effort is configured (high or low)
- Tests verify that other models (grok-4-0709, grok-code-fast-1, etc.)
  do NOT receive providerOptions even when effort is configured
- Increased test coverage from 90 to 100 tests

Addresses review feedback about missing positive test case.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

* refactor: remove dead code branches in getSupportedReasoningEfforts

Removed unreachable multiAgent and responsesOnly branches since only
grok-3-mini currently has supportsReasoningEffort: true, and it has
neither of those flags.

Added comment explaining that only grok-3-mini supports reasoning_effort
per xAI documentation, and it supports 'low' and 'high' efforts.

If xAI adds reasoning_effort support to other models in the future,
the logic can be expanded as needed.

Addresses review feedback about dead code.

Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ismail Pelaseyed <homanp@users.noreply.github.com>
2026-03-23 14:00:49 +01:00

48 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
DEFAULT_MODEL,
getEffectiveReasoningEffort,
getModelInfo,
getSupportedReasoningEfforts,
normalizeModelId,
} from "./models";
describe("models", () => {
it("keeps the default model on a canonical reasoning id", () => {
expect(DEFAULT_MODEL).toBe("grok-4-1-fast-reasoning");
});
it("normalizes current aliases to canonical ids", () => {
expect(normalizeModelId("grok-4-1-fast")).toBe("grok-4-1-fast-reasoning");
expect(normalizeModelId("grok-4.20-multi-agent")).toBe("grok-4.20-multi-agent-0309");
expect(normalizeModelId("x-ai/grok-4.20-multi-agent-beta")).toBe("grok-4.20-multi-agent-0309");
expect(normalizeModelId("xai/grok-code-fast-1")).toBe("grok-code-fast-1");
});
it("returns model metadata for aliased ids", () => {
expect(getModelInfo("grok-4-1-fast")?.id).toBe("grok-4-1-fast-reasoning");
expect(getModelInfo("grok-4.20-multi-agent")?.responsesOnly).toBe(true);
expect(getModelInfo("grok-4.20-multi-agent")?.supportsClientTools).toBe(false);
});
it("reports supported reasoning-effort levels", () => {
expect(getSupportedReasoningEfforts("grok-3-mini")).toEqual(["low", "high"]);
expect(getSupportedReasoningEfforts("grok-4.20-multi-agent-0309")).toEqual([]);
expect(getSupportedReasoningEfforts("grok-4-1-fast-reasoning")).toEqual([]);
expect(getSupportedReasoningEfforts("grok-4-1-fast-non-reasoning")).toEqual([]);
expect(getSupportedReasoningEfforts("grok-code-fast-1")).toEqual([]);
expect(getSupportedReasoningEfforts("grok-4-0709")).toEqual([]);
expect(getSupportedReasoningEfforts("grok-3")).toEqual([]);
});
it("resolves effective reasoning effort with defaults and overrides", () => {
expect(getEffectiveReasoningEffort("grok-3-mini")).toBeUndefined();
expect(getEffectiveReasoningEffort("grok-3-mini", "high")).toBe("high");
expect(getEffectiveReasoningEffort("grok-3-mini", "low")).toBe("low");
expect(getEffectiveReasoningEffort("grok-4.20-multi-agent-0309")).toBeUndefined();
expect(getEffectiveReasoningEffort("grok-4.20-multi-agent-0309", "high")).toBeUndefined();
expect(getEffectiveReasoningEffort("grok-4-1-fast-reasoning")).toBeUndefined();
expect(getEffectiveReasoningEffort("grok-code-fast-1", "high")).toBeUndefined();
});
});