Most cheap generic drugs are imported by the containerload, so simply create an arbitrary "batch" from each instance of importation. If the manufacturer is decent and has its own batch number, then the label could read
"Manufacturer batch: XXXX FDA Import of Record batch: YYYY."
Drugs that are imported in more specialized ways -- e.g. by small-volume refrigerated air freight -- are, as a general rule, far more expensive and batches are correspondingly smaller. The above paradigm would still work, where each importation instance is, for the FDA's purposes, a batch.
Testing fees, which shouldn't amount to more than a few thousand bucks per import, can be the responsibility of the importer -- so as to dissuade importers from receiving small batch after small batch.
If there's a manufacturing defect, the manufacturer -- after losing a couple of batches or having them returned to sender, and having paid for multiple transit and testing costs -- should wise up.
In any case, this would absolutely protect the US pharmaceutical supply chain without pushing unnecessary and excessively onerous requirements onto manufacturers. How foreign facilities manufacture drugs should not be the FDA's concern; drugs are chemical systems and chemicals are easily amenable to testing as things in themselves.
It's not difficult. There are known quantitative and qualitative testing methods for finished drug products, and these usually cost anywhere from a couple hundred to a few thousand dollars. In other words: It's typically very cheap.
So say a company imports 1M doses, and say you're an FDA inspector. At the port of entry, you take a statistically valid sample from that batch of doses, and you subject them to those tests. (This could be at an FDA/Customs lab or a third party lab -- in any case, the importer pays.) If there's a problem, you either test additional samples, or dispose of the batch summarily with a note to the importer as to what you've found.
Testing every import shipment, instead of stationing FDA inspectors overseas, would do more to improve the quality and availability of drugs, and more to reduce costs.
As things stand right now, a lot of drug companies don't want anything to do with the USA simply because they don't want the FDA getting into their business, inspecting their facilities, etc. It is a great, and wholly unwarranted and unnecessary, burden.
> how would any contamination be traced by the manufacturer?
That's not the FDA's problem. A batch of drugs is a thing in itself. A metformin capsule is a metformin capsule regardless of who made it and how.
But of course there would be import records and any halfway competent manufacturer would be able to tie a shipment to a production run.