@@ -1391,6 +1391,55 @@ TEST(config_toml_codex_reports_stable_failure_reasons) {
13911391 PASS ();
13921392}
13931393
1394+ /* #2044: an installed binary under a profile with a space (C:\Users\First Last)
1395+ * is rendered single-quoted by cbm_shell_quote_word / cbm_powershell_quote_word.
1396+ * The hook block must accept exactly what those writers emit, read it back as
1397+ * owned, and still refuse an unquoted word that the shell would split. */
1398+ TEST (config_toml_codex_accepts_quoted_binary_path_with_spaces ) {
1399+ static const char command [] = "'/Users/First Last/.local/bin/codebase-memory-mcp' hook-augment" ;
1400+ static const char command_windows [] = "& 'C:/Users/First Last/AppData/Local/Programs/"
1401+ "codebase-memory-mcp/codebase-memory-mcp.exe' "
1402+ "hook-augment" ;
1403+ char dir [CTE_PATH_CAP ];
1404+ char path [CTE_PATH_CAP ];
1405+ char first [CTE_FILE_CAP ];
1406+ char actual [CTE_FILE_CAP ];
1407+ ASSERT_EQ (cte_fixture (dir , sizeof (dir ), path , sizeof (path )), 0 );
1408+ ASSERT_EQ (th_write_file (path , "keep = true\n" ), 0 );
1409+
1410+ cbm_toml_codex_hook_failure_t failure = CBM_TOML_CODEX_HOOK_FAILURE_INVALID_ARGUMENT ;
1411+ ASSERT_EQ (cte_codex_edit_commands_detailed (path , command , command_windows ,
1412+ CBM_TOML_CODEX_HOOK_UPSERT , 1 , & failure ),
1413+ 0 );
1414+ ASSERT_STR_EQ (cbm_toml_codex_hook_failure_name (failure ), "none" );
1415+ ASSERT_EQ (cte_codex_edit_commands_detailed (path , command , command_windows ,
1416+ CBM_TOML_CODEX_HOOK_UPSERT , 0 , & failure ),
1417+ 0 );
1418+ ASSERT_EQ (cte_read (path , first , sizeof (first )), 0 );
1419+ ASSERT (strstr (first , "First Last/.local/bin/codebase-memory-mcp' hook-augment" ) != NULL );
1420+
1421+ /* The written block is recognised as ours: a second upsert is a no-op. */
1422+ ASSERT_EQ (cte_codex_edit_commands_detailed (path , command , command_windows ,
1423+ CBM_TOML_CODEX_HOOK_UPSERT , 0 , & failure ),
1424+ 0 );
1425+ ASSERT_EQ (cte_read (path , actual , sizeof (actual )), 0 );
1426+ ASSERT_STR_EQ (actual , first );
1427+ ASSERT_EQ (cte_codex_edit_commands_detailed (path , command , command_windows ,
1428+ CBM_TOML_CODEX_HOOK_REMOVE , 0 , & failure ),
1429+ 0 );
1430+ ASSERT_EQ (cte_read (path , actual , sizeof (actual )), 0 );
1431+ ASSERT_STR_EQ (actual , "keep = true\n" );
1432+
1433+ /* Unquoted, the space splits the executable word: still refused. */
1434+ ASSERT_EQ (cte_codex_edit_commands_detailed (
1435+ path , "/Users/First Last/.local/bin/codebase-memory-mcp hook-augment" ,
1436+ command_windows , CBM_TOML_CODEX_HOOK_UPSERT , 1 , & failure ),
1437+ -1 );
1438+ ASSERT_STR_EQ (cbm_toml_codex_hook_failure_name (failure ), "command_render" );
1439+ th_cleanup (dir );
1440+ PASS ();
1441+ }
1442+
13941443TEST (config_toml_codex_preserves_bom_crlf_and_foreign_aot ) {
13951444 char dir [CTE_PATH_CAP ];
13961445 char path [CTE_PATH_CAP ];
@@ -1506,6 +1555,7 @@ SUITE(config_toml_edit) {
15061555 RUN_TEST (config_toml_codex_accepts_v0102_managed_windows_crlf );
15071556 RUN_TEST (config_toml_codex_rejects_ambiguous_inline_byte_identically );
15081557 RUN_TEST (config_toml_codex_reports_stable_failure_reasons );
1558+ RUN_TEST (config_toml_codex_accepts_quoted_binary_path_with_spaces );
15091559 RUN_TEST (config_toml_codex_preserves_bom_crlf_and_foreign_aot );
15101560 RUN_TEST (config_toml_legacy_remove_reports_foreign_table_without_mutation );
15111561}
0 commit comments