diff --git a/src/__tests__/shared/templateVariables.test.ts b/src/__tests__/shared/templateVariables.test.ts index f5ccf018..de6f310e 100644 --- a/src/__tests__/shared/templateVariables.test.ts +++ b/src/__tests__/shared/templateVariables.test.ts @@ -655,8 +655,8 @@ describe('substituteTemplateVariables', () => { }), }); const result = substituteTemplateVariables('Name: {{PROJECT_NAME}}', context); - // split('/').pop() on '/path/to/project/' gives '' - expect(result).toBe('Name: '); + // split(/[/\\]/).filter(Boolean).pop() correctly handles trailing slashes + expect(result).toBe('Name: project'); }); it('should handle Windows-style paths', () => { @@ -666,10 +666,9 @@ describe('substituteTemplateVariables', () => { cwd: 'C:\\Users\\dev\\project', }), }); - // Windows paths don't split on '/', so PROJECT_NAME would be the full path + // Windows paths now split on both / and \ to extract the last segment const result = substituteTemplateVariables('{{PROJECT_NAME}}', context); - // Since split('/') doesn't work on backslashes, it returns the full path - expect(result).toBe('C:\\Users\\dev\\project'); + expect(result).toBe('project'); }); it('should handle very long templates efficiently', () => { diff --git a/src/shared/templateVariables.ts b/src/shared/templateVariables.ts index 47de8e09..acd6a074 100644 --- a/src/shared/templateVariables.ts +++ b/src/shared/templateVariables.ts @@ -123,11 +123,11 @@ export function substituteTemplateVariables( 'CWD': session.cwd, 'AUTORUN_FOLDER': autoRunFolder || session.autoRunFolderPath || '', - // Legacy aliases (deprecated - kept for backwards compatibility) + // Aliases (not documented in TEMPLATE_VARIABLES but still supported for internal use and backwards compatibility) 'SESSION_ID': session.id, 'SESSION_NAME': session.name, // Alias for TAB_NAME 'PROJECT_PATH': session.fullPath || session.projectRoot || session.cwd, - 'PROJECT_NAME': (session.fullPath || session.projectRoot || session.cwd).split('/').pop() || '', + 'PROJECT_NAME': (session.fullPath || session.projectRoot || session.cwd).split(/[/\\]/).filter(Boolean).pop() || '', // Document variables (for Auto Run) 'DOCUMENT_NAME': documentName || '',