|
| 1 | +import { describe, expect, test } from "vite-plus/test"; |
| 2 | +import { parseStdoutJson, runCli } from "./helpers.ts"; |
| 3 | + |
| 4 | +type ConsoleDryRunMeta = { |
| 5 | + consoleRegion?: string; |
| 6 | + consoleSite?: string; |
| 7 | + consoleSwitchAgent?: number; |
| 8 | +}; |
| 9 | + |
| 10 | +/** |
| 11 | + * E2E for global console flags (`--console-region`, `--console-site`, |
| 12 | + * `--console-switch-agent`) vs DashScope `--region`. |
| 13 | + */ |
| 14 | + |
| 15 | +describe("e2e: console global flags", () => { |
| 16 | + test("根帮助展示 --console-region / --console-site / --console-switch-agent", async () => { |
| 17 | + const { stderr, exitCode } = await runCli(["--help"]); |
| 18 | + expect(exitCode, stderr).toBe(0); |
| 19 | + expect(stderr).toMatch(/--console-region/); |
| 20 | + expect(stderr).toMatch(/--console-site/); |
| 21 | + expect(stderr).toMatch(/--console-switch-agent/); |
| 22 | + expect(stderr).toMatch(/--region.*cn.*us.*intl/i); |
| 23 | + }); |
| 24 | + |
| 25 | + test("quota check --help 不重复命令级 region,并提示全局 flags", async () => { |
| 26 | + const { stderr, exitCode } = await runCli(["quota", "check", "--help"]); |
| 27 | + expect(exitCode, stderr).toBe(0); |
| 28 | + expect(stderr).toMatch(/Global flags.*always available/i); |
| 29 | + expect(stderr).toMatch(/--model <model>/); |
| 30 | + expect(stderr).toMatch(/--period <minutes>/); |
| 31 | + expect(stderr).not.toMatch(/API region \(default: cn-beijing\)/); |
| 32 | + }); |
| 33 | + |
| 34 | + test("console call --help 不暴露命令级 region/site,示例使用 --console-region", async () => { |
| 35 | + const { stderr, exitCode } = await runCli(["console", "call", "--help"]); |
| 36 | + expect(exitCode, stderr).toBe(0); |
| 37 | + expect(stderr).toMatch(/--api <api>/); |
| 38 | + expect(stderr).toMatch(/--data <json>/); |
| 39 | + expect(stderr).not.toMatch(/^\s*--region\s/m); |
| 40 | + expect(stderr).not.toMatch(/^\s*--site\s/m); |
| 41 | + expect(stderr).toMatch(/--console-region cn-beijing/); |
| 42 | + }); |
| 43 | + |
| 44 | + test("auth login --help 描述 --console 与 --console-site 配合", async () => { |
| 45 | + const { stderr, exitCode } = await runCli(["auth", "login", "--help"]); |
| 46 | + expect(exitCode, stderr).toBe(0); |
| 47 | + expect(stderr).toMatch(/--console-site/); |
| 48 | + expect(stderr).toMatch(/--console.*console-site|console-site.*domestic|international/i); |
| 49 | + }); |
| 50 | + |
| 51 | + test("console call --dry-run 默认 consoleRegion 为 cn-beijing", async () => { |
| 52 | + const { stdout, stderr, exitCode } = await runCli([ |
| 53 | + "console", |
| 54 | + "call", |
| 55 | + "--api", |
| 56 | + "some.api.name", |
| 57 | + "--data", |
| 58 | + "{}", |
| 59 | + "--dry-run", |
| 60 | + "--non-interactive", |
| 61 | + "--output", |
| 62 | + "json", |
| 63 | + ]); |
| 64 | + expect(exitCode, stderr).toBe(0); |
| 65 | + const data = parseStdoutJson<ConsoleDryRunMeta>(stdout); |
| 66 | + expect(data.consoleRegion).toBe("cn-beijing"); |
| 67 | + expect(data.consoleSite).toBe("domestic"); |
| 68 | + }); |
| 69 | + |
| 70 | + test("console call --dry-run --console-region / --console-site / --console-switch-agent 透传", async () => { |
| 71 | + const { stdout, stderr, exitCode } = await runCli([ |
| 72 | + "console", |
| 73 | + "call", |
| 74 | + "--api", |
| 75 | + "some.api.name", |
| 76 | + "--data", |
| 77 | + "{}", |
| 78 | + "--dry-run", |
| 79 | + "--non-interactive", |
| 80 | + "--output", |
| 81 | + "json", |
| 82 | + "--console-region", |
| 83 | + "ap-southeast-1", |
| 84 | + "--console-site", |
| 85 | + "international", |
| 86 | + "--console-switch-agent", |
| 87 | + "12345", |
| 88 | + ]); |
| 89 | + expect(exitCode, stderr).toBe(0); |
| 90 | + const data = parseStdoutJson<ConsoleDryRunMeta>(stdout); |
| 91 | + expect(data.consoleRegion).toBe("ap-southeast-1"); |
| 92 | + expect(data.consoleSite).toBe("international"); |
| 93 | + expect(data.consoleSwitchAgent).toBe(12345); |
| 94 | + }); |
| 95 | + |
| 96 | + test("console call --dry-run --region cn-beijing 不改变 consoleRegion", async () => { |
| 97 | + const { stdout, stderr, exitCode } = await runCli([ |
| 98 | + "console", |
| 99 | + "call", |
| 100 | + "--api", |
| 101 | + "some.api.name", |
| 102 | + "--data", |
| 103 | + "{}", |
| 104 | + "--dry-run", |
| 105 | + "--non-interactive", |
| 106 | + "--output", |
| 107 | + "json", |
| 108 | + "--region", |
| 109 | + "cn-beijing", |
| 110 | + "--console-region", |
| 111 | + "ap-southeast-1", |
| 112 | + ]); |
| 113 | + expect(exitCode, stderr).toBe(0); |
| 114 | + const data = parseStdoutJson<ConsoleDryRunMeta>(stdout); |
| 115 | + expect(data.consoleRegion).toBe("ap-southeast-1"); |
| 116 | + }); |
| 117 | + |
| 118 | + test("mcp list --dry-run --console-region 透传", async () => { |
| 119 | + const { stdout, stderr, exitCode } = await runCli([ |
| 120 | + "mcp", |
| 121 | + "list", |
| 122 | + "--dry-run", |
| 123 | + "--non-interactive", |
| 124 | + "--output", |
| 125 | + "json", |
| 126 | + "--console-region", |
| 127 | + "cn-hangzhou", |
| 128 | + ]); |
| 129 | + expect(exitCode, stderr).toBe(0); |
| 130 | + const data = parseStdoutJson<ConsoleDryRunMeta>(stdout); |
| 131 | + expect(data.consoleRegion).toBe("cn-hangzhou"); |
| 132 | + }); |
| 133 | + |
| 134 | + test("quota check --dry-run --console-region 透传", async () => { |
| 135 | + const { stdout, stderr, exitCode } = await runCli([ |
| 136 | + "quota", |
| 137 | + "check", |
| 138 | + "--dry-run", |
| 139 | + "--non-interactive", |
| 140 | + "--output", |
| 141 | + "json", |
| 142 | + "--console-region", |
| 143 | + "cn-hangzhou", |
| 144 | + "--console-site", |
| 145 | + "international", |
| 146 | + ]); |
| 147 | + expect(exitCode, stderr).toBe(0); |
| 148 | + const data = parseStdoutJson<ConsoleDryRunMeta>(stdout); |
| 149 | + expect(data.consoleRegion).toBe("cn-hangzhou"); |
| 150 | + expect(data.consoleSite).toBe("international"); |
| 151 | + }); |
| 152 | +}); |
0 commit comments