feat(coding-agent/eval): enabled top-level await execution in Python runner cells

- Added a persistent asyncio event loop and coroutine-aware compiled-code execution for runner cells.
- Enabled compiling notebook cells with top-level await flags and awaiting coroutine results before rendering.
- Added an integration test confirming top-level await works across kernel cells with preserved state.
This commit is contained in:
can1357
2026-05-15 02:12:34 +02:00
parent 92c42f44f7
commit 7cd05c374c
2 changed files with 60 additions and 11 deletions
@@ -90,6 +90,24 @@ describe.skipIf(!SHOULD_RUN)("python runner subprocess", () => {
}
});
it("supports top-level await across cells", async () => {
using tempDir = TempDir.createSync("@python-runner-await-");
const kernel = await PythonKernel.start({ cwd: tempDir.path() });
try {
const first = await executePythonWithKernel(
kernel,
["import asyncio", "x = await asyncio.sleep(0, result=21)", "x * 2"].join("\n"),
);
expect(first.exitCode).toBe(0);
expect(first.output).toContain("42");
const second = await executePythonWithKernel(kernel, "x + 1");
expect(second.exitCode).toBe(0);
expect(second.output).toContain("22");
} finally {
await kernel.shutdown();
}
});
it("translates %pwd magic to the user namespace", async () => {
using tempDir = TempDir.createSync("@python-runner-magic-");
const kernel = await PythonKernel.start({ cwd: tempDir.path() });