The Senate voted yesterday to test immigrants for the AIDS virus, echoing President Reagan's plan to include immigrants in a screening program to identify people with the deadly disease.

By 96 to 0, the Senate agreed to add the testing provision to a $9.4 billion supplemental spending bill that is intended to provide money to finance dozens of government programs for the rest of the fiscal year, which ends Sept. 30.

Last night, on a 71-to-23 vote, the Senate approved the spending measure. It first had to waive the fiscal 1987 budget, which it did, 64 to 32.

The waiver, which failed in two earlier votes, was needed so the Senate could consider the supplemental appropriations bill, which increases spending $2.6 billion beyond Congress' self-imposed limit.

The AIDS measure directs Reagan to act by Aug. 31 to add acquired immune deficiency syndrome to the government's list of dangerous contagious diseases and to require that immigrants be tested for it.

The testing provision would also apply to illegal immigrants seeking to remain in the United States legally.

"The people of the United States will hold this Congress responsible if we don't do something about it," said Sen. Jesse Helms (R-N.C.), sponsor of the amendment.

Earlier this week, Reagan ordered AIDS tests for immigrants and inmates at federal prisons, and urged states to offer "routine testing" for couples seeking marriage licenses and patients at clinics for sexually transmitted diseases or drug abuse.

Other sections of the supplemental spending bill include more than $50 million for programs to help supply drugs to treat AIDS patients and for educational efforts to help limit spread of the disease.

The testing provision is nearly "beyond dispute," said Sen. John C. Danforth (R-Mo.), but he added that AIDS deserves a more thorough debate by the Senate to determine how victims of the disease should be treated and how federal money should be spent to help them.

The major item in the $9.4 billion supplemental spending bill is the $6.7 billion set aside for the Commodity Credit Corp., the government's "bank" for farm subsidy programs. The agency ran out of money May 1.

"This is in fact an urgent, must-pass bill," said Sen. J. Bennett Johnston (D-La.) shortly before the vote. "It needs to pass. It needs to pass now."

But Sen. Phil Gramm (R-Tex.) said the bill costs too much and should be sent back to the Appropriations Committee for revisions to reduce spending.

"If we can't hold the line on seafood promotion and weed research . . . and aid to Poland, we can't hold the line at all," Gramm said, referring to some of the nonemergency items included in the so-called urgent supplemental spending bill.

The bill also allocates money to keep dozens of other programs running through Sept. 30, and to meet government contributions for federal workers' retirement funds and to finance their pay raises.

The House has passed a $9.2 billion version of the supplemental spending plan.

Once the Senate completes work, the two branches must agree on a final measure to be sent to Reagan for his approval.