@@ -67,43 +67,46 @@ test('runHarmonyHdc forwards a binding abort signal to an in-flight HDC command'
6767 assert . equal ( mockRunCmd . mock . calls [ 0 ] ?. [ 2 ] ?. signal , controller . signal ) ;
6868} ) ;
6969
70- /** Creates `<root>/default/openharmony/toolchains/hdc` as an executable, like DevEco lays out. */
71- async function seedToolchain ( root : string ) : Promise < string > {
72- const toolchains = path . join ( root , 'default' , 'openharmony' , 'toolchains' ) ;
73- await fs . mkdir ( toolchains , { recursive : true } ) ;
74- const hdc = path . join ( toolchains , 'hdc' ) ;
70+ /** HDC_SDK_PATH names the toolchains directory itself, so `HDC_SDK_PATH/hdc` must exist. */
71+ async function seedDirectToolchain ( root : string ) : Promise < string > {
72+ await fs . mkdir ( root , { recursive : true } ) ;
73+ const hdc = path . join ( root , 'hdc' ) ;
7574 await fs . writeFile ( hdc , '#!/bin/sh\nexit 0\n' , 'utf8' ) ;
7675 await fs . chmod ( hdc , 0o755 ) ;
7776 return root ;
7877}
7978
80- /** HDC_SDK_PATH names the toolchains directory itself, so `HDC_SDK_PATH/hdc` must exist. */
81- async function seedDirectToolchain ( root : string ) : Promise < string > {
82- await fs . mkdir ( root , { recursive : true } ) ;
83- const hdc = path . join ( root , 'hdc' ) ;
79+ /** DevEco's home joins `default/openharmony/toolchains`; the command-line-tools root adds `sdk` first. */
80+ async function seedNestedToolchain ( root : string , ...segments : string [ ] ) : Promise < string > {
81+ const toolchains = path . join ( root , ...segments , 'default' , 'openharmony' , 'toolchains' ) ;
82+ await fs . mkdir ( toolchains , { recursive : true } ) ;
83+ const hdc = path . join ( toolchains , 'hdc' ) ;
8484 await fs . writeFile ( hdc , '#!/bin/sh\nexit 0\n' , 'utf8' ) ;
8585 await fs . chmod ( hdc , 0o755 ) ;
8686 return root ;
8787}
8888
8989test ( 'ensureHarmonyToolchainPathConfigured prepends every root holding an hdc binary' , async ( ) => {
9090 const hdcSdkRoot = await seedDirectToolchain ( mkdtempForTestSync ( 'agent-device-hdc-sdk-' ) ) ;
91- const devecoRoot = await seedToolchain ( mkdtempForTestSync ( 'agent-device-hdc-deveco-' ) ) ;
92- // A declared root without an hdc executable must not join PATH.
93- const emptyRoot = mkdtempForTestSync ( 'agent-device-hdc-empty-' ) ;
91+ const devecoRoot = await seedNestedToolchain ( mkdtempForTestSync ( 'agent-device-hdc-deveco-' ) ) ;
92+ const cmdlineRoot = await seedNestedToolchain (
93+ mkdtempForTestSync ( 'agent-device-hdc-cmdline-' ) ,
94+ 'sdk' ,
95+ ) ;
9496
9597 const env : NodeJS . ProcessEnv = {
9698 PATH : '/usr/bin' ,
9799 HDC_SDK_PATH : hdcSdkRoot ,
98100 DEVECO_SDK_HOME : devecoRoot ,
99- HARMONYOS_COMMAND_LINE_TOOLS : emptyRoot ,
101+ HARMONYOS_COMMAND_LINE_TOOLS : cmdlineRoot ,
100102 } ;
101103
102104 await ensureHarmonyToolchainPathConfigured ( env ) ;
103105
104106 assert . deepEqual ( ( env . PATH ?? '' ) . split ( path . delimiter ) , [
105107 hdcSdkRoot ,
106108 path . join ( devecoRoot , 'default' , 'openharmony' , 'toolchains' ) ,
109+ path . join ( cmdlineRoot , 'sdk' , 'default' , 'openharmony' , 'toolchains' ) ,
107110 '/usr/bin' ,
108111 ] ) ;
109112} ) ;
@@ -113,6 +116,7 @@ test('ensureHarmonyToolchainPathConfigured leaves PATH untouched when no root ho
113116 PATH : '/usr/bin' ,
114117 HDC_SDK_PATH : ' ' ,
115118 DEVECO_SDK_HOME : mkdtempForTestSync ( 'agent-device-hdc-none-' ) ,
119+ HARMONYOS_COMMAND_LINE_TOOLS : mkdtempForTestSync ( 'agent-device-hdc-none-' ) ,
116120 } ;
117121
118122 await ensureHarmonyToolchainPathConfigured ( env ) ;
0 commit comments