Skip to content

Commit 631a9c1

Browse files
committed
feat: Complete the missing changes for E2E Test
1 parent 6823212 commit 631a9c1

10 files changed

Lines changed: 209 additions & 17 deletions

File tree

packages/cli/src/commands/console/call.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
defineCommand,
33
callConsoleGateway,
4+
effectiveConsoleGatewayConfig,
45
resolveConsoleGatewayCredential,
56
CONSOLE_GATEWAY_NO_TOKEN_MESSAGE,
67
BailianError,
@@ -58,7 +59,15 @@ export default defineCommand({
5859
}
5960

6061
if (config.dryRun) {
61-
emitResult({ api, data, token: token ? token.slice(0, 8) + "..." : null }, format);
62+
emitResult(
63+
{
64+
api,
65+
data,
66+
token: token ? token.slice(0, 8) + "..." : null,
67+
...effectiveConsoleGatewayConfig(config),
68+
},
69+
format,
70+
);
6271
return;
6372
}
6473

packages/cli/src/commands/mcp/list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
defineCommand,
33
callConsoleGateway,
4+
effectiveConsoleGatewayConfig,
45
resolveConsoleGatewayCredential,
56
detectOutputFormat,
67
BailianError,
@@ -56,7 +57,7 @@ export default defineCommand({
5657
};
5758

5859
if (config.dryRun) {
59-
emitResult({ api: MCP_LIST_API, data }, format);
60+
emitResult({ api: MCP_LIST_API, data, ...effectiveConsoleGatewayConfig(config) }, format);
6061
return;
6162
}
6263

packages/cli/src/commands/quota/check.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
defineCommand,
33
callConsoleGateway,
4+
effectiveConsoleGatewayConfig,
45
resolveConsoleGatewayCredential,
56
detectOutputFormat,
67
type Config,
@@ -277,6 +278,7 @@ export default defineCommand({
277278
emitResult(
278279
{
279280
apis: [MODEL_LIST_API, MONITOR_API],
281+
...effectiveConsoleGatewayConfig(config),
280282
},
281283
format,
282284
);

packages/cli/tests/e2e/auth.e2e.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe("e2e: auth", () => {
1717
const { stderr, exitCode } = await runCli(["auth", "login", "--help"]);
1818
expect(exitCode, stderr).toBe(0);
1919
expect(stderr).toMatch(/login|api-key/i);
20+
expect(stderr).toMatch(/--console-site/);
2021
});
2122

2223
test("auth logout --help 正常退出", async () => {
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
});

packages/cli/tests/e2e/mcp.e2e.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("e2e: mcp", () => {
8888
});
8989

9090
test("mcp list --dry-run 自定义 --console-region 透传", async () => {
91-
const { stderr, exitCode } = await runCli([
91+
const { stdout, stderr, exitCode } = await runCli([
9292
"mcp",
9393
"list",
9494
"--dry-run",
@@ -99,6 +99,8 @@ describe("e2e: mcp", () => {
9999
"cn-hangzhou",
100100
]);
101101
expect(exitCode, stderr).toBe(0);
102+
const data = parseStdoutJson<{ consoleRegion?: string }>(stdout);
103+
expect(data.consoleRegion).toBe("cn-hangzhou");
102104
});
103105

104106
test("mcp tools <server-code> --dry-run 输出 /api/v1/mcps/<code>/mcp 形态 URL", async () => {

packages/cli/tests/e2e/quota.e2e.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,28 @@ describe.skipIf(!isConsoleE2EReady())("e2e: quota(Console)", () => {
228228
"json",
229229
]);
230230
expect(exitCode, stderr).toBe(0);
231-
const data = parseStdoutJson<{ apis?: string[] }>(stdout);
231+
const data = parseStdoutJson<{ apis?: string[]; consoleRegion?: string }>(stdout);
232232
expect(data.apis).toContain(
233233
"zeldaHttp.dashscopeModel./zelda/api/v1/modelCenter/listFoundationModels",
234234
);
235235
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.monitor.getMonitorData");
236+
expect(data.consoleRegion).toBe("cn-beijing");
237+
});
238+
239+
test("quota check --dry-run --console-region 透传", async () => {
240+
const { stdout, stderr, exitCode } = await runCli([
241+
"quota",
242+
"check",
243+
"--dry-run",
244+
"--non-interactive",
245+
"--output",
246+
"json",
247+
"--console-region",
248+
"cn-hangzhou",
249+
]);
250+
expect(exitCode, stderr).toBe(0);
251+
const data = parseStdoutJson<{ consoleRegion?: string }>(stdout);
252+
expect(data.consoleRegion).toBe("cn-hangzhou");
236253
});
237254

238255
test("quota check 文本输出包含双行表头", async () => {

packages/core/src/console/gateway.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ function resolveGateway(region: string, site: ConsoleSite): ConsoleGatewayInfo {
3535
return REGION_GATEWAYS[region]?.[site] ?? REGION_GATEWAYS["cn-beijing"]![site];
3636
}
3737

38+
/** Resolved console gateway settings (same defaults as {@link callConsoleGateway}). */
39+
export function effectiveConsoleGatewayConfig(config: Config): {
40+
consoleRegion: string;
41+
consoleSite: ConsoleSite;
42+
consoleSwitchAgent?: number;
43+
} {
44+
const consoleRegion = config.consoleRegion ?? "cn-beijing";
45+
const consoleSite = config.consoleSite ?? "domestic";
46+
const consoleSwitchAgent = config.consoleSwitchAgent;
47+
return consoleSwitchAgent != null
48+
? { consoleRegion, consoleSite, consoleSwitchAgent }
49+
: { consoleRegion, consoleSite };
50+
}
51+
3852
export interface ConsoleGatewayRequest {
3953
/** Console API name, e.g. zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota */
4054
api: string;
@@ -85,9 +99,11 @@ export async function callConsoleGateway(
8599
token: string | undefined,
86100
{ api, data }: ConsoleGatewayRequest,
87101
): Promise<unknown> {
88-
const effectiveRegion = config.consoleRegion ?? "cn-beijing";
89-
const effectiveSite = config.consoleSite ?? "domestic";
90-
const effectiveSwitchAgent = config.consoleSwitchAgent;
102+
const {
103+
consoleRegion: effectiveRegion,
104+
consoleSite: effectiveSite,
105+
consoleSwitchAgent: effectiveSwitchAgent,
106+
} = effectiveConsoleGatewayConfig(config);
91107

92108
const resolved = resolveGateway(effectiveRegion, effectiveSite);
93109
const gatewayBase = `https://${resolved.csGateway}`;

packages/core/src/console/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export type { ConsoleGatewayRequest, ConsoleSite } from "./gateway.ts";
2-
export { callConsoleGateway } from "./gateway.ts";
2+
export { callConsoleGateway, effectiveConsoleGatewayConfig } from "./gateway.ts";
33
export type { ModelListParams, ModelListResult } from "./models.ts";
44
export { fetchModelList } from "./models.ts";

packages/core/src/console/models.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ export async function fetchModelList(
2222
token: string,
2323
params: ModelListParams = {},
2424
): Promise<ModelListResult> {
25-
const {
26-
pageNo = 1,
27-
pageSize = 50,
28-
name = "",
29-
providers = [],
30-
capabilities = [],
31-
region,
32-
} = params;
25+
const { pageNo = 1, pageSize = 50, name = "", providers = [], capabilities = [] } = params;
3326

3427
const result = (await callConsoleGateway(config, token, {
3528
api: MODEL_LIST_API,
@@ -46,7 +39,6 @@ export async function fetchModelList(
4639
contextWindows: [],
4740
},
4841
},
49-
region,
5042
})) as any;
5143

5244
const responseData = result?.data?.DataV2?.data ?? result?.data ?? {};

0 commit comments

Comments
 (0)