pi-mono/packages/coding-agent/test/suite/regressions/tree-during-streaming.test.ts
Thomas Mustier cefa40ed8f
***WIP it's a PoC *** fix(coding-agent): guard tree navigation during responses (#7022)
* fix(coding-agent): guard tree navigation during responses

* fix(coding-agent): simplify tree navigation regression

* fix(coding-agent): abort active run on session replacement and tree navigation

Session replacement (resume, new, fork, import) now settles the active
response in teardownCurrent before disposing the outgoing session, so the
aborted turn and its tool results persist instead of leaving a dangling
tool call. Tree navigation aborts the active response directly once the
user commits, without a confirmation gate.
2026-07-28 14:46:30 +02:00

35 lines
1.2 KiB
TypeScript

import { fauxAssistantMessage } from "@earendil-works/pi-ai";
import { describe, expect, it } from "vitest";
import { userMsg } from "../../utilities.ts";
import { createHarness } from "../harness.ts";
describe("tree navigation during an active response", () => {
it("rejects navigation without changing the active leaf", async () => {
const harness = await createHarness();
const targetId = harness.sessionManager.appendMessage(userMsg("first"));
let navigationResult: unknown;
let leafUnchanged = false;
try {
// Navigate from inside the response factory, while the run is active.
harness.setResponses([
async () => {
const activeLeafId = harness.sessionManager.getLeafId();
navigationResult = await harness.session
.navigateTree(targetId, { summarize: false })
.catch((error) => error);
leafUnchanged = activeLeafId !== targetId && harness.sessionManager.getLeafId() === activeLeafId;
return fauxAssistantMessage("response");
},
]);
await harness.session.prompt("second");
expect(navigationResult).toEqual(
new Error("Wait for the current response to finish before navigating the session tree."),
);
expect(leafUnchanged).toBe(true);
} finally {
harness.cleanup();
}
});
});