Time `IPythonCodeMode` timeout tests on a clock the test moves, so a loaded runner cannot make them overrun
Three IPythonCodeMode tests that failed intermittently in merge-queue and main CI timed cells against real 0.3–0.5 s timeouts, which a trivial cell can overrun on a loaded runner. (This PR first also serialized IPythonKernel's shutdowns; #12347 landed the same fix on main, so that part is gone after merging main.)
test_timeout_interrupts_the_code_and_keeps_the_state(5 failed runs, e.g. run 40897488656:NameError: name 'survives_timeout' is not defined): the first cell overran its timeout and was interrupted before assigning.test_code_that_ignores_the_interrupt_gets_a_new_kernel(3 failed runs, e.g. run 41084598941: the old kernel was still alive): the timeout could pass before the cell ignoredSIGINT, so the interrupt simply stopped it.test_time_in_tool_calls_does_not_count_toward_the_timeout: a real 0.6 s sleep against a 0.5 s timeout.
A kernel_clock fixture stands in for the time the kernel module times cells by and stands still, so a deadline passes only when the test moves it. The first two tests move it once the slow cell has opened a FIFO, which tells the test it is running (or, for the second, that it ignores SIGINT; the clock then races so the interrupt's grace passes too, and the lost state is checked in a run without a timeout). The third moves it in its tool instead of sleeping. A finally releases a still-waiting FIFO reader so a failing run can't hang the test.
Verification:
- The three tests and
tests/harness/ipython_code_modepass; ruff and pyright are clean. - With a kernel clock that loses 0.3 s per reading, the old keep-state test fails and the new one passes.
What changes for existing users: nothing, test-only.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.