@@ -47,11 +47,13 @@ const createTempAstrBotSource = async ({ pyprojectVersion = '1.2.3', runtimeVers
4747 const runtimeVersionPath = resolveAstrbotRuntimeVersionPath ( { sourceDir : tempDir } ) ;
4848 const configDir = path . dirname ( runtimeVersionPath ) ;
4949 await mkdir ( configDir , { recursive : true } ) ;
50+ await mkdir ( path . join ( tempDir , 'astrbot' ) , { recursive : true } ) ;
5051 await writeFile (
5152 path . join ( tempDir , 'pyproject.toml' ) ,
5253 `[project]\nname = "AstrBot"\nversion = "${ pyprojectVersion } "\n` ,
5354 'utf8' ,
5455 ) ;
56+ await writeFile ( path . join ( tempDir , 'astrbot' , '__init__.py' ) , `__version__ = "${ runtimeVersion } "\n` , 'utf8' ) ;
5557 await writeFile (
5658 runtimeVersionPath ,
5759 `import os\n\nVERSION = "${ runtimeVersion } "\n` ,
@@ -99,6 +101,19 @@ test('readAstrbotRuntimeVersion reads static VERSION from default.py', async ()
99101 }
100102} ) ;
101103
104+ test ( 'readAstrbotRuntimeVersion resolves VERSION imported from package __version__' , async ( ) => {
105+ const tempDir = await createTempAstrBotSource ( { runtimeVersion : '4.26.1' } ) ;
106+ try {
107+ const runtimeVersionPath = resolveAstrbotRuntimeVersionPath ( { sourceDir : tempDir } ) ;
108+ await writeFile ( runtimeVersionPath , `from astrbot import __version__\n\nVERSION = __version__\n` , 'utf8' ) ;
109+
110+ const version = await readAstrbotRuntimeVersion ( { sourceDir : tempDir } ) ;
111+ assert . equal ( version , '4.26.1' ) ;
112+ } finally {
113+ await rm ( tempDir , { recursive : true , force : true } ) ;
114+ }
115+ } ) ;
116+
102117test ( 'validateAstrbotRuntimeVersion rejects 0.0.0 runtime version' , async ( ) => {
103118 const tempDir = await createTempAstrBotSource ( { runtimeVersion : '0.0.0' } ) ;
104119 try {
0 commit comments