docs: document model selection tests · openclaw/openclaw@4653454
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies configured model ref resolution and OpenRouter compatibility aliases. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import type { OpenClawConfig } from "../config/types.js"; |
3 | 4 | import { resolveAllowedModelRef, resolveConfiguredModelRef } from "./model-selection-resolve.js"; |
4 | 5 | |
5 | 6 | describe("model-selection-resolve OpenRouter compat aliases", () => { |
6 | 7 | it("preserves exact configured proxy provider ids for cron-style aliases", () => { |
| 8 | +// Proxy providers can intentionally own short ids like "cron"; keep the |
| 9 | +// configured provider scope instead of treating the id as a global alias. |
7 | 10 | const cfg = { |
8 | 11 | agents: { |
9 | 12 | defaults: { |
@@ -38,6 +41,7 @@ describe("model-selection-resolve OpenRouter compat aliases", () => {
|
38 | 41 | }); |
39 | 42 | |
40 | 43 | it("resolves openrouter:auto through the canonical OpenRouter auto model", () => { |
| 44 | +// Colon syntax is a legacy operator shortcut for OpenRouter's auto route. |
41 | 45 | const cfg = { |
42 | 46 | agents: { |
43 | 47 | defaults: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Covers plugin-owned model id normalization through selection surfaces. |
1 | 2 | import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | |
3 | 4 | const normalizeProviderModelIdWithPluginMock = vi.fn(); |
@@ -114,6 +115,8 @@ describe("model-selection plugin runtime normalization", () => {
|
114 | 115 | }); |
115 | 116 | |
116 | 117 | it("keeps model visibility policy construction off plugin runtime hooks by default", async () => { |
| 118 | +// Visibility policy is a hot/static path. It preserves configured keys |
| 119 | +// unless callers explicitly opt into runtime plugin normalization. |
117 | 120 | normalizeProviderModelIdWithPluginMock.mockImplementation(({ provider, context }) => { |
118 | 121 | if ( |
119 | 122 | provider === "custom-provider" && |
@@ -180,6 +183,8 @@ describe("model-selection plugin runtime normalization", () => {
|
180 | 183 | }); |
181 | 184 | |
182 | 185 | it("keeps plugin-normalized stored overrides allowed in auto-reply runtime selection", async () => { |
| 186 | +// Stored session overrides are runtime inputs, so provider-owned |
| 187 | +// normalization keeps old persisted ids usable without resetting them. |
183 | 188 | normalizeProviderModelIdWithPluginMock.mockImplementation(({ provider, context }) => { |
184 | 189 | if ( |
185 | 190 | provider === "custom-provider" && |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Exercises core model selection, aliases, thinking defaults, and visibility policy. |
1 | 2 | import { describe, it, expect, vi } from "vitest"; |
2 | 3 | import type { OpenClawConfig } from "../config/types.js"; |
3 | 4 | import { resetLogger, setLoggerOverride } from "../logging/logger.js"; |
@@ -175,6 +176,8 @@ const CLAUDE_CLI_OPUS_48_CATALOG = [
|
175 | 176 | ]; |
176 | 177 | |
177 | 178 | function resolveAnthropicOpusThinking(cfg: OpenClawConfig) { |
| 179 | +// Helper keeps thinking-default assertions focused on config differences |
| 180 | +// while using the same catalog metadata shape as production selection. |
178 | 181 | return resolveThinkingDefault({ |
179 | 182 | cfg, |
180 | 183 | provider: "anthropic", |
@@ -224,6 +227,7 @@ function createAgentFallbackConfig(params: {
|
224 | 227 | fallbacks?: string[]; |
225 | 228 | agentFallbacks?: string[]; |
226 | 229 | }) { |
| 230 | +// Compact fixture for primary/fallback allowlist tests. |
227 | 231 | return { |
228 | 232 | agents: { |
229 | 233 | defaults: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Documents model tool-support compatibility defaults. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { supportsModelTools } from "./model-tool-support.js"; |
3 | 4 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies models.json planning applies config env vars and discovery scope. |
1 | 2 | import fs from "node:fs/promises"; |
2 | 3 | import os from "node:os"; |
3 | 4 | import path from "node:path"; |
@@ -36,6 +37,8 @@ function createImplicitOpenRouterProvider(): ProviderConfig {
|
36 | 37 | } |
37 | 38 | |
38 | 39 | function createImplicitOpenAiProvider(overrides: Partial<ProviderConfig> = {}): ProviderConfig { |
| 40 | +// Minimal implicit OpenAI provider used to verify write planning without live |
| 41 | +// discovery or real credentials. |
39 | 42 | return { |
40 | 43 | baseUrl: "https://api.openai.com/v1", |
41 | 44 | api: "openai-responses", |
@@ -76,6 +79,8 @@ async function resolveProvidersForConfigEnvTest(params: {
|
76 | 79 | cfg: OpenClawConfig; |
77 | 80 | onResolveImplicitProviders: (env: NodeJS.ProcessEnv) => void; |
78 | 81 | }) { |
| 82 | +// Config env vars are materialized into the discovery env before implicit |
| 83 | +// provider resolution. |
79 | 84 | const env = createConfigRuntimeEnv(params.cfg); |
80 | 85 | return await resolveProvidersForModelsJsonWithDeps( |
81 | 86 | { |
@@ -121,6 +126,8 @@ let unauthenticatedProviderWritePlan: Awaited<ReturnType<typeof planOpenClawMode
|
121 | 126 | let unauthenticatedProviderParsed: { providers?: Record<string, unknown> }; |
122 | 127 | |
123 | 128 | beforeAll(async () => { |
| 129 | +// Reused no-auth write plan proves generated providers stay serializable |
| 130 | +// even when discovery returns auth-only provider shells. |
124 | 131 | unauthenticatedProviderWritePlan = await planOpenClawModelsJsonWithDeps( |
125 | 132 | { |
126 | 133 | cfg: { models: { providers: {} } }, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies models.json writes and repairs use private file permissions. |
1 | 2 | import fs from "node:fs/promises"; |
2 | 3 | import path from "node:path"; |
3 | 4 | import { afterEach, describe, expect, it } from "vitest"; |
@@ -26,6 +27,7 @@ describe("models-config file mode", () => {
|
26 | 27 | }); |
27 | 28 | |
28 | 29 | it("repairs models.json mode to 0600 on no-content-change paths", async () => { |
| 30 | +// No-op content updates should still harden existing file permissions. |
29 | 31 | if (process.platform === "win32") { |
30 | 32 | return; |
31 | 33 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。