From AI for Science to Agentic Science: A Survey on Autonomous Scientific Discovery