SAN FRANCISCO/BERLIN--A few camouflaged Audis arrived secretly from Germany early this year at a facility of electric-vehicle maker Rivian in California, where some 30 engineers stripped the electronics and fitted them with the U.S. startup's harnesses and modules. Intense testing followed at the Palo Alto, California, facility. The tests concerned how the U.S. startup's architecture and software - which control virtually every function - would work in the German cars. The mission: to see whether future EVs from Audi parent Volkswagen could benefit from Rivian's advanced technology, two people close to the situation told Reuters. A third confirmed that some Audis were shipped to California. The result: Europe's biggest carmaker said on Tuesday it would pump as much as $5 billion into Rivian as the two automakers agreed to a technology joint venture. The closely guarded deal took the auto industry and investors by surprise. Details on how it came about have not previously been reported. "I think it's an accomplishment in its own right that this hasn't leaked, given the amount of work that's already happened ... and the number of people involved across our teams," Rivian CEO RJ Scaringe told Reuters. Rivian and Volkswagen sought to be "super secretive," aiming "to see if the electrical topology and everything would actually work and if they could pull it off," one of the sources told Reuters. The three sources asked not to be named because they were not authorized to provide these details to media. Volkswagen did not respond to requests for comment. A Rivian spokesperson said in an email it was company policy "not to comment on details of private internal updates." The deal is crucial for both companies. For Rivian, known for its R1S SUVs and R1T pickups, it provides the financial lifeline it needs to survive a sharp slowdown in EV demand, build its less expensive R2 SUVs and, it hopes, turn profitable. It may also help the company obtain better deals from suppliers while procuring components in bigger volumes with the backing of Volkswagen and its brands including Audi, Porsche, Lamborghini and Bentley. Rivian shares jumped 23% on Wednesday. On Thursday, they closed 1.8% lower after the company estimated fewer EV deliveries for the June quarter than analysts were expecting. For Volkswagen, the deal brings low-cost, high-performance EV technology that traditional automakers have struggled to master. Work at the group's software unit, Cariad - set up in 2020 with the idea of rivalling similar capabilities by Tesla - has been riddled with delays and losses partly seen as a result of sluggish decision-making by the group's management. The talks that led to the dramatic tie-up began, Scaringe said, when he and Volkswagen CEO Oliver Blume met privately at Porsche's experience center in Atlanta. Two sources said the meeting was in August last year. "We just went deep, talking product and comparing notes on the things we like," Scaringe told reporters. "There was immediate realization that we have some shared vehicle interests. Quickly that led to a serious conversation as to how can we look at working together." The companies got to work straight away, with a Rivian team visiting Volkswagen in Germany last fall. The testing to make sure everything worked together was "like a scrimmage," Scaringe told a company town hall on Wednesday, according to one source. Another trip to Germany followed early this year with lawyers and software experts, this person said. Volkswagen under Blume, who became CEO in 2022, was less "dogmatic" than it had been previously about what it should do itself and where it should seek external partners, a fourth source told Reuters. To overcome the difficulty of integrating starkly different work cultures that often plague such deals, Volkswagen leadership agreed to embrace Rivian's agility, its software chief Wassym Bensaid told analysts on Tuesday. He said that "very clear rules and responsibilities" had been set for the JV. His comments were aimed at alleviating VW investor concerns about whether the company's traditional, more methodical approach to automaking and multiple supplier contracts would clash with Rivian's nimble software approach. VW shares fell 2% on Wednesday. VW investors also worry about Volkswagen spending more when it already has high capital expenditures compared with peers. Certainty on the deal came after Rivian ran tests on the Audis in Palo Alto, which arrived in the first quarter of the year, leading to financial talks over the past couple of months, one source said. A fifth person, close to Volkswagen, said the companies still need to conduct full-fledged tests to make sure VW vehicles with Rivian software can drive with complete functionality. "This isn't as if it's something that we thought of a month ago," Scaringe told Reuters on Tuesday. "This has been a long work in progress." For Scaringe, who grew up as a Porsche enthusiast and restored classic 356s, it was a natural fit. "To be able to see a Porsche on the road that has our technology in them, I couldn't be more excited," he said.