@@ -465,6 +465,38 @@ describe("renderEntrypoint clone cache", () => {
465465 } )
466466} )
467467
468+ describe ( "renderEntrypoint tilde target dir expansion" , ( ) => {
469+ // CHANGE: assert runtime `~`/`~/...` TARGET_DIR overrides resolve to the dev-owned home
470+ // WHY: the entrypoint runs as root (sshd), so `$HOME` is /root; expanding a tilde TARGET_DIR
471+ // against `$HOME` resolved the clone target to /root/app, which `su - dev` cannot write,
472+ // so `git clone` failed and the workspace `app` folder stayed EMPTY (issue #413)
473+ // QUOTE(ТЗ): "Почему-то при docker-git clone не делается git clone в папку app"
474+ // REF: issue-413
475+ // FORMAT THEOREM: expand("~") = /home/<sshUser> ∧ expand("~/p") = /home/<sshUser>/p
476+ it ( "expands a bare `~` against the dev home, not root's $HOME" , ( ) => {
477+ const entrypoint = renderEntrypoint ( makeTemplateConfig ( { sshUser : "dev" } ) )
478+
479+ expect ( entrypoint ) . toContain ( 'if [[ "$TARGET_DIR" == "~" ]]; then' )
480+ expect ( entrypoint ) . toContain ( 'TARGET_DIR="/home/dev"' )
481+ expect ( entrypoint ) . toContain ( 'TARGET_DIR="/home/dev${TARGET_DIR:1}"' )
482+ expect ( entrypoint ) . not . toContain ( 'TARGET_DIR="$HOME"' )
483+ expect ( entrypoint ) . not . toContain ( 'TARGET_DIR="$HOME${TARGET_DIR:1}"' )
484+ } )
485+
486+ it ( "expands the tilde against the configured ssh user for generated configs" , ( ) => {
487+ fc . assert (
488+ fc . property ( generatedTemplateConfigArbitrary , ( config ) => {
489+ const entrypoint = renderEntrypoint ( config )
490+
491+ expect ( entrypoint ) . toContain ( `TARGET_DIR="/home/${ config . sshUser } "` )
492+ expect ( entrypoint ) . toContain ( `TARGET_DIR="/home/${ config . sshUser } \${TARGET_DIR:1}"` )
493+ expect ( entrypoint ) . not . toContain ( 'TARGET_DIR="$HOME"' )
494+ expect ( entrypoint ) . not . toContain ( 'TARGET_DIR="$HOME${TARGET_DIR:1}"' )
495+ } )
496+ )
497+ } )
498+ } )
499+
468500describe ( "renderEntrypointGitHooks" , ( ) => {
469501 it ( "installs pre-push protection checks, plan sync, and a global git post-push runtime" , ( ) => {
470502 const hooks = renderEntrypointGitHooks ( )
0 commit comments