mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:10:42 +00:00
fix(cli): streamline local model probes
This commit is contained in:
@@ -34,9 +34,25 @@ const mocks = vi.hoisted(() => ({
|
||||
),
|
||||
resolveMemorySearchConfig: vi.fn(() => null),
|
||||
loadModelCatalog: vi.fn(async () => []),
|
||||
agentCommand: vi.fn(async () => ({
|
||||
payloads: [{ text: "local reply" }],
|
||||
meta: { agentMeta: { provider: "openai", model: "gpt-5.4" } },
|
||||
prepareSimpleCompletionModelForAgent: vi.fn(async () => ({
|
||||
selection: {
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
agentDir: "/tmp/agent",
|
||||
},
|
||||
model: {
|
||||
provider: "openai",
|
||||
id: "gpt-5.4",
|
||||
maxTokens: 128,
|
||||
},
|
||||
auth: {
|
||||
apiKey: "sk-test",
|
||||
source: "env:TEST_API_KEY",
|
||||
mode: "api-key",
|
||||
},
|
||||
})),
|
||||
completeWithPreparedSimpleCompletionModel: vi.fn(async () => ({
|
||||
content: [{ type: "text", text: "local reply" }],
|
||||
})),
|
||||
callGateway: vi.fn(async ({ method }: { method: string }) => {
|
||||
if (method === "tts.status") {
|
||||
@@ -131,11 +147,6 @@ vi.mock("../config/config.js", () => ({
|
||||
loadConfig: mocks.loadConfig as typeof import("../config/config.js").loadConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/agent-command.js", () => ({
|
||||
agentCommand:
|
||||
mocks.agentCommand as unknown as typeof import("../agents/agent-command.js").agentCommand,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/agent-scope.js", () => ({
|
||||
resolveDefaultAgentId: () => "main",
|
||||
resolveAgentDir: () => "/tmp/agent",
|
||||
@@ -146,6 +157,13 @@ vi.mock("../agents/model-catalog.js", () => ({
|
||||
mocks.loadModelCatalog as typeof import("../agents/model-catalog.js").loadModelCatalog,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/simple-completion-runtime.js", () => ({
|
||||
prepareSimpleCompletionModelForAgent:
|
||||
mocks.prepareSimpleCompletionModelForAgent as unknown as typeof import("../agents/simple-completion-runtime.js").prepareSimpleCompletionModelForAgent,
|
||||
completeWithPreparedSimpleCompletionModel:
|
||||
mocks.completeWithPreparedSimpleCompletionModel as unknown as typeof import("../agents/simple-completion-runtime.js").completeWithPreparedSimpleCompletionModel,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/auth-profiles.js", () => ({
|
||||
loadAuthProfileStoreForRuntime:
|
||||
mocks.loadAuthProfileStoreForRuntime as unknown as typeof import("../agents/auth-profiles.js").loadAuthProfileStoreForRuntime,
|
||||
@@ -291,7 +309,8 @@ describe("capability cli", () => {
|
||||
return store;
|
||||
});
|
||||
mocks.resolveMemorySearchConfig.mockReset().mockReturnValue(null);
|
||||
mocks.agentCommand.mockClear();
|
||||
mocks.prepareSimpleCompletionModelForAgent.mockClear();
|
||||
mocks.completeWithPreparedSimpleCompletionModel.mockClear();
|
||||
mocks.callGateway.mockClear().mockImplementation((async ({ method }: { method: string }) => {
|
||||
if (method === "tts.status") {
|
||||
return { enabled: true, provider: "openai" };
|
||||
@@ -362,7 +381,8 @@ describe("capability cli", () => {
|
||||
argv: ["capability", "model", "run", "--prompt", "hello", "--json"],
|
||||
});
|
||||
|
||||
expect(mocks.agentCommand).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.prepareSimpleCompletionModelForAgent).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.completeWithPreparedSimpleCompletionModel).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.callGateway).not.toHaveBeenCalled();
|
||||
expect(mocks.runtime.writeJson).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -372,20 +392,30 @@ describe("capability cli", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("runs local model probes without chat-agent prompt policy or tools", async () => {
|
||||
it("runs local model probes through the lean completion path", async () => {
|
||||
await runRegisteredCli({
|
||||
register: registerCapabilityCli as (program: Command) => void,
|
||||
argv: ["capability", "model", "run", "--prompt", "hello", "--json"],
|
||||
});
|
||||
|
||||
expect(mocks.agentCommand).toHaveBeenCalledWith(
|
||||
expect(mocks.prepareSimpleCompletionModelForAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
cleanupBundleMcpOnRunEnd: true,
|
||||
modelRun: true,
|
||||
promptMode: "none",
|
||||
agentId: "main",
|
||||
allowMissingApiKeyModes: ["aws-sdk"],
|
||||
skipPiDiscovery: true,
|
||||
}),
|
||||
);
|
||||
expect(mocks.completeWithPreparedSimpleCompletionModel).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
context: {
|
||||
messages: [
|
||||
expect.objectContaining({
|
||||
role: "user",
|
||||
content: "hello",
|
||||
}),
|
||||
],
|
||||
},
|
||||
}),
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user