@@ -14,6 +14,7 @@ import {
1414 runGeneratedBashCompletion ,
1515 runGeneratedFishCompletion ,
1616} from "./completion-cli.test-support.js" ;
17+ import { registerModelsCli } from "./models-cli.js" ;
1718
1819const powerShellCompletion = new PowerShellCompletionRunner ( ) ;
1920
@@ -86,6 +87,73 @@ describe("completion-cli", () => {
8687 expect ( script ) . not . toContain ( "John'\\''s" ) ;
8788 } ) ;
8889
90+ it . skipIf ( process . platform === "win32" ) . each ( [ "built-in" , "root" , "nested" ] as const ) (
91+ "keeps %s command descriptions literal through real zsh parsing" ,
92+ ( scope ) => {
93+ const program = new Command ( ) . name ( "openclaw" ) ;
94+ let describedCommand : Command ;
95+ let completionFunction : string ;
96+ if ( scope === "built-in" ) {
97+ registerModelsCli ( program ) ;
98+ const auth = program . commands
99+ . find ( ( command ) => command . name ( ) === "models" )
100+ ?. commands . find ( ( command ) => command . name ( ) === "auth" ) ;
101+ const logout = auth ?. commands . find ( ( command ) => command . name ( ) === "logout" ) ;
102+ if ( ! logout ) {
103+ throw new Error ( "Models auth logout command is unavailable" ) ;
104+ }
105+ describedCommand = logout ;
106+ completionFunction = "_openclaw_models_auth" ;
107+ } else {
108+ const parent = scope === "nested" ? program . command ( "parent" ) : program ;
109+ describedCommand = parent
110+ . command ( "inspect" )
111+ . alias ( "review" )
112+ . description (
113+ 'Show John\'s "literal" $OPENCLAW_COMPLETION_LITERAL with `models auth list`' ,
114+ ) ;
115+ completionFunction = scope === "nested" ? "_openclaw_parent" : "_openclaw_root_completion" ;
116+ }
117+
118+ const result = spawnSync (
119+ "zsh" ,
120+ [
121+ "-fc" ,
122+ `${ getCompletionScript ( "zsh" , program ) }
123+ OPENCLAW_COMPLETION_LITERAL=expanded-value
124+ models() { printf '%s\\n' "OPENCLAW_COMPLETION_DESCRIPTION_EVALUATED:$*" >&2; }
125+ _arguments() {
126+ local spec
127+ for spec in "$@"; do
128+ if [[ "$spec" == "1: :"* ]]; then
129+ local -a action
130+ eval "action=( \${spec#1: :} )"
131+ printf '%s\\0' "\${action[@]}"
132+ fi
133+ done
134+ }
135+ ${ completionFunction }
136+ ` ,
137+ ] ,
138+ { encoding : "utf8" , timeout : 10_000 } ,
139+ ) ;
140+ if ( result . error ) {
141+ if ( "code" in result . error && result . error . code === "ENOENT" ) {
142+ return ;
143+ }
144+ throw result . error ;
145+ }
146+
147+ expect ( result . stderr ) . toBe ( "" ) ;
148+ expect ( result . status ) . toBe ( 0 ) ;
149+ const action = result . stdout . split ( "\0" ) . filter ( Boolean ) ;
150+ expect ( action . slice ( 0 , 2 ) ) . toEqual ( [ "_values" , "command" ] ) ;
151+ for ( const name of [ describedCommand . name ( ) , ...describedCommand . aliases ( ) ] ) {
152+ expect ( action ) . toContain ( `${ name } [${ describedCommand . description ( ) } ]` ) ;
153+ }
154+ } ,
155+ ) ;
156+
89157 it ( "marks zsh option arguments and completes validated shell choices" , ( ) => {
90158 const script = getCompletionScript ( "zsh" , createDocumentedCompletionProgram ( ) ) ;
91159
0 commit comments