Try listHistory with -pruneDagObjects 1, which will make it stop if it reaches a different shape. I'm not sure if there are any other gotchas, but that's what the input/output button in the toolbar uses. With PyMEL:
import pymel.core as pm
for node in pm.ls(sl=True):
print(node.listHistory(pruneDagObjects=True, type='blendShape'))
I wouldn't use getChain. It looks like an ancient bit of MEL that nothing in Maya itself is actually using (usually a bad sign), and it looks like it hasn't been updated for 2022. It still assumes groupParts nodes exist for deformers, which they usually no longer do, and at a quick look it seems to make bad assumptions about groupParts nodes (it seems to assume there will never be two groupParts nodes in a row, which happened all the time). That's probably why it's not returning results in the correct order.