Here is a PR to add a static test vector that tests this logic in bitcoin core:
Here is what the patch looks like to fix this in bitcoin-s: