GeezerVison is showing github.com — fix(auth): preserve site/config in open-api paste command and report … · modelstudioai/cli@a222f9f
File treeExpand file treeCollapse file tree Open diff view settings skills/bailian-cli/reference
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/agents/auth-change.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,8 +40,8 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx | 40 | 40 | - `bl auth login --api-key ...` 先通过只读 `GET /models` 校验 Key,校验成功后才原子写入 `api_key` 与实际匹配的 `base_url`。公共 DashScope 站点使用 `/api/v1/models?page_no=1&page_size=1`,`*.maas.aliyuncs.com`(Workspace 与 Token Plan)使用 `/compatible-mode/v1/models`。显式 `--base-url` 只校验该站点,不自动改写;未显式指定时,普通 `sk-*` / `sk-ws-*` 按“当前 Profile 已保存的同类站点 → 基于 `workspace_id` 构造的各地域 Workspace 专属站点 → 公共地域”顺序选择首个成功结果,`sk-sp-*` 并行探测国内站与新加坡 Token Plan,其他格式同时尝试两类候选。所有候选失败时选择最有诊断价值的原始错误透传:无 HTTP status 的网络、超时或响应解析错误优先,其次为 HTTP 429/5xx,最后为其他 HTTP 错误;同级保持候选顺序。HTTP status、API code、request ID 与服务端 message 保持不变,不重新分类为 `AUTH`。任一失败都不落盘、不激活 Profile | 41 | 41 | - 未显式传 `--config` 时,`sk-sp-*` 自动写入并激活 `token-plan`;普通 `sk-*` / `sk-ws-*` 仅在当前为 `token-plan` 时改写并激活 `default`,否则保留当前 Profile;其他格式不自动切换。显式 `--config` 始终优先。`sk-sp-*` 无论写入哪个 Profile 都会携带 Token Plan 的预设默认模型,并在保留已有项的基础上补齐 `api_key_capabilities`,不自动删除任何已有能力。登录仍不得删除其他鉴权域的凭证 | 42 | 42 | - `bl auth login --console` 更新 `access_token` 以及回调携带的 console 作用域字段;若所选 Profile 没有模型 API Key,会要求控制台页面创建并回传一个普通 API Key 与 Base URL 一并保存。该回调结果不重复执行 `/models` 校验,且不会创建或配置 Token Plan | 43 | | -- `bl auth login --open-api` **不带** AK/SK:打开控制台 `/aksk-guide` 浏览器引导(非阻塞,不启本地 callback;SecretKey 不会经页面回传)。支持 `--no-browser` 只打印 URL,以及 `--console-site` 选择国内/国际站。引导完成后用户自行粘贴 `auth login --open-api --access-key-id … --access-key-secret …` | 44 | | -- `bl auth login --open-api --access-key-id … --access-key-secret …`:调用 OpenAPI 生成 CLI `access_token`,通过目标 Console 网关的只读 `loginInfo` 校验后,才一并写入 `access_key_id` / `access_key_secret` / `access_token` 和实际 `console_region` / `console_site`;失败不覆盖原凭证、不激活 Profile。一次成功登录同时产生 `openapi` 与 `console` 域凭证 | | 43 | +- `bl auth login --open-api` **不带** AK/SK:打开控制台 `/aksk-guide` 浏览器引导(不等浏览器回传、不启本地 callback;SecretKey 不会经页面回传)。会等待打开器进程返回,但 URL 与粘贴命令在此之前已打印——打开器挂起(Linux `xdg-open` 可能阻塞到浏览器退出)不得推迟可操作输出,顺序规则与 `login-console.ts`「先注册回调再打开」一致。支持 `--no-browser` 只打印 URL,以及 `--console-site` 选择国内/国际站。粘贴命令**无条件回显**引导页实际使用的 `--console-site`(含显式 `domestic`,否则 Profile 的 `console_site` 会覆盖用户意图)与按 `recoveryConfigName` 解析出的 `--config`,使粘贴回来等价于「引导页站点 + 目标 Profile」;浏览器自动打开失败时文案不得宣称「已打开」,且不得与警告重复同一句「请手动打开上方地址」,exit 仍为 0 | | 44 | +- `bl auth login --open-api --access-key-id … --access-key-secret …`:调用 OpenAPI 生成 CLI `access_token`,通过目标 Console 网关的只读 `loginInfo` 校验后,才一并写入 `access_key_id` / `access_key_secret` / `access_token` 和实际 `console_region` / `console_site`;失败不覆盖原凭证、不激活 Profile。一次成功登录同时产生 `openapi` 与 `console` 域凭证。`--console-site` 在 guide 与带 AK/SK 落盘路径均可用 | 45 | 45 | - `auth status` 未配置 OpenAPI 时提示:先 `auth login --open-api` 按引导获取 AccessKey;若已有则用 `--access-key-id` / `--access-key-secret` 直接配置。缺凭证的 AUTH hint 同样指向 `auth login --open-api`,并保留成对 flag / env 说明 | 46 | 46 | - `bl auth logout --console` 只清 `access_token` | 47 | 47 | - `bl auth logout --open-api` 只清 `access_key_id` / `access_key_secret` / `security_token` | |
Collapse file Copy file name to clipboardExpand all lines: packages/commands/src/commands/auth/login-openapi-guide.ts +45-23Lines changed: 45 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,9 +5,16 @@ import { resolveConsoleOrigin, type LoginDeps } from "./login-console.ts"; | 5 | 5 |
| 6 | 6 | export interface OpenApiGuideOptions { | 7 | 7 | site?: string; | | 8 | + /** Profile name to echo as `--config` in the paste-ready command. */ | | 9 | + config?: string; | 8 | 10 | noBrowser?: boolean; | 9 | 11 | } | 10 | 12 |
| | 13 | +export interface OpenApiPasteOptions { | | 14 | + site?: string; | | 15 | + config?: string; | | 16 | +} | | 17 | + | 11 | 18 | function localizeGuide(deps: LoginDeps, text: LocalizedText): string { | 12 | 19 | if (typeof text === "string") return text; | 13 | 20 | return deps.localize ? deps.localize(text) : text["en-US"]; | @@ -19,23 +26,37 @@ export function resolveAkskGuideUrl(site?: string): string { | 19 | 26 | } | 20 | 27 |
| 21 | 28 | /** Paste-ready command after the browser guide completes. */ | 22 | | -export function openApiPasteCommand(identity: Identity): string { | 23 | | - return formatCommand( | 24 | | - identity, | 25 | | - "auth login --open-api --access-key-id <id> --access-key-secret <secret>", | 26 | | - ); | | 29 | +export function openApiPasteCommand(identity: Identity, options: OpenApiPasteOptions = {}): string { | | 30 | + const parts = ["auth login --open-api --access-key-id <id> --access-key-secret <secret>"]; | | 31 | + // Always echo the resolved site. It is exactly the site the guide page targeted, | | 32 | + // so pinning it can never be wrong; omitting it lets a Profile default override an | | 33 | + // explicit choice (e.g. file `console_site: international` + `--console-site domestic` | | 34 | + // would otherwise save the credential to the international gateway). | | 35 | + if (options.site) { | | 36 | + parts.push(`--console-site ${options.site}`); | | 37 | + } | | 38 | + if (options.config?.trim()) { | | 39 | + parts.push(`--config ${options.config.trim()}`); | | 40 | + } | | 41 | + return formatCommand(identity, parts.join(" ")); | 27 | 42 | } | 28 | 43 |
| 29 | 44 | /** | 30 | 45 | * Open (or print) the AK/SK guide page. Does not wait for a callback — SecretKey | 31 | | - * never returns through the browser. | | 46 | + * never returns through the browser. The URL and the paste-ready command are printed | | 47 | + * before awaiting the opener, so a slow or hanging `open` / `xdg-open` never withholds | | 48 | + * what the user needs to act on — the same ordering rule `login-console.ts` follows by | | 49 | + * registering the callback before opening the browser. | 32 | 50 | */ | 33 | 51 | export async function runOpenApiGuide( | 34 | 52 | deps: LoginDeps, | 35 | 53 | options: OpenApiGuideOptions = {}, | 36 | | -): Promise<{ url: string }> { | | 54 | +): Promise<{ url: string; browserOpened: boolean }> { | 37 | 55 | const url = resolveAkskGuideUrl(options.site); | 38 | | - const paste = openApiPasteCommand(deps.identity); | | 56 | + const paste = openApiPasteCommand(deps.identity, { | | 57 | + site: options.site, | | 58 | + config: options.config, | | 59 | + }); | 39 | 60 |
| 40 | 61 | deps.output.info( | 41 | 62 | `${localizeGuide(deps, { | @@ -44,26 +65,27 @@ export async function runOpenApiGuide( | 44 | 65 | })}\n${url}`, | 45 | 66 | ); | 46 | 67 |
| 47 | | - if (!options.noBrowser) { | 48 | | - void openInBrowser(url).then( | 49 | | - () => undefined, | 50 | | - (error: unknown) => { | 51 | | - deps.output.warning( | 52 | | - localizeGuide(deps, { | 53 | | - "en-US": `Could not open a browser automatically (${error instanceof Error ? error.message : String(error)}). Open the URL above manually.`, | 54 | | - "zh-CN": `无法自动打开浏览器(${error instanceof Error ? error.message : String(error)})。请手动打开上方地址。`, | 55 | | - }), | 56 | | - ); | 57 | | - }, | 58 | | - ); | 59 | | - } | 60 | | - | 61 | 68 | deps.output.info( | 62 | 69 | localizeGuide(deps, { | 63 | 70 | "en-US": `After finishing the guide, return here and paste your AccessKey:\n ${paste}`, | 64 | 71 | "zh-CN": `按照引导完成操作后,回到当前命令行粘贴AccessKey:\n ${paste}`, | 65 | 72 | }), | 66 | 73 | ); | 67 | 74 |
| 68 | | - return { url }; | | 75 | + let browserOpened = false; | | 76 | + if (!options.noBrowser) { | | 77 | + try { | | 78 | + await openInBrowser(url); | | 79 | + browserOpened = true; | | 80 | + } catch (error: unknown) { | | 81 | + deps.output.warning( | | 82 | + localizeGuide(deps, { | | 83 | + "en-US": `Could not open a browser automatically (${error instanceof Error ? error.message : String(error)}). Open the URL above manually.`, | | 84 | + "zh-CN": `无法自动打开浏览器(${error instanceof Error ? error.message : String(error)})。请手动打开上方地址。`, | | 85 | + }), | | 86 | + ); | | 87 | + } | | 88 | + } | | 89 | + | | 90 | + return { url, browserOpened }; | 69 | 91 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/commands/src/commands/auth/login.ts +23-9Lines changed: 23 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ export default defineCommand({ | 27 | 27 | }, | 28 | 28 | auth: "none", | 29 | 29 | usageArgs: | 30 | | - "--api-key <key> | --console [--no-browser | --token-stdin --console-region <region>] | --open-api [--no-browser] [--access-key-id <id> --access-key-secret <secret>]", | | 30 | + "--api-key <key> | --console [--no-browser | --token-stdin --console-region <region>] | --open-api [--no-browser] [--console-site <site>] [--access-key-id <id> --access-key-secret <secret>]", | 31 | 31 | flags: { | 32 | 32 | apiKey: { | 33 | 33 | type: "string", | @@ -118,6 +118,7 @@ export default defineCommand({ | 118 | 118 | "--open-api", | 119 | 119 | "--open-api --no-browser --console-site international", | 120 | 120 | "--open-api --access-key-id LTAIxxxxx --access-key-secret xxxxx", | | 121 | + "--open-api --access-key-id LTAIxxxxx --access-key-secret xxxxx --console-site international", | 121 | 122 | ], | 122 | 123 | validate: (flags) => { | 123 | 124 | const apiKeyMode = hasValue(flags.apiKey); | @@ -126,7 +127,6 @@ export default defineCommand({ | 126 | 127 | const openApiHasId = hasValue(flags.accessKeyId); | 127 | 128 | const openApiHasSecret = hasValue(flags.accessKeySecret); | 128 | 129 | const openApiPersist = openApiMode && openApiHasId && openApiHasSecret; | 129 | | - const openApiGuide = openApiMode && !openApiHasId && !openApiHasSecret; | 130 | 130 |
| 131 | 131 | if (flags.tokenStdin || hasValue(flags.consoleRegion)) { | 132 | 132 | if (!consoleMode) { | @@ -151,8 +151,8 @@ export default defineCommand({ | 151 | 151 | if (!apiKeyMode && hasValue(flags.baseUrl)) { | 152 | 152 | return "Use --base-url only with --api-key"; | 153 | 153 | } | 154 | | - if (hasValue(flags.consoleSite) && !consoleMode && !openApiGuide) { | 155 | | - return "Use --console-site with --console or --open-api (setup guide). / --console-site 只能与 --console 或 --open-api(配置引导)一起使用。"; | | 154 | + if (hasValue(flags.consoleSite) && !consoleMode && !openApiMode) { | | 155 | + return "Use --console-site with --console or --open-api. / --console-site 只能与 --console 或 --open-api 一起使用。"; | 156 | 156 | } | 157 | 157 | if (!openApiMode && (openApiHasId || openApiHasSecret)) { | 158 | 158 | return "Use --open-api with --access-key-id and --access-key-secret"; | @@ -305,8 +305,12 @@ export default defineCommand({ | 305 | 305 | ); | 306 | 306 | return; | 307 | 307 | } | 308 | | - const { url } = await runOpenApiGuide(deps, { | | 308 | + // Global `--config` lives in settings, not command flags; recoveryConfigName | | 309 | + // is set for an explicit flag or an active named profile. | | 310 | + const pasteConfig = settings.recoveryConfigName?.trim() || undefined; | | 311 | + const { url, browserOpened } = await runOpenApiGuide(deps, { | 309 | 312 | site, | | 313 | + config: pasteConfig, | 310 | 314 | noBrowser: flags.noBrowser, | 311 | 315 | }); | 312 | 316 | ctx.output.result( | @@ -315,6 +319,7 @@ export default defineCommand({ | 315 | 319 | method: "open-api-guide", | 316 | 320 | url, | 317 | 321 | no_browser: !!flags.noBrowser, | | 322 | + browser_opened: browserOpened, | 318 | 323 | config: settings.configName ?? "default", | 319 | 324 | config_file: store.path, | 320 | 325 | }, | @@ -325,10 +330,19 @@ export default defineCommand({ | 325 | 330 | "en-US": "Browser not opened automatically. Open the URL above manually.", | 326 | 331 | "zh-CN": "未自动打开浏览器,请手动打开上方地址。", | 327 | 332 | } | 328 | | - : { | 329 | | - "en-US": "Opened the setup page in your default browser.", | 330 | | - "zh-CN": "已在默认浏览器打开引导页面。", | 331 | | - }, | | 333 | + : browserOpened | | 334 | + ? { | | 335 | + "en-US": "Opened the setup page in your default browser.", | | 336 | + "zh-CN": "已在默认浏览器打开引导页面。", | | 337 | + } | | 338 | + : { | | 339 | + // The warning above already carries the errno reason and the | | 340 | + // manual-open instruction, so the status line reports what is | | 341 | + // still usable instead of repeating that the browser did not open. | | 342 | + "en-US": | | 343 | + "Guide URL and follow-up command printed above; paste your AccessKey after finishing the guide.", | | 344 | + "zh-CN": "已打印引导地址与后续命令,完成引导后粘贴 AccessKey 即可。", | | 345 | + }, | 332 | 346 | ), | 333 | 347 | }, | 334 | 348 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/commands/tests/e2e/auth.e2e.test.ts +35-3Lines changed: 35 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -117,7 +117,7 @@ describe("e2e: auth", () => { | 117 | 117 | ]); | 118 | 118 | expect(consoleSiteWithoutConsole.exitCode).toBe(2); | 119 | 119 | expect(consoleSiteWithoutConsole.stderr).toMatch( | 120 | | - /Use --console-site with --console or --open-api \(setup guide\)/, | | 120 | + /Use --console-site with --console or --open-api/, | 121 | 121 | ); | 122 | 122 | }); | 123 | 123 |
| @@ -148,18 +148,50 @@ describe("e2e: auth", () => { | 148 | 148 |
| 149 | 149 | const noBrowser = await runCommandE2e( | 150 | 150 | AUTH_ROUTES, | 151 | | - ["auth", "login", "--open-api", "--no-browser", "--console-site", "international"], | | 151 | + [ | | 152 | + "auth", | | 153 | + "login", | | 154 | + "--open-api", | | 155 | + "--no-browser", | | 156 | + "--console-site", | | 157 | + "international", | | 158 | + "--config", | | 159 | + "release-review", | | 160 | + ], | 152 | 161 | { BAILIAN_CONFIG_DIR: configDir }, | 153 | 162 | ); | 154 | 163 | expect(noBrowser.exitCode, noBrowser.stderr).toBe(0); | 155 | 164 | expect(noBrowser.stdout + noBrowser.stderr).toMatch( | 156 | 165 | /modelstudio\.console\.alibabacloud\.com\/aksk-guide/, | 157 | 166 | ); | 158 | 167 | expect(noBrowser.stdout + noBrowser.stderr).toMatch( | 159 | | - /auth login --open-api --access-key-id <id> --access-key-secret <secret>/, | | 168 | + /auth login --open-api --access-key-id <id> --access-key-secret <secret> --console-site international --config release-review/, | 160 | 169 | ); | 161 | 170 | expect(existsSync(join(configDir, "config.json"))).toBe(false); | 162 | 171 |
| | 172 | + const persistWithSite = await runCommandE2e( | | 173 | + AUTH_ROUTES, | | 174 | + [ | | 175 | + "auth", | | 176 | + "login", | | 177 | + "--open-api", | | 178 | + "--access-key-id", | | 179 | + "LTAI-e2e", | | 180 | + "--access-key-secret", | | 181 | + "secret-e2e", | | 182 | + "--console-site", | | 183 | + "international", | | 184 | + // Mirror the full echoed paste command, `--config` included, so the | | 185 | + // guide output stays something the user can paste back verbatim. | | 186 | + "--config", | | 187 | + "release-review", | | 188 | + "--dry-run", | | 189 | + ], | | 190 | + { BAILIAN_CONFIG_DIR: configDir }, | | 191 | + ); | | 192 | + expect(persistWithSite.exitCode, persistWithSite.stderr).toBe(0); | | 193 | + expect(persistWithSite.stdout).toMatch(/Would save AccessKey credentials/); | | 194 | + | 163 | 195 | const noBrowserWithKeys = await runCommandE2e(AUTH_ROUTES, [ | 164 | 196 | "auth", | 165 | 197 | "login", | |
Collapse file Copy file name to clipboard +127Lines changed: 127 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { buildSettings, type AuthStore, type Identity, type LocalizedText } from "bailian-cli-core"; | | 2 | +import { expect, test, vi } from "vite-plus/test"; | | 3 | + | | 4 | +const openInBrowser = vi.hoisted(() => vi.fn<(url: string) => Promise<void>>()); | | 5 | + | | 6 | +vi.mock("../src/commands/shared/local-server.ts", async (importOriginal) => { | | 7 | + const actual = await importOriginal<typeof import("../src/commands/shared/local-server.ts")>(); | | 8 | + return { | | 9 | + ...actual, | | 10 | + openInBrowser: (url: string) => openInBrowser(url), | | 11 | + }; | | 12 | +}); | | 13 | + | | 14 | +import { openApiPasteCommand, runOpenApiGuide } from "../src/commands/auth/login-openapi-guide.ts"; | | 15 | +import type { LoginDeps } from "../src/commands/auth/login-console.ts"; | | 16 | + | | 17 | +const identity = { binName: "bl" } as Identity; | | 18 | + | | 19 | +function localize(text: LocalizedText): string { | | 20 | + return typeof text === "string" ? text : text["en-US"]; | | 21 | +} | | 22 | + | | 23 | +function messageText(message: unknown): string { | | 24 | + if (typeof message === "string") return message; | | 25 | + if (message && typeof message === "object" && "en-US" in message) { | | 26 | + return String((message as { "en-US": string })["en-US"]); | | 27 | + } | | 28 | + return String(message); | | 29 | +} | | 30 | + | | 31 | +function makeDeps(options?: { infos?: string[]; warnings?: string[] }): LoginDeps { | | 32 | + const infos = options?.infos; | | 33 | + const warnings = options?.warnings; | | 34 | + return { | | 35 | + identity, | | 36 | + settings: buildSettings({ flags: {}, file: {}, env: {} }), | | 37 | + authStore: {} as AuthStore, | | 38 | + localize, | | 39 | + output: { | | 40 | + info: (message) => { | | 41 | + infos?.push(messageText(message)); | | 42 | + }, | | 43 | + warning: (message) => { | | 44 | + warnings?.push(messageText(message)); | | 45 | + }, | | 46 | + debug: () => undefined, | | 47 | + }, | | 48 | + }; | | 49 | +} | | 50 | + | | 51 | +test("openApiPasteCommand keeps non-domestic site and explicit config", () => { | | 52 | + expect(openApiPasteCommand(identity)).toBe( | | 53 | + "bl auth login --open-api --access-key-id <id> --access-key-secret <secret>", | | 54 | + ); | | 55 | + expect(openApiPasteCommand(identity, { site: "domestic" })).toBe( | | 56 | + "bl auth login --open-api --access-key-id <id> --access-key-secret <secret> --console-site domestic", | | 57 | + ); | | 58 | + expect(openApiPasteCommand(identity, { site: "international", config: "release-review" })).toBe( | | 59 | + "bl auth login --open-api --access-key-id <id> --access-key-secret <secret> --console-site international --config release-review", | | 60 | + ); | | 61 | + // An explicit domestic has to survive paste-back: dropping the flag would let a | | 62 | + // Profile default of `console_site: international` win on the save path. | | 63 | + expect(openApiPasteCommand(identity, { site: "domestic", config: "p" })).toBe( | | 64 | + "bl auth login --open-api --access-key-id <id> --access-key-secret <secret> --console-site domestic --config p", | | 65 | + ); | | 66 | +}); | | 67 | + | | 68 | +test("runOpenApiGuide awaits browser open and reports failure without claiming success", async () => { | | 69 | + const warnings: string[] = []; | | 70 | + const infos: string[] = []; | | 71 | + openInBrowser.mockReset(); | | 72 | + openInBrowser.mockRejectedValue(new Error("spawn open ENOENT")); | | 73 | + | | 74 | + const result = await runOpenApiGuide(makeDeps({ infos, warnings }), { | | 75 | + site: "international", | | 76 | + config: "release-review", | | 77 | + }); | | 78 | + | | 79 | + expect(result.browserOpened).toBe(false); | | 80 | + expect(result.url).toMatch(/modelstudio\.console\.alibabacloud\.com\/aksk-guide/); | | 81 | + expect(openInBrowser).toHaveBeenCalledOnce(); | | 82 | + expect(warnings.join("\n")).toMatch(/Could not open a browser automatically/); | | 83 | + expect(infos.join("\n")).toMatch(/--console-site international --config release-review/); | | 84 | + expect(infos.join("\n")).not.toMatch(/Opened the setup page/); | | 85 | +}); | | 86 | + | | 87 | +test("runOpenApiGuide marks browserOpened when open succeeds", async () => { | | 88 | + openInBrowser.mockReset(); | | 89 | + openInBrowser.mockResolvedValue(undefined); | | 90 | + | | 91 | + const result = await runOpenApiGuide(makeDeps(), { site: "domestic", noBrowser: false }); | | 92 | + | | 93 | + expect(result.browserOpened).toBe(true); | | 94 | + expect(openInBrowser).toHaveBeenCalledOnce(); | | 95 | +}); | | 96 | + | | 97 | +test("runOpenApiGuide prints the paste command before the opener resolves", async () => { | | 98 | + let releaseOpen: () => void = () => undefined; | | 99 | + openInBrowser.mockReset(); | | 100 | + openInBrowser.mockImplementation( | | 101 | + () => | | 102 | + new Promise<void>((resolve) => { | | 103 | + releaseOpen = resolve; | | 104 | + }), | | 105 | + ); | | 106 | + | | 107 | + const infos: string[] = []; | | 108 | + const pendingGuide = runOpenApiGuide(makeDeps({ infos }), { site: "international" }); | | 109 | + | | 110 | + // A hanging `open` / `xdg-open` must not withhold the actionable output. | | 111 | + await new Promise((resolve) => setImmediate(resolve)); | | 112 | + expect(infos.join("\n")).toMatch( | | 113 | + /--access-key-id <id> --access-key-secret <secret> --console-site international/, | | 114 | + ); | | 115 | + | | 116 | + releaseOpen(); | | 117 | + expect((await pendingGuide).browserOpened).toBe(true); | | 118 | +}); | | 119 | + | | 120 | +test("runOpenApiGuide with --no-browser skips openInBrowser", async () => { | | 121 | + openInBrowser.mockReset(); | | 122 | + | | 123 | + const result = await runOpenApiGuide(makeDeps(), { noBrowser: true }); | | 124 | + | | 125 | + expect(result.browserOpened).toBe(false); | | 126 | + expect(openInBrowser).not.toHaveBeenCalled(); | | 127 | +}); |
|