test(coding-agent): stabilized coding-agent tests with safer teardown and timing tweaks

- Updated interactive-mode plan review tests to capture shared fixtures, clear references, and run cleanup with explicit garbage collection before disposal.
- Increased the MCP HTTP transport test connection timeout from 200ms to 1,000ms.
- Adjusted the tool streaming command delay and tightened a start-pending-submission spy type in tests for better stability and type accuracy.
This commit is contained in:
can1357
2026-05-31 04:25:14 +02:00
parent ce2e8ce7cd
commit 2eb39bae34
4 changed files with 18 additions and 8 deletions
@@ -2,8 +2,8 @@ import { describe, expect, it, type Mock, vi } from "bun:test";
import { InputController } from "@oh-my-pi/pi-coding-agent/modes/controllers/input-controller";
import type { InteractiveModeContext, SubmittedUserInput } from "@oh-my-pi/pi-coding-agent/modes/types";
type Spy = Mock<(...args: unknown[]) => unknown>;
type StartPendingSubmissionSpy = Mock<InteractiveModeContext["startPendingSubmission"]>;
type FakeEditor = {
onEscape?: () => void;
onSubmit?: (text: string) => Promise<void>;
@@ -64,7 +64,7 @@ function createContext(): {
onInputCallback: Spy;
prompt: Spy;
requestRender: Spy;
startPendingSubmission: Spy;
startPendingSubmission: StartPendingSubmissionSpy;
};
} {
let editorText = "";
@@ -39,6 +39,7 @@ describe("InteractiveMode plan review rendering", () => {
});
beforeEach(async () => {
Bun.gc(true);
resetSettingsForTest();
tempDir = TempDir.createSync("@pi-plan-review-");
await Settings.init({ inMemory: true, cwd: tempDir.path() });
@@ -67,11 +68,20 @@ describe("InteractiveMode plan review rendering", () => {
afterEach(async () => {
vi.restoreAllMocks();
mode?.stop();
await session?.dispose();
authStorage?.close();
tempDir?.removeSync();
const currentMode = mode;
const currentSession = session;
const currentAuthStorage = authStorage;
const currentTempDir = tempDir;
mode = undefined as unknown as InteractiveMode;
session = undefined as unknown as AgentSession;
authStorage = undefined as unknown as AuthStorage;
tempDir = undefined as unknown as TempDir;
currentMode?.stop();
await currentSession?.dispose();
currentAuthStorage?.close();
currentTempDir?.removeSync();
resetSettingsForTest();
Bun.gc(true);
});
it("appends each submitted plan review preview to preserve scrollback", async () => {
@@ -57,7 +57,7 @@ describe("HTTP MCP transport", () => {
connection = await connectToServer("storybook", {
type: "http",
url: String(activeServer.url),
timeout: 200,
timeout: 1_000,
});
expect(connection.serverInfo.name).toBe("storybook-repro");
+1 -1
View File
@@ -1108,7 +1108,7 @@ function b() {
const updates: string[] = [];
const result = await bashTool.execute(
"test-call-8-stream",
{ command: "for i in 1 2 3; do echo $i; sleep 0.05; done" },
{ command: "for i in 1 2 3; do echo $i; sleep 0.2; done" },
undefined,
update => {
const text = update.content?.find(c => c.type === "text")?.text ?? "";