http://69.10.163.89/stations.htm is somebody's decent overview of the types of smog check stations in California.
I think the racket works like this: For a repair shop to be authorized to certify gross polluter vehicles as repaired they need a special "GPC" certification from the state. There are only a few hundred places with that certification. Your failure on the smog test is a scarlet letter. The GPC stations are the only ones authorized to perform the test, and they won't do the test unless you let them make repairs. Licensed repair shops that do not have the GPC certificate can't work on a known gross polluter. That's buried in the code somewhere.
I suppose you could drop in your own new engine or have your brother-in-law do it and not mention the fact that you've worked on the vehicle when you take it to the GPC station. There's nothing specific in the law that prevents that, but you don't have the option of having a "real" mechanic like the nice guy at the Chevron station on the corner do the repairs. I guarantee the GPC station will find something to charge you hundreds or thousands of dollars for, they always do. They're a bunch of crooks because they have a steady stream of captive clientele courtesy of the "test-only" stations.