Skip to content

Commit 508f455

Browse files
test(plugin): cover remaining manifest summary branches
1 parent beba3fd commit 508f455

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

packages/backend/src/routing/resolve.controller.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,32 @@ describe('ResolveController', () => {
256256
]);
257257
expect(mockRoutingService.getEffectiveModel).toHaveBeenCalledTimes(1);
258258
});
259+
260+
it('sorts same-provider entries by auth type and defaults missing auth type to api_key', async () => {
261+
const req = {
262+
ingestionContext: {
263+
userId: 'user-42',
264+
tenantId: 't1',
265+
agentId: 'a1',
266+
agentName: 'test-agent',
267+
},
268+
} as never;
269+
270+
mockRoutingService.getProviders.mockResolvedValue([
271+
{ provider: 'openai', auth_type: 'subscription', is_active: true },
272+
{ provider: 'openai', auth_type: 'api_key', is_active: true },
273+
{ provider: 'mistral', is_active: true },
274+
]);
275+
mockRoutingService.getTiers.mockResolvedValue([]);
276+
277+
const result = await controller.getSummary(req);
278+
279+
expect(result.providers).toEqual([
280+
{ provider: 'mistral', auth_type: 'api_key' },
281+
{ provider: 'openai', auth_type: 'api_key' },
282+
{ provider: 'openai', auth_type: 'subscription' },
283+
]);
284+
});
259285
});
260286

261287
describe('RegisterSubscriptionsDto', () => {

packages/openclaw-plugin/__tests__/command.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,46 @@ describe("registerCommand", () => {
130130
);
131131
});
132132

133+
it("formats empty providers, unknown tiers, and api-key auth headers", async () => {
134+
mockVerify.mockResolvedValueOnce({
135+
endpointReachable: true,
136+
authValid: true,
137+
agentName: null,
138+
error: null,
139+
});
140+
mockFetch.mockResolvedValueOnce({
141+
ok: true,
142+
json: async () => ({
143+
agentName: "custom-agent",
144+
providers: [],
145+
tiers: [
146+
{ tier: "custom", model: null, source: "auto", fallback_models: [] },
147+
],
148+
}),
149+
});
150+
151+
const api = { registerCommand: jest.fn() };
152+
registerCommand(
153+
api,
154+
{ ...config, apiKey: "mnfst_test_key", devMode: false },
155+
mockLogger,
156+
);
157+
158+
const cmd = api.registerCommand.mock.calls[0][0];
159+
const result = await cmd.execute();
160+
161+
expect(result).toContain("Dev mode: no");
162+
expect(result).toContain("Agent: custom-agent");
163+
expect(result).toContain("Providers: none");
164+
expect(result).toContain("custom -> unassigned (auto)");
165+
expect(mockFetch).toHaveBeenCalledWith(
166+
"http://localhost:38238/api/v1/routing/summary",
167+
expect.objectContaining({
168+
headers: { Authorization: "Bearer mnfst_test_key" },
169+
}),
170+
);
171+
});
172+
133173
it("falls back to status output when the routing summary request fails", async () => {
134174
mockVerify.mockResolvedValueOnce({
135175
endpointReachable: true,
@@ -153,6 +193,26 @@ describe("registerCommand", () => {
153193
);
154194
});
155195

196+
it("stringifies non-Error routing summary failures", async () => {
197+
mockVerify.mockResolvedValueOnce({
198+
endpointReachable: true,
199+
authValid: true,
200+
agentName: "test-agent",
201+
error: null,
202+
});
203+
mockFetch.mockRejectedValueOnce("summary-string-error");
204+
205+
const api = { registerCommand: jest.fn() };
206+
registerCommand(api, config, mockLogger);
207+
208+
const cmd = api.registerCommand.mock.calls[0][0];
209+
await cmd.execute();
210+
211+
expect(mockLogger.debug).toHaveBeenCalledWith(
212+
"[manifest] Routing summary failed (summary-string-error)",
213+
);
214+
});
215+
156216
it("includes error in status text when verify reports one", async () => {
157217
mockVerify.mockResolvedValueOnce({
158218
endpointReachable: false,

0 commit comments

Comments
 (0)