1515 */
1616
1717import { fileURLToPath } from 'node:url' ;
18+ import { join } from 'node:path' ;
19+ import { readdir } from 'node:fs/promises' ;
1820import { SourceTestkit } from '@salesforce/source-testkit' ;
21+ import { expect } from 'chai' ;
22+
23+ async function getAllFilePaths ( dir : string ) : Promise < string [ ] > {
24+ let filePaths : string [ ] = [ ] ;
25+ const entries = await readdir ( dir , { withFileTypes : true } ) ;
26+
27+ for ( const entry of entries ) {
28+ const fullPath = join ( dir , entry . name ) ;
29+ if ( entry . isFile ( ) ) {
30+ filePaths . push ( fullPath ) ;
31+ } else if ( entry . isDirectory ( ) ) {
32+ // eslint-disable-next-line no-await-in-loop
33+ filePaths = filePaths . concat ( await getAllFilePaths ( fullPath ) ) ;
34+ }
35+ }
36+ return filePaths ;
37+ }
1938
2039describe ( 'deploy metadata NUTs' , ( ) => {
2140 let testkit : SourceTestkit ;
@@ -40,9 +59,20 @@ describe('deploy metadata NUTs', () => {
4059
4160 describe ( '--metadata flag' , ( ) => {
4261 it ( 'should deploy ApexClass' , async ( ) => {
62+ process . env . SF_MDAPI_TEMP_DIR = 'myTempDirectory' ;
4363 await testkit . modifyLocalGlobs ( [ 'force-app/main/default/classes/*.cls' ] , '// comment' ) ;
4464 await testkit . deploy ( { args : '--metadata ApexClass' } ) ;
4565 await testkit . expect . filesToBeDeployed ( [ 'force-app/main/default/classes/*' ] ) ;
66+
67+ // no illegal file paths should be generated when using SF_MDAPI_TEMP_DIR
68+ // Users/william.ruemmele/projects/oss/plugin-deploy-retrieve/test_session_1761066173823d94ce455705e3fe5/dreamhouse-lwc/myTempDirectory/2025-10-21T17_03_52.245Z_deploy/metadata/package.xml
69+ expect (
70+ ( await getAllFilePaths ( join ( testkit . projectDir , process . env . SF_MDAPI_TEMP_DIR ) ) ) . every ( ( path ) =>
71+ / [ < > : " / \\ | ? * ] / . test ( path )
72+ )
73+ ) . to . be . true ;
74+
75+ delete process . env . SF_MDAPI_TEMP_DIR ;
4676 } ) ;
4777
4878 it ( 'should deploy named ApexClass' , async ( ) => {
0 commit comments