test(llama-cpp): keep lifecycle helpers private

This commit is contained in:
Vincent Koc
2026-08-04 21:27:41 +08:00
parent 747c4e7a72
commit b8eebb07e4
2 changed files with 15 additions and 17 deletions
@@ -54,16 +54,15 @@ vi.mock("node-llama-cpp", () => ({
},
}));
import {
createLlamaCppInferenceRuntime,
llamaCppInferenceTestApi,
type LlamaCppInferenceRuntime,
} from "./inference-provider.js";
import { createLlamaCppInferenceRuntime } from "./inference-provider.js";
if (!llamaCppInferenceTestApi) {
throw new Error("expected llama.cpp inference test API");
}
const { mapContextToLlamaChatHistory, mapToolsToLlamaFunctions } = llamaCppInferenceTestApi;
const { mapContextToLlamaChatHistory, mapToolsToLlamaFunctions } = (
globalThis as Record<PropertyKey, unknown>
)[Symbol.for("openclaw.llamaCppInferenceTestApi")] as {
mapContextToLlamaChatHistory: (context: Context) => unknown[];
mapToolsToLlamaFunctions: (context: Context) => Record<string, unknown> | undefined;
};
type LlamaCppInferenceRuntime = ReturnType<typeof createLlamaCppInferenceRuntime>;
let inferenceRuntime: LlamaCppInferenceRuntime;
const model: Model = {
@@ -49,7 +49,7 @@ type LlamaCppInferenceRuntimeState = {
disposePromise?: Promise<void>;
};
export type LlamaCppInferenceRuntime = {
type LlamaCppInferenceRuntime = {
createStreamFn: (params: { providerConfig?: ModelProviderConfig }) => StreamFn;
dispose: () => Promise<void>;
};
@@ -681,10 +681,9 @@ export function createLlamaCppInferenceRuntime(): LlamaCppInferenceRuntime {
};
}
export const llamaCppInferenceTestApi =
process.env.VITEST || process.env.NODE_ENV === "test"
? {
mapContextToLlamaChatHistory,
mapToolsToLlamaFunctions,
}
: undefined;
if (process.env.VITEST || process.env.NODE_ENV === "test") {
(globalThis as Record<PropertyKey, unknown>)[Symbol.for("openclaw.llamaCppInferenceTestApi")] = {
mapContextToLlamaChatHistory,
mapToolsToLlamaFunctions,
};
}