i've modified the commit with a couple goals. + make the bug fixing part of the diff as small as possible. + made the new tests look more like existing ones. + rebased onto the head of the emacs-29 branch pulled in earlier today.