@@ -34,6 +34,8 @@ afterAll(() => {
3434beforeEach ( ( ) => {
3535 for ( const f of fs . readdirSync ( tmp ) ) fs . rmSync ( path . join ( tmp , f ) , { recursive : true , force : true } )
3636 delete process . env . ALTIMATE_INTEGRATIONS_DEMO
37+ // A GitHub host exported on this machine would block GitHub tokens in every test.
38+ for ( const k of [ "GITHUB_HOST" , "GH_HOST" , "GITHUB_API_URL" , "GITHUB_SERVER_URL" , "GITHUB_ENTERPRISE_URL" ] ) delete process . env [ k ]
3739} )
3840
3941describe ( "sameRecord" , ( ) => {
@@ -658,7 +660,7 @@ describe("workspace connections", () => {
658660 const update = spyOn ( backend , "updateDatamateIntegrations" ) . mockResolvedValue ( undefined as any )
659661 try {
660662 const refused = await core . syncProvider ( "github" , undefined , 0 , true )
661- expect ( [ refused . result , refused . reason ] ) . toEqual ( [ "failed" , core . ATTACH_FAILED_PREFIX + core . SHARED_WORKSPACE_REFUSAL ( "WS" , "github" ) ] )
663+ expect ( [ refused . result , refused . reason ] ) . toEqual ( [ "failed" , core . ATTACH_EXISTING_FAILED_PREFIX + core . SHARED_WORKSPACE_REFUSAL ( "WS" , "github" ) ] )
662664 expect ( update ) . not . toHaveBeenCalled ( )
663665 const shared = await core . syncProvider ( "github" , undefined , 0 , true , true )
664666 expect ( [ shared . result , shared . shared ] ) . toEqual ( [ "synced" , true ] )
@@ -847,6 +849,23 @@ describe("workspace connections", () => {
847849 spy . mockRestore ( )
848850 }
849851 expect ( core . isSynced ( "github" ) ) . toBe ( true )
852+ // The sync that the warning names has nothing left to upload, and removes the leftover while it attaches.
853+ expect ( await core . readSecret ( "github" ) ) . toBe ( "leftover_token" )
854+ delete process . env . GITHUB_TOKEN
855+ // No gh either, so the retry has nothing to upload and takes the attach-only path.
856+ const pathBefore = process . env . PATH
857+ process . env . PATH = fs . mkdtempSync ( path . join ( tmp , "nobin-" ) )
858+ const update = spyOn ( backend , "updateConnection" )
859+ let retry : core . SyncOutcome
860+ try {
861+ retry = await core . syncProvider ( "github" )
862+ expect ( update ) . not . toHaveBeenCalled ( )
863+ } finally {
864+ process . env . PATH = pathBefore
865+ update . mockRestore ( )
866+ }
867+ expect ( [ retry . result , retry . steps . some ( ( st ) => st . label . startsWith ( core . LOCAL_CLEANUP_FAILED_PREFIX ) ) ] ) . toEqual ( [ "synced" , false ] )
868+ expect ( await core . readSecret ( "github" ) ) . toBeUndefined ( )
850869 } )
851870
852871 test ( "a record that cannot be written after the workspace accepted the upload is reported, and a retry updates the same connection" , async ( ) => {
@@ -2868,6 +2887,12 @@ describe("the CLI passes --share through and reports shared", () => {
28682887 await ( SyncCommand . handler as any ) ( { provider : "github" , share : true , json : true } )
28692888 expect ( sync . mock . calls [ 0 ] [ 4 ] ) . toBe ( true )
28702889 expect ( JSON . parse ( logs [ logs . length - 1 ] ) . results [ 0 ] . shared ) . toBe ( true )
2890+ // Text output shows a local cleanup warning on a failed sync too, as --json carries it.
2891+ const warning = `${ core . LOCAL_CLEANUP_FAILED_PREFIX } disk full. Run altimate integrations sync github to remove it.`
2892+ sync . mockResolvedValue ( { id : "github" , result : "failed" , reason : "boom" , steps : [ { label : warning , ok : false } ] } )
2893+ logs . length = 0
2894+ await ( SyncCommand . handler as any ) ( { provider : "github" , json : false } )
2895+ expect ( logs . some ( ( l ) => clean ( l ) . includes ( warning ) ) ) . toBe ( true )
28712896 } finally {
28722897 for ( const sp of [ log , connect , sync , info ] ) sp . mockRestore ( )
28732898 process . exitCode = 0
0 commit comments