1- import { describe , expect , test } from "vite-plus/test" ;
2- import { deriveGroupPaths } from "e2e/registry-smoke" ;
1+ import { mkdtempSync , rmSync } from "fs" ;
2+ import { tmpdir } from "os" ;
3+ import { join } from "path" ;
4+ import { afterAll , describe , expect , test } from "vite-plus/test" ;
5+ import { captureRegistryHelp , deriveGroupPaths } from "e2e/registry-smoke" ;
6+ import { CommandRegistry , resolve } from "bailian-cli-runtime" ;
37import { commands } from "../../src/commands.ts" ;
48import { runCli } from "./helpers.ts" ;
59
610const commandPaths = Object . keys ( commands ) . sort ( ) ;
711const groupPaths = deriveGroupPaths ( commandPaths ) ;
12+ const registry = new CommandRegistry ( commands , "bl" ) ;
13+ const isolatedConfigDir = mkdtempSync ( join ( tmpdir ( ) , "bl-registry-smoke-" ) ) ;
14+
15+ afterAll ( ( ) => rmSync ( isolatedConfigDir , { recursive : true , force : true } ) ) ;
16+
17+ function runCliSmoke ( args : string [ ] ) {
18+ return runCli ( args , { BAILIAN_CONFIG_DIR : isolatedConfigDir } ) ;
19+ }
820
921describe ( "e2e: bl registry smoke" , ( ) => {
1022 test ( "根帮助展示 bl、逐命令鉴权域与全局 flag" , async ( ) => {
11- const { stderr, exitCode } = await runCli ( [ "--help" ] ) ;
23+ const { stderr, exitCode } = await runCliSmoke ( [ "--help" ] ) ;
1224 expect ( exitCode , stderr ) . toBe ( 0 ) ;
1325 expect ( stderr ) . toMatch ( / \b b l \b / i) ;
1426 expect ( stderr ) . not . toMatch ( / C O M M A N D \s + A U T H \s + D E S C R I P T I O N / ) ;
@@ -24,7 +36,7 @@ describe("e2e: bl registry smoke", () => {
2436 } ) ;
2537
2638 test ( "分组帮助按叶子命令展示不同鉴权域" , async ( ) => {
27- const { stderr, exitCode } = await runCli ( [ "app" , "--help" ] ) ;
39+ const { stderr, exitCode } = await runCliSmoke ( [ "app" , "--help" ] ) ;
2840 expect ( exitCode , stderr ) . toBe ( 0 ) ;
2941 expect ( stderr ) . toMatch ( / a p p c a l l \s + \[ A P I K e y \] \s + C a l l a B a i l i a n a p p l i c a t i o n / ) ;
3042 expect ( stderr ) . toMatch ( / a p p l i s t \s + \[ C o n s o l e \] \s + L i s t B a i l i a n a p p l i c a t i o n s / ) ;
@@ -36,13 +48,13 @@ describe("e2e: bl registry smoke", () => {
3648 [ [ "token-plan" , "list-seats" ] , "AK/SK" ] ,
3749 [ [ "config" , "show" ] , "No Auth" ] ,
3850 ] as const ) ( "%s --help 明确展示鉴权域 %s" , async ( commandPath , authLabel ) => {
39- const { stderr, exitCode } = await runCli ( [ ...commandPath , "--help" ] ) ;
51+ const { stderr, exitCode } = await runCliSmoke ( [ ...commandPath , "--help" ] ) ;
4052 expect ( exitCode , stderr ) . toBe ( 0 ) ;
4153 expect ( stderr ) . toContain ( `Authentication: ${ authLabel } ` ) ;
4254 } ) ;
4355
4456 test ( "quota check --help:Flags 含 console 域鉴权 flag,Global Flags 全量列出" , async ( ) => {
45- const { stderr, exitCode } = await runCli ( [ "quota" , "check" , "--help" ] ) ;
57+ const { stderr, exitCode } = await runCliSmoke ( [ "quota" , "check" , "--help" ] ) ;
4658 expect ( exitCode , stderr ) . toBe ( 0 ) ;
4759 expect ( stderr ) . toMatch ( / G l o b a l F l a g s : / ) ;
4860 expect ( stderr ) . toMatch ( / - - c o n s o l e - r e g i o n < r e g i o n > / ) ;
@@ -52,13 +64,25 @@ describe("e2e: bl registry smoke", () => {
5264 expect ( stderr ) . not . toMatch ( / A P I r e g i o n \( d e f a u l t : c n - b e i j i n g \) / ) ;
5365 } ) ;
5466
55- test . each ( commandPaths ) ( "已注册命令 %s --help 成功" , async ( path ) => {
56- const { stderr, exitCode } = await runCli ( [ ...path . split ( " " ) , "--help" ] ) ;
57- expect ( exitCode , stderr ) . toBe ( 0 ) ;
67+ test . each ( commandPaths ) ( "已注册命令 %s --help 成功" , ( path ) => {
68+ const commandPath = path . split ( " " ) ;
69+
70+ expect ( resolve ( [ ...commandPath , "--help" ] , registry ) ) . toEqual ( {
71+ kind : "help" ,
72+ path : commandPath ,
73+ } ) ;
74+ expect ( captureRegistryHelp ( registry , commandPath ) ) . toContain ( `Usage: bl ${ path } ` ) ;
5875 } ) ;
5976
60- test . each ( groupPaths ) ( "命令分组 %s --help 成功" , async ( path ) => {
61- const { stderr, exitCode } = await runCli ( [ ...path . split ( " " ) , "--help" ] ) ;
62- expect ( exitCode , stderr ) . toBe ( 0 ) ;
77+ test . each ( groupPaths ) ( "命令分组 %s --help 成功" , ( path ) => {
78+ const commandPath = path . split ( " " ) ;
79+
80+ expect ( resolve ( [ ...commandPath , "--help" ] , registry ) ) . toEqual ( {
81+ kind : "help" ,
82+ path : commandPath ,
83+ } ) ;
84+ expect ( captureRegistryHelp ( registry , commandPath ) ) . toContain (
85+ `Usage: bl ${ path } <command> [flags]` ,
86+ ) ;
6387 } ) ;
6488} ) ;
0 commit comments