@@ -67,6 +67,21 @@ void malformedRootRegistryLeavesLocalInvocationAvailable() {
6767 }
6868 }
6969
70+ @ Test
71+ void invalidVersionOutputPreventsTheHelpProbe (@ TempDir Path directory ) {
72+ Path marker = directory .resolve ("help-started" );
73+ OpenCliProperties props = properties ("invalid-version" );
74+ props .getEnvironment ().put ("OPENCLI_TEST_DISCOVERY_HELP_MARKER" , marker .toString ());
75+ try (OpenCliClient client = new OpenCliClient (props )) {
76+ OpenCliCapabilitySnapshot result = client .discoverCapabilities ();
77+ assertFalse (Files .exists (marker ), "help was started after malformed version output" );
78+ assertEquals (OpenCliCapabilitySnapshot .Status .UNKNOWN , result .getStatus ());
79+ assertEquals ("INVALID_VERSION_OUTPUT" , result .getReason ());
80+ assertNull (result .getObservedVersion ());
81+ assertNull (result .getHelp ());
82+ }
83+ }
84+
7085 @ Test
7186 void pathLookupAndRemoteModeAreUnsupported () {
7287 try (OpenCliClient client = new OpenCliClient ()) {
@@ -269,6 +284,10 @@ public static void main(String[] args) throws Exception {
269284 mode = new String (Files .readAllBytes (Paths .get (control )), StandardCharsets .UTF_8 );
270285 }
271286 if (Arrays .equals (args , new String []{"--version" })) {
287+ if ("invalid-version" .equals (mode )) {
288+ System .out .println ("1.8.8" + (char ) 0 );
289+ return ;
290+ }
272291 System .out .println ("new-version-error" .equals (mode ) ? "1.8.9" : "1.8.8" );
273292 return ;
274293 }
@@ -300,6 +319,10 @@ public static void main(String[] args) throws Exception {
300319 if (!Arrays .equals (args , new String []{"--help" , "-f" , "json" })) {
301320 System .exit (2 );
302321 }
322+ String marker = System .getenv ("OPENCLI_TEST_DISCOVERY_HELP_MARKER" );
323+ if (Objects .nonNull (marker )) {
324+ Files .createFile (Paths .get (marker ));
325+ }
303326 if ("hold-old" .equals (mode )) {
304327 Path path = Paths .get (control ).getParent ();
305328 Files .createFile (path .resolve ("entered" ));
0 commit comments