How does a CFI know what endorsements to give?
In general, a flight instructor must demonstrate sufficient knowledge so as to be able to provide the proper endorsements for his students. This is covered both in AC 61-65 and in the Flight Instructor Practical Test Standards Task M:


  Task M: Logbook Entries and Certificate Endorsements
  
  References: 14 CFR part 61, AC 61-65.
  
  Objective: To determine that the applicant exhibits instructional
  knowledge of the elements related to logbook entries
  and certificate endorsements by describing:
  
  
  Required logbook entries for instruction given.
  Required student pilot certificate endorsements, including
  appropriate logbook entries.
  Preparation of a recommendation for a pilot practical test,
  including appropriate logbook entry for:
  a. Initial pilot certification.
  b. Additional pilot certification.
  c. Additional aircraft qualification.
  Required endorsement of a pilot logbook for the satisfactory
  completion of the required FAA flight review.
  Required flight instructor records.
  


Regarding the question: 


  Let's say someone has a helicopter license and wants to get their private pilot? Do they have to take a knowledge test?


According to 61.63:


  § 61.63 Additional aircraft ratings (other than for ratings at the airline transport pilot certification level).
  
  (b) Additional aircraft category rating. A person who applies to add a category rating to a pilot certificate:
  
  (4) Need not take an additional knowledge test, provided the applicant holds an airplane, rotorcraft, powered-lift, weight-shift-control aircraft, powered parachute, or airship rating at that pilot certificate level.


So a private pilot looking to add an additional category rating at the same certificate level need not take the aeronautical test.

Regarding the question:


  What if someone is a sports pilot and wants to upgrade to a private pilot, what do they have to do? 


you can find the answer in part 61.103:


  Subpart E—Private Pilots
  
  §61.103   Eligibility requirements: General.
  
  To be eligible for a private pilot certificate, a person must:
  
  (e) Pass the required knowledge test on the aeronautical knowledge areas listed in §61.105(b) of this part.
  
  (j) Hold a U.S. student pilot certificate, sport pilot certificate, or recreational pilot certificate.


So a sport pilot upgrading his certificate to private pilot must take the private pilot test.