GHCi: Fix order of `PackageDBFlag`s for interactive home unit
Fixes #27640 (closed)
Reverse the package db stacks before calculating the longest common prefix.
Adds a regression test so this doesn't happen again. Verified this test fails without the patch.