|
| 1 | +import { describe, expect, test } from "vite-plus/test"; |
| 2 | +import { isConsoleE2EReady, isConsoleAuthFailure, parseStdoutJson, runCli } from "./helpers.ts"; |
| 3 | + |
| 4 | +describe("e2e: usage summary", () => { |
| 5 | + test("usage summary --help 正常退出", async () => { |
| 6 | + const { stderr, exitCode } = await runCli(["usage", "summary", "--help"]); |
| 7 | + expect(exitCode, stderr).toBe(0); |
| 8 | + expect(stderr).toMatch(/--days|summary|usage/i); |
| 9 | + }); |
| 10 | + |
| 11 | + test("usage summary --help 包含所有示例", async () => { |
| 12 | + const { stderr, exitCode } = await runCli(["usage", "summary", "--help"]); |
| 13 | + expect(exitCode, stderr).toBe(0); |
| 14 | + expect(stderr).toContain("bl usage summary"); |
| 15 | + expect(stderr).toContain("bl usage summary --days 30"); |
| 16 | + }); |
| 17 | +}); |
| 18 | + |
| 19 | +describe.skipIf(!isConsoleE2EReady())("e2e: usage summary(Console)", () => { |
| 20 | + test("usage summary --dry-run 输出 free-tier 计划请求", async () => { |
| 21 | + const { stdout, stderr, exitCode } = await runCli([ |
| 22 | + "usage", |
| 23 | + "summary", |
| 24 | + "--dry-run", |
| 25 | + "--output", |
| 26 | + "json", |
| 27 | + ]); |
| 28 | + expect(exitCode, stderr).toBe(0); |
| 29 | + const data = parseStdoutJson<{ freeTier?: { api?: string }; usage?: unknown }>(stdout); |
| 30 | + expect(data.freeTier?.api).toContain("queryFreeTierQuota"); |
| 31 | + }); |
| 32 | + |
| 33 | + test("usage summary --dry-run --workspace-id 附带用量概览计划请求", async () => { |
| 34 | + const { stdout, stderr, exitCode } = await runCli([ |
| 35 | + "usage", |
| 36 | + "summary", |
| 37 | + "--dry-run", |
| 38 | + "--workspace-id", |
| 39 | + "ws-e2e-dry-run", |
| 40 | + "--output", |
| 41 | + "json", |
| 42 | + ]); |
| 43 | + expect(exitCode, stderr).toBe(0); |
| 44 | + const data = parseStdoutJson<{ |
| 45 | + usage?: { api?: string; data?: { reqDTO?: { filterWorkspaceId?: string } } }; |
| 46 | + }>(stdout); |
| 47 | + expect(data.usage?.api).toContain("getModelUsageStatistic"); |
| 48 | + expect(data.usage?.data?.reqDTO?.filterWorkspaceId).toBe("ws-e2e-dry-run"); |
| 49 | + }); |
| 50 | + |
| 51 | + test("usage summary 文本输出正常返回", async () => { |
| 52 | + const result = await runCli(["usage", "summary", "--output", "text"]); |
| 53 | + if (isConsoleAuthFailure(result)) return; |
| 54 | + expect(result.exitCode, result.stderr).toBe(0); |
| 55 | + }); |
| 56 | + |
| 57 | + test("usage summary JSON 输出包含 freeTier 字段", async () => { |
| 58 | + const result = await runCli(["usage", "summary", "--output", "json"]); |
| 59 | + if (isConsoleAuthFailure(result)) return; |
| 60 | + expect(result.exitCode, result.stderr).toBe(0); |
| 61 | + const data = parseStdoutJson<{ freeTier?: unknown; period?: unknown }>(result.stdout); |
| 62 | + expect(data.period).toBeTypeOf("object"); |
| 63 | + expect(Array.isArray(data.freeTier)).toBe(true); |
| 64 | + }); |
| 65 | +}); |
0 commit comments