A lab mate of mine, who had already accepted a professorship at another university, gave me one of his start-up projects. By agreement, as I built the experiment, I sent him copies of my drawings, circuit diagrams, and source code, letting him reproduce my work almost concurrently.
That became my thesis, and the technical work became my ticket to industry.
Often, dissertations bear little resemblance to the proposed project.
There was high attrition in between this step and getting the PhD.
The other end, where the student is basically done except for the writing, is less risky. One reason is that professors are strongly discouraged from letting a student fail a thesis. When I was ready to defend my thesis, I had to get permission from my committee to do so, and their signature indicated that they considered my work to be defensible. So the defense was in fact a formality. Failures at that point, that I know about, had to do with students getting caught fudging their work.