@@ -2687,6 +2687,42 @@ describe("runCli exit behavior", () => {
26872687 expect ( registerPluginCliCommandsFromValidatedConfigMock ) . not . toHaveBeenCalled ( ) ;
26882688 } ) ;
26892689
2690+ it ( "sanitizes control characters in unowned command diagnostics" , async ( ) => {
2691+ const primary = "bad\u001b[31m-red\u001b[0m\nforged\tline" ;
2692+
2693+ await expect ( runCli ( [ "node" , "openclaw" , primary ] ) ) . rejects . toThrow (
2694+ 'Unknown command: openclaw bad-red\\nforged\\tline. No built-in command or plugin CLI metadata owns "bad-red\\nforged\\tline".' ,
2695+ ) ;
2696+
2697+ expect ( startProxyMock ) . not . toHaveBeenCalled ( ) ;
2698+ expect ( tryRouteCliMock ) . not . toHaveBeenCalled ( ) ;
2699+ expect ( buildProgramMock ) . not . toHaveBeenCalled ( ) ;
2700+ expect ( registerPluginCliCommandsFromValidatedConfigMock ) . not . toHaveBeenCalled ( ) ;
2701+ } ) ;
2702+
2703+ it ( "bounds long unowned command diagnostics without splitting Unicode" , async ( ) => {
2704+ const primary = "🦞" . repeat ( 1_000 ) ;
2705+
2706+ let error : unknown ;
2707+ try {
2708+ await runCli ( [ "node" , "openclaw" , primary ] ) ;
2709+ } catch ( caught ) {
2710+ error = caught ;
2711+ }
2712+
2713+ expect ( error ) . toBeInstanceOf ( Error ) ;
2714+ const message = ( error as Error ) . message ;
2715+ const displayPrimary = `${ "🦞" . repeat ( 63 ) } …` ;
2716+ expect ( displayPrimary . length ) . toBeLessThanOrEqual ( 128 ) ;
2717+ expect ( message ) . toContain ( `Unknown command: openclaw ${ displayPrimary } ` ) ;
2718+ expect ( message ) . not . toContain ( "�" ) ;
2719+ expect ( message . length ) . toBeLessThan ( 500 ) ;
2720+ expect ( startProxyMock ) . not . toHaveBeenCalled ( ) ;
2721+ expect ( tryRouteCliMock ) . not . toHaveBeenCalled ( ) ;
2722+ expect ( buildProgramMock ) . not . toHaveBeenCalled ( ) ;
2723+ expect ( registerPluginCliCommandsFromValidatedConfigMock ) . not . toHaveBeenCalled ( ) ;
2724+ } ) ;
2725+
26902726 it ( "keeps suggestions out of plugin-policy diagnostics" , async ( ) => {
26912727 resolveManifestCommandAliasOwnerMock . mockReturnValueOnce ( {
26922728 pluginId : "codex" ,
0 commit comments