A veteran Air Force investigator testified yesterday that he repeatedly assured 2nd Lt. Christopher M. Cooke of complete immunity from prosecution if he would tell the truth about his unauthorized contacts with Soviet diplomats here.

Lt. Col. Jerome E. Hoffman of the Air Force's Office of Special Investigations said that as far as he was concerned Cooke lived up to his end of the bargain with the successful completion of a polygraph examination May 22.

The testimony marked a last-ditch effort by Cooke's attorneys to prevent his court-martial at Andrews Air Force Base on three counts of espionage and 11 counts of illicit visits and conversations with members of the Soviet Embassy here since June, 1980.

The precise secrets he is accused of having given the Soviets remain classified, but an Air Force memo dated last May 10 and cited briefly at yesterday's hearing said, "A major breach of security had occurred, the worst perhaps in the history of the Air Force."

Formerly deputy commander of an Air Force Titan missile crew, Cooke, 26, faces a maximum of 52 years in federal prison if convicted on all counts. The motion to dismiss represents his main defense. As his lawyer said in one pretrial pleading, "Cooke is no hero, and the defense would not claim him to be so."

Cooke's defense lawyers maintain that "a higher goal is necessary here than just prosecuting Christopher Cooke. That goal is the honor of the United States government in living up to its promise."

"The Air Force has conspired to take away from Lt. Cooke what was his--his immunity," chief defense attorney F. Lee Bailey protested yesterday at what amounted to a pretrial hearing at Andrews.

Cooke's court-martial is scheduled to begin this week unless the military judge assigned to the case, Lt. Col. David Orser, dismisses the case. The proceedings are being held in the 1776 Air Base Wing's headquarters building.

Cooke sat pale and tight-lipped between his military and civilian lawyers. His uniform looked large on him as he left the building under guard for the day. He is being held at Fort Meade.

Capt. Charles H. Williams, an Air Force prosecutor at the hearing, told the court that the court-martial would require closed sessions at times since it will deal with classified data.

Williams mentioned such data as the "design capabilities and vulnerabilities of the Titan II weapons system . . . attack options and their objectives and sub-options . . . cryptological procedures" as well as transcripts and tapes of electronic surveillance operations aimed at the Soviet Embassy.

Orser said he intends to "have the trial open to the public to the maximum extent possible." But he found himself moving into a one-hour closed session this afternoon before taking up the motion to dismiss.

Bailey depicted Brig. Gen. C. Claude Teagarden, primary legal adviser for Strategic Air Command headquarters at Offutt Air Force Base in Nebraska, and SAC's recently retired commander, Gen. Richard H. Ellis, as the men chiefly responsible for abrogating the Air Force agreement not to prosecute Cooke.

Bailey charged that Ellis "became furious" after learning of Cooke's admissions under the immunity arrangement last May "and from that point on, looked for ways to breach the contract."

The Air Force contends that promises of immunity for Cooke had not been authorized by Ellis or other appropriate officers.

In addition, according to Bailey, Teagarden recently began contending that he conditioned his verbal assurance of immunity on the understanding that an initial statement given investigators by Cooke last May 7 would prove truthful.

Investigator Hoffman, however, said Teagarden explicity told him by telephone May 9, a few hours before Cooke began to cooperate, that Cooke effectively would be absolved from prosecution "regardless of the seriousness of his disclosures."

Hoffman, a veteran of 18 years in the special investigations office who served as Cooke's principal interrogator, said Teagarden expressed "some irritation" at being pressed about the matter, but explicitly informed Hoffman that the commander in chief of SAC, Ellis, "stands behind his decision."

Bailey suggested that the government changed its tune after realizing that it "might have immunized the only spy in the ring" and that, except for Cooke, there would be no one to prosecute.