Tests that pass on the tip of a branch say nothing about the commits underneath. --exec runs a command after every commit during a rebase, so each one gets checked.
The docs say --exec appends an exec line after each line creating a commit, and any command that fails interrupts the rebase. It also has a short form, -x:
git rebase --exec "make test" origin/main
You do not need -i. The docs mention that it uses the interactive machinery internally but can run without it. The command runs from the root of the working tree, and for a branch of three commits Git shows six steps, three picks and three runs of your command. To run several commands, join them with && or repeat the option.
When the command fails on a commit, Git stops right there and prints:
warning: execution failed: make test
You can fix the problem, and then run
git rebase --continue
Fix the code, run git commit --amend, then git rebase --continue and the check continues with the next commit. It is a good way to keep a branch bisectable before you open a pull request, because every commit has been through the same test.
Caveats: it rewrites the commits, so keep it away from history other people already have. A slow suite runs once per commit, so use a fast check such as a linter or a single test file. The docs also note that with --autosquash, exec lines are not added for the intermediate commits of a squash or fixup series, only at the end of it.
Further reading: git-rebase documentation