|
1 | 1 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { legacyConfigRules, normalizeCompatibilityConfig } from "./doctor-contract-api.js"; |
| 4 | +import { inspectEmbeddingProviderSetup } from "./provider-policy-api.js"; |
| 5 | +import { buildLlamaCppProviderConfig } from "./src/defaults.js"; |
4 | 6 |
|
5 | 7 | describe("llama.cpp doctor migration", () => { |
6 | 8 | it("moves the shipped local URL to an absolute managed service", () => { |
@@ -49,4 +51,56 @@ describe("llama.cpp doctor migration", () => { |
49 | 51 | expect(normalizeCompatibilityConfig({ cfg })).toEqual({ config: cfg, changes: [] }); |
50 | 52 | expect(legacyConfigRules[0]?.match?.("http://gpu-box.local:8080/v1")).toBe(false); |
51 | 53 | }); |
| 54 | + |
| 55 | + it("reports the direct-start managed setup blocker with the supported CLI remediation", async () => { |
| 56 | + expect( |
| 57 | + inspectEmbeddingProviderSetup({ |
| 58 | + config: {}, |
| 59 | + env: {}, |
| 60 | + agentId: "main", |
| 61 | + provider: "local", |
| 62 | + }), |
| 63 | + ).toEqual({ |
| 64 | + provider: "local", |
| 65 | + reason: expect.stringContaining("Local embeddings need the managed llama.cpp server config"), |
| 66 | + requirement: "managed-llama-cpp-setup", |
| 67 | + fixHint: |
| 68 | + "Run `openclaw models --agent main auth login --provider llama-cpp --method local` in an interactive terminal, then rerun this check.", |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + it("accepts managed config produced by the models auth CLI without mutating it", async () => { |
| 73 | + const provider = buildLlamaCppProviderConfig(undefined, { |
| 74 | + command: "/managed/llama-server", |
| 75 | + baseUrl: "http://127.0.0.1:19432/v1", |
| 76 | + healthUrl: "http://127.0.0.1:19432/health", |
| 77 | + args: ["--models-preset", "/managed/models.ini"], |
| 78 | + }); |
| 79 | + const config: OpenClawConfig = { |
| 80 | + models: { providers: { "llama-cpp": provider } }, |
| 81 | + }; |
| 82 | + const configBefore = JSON.stringify(config); |
| 83 | + |
| 84 | + expect( |
| 85 | + inspectEmbeddingProviderSetup({ |
| 86 | + config, |
| 87 | + env: {}, |
| 88 | + agentId: "main", |
| 89 | + provider: "local", |
| 90 | + }), |
| 91 | + ).toBeNull(); |
| 92 | + |
| 93 | + expect(JSON.stringify(config)).toBe(configBefore); |
| 94 | + }); |
| 95 | + |
| 96 | + it("does not apply managed llama.cpp setup to a non-local memory provider", async () => { |
| 97 | + expect( |
| 98 | + inspectEmbeddingProviderSetup({ |
| 99 | + config: {}, |
| 100 | + env: {}, |
| 101 | + agentId: "main", |
| 102 | + provider: "openai", |
| 103 | + }), |
| 104 | + ).toBeNull(); |
| 105 | + }); |
52 | 106 | }); |
0 commit comments