Even if they give you immunity for the specific thing you’re testifying about, what if your testimony reveals that you’re guilty of some completely different crime?
https://en.wikipedia.org/wiki/Witness_immunity seems to be the reference. Seems to cover the exact issue: "In the United States, the prosecution may grant immunity in one of two forms. Transactional immunity, colloquially known as "blanket" or "total" immunity, completely protects the witness from future prosecution for crimes related to his or her testimony. Use and derivative use immunity prevents the prosecution only from using the witness's own testimony or any evidence derived from the testimony against the witness. However, if the prosecutor acquires evidence substantiating the crime independently of the witness's testimony, the witness may then be prosecuted."
Immunity, like double jeopardy, is limited to a given court. For example a state prosecutor can grant immunity in exchange for testimony, but in the case of overlap with federal law the witness can still be prosecuted in a federal court.
If that is not how immunity works, then how can the government force anyone to testify? The government does not know what (unrelated) crimes I may have to confess to in order to give truthful testimony on the matter in question.