@@ -103,7 +103,6 @@ func (ts *testServerImpl) StartNode(i int) error {
103103 "COCKROACH_MAX_OFFSET=1ns" ,
104104 "COCKROACH_TRUST_CLIENT_PROVIDED_SQL_REMOTE_ADDR=true" ,
105105 }
106- currCmd .Env = append (currCmd .Env , ts .serverArgs .envVars ... )
107106
108107 // Set the working directory of the cockroach process to our temp folder.
109108 // This stops cockroach from polluting the project directory with _dump
@@ -135,6 +134,19 @@ func (ts *testServerImpl) StartNode(i int) error {
135134 for k , v := range defaultEnv () {
136135 currCmd .Env = append (currCmd .Env , k + "=" + v )
137136 }
137+ // Allow caller-provided environment variables to override defaults.
138+ currCmd .Env = append (currCmd .Env , ts .serverArgs .envVars ... )
139+ // For demo clusters, force HOME into a sandbox-writable directory under
140+ // the testserver temp dir so that demo's ~/.cockroach-demo sockets work
141+ // in sandboxed environments.
142+ if ts .serverArgs .demoMode {
143+ // Prefer a very short path to stay under Unix-domain socket length limits.
144+ demoHome , err := os .MkdirTemp ("/tmp" , "cockroach-demo-*" )
145+ if err != nil {
146+ return fmt .Errorf ("unable to create demo HOME directory %s: %w" , demoHome , err )
147+ }
148+ currCmd .Env = append (currCmd .Env , "HOME=" + demoHome )
149+ }
138150
139151 log .Printf ("executing: %s" , currCmd )
140152 err := currCmd .Start ()
0 commit comments