@@ -18,9 +18,10 @@ async function globalTeardown() {
1818 LoginTestUtil . resetCache ( ) ;
1919 console . log ( '✅ Test cache cleared' ) ;
2020
21- // Clean up based on test notebook directory configuration
21+ // Clean up test notebooks
22+ // CI: Uses ZEPPELIN_E2E_TEST_NOTEBOOK_DIR which gets cleaned up by workflow
23+ // Local: Uses API-based cleanup to avoid server restart required for directory changes
2224 if ( ! process . env . CI ) {
23- // Use dedicated test directory (typically in CI)
2425 await cleanupTestNotebooks ( ) ;
2526 }
2627}
@@ -35,15 +36,30 @@ async function cleanupTestNotebooks() {
3536 const response = await fetch ( `${ baseURL } /api/notebook` ) ;
3637 const data = await response . json ( ) ;
3738
39+ // Debug: Log the API response structure
40+ console . log ( '🔍 API Response structure:' , JSON . stringify ( data , null , 2 ) ) ;
41+
3842 if ( ! data . body || ! Array . isArray ( data . body ) ) {
3943 console . log ( 'No notebooks found or invalid response format' ) ;
4044 return ;
4145 }
4246
43- // Filter notebooks that start with "Test Notebook" (created by createTestNotebook)
44- const testNotebooks = data . body . filter (
45- ( notebook : { path : string } ) => notebook . path && notebook . path . startsWith ( '/Test Notebook ' )
46- ) ;
47+ // Debug: Log individual notebook structure
48+ if ( data . body . length > 0 ) {
49+ console . log ( '🔍 Sample notebook structure:' , JSON . stringify ( data . body [ 0 ] , null , 2 ) ) ;
50+ }
51+
52+ // Simple filter for test notebooks and folders with unified naming
53+ const isTestItem = ( item : { id : string ; path : string } ) => {
54+ const path = item . path || '' ;
55+ // Match test items by Date.now() pattern (13-digit timestamp)
56+ const hasTimestamp = / \d { 13 } / . test ( path ) ;
57+ const isTestPattern =
58+ path . includes ( 'TestNotebook_' ) || path . includes ( 'TestFolder_' ) || path . includes ( 'TestFolderRenamed_' ) ;
59+ return hasTimestamp && isTestPattern ;
60+ } ;
61+
62+ const testNotebooks = data . body . filter ( isTestItem ) ;
4763
4864 if ( testNotebooks . length === 0 ) {
4965 console . log ( '✅ No test notebooks to clean up via API' ) ;
0 commit comments