docs: document provider policy tests · openclaw/openclaw@c1b54fe
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Exercises startup provider discovery scoping without loading real plugin manifests. |
1 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { PluginMetadataSnapshotOwnerMaps } from "../plugins/plugin-metadata-snapshot.js"; |
3 | 4 | import type { ProviderPlugin } from "../plugins/types.js"; |
4 | 5 | |
5 | | -// Exercises startup provider discovery scoping without loading real plugin manifests. |
6 | 6 | const mocks = vi.hoisted(() => ({ |
7 | 7 | resolveRuntimePluginDiscoveryProviders: vi.fn(), |
8 | 8 | runProviderCatalog: vi.fn(), |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Covers live-test provider filters before they reach runtime plugin discovery. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import type { PluginMetadataSnapshotOwnerMaps } from "../plugins/plugin-metadata-snapshot.js"; |
3 | 4 | import { |
4 | 5 | resolvePluginMetadataProviderOwnersForTest, |
5 | 6 | resolveProviderDiscoveryFilterForTest, |
6 | 7 | } from "./models-config.providers.implicit.js"; |
7 | 8 | |
8 | | -// Covers live-test provider filters before they reach runtime plugin discovery. |
9 | 9 | function liveFilterEnv(overrides: NodeJS.ProcessEnv): NodeJS.ProcessEnv { |
10 | 10 | // VITEST enables the live-filter parsing path without requiring real live creds. |
11 | 11 | return { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Mirrors the implicit API-key and OAuth MiniMax catalogs that must stay in lockstep. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | |
3 | | -// Mirrors the implicit API-key and OAuth MiniMax catalogs that must stay in lockstep. |
4 | 4 | function buildMinimaxCatalog() { |
5 | 5 | return [ |
6 | 6 | { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Isolates Moonshot implicit-provider auth and streaming compat decisions. |
1 | 2 | import { describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { ModelProviderConfig } from "../config/types.models.js"; |
3 | 4 | import { applyProviderNativeStreamingUsageCompat } from "../plugin-sdk/provider-catalog-shared.js"; |
4 | 5 | import { resolveMissingProviderApiKey } from "./models-config.providers.secret-helpers.js"; |
5 | 6 | |
6 | | -// Isolates Moonshot implicit-provider auth and streaming compat decisions. |
7 | 7 | vi.mock("../plugins/setup-registry.js", () => ({ |
8 | 8 | resolvePluginSetupProvider: () => undefined, |
9 | 9 | })); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Covers provider-key canonicalization plus secret marker persistence safeguards. |
1 | 2 | import fs from "node:fs/promises"; |
2 | 3 | import os from "node:os"; |
3 | 4 | import path from "node:path"; |
@@ -8,7 +9,6 @@ import { normalizeProviders } from "./models-config.providers.normalize.js";
|
8 | 9 | import { resolveApiKeyFromProfiles } from "./models-config.providers.secret-helpers.js"; |
9 | 10 | import { enforceSourceManagedProviderSecrets } from "./models-config.providers.source-managed.js"; |
10 | 11 | |
11 | | -// Covers provider-key canonicalization plus secret marker persistence safeguards. |
12 | 12 | function normalizeLmstudioBaseUrl(baseUrl: string): string { |
13 | 13 | const trimmed = baseUrl.trim().replace(/\/+$/, ""); |
14 | 14 | return trimmed.replace(/\/api\/v1$/, "").replace(/\/v1$/, "") + "/v1"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies implicit provider secret wiring for NVIDIA, MiniMax portal, and vLLM. |
1 | 2 | import { describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { ModelDefinitionConfig, ModelProviderConfig } from "../config/types.models.js"; |
3 | 4 | import { resolveEnvApiKey } from "./model-auth-env.js"; |
@@ -6,7 +7,6 @@ import {
|
6 | 7 | resolveMissingProviderApiKey, |
7 | 8 | } from "./models-config.providers.secret-helpers.js"; |
8 | 9 | |
9 | | -// Verifies implicit provider secret wiring for NVIDIA, MiniMax portal, and vLLM. |
10 | 10 | vi.mock("../plugins/setup-registry.js", () => ({ |
11 | 11 | resolvePluginSetupProvider: () => undefined, |
12 | 12 | })); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies custom providers route to the correct provider-policy plugin key. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { resolveProviderPluginLookupKey } from "./models-config.providers.policy.lookup.js"; |
3 | 4 | |
@@ -51,6 +52,7 @@ describe("resolveProviderPluginLookupKey", () => {
|
51 | 52 | }); |
52 | 53 | |
53 | 54 | it("falls through when runtime provider models is an object map", () => { |
| 55 | +// Runtime object maps are not catalog arrays, so model-level API sniffing must not run. |
54 | 56 | expect( |
55 | 57 | resolveProviderPluginLookupKey("openrouter", { |
56 | 58 | baseUrl: "https://openrouter.ai/api/v1", |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies provider policy hooks without loading real provider plugins. |
1 | 2 | import { describe, expect, it, vi } from "vitest"; |
2 | 3 | |
3 | 4 | vi.mock("../plugins/provider-runtime.js", () => ({ |
@@ -6,6 +7,7 @@ vi.mock("../plugins/provider-runtime.js", () => ({
|
6 | 7 | provider: string; |
7 | 8 | context: { providerConfig?: { baseUrl?: string } }; |
8 | 9 | }) => { |
| 10 | +// Google URL normalization is representative of plugin-owned policy hooks. |
9 | 11 | if (params.provider !== "google") { |
10 | 12 | return undefined; |
11 | 13 | } |
@@ -25,6 +27,7 @@ vi.mock("../plugins/provider-runtime.js", () => ({
|
25 | 27 | provider: string; |
26 | 28 | context: { env: NodeJS.ProcessEnv }; |
27 | 29 | }) => { |
| 30 | +// API key markers can come from provider-specific non-key auth state. |
28 | 31 | if (params.provider === "amazon-bedrock") { |
29 | 32 | return params.context.env.AWS_PROFILE?.trim() ? "AWS_PROFILE" : undefined; |
30 | 33 | } |
@@ -81,6 +84,7 @@ describe("models-config.providers.policy", () => {
|
81 | 84 | }); |
82 | 85 | |
83 | 86 | it("does not treat generic transport APIs as provider plugin ids", () => { |
| 87 | +// Transport ids like openai-completions are not provider-policy namespaces. |
84 | 88 | const provider = { |
85 | 89 | api: "openai-completions" as const, |
86 | 90 | baseUrl: "https://example.invalid/v1", |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Covers Bedrock AWS SDK auth markers and marker-backed discovery secret guardrails. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { NON_ENV_SECRETREF_MARKER } from "./model-auth-markers.js"; |
3 | 4 | import type { ProviderConfig } from "./models-config.providers.secret-helpers.js"; |
@@ -44,7 +45,7 @@ describe("resolveMissingProviderApiKey — aws-sdk auth", () => {
|
44 | 45 | profileApiKey: undefined, |
45 | 46 | }); |
46 | 47 | |
47 | | -// Provider should be returned unchanged — no apiKey field added |
| 48 | +// Provider stays unchanged; instance-role auth must not become a fake apiKey marker. |
48 | 49 | expect(result).toBe(baseProvider); |
49 | 50 | expect(result.apiKey).toBeUndefined(); |
50 | 51 | }); |
@@ -121,7 +122,7 @@ describe("resolveMissingProviderApiKey — aws-sdk auth", () => {
|
121 | 122 | profileApiKey: undefined, |
122 | 123 | }); |
123 | 124 | |
124 | | -// Should return unchanged — already has apiKey |
| 125 | +// Existing apiKey config wins over inferred AWS environment markers. |
125 | 126 | expect(result).toBe(providerWithKey); |
126 | 127 | expect(result.apiKey).toBe("existing-key"); |
127 | 128 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。