Apache .htaccess <Directory not allowed here
<Directory>
directive is not allowed in .htaccess and for meeting your requirements you don't even need this in .htaccess.
You can use this rule in site root (parent) .htaccess
:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(?:^|&)test=yes(?:&|$) [NC]
RewriteRule ^foo/(.*)$ bar/$1?test=yes [NC,QSA,L]