11package localenv
22
33import (
4+ "context"
45 "errors"
56 "os"
67 "path/filepath"
@@ -120,10 +121,10 @@ func TestPipelineWorkspaceMember(t *testing.T) {
120121 assert .Contains (t , string (memberBytes ), `"databricks-connect~=17.2.0"` )
121122
122123 assert .Equal (t , "../../.venv" , res .VenvPath )
123- assert .Equal (t , filepath .ToSlash (root ), res .WorkspaceRoot )
124- assert .Equal (t , filepath .ToSlash (filepath .Join (root , backupFile )), res .WorkspaceBackupPath )
124+ assert .Equal (t , filepath .ToSlash (root ), res .UvWorkspaceRoot )
125+ assert .Equal (t , filepath .ToSlash (filepath .Join (root , backupFile )), res .UvWorkspaceBackupPath )
125126 assert .Equal (t , filepath .ToSlash (filepath .Join (member , backupFile )), res .BackupPath )
126- assert .NotContains (t , codes (res .Warnings ), WarnWorkspaceConstraintsReplaced , "first run must not warn" )
127+ assert .NotContains (t , codes (res .Warnings ), WarnUvWorkspaceConstraintsReplaced , "first run must not warn" )
127128}
128129
129130func TestPipelineWorkspaceMemberIdempotent (t * testing.T ) {
@@ -133,8 +134,8 @@ func TestPipelineWorkspaceMemberIdempotent(t *testing.T) {
133134 res , err := p .Run (t .Context ())
134135 require .NoError (t , err )
135136 assert .Empty (t , res .BackupPath )
136- assert .Empty (t , res .WorkspaceBackupPath )
137- assert .NotContains (t , codes (res .Warnings ), WarnWorkspaceConstraintsReplaced )
137+ assert .Empty (t , res .UvWorkspaceBackupPath )
138+ assert .NotContains (t , codes (res .Warnings ), WarnUvWorkspaceConstraintsReplaced )
138139 for _ , dir := range []string {root , member } {
139140 matches , err := filepath .Glob (filepath .Join (dir , "pyproject.toml.*.bak" ))
140141 require .NoError (t , err )
@@ -155,7 +156,7 @@ func TestPipelineWorkspaceConstraintsReplacedWarning(t *testing.T) {
155156
156157 res , err := p .Run (t .Context ())
157158 require .NoError (t , err )
158- assert .Contains (t , codes (res .Warnings ), WarnWorkspaceConstraintsReplaced )
159+ assert .Contains (t , codes (res .Warnings ), WarnUvWorkspaceConstraintsReplaced )
159160}
160161
161162func TestPipelineWorkspaceMemberNoConstraints (t * testing.T ) {
@@ -168,7 +169,7 @@ func TestPipelineWorkspaceMemberNoConstraints(t *testing.T) {
168169 after , err := os .ReadFile (filepath .Join (root , pyprojectFile ))
169170 require .NoError (t , err )
170171 assert .Equal (t , before , after )
171- assert .Empty (t , res .WorkspaceBackupPath )
172+ assert .Empty (t , res .UvWorkspaceBackupPath )
172173 assert .NoFileExists (t , filepath .Join (root , backupFile ))
173174}
174175
@@ -184,8 +185,8 @@ func TestPipelineWorkspaceMemberDryRun(t *testing.T) {
184185 assert .Equal (t , before , after )
185186 require .NotNil (t , res .Plan )
186187 assert .Equal (t , filepath .ToSlash (filepath .Join (member , pyprojectFile )), res .Plan .WouldWrite )
187- assert .Equal (t , filepath .ToSlash (filepath .Join (root , pyprojectFile )), res .Plan .WouldWriteWorkspace )
188- assert .Equal (t , filepath .ToSlash (filepath .Join (root , backupFile )), res .Plan .WouldBackupWorkspace )
188+ assert .Equal (t , filepath .ToSlash (filepath .Join (root , pyprojectFile )), res .Plan .WouldWriteUvWorkspace )
189+ assert .Equal (t , filepath .ToSlash (filepath .Join (root , backupFile )), res .Plan .WouldBackupUvWorkspace )
189190 assert .Contains (t , res .Plan .Diff , "workspace root" )
190191}
191192
@@ -286,7 +287,7 @@ func TestPipelineWorkspaceReplacesUserRootPinsWithWarning(t *testing.T) {
286287
287288 res , err := p .Run (t .Context ())
288289 require .NoError (t , err )
289- assert .Contains (t , codes (res .Warnings ), WarnWorkspaceConstraintsReplaced )
290+ assert .Contains (t , codes (res .Warnings ), WarnUvWorkspaceConstraintsReplaced )
290291}
291292
292293func TestApplyMergeRootFailureBeforeAnyWriteIsNotDiskMutated (t * testing.T ) {
@@ -335,7 +336,44 @@ func TestPipelineWorkspaceMemberDryRunReRunPlansNoRootWrite(t *testing.T) {
335336 res , err := p .Run (t .Context ())
336337 require .NoError (t , err )
337338 require .NotNil (t , res .Plan )
338- assert .Empty (t , res .Plan .WouldWriteWorkspace )
339- assert .Empty (t , res .Plan .WouldBackupWorkspace )
340- assert .NotEmpty (t , res .WorkspaceRoot )
339+ assert .Empty (t , res .Plan .WouldWriteUvWorkspace )
340+ assert .Empty (t , res .Plan .WouldBackupUvWorkspace )
341+ assert .NotEmpty (t , res .UvWorkspaceRoot )
342+ }
343+
344+ // cancelDiscoveryPM cancels the run while workspace discovery runs, like a
345+ // SIGINT that interrupts `uv workspace dir`.
346+ type cancelDiscoveryPM struct {
347+ fakePM
348+ cancel context.CancelFunc
349+ }
350+
351+ func (f cancelDiscoveryPM ) WorkspaceRoot (ctx context.Context , _ string ) (string , error ) {
352+ f .cancel ()
353+ return "" , ctx .Err ()
354+ }
355+
356+ func TestPipelineCancelDuringDiscoveryWritesNothing (t * testing.T ) {
357+ p , root , member := newMemberPipeline (t )
358+ // A first run fills the constraint cache, so the canceled run below can
359+ // still fetch; then the member file is reset so a merge would change it.
360+ _ , err := p .Run (t .Context ())
361+ require .NoError (t , err )
362+ require .NoError (t , os .WriteFile (filepath .Join (member , pyprojectFile ),
363+ []byte ("[project]\n name = \" a\" \n version = \" 0.1.0\" \n requires-python = \" >=3.10\" \n " ), 0o644 ))
364+
365+ ctx , cancel := context .WithCancel (t .Context ())
366+ defer cancel ()
367+ p .PM = cancelDiscoveryPM {fakePM : fakePM {py : "3.12" , dbc : "17.2.0" , root : root }, cancel : cancel }
368+ before , err := os .ReadFile (filepath .Join (member , pyprojectFile ))
369+ require .NoError (t , err )
370+
371+ res , err := p .Run (ctx )
372+ require .Error (t , err )
373+ require .NotNil (t , res .Error )
374+ assert .Equal (t , ErrCanceled , res .Error .Code )
375+ assert .False (t , res .Error .DiskMutated )
376+ after , err := os .ReadFile (filepath .Join (member , pyprojectFile ))
377+ require .NoError (t , err )
378+ assert .Equal (t , before , after )
341379}
0 commit comments