






















11import { beforeEach, describe, expect, it, vi } from "vitest";
22import type { AuthHealthSummary } from "../../agents/auth-health.js";
33import type { AuthProfileStore } from "../../agents/auth-profiles.js";
4+import type { UsageSummary } from "../../infra/provider-usage.types.js";
45import { MAX_DATE_TIMESTAMP_MS } from "../../shared/number-coercion.js";
56import type { GatewayRequestHandlerOptions } from "./types.js";
678+const emptyUsageSummary = (): UsageSummary => ({ updatedAt: 0, providers: [] });
9+710const mocks = vi.hoisted(() => ({
811getRuntimeConfig: vi.fn(() => ({})),
912resolveDefaultAgentDir: vi.fn(() => "/tmp/agent"),
@@ -29,7 +32,7 @@ const mocks = vi.hoisted(() => ({
2932buildAuthHealthSummary: vi.fn(
3033(): AuthHealthSummary => ({ now: 0, warnAfterMs: 0, profiles: [], providers: [] }),
3134),
32-loadProviderUsageSummary: vi.fn(async () => ({ updatedAt: 0, providers: [] })),
35+loadProviderUsageSummary: vi.fn(async (): Promise<UsageSummary> => emptyUsageSummary()),
3336}));
34373538vi.mock("../../config/config.js", () => ({
@@ -216,7 +219,7 @@ describe("models.authStatus", () => {
216219profiles: [],
217220providers: [],
218221});
219-mocks.loadProviderUsageSummary.mockResolvedValue({ updatedAt: 0, providers: [] });
222+mocks.loadProviderUsageSummary.mockResolvedValue(emptyUsageSummary());
220223});
221224222225it("returns a serialisable snapshot on first call", async () => {
@@ -303,6 +306,65 @@ describe("models.authStatus", () => {
303306expect(mocks.loadProviderUsageSummary).not.toHaveBeenCalled();
304307});
305308309+it("adds DeepSeek API-key balance summaries to auth status usage", async () => {
310+mocks.buildAuthHealthSummary.mockReturnValue({
311+now: 0,
312+warnAfterMs: 0,
313+profiles: [
314+{
315+profileId: "deepseek:default",
316+provider: "deepseek",
317+type: "api_key",
318+status: "static",
319+source: "store",
320+label: "deepseek:default",
321+},
322+],
323+providers: [
324+{
325+provider: "deepseek",
326+status: "static",
327+profiles: [
328+{
329+profileId: "deepseek:default",
330+provider: "deepseek",
331+type: "api_key",
332+status: "static",
333+source: "store",
334+label: "deepseek:default",
335+},
336+],
337+},
338+],
339+});
340+mocks.loadProviderUsageSummary.mockResolvedValue({
341+updatedAt: 0,
342+providers: [
343+{
344+provider: "deepseek",
345+displayName: "DeepSeek",
346+windows: [],
347+summary: "Balance ¥42.50",
348+},
349+],
350+});
351+352+const opts = createOptions();
353+await handler(opts);
354+355+expect(mocks.loadProviderUsageSummary).toHaveBeenCalledWith({
356+providers: ["deepseek"],
357+agentDir: "/tmp/agent",
358+timeoutMs: 3500,
359+});
360+const [, payload] = firstRespondCall(opts) ?? [];
361+const result = payload as ModelAuthStatusResult;
362+expect(result.providers[0]?.usage).toEqual({
363+windows: [],
364+summary: "Balance ¥42.50",
365+});
366+});
367+306368it("scopes external CLI auth overlays to configured providers", async () => {
307369mocks.getRuntimeConfig.mockReturnValue({
308370auth: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。