@@ -1416,52 +1416,34 @@ export function consumerInW(): string {
14161416 // Test nx affected correctly identifies affected projects
14171417 console . log ( '[GRAPH-REACTION] Testing nx affected detection...' ) ;
14181418
1419- // Commit the file move changes so we have a second commit for HEAD~1 comparison
1420- execSync ( 'git add .' , {
1421- cwd : sharedWorkspace . path ,
1422- stdio : 'pipe' ,
1423- } ) ;
1424-
1425- // Check if there are changes to commit
1426- const gitStatus = execSync ( 'git status --porcelain' , {
1427- cwd : sharedWorkspace . path ,
1428- encoding : 'utf-8' ,
1429- stdio : 'pipe' ,
1430- } ) ;
1431- console . log (
1432- '[GRAPH-REACTION] Git status after add:' ,
1433- gitStatus . trim ( ) || '(no changes)' ,
1434- ) ;
1435-
1436- // Commit with --allow-empty only if no changes, otherwise commit normally
1437- if ( gitStatus . trim ( ) ) {
1438- execSync ( 'git commit -m "Move util.ts from lib-x to lib-w"' , {
1439- cwd : sharedWorkspace . path ,
1440- stdio : 'pipe' ,
1441- } ) ;
1442- console . log ( '[GRAPH-REACTION] ✓ File move changes committed' ) ;
1443- } else {
1444- execSync ( 'git commit --allow-empty -m "Move util.ts from lib-x to lib-w"' , {
1419+ // Use file-based nx affected detection (avoids git SHA contamination issues)
1420+ // This tests that nx affected correctly identifies projects based on changed files
1421+ const movedFilePath = `${ libW } /src/lib/util.ts` ;
1422+ const updatedIndexPath = `${ libX } /src/index.ts` ;
1423+ const affectedOutput = execSync (
1424+ `npx nx show projects --affected --files=${ movedFilePath } ,${ updatedIndexPath } ` ,
1425+ {
14451426 cwd : sharedWorkspace . path ,
1427+ encoding : 'utf-8' ,
14461428 stdio : 'pipe' ,
1447- } ) ;
1448- console . log ( '[GRAPH-REACTION] ✓ Empty commit created (no changes)' ) ;
1449- }
1450-
1451- // Verify git repository exists and has proper history
1452- const gitLogOutput = execSync ( 'git log --oneline' , {
1453- cwd : sharedWorkspace . path ,
1454- encoding : 'utf-8' ,
1455- stdio : 'pipe' ,
1456- } ) ;
1457- const commitCount = gitLogOutput . trim ( ) . split ( '\n' ) . length ;
1458- expect ( commitCount ) . toBeGreaterThanOrEqual ( 2 ) ;
1459- console . log (
1460- `[GRAPH-REACTION] ✓ Git repository has ${ commitCount } commits after move` ,
1429+ } ,
14611430 ) ;
14621431
1463- // Note: nx affected testing with --base is skipped due to git context contamination
1464- // in e2e environment. The core functionality (move + graph update) is validated above.
1432+ // Parse affected projects
1433+ const affectedProjects = affectedOutput
1434+ . trim ( )
1435+ . split ( '\n' )
1436+ . filter ( ( line ) => line . trim ( ) . length > 0 ) ;
1437+
1438+ console . log ( '[GRAPH-REACTION] Affected projects:' , affectedProjects ) ;
1439+
1440+ // Verify that lib-w is in affected projects (since it received the moved file)
1441+ expect ( affectedProjects ) . toContain ( libW ) ;
1442+ console . log ( '[GRAPH-REACTION] ✓ lib-w detected as affected (received moved file)' ) ;
1443+
1444+ // Verify that lib-x is in affected projects (since it had a file moved out)
1445+ expect ( affectedProjects ) . toContain ( libX ) ;
1446+ console . log ( '[GRAPH-REACTION] ✓ lib-x detected as affected (file moved out)' ) ;
14651447
14661448 console . log ( '[GRAPH-REACTION] All assertions passed ✓' ) ;
14671449 } , 120000 ) ; // 2 min: two graph generations + generator execution + assertions
0 commit comments