mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-18 20:24:47 +00:00
fix: prefer target entry for models command
This commit is contained in:
@@ -13,12 +13,16 @@ const modelCatalogMocks = vi.hoisted(() => ({
|
||||
loadModelCatalog: vi.fn(),
|
||||
}));
|
||||
|
||||
const modelAuthLabelMocks = vi.hoisted(() => ({
|
||||
resolveModelAuthLabel: vi.fn(() => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/model-catalog.js", () => ({
|
||||
loadModelCatalog: (...args: unknown[]) => modelCatalogMocks.loadModelCatalog(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/model-auth-label.js", () => ({
|
||||
resolveModelAuthLabel: () => undefined,
|
||||
resolveModelAuthLabel: (...args: unknown[]) => modelAuthLabelMocks.resolveModelAuthLabel(...args),
|
||||
}));
|
||||
|
||||
const telegramModelsTestPlugin: ChannelPlugin = {
|
||||
@@ -59,6 +63,8 @@ beforeEach(() => {
|
||||
{ provider: "openai", id: "gpt-4.1-mini", name: "GPT-4.1 Mini" },
|
||||
{ provider: "google", id: "gemini-2.0-flash", name: "Gemini Flash" },
|
||||
]);
|
||||
modelAuthLabelMocks.resolveModelAuthLabel.mockReset();
|
||||
modelAuthLabelMocks.resolveModelAuthLabel.mockReturnValue(undefined);
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
@@ -243,6 +249,37 @@ describe("handleModelsCommand", () => {
|
||||
expect(result?.reply?.text).toContain("localai");
|
||||
});
|
||||
|
||||
it("prefers the target session entry for model auth labeling", async () => {
|
||||
modelAuthLabelMocks.resolveModelAuthLabel.mockReturnValue("target-auth");
|
||||
const params = buildModelsParams("/models anthropic", cfg, "discord", {
|
||||
agentId: "main",
|
||||
sessionKey: "agent:support:main",
|
||||
});
|
||||
params.sessionEntry = {
|
||||
providerOverride: "wrapper-provider",
|
||||
modelOverride: "wrapper-model",
|
||||
} as HandleCommandsParams["sessionEntry"];
|
||||
params.sessionStore = {
|
||||
"agent:support:main": {
|
||||
providerOverride: "target-provider",
|
||||
modelOverride: "target-model",
|
||||
},
|
||||
} as HandleCommandsParams["sessionStore"];
|
||||
|
||||
const result = await handleModelsCommand(params, true);
|
||||
|
||||
expect(result?.shouldContinue).toBe(false);
|
||||
expect(modelAuthLabelMocks.resolveModelAuthLabel).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
sessionEntry: expect.objectContaining({
|
||||
providerOverride: "target-provider",
|
||||
modelOverride: "target-model",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(result?.reply?.text).toContain("target-auth");
|
||||
});
|
||||
|
||||
it("honors model allowlists and config-only providers", async () => {
|
||||
const allowlistedCfg = {
|
||||
commands: { text: true },
|
||||
|
||||
@@ -394,6 +394,7 @@ export const handleModelsCommand: CommandHandler = async (params, allowTextComma
|
||||
})
|
||||
: params.agentId;
|
||||
const modelsAgentDir = modelsAgentId ? resolveAgentDir(params.cfg, modelsAgentId) : undefined;
|
||||
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
|
||||
|
||||
const reply = await resolveModelsCommandReply({
|
||||
cfg: params.cfg,
|
||||
@@ -402,7 +403,7 @@ export const handleModelsCommand: CommandHandler = async (params, allowTextComma
|
||||
currentModel: params.model ? `${params.provider}/${params.model}` : undefined,
|
||||
agentId: modelsAgentId,
|
||||
agentDir: modelsAgentDir,
|
||||
sessionEntry: params.sessionEntry,
|
||||
sessionEntry: targetSessionEntry,
|
||||
});
|
||||
if (!reply) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user