The S&P 500 and the Nasdaq indexes logged their sixth consecutive weekly advances, their longest run of weekly gains since October 2024.